pi-agent-swarm 0.3.0 → 0.4.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
@@ -14,6 +14,8 @@ Every agent is a real terminal window tiled by your window manager — never a h
14
14
  - Waits for the child to authenticate before reporting that the new session is ready.
15
15
  - Connects explicitly joined same-user sessions through owner-only local sockets and ephemeral invites.
16
16
  - Delivers notifications without a model turn and bounds each allowed request to one turn.
17
+ - Supports explicit follow-up requests so a leader can review a worker's reply and continue the same session.
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.
17
19
  - Relays user input from a worker window into the leader's model context.
18
20
  - Shows a colored footer badge with the session name, id, and role, degrading through full, compact, and minimal tiers as the terminal narrows.
19
21
  - Authenticates and bounds local protocol traffic, peers, retries, rates, deadlines, and diagnostics.
@@ -49,10 +51,18 @@ Review extension source before installing it.
49
51
 
50
52
  ## 🚀 Quick start
51
53
 
52
- Run `/swarm` to open the menu and spawn a worker Pi session, rename this session, or change its footer color.
54
+ Run `/swarm` to open the menu and spawn a worker Pi session, rename this session, change its footer color, or toggle follow-up requests.
53
55
  Start a local group with `/swarm start`, then ask your model to launch a child session with the `session_spawn` tool; the child joins the group automatically.
54
56
  Before creating a window, Pi Agent Swarm asks for the configured launch confirmation.
55
57
 
58
+ For a review-and-revise workflow, select **Allow paid turns from trusted peers** when spawning, or set `allowRequests: true` in `session_spawn`.
59
+ The worker can then report with `session_bus reply`, and the leader can request revisions in that same session with `session_bus send mode=request`.
60
+ In an existing joined session, the local user can run `/swarm requests on` to enable this workflow and `/swarm requests off` to block it again.
61
+
62
+ For long or unpredictable work, set `contextRecycling` in `session_spawn` and launch with a task. After a turn finishes at or above the soft threshold, an unfinished worker enters `handoff_pending`, publishes a structured handoff with `session_bus`, and freezes. The leader starts one bounded successor with the same cwd, model, request permission, and lineage. The current turn is never aborted merely for crossing the threshold; a completed task is not replaced. A worker that cannot publish a handoff after two attempts stays frozen on a durable `failed` lineage, and the leader is notified.
63
+
64
+ See [Worker context recycling and handoff storage](../../docs/worker-context-recycling.md) for lifecycle and recovery details.
65
+
56
66
  ## 🧭 Launch flow
57
67
 
58
68
  Edit `pi-agent-swarm.json` to change final launch confirmation or toggle lead-workspace pinning.
@@ -78,6 +88,8 @@ Creates a separate Pi process in an external terminal window.
78
88
  | Parameter | Required | Description |
79
89
  | --- | --- | --- |
80
90
  | `direction` | No | `right`, `down`, `left`, or `up`; defaults to `right`. |
91
+ | `allowRequests` | No | Allows trusted peers to request follow-up turns after the initial task; defaults to `false`. |
92
+ | `contextRecycling` | No | Opts into automatic lineage handoff. Fields: `taskProfile` (`short`, `long`, or `auto`), optional `maxContextPercent` (1–100, default 50), and optional `maxReplacements` (0–10, default 3). |
81
93
  | `task` | No | First task sent only after authenticated readiness. |
82
94
  | `name` | No | Child session display name. |
83
95
  | `color` | No | Child color: a palette name or a `#rrggbb` hex. |
@@ -87,6 +99,7 @@ Creates a separate Pi process in an external terminal window.
87
99
  The tool supports only TUI and RPC modes because launch may require confirmation.
88
100
  In JSON and print modes, it fails before creating a group, launcher, or window.
89
101
  Successful details include `terminalId` and `terminalVersion`.
102
+ Context recycling requires a non-empty initial task and `allowRequests: true`. The replacement budget is authorization for automatic launches, not a per-turn deadline.
90
103
 
91
104
  ### `session_bus`
92
105
 
@@ -96,20 +109,25 @@ Lists or messages sessions in the active Pi Agent Swarm group.
96
109
  | --- | --- | --- |
97
110
  | `list` | none | Lists authenticated live peers and request policy. |
98
111
  | `send` | `targetSessionId`, `message`, optional `mode` | Sends `notify` by default or a permitted one-turn `request`. |
