pi-crew 0.1.28 → 0.1.30

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 (59) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/NOTICE.md +1 -0
  3. package/docs/architecture.md +164 -92
  4. package/docs/refactor-tasks-phase6.md +662 -0
  5. package/docs/runtime-flow.md +148 -0
  6. package/package.json +1 -1
  7. package/schema.json +1 -0
  8. package/skills/git-master/SKILL.md +19 -0
  9. package/skills/read-only-explorer/SKILL.md +21 -0
  10. package/skills/safe-bash/SKILL.md +16 -0
  11. package/skills/task-packet/SKILL.md +23 -0
  12. package/skills/verify-evidence/SKILL.md +22 -0
  13. package/src/config/config.ts +2 -0
  14. package/src/config/defaults.ts +1 -0
  15. package/src/extension/async-notifier.ts +33 -4
  16. package/src/extension/register.ts +15 -522
  17. package/src/extension/registration/artifact-cleanup.ts +14 -0
  18. package/src/extension/registration/commands.ts +208 -0
  19. package/src/extension/registration/subagent-helpers.ts +1 -1
  20. package/src/extension/registration/subagent-tools.ts +110 -0
  21. package/src/extension/registration/team-tool.ts +44 -0
  22. package/src/extension/team-tool/api.ts +4 -4
  23. package/src/extension/team-tool/cancel.ts +31 -0
  24. package/src/extension/team-tool/inspect.ts +41 -0
  25. package/src/extension/team-tool/lifecycle-actions.ts +79 -0
  26. package/src/extension/team-tool/plan.ts +19 -0
  27. package/src/extension/team-tool/run.ts +41 -3
  28. package/src/extension/team-tool/status.ts +73 -0
  29. package/src/extension/team-tool.ts +57 -224
  30. package/src/runtime/async-marker.ts +26 -0
  31. package/src/runtime/async-runner.ts +44 -9
  32. package/src/runtime/background-runner.ts +2 -0
  33. package/src/runtime/child-pi.ts +5 -1
  34. package/src/runtime/concurrency.ts +9 -3
  35. package/src/runtime/crew-agent-records.ts +1 -0
  36. package/src/runtime/crew-agent-runtime.ts +2 -1
  37. package/src/runtime/model-fallback.ts +21 -4
  38. package/src/runtime/pi-args.ts +2 -0
  39. package/src/runtime/process-status.ts +1 -0
  40. package/src/runtime/role-permission.ts +11 -0
  41. package/src/runtime/task-runner/live-executor.ts +98 -0
  42. package/src/runtime/task-runner/progress.ts +111 -0
  43. package/src/runtime/task-runner/prompt-builder.ts +72 -0
  44. package/src/runtime/task-runner/result-utils.ts +14 -0
  45. package/src/runtime/task-runner/state-helpers.ts +22 -0
  46. package/src/runtime/task-runner.ts +38 -283
  47. package/src/runtime/team-runner.ts +116 -7
  48. package/src/schema/config-schema.ts +1 -0
  49. package/src/state/mailbox.ts +28 -0
  50. package/src/state/types.ts +16 -0
  51. package/src/subagents/async-entry.ts +1 -0
  52. package/src/subagents/index.ts +3 -0
  53. package/src/subagents/live/control.ts +1 -0
  54. package/src/subagents/live/manager.ts +1 -0
  55. package/src/subagents/live/realtime.ts +1 -0
  56. package/src/subagents/live/session-runtime.ts +1 -0
  57. package/src/subagents/manager.ts +1 -0
  58. package/src/subagents/spawn.ts +1 -0
  59. package/src/ui/live-run-sidebar.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ### Added
6
+
7
+ - Added Phase 6 async hardening: jiti loader resolution/fail-fast, async startup marker files, and early background-runner exit detection.
8
+ - Added worker concurrency hard cap with explicit `limits.allowUnboundedConcurrency` opt-out and observability event.
9
+ - Added persisted model routing metadata on tasks and agent records: requested model, resolved model, fallback chain, reason, and used attempt.
10
+ - Added self-contained architecture/runtime-flow docs and five built-in coding skills.
11
+ - Added mailbox replay on resume for pending inbox messages, including task-scoped messages.
12
+ - Added task resume checkpoints and recovery for crash-after-final-stdout and crash-after-artifact-write child-process tasks.
13
+ - Added async notifier detection for quiet dead background runners with durable `async.died` events.
14
+ - Added adaptive planner repair for malformed JSON, oversized task plans, and common role aliases before blocking implementation runs.
15
+ - Added package snapshot coverage for Phase 6 docs, skills, Pi manifest entries, and the runtime `jiti` dependency.
16
+ - Added `src/subagents/*` consolidation entrypoints for child spawning, background runner commands, and subagent manager APIs.
17
+ - Split `team-tool.ts` actions into focused status, inspect, lifecycle, cancel, and plan modules while preserving public action names.
18
+ - Split `register.ts` lifecycle wiring into command, team-tool, subagent-tool, and artifact-cleanup registration modules.
19
+ - Added async restart recovery integration smoke coverage for stale background pids.
20
+ - Added explicit recursive subagent depth and read-only role spawn-denial tests.
21
+
22
+ ### Changed
23
+
24
+ - Async background runs now use an explicit jiti loader path and expose startup markers for recovery/health checks.
25
+ - Active batch selection now caps excessive user concurrency by default to protect local machines.
26
+ - Resume now emits mailbox replay metadata before restarting queued work.
27
+ - Child-process tasks now persist checkpoint phases (`started`, `child-spawned`, `child-stdout-final`, `artifact-written`) during execution.
28
+ - Split `task-runner.ts` prompt/progress/state/live helpers into focused modules while keeping `runTeamTask` as the public entrypoint.
29
+ - Moved live-session access behind `src/subagents/live/*` and dynamic task-runner imports so default child-process flow does not eagerly load live runtime code.
30
+
31
+ ### Fixed
32
+
33
+ - Background runner startup failures are reported earlier instead of silently leaving queued/running manifests stale.
34
+
35
+ ### Release prep notes
36
+
37
+ - Suggested next release grouping: `0.1.30` for Phase 6 runtime hardening, resume recovery, model observability, docs/skills, and internal refactors.
38
+ - Gate run locally: `npm run typecheck`, `npm test`, and `npm pack --dry-run`.
39
+ - No breaking public API changes: tool actions, slash commands, config schema, and package name remain stable.
40
+
41
+ ## 0.1.29
42
+
43
+ - Republished the child worker response timeout fix as a fresh npm version.
44
+
3
45
  ## 0.1.28
4
46
 
5
47
  - Fixed child-process workers being terminated after only 15 seconds of quiet provider/tool time by increasing the default response watchdog to five minutes and clarifying the timeout error message.
package/NOTICE.md CHANGED
@@ -7,6 +7,7 @@
7
7
  - Primary design and Pi-extension implementation inspiration: `pi-subagents` by Nico Bailon, MIT license.
8
8
  - Team orchestration, state, and worktree contract inspiration: `oh-my-claudecode` by Yeachan Heo, MIT license.
9
9
  - Conceptual inspiration only: `oh-my-openagent` / `oh-my-opencode`, SUL-1.0. No source code from this project should be copied into `pi-crew` unless explicitly reviewed for license compatibility and documented here.
10
+ - Built-in skill topics are original pi-crew guidance informed by common agent-skill patterns in `Source/awesome-agent-skills`, `Source/oh-my-claudecode`, and related local references; no verbatim skill text was copied.
10
11
 
11
12
  ## Copied code policy
12
13
 
