pi-agent-fleet 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
@@ -42,7 +42,13 @@ Ask your pi session (the LLM drives the tools):
42
42
  > combiner (depends on both) writes output/sum.md with the total.
43
43
  > Each declares its output as a markdown contract.
44
44
 
45
- The agent calls `fleet_design` (if you describe it in prose) or `fleet_plan` (if you already have JSON), you confirm the preview, then `fleet_launch` runs it. Watch the live widget or open the browser canvas; read the report at `.fleet/<name>-<ts>/report.md`.
45
+ The agent calls `fleet_design` (if you describe it in prose) or `fleet_plan` (if you already have JSON), you confirm the preview, then `fleet_launch` runs it. Plan and launch responses include a fleet canvas link by default; the in-chat widget is hidden until you run `/fleet viz`. Read the report at `.fleet/<name>-<ts>/report.md`.
46
+
47
+ JSON pipeline variant — a numeric handoff chain where workers pass typed JSON, verified by schemas at contract check:
48
+
49
+ > Plan and launch the fleet defined in `examples/json-number-pipeline.json`.
50
+
51
+ One writer emits `{"values":[3,5,8]}`, two parallel consumers add and subtract, a synthesizer combines the results — each output declared as a `json` contract with a `schema` naming its required and numeric keys.
46
52
 
47
53
  ## Writing a fleet
48
54
 
