wave-agent-sdk 0.5.0 → 0.6.2
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 -11
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +64 -151
- package/dist/constants/subagents.d.ts +5 -0
- package/dist/constants/subagents.d.ts.map +1 -0
- package/dist/constants/subagents.js +4 -0
- 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 +43 -48
- package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
- package/dist/managers/backgroundTaskManager.js +63 -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 +13 -27
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +94 -89
- 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/reversionManager.d.ts.map +1 -1
- package/dist/managers/reversionManager.js +23 -2
- package/dist/managers/slashCommandManager.d.ts +3 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +8 -3
- package/dist/managers/subagentManager.d.ts +8 -14
- package/dist/managers/subagentManager.d.ts.map +1 -1
- package/dist/managers/subagentManager.js +46 -112
- 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/{constants/prompts.d.ts → prompts/index.d.ts} +17 -15
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +309 -0
- 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 +25 -0
- package/dist/services/taskManager.d.ts.map +1 -0
- package/dist/services/taskManager.js +164 -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 +13 -11
- 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 +26 -2
- 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 +461 -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 +37 -2
- package/dist/tools/types.d.ts +11 -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 -18
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/types/processes.d.ts +16 -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 +59 -44
- 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/editUtils.d.ts.map +1 -1
- package/dist/utils/editUtils.js +2 -2
- package/dist/utils/gitUtils.d.ts +7 -0
- package/dist/utils/gitUtils.d.ts.map +1 -0
- package/dist/utils/gitUtils.js +24 -0
- package/dist/utils/messageOperations.d.ts +3 -58
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +4 -146
- 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 +86 -183
- package/src/constants/subagents.ts +4 -0
- package/src/constants/tools.ts +4 -1
- package/src/index.ts +1 -0
- package/src/managers/aiManager.ts +63 -70
- package/src/managers/backgroundTaskManager.ts +58 -54
- package/src/managers/foregroundTaskManager.ts +3 -2
- package/src/managers/mcpManager.ts +6 -3
- package/src/managers/messageManager.ts +126 -142
- package/src/managers/permissionManager.ts +32 -21
- package/src/managers/planManager.ts +2 -2
- package/src/managers/reversionManager.ts +26 -2
- package/src/managers/slashCommandManager.ts +12 -3
- package/src/managers/subagentManager.ts +60 -144
- package/src/managers/toolManager.ts +32 -2
- package/src/prompts/index.ts +366 -0
- 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 +195 -0
- package/src/tools/askUserQuestion.ts +51 -29
- package/src/tools/bashTool.ts +15 -17
- package/src/tools/editTool.ts +3 -1
- package/src/tools/exitPlanMode.ts +27 -3
- 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 +516 -0
- package/src/tools/taskOutputTool.ts +34 -12
- package/src/tools/taskStopTool.ts +7 -1
- package/src/tools/taskTool.ts +45 -1
- package/src/tools/types.ts +12 -0
- package/src/tools/writeTool.ts +9 -2
- package/src/types/index.ts +1 -0
- package/src/types/messaging.ts +1 -21
- package/src/types/processes.ts +18 -7
- package/src/types/tasks.ts +13 -0
- package/src/types/tools.ts +4 -1
- package/src/utils/builtinSubagents.ts +81 -45
- package/src/utils/cacheControlUtils.ts +26 -18
- package/src/utils/constants.ts +0 -5
- package/src/utils/convertMessagesForAPI.ts +2 -2
- package/src/utils/editUtils.ts +2 -6
- package/src/utils/gitUtils.ts +24 -0
- package/src/utils/messageOperations.ts +6 -229
- package/src/utils/nameGenerator.ts +20 -3
- package/dist/constants/prompts.d.ts.map +0 -1
- package/dist/constants/prompts.js +0 -118
- 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/constants/prompts.ts +0 -155
- package/src/tools/todoWriteTool.ts +0 -257
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import * as fsSync from "node:fs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if a directory is a git repository
|
|
6
|
+
* @param dirPath Directory path
|
|
7
|
+
* @returns "Yes" if it's a git repository, "No" otherwise
|
|
8
|
+
*/
|
|
9
|
+
export function isGitRepository(dirPath: string): string {
|
|
10
|
+
try {
|
|
11
|
+
// Check if .git directory exists in current directory or any parent directory
|
|
12
|
+
let currentPath = path.resolve(dirPath);
|
|
13
|
+
while (currentPath !== path.dirname(currentPath)) {
|
|
14
|
+
const gitPath = path.join(currentPath, ".git");
|
|
15
|
+
if (fsSync.existsSync(gitPath)) {
|
|
16
|
+
return "Yes";
|
|
17
|
+
}
|
|
18
|
+
currentPath = path.dirname(currentPath);
|
|
19
|
+
}
|
|
20
|
+
return "No";
|
|
21
|
+
} catch {
|
|
22
|
+
return "No";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Message, Usage } from "../types/index.js";
|
|
2
2
|
import { MessageSource } from "../types/index.js";
|
|
3
|
-
import { DEFAULT_KEEP_LAST_MESSAGES_COUNT } from "./constants.js";
|
|
4
|
-
import type { SubagentConfiguration } from "./subagentParser.js";
|
|
5
3
|
import { readFileSync } from "fs";
|
|
6
4
|
import { extname } from "path";
|
|
7
5
|
import { ChatCompletionMessageFunctionToolCall } from "openai/resources.js";
|
|
@@ -23,7 +21,7 @@ export interface AddUserMessageParams extends UserMessageParams {
|
|
|
23
21
|
export interface UpdateToolBlockParams {
|
|
24
22
|
messages: Message[];
|
|
25
23
|
id: string;
|
|
26
|
-
parameters
|
|
24
|
+
parameters?: string;
|
|
27
25
|
result?: string;
|
|
28
26
|
success?: boolean;
|
|
29
27
|
error?: string;
|
|
@@ -40,6 +38,7 @@ export interface UpdateToolBlockParams {
|
|
|
40
38
|
images?: Array<{ data: string; mediaType?: string }>;
|
|
41
39
|
compactParams?: string;
|
|
42
40
|
parametersChunk?: string; // Incremental parameter updates for streaming
|
|
41
|
+
isManuallyBackgrounded?: boolean;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
// Agent specific interfaces (without messages parameter)
|
|
@@ -53,14 +52,6 @@ export interface AddErrorBlockParams {
|
|
|
53
52
|
error: string;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
export interface AddMemoryBlockParams {
|
|
57
|
-
messages: Message[];
|
|
58
|
-
content: string;
|
|
59
|
-
isSuccess: boolean;
|
|
60
|
-
memoryType?: "project" | "user";
|
|
61
|
-
storagePath?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
55
|
export interface AddCommandOutputParams {
|
|
65
56
|
messages: Message[];
|
|
66
57
|
command: string;
|
|
@@ -78,26 +69,6 @@ export interface CompleteCommandParams {
|
|
|
78
69
|
exitCode: number;
|
|
79
70
|
}
|
|
80
71
|
|
|
81
|
-
/**
|
|
82
|
-
* Extract text content from user messages in the messages array
|
|
83
|
-
* Excludes messages with source HOOK to prevent hook-generated content from entering user history
|
|
84
|
-
*/
|
|
85
|
-
export const extractUserInputHistory = (messages: Message[]): string[] => {
|
|
86
|
-
return messages
|
|
87
|
-
.filter((message) => message.role === "user")
|
|
88
|
-
.map((message) => {
|
|
89
|
-
// Extract text block content, excluding HOOK-sourced blocks
|
|
90
|
-
const textBlocks = message.blocks.filter(
|
|
91
|
-
(block) => block.type === "text" && block.source !== MessageSource.HOOK,
|
|
92
|
-
);
|
|
93
|
-
return textBlocks
|
|
94
|
-
.map((block) => (block as { content: string }).content)
|
|
95
|
-
.join(" ")
|
|
96
|
-
.trim();
|
|
97
|
-
})
|
|
98
|
-
.filter((text) => text.length > 0); // Filter out empty text
|
|
99
|
-
};
|
|
100
|
-
|
|
101
72
|
/**
|
|
102
73
|
* Convert image file path to base64 format
|
|
103
74
|
* @param imagePath Image file path
|
|
@@ -230,6 +201,7 @@ export const updateToolBlockInMessage = ({
|
|
|
230
201
|
images,
|
|
231
202
|
compactParams,
|
|
232
203
|
parametersChunk,
|
|
204
|
+
isManuallyBackgrounded,
|
|
233
205
|
}: UpdateToolBlockParams): Message[] => {
|
|
234
206
|
const newMessages = [...messages];
|
|
235
207
|
// Find the last assistant message
|
|
@@ -253,6 +225,8 @@ export const updateToolBlockInMessage = ({
|
|
|
253
225
|
toolBlock.compactParams = compactParams;
|
|
254
226
|
if (parametersChunk !== undefined)
|
|
255
227
|
toolBlock.parametersChunk = parametersChunk;
|
|
228
|
+
if (isManuallyBackgrounded !== undefined)
|
|
229
|
+
toolBlock.isManuallyBackgrounded = isManuallyBackgrounded;
|
|
256
230
|
}
|
|
257
231
|
} else {
|
|
258
232
|
// If existing block not found, create new one
|
|
@@ -270,6 +244,7 @@ export const updateToolBlockInMessage = ({
|
|
|
270
244
|
stage: stage ?? "start",
|
|
271
245
|
compactParams: compactParams,
|
|
272
246
|
parametersChunk: parametersChunk,
|
|
247
|
+
isManuallyBackgrounded: isManuallyBackgrounded,
|
|
273
248
|
});
|
|
274
249
|
}
|
|
275
250
|
break;
|
|
@@ -315,113 +290,6 @@ export const addErrorBlockToMessage = ({
|
|
|
315
290
|
return newMessages;
|
|
316
291
|
};
|
|
317
292
|
|
|
318
|
-
// Add Memory Block as new assistant message
|
|
319
|
-
export const addMemoryBlockToMessage = ({
|
|
320
|
-
messages,
|
|
321
|
-
content,
|
|
322
|
-
isSuccess,
|
|
323
|
-
memoryType,
|
|
324
|
-
storagePath,
|
|
325
|
-
}: AddMemoryBlockParams): Message[] => {
|
|
326
|
-
const newMessages = [...messages];
|
|
327
|
-
|
|
328
|
-
// Create new assistant message containing MemoryBlock
|
|
329
|
-
const memoryMessage: Message = {
|
|
330
|
-
role: "assistant",
|
|
331
|
-
blocks: [
|
|
332
|
-
{
|
|
333
|
-
type: "memory",
|
|
334
|
-
content,
|
|
335
|
-
isSuccess,
|
|
336
|
-
memoryType,
|
|
337
|
-
storagePath,
|
|
338
|
-
},
|
|
339
|
-
],
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
// Add to end of message list
|
|
343
|
-
newMessages.push(memoryMessage);
|
|
344
|
-
return newMessages;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Count valid blocks from the end
|
|
349
|
-
* Only text, image, and tool type blocks are counted
|
|
350
|
-
* @param messages Message array
|
|
351
|
-
* @param targetCount Number of valid blocks to count
|
|
352
|
-
* @returns { messageIndex: number, blockCount: number } Message index and actual counted block count
|
|
353
|
-
*/
|
|
354
|
-
export const countValidBlocksFromEnd = (
|
|
355
|
-
messages: Message[],
|
|
356
|
-
targetCount: number,
|
|
357
|
-
): { messageIndex: number; blockCount: number } => {
|
|
358
|
-
let validBlockCount = 0;
|
|
359
|
-
|
|
360
|
-
// Iterate messages from end to beginning
|
|
361
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
362
|
-
const message = messages[i];
|
|
363
|
-
|
|
364
|
-
// Iterate through all blocks of current message
|
|
365
|
-
for (const block of message.blocks) {
|
|
366
|
-
// Only count valid block types
|
|
367
|
-
if (
|
|
368
|
-
block.type === "text" ||
|
|
369
|
-
block.type === "image" ||
|
|
370
|
-
block.type === "tool"
|
|
371
|
-
) {
|
|
372
|
-
validBlockCount++;
|
|
373
|
-
|
|
374
|
-
// If target count reached, return current message index
|
|
375
|
-
if (validBlockCount >= targetCount) {
|
|
376
|
-
return { messageIndex: i, blockCount: validBlockCount };
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// If target count not reached, return index 0
|
|
383
|
-
return { messageIndex: 0, blockCount: validBlockCount };
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Get messages to be compressed and insertion position
|
|
388
|
-
* @param messages Message array
|
|
389
|
-
* @param keepLastCount Keep the last few valid blocks uncompressed
|
|
390
|
-
* @returns { messagesToCompress: Message[], insertIndex: number }
|
|
391
|
-
*/
|
|
392
|
-
export const getMessagesToCompress = (
|
|
393
|
-
messages: Message[],
|
|
394
|
-
keepLastCount: number = DEFAULT_KEEP_LAST_MESSAGES_COUNT,
|
|
395
|
-
): { messagesToCompress: Message[]; insertIndex: number } => {
|
|
396
|
-
// Calculate message position to keep from end to beginning
|
|
397
|
-
const { messageIndex } = countValidBlocksFromEnd(messages, keepLastCount);
|
|
398
|
-
|
|
399
|
-
// Find the last message containing compression block
|
|
400
|
-
let lastCompressIndex = -1;
|
|
401
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
402
|
-
const hasCompressBlock = messages[i].blocks.some(
|
|
403
|
-
(block) => block.type === "compress",
|
|
404
|
-
);
|
|
405
|
-
if (hasCompressBlock) {
|
|
406
|
-
lastCompressIndex = i;
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Determine compression start position
|
|
412
|
-
// If compression block exists, start from compression block position (include compression block)
|
|
413
|
-
// If no compression block, start from beginning
|
|
414
|
-
const startIndex = lastCompressIndex >= 0 ? lastCompressIndex : 0;
|
|
415
|
-
|
|
416
|
-
// Messages to compress are all messages from start position to before calculated position
|
|
417
|
-
const messagesToCompress = messages.slice(startIndex, messageIndex);
|
|
418
|
-
|
|
419
|
-
// Change insertion position to negative number, indicating position from end
|
|
420
|
-
const insertIndex = messageIndex - messages.length;
|
|
421
|
-
|
|
422
|
-
return { messagesToCompress, insertIndex };
|
|
423
|
-
};
|
|
424
|
-
|
|
425
293
|
// Add command output block to message list
|
|
426
294
|
export const addCommandOutputMessage = ({
|
|
427
295
|
messages,
|
|
@@ -496,97 +364,6 @@ export const completeCommandInMessage = ({
|
|
|
496
364
|
return newMessages;
|
|
497
365
|
};
|
|
498
366
|
|
|
499
|
-
// Subagent block message operations
|
|
500
|
-
export interface AddSubagentBlockParams {
|
|
501
|
-
messages: Message[];
|
|
502
|
-
subagentId: string;
|
|
503
|
-
subagentName: string;
|
|
504
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
505
|
-
sessionId: string;
|
|
506
|
-
configuration: SubagentConfiguration;
|
|
507
|
-
runInBackground?: boolean;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
export interface UpdateSubagentBlockParams {
|
|
511
|
-
messages: Message[];
|
|
512
|
-
subagentId: string;
|
|
513
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
514
|
-
sessionId?: string;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
export const addSubagentBlockToMessage = ({
|
|
518
|
-
messages,
|
|
519
|
-
subagentId,
|
|
520
|
-
subagentName,
|
|
521
|
-
status,
|
|
522
|
-
sessionId,
|
|
523
|
-
configuration,
|
|
524
|
-
runInBackground,
|
|
525
|
-
}: AddSubagentBlockParams): Message[] => {
|
|
526
|
-
const newMessages = [...messages];
|
|
527
|
-
|
|
528
|
-
// Find the last assistant message or create one
|
|
529
|
-
let lastAssistantMessage = newMessages[newMessages.length - 1];
|
|
530
|
-
|
|
531
|
-
if (!lastAssistantMessage || lastAssistantMessage.role !== "assistant") {
|
|
532
|
-
// Create new assistant message if the last message is not from assistant
|
|
533
|
-
lastAssistantMessage = {
|
|
534
|
-
id: `msg-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
|
|
535
|
-
role: "assistant",
|
|
536
|
-
blocks: [],
|
|
537
|
-
};
|
|
538
|
-
newMessages.push(lastAssistantMessage);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// Add subagent block
|
|
542
|
-
lastAssistantMessage.blocks.push({
|
|
543
|
-
type: "subagent",
|
|
544
|
-
subagentId,
|
|
545
|
-
subagentName,
|
|
546
|
-
status,
|
|
547
|
-
sessionId,
|
|
548
|
-
configuration,
|
|
549
|
-
runInBackground,
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
return newMessages;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
export const updateSubagentBlockInMessage = (
|
|
556
|
-
messages: Message[],
|
|
557
|
-
subagentId: string,
|
|
558
|
-
updates: Partial<{
|
|
559
|
-
status: "active" | "completed" | "error" | "aborted";
|
|
560
|
-
sessionId: string;
|
|
561
|
-
runInBackground: boolean;
|
|
562
|
-
}>,
|
|
563
|
-
): Message[] => {
|
|
564
|
-
const newMessages = [...messages];
|
|
565
|
-
|
|
566
|
-
// Find and update the subagent block
|
|
567
|
-
for (let i = newMessages.length - 1; i >= 0; i--) {
|
|
568
|
-
const message = newMessages[i];
|
|
569
|
-
if (message.role === "assistant") {
|
|
570
|
-
for (const block of message.blocks) {
|
|
571
|
-
if (block.type === "subagent" && block.subagentId === subagentId) {
|
|
572
|
-
if (updates.status !== undefined) {
|
|
573
|
-
block.status = updates.status;
|
|
574
|
-
}
|
|
575
|
-
if (updates.sessionId !== undefined) {
|
|
576
|
-
block.sessionId = updates.sessionId;
|
|
577
|
-
}
|
|
578
|
-
if (updates.runInBackground !== undefined) {
|
|
579
|
-
block.runInBackground = updates.runInBackground;
|
|
580
|
-
}
|
|
581
|
-
return newMessages;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return newMessages;
|
|
588
|
-
};
|
|
589
|
-
|
|
590
367
|
/**
|
|
591
368
|
* Removes the last user message from the messages array
|
|
592
369
|
* Used for hook error handling when the user prompt needs to be erased
|
|
@@ -71,8 +71,25 @@ const nouns = [
|
|
|
71
71
|
/**
|
|
72
72
|
* Generates a random English name (adjective-noun)
|
|
73
73
|
*/
|
|
74
|
-
export function generateRandomName(): string {
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
export function generateRandomName(seed?: string): string {
|
|
75
|
+
let adjIndex: number;
|
|
76
|
+
let nounIndex: number;
|
|
77
|
+
|
|
78
|
+
if (seed) {
|
|
79
|
+
// Simple hash function to derive indices from seed
|
|
80
|
+
let hash = 0;
|
|
81
|
+
for (let i = 0; i < seed.length; i++) {
|
|
82
|
+
hash = (hash << 5) - hash + seed.charCodeAt(i);
|
|
83
|
+
hash |= 0; // Convert to 32bit integer
|
|
84
|
+
}
|
|
85
|
+
adjIndex = Math.abs(hash) % adjectives.length;
|
|
86
|
+
nounIndex = Math.abs(hash >> 8) % nouns.length;
|
|
87
|
+
} else {
|
|
88
|
+
adjIndex = Math.floor(Math.random() * adjectives.length);
|
|
89
|
+
nounIndex = Math.floor(Math.random() * nouns.length);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const adj = adjectives[adjIndex];
|
|
93
|
+
const noun = nouns[nounIndex];
|
|
77
94
|
return `${adj}-${noun}`;
|
|
78
95
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/constants/prompts.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,kBAAkB,ksFAe8G,CAAC;AAE9I,eAAO,MAAM,sBAAsB,+lBAImH,CAAC;AAEvJ,eAAO,MAAM,eAAe,mVAEgS,CAAC;AAE7T,eAAO,MAAM,eAAe,meAG0P,CAAC;AAEvR,eAAO,MAAM,uBAAuB,2JAA2J,CAAC;AAChM,eAAO,MAAM,gBAAgB,qDAAkE,CAAC;AAChG,eAAO,MAAM,gBAAgB,mDAA8E,CAAC;AAC5G,eAAO,MAAM,iBAAiB,8EAA2F,CAAC;AAC1H,eAAO,MAAM,kBAAkB,0EAAiH,CAAC;AAEjJ,eAAO,MAAM,WAAW,sjBAE4O,CAAC;AAErQ,eAAO,MAAM,qBAAqB,ksFAAqB,CAAC;AAExD,eAAO,MAAM,6BAA6B,izCAeK,CAAC;AAEhD,eAAO,MAAM,WAAW,kkDAoBjB,CAAC;AAER,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EAAE,GACtD,MAAM,CAsDR"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { ASK_USER_QUESTION_TOOL_NAME, BASH_TOOL_NAME, EDIT_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME, LS_TOOL_NAME, MULTI_EDIT_TOOL_NAME, READ_TOOL_NAME, TASK_TOOL_NAME, TODO_WRITE_TOOL_NAME, WRITE_TOOL_NAME, } from "./tools.js";
|
|
2
|
-
export const BASE_SYSTEM_PROMPT = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
3
|
-
|
|
4
|
-
# Doing tasks
|
|
5
|
-
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
6
|
-
- NEVER propose changes to code you haven't read. If a user asks about or wants you to modify a file, read it first. Understand existing code before suggesting modifications.
|
|
7
|
-
- Be careful not to introduce security vulnerabilities such as command injection, XSS, SQL injection, and other OWASP top 10 vulnerabilities. If you notice that you wrote insecure code, immediately fix it.
|
|
8
|
-
- Avoid over-engineering. Only make changes that are directly requested or clearly necessary. Keep solutions simple and focused.
|
|
9
|
-
- Don't add features, refactor code, or make "improvements" beyond what was asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need extra configurability. Don't add docstrings, comments, or type annotations to code you didn't change. Only add comments where the logic isn't self-evident.
|
|
10
|
-
- Don't add error handling, fallbacks, or validation for scenarios that can't happen. Trust internal code and framework guarantees. Only validate at system boundaries (user input, external APIs). Don't use feature flags or backwards-compatibility shims when you can just change the code.
|
|
11
|
-
- Don't create helpers, utilities, or abstractions for one-time operations. Don't design for hypothetical future requirements. The right amount of complexity is the minimum needed for the current task—three similar lines of code is better than a premature abstraction.
|
|
12
|
-
- Avoid backwards-compatibility hacks like renaming unused \`_vars\`, re-exporting types, adding \`// removed\` comments for removed code, etc. If something is unused, delete it completely.
|
|
13
|
-
|
|
14
|
-
# Tool usage policy
|
|
15
|
-
- You can call multiple tools in a single response. If you intend to call multiple tools and there are no dependencies between them, make all independent tool calls in parallel. Maximize use of parallel tool calls where possible to increase efficiency.
|
|
16
|
-
- However, if some tool calls depend on previous calls to inform dependent values, do NOT call these tools in parallel and instead call them sequentially. For instance, if one operation must complete before another starts, run these operations sequentially instead. Never use placeholders or guess missing parameters in tool calls.
|
|
17
|
-
- If the user specifies that they want you to run tools "in parallel", you MUST send a single message with multiple tool use content blocks.`;
|
|
18
|
-
export const TASK_MANAGEMENT_POLICY = `
|
|
19
|
-
# Task Management
|
|
20
|
-
You have access to the ${TODO_WRITE_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.
|
|
21
|
-
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.
|
|
22
|
-
It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.`;
|
|
23
|
-
export const ASK_USER_POLICY = `
|
|
24
|
-
# Asking questions as you work
|
|
25
|
-
You have access to the ${ASK_USER_QUESTION_TOOL_NAME} tool to ask the user questions when you need clarification, want to validate assumptions, or need to make a decision you're unsure about. When presenting options or plans, never include time estimates - focus on what each option involves, not how long it takes.`;
|
|
26
|
-
export const SUBAGENT_POLICY = `
|
|
27
|
-
- When doing file search, prefer to use the ${TASK_TOOL_NAME} tool in order to reduce context usage.
|
|
28
|
-
- You should proactively use the ${TASK_TOOL_NAME} tool with specialized agents when the task at hand matches the agent's description.
|
|
29
|
-
- 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.`;
|
|
30
|
-
export const FILE_TOOL_POLICY_PREFIX = `\n- Use specialized tools instead of bash commands when possible, as this provides a better user experience. For file operations, use dedicated tools:`;
|
|
31
|
-
export const READ_FILE_POLICY = ` ${READ_TOOL_NAME} for reading files instead of cat/head/tail`;
|
|
32
|
-
export const EDIT_FILE_POLICY = ` ${EDIT_TOOL_NAME}/${MULTI_EDIT_TOOL_NAME} for editing instead of sed/awk`;
|
|
33
|
-
export const WRITE_FILE_POLICY = ` ${WRITE_TOOL_NAME} for creating files instead of cat with heredoc or echo redirection`;
|
|
34
|
-
export const SEARCH_FILE_POLICY = ` ${LS_TOOL_NAME}/${GLOB_TOOL_NAME}/${GREP_TOOL_NAME} for searching and listing files instead of find/ls/grep`;
|
|
35
|
-
export const BASH_POLICY = `
|
|
36
|
-
- Reserve bash tools exclusively for actual system commands and terminal operations that require shell execution. NEVER use bash echo or other command-line tools to communicate thoughts, explanations, or instructions to the user. Output all communication directly in your response text instead.
|
|
37
|
-
- When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.`;
|
|
38
|
-
export const DEFAULT_SYSTEM_PROMPT = BASE_SYSTEM_PROMPT;
|
|
39
|
-
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.
|
|
40
|
-
|
|
41
|
-
Your strengths:
|
|
42
|
-
- Searching for code, configurations, and patterns across large codebases
|
|
43
|
-
- Analyzing multiple files to understand system architecture
|
|
44
|
-
- Investigating complex questions that require exploring many files
|
|
45
|
-
- Performing multi-step research tasks
|
|
46
|
-
|
|
47
|
-
Guidelines:
|
|
48
|
-
- For file searches: Use Grep or Glob when you need to search broadly. Use Read when you know the specific file path.
|
|
49
|
-
- For analysis: Start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
50
|
-
- Be thorough: Check multiple locations, consider different naming conventions, look for related files.
|
|
51
|
-
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
52
|
-
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
53
|
-
- 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.
|
|
54
|
-
- For clear communication, avoid using emojis.`;
|
|
55
|
-
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.
|
|
56
|
-
|
|
57
|
-
What to add:
|
|
58
|
-
1. Commands that will be commonly used, such as how to build, lint, and run tests. Include the necessary commands to develop in this codebase, such as how to run a single test.
|
|
59
|
-
2. High-level code architecture and structure so that future instances can be productive more quickly. Focus on the "big picture" architecture that requires reading multiple files to understand.
|
|
60
|
-
|
|
61
|
-
Usage notes:
|
|
62
|
-
- If there's already a AGENTS.md, suggest improvements to it.
|
|
63
|
-
- When you make the initial AGENTS.md, do not repeat yourself and do not include obvious instructions like "Provide helpful error messages to users", "Write unit tests for all new utilities", "Never include sensitive information (API keys, tokens) in code or commits".
|
|
64
|
-
- Avoid listing every component or file structure that can be easily discovered.
|
|
65
|
-
- Don't include generic development practices.
|
|
66
|
-
- If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include the important parts.
|
|
67
|
-
- If there is a README.md, make sure to include the important parts.
|
|
68
|
-
- Do not make up information such as "Common Development Tasks", "Tips for Development", "Support and Documentation" unless this is expressly included in other files that you read.
|
|
69
|
-
- Be sure to prefix the file with the following text:
|
|
70
|
-
|
|
71
|
-
\`\`\`
|
|
72
|
-
# AGENTS.md
|
|
73
|
-
|
|
74
|
-
This file provides guidance to Agent when working with code in this repository.
|
|
75
|
-
\`\`\``;
|
|
76
|
-
export function buildSystemPrompt(basePrompt, tools) {
|
|
77
|
-
let prompt = basePrompt;
|
|
78
|
-
const toolNames = new Set(tools.map((t) => t.function?.name || t.name).filter(Boolean));
|
|
79
|
-
if (toolNames.has(TODO_WRITE_TOOL_NAME)) {
|
|
80
|
-
prompt += TASK_MANAGEMENT_POLICY;
|
|
81
|
-
}
|
|
82
|
-
if (toolNames.has(ASK_USER_QUESTION_TOOL_NAME)) {
|
|
83
|
-
prompt += ASK_USER_POLICY;
|
|
84
|
-
}
|
|
85
|
-
if (toolNames.has(TASK_TOOL_NAME)) {
|
|
86
|
-
prompt += SUBAGENT_POLICY;
|
|
87
|
-
}
|
|
88
|
-
if (toolNames.has(READ_TOOL_NAME) ||
|
|
89
|
-
toolNames.has(EDIT_TOOL_NAME) ||
|
|
90
|
-
toolNames.has(MULTI_EDIT_TOOL_NAME) ||
|
|
91
|
-
toolNames.has(WRITE_TOOL_NAME) ||
|
|
92
|
-
toolNames.has(LS_TOOL_NAME) ||
|
|
93
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
94
|
-
toolNames.has(GREP_TOOL_NAME)) {
|
|
95
|
-
const parts = [];
|
|
96
|
-
if (toolNames.has(READ_TOOL_NAME)) {
|
|
97
|
-
parts.push(READ_FILE_POLICY);
|
|
98
|
-
}
|
|
99
|
-
if (toolNames.has(EDIT_TOOL_NAME) || toolNames.has(MULTI_EDIT_TOOL_NAME)) {
|
|
100
|
-
parts.push(EDIT_FILE_POLICY);
|
|
101
|
-
}
|
|
102
|
-
if (toolNames.has(WRITE_TOOL_NAME)) {
|
|
103
|
-
parts.push(WRITE_FILE_POLICY);
|
|
104
|
-
}
|
|
105
|
-
if (toolNames.has(LS_TOOL_NAME) ||
|
|
106
|
-
toolNames.has(GLOB_TOOL_NAME) ||
|
|
107
|
-
toolNames.has(GREP_TOOL_NAME)) {
|
|
108
|
-
parts.push(SEARCH_FILE_POLICY);
|
|
109
|
-
}
|
|
110
|
-
if (parts.length > 0) {
|
|
111
|
-
prompt += FILE_TOOL_POLICY_PREFIX + parts.join(",") + ".";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (toolNames.has(BASH_TOOL_NAME)) {
|
|
115
|
-
prompt += BASH_POLICY;
|
|
116
|
-
}
|
|
117
|
-
return prompt;
|
|
118
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"todoWriteTool.d.ts","sourceRoot":"","sources":["../../src/tools/todoWriteTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAStE;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UAoP3B,CAAC"}
|