wave-agent-sdk 0.5.0 → 0.6.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/dist/agent.d.ts +14 -6
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +65 -88
- package/dist/constants/prompts.d.ts +18 -14
- package/dist/constants/prompts.d.ts.map +1 -1
- package/dist/constants/prompts.js +130 -54
- package/dist/constants/tools.d.ts +4 -1
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/aiManager.d.ts +2 -5
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +59 -48
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +59 -53
- package/dist/managers/foregroundTaskManager.d.ts.map +1 -1
- package/dist/managers/foregroundTaskManager.js +3 -2
- package/dist/managers/mcpManager.d.ts.map +1 -1
- package/dist/managers/messageManager.d.ts +14 -10
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +102 -62
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +25 -15
- package/dist/managers/planManager.d.ts +1 -1
- package/dist/managers/planManager.d.ts.map +1 -1
- package/dist/managers/planManager.js +2 -2
- package/dist/managers/slashCommandManager.d.ts +3 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +7 -2
- package/dist/managers/subagentManager.d.ts +4 -0
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +22 -14
- package/dist/managers/toolManager.d.ts +11 -0
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +20 -2
- package/dist/services/aiService.d.ts +0 -1
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +4 -140
- package/dist/services/memory.d.ts +0 -3
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js +0 -59
- package/dist/services/session.d.ts +15 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +57 -1
- package/dist/services/taskManager.d.ts +21 -0
- package/dist/services/taskManager.d.ts.map +1 -0
- package/dist/services/taskManager.js +158 -0
- package/dist/tools/askUserQuestion.d.ts.map +1 -1
- package/dist/tools/askUserQuestion.js +39 -25
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +7 -9
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +2 -1
- package/dist/tools/exitPlanMode.d.ts.map +1 -1
- package/dist/tools/exitPlanMode.js +25 -1
- package/dist/tools/globTool.d.ts.map +1 -1
- package/dist/tools/globTool.js +8 -2
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +17 -6
- package/dist/tools/lsTool.d.ts.map +1 -1
- package/dist/tools/lsTool.js +3 -1
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +16 -1
- package/dist/tools/taskManagementTools.d.ts +6 -0
- package/dist/tools/taskManagementTools.d.ts.map +1 -0
- package/dist/tools/taskManagementTools.js +453 -0
- package/dist/tools/taskOutputTool.d.ts.map +1 -1
- package/dist/tools/taskOutputTool.js +32 -8
- package/dist/tools/taskStopTool.d.ts.map +1 -1
- package/dist/tools/taskStopTool.js +7 -1
- package/dist/tools/taskTool.d.ts.map +1 -1
- package/dist/tools/taskTool.js +6 -1
- package/dist/tools/types.d.ts +9 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +9 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/messaging.d.ts +2 -8
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +11 -6
- package/dist/types/processes.d.ts.map +1 -1
- package/dist/types/tasks.d.ts +13 -0
- package/dist/types/tasks.d.ts.map +1 -0
- package/dist/types/tasks.js +1 -0
- package/dist/types/tools.d.ts +4 -1
- package/dist/types/tools.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.d.ts.map +1 -1
- package/dist/utils/builtinSubagents.js +38 -1
- package/dist/utils/cacheControlUtils.d.ts.map +1 -1
- package/dist/utils/cacheControlUtils.js +18 -12
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +0 -4
- package/dist/utils/convertMessagesForAPI.js +2 -2
- package/dist/utils/messageOperations.d.ts +2 -35
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +4 -97
- package/dist/utils/nameGenerator.d.ts +1 -1
- package/dist/utils/nameGenerator.d.ts.map +1 -1
- package/dist/utils/nameGenerator.js +19 -3
- package/package.json +1 -1
- package/src/agent.ts +90 -101
- package/src/constants/prompts.ts +156 -65
- package/src/constants/tools.ts +4 -1
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +79 -70
- package/src/managers/backgroundTaskManager.ts +53 -54
- package/src/managers/foregroundTaskManager.ts +3 -2
- package/src/managers/mcpManager.ts +6 -3
- package/src/managers/messageManager.ts +137 -73
- package/src/managers/permissionManager.ts +32 -21
- package/src/managers/planManager.ts +2 -2
- package/src/managers/slashCommandManager.ts +11 -2
- package/src/managers/subagentManager.ts +33 -14
- package/src/managers/toolManager.ts +32 -2
- package/src/services/aiService.ts +3 -145
- package/src/services/memory.ts +0 -72
- package/src/services/session.ts +73 -0
- package/src/services/taskManager.ts +188 -0
- package/src/tools/askUserQuestion.ts +51 -29
- package/src/tools/bashTool.ts +9 -15
- package/src/tools/editTool.ts +3 -1
- package/src/tools/exitPlanMode.ts +26 -2
- package/src/tools/globTool.ts +10 -2
- package/src/tools/grepTool.ts +17 -6
- package/src/tools/lsTool.ts +3 -1
- package/src/tools/readTool.ts +17 -1
- package/src/tools/taskManagementTools.ts +498 -0
- package/src/tools/taskOutputTool.ts +34 -12
- package/src/tools/taskStopTool.ts +7 -1
- package/src/tools/taskTool.ts +7 -1
- package/src/tools/types.ts +10 -0
- package/src/tools/writeTool.ts +9 -2
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +1 -9
- package/src/types/processes.ts +13 -7
- package/src/types/tasks.ts +13 -0
- package/src/types/tools.ts +4 -1
- package/src/utils/builtinSubagents.ts +47 -1
- package/src/utils/cacheControlUtils.ts +26 -18
- package/src/utils/constants.ts +0 -5
- package/src/utils/convertMessagesForAPI.ts +2 -2
- package/src/utils/messageOperations.ts +5 -136
- package/src/utils/nameGenerator.ts +20 -3
- package/dist/tools/todoWriteTool.d.ts +0 -6
- package/dist/tools/todoWriteTool.d.ts.map +0 -1
- package/dist/tools/todoWriteTool.js +0 -220
- package/src/tools/todoWriteTool.ts +0 -257
|
@@ -13,7 +13,7 @@ export class PlanManager {
|
|
|
13
13
|
/**
|
|
14
14
|
* Ensures the plan directory exists and generates a new plan file path with a random name
|
|
15
15
|
*/
|
|
16
|
-
async getOrGeneratePlanFilePath() {
|
|
16
|
+
async getOrGeneratePlanFilePath(seed) {
|
|
17
17
|
try {
|
|
18
18
|
await fs.mkdir(this.planDir, { recursive: true });
|
|
19
19
|
}
|
|
@@ -21,7 +21,7 @@ export class PlanManager {
|
|
|
21
21
|
this.logger?.error(`Failed to create plan directory: ${this.planDir}`, error);
|
|
22
22
|
throw error;
|
|
23
23
|
}
|
|
24
|
-
const name = generateRandomName();
|
|
24
|
+
const name = generateRandomName(seed);
|
|
25
25
|
const filePath = path.join(this.planDir, `${name}.md`);
|
|
26
26
|
this.logger?.info(`Generated plan file path: ${filePath}`);
|
|
27
27
|
return { path: filePath, name };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { MessageManager } from "./messageManager.js";
|
|
2
2
|
import type { AIManager } from "./aiManager.js";
|
|
3
3
|
import type { BackgroundTaskManager } from "./backgroundTaskManager.js";
|
|
4
|
+
import type { TaskManager } from "../services/taskManager.js";
|
|
4
5
|
import type { SlashCommand, CustomSlashCommand, Logger } from "../types/index.js";
|
|
5
6
|
export interface SlashCommandManagerOptions {
|
|
6
7
|
messageManager: MessageManager;
|
|
7
8
|
aiManager: AIManager;
|
|
8
9
|
backgroundTaskManager: BackgroundTaskManager;
|
|
10
|
+
taskManager: TaskManager;
|
|
9
11
|
workdir: string;
|
|
10
12
|
logger?: Logger;
|
|
11
13
|
}
|
|
@@ -15,6 +17,7 @@ export declare class SlashCommandManager {
|
|
|
15
17
|
private messageManager;
|
|
16
18
|
private aiManager;
|
|
17
19
|
private backgroundTaskManager;
|
|
20
|
+
private taskManager;
|
|
18
21
|
private workdir;
|
|
19
22
|
private logger?;
|
|
20
23
|
constructor(options: SlashCommandManagerOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashCommandManager.d.ts","sourceRoot":"","sources":["../../src/managers/slashCommandManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACP,MAAM,mBAAmB,CAAC;AAmB3B,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;IACrB,qBAAqB,EAAE,qBAAqB,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,SAAS,CAA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C7B,IAAI;IAwDP;;OAEG;IACI,oBAAoB,IAAI,IAAI;IAWnC;;OAEG;IACI,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAKnD;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACI,WAAW,IAAI,YAAY,EAAE;IAIpC;;OAEG;IACI,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI9D;;OAEG;IACU,cAAc,CACzB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC;IAenB;;;OAGG;IACI,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG;QAClD,OAAO,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;IAeD;;OAEG;IACI,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAI7C;;OAEG;IACI,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI1E;;OAEG;IACI,iBAAiB,IAAI,kBAAkB,EAAE;IAIhD;;OAEG;YACW,+BAA+B;IA0E7C;;OAEG;IACI,mBAAmB,IAAI,IAAI;CAInC"}
|
|
@@ -12,6 +12,7 @@ export class SlashCommandManager {
|
|
|
12
12
|
this.messageManager = options.messageManager;
|
|
13
13
|
this.aiManager = options.aiManager;
|
|
14
14
|
this.backgroundTaskManager = options.backgroundTaskManager;
|
|
15
|
+
this.taskManager = options.taskManager;
|
|
15
16
|
this.workdir = options.workdir;
|
|
16
17
|
this.logger = options.logger;
|
|
17
18
|
this.initializeBuiltinCommands();
|
|
@@ -26,8 +27,12 @@ export class SlashCommandManager {
|
|
|
26
27
|
handler: () => {
|
|
27
28
|
// Clear chat messages
|
|
28
29
|
this.messageManager.clearMessages();
|
|
29
|
-
//
|
|
30
|
-
process.
|
|
30
|
+
// Reset task list if WAVE_TASK_LIST_ID is not set
|
|
31
|
+
if (!process.env.WAVE_TASK_LIST_ID) {
|
|
32
|
+
const newTaskListId = this.messageManager.getRootSessionId();
|
|
33
|
+
this.taskManager.setTaskListId(newTaskListId);
|
|
34
|
+
this.taskManager.emit("tasksChange", newTaskListId);
|
|
35
|
+
}
|
|
31
36
|
},
|
|
32
37
|
});
|
|
33
38
|
// Register built-in init command
|
|
@@ -21,6 +21,8 @@ export interface SubagentManagerCallbacks {
|
|
|
21
21
|
onSubagentToolBlockUpdated?: (subagentId: string, params: AgentToolBlockUpdateParams) => void;
|
|
22
22
|
/** Triggered when subagent messages change */
|
|
23
23
|
onSubagentMessagesChange?: (subagentId: string, messages: Message[]) => void;
|
|
24
|
+
/** Triggered when subagent latest total tokens change */
|
|
25
|
+
onSubagentLatestTotalTokensChange?: (subagentId: string, tokens: number) => void;
|
|
24
26
|
}
|
|
25
27
|
export interface SubagentInstance {
|
|
26
28
|
subagentId: string;
|
|
@@ -37,6 +39,7 @@ export interface SubagentManagerOptions {
|
|
|
37
39
|
workdir: string;
|
|
38
40
|
parentToolManager: ToolManager;
|
|
39
41
|
parentMessageManager: MessageManager;
|
|
42
|
+
taskManager: import("../services/taskManager.js").TaskManager;
|
|
40
43
|
callbacks?: SubagentManagerCallbacks;
|
|
41
44
|
logger?: Logger;
|
|
42
45
|
getGatewayConfig: () => GatewayConfig;
|
|
@@ -54,6 +57,7 @@ export declare class SubagentManager {
|
|
|
54
57
|
private workdir;
|
|
55
58
|
private parentToolManager;
|
|
56
59
|
private parentMessageManager;
|
|
60
|
+
private taskManager;
|
|
57
61
|
private callbacks?;
|
|
58
62
|
private logger?;
|
|
59
63
|
private getGatewayConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagentManager.d.ts","sourceRoot":"","sources":["../../src/managers/subagentManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,E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AC,MAAM,CAAC;IAsEZ,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAkC/C,eAAe;IAwI7B;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAIxD;;OAEG;IACH,oBAAoB,CAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GACjC,IAAI;IAOP;;OAEG;IACH,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAOhE;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAYzC;;OAEG;IACH,kBAAkB,IAAI,gBAAgB,EAAE;IAOxC;;OAEG;IACH,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACG,uBAAuB,CAC3B,gBAAgB,EAAE,KAAK,CAAC;QACtB,WAAW,EAAE,WAAW,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,qBAAqB,CAAC;KACtC,CAAC,GACD,OAAO,CAAC,IAAI,CAAC;IAmFhB;;;OAGG;IACH,OAAO,CAAC,uBAAuB;CA8EhC"}
|
|
@@ -9,6 +9,7 @@ export class SubagentManager {
|
|
|
9
9
|
this.workdir = options.workdir;
|
|
10
10
|
this.parentToolManager = options.parentToolManager;
|
|
11
11
|
this.parentMessageManager = options.parentMessageManager;
|
|
12
|
+
this.taskManager = options.taskManager;
|
|
12
13
|
this.callbacks = options.callbacks; // Store SubagentManagerCallbacks
|
|
13
14
|
this.logger = options.logger;
|
|
14
15
|
this.getGatewayConfig = options.getGatewayConfig;
|
|
@@ -76,6 +77,7 @@ export class SubagentManager {
|
|
|
76
77
|
const aiManager = new AIManager({
|
|
77
78
|
messageManager,
|
|
78
79
|
toolManager,
|
|
80
|
+
taskManager: this.taskManager,
|
|
79
81
|
logger: this.logger,
|
|
80
82
|
workdir: this.workdir,
|
|
81
83
|
systemPrompt: configuration.systemPrompt,
|
|
@@ -153,6 +155,7 @@ export class SubagentManager {
|
|
|
153
155
|
description: instance.configuration.description,
|
|
154
156
|
stdout: "",
|
|
155
157
|
stderr: "",
|
|
158
|
+
onStop: () => instance.aiManager.abortAIMessage(),
|
|
156
159
|
});
|
|
157
160
|
instance.backgroundTaskId = taskId;
|
|
158
161
|
// Execute in background
|
|
@@ -208,6 +211,7 @@ export class SubagentManager {
|
|
|
208
211
|
description: instance.configuration.description,
|
|
209
212
|
stdout: "",
|
|
210
213
|
stderr: "",
|
|
214
|
+
onStop: () => instance.aiManager.abortAIMessage(),
|
|
211
215
|
});
|
|
212
216
|
instance.backgroundTaskId = taskId;
|
|
213
217
|
// Update parent message manager to reflect background status
|
|
@@ -219,24 +223,19 @@ export class SubagentManager {
|
|
|
219
223
|
async internalExecute(instance, prompt, abortSignal) {
|
|
220
224
|
// Set up consolidated abort handler to prevent listener accumulation
|
|
221
225
|
let abortCleanup;
|
|
222
|
-
if
|
|
226
|
+
// Only link to parent abort signal if NOT running in background
|
|
227
|
+
if (abortSignal && !instance.backgroundTaskId) {
|
|
223
228
|
abortCleanup = addConsolidatedAbortListener(abortSignal, [
|
|
224
229
|
() => {
|
|
225
230
|
// Update status to aborted
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
status: "aborted",
|
|
231
|
-
});
|
|
232
|
-
}
|
|
231
|
+
this.updateInstanceStatus(instance.subagentId, "aborted");
|
|
232
|
+
this.parentMessageManager.updateSubagentBlock(instance.subagentId, {
|
|
233
|
+
status: "aborted",
|
|
234
|
+
});
|
|
233
235
|
},
|
|
234
236
|
() => {
|
|
235
237
|
// Abort the AI execution
|
|
236
|
-
|
|
237
|
-
if (!instance.backgroundTaskId) {
|
|
238
|
-
instance.aiManager.abortAIMessage();
|
|
239
|
-
}
|
|
238
|
+
instance.aiManager.abortAIMessage();
|
|
240
239
|
},
|
|
241
240
|
]);
|
|
242
241
|
}
|
|
@@ -276,8 +275,6 @@ export class SubagentManager {
|
|
|
276
275
|
model: resolvedModel,
|
|
277
276
|
});
|
|
278
277
|
// If we have an abort signal, race against it using utilities to prevent listener accumulation
|
|
279
|
-
// BUT: If this is a background task, we DON'T want to race against the abort signal
|
|
280
|
-
// because the abort signal (Esc) should only stop the tool watching the task, not the task itself.
|
|
281
278
|
if (abortSignal && !instance.backgroundTaskId) {
|
|
282
279
|
await Promise.race([
|
|
283
280
|
executeAI,
|
|
@@ -424,6 +421,7 @@ export class SubagentManager {
|
|
|
424
421
|
const aiManager = new AIManager({
|
|
425
422
|
messageManager,
|
|
426
423
|
toolManager,
|
|
424
|
+
taskManager: this.taskManager,
|
|
427
425
|
logger: this.logger,
|
|
428
426
|
workdir: this.workdir,
|
|
429
427
|
systemPrompt: configuration.systemPrompt,
|
|
@@ -516,6 +514,16 @@ export class SubagentManager {
|
|
|
516
514
|
sessionId: newSessionId,
|
|
517
515
|
});
|
|
518
516
|
},
|
|
517
|
+
onLatestTotalTokensChange: (tokens) => {
|
|
518
|
+
// Forward latest total tokens to parent via SubagentManager callbacks
|
|
519
|
+
if (this.callbacks?.onSubagentLatestTotalTokensChange) {
|
|
520
|
+
this.callbacks.onSubagentLatestTotalTokensChange(subagentId, tokens);
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
onFileHistoryBlockAdded: (snapshots) => {
|
|
524
|
+
// Forward file history blocks to parent MessageManager
|
|
525
|
+
this.parentMessageManager.addFileHistoryBlock(snapshots);
|
|
526
|
+
},
|
|
519
527
|
};
|
|
520
528
|
}
|
|
521
529
|
}
|
|
@@ -14,6 +14,8 @@ export interface ToolManagerOptions {
|
|
|
14
14
|
permissionManager?: PermissionManager;
|
|
15
15
|
/** Foreground task manager for backgrounding tasks */
|
|
16
16
|
foregroundTaskManager?: import("../types/processes.js").IForegroundTaskManager;
|
|
17
|
+
/** Task manager for task management */
|
|
18
|
+
taskManager?: import("../services/taskManager.js").TaskManager;
|
|
17
19
|
/** Reversion manager for file snapshots */
|
|
18
20
|
reversionManager?: ReversionManager;
|
|
19
21
|
/** Background task manager for background execution */
|
|
@@ -37,6 +39,7 @@ declare class ToolManager {
|
|
|
37
39
|
private permissionManager?;
|
|
38
40
|
private foregroundTaskManager?;
|
|
39
41
|
private reversionManager?;
|
|
42
|
+
private taskManager?;
|
|
40
43
|
private backgroundTaskManager?;
|
|
41
44
|
private permissionMode?;
|
|
42
45
|
private canUseToolCallback?;
|
|
@@ -88,6 +91,10 @@ declare class ToolManager {
|
|
|
88
91
|
execute(name: string, args: Record<string, unknown>, context: ToolContext): Promise<ToolResult>;
|
|
89
92
|
list(): ToolPlugin[];
|
|
90
93
|
getToolsConfig(): ChatCompletionFunctionTool[];
|
|
94
|
+
/**
|
|
95
|
+
* Get the list of registered tool plugins
|
|
96
|
+
*/
|
|
97
|
+
getTools(): ToolPlugin[];
|
|
91
98
|
/**
|
|
92
99
|
* Get the current permission mode
|
|
93
100
|
*/
|
|
@@ -101,6 +108,10 @@ declare class ToolManager {
|
|
|
101
108
|
* Get the permission manager
|
|
102
109
|
*/
|
|
103
110
|
getPermissionManager(): PermissionManager | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Get the task manager
|
|
113
|
+
*/
|
|
114
|
+
getTaskManager(): import("../services/taskManager.js").TaskManager | undefined;
|
|
104
115
|
}
|
|
105
116
|
export { ToolManager };
|
|
106
117
|
//# sourceMappingURL=toolManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolManager.d.ts","sourceRoot":"","sources":["../../src/managers/toolManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"toolManager.d.ts","sourceRoot":"","sources":["../../src/managers/toolManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAA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,OAAO,CAAC,qBAAqB,CAAC,CAAyD;IACvF,OAAO,CAAC,gBAAgB,CAAC,CAAmB;IAC5C,OAAO,CAAC,WAAW,CAAC,CAAmD;IACvE,OAAO,CAAC,qBAAqB,CAAC,CAA6D;IAC3F,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,kBAAkB,CAAC,CAAqB;gBAEpC,OAAO,EAAE,kBAAkB;IAcvC;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAIvC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,sBAAsB,CAAC,IAAI,CAAC,EAAE;QACnC,eAAe,CAAC,EAAE,eAAe,CAAC;QAClC,YAAY,CAAC,EAAE,YAAY,CAAC;KAC7B,GAAG,IAAI;IAsCR;;;;;;;;;;;;OAYG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC;IAgEtB,IAAI,IAAI,UAAU,EAAE;IAMpB,cAAc,IAAI,0BAA0B,EAAE;IAmB9C;;OAEG;IACI,QAAQ,IAAI,UAAU,EAAE;IAI/B;;OAEG;IACI,iBAAiB,IAAI,cAAc;IAS1C;;;OAGG;IACI,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAIpD;;OAEG;IACI,oBAAoB,IAAI,iBAAiB,GAAG,SAAS;IAI5D;;OAEG;IACI,cAAc,IACjB,OAAO,4BAA4B,EAAE,WAAW,GAChD,SAAS;CAGd;AAGD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -12,10 +12,10 @@ import { globTool } from "../tools/globTool.js";
|
|
|
12
12
|
import { grepTool } from "../tools/grepTool.js";
|
|
13
13
|
import { lsTool } from "../tools/lsTool.js";
|
|
14
14
|
import { readTool } from "../tools/readTool.js";
|
|
15
|
-
import { todoWriteTool } from "../tools/todoWriteTool.js";
|
|
16
15
|
import { lspTool } from "../tools/lspTool.js";
|
|
17
16
|
import { createTaskTool } from "../tools/taskTool.js";
|
|
18
17
|
import { createSkillTool } from "../tools/skillTool.js";
|
|
18
|
+
import { taskCreateTool, taskGetTool, taskUpdateTool, taskListTool, } from "../tools/taskManagementTools.js";
|
|
19
19
|
/**
|
|
20
20
|
* Tool Manager
|
|
21
21
|
*
|
|
@@ -29,6 +29,7 @@ class ToolManager {
|
|
|
29
29
|
this.lspManager = options.lspManager;
|
|
30
30
|
this.logger = options.logger;
|
|
31
31
|
this.permissionManager = options.permissionManager;
|
|
32
|
+
this.taskManager = options.taskManager;
|
|
32
33
|
this.foregroundTaskManager = options.foregroundTaskManager;
|
|
33
34
|
this.reversionManager = options.reversionManager;
|
|
34
35
|
this.backgroundTaskManager = options.backgroundTaskManager;
|
|
@@ -80,8 +81,11 @@ class ToolManager {
|
|
|
80
81
|
grepTool,
|
|
81
82
|
lsTool,
|
|
82
83
|
readTool,
|
|
83
|
-
todoWriteTool,
|
|
84
84
|
lspTool,
|
|
85
|
+
taskCreateTool,
|
|
86
|
+
taskGetTool,
|
|
87
|
+
taskUpdateTool,
|
|
88
|
+
taskListTool,
|
|
85
89
|
];
|
|
86
90
|
for (const tool of builtInTools) {
|
|
87
91
|
this.tools.set(tool.name, tool);
|
|
@@ -120,11 +124,13 @@ class ToolManager {
|
|
|
120
124
|
permissionMode: effectivePermissionMode,
|
|
121
125
|
canUseToolCallback: this.canUseToolCallback,
|
|
122
126
|
permissionManager: this.permissionManager,
|
|
127
|
+
taskManager: this.taskManager,
|
|
123
128
|
reversionManager: this.reversionManager,
|
|
124
129
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
125
130
|
foregroundTaskManager: this.foregroundTaskManager,
|
|
126
131
|
mcpManager: this.mcpManager,
|
|
127
132
|
lspManager: this.lspManager,
|
|
133
|
+
sessionId: context.sessionId,
|
|
128
134
|
};
|
|
129
135
|
this.logger?.debug("Executing tool with enhanced context", {
|
|
130
136
|
toolName: name,
|
|
@@ -185,6 +191,12 @@ class ToolManager {
|
|
|
185
191
|
const mcpToolsConfig = this.mcpManager.getMcpToolsConfig();
|
|
186
192
|
return [...builtInToolsConfig, ...mcpToolsConfig];
|
|
187
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the list of registered tool plugins
|
|
196
|
+
*/
|
|
197
|
+
getTools() {
|
|
198
|
+
return Array.from(this.tools.values());
|
|
199
|
+
}
|
|
188
200
|
/**
|
|
189
201
|
* Get the current permission mode
|
|
190
202
|
*/
|
|
@@ -207,6 +219,12 @@ class ToolManager {
|
|
|
207
219
|
getPermissionManager() {
|
|
208
220
|
return this.permissionManager;
|
|
209
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Get the task manager
|
|
224
|
+
*/
|
|
225
|
+
getTaskManager() {
|
|
226
|
+
return this.taskManager;
|
|
227
|
+
}
|
|
210
228
|
}
|
|
211
229
|
// Export tool registry class and types
|
|
212
230
|
export { ToolManager };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAA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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA+S1B;AA4OD,MAAM,WAAW,uBAAuB;IAEtC,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,WAAW,CAAC;IAGzB,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IACvC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CAmEjC"}
|
|
@@ -4,33 +4,7 @@ import { transformMessagesForClaudeCache, addCacheControlToLastTool, isClaudeMod
|
|
|
4
4
|
import * as os from "os";
|
|
5
5
|
import * as fs from "fs";
|
|
6
6
|
import * as path from "path";
|
|
7
|
-
import {
|
|
8
|
-
/**
|
|
9
|
-
* Use parametersChunk as compact param for better performance
|
|
10
|
-
* Instead of parsing JSON, we use the raw chunk for efficient streaming
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Check if a directory is a git repository
|
|
14
|
-
* @param dirPath Directory path to check
|
|
15
|
-
* @returns "Yes" if it's a git repo, "No" otherwise
|
|
16
|
-
*/
|
|
17
|
-
function isGitRepository(dirPath) {
|
|
18
|
-
try {
|
|
19
|
-
// Check if .git directory exists in current directory or any parent directory
|
|
20
|
-
let currentPath = path.resolve(dirPath);
|
|
21
|
-
while (currentPath !== path.dirname(currentPath)) {
|
|
22
|
-
const gitPath = path.join(currentPath, ".git");
|
|
23
|
-
if (fs.existsSync(gitPath)) {
|
|
24
|
-
return "Yes";
|
|
25
|
-
}
|
|
26
|
-
currentPath = path.dirname(currentPath);
|
|
27
|
-
}
|
|
28
|
-
return "No";
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return "No";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
7
|
+
import { COMPRESS_MESSAGES_SYSTEM_PROMPT } from "../constants/prompts.js";
|
|
34
8
|
/**
|
|
35
9
|
* Get specific configuration parameters based on model name
|
|
36
10
|
* @param modelName Model name
|
|
@@ -58,7 +32,7 @@ function getModelConfig(modelName, baseConfig = {}) {
|
|
|
58
32
|
return config;
|
|
59
33
|
}
|
|
60
34
|
export async function callAgent(options) {
|
|
61
|
-
const { gatewayConfig, modelConfig, messages, abortSignal,
|
|
35
|
+
const { gatewayConfig, modelConfig, messages, abortSignal, workdir, tools, model, systemPrompt, onContentUpdate, onToolUpdate, onReasoningUpdate, } = options;
|
|
62
36
|
// Declare variables outside try block for error handling access
|
|
63
37
|
let openaiMessages;
|
|
64
38
|
let createParams;
|
|
@@ -73,23 +47,7 @@ export async function callAgent(options) {
|
|
|
73
47
|
fetch: gatewayConfig.fetch,
|
|
74
48
|
});
|
|
75
49
|
// Build system prompt content
|
|
76
|
-
|
|
77
|
-
// Always add environment information
|
|
78
|
-
systemContent += `
|
|
79
|
-
|
|
80
|
-
Here is useful information about the environment you are running in:
|
|
81
|
-
<env>
|
|
82
|
-
Working directory: ${workdir}
|
|
83
|
-
Is directory a git repo: ${isGitRepository(workdir)}
|
|
84
|
-
Platform: ${os.platform()}
|
|
85
|
-
OS Version: ${os.type()} ${os.release()}
|
|
86
|
-
Today's date: ${new Date().toISOString().split("T")[0]}
|
|
87
|
-
</env>
|
|
88
|
-
`;
|
|
89
|
-
// If there is memory content, add it to the system prompt
|
|
90
|
-
if (memory && memory.trim()) {
|
|
91
|
-
systemContent += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${memory}`;
|
|
92
|
-
}
|
|
50
|
+
const systemContent = systemPrompt || "";
|
|
93
51
|
// Add system prompt
|
|
94
52
|
const systemMessage = {
|
|
95
53
|
role: "system",
|
|
@@ -470,101 +428,7 @@ export async function compressMessages(options) {
|
|
|
470
428
|
messages: [
|
|
471
429
|
{
|
|
472
430
|
role: "system",
|
|
473
|
-
content:
|
|
474
|
-
This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
|
|
475
|
-
|
|
476
|
-
Before providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
|
|
477
|
-
|
|
478
|
-
1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
|
|
479
|
-
- The user's explicit requests and intents
|
|
480
|
-
- Your approach to addressing the user's requests
|
|
481
|
-
- Key decisions, technical concepts and code patterns
|
|
482
|
-
- Specific details like:
|
|
483
|
-
- file names
|
|
484
|
-
- full code snippets
|
|
485
|
-
- function signatures
|
|
486
|
-
- file edits
|
|
487
|
-
- Errors that you ran into and how you fixed them
|
|
488
|
-
- Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
489
|
-
2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
|
|
490
|
-
|
|
491
|
-
Your summary should include the following sections:
|
|
492
|
-
|
|
493
|
-
1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail
|
|
494
|
-
2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.
|
|
495
|
-
3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
|
|
496
|
-
4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received, especially if the user told you to do something differently.
|
|
497
|
-
5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
|
|
498
|
-
6. All user messages: List ALL user messages that are not tool results. These are critical for understanding the users' feedback and changing intent.
|
|
499
|
-
6. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
|
|
500
|
-
7. Current Work: Describe in detail precisely what was being worked on immediately before this summary request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
|
|
501
|
-
8. Optional Next Step: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's most recent explicit requests, and the task you were working on immediately before this summary request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests or really old requests that were already completed without confirming with the user first.
|
|
502
|
-
If there is a next step, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no drift in task interpretation.
|
|
503
|
-
|
|
504
|
-
Here's an example of how your output should be structured:
|
|
505
|
-
|
|
506
|
-
<example>
|
|
507
|
-
<analysis>
|
|
508
|
-
[Your thought process, ensuring all points are covered thoroughly and accurately]
|
|
509
|
-
</analysis>
|
|
510
|
-
|
|
511
|
-
<summary>
|
|
512
|
-
1. Primary Request and Intent:
|
|
513
|
-
[Detailed description]
|
|
514
|
-
|
|
515
|
-
2. Key Technical Concepts:
|
|
516
|
-
- [Concept 1]
|
|
517
|
-
- [Concept 2]
|
|
518
|
-
- [...]
|
|
519
|
-
|
|
520
|
-
3. Files and Code Sections:
|
|
521
|
-
- [File Name 1]
|
|
522
|
-
- [Summary of why this file is important]
|
|
523
|
-
- [Summary of the changes made to this file, if any]
|
|
524
|
-
- [Important Code Snippet]
|
|
525
|
-
- [File Name 2]
|
|
526
|
-
- [Important Code Snippet]
|
|
527
|
-
- [...]
|
|
528
|
-
|
|
529
|
-
4. Errors and fixes:
|
|
530
|
-
- [Detailed description of error 1]:
|
|
531
|
-
- [How you fixed the error]
|
|
532
|
-
- [User feedback on the error if any]
|
|
533
|
-
- [...]
|
|
534
|
-
|
|
535
|
-
5. Problem Solving:
|
|
536
|
-
[Description of solved problems and ongoing troubleshooting]
|
|
537
|
-
|
|
538
|
-
6. All user messages:
|
|
539
|
-
- [Detailed non tool use user message]
|
|
540
|
-
- [...]
|
|
541
|
-
|
|
542
|
-
7. Pending Tasks:
|
|
543
|
-
- [Task 1]
|
|
544
|
-
- [Task 2]
|
|
545
|
-
- [...]
|
|
546
|
-
|
|
547
|
-
8. Current Work:
|
|
548
|
-
[Precise description of current work]
|
|
549
|
-
|
|
550
|
-
9. Optional Next Step:
|
|
551
|
-
[Optional Next step to take]
|
|
552
|
-
|
|
553
|
-
</summary>
|
|
554
|
-
</example>
|
|
555
|
-
|
|
556
|
-
Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.
|
|
557
|
-
|
|
558
|
-
There may be additional summarization instructions provided in the included context. If so, remember to follow these instructions when creating the above summary. Examples of instructions include:
|
|
559
|
-
<example>
|
|
560
|
-
## Compact Instructions
|
|
561
|
-
When summarizing the conversation focus on typescript code changes and also remember the mistakes you made and how you fixed them.
|
|
562
|
-
</example>
|
|
563
|
-
|
|
564
|
-
<example>
|
|
565
|
-
# Summary instructions
|
|
566
|
-
When you are using compact - please focus on test output and code changes. Include file reads verbatim.
|
|
567
|
-
</example>`,
|
|
431
|
+
content: COMPRESS_MESSAGES_SYSTEM_PROMPT,
|
|
568
432
|
},
|
|
569
433
|
...messages,
|
|
570
434
|
{
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export declare const isMemoryMessage: (message: string) => boolean;
|
|
2
|
-
export declare const addMemory: (message: string, workdir: string) => Promise<void>;
|
|
3
1
|
export declare const ensureUserMemoryFile: () => Promise<void>;
|
|
4
|
-
export declare const addUserMemory: (message: string) => Promise<void>;
|
|
5
2
|
export declare const getUserMemoryContent: () => Promise<string>;
|
|
6
3
|
export declare const readMemoryFile: (workdir: string) => Promise<string>;
|
|
7
4
|
export declare const getCombinedMemoryContent: (workdir: string) => Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/services/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/services/memory.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,IAAI,CA4BzD,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,MAAM,CAa3D,CAAC;AAGF,eAAO,MAAM,cAAc,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAqBpE,CAAC;AAGF,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,KACd,OAAO,CAAC,MAAM,CAoBhB,CAAC"}
|
package/dist/services/memory.js
CHANGED
|
@@ -3,46 +3,6 @@ import path from "path";
|
|
|
3
3
|
import { USER_MEMORY_FILE, DATA_DIRECTORY } from "../utils/constants.js";
|
|
4
4
|
import { logger } from "../utils/globalLogger.js";
|
|
5
5
|
// Project memory related methods
|
|
6
|
-
export const isMemoryMessage = (message) => {
|
|
7
|
-
return message.trim().startsWith("#");
|
|
8
|
-
};
|
|
9
|
-
export const addMemory = async (message, workdir) => {
|
|
10
|
-
if (!isMemoryMessage(message)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
const memoryFilePath = path.join(workdir, "AGENTS.md");
|
|
15
|
-
// Format memory entry, starting with -, no timestamp
|
|
16
|
-
const memoryEntry = `- ${message.substring(1).trim()}\n`;
|
|
17
|
-
// Check if file exists
|
|
18
|
-
let existingContent = "";
|
|
19
|
-
try {
|
|
20
|
-
existingContent = await fs.readFile(memoryFilePath, "utf-8");
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
// File does not exist, create new file
|
|
24
|
-
if (error.code === "ENOENT") {
|
|
25
|
-
logger.info("Memory file does not exist, will create new one", {
|
|
26
|
-
memoryFilePath,
|
|
27
|
-
});
|
|
28
|
-
existingContent =
|
|
29
|
-
"# Memory\n\nThis is the AI assistant's memory file, recording important information and context.\n\n";
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// Append new memory entry to the end of the file
|
|
36
|
-
const updatedContent = existingContent + memoryEntry;
|
|
37
|
-
// Write file
|
|
38
|
-
await fs.writeFile(memoryFilePath, updatedContent, "utf-8");
|
|
39
|
-
logger.debug(`Memory added to ${memoryFilePath}:`, message);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
logger.error("Failed to add memory:", error);
|
|
43
|
-
throw new Error(`Failed to add memory: ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
6
|
// User memory related methods
|
|
47
7
|
export const ensureUserMemoryFile = async () => {
|
|
48
8
|
try {
|
|
@@ -72,25 +32,6 @@ export const ensureUserMemoryFile = async () => {
|
|
|
72
32
|
throw new Error(`Failed to ensure user memory file: ${error.message}`);
|
|
73
33
|
}
|
|
74
34
|
};
|
|
75
|
-
export const addUserMemory = async (message) => {
|
|
76
|
-
try {
|
|
77
|
-
// Ensure user memory file exists
|
|
78
|
-
await ensureUserMemoryFile();
|
|
79
|
-
// Format memory entry, starting with -
|
|
80
|
-
const memoryEntry = `- ${message.substring(1).trim()}\n`;
|
|
81
|
-
// Read existing content
|
|
82
|
-
const existingContent = await fs.readFile(USER_MEMORY_FILE, "utf-8");
|
|
83
|
-
// Append new memory entry to the end of the file
|
|
84
|
-
const updatedContent = existingContent + memoryEntry;
|
|
85
|
-
// Write file
|
|
86
|
-
await fs.writeFile(USER_MEMORY_FILE, updatedContent, "utf-8");
|
|
87
|
-
logger.debug(`User memory added to ${USER_MEMORY_FILE}:`, message);
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
logger.error("Failed to add user memory:", error);
|
|
91
|
-
throw new Error(`Failed to add user memory: ${error.message}`);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
35
|
export const getUserMemoryContent = async () => {
|
|
95
36
|
try {
|
|
96
37
|
await ensureUserMemoryFile();
|