pi-crew 0.1.46 → 0.1.49

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 (253) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/agents/analyst.md +11 -11
  3. package/agents/critic.md +11 -11
  4. package/agents/executor.md +11 -11
  5. package/agents/explorer.md +11 -11
  6. package/agents/planner.md +11 -11
  7. package/agents/reviewer.md +11 -11
  8. package/agents/security-reviewer.md +11 -11
  9. package/agents/test-engineer.md +11 -11
  10. package/agents/verifier.md +11 -11
  11. package/agents/writer.md +11 -11
  12. package/docs/next-upgrade-roadmap.md +117 -42
  13. package/docs/refactor-tasks-phase3.md +394 -394
  14. package/docs/refactor-tasks-phase4.md +564 -564
  15. package/docs/refactor-tasks-phase5.md +402 -402
  16. package/docs/refactor-tasks-phase6.md +662 -662
  17. package/docs/research/AGENT-EXECUTION-ARCHITECTURE.md +261 -0
  18. package/docs/research/AGENT-LIFECYCLE-COMPARISON.md +111 -0
  19. package/docs/research/AUDIT_OH_MY_PI.md +261 -0
  20. package/docs/research/AUDIT_PI_CREW.md +457 -0
  21. package/docs/research/CAVEMAN-DEEP-RESEARCH.md +281 -0
  22. package/docs/research/COMPARISON_OH_MY_PI_VS_PI_CREW.md +264 -0
  23. package/docs/research/DEEP-RESEARCH-PI-POWERBAR.md +343 -0
  24. package/docs/research/DEEP_RESEARCH_SUBAGENT_ARCHITECTURE.md +480 -0
  25. package/docs/research/GAP_CLOSURE_IMPLEMENTATION_PLAN.md +354 -0
  26. package/docs/research/IMPLEMENTATION_PLAN.md +385 -0
  27. package/docs/research/LIVE-SESSION-PRODUCTION-READY-PLAN.md +502 -0
  28. package/docs/research/OH-MY-PI-DEEP-RESEARCH-v14.7.6.md +266 -0
  29. package/docs/research/REMAINING-GAPS-PLAN.md +363 -0
  30. package/docs/research/SESSION-SUMMARY-2026-05-08.md +146 -0
  31. package/docs/research/UI-RESPONSIVENESS-AUDIT.md +173 -0
  32. package/docs/research-awesome-agent-skills-distillation.md +100 -100
  33. package/docs/research-extension-examples.md +297 -297
  34. package/docs/research-extension-system.md +324 -324
  35. package/docs/research-oh-my-pi-distillation.md +56 -9
  36. package/docs/research-optimization-plan.md +548 -548
  37. package/docs/research-phase10-distillation.md +198 -198
  38. package/docs/research-phase11-distillation.md +201 -201
  39. package/docs/research-pi-coding-agent.md +357 -357
  40. package/docs/research-source-pi-crew-reference.md +174 -174
  41. package/docs/runtime-flow.md +148 -148
  42. package/docs/source-runtime-refactor-map.md +107 -107
  43. package/index.ts +6 -6
  44. package/package.json +99 -98
  45. package/schema.json +8 -0
  46. package/skills/async-worker-recovery/SKILL.md +42 -42
  47. package/skills/context-artifact-hygiene/SKILL.md +52 -52
  48. package/skills/delegation-patterns/SKILL.md +54 -54
  49. package/skills/mailbox-interactive/SKILL.md +40 -40
  50. package/skills/model-routing-context/SKILL.md +39 -39
  51. package/skills/multi-perspective-review/SKILL.md +58 -58
  52. package/skills/observability-reliability/SKILL.md +41 -41
  53. package/skills/orchestration/SKILL.md +157 -0
  54. package/skills/ownership-session-security/SKILL.md +41 -41
  55. package/skills/pi-extension-lifecycle/SKILL.md +39 -39
  56. package/skills/requirements-to-task-packet/SKILL.md +63 -63
  57. package/skills/resource-discovery-config/SKILL.md +41 -41
  58. package/skills/runtime-state-reader/SKILL.md +44 -44
  59. package/skills/secure-agent-orchestration-review/SKILL.md +45 -45
  60. package/skills/state-mutation-locking/SKILL.md +42 -42
  61. package/skills/systematic-debugging/SKILL.md +67 -67
  62. package/skills/ui-render-performance/SKILL.md +39 -39
  63. package/skills/verification-before-done/SKILL.md +57 -57
  64. package/skills/worktree-isolation/SKILL.md +39 -39
  65. package/src/agents/agent-config.ts +6 -0
  66. package/src/agents/agent-search.ts +98 -0
  67. package/src/agents/agent-serializer.ts +4 -0
  68. package/src/agents/discover-agents.ts +17 -4
  69. package/src/config/config.ts +24 -0
  70. package/src/config/defaults.ts +11 -0
  71. package/src/extension/autonomous-policy.ts +26 -33
  72. package/src/extension/cross-extension-rpc.ts +82 -82
  73. package/src/extension/help.ts +1 -0
  74. package/src/extension/management.ts +5 -0
  75. package/src/extension/register.ts +58 -13
  76. package/src/extension/registration/commands.ts +33 -1
  77. package/src/extension/registration/compaction-guard.ts +125 -125
  78. package/src/extension/registration/team-tool.ts +6 -4
  79. package/src/extension/run-bundle-schema.ts +89 -89
  80. package/src/extension/run-index.ts +24 -18
  81. package/src/extension/run-maintenance.ts +68 -62
  82. package/src/extension/team-tool/api.ts +23 -2
  83. package/src/extension/team-tool/cancel.ts +86 -11
  84. package/src/extension/team-tool/context.ts +3 -0
  85. package/src/extension/team-tool/handle-settings.ts +188 -188
  86. package/src/extension/team-tool/inspect.ts +41 -41
  87. package/src/extension/team-tool/intent-policy.ts +42 -0
  88. package/src/extension/team-tool/lifecycle-actions.ts +47 -18
  89. package/src/extension/team-tool/parallel-dispatch.ts +156 -0
  90. package/src/extension/team-tool/plan.ts +19 -19
  91. package/src/extension/team-tool/respond.ts +10 -2
  92. package/src/extension/team-tool/run.ts +3 -2
  93. package/src/extension/team-tool/status.ts +1 -1
  94. package/src/extension/team-tool-types.ts +1 -0
  95. package/src/extension/team-tool.ts +13 -3
  96. package/src/hooks/registry.ts +61 -0
  97. package/src/hooks/types.ts +41 -0
  98. package/src/i18n.ts +184 -184
  99. package/src/observability/exporters/otlp-exporter.ts +77 -77
  100. package/src/prompt/prompt-runtime.ts +72 -72
  101. package/src/runtime/agent-control.ts +108 -2
  102. package/src/runtime/agent-memory.ts +72 -72
  103. package/src/runtime/agent-observability.ts +114 -114
  104. package/src/runtime/async-marker.ts +26 -26
  105. package/src/runtime/async-runner.ts +3 -1
  106. package/src/runtime/attention-events.ts +28 -28
  107. package/src/runtime/background-runner.ts +19 -0
  108. package/src/runtime/cancellation-token.ts +89 -0
  109. package/src/runtime/cancellation.ts +61 -51
  110. package/src/runtime/capability-inventory.ts +116 -0
  111. package/src/runtime/child-pi.ts +2 -1
  112. package/src/runtime/code-summary.ts +247 -0
  113. package/src/runtime/completion-guard.ts +190 -190
  114. package/src/runtime/crash-recovery.ts +181 -0
  115. package/src/runtime/crew-agent-records.ts +35 -7
  116. package/src/runtime/crew-agent-runtime.ts +1 -0
  117. package/src/runtime/custom-tools/irc-tool.ts +201 -0
  118. package/src/runtime/custom-tools/submit-result-tool.ts +90 -0
  119. package/src/runtime/delivery-coordinator.ts +3 -1
  120. package/src/runtime/direct-run.ts +35 -35
  121. package/src/runtime/effectiveness.ts +81 -76
  122. package/src/runtime/event-stream-bridge.ts +90 -0
  123. package/src/runtime/foreground-control.ts +82 -82
  124. package/src/runtime/green-contract.ts +46 -46
  125. package/src/runtime/group-join.ts +106 -106
  126. package/src/runtime/heartbeat-gradient.ts +28 -28
  127. package/src/runtime/heartbeat-watcher.ts +124 -124
  128. package/src/runtime/live-agent-control.ts +88 -88
  129. package/src/runtime/live-agent-manager.ts +78 -2
  130. package/src/runtime/live-control-realtime.ts +36 -36
  131. package/src/runtime/live-extension-bridge.ts +150 -0
  132. package/src/runtime/live-irc.ts +92 -0
  133. package/src/runtime/live-session-health.ts +100 -0
  134. package/src/runtime/live-session-runtime.ts +297 -7
  135. package/src/runtime/mcp-proxy.ts +113 -0
  136. package/src/runtime/notebook-helpers.ts +90 -0
  137. package/src/runtime/orphan-sentinel.ts +7 -0
  138. package/src/runtime/output-validator.ts +187 -0
  139. package/src/runtime/parallel-research.ts +44 -44
  140. package/src/runtime/parallel-utils.ts +57 -0
  141. package/src/runtime/parent-guard.ts +80 -0
  142. package/src/runtime/pi-json-output.ts +111 -111
  143. package/src/runtime/policy-engine.ts +79 -79
  144. package/src/runtime/progress-event-coalescer.ts +43 -43
  145. package/src/runtime/prose-compressor.ts +164 -0
  146. package/src/runtime/recovery-recipes.ts +74 -74
  147. package/src/runtime/result-extractor.ts +121 -0
  148. package/src/runtime/role-permission.ts +39 -39
  149. package/src/runtime/runtime-resolver.ts +1 -4
  150. package/src/runtime/semaphore.ts +131 -0
  151. package/src/runtime/sensitive-paths.ts +92 -0
  152. package/src/runtime/session-resources.ts +25 -25
  153. package/src/runtime/session-snapshot.ts +59 -59
  154. package/src/runtime/session-usage.ts +79 -79
  155. package/src/runtime/sidechain-output.ts +29 -29
  156. package/src/runtime/stream-preview.ts +177 -0
  157. package/src/runtime/subagent-manager.ts +3 -2
  158. package/src/runtime/subprocess-tool-registry.ts +67 -0
  159. package/src/runtime/supervisor-contact.ts +59 -59
  160. package/src/runtime/task-display.ts +38 -38
  161. package/src/runtime/task-output-context.ts +59 -9
  162. package/src/runtime/task-runner/capabilities.ts +78 -78
  163. package/src/runtime/task-runner/live-executor.ts +2 -0
  164. package/src/runtime/task-runner/progress.ts +119 -119
  165. package/src/runtime/task-runner/prompt-builder.ts +70 -8
  166. package/src/runtime/task-runner/prompt-pipeline.ts +64 -64
  167. package/src/runtime/task-runner/result-utils.ts +14 -14
  168. package/src/runtime/task-runner/run-projection.ts +104 -0
  169. package/src/runtime/task-runner/state-helpers.ts +22 -22
  170. package/src/runtime/task-runner.ts +75 -4
  171. package/src/runtime/team-runner.ts +60 -8
  172. package/src/runtime/worker-heartbeat.ts +21 -21
  173. package/src/runtime/worker-startup.ts +57 -57
  174. package/src/runtime/workspace-tree.ts +298 -0
  175. package/src/runtime/yield-handler.ts +189 -0
  176. package/src/schema/config-schema.ts +6 -0
  177. package/src/schema/team-tool-schema.ts +11 -1
  178. package/src/skills/discover-skills.ts +67 -0
  179. package/src/state/active-run-registry.ts +4 -2
  180. package/src/state/artifact-store.ts +4 -1
  181. package/src/state/atomic-write.ts +50 -1
  182. package/src/state/blob-store.ts +117 -0
  183. package/src/state/contracts.ts +1 -0
  184. package/src/state/event-log-rotation.ts +158 -0
  185. package/src/state/event-log.ts +52 -2
  186. package/src/state/mailbox.ts +87 -7
  187. package/src/state/state-store.ts +24 -4
  188. package/src/state/task-claims.ts +44 -44
  189. package/src/state/types.ts +20 -0
  190. package/src/state/usage.ts +29 -29
  191. package/src/subagents/async-entry.ts +1 -1
  192. package/src/subagents/index.ts +3 -3
  193. package/src/subagents/live/control.ts +1 -1
  194. package/src/subagents/live/manager.ts +1 -1
  195. package/src/subagents/live/realtime.ts +1 -1
  196. package/src/subagents/live/session-runtime.ts +1 -1
  197. package/src/subagents/manager.ts +1 -1
  198. package/src/subagents/spawn.ts +1 -1
  199. package/src/teams/team-serializer.ts +38 -38
  200. package/src/types/diff.d.ts +18 -18
  201. package/src/ui/agent-management-overlay.ts +144 -0
  202. package/src/ui/crew-footer.ts +101 -101
  203. package/src/ui/crew-select-list.ts +111 -111
  204. package/src/ui/crew-widget.ts +11 -2
  205. package/src/ui/dashboard-panes/cancellation-pane.ts +43 -0
  206. package/src/ui/dashboard-panes/capability-pane.ts +60 -0
  207. package/src/ui/dashboard-panes/mailbox-pane.ts +35 -11
  208. package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
  209. package/src/ui/dynamic-border.ts +25 -25
  210. package/src/ui/layout-primitives.ts +106 -106
  211. package/src/ui/live-run-sidebar.ts +4 -0
  212. package/src/ui/loaders.ts +158 -158
  213. package/src/ui/powerbar-publisher.ts +77 -15
  214. package/src/ui/render-coalescer.ts +51 -0
  215. package/src/ui/render-diff.ts +119 -119
  216. package/src/ui/render-scheduler.ts +143 -143
  217. package/src/ui/run-dashboard.ts +4 -0
  218. package/src/ui/run-event-bus.ts +209 -0
  219. package/src/ui/run-snapshot-cache.ts +68 -16
  220. package/src/ui/snapshot-types.ts +8 -0
  221. package/src/ui/spinner.ts +17 -17
  222. package/src/ui/status-colors.ts +58 -58
  223. package/src/ui/syntax-highlight.ts +116 -116
  224. package/src/ui/transcript-entries.ts +258 -0
  225. package/src/utils/atomic-write.ts +33 -33
  226. package/src/utils/completion-dedupe.ts +63 -63
  227. package/src/utils/frontmatter.ts +68 -68
  228. package/src/utils/git.ts +262 -262
  229. package/src/utils/ids.ts +17 -12
  230. package/src/utils/incremental-reader.ts +104 -0
  231. package/src/utils/names.ts +27 -27
  232. package/src/utils/redaction.ts +44 -44
  233. package/src/utils/safe-paths.ts +47 -47
  234. package/src/utils/scan-cache.ts +137 -0
  235. package/src/utils/sleep.ts +32 -32
  236. package/src/utils/sse-parser.ts +134 -0
  237. package/src/utils/task-name-generator.ts +337 -0
  238. package/src/utils/visual.ts +33 -2
  239. package/src/workflows/validate-workflow.ts +40 -40
  240. package/src/worktree/branch-freshness.ts +45 -45
  241. package/src/worktree/cleanup.ts +2 -1
  242. package/teams/default.team.md +12 -12
  243. package/teams/fast-fix.team.md +11 -11
  244. package/teams/implementation.team.md +18 -18
  245. package/teams/parallel-research.team.md +14 -14
  246. package/teams/research.team.md +11 -11
  247. package/teams/review.team.md +12 -12
  248. package/workflows/default.workflow.md +29 -29
  249. package/workflows/fast-fix.workflow.md +22 -22
  250. package/workflows/implementation.workflow.md +38 -38
  251. package/workflows/parallel-research.workflow.md +46 -46
  252. package/workflows/research.workflow.md +22 -22
  253. package/workflows/review.workflow.md +30 -30
