VS Code Extension Architecture
The VS Code extension (packages/biggi-vscode/) is the BIGGI client. It bundles the local runtime, starts one shared editor-owned server on demand, and drives that server through generated SDK HTTP calls plus global SSE.
This page covers extension-host ownership, webview routing, Agent Manager, local terminal paths, recovery, bundled resources, and build outputs. It is not full extension feature inventory.
Shared server ownership
Embedded Runtime defines local-server authentication, directory routing, provider routing, persistence, and SSE contracts. This page starts at the VS Code client boundary.
Activation creates one BiggiConnectionService. It owns one ServerManager, one active SDK client, and one SSE adapter. ServerManager owns child process lifecycle. This editor-owned child is separate from detached local daemon managed by biggi daemon.
| Area | Behavior |
|---|---|
| Startup | Lazy on client demand; autocomplete prewarm can start server during activation |
| Binary | Uses extension bin/biggi, or bin/biggi.exe on Windows |
| Port | Starts biggi serve --port 0; the runtime server prefers 4096, then asks the OS for a free port |
| Authentication | Generates random 32-byte hex password per spawn and passes it as BIGGI_SERVER_PASSWORD; username defaults to biggi |
| Reuse | Sidebar, editor tabs, panels, Agent Manager, and host services share active server |
| Exit | ServerManager clears dead child; connection service clears SDK/SSE state and enters error state |
| Replacement | Later retry or connection attempt starts replacement server |
Shared consumers
Shared service has more consumers than chat tabs:
| Family | Consumers |
|---|---|
| Chat | Sidebar provider and editor-tab providers |
| Panels | Settings, profile, sub-agent viewers, and Agent Manager |
| Diff | Diff Viewer, Diff Virtual, and diff source catalog |
| Editor assistance | Autocomplete and commit-message generation |
| Integrations | Browser automation and MCP registration |
New mutable state must account for concurrent consumers and multiple directory contexts on one process.
Webview bridge
Main chat webviews use host-mediated message bridge:
webview vscode.postMessage() -> BiggiProvider host handler -> generated SDK HTTP request -> embedded runtime -> /global/event SSE -> SdkSSEAdapter -> BiggiConnectionService subscribers -> BiggiProvider directory/session filtering and stream coalescing -> webview postMessage()
Global SSE carries wrapped events for multiple directories. Connection service broadcasts incoming payload plus directory to subscribers. Providers resolve session scope, maintain message-to-session lookup where events omit direct session ID, filter for relevant views, and coalesce high-frequency stream updates before posting UI messages.
Agent Manager
Agent Manager is extension feature, not separate product. It opens as editor tab and manages parallel sessions, optional worktrees, terminals, diffs, setup scripts, and extra editor windows.
| Aspect | Sidebar | Agent Manager |
|---|---|---|
| Primary use | One active chat view | Multi-session orchestration |
| Git isolation | Workspace root by default | Optional worktree per session |
| Backend | Shared biggi serve process | Same shared process |
| Request routing | Workspace directory | Session worktree path passed as SDK directory |
| Runtime instance key | Normalized workspace root | Normalized worktree directory |
Agent Manager request path is:
session worktree path -> SDK directory -> runtime directory-routing middleware -> InstanceStore directory key
Agent Manager persists state in .biggi/agent-manager.json and worktrees under .biggi/worktrees/. Startup migration moves Agent Manager-owned data from legacy .biggi/ paths when target items do not already exist and repairs git worktree refs.
State boundaries
Directory-keyed runtime state is isolated by worktree path. Process-owned state remains shared because all Agent Manager sessions use one runtime process. Snapshot implementation state is directory-keyed, but slow-snapshot prompt guard belongs to shared Snapshot.Service scope. Managed Agent Manager prompts pass snapshotInitialization: "wait" so slow baseline setup waits without interrupting concurrently started sessions.
Terminal surfaces
VS Code extension has two terminal paths:
| Surface | Owner | Use |
|---|---|---|
| VS Code integrated terminal | VS Code host | Shell terminals and setup-script execution surfaced through editor |
| Runtime PTY WebSocket tab | Agent Manager and embedded server | Server-created PTY session streamed over loopback WebSocket |
Agent Manager PTY WebSocket URL uses auth_token=<base64 biggi:password> query mode because browser WebSocket API cannot attach Basic header. Webview CSP permits loopback HTTP and WebSocket origins for the active server port. The runtime also exposes a scope-bound, short-lived PTY ticket API as an alternate browser WebSocket auth mode.
Config split
| Config owner | Examples |
|---|---|
| VS Code settings | biggi-code.new.* extension UI, proxy, autocomplete, and integration settings |
| Runtime config | Global and project biggi.jsonc, biggi.json, compatible OpenCode files, provider auth, tools, permissions, modes |
Extension-specific behavior belongs in VS Code settings. Agent runtime behavior belongs in runtime config.
Bundled resources
| Resource | Behavior |
|---|---|
| Runtime executable | Platform binary under extension bin/; Windows uses biggi.exe |
| Runtime Tree-sitter WASM | Copied under bin/tree-sitter; backend spawn sets BIGGI_TREE_SITTER_WASM_DIR |
| Empty-window cwd | Uses extension global storage directory when no VS Code workspace folder exists |
| Empty-window indexing | Sets BIGGI_DISABLE_CODEBASE_INDEXING=vscode-no-workspace so the runtime reports indexing disabled |
Speech-to-text and the hosted BIGGI Marketplace are not part of the current user-facing product. Do not document dormant implementation paths as available features without first shipping and enabling their complete user flow.
Recovery
| Failure signal | Response |
|---|---|
| Missing SSE events for 15 seconds | SSE adapter aborts attempt and reconnects |
| SSE reconnect | Starts at 250 ms delay and backs off to 5 seconds until stream opens |
| Health poll | Every 10 seconds, checks /global/health with 3 second timeout; failure forces SSE reconnect |
| Server exit | Clears connection state, reports error, and lets later retry or connection attempt spawn replacement |
| Extension disposal | Stops polls, disposes SSE, and sends server process group termination with kill fallback |
Builds
| Build | Source | Output |
|---|---|---|
| Extension host | src/extension.ts | dist/extension.js |
| Sidebar and editor chat webview | webview-ui/src/index.tsx | dist/webview.js |
| Agent Manager webview | webview-ui/agent-manager/index.tsx | dist/agent-manager.js |
| Diff Viewer webview | webview-ui/diff-viewer/index.tsx | dist/diff-viewer.js |
| Diff Virtual webview | webview-ui/diff-virtual/index.tsx | dist/diff-virtual.js |
| Shared Shiki worker | synthetic worker entry | dist/shiki-worker.js |
Extension host bundle targets Node/CommonJS. Browser webviews and shared worker use esbuild browser bundles. Run bun run typecheck, bun run lint, and targeted unit tests from packages/biggi-vscode/ after changing this area.
Source map
Paths below are relative to stemcat/biggi.
| Concern | Source path |
|---|---|
| Activation | packages/biggi-vscode/src/extension.ts |
| Editor-owned server child process | packages/biggi-vscode/src/services/cli-backend/server-manager.ts |
| Shared SDK and SSE ownership | packages/biggi-vscode/src/services/cli-backend/connection-service.ts |
| SSE reconnect adapter | packages/biggi-vscode/src/services/cli-backend/sdk-sse-adapter.ts |
| Agent Manager | packages/biggi-vscode/src/agent-manager/ |
| Build entries | packages/biggi-vscode/esbuild.js |
Related pages
- Architecture Overview - local and hosted execution map
- Embedded Runtime - shared local-server, routing, persistence, and SSE behavior
- Development Patterns - choose code-ownership seam and validation workflow before editing extension contracts