foliko 1.1.13 → 1.1.14

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 (246) hide show
  1. package/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
  2. package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
  3. package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
  4. package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
  5. package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
  6. package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
  7. package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
  8. package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  9. package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  10. package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  11. package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  12. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  13. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  14. package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  15. package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
  16. package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  17. package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  18. package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  19. package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  20. package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
  21. package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
  22. package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  23. package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  24. package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
  25. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
  26. package/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-313.pyc +0 -0
  27. package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
  28. package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
  29. package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
  30. package/.agent/ARCHITECTURE.md +288 -0
  31. package/.agent/agents/ambient-agent.md +57 -0
  32. package/.agent/agents/debugger.md +55 -0
  33. package/.agent/agents/email-assistant.md +49 -0
  34. package/.agent/agents/file-manager.md +42 -0
  35. package/.agent/agents/poster-expert.md +135 -196
  36. package/.agent/agents/python-developer.md +60 -0
  37. package/.agent/agents/scheduler.md +59 -0
  38. package/.agent/agents/web-developer.md +45 -0
  39. package/.agent/data/default.json +404 -9
  40. package/.agent/data/plugins-state.json +172 -173
  41. package/.agent/data/puppeteer-sessions/undefined.json +6 -0
  42. package/.agent/data/weixin-media/2026-04-08/img_1775618677512.jpg +0 -0
  43. package/.agent/data/weixin-media/2026-04-08/img_1775619073340.jpg +0 -0
  44. package/.agent/data/weixin-media/2026-04-08/img_1775619097536.jpg +0 -0
  45. package/.agent/data/weixin-media/2026-04-08/img_1775619209388.jpg +0 -0
  46. package/.agent/mcp_config.json +21 -0
  47. package/.agent/memory/feedback/mnygjgox-ualjip.md +11 -0
  48. package/.agent/memory/project/mnqx54u5-loqtoe.md +9 -0
  49. package/.agent/memory/project/mnqx84cv-mx6dmd.md +9 -0
  50. package/.agent/memory/project/mnsacuyr-hgtk5n.md +20 -0
  51. package/.agent/memory/project/mnu5hy2x-bjsg7u.md +9 -0
  52. package/.agent/memory/project/mny28ot4-8qe9au.md +9 -0
  53. package/.agent/memory/reference/mnre3cww-penbo1.md +9 -0
  54. package/.agent/memory/reference/mns9wn48-luerua.md +14 -0
  55. package/.agent/memory/reference/mns9yz5c-thc2s0.md +16 -0
  56. package/.agent/memory/reference/mnsfy4um-910f1o.md +23 -0
  57. package/.agent/memory/reference/mnsg37dp-lmfj18.md +32 -0
  58. package/.agent/memory/reference/mnsll60q-0j911u.md +36 -0
  59. package/.agent/memory/reference/mnsmlb5y-nej31u.md +16 -0
  60. package/.agent/memory/reference/mnssle72-yrot96.md +9 -0
  61. package/.agent/memory/reference/mnygj8nb-bjthmc.md +20 -0
  62. package/.agent/memory/user/mnsfuon6-l416q1.md +21 -0
  63. package/.agent/memory/user/mnsg9kut-95m7rf.md +20 -0
  64. package/.agent/memory/user/mnu2eo1v-yy6fhe.md +9 -0
  65. package/.agent/memory/user/mnu2etuo-8u8jk8.md +9 -0
  66. package/.agent/memory/user/mnx0rk6g-gsznjj.md +9 -0
  67. package/.agent/memory/user/mnyf1riz-4yo5yz.md +9 -0
  68. package/.agent/plugins/puppeteer-plugin/README.md +147 -0
  69. package/.agent/plugins/puppeteer-plugin/index.js +1422 -0
  70. package/.agent/plugins/puppeteer-plugin/package.json +9 -0
  71. package/.agent/plugins.json +5 -11
  72. package/.agent/rules/GEMINI.md +273 -0
  73. package/.agent/rules/allow-rule.md +77 -0
  74. package/.agent/rules/log-rule.md +83 -0
  75. package/.agent/rules/security-rule.md +93 -0
  76. package/.agent/scripts/auto_preview.py +148 -0
  77. package/.agent/scripts/checklist.py +217 -0
  78. package/.agent/scripts/session_manager.py +120 -0
  79. package/.agent/scripts/verify_all.py +327 -0
  80. package/.agent/sessions/cli_default.json +11 -641
  81. package/.agent/skills/api-patterns/SKILL.md +81 -0
  82. package/.agent/skills/api-patterns/api-style.md +42 -0
  83. package/.agent/skills/api-patterns/auth.md +24 -0
  84. package/.agent/skills/api-patterns/documentation.md +26 -0
  85. package/.agent/skills/api-patterns/graphql.md +41 -0
  86. package/.agent/skills/api-patterns/rate-limiting.md +31 -0
  87. package/.agent/skills/api-patterns/response.md +37 -0
  88. package/.agent/skills/api-patterns/rest.md +40 -0
  89. package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
  90. package/.agent/skills/api-patterns/security-testing.md +122 -0
  91. package/.agent/skills/api-patterns/trpc.md +41 -0
  92. package/.agent/skills/api-patterns/versioning.md +22 -0
  93. package/.agent/skills/app-builder/SKILL.md +75 -0
  94. package/.agent/skills/app-builder/agent-coordination.md +71 -0
  95. package/.agent/skills/app-builder/feature-building.md +53 -0
  96. package/.agent/skills/app-builder/project-detection.md +34 -0
  97. package/.agent/skills/app-builder/scaffolding.md +118 -0
  98. package/.agent/skills/app-builder/tech-stack.md +40 -0
  99. package/.agent/skills/app-builder/templates/SKILL.md +39 -0
  100. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  101. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  102. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  103. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  104. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  105. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  106. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  107. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
  108. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
  109. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
  110. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
  111. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  112. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
  113. package/.agent/skills/architecture/SKILL.md +55 -0
  114. package/.agent/skills/architecture/context-discovery.md +43 -0
  115. package/.agent/skills/architecture/examples.md +94 -0
  116. package/.agent/skills/architecture/pattern-selection.md +68 -0
  117. package/.agent/skills/architecture/patterns-reference.md +50 -0
  118. package/.agent/skills/architecture/trade-off-analysis.md +77 -0
  119. package/.agent/skills/clean-code/SKILL.md +201 -0
  120. package/.agent/skills/doc.md +177 -0
  121. package/.agent/skills/frontend-design/SKILL.md +418 -0
  122. package/.agent/skills/frontend-design/animation-guide.md +331 -0
  123. package/.agent/skills/frontend-design/color-system.md +311 -0
  124. package/.agent/skills/frontend-design/decision-trees.md +418 -0
  125. package/.agent/skills/frontend-design/motion-graphics.md +306 -0
  126. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  127. package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
  128. package/.agent/skills/frontend-design/typography-system.md +345 -0
  129. package/.agent/skills/frontend-design/ux-psychology.md +1116 -0
  130. package/.agent/skills/frontend-design/visual-effects.md +383 -0
  131. package/.agent/skills/i18n-localization/SKILL.md +154 -0
  132. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  133. package/.agent/skills/mcp-builder/SKILL.md +176 -0
  134. package/.agent/skills/poster-design/SKILL.md +385 -0
  135. package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
  136. package/.agent/workflows/brainstorm.md +113 -0
  137. package/.agent/workflows/create.md +59 -0
  138. package/.agent/workflows/debug.md +103 -0
  139. package/.agent/workflows/deploy.md +176 -0
  140. package/.agent/workflows/enhance.md +63 -0
  141. package/.agent/workflows/orchestrate.md +237 -0
  142. package/.agent/workflows/plan.md +89 -0
  143. package/.agent/workflows/preview.md +81 -0
  144. package/.agent/workflows/simple-test.md +42 -0
  145. package/.agent/workflows/status.md +86 -0
  146. package/.agent/workflows/structured-orchestrate.md +180 -0
  147. package/.agent/workflows/test.md +144 -0
  148. package/.agent/workflows/ui-ux-pro-max.md +296 -0
  149. package/.claude/settings.local.json +23 -1
  150. package/.env.example +56 -56
  151. package/README.md +441 -441
  152. package/cli/src/commands/chat.js +9 -15
  153. package/cli/src/ui/chat-ui.js +41 -71
  154. package/package.json +1 -1
  155. package/plugins/default-plugins.js +5 -5
  156. package/plugins/file-system-plugin.js +1 -1
  157. package/plugins/memory-plugin.js +12 -12
  158. package/plugins/plugin-manager-plugin.js +1 -0
  159. package/plugins/subagent-plugin.js +55 -1
  160. package/plugins/telegram-plugin.js +9 -6
  161. package/plugins/weixin-plugin.js +50 -34
  162. package/skills/find-skills/AGENTS.md +162 -162
  163. package/skills/find-skills/SKILL.md +133 -133
  164. package/src/core/agent-chat.js +460 -1612
  165. package/src/core/agent.js +53 -134
  166. package/src/core/chat-session.js +423 -0
  167. package/src/core/context-compressor.js +473 -0
  168. package/src/core/context-manager.js +0 -48
  169. package/src/core/framework.js +95 -68
  170. package/src/core/index.js +11 -0
  171. package/src/core/notification-manager.js +125 -0
  172. package/src/core/subagent.js +295 -0
  173. package/src/core/token-counter.js +190 -0
  174. package/src/core/tool-executor.js +270 -0
  175. package/src/executors/mcp-executor.js +14 -1
  176. package/system.md +312 -2373
  177. package/.agent/agents/code-assistant.json +0 -17
  178. package/.agent/agents/email-assistant.json +0 -14
  179. package/.agent/agents/file-assistant.json +0 -18
  180. package/.agent/agents/orchestrator-demo.md +0 -53
  181. package/.agent/agents/orchestrator.json +0 -7
  182. package/.agent/agents/system-assistant.json +0 -15
  183. package/.agent/agents/web-assistant.json +0 -12
  184. package/.agent/data/email/processed-emails.json +0 -1
  185. package/.agent/data/scheduler/tasks.json +0 -1
  186. package/.agent/data/web/web-config.json +0 -5
  187. package/.agent/memory/feedback/mnv3nu27-3o15pf.md +0 -9
  188. package/.agent/memory/feedback/mnv3o078-b959yj.md +0 -9
  189. package/.agent/memory/feedback/mnv3o6ej-u0fif5.md +0 -9
  190. package/.agent/memory/feedback/mnv3obgl-bkkjoj.md +0 -9
  191. package/.agent/memory/feedback/mnv4a3js-dv6onx.md +0 -9
  192. package/.agent/memory/feedback/mnv4aacm-sxxowp.md +0 -9
  193. package/.agent/memory/feedback/mnv4ahto-w40ffm.md +0 -9
  194. package/.agent/memory/feedback/mnv4anvp-3cs06y.md +0 -9
  195. package/.agent/memory/feedback/mnvzgvtd-0o2900.md +0 -9
  196. package/.agent/memory/feedback/mnvzhajn-swbx61.md +0 -15
  197. package/.agent/memory/feedback/mnvzhgsp-p5vog3.md +0 -9
  198. package/.agent/memory/feedback/mnvzho0c-fgql7q.md +0 -14
  199. package/.agent/memory/feedback/mnvzhtzq-ufr5at.md +0 -9
  200. package/.agent/memory/feedback/mnvzhyb3-9byq2z.md +0 -9
  201. package/.agent/memory/feedback/mnvzi7hp-hyeafp.md +0 -9
  202. package/.agent/memory/feedback/mnvzibph-z7rwp5.md +0 -9
  203. package/.agent/memory/feedback/mnvzilys-7h176w.md +0 -14
  204. package/.agent/memory/feedback/mnvziuh5-zjshci.md +0 -9
  205. package/.agent/memory/feedback/mnw07wde-6zqsc8.md +0 -9
  206. package/.agent/memory/feedback/mnw084bp-j0ba2a.md +0 -9
  207. package/.agent/memory/user/mnv3n62r-y0h79j.md +0 -21
  208. package/.agent/memory/user/mnv3n9yf-ead4g8.md +0 -13
  209. package/.agent/memory/user/mnv3ne3j-82tq1k.md +0 -19
  210. package/.agent/memory/user/mnv3nhgm-g2s2us.md +0 -11
  211. package/.agent/memory/user/mnv3nl9u-ejd998.md +0 -16
  212. package/.agent/memory/user/mnv3nofp-ya5szl.md +0 -10
  213. package/.agent/memory/user/mnv49qne-bhk0ki.md +0 -9
  214. package/.agent/memory/user/mnv49w3y-rzr8ju.md +0 -13
  215. package/.agent/package.json +0 -8
  216. package/.agent/plugins/__pycache__/file_writer.cpython-312.pyc +0 -0
  217. package/.agent/plugins/daytona/README.md +0 -89
  218. package/.agent/plugins/daytona/index.js +0 -377
  219. package/.agent/plugins/daytona/package.json +0 -12
  220. package/.agent/plugins/marknative/README.md +0 -134
  221. package/.agent/plugins/marknative/fonts/SegoeUI Emoji.ttf +0 -0
  222. package/.agent/plugins/marknative/fonts.zip +0 -0
  223. package/.agent/plugins/marknative/index.js +0 -256
  224. package/.agent/plugins/marknative/package.json +0 -12
  225. package/.agent/plugins/system-info/index.js +0 -387
  226. package/.agent/plugins/system-info/package.json +0 -4
  227. package/.agent/plugins/system-info/test.js +0 -40
  228. package/.agent/plugins/test-plugin.py +0 -123
  229. package/.agent/plugins/test_nested_plugin.py +0 -85
  230. package/.agent/python-scripts/test_sample.py +0 -24
  231. package/.agent/sessions/test.json +0 -16
  232. package/.agent/skills/agent-browser/SKILL.md +0 -311
  233. package/.agent/skills/agent-browser/TEST_PLAN.md +0 -200
  234. package/.agent/skills/sysinfo/SKILL.md +0 -38
  235. package/.agent/skills/sysinfo/system-info.sh +0 -130
  236. package/.agent/skills/workflow/SKILL.md +0 -324
  237. package/.agent/test-agent.js +0 -35
  238. package/.agent/weixin.json +0 -6
  239. package/.agent/workflows/email-digest.json +0 -50
  240. package/.agent/workflows/file-backup.json +0 -21
  241. package/.agent/workflows/get-ip-notify.json +0 -32
  242. package/.agent/workflows/news-aggregator.json +0 -93
  243. package/.agent/workflows/news-dashboard-v2.json +0 -94
  244. package/.agent/workflows/notification-batch.json +0 -32
  245. package/plugins/python-plugin-loader.js.bak +0 -856
  246. package/src/core/agent-context.js +0 -188
