pi-crew 0.1.37 → 0.1.39

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 (162) hide show
  1. package/AGENTS.md +1 -1
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +5 -0
  4. package/agents/analyst.md +11 -11
  5. package/agents/critic.md +11 -11
  6. package/agents/executor.md +11 -11
  7. package/agents/explorer.md +11 -11
  8. package/agents/planner.md +11 -11
  9. package/agents/reviewer.md +11 -11
  10. package/agents/security-reviewer.md +11 -11
  11. package/agents/test-engineer.md +11 -11
  12. package/agents/verifier.md +11 -11
  13. package/agents/writer.md +11 -11
  14. package/docs/refactor-tasks-phase3.md +394 -394
  15. package/docs/refactor-tasks-phase4.md +564 -564
  16. package/docs/refactor-tasks-phase5.md +402 -402
  17. package/docs/refactor-tasks-phase6.md +662 -662
  18. package/docs/research-extension-examples.md +297 -297
  19. package/docs/research-extension-system.md +324 -324
  20. package/docs/research-optimization-plan.md +548 -548
  21. package/docs/research-pi-coding-agent.md +357 -357
  22. package/docs/research-source-pi-crew-reference.md +174 -174
  23. package/docs/resource-formats.md +10 -8
  24. package/docs/runtime-flow.md +148 -148
  25. package/docs/source-runtime-refactor-map.md +83 -83
  26. package/docs/usage.md +6 -0
  27. package/index.ts +6 -6
  28. package/package.json +3 -3
  29. package/schema.json +2 -2
  30. package/src/agents/agent-serializer.ts +34 -34
  31. package/src/config/config.ts +8 -4
  32. package/src/extension/cross-extension-rpc.ts +82 -82
  33. package/src/extension/import-index.ts +18 -2
  34. package/src/extension/register.ts +11 -1
  35. package/src/extension/registration/compaction-guard.ts +125 -125
  36. package/src/extension/registration/subagent-helpers.ts +30 -6
  37. package/src/extension/registration/subagent-tools.ts +8 -3
  38. package/src/extension/result-watcher.ts +98 -98
  39. package/src/extension/run-import.ts +12 -2
  40. package/src/extension/run-index.ts +12 -2
  41. package/src/extension/run-maintenance.ts +24 -24
  42. package/src/extension/team-tool/api.ts +54 -14
  43. package/src/extension/team-tool/cancel.ts +31 -31
  44. package/src/extension/team-tool/doctor.ts +179 -179
  45. package/src/extension/team-tool/inspect.ts +41 -41
  46. package/src/extension/team-tool/lifecycle-actions.ts +79 -79
  47. package/src/extension/team-tool/plan.ts +19 -19
  48. package/src/extension/team-tool/status.ts +73 -73
  49. package/src/observability/correlation.ts +35 -35
  50. package/src/observability/event-to-metric.ts +54 -54
  51. package/src/observability/exporters/adapter.ts +24 -24
  52. package/src/observability/exporters/otlp-exporter.ts +65 -65
  53. package/src/observability/exporters/prometheus-exporter.ts +47 -47
  54. package/src/observability/metric-registry.ts +72 -72
  55. package/src/observability/metric-retention.ts +46 -46
  56. package/src/observability/metric-sink.ts +51 -51
  57. package/src/observability/metrics-primitives.ts +166 -166
  58. package/src/prompt/prompt-runtime.ts +68 -68
  59. package/src/runtime/agent-control.ts +64 -64
  60. package/src/runtime/agent-memory.ts +72 -72
  61. package/src/runtime/agent-observability.ts +114 -113
  62. package/src/runtime/async-marker.ts +26 -26
  63. package/src/runtime/background-runner.ts +53 -53
  64. package/src/runtime/crash-recovery.ts +56 -56
  65. package/src/runtime/crew-agent-records.ts +54 -9
  66. package/src/runtime/crew-agent-runtime.ts +58 -58
  67. package/src/runtime/deadletter.ts +36 -36
  68. package/src/runtime/direct-run.ts +35 -35
  69. package/src/runtime/foreground-control.ts +82 -82
  70. package/src/runtime/green-contract.ts +46 -46
  71. package/src/runtime/group-join.ts +88 -88
  72. package/src/runtime/heartbeat-gradient.ts +28 -28
  73. package/src/runtime/heartbeat-watcher.ts +80 -80
  74. package/src/runtime/live-agent-control.ts +87 -78
  75. package/src/runtime/live-agent-manager.ts +85 -85
  76. package/src/runtime/live-control-realtime.ts +36 -36
  77. package/src/runtime/live-session-runtime.ts +299 -299
  78. package/src/runtime/manifest-cache.ts +248 -212
  79. package/src/runtime/model-fallback.ts +261 -261
  80. package/src/runtime/parallel-research.ts +44 -44
  81. package/src/runtime/parallel-utils.ts +99 -99
  82. package/src/runtime/pi-json-output.ts +111 -111
  83. package/src/runtime/policy-engine.ts +78 -78
  84. package/src/runtime/post-exit-stdio-guard.ts +86 -86
  85. package/src/runtime/process-status.ts +56 -56
  86. package/src/runtime/progress-event-coalescer.ts +43 -43
  87. package/src/runtime/recovery-recipes.ts +74 -74
  88. package/src/runtime/retry-executor.ts +59 -59
  89. package/src/runtime/role-permission.ts +39 -39
  90. package/src/runtime/session-usage.ts +79 -79
  91. package/src/runtime/sidechain-output.ts +28 -28
  92. package/src/runtime/subagent-manager.ts +80 -12
  93. package/src/runtime/task-display.ts +38 -38
  94. package/src/runtime/task-output-context.ts +127 -106
  95. package/src/runtime/task-runner/live-executor.ts +98 -98
  96. package/src/runtime/task-runner/progress.ts +111 -111
  97. package/src/runtime/task-runner/result-utils.ts +14 -14
  98. package/src/runtime/task-runner/state-helpers.ts +22 -22
  99. package/src/runtime/team-runner.ts +1 -1
  100. package/src/runtime/worker-heartbeat.ts +21 -21
  101. package/src/runtime/worker-startup.ts +57 -57
  102. package/src/schema/config-schema.ts +21 -21
  103. package/src/schema/team-tool-schema.ts +100 -100
  104. package/src/state/artifact-store.ts +122 -108
  105. package/src/state/contracts.ts +105 -105
  106. package/src/state/jsonl-writer.ts +77 -77
  107. package/src/state/mailbox.ts +67 -22
  108. package/src/state/state-store.ts +36 -5
  109. package/src/state/task-claims.ts +42 -42
  110. package/src/state/usage.ts +29 -29
  111. package/src/subagents/async-entry.ts +1 -1
  112. package/src/subagents/index.ts +3 -3
  113. package/src/subagents/live/control.ts +1 -1
  114. package/src/subagents/live/manager.ts +1 -1
  115. package/src/subagents/live/realtime.ts +1 -1
  116. package/src/subagents/live/session-runtime.ts +1 -1
  117. package/src/subagents/manager.ts +1 -1
  118. package/src/subagents/spawn.ts +1 -1
  119. package/src/teams/discover-teams.ts +27 -5
  120. package/src/teams/team-serializer.ts +38 -36
  121. package/src/types/diff.d.ts +18 -18
  122. package/src/ui/crew-footer.ts +101 -101
  123. package/src/ui/crew-select-list.ts +111 -111
  124. package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
  125. package/src/ui/dynamic-border.ts +25 -25
  126. package/src/ui/layout-primitives.ts +106 -106
  127. package/src/ui/loaders.ts +158 -158
  128. package/src/ui/mascot.ts +441 -441
  129. package/src/ui/render-diff.ts +119 -119
  130. package/src/ui/run-dashboard.ts +5 -2
  131. package/src/ui/run-snapshot-cache.ts +19 -8
  132. package/src/ui/spinner.ts +17 -17
  133. package/src/ui/status-colors.ts +54 -54
  134. package/src/ui/syntax-highlight.ts +116 -116
  135. package/src/ui/transcript-viewer.ts +15 -1
  136. package/src/utils/completion-dedupe.ts +63 -63
  137. package/src/utils/file-coalescer.ts +84 -84
  138. package/src/utils/frontmatter.ts +36 -36
  139. package/src/utils/fs-watch.ts +31 -31
  140. package/src/utils/git.ts +262 -262
  141. package/src/utils/ids.ts +12 -12
  142. package/src/utils/names.ts +26 -26
  143. package/src/utils/paths.ts +3 -2
  144. package/src/utils/safe-paths.ts +34 -0
  145. package/src/utils/sleep.ts +32 -32
  146. package/src/utils/timings.ts +31 -31
  147. package/src/utils/visual.ts +159 -159
  148. package/src/workflows/discover-workflows.ts +30 -3
  149. package/src/workflows/validate-workflow.ts +40 -40
  150. package/src/worktree/branch-freshness.ts +45 -45
  151. package/teams/default.team.md +12 -12
  152. package/teams/fast-fix.team.md +11 -11
  153. package/teams/implementation.team.md +18 -18
  154. package/teams/parallel-research.team.md +14 -14
  155. package/teams/research.team.md +11 -11
  156. package/teams/review.team.md +12 -12
  157. package/workflows/default.workflow.md +29 -29
  158. package/workflows/fast-fix.workflow.md +22 -22
  159. package/workflows/implementation.workflow.md +38 -38
  160. package/workflows/parallel-research.workflow.md +46 -46
  161. package/workflows/research.workflow.md +22 -22
  162. package/workflows/review.workflow.md +30 -30
