@ai-zen/agents-sdk 2.0.0-alpha.0 → 2.0.0-alpha.1

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 (131) hide show
  1. package/CHANGELOG.md +73 -16
  2. package/README.md +397 -113
  3. package/README.zh.md +314 -112
  4. package/dist/agent-plugins/AssetTransportPlugin.d.ts +51 -0
  5. package/dist/agent-plugins/AssetTransportPlugin.js +145 -0
  6. package/dist/agent-plugins/AutoMigratePlugin.d.ts +35 -14
  7. package/dist/agent-plugins/AutoMigratePlugin.js +36 -36
  8. package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +6 -6
  9. package/dist/agent-plugins/AutoRefreshToolsPlugin.js +2 -2
  10. package/dist/agent-plugins/ContextGuardPlugin.d.ts +20 -24
  11. package/dist/agent-plugins/ContextGuardPlugin.js +25 -24
  12. package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +25 -35
  13. package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +26 -41
  14. package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +14 -9
  15. package/dist/agent-plugins/UnknownToolHintPlugin.js +15 -13
  16. package/dist/config/ConfigManager.d.ts +13 -5
  17. package/dist/config/ConfigManager.js +58 -39
  18. package/dist/config/constants.d.ts +1 -1
  19. package/dist/config/constants.js +2 -2
  20. package/dist/config/factory-skills.js +2 -2
  21. package/dist/config/normalize.d.ts +93 -0
  22. package/dist/config/normalize.js +158 -0
  23. package/dist/crud/AgentRepository.d.ts +3 -1
  24. package/dist/crud/AgentRepository.js +4 -2
  25. package/dist/index.d.ts +19 -9
  26. package/dist/index.js +14 -7
  27. package/dist/runtime/AgentRuntime.d.ts +293 -0
  28. package/dist/runtime/AgentRuntime.js +457 -0
  29. package/dist/runtime/HandoffGuardPlugin.d.ts +82 -15
  30. package/dist/runtime/HandoffGuardPlugin.js +136 -17
  31. package/dist/runtime/HandoffService.d.ts +244 -119
  32. package/dist/runtime/HandoffService.js +373 -251
  33. package/dist/runtime/RuntimePeerSessions.d.ts +34 -0
  34. package/dist/runtime/RuntimePeerSessions.js +50 -0
  35. package/dist/runtime/Scopes.d.ts +123 -0
  36. package/dist/runtime/Scopes.js +169 -0
  37. package/dist/runtime/SdkAgent.d.ts +19 -8
  38. package/dist/runtime/SdkAgent.js +23 -6
  39. package/dist/runtime/completeOnce.d.ts +3 -3
  40. package/dist/runtime/completeOnce.js +3 -3
  41. package/dist/runtime/createAgent.d.ts +29 -7
  42. package/dist/runtime/createAgent.js +57 -12
  43. package/dist/runtime/createModel.d.ts +4 -4
  44. package/dist/runtime/createModel.js +6 -6
  45. package/dist/runtime/lastPromptTokens.d.ts +18 -0
  46. package/dist/runtime/lastPromptTokens.js +26 -0
  47. package/dist/runtime/resolveModel.d.ts +9 -9
  48. package/dist/runtime/resolveModel.js +8 -8
  49. package/dist/scope/Scope.d.ts +10 -9
  50. package/dist/scope/Scope.js +6 -6
  51. package/dist/scope/ScopePlugin.d.ts +2 -8
  52. package/dist/scope/disclosure.d.ts +1 -1
  53. package/dist/scope/disclosure.js +1 -1
  54. package/dist/scope/plugins/allInOne.d.ts +13 -1
  55. package/dist/scope/plugins/allInOne.js +9 -5
  56. package/dist/scope/plugins/builtin/AsyncExecTool.d.ts +12 -0
  57. package/dist/scope/plugins/builtin/AsyncExecTool.js +103 -0
  58. package/dist/scope/plugins/builtin/AsyncTimeoutTool.d.ts +10 -0
  59. package/dist/scope/plugins/builtin/AsyncTimeoutTool.js +90 -0
  60. package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +1 -1
  61. package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +1 -1
  62. package/dist/scope/plugins/builtin/DownloadFileTool.js +1 -1
  63. package/dist/scope/plugins/builtin/ExecTool.js +10 -199
  64. package/dist/scope/plugins/builtin/FindTextTool.d.ts +1 -1
  65. package/dist/scope/plugins/builtin/FindTextTool.js +1 -1
  66. package/dist/scope/plugins/builtin/GenerateImageTool.d.ts +1 -4
  67. package/dist/scope/plugins/builtin/GenerateImageTool.js +2 -8
  68. package/dist/scope/plugins/builtin/InspectFileTool.js +1 -1
  69. package/dist/scope/plugins/builtin/SdkCallbackTool.d.ts +4 -4
  70. package/dist/scope/plugins/builtin/SdkCallbackTool.js +3 -3
  71. package/dist/scope/plugins/builtin/SleepTool.js +2 -3
  72. package/dist/scope/plugins/builtin/ViewImageTool.d.ts +2 -4
  73. package/dist/scope/plugins/builtin/ViewImageTool.js +4 -6
  74. package/dist/scope/plugins/builtin/WriteTool.d.ts +7 -0
  75. package/dist/scope/plugins/builtin/WriteTool.js +8 -1
  76. package/dist/scope/plugins/builtin/asyncTasks.d.ts +41 -0
  77. package/dist/scope/plugins/builtin/asyncTasks.js +97 -0
  78. package/dist/scope/plugins/builtin/commandOutput.d.ts +22 -0
  79. package/dist/scope/plugins/builtin/commandOutput.js +55 -0
  80. package/dist/scope/plugins/builtin/commandRun.d.ts +48 -0
  81. package/dist/scope/plugins/builtin/commandRun.js +169 -0
  82. package/dist/scope/plugins/builtin/discover.d.ts +1 -3
  83. package/dist/scope/plugins/builtin/discover.js +1 -3
  84. package/dist/scope/plugins/builtin/index.d.ts +5 -7
  85. package/dist/scope/plugins/builtin/index.js +7 -7
  86. package/dist/scope/plugins/builtin/outputGuard.d.ts +1 -5
  87. package/dist/scope/plugins/builtin/outputGuard.js +1 -5
  88. package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +56 -11
  89. package/dist/scope/plugins/mcp/McpConnectionManager.js +169 -74
  90. package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +17 -7
  91. package/dist/scope/plugins/mcp/McpScopePlugin.js +36 -12
  92. package/dist/scope/plugins/mcp/discover.d.ts +9 -2
  93. package/dist/scope/plugins/mcp/discover.js +12 -14
  94. package/dist/scope/plugins/mcp/mcpTaskNotice.d.ts +52 -0
  95. package/dist/scope/plugins/mcp/mcpTaskNotice.js +8 -0
  96. package/dist/scope/plugins/mcp/mcpTools.d.ts +20 -2
  97. package/dist/scope/plugins/mcp/mcpTools.js +220 -39
  98. package/dist/scope/plugins/peers/PeerSessionsScopePlugin.d.ts +4 -7
  99. package/dist/scope/plugins/peers/PeerSessionsScopePlugin.js +4 -7
  100. package/dist/scope/plugins/peers/peerSessionTools.d.ts +97 -46
  101. package/dist/scope/plugins/peers/peerSessionTools.js +147 -121
  102. package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +4 -0
  103. package/dist/scope/plugins/skills/SkillsScopePlugin.js +10 -4
  104. package/dist/scope/plugins/skills/discover.d.ts +15 -8
  105. package/dist/scope/plugins/skills/discover.js +15 -26
  106. package/dist/scope/plugins/skills/skillTools.d.ts +8 -7
  107. package/dist/scope/plugins/skills/skillTools.js +18 -14
  108. package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +4 -0
  109. package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +4 -1
  110. package/dist/scope/plugins/subagents/discover.d.ts +7 -1
  111. package/dist/scope/plugins/subagents/discover.js +7 -3
  112. package/dist/scope/plugins/subagents/subAgentTools.d.ts +0 -1
  113. package/dist/scope/plugins/subagents/subAgentTools.js +11 -1
  114. package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +4 -0
  115. package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +4 -1
  116. package/dist/scope/plugins/usertools/discover.d.ts +7 -8
  117. package/dist/scope/plugins/usertools/discover.js +17 -27
  118. package/dist/shared/EntityRepository.d.ts +22 -5
  119. package/dist/shared/EntityRepository.js +45 -29
  120. package/dist/shared/content-blocks.d.ts +9 -3
  121. package/dist/shared/content-blocks.js +12 -19
  122. package/dist/shared/errors.d.ts +5 -7
  123. package/dist/shared/errors.js +6 -8
  124. package/dist/shared/logger.d.ts +21 -10
  125. package/dist/shared/logger.js +9 -15
  126. package/dist/types/index.d.ts +36 -13
  127. package/package.json +2 -2
  128. package/dist/config/migrate.d.ts +0 -115
  129. package/dist/config/migrate.js +0 -200
  130. package/dist/scope/plugins/builtin/test-helpers.d.ts +0 -3
  131. package/dist/scope/plugins/builtin/test-helpers.js +0 -4
