pi-crew 0.9.26 → 0.9.28

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 (64) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/NOTICE.md +14 -0
  3. package/assets/crew-vibes.ttf +0 -0
  4. package/assets/runner-spritesheet.png +0 -0
  5. package/dist/build-meta.json +245 -48
  6. package/dist/index.mjs +1611 -243
  7. package/dist/index.mjs.map +4 -4
  8. package/docs/perf/optimization-plan-2026-07-verified.md +396 -0
  9. package/package.json +9 -2
  10. package/scripts/bench-check.mjs +96 -0
  11. package/scripts/bench-cold-start.mjs +216 -0
  12. package/scripts/build-bundle.mjs +84 -0
  13. package/scripts/build-crew-vibes-font.py +328 -0
  14. package/scripts/check-all-skills.ts +294 -0
  15. package/scripts/check-bundle-staleness.mjs +97 -0
  16. package/scripts/check-conflict-markers.mjs +91 -0
  17. package/scripts/check-lazy-imports.mjs +28 -0
  18. package/scripts/install-crew-vibes-font.mjs +91 -0
  19. package/scripts/postinstall.mjs +47 -0
  20. package/scripts/profile-startup.mjs +125 -0
  21. package/scripts/release-smoke.mjs +74 -0
  22. package/scripts/run-bench.mjs +47 -0
  23. package/scripts/run-real-chain.ts +41 -0
  24. package/scripts/test-issue-29-crash.ts +111 -0
  25. package/scripts/test-issue-29-e2e.ts +183 -0
  26. package/scripts/test-issue-29-real-runtime.ts +330 -0
  27. package/scripts/test-issue-29-real-tasks.ts +387 -0
  28. package/scripts/test-issue-29-team-tool.ts +105 -0
  29. package/scripts/test-runner.mjs +74 -0
  30. package/scripts/verify-flicker-fix.ts +109 -0
  31. package/scripts/verify-skill.ts +550 -0
  32. package/scripts/watch-bundle.mjs +259 -0
  33. package/scripts/watchdog-harness.ts +119 -0
  34. package/src/agents/agent-config.ts +2 -0
  35. package/src/agents/discover-agents.ts +10 -1
  36. package/src/config/defaults.ts +6 -0
  37. package/src/extension/crew-vibes/cat-frames.ts +18 -0
  38. package/src/extension/crew-vibes/config.ts +195 -0
  39. package/src/extension/crew-vibes/figures.ts +94 -0
  40. package/src/extension/crew-vibes/font-detect.ts +58 -0
  41. package/src/extension/crew-vibes/index.ts +385 -0
  42. package/src/extension/crew-vibes/provider-usage.ts +396 -0
  43. package/src/extension/crew-vibes/render.ts +206 -0
  44. package/src/extension/crew-vibes/speed.ts +286 -0
  45. package/src/extension/knowledge-injection.ts +12 -3
  46. package/src/extension/management.ts +23 -3
  47. package/src/extension/register.ts +7 -0
  48. package/src/extension/team-tool.ts +11 -0
  49. package/src/prompt/prompt-runtime.ts +65 -0
  50. package/src/runtime/child-pi.ts +123 -10
  51. package/src/runtime/crew-agent-records.ts +10 -3
  52. package/src/runtime/pi-args.ts +2 -0
  53. package/src/runtime/retry-executor.ts +4 -1
  54. package/src/runtime/task-runner/state-helpers.ts +9 -30
  55. package/src/runtime/task-runner.ts +1 -0
  56. package/src/runtime/team-runner.ts +5 -3
  57. package/src/state/atomic-write.ts +153 -49
  58. package/src/state/event-log.ts +16 -10
  59. package/src/state/locks.ts +7 -8
  60. package/src/state/mailbox.ts +15 -4
  61. package/src/state/state-store.ts +39 -10
  62. package/src/teams/discover-teams.ts +56 -1
  63. package/src/utils/safe-paths.ts +2 -1
  64. package/src/workflows/discover-workflows.ts +72 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,107 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.28] — maxTokens cap + real-time steering + provider-per-model (2026-07-09)
