pi-agent-swarm 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,7 @@ Every agent is a real terminal window tiled by your window manager — never a h
16
16
  - Delivers notifications without a model turn and bounds each allowed request to one turn.
17
17
  - Supports explicit follow-up requests so a leader can review a worker's reply and continue the same session.
18
18
  - Recycles an opted-in unfinished worker at a stable boundary after a soft context threshold, preserving a concise project-local handoff for its successor.
19
+ - Optionally hands off a long-running leader in the same terminal, restoring its model, identity, group, and expected worker replies.
19
20
  - Relays user input from a worker window into the leader's model context.
20
21
  - Shows a colored footer badge with the session name, id, and role, degrading through full, compact, and minimal tiers as the terminal narrows.
21
22
  - Authenticates and bounds local protocol traffic, peers, retries, rates, deadlines, and diagnostics.
@@ -63,6 +64,8 @@ For long or unpredictable work, set `contextRecycling` in `session_spawn` and la
63
64
 
64
65
  See [Worker context recycling and handoff storage](../../docs/worker-context-recycling.md) for lifecycle and recovery details.
65
66
 
67
+ Leader recycling is separately opt-in through `leaderRecycling.enabled`. In `ask` mode an armed advisory lets the leader decline; `auto` mode instructs it to publish at a non-aborted settled boundary. Three consecutive automatic failures open a lineage-persisted circuit that survives reload and failed replacement attempts; only a fully restored successor resets it, while manual `/swarm handoff` remains available. Run `/swarm handoff` to request a handoff manually, including while the agent is streaming. The `leader_handoff` tool writes the ten-section artifact, then the same terminal creates a successor with the outgoing session as parent. See [Leader context recycling](../../docs/leader-context-recycling.md).
68
+
66
69
  ## 🧭 Launch flow
67
70
 
68
71
  Edit `pi-agent-swarm.json` to change final launch confirmation or toggle lead-workspace pinning.
@@ -121,6 +124,10 @@ Peer-list text and details share a 40 KiB UTF-8 result budget below Pi's tool-ou
121
124
 
122
125
  A handoff requires `originalObjective`, `currentState`, `completedWork`, `remainingWork`, `modifiedFiles`, `verification`, `decisions`, `blocker`, `nextAction`, and `artifacts`. Artifacts are absolute paths within the worker project, not inline logs. The leader receives only the bounded handoff path and its launch metadata; it reads the document when constructing the successor kickoff. `taskStatus` is available on `reply` and defaults to `completed`; ordinary `send` remains a working notification or request.
123
126
 
127
+ ### `leader_handoff`
128
+
129
+ Publishes the current lead session's ten-section handoff and stages a same-terminal successor. It uses the same bounded fields as worker handoff. During `session_start`, after settings load and before the first request, the active-tool list excludes it by default or includes it when leader recycling is enabled. Calls are rejected when leader recycling is disabled, from non-lead sessions, without a persisted session file, or when another handoff is already staged. Call it alone in its assistant batch; mixed or duplicate batches reject the handoff, and no tools may run after a successful handoff is staged. Success returns `terminate: true`; the actual replacement begins only after the current agent run settles. Once the successor atomically commits the next lineage generation, recovery failures only degrade individual steps and warn: they never roll leadership or worker ownership back to the closed predecessor. See [Leader context recycling](../../docs/leader-context-recycling.md) for replacement and retry behavior.
130
+
124
131
  ## 💬 Commands
125
132
 
126
133
  | Command | Purpose |
@@ -128,6 +135,7 @@ A handoff requires `originalObjective`, `currentState`, `completedWork`, `remain
128
135
  | `/swarm` | Open the menu to spawn a worker, rename this session, or set its color. |
129
136
  | `/swarm start` | Start a local group with this session as lead. |
130
137
  | `/swarm requests <on\|off>` | Allow or block follow-up agent requests in this joined session; blocked by default. |
138
+ | `/swarm handoff` | Ask the lead model to publish a leader handoff and continue in a same-terminal successor; requires `leaderRecycling.enabled`. |
131
139
  | `/swarm <piagentswarm:v1:invite>` | Review the join confirmation and join one ephemeral local group. |
132
140
  | `/lead` | Promote a session to leader or inspect the current leader. |
133
141
  | `/color` | Set the current session's footer color. |
@@ -163,7 +171,15 @@ Edit user settings in `<getAgentDir()>/pi-agent-swarm.json`, normally `~/.pi/age
163
171
  "confirmSessionLaunch": true,
164
172
  "pinToLeadWorkspace": false,
165
173
  "autoName": true,
