wave-agent-sdk 0.0.1 → 0.0.3
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 +37 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +82 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/managers/aiManager.d.ts +7 -1
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +11 -5
- package/dist/managers/messageManager.d.ts +8 -0
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +26 -2
- package/dist/managers/skillManager.d.ts +4 -5
- package/dist/managers/skillManager.d.ts.map +1 -1
- package/dist/managers/skillManager.js +6 -82
- package/dist/managers/subagentManager.d.ts +96 -0
- package/dist/managers/subagentManager.d.ts.map +1 -0
- package/dist/managers/subagentManager.js +261 -0
- package/dist/managers/toolManager.d.ts +33 -1
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +43 -5
- package/dist/services/aiService.d.ts +5 -0
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +58 -28
- package/dist/services/session.d.ts.map +1 -1
- package/dist/services/session.js +4 -0
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +8 -6
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +36 -6
- package/dist/tools/skillTool.d.ts +8 -0
- package/dist/tools/skillTool.d.ts.map +1 -0
- package/dist/tools/skillTool.js +72 -0
- package/dist/tools/taskTool.d.ts +8 -0
- package/dist/tools/taskTool.d.ts.map +1 -0
- package/dist/tools/taskTool.js +109 -0
- package/dist/tools/todoWriteTool.d.ts +6 -0
- package/dist/tools/todoWriteTool.d.ts.map +1 -0
- package/dist/tools/todoWriteTool.js +203 -0
- package/dist/types.d.ts +65 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -0
- package/dist/utils/configResolver.d.ts +38 -0
- package/dist/utils/configResolver.d.ts.map +1 -0
- package/dist/utils/configResolver.js +106 -0
- package/dist/utils/configValidator.d.ts +36 -0
- package/dist/utils/configValidator.d.ts.map +1 -0
- package/dist/utils/configValidator.js +78 -0
- package/dist/utils/constants.d.ts +10 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +10 -0
- package/dist/utils/fileFormat.d.ts +17 -0
- package/dist/utils/fileFormat.d.ts.map +1 -0
- package/dist/utils/fileFormat.js +35 -0
- package/dist/utils/messageOperations.d.ts +18 -0
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +43 -0
- package/dist/utils/subagentParser.d.ts +19 -0
- package/dist/utils/subagentParser.d.ts.map +1 -0
- package/dist/utils/subagentParser.js +159 -0
- package/package.json +11 -15
- package/src/agent.ts +130 -9
- package/src/index.ts +0 -1
- package/src/managers/aiManager.ts +22 -10
- package/src/managers/messageManager.ts +55 -1
- package/src/managers/skillManager.ts +7 -96
- package/src/managers/subagentManager.ts +368 -0
- package/src/managers/toolManager.ts +50 -5
- package/src/services/aiService.ts +92 -36
- package/src/services/session.ts +5 -0
- package/src/tools/grepTool.ts +9 -6
- package/src/tools/readTool.ts +40 -6
- package/src/tools/skillTool.ts +82 -0
- package/src/tools/taskTool.ts +128 -0
- package/src/tools/todoWriteTool.ts +232 -0
- package/src/types.ts +85 -1
- package/src/utils/configResolver.ts +142 -0
- package/src/utils/configValidator.ts +133 -0
- package/src/utils/constants.ts +10 -0
- package/src/utils/fileFormat.ts +40 -0
- package/src/utils/messageOperations.ts +80 -0
- package/src/utils/subagentParser.ts +223 -0
package/dist/tools/grepTool.js
CHANGED
|
@@ -58,7 +58,7 @@ export const grepTool = {
|
|
|
58
58
|
},
|
|
59
59
|
head_limit: {
|
|
60
60
|
type: "number",
|
|
61
|
-
description: 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries).
|
|
61
|
+
description: 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). Defaults to 100 to prevent excessive token usage.',
|
|
62
62
|
},
|
|
63
63
|
multiline: {
|
|
64
64
|
type: "boolean",
|
|
@@ -176,11 +176,13 @@ export const grepTool = {
|
|
|
176
176
|
shortResult: "No matches found",
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
-
// Apply head_limit
|
|
179
|
+
// Apply head_limit with default fallback
|
|
180
180
|
let finalOutput = output;
|
|
181
181
|
let lines = output.split("\n");
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
// Set default head_limit if not specified to prevent excessive token usage
|
|
183
|
+
const effectiveHeadLimit = headLimit || 100;
|
|
184
|
+
if (lines.length > effectiveHeadLimit) {
|
|
185
|
+
lines = lines.slice(0, effectiveHeadLimit);
|
|
184
186
|
finalOutput = lines.join("\n");
|
|
185
187
|
}
|
|
186
188
|
// Generate short result
|
|
@@ -195,8 +197,8 @@ export const grepTool = {
|
|
|
195
197
|
else {
|
|
196
198
|
shortResult = `Found ${totalLines} matching line${totalLines === 1 ? "" : "s"}`;
|
|
197
199
|
}
|
|
198
|
-
if (
|
|
199
|
-
shortResult += ` (showing first ${
|
|
200
|
+
if (effectiveHeadLimit && totalLines > effectiveHeadLimit) {
|
|
201
|
+
shortResult += ` (showing first ${effectiveHeadLimit})`;
|
|
200
202
|
}
|
|
201
203
|
return {
|
|
202
204
|
success: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readTool.d.ts","sourceRoot":"","sources":["../../src/tools/readTool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"readTool.d.ts","sourceRoot":"","sources":["../../src/tools/readTool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAOtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA2LtB,CAAC"}
|
package/dist/tools/readTool.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from "fs/promises";
|
|
2
2
|
import { resolvePath, getDisplayPath } from "../utils/path.js";
|
|
3
|
+
import { isBinaryDocument, getBinaryDocumentError, } from "../utils/fileFormat.js";
|
|
3
4
|
/**
|
|
4
5
|
* Read Tool Plugin - Read file content
|
|
5
6
|
*/
|
|
@@ -9,7 +10,7 @@ export const readTool = {
|
|
|
9
10
|
type: "function",
|
|
10
11
|
function: {
|
|
11
12
|
name: "Read",
|
|
12
|
-
description: "Reads a file from the local filesystem. You can access any file directly by using this tool.\nAssume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to 2000 lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any lines longer than 2000 characters will be truncated\n- Results are returned using cat -n format, with line numbers starting at 1\n- This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.\n- This tool can read
|
|
13
|
+
description: "Reads a file from the local filesystem. You can access any file directly by using this tool.\nAssume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.\n\nUsage:\n- The file_path parameter must be an absolute path, not a relative path\n- By default, it reads up to 2000 lines starting from the beginning of the file\n- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters\n- Any lines longer than 2000 characters will be truncated\n- Results are returned using cat -n format, with line numbers starting at 1\n- This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.\n- This tool can read Jupyter notebooks (.ipynb files) and returns all cells with their outputs, combining code, text, and visualizations.\n- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.\n- You will regularly be asked to read screenshots. If the user provides a path to a screenshot ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths like /var/folders/123/abc/T/TemporaryItems/NSIRD_screencaptureui_ZfB1tD/Screenshot.png\n- If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.\n- Binary document formats (PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX) are not supported and will return an error.",
|
|
13
14
|
parameters: {
|
|
14
15
|
type: "object",
|
|
15
16
|
properties: {
|
|
@@ -41,6 +42,14 @@ export const readTool = {
|
|
|
41
42
|
error: "file_path parameter is required and must be a string",
|
|
42
43
|
};
|
|
43
44
|
}
|
|
45
|
+
// Check for binary document formats
|
|
46
|
+
if (isBinaryDocument(filePath)) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
content: "",
|
|
50
|
+
error: getBinaryDocumentError(filePath),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
44
53
|
try {
|
|
45
54
|
// Note: New Read tool requires absolute paths, so we don't use resolvePath
|
|
46
55
|
// But for compatibility, if it's not an absolute path, we still try to resolve
|
|
@@ -57,8 +66,17 @@ export const readTool = {
|
|
|
57
66
|
shortResult: "Empty file",
|
|
58
67
|
};
|
|
59
68
|
}
|
|
60
|
-
|
|
69
|
+
// Check content size limit (100KB)
|
|
70
|
+
const MAX_CONTENT_SIZE = 100 * 1024; // 100KB
|
|
71
|
+
let contentToProcess = fileContent;
|
|
72
|
+
let contentTruncated = false;
|
|
73
|
+
if (fileContent.length > MAX_CONTENT_SIZE) {
|
|
74
|
+
contentToProcess = fileContent.substring(0, MAX_CONTENT_SIZE);
|
|
75
|
+
contentTruncated = true;
|
|
76
|
+
}
|
|
77
|
+
const lines = contentToProcess.split("\n");
|
|
61
78
|
const totalLines = lines.length;
|
|
79
|
+
const originalTotalLines = fileContent.split("\n").length;
|
|
62
80
|
// Handle offset and limit
|
|
63
81
|
let startLine = 1;
|
|
64
82
|
let endLine = Math.min(totalLines, 2000); // Default maximum read 2000 lines
|
|
@@ -94,7 +112,11 @@ export const readTool = {
|
|
|
94
112
|
.join("\n");
|
|
95
113
|
// Add file information header
|
|
96
114
|
let content = `File: ${filePath}\n`;
|
|
97
|
-
if (
|
|
115
|
+
if (contentTruncated) {
|
|
116
|
+
content += `Content truncated at ${MAX_CONTENT_SIZE} bytes\n`;
|
|
117
|
+
content += `Lines ${startLine}-${endLine} of ${totalLines} (original file: ${originalTotalLines} lines)\n`;
|
|
118
|
+
}
|
|
119
|
+
else if (startLine > 1 || endLine < totalLines) {
|
|
98
120
|
content += `Lines ${startLine}-${endLine} of ${totalLines}\n`;
|
|
99
121
|
}
|
|
100
122
|
else {
|
|
@@ -103,14 +125,22 @@ export const readTool = {
|
|
|
103
125
|
content += "─".repeat(50) + "\n";
|
|
104
126
|
content += formattedContent;
|
|
105
127
|
// If only showing partial content, add prompt
|
|
106
|
-
if (endLine < totalLines) {
|
|
128
|
+
if (endLine < totalLines || contentTruncated) {
|
|
107
129
|
content += `\n${"─".repeat(50)}\n`;
|
|
108
|
-
|
|
130
|
+
if (contentTruncated) {
|
|
131
|
+
content += `... content truncated due to size limit (${MAX_CONTENT_SIZE} bytes)`;
|
|
132
|
+
if (endLine < totalLines) {
|
|
133
|
+
content += ` and ${totalLines - endLine} more lines not shown`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
content += `... ${totalLines - endLine} more lines not shown`;
|
|
138
|
+
}
|
|
109
139
|
}
|
|
110
140
|
return {
|
|
111
141
|
success: true,
|
|
112
142
|
content,
|
|
113
|
-
shortResult: `Read ${selectedLines.length} lines${totalLines > 2000 ? " (truncated)" : ""}`,
|
|
143
|
+
shortResult: `Read ${selectedLines.length} lines${totalLines > 2000 || contentTruncated ? " (truncated)" : ""}`,
|
|
114
144
|
};
|
|
115
145
|
}
|
|
116
146
|
catch (error) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolPlugin } from "./types.js";
|
|
2
|
+
import type { SkillManager } from "../managers/skillManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a skill tool plugin that uses the provided SkillManager
|
|
5
|
+
* Note: SkillManager should be initialized before calling this function
|
|
6
|
+
*/
|
|
7
|
+
export declare function createSkillTool(skillManager: SkillManager): ToolPlugin;
|
|
8
|
+
//# sourceMappingURL=skillTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skillTool.d.ts","sourceRoot":"","sources":["../../src/tools/skillTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,UAAU,CA0EtE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a skill tool plugin that uses the provided SkillManager
|
|
3
|
+
* Note: SkillManager should be initialized before calling this function
|
|
4
|
+
*/
|
|
5
|
+
export function createSkillTool(skillManager) {
|
|
6
|
+
const getToolDescription = () => {
|
|
7
|
+
const availableSkills = skillManager.getAvailableSkills();
|
|
8
|
+
if (availableSkills.length === 0) {
|
|
9
|
+
return "Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific. No skills are currently available.";
|
|
10
|
+
}
|
|
11
|
+
const skillList = availableSkills
|
|
12
|
+
.map((skill) => `• **${skill.name}** (${skill.type}): ${skill.description}`)
|
|
13
|
+
.join("\n");
|
|
14
|
+
return `Invoke a Wave skill by name. Skills are user-defined automation templates that can be personal or project-specific.\n\nAvailable skills:\n${skillList}`;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
name: "skill",
|
|
18
|
+
config: {
|
|
19
|
+
type: "function",
|
|
20
|
+
function: {
|
|
21
|
+
name: "skill",
|
|
22
|
+
description: getToolDescription(),
|
|
23
|
+
parameters: {
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
skill_name: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Name of the skill to invoke",
|
|
29
|
+
enum: skillManager
|
|
30
|
+
.getAvailableSkills()
|
|
31
|
+
.map((skill) => skill.name),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
required: ["skill_name"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
execute: async (args) => {
|
|
39
|
+
try {
|
|
40
|
+
// Validate arguments
|
|
41
|
+
const skillName = args.skill_name;
|
|
42
|
+
if (!skillName || typeof skillName !== "string") {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
content: "",
|
|
46
|
+
error: "skill_name parameter is required and must be a string",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Execute the skill
|
|
50
|
+
const result = await skillManager.executeSkill({
|
|
51
|
+
skill_name: skillName,
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
success: true,
|
|
55
|
+
content: result.content,
|
|
56
|
+
shortResult: `Invoked skill: ${skillName}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
content: "",
|
|
63
|
+
error: error instanceof Error ? error.message : String(error),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
formatCompactParams: (params) => {
|
|
68
|
+
const skillName = params.skill_name;
|
|
69
|
+
return skillName || "unknown-skill";
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolPlugin } from "./types.js";
|
|
2
|
+
import type { SubagentManager } from "../managers/subagentManager.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a task tool plugin that uses the provided SubagentManager
|
|
5
|
+
* Note: SubagentManager should be initialized before calling this function
|
|
6
|
+
*/
|
|
7
|
+
export declare function createTaskTool(subagentManager: SubagentManager): ToolPlugin;
|
|
8
|
+
//# sourceMappingURL=taskTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taskTool.d.ts","sourceRoot":"","sources":["../../src/tools/taskTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,eAAe,GAAG,UAAU,CAwH3E"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a task tool plugin that uses the provided SubagentManager
|
|
3
|
+
* Note: SubagentManager should be initialized before calling this function
|
|
4
|
+
*/
|
|
5
|
+
export function createTaskTool(subagentManager) {
|
|
6
|
+
// Get available subagents from the initialized subagent manager
|
|
7
|
+
const availableSubagents = subagentManager.getConfigurations();
|
|
8
|
+
const subagentList = availableSubagents
|
|
9
|
+
.map((config) => `- ${config.name}: ${config.description}`)
|
|
10
|
+
.join("\n");
|
|
11
|
+
const description = `Delegate a task to a specialized subagent. Use this when you need specialized expertise or want to break down complex work into focused subtasks.
|
|
12
|
+
|
|
13
|
+
Available subagents:
|
|
14
|
+
${subagentList || "No subagents configured"}`;
|
|
15
|
+
return {
|
|
16
|
+
name: "Task",
|
|
17
|
+
config: {
|
|
18
|
+
type: "function",
|
|
19
|
+
function: {
|
|
20
|
+
name: "Task",
|
|
21
|
+
description,
|
|
22
|
+
parameters: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
description: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "A clear, concise description of what needs to be accomplished",
|
|
28
|
+
},
|
|
29
|
+
prompt: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "The specific instructions or prompt to send to the subagent",
|
|
32
|
+
},
|
|
33
|
+
subagent_type: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: `The type or name of subagent to use. Available options: ${availableSubagents.map((c) => c.name).join(", ") || "none"}`,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["description", "prompt", "subagent_type"],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
execute: async (args) => {
|
|
43
|
+
// Input validation
|
|
44
|
+
const description = args.description;
|
|
45
|
+
const prompt = args.prompt;
|
|
46
|
+
const subagent_type = args.subagent_type;
|
|
47
|
+
if (!description || typeof description !== "string") {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
content: "",
|
|
51
|
+
error: "description parameter is required and must be a string",
|
|
52
|
+
shortResult: "Task delegation failed",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (!prompt || typeof prompt !== "string") {
|
|
56
|
+
return {
|
|
57
|
+
success: false,
|
|
58
|
+
content: "",
|
|
59
|
+
error: "prompt parameter is required and must be a string",
|
|
60
|
+
shortResult: "Task delegation failed",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (!subagent_type || typeof subagent_type !== "string") {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
content: "",
|
|
67
|
+
error: "subagent_type parameter is required and must be a string",
|
|
68
|
+
shortResult: "Task delegation failed",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
// Subagent selection logic with explicit name matching only
|
|
73
|
+
const configuration = await subagentManager.findSubagent(subagent_type);
|
|
74
|
+
if (!configuration) {
|
|
75
|
+
// Error handling for nonexistent subagents with available subagents listing
|
|
76
|
+
const allConfigs = subagentManager.getConfigurations();
|
|
77
|
+
const availableNames = allConfigs.map((c) => c.name).join(", ");
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
content: "",
|
|
81
|
+
error: `No subagent found matching "${subagent_type}". Available subagents: ${availableNames || "none"}`,
|
|
82
|
+
shortResult: "Subagent not found",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Create subagent instance and execute task
|
|
86
|
+
const instance = await subagentManager.createInstance(configuration, description);
|
|
87
|
+
const response = await subagentManager.executeTask(instance, prompt);
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
content: response,
|
|
91
|
+
shortResult: `Task completed by ${configuration.name}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
content: "",
|
|
98
|
+
error: `Task delegation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
99
|
+
shortResult: "Delegation error",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
formatCompactParams: (params) => {
|
|
104
|
+
const subagent_type = params.subagent_type;
|
|
105
|
+
const description = params.description;
|
|
106
|
+
return `${subagent_type || "unknown"}: ${description || "no description"}`;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todoWriteTool.d.ts","sourceRoot":"","sources":["../../src/tools/todoWriteTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAQzD;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UA4N3B,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TodoWrite tool for creating and managing structured task lists
|
|
3
|
+
*/
|
|
4
|
+
export const todoWriteTool = {
|
|
5
|
+
name: "TodoWrite",
|
|
6
|
+
config: {
|
|
7
|
+
type: "function",
|
|
8
|
+
function: {
|
|
9
|
+
name: "TodoWrite",
|
|
10
|
+
description: `Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
11
|
+
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
12
|
+
|
|
13
|
+
## When to Use This Tool
|
|
14
|
+
Use this tool proactively in these scenarios:
|
|
15
|
+
|
|
16
|
+
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
17
|
+
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
|
|
18
|
+
3. User explicitly requests todo list - When the user directly asks you to use the todo list
|
|
19
|
+
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
20
|
+
5. After receiving new instructions - Immediately capture user requirements as todos
|
|
21
|
+
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
22
|
+
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during implementation
|
|
23
|
+
|
|
24
|
+
## When NOT to Use This Tool
|
|
25
|
+
|
|
26
|
+
Skip using this tool when:
|
|
27
|
+
1. There is only a single, straightforward task
|
|
28
|
+
2. The task is trivial and tracking it provides no organizational benefit
|
|
29
|
+
3. The task can be completed in less than 3 trivial steps
|
|
30
|
+
4. The task is purely conversational or informational
|
|
31
|
+
|
|
32
|
+
NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
|
|
33
|
+
|
|
34
|
+
## Task States and Management
|
|
35
|
+
|
|
36
|
+
1. **Task States**: Use these states to track progress:
|
|
37
|
+
- pending: Task not yet started
|
|
38
|
+
- in_progress: Currently working on (limit to ONE task at a time)
|
|
39
|
+
- completed: Task finished successfully
|
|
40
|
+
|
|
41
|
+
2. **Task Management**:
|
|
42
|
+
- Update task status in real-time as you work
|
|
43
|
+
- Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
|
|
44
|
+
- Only have ONE task in_progress at any time
|
|
45
|
+
- Complete current tasks before starting new ones
|
|
46
|
+
- Remove tasks that are no longer relevant from the list entirely
|
|
47
|
+
|
|
48
|
+
3. **Task Completion Requirements**:
|
|
49
|
+
- ONLY mark a task as completed when you have FULLY accomplished it
|
|
50
|
+
- If you encounter errors, blockers, or cannot finish, keep the task as in_progress
|
|
51
|
+
- When blocked, create a new task describing what needs to be resolved
|
|
52
|
+
- Never mark a task as completed if:
|
|
53
|
+
- Tests are failing
|
|
54
|
+
- Implementation is partial
|
|
55
|
+
- You encountered unresolved errors
|
|
56
|
+
- You couldn't find necessary files or dependencies
|
|
57
|
+
|
|
58
|
+
4. **Task Breakdown**:
|
|
59
|
+
- Create specific, actionable items
|
|
60
|
+
- Break complex tasks into smaller, manageable steps
|
|
61
|
+
- Use clear, descriptive task names
|
|
62
|
+
|
|
63
|
+
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.`,
|
|
64
|
+
parameters: {
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
todos: {
|
|
68
|
+
type: "array",
|
|
69
|
+
items: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
content: {
|
|
73
|
+
type: "string",
|
|
74
|
+
minLength: 1,
|
|
75
|
+
},
|
|
76
|
+
status: {
|
|
77
|
+
type: "string",
|
|
78
|
+
enum: ["pending", "in_progress", "completed"],
|
|
79
|
+
},
|
|
80
|
+
id: {
|
|
81
|
+
type: "string",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ["content", "status", "id"],
|
|
85
|
+
additionalProperties: false,
|
|
86
|
+
},
|
|
87
|
+
description: "The updated todo list",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ["todos"],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
execute: async (args) => {
|
|
96
|
+
try {
|
|
97
|
+
// Validate arguments
|
|
98
|
+
const { todos } = args;
|
|
99
|
+
if (!todos || !Array.isArray(todos)) {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
content: "",
|
|
103
|
+
error: "todos parameter must be an array",
|
|
104
|
+
shortResult: "Invalid todos format",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Validate each task item
|
|
108
|
+
for (const [index, todo] of todos.entries()) {
|
|
109
|
+
if (!todo || typeof todo !== "object") {
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
content: "",
|
|
113
|
+
error: `Todo item at index ${index} must be an object`,
|
|
114
|
+
shortResult: "Invalid todo item",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (!todo.content ||
|
|
118
|
+
typeof todo.content !== "string" ||
|
|
119
|
+
todo.content.trim().length === 0) {
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
content: "",
|
|
123
|
+
error: `Todo item at index ${index} must have non-empty content`,
|
|
124
|
+
shortResult: "Invalid todo content",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (!["pending", "in_progress", "completed"].includes(todo.status)) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
content: "",
|
|
131
|
+
error: `Todo item at index ${index} has invalid status: ${todo.status}`,
|
|
132
|
+
shortResult: "Invalid todo status",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (!todo.id ||
|
|
136
|
+
typeof todo.id !== "string" ||
|
|
137
|
+
todo.id.trim().length === 0) {
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
content: "",
|
|
141
|
+
error: `Todo item at index ${index} must have a non-empty id`,
|
|
142
|
+
shortResult: "Invalid todo id",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Check for duplicate IDs
|
|
147
|
+
const ids = todos.map((todo) => todo.id);
|
|
148
|
+
const duplicateIds = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
149
|
+
if (duplicateIds.length > 0) {
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
content: "",
|
|
153
|
+
error: `Duplicate todo IDs found: ${duplicateIds.join(", ")}`,
|
|
154
|
+
shortResult: "Duplicate todo IDs",
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// Check that only one task is in_progress
|
|
158
|
+
const inProgressTodos = todos.filter((todo) => todo.status === "in_progress");
|
|
159
|
+
if (inProgressTodos.length > 1) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
content: "",
|
|
163
|
+
error: `Only one todo can be in_progress at a time. Found ${inProgressTodos.length} in_progress todos`,
|
|
164
|
+
shortResult: "Multiple in_progress todos",
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const completedCount = todos.filter((t) => t.status === "completed").length;
|
|
168
|
+
const totalCount = todos.length;
|
|
169
|
+
let shortResult = `${completedCount}/${totalCount} done`;
|
|
170
|
+
if (totalCount > 0) {
|
|
171
|
+
const symbols = {
|
|
172
|
+
pending: "[ ]",
|
|
173
|
+
in_progress: "[>]",
|
|
174
|
+
completed: "[x]",
|
|
175
|
+
};
|
|
176
|
+
const inProgress = todos.filter((t) => t.status === "in_progress");
|
|
177
|
+
const pending = todos.filter((t) => t.status === "pending");
|
|
178
|
+
if (inProgress.length > 0) {
|
|
179
|
+
shortResult += `\n${symbols.in_progress} ${inProgress[0].content}`;
|
|
180
|
+
}
|
|
181
|
+
if (pending.length > 0) {
|
|
182
|
+
shortResult += `\n${symbols.pending} ${pending[0].content}`;
|
|
183
|
+
if (pending.length > 1) {
|
|
184
|
+
shortResult += ` +${pending.length - 1}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
success: true,
|
|
190
|
+
content: `Todo list updated: ${completedCount}/${totalCount} completed`,
|
|
191
|
+
shortResult: shortResult,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
content: "",
|
|
198
|
+
error: error instanceof Error ? error.message : String(error),
|
|
199
|
+
shortResult: "Todo list update failed",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
};
|
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface Message {
|
|
|
13
13
|
role: "user" | "assistant";
|
|
14
14
|
blocks: MessageBlock[];
|
|
15
15
|
}
|
|
16
|
-
export type MessageBlock = TextBlock | ErrorBlock | ToolBlock | ImageBlock | DiffBlock | CommandOutputBlock | CompressBlock | MemoryBlock | CustomCommandBlock;
|
|
16
|
+
export type MessageBlock = TextBlock | ErrorBlock | ToolBlock | ImageBlock | DiffBlock | CommandOutputBlock | CompressBlock | MemoryBlock | CustomCommandBlock | SubagentBlock;
|
|
17
17
|
export interface TextBlock {
|
|
18
18
|
type: "text";
|
|
19
19
|
content: string;
|
|
@@ -75,6 +75,13 @@ export interface CustomCommandBlock {
|
|
|
75
75
|
content: string;
|
|
76
76
|
originalInput?: string;
|
|
77
77
|
}
|
|
78
|
+
export interface SubagentBlock {
|
|
79
|
+
type: "subagent";
|
|
80
|
+
subagentId: string;
|
|
81
|
+
subagentName: string;
|
|
82
|
+
status: "active" | "completed" | "error" | "aborted";
|
|
83
|
+
messages: Message[];
|
|
84
|
+
}
|
|
78
85
|
export interface AIRequest {
|
|
79
86
|
content: string;
|
|
80
87
|
files: unknown[];
|
|
@@ -209,4 +216,61 @@ export declare const SKILL_DEFAULTS: {
|
|
|
209
216
|
readonly SCAN_TIMEOUT: 5000;
|
|
210
217
|
readonly LOAD_TIMEOUT: 2000;
|
|
211
218
|
};
|
|
219
|
+
export interface GatewayConfig {
|
|
220
|
+
apiKey: string;
|
|
221
|
+
baseURL: string;
|
|
222
|
+
}
|
|
223
|
+
export interface ModelConfig {
|
|
224
|
+
agentModel: string;
|
|
225
|
+
fastModel: string;
|
|
226
|
+
}
|
|
227
|
+
export interface ConfigurationResolver {
|
|
228
|
+
/**
|
|
229
|
+
* Resolves gateway configuration from constructor args and environment
|
|
230
|
+
* @param apiKey - API key from constructor (optional)
|
|
231
|
+
* @param baseURL - Base URL from constructor (optional)
|
|
232
|
+
* @returns Resolved gateway configuration
|
|
233
|
+
* @throws Error if required configuration is missing after fallbacks
|
|
234
|
+
*/
|
|
235
|
+
resolveGatewayConfig(apiKey?: string, baseURL?: string): GatewayConfig;
|
|
236
|
+
/**
|
|
237
|
+
* Resolves model configuration with fallbacks
|
|
238
|
+
* @param agentModel - Agent model from constructor (optional)
|
|
239
|
+
* @param fastModel - Fast model from constructor (optional)
|
|
240
|
+
* @returns Resolved model configuration with defaults
|
|
241
|
+
*/
|
|
242
|
+
resolveModelConfig(agentModel?: string, fastModel?: string): ModelConfig;
|
|
243
|
+
/**
|
|
244
|
+
* Resolves token limit with fallbacks
|
|
245
|
+
* @param constructorLimit - Token limit from constructor (optional)
|
|
246
|
+
* @returns Resolved token limit
|
|
247
|
+
*/
|
|
248
|
+
resolveTokenLimit(constructorLimit?: number): number;
|
|
249
|
+
}
|
|
250
|
+
export interface ConfigurationValidator {
|
|
251
|
+
/**
|
|
252
|
+
* Validates gateway configuration
|
|
253
|
+
* @param config - Configuration to validate
|
|
254
|
+
* @throws Error with descriptive message if invalid
|
|
255
|
+
*/
|
|
256
|
+
validateGatewayConfig(config: GatewayConfig): void;
|
|
257
|
+
/**
|
|
258
|
+
* Validates token limit value
|
|
259
|
+
* @param tokenLimit - Token limit to validate
|
|
260
|
+
* @throws Error if invalid
|
|
261
|
+
*/
|
|
262
|
+
validateTokenLimit(tokenLimit: number): void;
|
|
263
|
+
}
|
|
264
|
+
export declare class ConfigurationError extends Error {
|
|
265
|
+
readonly field: string;
|
|
266
|
+
readonly provided?: unknown | undefined;
|
|
267
|
+
constructor(message: string, field: string, provided?: unknown | undefined);
|
|
268
|
+
}
|
|
269
|
+
export declare const CONFIG_ERRORS: {
|
|
270
|
+
readonly MISSING_API_KEY: "Gateway configuration requires apiKey. Provide via constructor or AIGW_TOKEN environment variable.";
|
|
271
|
+
readonly MISSING_BASE_URL: "Gateway configuration requires baseURL. Provide via constructor or AIGW_URL environment variable.";
|
|
272
|
+
readonly INVALID_TOKEN_LIMIT: "Token limit must be a positive integer.";
|
|
273
|
+
readonly EMPTY_API_KEY: "API key cannot be empty string.";
|
|
274
|
+
readonly EMPTY_BASE_URL: "Base URL cannot be empty string.";
|
|
275
|
+
};
|
|
212
276
|
//# sourceMappingURL=types.d.ts.map
|