feat(tools): add the stage performance statistics CLI (amadeus-stage-stats) - #2448
Conversation
amadeus-stage-stats.ts derives a per-stage duration baseline from the audit shards and the review-iteration distribution from the record artefacts. Stage windows pair STAGE_STARTED with STAGE_COMPLETED; the reported net duration subtracts approval waits, parks and session gaps, which is what makes raw wall-clock unusable as a performance signal. net is an estimate, and the header says so on every run. Exclusion buckets are layered by the three disjoint populations they count in, so the window identity stays checkable on the output: constructed windows = net population + unclosed-idle + zero-second. Every bucket is reported whatever its value, and a shard that exists but cannot be read is fail-loud at the exit code. Two-generation journal normalization is reused from amadeus-journal.ts rather than reimplemented; the tool imports no filesystem write API. Refs #2405
…en coverage registry
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthrough監査ジャーナルと Markdown artefact を走査する読み取り専用のステージ統計 CLI を追加した。実働時間、レビュー反復、センサー、モデル帰属を集計し、Markdown、CSV、JSON で出力する。単体テストと統合テストも追加した。 Changesステージ統計集計
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0a1daf3. Configure here.
|
Bugbot 指摘(Subagent model rows double counted)を e4b1962 で修正しました。 |
…pse the broken-line catch onto one measurable line
…tch for the no-silent-drop gate
…for lcov attribution
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/framework/core/tools/amadeus-stage-stats.ts`:
- Around line 853-862: Update markdownUnder to enumerate entries with
readdirSync(..., { withFileTypes: true }) and use Dirent metadata to recurse
only into directories, while collecting .md files as before. Skip directory
symlinks (or otherwise track visited real paths) so symlinked ancestors cannot
cause infinite recursion, and preserve the existing audit/node_modules
exclusions and intent-relative paths.
- Around line 361-365: SENSOR_EVENTS を Object.prototype
を継承しないマップとして定義し、イベント名によるプロトタイプキーの誤マッチを防いでください。あわせて、SENSOR_EVENTS[event]
のルックアップでも own-property のみを受け入れ、constructor や toString など信頼できない入力が outcome として
counter や SensorTally に流入しないようにしてください。
- Around line 115-120: Update epochSeconds and its callers to detect invalid
timestamp parsing instead of allowing NaN to flow into rawSeconds and net
statistics. Exclude invalid records from the measurement population or route
them into a dedicated invalid-timestamp bucket, ensuring they are not silently
treated as the zero-second bucket.
In `@tests/integration/t487-stage-stats.integration.test.ts`:
- Around line 381-389: Update the import assertion in the test “no filesystem
write API is imported or referenced by the tool” to ignore type-only imports
such as Dirent while still validating runtime fs imports. Keep the WRITE_APIS
check and node:fs/promises prohibition unchanged, and assert only the non-type
imports against the existing expected list.
- Around line 339-362: 3つの spawnSync 呼び出しに明示的な timeout と killSignal
オプションを追加し、CLI
がハングした場合に子プロセスを終了できるようにしてください。既存の実行引数、encoding、env、終了ステータス検証は維持してください。
In `@tests/unit/t486-stage-stats.test.ts`:
- Around line 454-493: Add two focused tests to the renderer describe block:
verify renderMarkdown sanitizes a stage name containing a newline and control
byte so only the cleaned value appears, and verify renderCsv escapes commas and
quotes in a model name by quoting the field and doubling embedded quotes. Use
sampleReport-based fixtures and assert the injected content cannot alter output
structure.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 1157a386-33f9-436d-a757-c5c8652ca389
📒 Files selected for processing (5)
packages/framework/core/tools/amadeus-stage-stats.tstests/.coverage-registry.jsontests/integration/t-coverage-mechanism-ratchet.test.tstests/integration/t487-stage-stats.integration.test.tstests/unit/t486-stage-stats.test.ts
…type-safe sensor lookup, symlink-safe record walk, spawn timeouts, sanitize tests
|
CodeRabbit 指摘 6 件を ee2e5b9 で対応しました:
検証: typecheck 0 / lint 0 / twin 79 pass 0 fail / 実ワークスペース再実行で invalid-timestamp: 0・恒等 W 不変(1563 = 1126 + 34 + 403) |

概要
ステージ実行パフォーマンスレポート CLI
amadeus-stage-stats.tsを新設する(intent260807-stage-perf-report、Bolt 1 = walking-skeleton ゲート付き)。監査シャード 2 世代の正規化読取・idle 減算による net 実作業時間・§12a レビューイテレーション集計・センサー FAILED 率・モデル帰属を、Markdown / CSV /--jsonの 3 形で決定的に出力する read-only ツール。Refs #2405(クローズは intent 完了時の着地確認後)
変更内容
packages/framework/core/tools/amadeus-stage-stats.ts(新規、944 行)— 依存はnode:fs(read)/node:path/amadeus-journal.tsのみ(readJournalRecords/journalRecordFieldを再利用、第 3 の正規化実装なし)。export function main(argv)+import.meta.main(in-process seam)tests/unit/t486-stage-stats.test.ts(55 tests / 126 assertions — 純関数のみ)tests/integration/t487-stage-stats.integration.test.ts(15 tests / 70 assertions — 実 FS fixture + spawn exit ladder 実測 + fs write API import 0 件検査)tests/.coverage-registry.json/tests/.coverage-ratchet.json再生成検証(実測 exit code)
申告事項
unparseableReviewHeading実測 117 vs 上流 observed 参照値 3 — 2 段マッチの寛容側が裸の## Review等を拾う仕様どおりの挙動(OQ-2 により実装の機械集計値を最終確定とし、build-and-test 成果物へ記録)Note
Low Risk
New read-only reporting CLI with extensive tests; no writes to workspace data and no changes to runtime auth or workflow execution paths.
Overview
Adds
amadeus-stage-stats.ts, a read-only Bun CLI that aggregates audit journal shards and record markdown into a stage performance report (issue #2405).It pairs STAGE_STARTED → STAGE_COMPLETED per intent×stage, subtracts idle spans (approval, park, session gaps) to produce net duration stats, and also tallies §12a review iterations, sensor outcomes by
Stage slug, and subagent model attribution. Output is deterministic markdown, CSV, or JSON, always led by a measurement ref and a prominent notice that net is an estimate. Journal v1/v2 fields come only fromamadeus-journal.ts; the tool does not importamadeus-lib.ts. Exit 1 when a shard exists but is unreadable; 2 on usage errors.Tests:
t486(pure aggregation) andt487(FS scan, CLI spawn, read-only invariant). Coverage registry/ratchet updated;function:maingains CLI coverage via t487; prior entries forevaluateDispatchGuard/amadeus-subagent-model-guardare dropped from the registry diff (renumbering/collision), not new product removals in this tool file.Reviewed by Cursor Bugbot for commit 0a1daf3. Configure here.
Summary by CodeRabbit
新機能
テスト