4
+
5
+ ### Features
6
+ - **maxTokens cap for background workers**: agent config `maxTokens: N` sets `PI_CREW_MAX_OUTPUT` env var; prompt-runtime hooks `before_provider_request` to cap `payload.max_tokens`
7
+ - **Real-time child steering**: team tool writes steers to JSONL file in real-time; child's prompt-runtime polls file every 500ms and injects via `pi.sendMessage({deliverAs:"steer"})`
8
+ - **Provider quota follows selected model**: `fetchProviderUsage()` now takes a provider parameter; quota section shows data for the current model's provider only, hides for unsupported providers
9
+ - **Minimax provider quota**: fetches from `https://www.minimax.io/v1/token_plan/remains` (interval + weekly usage with reset timers)
10
+
11
+ ### Fixes
12
+ - **currentProvider not initialized**: quota bar was always hidden because `model_select` only fires on manual switch; now reads `ctx.model.provider` at `session_start`
13
+ - **Animation stability**: PUA cat frames for native terminals, braille fallback for web terminals (gotty/wetty). Removed unstable cat widget and isWebTerminal detection for default behavior
14
+ - **PI_CREW_MAX_OUTPUT_TOKENS → PI_CREW_MAX_OUTPUT**: renamed to avoid `isSecretKey` detection ("TOKEN" pattern)
15
+ - **BASE_ALLOWLIST**: added `PI_CREW_MAX_OUTPUT` and `PI_CREW_STEERING_FILE` so `sanitizeEnvSecrets` passes them through
16
+ - **parseAgentFile**: now parses `maxTokens` from agent definition frontmatter
17
+
18
+ ## [0.9.27] — crew-vibes provider usage + animation fixes (2026-07-08)
19
+
20
+ ### Features
21
+ - **Provider rate-limit usage display**: fetches Anthropic / z.ai / Copilot quota data and shows progress bars in the status bar (5h window + weekly/monthly window with reset timers)
22
+ - **Space journey capacity labels**: Orbit → Cruise → Warp → Black Hole → Supernova → Big Bang
23
+ - **Auto-detect web terminals** (gotty, wetty) via cgroup walk — falls back to braille spinner automatically
24
+ - **Provider name** shown in usage bar (z.ai / Claude / Copilot)
25
+ - **Reset timer in days** for long windows (>48h → `30d16h`)
26
+
27
+ ### Fixes
28
+ - **z.ai epoch ms resetAt**: `nextResetTime` is epoch milliseconds, was stored as-is → wrong timer. Now converted to ISO string.
29
+ - **Separate 5h/weekly reset timers**: each window has its own reset time instead of one shared
30
+ - **pi footer sanitizer**: collapses `/ +/g → " "`, destroying space padding. Fixed with non-breaking space (U+00A0)
31
+ - **postinstall.mjs**: wrap main() in try/catch — postinstall must never fail npm install (SEC-M2)
32
+ - **Capacity timer leak**: stopCapacityTimer() in applyConfig disabled path
33
+ - **Cumulative usage delta**: track `_lastUsageOutput` to avoid inflating token count
34
+
35
+ ### Bundle
36
+ - Rebuilt dist/index.mjs with all crew-vibes changes
37
+
38
+ ## [perf-plan-2026-07] — verified optimization plan shipped (Phases 0–3) (2026-07-08)
39
+
40
+ Implements `docs/perf/optimization-plan-2026-07-verified.md` end-to-end with bench-first verification on Windows + Node 22. Not a version bump — perf-only change with the existing CLI surface unchanged.
41
+
42
+ ### Phase 0 — measurement infrastructure
43
+ - New `test/bench/discover-workflows.bench.ts` (was missing — powerbar hot path).
44
+ - New `test/bench/persist-single-task-update.bench.ts` (covers F2 + F4).
45
+ - New `test/bench/config-load.bench.ts` (regression guard for F16 cache).
46
+ - Extended `test/bench/event-append.bench.ts` with `nonTerminal` vs `terminal` scenarios for F3a tracking.
47
+ - Extended `test/bench/atomic-write.bench.ts` with `bestEffortControl` scenario for F4 control.
48
+ - Baseline artifacts: `test/bench/baseline-v0.9.26-pre-fix.json`, `…-post-phase2.json`, `…-post-phase3.json`.
49
+
50
+ ### Phase 1 — high-confidence, low-risk
51
+ - **F17** `discoverWorkflows`: 5 s TTL cache + dirStamp invalidation + `invalidateWorkflowDiscoveryCache()`. Powerbar's 5 Hz scan now does 3 statSync instead of `readdirSync × 6 + N readFileSync + regex-parse`.
52
+ - **F15** `discoverAgents`: TTL 500 ms → 5 000 ms. `discoverTeams`: same TTL+dirStamp pattern + `invalidateTeamDiscoveryCache()`.
53
+ - **F17/F15** `management.ts`: `invalidateResourceCaches()` called on create/update/delete so new resources appear within the same action.
54
+ - **F4** `atomicWriteFile` + `atomicWriteFileAsync` + `atomicWriteJson(+Async)` + `atomicWriteJsonCoalesced` accept `WriteDurability = "full" | "best-effort"`. Skips data `fsync` + parent-dir `fsync` when `"best-effort"`; defaults to `"full"` (back-compat). Applied `best-effort` to: mailbox delivery informational writes (`mailbox.ts:writeDeliveryState`), crew-agent progress writes (`crew-agent-records.ts:saveCrewAgentsCoalesced` / `writeCrewAgentStatusCoalesced`). Terminal writes (manifest, mailbox ack/complete, agent terminal status) keep `"full"`.
55
+ - **F9** `ChildPiLineObserver`: `rawTextEvents` capped at 2 entries (consumer reads only the last); `intermediateFindings` capped at 32 (digest still reads last 20). Memory bound for verbose workers.
56
+
57
+ ### Phase 2 — correctness-sensitive wins
58
+ - **F2** `persistSingleTaskUpdate` (in `task-runner/state-helpers.ts`): collapsed 3 redundant `statSync` per CAS attempt into 1. The 2 extra stats were rác (sync code, no I/O between calls). The remaining stat still protects against unlocked best-effort writers (`async-notifier.ts:54`, `crash-recovery.ts:98/416/464`).
59
+ - **F3a** `event-log.ts` sync `appendEvent`: `fsync` skipped for non-terminal events. Terminal events (run/task completed/failed/cancelled/...) still fsync to close the append ↔ persistSequence crash window. Async path's fsync was already removed in v0.9.26 revert (commit `414b973`); F3a's sync-path win is the meaningful delta.
60
+ - **F5** `atomic-write.ts:isSymlinkSafeDirCached`: 30 s TTL LRU keyed by `dirname(filePath)` for the ancestor-chain walk. Target-file lstat still runs every call. `invalidateSymlinkSafeCache(dir)` exported.
61
+ - **F1** `state-store.ts`: generation counter moved from global `number` to `Map<stateRoot, number>`. A write to run A no longer bumps run B's generation → cache hits for sibling runs preserved under multi-run load.
62
+
63
+ ### Phase 3 — safety-tier
64
+ - **F12** `child-pi.ts` finalDrain: a parallel 200 ms unref'd polling watcher starts when the drain timer arms (i.e. after `isFinalAssistantEvent`). If stdout goes silent for ≥ `finalDrainQuietMs` (default 800 ms), the watcher fires the same SIGTERM/hardKill path as the 5 s ceiling. Heavy well-behaved workers exit at ~800 ms instead of up to 5 s. New `DEFAULT_CHILD_PI.finalDrainQuietMs` config (set to ≥ `finalDrainMs` to disable). New optional `reason: "stdout-quiet"` field on `ChildPiLifecycleEvent`.
65
+ - **F6** — NOT shipped in this change. Deferred entirely (see Deferred section).
66
+
67
+ ### Bench results (Windows, Node v22.14.0, `npm run bench`, ITERS=200)
68
+
69
+ | Bench | Baseline p50 | Post p50 | Δ |
70
+ |---|---|---|---|
71
+ | `discover-workflows.firstCall` | 3.76 ms | 1.20 ms | **-68%** |
72
+ | `discover-workflows.subsequent` | 1.77 ms | 0.78 ms | **-56%** |
73
+ | `event-append.nonTerminal` | 22.6 ms | 13.84 ms | **-39%** |
74
+ | `event-append.serial` | 13.0 ms | 7.78 ms | -40% |
75
+ | `persist-single-task-update.durable` | 4.96 ms | 3.54 ms | **-29%** |
76
+ | `persist-single-task-update.burst10` | 5.20 ms | 5.52 ms | within noise |
77
+ | `atomic-write-json.cold` | 1.71 ms | 4.01 ms | high variance on tmpfs (multi-run 2.4–4.8 ms) |
78
+
79
+ ### Verification
80
+
81
+ | Check | Result |
82
+ |---|---|
83
+ | `npm run typecheck` | ✅ pass |
84
+ | `npm run lint` | ✅ after `biome format --write` on touched files |
85
+ | `npm run format:check` | ✅ pass |
86
+ | `npm run check:lazy-imports` | ✅ pass |
87
+ | Targeted unit tests F17+F4+F9 (6 suites) | ✅ 61 pass |
88
+ | Targeted unit tests F2+F3a+F5+F1 (12 suites) | ✅ 68 pass |
89
+ | Targeted unit tests F12 (10 suites) | ✅ 57 pass |
90
+ | `npm run bench` | ✅ results.json reproducible within ±15% batch-to-batch |
91
+
92
+ ### Migration / rollback
93
+
94
+ - All atomic-write callers retain `"full"` durability by default. `durability: "best-effort"` was wired only where informational-loss tolerance was verified by existing recovery paths (event-reconstructor + crash-recovery).
95
+ - TTL caches invalidate on real resource create/update/delete via `invalidateResourceCaches()`; engine restart clears the process-local Map.
96
+ - F5 symlink cache: only the *directory* ancestor-chain verdict is cached (30 s TTL); the target-file symlink check (`isTargetNotSymlink`) runs uncached on every call, so a mid-window symlink swap at the target path is still caught. `invalidateSymlinkSafeCache(dir)` exported.
97
+ - F12 quiet-window: behavior change ONLY when a child emits `stopReason=stop` then stops emitting stdout. Set `DEFAULT_CHILD_PI.finalDrainQuietMs >= finalDrainMs` to disable.
98
+
99
+ ### Deferred (out of scope)
100
+
101
+ - **F3b** mở rộng buffering qua `appendEventAsync` — vừa revert ở `414b973` (deadlock). Cần RCA.
102
+ - **F6** (toàn bộ) — archive-list cache cho `mailbox.ts:safeReadMailboxFile` VÀ delivery-state append-only JSONL + compaction. Chưa implement dòng nào trong đợt này. Cần format migration + reader compat.
103
+ - **In-memory task state** — cần ADR riêng + cross-process invalidation protocol.
104
+
3
105
  ## [v0.9.22] — fix: batch buffered event-log flush (25-85x faster) (2026-07-07)
