yuangs 3.16.0 → 3.19.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/DualAgentRuntime.d.ts +23 -0
- package/dist/agent/DualAgentRuntime.js +265 -0
- package/dist/agent/DualAgentRuntime.js.map +1 -0
- package/dist/agent/codeSummary.d.ts +34 -0
- package/dist/agent/codeSummary.js +370 -0
- package/dist/agent/codeSummary.js.map +1 -0
- 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/errorHandling.d.ts +41 -0
- package/dist/agent/errorHandling.js +168 -0
- package/dist/agent/errorHandling.js.map +1 -0
- package/dist/agent/index.d.ts +4 -0
- package/dist/agent/index.js +7 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/llm.d.ts +27 -0
- package/dist/agent/llm.js +83 -3
- package/dist/agent/llm.js.map +1 -1
- package/dist/agent/preferences.d.ts +21 -0
- package/dist/agent/preferences.js +136 -0
- package/dist/agent/preferences.js.map +1 -0
- package/dist/agent/relevance.d.ts +18 -0
- package/dist/agent/relevance.js +120 -0
- package/dist/agent/relevance.js.map +1 -0
- package/dist/agent/riskDisclosure.d.ts +43 -0
- package/dist/agent/riskDisclosure.js +315 -0
- package/dist/agent/riskDisclosure.js.map +1 -0
- package/dist/agent/smartContextManager.d.ts +23 -0
- package/dist/agent/smartContextManager.js +83 -0
- package/dist/agent/smartContextManager.js.map +1 -0
- package/dist/agent/types.d.ts +15 -0
- package/package.json +3 -2
|
@@ -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,EAAE,IAAI,yBAAgB,EAAE;CACjC,CAAC,CAAC;AACH,6CAA0C;AAC1C,6CAAiD;AACjD,yCAA0C;AAC1C,qDAAkD;AAClD,4CAAqD;
|
|
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,EAAE,IAAI,yBAAgB,EAAE;CACjC,CAAC,CAAC;AACH,6CAA0C;AAC1C,6CAAiD;AACjD,yCAA0C;AAC1C,qDAAkD;AAClD,4CAAqD;AAErD,mDAIyB;AAEzB,MAAa,YAAY;IACf,OAAO,CAAiB;IACxB,WAAW,CAAS;IAE5B,YAAY,cAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAc,CAAC,cAA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AAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,sBAAsB,OAAO,EAAE,CAAC,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,wBAAwB;gBACxB,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC;gBACzB,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBAClE,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,IAAI,SAAS,IAAI,QAAQ,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,mBAAmB,QAAQ,YAAY,CAAC,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF;AApID,oCAoIC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TaskStep } from './types';
|
|
2
|
+
export declare class DualAgentRuntime {
|
|
3
|
+
private context;
|
|
4
|
+
private executionId;
|
|
5
|
+
private steps;
|
|
6
|
+
private currentIndex;
|
|
7
|
+
constructor(initialContext: any);
|
|
8
|
+
run(userInput: string, onChunk?: (chunk: string) => void, model?: string): Promise<void>;
|
|
9
|
+
private shouldUsePlanner;
|
|
10
|
+
private assessComplexity;
|
|
11
|
+
private runFastPath;
|
|
12
|
+
private runPlannedPath;
|
|
13
|
+
private callPlanner;
|
|
14
|
+
private buildPlannerPrompt;
|
|
15
|
+
private getContextSummary;
|
|
16
|
+
private executeStep;
|
|
17
|
+
private importAgentRuntime;
|
|
18
|
+
private askUser;
|
|
19
|
+
getExecutionState(): {
|
|
20
|
+
steps: TaskStep[];
|
|
21
|
+
currentIndex: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DualAgentRuntime = void 0;
|
|
40
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
+
const crypto_1 = require("crypto");
|
|
42
|
+
const executor_1 = require("./executor");
|
|
43
|
+
const contextManager_1 = require("./contextManager");
|
|
44
|
+
const client_1 = require("../ai/client");
|
|
45
|
+
class DualAgentRuntime {
|
|
46
|
+
context;
|
|
47
|
+
executionId;
|
|
48
|
+
steps = [];
|
|
49
|
+
currentIndex = 0;
|
|
50
|
+
constructor(initialContext) {
|
|
51
|
+
this.context = new contextManager_1.ContextManager(initialContext);
|
|
52
|
+
this.executionId = (0, crypto_1.randomUUID)();
|
|
53
|
+
}
|
|
54
|
+
async run(userInput, onChunk, model) {
|
|
55
|
+
const needsPlanner = await this.shouldUsePlanner(userInput);
|
|
56
|
+
if (!needsPlanner) {
|
|
57
|
+
await this.runFastPath(userInput, onChunk, model);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await this.runPlannedPath(userInput, onChunk, model);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async shouldUsePlanner(userInput) {
|
|
64
|
+
const config = (0, client_1.getUserConfig)();
|
|
65
|
+
if (config.disablePlanner) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (userInput.length < 50 && !userInput.includes('并') && !userInput.includes('然后')) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const plannerKeywords = ['重构', '优化整个', '批量', '多步骤', '逐个', '依次', '计划', 'refactor', 'optimize all', 'batch', 'multiple steps', 'sequentially'];
|
|
72
|
+
if (!plannerKeywords.some(kw => userInput.toLowerCase().includes(kw.toLowerCase()))) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const complexityScore = await this.assessComplexity(userInput);
|
|
76
|
+
return complexityScore > 0.7;
|
|
77
|
+
}
|
|
78
|
+
async assessComplexity(input) {
|
|
79
|
+
const simpleIndicators = [
|
|
80
|
+
/列出|list|ls/,
|
|
81
|
+
/查看|show|cat|less/,
|
|
82
|
+
/查找|find|grep/,
|
|
83
|
+
/创建|create|mkdir|touch/
|
|
84
|
+
];
|
|
85
|
+
const hasSimpleIndicator = simpleIndicators.some(pattern => pattern.test(input));
|
|
86
|
+
if (input.length < 30 || hasSimpleIndicator) {
|
|
87
|
+
return 0.3;
|
|
88
|
+
}
|
|
89
|
+
return 0.8;
|
|
90
|
+
}
|
|
91
|
+
async runFastPath(userInput, onChunk, model) {
|
|
92
|
+
console.log(chalk_1.default.gray('🚀 Quick path: Direct execution'));
|
|
93
|
+
const runtime = await this.importAgentRuntime();
|
|
94
|
+
this.context.addMessage('user', userInput);
|
|
95
|
+
await runtime.run(userInput, 'command', onChunk, model);
|
|
96
|
+
}
|
|
97
|
+
async runPlannedPath(userInput, onChunk, model) {
|
|
98
|
+
console.log(chalk_1.default.blue('📋 Planning task...'));
|
|
99
|
+
const plan = await this.callPlanner(userInput, model);
|
|
100
|
+
this.steps = plan.steps;
|
|
101
|
+
console.log(chalk_1.default.cyan(`\nPlan created with ${this.steps.length} steps:\n`));
|
|
102
|
+
this.steps.forEach((step, i) => {
|
|
103
|
+
const icon = step.risk_level === 'high' ? '⚠️' : '✅';
|
|
104
|
+
console.log(` ${i + 1}. ${icon} ${step.description}`);
|
|
105
|
+
});
|
|
106
|
+
console.log(chalk_1.default.gray(`\n${plan.plan}`));
|
|
107
|
+
console.log(chalk_1.default.gray(`Estimated time: ${plan.estimated_time}\n`));
|
|
108
|
+
const shouldProceed = await this.askUser('Proceed with this plan? (y/N): ');
|
|
109
|
+
if (!shouldProceed) {
|
|
110
|
+
console.log(chalk_1.default.yellow('Execution cancelled by user.'));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
114
|
+
this.currentIndex = i;
|
|
115
|
+
const step = this.steps[i];
|
|
116
|
+
console.log(chalk_1.default.yellow(`\n▶️ Step ${i + 1}/${this.steps.length}: ${step.description}`));
|
|
117
|
+
const result = await this.executeStep(step, onChunk, model);
|
|
118
|
+
if (!result.success) {
|
|
119
|
+
console.log(chalk_1.default.red(`❌ Step failed: ${result.error}`));
|
|
120
|
+
const shouldContinue = await this.askUser('Step failed. Continue with remaining steps? (y/N): ');
|
|
121
|
+
if (!shouldContinue) {
|
|
122
|
+
console.log(chalk_1.default.yellow('Execution stopped by user.'));
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log(chalk_1.default.green(`✅ Step completed`));
|
|
128
|
+
if (result.output && result.output.length > 0) {
|
|
129
|
+
const preview = result.output.length > 300 ? result.output.substring(0, 300) + '...' : result.output;
|
|
130
|
+
console.log(chalk_1.default.gray(` Output: ${preview}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
console.log(chalk_1.default.blue('\n🎉 All tasks completed!'));
|
|
135
|
+
}
|
|
136
|
+
async callPlanner(input, model) {
|
|
137
|
+
const config = (0, client_1.getUserConfig)();
|
|
138
|
+
const finalModel = model || config.defaultModel || 'Assistant';
|
|
139
|
+
const prompt = this.buildPlannerPrompt(input);
|
|
140
|
+
const messages = [{ role: 'user', content: prompt }];
|
|
141
|
+
try {
|
|
142
|
+
const response = await (0, client_1.askAI)(prompt, finalModel);
|
|
143
|
+
const jsonMatch = response.match(/```json\n([\s\S]*?)\n```/);
|
|
144
|
+
if (jsonMatch) {
|
|
145
|
+
return JSON.parse(jsonMatch[1]);
|
|
146
|
+
}
|
|
147
|
+
const braceMatch = response.match(/\{[\s\S]*\}/);
|
|
148
|
+
if (braceMatch) {
|
|
149
|
+
return JSON.parse(braceMatch[0]);
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
plan: 'No plan generated',
|
|
153
|
+
steps: [],
|
|
154
|
+
estimated_time: 'Unknown'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error(chalk_1.default.red(`Planner error: ${error}`));
|
|
159
|
+
return {
|
|
160
|
+
plan: 'Plan generation failed',
|
|
161
|
+
steps: [],
|
|
162
|
+
estimated_time: 'Unknown'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
buildPlannerPrompt(input) {
|
|
167
|
+
const context = this.getContextSummary();
|
|
168
|
+
return `# ROLE: Task Planner
|
|
169
|
+
|
|
170
|
+
You are a strategic planner. Break down complex tasks into executable steps.
|
|
171
|
+
|
|
172
|
+
# INPUT
|
|
173
|
+
User Request: ${input}
|
|
174
|
+
|
|
175
|
+
${context ? `Context:\n${context}\n` : ''}
|
|
176
|
+
|
|
177
|
+
# OUTPUT FORMAT
|
|
178
|
+
\`\`\`json
|
|
179
|
+
{
|
|
180
|
+
"plan": "Brief overview of the approach",
|
|
181
|
+
"steps": [
|
|
182
|
+
{
|
|
183
|
+
"id": "step_1",
|
|
184
|
+
"description": "What to do",
|
|
185
|
+
"type": "shell_cmd | tool_call | analysis | code_diff",
|
|
186
|
+
"command": "Command if shell_cmd",
|
|
187
|
+
"tool_name": "Tool name if tool_call",
|
|
188
|
+
"parameters": {},
|
|
189
|
+
"risk_level": "low | medium | high",
|
|
190
|
+
"dependencies": []
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"estimated_time": "2 minutes"
|
|
194
|
+
}
|
|
195
|
+
\`\`\`
|
|
196
|
+
|
|
197
|
+
# GUIDELINES
|
|
198
|
+
- Keep steps granular and verifiable
|
|
199
|
+
- Mark destructive operations (rm, dd, format) as high risk
|
|
200
|
+
- Include validation steps when appropriate
|
|
201
|
+
- Consider error handling in each step
|
|
202
|
+
- For shell commands, use exact commands that can be executed directly
|
|
203
|
+
- For tool calls, specify tool_name and parameters
|
|
204
|
+
- Dependencies are step IDs that must complete before this step`;
|
|
205
|
+
}
|
|
206
|
+
getContextSummary() {
|
|
207
|
+
const files = this.context.getMessages()
|
|
208
|
+
.filter(m => m.role === 'user')
|
|
209
|
+
.map(m => m.content)
|
|
210
|
+
.join('\n');
|
|
211
|
+
return files ? `Files/Context:\n${files}` : '';
|
|
212
|
+
}
|
|
213
|
+
async executeStep(step, onChunk, model) {
|
|
214
|
+
const action = {
|
|
215
|
+
id: (0, crypto_1.randomUUID)(),
|
|
216
|
+
type: step.type,
|
|
217
|
+
payload: {
|
|
218
|
+
tool_name: step.tool_name || '',
|
|
219
|
+
parameters: step.parameters || {},
|
|
220
|
+
command: step.command || '',
|
|
221
|
+
risk_level: step.risk_level
|
|
222
|
+
},
|
|
223
|
+
riskLevel: step.risk_level,
|
|
224
|
+
reasoning: `Executing planned step: ${step.description}`
|
|
225
|
+
};
|
|
226
|
+
const result = await executor_1.ToolExecutor.execute(action);
|
|
227
|
+
if (result.success) {
|
|
228
|
+
this.context.addToolResult(step.type, result.output);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
this.context.addToolResult(step.type, `Error: ${result.error}`);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
success: result.success,
|
|
235
|
+
output: result.output,
|
|
236
|
+
error: result.error
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
async importAgentRuntime() {
|
|
240
|
+
const module = await Promise.resolve().then(() => __importStar(require('./AgentRuntime')));
|
|
241
|
+
const AgentRuntime = module.AgentRuntime;
|
|
242
|
+
return new AgentRuntime({});
|
|
243
|
+
}
|
|
244
|
+
async askUser(question) {
|
|
245
|
+
const readline = await Promise.resolve().then(() => __importStar(require('readline')));
|
|
246
|
+
const rl = readline.createInterface({
|
|
247
|
+
input: process.stdin,
|
|
248
|
+
output: process.stdout
|
|
249
|
+
});
|
|
250
|
+
return new Promise((resolve) => {
|
|
251
|
+
rl.question(question, (answer) => {
|
|
252
|
+
rl.close();
|
|
253
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
getExecutionState() {
|
|
258
|
+
return {
|
|
259
|
+
steps: this.steps,
|
|
260
|
+
currentIndex: this.currentIndex
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
exports.DualAgentRuntime = DualAgentRuntime;
|
|
265
|
+
//# sourceMappingURL=DualAgentRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DualAgentRuntime.js","sourceRoot":"","sources":["../../src/agent/DualAgentRuntime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,mCAAoC;AAGpC,yCAA0C;AAC1C,qDAAkD;AAIlD,yCAAoD;AAEpD,MAAa,gBAAgB;IACnB,OAAO,CAAiB;IACxB,WAAW,CAAS;IACpB,KAAK,GAAe,EAAE,CAAC;IACvB,YAAY,GAAG,CAAC,CAAC;IAEzB,YAAY,cAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAc,CAAC,cAAc,CAAC,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,IAAA,mBAAU,GAAE,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,SAAiB,EACjB,OAAiC,EACjC,KAAc;QAEd,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAE5D,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QAC9C,MAAM,MAAM,GAAG,IAAA,sBAAa,GAAE,CAAC;QAE/B,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,SAAS,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,SAAS,CA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,GAAG,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB;QACf,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;IACJ,CAAC;CACF;AA9QD,4CA8QC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代码摘要生成器
|
|
3
|
+
* 通过AST/Symbol级分析生成代码结构摘要,减少Token使用
|
|
4
|
+
*/
|
|
5
|
+
export interface FileSummary {
|
|
6
|
+
path: string;
|
|
7
|
+
summary: string;
|
|
8
|
+
symbols: Symbol[];
|
|
9
|
+
}
|
|
10
|
+
export interface Symbol {
|
|
11
|
+
name: string;
|
|
12
|
+
type: 'function' | 'class' | 'variable' | 'import' | 'export';
|
|
13
|
+
line?: number;
|
|
14
|
+
signature?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 从代码中提取符号(简单正则实现,支持多语言)
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractSymbols(code: string, filename: string): Symbol[];
|
|
20
|
+
/**
|
|
21
|
+
* 生成文件摘要
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateFileSummary(filePath: string, content: string): FileSummary;
|
|
24
|
+
/**
|
|
25
|
+
* 生成多文件摘要
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateMultipleFileSummaries(files: Array<{
|
|
28
|
+
path: string;
|
|
29
|
+
content: string;
|
|
30
|
+
}>): Promise<FileSummary[]>;
|
|
31
|
+
/**
|
|
32
|
+
* 生成摘要报告(用于注入到Prompt)
|
|
33
|
+
*/
|
|
34
|
+
export declare function generateSummaryReport(summaries: FileSummary[], maxLength?: number): string;
|