@@ -1,148 +1,148 @@
1
- # pi-crew Runtime Flow
2
-
3
- This document is a compact map of the runtime paths used by `pi-crew`.
4
-
5
- ## Main sequence
6
-
7
- ```text
8
- User / model
9
- │ calls team({ action: "run", ... }) or /team-run
10
-
11
- handleTeamTool()
12
- │ validates schema and routes action
13
-
14
- handleRun()
15
- ├─ discoverTeams/discoverWorkflows/discoverAgents
16
- ├─ validateWorkflowForTeam
17
- ├─ expandParallelResearchWorkflow when applicable
18
- ├─ createRunManifest + tasks.json + goal artifact
19
- ├─ if async=true ─────────────────────────────────────────────┐
20
- │ spawnBackgroundTeamRun() │
21
- │ ├─ resolve jiti-register.mjs │
22
- │ ├─ fail-fast if jiti missing │
23
- │ ├─ node --import jiti-register.mjs background-runner.ts │
24
- │ └─ parent schedules early-exit guard │
25
- │ ▼
26
- │ background-runner.ts
27
- │ ├─ append async.started
28
- │ ├─ write async.pid startup marker
29
- │ ├─ rediscover team/workflow/agents
30
- │ └─ executeTeamRun()
31
-
32
- └─ if foreground/default
33
- ├─ startForegroundRun schedules session-bound run, or
34
- └─ executeTeamRun inline for scaffold/non-scheduled paths
35
-
36
- executeTeamRun()
37
- ├─ write run.running
38
- ├─ materialize queued/running agent records lazily
39
- ├─ build task graph index
40
- ├─ while queued tasks exist
41
- │ ├─ taskGraphSnapshot
42
- │ ├─ resolveBatchConcurrency
43
- │ ├─ getReadyTasks
44
- │ ├─ append task.progress batch event
45
- │ ├─ mapConcurrent ready batch
46
- │ │ └─ runTeamTask()
47
- │ │ ├─ prepare workspace/worktree
48
- │ │ ├─ build task packet
49
- │ │ ├─ render prompt + dependency context
50
- │ │ ├─ choose model candidates from Pi config
51
- │ │ ├─ spawn child Pi process
52
- │ │ ├─ ChildPiLineObserver parses stdout/stderr
53
- │ │ ├─ append per-agent events/output
54
- │ │ ├─ update agent progress/task state
55
- │ │ ├─ parse final JSONL/session usage
56
- │ │ └─ write result/log/transcript/metadata artifacts
57
- │ ├─ merge task updates monotonically
58
- │ ├─ optional adaptive plan injection
59
- │ ├─ save tasks/agents/progress
60
- │ └─ write batch artifact
61
- ├─ policy closeout
62
- └─ run.completed / run.failed / run.blocked / run.cancelled
63
- ```
64
-
65
- ## Action router
66
-
67
- | Action | Handler | Purpose |
68
- |---|---|---|
69
- | `run` | `team-tool/run.ts` | Create and execute a run, foreground or async. |
70
- | `status` | `team-tool.ts` | Show manifest/tasks/agents/events and mark stale async runs failed. |
71
- | `summary` | `session-summary.ts`/summary handler | Write/read run summary artifact. |
72
- | `events` | `team-tool.ts` | Tail durable run events. |
73
- | `artifacts` | `team-tool.ts` | List run artifacts. |
74
- | `resume` | `team-tool.ts` | Requeue failed/cancelled/skipped/running tasks. |
75
- | `cancel` | `team-tool.ts` | Mark queued/running tasks cancelled and request foreground interrupt. |
76
- | `forget` | `run-maintenance.ts` | Delete run state/artifacts with confirmation. |
77
- | `prune` | `run-maintenance.ts` | Remove old finished runs with confirmation. |
78
- | `export` | `run-export.ts` | Create portable run bundle. |
79
- | `import` / `imports` | `run-import.ts` / `import-index.ts` | Store/list imported bundles. |
80
- | `config` | `config.ts` + config action | Show/update user/project config. |
81
- | `doctor` | `team-tool/doctor.ts` | Platform/resource/runtime diagnostics. |
82
- | `validate` | `validate-resources.ts` | Validate agents/teams/workflows. |
83
- | `recommend` | `team-recommendation.ts` | Suggest team/workflow/action for a goal. |
84
- | management | `management.ts` | Create/update/delete/rename teams, agents, workflows. |
85
- | API | `team-tool/api.ts` | File-backed observability/control/mailbox API. |
86
-
87
- ## Worker modes
88
-
89
- | Mode | Behavior |
90
- |---|---|
91
- | `child-process` | Default. Launches real child `pi` processes per task. |
92
- | `scaffold` | Explicit dry-run. No child Pi worker execution. |
93
- | `live-session` | Experimental/gated in-process/live agent path. |
94
- | `auto` | Resolves to child-process unless config/env requests otherwise. |
95
-
96
- ## Important files
97
-
98
- ```text
99
- src/extension/register.ts Pi extension entry/wiring
100
- src/extension/team-tool/run.ts run creation and foreground/async split
101
- src/runtime/background-runner.ts detached async entrypoint
102
- src/runtime/async-runner.ts background spawn command/options
103
- src/runtime/team-runner.ts workflow/task graph scheduler
104
- src/runtime/task-runner.ts single task execution
105
- src/runtime/child-pi.ts child Pi process and output observer
106
- src/runtime/model-fallback.ts configured model candidates/routing
107
- src/runtime/concurrency.ts batch concurrency decisions
108
- src/runtime/process-status.ts pid/liveness/stale detection
109
- src/state/state-store.ts manifest/tasks persistence
110
- src/state/event-log.ts JSONL run events
111
- src/runtime/crew-agent-records.ts aggregate + per-agent status files
112
- ```
113
-
114
- ## Environment variables
115
-
116
- | Env | Effect |
117
- |---|---|
118
- | `PI_CREW_EXECUTE_WORKERS=0` | Disable real workers, use scaffold behavior. |
119
- | `PI_TEAMS_EXECUTE_WORKERS=0` | Legacy alias for worker disable. |
120
- | `PI_CREW_ENABLE_EXPERIMENTAL_LIVE_SESSION=1` | Allow experimental live-session runtime. |
121
- | `PI_CREW_MOCK_LIVE_SESSION=success` | Test hook for live-session mock. |
122
- | `PI_TEAMS_MOCK_CHILD_PI` | Test hook for mocked child Pi execution. |
123
- | `PI_CREW_DEPTH`, `PI_CREW_MAX_DEPTH` | Canonical subagent recursion guard. |
124
- | `PI_TEAMS_DEPTH`, `PI_TEAMS_MAX_DEPTH` | Legacy recursion guard aliases. |
125
- | `PI_TEAMS_HOME` | Override user config/state home in tests. |
126
- | `PI_TEAMS_PI_BIN` | Override child `pi` executable. |
127
- | `PI_CODING_AGENT_DIR` | Override Pi settings/models directory for model discovery. |
128
- | `PI_CREW_ASYNC_EARLY_EXIT_GUARD=0` | Disable 3s background early-exit guard. |
129
-
130
- ## State transition summary
131
-
132
- ```text
133
- queued/planning/running ── completed
134
- ├─ failed
135
- ├─ blocked
136
- └─ cancelled
137
- ```
138
-
139
- Task states follow the same durable contract plus `skipped`. Terminal states are monotonic during parallel merge.
140
-
141
- ## Observability tips
142
-
143
- - Use `/team-dashboard` for a UI overview.
144
- - Use `team status runId=...` for canonical state and stale async detection.
145
- - Read `background.log` for early import/spawn errors.
146
- - Read `events.jsonl` for event chronology.
147
- - Read `agents/{taskId}/status.json` for per-agent model/progress/tool status.
148
- - Read `artifacts/{runId}/transcripts/{taskId}.jsonl` for raw child Pi transcript.
1
+ # pi-crew Runtime Flow
2
+
3
+ This document is a compact map of the runtime paths used by `pi-crew`.
4
+
5
+ ## Main sequence
6
+
7
+ ```text
8
+ User / model
9
+ │ calls team({ action: "run", ... }) or /team-run
10
+
11
+ handleTeamTool()
12
+ │ validates schema and routes action
13
+
14
+ handleRun()
15
+ ├─ discoverTeams/discoverWorkflows/discoverAgents
16
+ ├─ validateWorkflowForTeam
17
+ ├─ expandParallelResearchWorkflow when applicable
18
+ ├─ createRunManifest + tasks.json + goal artifact
19
+ ├─ if async=true ─────────────────────────────────────────────┐
20
+ │ spawnBackgroundTeamRun() │
21
+ │ ├─ resolve jiti-register.mjs │
22
+ │ ├─ fail-fast if jiti missing │
23
+ │ ├─ node --import jiti-register.mjs background-runner.ts │
24
+ │ └─ parent schedules early-exit guard │
25
+ │ ▼
26
+ │ background-runner.ts
27
+ │ ├─ append async.started
28
+ │ ├─ write async.pid startup marker
29
+ │ ├─ rediscover team/workflow/agents
30
+ │ └─ executeTeamRun()
31
+
32
+ └─ if foreground/default
33
+ ├─ startForegroundRun schedules session-bound run, or
34
+ └─ executeTeamRun inline for scaffold/non-scheduled paths
35
+
36
+ executeTeamRun()
37
+ ├─ write run.running
38
+ ├─ materialize queued/running agent records lazily
39
+ ├─ build task graph index
40
+ ├─ while queued tasks exist
41
+ │ ├─ taskGraphSnapshot
42
+ │ ├─ resolveBatchConcurrency
43
+ │ ├─ getReadyTasks
44
+ │ ├─ append task.progress batch event
45
+ │ ├─ mapConcurrent ready batch
46
+ │ │ └─ runTeamTask()
47
+ │ │ ├─ prepare workspace/worktree
48
+ │ │ ├─ build task packet
49
+ │ │ ├─ render prompt + dependency context
50
+ │ │ ├─ choose model candidates from Pi config
51
+ │ │ ├─ spawn child Pi process
52
+ │ │ ├─ ChildPiLineObserver parses stdout/stderr
53
+ │ │ ├─ append per-agent events/output
54
+ │ │ ├─ update agent progress/task state
55
+ │ │ ├─ parse final JSONL/session usage
56
+ │ │ └─ write result/log/transcript/metadata artifacts
57
+ │ ├─ merge task updates monotonically
58
+ │ ├─ optional adaptive plan injection
59
+ │ ├─ save tasks/agents/progress
60
+ │ └─ write batch artifact
61
+ ├─ policy closeout
62
+ └─ run.completed / run.failed / run.blocked / run.cancelled
63
+ ```
64
+
65
+ ## Action router
66
+
67
+ | Action | Handler | Purpose |
68
+ |---|---|---|
69
+ | `run` | `team-tool/run.ts` | Create and execute a run, foreground or async. |
70
+ | `status` | `team-tool.ts` | Show manifest/tasks/agents/events and mark stale async runs failed. |
71
+ | `summary` | `session-summary.ts`/summary handler | Write/read run summary artifact. |
72
+ | `events` | `team-tool.ts` | Tail durable run events. |
73
+ | `artifacts` | `team-tool.ts` | List run artifacts. |
74
+ | `resume` | `team-tool.ts` | Requeue failed/cancelled/skipped/running tasks. |
75
+ | `cancel` | `team-tool.ts` | Mark queued/running tasks cancelled and request foreground interrupt. |
76
+ | `forget` | `run-maintenance.ts` | Delete run state/artifacts with confirmation. |
77
+ | `prune` | `run-maintenance.ts` | Remove old finished runs with confirmation. |
78
+ | `export` | `run-export.ts` | Create portable run bundle. |
79
+ | `import` / `imports` | `run-import.ts` / `import-index.ts` | Store/list imported bundles. |
80
+ | `config` | `config.ts` + config action | Show/update user/project config. |
81
+ | `doctor` | `team-tool/doctor.ts` | Platform/resource/runtime diagnostics. |
82
+ | `validate` | `validate-resources.ts` | Validate agents/teams/workflows. |
83
+ | `recommend` | `team-recommendation.ts` | Suggest team/workflow/action for a goal. |
84
+ | management | `management.ts` | Create/update/delete/rename teams, agents, workflows. |
85
+ | API | `team-tool/api.ts` | File-backed observability/control/mailbox API. |
86
+
87
+ ## Worker modes
88
+
89
+ | Mode | Behavior |
90
+ |---|---|
91
+ | `child-process` | Default. Launches real child `pi` processes per task. |
92
+ | `scaffold` | Explicit dry-run. No child Pi worker execution. |
93
+ | `live-session` | Experimental/gated in-process/live agent path. |
94
+ | `auto` | Resolves to child-process unless config/env requests otherwise. |
95
+
96
+ ## Important files
97
+
98
+ ```text
99
+ src/extension/register.ts Pi extension entry/wiring
100
+ src/extension/team-tool/run.ts run creation and foreground/async split
101
+ src/runtime/background-runner.ts detached async entrypoint
102
+ src/runtime/async-runner.ts background spawn command/options
103
+ src/runtime/team-runner.ts workflow/task graph scheduler
104
+ src/runtime/task-runner.ts single task execution
105
+ src/runtime/child-pi.ts child Pi process and output observer
106
+ src/runtime/model-fallback.ts configured model candidates/routing
107
+ src/runtime/concurrency.ts batch concurrency decisions
108
+ src/runtime/process-status.ts pid/liveness/stale detection
109
+ src/state/state-store.ts manifest/tasks persistence
110
+ src/state/event-log.ts JSONL run events
111
+ src/runtime/crew-agent-records.ts aggregate + per-agent status files
112
+ ```
113
+
114
+ ## Environment variables
115
+
116
+ | Env | Effect |
117
+ |---|---|
118
+ | `PI_CREW_EXECUTE_WORKERS=0` | Disable real workers, use scaffold behavior. |
119
+ | `PI_TEAMS_EXECUTE_WORKERS=0` | Legacy alias for worker disable. |
120
+ | `PI_CREW_ENABLE_EXPERIMENTAL_LIVE_SESSION=1` | Allow experimental live-session runtime. |
121
+ | `PI_CREW_MOCK_LIVE_SESSION=success` | Test hook for live-session mock. |
122
+ | `PI_TEAMS_MOCK_CHILD_PI` | Test hook for mocked child Pi execution. |
123
+ | `PI_CREW_DEPTH`, `PI_CREW_MAX_DEPTH` | Canonical subagent recursion guard. |
124
+ | `PI_TEAMS_DEPTH`, `PI_TEAMS_MAX_DEPTH` | Legacy recursion guard aliases. |
125
+ | `PI_TEAMS_HOME` | Override user config/state home in tests. |
126
+ | `PI_TEAMS_PI_BIN` | Override child `pi` executable. |
127
+ | `PI_CODING_AGENT_DIR` | Override Pi settings/models directory for model discovery. |
128
+ | `PI_CREW_ASYNC_EARLY_EXIT_GUARD=0` | Disable 3s background early-exit guard. |
129
+
130
+ ## State transition summary
131
+
132
+ ```text
133
+ queued/planning/running ── completed
134
+ ├─ failed
135
+ ├─ blocked
136
+ └─ cancelled
137
+ ```
138
+
139
+ Task states follow the same durable contract plus `skipped`. Terminal states are monotonic during parallel merge.
140
+
141
+ ## Observability tips
142
+
143
+ - Use `/team-dashboard` for a UI overview.
144
+ - Use `team status runId=...` for canonical state and stale async detection.
145
+ - Read `background.log` for early import/spawn errors.
146
+ - Read `events.jsonl` for event chronology.
147
+ - Read `agents/{taskId}/status.json` for per-agent model/progress/tool status.
148
+ - Read `artifacts/{runId}/transcripts/{taskId}.jsonl` for raw child Pi transcript.
@@ -1,83 +1,83 @@
1
- # pi-crew runtime refactor source map
2
-
3
- This document records the source projects used as the baseline for the pi-crew subagent/runtime refactor. The goal is to avoid ad-hoc fixes in critical process orchestration paths and instead align pi-crew with proven Pi extension patterns.
4
-
5
- ## Source/pi-subagents
6
-
7
- Primary source for child-process worker execution.
8
-
9
- - `pi-spawn.ts`: robust Pi CLI resolution on Windows and package installs.
10
- - `async-execution.ts`: detached async runner with `windowsHide: true` to avoid blank console windows.
11
- - `subagent-runner.ts`: streaming child Pi process runner, output capture, result extraction.
12
- - `post-exit-stdio-guard.ts`: guards for child processes that exit before stdio fully closes.
13
- - `result-watcher.ts` and `async-job-tracker.ts`: durable async job/result observation patterns.
14
- - `model-fallback.ts`: model fallback policy independent of hardcoded provider assumptions.
15
- - `subagent-control.ts`, `run-status.ts`: status and control semantics.
16
-
17
- pi-crew alignment:
18
-
19
- - Background runner and child worker spawn options now explicitly set `windowsHide: true`.
20
- - Parallel research no longer gates all shard workers behind a single discover worker.
21
- - Further work should consolidate `child-pi.ts`, `async-runner.ts`, and `subagent-manager.ts` into a durable-first subagent runtime module.
22
-
23
- ## Source/pi-subagents2
24
-
25
- Primary source for higher-level agent management and UI patterns.
26
-
27
- - `src/agent-manager.ts`: agent lifecycle registry boundaries.
28
- - `src/agent-runner.ts`: invocation/run abstraction separate from UI registration.
29
- - `src/model-resolver.ts`: cleaner model resolution responsibility.
30
- - `src/output-file.ts`: output file abstraction.
31
- - `src/ui/agent-widget.ts`, `src/ui/conversation-viewer.ts`: compact live status and transcript viewing.
32
-
33
- pi-crew alignment:
34
-
35
- - Keep `Agent`/`crew_agent` tools as thin adapters over a durable manager.
36
- - Avoid storing essential run mapping in memory only.
37
- - Keep UI active-only and file-backed.
38
-
39
- ## Source/pi-mono
40
-
41
- Primary source for Pi extension API/lifecycle constraints.
42
-
43
- - `packages/coding-agent/src/core/extensions/types.ts`: extension context/tool contracts.
44
- - `packages/coding-agent/src/core/extensions/runner.ts`: extension execution boundaries.
45
- - `packages/coding-agent/src/core/model-registry.ts`: available model discovery.
46
- - `packages/coding-agent/src/modes/interactive/interactive-mode.ts`: session lifecycle/UI behavior.
47
-
48
- pi-crew alignment:
49
-
50
- - Treat session-bound foreground workers differently from explicit async background workers.
51
- - Do not assume hardcoded providers/models.
52
- - Use Pi-native UI calls without modal auto-open by default.
53
-
54
- ## Source/pi-powerbar, pi-plan, pi-diff-review, pi-extensions*
55
-
56
- Sources for UI and small-extension patterns.
57
-
58
- - `pi-powerbar/src/powerbar/*`: low-noise status segment publishing.
59
- - `pi-plan/src/plan-action-ui.ts`: action-oriented UI without persistent heavy overlays.
60
- - `pi-diff-review/src/*`: command/tool registration and review UX patterns.
61
- - `pi-extensions2/files-widget/*`: file-backed UI composition and navigation.
62
-
63
- pi-crew alignment:
64
-
65
- - Keep persistent widget active-only.
66
- - Prefer manual dashboard/transcript commands for history.
67
- - Avoid expensive render scans and auto-opening focus-capturing overlays.
68
-
69
- ## Current refactor checkpoints
70
-
71
- - [x] Hide Windows console windows for background runner and child Pi workers.
72
- - [x] Make parallel research shard workers start in parallel instead of depending on a single discover worker.
73
- - [x] Keep direct-agent reconstruction gated by `workflow === "direct-agent"` only.
74
- - [x] Persist subagent records and recover terminal results after restart.
75
- - [x] Fail fast for unrecoverable persisted records without `runId` instead of hanging.
76
- - [x] Persist direct-agent model override into task state for background/resume reconstruction.
77
-
78
- ## Remaining larger subsystem work
79
-
80
- - Consolidate subagent runtime into `src/subagents/*` or equivalent durable-first module.
81
- - Move model routing transparency into persisted task/subagent records: requested model, selected model, fallback chain, fallback reason.
82
- - Add real integration smoke scripts for Windows process visibility, async restart recovery, and multi-shard fanout.
83
- - Add adaptive planner repair/retry for invalid JSON instead of immediate block when safe.
1
+ # pi-crew runtime refactor source map
2
+
3
+ This document records the source projects used as the baseline for the pi-crew subagent/runtime refactor. The goal is to avoid ad-hoc fixes in critical process orchestration paths and instead align pi-crew with proven Pi extension patterns.
4
+
5
+ ## Source/pi-subagents
6
+
7
+ Primary source for child-process worker execution.
8
+
9
+ - `pi-spawn.ts`: robust Pi CLI resolution on Windows and package installs.
10
+ - `async-execution.ts`: detached async runner with `windowsHide: true` to avoid blank console windows.
11
+ - `subagent-runner.ts`: streaming child Pi process runner, output capture, result extraction.
12
+ - `post-exit-stdio-guard.ts`: guards for child processes that exit before stdio fully closes.
13
+ - `result-watcher.ts` and `async-job-tracker.ts`: durable async job/result observation patterns.
14
+ - `model-fallback.ts`: model fallback policy independent of hardcoded provider assumptions.
15
+ - `subagent-control.ts`, `run-status.ts`: status and control semantics.
16
+
17
+ pi-crew alignment:
18
+
19
+ - Background runner and child worker spawn options now explicitly set `windowsHide: true`.
20
+ - Parallel research no longer gates all shard workers behind a single discover worker.
21
+ - Further work should consolidate `child-pi.ts`, `async-runner.ts`, and `subagent-manager.ts` into a durable-first subagent runtime module.
22
+
23
+ ## Source/pi-subagents2
24
+
25
+ Primary source for higher-level agent management and UI patterns.
26
+
27
+ - `src/agent-manager.ts`: agent lifecycle registry boundaries.
28
+ - `src/agent-runner.ts`: invocation/run abstraction separate from UI registration.
29
+ - `src/model-resolver.ts`: cleaner model resolution responsibility.
30
+ - `src/output-file.ts`: output file abstraction.
31
+ - `src/ui/agent-widget.ts`, `src/ui/conversation-viewer.ts`: compact live status and transcript viewing.
32
+
33
+ pi-crew alignment:
34
+
35
+ - Keep `Agent`/`crew_agent` tools as thin adapters over a durable manager.
36
+ - Avoid storing essential run mapping in memory only.
37
+ - Keep UI active-only and file-backed.
38
+
39
+ ## Source/pi-mono
40
+
41
+ Primary source for Pi extension API/lifecycle constraints.
42
+
43
+ - `packages/coding-agent/src/core/extensions/types.ts`: extension context/tool contracts.
44
+ - `packages/coding-agent/src/core/extensions/runner.ts`: extension execution boundaries.
45
+ - `packages/coding-agent/src/core/model-registry.ts`: available model discovery.
46
+ - `packages/coding-agent/src/modes/interactive/interactive-mode.ts`: session lifecycle/UI behavior.
47
+
48
+ pi-crew alignment:
49
+
50
+ - Treat session-bound foreground workers differently from explicit async background workers.
51
+ - Do not assume hardcoded providers/models.
52
+ - Use Pi-native UI calls without modal auto-open by default.
53
+
54
+ ## Source/pi-powerbar, pi-plan, pi-diff-review, pi-extensions*
55
+
56
+ Sources for UI and small-extension patterns.
57
+
58
+ - `pi-powerbar/src/powerbar/*`: low-noise status segment publishing.
59
+ - `pi-plan/src/plan-action-ui.ts`: action-oriented UI without persistent heavy overlays.
60
+ - `pi-diff-review/src/*`: command/tool registration and review UX patterns.
61
+ - `pi-extensions2/files-widget/*`: file-backed UI composition and navigation.
62
+
63
+ pi-crew alignment:
64
+
65
+ - Keep persistent widget active-only.
66
+ - Prefer manual dashboard/transcript commands for history.
67
+ - Avoid expensive render scans and auto-opening focus-capturing overlays.
68
+
69
+ ## Current refactor checkpoints
70
+
71
+ - [x] Hide Windows console windows for background runner and child Pi workers.
72
+ - [x] Make parallel research shard workers start in parallel instead of depending on a single discover worker.
73
+ - [x] Keep direct-agent reconstruction gated by `workflow === "direct-agent"` only.
74
+ - [x] Persist subagent records and recover terminal results after restart.
75
+ - [x] Fail fast for unrecoverable persisted records without `runId` instead of hanging.
76
+ - [x] Persist direct-agent model override into task state for background/resume reconstruction.
77
+
78
+ ## Remaining larger subsystem work
79
+
80
+ - Consolidate subagent runtime into `src/subagents/*` or equivalent durable-first module.
81
+ - Move model routing transparency into persisted task/subagent records: requested model, selected model, fallback chain, fallback reason.
82
+ - Add real integration smoke scripts for Windows process visibility, async restart recovery, and multi-shard fanout.
83
+ - Add adaptive planner repair/retry for invalid JSON instead of immediate block when safe.
package/docs/usage.md CHANGED
@@ -107,6 +107,12 @@ Check status:
107
107
  }