@@ -1,66 +1,56 @@
1
1
  /**
2
- * 子 Agent 护栏安装器 — SubAgentGuardInstallerPlugin
2
+ * subagent 护栏安装器 — SubAgentGuardInstallerPlugin
3
3
  *
4
- * 为什么在 SDK 而不在 CLI:子 Agent 内循环缺护栏是**所有宿主**共有的问题,不是 CLI 特性。
4
+ * 为什么在 SDK 而不在 CLI:subagent 内循环缺护栏是**所有宿主**共有的问题,不是 CLI 特性。
5
5
  * 会话执行搬到服务端之后,服务端装配插件的那一处(`installPlugins`)装不到 CLI 仓里的实现,
6
- * 远程会话的子 Agent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
6
+ * 远程会话的 subagent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
7
7
  * 共享同一套阈值语义。
8
8
  *
9
- * 背景:SDK 的子 Agent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
9
+ * 背景:SDK 的 subagent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
10
10
  * 构建(core 的 `buildAgent` 回调),新建实例不携带任何插件(`Agent` 的插件表每实例私有,
11
- * 不向子 Agent 传播),且子 Agent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
- * `ContextGuardPlugin` 对它完全无效:子 Agent 的内循环没有上下文 token 护栏。
11
+ * 不向 subagent 传播),且 subagent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
+ * `ContextGuardPlugin` 对它完全无效:subagent 的内循环没有上下文 token 护栏。
13
13
  *
14
- * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
- * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
14
+ * 介入点:core 的 `onSubAgentStart` 钩子在「subagent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
+ * 分发,载荷携带 subagent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
16
16
  * 该列表,故在钩子内安插对**本次 runOnce 立即生效**(无需 init;`AgentToolLazy` 也不会调用
17
- * 子 Agent 的 init)。
17
+ * subagent 的 init)。
18
18
  *
19
- * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到子 Agent 上
20
- * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`),使「请求前用量超过硬线即中断」
21
- * 对子 Agent 同样成立;同一个 `isSuspended`(会话层的交接/迁移让行判断),使「交接回合让行」
22
- * 对子 Agent 同样成立。
23
- *
24
- * 为什么让行判断也必须透传:交接回合本身就是上下文最满的时刻 —— 主 Agent 那颗护栏靠
25
- * `isSuspended` 让行才不至于「交接触发拦截 → 拦截又触发交接」地打转。子 Agent 若只带阈值、
26
- * 不带让行,就会在交接中派出去的子任务上照拦,护栏比主 Agent 还严一档;递归安插时更是层层
27
- * 都要带上,否则孙级又会把让行丢掉(同一个缺口往下挪一层而已)。
28
- * **不设**轮次上限,**不设**工具调用次数上限。
19
+ * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到 subagent 上
20
+ * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`;会话行上有覆盖时取会话行那一格),
21
+ * 使「请求前用量超过硬线即中断」对 subagent 同样成立。
22
+ * **不设**循环次数上限,**不设**工具调用次数上限。
29
23
  *
30
24
  * 中断语义(core 重写之后变了,这是必须知道的一条):护栏在 `onInnerLoopStart` 里**返回
31
- * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是子 Agent 的那一圈**压根没发出去** ——
32
- * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是子 Agent
25
+ * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是 subagent 的那一次请求**压根没发出去** ——
26
+ * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是 subagent
33
27
  * 已装好的历史(委派工具交回 `messages` 的最后一条),**不是**一段「执行工具时出错」的异常
34
28
  * 文本 —— 新 core 里钩子抛错会穿到 `start()` 外面把循环打死,反而连收尾都做不干净。
35
29
  *
36
30
  * 覆盖范围:core 的委派路径是 `AgentToolLazy`,它分发 onSubAgentStart / onSubAgentEnd,
37
- * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)与
31
+ * 故本插件对**全部**subagent 生效。SDK 的 `call_skill_sub_agent`(技能 subagent)与
38
32
  * `createSubAgentTool` 造出来的那些(名称取自定义的 `function.name`)同样由
39
33
  * `AgentToolLazy` 承载、走同一委派边界,因此也在覆盖范围内。
40
34
  */