99
- | `reply` | `targetSessionId`, `message`, `replyTo` | Correlates a reply without starting another automatic turn. |
112
+ | `reply` | `targetSessionId`, `message`, `replyTo`, optional `taskStatus` | Correlates a reply without starting another automatic turn. `taskStatus` is `working` or `completed`. |
113
+ | `send` | `kind: "handoff"`, `handoff` | Publishes the current worker's structured handoff to the leader without injecting it into model context. |
100
114
  | `shutdown` | `targetSessionId` | Asks a peer to shut down gracefully. |
101
115
 
102
116
  An accepted acknowledgement means the recipient extension accepted or deduplicated the message, not that the remote agent completed the work.
103
- Rejected and busy acknowledgements use stable codes such as `requests_disabled`, `rate_limited`, `target_busy`, `shutdown_unauthorized`, and `delivery_failed`.
117
+ Rejected and busy acknowledgements use stable codes such as `requests_disabled`, `context_handoff`, `rate_limited`, `target_busy`, `shutdown_unauthorized`, and `delivery_failed`.
118
+ A recycled worker that is frozen for handoff, replacement, or retirement answers requests with `context_handoff` so a leader does not mistake the freeze for a disabled request policy.
104
119
  Rate-limited responses may include a bounded retry delay.
105
120
  Peer-list text and details share a 40 KiB UTF-8 result budget below Pi's tool-output limit.
106
121
 
122
+ 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
+
107
124
  ## 💬 Commands
108
125
 
109
126
  | Command | Purpose |
110
127
  | --- | --- |
111
128
  | `/swarm` | Open the menu to spawn a worker, rename this session, or set its color. |
112
129
  | `/swarm start` | Start a local group with this session as lead. |
130
+ | `/swarm requests <on\|off>` | Allow or block follow-up agent requests in this joined session; blocked by default. |
113
131
  | `/swarm <piagentswarm:v1:invite>` | Review the join confirmation and join one ephemeral local group. |
114
132
  | `/lead` | Promote a session to leader or inspect the current leader. |
115
133
  | `/color` | Set the current session's footer color. |
@@ -178,6 +196,7 @@ The child consumes and deletes those values during `session_start` before Pi too
178
196
  These values are not user settings or supported environment overrides.
179
197
 
180
198
  Incoming agent requests are blocked by default.
199
+ Enable them explicitly during spawn or with `/swarm requests on` in the target session.
181
200
  Enabling them permits trusted invite holders to start paid model turns that may edit the same workspace concurrently.
182
201
 
183
202
  ## 🔒 Security and privacy
@@ -198,6 +217,8 @@ Enabling them permits trusted invite holders to start paid model turns that may
198
217
  - 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.
199
218
  - Invites are not placed in tool output, status, notifications, custom renderers, or model context.
200
219
  - 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.
221
+ - Handoffs contain structured progress and artifact references rather than a copied session transcript. Large artifacts remain opt-in reads.
201
222
  - Peer names, paths, messages, model ids, and errors are treated as untrusted terminal text and sanitized only at display boundaries.
202
223
  - 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.
203
224
  - Pi Agent Swarm separates groups but does not sandbox them from the operating-system user.
@@ -11,12 +11,13 @@ var PALETTE_OPTIONS = [
11
11
  { label: "muted (default, low-saturation GitHub colors)", value: "muted" },
12
12
  { label: "bright (vivid GitHub colors)", value: "bright" }
13
13
  ];