@@ -1,92 +1,164 @@
1
- # pi-crew Architecture
2
-
3
- Canonical architecture documentation currently lives at workspace level:
4
-
5
- - `../docs/pi-crew-source-review-and-lessons.md`
6
- - `../docs/pi-crew-architecture.md`
7
- - `../docs/pi-crew-mvp-plan.md`
8
-
9
- This project-local document exists so the package contains an obvious documentation entry point. Keep it in sync as implementation progresses.
10
-
11
- ## Current scaffold
12
-
13
- Implemented now:
14
-
15
- - Pi package manifest
16
- - autonomous delegation policy injection so the agent can decide when to use the `team` tool
17
- - dynamic autonomous resource guidance generated from discovered agents/teams/workflows
18
- - `recommend` action for agent-side team/workflow routing, decomposition, and fanout hints before plan/run
19
- - `autonomy` action and `/team-autonomy` command for toggling autonomous delegation and profiles
20
- - centralized state contracts plus task-claim, worker-heartbeat, run-lock, progress-artifact, mailbox files, dashboard progress/action helpers, and safe API interop contracts for runtime hardening
21
- - extension entrypoint
22
- - main `team` tool
23
- - slash commands: `/teams`, `/team-run`, `/team-status`, `/team-doctor`
24
- - builtin agent/team/workflow markdown resources
25
- - resource discovery for builtin/user/project paths
26
- - TypeBox tool schema
27
- - model fallback helper
28
- - state type definitions
29
- - atomic state writes
30
- - JSONL event log
31
- - artifact store with content hashes
32
- - durable run manifests and task files
33
- - workflow validation
34
- - foreground workflow scheduler
35
- - child Pi task execution by default
36
- - explicit scaffold/dry-run task execution via `runtime.mode=scaffold` or `executeWorkers=false`
37
- - safety-first create/update/delete for agents, teams, and workflows
38
- - backups for update/delete mutations
39
- - dry-run support for management mutations
40
- - detached async background runner
41
- - opt-in git worktree task workspace creation
42
- - worktree diff artifacts
43
- - child prompt runtime for inherited project-context/skills stripping
44
- - retryable model fallback attempts per worker task
45
- - rich status output with recent artifacts and event tail
46
- - recent run listing
47
- - `/team-cleanup` worktree cleanup command
48
- - improved `/team-run` parser for `--async`, `--worktree`, `--team=`, `--workflow=`, `--role=`, `--agent=`
49
- - async completion polling notifications during Pi sessions
50
- - active run summary on session start
51
- - reference checks before deleting referenced agents/workflows
52
- - optional reference updates when renaming agents/workflows
53
- - expanded doctor checks for `pi`, `git`, writable state paths, and resource discovery
54
- - durable run integration-style test coverage
55
- - user config loader for async defaults, worker execution, notifier interval, and worktree cleanliness policy
56
- - `pi-crew` install helper that creates default config
57
- - worktree branch mismatch detection before reuse
58
- - simple interactive `/team-manager` built with Pi UI dialogs
59
- - dedicated `events` and `artifacts` actions plus slash commands
60
- - persisted worktree metadata on task state/status
61
- - mocked child Pi execution path for integration-style tests
62
- - package polish: `.gitignore`, `tsconfig.json`, `npm run check`
63
- - project-local `AGENTS.md` development rules
64
- - run resume action/command that re-queues failed/cancelled/skipped/running tasks
65
- - dedicated worktrees inspection action and `/team-worktrees`
66
- - real temp-git worktree integration test
67
- - async run metadata persisted in manifest/status
68
- - stale async PID detection that marks active orphaned runs failed on status inspection
69
- - child Pi JSON output parsing for final text, usage, and JSON event counts
70
- - aggregate usage totals in status/summary
71
- - summary artifact and `summary` action/`/team-summary` command
72
- - custom overlay `/team-dashboard` run browser built with `ctx.ui.custom`
73
- - dashboard details pane with status counts and selected run metadata
74
- - prune action and `/team-prune` to remove old finished runs after confirmation
75
- - export action and `/team-export` to write portable JSON/Markdown run bundles
76
- - import action and `/team-import` to store exported bundles under local imports
77
- - imports action and `/team-imports` to browse imported bundles
78
- - help action and `/team-help` command
79
- - validate action and `/team-validate` command for agents/teams/workflows
80
- - doctor auto-runs resource validation and reports validation errors/warnings
81
- - project init action and `/team-init` command for `.pi` directories, `.gitignore`, and optional builtin resource copying
82
- - config action and `/team-config` command
83
- - published `schema.json` for config validation
84
- - publishing checklist docs
85
- - `/team-cancel` command alias
86
- - forget action and `/team-forget` to delete run state/artifacts after confirmation
87
- - resource format documentation
88
- - unit tests for async stale detection, autonomous config toggling, autonomous policy, autonomous recommendation/decomposition, config, project config merge, config action, dashboard rendering/navigation, discovery, doctor/model validation, events/artifacts/worktrees inspection, export/import run bundles and schema validation, help output, imported bundle listing, forget run cleanup, management, management reference checks, mocked child execution, child JSON output parsing and fixtures, model fallback, project init, prompt runtime, prune run cleanup, resource validation, resume/cancel, routing metadata, runtime hardening/progress/API interop, state contracts, state store, summary artifact/action, task claims, team run persistence, worker heartbeat, worktree mode, and workflow validation
89
-
90
- Not implemented yet:
91
-
92
- - richer multi-pane custom TUI manager
1
+ # pi-crew Architecture
2
+
3
+ `pi-crew` is a Pi package for coordinated multi-agent work. It is intentionally durable-first: every run is represented on disk, every task has a state record, and child workers stream progress into JSONL/status files so foreground sessions, background jobs, dashboards, and later restarts all read the same source of truth.
4
+
5
+ ## Layers
6
+
7
+ ```text
8
+ Pi extension layer
9
+ register tools, slash commands, widget/dashboard, notifier, lifecycle cleanup
10
+
11
+ Runtime layer
12
+ team runner, task graph scheduler, child Pi process runner, async runner,
13
+ model fallback, policy engine, worktree manager, live-session experimental path
14
+
15
+ State layer
16
+ .pi/teams/state/runs/{runId}/manifest.json
17
+ .pi/teams/state/runs/{runId}/tasks.json
18
+ .pi/teams/state/runs/{runId}/events.jsonl
19
+ .pi/teams/state/runs/{runId}/agents/{taskId}/status.json
20
+ .pi/teams/artifacts/{runId}/...
21
+ ```
22
+
23
+ ## Run flow
24
+
25
+ ```text
26
+ user/team tool
27
+
28
+
29
+ handleTeamTool(action=run)
30
+ ├─ discover agents/teams/workflows
31
+ ├─ validate team/workflow refs
32
+ ├─ create run manifest + task graph
33
+ ├─ write goal artifact
34
+ └─ choose foreground/session-bound or async/background mode
35
+
36
+ ├─ foreground: startForegroundRun() schedules executeTeamRun()
37
+
38
+ └─ async: spawnBackgroundTeamRun()
39
+ ├─ node --import jiti-register.mjs background-runner.ts
40
+ ├─ background-runner writes async.started + async.pid marker
41
+ └─ executeTeamRun()
42
+ ├─ resolve ready task batch
43
+ ├─ resolveBatchConcurrency() with hard cap
44
+ ├─ runTeamTask() per task
45
+ │ ├─ build prompt + dependency context
46
+ │ ├─ choose configured Pi model candidates
47
+ │ ├─ spawn child `pi` worker
48
+ │ ├─ observe JSONL/stdout progress
49
+ │ ├─ persist agent status/events/output
50
+ │ └─ write result/log/transcript artifacts
51
+ ├─ merge task updates monotonically
52
+ ├─ write progress artifacts
53
+ └─ synthesize policy closeout
54
+ ```
55
+
56
+ ## Extension layer
57
+
58
+ `src/extension/register.ts` wires the package into Pi:
59
+
60
+ - `team` tool and management actions.
61
+ - Conflict-safe subagent tools: `crew_agent`, `crew_agent_result`, `crew_agent_steer`.
62
+ - Claude-style aliases: `Agent`, `get_subagent_result`, `steer_subagent` when available.
63
+ - Slash commands including `/team-run`, `/team-status`, `/team-dashboard`, `/team-doctor`, `/team-config`, `/team-summary`.
64
+ - Active-only widget and optional dashboard/sidebar UI.
65
+ - Foreground run scheduling and shutdown cleanup.
66
+ - Async completion notifier and session-start active-run summary.
67
+
68
+ The extension layer should remain thin: user input is normalized into tool parameters, then delegated to runtime/state modules.
69
+
70
+ ## Runtime layer
71
+
72
+ ### Team runner
73
+
74
+ `src/runtime/team-runner.ts` drives workflow execution. It reads queued tasks, computes the ready set from the task graph, applies concurrency limits, runs a batch, then merges results back into the latest task state. Terminal task states are monotonic: stale parallel snapshots must not regress completed/failed/cancelled/skipped tasks back to queued/running.
75
+
76
+ ### Task runner
77
+
78
+ `src/runtime/task-runner.ts` executes one task. It prepares workspace/worktree context, renders a task prompt, chooses model candidates from Pi configuration, launches a child Pi process by default, and writes result artifacts. Scaffold mode is explicit dry-run only.
79
+
80
+ ### Child Pi runtime
81
+
82
+ `src/runtime/child-pi.ts` is the default worker runtime. It:
83
+
84
+ - launches real `pi` child processes,
85
+ - hides Windows console windows with `windowsHide: true`,
86
+ - streams JSONL output into transcripts,
87
+ - compacts noisy message updates,
88
+ - isolates observer callback failures so progress persistence cannot kill orchestration,
89
+ - applies post-exit stdio guards for late output.
90
+
91
+ ### Async background runner
92
+
93
+ `src/runtime/async-runner.ts` spawns detached background runs. Installed packages use an absolute `jiti-register.mjs` loader path because Node strip-types refuses TypeScript under `node_modules`. The runner fail-fasts if jiti is missing, and writes `async.pid` once startup begins so the parent can distinguish a healthy start from an early import crash.
94
+
95
+ ### Concurrency and policy
96
+
97
+ `src/runtime/concurrency.ts` picks batch size from explicit limits, team settings, workflow settings, or built-in defaults. User-provided `limits.maxConcurrentWorkers` is hard-capped by default to prevent local DoS; `limits.allowUnboundedConcurrency=true` is an explicit opt-out and emits an observability event.
98
+
99
+ `src/runtime/policy-engine.ts` applies closeout and safety policy decisions such as limit exceeded, failed task blocking, stale workers, and green-contract failures.
100
+
101
+ ### Model routing
102
+
103
+ Model choice is based on Pi's current configuration/model registry, not hardcoded providers. Task and agent records persist model attempts and routing metadata so dashboards/status can show requested model, selected model, fallback chain, and fallback reason.
104
+
105
+ ## State layer
106
+
107
+ Run state is under:
108
+
109
+ ```text
110
+ .pi/teams/state/runs/{runId}/
111
+ manifest.json run metadata/status/artifacts/async pid
112
+ tasks.json task graph and per-task status
113
+ events.jsonl append-only run events
114
+ events.jsonl.seq event sequence cache
115
+ agents.json aggregate agent cache
116
+ async.pid background startup marker
117
+ agents/{taskId}/
118
+ status.json per-agent status source
119
+ events.jsonl per-agent event stream
120
+ output.log compact worker output
121
+ sidechain.output.jsonl
122
+ live-control.jsonl
123
+ ```
124
+
125
+ Artifacts are under:
126
+
127
+ ```text
128
+ .pi/teams/artifacts/{runId}/
129
+ goal.md
130
+ prompts/{taskId}.md
131
+ results/{taskId}.txt
132
+ logs/{taskId}.log
133
+ transcripts/{taskId}.jsonl
134
+ metadata/*.json
135
+ progress.md
136
+ summary.md
137
+ ```
138
+
139
+ Atomic writes use temp-file replace with retry for transient Windows `EPERM`/`EBUSY`/`EACCES`. JSONL append paths are best-effort where used for observers/progress; write failures must not crash child output parsing.
140
+
141
+ ## UI and observability
142
+
143
+ - The persistent widget shows active runs only.
144
+ - Stale async runs with dead background pids are hidden from the active widget.
145
+ - `/team-status` is the canonical detailed state view and can mark stale active async runs failed.
146
+ - `/team-dashboard` provides history and details.
147
+ - Powerbar publishing is optional and event-compatible.
148
+ - Transcript viewer is file-backed so it works for foreground and async runs.
149
+
150
+ ## Lifecycle and cleanup
151
+
152
+ Foreground runs are session-bound and should be interrupted on session shutdown or session switch. Only explicit `async: true` runs are allowed to survive the Pi session. Runtime cleanup is registered through Pi lifecycle hooks and a global reload cleanup guard.
153
+
154
+ ## Configuration
155
+
156
+ Key config sections:
157
+
158
+ - `runtime`: `auto`, `child-process`, `scaffold`, experimental `live-session`.
159
+ - `limits`: concurrency/task/depth safety controls.
160
+ - `ui`: widget/dashboard/powerbar/model-token display settings.
161
+ - `agents`: builtin overrides for models/fallbacks/tools.
162
+ - `autonomous`: policy injection/profile for proactive team delegation.
163
+
164
+ See `usage.md`, `resource-formats.md`, `runtime-flow.md`, and `live-mailbox-runtime.md` for operational details.