3.9 KiB
Copilot Instructions for Cline
This is a VS Code extension. Read .clinerules/general.md for tribal knowledge and nuanced patterns.
Architecture
- Core (
src/):extension.ts→WebviewProvider→Controller(single source of truth) →Task(agent loop). - Webview (
webview-ui/): React/Vite app. State viaExtensionStateContext.tsx, synced through message passing. - CLI (
cli/): React Ink terminal UI sharing core logic. Update CLI when changing webview features. - Communication: Protobuf-defined gRPC-like protocol over VS Code message passing. Schemas in
proto/. - MCP:
src/services/mcp/McpHub.ts.
Build & Test (Critical — non-obvious commands)
- Build:
npm run compile— NOTnpm run build. - Watch:
npm run watch(extension + webview). - Protos:
npm run protos— run immediately after any.protochange. Generates intosrc/shared/proto/,src/generated/. - Tests:
npm run test:unit. After prompt/tool changes:UPDATE_SNAPSHOTS=true npm run test:unit.
Protobuf RPC Workflow (4 steps)
- Define in
proto/cline/*.proto. Naming:PascalCaseService,camelCaseRPCs,PascalCaseMessages. Usecommon.protoshared types for simple data. - Generate:
npm run protos. - Backend handler:
src/core/controller/<domain>/. - Frontend call:
UiServiceClient.myMethod(Request.create({...})).
- Adding enums (e.g.
ClineSay) → also updatesrc/shared/proto-conversions/cline-message.ts.
Adding API Providers (silent failure risk)
Three proto conversion updates are required or the provider silently resets to Anthropic:
proto/cline/models.proto— add toApiProviderenum.convertApiProviderToProto()insrc/shared/proto-conversions/models/api-configuration-conversion.ts.convertProtoToApiProvider()in the same file.
Also update: src/shared/api.ts, src/shared/providers/providers.json, src/core/api/index.ts, webview-ui/.../providerUtils.ts, webview-ui/.../validate.ts, webview-ui/.../ApiOptions.tsx, and cli/src/components/ModelPicker.tsx.
For Responses API providers: add to isNextGenModelProvider() in src/utils/model-utils.ts and set apiFormat: ApiFormat.OPENAI_RESPONSES on models.
Adding Tools to System Prompt (5+ file chain)
- Add enum to
ClineDefaultToolinsrc/shared/tools.ts. - Create definition in
src/core/prompts/system-prompt/tools/(export[GENERIC]minimum). - Register in
src/core/prompts/system-prompt/tools/init.ts. - Whitelist in
src/core/prompts/system-prompt/variants/*/config.tsfor each model family. - Handler in
src/core/task/tools/handlers/, wire inToolExecutor.ts. - If tool has UI: add
ClineSayenum in proto →ExtensionMessage.ts→cline-message.ts→ChatRow.tsx. - Regenerate snapshots:
UPDATE_SNAPSHOTS=true npm run test:unit.
Modifying System Prompt
Modular: components/ (shared) + variants/ (model-specific) + templates/ ({{PLACEHOLDER}}). Variants override components via componentOverrides in config.ts or custom template.ts. XS variant is heavily condensed inline. Always regenerate snapshots after changes.
Global State Keys (silent failure risk)
Adding a key requires: type in src/shared/storage/state-keys.ts, read via context.globalState.get() in src/core/storage/utils/state-helpers.ts readGlobalStateFromDisk(), and add to return object. Missing the .get() call compiles fine but value is always undefined.
Slash Commands (3 places)
src/core/slash-commands/index.ts— definitions.src/core/prompts/commands.ts— system prompt integration.webview-ui/src/utils/slash-commands.ts— webview autocomplete.
Conventions
- Paths: Always use
src/utils/pathhelpers (toPosixString) for cross-platform compatibility. - Logging:
src/shared/services/Logger.ts. - Feature flags: See PR #7566 as reference pattern.