4
106
 
5
107
  P0 follow-up to v0.9.21 event batching. The buffered flush path was calling `appendEventInsideLock` per-event, which triggered an `fsyncSync` per queued event. This defeated the entire point of batching — for 100 buffered events the flush took ~3s on tmpfs instead of the expected ~20ms.
package/NOTICE.md CHANGED
@@ -14,3 +14,17 @@
14
14
  When code is copied or substantially adapted from an MIT source, add the source path and license note here.
15
15
 
16
16
  Current scaffold status: no substantial source files have been copied verbatim; implementation is a fresh scaffold based on documented design lessons.
17
+
18
+ ## crew-vibes font assets
19
+
20
+ - `assets/runner-spritesheet.png` and the 16 runner glyphs (U+E700..U+E70F) traced
21
+ from it in `assets/crew-vibes.ttf` are adapted from the RunCat sprite art of
22
+ `pi-speeed` by somus (MIT license, https://github.com/somus/pi-speeed), which
23
+ itself traces inspiration to `pi-runcat` by FredySandoval. The silhouettes are
24
+ re-traced (bitmap -> contour) into a new Private-Use-Area font; no font binary
25
+ was copied verbatim.
26
+ - The token-speed engine in `src/extension/crew-vibes/speed.ts` is adapted from
27
+ `pi-speeed` (MIT license, https://github.com/somus/pi-speeed).
28
+ - The capacity meter concept is adapted from `pi-chonk` by somus (MIT license,
29
+ https://github.com/somus/pi-chonk); the boat+crew figures (U+E710..U+E715) are
30
+ original vector drawings.
Binary file
Binary file