foliko 2.0.5 → 2.0.7

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.
Files changed (93) hide show
  1. package/.claude/settings.local.json +4 -1
  2. package/.cli_default_systemPrompt.md +291 -0
  3. package/CLAUDE.md +3 -0
  4. package/README.md +20 -3
  5. package/docs/architecture.md +34 -2
  6. package/docs/extensions.md +199 -0
  7. package/docs/migration.md +100 -0
  8. package/docs/public-api.md +280 -24
  9. package/docs/usage.md +122 -30
  10. package/package.json +1 -1
  11. package/plugins/core/audit/index.js +1 -1
  12. package/plugins/core/default/bootstrap.js +44 -19
  13. package/plugins/core/python-loader/index.js +43 -25
  14. package/plugins/core/scheduler/index.js +1 -0
  15. package/plugins/core/skill-manager/PROMPT.md +6 -0
  16. package/plugins/core/skill-manager/index.js +402 -115
  17. package/plugins/core/sub-agent/PROMPT.md +10 -0
  18. package/plugins/core/sub-agent/index.js +36 -3
  19. package/plugins/core/think/index.js +1 -0
  20. package/plugins/core/workflow/context.js +941 -0
  21. package/plugins/core/workflow/engine.js +66 -0
  22. package/plugins/core/workflow/examples/01-basic.js +42 -0
  23. package/plugins/core/workflow/examples/01-basic.json +30 -0
  24. package/plugins/core/workflow/examples/02-choice.js +75 -0
  25. package/plugins/core/workflow/examples/02-choice.json +59 -0
  26. package/plugins/core/workflow/examples/03-chain-style.js +114 -0
  27. package/plugins/core/workflow/examples/03-each.json +41 -0
  28. package/plugins/core/workflow/examples/04-parallel.js +52 -0
  29. package/plugins/core/workflow/examples/04-parallel.json +51 -0
  30. package/plugins/core/workflow/examples/05-chain-style.json +68 -0
  31. package/plugins/core/workflow/examples/05-each.js +65 -0
  32. package/plugins/core/workflow/examples/06-script.js +82 -0
  33. package/plugins/core/workflow/examples/07-module-export.js +43 -0
  34. package/plugins/core/workflow/examples/08-default-export.js +29 -0
  35. package/plugins/core/workflow/examples/09-next-with-args.js +50 -0
  36. package/plugins/core/workflow/examples/10-logger.js +34 -0
  37. package/plugins/core/workflow/examples/11-storage.js +68 -0
  38. package/plugins/core/workflow/examples/simple.js +77 -0
  39. package/plugins/core/workflow/examples/simple.json +75 -0
  40. package/plugins/core/workflow/index.js +204 -78
  41. package/plugins/core/workflow/js-runner.js +318 -0
  42. package/plugins/core/workflow/json-runner.js +323 -0
  43. package/plugins/core/workflow/stages/action.js +211 -0
  44. package/plugins/core/workflow/stages/choice.js +74 -0
  45. package/plugins/core/workflow/stages/delay.js +73 -0
  46. package/plugins/core/workflow/stages/each.js +123 -0
  47. package/plugins/core/workflow/stages/parallel.js +69 -0
  48. package/plugins/core/workflow/stages/try.js +142 -0
  49. package/plugins/executors/data-splitter/PROMPT.md +13 -0
  50. package/plugins/executors/data-splitter/index.js +8 -6
  51. package/plugins/executors/extension/extension-registry.js +145 -0
  52. package/plugins/executors/extension/index.js +405 -437
  53. package/plugins/executors/extension/prompt-builder.js +359 -0
  54. package/plugins/executors/extension/skill-helper.js +143 -0
  55. package/plugins/messaging/feishu/index.js +5 -3
  56. package/plugins/messaging/qq/index.js +6 -4
  57. package/plugins/messaging/telegram/index.js +6 -3
  58. package/plugins/messaging/weixin/index.js +5 -3
  59. package/plugins/tools/PROMPT.md +26 -0
  60. package/plugins/tools/index.js +6 -5
  61. package/sandbox/check-context.js +5 -0
  62. package/sandbox/test-context.js +27 -0
  63. package/sandbox/test-fixes.js +40 -0
  64. package/sandbox/test-hello-js.js +46 -0
  65. package/skills/foliko/AGENTS.md +196 -43
  66. package/skills/foliko/SKILL.md +157 -28
  67. package/skills/mcp/SKILL.md +77 -118
  68. package/skills/plugins/SKILL.md +89 -3
  69. package/skills/python/SKILL.md +57 -39
  70. package/skills/skill-guide/SKILL.md +42 -34
  71. package/skills/workflows/SKILL.md +753 -436
  72. package/src/agent/chat.js +56 -28
  73. package/src/agent/main.js +39 -14
  74. package/src/agent/prompt-registry.js +56 -16
  75. package/src/agent/prompts/PROMPT.md +3 -0
  76. package/src/agent/sub.js +1 -1
  77. package/src/cli/ui/chat-ui-old.js +5 -2
  78. package/src/cli/ui/chat-ui.js +9 -5
  79. package/src/common/constants.js +12 -0
  80. package/src/common/error-capture.js +91 -0
  81. package/src/common/json-safe.js +20 -0
  82. package/src/common/logger.js +2 -2
  83. package/src/context/compressor.js +6 -2
  84. package/src/executors/mcp-executor.js +105 -125
  85. package/src/framework/framework.js +78 -12
  86. package/src/index.js +4 -0
  87. package/src/plugin/base.js +908 -5
  88. package/src/plugin/manager.js +124 -9
  89. package/src/tool/schema.js +32 -9
  90. package/src/utils/sandbox.js +1 -1
  91. package/website/index.html +821 -0
  92. package/skills/workflows/workflow-troubleshooting/DEBUGGING.md +0 -197
  93. package/skills/workflows/workflow-troubleshooting/SKILL.md +0 -391