@@ -1,39 +1,39 @@
1
- ---
2
- name: ui-render-performance
3
- description: Non-blocking Pi TUI render workflow. Use when changing widgets, powerbar/statusbar segments, dashboard panes, overlays, snapshot caches, or live UI refresh behavior.
4
- ---
5
-
6
- # ui-render-performance
7
-
8
- Use this skill for Pi/pi-crew TUI work.
9
-
10
- ## Source patterns distilled
11
-
12
- - Pi TUI is synchronous immediate-mode/string rendering: `source/pi-mono/packages/coding-agent/src/modes/interactive/interactive-mode.ts`
13
- - Pi extension examples use event-driven state updates, not render-time loading.
14
- - pi-crew UI: `src/extension/register.ts`, `src/ui/run-dashboard.ts`, `src/ui/run-snapshot-cache.ts`, `src/ui/crew-widget.ts`, `src/ui/powerbar-publisher.ts`, `src/ui/render-scheduler.ts`
15
-
16
- ## Rules
17
-
18
- - Treat every `render(width)` and widget/powerbar update as a hot synchronous path.
19
- - Render from in-memory snapshots only. Preload config, manifests, snapshots, agents, and mailbox counts asynchronously.
20
- - Use `RenderScheduler.schedule()` to coalesce renders; avoid direct repeated rendering.
21
- - Prefer `snapshotCache.get(runId)` in render paths. If a sync fallback is unavoidable, classify it as first-load/rare and document why.
22
- - Keep dashboard panes pure: accept a snapshot/model and format strings; do not call `fs.readFileSync`, `fs.readdirSync`, `fs.statSync`, or network APIs from pane render methods.
23
- - On session switch, cancel timers and ensure in-flight async preloads cannot update stale session UI.
24
- - Watch TTL interactions: a preload interval shorter than cache TTL prevents render-time refresh gaps.
25
-
26
- ## Anti-patterns
27
-
28
- - Do not call `loadConfig()`, `manifestCache.list()`, or `refreshIfStale()` repeatedly inside `renderTick()` unless backed by preloaded frame data.
29
- - Do not do large JSON parsing or directory scans inside widget render/update functions.
30
- - Do not show stale health warnings for completed/cancelled/failed runs.
31
-
32
- ## Verification
33
-
34
- ```bash
35
- cd pi-crew
36
- npx tsc --noEmit
37
- node --experimental-strip-types --test test/unit/run-snapshot-cache.test.ts test/unit/crew-widget.test.ts test/unit/powerbar-publisher.test.ts test/unit/run-dashboard.test.ts
38
- npm test
39
- ```
1
+ ---
2
+ name: ui-render-performance
3
+ description: Non-blocking Pi TUI render workflow. Use when changing widgets, powerbar/statusbar segments, dashboard panes, overlays, snapshot caches, or live UI refresh behavior.
4
+ ---
5
+
6
+ # ui-render-performance
7
+
8
+ Use this skill for Pi/pi-crew TUI work.
9
+
10
+ ## Source patterns distilled
11
+
12
+ - Pi TUI is synchronous immediate-mode/string rendering: `source/pi-mono/packages/coding-agent/src/modes/interactive/interactive-mode.ts`
13
+ - Pi extension examples use event-driven state updates, not render-time loading.
14
+ - pi-crew UI: `src/extension/register.ts`, `src/ui/run-dashboard.ts`, `src/ui/run-snapshot-cache.ts`, `src/ui/crew-widget.ts`, `src/ui/powerbar-publisher.ts`, `src/ui/render-scheduler.ts`
15
+
16
+ ## Rules
17
+
18
+ - Treat every `render(width)` and widget/powerbar update as a hot synchronous path.
19
+ - Render from in-memory snapshots only. Preload config, manifests, snapshots, agents, and mailbox counts asynchronously.
20
+ - Use `RenderScheduler.schedule()` to coalesce renders; avoid direct repeated rendering.
21
+ - Prefer `snapshotCache.get(runId)` in render paths. If a sync fallback is unavoidable, classify it as first-load/rare and document why.
22
+ - Keep dashboard panes pure: accept a snapshot/model and format strings; do not call `fs.readFileSync`, `fs.readdirSync`, `fs.statSync`, or network APIs from pane render methods.
23
+ - On session switch, cancel timers and ensure in-flight async preloads cannot update stale session UI.
24
+ - Watch TTL interactions: a preload interval shorter than cache TTL prevents render-time refresh gaps.
25
+
26
+ ## Anti-patterns
27
+
28
+ - Do not call `loadConfig()`, `manifestCache.list()`, or `refreshIfStale()` repeatedly inside `renderTick()` unless backed by preloaded frame data.
29
+ - Do not do large JSON parsing or directory scans inside widget render/update functions.
30
+ - Do not show stale health warnings for completed/cancelled/failed runs.
31
+
32
+ ## Verification
33
+
34
+ ```bash
35
+ cd pi-crew
36
+ npx tsc --noEmit
37
+ node --experimental-strip-types --test test/unit/run-snapshot-cache.test.ts test/unit/crew-widget.test.ts test/unit/powerbar-publisher.test.ts test/unit/run-dashboard.test.ts
38
+ npm test
39
+ ```
@@ -1,57 +1,57 @@
1
- ---
2
- name: verification-before-done
3
- description: Use when about to claim work is complete, fixed, passing, reviewed, committed, or ready to hand off.
4
- ---
5
-
6
- # verification-before-done
7
-
8
- Core principle: evidence before claims. A worker report, green-looking log, or previous run is not fresh verification.
9
-
10
- Distilled from detailed reads of agent-skill patterns for verification-before-completion, TDD, review reception, and QA workflows.
11
-
12
- ## Gate Function
13
-
14
- Before any completion claim:
15
-
16
- 1. Identify the command or inspection that proves the claim.
17
- 2. Run the full command fresh, or explicitly state why a command cannot be run.
18
- 3. Read the output, including exit code and failure counts.
19
- 4. Compare the output to the claim.
20
- 5. Report the claim only with the evidence.
21
-
22
- ## Claim-to-Evidence Table
23
-
24
- | Claim | Requires | Not sufficient |
25
- |---|---|---|
26
- | Tests pass | Fresh test output with zero failures | Prior run, “should pass” |
27
- | Typecheck passes | Typecheck command exit 0 | Lint or targeted tests only |
28
- | Bug fixed | Original symptom/regression test passes | Code changed |
29
- | Requirements met | Checklist against request/plan | Generic test success |
30
- | Agent completed | Worker output plus artifact/diff/state inspection | Worker says DONE |
31
- | Safe to commit | Relevant checks pass and status reviewed | Partial local confidence |
32
-
33
- ## Verification Ladder
34
-
35
- Choose the smallest reliable gate, then escalate when risk requires it:
36
-
37
- 1. Read-only inspection for plans/reviews.
38
- 2. Targeted unit test for touched behavior.
39
- 3. Typecheck for TypeScript/schema/API changes.
40
- 4. Integration test for runtime, subprocess, state, filesystem, UI, config, or session behavior.
41
- 5. Full suite before commit/release or broad changes.
42
- 6. Real Pi smoke only when safe and needed.
43
-
44
- ## Done Report
45
-
46
- Include:
47
-
48
- - changed files or read-only status;
49
- - commands run and pass/fail result;
50
- - artifacts, run IDs, logs, or state paths inspected;
51
- - behavior actually verified;
52
- - skipped checks and why;
53
- - risks and rollback notes.
54
-
55
- ## Red Flags
56
-
57
- Stop before saying done if you are using words like “should”, “probably”, “looks”, “seems”, “I think”, or if you are trusting an agent report without checking evidence.
1
+ ---
2
+ name: verification-before-done
3
+ description: Use when about to claim work is complete, fixed, passing, reviewed, committed, or ready to hand off.
4
+ ---
5
+
6
+ # verification-before-done
7
+
8
+ Core principle: evidence before claims. A worker report, green-looking log, or previous run is not fresh verification.
9
+
10
+ Distilled from detailed reads of agent-skill patterns for verification-before-completion, TDD, review reception, and QA workflows.
11
+
12
+ ## Gate Function
13
+
14
+ Before any completion claim:
15
+
16
+ 1. Identify the command or inspection that proves the claim.
17
+ 2. Run the full command fresh, or explicitly state why a command cannot be run.
18
+ 3. Read the output, including exit code and failure counts.
19
+ 4. Compare the output to the claim.
20
+ 5. Report the claim only with the evidence.
21
+
22
+ ## Claim-to-Evidence Table
23
+
24
+ | Claim | Requires | Not sufficient |
25
+ |---|---|---|
26
+ | Tests pass | Fresh test output with zero failures | Prior run, “should pass” |
27
+ | Typecheck passes | Typecheck command exit 0 | Lint or targeted tests only |
28
+ | Bug fixed | Original symptom/regression test passes | Code changed |
29
+ | Requirements met | Checklist against request/plan | Generic test success |
30
+ | Agent completed | Worker output plus artifact/diff/state inspection | Worker says DONE |
31
+ | Safe to commit | Relevant checks pass and status reviewed | Partial local confidence |
32
+
33
+ ## Verification Ladder
34
+
35
+ Choose the smallest reliable gate, then escalate when risk requires it:
36
+
37
+ 1. Read-only inspection for plans/reviews.
38
+ 2. Targeted unit test for touched behavior.
39
+ 3. Typecheck for TypeScript/schema/API changes.
40
+ 4. Integration test for runtime, subprocess, state, filesystem, UI, config, or session behavior.
41
+ 5. Full suite before commit/release or broad changes.
42
+ 6. Real Pi smoke only when safe and needed.
43
+
44
+ ## Done Report
45
+
46
+ Include:
47
+
48
+ - changed files or read-only status;
49
+ - commands run and pass/fail result;
50
+ - artifacts, run IDs, logs, or state paths inspected;
51
+ - behavior actually verified;
52
+ - skipped checks and why;
53
+ - risks and rollback notes.
54
+
55
+ ## Red Flags
56
+
57
+ Stop before saying done if you are using words like “should”, “probably”, “looks”, “seems”, “I think”, or if you are trusting an agent report without checking evidence.
@@ -1,39 +1,39 @@
1
- ---
2
- name: worktree-isolation
3
- description: Conflict-safe git worktree workflow. Use when running parallel implementation workers, isolating risky edits, or cleaning up task worktrees.
4
- ---
5
-
6
- # worktree-isolation
7
-
8
- Use this skill for worktree-based execution or cleanup.
9
-
10
- ## Source patterns distilled
11
-
12
- - pi-subagents worktree runner and cleanup patterns
13
- - pi-crew worktrees: `src/worktree/worktree-manager.ts`, `src/worktree/cleanup.ts`, `src/worktree/branch-freshness.ts`
14
- - Team runner workspace mode: `src/runtime/team-runner.ts`, workflow/team resource fields
15
-
16
- ## Rules
17
-
18
- - Use worktree mode for parallel or risky code-changing tasks when the repository is clean enough and merge ownership is clear.
19
- - Assign one owner per file/symbol/migration path to avoid conflict-heavy merges.
20
- - Name branches/worktrees deterministically from run/task IDs; avoid user-controlled path fragments without sanitization.
21
- - Before cleanup, check dirty state. Preserve dirty worktrees unless `force` is explicitly set.
22
- - Record worktree paths and branch metadata in artifacts/events so the operator can inspect or recover.
23
- - Do not run destructive git operations without explicit confirmation and evidence of target path containment.
24
-
25
- ## Anti-patterns
26
-
27
- - Parallel editing the same file in multiple worktrees without a merge plan.
28
- - Force-removing dirty worktrees by default.
29
- - Reusing stale worktrees after the base branch has moved without freshness checks.
30
- - Storing worktrees outside the intended contained workspace root.
31
-
32
- ## Verification
33
-
34
- ```bash
35
- cd pi-crew
36
- npx tsc --noEmit
37
- node --experimental-strip-types --test test/integration/worktree-mode.test.ts test/unit/run-index.test.ts
38
- npm test
39
- ```
1
+ ---
2
+ name: worktree-isolation
3
+ description: Conflict-safe git worktree workflow. Use when running parallel implementation workers, isolating risky edits, or cleaning up task worktrees.
4
+ ---
5
+
6
+ # worktree-isolation
7
+
8
+ Use this skill for worktree-based execution or cleanup.
9
+
10
+ ## Source patterns distilled
11
+
12
+ - pi-subagents worktree runner and cleanup patterns
13
+ - pi-crew worktrees: `src/worktree/worktree-manager.ts`, `src/worktree/cleanup.ts`, `src/worktree/branch-freshness.ts`
14
+ - Team runner workspace mode: `src/runtime/team-runner.ts`, workflow/team resource fields
15
+
16
+ ## Rules
17
+
18
+ - Use worktree mode for parallel or risky code-changing tasks when the repository is clean enough and merge ownership is clear.
19
+ - Assign one owner per file/symbol/migration path to avoid conflict-heavy merges.
20
+ - Name branches/worktrees deterministically from run/task IDs; avoid user-controlled path fragments without sanitization.
21
+ - Before cleanup, check dirty state. Preserve dirty worktrees unless `force` is explicitly set.
22
+ - Record worktree paths and branch metadata in artifacts/events so the operator can inspect or recover.
23
+ - Do not run destructive git operations without explicit confirmation and evidence of target path containment.
24
+
25
+ ## Anti-patterns
26
+
27
+ - Parallel editing the same file in multiple worktrees without a merge plan.
28
+ - Force-removing dirty worktrees by default.
29
+ - Reusing stale worktrees after the base branch has moved without freshness checks.
30
+ - Storing worktrees outside the intended contained workspace root.
31
+
32
+ ## Verification
33
+
34
+ ```bash
35
+ cd pi-crew
36
+ npx tsc --noEmit
37
+ node --experimental-strip-types --test test/integration/worktree-mode.test.ts test/unit/run-index.test.ts
38
+ npm test
39
+ ```
@@ -25,6 +25,12 @@ export interface AgentConfig {
25
25
  inheritSkills?: boolean;
26
26
  routing?: RoutingMetadata;
27
27
  memory?: "user" | "project" | "local";
28
+ /** Tool loading strategy: "essential" = always load all tools, "lean" = only load tools in defaultTools list */
29
+ loadMode?: "essential" | "lean";
30
+ /** Explicit tool list when loadMode is "lean". null means all available tools. */
31
+ defaultTools?: string[] | null;
32
+ /** Context mode: "fresh" = clean start, "fork" = inherit parent session context */
33
+ contextMode?: "fresh" | "fork";
28
34
  disabled?: boolean;
29
35
  override?: { source: "config"; path: string };
30
36
  }
