Skip to content

Commit bac4937

Browse files
committed
docs: update .deepcode/AGENTS.md
1 parent 4f71c05 commit bac4937

1 file changed

Lines changed: 65 additions & 79 deletions

File tree

.deepcode/AGENTS.md

Lines changed: 65 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,61 @@
22

33
## Project Structure & Module Organization
44

5+
This is an **npm workspaces monorepo**. Packages live under `packages/`.
6+
57
```
6-
src/
7-
├── cli.tsx # Entry point — parses args (-p, -v), renders Ink App
8-
├── session.ts # SessionManager — LLM loop, compaction, tool orchestration
9-
├── settings.ts # Settings resolution from ~/.deepcode/settings.json
10-
├── prompt.ts # System prompt builder, tool definitions, built-in skills
11-
├── common/
12-
│ ├── bash-timeout.ts # Bash command timeout enforcement
13-
│ ├── debug-logger.ts # Debug logging for OpenAI API calls
14-
│ ├── error-logger.ts # API error logging
15-
│ ├── file-history.ts # GitFileHistory — checkpoint/undo via Git branches
16-
│ ├── file-utils.ts # File read/write with encoding and diff preview
17-
│ ├── model-capabilities.ts # Model detection and thinking-mode defaults
18-
│ ├── notify.ts # Desktop notification after LLM turn completion
19-
│ ├── openai-client.ts # OpenAI client singleton with keep-alive agent
20-
│ ├── openai-thinking.ts # OpenAI thinking request options builder
21-
│ ├── permissions.ts # Permission scoping, decisions, and tool-call tracking
22-
│ ├── process-tree.ts # Process tree construction and orphan detection
23-
│ ├── shell-utils.ts # Shell path resolution (Git Bash, zsh, bash)
24-
│ ├── state.ts # In-memory file state and snippet tracking
25-
│ ├── telemetry.ts # Usage telemetry collection and reporting
26-
│ ├── update-check.ts # Latest-version check against npm registry
27-
│ └── validate.ts # Tool validation runtime helpers (was runtime.ts)
28-
├── mcp/
29-
│ ├── mcp-client.ts # MCP client — JSON-RPC communication with MCP servers
30-
│ └── mcp-manager.ts # MCP manager — lifecycle, tool registration, execution, status
31-
├── tools/
32-
│ ├── executor.ts # ToolExecutor — dispatches tool calls to handlers (7 built-in)
33-
│ ├── bash-handler.ts # Executes shell commands with live stdout streaming
34-
│ ├── read-handler.ts # Reads files, images, PDFs, and notebooks
35-
│ ├── write-handler.ts # Creates/overwrites files
36-
│ ├── edit-handler.ts # Scoped string replacements with snippet tracking
37-
│ ├── update-plan-handler.ts # Updates the task plan progress display
38-
│ ├── web-search-handler.ts # Web search via natural language queries
39-
│ └── ask-user-question-handler.ts # Interactive user prompts with options
40-
├── ui/
41-
│ ├── components/ # Reusable Ink components (MessageView, DropdownMenu, ModelsDropdown, SkillsDropdown, FileMentionMenu, RawModelDropdown, etc.)
42-
│ ├── contexts/ # React contexts (AppContext, RawModeContext)
43-
│ ├── hooks/ # Custom hooks (cursor, useHistoryNavigation, usePasteHandling, useTerminalInput)
44-
│ ├── views/ # Top-level screen components (App, PromptInput, SessionList, PermissionPrompt, ProcessStdoutView, WelcomeScreen, UndoSelector, etc.)
45-
│ ├── core/ # Core UI logic (file-mentions, slash-commands, prompt-buffer, thinking-state, clipboard, prompt-undo-redo, etc.)
46-
│ ├── utils/ # Shared utility helpers
47-
│ ├── ascii-art.ts # ASCII art banner for welcome screen
48-
│ ├── exit-summary.ts # Session exit summary and cost reporting
49-
│ ├── index.ts # UI module barrel exports
50-
│ └── constants.ts # UI-wide constants
51-
├── tests/ # Test files per source module, plus run-tests.mjs
52-
templates/
53-
├── tools/ # Tool descriptions fed to the LLM
54-
├── skills/ # Built-in skill definitions (agent-drift-guard, plan-and-execute, karpathy-guidelines)
55-
└── prompts/ # EJS templates (e.g., init_command.md.ejs)
56-
docs/ # User-facing documentation (configuration, MCP, notify, permissions)
57-
resources/ # Static assets (intro screenshots)
58-
dist/ # Bundled CLI output (gitignored)
8+
packages/
9+
├── core/src/ # LLM session, tool execution, shared utilities
10+
│ ├── common/ # File I/O, permissions, telemetry, OpenAI client, shell utils, etc.
11+
│ ├── tools/ # 7 built-in handlers (bash, read, write, edit, web-search, ask-user-question, update-plan)
12+
│ ├── mcp/ # MCP client & manager (JSON-RPC lifecycle)
13+
│ ├── session.ts # SessionManager — LLM loop, compaction, tool orchestration
14+
│ ├── prompt.ts # System prompt builder & tool definitions
15+
│ └── settings.ts # Settings resolution from ~/.deepcode/settings.json
16+
├── cli/src/ # Terminal UI (Ink/React)
17+
│ ├── cli.tsx # Entry point — parses args (-p, -v), renders AppContainer
18+
│ ├── ui/views/ # Top-level screens (App, PromptInput, SessionList, PermissionPrompt, etc.)
19+
│ ├── ui/components/ # Reusable Ink components (MessageView, DropdownMenu, ModelsDropdown, etc.)
20+
│ ├── ui/core/ # Prompt buffer, slash commands, file mentions, clipboard, undo/redo
21+
│ ├── ui/hooks/ # Custom hooks (cursor, history navigation, paste handling, terminal input)
22+
│ ├── ui/contexts/ # React contexts (AppContext, RawModeContext)
23+
│ └── tests/ # UI-focused tests with run-tests.mjs runner
24+
├── vscode-ide-companion/ # VSCode extension companion
25+
│ └── src/ # extension.ts, provider.ts, utils.ts
26+
docs/ # User-facing documentation (configuration, MCP, notify, permissions)
27+
scripts/ # Build, release, and packaging scripts
28+
dist/ # Bundled CLI output — single-file dist/cli.js (gitignored)
29+
dist/bundled/ # Bundled skills & references shipped with the CLI
5930
```
6031

