pi-crew 0.11.22 → 0.11.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/agents/explorer.md +3 -3
  3. package/agents/librarian.md +3 -3
  4. package/dist/index.mjs +523 -520
  5. package/docs/dynamic-workflows.md +14 -2
  6. package/package.json +4 -4
  7. package/src/agents/discover-agents.ts +8 -2
  8. package/src/config/config-validation.ts +3 -1
  9. package/src/config/env-allowlist-registry.ts +5 -0
  10. package/src/config/env-vars.ts +9 -6
  11. package/src/config/role-tools.ts +7 -6
  12. package/src/extension/management.ts +7 -0
  13. package/src/extension/register.ts +15 -0
  14. package/src/extension/run-index.ts +24 -1
  15. package/src/extension/team-tool/destructive-gate.ts +208 -0
  16. package/src/extension/team-tool/goal-wrap.ts +11 -1
  17. package/src/extension/team-tool/goal.ts +13 -1
  18. package/src/extension/team-tool/respond.ts +8 -6
  19. package/src/extension/team-tool/run.ts +4 -4
  20. package/src/extension/team-tool.ts +10 -0
  21. package/src/observability/exporters/otlp-exporter.ts +11 -1
  22. package/src/prompt/prompt-runtime.ts +102 -18
  23. package/src/prompt/surface-worker.ts +13 -1
  24. package/src/runtime/broker/crew-broker-client.ts +7 -0
  25. package/src/runtime/broker/crew-broker.ts +113 -152
  26. package/src/runtime/broker/protocol/connection-state.ts +159 -1
  27. package/src/runtime/broker/protocol/events-replay.ts +50 -10
  28. package/src/runtime/broker/protocol/request-parsers.ts +68 -0
  29. package/src/runtime/child-pi/child-pi-constants.ts +9 -0
  30. package/src/runtime/child-pi/child-pi-rpc.ts +72 -7
  31. package/src/runtime/child-pi/child-pi-streams.ts +19 -3
  32. package/src/runtime/child-pi/postmortem-registry.ts +8 -2
  33. package/src/runtime/classifier/ambient-noise-gate.ts +5 -1
  34. package/src/runtime/compaction/tool-output-pruner.ts +20 -2
  35. package/src/runtime/crew-agent-records.ts +92 -17
  36. package/src/runtime/custom-tools/submit-result-tool.ts +17 -0
  37. package/src/runtime/deadletter.ts +5 -1
  38. package/src/runtime/dispatch-batch.ts +60 -16
  39. package/src/runtime/effectiveness.ts +24 -1
  40. package/src/runtime/finalize-run.ts +12 -1
  41. package/src/runtime/goal-workflow/dynamic-workflow-context.ts +12 -3
  42. package/src/runtime/goal-workflow/goal-evaluator.ts +30 -5
  43. package/src/runtime/goal-workflow/goal-loop-runner.ts +60 -3
  44. package/src/runtime/live-session/live-agent-control.ts +34 -14
  45. package/src/runtime/live-session/live-agent-manager.ts +20 -5
  46. package/src/runtime/live-session/live-session-runtime.ts +66 -81
  47. package/src/runtime/live-session/usage-bridge.ts +66 -2
  48. package/src/runtime/mcp-proxy.ts +10 -0
  49. package/src/runtime/model/model-fallback.ts +68 -0
  50. package/src/runtime/model/runtime-policy.ts +20 -6
  51. package/src/runtime/model/runtime-resolver.ts +5 -3
  52. package/src/runtime/orphan-worker-registry.ts +64 -24
  53. package/src/runtime/pi-spawn.ts +4 -1
  54. package/src/runtime/process/zombie-scanner.ts +6 -2
  55. package/src/runtime/recovery/crash-recovery.ts +35 -2
  56. package/src/runtime/scheduling/batch-barrier.ts +42 -5
  57. package/src/runtime/scheduling/run-coalesced-task-group.ts +9 -3
  58. package/src/runtime/scheduling/scheduler.ts +74 -29
  59. package/src/runtime/stale-reconciler.ts +45 -6
  60. package/src/runtime/surface/herdr-provider.ts +54 -1
  61. package/src/runtime/surface/launch-script.ts +7 -1
  62. package/src/runtime/surface/resolve-surface.ts +4 -1
  63. package/src/runtime/surface/tmux-provider.ts +32 -2
  64. package/src/runtime/task-runner/child-executor.ts +3 -2
  65. package/src/runtime/workspace-lock.ts +52 -4
  66. package/src/state/contracts.ts +2 -0
  67. package/src/state/coordination/process-lock.ts +50 -0
  68. package/src/state/event-log/cursor.ts +24 -3
  69. package/src/state/event-log/event-log-rotation.ts +26 -2
  70. package/src/state/event-log/worker-atomic-writer.ts +5 -0
  71. package/src/state/stores/active-run-registry.ts +56 -5
  72. package/src/state/stores/ownership-map.ts +26 -7
  73. package/src/state/stores/plan-store.ts +30 -1
  74. package/src/state/stores/sqlite-run-state.ts +91 -1
  75. package/src/state/types.ts +5 -0
  76. package/src/ui/dashboard-panes/agents-pane.ts +4 -3
  77. package/src/ui/dashboard-panes/plan-pane.ts +5 -3
  78. package/src/ui/dashboard-panes/transcript-pane.ts +2 -1
  79. package/src/ui/overlays/mailbox-detail-overlay.ts +5 -3
  80. package/src/ui/run-dashboard.ts +6 -4
  81. package/src/ui/run-snapshot-cache.ts +3 -2
  82. package/src/ui/settings-overlay.ts +68 -10
  83. package/src/ui/theme-discovery.ts +26 -7
  84. package/src/ui/transcript-viewer.ts +5 -3
  85. package/src/utils/visual.ts +84 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ### Fixed (deep review 2026-10-16/17 — Waves 2-4; report `pi-crew-deep-review-2026-10-16.md`, 128/128 cold-verified)
6
+
7
+ - **fix(state): FS2 + R5-M-B4 + family-2 read-error wipes** — readCrewAgents/plan-store/ownership-map/active-run-registry/orphan-worker-registry no longer collapse non-ENOENT read faults to empty feeding a locked full overwrite (sentinel + skip-save + loud log; ST-4-style guards).
8
+ - **fix(ui): R4-B1 + R5-M-A3 terminal-escape injection closed** — new `sanitizeUntrustedLine` (strips ALL OSC/APC, non-SGR CSI, DCS/bare-ESC; C0/C1→space) applied at 10 worker-data render seams (mailbox-detail, snapshot-cache, transcript pane/viewer, agents-pane, dashboard, plan-pane). OSC-52 clipboard poison + OSC-8 dispatch now render inert (pinning tests).
9
+ - **fix(broker): R9-N1/N2 + R8-M1 replay/overflow hardening** — oversize encode can no longer silently hang events.since (typed `response-oversize` + limit-halving with `nextSinceSeq` continuation); wide-path replay gains `fromByteOffset`/`truncated` continuation (prefix of >4MB logs replayable); per-connection queued-BYTES cap (4 MiB) alongside the frame cap.
10
+ - **fix(prompt): R9-F1 delegate-result recovery** — pending delegate results surviving in the task inbox are re-injected at poll-loop restart (turn-restart drop fixed at the pi-crew seam) + timeout-notice recovery hint.
11
+ - **fix(recovery): R2-M-A1 + R4-N1** — individual-stale reconcile cancels ONLY the stale tasks (pid-alive siblings untouched); foreign-rotation (size<offset) now aborts compaction instead of clobbering the new live file.
12
+ - **fix(security/policy — Wave 3, owner-decided defaults):** 8-entry worker-origin root-gate (schedule/goal+force/config-user/settings-user+theme/autonomy/create-user/update-user — reads + project scope stay open); explorer+librarian lose `bash` in BOTH frontmatter and ROLE_TOOL_CONFIGS (Chain A cheapest cut); MCP G2-degradation now fails CLOSED for non-permitted roles; structured safety-refusal stop-reasons are non-retryable (no more safety-refusal laundering); IRC peer messages fenced `<untrusted-peer-message>`; DWF identical-call cache is resume-only (live runs re-spawn — the documented review loop now works); judge fence length adapts to backtick runs; workspace-lock post-claim/post-refresh ownership verify + heartbeat-false → goal blocked; rpc pool keyed per-run with pinnedRunId re-validation; sqlite corrupt-DB quarantine (.corrupt-<ts> + user_version=1) instead of permanent unloadability; goal maxTurns clamped to LIMIT_CEILINGS; hermeticWorkers:false init warning; peer pins floored >=1.0.4.
13
+ - **fix(reliability — Wave 4):** R9-F3 effectiveness counts delegate.completed; R9-OPS2 stale /tmp pc-*.sock sweep (24h); spawnedRunIds pruned; tmux-watcher/BatchBarrier disposal; cron scan hoisted+hopped (no 527k-iteration stall); prune digest head-2/tail-2 fallback for all tools; herdr 10s request timeout + error-ack → mux-dead; oscillation period-2 detection; parked-ask shield derives from clamped deadline (+ broker stamps manifest.waitState.deadline); purgeStaleActiveRunIndex isIntentionalWait + waitState clear; rpcPool overwrite guard; FS6 liveness-before-exactly-once; FS7 fallback attempt enters accounting; FS8 writer-timeout terminates wedged worker; client per-request timer unref'd; steer.push requestId dedupe; missed-cron one-time skipped event.
14
+ - **fix(hardening one-liners):** TMPDIR in child env allowlists (macOS run-lock dual-guard actually contends); escalate `to` validated; deadletter assertSafePathId; PI_TEAMS_PI_BIN path-separator boundary; submit_result error-result on throw; launch-script env-key regex; quoted `command -v` probe; classifier failureSummary redacted; tool_execution args/supervisor_contact compacted + 64KiB line cap; env-vars numeric defaults route through parsers; mock-seam double-gated; sqlite 0600; theme atomic write + no corrupt-wipe; OTLP CUMULATIVE temporality + header precedence; goal-wrap spawn-failure → blocked (no zombie goal); CI-only concurrency clamp; sweep-test-tmp age guard; watch-bundle recursion; temp-root realpath both sides; agent frontmatter ceilings; non-finite heartbeat = corrupt lock; agent-events cursor seq-sort; settings enums derived from schema (+ drift test); mailbox seam sanitize; R10-C1 duplicate-condition fix.
15
+
16
+ ### Fixed (deep review 2026-10-16/17 — Wave 1; report `pi-crew-deep-review-2026-10-16.md`, 128/128 cold-verified)
17
+
18
+ - **fix(recovery): R2-H1 — orphan reconcile persisted the FILTERED zombie subset** (tasks.json data loss, runtime-proven). `/tmp` orphan reconcile wrote `result.repairedTasks` (stale-only subset) via full-overwrite — every sibling record destroyed on a timer tick. Now persists `result.persistTasks ?? repairedTasks` (mirror of `crash-recovery.ts`); caller retention pinning test (3-task fixture: alive + zombie + completed all retained).
19
+ - **fix(scheduling): R3-H1 — coalesced-group writes used the dispatch-time snapshot** (concurrent sibling state loss, runtime-proven ×3). Terminal write (:401) and both pre-dispatch saves (:64/:89) now use the in-file `repairGroupTerminalWrite` fresh-read group-scoped merge (was wired only to the late-heartbeat path); concurrent-sibling pinning test + repair-warn companion updated.
20
+ - **fix(state): R4-A1 — agents.json requeue subset-wipe** (deterministic). Both ask-requeue paths (`dispatch-batch.ts` sweep + `respond.ts`) overwrote the authoritative index with only the requeued subset — RUNNING siblings unresolvable until next full save. Both now full-set merge (mirror `team-runner.ts:525-538`); retention tests on both paths.
21
+ - **fix(broker): R7-H1 — delegate.request params bypassed the server-side validation family** (durable budget/turn-cap sandbox escape, exploit-transcript-proven). `maxTurns`/`budgetTokens` were parsed with `typeof === "number"` only: `budgetTokens:-1e9` durably inflated remaining budget by ~1e9 (reserve decrements `tokensSpent` unclamped; refunds gated `reserved > 0` never reconcile), `maxTurns:1e999` → Infinity killed soft+hard turn caps. New `parseDelegateRequestParams` (in `broker/protocol/request-parsers.ts`, the family home): `Number.isInteger` maxTurns 1..200 + budgetTokens 0..100_000_000 (client `Type.Integer` parity), prompt ≤100k, role enum, timeoutSec finite with §7 range — rejected `bad-params` BEFORE admission and the reserve write; edge-matrix tests (15 cases from the runtime negative control).
22
+ - **fix(process): R7-A2 — zombie-scanner `isPidAlive` treated EPERM as dead** — live-but-protected workers landed in `scan.zombies` and `doctor` SIGHUPed them. Now `code !== ESRCH && code !== ENOENT → alive` (mirror of active-run-registry R7-15); EPERM pinning test.
23
+ - **fix(prompt): R7-P1 — surface workers self-terminated at 5s off-Linux** — `parentAlive`'s default `/proc` reader throws off-Linux and `return false` fired BEFORE the empty-start-time tolerance the host writer implements; guard now armed only when `/proc` is readable. Verified in clone (surface-runtime 38/38).
24
+ - **fix(event-log): FS1 + FS3**. FS1: agent-events `.seq` sidecar trusted with no regression guard — crash-window re-mints duplicate seqs that `> sinceSeq` consumers drop forever; now max(sidecar, tail-scan) like EL-1. FS3: cursor `nextSeq=max-delivered` + file-order slice stranded lower-seq events forever on documented non-monotonic files (field-confirmed in 7 runs); `filtered` is now seq-sorted before the limit slice (2 sites); the 2 file-order test pins updated to seq-order contract.
25
+ - **fix(run): R5-M-B3 — 4 bare `void appendEventAsync` in `run.ts`** (probe-proven host crash via unhandledRejection, exit=7); all now `.catch`-logged (17 other sites already were).
26
+
5
27
  ### Fixed (rounds 4–7 audit waves — DR-02/DR-03/DR-04, reports `docs/reviews/pi-crew-audit-round{4,5,6,7}-*.md`)
