code-gate 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +105 -2
  2. package/README_ZH.md +103 -1
  3. package/dist/agent/index.d.ts +8 -0
  4. package/dist/agent/index.js +10 -0
  5. package/dist/agent/index.js.map +1 -0
  6. package/dist/agent/orchestrator.d.ts +13 -0
  7. package/dist/agent/orchestrator.js +109 -0
  8. package/dist/agent/orchestrator.js.map +1 -0
  9. package/dist/agent/prompts/system.d.ts +14 -0
  10. package/dist/agent/prompts/system.js +108 -0
  11. package/dist/agent/prompts/system.js.map +1 -0
  12. package/dist/agent/tools/index.d.ts +15 -0
  13. package/dist/agent/tools/index.js +57 -0
  14. package/dist/agent/tools/index.js.map +1 -0
  15. package/dist/agent/tools/list-directory.d.ts +13 -0
  16. package/dist/agent/tools/list-directory.js +162 -0
  17. package/dist/agent/tools/list-directory.js.map +1 -0
  18. package/dist/agent/tools/read-file.d.ts +13 -0
  19. package/dist/agent/tools/read-file.js +106 -0
  20. package/dist/agent/tools/read-file.js.map +1 -0
  21. package/dist/agent/tools/search-content.d.ts +13 -0
  22. package/dist/agent/tools/search-content.js +110 -0
  23. package/dist/agent/tools/search-content.js.map +1 -0
  24. package/dist/agent/tools/types.d.ts +71 -0
  25. package/dist/agent/tools/types.js +5 -0
  26. package/dist/agent/tools/types.js.map +1 -0
  27. package/dist/agent/types.d.ts +55 -0
  28. package/dist/agent/types.js +5 -0
  29. package/dist/agent/types.js.map +1 -0
  30. package/dist/cli/commands/hook.js +18 -3
  31. package/dist/cli/commands/hook.js.map +1 -1
  32. package/dist/cli/commands/review.js +18 -3
  33. package/dist/cli/commands/review.js.map +1 -1
  34. package/dist/config/defaults.js +5 -0
  35. package/dist/config/defaults.js.map +1 -1
  36. package/dist/config/types.d.ts +6 -0
  37. package/dist/core/review.d.ts +2 -1
  38. package/dist/core/review.js +128 -66
  39. package/dist/core/review.js.map +1 -1
  40. package/dist/llm/base.d.ts +20 -0
  41. package/dist/llm/base.js +15 -0
  42. package/dist/llm/base.js.map +1 -1
  43. package/dist/llm/index.d.ts +13 -1
  44. package/dist/llm/index.js +25 -0
  45. package/dist/llm/index.js.map +1 -1
  46. package/dist/llm/providers/deepseek.d.ts +20 -2
  47. package/dist/llm/providers/deepseek.js +89 -4
  48. package/dist/llm/providers/deepseek.js.map +1 -1
  49. package/dist/llm/providers/zhipu.d.ts +20 -2
  50. package/dist/llm/providers/zhipu.js +80 -4
  51. package/dist/llm/providers/zhipu.js.map +1 -1
  52. package/dist/locales/de.js +3 -0
  53. package/dist/locales/de.js.map +1 -1
  54. package/dist/locales/en.js +3 -0
  55. package/dist/locales/en.js.map +1 -1
  56. package/dist/locales/fr.js +3 -0
  57. package/dist/locales/fr.js.map +1 -1
  58. package/dist/locales/ja.js +3 -0
  59. package/dist/locales/ja.js.map +1 -1
  60. package/dist/locales/ko.js +3 -0
  61. package/dist/locales/ko.js.map +1 -1
  62. package/dist/locales/types.d.ts +3 -0
  63. package/dist/locales/zh-CN.js +3 -0
  64. package/dist/locales/zh-CN.js.map +1 -1
  65. package/dist/locales/zh-TW.js +3 -0
  66. package/dist/locales/zh-TW.js.map +1 -1
  67. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,9 @@
6
6
 
7
7
  # Code Gate
8
8
 
