Skip to content

Add Cesium Copilot AI assistant to Sandcastle#13185

Closed
jdehorty wants to merge 3 commits intoCesiumGS:mainfrom
jdehorty:cesium-copilot-mvp
Closed

Add Cesium Copilot AI assistant to Sandcastle#13185
jdehorty wants to merge 3 commits intoCesiumGS:mainfrom
jdehorty:cesium-copilot-mvp

Conversation

@jdehorty
Copy link

@jdehorty jdehorty commented Feb 3, 2026

Summary

This PR introduces Cesium Copilot, an AI-powered coding assistant integrated directly into Sandcastle. Copilot helps users write, modify, and debug CesiumJS code through a conversational interface with intelligent code generation and real-time diff previews.

Features

Multi-Model AI Support

  • Google Gemini (Gemini 3 Flash Preview, Gemini 3 Pro Preview)
  • Anthropic Claude (Claude Opus 4.5, Claude Sonnet 4.5, Claude Haiku 4.5)
  • Easy model switching via dropdown picker
  • Secure API key management with localStorage persistence

Intelligent Code Assistance

  • Contextual Understanding: Copilot sees your current JavaScript and HTML code
  • CesiumJS-Aware Prompts: System prompts include API deprecation guides to avoid suggesting outdated patterns (e.g., createWorldTerrain()Terrain.fromWorldTerrain())
  • Streaming Responses: Real-time token streaming for responsive feedback
  • Extended Thinking: Support for Claude's extended thinking mode with reasoning display

Code Editing with Diff Preview

  • Search/Replace Diff Format: AI generates precise code edits using a structured diff format
  • Visual Diff Preview: Side-by-side comparison before applying changes
  • Fuzzy Matching: Robust diff application even when code has minor variations
  • One-Click Apply: Accept or reject proposed changes with full undo support

Tool Use Integration

  • Run Code Tool: Execute code in Sandcastle and capture results/errors
  • Error Context Extraction: Automatic error detection with line numbers and stack traces
  • Auto-Iteration: Optional automatic retry on errors with oscillation detection

Conversation Management

  • Chat History: Persistent conversation history with search
  • Multi-Turn Context: Full conversation context maintained across messages
  • Image Attachments: Paste or drag-and-drop images for visual context

User Experience

  • Collapsible chat panel with keyboard shortcuts
  • Settings panel for model configuration and feature toggles
  • Welcome guidance for new users
  • Token usage display

Architecture

packages/sandcastle/src/
├── AI/
│   ├── AIClientFactory.ts      # Factory for creating AI clients
│   ├── AnthropicClient.ts      # Claude API integration
│   ├── GeminiClient.ts         # Gemini API integration  
│   ├── ApiKeyManager.ts        # Secure key storage
│   ├── DiffParser.ts           # Parse AI-generated diffs
│   ├── DiffMatcher.ts          # Fuzzy matching for diff application
│   ├── DiffApplier.ts          # Apply diffs to source code
│   ├── EditParser.ts           # Parse edit instructions
│   ├── ErrorContext.ts         # Extract error information
│   ├── prompts.ts              # System prompts with CesiumJS knowledge
│   ├── tools/toolRegistry.ts   # Tool definitions for function calling
│   └── types.ts                # TypeScript interfaces
├── ChatPanel.tsx               # Main chat interface
├── ChatMessage.tsx             # Message rendering with markdown
├── DiffPreview.tsx             # Visual diff component
├── components/
│   ├── settings/               # Settings UI components
│   ├── history/                # Conversation history sidebar
│   └── controls/               # Model picker, toggles
└── contexts/                   # React contexts for state management

Testing

  • 16 test files covering core functionality
  • Unit tests for diff parsing, matching, and application
  • Component tests for UI interactions
  • Integration tests for AI client behavior

Screenshots

[Screenshots would be added here showing the chat panel, diff preview, and settings]

Checklist

  • Code compiles without errors
  • Tests pass locally
  • No changes to core CesiumJS engine
  • Changes isolated to packages/sandcastle
  • API keys are never logged or exposed
  • Added contributor entry

Notes

  • This feature is opt-in: users must provide their own API keys
  • No API keys are stored on any server; all keys remain in browser localStorage
  • The AI has read-only context of the current code; all edits require user approval

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Thank you for the pull request, @jdehorty!

✅ We can confirm we have a CLA on file for you.

Integrates an AI-powered coding assistant into Sandcastle that helps users
write and modify Cesium code. Features include:

- Multi-model support (Gemini, Anthropic Claude) with API key management
- Intelligent diff parsing and application for code modifications
- Chat interface with streaming responses and tool call handling
- Error context extraction for debugging assistance
- Comprehensive test coverage for AI client and diff logic
@Guillar1 Guillar1 marked this pull request as draft February 3, 2026 10:35
@jdehorty jdehorty closed this Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants