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

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 (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -3
  4. package/dist/agent-plugins/AutoMigratePlugin.d.ts +34 -5
  5. package/dist/agent-plugins/AutoMigratePlugin.js +56 -7
  6. package/dist/agent-plugins/AutoRefreshToolsPlugin.d.ts +8 -5
  7. package/dist/agent-plugins/AutoRefreshToolsPlugin.js +5 -6
  8. package/dist/agent-plugins/ContextGuardPlugin.d.ts +15 -3
  9. package/dist/agent-plugins/ContextGuardPlugin.js +16 -2
  10. package/dist/agent-plugins/SubAgentGuardInstallerPlugin.d.ts +18 -16
  11. package/dist/agent-plugins/SubAgentGuardInstallerPlugin.js +16 -14
  12. package/dist/agent-plugins/UnknownToolHintPlugin.d.ts +12 -3
  13. package/dist/agent-plugins/UnknownToolHintPlugin.js +16 -4
  14. package/dist/index.d.ts +5 -2
  15. package/dist/index.js +3 -0
  16. package/dist/runtime/HandoffGuardPlugin.d.ts +7 -5
  17. package/dist/runtime/HandoffGuardPlugin.js +8 -6
  18. package/dist/runtime/HandoffService.d.ts +51 -12
  19. package/dist/runtime/HandoffService.js +112 -19
  20. package/dist/runtime/SdkAgent.d.ts +2 -3
  21. package/dist/runtime/SdkAgent.js +1 -2
  22. package/dist/scope/Scope.d.ts +35 -8
  23. package/dist/scope/Scope.js +50 -11
  24. package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +7 -0
  25. package/dist/scope/plugins/mcp/McpConnectionManager.js +7 -0
  26. package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +23 -0
  27. package/dist/scope/plugins/mcp/McpScopePlugin.js +68 -1
  28. package/dist/scope/plugins/peers/PeerSessionsScopePlugin.d.ts +28 -0
  29. package/dist/scope/plugins/peers/PeerSessionsScopePlugin.js +35 -0
  30. package/dist/scope/plugins/peers/peerSessionTools.d.ts +122 -0
  31. package/dist/scope/plugins/peers/peerSessionTools.js +266 -0
  32. package/dist/scope/plugins/skills/skillTools.d.ts +1 -1
  33. package/dist/scope/plugins/skills/skillTools.js +6 -2
  34. package/dist/scope/plugins/subagents/subAgentTools.js +3 -0
  35. package/dist/shared/errors.d.ts +10 -3
  36. package/dist/shared/errors.js +10 -3
  37. package/dist/types/index.d.ts +6 -4
  38. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## [2.0.0-alpha.0] - 2026-11-16
2
+
3
+ > Follows `@ai-zen/agents-core` 5.0.0-alpha.0. Every plugin in this package was written against
4
+ > hooks that no longer exist, so the migration was not mechanical: each one had to pick a new seam
5
+ > and justify it.
6
+
7
+ ### Changed
8
+
9
+ - `onUnknownTool` folded into `onToolStart`: an unknown tool now runs the same gate, and whatever
10
+ the hook returns *is* the tool message the model reads (core no longer wraps it in "tool X was
11
+ denied: …").
12
+ - `ContextGuardPlugin` refuses by **returning a string** from `onInnerLoopStart` instead of throwing
13
+ `ContextOverflowError`. Throwing would tear down the whole loop; refusing leaves no placeholder
14
+ and reports `denied`.
15
+ - `AutoMigratePlugin` moved from `onAfterSend` to `onIdle`: migration is "nothing is moving any more",
16
+ not "this round ended".
17
+ - `HandoffService` no longer awaits an agent round it cannot own: it pushes the instruction and
18
+ watches `state`, accepting only an idle that follows a busy.
19
+ - Sub-agents are built with `lifetime: "one-shot"`; injected messages carry `source`.
20
+
1
21
  ## [1.1.0] - 2026-11-09
2
22
 
3
23
  > Cancelling a handoff now means "go back to how it was". Before this release `Ctrl+C` only
package/README.md CHANGED
@@ -4,7 +4,7 @@ AI-Zen SDK — shared business logic layer providing a unified Agent runtime for
4
4
 
5
5
  ## Source of Truth
6
6
 
7
- **[`docs/sdk-design-v1.md`](./docs/sdk-design-v1.md)** is the single source of truth for this package's design. All implementations must stay consistent with the document.
7
+ **[`../../PRD.md`](../../PRD.md)** (requirements) and **[`../../PLAN.md`](../../PLAN.md)** (implementation) are the single sources of truth for this package's behaviour. All implementations must stay consistent with them.
8
8
 
9
9
  ## Architecture
10
10
 
@@ -111,7 +111,7 @@ Conditionally injected based on the active model / config:
111
111
  | `generate_image` | Only when `defaultImageModel` is configured | Generate an image from a text description |
112
112
  | `view_image` | Only for vision models (the agent's `modelId` resolves to a model with `vision: true`) | View / analyze an image: local images are auto-uploaded via the Files API, network URLs are referenced directly |
113
113
 
114
- Tool output protection: `AppConfig.maxToolOutput` (in characters, default 32768) is the unified ceiling for tool output. Each tool handles overflow itself — `exec` dumps `stdout.log` / `stderr.log` separately (returning head/tail previews per stream), `find_text` / `glob` / `ls` dump `result.json` (returning a head preview), and `read` only warns and suggests batched reads via `range`. Dumps go to `<tmpdir>/ai-zen/tool-output/<tool>-<timestamp>-<random>/`, one directory per call, with no self-cleanup. See [`docs/sdk-design-v1.md`](docs/sdk-design-v1.md).
114
+ Tool output protection: `AppConfig.maxToolOutput` (in characters, default 32768) is the unified ceiling for tool output. Each tool handles overflow itself — `exec` dumps `stdout.log` / `stderr.log` separately (returning head/tail previews per stream), `find_text` / `glob` / `ls` dump `result.json` (returning a head preview), and `read` only warns and suggests batched reads via `range`. Dumps go to `<tmpdir>/ai-zen/tool-output/<tool>-<timestamp>-<random>/`, one directory per call, with no self-cleanup. Targets and boundaries: [`../../PLAN.md`](../../PLAN.md) §9; the exact behaviour lives in the code.
115
115
 
116
116
  Interrupt strategies live in the config: `AppConfig.abortedMessageStrategy` (`keep` / `drop`, factory `keep` — the model can continue the half-sentence after an interrupt) and `AppConfig.abortedToolRoundStrategy` (`fill` / `drop`, factory `fill` — whole rounds go in or out, because `tool_calls` must pair with results). `createAgent()` reads them from `scope.config` when no explicit option is passed, keeping a single source of truth.
117
117
 
@@ -135,7 +135,7 @@ This is a performance boundary, not a convenience choice — **SDK behaviour and
135
135
  - **Cache prefixes stop being comparable.** Prompt caching matches on the prefix; letting language into the SDK multiplies the prefix shapes of one code path and removes the single variable that benchmarks rely on.
136
136
  - **Diagnosis needs one shape.** Performance data, bug reproductions and tool-call success rates have to be comparable across users; once behaviour drifts with locale, every conclusion needs a "what language are you on?" qualifier first.
137
137
 
138
- Following the user's language is handled by one language-neutral instruction in the factory system prompt — `Always reply in the same language the user writes in.` — which adapts per **message** rather than per installation, and needs no locale plumbing in the SDK. Full rationale: [`docs/sdk-design-v1.md`](docs/sdk-design-v1.md).
138
+ Following the user's language is handled by one language-neutral instruction in the factory system prompt — `Always reply in the same language the user writes in.` — which adapts per **message** rather than per installation, and needs no locale plumbing in the SDK. Boundary: [`../../PLAN.md`](../../PLAN.md) §9.
139
139
 
140
140
  ## Design Principles
141
141
 
package/README.zh.md CHANGED
@@ -4,7 +4,7 @@ AI-Zen SDK — 共享业务逻辑层,为 CLI 和 Desktop 提供统一的 Agent
4
4
 
5
5
  ## 真相源
6
6
 
7
- **[`docs/sdk-design-v1.md`](./docs/sdk-design-v1.md)** 是本包的唯一设计真相源。所有实现必须与文档一致。
7
+ **[`../../PRD.md`](../../PRD.md)**(需求)与 **[`../../PLAN.md`](../../PLAN.md)**(实施)是本包行为的唯一真相源。所有实现必须与它们一致。
8
8
  ## 架构
9
9
 
10
10
  ```
@@ -110,7 +110,7 @@ await scope.dispose(); // 断开 MCP、释放插件资源
110
110
  | `generate_image` | 配置了 `defaultImageModel` 才注册 | 根据文字描述生成图片 |
111
111
  | `view_image` | 仅视觉模型可用(Agent 的 `modelId` 解析为 `vision: true` 的模型) | 查看/分析图片:本地图片自动经 Files API 上传,网络 URL 直接引用 |
112
112
 
113
- 工具输出保护:`AppConfig.maxToolOutput`(字符数,缺省 32768)是工具输出的统一上限,超限时由各工具自行处置——`exec` 分文件落盘 `stdout.log` / `stderr.log`(返回各流头尾预览),`find_text` / `glob` / `ls` 落盘 `result.json`(返回头部预览),`read` 仅警告并提示用 `range` 分批读取。落盘目录为 `<tmpdir>/ai-zen/tool-output/<工具名>-<时间戳>-<随机串>/`,每次调用独立、不自清理。详见 [`docs/sdk-design-v1.md`](docs/sdk-design-v1.md)。
113
+ 工具输出保护:`AppConfig.maxToolOutput`(字符数,缺省 32768)是工具输出的统一上限,超限时由各工具自行处置——`exec` 分文件落盘 `stdout.log` / `stderr.log`(返回各流头尾预览),`find_text` / `glob` / `ls` 落盘 `result.json`(返回头部预览),`read` 仅警告并提示用 `range` 分批读取。落盘目录为 `<tmpdir>/ai-zen/tool-output/<工具名>-<时间戳>-<随机串>/`,每次调用独立、不自清理。口径与边界见 [`../../PLAN.md`](../../PLAN.md) §9;具体行为以代码为准。
114
114
 
115
115
  中断策略进配置:`AppConfig.abortedMessageStrategy`(`keep` / `drop`,出厂 `keep`——中断后模型能接着半截往下说)与 `AppConfig.abortedToolRoundStrategy`(`fill` / `drop`,出厂 `fill`——整轮进出,`tool_calls` 必须与结果配对)。`createAgent()` 不传参数时直接取 `scope.config`,于是策略只有一个真相源。
116
116
 
@@ -134,7 +134,7 @@ SDK 是 **English-only**:所有面向模型与面向用户的文案(工具 s
134
134
  - **缓存前缀不再可比。** prompt 缓存按前缀匹配;语言一旦进入 SDK,同一条代码路径就有了多个前缀形态,基准测试失去单一变量。
135
135
  - **基准与排查需要单一形态。** 性能数据、bug 复现、工具调用成功率都要能横向比较;行为若随 locale 漂移,任何结论都得先问「你是什么语言」。
136
136
 
137
- 「模型跟随用户语言」由一条语言中立的 system prompt 指令承担 —— `Always reply in the same language the user writes in.` —— 按**每条消息**自适应,比按安装实例绑定 locale 更准确,也不需要 SDK 参与。完整论述见 [`docs/sdk-design-v1.md`](docs/sdk-design-v1.md)。
137
+ 「模型跟随用户语言」由一条语言中立的 system prompt 指令承担 —— `Always reply in the same language the user writes in.` —— 按**每条消息**自适应,比按安装实例绑定 locale 更准确,也不需要 SDK 参与。边界见 [`../../PLAN.md`](../../PLAN.md) §9。
138
138
 
139
139
  ## 设计原则
140
140
 
@@ -1,4 +1,4 @@
1
- import type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
1
+ import type { AgentPlugin, OuterLoopContext } from "@ai-zen/agents-core";
2
2
  import type { HandoffMode, HandoffService } from "../runtime/HandoffService.js";
3
3
  /** 触发迁移时的用量信息(供执行者选择、确认文案使用) */
4
4
  export interface AutoMigrateTriggerInfo {
@@ -25,6 +25,15 @@ export interface AutoMigrateOptions {
25
25
  * 或直接返回 `null` 表达「本次不迁移」——**无需**再继承本插件。
26
26
  */
27
27
  resolveMode?: AutoMigrateModeResolver;
28
+ /**
29
+ * 迁移完成之后的回声(可选):`mode` 是**实际**用的执行者(`self` 降级到 `summary` 时以
30
+ * 服务报的为准)。宿主据此落「这段会话压缩过」这类观测事实 —— 插件自己不认识存储层。
31
+ *
32
+ * 钩子抛错只记一条日志:迁移已经完成,标不出来是观测问题,不该反过来让这一轮报错。
33
+ */
34
+ onMigrated?: (info: AutoMigrateTriggerInfo & {
35
+ mode: HandoffMode;
36
+ }) => void | Promise<void>;
28
37
  }
29
38
  /**
30
39
  * 自动迁移插件 —— 只负责「何时触发」,实际迁移统一委托给持有的 `HandoffService`。
@@ -40,13 +49,33 @@ export interface AutoMigrateOptions {
40
49
  * }));
41
50
  * ```
42
51
  *
43
- * 两层让行(缺一不可):
44
- * - `service.busy`:交接回合本身就是一次 `send()`,其 `onAfterSend` 会再次到这里;
45
- * 不跳过就会「交接触发迁移 → 迁移再交接」无限递归;
52
+ * ## 为什么落在 `onIdle`(旧的 `onAfterSend` 已删除)
53
+ *
54
+ * 迁移是「**彻底不动了才做**」的事:它要在原会话里再跑一个交接回合、然后把整段历史
55
+ * 标 `omit` / 物理剔除、换掉 `agent.messages` 的引用。「这一圈答完了」还不够 ——
56
+ * 内循环可能还要接着跑工具、队列里可能还压着别的投递,那些都还在写同一个数组。
57
+ * `onIdle` 的语义正是「手上没活、队列也空」(`CORE.md` §4),此刻换历史引用才不会
58
+ * 踩到正在跑的圈;而 `onOuterLoopEnd` 只保证「这一批跑完了」,队列里可能还有货。
59
+ *
60
+ * ## 两层让行(缺一不可)
61
+ * - `service.busy`:交接回合本身就是「往同一个 agent 里再投一轮」,它跑完后 agent 又会
62
+ * 变闲一次,`onIdle` 会再次到这里;不跳过就会「交接触发迁移 → 迁移再交接」无限递归;
46
63
  * - 交接回合结束后的用量也仍可能超阈值,故 busy 判断必须覆盖整个交接 + 迁移过程。
64
+ *
65
+ * ## `onIdle()` 不带 ctx:agent 从 `onOuterLoopStart` 认领
66
+ *
67
+ * core 的死活钩子(`onIdle` / `onStart` / `onStop` …)没有参数,而迁移必须有 agent。
68
+ * 于是这里在 `onOuterLoopStart`(每一批事件开头必到,且排在 `onIdle` 之前)把 agent
69
+ * 记下来 —— 那一步只做登记,不做任何判断。
47
70
  */
48
71
  export declare class AutoMigratePlugin implements AgentPlugin {
49
72
  private options;
73
+ /** 认领到的 agent(见类注释最后一段:`onIdle()` 不带 ctx) */
74
+ private agent?;
50
75
  constructor(options: AutoMigrateOptions);
51
- onAfterSend(ctx: SendContext): Promise<void>;
76
+ /** 只登记 agent:`onIdle()` 没有 ctx,而迁移需要它。不做任何判断。 */
77
+ onOuterLoopStart(ctx: OuterLoopContext): void;
78
+ onIdle(): Promise<void>;
79
+ /** 迁移之后的回声:钩子自己的失败不影响迁移结果(只记日志) */
80
+ private notifyMigrated;
52
81
  }
@@ -1,3 +1,4 @@
1
+ import { AgentError } from "@ai-zen/agents-core";
1
2
  import { HandoffAbortedError } from "../runtime/HandoffService.js";
2
3
  import { getLogger } from "../shared/logger.js";
3
4
  /**
@@ -14,19 +15,41 @@ import { getLogger } from "../shared/logger.js";
14
15
  * }));
15
16
  * ```
16
17
  *
17
- * 两层让行(缺一不可):
18
- * - `service.busy`:交接回合本身就是一次 `send()`,其 `onAfterSend` 会再次到这里;
19
- * 不跳过就会「交接触发迁移 → 迁移再交接」无限递归;
18
+ * ## 为什么落在 `onIdle`(旧的 `onAfterSend` 已删除)
19
+ *
20
+ * 迁移是「**彻底不动了才做**」的事:它要在原会话里再跑一个交接回合、然后把整段历史
21
+ * 标 `omit` / 物理剔除、换掉 `agent.messages` 的引用。「这一圈答完了」还不够 ——
22
+ * 内循环可能还要接着跑工具、队列里可能还压着别的投递,那些都还在写同一个数组。
23
+ * `onIdle` 的语义正是「手上没活、队列也空」(`CORE.md` §4),此刻换历史引用才不会
24
+ * 踩到正在跑的圈;而 `onOuterLoopEnd` 只保证「这一批跑完了」,队列里可能还有货。
25
+ *
26
+ * ## 两层让行(缺一不可)
27
+ * - `service.busy`:交接回合本身就是「往同一个 agent 里再投一轮」,它跑完后 agent 又会
28
+ * 变闲一次,`onIdle` 会再次到这里;不跳过就会「交接触发迁移 → 迁移再交接」无限递归;
20
29
  * - 交接回合结束后的用量也仍可能超阈值,故 busy 判断必须覆盖整个交接 + 迁移过程。
30
+ *
31
+ * ## `onIdle()` 不带 ctx:agent 从 `onOuterLoopStart` 认领
32
+ *
33
+ * core 的死活钩子(`onIdle` / `onStart` / `onStop` …)没有参数,而迁移必须有 agent。
34
+ * 于是这里在 `onOuterLoopStart`(每一批事件开头必到,且排在 `onIdle` 之前)把 agent
35
+ * 记下来 —— 那一步只做登记,不做任何判断。
21
36
  */
22
37
  export class AutoMigratePlugin {
23
38
  options;
39
+ /** 认领到的 agent(见类注释最后一段:`onIdle()` 不带 ctx) */
40
+ agent;
24
41
  constructor(options) {
25
42
  this.options = options;
26
43
  }
27
- async onAfterSend(ctx) {
28
- const agent = ctx.agent;
29
- const { service, handoffTokens, resolveMode } = this.options;
44
+ /** 只登记 agent:`onIdle()` 没有 ctx,而迁移需要它。不做任何判断。 */
45
+ onOuterLoopStart(ctx) {
46
+ this.agent = ctx.agent;
47
+ }
48
+ async onIdle() {
49
+ const agent = this.agent;
50
+ if (!agent)
51
+ return;
52
+ const { service, handoffTokens, resolveMode, onMigrated } = this.options;
30
53
  // 交接/迁移进行中:让行(防递归)
31
54
  if (service.busy)
32
55
  return;
@@ -39,14 +62,40 @@ export class AutoMigratePlugin {
39
62
  const mode = resolveMode ? await resolveMode({ promptTokens, handoffTokens }) : undefined;
40
63
  if (mode === null)
41
64
  return; // 用户选择跳过本次迁移
42
- await service.migrate({ agent, promptTokens, handoffTokens, mode: mode ?? undefined });
65
+ const migrated = await service.migrate({
66
+ agent,
67
+ promptTokens,
68
+ handoffTokens,
69
+ mode: mode ?? undefined,
70
+ });
71
+ // 迁移已经完成(历史已 omit / prune,断点已注入):这时候才报「压过了」
72
+ await this.notifyMigrated(onMigrated, {
73
+ promptTokens,
74
+ handoffTokens,
75
+ mode: migrated?.mode ?? mode ?? "self",
76
+ });
43
77
  }
44
78
  catch (err) {
45
79
  // 用户主动取消不是失败:服务已把会话退回交接前,这里再报错只会在界面上
46
80
  // 凭空多一条「迁移失败」(默认 logger 是 console.error,TUI 下直接撕画面)
47
81
  if (err instanceof HandoffAbortedError)
48
82
  return;
83
+ // agent 已经关门/被硬杀(`stop()` / `kill()` 之后又走到 idle):没什么可迁移的。
84
+ // 不报错、也不降级 summary —— 那会为一个已经没有的会话白烧一轮全量输入。
85
+ if (err instanceof AgentError && err.code === "closed")
86
+ return;
49
87
  getLogger().error(`[autoMigrate] migration failed: ${err?.message ?? err}`);
50
88
  }
51
89
  }
90
+ /** 迁移之后的回声:钩子自己的失败不影响迁移结果(只记日志) */
91
+ async notifyMigrated(hook, info) {
92
+ if (!hook)
93
+ return;
94
+ try {
95
+ await hook(info);
96
+ }
97
+ catch (err) {
98
+ getLogger().error(`[autoMigrate] onMigrated hook failed: ${err?.message ?? err}`);
99
+ }
100
+ }
52
101
  }
@@ -1,4 +1,4 @@
1
- import type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
1
+ import type { AgentPlugin, InnerLoopContext, OuterLoopContext } from "@ai-zen/agents-core";
2
2
  /**
3
3
  * 自动刷新能力的时机。
4
4
  *
@@ -7,12 +7,15 @@ import type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
7
7
  * | 档位 | 钩子 | 会话中新装的 MCP / skill / 工具什么时候能被模型看见 |
8
8
  * |------|------|---------------------------------------------|
9
9
  * | `inner-loop-start` | `onInnerLoopStart`(每次请求发出前) | 同一轮里下一次请求就看见(含工具回合的空档) |
10
- * | `outer-loop-start` | `onBeforeSend`(整个 `send()` 开头) | 下一轮对话才看见;一轮只刷一次,开销最小 |
10
+ * | `outer-loop-start` | `onOuterLoopStart`(每一批事件开头,一圈只刷一次) | 下一轮对话才看见;一轮只刷一次,开销最小 |
11
11
  * | `off` | 不装插件 | 只靠 `/reload` |
12
12
  *
13
13
  * 为什么不是「每轮固定刷一次」:一次 `refresh()` 会重扫 MCP 配置、按需建连接,
14
14
  * 长工具链的一轮里可能要跑好几次。默认 `inner-loop-start` 是时效优先的取舍,
15
15
  * 嫌开销大就换成 `outer-loop-start`。
16
+ *
17
+ * 档位名沿用 `outer-loop-start`(配置里写着它):它映射到的钩子就是 core 的外循环开头
18
+ * —— 原来是 `onBeforeSend`(一次 `send()` 的开头),而 `send()` 已经不存在了。
16
19
  */
17
20
  export type AutoRefreshWhen = "inner-loop-start" | "outer-loop-start";
18
21
  /**
@@ -33,7 +36,7 @@ export declare class AutoRefreshToolsPlugin implements AgentPlugin {
33
36
  when?: AutoRefreshWhen;
34
37
  });
35
38
  /** 内循环开始(每次请求前):能力变化在同一轮里就能生效 */
36
- onInnerLoopStart(ctx: SendContext): Promise<void>;
37
- /** 外循环开始(整个 `send()` 一次):最省,代价是要等到下一轮 */
38
- onBeforeSend(ctx: SendContext): Promise<void>;
39
+ onInnerLoopStart(ctx: InnerLoopContext): Promise<void>;
40
+ /** 外循环开始(这一批事件的开头):最省,代价是要等到下一轮 */
41
+ onOuterLoopStart(ctx: OuterLoopContext): Promise<void>;
39
42
  }
@@ -19,18 +19,17 @@ export class AutoRefreshToolsPlugin {
19
19
  async onInnerLoopStart(ctx) {
20
20
  if (this.when !== "inner-loop-start")
21
21
  return;
22
- await refreshTools(ctx);
22
+ await refreshTools(ctx.agent);
23
23
  }
24
- /** 外循环开始(整个 `send()` 一次):最省,代价是要等到下一轮 */
25
- async onBeforeSend(ctx) {
24
+ /** 外循环开始(这一批事件的开头):最省,代价是要等到下一轮 */
25
+ async onOuterLoopStart(ctx) {
26
26
  if (this.when !== "outer-loop-start")
27
27
  return;
28
- await refreshTools(ctx);
28
+ await refreshTools(ctx.agent);
29
29
  }
30
30
  }
31
31
  /** 重新发现 + 按新结果重建工具集(两个档位共用同一段,免得两处漂) */
32
- async function refreshTools(ctx) {
33
- const agent = ctx.agent;
32
+ async function refreshTools(agent) {
34
33
  await agent.scope.refresh({ silent: true });
35
34
  agent.tools = agent.scope.buildTools(agent.definition, {
36
35
  exclude: {
@@ -1,4 +1,4 @@
1
- import type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
1
+ import type { AgentPlugin, InnerLoopContext } from "@ai-zen/agents-core";
2
2
  export interface ContextGuardOptions {
3
3
  /**
4
4
  * 强行阻断阈值(tokens,绝对值)。
@@ -20,7 +20,7 @@ export interface ContextGuardOptions {
20
20
  * 上下文安全护栏插件。
21
21
  *
22
22
  * 在每次内循环**发请求前**检测上一轮用量(usage.prompt_tokens):超过 `guardTokens`
23
- * 即抛 `ContextOverflowError` 中断对话,交由上层向用户报错。
23
+ * 就**拒绝这一圈**,交由上层向用户报错。
24
24
  *
25
25
  * 与迁移插件职责分离:
26
26
  * - `ContextGuardPlugin`:硬线,只做「严重超限即中断」的安全兜底,绝不继续对话/迁移;
@@ -37,10 +37,22 @@ export interface ContextGuardOptions {
37
37
  * );
38
38
  * agent.use(new AutoMigratePlugin({ service: handoffService, handoffTokens: handoff }));
39
39
  * ```
40
+ *
41
+ * ## 为什么是「返回字符串」而不是「抛错」
42
+ *
43
+ * 新 core(`CORE.md` §11)里 `onInnerLoopStart` 能拒:**返回 string = 这一圈压根没发出去**
44
+ * —— 不会留下一类「永远 Pending 的助手占位」,core 报一个 `denied` 事件(带钩子名与理由),
45
+ * 然后回外循环等下一个事件,循环还活着。
46
+ *
47
+ * 抛错不是「更硬的拒绝」:钩子里的异常会穿到 `start()` 外面,把整个循环打死
48
+ * (`start()` 的 promise 直接 resolve、循环不再取件),agent 从此变成「塞进去也不动」的
49
+ * 僵尸。这也是为什么老的「抛 `ContextOverflowError` 让上层接住」不能照搬 —— 上层现在能从
50
+ * `denied` 事件和 `message` 的历史里看到同一件事,不需要一个把 agent 弄死的异常。
40
51
  */
41
52
  export declare class ContextGuardPlugin implements AgentPlugin {
42
53
  private readonly guardTokens;
43
54
  private readonly isSuspended?;
44
55
  constructor(options: ContextGuardOptions);
45
- onInnerLoopStart(ctx: SendContext): Promise<void>;
56
+ /** 返回 string = 拒这一圈(这一圈不会发出去,历史里一个字都不多) */
57
+ onInnerLoopStart(ctx: InnerLoopContext): Promise<string | undefined>;
46
58
  }
@@ -3,7 +3,7 @@ import { ContextOverflowError } from "../shared/errors.js";
3
3
  * 上下文安全护栏插件。
4
4
  *
5
5
  * 在每次内循环**发请求前**检测上一轮用量(usage.prompt_tokens):超过 `guardTokens`
6
- * 即抛 `ContextOverflowError` 中断对话,交由上层向用户报错。
6
+ * 就**拒绝这一圈**,交由上层向用户报错。
7
7
  *
8
8
  * 与迁移插件职责分离:
9
9
  * - `ContextGuardPlugin`:硬线,只做「严重超限即中断」的安全兜底,绝不继续对话/迁移;
@@ -20,6 +20,17 @@ import { ContextOverflowError } from "../shared/errors.js";
20
20
  * );
21
21
  * agent.use(new AutoMigratePlugin({ service: handoffService, handoffTokens: handoff }));
22
22
  * ```
23
+ *
24
+ * ## 为什么是「返回字符串」而不是「抛错」
25
+ *
26
+ * 新 core(`CORE.md` §11)里 `onInnerLoopStart` 能拒:**返回 string = 这一圈压根没发出去**
27
+ * —— 不会留下一类「永远 Pending 的助手占位」,core 报一个 `denied` 事件(带钩子名与理由),
28
+ * 然后回外循环等下一个事件,循环还活着。
29
+ *
30
+ * 抛错不是「更硬的拒绝」:钩子里的异常会穿到 `start()` 外面,把整个循环打死
31
+ * (`start()` 的 promise 直接 resolve、循环不再取件),agent 从此变成「塞进去也不动」的
32
+ * 僵尸。这也是为什么老的「抛 `ContextOverflowError` 让上层接住」不能照搬 —— 上层现在能从
33
+ * `denied` 事件和 `message` 的历史里看到同一件事,不需要一个把 agent 弄死的异常。
23
34
  */
24
35
  export class ContextGuardPlugin {
25
36
  guardTokens;
@@ -28,6 +39,7 @@ export class ContextGuardPlugin {
28
39
  this.guardTokens = options.guardTokens;
29
40
  this.isSuspended = options.isSuspended;
30
41
  }
42
+ /** 返回 string = 拒这一圈(这一圈不会发出去,历史里一个字都不多) */
31
43
  async onInnerLoopStart(ctx) {
32
44
  // 交接/迁移回合让行(见 `isSuspended`)
33
45
  if (this.isSuspended?.())
@@ -37,7 +49,9 @@ export class ContextGuardPlugin {
37
49
  if (promptTokens == null)
38
50
  return;
39
51
  if (promptTokens > this.guardTokens) {
40
- throw new ContextOverflowError(promptTokens, this.guardTokens);
52
+ // 理由就是给用户看的那句话:`denied` 事件里只有字符串这一个通道,
53
+ // 所以用量与阈值一并写进去(`ContextOverflowError` 只用来拼这句话,不往外抛)
54
+ return new ContextOverflowError(promptTokens, this.guardTokens).message;
41
55
  }
42
56
  }
43
57
  }
@@ -6,15 +6,15 @@
6
6
  * 远程会话的子 Agent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
7
7
  * 共享同一套阈值语义。
8
8
  *
9
- * 背景:SDK 的子 Agent 由 `AgentTool` / `AgentToolLazy` 在委派时 `new Agent({...})` 构建,
10
- * 新建实例不携带任何插件(`Agent._plugins` 每实例私有,不向子 Agent 传播),且子 Agent 走
11
- * `run()` 而非 `send()`(`onBeforeSend` / `onAfterSend` 不会触发)。因此主 Agent 上的
12
- * `ContextGuardPlugin` 对子 Agent 完全无效:子 Agent 的内循环没有上下文 token 护栏。
9
+ * 背景:SDK 的子 Agent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
10
+ * 构建(core 的 `buildAgent` 回调),新建实例不携带任何插件(`Agent` 的插件表每实例私有,
11
+ * 不向子 Agent 传播),且子 Agent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
+ * `ContextGuardPlugin` 对它完全无效:子 Agent 的内循环没有上下文 token 护栏。
13
13
  *
14
- * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 run()」时由宿主 Agent
15
- * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入 `_plugins`,而钩子分发每次都实时遍历
16
- * 该列表,故在钩子内安插对**本次 run 立即生效**(无需 init;AgentTool 也不会调用子 Agent 的
17
- * init)。
14
+ * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
+ * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
16
+ * 该列表,故在钩子内安插对**本次 runOnce 立即生效**(无需 init;`AgentToolLazy` 也不会调用
17
+ * 子 Agent 的 init)。
18
18
  *
19
19
  * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到子 Agent 上
20
20
  * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`),使「请求前用量超过硬线即中断」
@@ -27,16 +27,18 @@
27
27
  * 都要带上,否则孙级又会把让行丢掉(同一个缺口往下挪一层而已)。
28
28
  * **不设**轮次上限,**不设**工具调用次数上限。
29
29
  *
30
- * 中断语义:抛错即结束子 Agent 的 run;异常经 `AgentTool` 的 finally(分发 onSubAgentEnd)
31
- * 上抛至父 Agent,因父 Agent 默认 `allowJsonParseError = true` 而降级为一条工具结果文本
32
- * (`执行工具 X 时出错: …`),父 Agent 继续下一轮——即「软中断」:停掉越界的子 Agent,但不
33
- * 终止用户对话(如需硬停,父 Agent 须设 allowJsonParseError=false)。
30
+ * 中断语义(core 重写之后变了,这是必须知道的一条):护栏在 `onInnerLoopStart` 里**返回
31
+ * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是子 Agent 的那一圈**压根没发出去** ——
32
+ * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是子 Agent
33
+ * 已装好的历史(委派工具交回 `messages` 的最后一条),**不是**一段「执行工具时出错」的异常
34
+ * 文本 —— 新 core 里钩子抛错会穿到 `start()` 外面把循环打死,反而连收尾都做不干净。
34
35
  *
35
- * 覆盖范围:core 只有两条委派路径(`AgentTool` / `AgentToolLazy`),均分发 onSubAgentStart,
36
- * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)同样由
36
+ * 覆盖范围:core 的委派路径是 `AgentToolLazy`,它分发 onSubAgentStart / onSubAgentEnd,
37
+ * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)与
38
+ * `createSubAgentTool` 造出来的那些(名称取自定义的 `function.name`)同样由
37
39
  * `AgentToolLazy` 承载、走同一委派边界,因此也在覆盖范围内。
38
40
  */
39
- import type { AgentPlugin, SubAgentContext } from "@ai-zen/agents-core";
41
+ import type { AgentPlugin, SubAgentHookContext } from "@ai-zen/agents-core";
40
42
  export interface SubAgentGuardOptions {
41
43
  /** 强行阻断阈值;与主 Agent 同源(当前模型的 `tokenThresholds.guard`) */
42
44
  guardTokens: number;
@@ -60,5 +62,5 @@ export declare class SubAgentGuardInstallerPlugin implements AgentPlugin {
60
62
  /** 让行判断按**引用**存下:它读的是「此刻是否在交接」,不是装配那一刻的快照 */
61
63
  private readonly isSuspended?;
62
64
  constructor(options: SubAgentGuardOptions);
63
- onSubAgentStart({ subAgent }: SubAgentContext): void;
65
+ onSubAgentStart({ subAgent }: SubAgentHookContext): void;
64
66
  }
@@ -6,15 +6,15 @@
6
6
  * 远程会话的子 Agent 就会裸奔;把它放进 SDK,CLI 与服务端才能装同一份护栏、
7
7
  * 共享同一套阈值语义。
8
8
  *
9
- * 背景:SDK 的子 Agent 由 `AgentTool` / `AgentToolLazy` 在委派时 `new Agent({...})` 构建,
10
- * 新建实例不携带任何插件(`Agent._plugins` 每实例私有,不向子 Agent 传播),且子 Agent 走
11
- * `run()` 而非 `send()`(`onBeforeSend` / `onAfterSend` 不会触发)。因此主 Agent 上的
12
- * `ContextGuardPlugin` 对子 Agent 完全无效:子 Agent 的内循环没有上下文 token 护栏。
9
+ * 背景:SDK 的子 Agent 由 `AgentToolLazy` 在委派时 `new Agent({ lifetime: "one-shot", ... })`
10
+ * 构建(core 的 `buildAgent` 回调),新建实例不携带任何插件(`Agent` 的插件表每实例私有,
11
+ * 不向子 Agent 传播),且子 Agent 走 `runOnce()`(一次性的那一条路),主 Agent 上的
12
+ * `ContextGuardPlugin` 对它完全无效:子 Agent 的内循环没有上下文 token 护栏。
13
13
  *
14
- * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 run()」时由宿主 Agent
15
- * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入 `_plugins`,而钩子分发每次都实时遍历
16
- * 该列表,故在钩子内安插对**本次 run 立即生效**(无需 init;AgentTool 也不会调用子 Agent 的
17
- * init)。
14
+ * 介入点:core 的 `onSubAgentStart` 钩子在「子 Agent 已构建、尚未 `runOnce()`」时由宿主 Agent
15
+ * 分发,载荷携带子 Agent 实例。`use()` 只是把插件推入插件表,而钩子分发每次都实时遍历
16
+ * 该列表,故在钩子内安插对**本次 runOnce 立即生效**(无需 init;`AgentToolLazy` 也不会调用
17
+ * 子 Agent 的 init)。
18
18
  *
19
19
  * 约束口径(与主 Agent 同款,一项不落):把主 Agent 同款的 `ContextGuardPlugin` 装到子 Agent 上
20
20
  * —— 同一个 `guardTokens`(当前模型的 `tokenThresholds.guard`),使「请求前用量超过硬线即中断」
@@ -27,13 +27,15 @@
27
27
  * 都要带上,否则孙级又会把让行丢掉(同一个缺口往下挪一层而已)。
28
28
  * **不设**轮次上限,**不设**工具调用次数上限。
29
29
  *
30
- * 中断语义:抛错即结束子 Agent 的 run;异常经 `AgentTool` 的 finally(分发 onSubAgentEnd)
31
- * 上抛至父 Agent,因父 Agent 默认 `allowJsonParseError = true` 而降级为一条工具结果文本
32
- * (`执行工具 X 时出错: …`),父 Agent 继续下一轮——即「软中断」:停掉越界的子 Agent,但不
33
- * 终止用户对话(如需硬停,父 Agent 须设 allowJsonParseError=false)。
30
+ * 中断语义(core 重写之后变了,这是必须知道的一条):护栏在 `onInnerLoopStart` 里**返回
31
+ * 拒绝字符串**(`CORE.md` §11「哪些钩子能拒」),于是子 Agent 的那一圈**压根没发出去** ——
32
+ * 历史里一个字都不多,core 报 `denied`,委派工具照常收尾。父 Agent 这边拿到的是子 Agent
33
+ * 已装好的历史(委派工具交回 `messages` 的最后一条),**不是**一段「执行工具时出错」的异常
34
+ * 文本 —— 新 core 里钩子抛错会穿到 `start()` 外面把循环打死,反而连收尾都做不干净。
34
35
  *
35
- * 覆盖范围:core 只有两条委派路径(`AgentTool` / `AgentToolLazy`),均分发 onSubAgentStart,
36
- * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)同样由
36
+ * 覆盖范围:core 的委派路径是 `AgentToolLazy`,它分发 onSubAgentStart / onSubAgentEnd,
37
+ * 故本插件对**全部**子 Agent 生效。SDK 的 `call_skill_sub_agent`(技能子 Agent)与
38
+ * `createSubAgentTool` 造出来的那些(名称取自定义的 `function.name`)同样由
37
39
  * `AgentToolLazy` 承载、走同一委派边界,因此也在覆盖范围内。
38
40
  */
39
41
  import { ContextGuardPlugin } from "./ContextGuardPlugin.js";
@@ -1,4 +1,4 @@
1
- import type { AgentPlugin, UnknownToolContext } from "@ai-zen/agents-core";
1
+ import type { AgentPlugin, ToolHookContext } from "@ai-zen/agents-core";
2
2
  import type { Scope } from "../scope/Scope.js";
3
3
  /**
4
4
  * 未知工具智能提示插件 — MCP 场景引导。
@@ -9,14 +9,23 @@ import type { Scope } from "../scope/Scope.js";
9
9
  * - 否则 → 仅提示工具不存在
10
10
  *
11
11
  * 由调用方显式注册(`agent.use(new UnknownToolHintPlugin({ scope }))`)。
12
- * 未注册时,Agent 回落到底层的简单文本默认提示(core 内建)。
12
+ * 未注册时,core 自己回落到简单文本提示(`未知工具: X,没有找到对应的工具实现。`)。
13
13
  *
14
14
  * 是否"有 MCP 配置"经 `scope.getPluginById(McpScopePlugin.ID)` 查询 MCP 插件获得。
15
+ *
16
+ * ## 钩子:`onToolStart`(`onUnknownTool` 已删除)
17
+ *
18
+ * core 重写后没有单独的「未知工具」钩子了 —— 未知工具也走 `onToolStart`,只是
19
+ * `ctx.toolCall.tool === undefined`(没匹配到已注册的实现)。于是本插件就守在这条缝上:
20
+ * 判到「工具不存在」才返回提示字符串,其余一律放行(返回 undefined)。
21
+ *
22
+ * 返回的字符串**就是那条 tool 消息的正文**(core 会把它作为拒绝原因回给模型),
23
+ * 因此模型读到的是引导、而不是默认的「没有找到对应的工具实现」。
15
24
  */
16
25
  export declare class UnknownToolHintPlugin implements AgentPlugin {
17
26
  private readonly scope;
18
27
  constructor(options: {
19
28
  scope: Scope;
20
29
  });
21
- onUnknownTool(ctx: UnknownToolContext): string | undefined;
30
+ onToolStart(ctx: ToolHookContext): string | undefined;
22
31
  }
@@ -8,20 +8,32 @@ import { McpScopePlugin } from "../scope/plugins/mcp/McpScopePlugin.js";
8
8
  * - 否则 → 仅提示工具不存在
9
9
  *
10
10
  * 由调用方显式注册(`agent.use(new UnknownToolHintPlugin({ scope }))`)。
11
- * 未注册时,Agent 回落到底层的简单文本默认提示(core 内建)。
11
+ * 未注册时,core 自己回落到简单文本提示(`未知工具: X,没有找到对应的工具实现。`)。
12
12
  *
13
13
  * 是否"有 MCP 配置"经 `scope.getPluginById(McpScopePlugin.ID)` 查询 MCP 插件获得。
14
+ *
15
+ * ## 钩子:`onToolStart`(`onUnknownTool` 已删除)
16
+ *
17
+ * core 重写后没有单独的「未知工具」钩子了 —— 未知工具也走 `onToolStart`,只是
18
+ * `ctx.toolCall.tool === undefined`(没匹配到已注册的实现)。于是本插件就守在这条缝上:
19
+ * 判到「工具不存在」才返回提示字符串,其余一律放行(返回 undefined)。
20
+ *
21
+ * 返回的字符串**就是那条 tool 消息的正文**(core 会把它作为拒绝原因回给模型),
22
+ * 因此模型读到的是引导、而不是默认的「没有找到对应的工具实现」。
14
23
  */
15
24
  export class UnknownToolHintPlugin {
16
25
  scope;
17
26
  constructor(options) {
18
27
  this.scope = options.scope;
19
28
  }
20
- onUnknownTool(ctx) {
21
- const toolName = ctx.toolCall.function?.name ?? "unknown";
29
+ onToolStart(ctx) {
30
+ // 只关心「工具不存在」:匹配到实现的一律放行,别抢别的工具的活
31
+ if (ctx.toolCall.tool !== undefined)
32
+ return;
33
+ const toolName = ctx.toolCall.tool_call.function?.name ?? "unknown";
22
34
  const mcpPlugin = this.scope.getPluginById(McpScopePlugin.ID);
23
35
  const hasMcpConfig = mcpPlugin?.hasConfig() ?? false;
24
- const hasCallMcpTool = ctx.availableTools.some((t) => t.function.name === "call_mcp_tool");
36
+ const hasCallMcpTool = ctx.agent.tools.some((t) => t.function.name === "call_mcp_tool");
25
37
  if (hasMcpConfig && !hasCallMcpTool) {
26
38
  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.`;
27
39
  }
package/dist/index.d.ts CHANGED
@@ -11,13 +11,16 @@ export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
11
11
  export { discoverUserTools, discoverUserToolFiles } from "./scope/plugins/usertools/discover.js";
12
12
  export type { UserToolFile } from "./scope/plugins/usertools/discover.js";
13
13
  export { Scope } from "./scope/Scope.js";
14
- export type { FilterOutput, ExcludeOptions, FilterOptions } from "./scope/Scope.js";
14
+ export type { FilterOutput, ExcludeOptions, FilterOptions, ScopeConfigSource, } from "./scope/Scope.js";
15
15
  export type { ScopePlugin, ScopeCandidates } from "./scope/ScopePlugin.js";
16
16
  export { BuiltinToolsScopePlugin } from "./scope/plugins/builtin/BuiltinToolsScopePlugin.js";
17
17
  export { UserToolsScopePlugin } from "./scope/plugins/usertools/UserToolsScopePlugin.js";
18
18
  export { SkillsScopePlugin } from "./scope/plugins/skills/SkillsScopePlugin.js";
19
19
  export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
20
20
  export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
21
+ export { PeerSessionsScopePlugin } from "./scope/plugins/peers/PeerSessionsScopePlugin.js";
22
+ export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL, SEND_TO_SESSION_TOOL, } from "./scope/plugins/peers/peerSessionTools.js";
23
+ export type { PeerSessionPort, PeerSessionCreated, PeerSessionStatus, PeerSessionState, PeerSessionRejectReason, PeerSessionCreateInput, PeerSessionSent, PeerSessionSendInput, PeerSessionSendState, } from "./scope/plugins/peers/peerSessionTools.js";
21
24
  export { allInOne } from "./scope/plugins/allInOne.js";
22
25
  export type { AllInOneOptions } from "./scope/plugins/allInOne.js";
23
26
  export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
@@ -33,7 +36,7 @@ export type { AgentModel } from "./runtime/createModel.js";
33
36
  export { completeOnce } from "./runtime/completeOnce.js";
34
37
  export type { CompleteOnceInput } from "./runtime/completeOnce.js";
35
38
  export { SdkAgent } from "./runtime/SdkAgent.js";
36
- export type { AgentPlugin, SendContext } from "./runtime/SdkAgent.js";
39
+ export type { AgentPlugin, InnerLoopContext, OuterLoopContext, SubAgentHookContext, ToolHookContext, } from "./runtime/SdkAgent.js";
37
40
  export { createAgent } from "./runtime/createAgent.js";
38
41
  export type { CreateAgentOptions } from "./runtime/createAgent.js";
39
42
  export { resolveModel, resolveModelParams } from "./runtime/resolveModel.js";
package/dist/index.js CHANGED
@@ -14,6 +14,9 @@ export { UserToolsScopePlugin } from "./scope/plugins/usertools/UserToolsScopePl
14
14
  export { SkillsScopePlugin } from "./scope/plugins/skills/SkillsScopePlugin.js";
15
15
  export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
16
16
  export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
17
+ // 平级会话:能力来自宿主注入的端口,不给端口就不产出任何工具
18
+ export { PeerSessionsScopePlugin } from "./scope/plugins/peers/PeerSessionsScopePlugin.js";
19
+ export { PEER_SESSION_TOOL_NAMES, CREATE_SESSION_TOOL, READ_SESSION_STATUS_TOOL, SEND_TO_SESSION_TOOL, } from "./scope/plugins/peers/peerSessionTools.js";
17
20
  export { allInOne } from "./scope/plugins/allInOne.js";
18
21
  // 配置 — ConfigManager
19
22
  export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";