CoDoc is a lightweight VS Code extension for authoring CODOC structures and driving dependency-aware code generation through the OpenCode CLI. It gives you a file-explorer-style view of your codebase, a structured CODOC language for describing intent, and a full loop of analysis, feedforward suggestions, generation, and AI-only feedback decorations.
This README is the primary reference for installation, setup, usage flow, and how the pieces fit together. For deep architectural details, see ARCHITECTURE.md and the referenced source files.
- VS Code 1.80.0+
- Node.js 18+
- Git and a local project to analyze
- OpenCode CLI installed
- OpenAI API key (for impact analysis / feedforward)
Install or upgrade OpenCode following the official instructions, for example:
curl -fsSL https://opencode.ai/install | bashor
npm install -g opencode-ai
Confirm it is available:
opencode --help
opencode version opencode auth login(Optional) You can also add a opencode.json in your project. Settings from this config are merged with and can override the global config. This is useful for configuring providers or modes specific to your project.
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"edit": "allow",
"bash": "allow",
"webfetch": "ask",
"doom_loop": "ask",
"external_directory": "ask"
}
}
The CoDoc extension assumes that:
opencodeis on yourPATH- The model you intend to use for generation is available
For local development CoDoc expects an OpenCode server endpoint. Start it from a terminal:
opencode serve -p 4096 --hostname 127.0.0.1Keep this process running while you use CoDoc. If you run it on a different port or host, update your local configuration or the extension settings accordingly.
Clone this repository and install dependencies:
cd /Users/r4yen/Desktop/Research/CoDoc/repos/CoDoc
npm installBuild the extension and the webview:
# Build the extension TypeScript
npm run compile
# Build the React-based webview UI
cd webview-ui
npm install
cd ..
npm run build:webviewYou can also use the provided VS Code tasks (for example build-all) to run npm: compile and build:webview in sequence.
To launch the extension in an Extension Development Host:
- Open this folder in VS Code.
- Press
F5to start debugging. - In the new window, open or create a
.codocfile.
At a high level, CoDoc provides:
- A custom text editor for
.codocfiles with a file-explorer-style layout. - A Chevrotain-based parser that turns CODOC text into a structured
SchemaNodetree. - A Babel-based analysis engine that scans your actual source code and builds a dependency graph.
- A feedforward (impact analysis) loop that suggests CODOC edits based on the dependencies of what you are editing.
- An OpenCode integration that uses your CODOC structure and analysis results to drive code generation.
- A feedback decoration system that visually marks only AI-generated changes in the CODOC view (additions, removals, modifications, renames, moves, refactors) with gutter markers and hover actions.
The core types live in src/types.ts and are shared across these systems (SchemaNode, CodebaseSnapshot, DependencyGraph, StructuralDiff, AIChange, and related interfaces).
This section describes the typical flow from a human interaction perspective, and then points you to the implementation files.
- You open a
.codocfile in the CoDoc editor. - You click the "Scan Codebase" button or run the
CoDoc: Scan Codebasecommand. - The extension invokes the
AnalysisEngineto scan your project files (for examplesrc/**/*.{ts,tsx,js,jsx,py,java}) using Babel. - As it walks the AST, it extracts functions, components, variables, imports, exports, calls, and identifier references.
- From this, it builds a
CodebaseSnapshotandDependencyGraph, recording upstream and downstream relationships for each element.
From your perspective: after a scan completes, the CODOC view is now connected to the real codebase and can reason about dependencies.
Related files:
src/services/AnalysisEngine.ts– Babel-based analysis and snapshot buildingsrc/types.ts–CodeElement,FileStructure,CodebaseSnapshot,DependencyGraphsrc/providers/CodocEditorProvider.ts– bridges commands from the webview to the analysis engine
You describe the intended structure of your codebase using CODOC syntax in the custom editor. Example:
/src -> / for folder
/components
Register.tsx -> file (*.(ts,tsx,js,jsx, html, css))
%Register -> component
$handleSubmit() -> function
$validateForm()
# fetch database and auth -> natural language commments
From your perspective: you think in terms of folders, files, components, and functions. CoDoc keeps indentation and structure consistent and validates against the CODOC grammar.
Related files:
src/parser/lexer.ts– token definitions for directories, files, components, functions, variables, references, and notessrc/parser/lineParser.ts– line-level CST parsersrc/parser/codocParser.ts– builds theSchemaNodetree and computes content hashessrc/parser/indentCalculator.ts– central indentation rules
While you edit a .codoc file:
- When you change a node that has dependencies or dependents, the editor sends an event to the extension.
- After a short debounce (for example 2.5 seconds), the
ImpactAnalysisServicequeries the dependency graph and recent generation history. - It calls an OpenAI model (via your OpenAI API key) to analyze the impact of your edit and suggest additional CODOC changes.
- The webview displays these as structured suggestions (with
codocSyntax,reason,insertLine, andindentLevel).
From your perspective: when you touch something that affects other parts of the system, CoDoc recommends concrete CODOC edits you may want to make elsewhere.
Related files:
src/services/ImpactAnalysisService.ts– feedforward logic and OpenAI callssrc/types.ts–ImpactAnalysis,SuggestedChangewebview-ui/src/components/CodocEditor.tsx– renders suggestion panels and handles messages
When you are satisfied with your CODOC description:
- You click "Generate Code" or run
CoDoc: Generate with OpenCode. - The extension gathers the current CODOC content and the latest
CodebaseSnapshot. - It uses the OpenCode integration service to write a temporary prompt file under
/tmp, containing your CODOC structure, analysis summaries, and any relevant context. - It launches
opencode generate --prompt-file ...in a VS Code-integrated terminal. - OpenCode produces code changes in your real project files.
- The extension records a concise generation summary in
.codoc/history.json(bounded history) for later impact analysis.
From your perspective: you press one button, watch OpenCode run, and then see your project files updated accordingly.
Related files:
src/services/OpenCodeService.tsorsrc/services/agent/OpenCodeSDKService.ts– wrapper around theopencodeCLI and server endpointsrc/providers/CodocEditorProvider.ts– orchestrates generation and message passingsrc/types.ts–OpenCodeRequest,OpenCodeResponse
After a generation finishes, CoDoc highlights only the AI-generated changes in the CODOC view. The flow is:
- When you press "Generate", previous feedback decorations are cleared (treated as accepted).
- The extension stores a pre-generation snapshot of the CODOC structure (
SchemaNode[]) andCodebaseSnapshot. - OpenCode runs and modifies the codebase.
- After a short delay, CoDoc rescans the codebase and reconstructs a new CODOC structure from the updated files.
- The
StructuralDiffEnginecompares pre- and post-generation CODOC snapshots. - It classifies node-level changes into
AIChange[], including additions, removals, modifications, renames, moves, and refactorings. - The extension sends
AIChange[]to the webview, which renders them as editor decorations.
From your perspective: you see a clear overlay of what the AI changed, without mixing in your manual edits.
Change classes and their visual treatment include:
- Add (green): new functions, components, files, directories.
- Remove (red): deleted elements, shown as strikethrough widgets.
- Modify (orange): changed content at the same path.
- Rename (blue): same content hash, different name.
- Move (purple): same content hash and name, different directory.
- Refactor (teal): extracted, inlined, split, merged, or restructured logic.
Hover affordances allow you to reject individual changes. Rejections clear the decoration and dispatch a feedbackChangeRejected event; full content restoration is a planned enhancement.
Related files:
src/services/StructuralDiffEngine.ts– structural diff andAIChangeclassificationsrc/services/AnalysisEngine.ts– provides the structural snapshots used for comparisonsrc/providers/CodocEditorProvider.ts– orchestrates pre/post snapshots and sendsAIChange[]to the webviewwebview-ui/src/lib/editor/feedbackDecorationExtension.ts– CodeMirror decorations for AI feedbackwebview-ui/src/components/CodocEditor.tsx– routes messages and hooks the extension into the view
The webview editor is built on CodeMirror and uses custom extensions to represent CODOC semantics:
- Feedback decorations: colored backgrounds, borders, gutter markers, hover buttons, and deletion widgets driven by
AIChangeobjects. - Activity and impact gutters: visual cues for where recent activity or suggestions are located.
- Dependency and file-structure extensions: highlighting of related nodes and collapsible structure.
- Schema folding: expand and collapse directories, files, and logical sections.
From your perspective: the editor behaves like a structured file explorer plus outline view, with gutters that surface analysis, suggestions, and AI feedback without leaving the CODOC context.
Related files:
webview-ui/src/lib/editor/activityGutterExtension.tswebview-ui/src/lib/editor/dependencyHighlightExtension.tswebview-ui/src/lib/editor/fileStructureExtension.tswebview-ui/src/lib/editor/schemaFoldingExtension.tswebview-ui/src/lib/editor/feedforwardService.tswebview-ui/src/lib/editor/feedbackDecorationExtension.ts
CoDoc supports two code generation providers. Choose one:
- OpenCode SDK (default): Uses a local OpenCode server. Requires setup (install CLI, auth, start server).
- Claude Agent SDK: Uses Anthropic Claude API. Requires only an API key.
Via VS Code Settings UI
- Open VS Code Settings:
Cmd + ,(macOS) /Ctrl + ,(Windows/Linux). - Search
codocand click the CoDoc section. - Set SDK Provider to OpenCode SDK (Local Server).
- Scroll down to OpenCode SDK Setup and click each blue link in order:
- Step 1: Install OpenCode CLI → runs
npm install -g opencode-ai. - Step 2: OpenCode Authentication → runs
opencode auth login(follow terminal prompts). - Step 3: Start OpenCode Server → runs
opencode serve -p 4096 --hostname 127.0.0.1(keep this terminal open).
- Step 1: Install OpenCode CLI → runs
Via settings.json
{
"codoc.sdkProvider": "opencode",
"codoc.openCodeServerUrl": "http://127.0.0.1:4096"
}Via VS Code Settings UI
- Open VS Code Settings:
Cmd + ,(macOS) /Ctrl + ,(Windows/Linux). - Search
codocand click the CoDoc section. - Set SDK Provider to Claude Agent SDK (API Key).
- Fill in Claude API Key with your Anthropic API key (get one from https://console.anthropic.com/keys).
Via settings.json
{
"codoc.sdkProvider": "claude",
"codoc.claudeApiKey": "sk-ant-..."
}- OpenAI API Key: Required for impact analysis and feedforward suggestions.
- Auto Sync: Toggle to auto-sync CoDoc with codebase changes.
- OpenCode Server URL: Customize if running OpenCode on a different host/port.
Key paths and scripts:
- Core extension entry:
src/extension.ts - Custom editor provider:
src/providers/CodocEditorProvider.ts - Services:
src/services/* - Parser:
src/parser/* - Webview UI:
webview-ui/src/*
Build and watch during development:
npm run compile # Build extension
npm run watch # TypeScript watch mode for extension
npm run build:webview # Build React webviewTo debug, use F5 in VS Code to launch an Extension Development Host and work against a test project and .codoc file.
| Syntax | Element | Example |
|---|---|---|
/name |
Directory | /src |
file.ext |
File | Register.tsx |
%Name |
Component | %Register |
$name() |
Function | $handleSubmit() |
varName |
Variable | emailInput |
@name |
Reference | @useAuth |
# text |
Note | # Auth logic |
Indentation: 2 spaces per level.
MIT