41
35
  import type { AgentPlugin, SubAgentHookContext } from "@ai-zen/agents-core";
42
36
  export interface SubAgentGuardOptions {
43
- /** 强行阻断阈值;与主 Agent 同源(当前模型的 `tokenThresholds.guard`) */
44
- guardTokens: number;
45
37
  /**
46
- * 让行判断(与主 Agent 的 `ContextGuardPlugin` 同一个来源)。
47
- * 交接回合本身就是上下文最满的时刻,硬线必须让行 —— 否则「交接触发拦截 → 拦截
48
- * 又触发交接」形成死循环。子 Agent 也必须遵守同一判断,否则交接中派出去的子任务
49
- * 会被自己的硬线打断。
38
+ * 强行阻断阈值;与主 Agent 同源(当前模型的 `tokenThresholds.guard`,会话行上有覆盖时取那一格)。
39
+ *
40
+ * 可以是一个 getter:那样每次委派都现读,改阈值不必重建执行体。
50
41
  */
51
- isSuspended?: () => boolean;
42
+ guardTokens: number;
52
43
  }
53
44
  /**
54
- * 子 Agent 护栏安装器(装在**宿主 Agent** 上)。
45
+ * subagent 护栏安装器(装在**宿主 Agent** 上)。
55
46
  *
56
- * 每次委派边界把 `ContextGuardPlugin` 装到子 Agent 身上(阈值与让行判断都与主 Agent 相同),
57
- * 并递归安插自身,使子 Agent 再委派(孙级)时同样受约束。始终返回 undefined,永不拒绝委派
47
+ * 每次委派边界把 `ContextGuardPlugin` 装到 subagent 身上(阈值与主 Agent 相同),
48
+ * 并递归安插自身,使 subagent 再委派(孙级)时同样受约束。始终返回 undefined,永不拒绝委派
58
49
  * ——是否中断由 `ContextGuardPlugin` 按阈值决定。
59
50
  */
60
51
  export declare class SubAgentGuardInstallerPlugin implements AgentPlugin {
61
- private readonly guardTokens;
62
- /** 让行判断按**引用**存下:它读的是「此刻是否在交接」,不是装配那一刻的快照 */
63
- private readonly isSuspended?;
52
+ private readonly options;
53
+ /** 选项按**引用**存下:阈值每次委派现读(它可能是一个 getter),不存装配那一刻的快照 */
64
54
  constructor(options: SubAgentGuardOptions);
65
55
  onSubAgentStart({ subAgent }: SubAgentHookContext): void;
66
56
  }
