@herbertgao/pi-extensions 2026.11.17 → 2026.11.19

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 (159) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +2 -23
  4. package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
  5. package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
  6. package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
  7. package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
  8. package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
  9. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
  10. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
  11. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
  12. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
  13. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
  14. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
  15. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
  16. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
  17. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
  18. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
  19. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
  20. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
  21. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
  22. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
  23. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
  24. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
  25. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
  26. package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
  27. package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
  28. package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
  29. package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
  30. package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
  31. package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
  32. package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
  33. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
  34. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
  35. package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
  36. package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
  37. package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
  38. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
  39. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
  40. package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
  41. package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
  42. package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
  43. package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
  44. package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
  45. package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
  46. package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
  47. package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
  48. package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
  49. package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
  50. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
  51. package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
  52. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
  53. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
  54. package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
  55. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
  56. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
  57. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
  58. package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
  59. package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
  60. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
  61. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
  62. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
  63. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +7 -0
  64. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/agent-badge.ts +244 -0
  65. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +1 -1
  66. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -3
  67. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +18 -0
  68. package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
  69. package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +18 -0
  70. package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
  71. package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +80 -0
  72. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +320 -102
  73. package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
  74. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -30
  75. package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
  76. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
  77. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  78. package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
  79. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
  80. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
  81. package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +27 -13
  82. package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
  83. package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
  84. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +217 -41
  85. package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
  86. package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
  87. package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -93
  88. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
  89. package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
  90. package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
  91. package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
  92. package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
  93. package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
  94. package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
  95. package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
  96. package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
  97. package/node_modules/pi-commandcode-provider/README.md +3 -2
  98. package/node_modules/pi-commandcode-provider/index.ts +120 -13
  99. package/node_modules/pi-commandcode-provider/package.json +4 -3
  100. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
  101. package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
  102. package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
  103. package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
  104. package/package.json +12 -15
  105. package/node_modules/pi-antigravity/README.md +0 -298
  106. package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
  107. package/node_modules/pi-antigravity/package.json +0 -87
  108. package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
  109. package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
  110. package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
  111. package/node_modules/pi-antigravity/src/client/client.ts +0 -602
  112. package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
  113. package/node_modules/pi-antigravity/src/client/index.ts +0 -2
  114. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
  115. package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
  116. package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
  117. package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
  118. package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
  119. package/node_modules/pi-antigravity/src/image/image.ts +0 -427
  120. package/node_modules/pi-antigravity/src/image/index.ts +0 -1
  121. package/node_modules/pi-antigravity/src/image/native.ts +0 -69
  122. package/node_modules/pi-antigravity/src/index.ts +0 -547
  123. package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
  124. package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
  125. package/node_modules/pi-antigravity/src/models/index.ts +0 -3
  126. package/node_modules/pi-antigravity/src/models/models.ts +0 -647
  127. package/node_modules/pi-antigravity/src/search/index.ts +0 -1
  128. package/node_modules/pi-antigravity/src/search/search.ts +0 -967
  129. package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
  130. package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
  131. package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
  132. package/node_modules/pi-antigravity/src/types/index.ts +0 -2
  133. package/node_modules/pi-antigravity/src/types/types.ts +0 -329
  134. package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
  135. package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
  136. package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
  137. package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
  138. package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
  139. package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
  140. package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
  141. package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
  142. package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
  143. package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
  144. package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
  145. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
  146. package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
  147. package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
  148. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
  149. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
  150. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
  151. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
  152. package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
  153. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
  154. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
  155. package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
  156. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
  157. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
  158. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
  159. package/node_modules/pi-antigravity/tsconfig.json +0 -21
@@ -1,6 +1,6 @@
1
1
  # Security Policy
2
2
 
3
- This document explains the security model behind `@herbertgao/pi-subagents` and
3
+ This document explains the security model behind `@tintinweb/pi-subagents` and
4
4
  where the boundaries are.
5
5
 
