yuangs 3.15.0 → 3.17.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.
- package/dist/agent/AgentRuntime.js +15 -1
- package/dist/agent/AgentRuntime.js.map +1 -1
- package/dist/agent/dynamicPrompt.d.ts +34 -0
- package/dist/agent/dynamicPrompt.js +233 -0
- package/dist/agent/dynamicPrompt.js.map +1 -0
- package/dist/agent/llmAdapter.d.ts +1 -1
- package/dist/agent/llmAdapter.js +53 -19
- package/dist/agent/llmAdapter.js.map +1 -1
- package/dist/agent/prompt.js +37 -1
- package/dist/agent/prompt.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ const governance_1 = require("./governance");
|
|
|
17
17
|
const executor_1 = require("./executor");
|
|
18
18
|
const contextManager_1 = require("./contextManager");
|
|
19
19
|
const core_1 = require("./governance/core");
|
|
20
|
+
const dynamicPrompt_1 = require("./dynamicPrompt");
|
|
20
21
|
class AgentRuntime {
|
|
21
22
|
context;
|
|
22
23
|
executionId;
|
|
@@ -27,6 +28,9 @@ class AgentRuntime {
|
|
|
27
28
|
async run(userInput, mode = "chat", onChunk, model) {
|
|
28
29
|
let turnCount = 0;
|
|
29
30
|
const maxTurns = 10;
|
|
31
|
+
let lastError;
|
|
32
|
+
// 构建初始动态上下文
|
|
33
|
+
const initialDynamicContext = await (0, dynamicPrompt_1.buildDynamicContext)();
|
|
30
34
|
if (userInput) {
|
|
31
35
|
this.context.addMessage("user", userInput);
|
|
32
36
|
}
|
|
@@ -35,11 +39,17 @@ class AgentRuntime {
|
|
|
35
39
|
if (currentTurn > 1) {
|
|
36
40
|
console.log(chalk_1.default.blue(`\n--- Turn ${currentTurn} ---`));
|
|
37
41
|
}
|
|
42
|
+
// 构建动态上下文(如果上一步有错误)
|
|
43
|
+
const dynamicContext = await (0, dynamicPrompt_1.buildDynamicContext)(lastError);
|
|
38
44
|
const messages = this.context.getMessages().map((msg) => ({
|
|
39
45
|
role: (msg.role === "tool" ? "system" : msg.role),
|
|
40
46
|
content: msg.content,
|
|
41
47
|
}));
|
|
42
|
-
|
|
48
|
+
// 构建基础prompt(包括治理策略)
|
|
49
|
+
const basePrompt = governance_1.GovernanceService.getPolicyManual();
|
|
50
|
+
// 注入动态上下文
|
|
51
|
+
const enhancedPrompt = (0, dynamicPrompt_1.injectDynamicContext)(basePrompt, dynamicContext);
|
|
52
|
+
const thought = await llmAdapter_1.LLMAdapter.think(messages, mode, onChunk, model, enhancedPrompt);
|
|
43
53
|
const action = {
|
|
44
54
|
id: (0, crypto_1.randomUUID)(),
|
|
45
55
|
type: thought.type || "answer",
|
|
@@ -78,6 +88,8 @@ class AgentRuntime {
|
|
|
78
88
|
console.log(chalk_1.default.yellow(`[EXECUTING] ⚙️ ${action.type}...`));
|
|
79
89
|
const result = await executor_1.ToolExecutor.execute(action);
|
|
80
90
|
if (result.success) {
|
|
91
|
+
// 成功时清除错误状态
|
|
92
|
+
lastError = undefined;
|
|
81
93
|
this.context.addToolResult(action.type, result.output);
|
|
82
94
|
const preview = result.output.length > 300
|
|
83
95
|
? result.output.substring(0, 300) + '...'
|
|
@@ -85,6 +97,8 @@ class AgentRuntime {
|
|
|
85
97
|
console.log(chalk_1.default.green(`[SUCCESS] Result:\n${preview}`));
|
|
86
98
|
}
|
|
87
99
|
else {
|
|
100
|
+
// 失败时记录错误,下次循环会注入错误恢复指导
|
|
101
|
+
lastError = result.error;
|
|
88
102
|
this.context.addToolResult(action.type, `Error: ${result.error}`);
|
|
89
103
|
console.log(chalk_1.default.red(`[ERROR] ${result.error}`));
|
|
90
104
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentRuntime.js","sourceRoot":"","sources":["../../src/agent/AgentRuntime.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAoC;AACpC,mCAAgC;AAChC,sEAA+C;AAE/C,mBAAmB;AACnB,eAAM,CAAC,UAAU,CAAC;IAChB,QAAQ,E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* 动态Prompt生成器
|
|
3
|
+
* 根据运行时状态动态注入Prompt片段
|
|
4
|
+
*/
|
|
5
|
+
export interface DynamicContext {
|
|
6
|
+
gitContext?: string;
|
|
7
|
+
techStack?: string[];
|
|
8
|
+
lastError?: string;
|
|
9
|
+
errorRecovery?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 检测Git上下文(增强版,支持子目录检测)
|
|
13
|
+
*/
|
|
14
|
+
export declare function detectGitContext(): Promise<string | null>;
|
|
15
|
+
/**
|
|
16
|
+
* 检测技术栈(使用Promise.all并发检测,提升性能)
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectTechStack(): Promise<string[]>;
|
|
19
|
+
/**
|
|
20
|
+
* 生成技术栈指导
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateTechStackGuidance(stacks: string[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* 生成错误恢复指导
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateErrorRecovery(lastError: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* 构建动态上下文
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildDynamicContext(lastError?: string, includeTechStack?: boolean): Promise<DynamicContext>;
|
|
31
|
+
/**
|
|
32
|
+
* 将动态上下文注入到Prompt
|
|
33
|
+
*/
|
|
34
|
+
export declare function injectDynamicContext(basePrompt: string, context: DynamicContext): string;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.detectGitContext = detectGitContext;
|
|
37
|
+
exports.detectTechStack = detectTechStack;
|
|
38
|
+
exports.generateTechStackGuidance = generateTechStackGuidance;
|
|
39
|
+
exports.generateErrorRecovery = generateErrorRecovery;
|
|
40
|
+
exports.buildDynamicContext = buildDynamicContext;
|
|
41
|
+
exports.injectDynamicContext = injectDynamicContext;
|
|
42
|
+
const fs = __importStar(require("fs/promises"));
|
|
43
|
+
const child_process_1 = require("child_process");
|
|
44
|
+
const util_1 = require("util");
|
|
45
|
+
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
46
|
+
/**
|
|
47
|
+
* 缓存检测结果,避免重复IO操作
|
|
48
|
+
*/
|
|
49
|
+
let cachedGitContext = null;
|
|
50
|
+
let cachedTechStack = null;
|
|
51
|
+
let lastCheckTimestamp = 0;
|
|
52
|
+
const CACHE_TTL = 5000; // 5秒缓存
|
|
53
|
+
/**
|
|
54
|
+
* 检测Git上下文(增强版,支持子目录检测)
|
|
55
|
+
*/
|
|
56
|
+
async function detectGitContext() {
|
|
57
|
+
// 使用git命令检测,支持在项目子目录中运行
|
|
58
|
+
try {
|
|
59
|
+
const { stdout } = await execAsync('git rev-parse --is-inside-work-tree', {
|
|
60
|
+
cwd: process.cwd(),
|
|
61
|
+
timeout: 2000
|
|
62
|
+
});
|
|
63
|
+
if (stdout.trim() === 'true') {
|
|
64
|
+
return `
|
|
65
|
+
[GIT CONTEXT]
|
|
66
|
+
当前目录在一个Git仓库中。
|
|
67
|
+
- 优先使用 \`git ls-files\` 列出文件(遵守.gitignore)
|
|
68
|
+
- 使用 \`git diff\` 查看未提交的更改
|
|
69
|
+
- 使用 \`git log\` 查看最近历史
|
|
70
|
+
- 谨慎操作版本控制文件
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// git命令失败,回退到文件系统检测
|
|
76
|
+
try {
|
|
77
|
+
await fs.access('.git');
|
|
78
|
+
return `
|
|
79
|
+
[GIT CONTEXT]
|
|
80
|
+
当前目录是一个Git仓库。
|
|
81
|
+
- 优先使用 \`git ls-files\` 列出文件(遵守.gitignore)
|
|
82
|
+
- 使用 \`git diff\` 查看未提交的更改
|
|
83
|
+
- 使用 \`git log\` 查看最近历史
|
|
84
|
+
- 谨慎操作版本控制文件
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 检测技术栈(使用Promise.all并发检测,提升性能)
|
|
95
|
+
*/
|
|
96
|
+
async function detectTechStack() {
|
|
97
|
+
const filesToCheck = [
|
|
98
|
+
{ file: 'package.json', stack: 'Node.js' },
|
|
99
|
+
{ file: 'Cargo.toml', stack: 'Rust' },
|
|
100
|
+
{ file: 'go.mod', stack: 'Go' },
|
|
101
|
+
{ file: 'requirements.txt', stack: 'Python' },
|
|
102
|
+
{ file: 'pom.xml', stack: 'Java/Maven' },
|
|
103
|
+
{ file: 'build.gradle', stack: 'Java/Gradle' },
|
|
104
|
+
{ file: 'Gemfile', stack: 'Ruby' },
|
|
105
|
+
{ file: 'composer.json', stack: 'PHP' },
|
|
106
|
+
{ file: 'Dockerfile', stack: 'Docker' },
|
|
107
|
+
];
|
|
108
|
+
// 并发检测所有文件,提升性能
|
|
109
|
+
const results = await Promise.all(filesToCheck.map(async ({ file, stack }) => {
|
|
110
|
+
try {
|
|
111
|
+
await fs.access(file);
|
|
112
|
+
return stack;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
// 过滤掉null值并去重
|
|
119
|
+
return results.filter((stack) => stack !== null);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 生成技术栈指导
|
|
123
|
+
*/
|
|
124
|
+
function generateTechStackGuidance(stacks) {
|
|
125
|
+
if (stacks.length === 0) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
const guidance = [];
|
|
129
|
+
if (stacks.includes('Node.js')) {
|
|
130
|
+
guidance.push(`
|
|
131
|
+
[TECH STACK: Node.js]
|
|
132
|
+
- 使用 \`npm\` 或 \`yarn\` 进行包管理
|
|
133
|
+
- 检查 package.json 可用的脚本命令
|
|
134
|
+
- 生成代码时使用TypeScript严格模式
|
|
135
|
+
- 使用ESLint和Prettier进行代码格式化`);
|
|
136
|
+
}
|
|
137
|
+
if (stacks.includes('Python')) {
|
|
138
|
+
guidance.push(`
|
|
139
|
+
[TECH STACK: Python]
|
|
140
|
+
- 使用 \`pip\` 或 \`poetry\` 进行包管理
|
|
141
|
+
- 检查 requirements.txt 或 pyproject.toml
|
|
142
|
+
- 遵循PEP 8代码风格指南
|
|
143
|
+
- 使用虚拟环境隔离依赖`);
|
|
144
|
+
}
|
|
145
|
+
if (stacks.includes('Go')) {
|
|
146
|
+
guidance.push(`
|
|
147
|
+
[TECH STACK: Go]
|
|
148
|
+
- 使用 \`go mod\` 进行模块管理
|
|
149
|
+
- 检查 go.mod 文件了解依赖
|
|
150
|
+
- 遵循Go惯用模式和错误处理
|
|
151
|
+
- 使用 \`go test\` 运行测试`);
|
|
152
|
+
}
|
|
153
|
+
if (stacks.includes('Rust')) {
|
|
154
|
+
guidance.push(`
|
|
155
|
+
[TECH STACK: Rust]
|
|
156
|
+
- 使用 \`cargo\` 进行包管理
|
|
157
|
+
- 检查 Cargo.toml 了解依赖
|
|
158
|
+
- 遵循Rust所有权和借用规则
|
|
159
|
+
- 使用 \`cargo clippy\` 进行代码检查`);
|
|
160
|
+
}
|
|
161
|
+
if (stacks.includes('Docker')) {
|
|
162
|
+
guidance.push(`
|
|
163
|
+
[TECH STACK: Docker]
|
|
164
|
+
- 检查 Dockerfile 和 docker-compose.yml
|
|
165
|
+
- 容器化运行和测试命令
|
|
166
|
+
- 注意多阶段构建优化
|
|
167
|
+
- 管理容器网络和卷`);
|
|
168
|
+
}
|
|
169
|
+
return guidance.join('\n');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 生成错误恢复指导
|
|
173
|
+
*/
|
|
174
|
+
function generateErrorRecovery(lastError) {
|
|
175
|
+
return `
|
|
176
|
+
[ERROR RECOVERY]
|
|
177
|
+
上一步操作失败: ${lastError}
|
|
178
|
+
你必须尝试不同的方法或验证前置条件。
|
|
179
|
+
|
|
180
|
+
考虑以下选项:
|
|
181
|
+
- 检查命令语法是否正确
|
|
182
|
+
- 验证文件/路径是否存在
|
|
183
|
+
- 使用不同的标志或工具
|
|
184
|
+
- 检查依赖是否已安装
|
|
185
|
+
- 查看错误日志获取更多信息
|
|
186
|
+
|
|
187
|
+
如果仍然失败,切换到 "answer" 模式向用户说明问题`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 构建动态上下文
|
|
191
|
+
*/
|
|
192
|
+
async function buildDynamicContext(lastError, includeTechStack = true) {
|
|
193
|
+
const context = {};
|
|
194
|
+
// 检测Git上下文
|
|
195
|
+
const gitContext = await detectGitContext();
|
|
196
|
+
if (gitContext) {
|
|
197
|
+
context.gitContext = gitContext;
|
|
198
|
+
}
|
|
199
|
+
// 检测技术栈
|
|
200
|
+
if (includeTechStack) {
|
|
201
|
+
const techStack = await detectTechStack();
|
|
202
|
+
if (techStack.length > 0) {
|
|
203
|
+
context.techStack = techStack;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// 错误恢复
|
|
207
|
+
if (lastError) {
|
|
208
|
+
context.lastError = lastError;
|
|
209
|
+
context.errorRecovery = generateErrorRecovery(lastError);
|
|
210
|
+
}
|
|
211
|
+
return context;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 将动态上下文注入到Prompt
|
|
215
|
+
*/
|
|
216
|
+
function injectDynamicContext(basePrompt, context) {
|
|
217
|
+
let prompt = basePrompt;
|
|
218
|
+
// 注入Git上下文
|
|
219
|
+
if (context.gitContext) {
|
|
220
|
+
prompt += `\n${context.gitContext}`;
|
|
221
|
+
}
|
|
222
|
+
// 注入技术栈指导
|
|
223
|
+
if (context.techStack && context.techStack.length > 0) {
|
|
224
|
+
const guidance = generateTechStackGuidance(context.techStack);
|
|
225
|
+
prompt += `\n${guidance}`;
|
|
226
|
+
}
|
|
227
|
+
// 注入错误恢复
|
|
228
|
+
if (context.errorRecovery) {
|
|
229
|
+
prompt += `\n${context.errorRecovery}`;
|
|
230
|
+
}
|
|
231
|
+
return prompt;
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=dynamicPrompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamicPrompt.js","sourceRoot":"","sources":["../../src/agent/dyn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C,CAAC;IAC3D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,UAAkB,EAClB,OAAuB;IAEvB,IAAI,MAAM,GAAG,UAAU,CAAC;IAExB,WAAW;IACX,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAED,UAAU;IACV,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC9D,MAAM,IAAI,KAAK,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAED,SAAS;IACT,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC;IACzC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -2,5 +2,5 @@ import { AgentThought } from './state';
|
|
|
2
2
|
import type { AIRequestMessage } from '../core/validation';
|
|
3
3
|
export declare class LLMAdapter {
|
|
4
4
|
static think(messages: AIRequestMessage[], mode?: 'chat' | 'command' | 'command+exec', onChunk?: (chunk: string) => void, model?: string, customSystemPrompt?: string): Promise<AgentThought>;
|
|
5
|
-
|
|
5
|
+
static parseThought(raw: string): AgentThought;
|
|
6
6
|
}
|
package/dist/agent/llmAdapter.js
CHANGED
|
@@ -9,29 +9,57 @@ const client_1 = require("../ai/client");
|
|
|
9
9
|
const json5_1 = __importDefault(require("json5"));
|
|
10
10
|
class LLMAdapter {
|
|
11
11
|
static async think(messages, mode = 'chat', onChunk, model, customSystemPrompt) {
|
|
12
|
-
|
|
12
|
+
// SYSTEM PROTOCOL V2.2 - CoT (Chain of Thought) 显式分离
|
|
13
|
+
let protocol = `[SYSTEM PROTOCOL V2.2]
|
|
13
14
|
- ROLE: AUTOMATED EXECUTION AGENT
|
|
14
|
-
- OUTPUT: STRICT JSON ONLY
|
|
15
|
-
- TALK: FORBIDDEN
|
|
16
15
|
- MODE: REACT (THINK -> ACTION -> PERCEIVE)
|
|
16
|
+
- OUTPUT: CoT Block + JSON Block
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
# EXECUTION PROTOCOL
|
|
19
|
+
1. **THINK**: First, analyze the user's request, the current context, and previous history. Plan your next step.
|
|
20
|
+
2. **ACT**: Generate a structured JSON action.
|
|
21
|
+
3. **OBSERVE**: Wait for the tool output.
|
|
22
|
+
|
|
23
|
+
# OUTPUT FORMAT
|
|
24
|
+
You must output a "Thought Block" followed by a "JSON Action Block".
|
|
25
|
+
|
|
26
|
+
[THOUGHT]
|
|
27
|
+
Explain your reasoning here.
|
|
28
|
+
- Why are you choosing this tool?
|
|
29
|
+
- If the previous step failed, how are you fixing it?
|
|
30
|
+
- If using a file, mention lines you are interested in.
|
|
31
|
+
[/THOUGHT]
|
|
32
|
+
|
|
33
|
+
\`\`\`json
|
|
19
34
|
{
|
|
20
35
|
"action_type": "tool_call" | "shell_cmd" | "answer",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
36
|
+
"tool_name": "...",
|
|
37
|
+
"parameters": { ... },
|
|
38
|
+
"command": "...",
|
|
39
|
+
"risk_level": "low" | "medium" | "high",
|
|
40
|
+
"risk_explanation": "Required if risk is medium/high"
|
|
26
41
|
}
|
|
42
|
+
\`\`\`
|
|
43
|
+
|
|
44
|
+
# GUIDELINES
|
|
45
|
+
- **Silence**: Do not output conversational filler outside the [THOUGHT] block.
|
|
46
|
+
- **Safety**: If you must run a destructive command (rm, dd), set risk_level to "high".
|
|
47
|
+
- **Context**: You have access to files in context.
|
|
48
|
+
- **Formatting**: When answering (action_type="answer"), use standard Markdown.
|
|
27
49
|
|
|
28
|
-
|
|
29
|
-
1. If data is unknown (e.g. file list), use 'shell_cmd' or 'tool_call'.
|
|
30
|
-
2. NEVER explain how to do it. JUST EXECUTE.
|
|
31
|
-
3. Your output MUST start with '{' and end with '}'.
|
|
50
|
+
Example Task: "count files in /tmp"
|
|
32
51
|
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
[THOUGHT]
|
|
53
|
+
User wants to count files in /tmp directory. I'll use ls to list files and pipe to wc -l to count them. This is a safe operation with low risk.
|
|
54
|
+
[/THOUGHT]
|
|
55
|
+
|
|
56
|
+
\`\`\`json
|
|
57
|
+
{
|
|
58
|
+
"action_type": "shell_cmd",
|
|
59
|
+
"command": "ls /tmp | wc -l",
|
|
60
|
+
"risk_level": "low"
|
|
61
|
+
}
|
|
62
|
+
\`\`\``;
|
|
35
63
|
if (mode === 'command' || mode === 'command+exec') {
|
|
36
64
|
protocol += `\n\nCOMMAND MODE ACTIVE:
|
|
37
65
|
- Prioritize "shell_cmd" for any terminal-based task.
|
|
@@ -54,10 +82,13 @@ Your Output: {"action_type":"shell_cmd","reasoning":"count files","command":"ls
|
|
|
54
82
|
}
|
|
55
83
|
static parseThought(raw) {
|
|
56
84
|
try {
|
|
57
|
-
//
|
|
85
|
+
// CoT V2.2: 分别提取 [THOUGHT] 块和 JSON 块
|
|
86
|
+
const thoughtMatch = raw.match(/\[THOUGHT\]([\s\S]*?)\[\/THOUGHT\]/);
|
|
58
87
|
const jsonMatch = raw.match(/```json\n([\s\S]*?)\n```/) || raw.match(/\{[\s\S]*\}/);
|
|
59
88
|
if (jsonMatch) {
|
|
60
89
|
const parsed = json5_1.default.parse(jsonMatch[1] || jsonMatch[0]);
|
|
90
|
+
// 从 THOUGHT 块提取思考内容
|
|
91
|
+
const thoughtContent = thoughtMatch ? thoughtMatch[1].trim() : '';
|
|
61
92
|
// 如果明确标记为 done,或者动作为 answer,则视为任务结束
|
|
62
93
|
if (parsed.is_done === true || parsed.action_type === 'answer') {
|
|
63
94
|
return {
|
|
@@ -67,7 +98,8 @@ Your Output: {"action_type":"shell_cmd","reasoning":"count files","command":"ls
|
|
|
67
98
|
type: 'answer',
|
|
68
99
|
payload: {
|
|
69
100
|
content: parsed.final_answer || parsed.content || parsed.text || raw
|
|
70
|
-
}
|
|
101
|
+
},
|
|
102
|
+
reasoning: thoughtContent
|
|
71
103
|
};
|
|
72
104
|
}
|
|
73
105
|
// 智能推断动作类型:如果 AI 没给 action_type,我们根据字段猜测
|
|
@@ -92,9 +124,11 @@ Your Output: {"action_type":"shell_cmd","reasoning":"count files","command":"ls
|
|
|
92
124
|
parameters: parsed.parameters || parsed.params || {},
|
|
93
125
|
command: parsed.command || parsed.cmd || '',
|
|
94
126
|
diff: parsed.diff || parsed.patch || '',
|
|
95
|
-
content: parsed.content || parsed.text || ''
|
|
127
|
+
content: parsed.content || parsed.text || '',
|
|
128
|
+
risk_level: parsed.risk_level || 'low',
|
|
129
|
+
risk_explanation: parsed.risk_explanation || ''
|
|
96
130
|
},
|
|
97
|
-
reasoning:
|
|
131
|
+
reasoning: thoughtContent // 从 THOUGHT 块提取
|
|
98
132
|
};
|
|
99
133
|
}
|
|
100
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmAdapter.js","sourceRoot":"","sources":["../../src/agent/llmAdapter.ts"],"names":[],"mappings":";;;;;;AACA,+BAA+B;AAG/B,yCAA6C;AAC7C,kDAA0B;AAE1B,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,QAA4B,EAC5B,OAA4C,MAAM,EAClD,OAAiC,EACjC,KAAc,EACd,kBAA2B;QAE3B,IAAI,QAAQ,GAAG
|
|
1
|
+
{"version":3,"file":"llmAdapter.js","sourceRoot":"","sources":["../../src/agent/llmAdapter.ts"],"names":[],"mappings":";;;;;;AACA,+BAA+B;AAG/B,yCAA6C;AAC7C,kDAA0B;AAE1B,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,QAA4B,EAC5B,OAA4C,MAAM,EAClD,OAAiC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,IAAI,EAAE;wBAC3C,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE;wBACvC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,EAAE;wBAC5C,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,KAAK;wBACtC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,EAAE;qBAChD;oBACD,SAAS,EAAE,cAAc,CAAC,gBAAgB;iBAC3C,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,qBAAqB;QACvB,CAAC;QAED,OAAO;YACL,GAAG;YACH,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;YACzB,SAAS,EAAE,EAAE;SACd,CAAC;IACJ,CAAC;CACF;AAtJD,gCAsJC"}
|
package/dist/agent/prompt.js
CHANGED
|
@@ -28,8 +28,44 @@ function buildChatPrompt(context, input) {
|
|
|
28
28
|
role: 'user',
|
|
29
29
|
content: input,
|
|
30
30
|
});
|
|
31
|
+
// Enhanced system prompt with role definition, interaction guidelines, and format standards
|
|
32
|
+
const systemPrompt = `你是一个专业的技术助手(Yuangs AI),专精于:
|
|
33
|
+
- 软件开发(前端、后端、DevOps)
|
|
34
|
+
- 系统管理和自动化
|
|
35
|
+
- 问题诊断和解决
|
|
36
|
+
- 技术方案设计
|
|
37
|
+
|
|
38
|
+
【交互原则】
|
|
39
|
+
1. 简洁明了:优先提供直接答案,必要时补充解释
|
|
40
|
+
2. 上下文感知:充分利用提供的文件和目录上下文
|
|
41
|
+
3. 实用导向:提供可执行的命令和代码示例
|
|
42
|
+
4. 渐进式说明:除非用户要求深度解析,否则先提供概要
|
|
43
|
+
|
|
44
|
+
【输出格式】
|
|
45
|
+
- 使用Markdown格式化代码、列表等
|
|
46
|
+
- 关键信息使用加粗或emoji标记
|
|
47
|
+
- 分步骤说明使用数字列表
|
|
48
|
+
- 代码块指定语言类型
|
|
49
|
+
|
|
50
|
+
【上下文使用】
|
|
51
|
+
- 当上下文中包含相关文件时,引用具体文件名和行号
|
|
52
|
+
- 对目录上下文中的文件进行相关性筛选
|
|
53
|
+
- 优先使用上下文中的信息作为回答基础
|
|
54
|
+
|
|
55
|
+
【当前能力】
|
|
56
|
+
✓ 读取和分析代码文件
|
|
57
|
+
✓ 执行Shell命令(需用户确认)
|
|
58
|
+
✓ 搜索和过滤文件内容
|
|
59
|
+
✓ Git操作和版本控制
|
|
60
|
+
✓ 代码生成和重构建议
|
|
61
|
+
|
|
62
|
+
【注意事项】
|
|
63
|
+
- 执行危险操作前会说明风险
|
|
64
|
+
- 无法直接修改文件,提供修改建议
|
|
65
|
+
- 大文件只读取关键部分以节省Token
|
|
66
|
+
- 敏感信息(如密码)不会保存`;
|
|
31
67
|
return {
|
|
32
|
-
system:
|
|
68
|
+
system: systemPrompt,
|
|
33
69
|
messages,
|
|
34
70
|
};
|
|
35
71
|
}
|
package/dist/agent/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/agent/prompt.ts"],"names":[],"mappings":";;AAYA,kCAWC;AAjBD,yCAA8E;AAC9E,mCAA0C;AAC1C,2CAA2C;AAC3C,mDAAyD;AACzD,qCAA6C;AAE7C,SAAgB,WAAW,CACvB,MAAmB,EACnB,OAAqB,EACrB,IAAe,EACf,KAAa;IAEb,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAClB,OAAO,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,eAAe,CACpB,OAAqB,EACrB,KAAa;IAEb,MAAM,QAAQ,GAAU;QACpB,GAAG,CAAC,OAAO,CAAC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