@@ -0,0 +1,98 @@
1
+ import type { AgentConfig } from "./agent-config.ts";
2
+
3
+ // ─── BM25 Agent Search ──────────────────────────────────────────────────────
4
+ // Lightweight BM25 search over agent descriptors for task-to-agent matching.
5
+ // Based on the same BM25 algorithm used in oh-my-pi's tool-index.ts.
6
+
7
+ export interface AgentSearchDocument {
8
+ agent: AgentConfig;
9
+ termFrequencies: Map<string, number>;
10
+ length: number;
11
+ }
12
+
13
+ export interface AgentSearchIndex {
14
+ documents: AgentSearchDocument[];
15
+ averageLength: number;
16
+ documentFrequencies: Map<string, number>;
17
+ }
18
+
19
+ export interface AgentSearchResult {
20
+ agent: AgentConfig;
21
+ score: number;
22
+ }
23
+
24
+ const BM25_K1 = 1.2;
25
+ const BM25_B = 0.75;
26
+ const FIELD_WEIGHTS = {
27
+ name: 6,
28
+ description: 2,
29
+ role: 3,
30
+ } as const;
31
+
32
+ function tokenize(value: string): string[] {
33
+ return value
34
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
35
+ .replace(/[^a-zA-Z0-9]+/g, " ")
36
+ .toLowerCase()
37
+ .trim()
38
+ .split(/\s+/)
39
+ .filter((token) => token.length > 0);
40
+ }
41
+
42
+ function addWeightedTokens(termFrequencies: Map<string, number>, value: string | undefined, weight: number): void {
43
+ if (!value) return;
44
+ for (const token of tokenize(value)) {
45
+ termFrequencies.set(token, (termFrequencies.get(token) ?? 0) + weight);
46
+ }
47
+ }
48
+
49
+ function buildAgentSearchDocument(agent: AgentConfig): AgentSearchDocument {
50
+ const termFrequencies = new Map<string, number>();
51
+ addWeightedTokens(termFrequencies, agent.name, FIELD_WEIGHTS.name);
52
+ addWeightedTokens(termFrequencies, agent.description, FIELD_WEIGHTS.description);
53
+ // Role from agent name heuristic
54
+ const roleHint = agent.name?.replace(/[-_]/g, " ") ?? "";
55
+ addWeightedTokens(termFrequencies, roleHint, FIELD_WEIGHTS.role);
56
+ const length = Array.from(termFrequencies.values()).reduce((sum, value) => sum + value, 0);
57
+ return { agent, termFrequencies, length };
58
+ }
59
+
60
+ export function buildAgentSearchIndex(agents: Iterable<AgentConfig>): AgentSearchIndex {
61
+ const documents = Array.from(agents, buildAgentSearchDocument);
62
+ const averageLength = documents.reduce((sum, document) => sum + document.length, 0) / documents.length || 1;
63
+ const documentFrequencies = new Map<string, number>();
64
+ for (const document of documents) {
65
+ for (const token of new Set(document.termFrequencies.keys())) {
66
+ documentFrequencies.set(token, (documentFrequencies.get(token) ?? 0) + 1);
67
+ }
68
+ }
69
+ return { documents, averageLength, documentFrequencies };
70
+ }
71
+
72
+ export function searchAgents(index: AgentSearchIndex, query: string, limit: number): AgentSearchResult[] {
73
+ const queryTokens = tokenize(query);
74
+ if (queryTokens.length === 0) return [];
75
+ if (index.documents.length === 0) return [];
76
+
77
+ const queryTermCounts = new Map<string, number>();
78
+ for (const token of queryTokens) {
79
+ queryTermCounts.set(token, (queryTermCounts.get(token) ?? 0) + 1);
80
+ }
81
+
82
+ return index.documents
83
+ .map((document) => {
84
+ let score = 0;
85
+ for (const [token, queryTermCount] of queryTermCounts) {
86
+ const termFrequency = document.termFrequencies.get(token) ?? 0;
87
+ if (termFrequency === 0) continue;
88
+ const documentFrequency = index.documentFrequencies.get(token) ?? 0;
89
+ const idf = Math.log(1 + (index.documents.length - documentFrequency + 0.5) / (documentFrequency + 0.5));
90
+ const normalization = BM25_K1 * (1 - BM25_B + BM25_B * (document.length / index.averageLength));
91
+ score += queryTermCount * idf * ((termFrequency * (BM25_K1 + 1)) / (termFrequency + normalization));
92
+ }
93
+ return { agent: document.agent, score };
94
+ })
95
+ .filter((result) => result.score > 0)
96
+ .sort((left, right) => right.score - left.score || left.agent.name.localeCompare(right.agent.name))
97
+ .slice(0, limit);
98
+ }
@@ -20,6 +20,10 @@ export function serializeAgent(agent: AgentConfig): string {
20
20
  line("systemPromptMode", agent.systemPromptMode),
21
21
  line("inheritProjectContext", agent.inheritProjectContext),
22
22
  line("inheritSkills", agent.inheritSkills),
23
+ line("memory", agent.memory),
24
+ line("loadMode", agent.loadMode),
25
+ line("defaultTools", agent.defaultTools ?? undefined),
26
+ line("contextMode", agent.contextMode),
23
27
  line("triggers", agent.routing?.triggers),
24
28
  line("useWhen", agent.routing?.useWhen),
25
29
  line("avoidWhen", agent.routing?.avoidWhen),
@@ -3,6 +3,7 @@ import * as path from "node:path";
3
3
  import type { AgentConfig, ResourceSource } from "./agent-config.ts";
4
4
  import { loadConfig, type LoadedPiTeamsConfig } from "../config/config.ts";
5
5
  import { parseCsv, parseFrontmatter } from "../utils/frontmatter.ts";
6
+ import { logInternalError } from "../utils/internal-error.ts";
6
7
  import { packageRoot, projectCrewRoot, userPiRoot } from "../utils/paths.ts";
7
8
 
8
9
  export interface AgentDiscoveryResult {
@@ -19,6 +20,14 @@ function parseMemory(value: string | undefined): "user" | "project" | "local" |
19
20
  return value === "user" || value === "project" || value === "local" ? value : undefined;
20
21
  }
21
22
 
23
+ function parseLoadMode(value: string | undefined): "essential" | "lean" | undefined {
24
+ return value === "essential" || value === "lean" ? value : undefined;
25
+ }
26
+
27
+ function parseContextMode(value: string | undefined): "fresh" | "fork" | undefined {
28
+ return value === "fresh" || value === "fork" ? value : undefined;
29
+ }
30
+
22
31
  function parseAgentFile(filePath: string, source: ResourceSource): AgentConfig | undefined {
23
32
  try {
24
33
  const content = fs.readFileSync(filePath, "utf-8");
@@ -43,13 +52,17 @@ function parseAgentFile(filePath: string, source: ResourceSource): AgentConfig |
43
52
  extensions: frontmatter.extensions === "" ? [] : parseCsv(frontmatter.extensions),
44
53
  skills: parseCsv(frontmatter.skills ?? frontmatter.skill),
45
54
  systemPromptMode: frontmatter.systemPromptMode === "append" ? "append" : "replace",
46
- inheritProjectContext: frontmatter.inheritProjectContext as unknown === true || frontmatter.inheritProjectContext === "true",
47
- inheritSkills: frontmatter.inheritSkills as unknown === true || frontmatter.inheritSkills === "true",
55
+ inheritProjectContext: frontmatter.inheritProjectContext === "true",
56
+ inheritSkills: frontmatter.inheritSkills === "true",
48
57
  memory: parseMemory(frontmatter.memory),
49
- disabled: frontmatter.disabled as unknown === true || frontmatter.disabled === "true" || frontmatter.enabled as unknown === false || frontmatter.enabled === "false",
58
+ loadMode: parseLoadMode(frontmatter.loadMode),
59
+ defaultTools: frontmatter.defaultTools !== undefined ? parseCsv(frontmatter.defaultTools) ?? null : undefined,
60
+ contextMode: parseContextMode(frontmatter.contextMode),
61
+ disabled: frontmatter.disabled === "true" || frontmatter.enabled === "false",
50
62
  routing: triggers || useWhen || avoidWhen || cost || category ? { triggers, useWhen, avoidWhen, cost, category } : undefined,
51
63
  };
52
- } catch {
64
+ } catch (error) {
65
+ logInternalError("discoverAgents.parseAgentFile", error, `filePath=${filePath}`);
53
66
  return undefined;
54
67
  }
55
68
  }