6
6
  `pi-subagents` is a [pi](https://pi.dev) extension. It spawns and orchestrates
@@ -31,7 +31,7 @@ coding agent and its sub-agents trivially, and this cannot be protected against.
31
31
 
32
32
  If you believe you found a security vulnerability in `pi-subagents`, please
33
33
  report it privately by opening a draft advisory through
34
- [GitHub Security Advisories](https://github.com/HerbertGao/pi-extensions/security/advisories/new)
34
+ [GitHub Security Advisories](https://github.com/tintinweb/pi-subagents/security/advisories/new)
35
35
  for this repository.
36
36
 
37
37
  Please include:
@@ -1,11 +1,35 @@
1
1
  # Driving subagents from another extension
2
2
 
3
- Another pi extension can spawn a subagent, listen for subagent completion, read the result, steer and stop the run — all over the `pi.events` bus, without importing this package directly. Seven request/reply channels (`subagents:rpc:ping`, `subagents:rpc:spawn`, `subagents:rpc:stop`, `subagents:rpc:consume`, `subagents:rpc:steer`, `subagents:rpc:register-agents`, `subagents:rpc:unregister-agents`), the lifecycle events in README's [event table](../README.md#events), one per-message usage event (`subagents:usage`), one terminal `subagents:disposed`, and one in-process registry at `Symbol.for("pi-subagents:manager")`.
3
+ Another pi extension can spawn a subagent, listen for subagent completion, read the result, steer and stop the run — all over the `pi.events` bus, without importing this package directly. Twelve request/reply channels on this fork: `subagents:rpc:ping`, `subagents:rpc:spawn`, `subagents:rpc:stop`, `subagents:rpc:consume`, `subagents:rpc:steer`, `subagents:rpc:get`, `subagents:rpc:list`, `subagents:rpc:workflow_get`, `subagents:rpc:workflow_list`, plus the HerbertGao-only type-registry channels `subagents:rpc:register-agents`, `subagents:rpc:unregister-agents`, and `subagents:rpc:list-agents` (not the running-agent `list` channel). Registry mutations also broadcast `subagents:agents-changed`. The lifecycle events in README's [event table](../README.md#events), two workflow-run events (`subagents:workflow_started`, `subagents:workflow_settled`), one per-message usage event (`subagents:usage`), one terminal `subagents:disposed`, and one in-process registry at `Symbol.for("pi-subagents:manager")` complete the bus surface.
4
4
 
5
5
  The thing worth understanding up front is that **the bus is in-process.** Every "RPC" call here is a synchronous `pi.events.emit` into the same event loop, and every reply comes back the same way. That single fact explains most of what follows: why `signal` and the `on*` callbacks work on a spawn payload at all, why a `consume` fired inside a `subagents:completed` handler lands _before_ the notification decision has been made, and why none of this survives a real process boundary.
6
6
 
7
7
  For the channel list, the reply envelope, the per-channel snippets and the event table, see [`README.md`](../README.md#cross-extension-rpc). This document is the reference README does not have room for: the complete spawn-option surface, every error string, the notification race, the registry, and what protocol version `2` does and does not promise.
8
8
 
9
+ ## The surface at a glance
10
+
11
+ Everything goes through `pi.events`. The lifecycle events push one agent shape, `SubagentInfo` (`toSubagentInfo` in `src/subagent-info.ts`). `get` and `list` return the same shape on request. `spawn`, `steer`, `consume` and `stop` act on an agent. A `SubagentWorkflow` run gets two lifecycle events of its own, carrying `WorkflowInfo` (`toWorkflowInfo` in `src/workflow-info.ts`); its live per-agent detail is pulled through `workflow_get`/`workflow_list`, never pushed. Every request gets its answer on its own `:reply:<requestId>` channel.
12
+
13
+ ```mermaid
14
+ flowchart LR
15
+ subgraph you["Your extension"]
16
+ L["listener"]
17
+ C["caller"]
18
+ end
19
+ subgraph ext["pi-subagents"]
20
+ R["cross-extension-rpc.ts<br/>handlers"]
21
+ M["AgentManager<br/>top-level, nested, workflow records"]
22
+ I["toSubagentInfo()"]
23
+ end
24
+ C -- "subagents:rpc:ping / spawn / steer / consume / stop / get / list /<br/>workflow_get / workflow_list" --> R
25
+ R -- "subagents:rpc:CHANNEL:reply:REQUESTID<br/>{ success, data? } or { success: false, error }<br/>ping: { version: 2, features }" --> C
26
+ R --> M
27
+ M --> I
28
+ I -- "subagents:created / started / completed /<br/>failed / steered / compacted" --> L
29
+ M -- "subagents:usage (per message)" --> L
30
+ M -- "subagents:workflow_started / workflow_settled" --> L
31
+ ```
32
+
9
33
  ## Spawn options
10
34
 
11
35
  `subagents:rpc:spawn` forwards `options` to `AgentManager.spawn` — but not verbatim. The manager's `spawn` behind the RPC is `spawnTopLevel` in `src/index.ts`, which deletes internal-only fields first, and then `spawnResolved` overwrites the activity-tracker callbacks with its own. The full interface is `SpawnOptions` in `src/agent-manager.ts`; what a bus caller actually gets is three different things.
@@ -86,7 +110,8 @@ Every failure reaches the caller as `{ success: false, error }`, where `error` i
86
110
  | ``Cannot run with isolation: "worktree" — not a git repo, no commits yet, or `git worktree add` failed. Initialize git and commit at least once, or omit `isolation`.`` | `AgentManager.startAgent`, surfaced through `awaitStartup`. Every git failure ends here: `createWorktree` (`src/worktree.ts`) catches git's own error and returns nothing |
87
111
  | `Agent not found` | stop handler, `src/cross-extension-rpc.ts` |
88
112
  | `Agent is owned by another agent or workflow` | stop handler |
89
- | `Agent is not running` | stop handler. The record exists, so it has already settled |
113
+ | `settleTimeoutMs must be a number of milliseconds` | stop handler — `settleTimeoutMs` is set but is not a finite number. Checked before the abort, so nothing is stopped |
114
+ | `Agent is not running` | stop handler. The agent exists, has finished, and nothing below it is still running |
90
115
  | `Agent not found or still running` | consume handler |
91
116
  | `Steer message must be a non-empty string` | steer handler — `message` missing, not a string, or whitespace |
92
117
  | `Agent not found` / `Agent is owned by another agent or workflow` / `Agent is not running` | steer handler — same lookup, ownership guard and settled check as stop |
@@ -94,22 +119,79 @@ Every failure reaches the caller as `{ success: false, error }`, where `error` i
94
119
  Three things the table cannot show:
95
120
 
96
121
  - **The failure that is not an error.** With `worktreeIsolation` off project-wide, `isolation: "worktree"` is dropped by the `isWorktreeIsolationEnabled()` check in `AgentManager.startAgent` with no error, no note on the record, and a success envelope on the wire. Your agent runs in the main tree. If you asked for isolation because two agents were going to write the same files, they now collide and nothing told you.
97
- - **`data` is omitted** when a handler returns nothing, so a successful stop or consume reply is a bare `{ success: true }` and `reply.data.anything` throws.
122
+ - **`data` is omitted** when a handler returns nothing, so a successful consume or steer reply is a bare `{ success: true }` and `reply.data.anything` throws. A successful stop replies `{ success: true, data: { settled } }`; see [Stopping](#stopping).
98
123
  - **`requestId` is not validated.** It is interpolated straight into the reply channel, so a caller that omits it gets its reply on the literal channel `subagents:rpc:spawn:reply:undefined` — where every other caller that omitted it is also listening. Send one, and send a unique one.
99
124
 
125
+ ## Stopping
126
+
127
+ `subagents:rpc:stop` aborts the agent, then waits to reply until the agent and every agent below it have finished (`waitForSettled` in `src/agent-manager.ts`, #443). `abort()` sets the status to `stopped` immediately, but a tool call that ignores the abort, such as a file write or a shell command, keeps running until it returns. Without the wait, that write could land on top of replacement work the caller started after the reply.
128
+
129
+ - **Time limit.** `settleTimeoutMs` on the request caps the wait. It is optional, clamped to `0`..`60000`, and defaults to `STOP_SETTLE_TIMEOUT_MS` (5 s, `src/cross-extension-rpc.ts`). The default stays under the 10 s pi-tasks allows for the stop reply. `0` replies immediately with the current state.
130
+ - **`settled: false`** means the time ran out and something may still be running. Agents started while the tree shuts down are waited for too.
131
+ - **Sending stop again.** After `settled: false`, `get` shows the agent with `settling: true` (see [Reading agent state](#reading-agent-state)). A second stop finds nothing to abort but something still running, so it goes straight to the wait and replies `{ settled }`. `Agent is not running` means everything has finished.
132
+ - **How it tracks runs.** `AgentManager` keeps a set of runs that have not finished (`trackRun`). `isSettling` and `waitForSettled` both read it.
133
+ - **Events are unchanged.** `subagents:failed` for the stopped agent still fires when its own run ends, so it can arrive before the stop reply.
134
+ - **`reply.success`** means the same as before. `data.settled` is new; a caller that ignores it just gets the reply later.
135
+
136
+ ```mermaid
137
+ sequenceDiagram
138
+ participant C as Caller
139
+ participant M as AgentManager
140
+ participant A as Stopped agent
141
+ participant N as Its nested agent
142
+ C->>M: subagents:rpc:stop { agentId, settleTimeoutMs? }
143
+ M->>A: abort() sets stopped
144
+ M->>M: waitForSettled(agentId, settleTimeoutMs) starts
145
+ Note over N: in a tool call that ignores the abort
146
+ A-->>M: run ends, abortOwnedChildren aborts N
147
+ M-->>C: subagents:failed for A (same timing as before)
148
+ alt N finishes in time
149
+ N-->>M: tool call returns, run ends
150
+ M-->>C: reply { success: true, data: { settled: true } }
151
+ else time runs out first
152
+ M-->>C: reply { success: true, data: { settled: false } }
153
+ Note over C: get shows settling: true
154
+ C->>M: subagents:rpc:stop { agentId } again
155
+ M->>M: nothing left to abort, still running: wait again
156
+ N-->>M: tool call returns, run ends
157
+ M-->>C: reply { success: true, data: { settled: true } }
158
+ end
159
+ Note over C: start replacement work here, not on subagents:failed
160
+ ```
161
+
100
162
  ## Ownership
101
163
 
102
- `isTopLevelAgent(record)` is `parentAgentId === undefined && workflowId === undefined` (`src/agent-manager.ts`). `subagents:rpc:stop` and `subagents:rpc:steer` enforce it through one shared check (`assertOwned` in `src/cross-extension-rpc.ts`): a nested child or a workflow's agent is owned by something that is _waiting on it_, and aborting or redirecting it out from under that owner turns another extension's request into a failed step. It is defence in depth rather than a live hole — no RPC hands out agent ids, so a caller has no ordinary way to name one it does not own.
164
+ `isTopLevelAgent(record)` is `parentAgentId === undefined && workflowId === undefined` (`src/agent-manager.ts`). `subagents:rpc:stop` and `subagents:rpc:steer` enforce it through one shared check (`assertOwned` in `src/cross-extension-rpc.ts`): a nested or workflow agent belongs to an agent or workflow that is _waiting on it_, and stopping or redirecting it behind that owner's back makes the owner's step fail. The check matters in practice: the lifecycle events and `subagents:rpc:list` expose every agent's id, nested and workflow ones included, so a caller can name an agent it does not own. Reads (`get`, `list`) have no check.
103
165
 
104
166
  Two asymmetries to know about, stated as they are:
105
167
 
106
168
  - **Stop takes an id only**: its `getRecord` is the manager's plain lookup. Consume takes an id _or_ an `@handle`: its `consumeResult` (both wired in the `session_start` handler, `src/index.ts`) goes through `resolveAgentRef`.
107
169
  - **Consume checks `parentAgentId` but not `workflowId`** (`consumeResult`, `src/index.ts`). A workflow-owned agent's result can be marked consumed over the bus even though the same agent cannot be stopped.
108
170
 
109
- The same predicate silently scopes the events. **Every lifecycle event is top-level only** — `subagents:started`, `:completed`, `:failed`, `:steered` and `:compacted` all return early for nested and workflow-owned agents (the `isTopLevelAgent` checks in the `AgentManager` callbacks, `src/index.ts`). `subagents:usage` is the one event that is not scoped: it fires for every agent's messages, nested and workflow-owned included, so a ledger sees a workflow's children spend even though it never sees them start or finish.
171
+ The lifecycle events do **not** use this check. `subagents:created`, `:started`, `:completed`, `:failed`, `:steered` and `:compacted` fire for nested and workflow agents too, with `parentAgentId` or `workflowId` set (#442). To see only the session's own agents, ignore events where either is set; up to 0.24 the events carried only those. After the event fires, the `isTopLevelAgent` checks in the `AgentManager` callbacks (`src/index.ts`) still keep nested and workflow agents out of completion messages, the saved `subagents:record` and the widget. A nested or workflow agent sends `subagents:created` when it starts (it is never queued), and again on each resume.
172
+
173
+ What reaches which kind of agent:
174
+
175
+ ```mermaid
176
+ flowchart TB
177
+ subgraph top["Top-level agent: isTopLevelAgent true"]
178
+ T1["lifecycle events"]
179
+ T2["get / list"]
180
+ T3["stop / steer / consume"]
181
+ T4["completion notification, subagents:record entry, widget"]
182
+ end
183
+ subgraph owned["Owned agent: parentAgentId or workflowId set"]
184
+ O1["lifecycle events, with owner fields"]
185
+ O2["get / list, with owner fields"]
186
+ O3["stop / steer: refused by assertOwned"]
187
+ O4["no notification, no subagents:record, no widget row"]
188
+ end
189
+ ```
110
190
 
111
191
  **`subagents:disposed` is the last event of a session.** It is emitted at the end of this extension's `session_shutdown`, after every agent is stopped and every child session has shut down, so no `subagents:usage` can follow it. A listener gets only its synchronous prefix on quit: `pi.events.emit` does not await listeners, and pi calls `process.exit` once the shutdown handlers return. Flush with `writeFileSync`, not `fs.promises`. Fields, and the other events, are in README's [event table](../README.md#events).
112
192
 
193
+ **Read a finished agent's report from the final event.** `subagents:completed` and `subagents:failed` carry the shared [agent fields](../README.md#agent-fields). A caller that spawned with `options.structuredOutput` reads the validated report from `structuredJson` and the session file path from `sessionFile`, without the registry. Both are left out when there is no value: `structuredJson` when no schema was passed or no valid report was produced, `sessionFile` when the session was not saved to disk. `structuredJson` is JSON text; `JSON.parse` it.
194
+
113
195
  ## The notification race
114
196
 
115
197
  When a background agent finishes, pi-subagents sends the user a completion notification. If you have already shown the model that result yourself, that notification arrives on top of an answer that was already given, and it costs the parent a turn to dismiss. `subagents:rpc:consume` is how you say you have handled it — the bus-side half of what `get_subagent_result` does when it returns a result.
@@ -120,6 +202,23 @@ When a background agent finishes, pi-subagents sends the user a completion notif
120
202
  2. Next, in the same synchronous callback, it checks `record.resultConsumed` and decides whether to notify at all.
121
203
  3. `pi.events` dispatch is synchronous and in-process, so a handler that emits `subagents:rpc:consume` **without awaiting anything** has already set that flag before step 2 evaluates.
122
204
 
205
+ ```mermaid
206
+ sequenceDiagram
207
+ participant M as AgentManager
208
+ participant X as pi-subagents completion callback
209
+ participant Y as Your listener
210
+ participant O as Completion outbox
211
+ participant P as Parent session
212
+ M->>X: agent settles
213
+ X->>Y: emit subagents:completed
214
+ Y->>X: emit subagents:rpc:consume (sync, sets resultConsumed)
215
+ X->>X: resultConsumed? then notify nothing
216
+ Note over X,O: otherwise
217
+ X->>O: queue notification
218
+ Y-->>O: consume after an await cancels it here
219
+ O->>P: sent 200 ms later if idle (starts a turn), or at turn_end if busy
220
+ ```
221
+
123
222
  | When you consume | What happens |
124
223
  | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
125
224
  | Synchronously, inside your `subagents:completed` handler | The notification is never scheduled. This is the clean path |
@@ -136,38 +235,148 @@ One related thing that lives nowhere else: on every top-level settle, pi-subagen
136
235
 
137
236
  `subagents:rpc:steer` `{ requestId, agentId, message }` delivers `message` into a running or queued agent's conversation, the bus-side half of the `steer_subagent` tool. It exists for the caller that spawned an agent over the bus and then learns something that agent needs mid-run — a second CI failure on the head it is already fixing, a review that landed while it works — and would otherwise have to choose between spawning a duplicate agent for the same work and dropping the fact.
138
237
 
139
- It takes an id only, enforces the same top-level ownership guard as stop, and answers `Agent is not running` for a record that has settled. A message queued before the agent's session exists is flushed when the session is created, exactly as the tool's steer is. A successful steer emits `subagents:steered` `{ id, message }`, as every steer path does. Like `consume`, it is outside the `ping` version handshake: an older build has no handler and the request times out on your side, so give it a timeout and treat expiry as "not available here".
140
-
141
- ## Registering session-scoped agent types
142
-
143
- `subagents:rpc:register-agents` `{ requestId, agents: [{ name, description, systemPrompt, color? }], tools?: "none" | "builtin" }` registers ephemeral agent types — spawnable immediately as `subagent_type`, surviving every agent-file reload, and cleared on the next `session_start`. The payload is deliberately narrow: the system prompt is applied in replace mode, extension and skill access is refused, and the only tool choice is none or the built-ins. A file-loaded agent with the same name (case-insensitively) wins — the overlay never shadows the user's own agents. `subagents:rpc:unregister-agents` `{ requestId, names }` removes types by name; file-backed types are untouched.
144
-
145
- Like `consume` and `steer`, both channels are outside the `ping` version handshake: an older build has no handler and never replies, so give the call a timeout and treat expiry as "not available here". The intended caller is `@herbertgao/pi-agency`, which seats an Agency Agents catalog persona this way — the persona body as system prompt, the card name as the agent's label, the card color as its badge.
238
+ It takes an id only, enforces the same top-level ownership guard as stop, and answers `Agent is not running` for a record that has settled. A message queued before the agent's session exists is flushed when the session is created, exactly as the tool's steer is. A successful steer emits `subagents:steered` with the agent fields plus `message`, as every steer path does. An older build has no handler and the request times out on your side: check `features.includes("steer")` on the `ping` reply first, or give it a timeout and treat expiry as "not available here".
239
+
240
+ ## Reading agent state
241
+
242
+ `subagents:rpc:get` `{ requestId, agentId }` replies `{ agent }`. `subagents:rpc:list` `{ requestId }` replies `{ agents }`. Both return the [agent fields](../README.md#agent-fields) the lifecycle events carry, built by the same `toSubagentInfo` (`src/subagent-info.ts`). Use them when your extension loaded after the events it needed had already fired. Detect them with `features.includes("get")` / `"list"` on the `ping` reply.
243
+
244
+ `list` returns every agent the manager holds, in any status, nested and workflow agents included. Filter on `status`, `parentAgentId` and `workflowId` yourself.
245
+
246
+ A record stays readable until the manager removes it: 10 minutes after the agent finishes (`cleanup` in `src/agent-manager.ts`), or sooner, at a session start or switch, if its result was consumed (`clearCompleted(true)` keeps records whose result was not read). After that, `get` returns `Agent not found`, and only a top-level agent's saved `subagents:record` session entry remains.
247
+
248
+ Both add two fields the events do not have. Both are computed when you ask, not stored on the record.
249
+
250
+ **`settling: true`**: the agent's status is final, but something below it is still running. For example, a stopped agent whose tool call ignored the abort, or a nested agent still shutting down after its parent finished (`isSettling` in `src/agent-manager.ts`). A `{ settled: false }` stop reply leaves the agent in this state. It clears once the last run ends. A running or queued agent never has it, since its `status` already says so.
251
+
252
+ ```mermaid
253
+ stateDiagram-v2
254
+ [*] --> Running
255
+ Running --> Settling: finishes or is stopped, something below still runs
256
+ Running --> Idle: finishes, nothing below still runs
257
+ Settling --> Idle: the last run below ends
258
+ Idle --> [*]
259
+ note right of Settling
260
+ settling is true only here.
261
+ Sending stop again waits again.
262
+ end note
263
+ ```
264
+
265
+ **`notificationPending: true`**: a finished top-level agent's completion message has not reached the parent yet (`isNotificationPending` in the `session_start` RPC wiring, `src/index.ts`). The message waits in one of three places:
266
+
267
+ - the completion outbox: 200 ms if the parent is idle, until `turn_end` if it is busy, and through an Esc
268
+ - a `group` waiting for the agent's siblings, up to 30 s
269
+ - a `group` spawn whose turn has not ended yet
270
+
271
+ When the message is sent, it starts a parent turn. So while it waits, `hasRunning()` is false and every `status` reads `completed`, yet a turn is still coming. That is the race in [#103](https://github.com/tintinweb/pi-subagents/issues/103). The field is never set once the result has been read (a read result gets no message), or on nested and workflow agents.
272
+
273
+ ```mermaid
274
+ stateDiagram-v2
275
+ [*] --> Running
276
+ Running --> Waiting: finishes with isBackground true, result not yet read
277
+ Running --> Done: finishes without isBackground (foreground, or an RPC spawn that left it unset), or is nested
278
+ Waiting --> Delivered: completion message sent to the parent
279
+ Waiting --> Read: consume, or get_subagent_result
280
+ Delivered --> [*]
281
+ Read --> [*]
282
+ Done --> [*]
283
+ note right of Waiting
284
+ notificationPending is true only here.
285
+ outbox.has, groupJoin.isHolding, or turnGroupSpawns.
286
+ end note
287
+ ```
288
+
289
+ The two fields are independent: a stopped background agent can have both set at once. An agent is idle when its `status` is final and neither field is set. The check to run before injecting your own prompt, with `agents` from a `list` reply:
290
+
291
+ ```typescript
292
+ const active = agents.some(
293
+ (a) =>
294
+ a.parentAgentId === undefined &&
295
+ a.workflowId === undefined &&
296
+ (a.status === "running" ||
297
+ a.status === "queued" ||
298
+ a.settling ||
299
+ a.notificationPending),
300
+ )
301
+ ```
302
+
303
+ ## Observing workflow runs
304
+
305
+ A `SubagentWorkflow` run is not an agent, so it has its own two events and two channels, carrying `WorkflowInfo` (`toWorkflowInfo`, `src/workflow-info.ts`), not `SubagentInfo`.
306
+
307
+ `subagents:workflow_started` fires once, before the first agent; `subagents:workflow_settled` fires once, when the run completes, fails or is stopped (`status` is `completed`, `failed` or `killed`, with `error`/`failures` on failure). Both carry the run summary — `id` (`wf_…`), `name`, `status`, `startedAt`/`completedAt`, `durationMs`, `agentCount`, `doneCount`, `failedCount`, `totalTokens`, `totalToolCalls`, `phaseLabel`, and `description`/`toolCallId` when present. The run's child agents are separate: they ride the ordinary agent-lifecycle events with `workflowId` set.
308
+
309
+ `subagents:workflow_settled` also carries `result`: the script's return value as returned (object, array or primitive), with no truncation and no `JSON.parse` needed. It is left out when the run failed, was stopped, or returned nothing. It is a copy, so mutating it never affects the run or its notification; listeners of one event share the same payload. `workflow_get` returns it too, for a listener that bound late; `workflow_started` and the `workflow_list` summaries never carry it.
310
+
311
+ `subagents:workflow_started` carries `args` the same way, at the other end of the run: what the call passed as the script's global `args`, so two runs of one saved workflow can be told apart. It is left out when the call passed none (always, for `--subagents-workflow-file`). It is a copy, `workflow_get` returns it too, and `workflow_settled` and `workflow_list` never carry it.
312
+
313
+ ```typescript
314
+ pi.events.on("subagents:workflow_settled", (run) => {
315
+ if (run.status === "completed" && run.result !== undefined) render(run.result)
316
+ })
317
+ ```
318
+
319
+ There is deliberately **no** `workflow_progress` push. A run's `onProgress` fires on every finished tool call and every assistant message for every running agent — far too hot for the bus. Pull the live detail instead, at whatever cadence you render:
320
+
321
+ ```typescript
322
+ pi.events.emit("subagents:rpc:workflow_get", {
323
+ requestId,
324
+ workflowId: "wf_...",
325
+ })
326
+ // reply data: { workflow: WorkflowDetail } — the summary, plus:
327
+ // version: number bumped once per applied progress batch; dedupe on it
328
+ // agents: WorkflowAgentInfo[] per-agent snapshot, collapsed to latest-by-index:
329
+ // index, label, state, phaseIndex?, phaseTitle?, agentType?, model?, thinking?,
330
+ // tokens?, toolCalls?, durationMs?, error?, skipped?, resultPreview?, recordId?
331
+ // logs: string[] the script's log() lines in order, as the TUI shows them; [] when none
332
+ // args?: unknown the call's args, when it passed any
333
+ // result?: unknown the script's return value, once the run completed with one
334
+
335
+ pi.events.emit("subagents:rpc:workflow_list", { requestId })
336
+ // reply data: { workflows: WorkflowInfo[] } — summaries only, no agents[] or result
337
+ ```
338
+
339
+ `workflow_get` on an unknown id replies `{ success: false, error: "Workflow not found" }`. Both are reads with no ownership check — a run is top-level. `WorkflowAgentInfo` is a fixed public subset of the internal entry: the churn-prone fields the dialog uses (`lastProgressAt`, `promptPreview`, `attempt`, …) and the runtime's internal `wf-agent-N` handle are not exposed, and `model` is the effective model once the child's session reports one. Its `recordId` is the join back to that child's own agent-lifecycle events (their `id`), so an observer can pair the per-agent snapshot with the live `subagents:usage` / `completed` stream. Detect the surface with `features.includes("workflow-events")` / `"workflow-get"` / `"workflow-list"` / `"workflow-result"` / `"workflow-args"` / `"workflow-logs"` on the `ping` reply. A new log line bumps `version`, so a poller can skip a reply whose `version` it has already rendered. A settled run stays in `list` and `get` for the rest of the session — runs are evicted only at session shutdown, unlike agent records, which are swept about ten minutes after they finish.
146
340
 
147
341
  ## The manager registry
148
342
 
149
343
  `globalThis[Symbol.for("pi-subagents:manager")]` (`MANAGER_KEY` and `registryEntry`, `src/index.ts`) is a second integration surface — the standard Node cross-package singleton pattern, no bus involved:
150
344
 
151
- | Member | Signature | Notes |
152
- | --------------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------- |
153
- | `waitForAll()` | `() => Promise<void>` | Resolves when nothing is running. **All** agents, including ones you did not spawn — a shutdown barrier, not a join |
154
- | `hasRunning()` | `() => boolean` | |
155
- | `spawn(pi, ctx, type, prompt, options)` | `=> string` | **Is** `spawnTopLevel`, so the strip list above applies identically |
156
- | `getRecord(id)` | `=> AgentRecord \| undefined` | Filtered through `isTopLevelAgent`, so someone else's child comes back `undefined` rather than leaking |
345
+ | Member | Signature | Notes |
346
+ | --------------------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
347
+ | `waitForAll()` | `() => Promise<void>` | Resolves when nothing is running. **All** agents, including ones you did not spawn — a shutdown barrier, not a join |
348
+ | `hasRunning()` | `() => boolean` | |
349
+ | `spawn(pi, ctx, type, prompt, options)` | `=> string` | **Is** `spawnTopLevel`, so the strip list above applies identically |
350
+ | `getRecord(id)` | `=> AgentRecord \| undefined` | Filtered through `isTopLevelAgent`: someone else's child comes back `undefined`. The record is live and mutable (abort controller, session), so handing out an owned one would bypass the ownership guard `subagents:rpc:stop` enforces. `subagents:rpc:get` returns owned agents because it returns a copy |
157
351
 
158
352
  The slot is claimed by the first activation only; subagent sessions re-activate this extension in the same process, and unconditionally overwriting would point the registry at a short-lived child manager whose shutdown would then delete the root session's entry ([#128](https://github.com/tintinweb/pi-subagents/pull/128)). Child activations leave it alone, and shutdown releases it only if this activation claimed it (`ownsManagerRegistry`, checked in the `session_shutdown` handler).
159
353
 
160
- Prefer the bus. The registry has no reply envelope, no version, and no availability event — `globalThis[Symbol.for("pi-subagents:manager")] === undefined` is the only probe you get, and it is also `undefined` in a session that filtered pi-subagents out. Reach for it for the two things the bus has no verb for — _is anything still running_, and _give me a settled record back_ — or for a headless host that wants to block on `waitForAll()` before exiting.
354
+ Prefer the bus. The registry has no reply envelope, no version, and no availability event — `globalThis[Symbol.for("pi-subagents:manager")] === undefined` is the only probe you get, and it is also `undefined` in a session that filtered pi-subagents out. `subagents:rpc:list` answers _what is still running_, including a finished agent whose notification is still on its way (`notificationPending`) or whose tree is still unwinding (`settling`), and `subagents:rpc:get` hands a record back after its terminal event has passed, both with the public agent fields rather than the live `AgentRecord`. Reach for the registry only for a headless host that wants to block on `waitForAll()` before exiting.
161
355
 
162
356
  ## Protocol versions
163
357
 
164
- `subagents:rpc:ping` replies `{ version: PROTOCOL_VERSION }`, currently `2` (`src/cross-extension-rpc.ts`). The constant was introduced already equal to `2` in 0.5.0; "v1" is a retroactive name for the pre-envelope contract, where spawn replied with a bare `{ id }` or `{ error }`, stop replied `{ success: boolean }` with no message, and each handler caught its own errors.
358
+ `subagents:rpc:ping` replies `{ version: PROTOCOL_VERSION, features: FEATURES }`, with the version currently `2` (`src/cross-extension-rpc.ts`). The constant was introduced already equal to `2` in 0.5.0; "v1" is a retroactive name for the pre-envelope contract, where spawn replied with a bare `{ id }` or `{ error }`, stop replied `{ success: boolean }` with no message, and each handler caught its own errors.
359
+
360
+ Everything added since kept version `2`, because each addition left existing calls working: stop's ownership check, string-`model` resolution ([#59](https://github.com/tintinweb/pi-subagents/pull/59)/[#60](https://github.com/tintinweb/pi-subagents/issues/60)), `scopeModels` enforcement ([#240](https://github.com/tintinweb/pi-subagents/issues/240)), and the channels and fields below. `features` tells you which of these a build has:
165
361
 
166
- Everything added since shipped **without a bump**, because all of it is additive: stop's ownership refusal, string-`model` resolution ([#59](https://github.com/tintinweb/pi-subagents/pull/59)/[#60](https://github.com/tintinweb/pi-subagents/issues/60)), `scopeModels` enforcement ([#240](https://github.com/tintinweb/pi-subagents/issues/240)), and the whole `consume` and `steer` channels.
362
+ | Feature | Means |
363
+ | ------------------------------- | ----------------------------------------------------------------------------------------------- |
364
+ | `consume` | `subagents:rpc:consume` exists |
365
+ | `steer` | `subagents:rpc:steer` exists |
366
+ | `get`, `list` | `subagents:rpc:get` and `subagents:rpc:list` exist |
367
+ | `owned-lifecycle` | The lifecycle events fire for nested and workflow agents too |
368
+ | `stop-settles` | The stop reply waits for the work to stop, returns `{ settled }`, and accepts `settleTimeoutMs` |
369
+ | `settling` | `get` / `list` set `settling`, and sending stop again while something still runs waits again |
370
+ | `notification-pending` | `get` / `list` set `notificationPending` |
371
+ | `workflow-events` | `subagents:workflow_started` / `subagents:workflow_settled` fire for `SubagentWorkflow` runs |
372
+ | `workflow-get`, `workflow-list` | `subagents:rpc:workflow_get` and `subagents:rpc:workflow_list` exist |
373
+ | `workflow-result` | `subagents:workflow_settled` and `workflow_get` carry the script's return value as `result` |
374
+ | `workflow-args` | `subagents:workflow_started` and `workflow_get` carry the call's `args` |
375
+ | `workflow-logs` | `workflow_get` returns the script's `log()` lines as `logs` |
167
376
 
168
- > A `ping` that answers `2` does not tell you whether `consume` or `steer` exists, whether model scope is enforced, or whether stop checks ownership.
377
+ Check with `features.includes(...)`. Entries are only ever added, so a feature present today stays present. A reply without `features` comes from an older build. Model scope and stop's ownership check are older than `features` and have no entry.
169
378
 
170
- So: send `consume` unconditionally and ignore the outcome — an older build has no handler and simply keeps notifying, which is exactly why it was left outside the handshake. And treat every error envelope as authoritative rather than trying to predict which checks are in force.
379
+ You can send `consume` without checking: an older build has no handler and just keeps sending the completion message. For everything else, check the feature, and trust any error reply over your own guess.
171
380
 
172
381
  ## Availability
173
382
 
@@ -175,17 +384,18 @@ So: send `consume` unconditionally and ignore the outcome — an older build has
175
384
 
176
385
  The consequence is worth stating plainly: **a session that excludes pi-subagents is indistinguishable from pi-subagents not being installed.** It emits no `subagents:ready` and answers nothing. Give discovery a timeout and treat expiry as "not available here" rather than waiting indefinitely. The payload is `{}` — read nothing off it. Handlers are torn down and `rpcHandle` reset in the `session_shutdown` handler, so a later `session_start` re-registers and re-emits.
177
386
 
178
- One more trap on the way in: an RPC-spawned agent emits **no `subagents:created`**. The only three emit sites, all in `src/index.ts`, are the `Agent` tool's `run_in_background` branch, a detached resume (`startBackgroundResume`), and a foreground `Agent` call handed to the background with ctrl+b or the viewer's `b` (`sendForegroundToBackground`) — that one fires after the agent's `subagents:started`, as resume does. Your first event for your own agent is `subagents:started` (the manager's start callback), so key your bookkeeping off the id that `spawn` handed you, not off `subagents:created`.
387
+ One more trap on the way in: an RPC-spawned agent emits **no top-level `subagents:created`**. The only three emit sites, all in `src/index.ts`, are the `Agent` tool's `run_in_background` branch, a detached resume (`startBackgroundResume`), and a foreground `Agent` call handed to the background with ctrl+b or the viewer's `b` (`sendForegroundToBackground`). All three fire after the agent's `subagents:started`, unless the spawn queued: each emits `created` only after startup, which is where the manager's start callback emits `started`. Owned agents are announced separately, `created` then `started`, when they start. Your first event for your own agent is `subagents:started` (the manager's start callback), so key your bookkeeping off the id that `spawn` handed you, not off `subagents:created`.
179
388
 
180
389
  ## What the tests pin
181
390
 
182
391
  This document has no test of its own, so it is worth knowing which claims are actually held in place:
183
392
 
184
- | Test | Level | Pins |
185
- | ------------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
186
- | `test/cross-extension-rpc.test.ts` | Mocked `SpawnCapable` | Envelope shape, per-channel error strings (including steer's), model resolution and scope enforcement |
187
- | `test/rpc-lifecycle-gating.test.ts` | Real extension factory | Nothing wired at factory time, everything once at `session_start`, and live widget activity for RPC spawns ([#142](https://github.com/tintinweb/pi-subagents/issues/142)/[#181](https://github.com/tintinweb/pi-subagents/pull/181)) |
188
- | `test/rpc-result-consumption.test.ts` | Real delivery path | The notification firing, and not firing, around `consume` |
393
+ | Test | Level | Pins |
394
+ | ------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
395
+ | `test/cross-extension-rpc.test.ts` | Mocked `SpawnCapable` / `WorkflowReader` | Envelope shape, per-channel error strings (including steer's and `workflow_get`'s), the `features` list, `workflow_get`/`workflow_list` replies, model resolution and scope enforcement |
396
+ | `test/workflow-info.test.ts` | Pure builder | The `WorkflowInfo` / `WorkflowDetail` field sets, omit-not-`undefined`, the `WorkflowAgentInfo` whitelist |
397
+ | `test/rpc-lifecycle-gating.test.ts` | Real extension factory | Nothing wired at factory time, everything once at `session_start`, and live widget activity for RPC spawns ([#142](https://github.com/tintinweb/pi-subagents/issues/142)/[#181](https://github.com/tintinweb/pi-subagents/pull/181)) |
398
+ | `test/rpc-result-consumption.test.ts` | Real delivery path | The notification firing, and not firing, around `consume` |
189
399
 
190
400
  Not pinned anywhere, so treat them as descriptions rather than contracts: the `SpawnOptions.cwd` error strings, `subagents:ready`'s `{}` payload, consume's handle resolution, and its missing `workflowId` check.
191
401
 
@@ -195,4 +405,4 @@ Not pinned anywhere, so treat them as descriptions rather than contracts: the `S
195
405
 
196
406
  Read it for the shape of the whole loop: waiting on `subagents:ready`, keeping an id-keyed map of outstanding spawns, resolving each from the `subagents:completed` / `subagents:failed` handler, and consuming the result in the same synchronous handler that reports it.
197
407
 
198
- If what you want is many coordinated agents rather than one, hand a script to [`SubagentWorkflow`](workflows.md) instead of fanning out over `subagents:rpc:spawn` — and note that a workflow's agents are not yours: they emit no lifecycle events — only `subagents:usage` — and `subagents:rpc:stop` refuses them.
408
+ If what you want is many coordinated agents rather than one, hand a script to [`SubagentWorkflow`](workflows.md) instead of fanning out over `subagents:rpc:spawn` — and note that a workflow's agents are not yours: you can watch them on the lifecycle events (they carry `workflowId`), but `subagents:rpc:stop` refuses them. The run itself announces `subagents:workflow_started` and `subagents:workflow_settled`, enough to know it is going; pull its live detail with `subagents:rpc:workflow_get` (see [Observing workflow runs](#observing-workflow-runs)).
@@ -0,0 +1,63 @@
1
+ # README translations
2
+
3
+ For maintainers updating `README.zh-CN.md`, `README.ja.md` or `README.ko.md`. The translations are condensed: they mirror only the intro, Features, Install, Quick Start and the `/agents` command, and link to the English `README.md` for everything else.
4
+
5
+ ## When to update
6
+
7
+ A change to a mirrored section of `README.md` updates all three translations in the same change. Each translation ends with `<!-- source: README.md @ <sha> -->`; `git diff <sha> -- README.md` shows what changed since it was last synced. Bump the sha after syncing.
8
+
9
+ Mirrored sections: the header (tagline, install line), the intro paragraph, `## Features`, `## Install` (with `### Other hosts`), `## Quick Start` (with its two subsections), and the `/agents` row of `## Commands`.
10
+
11
+ Every translation must also keep the pointers to the full English README, so neither a reader nor an agent mistakes the subset for the whole:
12
+
13
+ - `<!-- full-readme: README.md · <absolute URL> -->` directly under the `#` title.
14
+ - A blockquote right under the language switcher: one line in the target language naming what is covered and saying the rest is English-only, then the English line `Partial translation of the English README. Full reference: …`.
15
+ - ` (EN)` on every header nav label that leads to English content.
16
+ - A closing "More details (English)" section that opens with a link to the full README.
17
+ - `Full README (English): [README.md](README.md) · <absolute URL>` as the last visible line.
18
+
19
+ The absolute URL is required alongside the relative link, because the relative link breaks wherever the file is read outside the repo, such as on npm, in raw views or in a fetched copy.
20
+
21
+ ## Never translate
22
+
23
+ - Anything in a code span or code block, including comments inside code blocks.
24
+ - Tool names (`Agent`, `SubagentWorkflow`, `get_subagent_result`, `steer_subagent`), slash commands, menu paths (`/agents → Settings → Widget`), setting keys, frontmatter fields, file paths, CLI flags, event and RPC channel names, keys and keybindings.
25
+ - Product names: pi, Claude Code, FleetView, npm, DeepSeek Harness, Git.
26
+ - `worktree`: it stays English, written as plain text, in all three languages.
27
+
28
+ ## Glossary
29
+
30
+ | English | zh-CN | ja | ko |
31
+ | ----------------------- | ------------------- | ----------------------------------------------- | ----------------------- |
32
+ | sub-agent / subagent | 子代理 | サブエージェント | 서브에이전트 |
33
+ | agent | 代理 | エージェント | 에이전트 |
34
+ | main / parent agent | 主代理 / 父代理 | メイン / 親エージェント | 메인 / 부모 에이전트 |
35
+ | workflow | 工作流 | ワークフロー | 워크플로 |
36
+ | orchestration | 编排 | オーケストレーション | 오케스트레이션 |
37
+ | background / foreground | 后台 / 前台 | バックグラウンド / フォアグラウンド | 백그라운드 / 포그라운드 |
38
+ | steer (mid-run) | 引导 | ステアリング (gloss once: 指示を送って軌道修正) | 스티어링 |
39
+ | deterministic | 确定性的 | 決定論的 | 결정론적 |
40
+ | spawn | 启动 | 起動 | 실행 |
41
+ | resume | 恢复 | 再開 | 재개 |
42
+ | session | 会话 | セッション | 세션 |
43
+ | thinking level | 思考级别 | 思考レベル | 사고 수준 |
44
+ | extension | 扩展 | 拡張機能 | 확장 |
45
+ | conversation viewer | 对话查看器 | 会話ビューアー | 대화 뷰어 |
46
+ | completion notification | 完成通知 | 完了通知 | 완료 알림 |
47
+ | Claude Code-style | Claude Code 风格的 | Claude Code スタイルの | Claude Code 스타일의 |
48
+ | Claude Code-compatible | 兼容 Claude Code 的 | Claude Code 互換の | Claude Code 호환 |
49
+
50
+ "-style" means the extension follows Claude Code's conventions; "-compatible" means it works the same way. Keep the two apart: never render "-style" as 兼容 / 互換 / 호환, or "-compatible" as 风格 / スタイル / 스타일.
51
+
52
+ ## Register
53
+
54
+ - zh-CN: neutral technical prose, 你 rather than 您, full-width punctuation (,。:;()), a space between Chinese text and Latin text or code.
55
+ - ja: です/ます form, full-width 、。:()around Japanese text, a half-width space between Japanese text and Latin text or code.
56
+ - ko: 합니다 form, standard 띄어쓰기, half-width punctuation, particles attached directly to code spans (`Agent` 도구를).
57
+
58
+ ## Verifying an update
59
+
60
+ 1. Every code span and code block in the translation appears verbatim in `README.md`.
61
+ 2. Every link and `README.md#anchor` resolves.
62
+ 3. A reviewer reads the translation against the English source sentence by sentence. Pay particular attention to defaults, numbers, negations, conditionals and the "-style" / "-compatible" split.
63
+ 4. Each file's header says it is machine-translated until a native speaker has reviewed it. Remove that note only after such a review.
@@ -517,7 +517,7 @@ Concurrency is capped at `max(1, min(16, cpus - 2))`. Queued agents start as slo
517
517
  - **No UI that lists or launches saved workflows.** The inspector shows this session's runs.
518
518
  - **No scheduled workflows.** The scheduler runs agents, not workflows.
519
519
  - **Results are not persisted** beyond the journal and the transcript card.
520
- - **No driving one from another extension.** A workflow cannot be started or steered over the `pi.events` bus, and its agents are invisible to the RPC surface — they emit no lifecycle events, and `subagents:rpc:stop` refuses them. See [`rpc.md`](rpc.md).
520
+ - **No driving one from another extension.** A workflow cannot be started or steered over the `pi.events` bus. It can be _observed_: the run emits `subagents:workflow_started` / `subagents:workflow_settled`, another extension pulls its live detail with `subagents:rpc:workflow_get` / `workflow_list`, and its agents ride the lifecycle events with a `workflowId` — but `subagents:rpc:stop` refuses them. See [`rpc.md`](rpc.md).
521
521
 
522
522
  The sandbox is a determinism and accident boundary, not a defence against a deliberately hostile script: the injected globals are host closures, and disabled code generation is what actually stops one being used to compile anything.
523
523
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herbertgao/pi-subagents",
3
- "version": "0.26.1-local.2",
3
+ "version": "0.26.2-local.2",
4
4
  "description": "Claude Code-style autonomous subagents and workflow orchestration for Pi, with HerbertGao-maintained UI extensions.",
5
5
  "keywords": [
6
6
  "agent",
@@ -74,10 +74,10 @@
74
74
  },
75
75
  "x-upstream": {
76
76
  "package": "@tintinweb/pi-subagents",
77
- "version": "0.26.1",
78
- "reviewedVersion": "0.26.1",
77
+ "version": "0.26.2",
78
+ "reviewedVersion": "0.26.2",
79
79
  "repository": "https://github.com/tintinweb/pi-subagents",
80
- "commit": "14ef1946b439ad2c7e7db618ecdb36f5532052e7",
80
+ "commit": "e9bd10502cd512288642bd8a97c169042a2310b9",
81
81
  "trackVersion": true
82
82
  }
83
83
  }
@@ -337,6 +337,8 @@ export function serializeAgentFile(cfg: AgentConfig): string {
337
337
  fmFields.push(`persist_session: ${cfg.persistSession}`)
338
338
  if (cfg.sessionDir)
339
339
  fmFields.push(`session_dir: ${JSON.stringify(cfg.sessionDir)}`)
340
+ if (cfg.cacheRetention)
341
+ fmFields.push(`cache_retention: ${cfg.cacheRetention}`)
340
342
 
341
343
  return `---\n${fmFields.join("\n")}\n---\n\n${cfg.systemPrompt}\n`
342
344
  }