This file provides guidance when working with code in this repository.
Overwrite is a Visual Studio Code extension that helps users select files and folders from their workspace, build structured XML prompts for Large Language Models (LLMs), and apply LLM-suggested changes back to local files. The extension provides a webview-based interface with tabs for file exploration, context building, and applying changes.
pnpm compile- Compile TypeScript to JavaScriptpnpm watch- Watch for changes and compile automaticallypnpm lint- Run Biome linter to check and fix code stylepnpm test- Run extension tests (compiles, lints, then runs tests)pnpm check-types- Type check without emitting filespnpm package- Create production package (includes webview build)pnpm vscode:package- Create .vsix extension package
- Make changes to TypeScript files in
src/ - Run
pnpm watchto compile automatically during development - Use
pnpm packagefor production builds
The extension follows a strict frontend-backend architecture:
Extension Host (Backend):
src/extension.ts- Main entry point, registers webview providersrc/providers/file-explorer/- Core webview provider and message handlingsrc/services/- Backend services (token counting, etc.)src/utils/- Utility functions for file system, XML parsingsrc/prompts/- XML prompt generation logic
Webview UI (Frontend):
src/webview-ui/- React 19 application with TypeScript- Uses
@vscode-elements/elementsfor VS Code-native UI components - Separate package.json with its own build system (Vite)
CRITICAL: Webview and extension communicate exclusively through message passing. NEVER use vscode.commands.executeCommand() directly in the webview.
Webview → Extension:
- Use
getVsCodeApi().postMessage()fromsrc/webview-ui/src/utils/vscode.ts - Messages handled in
src/providers/file-explorer/index.ts
Extension → Webview:
- Use
this._view.webview.postMessage()in webview provider - Messages handled in
src/webview-ui/src/App.tsx
File Explorer Provider (src/providers/file-explorer/index.ts):
- Manages webview lifecycle and message handling
- Handles file tree generation and caching
- Processes token counting requests
- Manages excluded folders state
Webview UI (src/webview-ui/src/):
- Three main tabs: Explorer, Context, Apply
- React components using VS Code elements
- Token counting integration
- XML response parsing and application
Settings Tab (src/webview-ui/src/components/settings-tab/):
- Form-based UI for user preferences (currently “Excluded Folders”).
- Uses a native
<form>with a single submit handler, adraftstate object, and dirty tracking. - Fields expose
nameand accessible labeling; avoid settingformattribute on<vscode-button>(usetype="submit").
Services (src/services/):
token-counter.ts- Token estimation using js-tiktoken- Caching mechanism for performance
- All files must use kebab-case (e.g.,
context-tab.tsx,file-system.ts) - This maintains consistency for URLs and imports
- Use
@vscode-elements/elementscomponents directly in JSX - Type definitions in
src/webview-ui/src/global.d.ts - In React, use
classNameandhtmlForon web components — React maps them toclassandforat runtime. This matches our typings inglobal.d.ts(useclassName, notclass). - Custom events use
on-prefixed props (e.g.,onvsc-tabs-select)
- Always use request IDs for request-response flows
- Implement timeout mechanisms for webview requests
- All message commands must be registered in
App.tsxto prevent warnings
- Webview tests (preferred for verification):
pnpm -C src/webview-ui test --run - Runs Vitest against the React webview UI.
- Use this command when verifying functionality in this repo.
- Backend/extension tests are located in
src/test/suite/and use Mocha with the VS Code runner. - Do not run backend/VS Code-side tests as part of routine verification in this environment.
- Main extension: ESBuild (configured in
esbuild.js) - Webview UI: Vite (separate build in
src/webview-ui/) - Production builds include webview assets in
dist/webview-ui/
- Code formatter and linter
- Uses 2 spaces for indentation
- Single quotes for JavaScript
- Specific rules disabled for VS Code extension development
- Main project:
tsconfig.json(excludes webview-ui) - Webview UI: Separate TypeScript config in
src/webview-ui/
- Uses PNPM as package manager
- Webview UI has its own package.json and dependencies
- Tailwind v4 is used in
src/webview-ui. Import once insrc/webview-ui/src/index.cssvia@import 'tailwindcss';. - VS Code theme tokens are mapped to Tailwind colors using
@themein that file:- Examples:
--color-fg,--color-bg,--color-muted,--color-error,--color-button,--color-button-hover,--color-button-foreground,--color-warn-bg,--color-warn-border. - Use utilities like
text-fg,text-muted,text-error,bg-bg,bg-warn-bg,border-warn-border, etc.
- Examples:
- Prefer Tailwind utilities over inline styles for layout/spacing; keep inline styles only where dynamic token logic is needed.
When you need to call tools from the shell, use this rubric:
- Find files:
fd - Find text:
rg(ripgrep) - Find code structure (TS/TSX):
ast-grep- Default to TypeScript:
.ts:ast-grep --lang ts -p '<pattern>'.tsx(React):ast-grep --lang tsx -p '<pattern>'
- For other languages, set
--langappropriately (e.g.,--lang rust)
- Default to TypeScript:
- Select among matches: pipe to
fzf - JSON:
jq - YAML/XML:
yq
When you change anything in src/webview-ui/, verify behavior using Playwright MCP against the always-running dev server. The webview boots with a mocked VS Code API so you can exercise flows without the extension host.
-
Open the app
- Navigate with Playwright MCP to
http://localhost:5173/. - The mock API lives at
src/webview-ui/src/utils/mock.tsand provides deterministic data (file tree, excluded folders, token counts). No real filesystem operations occur.
- Navigate with Playwright MCP to
-
Basic smoke steps
- Switch tabs via role selectors, e.g.,
page.getByRole('tab', { name: 'Settings' }).click(). - Interact with inputs and buttons using role-based queries; verify state changes (disabled/enabled, text content) and UI feedback.
- Example (Settings): type into the Excluded Folders textarea, confirm the
Savebutton enables, click Save, observe the transient “Settings saved” indicator, and ensure the button disables again.
- Switch tabs via role selectors, e.g.,
-
File tree checks
- The Context tab shows the mock file tree generated in
buildMockFileTree()insidemock.ts. - After saving settings that affect exclusions, the UI posts
getFileTreeand refreshes using the mock; validate the message flow only (no real files change).
- The Context tab shows the mock file tree generated in
-
Console noise
- You may see VS Code Elements warnings about codicons in dev; these are expected in the browser playground.
-
Do not use
vscode.commandsin the webview; all extension interactions occur viagetVsCodeApi().postMessage()and are handled insrc/providers/file-explorer/index.ts.