code-gate 1.3.0 → 1.3.1
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.
- package/README.md +39 -1
- package/README_ZH.md +38 -1
- package/dist/config/index.js +34 -25
- package/dist/config/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,26 @@ Supports zero-config execution via npx, npm/yarn/pnpm package integration, and a
|
|
|
20
20
|
<img src="assets/review.png" alt="Code Gate example" width="100%" />
|
|
21
21
|
</div>
|
|
22
22
|
|
|
23
|
+
## Table of Contents
|
|
24
|
+
|
|
25
|
+
- [✨ Features](#-features)
|
|
26
|
+
- [🚀 Quick Start](#-quick-start)
|
|
27
|
+
- [Add Configuration File](#add-configuration-file)
|
|
28
|
+
- [Method 1: Zero-Install with npx](#method-1-zero-install-with-npx)
|
|
29
|
+
- [Method 2: NPM Integration](#method-2-npm-integration)
|
|
30
|
+
- [Method 3: Automated Git Hook Review](#method-3-automated-git-hook-review)
|
|
31
|
+
- [📖 Configuration Details](#-configuration-details)
|
|
32
|
+
- [providerOptions Configuration](#provideroptions-configuration)
|
|
33
|
+
- [API Key Configuration](#api-key-configuration)
|
|
34
|
+
- [🤖 Agent Mode](#-agent-mode)
|
|
35
|
+
- [Enabling Agent Mode](#enabling-agent-mode)
|
|
36
|
+
- [Supported Providers](#supported-providers)
|
|
37
|
+
- [Agent Mode Prompt Example](#agent-mode-prompt-example)
|
|
38
|
+
- [Available Tools](#available-tools)
|
|
39
|
+
- [How It Works](#how-it-works)
|
|
40
|
+
- [❓ FAQ](#-faq)
|
|
41
|
+
- [📄 License](#-license)
|
|
42
|
+
|
|
23
43
|
## ✨ Features
|
|
24
44
|
|
|
25
45
|
- **🔒 Privacy First**: Native support for Ollama local models.
|
|
@@ -337,6 +357,7 @@ export default {
|
|
|
337
357
|
maxIterations: 5,
|
|
338
358
|
maxToolCalls: 10
|
|
339
359
|
},
|
|
360
|
+
..., // other options
|
|
340
361
|
prompt: `You are a senior code reviewer with access to the full codebase context.
|
|
341
362
|
|
|
342
363
|
Project Info:
|
|
@@ -375,7 +396,24 @@ Final recommendation on whether to merge`
|
|
|
375
396
|
}
|
|
376
397
|
```
|
|
377
398
|
|
|
378
|
-
> **Note**: Agent mode increases API token usage due to multi-turn conversations and tool results. Consider this when reviewing large changes.
|
|
399
|
+
> **Note**: Agent mode increases API token usage due to multi-turn conversations and tool results. Consider this when reviewing large changes. To save tokens, the diff content is also merged and displayed.
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
### Available Tools
|
|
403
|
+
|
|
404
|
+
| Tool | Description | Use Case |
|
|
405
|
+
|------|-------------|----------|
|
|
406
|
+
| `read_file` | Read file contents with pagination | View complete source files, type definitions |
|
|
407
|
+
| `search_content` | Search code with regex patterns | Find function definitions, method calls |
|
|
408
|
+
| `list_directory` | List directory structure | Understand project organization |
|
|
409
|
+
|
|
410
|
+
### How It Works
|
|
411
|
+
|
|
412
|
+
1. AI receives the diff and list of changed files
|
|
413
|
+
2. AI analyzes the changes and identifies areas needing more context
|
|
414
|
+
3. AI uses tools to retrieve relevant code (e.g., type definitions, related functions)
|
|
415
|
+
4. AI generates a comprehensive review based on full context
|
|
416
|
+
5. Process repeats until AI has enough information or limits are reached
|
|
379
417
|
|
|
380
418
|
---
|
|
381
419
|
|
package/README_ZH.md
CHANGED
|
@@ -20,6 +20,26 @@ Code Gate 是一款无缝集成到 Git 工作流中的智能代码AI审查工具
|
|
|
20
20
|
<img src="assets/review_cn.png" alt="Code Gate example" width="100%" />
|
|
21
21
|
</div>
|
|
22
22
|
|
|
23
|
+
## 目录
|
|
24
|
+
|
|
25
|
+
- [✨ 核心特性](#-核心特性)
|
|
26
|
+
- [🚀 快速开始](#-快速开始)
|
|
27
|
+
- [添加配置文件](#添加配置文件)
|
|
28
|
+
- [方式一:npx 零安装使用](#方式一npx-零安装使用)
|
|
29
|
+
- [方式二:npm 包管理集成](#方式二npm-包管理集成)
|
|
30
|
+
- [方式三:Git Hook 自动化审查](#方式三git-hook-自动化审查)
|
|
31
|
+
- [📖 配置详解](#-配置详解)
|
|
32
|
+
- [providerOptions 配置](#provideroptions-配置)
|
|
33
|
+
- [API Key 配置方案](#api-key-配置方案)
|
|
34
|
+
- [🤖 Agent 模式](#-agent-模式)
|
|
35
|
+
- [启用 Agent 模式](#启用-agent-模式)
|
|
36
|
+
- [支持的 Provider](#支持的-provider)
|
|
37
|
+
- [Agent 模式提示词示例](#agent-模式提示词示例)
|
|
38
|
+
- [agent可用工具](#agent可用工具)
|
|
39
|
+
- [工作原理](#工作原理)
|
|
40
|
+
- [❓ 常见问题](#-常见问题)
|
|
41
|
+
- [📄 License](#-license)
|
|
42
|
+
|
|
23
43
|
## ✨ 核心特性
|
|
24
44
|
|
|
25
45
|
- **🔒 数据隐私优先**:原生支持 Ollama 本地模型。
|
|
@@ -341,6 +361,7 @@ export default {
|
|
|
341
361
|
maxIterations: 5,
|
|
342
362
|
maxToolCalls: 10
|
|
343
363
|
},
|
|
364
|
+
..., // 其它配置
|
|
344
365
|
prompt: `你是一位高级代码审查员,可以访问完整的代码库上下文。
|
|
345
366
|
|
|
346
367
|
项目信息:
|
|
@@ -379,7 +400,23 @@ export default {
|
|
|
379
400
|
}
|
|
380
401
|
```
|
|
381
402
|
|
|
382
|
-
> **注意**:Agent 模式会因多轮对话和工具结果而增加 API Token
|
|
403
|
+
> **注意**:Agent 模式会因多轮对话和工具结果而增加 API Token 消耗。审查大型变更时请注意这一点。为了节省token的同时,diff内容也会合并展示
|
|
404
|
+
|
|
405
|
+
### agent可用工具
|
|
406
|
+
|
|
407
|
+
| 工具 | 描述 | 使用场景 |
|
|
408
|
+
|------|------|----------|
|
|
409
|
+
| `read_file` | 分页读取文件内容 | 查看完整源代码、类型定义 |
|
|
410
|
+
| `search_content` | 使用正则表达式搜索代码 | 查找函数定义、方法调用 |
|
|
411
|
+
| `list_directory` | 列出目录结构 | 了解项目组织方式 |
|
|
412
|
+
|
|
413
|
+
### 工作原理
|
|
414
|
+
|
|
415
|
+
1. AI 接收 diff 和变更文件列表
|
|
416
|
+
2. AI 分析变更并识别需要更多上下文的区域
|
|
417
|
+
3. AI 使用工具获取相关代码(如类型定义、关联函数)
|
|
418
|
+
4. AI 基于完整上下文生成全面的审查报告
|
|
419
|
+
5. 重复上述过程直到 AI 获取足够信息或达到限制
|
|
383
420
|
|
|
384
421
|
---
|
|
385
422
|
|
package/dist/config/index.js
CHANGED
|
@@ -6,31 +6,40 @@ import { defaultConfig } from './defaults.js';
|
|
|
6
6
|
export * from './types.js';
|
|
7
7
|
export * from './defaults.js';
|
|
8
8
|
function findConfigFile(cwd) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
let currentDir = cwd;
|
|
10
|
+
while (true) {
|
|
11
|
+
const candidates = [
|
|
12
|
+
// Recommended formats
|
|
13
|
+
path.join(currentDir, '.codegate.ts'),
|
|
14
|
+
path.join(currentDir, '.codegate.js'),
|
|
15
|
+
path.join(currentDir, '.codegate.mjs'),
|
|
16
|
+
path.join(currentDir, '.codegate.cjs'),
|
|
17
|
+
path.join(currentDir, '.codegate.json'),
|
|
18
|
+
path.join(currentDir, '.codegate.yaml'),
|
|
19
|
+
path.join(currentDir, '.codegate.yml'),
|
|
20
|
+
// Legacy formats (kept for backward compatibility)
|
|
21
|
+
path.join(currentDir, 'code-gate.config.ts'),
|
|
22
|
+
path.join(currentDir, 'code-gate.config.js'),
|
|
23
|
+
path.join(currentDir, 'code-gate.config.mjs'),
|
|
24
|
+
path.join(currentDir, 'code-gate.config.cjs'),
|
|
25
|
+
path.join(currentDir, 'code-gate.config.json'),
|
|
26
|
+
path.join(currentDir, 'code-gate.config.yaml'),
|
|
27
|
+
path.join(currentDir, 'code-gate.config.yml'),
|
|
28
|
+
path.join(currentDir, '.code-gaterc'),
|
|
29
|
+
path.join(currentDir, '.code-gaterc.json'),
|
|
30
|
+
path.join(currentDir, '.code-gaterc.yaml'),
|
|
31
|
+
path.join(currentDir, '.code-gaterc.yml')
|
|
32
|
+
];
|
|
33
|
+
for (const p of candidates) {
|
|
34
|
+
if (fs.existsSync(p))
|
|
35
|
+
return p;
|
|
36
|
+
}
|
|
37
|
+
const parentDir = path.dirname(currentDir);
|
|
38
|
+
if (parentDir === currentDir) {
|
|
39
|
+
// Reached root
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
currentDir = parentDir;
|
|
34
43
|
}
|
|
35
44
|
return undefined;
|
|
36
45
|
}
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7C,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAE7B,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,UAAU,GAAG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AA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