Skip to content

Commit d9a3e15

Browse files
committed
Merge branch 'main' into feature/mcp-refactor
2 parents b858c87 + 85ab2c5 commit d9a3e15

27 files changed

Lines changed: 539 additions & 115 deletions

.deepcode/AGENTS.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ src/
1313
│ ├── App.tsx # Root Ink component — state, routing, session orchestration
1414
│ ├── PromptInput.tsx # Multi-line input with slash commands, image paste, skills
1515
│ ├── MessageView.tsx # Renders assistant/tool messages with markdown
16+
│ ├── DropdownMenu.tsx # Reusable dropdown for skill/model selection
1617
│ ├── SessionList.tsx # Session picker for /resume
18+
│ ├── promptUndoRedo.ts # Ctrl+- undo / Ctrl+Shift+- redo for prompt input
1719
│ └── ...
1820
├── mcp/
1921
│ ├── mcp-client.ts # MCP client — JSON-RPC communication with MCP servers
@@ -22,7 +24,7 @@ src/
2224
│ ├── file-utils.ts # File read/write with encoding and diff preview
2325
│ ├── shell-utils.ts # Shell path resolution (Git Bash, zsh, bash)
2426
│ ├── state.ts # In-memory file state and snippet tracking
25-
│ └── runtime.ts # Tool validation runtime helpers (executeValidatedTool, semanticBoolean)
27+
│ └── runtime.ts # Tool validation runtime helpers
2628
├── tools/
2729
│ ├── executor.ts # ToolExecutor — dispatches tool calls to handlers
2830
│ ├── bash-handler.ts # Executes shell commands
@@ -32,9 +34,10 @@ src/
3234
│ ├── web-search-handler.ts # Web search tool
3335
│ └── ask-user-question-handler.ts # Interactive user prompts
3436
├── tests/ # Test suite — one *.test.ts per module
35-
docs/
37+
templates/
3638
├── tools/ # Tool descriptions fed to the LLM
3739
├── prompts/ # EJS templates (e.g., init_command.md.ejs)
40+
docs/ # User-facing documentation
3841
dist/ # Bundled CLI output (gitignored)
3942
```
4043

@@ -87,7 +90,8 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
8790
- `fix:` — bug fix (e.g., `fix(ui): redraw cleanly after terminal resize`)
8891
- `chore:` — tooling, deps, hooks (e.g., `chore: add husky + lint-staged`)
8992
- `refactor:` — code restructuring (e.g., `refactor(ui): optimize App hooks`)
90-
- `style:` — formatting-only changes
93+
- `style:` — formatting-only changes (e.g., `style: adjust the tree structure symbols`)
94+
- `docs:` — documentation (e.g., `docs: add MCP configuration guide`)
9195

9296
**Pull requests** should include:
9397
- A clear description of what changed and why
@@ -100,7 +104,7 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
100104

101105
The 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).
102106

103-
Six tools are available to the LLM: `bash`, `read`, `write`, `edit`, `AskUserQuestion`, and `WebSearch`. Tool definitions are registered in `src/tools/executor.ts` and described to the LLM via `src/prompt.ts` and `docs/tools/`.
107+
Six tools are available to the LLM: `bash`, `read`, `write`, `edit`, `AskUserQuestion`, and `WebSearch`. Tool definitions are registered in `src/tools/executor.ts` and described to the LLM via `src/prompt.ts` and `templates/tools/`.
104108

105109
## Agent-Specific Instructions
106110

.lintstagedrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"*.{ts,tsx,js,mjs,cjs,ejs,jsx}": [
2+
"*.{ts,tsx,js,mjs,cjs,jsx}": [
33
"eslint --fix",
44
"prettier --write"
55
],

AGENTS.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Repository Guidelines
2+
3+
## Project Structure & Module Organization
4+
5+
- `src/` contains the TypeScript CLI implementation, with tool handlers in `src/tools/`, MCP integration in `src/mcp/`, UI components in `src/ui/`, and shared helpers in `src/common/`.
6+
- `src/tests/` contains Node test files named `*.test.ts`.
7+
- `templates/` contains runtime prompt assets: `templates/prompts/` for EJS prompt templates and `templates/tools/` for tool instruction Markdown loaded into the system prompt.
8+
- `docs/` is reserved for user-facing documentation such as configuration and MCP guides.
9+
- `resources/` stores static images used by the documentation or UI.
10+
11+
## Build, Test, and Development Commands
12+
13+
- `npm test` runs all test files with `tsx --test`.
14+
- `npm run test:single -- src/tests/<name>.test.ts` runs one test file.
15+
- `npm run typecheck` verifies TypeScript types without emitting files.
16+
- `npm run lint` checks ESLint rules for `src/`.
17+
- `npm run build` runs checks, bundles `src/cli.tsx` to `dist/cli.js`, and marks the bundle executable.
18+
19+
## Coding Style & Naming Conventions
20+
21+
- Use TypeScript ES modules and keep imports explicit.
22+
- Prefer small, focused functions; keep filesystem path construction centralized when a path is reused.
23+
- Use two-space indentation and Prettier-compatible formatting.
24+
- Respond in standard technical English. Avoid nonstandard phrasing and corporate jargon.
25+
26+
## Testing Guidelines
27+
28+
- Add or update tests in `src/tests/` when changing command behavior, prompt rendering, session flow, tools, or settings.
29+
- Prefer Node's built-in `node:test` and `node:assert/strict` APIs, matching the existing tests.
30+
- Keep tests deterministic by using temporary directories and mocked network calls where needed.
31+
32+
## Commit & Pull Request Guidelines
33+
34+
- Keep commits focused on a single change and use concise, imperative commit messages.
35+
- In pull requests, describe the behavior change, list verification commands, and note any packaging or template path changes.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vegamo/deepcode-cli",
3-
"version": "0.1.19",
3+
"version": "0.1.20",
44
"description": "Deep Code CLI - Vibe coding for the deepseek-v4 model in your terminal",
55
"license": "MIT",
66
"type": "module",
@@ -15,8 +15,8 @@
1515
"main": "./dist/cli.js",
1616
"files": [
1717
"dist/cli.js",
18-
"docs/tools/**",
19-
"docs/prompts/**",
18+
"templates/tools/**",
19+
"templates/prompts/**",
2020
"README.md",
2121
"LICENSE"
2222
],

src/common/model-capabilities.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const DEEPSEEK_V4_MODELS = new Set(["deepseek-v4-flash", "deepseek-v4-pro"]);
2+
3+
export const NON_MULTIMODAL_MODELS = new Set([
4+
"deepseek-v4-pro",
5+
"deepseek-v4-flash",
6+
"deepseek-chat",
7+
"deepseek-reasoner",
8+
]);
9+
10+
export function defaultsToThinkingMode(model: string): boolean {
11+
return DEEPSEEK_V4_MODELS.has(model);
12+
}
13+
14+
export function supportsMultimodal(model: string): boolean {
15+
return !NON_MULTIMODAL_MODELS.has(model.trim());
16+
}

src/model-capabilities.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/prompt.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import * as fs from "fs";
33
import * as os from "os";
44
import * as path from "path";
55
import { fileURLToPath } from "url";
6+
import ejs from "ejs";
67
import type { SessionMessage } from "./session";
78
import { findGitBashPath, resolveShellPath } from "./common/shell-utils";
9+
import { supportsMultimodal } from "./common/model-capabilities";
810

911
export const AGENT_DRIFT_GUARD_SKILL = `
1012
---
@@ -248,23 +250,28 @@ const SYSTEM_PROMPT_BASE = `你是名叫Deep Code的交互式CLI工具,帮助
248250
重要:严禁编造任何非编程相关的 URL。对于编程链接,仅限使用:1) 用户提供的上下文;2) 你确定的官方文档主域名。在输出前,必须自查该链接是否存在于你的上下文记忆中;若不存在,请明确说明无法提供。`;
249251