@@ -1,70 +1,55 @@
1
1
  /**
2
- * 子 Agent 护栏安装器 — SubAgentGuardInstallerPlugin
2
+ * subagent 护栏安装器 — SubAgentGuardInstallerPlugin
3
3
  *
4
- * 为什么在 SDK 而不在 CLI:子 Agent 内循环缺护栏是**所有宿主**共有的问题,不是 CLI 特性。
4
+ * 为什么在 SDK 而不在 CLI:subagent 内循环缺护栏是**所有宿主**共有的问题,不是 CLI 特性。
5
5
  * 会话执行搬到服务端之后,服务端装配插件的那一处(`installPlugins`)装不到 CLI 仓里的实现,
6
- * 远程会话的子 Agent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
6
+ * 远程会话的 subagent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
7
7
  * 共享同一套阈值语义。
8
8
  *
9
- * 背景:SDK 的子 Agent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
9
+ * 背景:SDK 的 subagent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
10
10
  * 构建(core 的 `buildAgent` 回调),新建实例不携带任何插件(`Agent` 的插件表每实例私有,
11
- * 不向子 Agent 传播),且子 Agent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
- * `ContextGuardPlugin` 对它完全无效:子 Agent 的内循环没有上下文 token 护栏。
11
+ * 不向 subagent 传播),且 subagent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
+ * `ContextGuardPlugin` 对它完全无效:subagent 的内循环没有上下文 token 护栏。
13
13
  *
14
- * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
- * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
14
+ * 介入点:core 的 `onSubAgentStart` 钩子在「subagent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
+ * 分发,载荷携带 subagent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
16
16
  * 该列表,故在钩子内安插对**本次 runOnce 立即生效**(无需 init;`AgentToolLazy` 也不会调用
17
- * 子 Agent 的 init)。
17
+ * subagent 的 init)。
18
18
  *
19
- * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到子 Agent 上
20
- * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`),使「请求前用量超过硬线即中断」
21
- * 对子 Agent 同样成立;同一个 `isSuspended`(会话层的交接/迁移让行判断),使「交接回合让行」
22
- * 对子 Agent 同样成立。
23
- *
24
- * 为什么让行判断也必须透传:交接回合本身就是上下文最满的时刻 —— 主 Agent 那颗护栏靠
25
- * `isSuspended` 让行才不至于「交接触发拦截 → 拦截又触发交接」地打转。子 Agent 若只带阈值、
26
- * 不带让行,就会在交接中派出去的子任务上照拦,护栏比主 Agent 还严一档;递归安插时更是层层
27
- * 都要带上,否则孙级又会把让行丢掉(同一个缺口往下挪一层而已)。
28
- * **不设**轮次上限,**不设**工具调用次数上限。
19
+ * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到 subagent 上
20
+ * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`;会话行上有覆盖时取会话行那一格),
21
+ * 使「请求前用量超过硬线即中断」对 subagent 同样成立。
22
+ * **不设**循环次数上限,**不设**工具调用次数上限。
29
23
  *
30
24
  * 中断语义(core 重写之后变了,这是必须知道的一条):护栏在 `onInnerLoopStart` 里**返回
31
- * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是子 Agent 的那一圈**压根没发出去** ——
32
- * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是子 Agent
25
+ * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是 subagent 的那一次请求**压根没发出去** ——
26
+ * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是 subagent
33
27
  * 已装好的历史(委派工具交回 `messages` 的最后一条),**不是**一段「执行工具时出错」的异常
34
28
  * 文本 —— 新 core 里钩子抛错会穿到 `start()` 外面把循环打死,反而连收尾都做不干净。
35
29
  *
36
30
  * 覆盖范围:core 的委派路径是 `AgentToolLazy`,它分发 onSubAgentStart / onSubAgentEnd,
37
- * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)与
31
+ * 故本插件对**全部**subagent 生效。SDK 的 `call_skill_sub_agent`(技能 subagent)与
38
32
  * `createSubAgentTool` 造出来的那些(名称取自定义的 `function.name`)同样由
39
33
  * `AgentToolLazy` 承载、走同一委派边界,因此也在覆盖范围内。
40
34
  */
41
35
  import { ContextGuardPlugin } from "./ContextGuardPlugin.js";
42
36
  /**
43
- * 子 Agent 护栏安装器(装在**宿主 Agent** 上)。
37
+ * subagent 护栏安装器(装在**宿主 Agent** 上)。
44
38
  *
45
- * 每次委派边界把 `ContextGuardPlugin` 装到子 Agent 身上(阈值与让行判断都与主 Agent 相同),
46
- * 并递归安插自身,使子 Agent 再委派(孙级)时同样受约束。始终返回 undefined,永不拒绝委派
39
+ * 每次委派边界把 `ContextGuardPlugin` 装到 subagent 身上(阈值与主 Agent 相同),
40
+ * 并递归安插自身,使 subagent 再委派(孙级)时同样受约束。始终返回 undefined,永不拒绝委派
47
41
  * ——是否中断由 `ContextGuardPlugin` 按阈值决定。
48
42
  */
49
43
  export class SubAgentGuardInstallerPlugin {
50
- guardTokens;
51
- /** 让行判断按**引用**存下:它读的是「此刻是否在交接」,不是装配那一刻的快照 */
52
- isSuspended;
44
+ options;
45
+ /** 选项按**引用**存下:阈值每次委派现读(它可能是一个 getter),不存装配那一刻的快照 */
53
46
  constructor(options) {
54
- this.guardTokens = options.guardTokens;
55
- this.isSuspended = options.isSuspended;
47
+ this.options = options;
56
48
  }
57
49
  onSubAgentStart({ subAgent }) {
58
- // 与主 Agent 完全同款:同一个 guardTokens 绝对阈值 + 同一个让行判断
59
- subAgent.use(new ContextGuardPlugin({
60
- guardTokens: this.guardTokens,
61
- isSuspended: this.isSuspended,
62
- }));
63
- // 传染到孙级:子 Agent 若再委派,其子 Agent 同样被安插。
64
- // 让行判断也必须跟着递归走,否则只差一层就把「交接中让行」丢了。
65
- subAgent.use(new SubAgentGuardInstallerPlugin({
66
- guardTokens: this.guardTokens,
67
- isSuspended: this.isSuspended,
68
- }));
50
+ // 与主 Agent 完全同款:同一个 guardTokens 绝对阈值
51
+ subAgent.use(new ContextGuardPlugin({ guardTokens: this.options.guardTokens }));
52
+ // 传染到孙级:subagent 若再委派,其 subagent 同样被安插。
53
+ subAgent.use(new SubAgentGuardInstallerPlugin({ guardTokens: this.options.guardTokens }));
69
54
  }
70
55
  }
@@ -1,4 +1,4 @@
1
- import type { AgentPlugin, ToolHookContext } from "@ai-zen/agents-core";
1
+ import type { AgentPlugin, UnknownToolContext } from "@ai-zen/agents-core";
2
2
  import type { Scope } from "../scope/Scope.js";
