|
2 | 2 |
|
3 | 3 | This file provides guidance to agents when working with code in this repository. |
4 | 4 |
|
5 | | -## Critical Non-Obvious Patterns |
6 | | - |
7 | | -- **JSON Writes**: MUST use `safeWriteJson()` from `src/utils/safeWriteJson.ts` for ALL JSON writes (atomic writes with locking, handles streaming) |
8 | | -- **Test Execution**: Tests MUST run from workspace directory: `cd src && npx vitest run` or `cd webview-ui && npx vitest run` (NOT from root) |
9 | | -- **Import Extensions**: Use `.js` extensions in packages/ imports despite TypeScript source files |
10 | | -- **Bootstrap**: `pnpm install` auto-bootstraps via `scripts/bootstrap.mjs` if pnpm not found |
11 | | -- **Webview DevTools**: Access via Command Palette → "Developer: Open Webview Developer Tools" (not F12) |
12 | | -- **VSCode CSS Variables**: Must be added to `webview-ui/src/index.css` before use in components |
13 | | -- **React Hooks Required**: External state libraries break webview isolation - use React hooks only |
14 | | -- **noUncheckedIndexedAccess**: TypeScript strict mode with this enabled - array/object access may return undefined |
15 | | - |
16 | | -## Architecture Gotchas |
17 | | - |
18 | | -- `src/` contains VSCode extension backend (not generic source) |
19 | | -- `webview-ui/` is React frontend in VSCode webview (restricted APIs, no localStorage) |
20 | | -- IPC messages between extension/webview must use typed interfaces from `packages/types` |
21 | | -- Provider implementations must be stateless (hidden caching layer assumes this) |
| 5 | +## Critical Non-Obvious Rules |
| 6 | + |
| 7 | +- **MUST** use `safeWriteJson()` from `src/utils/safeWriteJson.ts` for ALL JSON file writes (prevents corruption via atomic writes with locking) |
| 8 | +- Test files exempt from safeWriteJson rule |
| 9 | + |
| 10 | +## Project Structure (Non-Standard) |
| 11 | + |
| 12 | +- `src/` contains VSCode extension code (NOT general source - counterintuitive naming) |
| 13 | +- `webview-ui/` is the React UI that runs in VSCode webview (separate from extension) |
| 14 | +- Two separate i18n systems: root `locales/` for extension, `webview-ui/src/i18n/` for UI |
| 15 | +- Monorepo uses pnpm workspaces with unusual paths: `"src"` and `"webview-ui"` as workspace roots |
| 16 | + |
| 17 | +## Testing Specifics |
| 18 | + |
| 19 | +- Tests MUST be in `__tests__` folders or `.spec.ts` files (vitest configured this way) |
| 20 | +- VSCode module mocked at `src/__mocks__/vscode.js` and `webview-ui/src/__mocks__/vscode.ts` |
| 21 | +- Run single test: `pnpm test -- path/to/test.spec.ts` |
| 22 | + |
| 23 | +## Build Commands (Directory-Sensitive) |
| 24 | + |
| 25 | +- Database operations MUST run from `packages/evals/` directory: `cd packages/evals && pnpm db:migrate` |
| 26 | +- Extension bundling uses custom `esbuild.mjs` script, not standard vite/webpack |
| 27 | + |
| 28 | +## Webview Restrictions |
| 29 | + |
| 30 | +- Webview has NO localStorage, limited browser APIs |
| 31 | +- IPC communication through specific patterns in `src/core/webview/webviewMessageHandler.ts` |
| 32 | +- State management requires React hooks only (external state libraries break isolation) |
| 33 | + |
| 34 | +## Code Style (Non-Standard) |
| 35 | + |
| 36 | +- Tabs not spaces (4-width), no semicolons, bracket same line |
| 37 | +- Line width 120 chars (not default 80) |
0 commit comments