14
+ var REQUEST_OPTIONS = ["Block (default)", "Allow paid turns from trusted peers"];
14
15
  function createSwarmMenu(source) {
15
16
  const getState = ({ signal } = {}) => source.snapshot(signal);
16
17
  const menu = {
17
18
  start: "main",
18
19
  screens: {
19
- main: () => ({
20
+ main: ({ state }) => ({
20
21
  kind: "actions",
21
22
  title: "Pi Agent Swarm",
22
23
  lines: ["Spawn workers and manage this session's badge."],
@@ -40,6 +41,11 @@ function createSwarmMenu(source) {
40
41
  id: "theme",
41
42
  label: "Set theme",
42
43
  action: "setTheme"
44
+ },
45
+ {
46
+ id: "requests",
47
+ label: `Follow-up requests: ${state.acceptsRequests ? "allowed" : "blocked"}`,
48
+ action: "setRequests"
43
49
  }
44
50
  ],
45
51
  hint: "close"
@@ -51,6 +57,8 @@ function createSwarmMenu(source) {
51
57
  signal
52
58
  });
53
59
  if (!directionChoice || signal.aborted) return { kind: "stay" };
60
+ const requestChoice = await ctx.ui.select("Follow-up agent requests", [...REQUEST_OPTIONS], { signal });
61
+ if (!requestChoice || signal.aborted) return { kind: "stay" };
54
62
  const task = await ctx.ui.input("Optional first task", "Submit an empty value for an idle child session", {
55
63
  signal
56
64
  });
@@ -59,6 +67,7 @@ function createSwarmMenu(source) {
59
67
  ctx,
60
68
  {
61
69
  direction: directionChoice.toLowerCase(),
70
+ allowRequests: requestChoice === "Allow paid turns from trusted peers",
62
71
  ...task ? { task } : {}
63
72
  },
64
73
  signal
@@ -81,6 +90,10 @@ function createSwarmMenu(source) {
81
90
  await source.setColor(ctx, choice, signal);
82
91
  return { kind: "stay" };
83
92
  },
93
+ setRequests: async ({ ctx, state }) => {
94
+ await source.setRequests(ctx, !state.acceptsRequests);
95
+ return { kind: "stay" };
96
+ },
84
97
  setTheme: async ({ ctx, signal }) => {
85
98
  const choice = await ctx.ui.select(
86
99
  "Roster theme (badge palette)",
@@ -116,4 +129,4 @@ export {
116
129
  createSwarmMenu,
117
130
  showSwarmMenu
118
131
  };
119
- //# sourceMappingURL=menu-RH6GY6U4.ts.map
132
+ //# sourceMappingURL=menu-NLK5I2DA.ts.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/menu.ts"],
4
+ "sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\nimport { SWARM_COLORS, type SwarmColorPaletteName } from \"./color.js\";\nimport type { SpawnSessionInput, SwarmSnapshot } from \"./swarm-controller.js\";\nimport { safeError } from \"./text.js\";\n\nexport interface SwarmMenuState extends SwarmSnapshot {}\n\nexport interface SwarmMenuSource {\n snapshot(signal?: AbortSignal): Promise<SwarmMenuState>;\n spawn(ctx: ExtensionCommandContext, input: SpawnSessionInput, signal?: AbortSignal): Promise<void>;\n rename(ctx: ExtensionCommandContext, name: string, signal?: AbortSignal): Promise<void>;\n setColor(ctx: ExtensionCommandContext, color: string, signal?: AbortSignal): Promise<void>;\n setPalette(ctx: ExtensionCommandContext, palette: SwarmColorPaletteName, signal?: AbortSignal): Promise<void>;\n setRequests(ctx: ExtensionCommandContext, value: boolean): Promise<void>;\n}\n\ntype Screen = \"main\";\ntype Action = \"spawn\" | \"rename\" | \"setColor\" | \"setTheme\" | \"setRequests\";\n\nconst DIRECTION_OPTIONS = [\"Right\", \"Down\", \"Left\", \"Up\"] as const;\nconst PALETTE_OPTIONS = [\n { label: \"muted (default, low-saturation GitHub colors)\", value: \"muted\" },\n { label: \"bright (vivid GitHub colors)\", value: \"bright\" },\n] as const satisfies readonly { label: string; value: SwarmColorPaletteName }[];\nconst REQUEST_OPTIONS = [\"Block (default)\", \"Allow paid turns from trusted peers\"] as const;\n\nexport function createSwarmMenu(source: SwarmMenuSource) {\n const getState = ({ signal }: { signal?: AbortSignal } = {}) => source.snapshot(signal);\n const menu: MenuDefinition<SwarmMenuState, Screen, Action> = {\n start: \"main\",\n screens: {\n main: ({ state }) => ({\n kind: \"actions\",\n title: \"Pi Agent Swarm\",\n lines: [\"Spawn workers and manage this session's badge.\"],\n items: [\n {\n id: \"spawn\",\n label: \"Spawn\",\n action: \"spawn\",\n },\n {\n id: \"rename\",\n label: \"Rename\",\n action: \"rename\",\n },\n {\n id: \"color\",\n label: \"Set color\",\n action: \"setColor\",\n },\n {\n id: \"theme\",\n label: \"Set theme\",\n action: \"setTheme\",\n },\n {\n id: \"requests\",\n label: `Follow-up requests: ${state.acceptsRequests ? \"allowed\" : \"blocked\"}`,\n action: \"setRequests\",\n },\n ],\n hint: \"close\",\n }),\n },\n actions: {\n spawn: async ({ ctx, signal }) => {\n const directionChoice = await ctx.ui.select(\"Terminal window direction\", [...DIRECTION_OPTIONS], {\n signal,\n });\n if (!directionChoice || signal.aborted) return { kind: \"stay\" };\n const requestChoice = await ctx.ui.select(\"Follow-up agent requests\", [...REQUEST_OPTIONS], { signal });\n if (!requestChoice || signal.aborted) return { kind: \"stay\" };\n const task = await ctx.ui.input(\"Optional first task\", \"Submit an empty value for an idle child session\", {\n signal,\n });\n if (task === undefined || signal.aborted) return { kind: \"stay\" };\n await source.spawn(\n ctx,\n {\n direction: directionChoice.toLowerCase() as SpawnSessionInput[\"direction\"],\n allowRequests: requestChoice === \"Allow paid turns from trusted peers\",\n ...(task ? { task } : {}),\n },\n signal,\n );\n return { kind: \"close\" };\n },\n rename: async ({ ctx, signal, state }) => {\n const name = await ctx.ui.input(\"Rename session\", state.self?.name ?? \"Enter a new session name\", {\n signal,\n });\n if (name === undefined || !name.trim() || signal.aborted) return { kind: \"stay\" };\n await source.rename(ctx, name, signal);\n return { kind: \"stay\" };\n },\n setColor: async ({ ctx, signal }) => {\n const choice = await ctx.ui.select(\"Session color\", [...SWARM_COLORS.map((color) => color.name)], {\n signal,\n });\n if (!choice || signal.aborted) return { kind: \"stay\" };\n await source.setColor(ctx, choice, signal);\n return { kind: \"stay\" };\n },\n setRequests: async ({ ctx, state }) => {\n await source.setRequests(ctx, !state.acceptsRequests);\n return { kind: \"stay\" };\n },\n setTheme: async ({ ctx, signal }) => {\n const choice = await ctx.ui.select(\n \"Roster theme (badge palette)\",\n PALETTE_OPTIONS.map((option) => option.label),\n { signal },\n );\n if (!choice || signal.aborted) return { kind: \"stay\" };\n const palette = PALETTE_OPTIONS.find((option) => option.label === choice)?.value;\n if (!palette) return { kind: \"stay\" };\n await source.setPalette(ctx, palette, signal);\n return { kind: \"stay\" };\n },\n },\n };\n return { menu, getState };\n}\n\nexport async function showSwarmMenu(\n ctx: ExtensionCommandContext,\n source: SwarmMenuSource,\n ownership: { signal: AbortSignal; isCurrent(): boolean },\n): Promise<void> {\n const { runMenu } = await import(\"@narumitw/pi-tui-kit\");\n if (ownership.signal.aborted || !ownership.isCurrent()) return;\n const controller = createSwarmMenu(source);\n await runMenu(ctx, controller.menu, {\n getState: controller.getState,\n signal: ownership.signal,\n isCurrent: ownership.isCurrent,\n onError: (_ctx, error) => {\n if (ownership.isCurrent() && !ownership.signal.aborted) {\n ctx.ui.notify(`Pi Agent Swarm failed: ${safeError(error)}`, \"error\");\n }\n },\n });\n}\n"],
5
+ "mappings": ";;;;;;;;AAoBA,IAAM,oBAAoB,CAAC,SAAS,QAAQ,QAAQ,IAAI;AACxD,IAAM,kBAAkB;AAAA,EACtB,EAAE,OAAO,iDAAiD,OAAO,QAAQ;AAAA,EACzE,EAAE,OAAO,gCAAgC,OAAO,SAAS;AAC3D;AACA,IAAM,kBAAkB,CAAC,mBAAmB,qCAAqC;AAE1E,SAAS,gBAAgB,QAAyB;AACvD,QAAM,WAAW,CAAC,EAAE,OAAO,IAA8B,CAAC,MAAM,OAAO,SAAS,MAAM;AACtF,QAAM,OAAuD;AAAA,IAC3D,OAAO;AAAA,IACP,SAAS;AAAA,MACP,MAAM,CAAC,EAAE,MAAM,OAAO;AAAA,QACpB,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO,CAAC,gDAAgD;AAAA,QACxD,OAAO;AAAA,UACL;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,QAAQ;AAAA,UACV;AAAA,UACA;AAAA,YACE,IAAI;AAAA,YACJ,OAAO,uBAAuB,MAAM,kBAAkB,YAAY,SAAS;AAAA,YAC3E,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,QACA,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,OAAO,OAAO,EAAE,KAAK,OAAO,MAAM;AAChC,cAAM,kBAAkB,MAAM,IAAI,GAAG,OAAO,6BAA6B,CAAC,GAAG,iBAAiB,GAAG;AAAA,UAC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