3
3
  /**
4
4
  * 未知工具智能提示插件 — MCP 场景引导。
@@ -9,23 +9,28 @@ import type { Scope } from "../scope/Scope.js";
9
9
  * - 否则 → 仅提示工具不存在
10
10
  *
11
11
  * 由调用方显式注册(`agent.use(new UnknownToolHintPlugin({ scope }))`)。
12
- * 未注册时,core 自己回落到简单文本提示(`未知工具: X,没有找到对应的工具实现。`)。
12
+ * 未注册时(或返回 `undefined` 时),core 自己回落到简单文本提示
13
+ * (`未知工具: X,没有找到对应的工具实现。`)。
13
14
  *
14
15
  * 是否"有 MCP 配置"经 `scope.getPluginById(McpScopePlugin.ID)` 查询 MCP 插件获得。
15
16
  *
16
- * ## 钩子:`onToolStart`(`onUnknownTool` 已删除)
17
+ * ## 钩子:`onUnknownTool`
17
18
  *
18
- * core 重写后没有单独的「未知工具」钩子了 —— 未知工具也走 `onToolStart`,只是
19
- * `ctx.toolCall.tool === undefined`(没匹配到已注册的实现)。于是本插件就守在这条缝上:
20
- * 判到「工具不存在」才返回提示字符串,其余一律放行(返回 undefined)。
19
+ * 「未知工具」与「工具开始」是**两个问题**,core 分别用两个钩子问,一次工具调用只走其中一个:
20
+ * - `onToolStart`:工具**存在**,问「要不要开始跑」;
21
+ * - `onUnknownTool`:工具**不存在**,问「模型调了个不存在的工具,要怎么回应它」。
21
22
  *
22
- * 返回的字符串**就是那条 tool 消息的正文**(core 会把它作为拒绝原因回给模型),
23
- * 因此模型读到的是引导、而不是默认的「没有找到对应的工具实现」。
23
+ * 本插件守的是后一条缝 —— 于是不必再自己判「工具在不在」:来到这里就是不存在。
24
+ * 被调用的工具名与当时全部可用的工具都在入参里(`toolCall.function?.name` /
25
+ * `availableTools`),不必去别处捞。
26
+ *
27
+ * 返回的字符串**就是那条 tool 消息的正文**:模型读到的是引导,而不是默认的
28
+ * 「没有找到对应的工具实现」;返回 `undefined` 则交回 core 走默认文案。
24
29
  */
25
30
  export declare class UnknownToolHintPlugin implements AgentPlugin {
26
31
  private readonly scope;
27
32
  constructor(options: {
28
33
  scope: Scope;
29
34
  });
30
- onToolStart(ctx: ToolHookContext): string | undefined;
35
+ onUnknownTool(ctx: UnknownToolContext): string | undefined;
31
36
  }
@@ -8,32 +8,34 @@ import { McpScopePlugin } from "../scope/plugins/mcp/McpScopePlugin.js";
8
8
  * - 否则 → 仅提示工具不存在
9
9
  *
10
10
  * 由调用方显式注册(`agent.use(new UnknownToolHintPlugin({ scope }))`)。
11
- * 未注册时,core 自己回落到简单文本提示(`未知工具: X,没有找到对应的工具实现。`)。
11
+ * 未注册时(或返回 `undefined` 时),core 自己回落到简单文本提示
12
+ * (`未知工具: X,没有找到对应的工具实现。`)。
12
13
  *
13
14
  * 是否"有 MCP 配置"经 `scope.getPluginById(McpScopePlugin.ID)` 查询 MCP 插件获得。
14
15
  *
15
- * ## 钩子:`onToolStart`(`onUnknownTool` 已删除)
16
+ * ## 钩子:`onUnknownTool`
16
17
  *
17
- * core 重写后没有单独的「未知工具」钩子了 —— 未知工具也走 `onToolStart`,只是
18
- * `ctx.toolCall.tool === undefined`(没匹配到已注册的实现)。于是本插件就守在这条缝上:
19
- * 判到「工具不存在」才返回提示字符串,其余一律放行(返回 undefined)。
18
+ * 「未知工具」与「工具开始」是**两个问题**,core 分别用两个钩子问,一次工具调用只走其中一个:
19
+ * - `onToolStart`:工具**存在**,问「要不要开始跑」;
20
+ * - `onUnknownTool`:工具**不存在**,问「模型调了个不存在的工具,要怎么回应它」。
20
21
  *
21
- * 返回的字符串**就是那条 tool 消息的正文**(core 会把它作为拒绝原因回给模型),
22
- * 因此模型读到的是引导、而不是默认的「没有找到对应的工具实现」。
22
+ * 本插件守的是后一条缝 —— 于是不必再自己判「工具在不在」:来到这里就是不存在。
23
+ * 被调用的工具名与当时全部可用的工具都在入参里(`toolCall.function?.name` /
24
+ * `availableTools`),不必去别处捞。
25
+ *
26
+ * 返回的字符串**就是那条 tool 消息的正文**:模型读到的是引导,而不是默认的
27
+ * 「没有找到对应的工具实现」;返回 `undefined` 则交回 core 走默认文案。
23
28
  */