@@ -78,7 +84,7 @@ The agent calls `fleet_design` (if you describe it in prose) or `fleet_plan` (if
78
84
 
79
85
  - `config.model` / `config.effort` — fleet-wide defaults; per-worker `model` and `effort` override.
80
86
  - `effort` maps to pi thinking levels: `off | minimal | low | medium | high | xhigh | max`.
81
- - `config.warn_cost_usd` — soft cost guardrail surfaced in the live widget.
87
+ - `config.warn_cost_usd` — soft cost guardrail surfaced in the canvas and report.
82
88
  - `iterate: false` — run the node once at iteration 1 and carry its outputs forward.
83
89
  - `worktree: true` — run the node in a dedicated git worktree.
84
90
  - Worker types `research`, `code-run`, `reviewer`, `write`, `read-only` each get a tailored tool set.
@@ -112,9 +118,16 @@ Every worker declares `outputs[]` with kinds, verified in code at worker exit be
112
118
  | `markdown` | exists, non-empty, starts with `#` |
113
119
  | `file-exists` | exists, non-empty (repo-relative paths = code edits) |
114
120
  | `verdict` | `verdict: lgtm\|iterate\|escalate` line + non-empty body |
115
- | `json` | parses as JSON |
121
+ | `json` | parses as JSON; optional `schema` checks (below) |
116
122
  | `yaml` | parses as YAML |
117
123
 
124
+ JSON outputs may declare a `schema` with `required_keys` (keys that must exist) and `number_keys` (keys that must be numbers or arrays of numbers). Schemas are only allowed on `kind: "json"` outputs, are injected into the worker's prompt, and are enforced at contract check. When a `schema` is present, the JSON must be a top-level object (arrays and scalars fail):
125
+
126
+ ```json
127
+ { "path": "output/sum.json", "kind": "json", "required": true,
128
+ "schema": { "required_keys": ["operation", "result"], "number_keys": ["result"] } }
129
+ ```
130
+
118
131
  Failed required contract → `contract_failed`, dependents blocked, orchestrator notified. No silent passes.
119
132
 
120
133
  ## Tools & commands
@@ -123,8 +136,10 @@ Failed required contract → `contract_failed`, dependents blocked, orchestrator
123
136
  |---|---|
124
137
  | `fleet_design` | draft a fleet DAG from plain-language requirements (planner agent → validated JSON + preview) |
125
138
  | `fleet_plan` | validate + preview a fleet definition (no launch) |
139
+ | `fleet_models` | list available model refs (provider/id) from the live registry — call before `fleet_plan` if you don't know exact model IDs |
126
140
  | `fleet_launch` | launch the planned fleet after user confirmation; `skip_confirm` for unattended runs |
127
- | `fleet_status` | live DAG status and widget lines |
141
+ | `fleet_status` | live DAG status and text summary |
142
+ | `fleet_continue` | resume a failed/killed fleet from current state without restarting completed nodes |
128
143
  | `fleet_pause` / `fleet_resume` | pause/resume loop fleets at the next iteration boundary |
129
144
  | `fleet_kill` | kill all, or kill a single node by worker id |
130
145
  | `fleet_relaunch` | re-run a failed/killed node and its blocked downstream; optional model override |
@@ -133,7 +148,7 @@ Failed required contract → `contract_failed`, dependents blocked, orchestrator
133
148
  | `fleet_report` | regenerate the fleet markdown report |
134
149
  | `fleet_canvas` | open a browser canvas; `?demo=1` shows synthetic data for UI iteration |
135
150
 
136
- `/fleet viz | status | clear | pause | resume | kill all|<node_id> | relaunch <id> [model] | add <json> | edit <node_id>|config ... | configure [show|set k v] | canvas [open|url|stop]`
151
+ `/fleet viz | status | clear | pause | resume | continue | kill all|<node_id> | relaunch <id> [model] | add <json> | edit <node_id>|config ... | configure [show|set k v] | canvas [open|url|stop]`
137
152
 
138
153
  ## Runtime mutation
139
154
 
@@ -156,7 +171,7 @@ These are merged into `fleet_plan` results. Manage them with `/fleet configure s
156
171
 
157
172
  ## Records
158
173
 
159
- Everything lands in `.fleet/<name>-<ts>/` (git-ignored): `state.json` (single source of truth, atomic writes), per-worker `prompt.md` + `session.jsonl` + outputs, per-iteration archives, and a machine-written `report.md` with per-worker turns/tokens/cost, contract results, verdict history, and git diff stats. Completed nodes keep their stats visible in the widget and report after the fleet ends.
174
+ Everything lands in `.fleet/<name>-<ts>/` (git-ignored): `state.json` (single source of truth, atomic writes), per-worker `prompt.md` + `session.jsonl` + outputs, per-iteration archives, and a machine-written `report.md` with per-worker turns/tokens/cost, contract results, verdict history, and git diff stats. Completed nodes keep their stats visible in the canvas and report after the fleet ends.
160
175
 
161
176
  ## Model selection and effort
162
177
 
@@ -172,11 +187,11 @@ Model refs are validated at plan and launch time so bad names fail fast. There i
172
187
 
173
188
  ```bash
174
189
  npm install
175
- npm test # 232 tests, zero-API (fake session factory)
190
+ npm test # 274 tests, zero-API (fake session factory)
176
191
  npm run typecheck
177
192
  ```
178
193
 
179
- Design docs live in `docs/superpowers/specs/`; experiment history in `docs/experiments/`.
194
+ Design docs are archived locally under `.archive/docs/superpowers/` (not tracked); experiment history in `docs/experiments/`.
180
195
 
181
196
  ## License
182
197
 
@@ -0,0 +1,35 @@
1
+ {
2
+ "fleet_name": "json-number-pipeline",
3
+ "type": "dag",
4
+ "config": { "max_concurrent": 2 },
5
+ "workers": [
6
+ {
7
+ "id": "write-numbers",
8
+ "type": "write",
9
+ "task": "Write output/numbers.json containing exactly {\"values\":[3,5,8]}. No markdown. No commentary.",
10
+ "depends_on": [],
11
+ "outputs": [{ "path": "output/numbers.json", "kind": "json", "required": true, "schema": { "required_keys": ["values"], "number_keys": ["values"] } }]
12
+ },
13
+ {
14
+ "id": "add-numbers",
15
+ "type": "write",
16
+ "task": "Read output/numbers.json from write-numbers. Write output/sum.json containing {\"operation\":\"add\",\"result\":16}.",
17
+ "depends_on": ["write-numbers"],
18
+ "outputs": [{ "path": "output/sum.json", "kind": "json", "required": true, "schema": { "required_keys": ["operation", "result"], "number_keys": ["result"] } }]
19
+ },
20
+ {
21
+ "id": "subtract-numbers",
22
+ "type": "write",
23
+ "task": "Read output/numbers.json from write-numbers. Write output/difference.json containing {\"operation\":\"subtract\",\"result\":-10} using first value minus the rest.",
24
+ "depends_on": ["write-numbers"],
25
+ "outputs": [{ "path": "output/difference.json", "kind": "json", "required": true, "schema": { "required_keys": ["operation", "result"], "number_keys": ["result"] } }]
26
+ },
27
+ {
28
+ "id": "synthesize",
29
+ "type": "write",
30
+ "task": "Read output/sum.json and output/difference.json. Write output/final.json containing {\"sum\":16,\"difference\":-10,\"combined\":6} where combined = sum + difference.",
31
+ "depends_on": ["add-numbers", "subtract-numbers"],
32
+ "outputs": [{ "path": "output/final.json", "kind": "json", "required": true, "schema": { "required_keys": ["sum", "difference", "combined"], "number_keys": ["sum", "difference", "combined"] } }]
33
+ }
34
+ ]
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agent-fleet",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "DAG-of-agents fleets for pi — parallel workers with contracts, reviewer-gated iteration loops, and live progress",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  "extensions": [
25
25
  "./src/index.ts"
26
26
  ],
27
- "image": "https://raw.githubusercontent.com/sagarsrc/pi-agent-fleet/v0.4.0/assets/canvas.png"
27
+ "image": "https://raw.githubusercontent.com/sagarsrc/pi-agent-fleet/v0.5.0/assets/canvas.png"
28
28
  },
29
29
  "license": "MIT",
30
30
  "author": "Sagar Sarkale",
@@ -54,7 +54,26 @@ interface CanvasPayload {
54
54
  }
55
55
  interface FleetInfo { name: string; status: string }
56
56
  interface SessionEntry { role: string; text: string }
57
- interface SessionResp { entries: SessionEntry[]; task?: string }
57
+ interface ActionView {
58
+ type: "tool_call" | "tool_result" | "model_change" | "thinking_level_change" | "complete";
59
+ name?: string;
60
+ toolName?: string;
61
+ arguments?: Record<string, unknown>;
62
+ provider?: string;
63
+ modelId?: string;
64
+ thinkingLevel?: string;
65
+ stopReason?: string;
66
+ isError?: boolean;
67
+ timestamp?: string;
68
+ }
69
+ type TimelineEvent =
70
+ | { type: "message"; role: string; text: string; timestamp?: string }
71
+ | { type: "tool_call"; name: string; arguments?: Record<string, unknown>; timestamp?: string }
72
+ | { type: "tool_result"; toolName?: string; isError?: boolean; text?: string; timestamp?: string }
73
+ | { type: "model_change"; provider: string; modelId: string; timestamp?: string }
74
+ | { type: "thinking_level_change"; thinkingLevel: string; timestamp?: string }
75
+ | { type: "complete"; stopReason: string; timestamp?: string };
76
+ interface SessionResp { entries: SessionEntry[]; actions: ActionView[]; events: TimelineEvent[]; task?: string }
58
77
 
59
78
  /* ---------- helpers ---------- */
60
79
  const NODE_W = 284;
@@ -202,6 +221,134 @@ function FleetNode({ data }: NodeProps<Node<FleetNodeData>>) {
202
221
  const nodeTypes = { fleet: FleetNode };
203
222
 
204
223
  /* ---------- side panel ---------- */
224
+ function CollapsiblePrompt({ title, text }: { title: string; text: string }) {
225
+ const [open, setOpen] = useState(true);
226
+ if (!text) return null;
227
+ return (
228
+ <div className={"collapsible" + (open ? "" : " collapsed")}>
229
+ <button className="collapsible-head" onClick={() => setOpen((v) => !v)} aria-expanded={open}>
230
+ <span className="chevron">{open ? "-" : "+"}</span>
231
+ <span>{title}</span>
232
+ </button>
233
+ <div className="collapsible-body">{text}</div>
234
+ </div>
235
+ );
236
+ }
237
+
238
+ function formatActionDetail(a: { arguments?: Record<string, unknown> }): string {
239
+ const args = a.arguments || {};
240
+ if (typeof args.path === "string") return args.path;
241
+ if (typeof args.command === "string") return args.command;
242
+ if (Array.isArray(args.queries)) return String(args.queries[0]);
243
+ const keys = Object.keys(args);
244
+ if (keys[0]) return `${keys[0]}: ${JSON.stringify(args[keys[0]]).slice(0, 40)}`;
245
+ return "";
246
+ }
247
+
248
+ function TimelineItem({ event }: { event: TimelineEvent }) {
249
+ const [open, setOpen] = useState(event.isError ? true : false);
250
+ const ts = event.timestamp ? new Date(event.timestamp).toLocaleTimeString([], { hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit" }) : "";
251
+ if (event.type === "message") {
252
+ return (
253
+ <div className={"timeline-msg" + (event.role === "assistant" ? " assistant" : event.role === "user" ? " user" : "")}>
254
+ <div className="timeline-meta">
255
+ <span className="role">{event.role}</span>
256
+ {ts && <span className="ts">{ts}</span>}
257
+ </div>
258
+ <div className="timeline-text">{event.text}</div>
259
+ </div>
260
+ );
261
+ }
262
+ if (event.type === "tool_call") {
263
+ const detail = formatActionDetail(event);
264
+ const hasArgs = !!event.arguments && Object.keys(event.arguments).length > 0;
265
+ return (
266
+ <div className={"timeline-action" + (open ? " open" : "")}>
267
+ <div className="timeline-row">
268
+ <button className="activity-toggle" onClick={() => setOpen((v) => !v)} aria-expanded={open} title={open ? "collapse" : "expand"}>{open ? "-" : "+"}</button>
269
+ <span className="action-icon">call</span>
270
+ <span className="action-name">{event.name}</span>
271
+ {detail && <span className="action-detail" title={detail}>{detail}</span>}
272
+ {ts && <span className="ts">{ts}</span>}
273
+ </div>
274
+ {open && hasArgs && (
275
+ <div className="activity-body">
276
+ <pre>{JSON.stringify(event.arguments, null, 2)}</pre>
277
+ </div>
278
+ )}
279
+ </div>
280
+ );
281
+ }
282
+ if (event.type === "tool_result") {
283
+ const hasText = !!event.text && event.text.length > 0;
284
+ const expanded = open;
285
+ return (
286
+ <div className={"timeline-action" + (event.isError ? " action-error" : "") + (expanded ? " open" : "")}>
287
+ <div className="timeline-row">
288
+ <button className="activity-toggle" onClick={() => setOpen((v) => !v)} aria-expanded={expanded} title={expanded ? "collapse" : "expand"}>{expanded ? "-" : "+"}</button>
289
+ <span className={"action-icon" + (event.isError ? " action-error" : "")}>{event.isError ? "err" : "ok"}</span>
290
+ <span className="action-name">{event.toolName || "result"}</span>
291
+ {event.text && <span className={"action-detail" + (event.isError ? " action-error" : "")} title={event.text}>{event.isError ? "Error: " : ""}{event.text}</span>}
292
+ {ts && <span className="ts">{ts}</span>}
293
+ </div>
294
+ {expanded && hasText && (
295
+ <div className="activity-body">
296
+ {event.isError ? <strong>Error: </strong> : null}
297
+ {event.text}
298
+ </div>
299
+ )}
300
+ </div>
301
+ );
302
+ }
303
+ if (event.type === "model_change") {
304
+ return (
305
+ <div className="timeline-action">
306
+ <div className="timeline-row">
307
+ <span className="action-icon">mdl</span>
308
+ <span className="action-name">model</span>
309
+ <span className="action-detail">{event.provider}/{event.modelId}</span>
310
+ {ts && <span className="ts">{ts}</span>}
311
+ </div>
312
+ </div>
313
+ );
314
+ }
315
+ if (event.type === "thinking_level_change") {
316
+ return (
317
+ <div className="timeline-action">
318
+ <div className="timeline-row">
319
+ <span className="action-icon">think</span>
320
+ <span className="action-name">thinking</span>
321
+ <span className="action-detail">{event.thinkingLevel}</span>
322
+ {ts && <span className="ts">{ts}</span>}
323
+ </div>
324
+ </div>
325
+ );
326
+ }
327
+ if (event.type === "complete") {
328
+ return (
329
+ <div className="timeline-action">
330
+ <div className="timeline-row">
331
+ <span className="action-icon">done</span>
332
+ <span className="action-name">done</span>
333
+ {event.stopReason !== "complete" && event.stopReason !== "stop" && <span className="action-detail">{event.stopReason}</span>}
334
+ {ts && <span className="ts">{ts}</span>}
335
+ </div>
336
+ </div>
337
+ );
338
+ }
339
+ return null;
340
+ }
341
+
342
+ function Timeline({ events }: { events: TimelineEvent[] }) {
343
+ const visible = events.filter((e) => e.type !== "model_change" && e.type !== "thinking_level_change");
344
+ if (!visible.length) return <div className="timeline-empty">No session data yet.</div>;
345
+ return (
346
+ <div className="timeline" aria-label="Agent session timeline">
347
+ {visible.map((e, i) => <TimelineItem event={e} key={e.type + (e.timestamp || "") + "-" + i} />)}
348
+ </div>
349
+ );
350
+ }
351
+
205
352
  function SidePanel({ fleet, demo, selected, task, onClose }: { fleet: string | null; demo: boolean; selected: string | null; task: string | null; onClose: () => void }) {
206
353
  const [resp, setResp] = useState<SessionResp | null>(null);
207
354
  const boxRef = useRef<HTMLDivElement>(null);
@@ -214,11 +361,12 @@ function SidePanel({ fleet, demo, selected, task, onClose }: { fleet: string | n
214
361
  };
215
362
 
216
363
  useEffect(() => {
217
- if (!selected || demo) { setResp(null); return; }
364
+ if (!selected) { setResp(null); return; }
218
365
  let alive = true;
219
366
  const load = () => {
220
367
  const q = fleet ? "&fleet=" + encodeURIComponent(fleet) : "";
221
- j<SessionResp>("/api/session/" + selected + "?tail=30" + q).then((r) => alive && setResp(r)).catch(() => {});
368
+ const demoQ = demo ? "&demo=1" : "";
369
+ j<SessionResp>("/api/session/" + selected + "?tail=30" + q + demoQ).then((r) => alive && setResp(r)).catch(() => {});
222
370
  };
223
371
  load();
224
372
  const t = setInterval(load, 2000);
@@ -246,26 +394,29 @@ function SidePanel({ fleet, demo, selected, task, onClose }: { fleet: string | n
246
394
  if (nearBottom) el.scrollTop = el.scrollHeight;
247
395
  }, [resp]);
248
396
 
397
+ const latestModel = resp?.events?.slice().reverse().find((e): e is TimelineEvent & { type: "model_change" } => e.type === "model_change");
398
+ const latestThinking = resp?.events?.slice().reverse().find((e): e is TimelineEvent & { type: "thinking_level_change" } => e.type === "thinking_level_change");
249
399
  if (!selected) return null;
250
400
  return (
251
- <div id="side" className="open" ref={boxRef} tabIndex={-1} role="complementary" aria-label={`${selected} session`}>
401
+ <div id="side" className="open" role="complementary" aria-label={`${selected} session`}>
252
402
  <div className="side-head">
253
- <span className="meta"># {selected} — session</span>
403
+ <span className="meta"><span className="side-hash">#</span> <strong className="side-id">{selected}</strong> — session</span>
254
404
  <button className="icon-btn" onClick={closeAndRestore} aria-label="Close session panel" title="Close (Esc)">×</button>
405
+ {(!!latestModel || !!latestThinking) && (
406
+ <div className="side-meta">
407
+ {latestModel && <span className="side-meta-chip">{latestModel.provider}/{latestModel.modelId}</span>}
408
+ {latestThinking && <span className="side-meta-chip">thinking: {latestThinking.thinkingLevel}</span>}
409
+ </div>
410
+ )}
411
+ </div>
412
+ <div className="side-body" ref={boxRef} tabIndex={-1}>
413
+ <CollapsiblePrompt title="Instructions" text={resp?.task || task || ""} />
414
+ {resp === null ? (
415
+ <div className="timeline-loading"><span className="spinner" aria-hidden="true" /> Loading session…</div>
416
+ ) : (
417
+ <Timeline events={resp.events ?? []} />
418
+ )}
255
419
  </div>
256
- {(resp?.task || task) && (
257
- <div className="taskbox-side">
258
- <div className="taskbox-side-label">task</div>
259
- {resp?.task || task}
260
- </div>
261
- )}
262
- {demo && <div className="msg">Session transcripts hidden in demo mode.</div>}
263
- {(resp?.entries ?? []).map((e, i) => (
264
- <div className="msg" key={i}>
265
- <div className={"role role-" + e.role}>{e.role}</div>
266
- {e.text}
267
- </div>
268
- ))}
269
420
  </div>
270
421
  );
271
422
  }