pi-crew 0.1.51 → 0.2.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.
Files changed (239) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/README.md +176 -781
  3. package/agents/analyst.md +11 -11
  4. package/agents/critic.md +11 -11
  5. package/agents/executor.md +11 -11
  6. package/agents/explorer.md +11 -11
  7. package/agents/planner.md +11 -11
  8. package/agents/reviewer.md +11 -11
  9. package/agents/security-reviewer.md +11 -11
  10. package/agents/test-engineer.md +11 -11
  11. package/agents/verifier.md +70 -11
  12. package/agents/writer.md +11 -11
  13. package/docs/actions-reference.md +595 -0
  14. package/docs/commands-reference.md +347 -0
  15. package/docs/runtime-flow.md +148 -148
  16. package/index.ts +6 -6
  17. package/package.json +99 -99
  18. package/skills/async-worker-recovery/SKILL.md +42 -42
  19. package/skills/context-artifact-hygiene/SKILL.md +52 -52
  20. package/skills/delegation-patterns/SKILL.md +54 -54
  21. package/skills/mailbox-interactive/SKILL.md +40 -40
  22. package/skills/model-routing-context/SKILL.md +39 -39
  23. package/skills/multi-perspective-review/SKILL.md +58 -58
  24. package/skills/observability-reliability/SKILL.md +41 -41
  25. package/skills/orchestration/SKILL.md +157 -157
  26. package/skills/ownership-session-security/SKILL.md +41 -41
  27. package/skills/pi-extension-lifecycle/SKILL.md +39 -39
  28. package/skills/requirements-to-task-packet/SKILL.md +63 -63
  29. package/skills/resource-discovery-config/SKILL.md +41 -41
  30. package/skills/runtime-state-reader/SKILL.md +44 -44
  31. package/skills/secure-agent-orchestration-review/SKILL.md +45 -45
  32. package/skills/state-mutation-locking/SKILL.md +42 -42
  33. package/skills/systematic-debugging/SKILL.md +67 -67
  34. package/skills/ui-render-performance/SKILL.md +39 -39
  35. package/skills/verification-before-done/SKILL.md +57 -57
  36. package/skills/worktree-isolation/SKILL.md +39 -39
  37. package/src/adapters/claude-adapter.ts +25 -0
  38. package/src/adapters/codex-adapter.ts +21 -0
  39. package/src/adapters/cursor-adapter.ts +17 -0
  40. package/src/adapters/export-util.ts +137 -0
  41. package/src/adapters/index.ts +15 -0
  42. package/src/adapters/registry.ts +18 -0
  43. package/src/adapters/types.ts +23 -0
  44. package/src/agents/agent-config.ts +2 -0
  45. package/src/agents/agent-search.ts +98 -98
  46. package/src/agents/discover-agents.ts +2 -1
  47. package/src/config/config.ts +13 -1
  48. package/src/config/drift-detector.ts +211 -0
  49. package/src/config/markers.ts +327 -0
  50. package/src/config/resilient-parser.ts +108 -0
  51. package/src/config/suggestions.ts +74 -0
  52. package/src/extension/cross-extension-rpc.ts +103 -94
  53. package/src/extension/project-init.ts +21 -1
  54. package/src/extension/register.ts +45 -14
  55. package/src/extension/registration/commands.ts +77 -8
  56. package/src/extension/registration/subagent-tools.ts +10 -1
  57. package/src/extension/registration/team-tool.ts +10 -1
  58. package/src/extension/registration/viewers.ts +48 -34
  59. package/src/extension/run-bundle-schema.ts +89 -89
  60. package/src/extension/run-import.ts +25 -1
  61. package/src/extension/run-index.ts +5 -1
  62. package/src/extension/run-maintenance.ts +142 -68
  63. package/src/extension/team-manager-command.ts +10 -1
  64. package/src/extension/team-tool/doctor.ts +28 -3
  65. package/src/extension/team-tool/handle-settings.ts +195 -188
  66. package/src/extension/team-tool/inspect.ts +41 -41
  67. package/src/extension/team-tool/intent-policy.ts +42 -42
  68. package/src/extension/team-tool/lifecycle-actions.ts +27 -8
  69. package/src/extension/team-tool/plan.ts +19 -19
  70. package/src/extension/team-tool/run.ts +12 -1
  71. package/src/extension/team-tool.ts +11 -1
  72. package/src/i18n.ts +184 -184
  73. package/src/observability/exporters/otlp-exporter.ts +92 -77
  74. package/src/prompt/prompt-runtime.ts +72 -72
  75. package/src/runtime/agent-memory.ts +72 -72
  76. package/src/runtime/agent-observability.ts +114 -114
  77. package/src/runtime/async-marker.ts +26 -26
  78. package/src/runtime/attention-events.ts +28 -28
  79. package/src/runtime/auto-resume.ts +100 -0
  80. package/src/runtime/background-runner.ts +11 -1
  81. package/src/runtime/cancellation-token.ts +89 -89
  82. package/src/runtime/cancellation.ts +61 -61
  83. package/src/runtime/capability-inventory.ts +116 -116
  84. package/src/runtime/child-pi.ts +7 -2
  85. package/src/runtime/compaction-summary.ts +271 -0
  86. package/src/runtime/completion-guard.ts +190 -190
  87. package/src/runtime/crash-recovery.ts +33 -0
  88. package/src/runtime/delta-conflict.ts +360 -0
  89. package/src/runtime/direct-run.ts +35 -35
  90. package/src/runtime/foreground-control.ts +82 -82
  91. package/src/runtime/green-contract.ts +46 -46
  92. package/src/runtime/group-join.ts +106 -106
  93. package/src/runtime/heartbeat-gradient.ts +28 -28
  94. package/src/runtime/heartbeat-watcher.ts +124 -124
  95. package/src/runtime/iteration-hooks.ts +262 -0
  96. package/src/runtime/live-agent-control.ts +88 -88
  97. package/src/runtime/live-control-realtime.ts +36 -36
  98. package/src/runtime/live-extension-bridge.ts +150 -150
  99. package/src/runtime/live-irc.ts +92 -92
  100. package/src/runtime/live-session-health.ts +100 -100
  101. package/src/runtime/loop-gates.ts +129 -0
  102. package/src/runtime/metric-parser.ts +40 -0
  103. package/src/runtime/notebook-helpers.ts +90 -90
  104. package/src/runtime/orphan-sentinel.ts +7 -7
  105. package/src/runtime/parallel-research.ts +44 -44
  106. package/src/runtime/phase-progress.ts +217 -0
  107. package/src/runtime/pi-args.ts +38 -11
  108. package/src/runtime/pi-json-output.ts +111 -111
  109. package/src/runtime/pi-spawn.ts +57 -7
  110. package/src/runtime/policy-engine.ts +79 -79
  111. package/src/runtime/post-checks.ts +122 -0
  112. package/src/runtime/progress-event-coalescer.ts +43 -43
  113. package/src/runtime/prose-compressor.ts +164 -164
  114. package/src/runtime/recovery-recipes.ts +74 -74
  115. package/src/runtime/result-extractor.ts +121 -121
  116. package/src/runtime/role-permission.ts +39 -39
  117. package/src/runtime/sensitive-paths.ts +2 -2
  118. package/src/runtime/session-resources.ts +25 -25
  119. package/src/runtime/session-snapshot.ts +59 -59
  120. package/src/runtime/session-usage.ts +79 -79
  121. package/src/runtime/sidechain-output.ts +29 -29
  122. package/src/runtime/stream-preview.ts +177 -177
  123. package/src/runtime/supervisor-contact.ts +59 -59
  124. package/src/runtime/task-display.ts +38 -38
  125. package/src/runtime/task-graph.ts +207 -0
  126. package/src/runtime/task-quality.ts +207 -0
  127. package/src/runtime/task-runner/capabilities.ts +78 -78
  128. package/src/runtime/task-runner/live-executor.ts +7 -1
  129. package/src/runtime/task-runner/progress.ts +119 -119
  130. package/src/runtime/task-runner/prompt-pipeline.ts +64 -64
  131. package/src/runtime/task-runner/result-utils.ts +14 -14
  132. package/src/runtime/task-runner/run-projection.ts +103 -103
  133. package/src/runtime/task-runner/state-helpers.ts +22 -22
  134. package/src/runtime/team-runner.ts +117 -7
  135. package/src/runtime/worker-heartbeat.ts +21 -21
  136. package/src/runtime/worker-startup.ts +57 -57
  137. package/src/runtime/workflow-state.ts +187 -0
  138. package/src/runtime/workspace-tree.ts +298 -298
  139. package/src/schema/config-schema.ts +11 -0
  140. package/src/schema/validation-types.ts +148 -0
  141. package/src/skills/skill-templates.ts +374 -0
  142. package/src/state/active-run-registry.ts +35 -11
  143. package/src/state/atomic-write.ts +33 -26
  144. package/src/state/contracts.ts +1 -0
  145. package/src/state/event-reconstructor.ts +217 -0
  146. package/src/state/locks.ts +2 -13
  147. package/src/state/mailbox.ts +4 -3
  148. package/src/state/state-store.ts +32 -14
  149. package/src/state/task-claims.ts +44 -44
  150. package/src/state/types.ts +9 -0
  151. package/src/state/usage.ts +29 -29
  152. package/src/subagents/async-entry.ts +1 -1
  153. package/src/subagents/index.ts +3 -3
  154. package/src/subagents/live/control.ts +1 -1
  155. package/src/subagents/live/manager.ts +1 -1
  156. package/src/subagents/live/realtime.ts +1 -1
  157. package/src/subagents/live/session-runtime.ts +1 -1
  158. package/src/subagents/manager.ts +1 -1
  159. package/src/subagents/spawn.ts +1 -1
  160. package/src/teams/team-serializer.ts +38 -38
  161. package/src/types/diff.d.ts +18 -18
  162. package/src/ui/crew-footer.ts +101 -101
  163. package/src/ui/crew-select-list.ts +111 -111
  164. package/src/ui/crew-widget.ts +5 -2
  165. package/src/ui/dashboard-panes/cancellation-pane.ts +42 -42
  166. package/src/ui/dashboard-panes/capability-pane.ts +59 -59
  167. package/src/ui/dashboard-panes/mailbox-pane.ts +35 -35
  168. package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
  169. package/src/ui/dashboard-panes/progress-pane.ts +11 -0
  170. package/src/ui/dynamic-border.ts +25 -25
  171. package/src/ui/layout-primitives.ts +106 -106
  172. package/src/ui/loaders.ts +158 -158
  173. package/src/ui/render-coalescer.ts +51 -51
  174. package/src/ui/render-diff.ts +119 -119
  175. package/src/ui/render-scheduler.ts +143 -143
  176. package/src/ui/run-action-dispatcher.ts +10 -1
  177. package/src/ui/spinner.ts +17 -17
  178. package/src/ui/status-colors.ts +58 -58
  179. package/src/ui/syntax-highlight.ts +116 -116
  180. package/src/ui/transcript-entries.ts +258 -258
  181. package/src/utils/completion-dedupe.ts +63 -63
  182. package/src/utils/frontmatter.ts +68 -68
  183. package/src/utils/git.ts +262 -262
  184. package/src/utils/ids.ts +17 -17
  185. package/src/utils/incremental-reader.ts +104 -104
  186. package/src/utils/names.ts +27 -27
  187. package/src/utils/redaction.ts +44 -44
  188. package/src/utils/safe-paths.ts +47 -47
  189. package/src/utils/scan-cache.ts +136 -136
  190. package/src/utils/sleep.ts +40 -26
  191. package/src/utils/task-name-generator.ts +337 -337
  192. package/src/workflows/validate-workflow.ts +40 -40
  193. package/src/worktree/branch-freshness.ts +45 -45
  194. package/teams/default.team.md +12 -12
  195. package/teams/fast-fix.team.md +11 -11
  196. package/teams/implementation.team.md +18 -18
  197. package/teams/parallel-research.team.md +14 -14
  198. package/teams/research.team.md +11 -11
  199. package/teams/review.team.md +12 -12
  200. package/workflows/default.workflow.md +30 -29
  201. package/workflows/fast-fix.workflow.md +23 -22
  202. package/workflows/implementation.workflow.md +43 -43
  203. package/workflows/parallel-research.workflow.md +46 -46
  204. package/workflows/research.workflow.md +22 -22
  205. package/workflows/review.workflow.md +30 -30
  206. package/docs/refactor-tasks-phase3.md +0 -394
  207. package/docs/refactor-tasks-phase4.md +0 -564
  208. package/docs/refactor-tasks-phase5.md +0 -402
  209. package/docs/refactor-tasks-phase6.md +0 -662
  210. package/docs/refactor-tasks.md +0 -1484
  211. package/docs/research/AGENT-EXECUTION-ARCHITECTURE.md +0 -261
  212. package/docs/research/AGENT-LIFECYCLE-COMPARISON.md +0 -111
  213. package/docs/research/AUDIT_OH_MY_PI.md +0 -261
  214. package/docs/research/AUDIT_PI_CREW.md +0 -457
  215. package/docs/research/CAVEMAN-DEEP-RESEARCH.md +0 -281
  216. package/docs/research/COMPARISON_OH_MY_PI_VS_PI_CREW.md +0 -264
  217. package/docs/research/DEEP-RESEARCH-PI-POWERBAR.md +0 -343
  218. package/docs/research/DEEP_RESEARCH_SUBAGENT_ARCHITECTURE.md +0 -480
  219. package/docs/research/GAP_CLOSURE_IMPLEMENTATION_PLAN.md +0 -354
  220. package/docs/research/IMPLEMENTATION_PLAN.md +0 -385
  221. package/docs/research/LIVE-SESSION-PRODUCTION-READY-PLAN.md +0 -502
  222. package/docs/research/OH-MY-PI-DEEP-RESEARCH-v14.7.6.md +0 -266
  223. package/docs/research/REMAINING-GAPS-PLAN.md +0 -363
  224. package/docs/research/SESSION-SUMMARY-2026-05-08.md +0 -146
  225. package/docs/research/UI-RESPONSIVENESS-AUDIT.md +0 -173
  226. package/docs/research-awesome-agent-skills-distillation.md +0 -100
  227. package/docs/research-extension-examples.md +0 -297
  228. package/docs/research-extension-system.md +0 -324
  229. package/docs/research-oh-my-pi-distillation.md +0 -369
  230. package/docs/research-optimization-plan.md +0 -548
  231. package/docs/research-phase10-distillation.md +0 -199
  232. package/docs/research-phase11-distillation.md +0 -201
  233. package/docs/research-phase8-operator-experience-plan.md +0 -819
  234. package/docs/research-phase9-observability-reliability-plan.md +0 -1190
  235. package/docs/research-pi-coding-agent.md +0 -357
  236. package/docs/research-source-pi-crew-reference.md +0 -174
  237. package/docs/research-ui-optimization-plan.md +0 -480
  238. package/docs/source-runtime-refactor-map.md +0 -107
  239. package/src/utils/atomic-write.ts +0 -33