108
108
  ```
109
109
 
110
+ Background `Agent`/`crew_agent` subagents wake the parent Pi session when they complete, so the parent can call `get_subagent_result`/`crew_agent_result` and continue without waiting for another user prompt.
111
+
112
+ ## State and API safety
113
+
114
+ State paths are validated before read/write operations. Run ids, imported bundles, artifact and transcript references, mailbox files, and agent control/log files must stay inside their expected `.crew` roots and symlink escapes are rejected. Read-only mailbox APIs return default state without creating mailbox files when no messages exist.
115
+
110
116
  ## Worktree mode
111
117
 
112
118
  ```json
package/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
- import { registerPiTeams } from "./src/extension/register.ts";
3
-
4
- export default function (pi: ExtensionAPI): void {
5
- registerPiTeams(pi);
6
- }
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { registerPiTeams } from "./src/extension/register.ts";
3
+
4
+ export default function (pi: ExtensionAPI): void {
5
+ registerPiTeams(pi);
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-crew",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "description": "Pi extension for coordinated AI teams, workflows, worktrees, and async task orchestration",
5
5
  "author": "baphuongna",
6
6
  "license": "MIT",
@@ -47,8 +47,8 @@
47
47
  "ci": "npm run typecheck && npm test && npm pack --dry-run",
48
48
  "typecheck": "tsc --noEmit && node --experimental-strip-types -e \"await import('./index.ts'); console.log('strip-types import ok')\"",
49
49
  "test": "npm run test:unit && npm run test:integration",
50
- "test:unit": "node --experimental-strip-types --test --test-timeout=30000 test/unit/*.test.ts",
51
- "test:integration": "node --experimental-strip-types --test --test-timeout=120000 test/integration/*.test.ts",
50
+ "test:unit": "node --experimental-strip-types --test --test-concurrency=1 --test-timeout=30000 test/unit/*.test.ts",
51
+ "test:integration": "node --experimental-strip-types --test --test-concurrency=1 --test-timeout=120000 test/integration/*.test.ts",
52
52
  "smoke:pi": "pi install ."
53
53
  },