@@ -9,6 +9,7 @@ const { EventEmitter } = require('../utils/event-emitter');
9
9
  const { PluginManager } = require('./plugin-manager');
10
10
  const { ToolRegistry } = require('./tool-registry');
11
11
  const { Agent } = require('./agent');
12
+ const { Subagent } = require('./subagent');
12
13
  const { SubAgentConfigManager } = require('./sub-agent-config');
13
14
  const { ContextManager } = require('./context-manager');
14
15
  const { SessionContext } = require('./session-context');
@@ -25,10 +26,9 @@ if (!module.paths.includes(frameworkNodeModules)) {
25
26
  // 现有的 AsyncLocalStorage(保持向后兼容)
26
27
  const asyncLocalStorage = new AsyncLocalStorage();
27
28
 
28
- // 新增:三层 AsyncLocalStorage
29
+ // 新增:两层 AsyncLocalStorage
29
30
  const requestStorage = new AsyncLocalStorage(); // Request 级别
30
31
  const sessionStorage = new AsyncLocalStorage(); // Session 级别
31
- const agentStorage = new AsyncLocalStorage(); // Agent 级别
32
32
 
33
33
  class Framework extends EventEmitter {
34
34
  /**
@@ -498,30 +498,7 @@ class Framework extends EventEmitter {
498
498
  }
499
499
 
500
500
  // ============================================================================
501
- // 分层上下文系统 - Agent Context
502
- // ============================================================================
503
-
504
- /**
505
- * 获取当前 Agent 上下文
506
- * @returns {Object|null}
507
- */
508
- getAgentContext() {
509
- return agentStorage.getStore()?.agentContext || null;
510
- }
511
-
512
- /**
513
- * 在 Agent 上下文中执行函数
514
- * @param {string} agentId - Agent ID
515
- * @param {Object} context - Agent 上下文
516
- * @param {Function} fn - 异步函数
517
- * @returns {Promise}
518
- */
519
- runWithAgentContext(agentId, context, fn) {
520
- return agentStorage.run({ agentId, ...context }, fn);
521
- }
522
-
523
- // ============================================================================
524
- // 组合上下文
501
+ // 分层上下文系统 - 组合上下文
525
502
  // ============================================================================
526
503
 
527
504
  /**
@@ -589,45 +566,40 @@ class Framework extends EventEmitter {
589
566
  }
590
567
 
591
568
  /**
592
- * 创建子Agent(具有独立工具集的轻量级Agent)
569
+ * 创建子Agent(轻量级,单次任务)
593
570
  * @param {Object} config - 子Agent配置
594
571
  * @param {string} config.name - 子Agent名称
595
- * @param {string} config.role - 角色描述(用于智能选择)
596
- * @param {string} [config.description] - 供主Agent理解的描述)
572
+ * @param {string} [config.role] - 角色描述
573
+ * @param {string} [config.description] - 描述
574
+ * @param {string} [config.systemPrompt] - 直接指定的系统提示词(优先使用)
597
575
  * @param {Object} [config.tools] - 自定义工具 { name: toolDef }
598
- * @param {string[]} [config.parentTools] - 从父Agent继承的工具名称列表)
576
+ * @param {string[]} [config.parentTools] - 从父Agent继承的工具名称列表
599
577
  * @param {Object} [config.llmConfig] - 独立LLM配置
600
- * @returns {Agent} 创建的子Agent
578
+ * @returns {Subagent} 创建的子Agent
601
579
  */
602
580
  createSubAgent(config) {
603
581
  const {
604
582
  name,
605
583
  role,
606
584
  description = '',
585
+ systemPrompt: providedPrompt,
607
586
  tools = {},
608
- parentTools, // 如果不传,默认继承主agent所有工具
587
+ parentTools = [], // 如果不传,默认继承主agent所有工具
609
588
  llmConfig = null,
610
589
  } = config;
611
590
 
612
- // 构建子Agent配置
613
- const agentConfig = {
614
- name: `subagent_${name}`,
615
- role: role,
616
- systemPrompt: role, // 使用 role 作为 systemPrompt
617
- skipSyncTools: true, // 子agent跳过工具同步,使用createSubAgent时已配置的工具
618
- ...(llmConfig || {}), // 如果提供了独立LLM配置,合并
619
- };
620
-
621
- // 合并 AI 插件配置
622
- const merged = this._mergeAIConfig(agentConfig);
591
+ // 获取 AI 配置
592
+ const aiPlugin = this.pluginManager.get('ai');
593
+ const aiConfig = aiPlugin ? aiPlugin.getConfig() : {};
594
+ const mergedAIConfig = { ...aiConfig, ...(llmConfig || {}) };
623
595
 
624
- // 创建 Agent
625
- const agent = new Agent(this, merged);
596
+ // 构建工具列表
597
+ const toolList = [];
626
598
 
627
- // 注册自定义工具
599
+ // 添加自定义工具
628
600
  for (const [toolName, toolDef] of Object.entries(tools)) {
629
601
  if (toolDef && typeof toolDef === 'object') {
630
- agent.registerTool({
602
+ toolList.push({
631
603
  name: toolName,
632
604
  description: toolDef.description || '',
633
605
  inputSchema: toolDef.inputSchema,
@@ -635,31 +607,86 @@ class Framework extends EventEmitter {
635
607
  });
636
608
  }
637
609
  }
638
- // 从父Agent继承工具
610
+
611
+ // 创建 Subagent
612
+ // 如果提供了 systemPrompt 则直接使用,否则让 Subagent 动态构建
613
+ const subagent = new Subagent({
614
+ name: `subagent_${name}`,
615
+ role: role || name,
616
+ description: description,
617
+ systemPrompt: providedPrompt,
618
+ model: mergedAIConfig.model || 'deepseek-chat',
619
+ provider: mergedAIConfig.provider || 'deepseek',
620
+ apiKey: mergedAIConfig.apiKey,
621
+ baseURL: mergedAIConfig.baseURL,
622
+ providerOptions: {
623
+ maxOutputTokens: mergedAIConfig.maxOutputTokens || 8192,
624
+ temperature: mergedAIConfig.temperature || 0.3,
625
+ },
626
+ tools: toolList,
627
+ parentTools: parentTools,
628
+ framework: this, // 传递 framework 引用用于动态构建系统提示词
629
+ });
630
+
631
+ this._agents.push(subagent);
632
+ this.emit('agent:created', subagent);
633
+ return subagent;
634
+ }
635
+
636
+ /**
637
+ * 构建子Agent的系统提示词
638
+ * @private
639
+ */
640
+ _buildSubAgentSystemPrompt(role, description, tools) {
641
+ const lines = [];
642
+ const roleName = role || '助手';
643
+ const descText = description || '';
644
+
645
+ // 1. 角色定义
646
+ lines.push(`你是 ${roleName}。`);
647
+ if (descText) {
648
+ lines.push(descText);
649
+ }
650
+ lines.push('');
651
+
652
+ // 2. 主Agent的系统提示词(基础部分)
639
653
  if (this._mainAgent) {
640
- const parentToolsDefs = this._mainAgent.getTools();
641
- if (parentTools === undefined) {
642
- // 如果没有指定 parentTools,默认继承所有工具
643
- for (const toolDef of parentToolsDefs) {
644
- agent.registerTool(toolDef);
645
- }
646
- } else if (Array.isArray(parentTools)) {
647
- // 指定了要继承的工具列表
648
- const filteredTools = parentTools.filter((toolName) =>
649
- parentToolsDefs.some((def) => def.name === toolName)
650
- );
651
- for (const toolName of filteredTools) {
652
- const toolDef = parentToolsDefs.find((t) => t.name === toolName);
653
- if (toolDef) {
654
- agent.registerTool(toolDef);
655
- }
656
- }
654
+ const mainPrompt = this._mainAgent._originalPrompt;
655
+ if (mainPrompt) {
656
+ lines.push('## 主Agent的系统提示词');
657
+ lines.push(mainPrompt);
658
+ lines.push('');
657
659
  }
658
660
  }
659
661
 
660
- this._agents.push(agent);
661
- this.emit('agent:created', agent);
662
- return agent;
662
+ // 3. 工具描述
663
+ if (tools && tools.length > 0) {
664
+ lines.push('## 可用工具');
665
+ lines.push('');
666
+ for (const tool of tools) {
667
+ const desc = tool.description || '无描述';
668
+ lines.push(`- **${tool.name}**: ${desc}`);
669
+ }
670
+ lines.push('');
671
+ }
672
+
673
+ // 4. 子Agent核心规则
674
+ lines.push(`## ${roleName} 核心规则
675
+
676
+ 1. **专注本职任务**:只完成与 ${roleName} 相关的任务,不要处理其他领域的请求。
677
+ 2. **必须先调用工具**:需要信息或操作时,必须调用工具获取真实结果,禁止直接编造。
678
+ 3. **结果导向**:基于工具返回结果回答,不重复工具内部实现细节。
679
+ 4. **多步骤任务**:复杂任务拆解为多个工具调用,逐步完成。
680
+ 5. **响应规范**:直接给出结论,不说"我需要..."等铺垫话术。
681
+
682
+ ## 禁止事项
683
+
684
+ - 不调用工具就直接回答
685
+ - 编造数据、文件、订单等信息
686
+ - 处理本职外的任务
687
+ - 回复含糊不清`);
688
+
689
+ return lines.join('\n');
663
690
  }
664
691
 
665
692
  /**
package/src/core/index.js CHANGED
@@ -8,6 +8,11 @@ const { Plugin } = require('./plugin-base');
8
8
  const { PluginManager } = require('./plugin-manager');
9
9
  const { ToolRegistry } = require('./tool-registry');
10
10
  const { EventEmitter } = require('../utils/event-emitter');
11
+ const { ChatSession } = require('./chat-session');
12
+ const { ToolExecutor } = require('./tool-executor');
13
+ const { ContextCompressor } = require('./context-compressor');
14
+ const { NotificationManager } = require('./notification-manager');
15
+ const { TokenCounter } = require('./token-counter');
11
16
 
12
17
  module.exports = {
13
18
  Framework,
@@ -16,4 +21,10 @@ module.exports = {
16
21
  PluginManager,
17
22
  ToolRegistry,
18
23
  EventEmitter,
24
+ // 新拆分的模块
25
+ ChatSession,
26
+ ToolExecutor,
27
+ ContextCompressor,
28
+ NotificationManager,
29
+ TokenCounter,
19
30
  };
@@ -0,0 +1,125 @@
1
+ /**
2
+ * NotificationManager - 通知管理器
3
+ *
4
+ * 职责:
5
+ * 1. 收集待处理的调度通知
6
+ * 2. 收集待处理的思考通知
7
+ * 3. 格式化通知为可读文本
8
+ */
9
+
10
+ const logger = {
11
+ warn: (context, message, ...args) => console.warn(`[WARN] [${context}] ${message}`, ...args),
12
+ };
13
+
14
+ /**
15
+ * 通知优先级常量
16
+ */
17
+ const NOTIFICATION_CONFIG = {
18
+ MAX_NOTIFICATIONS: 5,
19
+ };
20
+
21
+ /**
22
+ * 格式化调度通知
23
+ * @param {Object} n - 调度通知对象
24
+ * @returns {string} 格式化后的文本
25
+ */
26
+ function formatSchedulerNotification(n) {
27
+ return `【定时任务通知】\n任务: ${n.taskName || n.taskId}\n执行时间: ${n.executedAt}\n结果: ${n.result || n.action || '执行完成'}`;
28
+ }
29
+
30
+ /**
31
+ * 格式化思考通知
32
+ * @param {Object} t - 思考通知对象
33
+ * @returns {string} 格式化后的文本
34
+ */
35
+ function formatThinkNotification(t) {
36
+ return `【主动思考】\n模式: ${t.mode}\n主题: ${t.topic}\n结果: ${t.result || '思考完成'}`;
37
+ }
38
+
39
+ class NotificationManager {
40
+ /**
41
+ * @param {Framework} framework - 框架实例
42
+ */
43
+ constructor(framework) {
44
+ this.framework = framework;
45
+ }
46
+
47
+ /**
48
+ * 获取待处理的调度通知并清除(下次不再重复显示)
49
+ * @returns {Array} 通知数组
50
+ */
51
+ getAndClearSchedulerNotifications() {
52
+ try {
53
+ const scheduler = this.framework.pluginManager.get('scheduler');
54
+ if (scheduler?.instance?.getPendingNotifications) {
55
+ const results = scheduler.instance.getPendingNotifications();
56
+ if (results.length > 0) {
57
+ const notifications = results.slice(-NOTIFICATION_CONFIG.MAX_NOTIFICATIONS).reverse();
58
+ if (scheduler.instance.clearDeliveredNotifications) {
59
+ scheduler.instance.clearDeliveredNotifications(notifications.length);
60
+ }
61
+ return notifications;
62
+ }
63
+ }
64
+ } catch (err) {
65
+ logger.warn('NotificationManager', '获取调度通知失败', err.message);
66
+ }
67
+ return [];
68
+ }
69
+
70
+ /**
71
+ * 获取待处理的思考结果并清除
72
+ * @returns {Array} 思考通知数组
73
+ */
74
+ getAndClearThinkNotifications() {
75
+ try {
76
+ const think = this.framework.pluginManager.get('think');
77
+ if (think?.instance?.getPendingThoughts) {
78
+ const thoughts = think.instance.getPendingThoughts();
79
+ if (thoughts.length > 0) {
80
+ return thoughts.slice(-NOTIFICATION_CONFIG.MAX_NOTIFICATIONS).reverse();
81
+ }
82
+ }
83
+ } catch (err) {
84
+ logger.warn('NotificationManager', '获取思考通知失败', err.message);
85
+ }
86
+ return [];
87
+ }
88
+
89
+ /**
90
+ * 获取所有待处理的系统通知(调度 + 思考)
91
+ * @returns {Array<string>} 格式化后的通知文本数组
92
+ */
93
+ getAllPendingNotifications() {
94
+ const notifications = [];
95
+
96
+ // 调度通知
97
+ const schedulerNotifs = this.getAndClearSchedulerNotifications();
98
+ for (const n of schedulerNotifs) {
99
+ notifications.push(formatSchedulerNotification(n));
100
+ }
101
+
102
+ // 思考通知
103
+ const thinkNotifs = this.getAndClearThinkNotifications();
104
+ for (const t of thinkNotifs) {
105
+ notifications.push(formatThinkNotification(t));
106
+ }
107
+
108
+ return notifications;
109
+ }
110
+
111
+ /**
112
+ * 将通知合并到消息中(用于 chat 输入)
113
+ * @param {string} message - 原始消息
114
+ * @returns {string} 增强后的消息
115
+ */
116
+ enhanceMessage(message) {
117
+ const notifications = this.getAllPendingNotifications();
118
+ if (notifications.length === 0) {
119
+ return message;
120
+ }
121
+ return `【系统通知】\n${notifications.join('\n\n')}\n\n---\n用户消息: ${message}`;
122
+ }
123
+ }
124
+
125
+ module.exports = { NotificationManager };
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Subagent 类
3
+ * 轻量级子 Agent,用于完成单次任务
4
+ * 不需要 session、上下文压缩等复杂功能
5
+ */
6
+
7
+ const { EventEmitter } = require('../utils/event-emitter');
8
+ const { cleanResponse } = require('../utils');
9
+ const { generateText, tool, stepCountIs } = require('ai');
10
+ const { z } = require('zod');
11
+
12
+ class Subagent extends EventEmitter {
13
+ /**
14
+ * @param {Object} config - 配置
15
+ * @param {string} config.name - Subagent 名称
16
+ * @param {string} [config.role] - 角色描述
17
+ * @param {string} [config.description] - 描述
18
+ * @param {string} [config.systemPrompt] - 系统提示词(可选,如果不提供则在 chat 时动态构建)
19
+ * @param {string} [config.model] - 模型名称
20
+ * @param {string} [config.provider] - 提供者
21
+ * @param {string} [config.apiKey] - API 密钥
22
+ * @param {string} [config.baseURL] - base URL
23
+ * @param {Object} [config.providerOptions] - 提供者选项
24
+ * @param {Array|Object} [config.tools] - 工具定义
25
+ * @param {Object} [config.framework] - Framework 引用(用于动态构建系统提示词)
26
+ */
27
+ constructor(config = {}) {
28
+ super();
29
+
30
+ this.name = config.name || 'Subagent';
31
+ this.role = config.role || '助手';
32
+ this.description = config.description || '';
33
+ this.model = config.model || 'deepseek-chat';
34
+ this.provider = config.provider || 'deepseek';
35
+ this.apiKey = config.apiKey;
36
+ this.baseURL = config.baseURL;
37
+ this.providerOptions = config.providerOptions || {};
38
+ this.framework = config.framework || null;
39
+
40
+ this.defaulTools = ['ext_call', 'subagent_call'];
41
+
42
+ this.bindTools = {
43
+ read: 'read_file',
44
+ write: 'write_file',
45
+ edit: 'modify_file',
46
+ glob: 'read_directory',
47
+ grep: 'search_file',
48
+ bash: 'bash',
49
+ };
50
+ // 如果提供了 systemPrompt 则使用,否则标记为需要动态构建
51
+ this._customSystemPrompt = config.systemPrompt || null;
52
+ this.parentTools = config?.parentTools || [];
53
+ // 工具管理
54
+ this._tools = new Map();
55
+ this._registerTools(config.tools || []);
56
+
57
+ this.framework.once('framework:ready', () => {
58
+ const extExecutor = this.framework?.pluginManager?.get('extension-executor');
59
+ extExecutor._refreshAllAgentsExtPrompt(this.framework);
60
+ });
61
+ }
62
+
63
+ /**
64
+ * 注册工具
65
+ * @param {Array|Object} tools - 工具定义
66
+ */
67
+ _registerTools(tools) {
68
+ if (Array.isArray(tools)) {
69
+ for (const t of tools) {
70
+ if (t && t.name) {
71
+ this._tools.set(t.name, t);
72
+ }
73
+ }
74
+ } else if (tools && typeof tools === 'object') {
75
+ for (const [name, t] of Object.entries(tools)) {
76
+ if (t && typeof t.execute === 'function') {
77
+ this._tools.set(name, { name, ...t });
78
+ } else if (t) {
79
+ this._tools.set(name, t);
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * 添加工具
87
+ * @param {Object} toolDef - 工具定义 { name, description, inputSchema, execute }
88
+ */
89
+ addTool(toolDef) {
90
+ if (toolDef && toolDef.name) {
91
+ this._tools.set(toolDef.name, toolDef);
92
+ }
93
+ return this;
94
+ }
95
+
96
+ /**
97
+ * 获取所有工具
98
+ */
99
+ getTools() {
100
+ return Array.from(this._tools.values());
101
+ }
102
+
103
+ /**
104
+ * 获取 AI 提供者
105
+ */
106
+ _getAIProvider() {
107
+ const { createAI } = require('./provider');
108
+ return createAI({
109
+ provider: this.provider,
110
+ model: this.model,
111
+ apiKey: this.apiKey,
112
+ baseURL: this.baseURL,
113
+ });
114
+ }
115
+
116
+ /**
117
+ * 构建 AI 工具格式
118
+ */
119
+ _buildAITools() {
120
+ const tools = {};
121
+ // 从父Agent继承工具
122
+ const all_tools = this.framework.getTools();
123
+ this.parentTools = this.parentTools.map((key) => {
124
+ return this.bindTools[key.toLocaleLowerCase()] || key;
125
+ });
126
+ for (const toolName of this.parentTools) {
127
+ const toolDef = all_tools.find((t) => t.name === toolName);
128
+ if (toolDef) {
129
+ tools[toolDef.name] = toolDef;
130
+ }
131
+ }
132
+ const defaulTools = all_tools.filter((a) => this.defaulTools.includes(a.name));
133
+
134
+ defaulTools.map((tool) => {
135
+ tools[tool.name] = tool;
136
+ });
137
+ return { ...tools, ...this._tools };
138
+ }
139
+
140
+ /**
141
+ * 动态构建系统提示词
142
+ * @private
143
+ */
144
+ _buildSystemPrompt() {
145
+ const lines = [];
146
+ const roleName = this.role || '助手';
147
+ const descText = this.description || '';
148
+
149
+ // 1. 角色定义
150
+ lines.push(`你是 ${roleName}。`);
151
+ if (descText) {
152
+ lines.push(descText);
153
+ }
154
+ lines.push('');
155
+
156
+ // if(this._customSystemPrompt){
157
+ // lines.push(this._customSystemPrompt)
158
+ // }
159
+
160
+ // 2. 主Agent的系统提示词
161
+ if (this.framework && this.framework._mainAgent) {
162
+ const mainPrompt = this.framework._mainAgent._originalPrompt;
163
+ if (mainPrompt) {
164
+ lines.push('## 主Agent的系统提示词');
165
+ lines.push(mainPrompt);
166
+ lines.push('');
167
+ }
168
+ }
169
+
170
+ // 3. 工具描述
171
+ const tools = this._buildAITools();
172
+
173
+ const toolKeys = Object.keys(tools);
174
+ if (toolKeys.length > 0) {
175
+ lines.push('## 可用工具');
176
+ lines.push('');
177
+ for (const key of toolKeys) {
178
+ const toolDef = tools[key];
179
+ const desc = toolDef.description || '无描述';
180
+ lines.push(`- **${toolDef.name}**: ${desc}`);
181
+ }
182
+ lines.push('');
183
+ }
184
+ const subagentManager = this.framework?.pluginManager?.get('subagent-manager');
185
+ lines.push(subagentManager._buildDescription());
186
+ lines.push('');
187
+ // 3.5 扩展插件工具描述
188
+ const extExecutor = this.framework?.pluginManager?.get('extension-executor');
189
+ const extDesc = extExecutor._buildExtensionsDescription();
190
+ if (extDesc) {
191
+ lines.push(extDesc);
192
+ lines.push('');
193
+ }
194
+
195
+ // 4. 子Agent核心规则
196
+ lines.push(`## ${roleName} 核心规则
197
+
198
+ 1. **专注本职任务**:只完成与 ${roleName} 相关的任务,不要处理其他领域的请求。
199
+ 2. **必须先调用工具**:需要信息或操作时,必须调用工具获取真实结果,禁止直接编造。
200
+ 3. **结果导向**:基于工具返回结果回答,不重复工具内部实现细节。
201
+ 4. **多步骤任务**:复杂任务拆解为多个工具调用,逐步完成。
202
+ 5. **响应规范**:直接给出结论,不说"我需要..."等铺垫话术。
203
+
204
+ ## 禁止事项
205
+
206
+ - 不调用工具就直接回答
207
+ - 编造数据、文件、订单等信息
208
+ - 处理本职外的任务
209
+ - 回复含糊不清`);
210
+
211
+ return lines.join('\n');
212
+ }
213
+
214
+ /**
215
+ * 执行任务
216
+ * @param {string} task - 任务描述
217
+ * @param {Object} [options] - 选项
218
+ * @param {number} [options.maxSteps] - 最大步数
219
+ * @param {AbortSignal} [options.signal] - 中止信号
220
+ * @returns {Promise<{success: boolean, message: string, steps: number}>}
221
+ */
222
+ async chat(task, options = {}) {
223
+ const maxSteps = options?.maxSteps || 30;
224
+ const aiProvider = this._getAIProvider();
225
+ const messages = [];
226
+ messages.push({ role: 'user', content: task });
227
+ try {
228
+ const tools = this._buildAITools();
229
+ const systemPrompt = this._buildSystemPrompt();
230
+ const result = await generateText({
231
+ model: aiProvider(this.model),
232
+ system: systemPrompt,
233
+ messages: messages,
234
+ tools: tools,
235
+ stopWhen: stepCountIs(maxSteps),
236
+ ...this.providerOptions,
237
+ abortSignal: options.signal,
238
+ onChunk: (chunk) => {
239
+ this.emit('chunk', chunk);
240
+ },
241
+ });
242
+ messages.push(...result.response.messages);
243
+ const full_text = cleanResponse(result.text);
244
+ this.emit('complete', { message: full_text, steps: result.steps?.length || 0 });
245
+ return {
246
+ success: true,
247
+ message: full_text,
248
+ steps: result.steps?.length || 0,
249
+ };
250
+ } catch (err) {
251
+ this.emit('error', { error: err.message });
252
+ return {
253
+ success: false,
254
+ message: '',
255
+ error: err.message,
256
+ steps: 0,
257
+ };
258
+ }
259
+ }
260
+
261
+ /**
262
+ * 设置角色(会清除自定义 systemPrompt)
263
+ * @param {string} role - 角色描述
264
+ */
265
+ setRole(role) {
266
+ this.role = role;
267
+ this._customSystemPrompt = null;
268
+ }
269
+
270
+ /**
271
+ * 设置描述
272
+ * @param {string} description - 描述
273
+ */
274
+ setDescription(description) {
275
+ this.description = description;
276
+ }
277
+
278
+ /**
279
+ * 设置系统提示词(会覆盖动态构建)
280
+ * @param {string} prompt - 系统提示词
281
+ */
282
+ setSystemPrompt(prompt) {
283
+ this._customSystemPrompt = prompt;
284
+ }
285
+
286
+ /**
287
+ * 销毁
288
+ */
289
+ destroy() {
290
+ this.removeAllListeners();
291
+ this._tools.clear();
292
+ }
293
+ }
294
+
295
+ module.exports = { Subagent };