@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
package/CHANGELOG.md CHANGED
@@ -1,22 +1,79 @@
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.
1
+ ## [2.0.0-alpha.1] - 2026-11-23
2
+
3
+ > Follows `@ai-zen/agents-core` `5.0.0-alpha.2`, and it is a major bump for the same reason the
4
+ > kernel's was one: this package used to be business logic sitting on `send()`. A handoff awaited
5
+ > the round it had started, a sub-agent awaited the agent it had built, auto-migration reacted to
6
+ > "this round ended". None of that survives — a resident session has no "deliver and wait" any
7
+ > more, because any other party can push it from idle to busy — so the same behaviour had to be
8
+ > rebuilt on facts instead of promises.
9
+ >
10
+ > Rebuilding it is what split the package in two. The **capability face** is what `1.1.0` already
11
+ > was: `Scope` with its five capability sources behind `allInOne()`, `PermissionEvaluator`, the
12
+ > configuration and definition repositories, model resolution, `createAgent` / `SdkAgent`, handoff.
13
+ > The **runtime** is what the package never had: the thing that keeps those agents alive and lets
14
+ > them talk to each other. The line between the two halves is the line the package is now measured
15
+ > by — the runtime is the only place that knows who is alive, who knows whom, and when to build and
16
+ > when to tear down, and it still imports no host.
17
+
18
+ ### Added
19
+
20
+ - **`AgentRuntime`** — one resident agent per session, with `wake(sessionId, materials)`
21
+ (idempotent; concurrent calls share one assembly), `post({ from, to, content })`,
22
+ `status(sessionId)`, `openPeer({ from, prompt, agentId?, modelId?, label? })`, `kill(sessionId)`,
23
+ `close()`, `observe(listener)` and the snapshots `get` / `sessionOf` / `aliveOn`. It waits for
24
+ nobody: a delivery is what wakes a session, and there is no "one run" object to settle. Its facts
25
+ are a discriminated union — `resident:appeared` / `resident:gone` of its own, `scope:appeared` /
26
+ `scope:refreshed` / `scope:gone` from the container registry, and every kernel event of every
27
+ agent unchanged in name and payload with the `sessionId` added.
28
+ - **`Scopes`** — containers live by directory: one per `cwd`, built on first use, shared by every
29
+ session working there, with `for(cwd)`, `dispose(cwd)`, `refreshAll()` and `disposeAll()`.
30
+ `dispose()` refuses while a session is still alive on that directory instead of cascading,
31
+ because a cascade would silently kill sessions that are in the middle of work. No idle timer, no
32
+ reference counting: "nobody is using it" is not a decidable state.
33
+ - **Four ports** the runtime borrows and never implements: `openScope(cwd, peers)`, `open(input)`
34
+ (write the session, choose the identity, hand back `WakeMaterials`), `nameOf(sessionId)` and
35
+ `log`. A session is an opaque `string` here; a cast that fakes an instance of something in this
36
+ package now means a port is missing.
37
+ - **Peer sessions** — three tools under `scope/plugins/peers/`: `create_session` answers
38
+ `{ sessionId, label }` at once, `read_session_status` answers working / idle, alive, name and an
39
+ excerpt of the last thing said, and `post_message` says only that the message was accepted. They
40
+ implement none of it themselves: `PeerSessionsScopePlugin` takes a `PeerSessionPort` (`create` /
41
+ `status` / `send`) and without a port it produces no tools at all. `RuntimePeerSessions` is that
42
+ port, which is why the three tools also work with no host around. A delegated one-shot agent has
43
+ none of the three: it has no identity to sign a message with and can open nothing that anybody
44
+ would own.
45
+ - **One level deep, structurally** — an agent that was itself opened as a peer is created with
46
+ `canOpenPeers: false`, so `create_session` is not among its tools at all and the model cannot even
47
+ try; `post_message` and `read_session_status` stay, because peers talk both ways. Refusals are
48
+ structured rather than sentences: `gone` / `dead` for a delivery, `depth_exceeded` /
49
+ `model_unresolved` for a creation.
50
+ - **`async_exec` / `async_timeout`** — two tools that return at once and report later. The result
51
+ is delivered back into the same session at low priority, so it never lands inside the batch that
52
+ is currently running, and whatever is still running is reaped when the agent stops. A one-shot
53
+ agent gets neither (`ASYNC_TASK_TOOL_NAMES` is stripped when the tools are chosen): its call
54
+ stack has returned by the time the result arrives.
55
+ - **MCP tasks** — `call_mcp_tool` hands back the task id at once and the server pushes status
56
+ notifications; a terminal status goes to `McpTaskNoticePort` (`sessionOf` / `deliver`), which the
57
+ caller implements, while `isTerminalTaskStatus` is the single test for "this task is over". The
58
+ result itself is fetched by task id with `get_mcp_task_result`; `cancel_mcp_task` cancels it.
59
+ - **`completeOnce`** — one non-streaming call with no tools and no history, the request shape both
60
+ the handoff summary and auto-naming need. **`lastPromptTokens`** is the read behind the context
61
+ guard: the last assistant message that carries usage, never a second copy of the count.
6
62
 
7
63
  ### Changed
8
64
 
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`.
65
+ - Every plugin was re-seated on the seams the new kernel offers, and each had to justify the seam
66
+ it picked. `ContextGuardPlugin` refuses by **returning a string** from `onInnerLoopStart` instead
67
+ of throwing: throwing tears the whole loop down, while refusing leaves no placeholder behind and
68
+ reports `denied`. `AutoMigratePlugin` moved to `onIdle`, because migration means "nothing is
69
+ moving any more", not "this round ended".
70
+ - `HandoffService` judges a handoff round by one fact — whether the write to that path happened
71
+ inside that batch — instead of waiting for the agent to go idle, and there is no timer either: a
72
+ model that replies "done" without calling the tool is answered by the batch closing. Cancellation
73
+ surfaces as `HandoffAbortedError` and is never retried with the other writer.
74
+ - Sub-agents are built with `lifetime: "one-shot"`, and every `role: user` message injected from a
75
+ template carries a `source` naming the injecting tool, so a delegated task's history is never
76
+ mistaken for something the user said.
20
77
 
21
78
  ## [1.1.0] - 2026-11-09
22
79