24
29
  export class UnknownToolHintPlugin {
25
30
  scope;
26
31
  constructor(options) {
27
32
  this.scope = options.scope;
28
33
  }
29
- onToolStart(ctx) {
30
- // 只关心「工具不存在」:匹配到实现的一律放行,别抢别的工具的活
31
- if (ctx.toolCall.tool !== undefined)
32
- return;
33
- const toolName = ctx.toolCall.tool_call.function?.name ?? "unknown";
34
+ onUnknownTool(ctx) {
35
+ const toolName = ctx.toolCall.function?.name ?? "unknown";
34
36
  const mcpPlugin = this.scope.getPluginById(McpScopePlugin.ID);
35
37
  const hasMcpConfig = mcpPlugin?.hasConfig() ?? false;
36
- const hasCallMcpTool = ctx.agent.tools.some((t) => t.function.name === "call_mcp_tool");
38
+ const hasCallMcpTool = ctx.availableTools.some((t) => t.function.name === "call_mcp_tool");
37
39
  if (hasMcpConfig && !hasCallMcpTool) {
38
40
  return `Tool "${toolName}" does not exist. An MCP server is configured, but the call_mcp_tool permission is disabled — adjust permissions if you need to use MCP tools.`;
39
41
  }
@@ -1,4 +1,5 @@
1
1
  import type { AppConfig, AgentDefinition, ReasoningPresets } from "../types/index.js";
2
+ import { type LogSink } from "../shared/logger.js";
2
3
  /**
3
4
  * 配置坏了、已经按出厂恢复之后的回调(参数是坏掉的那个文件路径)。
4
5
  *
@@ -16,18 +17,25 @@ export declare class ConfigManager {
16
17
  private knownModelIds;
17
18
  /** 配置坏了被恢复出厂之后要通知的那一下(不注入就只是恢复,不告诉任何人) */
18
19
  private readonly onRecovered?;
19
- constructor(configPath: string, onRecovered?: ConfigRecoveredHandler);
20
+ /** 日志口(不注入就不记):策略表 / 出厂 Skill 读不出来时的那几句话走它 */
21
+ private readonly logger;
22
+ /**
23
+ * @param configPath `config.json` 的路径(`basePath` 取它的同级目录)
24
+ * @param onRecovered 配置被恢复出厂之后的回调(可选)
25
+ * @param logger 日志口(可选):读不出来但已降级的那几处从这里报一句;缺省不记
26
+ */
27
+ constructor(configPath: string, onRecovered?: ConfigRecoveredHandler, logger?: LogSink);
20
28
  /**
21
29
  * 读取配置。文件不存在时返回出厂默认配置;文件坏了(解析不了 / 不是对象)时
22
30
  * 恢复出厂并写回磁盘,也返回出厂默认配置(见 `readRaw`)。
23
31
  *
24
- * 读到即**迁移**(`config/migrate.ts`):上层拿到的永远是当前字段形状,
25
- * 旧字段(`maxContextTokens` / `maxContextChars`)不会漏到调用方。
26
- * 迁移结果不在这里落盘——落盘只在 `ensureDefaultConfig()` 做一次。
32
+ * 读到即**补位**(`config/normalize.ts`):缺字段或非法值补成出厂值,上层拿到的永远是
33
+ * 合法形状(阈值两条齐、中断策略合法、端点能力位不缺)。
34
+ * 补位结果不在这里落盘——落盘只在 `ensureDefaultConfig()` 做一次。
27
35
  */
28
36
  read(): Promise<AppConfig>;
29
37
  /**
30
- * 读磁盘原文(不做任何迁移/同步),供 `ensureDefaultConfig()` 对比写盘用。
38
+ * 读磁盘原文(不做任何补位/同步),供 `ensureDefaultConfig()` 对比写盘用。
31
39
  *
32
40
  * 文件在但读不成配置(JSON 解析不了、或者解析出来不是对象)就是一档「坏」:先把坏文件
33
41
  * 改名留档,再用出厂配置写回磁盘,再回调一次,返回出厂配置。写回是为了让下次启动不再
@@ -1,9 +1,10 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
+ import { SILENT_LOG } from "../shared/logger.js";
3
4
  import { DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./constants.js";
4
5
  import { FACTORY_SKILLS, isCustomSkill } from "./factory-skills.js";
5
6
  import { FACTORY_REASONING_PRESETS, REASONING_PRESETS_FILE } from "./reasoning-presets.js";
6
- import { migrateConfig } from "./migrate.js";
7
+ import { normalizeConfig } from "./normalize.js";
7
8
  /**
8
9
  * 配置管理器 — 负责配置文件的读写、目录初始化、默认实体创建。
9
10
  */
@@ -14,10 +15,18 @@ export class ConfigManager {
14
15
  knownModelIds = new Set();
15
16
  /** 配置坏了被恢复出厂之后要通知的那一下(不注入就只是恢复,不告诉任何人) */
16
17
  onRecovered;
17
- constructor(configPath, onRecovered) {
18
+ /** 日志口(不注入就不记):策略表 / 出厂 Skill 读不出来时的那几句话走它 */
19
+ logger;
20
+ /**
21
+ * @param configPath `config.json` 的路径(`basePath` 取它的同级目录)
22
+ * @param onRecovered 配置被恢复出厂之后的回调(可选)
23
+ * @param logger 日志口(可选):读不出来但已降级的那几处从这里报一句;缺省不记
24
+ */
25
+ constructor(configPath, onRecovered, logger = SILENT_LOG) {
18
26
  this.configPath = configPath;
19
27
  this.basePath = dirname(configPath);
20
28
  this.onRecovered = onRecovered;
29
+ this.logger = logger;
21
30
  }
22
31
  // -----------------------------------------------------------------------
23
32
  // config.json
@@ -26,16 +35,16 @@ export class ConfigManager {
26
35
  * 读取配置。文件不存在时返回出厂默认配置;文件坏了(解析不了 / 不是对象)时
27
36
  * 恢复出厂并写回磁盘,也返回出厂默认配置(见 `readRaw`)。
28
37
  *
29
- * 读到即**迁移**(`config/migrate.ts`):上层拿到的永远是当前字段形状,
30
- * 旧字段(`maxContextTokens` / `maxContextChars`)不会漏到调用方。
31
- * 迁移结果不在这里落盘——落盘只在 `ensureDefaultConfig()` 做一次。
38
+ * 读到即**补位**(`config/normalize.ts`):缺字段或非法值补成出厂值,上层拿到的永远是
39
+ * 合法形状(阈值两条齐、中断策略合法、端点能力位不缺)。
40
+ * 补位结果不在这里落盘——落盘只在 `ensureDefaultConfig()` 做一次。
32
41
  */
33
42
  async read() {
34
43
  const raw = await this.readRaw();
35
- return raw ? migrateConfig(raw).config : { ...DEFAULT_APP_CONFIG };
44
+ return raw ? normalizeConfig(raw).config : { ...DEFAULT_APP_CONFIG };
36
45
  }
37
46
  /**
38
- * 读磁盘原文(不做任何迁移/同步),供 `ensureDefaultConfig()` 对比写盘用。
47
+ * 读磁盘原文(不做任何补位/同步),供 `ensureDefaultConfig()` 对比写盘用。
39
48
  *
40
49
  * 文件在但读不成配置(JSON 解析不了、或者解析出来不是对象)就是一档「坏」:先把坏文件
41
50
  * 改名留档,再用出厂配置写回磁盘,再回调一次,返回出厂配置。写回是为了让下次启动不再
@@ -69,13 +78,8 @@ export class ConfigManager {
69
78
  return parsed;
70
79
  }
71
80
  async write(config) {
72
- const dir = dirname(this.configPath);
73
- try {
74
- await fs.access(dir);
75
- }
76
- catch {
77
- await fs.mkdir(dir, { recursive: true });
78
- }
81
+ // `mkdir(recursive)` 幂等:目录已在时直接返回,不必先用 `access` 探一遍
82
+ await fs.mkdir(dirname(this.configPath), { recursive: true });
79
83
  const tmpPath = this.configPath + ".tmp";
80
84
  await fs.writeFile(tmpPath, JSON.stringify(config, null, 2), "utf-8");
81
85
  await fs.rename(tmpPath, this.configPath);
@@ -108,9 +112,9 @@ export class ConfigManager {
108
112
  await this.write(DEFAULT_APP_CONFIG);
109
113
  return { ...DEFAULT_APP_CONFIG };
110
114
  }
111
- // 先迁移历史字段,再同步出厂模型清单;两者结果与磁盘原文不同才写盘
112
- const migrated = migrateConfig(onDisk).config;
113
- const synced = syncManagedModels(migrated);
115
+ // 先把缺的字段补成出厂值,再同步出厂模型清单;两者结果与磁盘原文不同才写盘
116
+ const normalized = normalizeConfig(onDisk).config;
117
+ const synced = syncManagedModels(normalized);
114
118
  if (JSON.stringify(synced) !== JSON.stringify(onDisk)) {
115
119
  await this.write(synced);
116
120
  }
@@ -167,8 +171,12 @@ export class ConfigManager {
167
171
  await fs.writeFile(defaultPath, JSON.stringify(updated, null, 2), "utf-8");
168
172
  return updated;
169
173
  }
170
- catch {
171
- // 文件不存在或不可解析,继续走初始化流程
174
+ catch (error) {
175
+ // 文件不在 → 正常首次启动,走下面的初始化流程。
176
+ // 读得到却读不出来(不是合法 JSON、权限不对)是另一件事:**不能当成「没有这个文件」** ——
177
+ // 下面的「目录里已有文件就返回 null」会让它静默消失,用户永远不知道自己的定义坏了
178
+ if (error.code !== "ENOENT")
179
+ throw error;
172
180
  }
173
181
  await fs.mkdir(agentsDir, { recursive: true });
174
182
  let existing;
@@ -201,12 +209,14 @@ export class ConfigManager {
201
209
  async ensureDefaultSubAgent() {
202
210
  const subDir = join(this.basePath, "sub-agents");
203
211
  const defaultPath = join(subDir, `${DEFAULT_SUBAGENT_ID}.json`);
212
+ // 不必先 `access`:`readFile` 在文件不在时自己抛 ENOENT
204
213
  try {
205
- await fs.access(defaultPath);
206
214
  return JSON.parse(await fs.readFile(defaultPath, "utf-8"));
207
215
  }
208
- catch {
209
- // 文件不存在,继续
216
+ catch (error) {
217
+ // 只有「本来就没有」才继续往下建;解析不了 / 读不出来要抛,不能当成「没有」
218
+ if (error.code !== "ENOENT")
219
+ throw error;
210
220
  }
211
221
  await fs.mkdir(subDir, { recursive: true });
212
222
  let existing;
@@ -235,7 +245,7 @@ export class ConfigManager {
235
245
  */
236
246
  async bootstrap() {
237
247
  await this.ensureDirs();
238
- // 先把配置读到当前形状(内含迁移),再从里面取 `defaultModel` 去补默认 Agent 的模型
248
+ // 先把配置读到当前形状(内含补位),再从里面取 `defaultModel` 去补默认 Agent 的模型
239
249
  const config = await this.ensureDefaultConfig();
240
250
  this.knownModelIds = new Set((config.models ?? []).map((m) => m.id));
241
251
  const agent = await this.ensureDefaultAgent(config.defaultModel);
@@ -260,13 +270,18 @@ export class ConfigManager {
260
270
  */
261
271
  async readReasoningPresets() {
262
272
  try {
263
- const raw = await fs.readFile(this.reasoningPresetsPath, "utf-8");
264
- const parsed = JSON.parse(raw);
265
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
273
+ const parsed = JSON.parse(await fs.readFile(this.reasoningPresetsPath, "utf-8"));
274
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
266
275
  return parsed;
276
+ }
277
+ this.logger.error("[ConfigManager] 思考策略表不是合法对象,按出厂值提供服务");
267
278
  }
268
- catch {
269
- // 缺失或损坏 → 回落出厂种子
279
+ catch (error) {
280
+ // 文件还没释放过是首次启动的正常路径,不吵;其余(读不出来、不是 JSON)要说一声 ——
281
+ // 交出厂表是调用方要的(它要一张能用的表),但换了一张表不能装成没换
282
+ if (error.code !== "ENOENT") {
283
+ this.logger.error(`[ConfigManager] 思考策略表读不出来,按出厂值提供服务:${String(error)}`);
284
+ }
270
285
  }
271
286
  return { ...FACTORY_REASONING_PRESETS };
272
287
  }
@@ -286,8 +301,13 @@ export class ConfigManager {
286
301
  try {
287
302
  onDisk = JSON.parse(await fs.readFile(this.reasoningPresetsPath, "utf-8"));
288
303
  }
289
- catch {
290
- onDisk = null;
304
+ catch (error) {
305
+ // 只有「还没有这个文件」可以当成要释放出厂值。文件在却读不出来(不是 JSON、权限不对)
306
+ // 时**不覆盖** —— 那会把用户标了 `custom: true` 的条目一起抹掉,那是「擅自修」
307
+ if (error.code !== "ENOENT") {
308
+ this.logger.error(`[ConfigManager] 思考策略表读不出来,本次不写盘(你的表原样留着):${String(error)}`);
309
+ return [];
310
+ }
291
311
  }
292
312
  if (!onDisk || typeof onDisk !== "object" || Array.isArray(onDisk)) {
293
313
  await fs.mkdir(this.basePath, { recursive: true });
@@ -328,12 +348,16 @@ export class ConfigManager {
328
348
  for (const skill of FACTORY_SKILLS) {
329
349
  const dir = join(this.basePath, "skills", skill.id);
330
350
  const file = join(dir, "SKILL.md");
351
+ // 读不出来 ≠ 不存在:只有 ENOENT 才能当「还没释放过」,否则下面会拿出厂内容把它盖掉
331
352
  let existing = null;
332
353
  try {
333
354
  existing = await fs.readFile(file, "utf-8");
334
355
  }
335
- catch {
336
- existing = null;
356
+ catch (error) {
357
+ if (error.code !== "ENOENT") {
358
+ this.logger.error(`[ConfigManager] 出厂 Skill「${skill.id}」读不出来,本次不覆盖:${String(error)}`);
359
+ continue;
360
+ }
337
361
  }
338
362
  // 用户声明自有 → 永不覆盖
339
363
  if (existing != null && isCustomSkill(existing))
@@ -418,13 +442,8 @@ export class ConfigManager {
418
442
  }
419
443
  /** 原子写 JSON 文件(先写 .tmp 再 rename,避免半成品)。 */
420
444
  async writeJson(path, data) {
421
- const dir = dirname(path);
422
- try {
423
- await fs.access(dir);
424
- }
425
- catch {
426
- await fs.mkdir(dir, { recursive: true });
427
- }
445
+ // 同上:`mkdir(recursive)` 幂等,不必先探测
446
+ await fs.mkdir(dirname(path), { recursive: true });
428
447
  const tmpPath = path + ".tmp";
429
448
  await fs.writeFile(tmpPath, JSON.stringify(data, null, 2) + "\n", "utf-8");
430
449
  await fs.rename(tmpPath, path);
@@ -32,7 +32,7 @@ export declare const DEFAULT_MCP_CONFIG: {
32
32
  /**
33
33
  * 标准共享子目录列表(不包含运行时目录)。
34
34
  *
35
- * 各客户端(CLI/Desktop)的运行时数据(config.json、conversations/、drafts/)
35
+ * 各客户端(CLI/Desktop)的运行时数据(config.json、last-session.json、preferences.json)
36
36
  * 由客户端自行在各自目录下管理:
37
37
  * ~/.ai-zen/cli/ ← CLI 运行时
38
38
  * ~/.ai-zen/desktop/ ← Desktop 运行时
@@ -241,7 +241,7 @@ export const DEFAULT_APP_CONFIG = {
241
241
  defaultImageModel: "cogview-4",
242
242
  defaultAgent: "default",
243
243
  defaultMigrationModel: "deepseek-flash",
244
- // 自动标题:新会话第一轮结束后异步让模型起个名字(缺省开启,纯体验功能,
244
+ // 自动标题:新会话第一次回答结束后异步让模型起个名字(缺省开启,纯体验功能,
245
245
  // 关掉只省一次几十 token 的请求;缺字段的老配置也按开启算,判定见 `AppConfig.autoTitle`)
246
246
  autoTitle: true,
247
247
  // 工具输出上限(字符数),与 DEFAULT_MAX_TOOL_OUTPUT 保持一致
@@ -285,7 +285,7 @@ export const DEFAULT_MCP_CONFIG = {
285
285
  /**
286
286
  * 标准共享子目录列表(不包含运行时目录)。
287
287
  *
288
- * 各客户端(CLI/Desktop)的运行时数据(config.json、conversations/、drafts/)
288
+ * 各客户端(CLI/Desktop)的运行时数据(config.json、last-session.json、preferences.json)
289
289
  * 由客户端自行在各自目录下管理:
290
290
  * ~/.ai-zen/cli/ ← CLI 运行时
291
291
  * ~/.ai-zen/desktop/ ← Desktop 运行时
@@ -39,7 +39,7 @@ export const FALLBACK_HANDOFF_TEMPLATE = [
39
39
  /** 出厂 Skill:交接(handoff) */
40
40
  const HANDOFF_SKILL = `---
41
41
  name: handoff
42
- description: Write a task handoff document — when you stop work and leave the conversation, put the task goal, the actual current state, key decisions and next steps into a document that someone else can pick up directly.
42
+ description: Write a task handoff document — when you stop work and leave the session, put the task goal, the actual current state, key decisions and next steps into a document that someone else can pick up directly.
43
43
  metadata:
44
44
  custom: "false"
45
45
  ---
@@ -67,7 +67,7 @@ After writing with the write tool, read it back once with the read tool to confi
67
67
  ## Document Structure (write in this order, keep the headings exactly as they are)
68
68
 
69
69
  ## 💬 Conversation Breakpoint
70
- What the user last asked for, and what you last replied with or delivered. One paragraph each; do not restate the whole conversation.
70
+ What the user last asked for, and what you last replied with or delivered. One paragraph each; do not restate the whole session.
71
71
 
72
72
  ## 🎯 Task Goal
73
73
  What the user actually wants (intent and acceptance criteria), not a checklist of the steps you performed.