@@ -46,6 +46,7 @@ export interface CrewRuntimeConfig {
46
46
  requirePlanApproval?: boolean;
47
47
  completionMutationGuard?: CompletionMutationGuardMode;
48
48
  effectivenessGuard?: EffectivenessGuardMode;
49
+ yield?: { enabled?: boolean; maxReminders?: number; reminderPrompt?: string };
49
50
  }
50
51
 
51
52
  export interface CrewControlConfig {
@@ -100,6 +101,11 @@ export interface CrewTelemetryConfig {
100
101
  enabled?: boolean;
101
102
  }
102
103
 
104
+ export interface CrewPolicyConfig {
105
+ requireIntentForDestructiveActions?: boolean;
106
+ disabledCapabilities?: string[];
107
+ }
108
+
103
109
  export type CrewNotificationSeverity = "info" | "warning" | "error" | "critical";
104
110
 
105
111
  export interface CrewNotificationsConfig {
@@ -152,6 +158,7 @@ export interface PiTeamsConfig {
152
158
  agents?: CrewAgentsConfig;
153
159
  tools?: CrewToolsConfig;
154
160
  telemetry?: CrewTelemetryConfig;
161
+ policy?: CrewPolicyConfig;
155
162
  notifications?: CrewNotificationsConfig;
156
163
  observability?: CrewObservabilityConfig;
157
164
  reliability?: CrewReliabilityConfig;
@@ -363,6 +370,12 @@ function mergeConfig(base: PiTeamsConfig, override: PiTeamsConfig): PiTeamsConfi
363
370
  ...withoutUndefined((override.telemetry ?? {}) as Record<string, unknown>),
364
371
  };
365
372
  }
373
+ if (base.policy || override.policy) {
374
+ merged.policy = {
375
+ ...(base.policy ?? {}),
376
+ ...withoutUndefined((override.policy ?? {}) as Record<string, unknown>),
377
+ };
378
+ }
366
379
  if (base.notifications || override.notifications) {
367
380
  merged.notifications = {
368
381
  ...(base.notifications ?? {}),
@@ -619,6 +632,16 @@ function parseTelemetryConfig(value: unknown): CrewTelemetryConfig | undefined {
619
632
  return Object.values(telemetry).some((entry) => entry !== undefined) ? telemetry : undefined;
620
633
  }
621
634
 
635
+ function parsePolicyConfig(value: unknown): CrewPolicyConfig | undefined {
636
+ const obj = asRecord(value);
637
+ if (!obj) return undefined;
638
+ const policy: CrewPolicyConfig = {
639
+ requireIntentForDestructiveActions: parseWithSchema(Type.Boolean(), obj.requireIntentForDestructiveActions),
640
+ disabledCapabilities: parseWithSchema(Type.Array(Type.String()), obj.disabledCapabilities),
641
+ };
642
+ return Object.values(policy).some((entry) => entry !== undefined) ? policy : undefined;
643
+ }
644
+
622
645
  function parseNotificationsConfig(value: unknown): CrewNotificationsConfig | undefined {
623
646
  const obj = asRecord(value);
624
647
  if (!obj) return undefined;
@@ -700,6 +723,7 @@ export function parseConfig(raw: unknown): PiTeamsConfig {
700
723
  agents: parseAgentsConfig(obj.agents),
701
724
  tools: parseToolsConfig(obj.tools),
702
725
  telemetry: parseTelemetryConfig(obj.telemetry),
726
+ policy: parsePolicyConfig(obj.policy),
703
727
  notifications: parseNotificationsConfig(obj.notifications),
704
728
  observability: parseObservabilityConfig(obj.observability),
705
729
  reliability: parseReliabilityConfig(obj.reliability),
@@ -12,6 +12,17 @@ export const DEFAULT_CHILD_PI = {
12
12
  maxCompactContentChars: 4096,
13
13
  };
14
14
 
15
+ export const DEFAULT_LIVE_SESSION = {
16
+ /** Maximum wall-clock time for a single live-session task before abort (ms). */
17
+ responseTimeoutMs: 5 * 60_000,
18
+ /** Maximum yield reminder attempts before accepting no-yield. */
19
+ maxYieldRetries: 3,
20
+ /** Polling interval for session idle check during yield enforcement (ms). */
21
+ yieldPollIntervalMs: 500,
22
+ /** Maximum time to wait for session idle after prompt (ms). */
23
+ idleWaitTimeoutMs: 60_000,
24
+ };
25
+
15
26
  export const DEFAULT_LOCKS = {
16
27
  staleMs: 30_000,
17
28
  };
@@ -73,46 +73,39 @@ export function buildAutonomousPolicy(prompt: string, config: PiTeamsAutonomousC
73
73
  ? "Do not suggest worktree mode unless the user explicitly asks for it."
74
74
  : "Consider workspaceMode: 'worktree' for parallel or risky code-changing work in clean git repositories.";
75
75
  return [
76
- "# pi-crew Autonomous Delegation Policy",
76
+ "# pi-crew Delegation Policy (MANDATORY)",
77
77
  "",
78
78
  `Autonomy profile: ${effective.profile}.`,
79
- "You have access to the `team` tool for coordinated multi-agent work. Use it proactively when the task benefits from specialized roles, planning, review, verification, durable artifacts, async execution, or worktree isolation.",
79
+ "You MUST evaluate EVERY user request against the delegation decision table below BEFORE acting.",
80
80
  "",
81
- "Decision framework (not keyword-only):",
82
- "- Treat a user-supplied task list with 2+ actionable bullets/numbered items as a delegation candidate even when no pi-crew keyword appears.",
83
- "- Prefer `team` when tasks span multiple files/subsystems, require sequencing, combine implementation + tests/docs/review, or need independent exploration before edits.",
84
- "- If unsure whether subtasks conflict, call `team` with action='recommend' first instead of manually splitting work.",
85
- "- For assisted/aggressive autonomy and non-trivial multi-task work, prefer a team run or plan over direct single-agent execution.",
81
+ "## Decision Table Do I delegate?",
86
82
  "",
87
- "Use `team` automatically when:",
88
- "- The task spans multiple files, subsystems, or unclear code areas.",
89
- "- The prompt contains a non-trivial task list, roadmap, checklist, migration plan, or ordered implementation plan.",
90
- "- The task requires planning before implementation.",
91
- "- The task asks for implementation plus tests, review, verification, migration, architecture, security review, or debugging.",
92
- "- The task would benefit from explorer/planner/executor/reviewer/verifier roles.",
83
+ "| Task characteristic | Delegate? | Method |",
84
+ "|---|---|---|",
85
+ "| Read/edit 1-2 files, simple question | NO | Do it directly |",
86
+ "| User explicitly says \"do it yourself\" / \"no team\" | NO | Do it directly |",
87
+ "| Destructive action (delete/prune/forget) | NO | Ask for confirmation first |",
88
+ "| Research / deep-read / source audit / \"nghiên cứu\" | YES | `team action='research'` |",
89
+ "| Multi-file implementation / feature / refactor | YES | `team action='run', team='implementation'` |",
90
+ "| Small bug fix (1-2 files, clear cause) | YES | `team action='run', team='fast-fix'` |",
91
+ "| Code review / security review | YES | `team action='run', team='review'` |",
92
+ "| Task list with 2+ actionable items | YES | `team action='plan'` or `action='run'` |",
93
+ "| Need exploration before knowing scope | YES | `Agent(explorer)` or `team action='recommend'` |",
94
+ "| Parallel independent subtasks | YES | `team action='parallel'` or multiple `Agent` background |",
95
+ "| Unsure which team/workflow fits | YES | `team action='recommend'` first |",
93
96
  "",
94
- "Do not use `team` when:",
95
- "- The user asks a simple factual question or tiny single-file edit.",
96
- "- The user explicitly asks you to work directly without delegation.",
97
- "- The tasks clearly modify the same small file region and can be completed safer by one agent without parallel fanout.",
98
- "- The action is destructive (`delete`, `forget`, `prune`, forced cleanup) and the user has not explicitly confirmed it.",
97
+ "## Rules",
99
98
  "",
100
- "Recommended mappings:",
101
- "- Complex feature/refactor/migration -> action='run', team='implementation'.",
102
- "- Small bug fix -> action='run', team='fast-fix'.",
103
- "- Code/security review -> action='run', team='review'.",
104
- "- Research or documentation synthesis -> action='run', team='research'.",
105
- "- Unsure which team/workflow to use -> call the `team` tool with action='recommend' and the user's goal, then follow the suggested plan/run call if appropriate.",
106
- "- After delegating exploration/research/review, do not duplicate the same search manually. Continue only with non-overlapping work.",
107
- "- Before claiming delegated work is complete, inspect the run with action='status' or action='summary'.",
108
- "- Unsure or risky work -> action='plan' first, then run the selected team.",
99
+ "1. If the task needs reading >3 files OR editing >2 files OR has a research/review/planning component → you MUST delegate via `team` or `Agent`. Do not do it yourself.",
100
+ "2. After delegating, do NOT duplicate the same exploration/reading/review manually. Continue only with non-overlapping work.",
101
+ "3. Before claiming delegated work is complete, verify with `team action='status'` or `action='summary'`.",
102
+ "4. If unsure whether subtasks conflict, use `team action='recommend'` first.",
103
+ "5. For parallel implementation, prefer `workspaceMode: 'worktree'` in clean git repos.",
109
104
  "",
110
- "Conflict-safe task splitting:",
111
- "- Do not parallelize subtasks that may edit the same file, same symbol, same migration path, package manifest, lockfile, or generated schema unless a planner explicitly sequences them.",
112
- "- For potential overlap, use plan/recommend first, assign one owner per file/symbol, and require workers to report intended changed files before editing.",
113
- "- Prefer workspaceMode: 'worktree' for parallel implementation in clean git repositories, but still avoid merging overlapping edits without review.",
114
- "- If workers discover overlap, blockers, missing requirements, or need leader decisions, they must use mailbox/status artifacts to ask the leader/orchestrator and pause risky edits.",
115
- "- The leader should resolve conflicts by sequencing, narrowing scope, or reassigning ownership before continuing.",
105
+ "## Conflict-safe task splitting",
106
+ "- Do not parallelize subtasks that may edit the same file, same symbol, or same lockfile.",
107
+ "- Assign one owner per file/symbol. Workers must report intended changed files before editing.",
108
+ "- If workers discover overlap, they must pause and ask the leader to resolve.",
116
109
  "",
117
110
  asyncGuidance,
118
111
  worktreeGuidance,