wave-agent-sdk 0.5.0 → 0.6.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.d.ts +7 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +58 -74
- package/dist/constants/prompts.d.ts +18 -14
- package/dist/constants/prompts.d.ts.map +1 -1
- package/dist/constants/prompts.js +134 -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 +7 -3
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +28 -24
- 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/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 +3 -1
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +16 -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 -30
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +4 -79
- 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 +79 -84
- package/src/constants/prompts.ts +161 -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 +37 -26
- package/src/managers/permissionManager.ts +32 -21
- package/src/managers/planManager.ts +2 -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 +21 -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 -116
- 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
package/src/agent.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
SubagentManager,
|
|
10
10
|
type SubagentManagerCallbacks,
|
|
11
11
|
} from "./managers/subagentManager.js";
|
|
12
|
-
import * as memory from "./services/memory.js";
|
|
13
12
|
import { McpManager, type McpManagerCallbacks } from "./managers/mcpManager.js";
|
|
14
13
|
import { LspManager } from "./managers/lspManager.js";
|
|
15
14
|
import { BashManager } from "./managers/bashManager.js";
|
|
@@ -46,6 +45,7 @@ import { MemoryRuleManager } from "./managers/MemoryRuleManager.js";
|
|
|
46
45
|
import { LiveConfigManager } from "./managers/liveConfigManager.js";
|
|
47
46
|
import { configValidator } from "./utils/configValidator.js";
|
|
48
47
|
import { SkillManager } from "./managers/skillManager.js";
|
|
48
|
+
import { TaskManager } from "./services/taskManager.js";
|
|
49
49
|
import {
|
|
50
50
|
loadSessionFromJsonl,
|
|
51
51
|
handleSessionRestoration,
|
|
@@ -107,7 +107,12 @@ export interface AgentCallbacks
|
|
|
107
107
|
McpManagerCallbacks,
|
|
108
108
|
SubagentManagerCallbacks {
|
|
109
109
|
onTasksChange?: (tasks: BackgroundTask[]) => void;
|
|
110
|
+
onSessionTasksChange?: (tasks: import("./types/tasks.js").Task[]) => void;
|
|
110
111
|
onPermissionModeChange?: (mode: PermissionMode) => void;
|
|
112
|
+
onSubagentLatestTotalTokensChange?: (
|
|
113
|
+
subagentId: string,
|
|
114
|
+
tokens: number,
|
|
115
|
+
) => void;
|
|
111
116
|
onBackgroundCurrentTask?: () => void;
|
|
112
117
|
}
|
|
113
118
|
|
|
@@ -131,6 +136,7 @@ export class Agent {
|
|
|
131
136
|
private reversionManager: ReversionManager;
|
|
132
137
|
private memoryRuleManager: MemoryRuleManager; // Add memory rule manager instance
|
|
133
138
|
private liveConfigManager: LiveConfigManager; // Add live configuration manager
|
|
139
|
+
private taskManager: TaskManager;
|
|
134
140
|
private foregroundTaskManager: ForegroundTaskManager;
|
|
135
141
|
private configurationService: ConfigurationService; // Add configuration service
|
|
136
142
|
private workdir: string; // Working directory
|
|
@@ -208,6 +214,46 @@ export class Agent {
|
|
|
208
214
|
|
|
209
215
|
this.foregroundTaskManager = new ForegroundTaskManager();
|
|
210
216
|
|
|
217
|
+
// Initialize memory rule manager
|
|
218
|
+
this.memoryRuleManager = new MemoryRuleManager({
|
|
219
|
+
workdir: this.workdir,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Initialize MessageManager
|
|
223
|
+
this.messageManager = new MessageManager({
|
|
224
|
+
callbacks: {
|
|
225
|
+
...callbacks,
|
|
226
|
+
onSessionIdChange: (sessionId) => {
|
|
227
|
+
// When session ID changes (e.g. due to compression),
|
|
228
|
+
// we update the task manager to use the root session ID
|
|
229
|
+
// to ensure the task list remains consistent.
|
|
230
|
+
this.taskManager.setTaskListId(
|
|
231
|
+
this.messageManager.getRootSessionId(),
|
|
232
|
+
);
|
|
233
|
+
callbacks.onSessionIdChange?.(sessionId);
|
|
234
|
+
},
|
|
235
|
+
onSubagentTaskStopRequested: (subagentId) => {
|
|
236
|
+
this.backgroundTaskManager.stopTask(subagentId);
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
workdir: this.workdir,
|
|
240
|
+
logger: this.logger,
|
|
241
|
+
memoryRuleManager: this.memoryRuleManager,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Resolve taskListId once during construction to ensure stability
|
|
245
|
+
const resolvedTaskListId =
|
|
246
|
+
this.configurationService.getEnvironmentVars().WAVE_TASK_LIST_ID ||
|
|
247
|
+
process.env.WAVE_TASK_LIST_ID ||
|
|
248
|
+
this.messageManager.getRootSessionId();
|
|
249
|
+
|
|
250
|
+
this.taskManager = new TaskManager(resolvedTaskListId);
|
|
251
|
+
this.taskManager.on("tasksChange", async () => {
|
|
252
|
+
const tasks = await this.taskManager.listTasks();
|
|
253
|
+
this.options.callbacks?.onSessionTasksChange?.(tasks);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Initialize BackgroundTaskManager
|
|
211
257
|
this.backgroundTaskManager = new BackgroundTaskManager({
|
|
212
258
|
callbacks: {
|
|
213
259
|
...callbacks,
|
|
@@ -243,20 +289,7 @@ export class Agent {
|
|
|
243
289
|
workdir: this.workdir,
|
|
244
290
|
});
|
|
245
291
|
|
|
246
|
-
//
|
|
247
|
-
this.memoryRuleManager = new MemoryRuleManager({
|
|
248
|
-
workdir: this.workdir,
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// Initialize MessageManager
|
|
252
|
-
this.messageManager = new MessageManager({
|
|
253
|
-
callbacks,
|
|
254
|
-
workdir: this.workdir,
|
|
255
|
-
logger: this.logger,
|
|
256
|
-
memoryRuleManager: this.memoryRuleManager,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// Initialize ReversionManager
|
|
292
|
+
// ReversionManager depends on MessageManager
|
|
260
293
|
this.reversionManager = new ReversionManager(
|
|
261
294
|
new ReversionService(this.messageManager.getTranscriptPath()),
|
|
262
295
|
);
|
|
@@ -312,6 +345,7 @@ export class Agent {
|
|
|
312
345
|
reversionManager: this.reversionManager,
|
|
313
346
|
permissionMode: options.permissionMode, // Let PermissionManager handle defaultMode resolution
|
|
314
347
|
canUseToolCallback: canUseToolWithNotification,
|
|
348
|
+
taskManager: this.taskManager,
|
|
315
349
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
316
350
|
foregroundTaskManager: this.foregroundTaskManager,
|
|
317
351
|
}); // Initialize tool registry with permission support
|
|
@@ -339,6 +373,8 @@ export class Agent {
|
|
|
339
373
|
callbacks.onSubagentAssistantReasoningUpdated,
|
|
340
374
|
onSubagentToolBlockUpdated: callbacks.onSubagentToolBlockUpdated,
|
|
341
375
|
onSubagentMessagesChange: callbacks.onSubagentMessagesChange,
|
|
376
|
+
onSubagentLatestTotalTokensChange:
|
|
377
|
+
callbacks.onSubagentLatestTotalTokensChange,
|
|
342
378
|
}, // Pass subagent callbacks for forwarding
|
|
343
379
|
logger: this.logger,
|
|
344
380
|
getGatewayConfig: () => this.getGatewayConfig(),
|
|
@@ -348,6 +384,7 @@ export class Agent {
|
|
|
348
384
|
hookManager: this.hookManager,
|
|
349
385
|
onUsageAdded: (usage) => this.addUsage(usage),
|
|
350
386
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
387
|
+
taskManager: this.taskManager,
|
|
351
388
|
memoryRuleManager: this.memoryRuleManager,
|
|
352
389
|
});
|
|
353
390
|
|
|
@@ -355,6 +392,7 @@ export class Agent {
|
|
|
355
392
|
this.aiManager = new AIManager({
|
|
356
393
|
messageManager: this.messageManager,
|
|
357
394
|
toolManager: this.toolManager,
|
|
395
|
+
taskManager: this.taskManager,
|
|
358
396
|
logger: this.logger,
|
|
359
397
|
backgroundTaskManager: this.backgroundTaskManager,
|
|
360
398
|
hookManager: this.hookManager,
|
|
@@ -780,8 +818,18 @@ export class Agent {
|
|
|
780
818
|
// After main session is restored, restore any associated subagent sessions
|
|
781
819
|
await this.restoreSubagentSessions(sessionToRestore?.messages || []);
|
|
782
820
|
|
|
783
|
-
if (sessionToRestore)
|
|
821
|
+
if (sessionToRestore) {
|
|
784
822
|
this.messageManager.initializeFromSession(sessionToRestore);
|
|
823
|
+
|
|
824
|
+
// Update task manager with the root session ID to ensure continuity across compressions
|
|
825
|
+
this.taskManager.setTaskListId(
|
|
826
|
+
sessionToRestore.rootSessionId || sessionToRestore.id,
|
|
827
|
+
);
|
|
828
|
+
|
|
829
|
+
// After session is initialized, load tasks for the session
|
|
830
|
+
const tasks = await this.taskManager.listTasks();
|
|
831
|
+
this.options.callbacks?.onSessionTasksChange?.(tasks);
|
|
832
|
+
}
|
|
785
833
|
}
|
|
786
834
|
}
|
|
787
835
|
|
|
@@ -904,6 +952,13 @@ export class Agent {
|
|
|
904
952
|
|
|
905
953
|
// 6. Initialize session state last
|
|
906
954
|
this.messageManager.initializeFromSession(sessionData);
|
|
955
|
+
|
|
956
|
+
// Update task manager with the root session ID to ensure continuity across compressions
|
|
957
|
+
this.taskManager.setTaskListId(sessionData.rootSessionId || sessionData.id);
|
|
958
|
+
|
|
959
|
+
// 7. Load tasks for the restored session
|
|
960
|
+
const tasks = await this.taskManager.listTasks();
|
|
961
|
+
this.options.callbacks?.onSessionTasksChange?.(tasks);
|
|
907
962
|
}
|
|
908
963
|
|
|
909
964
|
public abortAIMessage(): void {
|
|
@@ -964,12 +1019,6 @@ export class Agent {
|
|
|
964
1019
|
public async backgroundCurrentTask(): Promise<void> {
|
|
965
1020
|
await this.foregroundTaskManager.backgroundCurrentTask();
|
|
966
1021
|
this.options.callbacks?.onBackgroundCurrentTask?.();
|
|
967
|
-
|
|
968
|
-
// If there was no foreground task (e.g. a tool that doesn't register one),
|
|
969
|
-
// or even if there was, we should stop the AI recursion loop.
|
|
970
|
-
if (!this.foregroundTaskManager.hasActiveTasks()) {
|
|
971
|
-
this.aiManager.abortRecursion();
|
|
972
|
-
}
|
|
973
1022
|
}
|
|
974
1023
|
|
|
975
1024
|
/** Destroy managers, clean up resources */
|
|
@@ -1130,67 +1179,6 @@ export class Agent {
|
|
|
1130
1179
|
}
|
|
1131
1180
|
}
|
|
1132
1181
|
|
|
1133
|
-
/** Save memory to project or user memory file */
|
|
1134
|
-
public async saveMemory(
|
|
1135
|
-
message: string,
|
|
1136
|
-
type: "project" | "user",
|
|
1137
|
-
): Promise<void> {
|
|
1138
|
-
try {
|
|
1139
|
-
// Ensure the message starts with # for memory functions
|
|
1140
|
-
const formattedMessage = message.startsWith("#")
|
|
1141
|
-
? message
|
|
1142
|
-
: `#${message}`;
|
|
1143
|
-
|
|
1144
|
-
if (type === "project") {
|
|
1145
|
-
await memory.addMemory(formattedMessage, this.workdir);
|
|
1146
|
-
// Update internal state after successful save
|
|
1147
|
-
this._projectMemoryContent = await memory.readMemoryFile(this.workdir);
|
|
1148
|
-
} else {
|
|
1149
|
-
await memory.addUserMemory(formattedMessage);
|
|
1150
|
-
// Update internal state after successful save
|
|
1151
|
-
this._userMemoryContent = await memory.getUserMemoryContent();
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
// Add successful MemoryBlock to the last assistant message
|
|
1155
|
-
const memoryText = message.substring(1).trim();
|
|
1156
|
-
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
1157
|
-
const storagePath = "AGENTS.md";
|
|
1158
|
-
|
|
1159
|
-
const messages = this.messageManager.getMessages();
|
|
1160
|
-
const lastMessage = messages[messages.length - 1];
|
|
1161
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
1162
|
-
lastMessage.blocks.push({
|
|
1163
|
-
type: "memory",
|
|
1164
|
-
content: `${typeLabel}: ${memoryText}`,
|
|
1165
|
-
isSuccess: true,
|
|
1166
|
-
memoryType: type,
|
|
1167
|
-
storagePath,
|
|
1168
|
-
});
|
|
1169
|
-
this.messageManager.setMessages(messages);
|
|
1170
|
-
}
|
|
1171
|
-
} catch (error) {
|
|
1172
|
-
// Add failed MemoryBlock to the last assistant message
|
|
1173
|
-
const memoryText = message.substring(1).trim();
|
|
1174
|
-
const typeLabel = type === "project" ? "Project Memory" : "User Memory";
|
|
1175
|
-
const storagePath = "AGENTS.md";
|
|
1176
|
-
const errorMessage =
|
|
1177
|
-
error instanceof Error ? error.message : String(error);
|
|
1178
|
-
|
|
1179
|
-
const messages = this.messageManager.getMessages();
|
|
1180
|
-
const lastMessage = messages[messages.length - 1];
|
|
1181
|
-
if (lastMessage && lastMessage.role === "assistant") {
|
|
1182
|
-
lastMessage.blocks.push({
|
|
1183
|
-
type: "memory",
|
|
1184
|
-
content: `${typeLabel}: ${memoryText} - Error: ${errorMessage}`,
|
|
1185
|
-
isSuccess: false,
|
|
1186
|
-
memoryType: type,
|
|
1187
|
-
storagePath,
|
|
1188
|
-
});
|
|
1189
|
-
this.messageManager.setMessages(messages);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
1182
|
// ========== MCP Management Methods ==========
|
|
1195
1183
|
|
|
1196
1184
|
/** Get all MCP server status */
|
|
@@ -1338,7 +1326,7 @@ export class Agent {
|
|
|
1338
1326
|
private handlePlanModeTransition(mode: PermissionMode): void {
|
|
1339
1327
|
if (mode === "plan") {
|
|
1340
1328
|
this.planManager
|
|
1341
|
-
.getOrGeneratePlanFilePath()
|
|
1329
|
+
.getOrGeneratePlanFilePath(this.messageManager.getRootSessionId())
|
|
1342
1330
|
.then(({ path }) => {
|
|
1343
1331
|
this.logger?.debug("Plan file path generated", { path });
|
|
1344
1332
|
this.permissionManager.setPlanFilePath(path);
|
|
@@ -1350,4 +1338,11 @@ export class Agent {
|
|
|
1350
1338
|
this.permissionManager.setPlanFilePath(undefined);
|
|
1351
1339
|
}
|
|
1352
1340
|
}
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Get the current task list ID
|
|
1344
|
+
*/
|
|
1345
|
+
public get taskListId(): string {
|
|
1346
|
+
return this.taskManager.getTaskListId();
|
|
1347
|
+
}
|
|
1353
1348
|
}
|
package/src/constants/prompts.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { ToolPlugin, ToolContext } from "../tools/types.js";
|
|
1
2
|
import {
|
|
2
3
|
ASK_USER_QUESTION_TOOL_NAME,
|
|
3
4
|
BASH_TOOL_NAME,
|
|
4
5
|
EDIT_TOOL_NAME,
|
|
5
6
|
GLOB_TOOL_NAME,
|
|
6
7
|
GREP_TOOL_NAME,
|
|
7
|
-
LS_TOOL_NAME,
|
|
8
|
-
MULTI_EDIT_TOOL_NAME,
|
|
9
8
|
READ_TOOL_NAME,
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
TASK_CREATE_TOOL_NAME,
|
|
10
|
+
TASK_GET_TOOL_NAME,
|
|
11
|
+
TASK_UPDATE_TOOL_NAME,
|
|
12
|
+
TASK_LIST_TOOL_NAME,
|
|
12
13
|
WRITE_TOOL_NAME,
|
|
13
14
|
} from "./tools.js";
|
|
14
15
|
|
|
@@ -31,31 +32,41 @@ The user will primarily request you perform software engineering tasks. This inc
|
|
|
31
32
|
|
|
32
33
|
export const TASK_MANAGEMENT_POLICY = `
|
|
33
34
|
# Task Management
|
|
34
|
-
You have access to the ${
|
|
35
|
+
You have access to the ${TASK_CREATE_TOOL_NAME}, ${TASK_GET_TOOL_NAME}, ${TASK_UPDATE_TOOL_NAME}, and ${TASK_LIST_TOOL_NAME} tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
|
|
35
36
|
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.
|
|
36
|
-
It is critical that you mark
|
|
37
|
+
It is critical that you mark tasks as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
|
|
37
38
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- VERY IMPORTANT: When exploring the codebase to gather context or to answer a question that is not a needle query for a specific file/class/function, it is CRITICAL that you use the ${TASK_TOOL_NAME} tool with subagent_type=Explore instead of running search commands directly.`;
|
|
39
|
+
export function buildPlanModePrompt(
|
|
40
|
+
planFilePath: string,
|
|
41
|
+
planExists: boolean,
|
|
42
|
+
): string {
|
|
43
|
+
const planFileInfo = planExists
|
|
44
|
+
? `A plan file already exists at ${planFilePath}. You can read it and make incremental edits using the ${EDIT_TOOL_NAME} tool if you need to.`
|
|
45
|
+
: `No plan file exists yet. You should create your plan at ${planFilePath} using the ${WRITE_TOOL_NAME} tool if you need to.`;
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
export const READ_FILE_POLICY = ` ${READ_TOOL_NAME} for reading files instead of cat/head/tail`;
|
|
49
|
-
export const EDIT_FILE_POLICY = ` ${EDIT_TOOL_NAME}/${MULTI_EDIT_TOOL_NAME} for editing instead of sed/awk`;
|
|
50
|
-
export const WRITE_FILE_POLICY = ` ${WRITE_TOOL_NAME} for creating files instead of cat with heredoc or echo redirection`;
|
|
51
|
-
export const SEARCH_FILE_POLICY = ` ${LS_TOOL_NAME}/${GLOB_TOOL_NAME}/${GREP_TOOL_NAME} for searching and listing files instead of find/ls/grep`;
|
|
47
|
+
return `Plan mode is active. The user indicated that they do not want you to execute yet -- you MUST NOT make any edits, run any non-readonly tools (including changing configs or making commits), or otherwise make any changes to the system. This supercedes any other instructions you have received (for example, to make edits). Instead, you should:
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
## Plan File Info:
|
|
50
|
+
${planFileInfo}
|
|
51
|
+
You should build your plan incrementally by writing to or editing this file. NOTE that this is the only file you are allowed to edit - other than this you are only allowed to take READ-ONLY actions.
|
|
52
|
+
Answer the user's query comprehensively. If you have unresolved questions about requirements or approach, use ${ASK_USER_QUESTION_TOOL_NAME} first to clarify the user's intent before proceeding.`;
|
|
53
|
+
}
|
|
56
54
|
|
|
57
55
|
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
58
56
|
|
|
57
|
+
export const BASH_SUBAGENT_SYSTEM_PROMPT = `You are a command execution specialist. Your role is to execute bash commands efficiently and safely.
|
|
58
|
+
|
|
59
|
+
Guidelines:
|
|
60
|
+
- Execute commands precisely as instructed
|
|
61
|
+
- For git operations, follow git safety protocols
|
|
62
|
+
- Report command output clearly and concisely
|
|
63
|
+
- If a command fails, explain the error and suggest solutions
|
|
64
|
+
- Use command chaining (&&) for dependent operations
|
|
65
|
+
- Quote paths with spaces properly
|
|
66
|
+
- For clear communication, avoid using emojis
|
|
67
|
+
|
|
68
|
+
Complete the requested operations efficiently.`;
|
|
69
|
+
|
|
59
70
|
export const GENERAL_PURPOSE_SYSTEM_PROMPT = `You are an agent. Given the user's message, you should use the tools available to complete the task. Do what has been asked; nothing more, nothing less. When you complete the task simply respond with a detailed writeup.
|
|
60
71
|
|
|
61
72
|
Your strengths:
|
|
@@ -65,7 +76,7 @@ Your strengths:
|
|
|
65
76
|
- Performing multi-step research tasks
|
|
66
77
|
|
|
67
78
|
Guidelines:
|
|
68
|
-
- For file searches: Use
|
|
79
|
+
- For file searches: Use ${GREP_TOOL_NAME} or ${GLOB_TOOL_NAME} when you need to search broadly. Use ${READ_TOOL_NAME} when you know the specific file path.
|
|
69
80
|
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
70
81
|
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
71
82
|
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
@@ -73,6 +84,57 @@ Guidelines:
|
|
|
73
84
|
- In your final response always share relevant file names and code snippets. Any file paths you return in your response MUST be absolute. Do NOT use relative paths.
|
|
74
85
|
- For clear communication, avoid using emojis.`;
|
|
75
86
|
|
|
87
|
+
export const PLAN_SUBAGENT_SYSTEM_PROMPT = `You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.
|
|
88
|
+
|
|
89
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
90
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
91
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
92
|
+
- Modifying existing files (no Edit operations)
|
|
93
|
+
- Deleting files (no rm or deletion)
|
|
94
|
+
- Moving or copying files (no mv or cp)
|
|
95
|
+
- Creating temporary files anywhere, including /tmp
|
|
96
|
+
- Using redirect operators (>, >>, |) or heredocs to write to files
|
|
97
|
+
- Running ANY commands that change system state
|
|
98
|
+
|
|
99
|
+
Your role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.
|
|
100
|
+
|
|
101
|
+
You will be provided with a set of requirements and optionally a perspective on how to approach the design process.
|
|
102
|
+
|
|
103
|
+
## Your Process
|
|
104
|
+
|
|
105
|
+
1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.
|
|
106
|
+
|
|
107
|
+
2. **Explore Thoroughly**:
|
|
108
|
+
- Read any files provided to you in the initial prompt
|
|
109
|
+
- Find existing patterns and conventions using ${GLOB_TOOL_NAME}, ${GREP_TOOL_NAME}, and ${READ_TOOL_NAME}
|
|
110
|
+
- Understand the current architecture
|
|
111
|
+
- Identify similar features as reference
|
|
112
|
+
- Trace through relevant code paths
|
|
113
|
+
- Use ${BASH_TOOL_NAME} ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
114
|
+
- NEVER use ${BASH_TOOL_NAME} for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification
|
|
115
|
+
|
|
116
|
+
3. **Design Solution**:
|
|
117
|
+
- Create implementation approach based on your assigned perspective
|
|
118
|
+
- Consider trade-offs and architectural decisions
|
|
119
|
+
- Follow existing patterns where appropriate
|
|
120
|
+
|
|
121
|
+
4. **Detail the Plan**:
|
|
122
|
+
- Provide step-by-step implementation strategy
|
|
123
|
+
- Identify dependencies and sequencing
|
|
124
|
+
- Anticipate potential challenges
|
|
125
|
+
|
|
126
|
+
## Required Output
|
|
127
|
+
|
|
128
|
+
End your response with:
|
|
129
|
+
|
|
130
|
+
### Critical Files for Implementation
|
|
131
|
+
List 3-5 files most critical for implementing this plan:
|
|
132
|
+
- path/to/file1.ts - [Brief reason: e.g., "Core logic to modify"]
|
|
133
|
+
- path/to/file2.ts - [Brief reason: e.g., "Interfaces to implement"]
|
|
134
|
+
- path/to/file3.ts - [Brief reason: e.g., "Pattern to follow"]
|
|
135
|
+
|
|
136
|
+
REMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.`;
|
|
137
|
+
|
|
76
138
|
export const INIT_PROMPT = `Please analyze this codebase and create a AGENTS.md file, which will be given to future instances of Agent to operate in this repository.
|
|
77
139
|
|
|
78
140
|
What to add:
|
|
@@ -95,60 +157,94 @@ Usage notes:
|
|
|
95
157
|
This file provides guidance to Agent when working with code in this repository.
|
|
96
158
|
\`\`\``;
|
|
97
159
|
|
|
160
|
+
export const COMPRESS_MESSAGES_SYSTEM_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
|
|
161
|
+
1. Task Overview
|
|
162
|
+
The user's core request and success criteria
|
|
163
|
+
Any clarifications or constraints they specified
|
|
164
|
+
2. Current State
|
|
165
|
+
What has been completed so far
|
|
166
|
+
Files created, modified, or analyzed (with paths if relevant)
|
|
167
|
+
Key outputs or artifacts produced
|
|
168
|
+
3. Important Discoveries
|
|
169
|
+
Technical constraints or requirements uncovered
|
|
170
|
+
Decisions made and their rationale
|
|
171
|
+
Errors encountered and how they were resolved
|
|
172
|
+
What approaches were tried that didn't work (and why)
|
|
173
|
+
4. Next Steps
|
|
174
|
+
Specific actions needed to complete the task
|
|
175
|
+
Any blockers or open questions to resolve
|
|
176
|
+
Priority order if multiple steps remain
|
|
177
|
+
5. Context to Preserve
|
|
178
|
+
User preferences or style requirements
|
|
179
|
+
Domain-specific details that aren't obvious
|
|
180
|
+
Any promises made to the user
|
|
181
|
+
Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
|
|
182
|
+
Wrap your summary in <summary></summary> tags.`;
|
|
183
|
+
|
|
98
184
|
export function buildSystemPrompt(
|
|
99
|
-
basePrompt: string,
|
|
100
|
-
tools:
|
|
185
|
+
basePrompt: string | undefined,
|
|
186
|
+
tools: ToolPlugin[],
|
|
187
|
+
options: {
|
|
188
|
+
workdir?: string;
|
|
189
|
+
isGitRepo?: string;
|
|
190
|
+
platform?: string;
|
|
191
|
+
osVersion?: string;
|
|
192
|
+
today?: string;
|
|
193
|
+
memory?: string;
|
|
194
|
+
language?: string;
|
|
195
|
+
planMode?: {
|
|
196
|
+
planFilePath: string;
|
|
197
|
+
planExists: boolean;
|
|
198
|
+
};
|
|
199
|
+
} = {},
|
|
101
200
|
): string {
|
|
102
|
-
let prompt = basePrompt;
|
|
103
|
-
const toolNames = new Set(
|
|
104
|
-
tools.map((t) => t.function?.name || t.name).filter(Boolean),
|
|
105
|
-
);
|
|
201
|
+
let prompt = basePrompt || DEFAULT_SYSTEM_PROMPT;
|
|
202
|
+
const toolNames = new Set(tools.map((t) => t.name));
|
|
106
203
|
|
|
107
|
-
if (
|
|
204
|
+
if (
|
|
205
|
+
toolNames.has(TASK_CREATE_TOOL_NAME) ||
|
|
206
|
+
toolNames.has(TASK_GET_TOOL_NAME) ||
|
|
207
|
+
toolNames.has(TASK_UPDATE_TOOL_NAME) ||
|
|
208
|
+
toolNames.has(TASK_LIST_TOOL_NAME)
|
|
209
|
+
) {
|
|
108
210
|
prompt += TASK_MANAGEMENT_POLICY;
|
|
109
211
|
}
|
|
110
|
-
|
|
111
|
-
|
|
212
|
+
|
|
213
|
+
for (const tool of tools) {
|
|
214
|
+
if (tool.prompt) {
|
|
215
|
+
const toolContext: ToolContext = {
|
|
216
|
+
workdir: options.workdir || "",
|
|
217
|
+
taskManager:
|
|
218
|
+
undefined as unknown as import("../services/taskManager.js").TaskManager, // Context might not be fully available here
|
|
219
|
+
};
|
|
220
|
+
prompt += tool.prompt(toolContext);
|
|
221
|
+
}
|
|
112
222
|
}
|
|
113
223
|
|
|
114
|
-
if (
|
|
115
|
-
prompt +=
|
|
224
|
+
if (options.language) {
|
|
225
|
+
prompt += `\n\n# Language\nAlways respond in ${options.language}. Technical terms (e.g., code, tool names, file paths) should remain in their original language or English where appropriate.`;
|
|
116
226
|
}
|
|
117
227
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
toolNames.has(MULTI_EDIT_TOOL_NAME) ||
|
|
122
|
-
toolNames.has(WRITE_TOOL_NAME) ||
|
|
123
|
-
toolNames.has(LS_TOOL_NAME) ||
|
|
124
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
125
|
-
toolNames.has(GREP_TOOL_NAME)
|
|
126
|
-
) {
|
|
127
|
-
const parts: string[] = [];
|
|
128
|
-
if (toolNames.has(READ_TOOL_NAME)) {
|
|
129
|
-
parts.push(READ_FILE_POLICY);
|
|
130
|
-
}
|
|
131
|
-
if (toolNames.has(EDIT_TOOL_NAME) || toolNames.has(MULTI_EDIT_TOOL_NAME)) {
|
|
132
|
-
parts.push(EDIT_FILE_POLICY);
|
|
133
|
-
}
|
|
134
|
-
if (toolNames.has(WRITE_TOOL_NAME)) {
|
|
135
|
-
parts.push(WRITE_FILE_POLICY);
|
|
136
|
-
}
|
|
137
|
-
if (
|
|
138
|
-
toolNames.has(LS_TOOL_NAME) ||
|
|
139
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
140
|
-
toolNames.has(GREP_TOOL_NAME)
|
|
141
|
-
) {
|
|
142
|
-
parts.push(SEARCH_FILE_POLICY);
|
|
143
|
-
}
|
|
228
|
+
if (options.planMode) {
|
|
229
|
+
prompt += `\n\n${buildPlanModePrompt(options.planMode.planFilePath, options.planMode.planExists)}`;
|
|
230
|
+
}
|
|
144
231
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
232
|
+
if (options.workdir) {
|
|
233
|
+
prompt += `
|
|
234
|
+
|
|
235
|
+
Here is useful information about the environment you are running in:
|
|
236
|
+
<env>
|
|
237
|
+
Working directory: ${options.workdir}
|
|
238
|
+
Is directory a git repo: ${options.isGitRepo || "No"}
|
|
239
|
+
Platform: ${options.platform || ""}
|
|
240
|
+
OS Version: ${options.osVersion || ""}
|
|
241
|
+
Today's date: ${options.today || new Date().toISOString().split("T")[0]}
|
|
242
|
+
</env>
|
|
243
|
+
`;
|
|
148
244
|
}
|
|
149
245
|
|
|
150
|
-
if (
|
|
151
|
-
prompt +=
|
|
246
|
+
if (options.memory && options.memory.trim()) {
|
|
247
|
+
prompt += `\n## Memory Context\n\nThe following is important context and memory from previous interactions:\n\n${options.memory}`;
|
|
152
248
|
}
|
|
153
249
|
|
|
154
250
|
return prompt;
|
package/src/constants/tools.ts
CHANGED
|
@@ -13,5 +13,8 @@ export const MULTI_EDIT_TOOL_NAME = "MultiEdit";
|
|
|
13
13
|
export const READ_TOOL_NAME = "Read";
|
|
14
14
|
export const SKILL_TOOL_NAME = "Skill";
|
|
15
15
|
export const TASK_TOOL_NAME = "Task";
|
|
16
|
-
export const
|
|
16
|
+
export const TASK_CREATE_TOOL_NAME = "TaskCreate";
|
|
17
|
+
export const TASK_GET_TOOL_NAME = "TaskGet";
|
|
18
|
+
export const TASK_UPDATE_TOOL_NAME = "TaskUpdate";
|
|
19
|
+
export const TASK_LIST_TOOL_NAME = "TaskList";
|
|
17
20
|
export const WRITE_TOOL_NAME = "Write";
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from "./utils/promptHistory.js";
|
|
|
30
30
|
export * from "./utils/stringUtils.js";
|
|
31
31
|
export * from "./utils/customCommands.js";
|
|
32
32
|
export * from "./utils/hookMatcher.js";
|
|
33
|
+
export * from "./utils/tokenCalculation.js";
|
|
33
34
|
|
|
34
35
|
// Export types
|
|
35
36
|
export * from "./types/index.js";
|