@@ -0,0 +1,40 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const helloPath = path.resolve('.foliko/workflows/hello-js.js');
5
+ delete require.cache[helloPath];
6
+ const helloModule = require(helloPath);
7
+
8
+ const t = typeof helloModule;
9
+ console.log('hello-js.js type:', t);
10
+
11
+ if (t === 'function') {
12
+ try {
13
+ const wf = helloModule({});
14
+ console.log('returned keys:', Object.keys(wf));
15
+ console.log(
16
+ 'steps count:',
17
+ Array.isArray(wf.steps) ? wf.steps.length : 'N/A'
18
+ );
19
+ console.log('OK: js workflow shape is v2 compatible');
20
+ } catch (e) {
21
+ console.log('execution failed (expected):', e.message);
22
+ }
23
+ }
24
+
25
+ // Also verify the manager.js and workflow/index.js parse OK
26
+ const filesToCheck = [
27
+ 'src/plugin/manager.js',
28
+ 'plugins/core/workflow/index.js',
29
+ ];
30
+
31
+ for (const rel of filesToCheck) {
32
+ const p = path.resolve(rel);
33
+ delete require.cache[p];
34
+ try {
35
+ const m = require(p);
36
+ console.log(`OK ${rel}: parsed, exports=`, Object.keys(m).slice(0, 5));
37
+ } catch (e) {
38
+ console.log(`FAIL ${rel}:`, e.message);
39
+ }
40
+ }
@@ -0,0 +1,46 @@
1
+ (async () => {
2
+ try {
3
+ const { JsRunner } = require('../plugins/core/workflow/js-runner');
4
+ const stubFramework = {
5
+ executeTool: async (name, args, sid) => {
6
+ console.log(' [tool]', name, JSON.stringify(args));
7
+ return { success: true, data: 'tool_ok', echo: args };
8
+ },
9
+ runWithContext: async (ctx, fn) => fn(),
10
+ getExecutionContext: () => ({ sessionId: 'test-session' })
11
+ };
12
+ // Override the proxy used by JsRunner to bind tool/extension/etc.
13
+ // (see fix in _createFlowApi below)
14
+ const origRequire = require.cache[require.resolve('../plugins/core/workflow/js-runner.js')].exports;
15
+ console.log('JsRunner exports:', Object.keys(origRequire));
16
+ console.log('tool keys at runtime:');
17
+ const { FlowContext } = require('../plugins/core/workflow/context');
18
+ const c = new FlowContext({}, 'sid');
19
+ c.setFramework(stubFramework);
20
+ const t = c.tool;
21
+ console.log(' t:', t);
22
+ console.log(' Object.getOwnPropertyNames:', Object.getOwnPropertyNames(t));
23
+ console.log(' for-in:');
24
+ for (const k in t) { console.log(' -', k); }
25
+ console.log(' execute type:', typeof t.execute);
26
+ const r = new JsRunner(stubFramework);
27
+ const wfPath = require.resolve('../.foliko/workflows/hello-js.js');
28
+ delete require.cache[wfPath];
29
+ const wf = require(wfPath);
30
+ const res = await r.execute(wf, {}, 'test-session');
31
+ console.log('Result:', JSON.stringify(res, null, 2));
32
+
33
+ // Direct test of $.tool
34
+ console.log('Direct $.tool test...');
35
+ const $obj = { data: {}, get tool() { return c.tool; }, push: () => {}, next: () => {} };
36
+ try {
37
+ const out = await $.tool.execute('notification_send', { title: 'x', message: 'y' });
38
+ console.log('Direct $.tool result:', out);
39
+ } catch (e) {
40
+ console.log('Direct $.tool error:', e.message);
41
+ }
42
+ } catch (err) {
43
+ console.error('OUTER ERROR:', err && err.stack || err);
44
+ process.exit(1);
45
+ }
46
+ })();
@@ -63,19 +63,18 @@ module.exports = function (Plugin) {
63
63
  this.priority = 10;
64
64
  }