32+
Templates for tool descriptions and prompts are at `packages/cli/dist/templates/` (copied during build from `packages/core/templates/`). Built-in skills are under `packages/cli/dist/bundled/`.
33+
6134
## Build, Test, and Development Commands
6235

63-
| Command | Purpose |
36+
All commands run from the repo root.
37+
38+
| Command | What it does |
6439
|---|---|
65-
| `npm run typecheck` | TypeScript type checking (`tsc --noEmit`) |
66-
| `npm run lint` | ESLint across `src/` |
40+
| `npm run typecheck` | TypeScript type checking across all workspaces |
41+
| `npm run lint` | ESLint across `packages/*/src/**/*.{ts,tsx}` + `scripts/*.js` |
6742
| `npm run lint:fix` | ESLint with auto-fix |
68-
| `npm run format` | Prettier on all `src/**/*.{ts,tsx}` |
43+
| `npm run format` | Prettier on all source files |
6944
| `npm run format:check` | Prettier in check-only mode |
7045
| `npm run check` | Runs typecheck + lint + format:check together |
71-
| `npm run bundle` | esbuild bundles cli + core + all deps → `dist/cli.js` (ESM, Node 22) |
72-
| `npm run build` | build core (tsc) + rewrite ESM imports + bundle CLI (esbuild) |
73-
| `npm test` | Runs all tests via `node src/tests/run-tests.mjs` |
74-
| `npm run test:single -- <file>` | Run a single test file via `tsx --test` (e.g., `npm run test:single -- src/tests/session.test.ts`) |
46+
| `npm run build` | Orchestrates full build (scripts/build.js) — compiles core + bundles CLI + copies assets |
47+
| `npm run bundle` | Generates git commit info + esbuild bundle + copies bundled assets |
48+
| `npm test` | Runs all workspace tests (`npm run test --workspaces --if-present`) |
49+
| `npm run start` | Runs the locally built CLI (`scripts/start.js`) |
50+
| `npm run build-and-start` | Builds then starts the CLI |
51+
| `npm run clean` | Removes generated files and dist directories |
52+
53+
To run a **single test file** within a package:
54+
```
55+
node packages/core/src/tests/run-tests.mjs packages/core/src/tests/session.test.ts
56+
node packages/cli/src/tests/run-tests.mjs packages/cli/src/tests/slash-commands.test.ts
57+
```
7558