54
54
  "exports": {
package/schema.json CHANGED
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "executeWorkers": {
13
13
  "type": "boolean",
14
- "description": "Allow real child Pi workers without setting PI_TEAMS_EXECUTE_WORKERS=1."
14
+ "description": "Allow real child Pi workers. Defaults to true; set false or use PI_CREW_EXECUTE_WORKERS=0/PI_TEAMS_EXECUTE_WORKERS=0 to force scaffold mode."
15
15
  },
16
16
  "notifierIntervalMs": {
17
17
  "type": "number",
@@ -128,7 +128,7 @@
128
128
  "showModel": { "type": "boolean", "default": true, "description": "Show worker model attempts in dashboard agent rows." },
129
129
  "showTokens": { "type": "boolean", "description": "Show token usage in dashboard agent rows." },
130
130
  "showTools": { "type": "boolean", "description": "Show tool activity in dashboard agent rows." },
131
- "transcriptTailBytes": { "type": "integer", "minimum": 1024, "default": 262144, "description": "Maximum transcript bytes to parse by default; use viewer hotkey f to load full content." },
131
+ "transcriptTailBytes": { "type": "integer", "minimum": 1024, "maximum": 52428800, "default": 262144, "description": "Maximum transcript bytes to parse by default; use viewer hotkey f to load full content." },
132
132
  "mascotStyle": { "type": "string", "enum": ["cat", "armin"] },
133
133
  "mascotEffect": { "type": "string", "enum": ["random", "none", "typewriter", "scanline", "rain", "fade", "crt", "glitch", "dissolve"] }
134
134
  }
@@ -1,34 +1,34 @@
1
- import type { AgentConfig } from "./agent-config.ts";
2
-
3
- function line(key: string, value: string | boolean | string[] | undefined): string | undefined {
4
- if (value === undefined) return undefined;
5
- if (Array.isArray(value)) return `${key}: ${value.join(", ")}`;
6
- return `${key}: ${String(value)}`;
7
- }
8
-
9
- export function serializeAgent(agent: AgentConfig): string {
10
- const lines = [
11
- "---",
12
- `name: ${agent.name}`,
13
- `description: ${agent.description}`,
14
- line("model", agent.model),
15
- line("fallbackModels", agent.fallbackModels),
16
- line("thinking", agent.thinking),
17
- line("tools", agent.tools),
18
- agent.extensions !== undefined ? line("extensions", agent.extensions) ?? "extensions:" : undefined,
19
- line("skills", agent.skills),
20
- line("systemPromptMode", agent.systemPromptMode),
21
- line("inheritProjectContext", agent.inheritProjectContext),
22
- line("inheritSkills", agent.inheritSkills),
23
- line("triggers", agent.routing?.triggers),
24
- line("useWhen", agent.routing?.useWhen),
25
- line("avoidWhen", agent.routing?.avoidWhen),
26
- line("cost", agent.routing?.cost),
27
- line("category", agent.routing?.category),
28
- "---",
29
- "",
30
- agent.systemPrompt.trim(),
31
- "",
32
- ].filter((entry): entry is string => entry !== undefined);
33
- return lines.join("\n");
34
- }
1
+ import type { AgentConfig } from "./agent-config.ts";
2
+
3
+ function line(key: string, value: string | boolean | string[] | undefined): string | undefined {
4
+ if (value === undefined) return undefined;
5
+ if (Array.isArray(value)) return `${key}: ${value.join(", ")}`;
6
+ return `${key}: ${String(value)}`;
7
+ }
8
+
9
+ export function serializeAgent(agent: AgentConfig): string {
10
+ const lines = [
11
+ "---",
12
+ `name: ${agent.name}`,
13
+ `description: ${agent.description}`,
14
+ line("model", agent.model),
15
+ line("fallbackModels", agent.fallbackModels),
16
+ line("thinking", agent.thinking),
17
+ line("tools", agent.tools),
18
+ agent.extensions !== undefined ? line("extensions", agent.extensions) ?? "extensions:" : undefined,
19
+ line("skills", agent.skills),
20
+ line("systemPromptMode", agent.systemPromptMode),
21
+ line("inheritProjectContext", agent.inheritProjectContext),
22
+ line("inheritSkills", agent.inheritSkills),
23
+ line("triggers", agent.routing?.triggers),
24
+ line("useWhen", agent.routing?.useWhen),
25
+ line("avoidWhen", agent.routing?.avoidWhen),
26
+ line("cost", agent.routing?.cost),
27
+ line("category", agent.routing?.category),
28
+ "---",
29
+ "",
30
+ agent.systemPrompt.trim(),
31
+ "",
32
+ ].filter((entry): entry is string => entry !== undefined);
33
+ return lines.join("\n");
34
+ }
@@ -319,8 +319,12 @@ function parseWithSchema<T extends TSchema>(schema: T, value: unknown): Static<T
319
319
  return Value.Decode(schema, value);
320
320
  }
