@shareai-lab/kode-sdk 2.7.1 → 2.7.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/core/agent/breakpoint-manager.js +36 -0
- package/dist/core/agent/message-queue.js +57 -0
- package/dist/core/agent/permission-manager.js +32 -0
- package/dist/core/agent/todo-manager.js +91 -0
- package/dist/core/agent/tool-runner.js +45 -0
- package/dist/core/agent.js +2035 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.js +241 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/events.js +329 -0
- package/dist/core/file-pool.d.ts +2 -0
- package/dist/core/file-pool.js +125 -0
- package/dist/core/hooks.js +71 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.js +301 -0
- package/dist/core/room.js +57 -0
- package/dist/core/scheduler.js +58 -0
- package/dist/core/skills/index.js +20 -0
- package/dist/core/skills/management-manager.js +557 -0
- package/dist/core/skills/manager.js +243 -0
- package/dist/core/skills/operation-queue.js +113 -0
- package/dist/core/skills/sandbox-file-manager.js +183 -0
- package/dist/core/skills/types.js +9 -0
- package/dist/core/skills/xml-generator.js +70 -0
- package/dist/core/template.js +35 -0
- package/dist/core/time-bridge.js +100 -0
- package/dist/core/todo.js +89 -0
- package/dist/core/types.js +3 -0
- package/dist/index.js +148 -60461
- package/dist/infra/db/postgres/postgres-store.js +1073 -0
- package/dist/infra/db/sqlite/sqlite-store.js +800 -0
- package/dist/infra/e2b/e2b-fs.js +128 -0
- package/dist/infra/e2b/e2b-sandbox.js +156 -0
- package/dist/infra/e2b/e2b-template.js +105 -0
- package/dist/infra/e2b/index.js +9 -0
- package/dist/infra/e2b/types.js +2 -0
- package/dist/infra/provider.js +67 -0
- package/dist/infra/providers/anthropic.js +308 -0
- package/dist/infra/providers/core/errors.js +353 -0
- package/dist/infra/providers/core/fork.js +418 -0
- package/dist/infra/providers/core/index.js +76 -0
- package/dist/infra/providers/core/logger.js +191 -0
- package/dist/infra/providers/core/retry.js +189 -0
- package/dist/infra/providers/core/usage.js +376 -0
- package/dist/infra/providers/gemini.js +493 -0
- package/dist/infra/providers/index.js +83 -0
- package/dist/infra/providers/openai.js +662 -0
- package/dist/infra/providers/types.js +20 -0
- package/dist/infra/providers/utils.js +400 -0
- package/dist/infra/sandbox-factory.js +30 -0
- package/dist/infra/sandbox.js +243 -0
- package/dist/infra/store/factory.js +80 -0
- package/dist/infra/store/index.js +26 -0
- package/dist/infra/store/json-store.js +606 -0
- package/dist/infra/store/types.js +2 -0
- package/dist/infra/store.js +29 -0
- package/dist/tools/bash_kill/index.js +35 -0
- package/dist/tools/bash_kill/prompt.js +14 -0
- package/dist/tools/bash_logs/index.js +40 -0
- package/dist/tools/bash_logs/prompt.js +14 -0
- package/dist/tools/bash_run/index.js +61 -0
- package/dist/tools/bash_run/prompt.js +18 -0
- package/dist/tools/builtin.js +26 -0
- package/dist/tools/define.js +214 -0
- package/dist/tools/fs_edit/index.js +62 -0
- package/dist/tools/fs_edit/prompt.js +15 -0
- package/dist/tools/fs_glob/index.js +40 -0
- package/dist/tools/fs_glob/prompt.js +15 -0
- package/dist/tools/fs_grep/index.js +66 -0
- package/dist/tools/fs_grep/prompt.js +16 -0
- package/dist/tools/fs_multi_edit/index.js +106 -0
- package/dist/tools/fs_multi_edit/prompt.js +16 -0
- package/dist/tools/fs_read/index.js +40 -0
- package/dist/tools/fs_read/prompt.js +16 -0
- package/dist/tools/fs_write/index.js +40 -0
- package/dist/tools/fs_write/prompt.js +15 -0
- package/dist/tools/index.js +61 -0
- package/dist/tools/mcp.js +185 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/scripts.js +205 -0
- package/dist/tools/skills.js +115 -0
- package/dist/tools/task_run/index.js +58 -0
- package/dist/tools/task_run/prompt.js +25 -0
- package/dist/tools/todo_read/index.js +29 -0
- package/dist/tools/todo_read/prompt.js +18 -0
- package/dist/tools/todo_write/index.js +42 -0
- package/dist/tools/todo_write/prompt.js +23 -0
- package/dist/tools/tool.js +211 -0
- package/dist/tools/toolkit.js +98 -0
- package/dist/tools/type-inference.js +207 -0
- package/dist/utils/agent-id.js +28 -0
- package/dist/utils/logger.js +44 -0
- package/dist/utils/session-id.js +64 -0
- package/package.json +7 -38
- package/dist/index.js.map +0 -7
- package/dist/index.mjs +0 -60385
- package/dist/index.mjs.map +0 -7
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scripts 执行工具
|
|
4
|
+
*
|
|
5
|
+
* 设计原则 (UNIX哲学):
|
|
6
|
+
* - 简洁: 只负责执行scripts,支持双模式(直接执行/sandbox隔离)
|
|
7
|
+
* - 安全: 支持sandbox隔离执行,拦截危险命令
|
|
8
|
+
* - 跨平台: 自动适配Windows、Linux、MacOS
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.createScriptsTool = createScriptsTool;
|
|
45
|
+
const tool_1 = require("../tools/tool");
|
|
46
|
+
const zod_1 = require("zod");
|
|
47
|
+
const child_process_1 = require("child_process");
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const os = __importStar(require("os"));
|
|
50
|
+
/**
|
|
51
|
+
* Scripts 工具描述
|
|
52
|
+
*/
|
|
53
|
+
const DESCRIPTION = `执行skill中的scripts脚本。
|
|
54
|
+
|
|
55
|
+
支持两种执行模式:
|
|
56
|
+
- 直接执行模式(默认): 本地开发时使用,直接在当前环境执行
|
|
57
|
+
- Sandbox隔离模式: 生产环境使用,在安全隔离环境中执行
|
|
58
|
+
|
|
59
|
+
支持的脚本类型:
|
|
60
|
+
- Node.js脚本 (.js, .ts): 跨平台兼容
|
|
61
|
+
- Shell脚本 (.sh): Linux/MacOS
|
|
62
|
+
- Batch脚本 (.bat): Windows
|
|
63
|
+
|
|
64
|
+
注意: 危险命令会被自动拦截(如rm -rf /、sudo等)`;
|
|
65
|
+
/**
|
|
66
|
+
* 检测平台
|
|
67
|
+
*/
|
|
68
|
+
function detectPlatform() {
|
|
69
|
+
const platform = os.platform();
|
|
70
|
+
if (platform === 'win32')
|
|
71
|
+
return 'windows';
|
|
72
|
+
if (platform === 'darwin')
|
|
73
|
+
return 'macos';
|
|
74
|
+
return 'linux';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 获取脚本执行命令
|
|
78
|
+
*/
|
|
79
|
+
function getScriptCommand(scriptPath, platform) {
|
|
80
|
+
const ext = path.extname(scriptPath).toLowerCase();
|
|
81
|
+
switch (ext) {
|
|
82
|
+
case '.js':
|
|
83
|
+
return `node "${scriptPath}"`;
|
|
84
|
+
case '.ts':
|
|
85
|
+
return `ts-node "${scriptPath}"`;
|
|
86
|
+
case '.sh':
|
|
87
|
+
if (platform === 'windows') {
|
|
88
|
+
// Windows下需要Git Bash或WSL来执行.sh
|
|
89
|
+
return `bash "${scriptPath}"`;
|
|
90
|
+
}
|
|
91
|
+
return `sh "${scriptPath}"`;
|
|
92
|
+
case '.bat':
|
|
93
|
+
case '.cmd':
|
|
94
|
+
if (platform !== 'windows') {
|
|
95
|
+
throw new Error(`Batch scripts (.bat/.cmd) are only supported on Windows`);
|
|
96
|
+
}
|
|
97
|
+
return `"${scriptPath}"`;
|
|
98
|
+
default:
|
|
99
|
+
throw new Error(`Unsupported script type: ${ext}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 创建Scripts工具
|
|
104
|
+
*
|
|
105
|
+
* @param skillsManager Skills管理器实例
|
|
106
|
+
* @param sandboxFactory Sandbox工厂(可选)
|
|
107
|
+
* @returns ToolInstance
|
|
108
|
+
*/
|
|
109
|
+
function createScriptsTool(skillsManager, sandboxFactory) {
|
|
110
|
+
const scriptsTool = (0, tool_1.tool)({
|
|
111
|
+
name: 'execute_script',
|
|
112
|
+
description: DESCRIPTION,
|
|
113
|
+
parameters: zod_1.z.object({
|
|
114
|
+
skill_name: zod_1.z.string().describe('技能名称'),
|
|
115
|
+
script_name: zod_1.z.string().describe('脚本文件名(如"script.js")'),
|
|
116
|
+
use_sandbox: zod_1.z.boolean().optional().default(true).describe('是否使用sandbox隔离执行'),
|
|
117
|
+
args: zod_1.z.array(zod_1.z.string()).optional().describe('脚本参数(可选)'),
|
|
118
|
+
}),
|
|
119
|
+
async execute(args, ctx) {
|
|
120
|
+
const { skill_name, script_name, use_sandbox, args: scriptArgs = [] } = args;
|
|
121
|
+
// 加载skill内容
|
|
122
|
+
const skillContent = await skillsManager.loadSkillContent(skill_name);
|
|
123
|
+
if (!skillContent) {
|
|
124
|
+
return {
|
|
125
|
+
ok: false,
|
|
126
|
+
error: `Skill '${skill_name}' not found`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// 查找脚本文件
|
|
130
|
+
const scriptPath = skillContent.scripts.find(p => path.basename(p) === script_name);
|
|
131
|
+
if (!scriptPath) {
|
|
132
|
+
return {
|
|
133
|
+
ok: false,
|
|
134
|
+
error: `Script '${script_name}' not found in skill '${skill_name}'. Available scripts: ${skillContent.scripts.map(p => path.basename(p)).join(', ')}`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const platform = detectPlatform();
|
|
138
|
+
let result;
|
|
139
|
+
try {
|
|
140
|
+
if (use_sandbox && sandboxFactory) {
|
|
141
|
+
// 使用sandbox隔离执行
|
|
142
|
+
const sandbox = sandboxFactory.create({
|
|
143
|
+
kind: 'local',
|
|
144
|
+
workDir: skillContent.metadata.baseDir,
|
|
145
|
+
});
|
|
146
|
+
const cmd = getScriptCommand(scriptPath, platform);
|
|
147
|
+
const cmdWithArgs = `${cmd} ${scriptArgs.join(' ')}`;
|
|
148
|
+
result = await sandbox.exec(cmdWithArgs, { timeoutMs: 60000 });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// 直接执行(本地开发模式)
|
|
152
|
+
const cmd = getScriptCommand(scriptPath, platform);
|
|
153
|
+
const cmdWithArgs = `${cmd} ${scriptArgs.join(' ')}`;
|
|
154
|
+
const stdout = (0, child_process_1.execSync)(cmdWithArgs, {
|
|
155
|
+
cwd: skillContent.metadata.baseDir,
|
|
156
|
+
encoding: 'utf-8',
|
|
157
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
158
|
+
timeout: 60000,
|
|
159
|
+
});
|
|
160
|
+
result = {
|
|
161
|
+
code: 0,
|
|
162
|
+
stdout: stdout || '',
|
|
163
|
+
stderr: '',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (result.code !== 0) {
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
error: `Script execution failed with code ${result.code}`,
|
|
170
|
+
data: {
|
|
171
|
+
stdout: result.stdout,
|
|
172
|
+
stderr: result.stderr,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
ok: true,
|
|
178
|
+
data: {
|
|
179
|
+
stdout: result.stdout,
|
|
180
|
+
stderr: result.stderr,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
ok: false,
|
|
187
|
+
error: error.message || 'Script execution failed',
|
|
188
|
+
data: {
|
|
189
|
+
stdout: error.stdout || '',
|
|
190
|
+
stderr: error.stderr || '',
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
metadata: {
|
|
196
|
+
readonly: false,
|
|
197
|
+
version: '1.0',
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
return scriptsTool;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 导出工具创建函数
|
|
204
|
+
*/
|
|
205
|
+
exports.default = createScriptsTool;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Skills 工具
|
|
4
|
+
*
|
|
5
|
+
* 设计原则 (UNIX哲学):
|
|
6
|
+
* - 简洁: 只负责列出和加载skills,不处理业务逻辑
|
|
7
|
+
* - 模块化: 复用SkillsManager进行实际操作
|
|
8
|
+
* - 组合: 与SDK工具系统无缝集成
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.createSkillsTool = createSkillsTool;
|
|
12
|
+
const tool_1 = require("../tools/tool");
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
/**
|
|
15
|
+
* Skills 工具描述
|
|
16
|
+
*
|
|
17
|
+
* 原始描述(已备份,list操作已临时禁用):
|
|
18
|
+
* const ORIGINAL_DESCRIPTION = `管理和加载skills。
|
|
19
|
+
*
|
|
20
|
+
* 使用此工具来:
|
|
21
|
+
* - 列出所有可用的skills(获取元数据列表)
|
|
22
|
+
* - 加载特定skill的详细内容(包含指令、references、scripts、assets)
|
|
23
|
+
*
|
|
24
|
+
* Skills是可重用的能力单元,可以扩展Agent的功能。`;
|
|
25
|
+
*/
|
|
26
|
+
const DESCRIPTION = `加载特定skill的详细内容。
|
|
27
|
+
|
|
28
|
+
使用此工具来:
|
|
29
|
+
- 加载特定skill的详细内容(包含指令、references、scripts、assets)
|
|
30
|
+
- 需要提供skill_name参数来指定要加载的技能
|
|
31
|
+
|
|
32
|
+
Skills是可重用的能力单元,可以扩展Agent的功能。`;
|
|
33
|
+
/**
|
|
34
|
+
* 创建Skills工具
|
|
35
|
+
*
|
|
36
|
+
* @param skillsManager Skills管理器实例
|
|
37
|
+
* @returns ToolInstance
|
|
38
|
+
*/
|
|
39
|
+
function createSkillsTool(skillsManager) {
|
|
40
|
+
// 临时禁用 list 操作,只保留 load 操作
|
|
41
|
+
// const actionSchema = z.enum(['list', 'load']).describe('操作类型');
|
|
42
|
+
const actionSchema = zod_1.z.enum(['load']).describe('操作类型');
|
|
43
|
+
const skillsTool = (0, tool_1.tool)({
|
|
44
|
+
name: 'skills',
|
|
45
|
+
description: DESCRIPTION,
|
|
46
|
+
parameters: zod_1.z.object({
|
|
47
|
+
action: actionSchema,
|
|
48
|
+
skill_name: zod_1.z.string().optional().describe('技能名称(当action=load时必需)'),
|
|
49
|
+
}),
|
|
50
|
+
async execute(args, ctx) {
|
|
51
|
+
const { action, skill_name } = args;
|
|
52
|
+
// 注释掉 list 操作的代码
|
|
53
|
+
// if (action === 'list') {
|
|
54
|
+
// // 列出所有skills
|
|
55
|
+
// const skills = await skillsManager.getSkillsMetadata();
|
|
56
|
+
//
|
|
57
|
+
// const skillsList = skills.map(s => ({
|
|
58
|
+
// name: s.name,
|
|
59
|
+
// description: s.description,
|
|
60
|
+
// }));
|
|
61
|
+
//
|
|
62
|
+
// return {
|
|
63
|
+
// ok: true,
|
|
64
|
+
// data: {
|
|
65
|
+
// count: skillsList.length,
|
|
66
|
+
// skills: skillsList,
|
|
67
|
+
// },
|
|
68
|
+
// };
|
|
69
|
+
// } else if (action === 'load') {
|
|
70
|
+
if (action === 'load') {
|
|
71
|
+
// 加载特定skill内容
|
|
72
|
+
if (!skill_name) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: 'skill_name is required when action=load',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const content = await skillsManager.loadSkillContent(skill_name);
|
|
79
|
+
if (!content) {
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
error: `Skill '${skill_name}' not found`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
ok: true,
|
|
87
|
+
data: {
|
|
88
|
+
name: content.metadata.name,
|
|
89
|
+
description: content.metadata.description,
|
|
90
|
+
content: content.content,
|
|
91
|
+
base_dir: content.metadata.baseDir,
|
|
92
|
+
references: content.references,
|
|
93
|
+
scripts: content.scripts,
|
|
94
|
+
assets: content.assets,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return {
|
|
100
|
+
ok: false,
|
|
101
|
+
error: `Unknown action: ${action}`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
metadata: {
|
|
106
|
+
readonly: true,
|
|
107
|
+
version: '1.0',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return skillsTool;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 导出工具创建函数
|
|
114
|
+
*/
|
|
115
|
+
exports.default = createSkillsTool;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTaskRunTool = createTaskRunTool;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
function createTaskRunTool(templates) {
|
|
8
|
+
if (!templates || templates.length === 0) {
|
|
9
|
+
throw new Error('Cannot create task_run tool: no agent templates provided');
|
|
10
|
+
}
|
|
11
|
+
const TaskRun = (0, tool_1.tool)({
|
|
12
|
+
name: 'task_run',
|
|
13
|
+
description: prompt_1.DESCRIPTION,
|
|
14
|
+
parameters: zod_1.z.object({
|
|
15
|
+
description: zod_1.z.string().describe('Short description of the task (3-5 words)'),
|
|
16
|
+
prompt: zod_1.z.string().describe('Detailed instructions for the sub-agent'),
|
|
17
|
+
agentTemplateId: zod_1.z.string().describe('Agent template ID to use for this task'),
|
|
18
|
+
context: zod_1.z.string().optional().describe('Additional context to append'),
|
|
19
|
+
}),
|
|
20
|
+
async execute(args, ctx) {
|
|
21
|
+
const { description, prompt, agentTemplateId, context } = args;
|
|
22
|
+
const template = templates.find((tpl) => tpl.id === agentTemplateId);
|
|
23
|
+
if (!template) {
|
|
24
|
+
const availableTemplates = templates
|
|
25
|
+
.map((tpl) => ` - ${tpl.id}: ${tpl.whenToUse || 'General purpose agent'}`)
|
|
26
|
+
.join('\n');
|
|
27
|
+
throw new Error(`Agent template '${agentTemplateId}' not found.\n\nAvailable templates:\n${availableTemplates}\n\nPlease choose one of the available template IDs.`);
|
|
28
|
+
}
|
|
29
|
+
const detailedPrompt = [
|
|
30
|
+
`# Task: ${description}`,
|
|
31
|
+
prompt,
|
|
32
|
+
context ? `\n# Additional Context\n${context}` : undefined,
|
|
33
|
+
]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('\n\n');
|
|
36
|
+
if (!ctx.agent?.delegateTask) {
|
|
37
|
+
throw new Error('Task delegation not supported by this agent version');
|
|
38
|
+
}
|
|
39
|
+
const result = await ctx.agent.delegateTask({
|
|
40
|
+
templateId: template.id,
|
|
41
|
+
prompt: detailedPrompt,
|
|
42
|
+
tools: template.tools,
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
status: result.status,
|
|
46
|
+
template: template.id,
|
|
47
|
+
text: result.text,
|
|
48
|
+
permissionIds: result.permissionIds,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
metadata: {
|
|
52
|
+
readonly: false,
|
|
53
|
+
version: '1.0',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
TaskRun.prompt = (0, prompt_1.generatePrompt)(templates);
|
|
57
|
+
return TaskRun;
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.generatePrompt = generatePrompt;
|
|
5
|
+
exports.DESCRIPTION = 'Delegate a task to a specialized sub-agent';
|
|
6
|
+
function generatePrompt(templates) {
|
|
7
|
+
const templateList = templates
|
|
8
|
+
.map((tpl) => `- agentTemplateId: ${tpl.id}\n whenToUse: ${tpl.whenToUse || 'General purpose tasks'}`)
|
|
9
|
+
.join('\n');
|
|
10
|
+
return `Delegate complex, multi-step work to specialized sub-agents.
|
|
11
|
+
|
|
12
|
+
Instructions:
|
|
13
|
+
- Always provide a concise "description" (3-5 words) and a detailed "prompt" outlining deliverables.
|
|
14
|
+
- REQUIRED: Set "agentTemplateId" to one of the available template IDs below.
|
|
15
|
+
- Optionally supply "context" for extra background information.
|
|
16
|
+
- The tool returns the sub-agent's final text and any pending permissions.
|
|
17
|
+
|
|
18
|
+
Available agent templates:
|
|
19
|
+
${templateList}
|
|
20
|
+
|
|
21
|
+
Safety/Limitations:
|
|
22
|
+
- Sub-agents inherit the same sandbox and tool restrictions.
|
|
23
|
+
- Task delegation depth may be limited to prevent infinite recursion.
|
|
24
|
+
- Sub-agents cannot access parent agent state or context directly.`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoRead = void 0;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
exports.TodoRead = (0, tool_1.tool)({
|
|
8
|
+
name: 'todo_read',
|
|
9
|
+
description: prompt_1.DESCRIPTION,
|
|
10
|
+
parameters: zod_1.z.object({}),
|
|
11
|
+
async execute(_args, ctx) {
|
|
12
|
+
if (ctx.agent?.getTodos) {
|
|
13
|
+
return { todos: ctx.agent.getTodos() };
|
|
14
|
+
}
|
|
15
|
+
const service = ctx.services?.todo;
|
|
16
|
+
if (!service) {
|
|
17
|
+
return {
|
|
18
|
+
todos: [],
|
|
19
|
+
note: 'Todo service not enabled for this agent'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { todos: service.list() };
|
|
23
|
+
},
|
|
24
|
+
metadata: {
|
|
25
|
+
readonly: true,
|
|
26
|
+
version: '1.0',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
exports.TodoRead.prompt = prompt_1.PROMPT;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROMPT = exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.DESCRIPTION = 'Read the current todo list managed by the agent';
|
|
5
|
+
exports.PROMPT = `Retrieve the canonical list of todos that this agent maintains.
|
|
6
|
+
|
|
7
|
+
Guidelines:
|
|
8
|
+
- Use this before planning or reprioritizing work
|
|
9
|
+
- The returned list reflects the current state of all tracked tasks
|
|
10
|
+
- Each todo includes: id, title, status, and optional assignee/notes
|
|
11
|
+
|
|
12
|
+
Todo Status Values:
|
|
13
|
+
- pending: Not yet started
|
|
14
|
+
- in_progress: Currently being worked on
|
|
15
|
+
- completed: Finished
|
|
16
|
+
|
|
17
|
+
Limitations:
|
|
18
|
+
- Returns empty list if todo service is not enabled for this agent`;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoWrite = void 0;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
const todoItemSchema = zod_1.z.object({
|
|
8
|
+
id: zod_1.z.string().describe('Unique identifier for the todo'),
|
|
9
|
+
title: zod_1.z.string().describe('Clear description of the task'),
|
|
10
|
+
status: zod_1.z.enum(['pending', 'in_progress', 'completed']).describe('Current status'),
|
|
11
|
+
assignee: zod_1.z.string().optional().describe('Who is responsible'),
|
|
12
|
+
notes: zod_1.z.string().optional().describe('Additional context'),
|
|
13
|
+
});
|
|
14
|
+
exports.TodoWrite = (0, tool_1.tool)({
|
|
15
|
+
name: 'todo_write',
|
|
16
|
+
description: prompt_1.DESCRIPTION,
|
|
17
|
+
parameters: zod_1.z.object({
|
|
18
|
+
todos: zod_1.z.array(todoItemSchema).describe('Array of todo items'),
|
|
19
|
+
}),
|
|
20
|
+
async execute(args, ctx) {
|
|
21
|
+
const { todos } = args;
|
|
22
|
+
const inProgressCount = todos.filter((t) => t.status === 'in_progress').length;
|
|
23
|
+
if (inProgressCount > 1) {
|
|
24
|
+
throw new Error(`Only one todo can be "in_progress" at a time. Found ${inProgressCount} in_progress todos.`);
|
|
25
|
+
}
|
|
26
|
+
if (!ctx.agent?.setTodos) {
|
|
27
|
+
const service = ctx.services?.todo;
|
|
28
|
+
if (!service) {
|
|
29
|
+
throw new Error('Todo service not enabled for this agent');
|
|
30
|
+
}
|
|
31
|
+
await service.setTodos(todos);
|
|
32
|
+
return { ok: true, count: todos.length };
|
|
33
|
+
}
|
|
34
|
+
await ctx.agent.setTodos(todos);
|
|
35
|
+
return { ok: true, count: todos.length };
|
|
36
|
+
},
|
|
37
|
+
metadata: {
|
|
38
|
+
readonly: false,
|
|
39
|
+
version: '1.0',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
exports.TodoWrite.prompt = prompt_1.PROMPT;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROMPT = exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.DESCRIPTION = 'Replace the todo list managed by the agent';
|
|
5
|
+
exports.PROMPT = `Replace the agent-managed todo list with a new array of todos.
|
|
6
|
+
|
|
7
|
+
Guidelines:
|
|
8
|
+
- Always provide structured IDs, titles, and statuses
|
|
9
|
+
- Only ONE item may have "in_progress" status at any time
|
|
10
|
+
- IDs should be unique and descriptive
|
|
11
|
+
- Titles should be clear and actionable
|
|
12
|
+
|
|
13
|
+
Todo Structure:
|
|
14
|
+
- id (required): Unique identifier for the todo
|
|
15
|
+
- title (required): Clear description of the task
|
|
16
|
+
- status (required): "pending" | "in_progress" | "completed"
|
|
17
|
+
- assignee (optional): Who is responsible
|
|
18
|
+
- notes (optional): Additional context or details
|
|
19
|
+
|
|
20
|
+
Safety/Limitations:
|
|
21
|
+
- This operation replaces the entire todo list
|
|
22
|
+
- Previous todos not included in the new list will be removed
|
|
23
|
+
- Returns error if todo service is not enabled`;
|