76-
Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundle`).
59+
Run the CLI locally for manual testing: `node packages/cli/dist/cli.js` (after `npm run bundle`).
7760

7861
## Coding Style & Naming Conventions
7962

@@ -84,32 +67,34 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
8467
- **Line width**: 120 characters max
8568
- **Line endings**: LF only
8669

87-
**TypeScript**: Strict mode enabled. Use `import type` for type-only imports (enforced by `@typescript-eslint/consistent-type-imports`). Unused variables prefixed with `_` are allowed.
70+
**TypeScript**: Strict mode enabled (`strict: true`). Use `import type` for type-only imports (`@typescript-eslint/consistent-type-imports`). Unused variables prefixed with `_` are allowed (`argsIgnorePattern: "^_"`). Target ES2022, module ESNext with bundler resolution. JSX is `react-jsx`.
8871

89-
**Formatting/Linting**: Prettier + ESLint (typescript-eslint, react-hooks). Run `npm run check` before pushing. On commit, Husky + lint-staged auto-formats staged `*.{ts,tsx,js,mjs,cjs,ejs,jsx}` and `*.json` files.
72+
**Formatting/Linting**: Prettier (double quotes, 2-space indent, semicolons) + ESLint (typescript-eslint, react-hooks). Run `npm run check` before pushing. On commit, Husky + lint-staged auto-formats staged `*.{ts,tsx,js,mjs,cjs,jsx}` and `*.json` files.
9073

9174
**File naming**: `kebab-case.ts` for modules, `kebab-case.tsx` for React/Ink components. Test files: `*.test.ts` (always kebab-case).
9275

9376
## Testing Guidelines
9477

9578
- **Framework**: Node.js native test runner (`node:test`) with `tsx` for TypeScript
9679
- **Assertions**: `node:assert/strict`
97-
- **Coverage**: Target meaningful unit tests for core logic (session management, tool handlers, settings resolution, prompt buffer, permissions, MCP client, telemetry). Test files are in `src/tests/` matching the source module name.
80+
- **Coverage**: Target meaningful unit tests for core logic (session management, tool handlers, settings resolution, prompt buffer, permissions, MCP client, telemetry). Test files are in `packages/*/src/tests/` matching the source module name.
9881
- **Test naming**: `describe`/`test` blocks with descriptive names. Example: `test("SessionManager preserves structured system content when building OpenAI messages", ...)`
9982
- **Relaxed lint rules**: Test files allow `any` and unused vars.
100-
- Run all tests with `npm test` before submitting a PR. A cross-platform test runner is available at `src/tests/run-tests.mjs`.
83+
- Run all tests with `npm test` before submitting a PR. Each package has its own `run-tests.mjs` cross-platform runner.
10184

10285
## Commit & Pull Request Guidelines
10386

104-
**Commit messages** follow conventional commits. From the project history:
87+
**Commit messages** follow conventional commits:
10588

10689
- `feat:` — new feature (e.g., `feat: add /model command`)
107-
- `fix:` — bug fix (e.g., `fix(ui): redraw cleanly after terminal resize`)
90+
- `fix:` — bug fix (e.g., `fix(mcp): fix Windows MCP spawn double-quoting`)
10891
- `chore:` — tooling, deps, hooks (e.g., `chore: add husky + lint-staged`)
10992
- `refactor:` — code restructuring (e.g., `refactor(ui): optimize App hooks`)
110-
- `style:` — formatting-only changes (e.g., `style: adjust the tree structure symbols`)
111-
- `test:` — adding or updating tests (e.g., `test: add telemetry module unit tests`)
112-
- `docs:` — documentation (e.g., `docs: add MCP configuration guide`)
93+
- `style:` — formatting-only changes
94+
- `test:` — adding or updating tests
95+
- `docs:` — documentation changes
96+
- `perf:` — performance improvements
97+
- `build:` — build system changes
11398

11499
**Pull requests** should include:
115100
- A clear description of what changed and why
@@ -120,22 +105,23 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
120105

121106
## Architecture Overview
122107

123-
The CLI (`@vegamo/deepcode-cli`) renders a terminal UI using [Ink](https://github.com/vadimdemedes/ink) (React for terminals). `SessionManager` drives the LLM interaction loop: it builds system prompts, sends user messages with optional skills/images, streams responses, executes tool calls via `ToolExecutor`, and compacts context when token thresholds are exceeded (512K for DeepSeek V4 models, 128K for others). OpenAI client connectivity is managed by `createOpenAIClient()` in `src/common/openai-client.ts`, which caches the client singleton and applies a 180-second keep-alive timeout.
108+
The CLI (`@vegamo/deepcode-cli`) renders a terminal UI using [Ink](https://github.com/vadimdemedes/ink) (React for terminals). `SessionManager` (in `@vegamo/deepcode-core`) drives the LLM interaction loop: it builds system prompts, sends user messages with optional skills/images, streams responses, executes tool calls via `ToolExecutor`, and compacts context when token thresholds are exceeded (512K for DeepSeek V4 models, 128K for others). OpenAI client connectivity is managed by `createOpenAIClient()` with a 180-second keep-alive timeout.
124109

125-
Seven built-in tools are available to the LLM: `bash`, `read`, `write`, `edit`, `AskUserQuestion`, `UpdatePlan`, and `WebSearch`. Tool definitions are registered in `src/tools/executor.ts` and described to the LLM via `src/prompt.ts` and `templates/tools/`. The `UpdatePlan` tool enables the LLM to display and update a structured task list in the terminal.
110+
Seven built-in tools are available to the LLM: `bash`, `read`, `write`, `edit`, `AskUserQuestion`, `UpdatePlan`, and `WebSearch`. Tool definitions are registered in `packages/core/src/tools/executor.ts` and described to the LLM via `packages/core/src/prompt.ts`.
126111

127-
A **permission system** (`src/common/permissions.ts`) controls tool execution scopes (read/write/delete/network/git-log, etc.) with configurable allow/deny/ask decisions. The `PermissionPrompt` view presents interactive prompts when a tool requires user approval.
112+
A **permission system** (`packages/core/src/common/permissions.ts`) controls tool execution scopes (read/write/delete/network/git-log, etc.) with configurable allow/deny/ask decisions.
128113

129-
A **file history system** (`src/common/file-history.ts`) provides undo/checkpoint support by creating lightweight Git branches per session. The `GitFileHistory` class manages blob storage and branch references via a `.deepcode-file-history.json` manifest.
114+
A **file history system** (`packages/core/src/common/file-history.ts`) provides undo/checkpoint support via lightweight Git branches.
130115

131-
**Slash commands**: `/model`, `/new`, `/init`, `/resume`, `/continue`, `/mcp`, `/exit`, plus dynamic `/skill-name` for each loaded skill.
116+
**Slash commands**: `/skills`, `/model`, `/new`, `/init`, `/resume`, `/continue`, `/undo`, `/mcp`, `/raw`, `/exit`, plus dynamic `/skill-name` for each loaded skill.
132117

133-
**Key UI features**: `@` file mentions in the prompt input (scans project files), `Ctrl+O` to view live process stdout in fullscreen, `Ctrl+V` to paste images, MCP server status display, undo selector, and permission prompts.
118+
**Key UI features**: `@` file mentions in the prompt input, `Ctrl+O` to view live process stdout, `Ctrl+V` to paste images, Shift+Enter for newlines, MCP server status display, undo selector, and permission prompts.
134119

135120
**CLI flags**: `-p <prompt>` / `--prompt` to auto-submit a prompt on launch, `-v` / `--version`, `-h` / `--help`.
136121

137122
## Agent-Specific Instructions
138123

139-
- **AGENTS.md loading**: The CLI loads agent instructions from `./AGENTS.md`, `./.deepcode/AGENTS.md`, or `~/.deepcode/AGENTS.md` (first found wins). Write project-specific guidance for the LLM in any of these.
124+
- **AGENTS.md loading**: The CLI loads agent instructions from `./AGENTS.md`, `./.deepcode/AGENTS.md`, or `~/.deepcode/AGENTS.md` (first found wins).
140125
- **Skills**: Place skill definitions in `~/.agents/skills/<name>/SKILL.md` (user-level) or `./.agents/skills/<name>/SKILL.md` (project-level). Legacy path `./.deepcode/skills/` is also supported. Each SKILL.md uses YAML frontmatter with `name` and `description` fields.
141-
- **Built-in skills**: `agent-drift-guard` (detects and corrects execution drift), `plan-and-execute` (structured task planning with progress tracking), and `karpathy-guidelines` (behavioral guidelines to reduce common LLM coding mistakes). All three are defined in `templates/skills/` and always injected into every session.
126+
- **Built-in skills**: Four bundled skills ship with the CLI — `plan` (task planning workflow), `deepcode-self-refer` (Deep Code CLI documentation), `skill-digester` (digest & install skills), `skill-writer` (create & debug skills). Additionally, `karpathy-guidelines` (behavioral guidelines to reduce LLM coding mistakes) is injected as a default skill template.
127+
- **Prompt file references**: Use `@path/to/file` syntax in prompts to load file contents through the read tool.

0 commit comments

Comments
 (0)