6
28
 
7
29
  - **fix(state): DR-03 C1 — disk-terminal status preserved + delegate allocation max-merge** (R6-1 HIGH). `persistSingleTaskUpdate` reloaded disk inside the lock but `updateTask` replaced by id UNCONDITIONALLY — a detached runner's late settle overwrote a crash-recovery `cancelled` task with `completed` and emitted `task.completed` after `crew.run.orphan_cancelled`. New `mergeTaskUpdateWithDisk()` preserves a differing disk-terminal status (result fields still recorded); post-execution derives the persisted status from the persist return (terminal events via `TERMINAL_TASK_EVENT_TYPES` — never `task.completed` over cancelled). R6-4: delegate budget reserve/roll-up now merges `tokensSpent=max(disk,incoming)` — the 1s heartbeat whole-record replace could no longer clobber a reservation (lost update), and refund over-subtraction self-heals.
@@ -5,7 +5,7 @@ model: false
5
5
  systemPromptMode: replace
6
6
  inheritProjectContext: true
7
7
  inheritSkills: false
8
- tools: read, grep, find, ls, glob, bash, ask
8
+ tools: read, grep, find, ls, glob, ask
9
9
  useWhen: "read-only mapping of files, symbols, constraints"
10
10
  avoidWhen: "any write action, external docs lookup"