321
321
 
322
+ function parseIntegerInRange(value: unknown, minimum = 1, maximum = Number.MAX_SAFE_INTEGER): number | undefined {
323
+ return parseWithSchema(Type.Integer({ minimum, maximum }), value);
324
+ }
325
+
322
326
  function parsePositiveInteger(value: unknown, max = Number.MAX_SAFE_INTEGER): number | undefined {
323
- return parseWithSchema(Type.Integer({ minimum: 1, maximum: max }), value);
327
+ return parseIntegerInRange(value, 1, max);
324
328
  }
325
329
 
326
330
  function parseProfile(value: unknown): PiTeamsAutonomyProfile | undefined {
@@ -462,14 +466,14 @@ function parseUiConfig(value: unknown): CrewUiConfig | undefined {
462
466
  widgetMaxLines: parsePositiveInteger(obj.widgetMaxLines, 50),
463
467
  powerbar: parseWithSchema(Type.Boolean(), obj.powerbar),
464
468
  dashboardPlacement: rawDashboardPlacement,
465
- dashboardWidth: parsePositiveInteger(obj.dashboardWidth, 120),
466
- dashboardLiveRefreshMs: parsePositiveInteger(obj.dashboardLiveRefreshMs, 60_000),
469
+ dashboardWidth: parseIntegerInRange(obj.dashboardWidth, 32, 120),
470
+ dashboardLiveRefreshMs: parseIntegerInRange(obj.dashboardLiveRefreshMs, 250, 60_000),
467
471
  autoOpenDashboard: parseWithSchema(Type.Boolean(), obj.autoOpenDashboard),
468
472
  autoOpenDashboardForForegroundRuns: parseWithSchema(Type.Boolean(), obj.autoOpenDashboardForForegroundRuns),
469
473
  showModel: parseWithSchema(Type.Boolean(), obj.showModel),
470
474
  showTokens: parseWithSchema(Type.Boolean(), obj.showTokens),
471
475
  showTools: parseWithSchema(Type.Boolean(), obj.showTools),
472
- transcriptTailBytes: parsePositiveInteger(obj.transcriptTailBytes, 50 * 1024 * 1024),
476
+ transcriptTailBytes: parseIntegerInRange(obj.transcriptTailBytes, 1024, 50 * 1024 * 1024),
473
477
  mascotStyle: parseWithSchema(Type.Union([Type.Literal("cat"), Type.Literal("armin")]), obj.mascotStyle),
474
478
  mascotEffect: parseWithSchema(Type.Union([Type.Literal("random"), Type.Literal("none"), Type.Literal("typewriter"), Type.Literal("scanline"), Type.Literal("rain"), Type.Literal("fade"), Type.Literal("crt"), Type.Literal("glitch"), Type.Literal("dissolve")]), obj.mascotEffect),
475
479
  };