65
65
 
66
- install(framework) {
67
- const { z } = require('zod');
68
- framework.registerTool({
66
+ onStart(framework) {
67
+ // Register AI SDK tool
68
+ this.tool.register({
69
69
  name: 'my_tool',
70
70
  description: '工具描述',
71
- inputSchema: z.object({
72
- param: z.string().describe('参数描述'),
71
+ inputSchema: framework.z.object({
72
+ param: framework.z.string().describe('参数描述'),
73
73
  }),
74
- execute: async (args, framework) => {
74
+ execute: async (args) => {
75
75
  return { success: true, result: args.param };
76
76
  },
77
77
  });
78
- return this;
79
78
  }
80
79
 
81
80
  uninstall(framework) {
@@ -119,18 +118,17 @@ class MyPlugin extends Plugin {
119
118
  this.priority = 10;
120
119
  }
121
120
 
122
- install(framework) {
123
- framework.registerTool({
121
+ onStart(framework) {
122
+ this.tool.register({
124
123
  name: 'my_tool',
125
124
  description: '工具描述',
126
- inputSchema: z.object({
127
- param: z.string().describe('参数描述'),
125
+ inputSchema: framework.z.object({
126
+ param: framework.z.string().describe('参数描述'),
128
127
  }),
129
- execute: async (args, framework) => {
128
+ execute: async (args) => {
130
129
  return { success: true, result: args.param };
131
130
  },
132
131
  });
133
- return this;
134
132
  }
135
133
 
136
134
  uninstall(framework) {}
@@ -150,47 +148,204 @@ module.exports = { MyPlugin };
150
148
 
151
149
  ## Lifecycle Methods
152
150
 
153
- | Method | Called When | Required |
154
- | ---------------------- | ------------------ | ----------- |
155
- | `install(framework)` | Plugin installed | ✅ |
156
- | `start(framework)` | Plugin started | Recommended |
157
- | `reload(framework)` | Hot reload | Optional |
158
- | `uninstall(framework)` | Plugin uninstalled | Recommended |
151
+ | Method | Called When | Required | Description |
152
+ |--------|-------------|----------|-------------|
153
+ | `install(framework)` | Plugin installed | ✅ | Initialize, get framework |
154
+ | `onStart(framework)` | start/enable/reload | Recommended | Register tools, extensions, sub-agents |
155
+ | `onStop()` | disable | Optional | Cleanup resources |
156
+ | `reload(framework)` | Hot reload | Optional | prompts auto cleanup/register |
157
+ | `uninstall(framework)` | Plugin uninstalled | Recommended | Cleanup resources |
158
+
159
+ ### onStart / onStop (Recommended)
160
+
161
+ **Use `onStart` to register tools and extensions** - base class handles lifecycle automatically:
162
+
163
+ ```javascript
164
+ class MyPlugin extends Plugin {
165
+ name = 'my-plugin';
166
+ version = '1.0.0';
167
+ description = '我的插件';
168
+
169
+ onStart(framework) {
170
+ // Register AI SDK tool (direct call)
171
+ this.tool.register({
172
+ name: 'hello',
173
+ description: '打招呼',
174
+ inputSchema: framework.z.object({
175
+ name: framework.z.string().describe('姓名')
176
+ }),
177
+ execute: async (args) => ({ message: `Hello, ${args.name}!` }),
178
+ });
179
+
180
+ // Register extension tool (via ext_call)
181
+ this.extension.register({
182
+ name: 'greet',
183
+ description: '打招呼扩展',
184
+ inputSchema: framework.z.object({
185
+ name: framework.z.string()
186
+ }),
187
+ execute: async (args) => ({ message: `Hi, ${args.name}!` }),
188
+ });
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### Lifecycle Auto-Management
194
+
195
+ | Operation | Effect |
196
+ |-----------|--------|
197
+ | `disable` | Auto-remove tools/extensions (keep registration records) |
198
+ | `enable` | Auto re-register tools/extensions |
199
+ | `reload` | Remove and re-register |
200
+ | `uninstall` | Remove and clear registration records |
159
201
 
160
202
  ## Tool Registration
161
203
 
162
- In `install()` method, register tools using `framework.registerTool()`:
204
+ ### Recommended: `this.tool.register()` in `onStart`
205
+
206
+ ```javascript
207
+ onStart(framework) {
208
+ this.tool.register({
209
+ name: 'my_tool',
210
+ description: 'Tool description',
211
+ inputSchema: framework.z.object({
212
+ param: framework.z.string().describe('Parameter description')
213
+ }),
214
+ execute: async (args) => ({ success: true, result: args.param })
215
+ });
216
+ }
217
+ ```
218
+
219
+ ### Alternative: `this.tools = {}` (ExtensionExecutor auto-scan)
220
+
221
+ ```javascript
222
+ class MyPlugin extends Plugin {
223
+ name = 'my-plugin';
224
+
225
+ tools = {
226
+ my_tool: {
227
+ description: 'Tool description',
228
+ inputSchema: z.object({
229
+ param: z.string().describe('Parameter description')
230
+ }),
231
+ execute: async (args) => ({ success: true })
232
+ }
233
+ };
234
+ }
235
+ ```
236
+
237
+ ### Legacy: `framework.registerTool()` in `install()`
163
238
 
164
239
  ```javascript
165
240
  install(framework) {
166
- const { z } = require('zod')
167
241
  framework.registerTool({
168
242
  name: 'my_tool',
169
- description: '工具描述',
170
- inputSchema: z.object({
171
- param: z.string().describe('参数描述')
243
+ description: 'Tool description',
244
+ inputSchema: framework.z.object({
245
+ param: framework.z.string().describe('Parameter description')
172
246
  }),
173
- execute: async (args, framework) => {
174
- return { success: true, result: args.param }
175
- }
176
- })
177
- return this
247
+ execute: async (args) => ({ success: true })
248
+ });
249
+ return this;
250
+ }
251
+ ```
252
+
253
+ ## Extension Registration
254
+
255
+ ```javascript
256
+ onStart(framework) {
257
+ this.extension.register({
258
+ name: 'my_ext_tool',
259
+ description: 'Extension tool',
260
+ inputSchema: framework.z.object({
261
+ param: framework.z.string()
262
+ }),
263
+ execute: async (args) => ({ success: true })
264
+ });
178
265
  }
179
266
  ```
180
267
 
268
+ ## Tool/Extension Operations
269
+
270
+ ```javascript
271
+ // Register
272
+ this.tool.register({ name: 'xxx', ... });
273
+ this.extension.register({ name: 'xxx', ... });
274
+
275
+ // Remove
276
+ this.tool.remove('xxx');
277
+ this.extension.remove('xxx');
278
+
279
+ // Execute
280
+ const r1 = await this.tool.execute('any-tool', { arg: 'value' }); // Execute any registered tool
281
+ const r2 = await this.extension.execute('xxx', { arg: 'value' }); // Execute current plugin's extension
282
+ const r3 = await this.extension.execute('plugin-name', 'xxx', { arg: 'value' }); // Execute specified plugin's extension
283
+ ```
284
+
285
+ ## Workflow Operations
286
+
287
+ ```javascript
288
+ // Register workflow
289
+ this.workflow.register('my-workflow', {
290
+ name: 'my-workflow',
291
+ description: 'My workflow',
292
+ steps: [
293
+ { type: 'tool', tool: 'hello', args: {} }
294
+ ]
295
+ });
296
+
297
+ // Execute workflow
298
+ const result = await this.workflow.execute('my-workflow', { input: 'value' });
299
+
300
+ // Remove workflow
301
+ this.workflow.remove('my-workflow');
302
+ ```
303
+
304
+ ## Agent Operations
305
+
306
+ ```javascript
307
+ // Register sub-agent
308
+ this.agent.register({
309
+ name: 'my-agent',
310
+ role: 'Assistant',
311
+ goal: 'Description',
312
+ tools: {},
313
+ parentTools: ['read_file', 'write_file']
314
+ });
315
+
316
+ // Get sub-agent
317
+ const agent = this.agent.get('my-agent');
318
+
319
+ // Remove sub-agent
320
+ this.agent.remove('my-agent');
321
+ ```
322
+
323
+ ## Prompt Operations
324
+
325
+ ```javascript
326
+ // Register prompt
327
+ this.prompt.register('my-prompt', () => 'Prompt content', {
328
+ scope: 'global',
329
+ priority: 50
330
+ });
331
+
332
+ // Remove prompt
333
+ this.prompt.remove('my-prompt');
334
+ ```
335
+
181
336
  ## Framework Object
182
337
 
183
338
  The framework object provides:
184
339
 
185
- | Method | Description |
186
- | ----------------------------------- | ------------------------------- |
187
- | `framework.registerTool(tool)` | Register tool |
188
- | `framework.getTools()` | Get all tools |
189
- | `framework.executeTool(name, args)` | Execute tool |
190
- | `framework.callTool(name, args)` | Call tool (for installing deps) |
191
- | `framework.createAgent(config)` | Create Agent |
192
- | `framework.reloadPlugin(name)` | Reload single plugin |
193
- | `framework.reloadAllPlugins()` | Reload all plugins |
340
+ | Method | Description |
341
+ |--------|-------------|
342
+ | `framework.registerTool(tool)` | Register tool (legacy) |
343
+ | `framework.getTools()` | Get all tools |
344
+ | `framework.executeTool(name, args)` | Execute tool |
345
+ | `framework.callTool(name, args)` | Call tool (for installing deps) |
346
+ | `framework.createAgent(config)` | Create Agent |
347
+ | `framework.reloadPlugin(name)` | Reload single plugin |
348
+ | `framework.reloadAllPlugins()` | Reload all plugins |
194
349
 
195
350
  ## Dependency Management
196
351
 
@@ -229,8 +384,6 @@ await framework.callTool('install', {
229
384
 
230
385
  ## Common Mistakes
231
386
 
232
- 1. ❌ Forgetting `install()` - tools won't be registered
233
- 2. ❌ Forgetting `return this` - chain calls will fail
234
- 3. ❌ Using `parameters` instead of `inputSchema`
235
- 4. ❌ Registering tools outside `install()`
236
- 5. ❌ Using same name for folder and file - folder takes priority, file will be ignored
387
+ 1. ❌ Using `parameters` instead of `inputSchema`
388
+ 2. ❌ Forgetting `framework.` prefix when using `framework.z.object()`
389
+ 3. ❌ Using same name for folder and file - folder takes priority, file will be ignored
@@ -341,28 +341,69 @@ module.exports = MyPlugin;
341
341
 
342
342
  ## 生命周期
343
343
 
344
- | 方法 | 调用时机 | 必须实现 |
345
- | ---------------------- | ---------- | -------- |
346
- | `install(framework)` | 插件安装时 | ✅ |
347
- | `start(framework)` | 插件启动时 | 推荐 |
348
- | `reload(framework)` | 热重载时 | 可选 |
349
- | `uninstall(framework)` | 卸载时 | 推荐 |
344
+ | 方法 | 调用时机 | 必须实现 | 说明 |
345
+ |------|----------|----------|------|
346
+ | `install(framework)` | 插件安装时 | ✅ | 初始化,获取 framework |
347
+ | `onStart(framework)` | start/enable/reload | 推荐 | 注册工具、扩展、子代理 |
348
+ | `onStop()` | disable 时 | 可选 | 清理资源 |
349
+ | `reload(framework)` | 热重载时 | 可选 | prompts 自动清理/注册 |
350
+ | `uninstall(framework)` | 卸载时 | 推荐 | 清理资源 |
351
+
352
+ ### onStart / onStop(推荐方式)
353
+
354
+ **推荐使用 `onStart` 注册工具和扩展**,基类自动处理生命周期:
355
+
356
+ ```javascript
357
+ class MyPlugin extends Plugin {
358
+ name = 'my-plugin';
359
+ version = '1.0.0';
360
+ description = '我的工具插件';
361
+
362
+ onStart(framework) {
363
+ // 注册 AI SDK 工具(直接调用)
364
+ this.tool.register({
365
+ name: 'hello',
366
+ description: '打招呼',
367
+ inputSchema: framework.z.object({
368
+ name: framework.z.string().describe('姓名')
369
+ }),
370
+ execute: async (args) => ({ message: `Hello, ${args.name}!` }),
371
+ });
372
+
373
+ // 注册扩展工具(通过 ext_call 调用)
374
+ this.extension.register({
375
+ name: 'greet',
376
+ description: '打招呼扩展',
377
+ inputSchema: framework.z.object({
378
+ name: framework.z.string()
379
+ }),
380
+ execute: async (args) => ({ message: `Hi, ${args.name}!` }),
381
+ });
382
+ }
383
+ }
384
+ ```
385
+
386
+ ### 生命周期自动管理
387
+
388
+ | 操作 | 效果 |
389
+ |------|------|
390
+ | `disable` | 自动移除工具/扩展(保留注册记录) |
391
+ | `enable` | 自动重新注册工具/扩展 |
392
+ | `reload` | 移除后重新注册 |
393
+ | `uninstall` | 移除并清空注册记录 |
350
394
 
351
395
  ---
352
396
 
353
397
  ## 注册工具
354
398
 
355
- ### 最新方式:定义在 `this.tools = {}`
399
+ ### 方式1:`this.tools = {}`(ExtensionExecutor 自动扫描)
356
400
 
357
- 插件将工具定义在 `this.tools = {}` 中,ExtensionExecutor 会自动扫描并注册到系统提示词:
401
+ 插件将工具定义在 `this.tools = {}` 中,ExtensionExecutor 会自动扫描并注册:
358
402
 
359
403
  ```javascript
360
404
  class MyPlugin extends Plugin {
361
- constructor(config = {}) {
362
- super();
363
- this.name = 'my-plugin';
364
- this.description = '我的工具插件';
365
- }
405
+ name = 'my-plugin';
406
+ description = '我的工具插件';
366
407
 
367
408
  tools = {
368
409
  my_tool: {
@@ -378,37 +419,125 @@ class MyPlugin extends Plugin {
378
419
  }
379
420
  ```
380
421
 
381
- ### 方式2:使用 `this.registerTool()`
422
+ ### 方式2:`this.tool.register()`(推荐)
382
423
 
383
- 支持两种调用格式:
424
+ 在 `onStart` 中使用,支持完整的生命周期管理:
384
425
 
385
426
  ```javascript
386
- install(framework) {
387
- const { z } = require('zod');
388
-
389
- // 方式1:分开传 name 和 def
390
- this.registerTool('my_tool', {
427
+ onStart(framework) {
428
+ this.tool.register({
429
+ name: 'my_tool',
391
430
  description: '我的工具',
392
- inputSchema: z.object({
393
- param: z.string().describe('参数描述')
431
+ inputSchema: framework.z.object({
432
+ param: framework.z.string().describe('参数描述')
394
433
  }),
395
434
  execute: async (args) => {
396
435
  return { success: true, result: args.param };
397
436
  }
398
437
  });
438
+ }
439
+ ```
399
440
 
400
- // 方式2:直接传对象(name 在对象中)
401
- this.registerTool({
402
- name: 'another_tool',
403
- description: '另一个工具',
404
- inputSchema: z.object({}),
441
+ ### 方式3:`this.registerTool()`(旧方式)
442
+
443
+ ```javascript
444
+ install(framework) {
445
+ this.registerTool('my_tool', {
446
+ description: '我的工具',
447
+ inputSchema: framework.z.object({
448
+ param: framework.z.string().describe('参数描述')
449
+ }),
405
450
  execute: async (args) => ({ success: true })
406
451
  });
407
-
408
452
  return this;
409
453
  }
410
454
  ```
411
455
 
456
+ ### 注册扩展工具
457
+
458
+ ```javascript
459
+ onStart(framework) {
460
+ this.extension.register({
461
+ name: 'my_ext_tool',
462
+ description: '扩展工具',
463
+ inputSchema: framework.z.object({
464
+ param: framework.z.string()
465
+ }),
466
+ execute: async (args) => ({ success: true })
467
+ });
468
+ }
469
+ ```
470
+
471
+ ---
472
+
473
+ ## 工具/扩展操作
474
+
475
+ ```javascript
476
+ // 注册
477
+ this.tool.register({ name: 'xxx', ... });
478
+ this.extension.register({ name: 'xxx', ... });
479
+
480
+ // 移除
481
+ this.tool.remove('xxx');
482
+ this.extension.remove('xxx');
483
+
484
+ // 执行
485
+ const r1 = await this.tool.execute('any-tool', { arg: 'value' }); // 执行任何已注册工具
486
+ const r2 = await this.extension.execute('xxx', { arg: 'value' }); // 执行当前插件的扩展
487
+ const r3 = await this.extension.execute('plugin-name', 'xxx', { arg: 'value' }); // 执行指定插件的扩展
488
+ ```
489
+
490
+ ## 工作流操作
491
+
492
+ ```javascript
493
+ // 注册工作流
494
+ this.workflow.register('my-workflow', {
495
+ name: 'my-workflow',
496
+ description: '我的工作流',
497
+ steps: [
498
+ { type: 'tool', tool: 'hello', args: {} }
499
+ ]
500
+ });
501
+
502
+ // 执行工作流
503
+ const result = await this.workflow.execute('my-workflow', { input: 'value' });
504
+
505
+ // 移除工作流
506
+ this.workflow.remove('my-workflow');
507
+ ```
508
+
509
+ ## 子代理操作
510
+
511
+ ```javascript
512
+ // 注册子代理
513
+ this.agent.register({
514
+ name: 'my-agent',
515
+ role: '助手',
516
+ goal: '描述',
517
+ tools: {},
518
+ parentTools: ['read_file', 'write_file']
519
+ });
520
+
521
+ // 获取子代理
522
+ const agent = this.agent.get('my-agent');
523
+
524
+ // 移除子代理
525
+ this.agent.remove('my-agent');
526
+ ```
527
+
528
+ ## Prompt 操作
529
+
530
+ ```javascript
531
+ // 注册 prompt
532
+ this.prompt.register('my-prompt', () => 'Prompt content', {
533
+ scope: 'global',
534
+ priority: 50
535
+ });
536
+
537
+ // 移除 prompt
538
+ this.prompt.remove('my-prompt');
539
+ ```
540
+
412
541
  ---
413
542
 
414
543
  ## 核心规则