@@ -1,369 +0,0 @@
1
- # oh-my-pi Distillation for pi-crew
2
-
3
- Date: 2026-05-05
4
- Source repo: `Source/oh-my-pi` at `1d898a7fe chore: bump version to 14.5.3`.
5
-
6
- ## Scope Read
7
-
8
- Read-only exploration covered four source areas:
9
-
10
- - Agent/provider runtime: `packages/agent`, `packages/ai`.
11
- - Main CLI/session/task implementation: `packages/coding-agent`.
12
- - TUI, extensions, hooks, skills, marketplace, rulebook docs and implementation.
13
- - Native/Rust reliability/performance/release docs and implementation.
14
-
15
- Representative files and docs inspected:
16
-
17
- - `packages/agent/src/agent-loop.ts`, `packages/agent/src/agent.ts`, `packages/agent/src/types.ts`.
18
- - `packages/ai/src/stream.ts`, `packages/ai/src/model-manager.ts`, `packages/ai/src/utils/{abort,retry,event-stream,overflow}.ts`, provider adapters.
19
- - `packages/coding-agent/src/session/*`, `src/extensibility/{hooks,slash-commands,skills,plugins}/*`, `src/task/*`, `src/edit/*`, prompts.
20
- - `packages/tui/src/tui.ts`, `docs/tui*.md`, `docs/extensions.md`, `docs/hooks.md`, `docs/skills.md`, `docs/marketplace.md`, `docs/rulebook-matching-pipeline.md`.
21
- - `crates/pi-natives/src/{task,shell,pty,fs_cache,glob,fd,grep}.rs`, natives docs, install/release scripts.
22
-
23
- This document rewrites the useful ideas as pi-crew-native patterns. It does not vendor or copy source code.
24
-
25
- ## High-Value Patterns to Adopt
26
-
27
- ### 1. Separate durable run history from provider/model context
28
-
29
- oh-my-pi keeps rich internal session messages separate from LLM-compatible provider messages. Custom events, UI messages, hook entries, and branch/compaction entries can live in durable history, while a conversion layer decides what reaches the model.
30
-
31
- pi-crew application:
32
-
33
- - Keep `TeamRunManifest`, task records, mailbox messages, artifacts, worker events, and review/verification notes as durable run history.
34
- - Add a projection/conversion step before worker prompt/model invocation:
35
- - `transformRunContextBeforeWorkerStart(...)` for pruning/context injection.
36
- - `convertRunHistoryToWorkerPrompt(...)` for provider/child-Pi compatible text.
37
- - Avoid treating UI/runtime events as prompt text by default.
38
-
39
- Benefit: safer compaction, mailbox summarization, and artifact hygiene without losing durable audit history.
40
-
41
- ### 2. Distinguish steering from follow-up
42
-
43
- oh-my-pi's agent runtime distinguishes interrupting current work (`steer`) from continuing after the agent would otherwise stop (`followUp`).
44
-
45
- pi-crew application:
46
-
47
- - Model leader/operator messages as two queues:
48
- - `steeringQueue`: urgent cancellation, nudge, priority change, user answer while worker is active.
49
- - `followUpQueue`: review/verification/documentation after a task reaches a natural stop.
50
- - Default to one-at-a-time delivery to reduce context shock.
51
- - Persist queue entries and delivery status in task mailbox/state.
52
-
53
- Benefit: clearer interactive semantics than a single generic respond/resume path.
54
-
55
- ### 3. Preserve invariants on cancellation and abort
56
-
57
- oh-my-pi propagates `AbortSignal` through model streaming and tool execution, distinguishes caller abort from provider-local watchdog abort, and emits synthetic tool results when abort happens after tool calls were started.
58
-
59
- pi-crew application:
60
-
61
- - Use structured cancel reasons:
62
- - `caller_cancelled`
63
- - `leader_interrupted`
64
- - `provider_timeout`
65
- - `worker_timeout`
66
- - `tool_timeout`
67
- - `shutdown`
68
- - If a worker/tool/action has started but is cancelled, emit a terminal synthetic event/result so task history has no dangling operation.
69
- - Add non-abortable cleanup/finalize phases for artifact preservation and state unlock.
70
-
71
- Benefit: fewer stuck `running` tasks and clearer recovery after cancellation.
72
-
73
- ### 4. Batch-aware execution with shared vs exclusive operations
74
-
75
- oh-my-pi marks tools with concurrency semantics: shared tools can run concurrently, exclusive tools serialize around shared/exclusive peers, and queued tools can be skipped when steering arrives.
76
-
77
- pi-crew application:
78
-
79
- - Classify worker subtasks or internal operations:
80
- - shared: read-only exploration, status, grep, artifact reads.
81
- - exclusive: edits, package manifests, lockfiles, migration/schema updates, worktree merge.
82
- - Attach `batchId`, `index`, `total`, and `conflictKey` metadata to task execution.
83
- - On new steering, skip not-yet-started low-priority operations with explicit skip reason.
84
-
85
- Benefit: safer parallelism and more auditable conflict handling.
86
-
87
- ### 5. Intent tracing for destructive/tool actions
88
-
89
- oh-my-pi optionally injects an intent field into tool schemas, strips it before execution, and keeps it for auditability.
90
-
91
- pi-crew application:
92
-
93
- - Add optional `_intent`/`intent` metadata to worker tool/action events.
94
- - Require intent for destructive actions: cancel, delete, prune, force cleanup, edits, package publish, worktree removal.
95
- - Store intent in events/artifacts but never pass it to low-level execution APIs if not needed.
96
-
97
- Benefit: reviewable why/what for high-risk actions without changing execution payloads.
98
-
99
- ### 6. Event-first UI with tiny component contract and coalesced rendering
100
-
101
- oh-my-pi TUI uses small components (`render(width)`, `handleInput`, `invalidate`) and event-driven, coalesced rendering. Components must be width-safe and lifecycle-clean.
102
-
103
- pi-crew application:
104
-
105
- - Keep dashboards/widgets as projections from snapshot/event state, not direct filesystem scanners.
106
- - Continue using render scheduler/coalescing; add width-safety tests for all dashboard panes/widgets.
107
- - Components should expose `dispose()` for timers/theme subscriptions.
108
- - UI event stream should be semantic (`task_started`, `worker_status`, `mailbox_updated`) rather than raw file polling.
109
-
110
- Benefit: avoids UI freezes and makes live views predictable.
111
-
112
- ### 7. Two-phase extension lifecycle
113
-
114
- oh-my-pi extensions have a registration phase where side-effecting runtime methods are unavailable, followed by an initialized phase with real context/actions.
115
-
116
- pi-crew application:
117
-
118
- - If pi-crew grows plugin/extension support, split APIs into:
119
- - `registerCrewExtension(api)`: declare teams, workflows, hooks, commands, renderers.
120
- - `initializeCrewExtension(context)`: subscribe to events, perform side effects.
121
- - In headless mode, UI APIs should be explicit no-ops or unavailable via `hasUI`.
122
- - Loader should collect extension errors without breaking builtin teams.
123
-
124
- Benefit: fewer load-time side effects and safer third-party extensibility.
125
-
126
- ### 8. Unified capability inventory/control center
127
-
128
- oh-my-pi normalizes extensions, skills, rules, tools, hooks, MCPs, prompts, and slash commands into a shared dashboard model with active/disabled/shadowed states.
129
-
130
- pi-crew application:
131
-
132
- - Extend `/team-settings` or add `/team-control` to show a unified inventory:
133
- - teams, workflows, agents, skills, hooks/policies, tools, runtime providers.
134
- - Normalize each item to:
135
- - `id`, `kind`, `name`, `description`, `source`, `path`, `state`, `disabledReason`, `shadowedBy`, `raw`.
136
- - Persist disables by stable capability ID, not file path.
137
-
138
- Benefit: better operator experience for complex multi-resource setups.
139
-
140
- ### 9. Hooks as typed lifecycle gates, not ad-hoc shell glue
141
-
142
- oh-my-pi hooks cover session lifecycle, before-agent-start, tool-call gates, tool-result transforms, and compaction events. Blocking hooks are scoped; non-blocking hook errors are captured but do not crash streaming.
143
-
144
- pi-crew application:
145
-
146
- - Define typed crew hooks:
147
- - `before_run_start`
148
- - `before_task_start`
149
- - `task_result`
150
- - `before_cancel`
151
- - `before_publish`
152
- - `session_before_switch`
153
- - `run_recovery`
154
- - Mark hooks as blocking or non-blocking.
155
- - Capture hook errors into diagnostics/status, not uncontrolled exceptions.
156
-
157
- Benefit: safer customization for policy/security/release gates.
158
-
159
- ### 10. Prompt pipeline should be explicit
160
-
161
- oh-my-pi applies slash/custom commands, templates, compaction, file mentions, hook injection, and model validation in a clear order before calling the agent.
162
-
163
- pi-crew application:
164
-
165
- Define a worker prompt pipeline:
166
-
167
- 1. Parse orchestration command/control intent.
168
- 2. Expand prompt templates/task packet.
169
- 3. Attach selected context/artifact/mailbox summaries.
170
- 4. Run `before_worker_start` hooks.
171
- 5. Persist exact task packet/artifacts.
172
- 6. Launch worker.
173
-
174
- Benefit: reproducible worker prompts and easier debugging of context injection.
175
-
176
- ### 11. Session/run history as append-only tree
177
-
178
- oh-my-pi persists session entries with parent relationships. Branching/forking moves the current leaf rather than rewriting past history.
179
-
180
- pi-crew application:
181
-
182
- - Keep `events.jsonl` append-only and add optional `parentEventId` / `attemptId` / `branchId` fields for retries/forks.
183
- - Represent retry attempts as child branches from the original task prompt/result.
184
- - Preserve old failed attempts instead of overwriting task state only.
185
-
186
- Benefit: better auditability and replay/debug of retries.
187
-
188
- ### 12. Cooperative cancellation token for long loops
189
-
190
- oh-my-pi native code uses cancel tokens with deadlines, abort signals, `heartbeat()`, and async wait. Long loops over external-size input must heartbeat at bounded cadence.
191
-
192
- pi-crew application:
193
-
194
- - Add a TS `CancellationToken` utility for internal long-running loops:
195
- - `heartbeat(stage?: string)`
196
- - `throwIfCancelled()`
197
- - `wait()`
198
- - `abort(reason)`
199
- - Require it in scanners over runs, artifacts, mailboxes, worktrees, and event logs.
200
-
201
- Benefit: bounded shutdown/cancel latency and easier stuck-loop diagnostics.
202
-
203
- ### 13. Process lifecycle: graceful cancel, forced kill, then non-reuse
204
-
205
- oh-my-pi shell/PTY runtime cancels gracefully, waits a grace window, forces abort/kill, drains output for bounded windows, and discards persistent sessions after cancellation/errors.
206
-
207
- pi-crew application:
208
-
209
- - For child Pi workers:
210
- - send graceful abort/TERM;
211
- - wait `graceMs`;
212
- - force-kill process tree;
213
- - drain stdout/stderr for bounded time;
214
- - mark session non-reusable after timeout/protocol error/cancel.
215
- - Return typed status `{ exitCode, cancelled, timedOut, killed, cleanupErrors }`.
216
-
217
- Benefit: more deterministic worker cleanup and fewer zombie/stale runs.
218
-
219
- ### 14. Reserve control channel before async worker start
220
-
221
- oh-my-pi PTY reserves its control channel before async process start, rejects duplicate starts, and always clears state in completion.
222
-
223
- pi-crew application:
224
-
225
- - Install a `WorkerRunCore`/controller synchronously before spawn returns.
226
- - Expose cancel/steer immediately, even while startup is still in progress.
227
- - Clear controller in `finally` and persist terminal state.
228
-
229
- Benefit: closes race windows where operator cannot cancel a starting worker.
230
-
231
- ### 15. Cache scan entries, not final query results
232
-
233
- oh-my-pi native search caches directory entries and applies query-specific filters/scoring later. Empty stale caches trigger rescan; ordering is deterministic.
234
-
235
- pi-crew application:
236
-
237
- - For run/artifact/mailbox discovery, cache raw entries/stats rather than final UI results.
238
- - Apply active-status/mailbox/health filters after cache retrieval.
239
- - Invalidate cache after state mutation.
240
- - Use deterministic sort keys for dashboards and summaries.
241
-
242
- Benefit: faster UI/status with fewer stale semantic bugs.
243
-
244
- ### 16. Blob artifacts and bounded file access
245
-
246
- oh-my-pi blob-artifact design uses content addressing, metadata sidecars, streaming writes, size budgets, manifest GC, and path whitelisting.
247
-
248
- pi-crew application:
249
-
250
- - Introduce content-addressed large artifacts for worker transcripts/screenshots/log chunks.
251
- - Persist metadata sidecars with MIME, source, redaction, run/task IDs, size, hash.
252
- - Keep task prompts/results small by referencing artifact IDs.
253
- - Add GC tied to run retention.
254
-
255
- Benefit: avoids bloating task JSON/events and improves artifact security.
256
-
257
- ### 17. Native/release verification checklist mindset
258
-
259
- oh-my-pi release scripts emphasize multi-platform build artifacts, install smoke tests, spoofed-version checks, and runtime loader fallback diagnostics.
260
-
261
- pi-crew application:
262
-
263
- - For npm releases, keep a release checklist with:
264
- - typecheck;
265
- - unit/integration tests;
266
- - `npm pack --dry-run`;
267
- - install from packed tarball in temp project;
268
- - Pi extension load smoke;
269
- - version/tag/npm consistency check.
270
-
271
- Benefit: fewer broken published packages.
272
-
273
- ## Skill/Rulebook Ideas to Port
274
-
275
- oh-my-pi's skills/rulebook ecosystem suggests additional pi-crew resources:
276
-
277
- 1. `worker-prompt-pipeline` skill: prompt assembly, context projection, before-worker hooks, artifact references.
278
- 2. `typed-hook-design` skill: lifecycle gates, blocking vs non-blocking hooks, diagnostics.
279
- 3. `process-cancellation-contract` skill: graceful/force kill, synthetic terminal results, non-reuse.
280
- 4. `capability-inventory-ux` skill: normalized resource inventory and disable/shadow semantics.
281
- 5. `append-only-run-history` skill: event tree, branch/retry provenance.
282
-
283
- ## Implementation Status as of `v0.1.46`
284
-
285
- This distillation has been **partially implemented**. It should remain open as a source of backlog items rather than be marked fully complete.
286
-
287
- ### Implemented / mostly implemented
288
-
289
- - Real worker default, explicit scaffold mode, and disabled-worker blocking.
290
- - Structured cancellation reasons and worker-level terminal evidence for cancelled child workers.
291
- - Prompt pipeline artifacts and exact per-task prompt/capability metadata artifacts.
292
- - Runtime safety metadata persisted on run manifests/status.
293
- - Effectiveness evidence surfaced in status/summary/progress.
294
- - Retry attempt IDs and deadletter linkage.
295
- - Render coalescing/snapshot caching improvements that reduce hot-path UI work.
296
- - Release checklist basics: typecheck, unit/integration tests, and `npm pack --dry-run` are part of `npm run ci`.
297
- - Steering vs follow-up: `/team-follow-up` command implemented, mailbox kind filter, separate from `/team-respond`.
298
- - Typed hook lifecycle: all 9 hooks defined; 8 wired (before_run_start, before_task_start, task_result, before_cancel, before_forget, before_cleanup, before_publish, run_recovery). Only session_before_switch unwired.
299
- - Event-first UI: RunEventBus wired into appendEvent, snapshot cache, dashboard, widget, sidebar for event-driven invalidation.
300
- - Cooperative CancellationToken wired into long scans (collectRuns, listRuns, listRecentRuns, listRunsByScope, validateMailbox, readAllMailboxMessages, pruneFinishedRuns, cleanupRunWorktrees).
301
- - Content-addressed blob artifact store with SHA-256 dedup and metadata sidecars.
302
- - Raw scan-entry cache (SharedScanCache) shared by run-index manifest reads and active-run-registry.
303
- - Unified capability inventory model with stable `kind:name` IDs and policy-driven disable.
304
- - Append-only run-history tree with event provenance (parentEventId, attemptId, branchId, causationId, correlationId).
305
- - Worker process controller reserved before spawn (ControlReservation in agent-control.ts).
306
- - Release hardening: `npm run smoke:release` automates tarball install + version consistency check.
307
- - Effectiveness policy enforcement: default guard escalates warn to blocked for mutating-role tasks.
308
- - Two-phase worker teardown via WorkerExitStatus.
309
-
310
- ### Partial
311
-
312
- - Cancellation invariants: `worker.cancelled` evidence exists, but generic synthetic `tool.cancelled` / model-operation terminal records are missing.
313
- - Durable history vs prompt projection: durable artifacts exist, projection functions exist (`run-projection.ts`), but not yet separated from prompt building in all paths.
314
- - Two-phase pi-crew extension lifecycle for third-party crew plugins (not yet needed).
315
-
316
- ### Missing / backlog
317
-
318
- - Shared/exclusive operation metadata (`batchId`, `index`, `total`, `conflictKey`) and skip-on-steering semantics.
319
- - Generic synthetic tool cancellation evidence for model operations.
320
- - `session_before_switch` hook wiring (no cwd switch mechanism in current codebase).
321
-
322
- ## Prioritized Backlog for pi-crew
323
-
324
- ### P0 / Done ✅
325
-
326
- - Fix current runtime review findings: waiting final status, respond semantics, no-registry model routing.
327
- - Add structured cancellation reason and terminal synthetic result/event for cancelled workers.
328
- - Centralize worker prompt pipeline and persist exact prompt packets.
329
-
330
- ### P1 / Done ✅
331
-
332
- - Add steering vs follow-up mailbox queues (kind filter + `/team-follow-up`).
333
- - Add typed hook lifecycle for all 9 hooks (8 wired, session_before_switch placeholder).
334
- - Add capability inventory model for teams/workflows/agents/skills/hooks/tools.
335
- - Add `CancellationToken` for long internal loops and scans.
336
-
337
- ### P2 / Done ✅
338
-
339
- - Append-only run-history tree with attempt/branch parentage.
340
- - Content-addressed blob artifact store with metadata sidecars.
341
- - Worker process controller installed before spawn; control channel reservation.
342
- - Raw scan-entry cache shared by dashboard/status/artifact lookup.
343
- - Event-first UI with RunEventBus subscriptions.
344
- - Release smoke test automation.
345
-
346
- ### P3 / Remaining
347
-
348
- - Shared/exclusive operation metadata and skip-on-steering semantics.
349
- - Generic synthetic tool cancellation evidence for model operations.
350
- - Two-phase extension lifecycle for third-party crew plugins.
351
- - `session_before_switch` hook wiring (awaiting cwd switch mechanism).
352
-
353
- ## Anti-Patterns to Avoid
354
-
355
- - Building prompts from scattered inline string concatenation without a traceable pipeline.
356
- - Treating UI render as a place to perform heavy filesystem scans.
357
- - Auto-opening modal/right-sidebar UI by default when a compact widget/status line would suffice.
358
- - Dropping queued user-facing results just because session generation changed.
359
- - Cancelling a task without writing a terminal event/result.
360
- - Caching semantic query results that should be recomputed from raw state.
361
- - Letting one bad extension/resource prevent builtin operation.
362
-
363
- ## Immediate Review Questions for Future Implementation
364
-
365
- - Should pi-crew project-local skills be allowed to shadow builtin safety skills by default, or require explicit `project:` namespace?
366
- - Should `respond` enqueue durable work or only deliver to live workers? Current semantics need to become explicit.
367
- - What is the stable capability ID scheme for teams/workflows/agents/skills/hooks?
368
- - Which hook events should be blocking by default and which should be diagnostic-only?
369
- - What artifact size threshold should trigger blob storage instead of embedding content in task/events JSON?