250252
type PromptToolOptions = {
253+
model?: string;
251254
webSearchEnabled?: boolean;
252255
};
253256

254-
function readToolDocs(extensionRoot: string, _options: PromptToolOptions = {}): string {
255-
const toolsDir = path.join(extensionRoot, "docs", "tools");
257+
function readToolDocs(extensionRoot: string, options: PromptToolOptions = {}): string {
258+
const toolsDir = path.join(extensionRoot, "templates", "tools");
256259
if (!fs.existsSync(toolsDir)) {
257260
return "";
258261
}
259262

260263
const entries = fs.readdirSync(toolsDir);
261264
const docs = entries
262-
.filter((entry) => entry.endsWith(".md"))
265+
.filter((entry) => entry.endsWith(".md") || entry.endsWith(".md.ejs"))
263266
.sort()
264267
.map((entry) => {
265268
const fullPath = path.join(toolsDir, entry);
266269
try {
267-
return fs.readFileSync(fullPath, "utf8").trim();
270+
const template = fs.readFileSync(fullPath, "utf8");
271+
const content = entry.endsWith(".ejs")
272+
? ejs.render(template, { supportsMultimodal: supportsMultimodal(options.model ?? "") })
273+
: template;
274+
return content.trim();
268275
} catch {
269276
return "";
270277
}
@@ -274,10 +281,14 @@ function readToolDocs(extensionRoot: string, _options: PromptToolOptions = {}):
274281
return docs.join("\n\n");
275282
}
276283

284+
function getCurrentDatePrompt(date = new Date()): string {
285+
return `今天是${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}日。随着对话的进行,时间在流逝。`;
286+
}
287+
277288
export function getSystemPrompt(projectRoot: string, options: PromptToolOptions = {}): string {
278289
const toolDocs = readToolDocs(getExtensionRoot(), options);
279290
const basePrompt = toolDocs ? `${SYSTEM_PROMPT_BASE}\n\n# Available Tools\n\n${toolDocs}` : SYSTEM_PROMPT_BASE;
280-
return `${basePrompt}\n\n${getRuntimeContext(projectRoot)}`;
291+
return `${basePrompt}\n\n${getCurrentDatePrompt()}\n\n${getRuntimeContext(projectRoot)}`;
281292
}
282293

283294
export function getCompactPrompt(sessionMessages: SessionMessage[]): string {
@@ -310,7 +321,6 @@ function getRuntimeContext(projectRoot: string): string {
310321
...shellModeOpts,
311322
...runtimeVersions,
312323
"command installed": {
313-
"ast-grep": checkToolInstalled("ast-grep"),
314324
ripgrep: checkToolInstalled("rg"),
315325
jq: checkToolInstalled("jq"),
316326
},

0 commit comments

Comments
 (0)