@herbertgao/pi-extensions 2026.11.18 → 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.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -23
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/package.json +11 -14
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- 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 `@
|
|
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/
|
|
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.
|
|
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
|
-
| `
|
|
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
|
|
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
|
|
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
|
|
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,44 +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`
|
|
140
|
-
|
|
141
|
-
##
|
|
142
|
-
|
|
143
|
-
`subagents:rpc:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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.
|
|
152
340
|
|
|
153
341
|
## The manager registry
|
|
154
342
|
|
|
155
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:
|
|
156
344
|
|
|
157
|
-
| Member | Signature | Notes
|
|
158
|
-
| --------------------------------------- | ----------------------------- |
|
|
159
|
-
| `waitForAll()` | `() => Promise<void>` | Resolves when nothing is running. **All** agents, including ones you did not spawn — a shutdown barrier, not a join
|
|
160
|
-
| `hasRunning()` | `() => boolean` |
|
|
161
|
-
| `spawn(pi, ctx, type, prompt, options)` | `=> string` | **Is** `spawnTopLevel`, so the strip list above applies identically
|
|
162
|
-
| `getRecord(id)` | `=> AgentRecord \| undefined` | Filtered through `isTopLevelAgent
|
|
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 |
|
|
163
351
|
|
|
164
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).
|
|
165
353
|
|
|
166
|
-
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.
|
|
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.
|
|
167
355
|
|
|
168
356
|
## Protocol versions
|
|
169
357
|
|
|
170
|
-
`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:
|
|
171
361
|
|
|
172
|
-
|
|
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` |
|
|
173
376
|
|
|
174
|
-
|
|
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.
|
|
175
378
|
|
|
176
|
-
|
|
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.
|
|
177
380
|
|
|
178
381
|
## Availability
|
|
179
382
|
|
|
@@ -181,17 +384,18 @@ So: send `consume` unconditionally and ignore the outcome — an older build has
|
|
|
181
384
|
|
|
182
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.
|
|
183
386
|
|
|
184
|
-
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`)
|
|
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`.
|
|
185
388
|
|
|
186
389
|
## What the tests pin
|
|
187
390
|
|
|
188
391
|
This document has no test of its own, so it is worth knowing which claims are actually held in place:
|
|
189
392
|
|
|
190
|
-
| Test | Level
|
|
191
|
-
| ------------------------------------- |
|
|
192
|
-
| `test/cross-extension-rpc.test.ts` | Mocked `SpawnCapable`
|
|
193
|
-
| `test/
|
|
194
|
-
| `test/rpc-
|
|
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` |
|
|
195
399
|
|
|
196
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.
|
|
197
401
|
|
|
@@ -201,4 +405,4 @@ Not pinned anywhere, so treat them as descriptions rather than contracts: the `S
|
|
|
201
405
|
|
|
202
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.
|
|
203
407
|
|
|
204
|
-
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:
|
|
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
|
|
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.
|
|
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.
|
|
78
|
-
"reviewedVersion": "0.26.
|
|
77
|
+
"version": "0.26.2",
|
|
78
|
+
"reviewedVersion": "0.26.2",
|
|
79
79
|
"repository": "https://github.com/tintinweb/pi-subagents",
|
|
80
|
-
"commit": "
|
|
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
|
}
|