11
11
  cost: free
@@ -19,7 +19,7 @@ You are a fast codebase explorer. Your job is FAST, READ-ONLY reconnaissance —
19
19
  - "File discovery" / "where does X live" → `glob` / `find`
20
20
  - "Read this specific file" → `read` with offset/limit if the file is large
21
21
  - "Directory survey" → `ls`
22
- - `bash` ONLY when a pipeline is genuinely the better diagnostic (e.g., `git log -p | head -50`). NEVER `cat`/`head`/`tail` to dump a file into context.
22
+ - No `bash` — read/grep/find/ls/glob only (read-only enforced toolset; attack-chain A hardening). Prefer targeted `grep`/`read` with line ranges over dumping files into context.
23
23
  - Structural/AST search is unavailable — approximate with targeted `grep` patterns; flag residual uncertainty in UNCERTAIN.
24
24
 
25
25
  ## Output format
@@ -37,7 +37,7 @@ ROUTING: <which downstream role should consume this — analyst|executor|planner
37
37
  ```
38
38
 
39
39
  ## Boundaries
40
- - READ-ONLY. No edit/write; bash must not mutate anything.
40
+ - READ-ONLY. No edit/write/bash.
41
41
  - Do not extract FULL file contents; return paths + line numbers.
42
42
  - If the question requires external docs/libraries (not in this repo), flag in ROUTING as "librarian" — route external-documentation questions to librarian instead of fetching them yourself.
43
43
 
@@ -5,7 +5,7 @@ model: false
5
5
  systemPromptMode: replace
6
6
  inheritProjectContext: true
7
7
  inheritSkills: false
8
- tools: read, grep, find, ls, glob, bash, ask
8
+ tools: read, grep, find, ls, glob, ask
9
9
  useWhen: "library internals and version behavior from on-disk evidence"
10
10
  avoidWhen: "repo-local code mapping, web fetching"
11
11
  cost: cheap
@@ -19,7 +19,7 @@ You are a librarian — a research specialist for documentation and dependency s
19
19
  - "What changed in version Y" → read `node_modules/<pkg>/CHANGELOG.md` + `package.json` version
20
20
  - "Official usage pattern for X" → grep the package's own README/docs/tests — tests are the most honest documentation
21
21
  - "Where is X configured in this repo" → `grep`/`glob` across the workspace, including lockfiles
22
- - `bash` ONLY for pipelines (e.g., `cat package.json | jq .dependencies`); NEVER fetch remote resources — you have no web tools; flag external needs in UNCERTAIN
22
+ - No `bash` — read/grep/find/ls/glob only (read-only enforced toolset; attack-chain A hardening). Read dependency sources directly with `read`/`grep`.
23
23
 
24
24
  ## Evidence discipline
25
25
  - Quote the exact file:line you based each claim on.
@@ -44,6 +44,6 @@ UNCERTAIN: <what requires external docs/web you could not verify locally, with r
44
44
 
45
45
  ## Anti-patterns
46
46
  - DO NOT answer API behavior from model memory without checking the installed source — memory is version-blind.
47
- - DO NOT `curl`/`wget` remote docs via bash — flag the gap in UNCERTAIN instead.
47
+ - DO NOT `curl`/`wget` remote docs (no web/bash tools) — flag the gap in UNCERTAIN instead.
48
48
  - DO NOT read entire large files; use grep to locate, then read a window.
49
49
  - DO NOT conflate this repo's local conventions with the library's official guidance.