166
- "autoNameModel": "anthropic/claude-haiku-4-5"
174
+ "autoNameModel": "anthropic/claude-haiku-4-5",
175
+ "leaderRecycling": {
176
+ "enabled": false,
177
+ "mode": "ask",
178
+ "softContextPercent": 50,
179
+ "softContextTokens": 100000,
180
+ "highWaterPercent": 75,
181
+ "maxReplacements": 3
182
+ }
167
183
  }
168
184
  ```
169
185
 
@@ -173,8 +189,9 @@ Edit user settings in `<getAgentDir()>/pi-agent-swarm.json`, normally `~/.pi/age
173
189
  | `externalCommand` | any terminal command | `alacritty -e` | Command used to open each new window. |
174
190
  | `confirmSessionLaunch` | `true`, `false` | `true` | Shows or skips the final launch preview for tool launches. |
175
191
  | `pinToLeadWorkspace` | `true`, `false` | `false` | Moves each new window onto the lead session's workspace instead of the focused one. |
176
- | `autoName` | `true`, `false` | `true` | Renames a human-started session from the bootstrap `MANAGER-<id>` name to a `MAN-<title>` summary of its first three completed turns. The rename uses a one-shot completion, retries on later turns if the completion fails, and steps aside forever as soon as you set a name yourself. Spawned child sessions keep their launch names. |
192
+ | `autoName` | `true`, `false` | `true` | Renames a human-started session from the bootstrap `MANAGER-<id>` name to a `MAN-<title>` summary of its first three completed turns (or after the first completed external-agent run reported over the extension-neutral `pi-agent-swarm:external-turn:v1` event on `pi.events` with at least 20 user characters). The rename uses a one-shot completion, ignores proxy/tool status noise, retries on later turns if the completion fails, and steps aside forever as soon as you set a name yourself. Spawned child sessions keep their launch names. |
177
193
  | `autoNameModel` | `provider/id` | unset | Model used for the `MAN-<title>` completion. When unset, the session's current model is used, so no extra authentication is needed. An unresolvable value keeps the default name and reports a warning. |
194
+ | `leaderRecycling` | object | disabled | Leader handoff policy: `enabled` defaults to `false`; `mode` is `ask` or `auto`; soft thresholds default to 50% and 100,000 tokens; high water defaults to 75%; at most three replacements are authorized by default. Invalid fields fall back individually with warnings. |
178
195
 
179
196
  Pi Agent Swarm does not read project settings or extension-specific environment-variable overrides.
180
197
  A missing file uses the defaults without creating the file.
@@ -189,7 +206,7 @@ Version-3 messages normally expire after two minutes and cannot declare a lifeti
189
206
  Accepted message ids remain deduplicated for ten minutes, longer than their valid delivery window.
190
207
  A copied invite is still a reusable bearer secret, so discard it or start a new group when you need to rotate access.
191
208
  A short-lived in-process handoff preserves a group across `/reload` for the same `sessionManager` only.
192
- Membership does not carry into `/new`, `/resume`, or another logical session without a new invite.
209
+ Membership does not carry into ordinary `/new`, `/resume`, or another logical session without a new invite. The single exception is an explicitly staged leader handoff: its token-bound successor rejoins the group, broadcasts the new lead, and restores expected worker replies. Replies arriving during restoration are rejected rather than ghost-acknowledged, and failed deferred delivery retains its body for recovery with a warning.
193
210
 
194
211
  The terminal child receives an internal launch-only environment envelope containing a parent-only kickoff capability.
195
212
  The child consumes and deletes those values during `session_start` before Pi tools can inherit them.
@@ -217,7 +234,7 @@ Enabling them permits trusted invite holders to start paid model turns that may
217
234
  - Pi Agent Swarm does not retain invites as durable settings or group state, but a recipient can copy and reuse one until every holder discards it or moves to a new group.
218
235
  - Invites are not placed in tool output, status, notifications, custom renderers, or model context.
219
236
  - Launch values briefly exist in a private `0700` launcher that unlinks itself before starting Pi, so terminal command metadata cannot retain them.
220
- - Worker lineage and handoff files are project-local, owner-restricted, atomically published, and excluded by `.pi/agent-swarm/.gitignore`. They reject bearer secrets and artifact paths outside the project, but are not a boundary against same-user processes.
237
+ - Worker and leader lineage/handoff files are project-local, owner-restricted, atomically published, and excluded by `.pi/agent-swarm/.gitignore`. Leader records use the separate `leader-lineages/` tree. They reject bearer secrets and artifact paths outside the project, but are not a boundary against same-user processes.
221
238
  - Handoffs contain structured progress and artifact references rather than a copied session transcript. Large artifacts remain opt-in reads.
222
239
  - Peer names, paths, messages, model ids, and errors are treated as untrusted terminal text and sanitized only at display boundaries.
223
240
  - A same-user process or another privileged Pi extension is outside the security boundary and may inspect process arguments, private runtime files, memory, or environment.