9
- ![Node Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen)
9
+ [![Node Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=for-the-badge)](https://nodejs.org/)
10
+ [![GitHub release](https://img.shields.io/github/v/release/Gil2015/code-gate?style=for-the-badge)](https://github.com/Gil2015/code-gate/releases/latest)
11
+ [![License](https://img.shields.io/github/license/Gil2015/code-gate?style=for-the-badge)](LICENSE)
10
12
 
11
13
  **Your Lightweight Local AI Code Review Assistant**
12
14
 
@@ -20,8 +22,9 @@ Supports zero-config execution via npx, npm/yarn/pnpm package integration, and a
20
22
 
21
23
  ## ✨ Features
22
24
 
23
- - **🔒 Privacy First**: Native support for Ollama local models.
25
+ - **🔒 Privacy First**: Native support for Ollama local models.
24
26
  - **☁️ Multi-Model Support**: Seamlessly integrates with DeepSeek, OpenAI, Anthropic, Aliyun Qwen, Doubao, and more.
27
+ - **🤖 Agent Mode**: AI can actively retrieve code context (file contents, search definitions, browse directories) for deeper and more accurate reviews. Supports DeepSeek and Zhipu.
25
28
  - **🌍 Multi-Language**: Built-in support for English, Chinese (Simplified & Traditional), Japanese, Korean, German, and French.
26
29
  - **⚡️ High Performance**: Intelligent concurrent processing for faster reviews across multiple files.
27
30
  - **🛠️ Highly Customizable**: Custom prompts, file filtering rules, and review strategies.
@@ -88,6 +91,12 @@ Provide feedback prioritized by:
88
91
  Provide specific examples on how to fix the issues.`,
89
92
  output: {
90
93
  dir: '.review-logs'
94
+ },
95
+ // Agent Mode (Optional) - Enables AI to actively retrieve code context
96
+ agent: {
97
+ enabled: false, // Set to true to enable Agent mode (supports DeepSeek and Zhipu)
98
+ maxIterations: 5, // Max iteration rounds
99
+ maxToolCalls: 10 // Max tool calls per review
91
100
  }
92
101
  }
93
102
  ```
@@ -200,6 +209,9 @@ git commit -m "feat: new feature"
200
209
  | `language` | `string` | `'en'` | UI & Prompt Language. Options: `'en'`, `'zh-CN'`, `'zh-TW'`, `'ja'`, `'ko'`, `'de'`, `'fr'` |
201
210
  | `prompt` | `string` | `...` | Universal system prompt sent to AI |
202
211
  | `output.dir` | `string` | `'.review-logs'` | Output directory for local reports and static assets |
212
+ | `agent.enabled` | `boolean` | `false` | Enable Agent mode for deeper context-aware reviews (DeepSeek & Zhipu only) |
213
+ | `agent.maxIterations` | `number` | `5` | Max iteration rounds for Agent to gather context |
214
+ | `agent.maxToolCalls` | `number` | `10` | Max tool calls allowed per review session |
203
215
 
204
216
  ### providerOptions Configuration
205
217
 
@@ -276,6 +288,97 @@ export DEEPSEEK_API_KEY=[your-deepseek-api-key]
276
288
 
277
289
  ---
278
290
 
291
+ ## 🤖 Agent Mode
292
+
293
+ Agent mode enables AI to actively retrieve code context during reviews, resulting in more accurate and comprehensive feedback. Instead of only seeing the diff, the AI can:
294
+
295
+ - **Read complete files** to understand the full context of changes
296
+ - **Search for definitions** to understand types, interfaces, and function implementations
297
+ - **Find references** to assess the impact of changes
298
+ - **Browse directory structure** to understand project organization
299
+
300
+ ### Enabling Agent Mode
301
+
302
+ Add the `agent` configuration to your `.codegate.js`:
303
+
304
+ ```javascript
305
+ export default {
306
+ provider: 'deepseek', // or 'zhipu'
307
+ providerOptions: {
308
+ deepseek: {
309
+ apiKeyEnv: 'DEEPSEEK_API_KEY',
310
+ model: 'deepseek-chat'
311
+ }
312
+ },
313
+ agent: {
314
+ enabled: true, // Enable Agent mode
315
+ maxIterations: 5, // Max rounds of context gathering
316
+ maxToolCalls: 10 // Max tool invocations
317
+ }
318
+ }
319
+ ```
320
+
321
+ ### Supported Providers
322
+
323
+ Currently, Agent mode is supported by:
324
+ - **DeepSeek** (`deepseek-chat` and other models with function calling)
325
+ - **Zhipu** (`glm-4` and other models with function calling)
326
+
327
+
328
+ ### Agent Mode Prompt Example
329
+
330
+ When using Agent mode, you can optimize your prompt to leverage the AI's ability to retrieve context. Here's a recommended prompt for Agent mode:
331
+
332
+ ```javascript
333
+ export default {
334
+ provider: 'deepseek',
335
+ agent: {
336
+ enabled: true,
337
+ maxIterations: 5,
338
+ maxToolCalls: 10
339
+ },
340
+ prompt: `You are a senior code reviewer with access to the full codebase context.
341
+
342
+ Project Info:
343
+ - [Fill in your project info: architecture, standards, business type, etc.]
344
+
345
+ Review Strategy:
346
+ 1. First analyze the diff to understand the scope and intent of changes
347
+ 2. When encountering unfamiliar types, interfaces, or functions, use tools to look up their definitions
348
+ 3. For significant logic changes, check how they affect other parts of the codebase
349
+ 4. Verify that changes follow existing patterns in the project
350
+
351
+ Key Review Points:
352
+ - Logic correctness and edge case handling
353
+ - Type safety and null checks
354
+ - Error handling completeness
355
+ - Performance implications
356
+ - Security considerations
357
+ - Consistency with existing codebase patterns
358
+
359
+ When using tools:
360
+ - Use read_file to view complete file context when needed
361
+ - Use search_content to find type definitions, function implementations, or usage patterns
362
+ - Use list_directory to understand module structure when reviewing architectural changes
363
+
364
+ Output Format:
365
+ ## Summary
366
+ Brief description of the changes
367
+
368
+ ## Issues Found
369
+ - 🔴 Critical: Must fix before merge
370
+ - 🟡 Warning: Should address
371
+ - 🔵 Suggestion: Consider improving
372
+
373
+ ## Overall Assessment
374
+ Final recommendation on whether to merge`
375
+ }
376
+ ```
377
+
378
+ > **Note**: Agent mode increases API token usage due to multi-turn conversations and tool results. Consider this when reviewing large changes.
379
+
380
+ ---
381
+
279
382
  ## ❓ FAQ
280
383
 
281
384
  **Q: Report shows diffs but no AI suggestions?**
package/README_ZH.md CHANGED
@@ -6,7 +6,9 @@
6
6
 
7
7
  # Code Gate
8
8
 
9
- ![Node Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen)
9
+ [![Node Version](https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=for-the-badge)](https://nodejs.org/)
10
+ [![GitHub release](https://img.shields.io/github/v/release/Gil2015/code-gate?style=for-the-badge)](https://github.com/Gil2015/code-gate/releases/latest)
11
+ [![License](https://img.shields.io/github/license/Gil2015/code-gate?style=for-the-badge)](LICENSE)
10
12
 
11
13
  **您的轻量级本地 AI 代码审查助手**
12
14
 
@@ -22,6 +24,7 @@ Code Gate 是一款无缝集成到 Git 工作流中的智能代码AI审查工具
22
24
 
23
25
  - **🔒 数据隐私优先**:原生支持 Ollama 本地模型。
24
26
  - **☁️ 多模型支持**:无缝对接 DeepSeek, OpenAI, Anthropic, 阿里云 Qwen, 豆包等主流 AI 服务。
27
+ - **🤖 Agent 模式**:AI 可主动获取代码上下文(读取文件、搜索定义、浏览目录),实现更深入准确的代码审查。支持 DeepSeek 和智谱。
25
28
  - **🌍 多语言界面**:内置中(简/繁)、英、日、韩、德、法等多语言支持。
26
29
  - **⚡️ 高效并发**:智能并发处理多文件审查,提升 Review 速度。
27
30
  - **🛠️ 高度可定制**:支持自定义 Prompt、文件过滤规则及审查策略。
@@ -87,6 +90,12 @@ export default {
87
90
  提供具体的示例说明如何修复问题。`,
88
91
  output: {
89
92
  dir: '.review-logs'
93
+ },
94
+ // Agent 模式(可选)- 启用后 AI 可主动获取代码上下文
95
+ agent: {
96
+ enabled: false, // 设为 true 启用 Agent 模式(仅支持 DeepSeek 和智谱)
97
+ maxIterations: 5, // 最大迭代轮数
98
+ maxToolCalls: 10 // 每次审查最大工具调用次数
90
99
  }
91
100
  }
92
101
  ```
@@ -207,6 +216,9 @@ git commit -m "feat: new feature"
207
216
  | `language` | `string` | `'en'` | 界面与 Prompt 语言。可选值:`'en'`, `'zh-CN'`, `'zh-TW'`, `'ja'`, `'ko'`, `'de'`, `'fr'` |
208
217
  | `prompt` | `string` | `...` | 发送给 AI 的通用系统提示词 |
209
218
  | `output.dir` | `string` | `'.review-logs'` | 本地生成报告和静态资源的输出目录 |
219
+ | `agent.enabled` | `boolean` | `false` | 启用 Agent 模式,获取更深入的上下文感知审查(仅支持 DeepSeek 和智谱) |
220
+ | `agent.maxIterations` | `number` | `5` | Agent 获取上下文的最大迭代轮数 |
221
+ | `agent.maxToolCalls` | `number` | `10` | 每次审查允许的最大工具调用次数 |
210
222
 
211
223
  ### providerOptions 配置
212
224
  每个 Provider 可配置以下字段,支持 `request` 选项控制请求超时与重试。
@@ -281,6 +293,96 @@ export DEEPSEEK_API_KEY=[your-deepseek-api-key]
281
293
 
282
294
  ---
283
295
 
296
+ ## 🤖 Agent 模式
297
+
298
+ Agent 模式允许 AI 在审查过程中主动获取代码上下文,从而提供更准确、更全面的反馈。与仅查看 diff 不同,AI 可以:
299
+
300
+ - **读取完整文件**:了解变更的完整上下文
301
+ - **搜索定义**:理解类型、接口和函数实现
302
+ - **查找引用**:评估变更的影响范围
303
+ - **浏览目录结构**:了解项目组织方式
304
+
305
+ ### 启用 Agent 模式
306
+
307
+ 在 `.codegate.js` 中添加 `agent` 配置:
308
+
309
+ ```javascript
310
+ export default {
311
+ provider: 'deepseek', // 或 'zhipu'
312
+ providerOptions: {
313
+ deepseek: {
314
+ apiKeyEnv: 'DEEPSEEK_API_KEY',
315
+ model: 'deepseek-chat'
316
+ }
317
+ },
318
+ agent: {
319
+ enabled: true, // 启用 Agent 模式
320
+ maxIterations: 5, // 最大上下文获取轮数
321
+ maxToolCalls: 10 // 最大工具调用次数
322
+ }
323
+ }
324
+ ```
325
+
326
+ ### 支持的 Provider
327
+
328
+ 目前 Agent 模式支持以下 Provider:
329
+ - **DeepSeek**(`deepseek-chat` 及其他支持函数调用的模型)
330
+ - **智谱**(`glm-4` 及其他支持函数调用的模型)
331
+
332
+ ### Agent 模式提示词示例
333
+
334
+ 使用 Agent 模式时,可以优化提示词以充分利用 AI 获取上下文的能力。以下是推荐的 Agent 模式提示词:
335
+
336
+ ```javascript
337
+ export default {
338
+ provider: 'deepseek',
339
+ agent: {
340
+ enabled: true,
341
+ maxIterations: 5,
342
+ maxToolCalls: 10
343
+ },
344
+ prompt: `你是一位高级代码审查员,可以访问完整的代码库上下文。
345
+
346
+ 项目信息:
347
+ - [填入你项目相关信息:架构、规范、业务类型等]
348
+
349
+ 审查策略:
350
+ 1. 首先分析 diff,理解变更的范围和意图
351
+ 2. 遇到不熟悉的类型、接口或函数时,使用工具查找其定义
352
+ 3. 对于重要的逻辑变更,检查它们对代码库其他部分的影响
353
+ 4. 验证变更是否遵循项目中现有的模式
354
+
355
+ 重点审查项:
356
+ - 逻辑正确性和边界情况处理
357
+ - 类型安全和空值检查
358
+ - 错误处理的完整性
359
+ - 性能影响
360
+ - 安全性考虑
361
+ - 与现有代码风格的一致性
362
+
363
+ 工具使用建议:
364
+ - 使用 read_file 查看需要的完整文件上下文
365
+ - 使用 search_content 查找类型定义、函数实现或使用模式
366
+ - 使用 list_directory 在审查架构变更时了解模块结构
367
+
368
+ 输出格式:
369
+ ## 变更概述
370
+ 简要描述本次变更
371
+
372
+ ## 发现的问题
373
+ - 🔴 严重问题:合并前必须修复
374
+ - 🟡 警告:建议处理
375
+ - 🔵 建议:可以考虑改进
376
+
377
+ ## 总体评价
378
+ 是否建议合并的最终建议`
379
+ }
380
+ ```
381
+
382
+ > **注意**:Agent 模式会因多轮对话和工具结果而增加 API Token 消耗。审查大型变更时请注意这一点。
383
+
384
+ ---
385
+
284
386
  ## ❓ 常见问题
285
387
 
286
388
  **Q: 页面显示 Diff 但没有 AI 建议?**
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Agent 模块入口
3
+ */
4
+ export { createOrchestrator } from './orchestrator.js';
5
+ export { toolDefinitions, executeTool, executeTools } from './tools/index.js';
6
+ export { buildAgentSystemPrompt, buildAgentUserPrompt } from './prompts/system.js';
7
+ export type { AgentMessage, AgentReviewInput, AgentReviewOptions, OrchestratorState, AgentProvider, LLMCallFunction, AgentOrchestrator } from './types.js';
8
+ export type { ToolDefinition, ToolCall, ToolResult, ReadFileParams, ReadFileResult, SearchContentParams, SearchContentResult, ListDirectoryParams, ListDirectoryResult } from './tools/types.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Agent 模块入口
3
+ */
4
+ // 导出编排器
5
+ export { createOrchestrator } from './orchestrator.js';
6
+ // 导出工具
7
+ export { toolDefinitions, executeTool, executeTools } from './tools/index.js';
8
+ // 导出 prompts
9
+ export { buildAgentSystemPrompt, buildAgentUserPrompt } from './prompts/system.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO;AACP,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE7E,aAAa;AACb,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Agent 编排器
3
+ * 实现 Agent 循环逻辑,协调 LLM 调用和工具执行
4
+ */
5
+ import type { Config } from '../config/types.js';
6
+ import type { LLMCallFunction, AgentOrchestrator } from './types.js';
7
+ /**
8
+ * 创建 Agent 编排器
9
+ * @param config 配置
10
+ * @param llmCall LLM 调用函数
11
+ */
12
+ export declare function createOrchestrator(_config: Config, llmCall: LLMCallFunction): AgentOrchestrator;
13
+ export type { AgentOrchestrator } from './types.js';
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Agent 编排器
3
+ * 实现 Agent 循环逻辑,协调 LLM 调用和工具执行
4
+ */
5
+ import { toolDefinitions, executeTools } from './tools/index.js';
6
+ import { buildAgentSystemPrompt, buildAgentUserPrompt } from './prompts/system.js';
7
+ /**
8
+ * 创建 Agent 编排器
9
+ * @param config 配置
10
+ * @param llmCall LLM 调用函数
11
+ */
12
+ export function createOrchestrator(_config, llmCall) {
13
+ /**
14
+ * 运行 Agent 循环
15
+ */
16
+ async function run(input, options) {
17
+ const { maxIterations, maxToolCalls, onToolCall, onIteration } = options;
18
+ // 初始化状态
19
+ const state = {
20
+ messages: [
21
+ {
22
+ role: 'system',
23
+ content: buildAgentSystemPrompt(input.prompt)
24
+ },
25
+ {
26
+ role: 'user',
27
+ content: buildAgentUserPrompt(input.diff, input.files)
28
+ }
29
+ ],
30
+ iteration: 0,
31
+ totalToolCalls: 0,
32
+ done: false
33
+ };
34
+ // Agent 循环
35
+ while (!state.done && state.iteration < maxIterations) {
36
+ state.iteration++;
37
+ // 调用 LLM
38
+ const response = await llmCall(state.messages, toolDefinitions);
39
+ // 没有工具调用,说明 LLM 已经完成审查,返回最终结果
40
+ if (!response.toolCalls || response.toolCalls.length === 0) {
41
+ state.done = true;
42
+ return response.content || '';
43
+ }
44
+ // 检查工具调用数限制
45
+ const callsThisIteration = response.toolCalls.length;
46
+ if (state.totalToolCalls + callsThisIteration > maxToolCalls) {
47
+ // 超过限制,强制请求最终结果
48
+ state.done = true;
49
+ return await requestFinalResult(state, response.content, llmCall);
50
+ }
51
+ // 触发回调
52
+ onIteration?.(state.iteration, callsThisIteration);
53
+ response.toolCalls.forEach(call => onToolCall?.(call));
54
+ // 执行工具调用
55
+ const results = await executeTools(response.toolCalls);
56
+ state.totalToolCalls += callsThisIteration;
57
+ // 添加 assistant 消息(包含工具调用)
58
+ const assistantMessage = {
59
+ role: 'assistant',
60
+ content: response.content,
61
+ tool_calls: response.toolCalls
62
+ };
63
+ // DeepSeek Reasoner 模型需要保留 reasoning_content
64
+ if (response.reasoning_content) {
65
+ assistantMessage.reasoning_content = response.reasoning_content;
66
+ }
67
+ state.messages.push(assistantMessage);
68
+ // 添加工具结果消息
69
+ for (const result of results) {
70
+ state.messages.push({
71
+ role: 'tool',
72
+ tool_call_id: result.id,
73
+ name: result.name,
74
+ content: result.error
75
+ ? JSON.stringify({ error: result.error })
76
+ : JSON.stringify(result.result)
77
+ });
78
+ }
79
+ }
80
+ // 达到最大迭代次数,强制请求最终结果
81
+ if (!state.done) {
82
+ return await requestFinalResult(state, null, llmCall);
83
+ }
84
+ return '';
85
+ }
86
+ return { run };
87
+ }
88
+ /**
89
+ * 请求 LLM 输出最终结果
90
+ */
91
+ async function requestFinalResult(state, lastContent, llmCall) {
92
+ // 如果上一次响应有内容,先添加到消息历史
93
+ if (lastContent) {
94
+ state.messages.push({
95
+ role: 'assistant',
96
+ content: lastContent
97
+ });
98
+ }
99
+ // 添加请求最终结果的消息
100
+ state.messages.push({
101
+ role: 'user',
102
+ content: '已达到工具调用次数上限或迭代次数上限。请根据已获取的信息,输出最终的代码审查报告。'
103
+ });
104
+ // 调用 LLM,不提供工具(强制输出文本)
105
+ const emptyTools = [];
106
+ const finalResponse = await llmCall(state.messages, emptyTools);
107
+ return finalResponse.content || '';
108
+ }
109
+ //# sourceMappingURL=orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/agent/orchestrator.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KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;wBACzC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;iBAClC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,oBAAoB;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,OAAO,MAAM,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QACvD,CAAC;QAED,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,CAAA;AAChB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAC/B,KAAwB,EACxB,WAA0B,EAC1B,OAAwB;IAExB,sBAAsB;IACtB,IAAI,WAAW,EAAE,CAAC;QAChB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,WAAW;SACrB,CAAC,CAAA;IACJ,CAAC;IAED,cAAc;IACd,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QAClB,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,2CAA2C;KACrD,CAAC,CAAA;IAEF,uBAAuB;IACvB,MAAM,UAAU,GAAqB,EAAE,CAAA;IACvC,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;IAE/D,OAAO,aAAa,CAAC,OAAO,IAAI,EAAE,CAAA;AACpC,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Agent System Prompt 构建
3
+ */
4
+ /**
5
+ * 构建 Agent 专用的 System Prompt
6
+ * @param basePrompt 基础审查 prompt
7
+ */
8
+ export declare function buildAgentSystemPrompt(basePrompt: string): string;
9
+ /**
10
+ * 构建用户消息
11
+ * @param diff diff 内容
12
+ * @param files 变更的文件列表
13
+ */
14
+ export declare function buildAgentUserPrompt(diff: string, files: string[]): string;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Agent System Prompt 构建
3
+ */
4
+ /**
5
+ * 构建 Agent 专用的 System Prompt
6
+ * @param basePrompt 基础审查 prompt
7
+ */
8
+ export function buildAgentSystemPrompt(basePrompt) {
9
+ return `${basePrompt}
10
+
11
+ ## 工具使用指南
12
+
13
+ 你可以使用以下工具来获取代码上下文,以便更准确地进行代码审查:
14
+
15
+ ### read_file
16
+ 读取文件完整内容。适用场景:
17
+ - 查看被修改文件的完整代码,了解上下文
18
+ - 查看类型定义文件(如 .d.ts, types.ts)
19
+ - 查看相关的配置文件
20
+ - 查看被调用的函数/方法的实现
21
+
22
+ 参数:
23
+ - path: 文件路径(相对于项目根目录)
24
+ - startLine: 起始行号(可选,用于分页读取大文件)
25
+ - maxLines: 最大读取行数(可选,默认 200)
26
+
27
+ ### search_content
28
+ 在项目中搜索内容,支持正则表达式。适用场景:
29
+ - 查找某个函数、类、接口的定义位置
30
+ - 查找某个方法或变量的使用位置
31
+ - 搜索特定的代码模式或关键字
32
+ - 查找相关的测试文件
33
+
34
+ 参数:
35
+ - pattern: 搜索模式(支持正则表达式)
36
+ - path: 搜索范围(可选,默认整个项目)
37
+ - offset/limit: 分页参数
38
+
39
+ ### list_directory
40
+ 列出目录结构。适用场景:
41
+ - 了解项目的模块划分和目录结构
42
+ - 查找相关文件的位置
43
+ - 了解某个功能模块包含哪些文件
44
+
45
+ 参数:
46
+ - path: 目录路径
47
+ - depth: 递归深度(可选,默认 1)
48
+ - offset/limit: 分页参数
49
+
50
+ ## 审查流程建议
51
+
52
+ 1. **初步分析**:首先阅读 diff,识别变更的类型、范围和关键点
53
+ 2. **获取上下文**:如果需要更多信息来理解代码,使用工具获取:
54
+ - 不确定某个类型的定义?使用 search_content 查找,然后 read_file 查看
55
+ - 不了解被调用函数的行为?使用 read_file 查看其实现
56
+ - 不确定变更影响范围?使用 search_content 查找引用位置
57
+ 3. **深入审查**:基于完整信息进行审查,关注:
58
+ - 代码逻辑是否正确
59
+ - 是否有潜在的 bug 或边界情况
60
+ - 代码风格是否符合项目规范
61
+ - 是否有性能或安全问题
62
+ 4. **输出报告**:完成审查后,输出结构化的审查报告
63
+
64
+ ## 输出格式要求
65
+
66
+ 最终的审查报告应包含以下部分(根据实际情况选择性输出):
67
+
68
+ ### 变更概述
69
+ 简要描述本次变更的目的和范围
70
+
71
+ ### 发现的问题
72
+ 列出发现的问题,按严重程度分类:
73
+ - 🔴 严重问题:必须修复的 bug 或安全漏洞
74
+ - 🟡 建议改进:可以优化的地方
75
+ - 🔵 代码风格:格式或命名建议
76
+
77
+ ### 代码亮点
78
+ 如果代码有做得好的地方,也可以指出
79
+
80
+ ### 总体评价
81
+ 给出总体评价和是否建议合并
82
+
83
+ ## 注意事项
84
+
85
+ - 只在确实需要更多上下文时才使用工具,避免不必要的调用
86
+ - 如果工具返回 hasMore: true,可以使用 offset 参数获取更多结果
87
+ - 审查时要结合项目的实际情况,避免教条主义
88
+ - 如果不确定某个写法是否有问题,应该先查看项目中的其他代码作为参考`;
89
+ }
90
+ /**
91
+ * 构建用户消息
92
+ * @param diff diff 内容
93
+ * @param files 变更的文件列表
94
+ */
95
+ export function buildAgentUserPrompt(diff, files) {
96
+ return `## 变更的文件
97
+ ${files.map(f => `- ${f}`).join('\n')}
98
+
99
+ ## Diff 内容
100
+ \`\`\`diff
101
+ ${diff}
102
+ \`\`\`
103
+
104
+ 请审查以上代码变更。如果需要了解更多上下文(如完整文件内容、类型定义、引用位置等),请使用提供的工具获取信息。
105
+
106
+ 审查完成后,请输出最终的代码审查报告。`;
107
+ }
108
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/agent/prompts/system.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IACvD,OAAO,GAAG,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCA+Ea,CAAA;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,KAAe;IAChE,OAAO;EACP,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;EAInC,IAAI;;;;;oBAKc,CAAA;AACpB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 工具注册入口
3
+ * 统一管理所有 Agent 工具的定义和执行
4
+ */
5
+ import type { ToolDefinition, ToolCall, ToolResult } from './types.js';
6
+ export declare const toolDefinitions: ToolDefinition[];
7
+ /**
8
+ * 执行单个工具调用
9
+ */
10
+ export declare function executeTool(call: ToolCall): Promise<ToolResult>;
11
+ /**
12
+ * 并行执行多个工具调用
13
+ */
14
+ export declare function executeTools(calls: ToolCall[]): Promise<ToolResult[]>;
15
+ export type { ToolDefinition, ToolCall, ToolResult } from './types.js';
@@ -0,0 +1,57 @@
1
+ /**
2
+ * 工具注册入口
3
+ * 统一管理所有 Agent 工具的定义和执行
4
+ */
5
+ import { readFileTool, executeReadFile } from './read-file.js';
6
+ import { searchContentTool, executeSearchContent } from './search-content.js';
7
+ import { listDirectoryTool, executeListDirectory } from './list-directory.js';
8
+ // ============ 工具定义列表 ============
9
+ export const toolDefinitions = [
10
+ readFileTool,
11
+ searchContentTool,
12
+ listDirectoryTool
13
+ ];
14
+ const executors = {
15
+ read_file: executeReadFile,
16
+ search_content: executeSearchContent,
17
+ list_directory: executeListDirectory
18
+ };
19
+ // ============ 工具执行函数 ============
20
+ /**
21
+ * 执行单个工具调用
22
+ */
23
+ export async function executeTool(call) {
24
+ const executor = executors[call.name];
25
+ if (!executor) {
26
+ return {
27
+ id: call.id,
28
+ name: call.name,
29
+ result: null,
30
+ error: `Unknown tool: ${call.name}`
31
+ };
32
+ }
33
+ try {
34
+ const result = await executor(call.arguments);
35
+ return {
36
+ id: call.id,
37
+ name: call.name,
38
+ result
39
+ };
40
+ }
41
+ catch (e) {
42
+ const error = e instanceof Error ? e.message : String(e);
43
+ return {
44
+ id: call.id,
45
+ name: call.name,
46
+ result: null,
47
+ error
48
+ };
49
+ }
50
+ }
51
+ /**
52
+ * 并行执行多个工具调用
53
+ */
54
+ export async function executeTools(calls) {
55
+ return Promise.all(calls.map(executeTool));
56
+ }
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE7E,mCAAmC;AAEnC,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;CAClB,CAAA;AAOD,MAAM,SAAS,GAAmC;IAChD,SAAS,EAAE,eAAe;IAC1B,cAAc,EAAE,oBAAoB;IACpC,cAAc,EAAE,oBAAoB;CACrC,CAAA;AAED,mCAAmC;AAEnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAc;IAC9C,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAErC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,iBAAiB,IAAI,CAAC,IAAI,EAAE;SACpC,CAAA;IACH,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAC7C,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM;SACP,CAAA;IACH,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACxD,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI;YACZ,KAAK;SACN,CAAA;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAiB;IAClD,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * list_directory 工具实现
3
+ * 列出目录内容,支持递归和分页
4
+ */
5
+ import type { ToolDefinition, ListDirectoryParams, ListDirectoryResult } from './types.js';
6
+ /**
7
+ * 工具定义
8
+ */
9
+ export declare const listDirectoryTool: ToolDefinition;
10
+ /**
11
+ * 执行 list_directory 工具
12
+ */
13
+ export declare function executeListDirectory(params: ListDirectoryParams): Promise<ListDirectoryResult>;