Skip to content

fix(record): preserve env fallback prompt context#74

Merged
wasabeef merged 6 commits into
mainfrom
test/cli-e2e-smoke
May 12, 2026
Merged

fix(record): preserve env fallback prompt context#74
wasabeef merged 6 commits into
mainfrom
test/cli-e2e-smoke

Conversation

@wasabeef
Copy link
Copy Markdown
Owner

@wasabeef wasabeef commented May 12, 2026

Pull Request

Summary

  • Preserve bounded decision-context prompts for Codex --fallback-env notes instead of saving only the final file-matched implementation prompt.
  • Keep attribution strict: AI files and line counts still come only from direct transcript rows that touch committed files.
  • Fix env fallback branch priority so cmux/Codex commits with no repo-local prompt window actually use the env-specific display policy.
  • Add an integration regression test plus 75 generated selection simulations covering context length, time gaps, same-file context, and other-file task boundaries.
  • Update maintainer architecture docs and rebuild the CLI bundle.

Release Note Plan

Release note: Codex environment fallback now preserves useful prompt context without loosening AI attribution.

Type of Change

  • Fix
  • Feature
  • Documentation
  • Refactor
  • Test
  • CI / release

Checklist

  • I kept structural changes separate from behavior changes where practical.
  • I added or updated tests for behavior changes.
  • I updated README / docs / website content when user-facing behavior changed.
  • I rebuilt generated bundles when bundled source changed.
  • I ran the relevant checks locally.

Notes for Reviewers

This PR started as regression-test hardening, then exposed two real recovery gaps:

  • A stale trailer could prevent --fallback-env from running even when the trailer path wrote no git note.
  • After that was fixed, env fallback still saved only the direct file-matched transcript row, so the PR Report/Dashboard lost the investigation prompts that explained why the implementation happened.

The final shape intentionally separates display from attribution. Env fallback may keep bounded preceding transcript prompts so Agent Note preserves the “why,” but only direct file-matched transcript rows affect files_touched, AI files, and line attribution.

Local verification:

  • npm run build in packages/cli
  • npm run typecheck in packages/cli
  • npm run lint in packages/cli
  • env -u CODEX_THREAD_ID node --import tsx/esm --test src/core/record.test.ts in packages/cli
  • env -u CODEX_THREAD_ID node --import tsx/esm --test src/commands/init.test.ts in packages/cli
  • env -u CODEX_THREAD_ID npm test in packages/cli (458 tests)
  • node packages/cli/dist/cli.js show HEAD confirms the latest commit records 13 prompts, including the cmux/fallback investigation context.

Pre-existing local changes in docs/knowledge/investigations.md and docs/blog/ are not part of this PR.

🧑💬🤖 Agent Note

Total AI Ratio: ████████ 100%
Model: gpt-5.4

Commit AI Ratio Prompts Files
296707f test: strengthen regression coverage
1b4aa3a docs: clarify regression test strategy
eb73bfe fix(hooks): retry env fallback after empty trailer notes █████ 100% 1 AGENTS.md 🤖, CLAUDE.md 🤖, architecture.md 🤖, cli.js 👤, init.test.ts 🤖, init.ts 🤖, record.ts 🤖
5c67316 fix(record): preserve env fallback prompt context █████ 100% 13 AGENTS.md 🤖, CLAUDE.md 🤖, architecture.md 🤖, cli.js 👤, init.test.ts 🤖, record.test.ts 🤖, record.ts 🤖
7c33632 test(cli): fail fast when dist smoke bundle is missing █████ 100% 6 e2e-smoke.test.ts 🤖
5c7f907 test(cli): isolate dist smoke test environment █████ 100% 2 e2e-smoke.test.ts 🤖
💬 Prompts & Responses (20 shown / 22 total)

eb73bfe fix(hooks): retry env fallback after empty trailer notes

🧑 Prompt
今後、こういったことがデグレしないようにテストも強化しつつ実装をすすめてほしい

🤖 Response
PR #72 で入れた fallback は「no trailer」には効いていましたが、今回のデグレは「wrong trailer があるせいで env fallback まで到達しない」形です。ここを hook script と record --fallback-env の両方で塞ぎ、同じ形の regression test を追加します。
テスト群を見ると、今までの env fallback は「trailer 無し」の regression はかなり厚いですが、「trailer はあるが note が作れない」という今回の形が抜けています。ここにピンポイントの統合テストを追加し、post-commit 側は note の有無を見て env fallback を二段目で試す構造にします。
実装の形は「既存 note があれば何もしない」という idempotency に寄せます。trailer の有無は信頼境界としては弱く、今回のように stale pointer 由来だと逆に邪魔になるので、env fallback の停止条件を trailer から note の実在へ切…

5c67316 fix(record): preserve env fallback prompt context

🧑 Prompt
cmux の問題かどうかなどプロンプトいれてたよね

🤖 Response
はい、そこはかなり違和感あります。cmux の問題か?以前にも対応したはずでは? は今回の意思決定に効いているので、少なくとも commit の説明文脈として残るべきです。今は env fallback の transcript selection が「commit file に直接 match した interaction」へ寄りすぎて、調査・方針確認の prompt を落としている可能性が高いです。
実データ上も cmux 関連の発話は transcript にあります。ただ、今の検索結果を見る限り、env fallback の selectEnvironmentTranscriptMatchedInteractions() は「commit files を cover する最新 interaction」だけを primary にしていて、その前段の調査プロンプトを文脈として広げる処理がありません。ここはプロンプト選択の設計として、確かに厳しすぎます。

🧑 Prompt
これ compact だから絞られている?
なら Dashboard は full なはずだからあるはずだけどない。

これはバグだ

🤖 Response
そうです、これは compact の問題ではありません。PR Report / Dashboard の前に git note 自体が interactions: 1 になっているので、保存時点で落ちています。つまり表示設定ではなく record 側の selection bug です。今から transcript の該当時間帯を抽出して、env fallback の selection を広げる方向で直します。

🧑 Prompt
これは今回の修正で対応が漏れていたのか、以前から発生しているのか

🤖 Response
切り分けると、「今回の fix で新しく壊した」というより、PR #72 で入った env fallback 専用の選択ロジックがもともと厳しく、今回の fix で初めてその経路が実際に使われて露出した、という見立てです。念のため git blame / 履歴で、該当ロジックがいつ入ったか確認します。
これは 今回の修正で新しく壊したものではなく、PR #72 で入った env fallback 経路に以前からあった選択ロジックの厳しさ です。

ただし、今回の修正で初めて表面化しました。

整理すると:

  • PR fix(hooks): recover Codex env sessions #72--fallback-env が入り、Codex / cmux 系の transcript から note を復旧できるようになった。
  • そのとき安全側に倒すため、env fallback は「commit file に直接触った transcript interaction」だけを保存する実装になった。
  • そのため cmux の問題か?以前にも対応したはずでは? のような調査・判断プロンプトは、commit file に直接…

🧑 Prompt
でも緩くするPRもいれたよね

🤖 Response
そうです、緩くする PR も入れています。ここでややこしいのは、その緩和は主に「shell-only / unmatched transcript を救う」方向で、今回のような「file-matched env fallback で前段の調査 prompt も一緒に残す」方向までは届いていなかった可能性があります。差分を見て、どの緩和がどこまで効いているかを明確にします。
はい、入れました。そこは自分の言い方が雑でした。

「緩くした PR」は確かにあります。ただし緩くした対象が別です。

  • 3b7d244 fix(record): restore Codex commit-level attribution
    • Codex の files_touched が取れないときでも、commit-level で AI Ratio / files を拾えるように戻したもの。
  • 0342220 fix(record): harden Codex env transcript fallback
    • CODEX_THREAD_ID から env fallback できるよ…

🧑 Prompt
では v0.2.0 でも発生していたということ?

🤖 Response
v0.2.0 で同じ症状だったかは、今の記憶だけで断定しない方がよいです。tag の当時の record.ts を見て、「env fallback が存在したか」「prompt selection が file-match に限定されていたか」を確認します。
結論: 同じ形では v0.2.0 では発生していません。が、近い “前段 prompt が落ちる” 性質は v0.2.0 からありました。

分けるとこうです。

v0.2.0 には --fallback-env / CODEX_THREAD_ID 経路が存在しません。なので今回のように「cmux / Codex env から transcript を復旧するが、file-matched interaction だけ保存される」という症状は v0.2.0 では起きません。

ただし v0.2.0 の record.ts も、transcript から file match が見つかった場合は:

interactions = transcriptMatched.map(...)

🧑 Prompt
v0.2.0 というか v0.2 系ね

🤖 Response
v0.2 系全体で見るのが正しいですね。各 v0.2 tag の record.ts と hook 経路を比較して、どこまで同じ制約が残っていたか確認します。
v0.2 系全体で見ると、少し答えが変わります。

v0.2.0〜v0.2.2
今回と同じ症状はほぼ起きません。理由は単純で、この頃はまだ今の複雑な prompt window / env fallback がなく、transcript window が取れたら比較的その window を使う作りでした。ただし、file match がある場合は transcriptMatched だけに寄せる傾向はありました。

v0.2.3〜v0.2.4
ここで今に近い prompt selection が入り始めています。selectPromptWindowEntries / transcriptPrimaryTurns / selectableTranscriptMatched が入り、Codex transcript でも「選ばれた prompt window」か「file に直接紐づく t…

🧑 Prompt
以前もお伝えしたけど、厳格すぎるとせっかくのプロンプトが見れるコアテーマがなくなってします。次は完璧に改善してほしい。

🤖 Response
ここは Agent Note の中心価値そのものなので、同意です。次は「note を作れる」だけで満足せず、env fallback でも意思決定に効いた前段 prompt を保存する方向で、テストから固定して直します。まず実データを小さく抽出し、どの prompt が落ちたかを再現できる fixture にします。
今回の本質は「AI Ratio を守るために attribution は厳しく、でも Prompt の可視性まで同じ厳しさで削ってしまった」ことだと見ています。まず実装箇所を最小範囲で確認して、env fallback 時だけ“意思決定の前段 Prompt”を安全に残す方向で直します。

🧑 Prompt
修正したとしても別のケースで発生しないかを50回改善と確認ループを一つづつおこなってください

🤖 Response
まず「Prompt 表示のための選択」と「AI Ratio / Files のための attribution」を分離して扱います。ここを混ぜたまま緩めると false positive が増えるので、今回は attribution は今の防御を維持しつつ、env fallback の note に残す Prompt window だけを安全に広げる方向で進めます。
該当箇所はやはり selectEnvironmentTranscriptMatchedInteractions() でした。ここは「commit files をカバーする最小の transcript row」を選ぶ関数なので、Files/AI Ratio には良い一方、Prompt 表示には狭すぎます。次はこの関数を壊さず、表示用の bounded context を別関数として追加します。
緩め方は「最大 N 件の前段 Prompt を足す」だけだと危ないので、境界を 3 つ置きます。commit file に直接触った row を attribution source として維持し、その直前の transcrip…

🧑 Prompt
50パターンというか50回以上、この作業を繰り返してほしい

🤖 Response
了解です。ここは「50 ケース」ではなく「50 回ぶんの観点を通す」という意味で受け取ります。手で 50 回似た確認をするより、同じ判断軸をコード化して 50+ の variation を一気に回し、落ちたケースを修正するループにします。

🧑 Prompt
65 const TRANSCRIPT_COMMIT_PAST_TOLERANCE_MS = 30 * 1000;
66 +const ENV_FALLBACK_CONTEXT_BEFORE_MATCH_LIMIT = 8;
67 +const ENV_FALLBACK_CONTEXT_MAX_GAP_MS = 45 * 60 * 1000;

これらはしっかりコメントを追加しないと意図がわからない

🤖 Response
その通りです。ここは単なる数値ではなく「Prompt を救う範囲」と「別タスク混入を止める境界」なので、将来いじる人が怖がらず調整できるコメントを付けます。合わせてテスト名にもその意図が残るようにします。

🧑 Prompt
TSdoc しっかり追加しよう

🤖 Response
了解です。関数にも TSDoc を足して、「これは attribution ではなく display selection」「止める条件は何か」が読めるようにします。コメントはコードの近くに、でもくどくなりすぎない粒度に整えます。

🧑 Prompt
ENV_FALLBACK_CONTEXT_BEFORE_MATCH_LIMIT は8でいいわけ?根拠は?

🤖 Response
8 はまだ仮置きです。根拠としては「実装直前の調査会話を数ターン救う」ための安全弁ですが、今のままだと説明責任が弱いので、そのまま固定するのはやめます。

方針を少し変えます。主境界は「時間ギャップ」と「別ファイル edit」で決め、件数上限は pathological な長い transcript だけを止める最後の保険にします。上限値も 8 と決め打ちせず、50+ パターンのシミュレーションで “必要な文脈を落とさず、別タスクを混ぜない最小限の値” に調整します。

🧑 Prompt
Agent Note の本質を見失わないようにして。

🤖 Response
はい。ここは数字合わせの機能ではなく「なぜその変更が生まれたかを後から読める」ことが芯です。AI Ratio の誤検知を怖がるあまり Prompt の文脈を落とすと Agent Note そのものが痩せるので、今回の修正はその芯を守る形に寄せます。
実装とテストを入れました。次に targeted test でまずこの修正だけを小さく叩きます。ここで落ちたら、いきなり全体テストへ行かず、ケースごとに境界条件を直します。
最初の小テストで 2 つ見つかりました。1 つは期待値側の穴で、文脈 Prompt が 0 件のときだけ「時間ギャップ」が作れていませんでした。もう 1 つは init.testdist/cli.js を使うため、まだ build 前の古い bundle で走っていたことです。これは想定内なので、期待値の穴を直してから build して再実行します。
ここで本命のデグレ原因がもう 1 つ出ました。--fallback-env でも、session prompts が空のときは env 専用 branch に入る前に「編集 row だけを出す汎用 tra…

7c33632 test(cli): fail fast when dist smoke bundle is missing

🧑 Prompt
自己レビューを10回

🤖 Response
common:pr-review skill を使って、PR #74 の最新差分を 10 観点で見直します。今回は「Prompt を残す」という本質を守れているか、逆に false positive や過剰混入を増やしていないかを中心に確認します。
まず差分・CI・PR body の現状を集めます。直前に PR Report で 13 prompts は確認済みですが、レビューでは「その出方が副作用なく成立しているか」をもう一段深く見ます。
PR 全体は #74 で 4 commit 分あるので、直近の prompt-context 修正だけでなく、前段の e2e / stale trailer / fallback retry も含めて 10 観点で見ます。未コミットの docs/knowledge/investigations.mddocs/blog/ は今回レビュー対象から外します。
10 回レビューは、単に「見た」ではなく観点を変えて潰し込みます。まず差分をもう一度コード単位で確認して、特に env fallback の display context と a…

🧑 Prompt
修正すべき項目はなし?

🤖 Response
修正すべきブロッカーはなしです。

あえて残すなら minor は 1 点だけで、selectEnvironmentTranscriptDisplayInteractions を test のために record.ts から export している点です。ただし内部 CLI package 内の export で public API ではなく、テスト可能性のためなら許容範囲です。

現状は merge してよい状態だと思います。

🧑 Prompt
claude review

PR #74 レビュー

CI: ✅ Test(458) / Lint / PR Report / Dashboard / Website / deploy 全 pass
CodeRabbit: skipped
Mergeable: ✅


全体像

PR #72 マージ後に実利用で発覚した 2 つの実バグへの follow-up + regression test 強化。

Commit: 296707f
種別: test
内容: e2e-smoke.test.ts 新規(294行)、CLI 50+ コマンド網羅。agents/codex.test.ts、PR Report tests、Dashboard sync-notes test 追加
────────────────────────────────────────
Commit: 1b4aa3a
種別: docs
内容: engineering.md に「regression test strategy」4 ルール追加
────…

🤖 Response
Claude review の内容を確認しました。こちらの自己レビュー結果とも整合していて、追加で直すべき blocker はありません。

特に重要な確認点はこの 2 つです。

  • stale trailer 問題は trailer があるか ではなく 実際に git note があるか で判定するようになっていて、正しい修正です。
  • Prompt 表示は広げつつ、AI Ratio / files / line attribution は envMatched のままなので、Agent Note の本質を守りながら false positive を増やさない設計になっています。

Claude review の low/info 指摘も見ましたが、どれも merge 前に修正必須ではないです。12 件 cap と 45min gap は heuristic ですが、TSDoc と 75-case simulation で意図と境界が残っているので現段階では十分だと思います。

マージ可です。

🧑 Prompt
修正は不要?

🤖 Response
不要です。少なくとも今回の PR #74 で merge を止める修正はありません。

強いて言えば 12 件 cap / 45min gap は将来の実データで調整余地がありますが、今は TSDoc・simulation・実 PR 出力で妥当性を確認済みです。今触るより、このまま入れて運用データを見る方がよいです。

🧑 Prompt
$coderabbit-review

coderabbit-review /Users/a12622/git/context-history/.codex/skills/coderabbit-review/SKILL.md --- name: coderabbit-review description: Fetch CodeRabbit review feedback for the current PR, classify actionable items, implement fixes, verify them, and resolve only addressed review threads. ---

CodeRabbit Review Workflow

Use this skill when the task asks to address CodeRabbit comments, review CodeRabbit feedback, or resolve CodeRabbit threads.…

🤖 Response
coderabbit-review skill を使います。現在の PR を特定して、未解決の CodeRabbit review thread だけを拾い、修正が必要かどうかを分類します。
PR #74 を対象にします。次に review thread と summary comment を取得して、CodeRabbit の未解決指摘だけに絞ります。
未解決 thread は 1 件だけで、dist/cli.js が未 build のときに e2e smoke が大量の spawn error にならないよう fail-fast する提案です。これは小さく有効なので修正します。
修正は e2e-smoke.test.ts の先頭だけで済みます。dist/cli.js がない場合に、temp repo 作成前に明示的な assertion で止めるようにします。
CodeRabbit の指摘は反映済みです。まず該当 e2e smoke のみを実行し、その後 lint で import 順や format を確認します。
該当 e2e smoke と lint は通りまし…

5c7f907 test(cli): isolate dist smoke test environment

🧑 Prompt
$coderabbit-review

coderabbit-review /Users/a12622/git/context-history/.codex/skills/coderabbit-review/SKILL.md --- name: coderabbit-review description: Fetch CodeRabbit review feedback for the current PR, classify actionable items, implement fixes, verify them, and resolve only addressed review threads. ---

CodeRabbit Review Workflow

Use this skill when the task asks to address CodeRabbit comments, review CodeRabbit feedback, or resolve CodeRabbit threads.…

🤖 Response
coderabbit-review skill で再確認します。直前に resolve したあと再レビューが pending だったので、今の未解決 thread と summary を取り直します。
CodeRabbit は pass になっています。未解決 thread が残っていないことを GraphQL でも確認します。
新しい未解決 thread が 3 件出ています。cleanup guard と env の hermetic 化は妥当なので修正、git helper の direct git 呼び出しは test fixture の同期 API として意図がありそうなので、コードを確認して対応可否を分けます。
3 件とも確認しました。cleanup guard と env leak は明確に修正、git helper 指摘も e2e fixture 内とはいえ repo のルールと揃える価値があるので、async setup にして共有 git.ts wrapper 経由へ寄せます。
3 件すべてコード側で対応しました。e2e setup を async にし…

Summary by CodeRabbit

  • Documentation

    • Clarified git-hook and environment-fallback semantics for session recording, attribution, and display boundaries.
  • Tests

    • Added broad end-to-end CLI smoke tests and targeted unit tests for transcript selection, mutation detection, dashboard-note merging, PR/markdown rendering, and environment-fallback behavior.
  • Improvements / Bug Fixes

    • Made post-commit recording more robust, avoid redundant env-fallback when a note exists, bound transcript display context for clearer attribution, and preserve user-authored hidden comments in PR descriptions.

Review Change Stack

Add dist CLI smoke coverage for public commands, Codex shell mutation classification tests, PR description/reviewer-context characterization tests, and Dashboard note merge robustness coverage.

Release note: skip

Agentnote-Session: 89e518cc-e1cc-46d7-bdd0-86525a708263
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3663e309-d16b-4d0e-8cd7-43296e4fd869

📥 Commits

Reviewing files that changed from the base of the PR and between 7c33632 and 5c7f907.

📒 Files selected for processing (1)
  • packages/cli/src/commands/e2e-smoke.test.ts

📝 Walkthrough

Walkthrough

This PR adds documentation updates and multiple tests: Codex shell-command classification, a built-CLI E2E smoke suite, post-commit/init/record env-fallback changes with tests, dashboard merge robustness, and PR-report edge-case tests.

Changes

Test coverage expansion for CLI, dashboard, and PR reporting

Layer / File(s) Summary
Test guidance documentation
docs/engineering.md, AGENTS.md, CLAUDE.md, docs/architecture.md
Engineering and architecture docs updated with characterization test requirements, Dist CLI smoke test isolation guidance, and clarified env-fallback behavior and attribution rules.
Codex shell command interaction tests
packages/cli/src/agents/codex.test.ts
Adds buildShellCommandTranscript helper and tests that mutating shell commands are flagged with both tools and mutation_tools while read-only commands only set tools.
E2E CLI smoke test suite
packages/cli/src/commands/e2e-smoke.test.ts
New Node node:test suite runs the built dist/cli.js in isolated temp repos with agent notes, exercising public and invalid commands and init/status/deinit workflows; includes CLI runner, uniqueness checks, git helpers, and note attachment.
Post-commit hook and record env-fallback
packages/cli/src/commands/init.ts, packages/cli/src/commands/record.ts
Generated post-commit hook now uses NOTES_REF and a record_agentnote helper and conditionally attempts --fallback-env only when HEAD lacks notes. record.ts adds hasHeadAgentNote() using gitSafe and skips redundant env fallback.
Init tests and env-fallback integration
packages/cli/src/commands/init.test.ts
Updates transcript helper to support context prompts/timestamps and adds integration tests validating env-fallback interaction selection, attribution, and stale-session retry behavior.
Core env-display selection and tests
packages/cli/src/core/record.ts, packages/cli/src/core/record.test.ts
Adds display-bounding constants, splits attribution vs display selection, exports selectEnvironmentTranscriptDisplayInteractions, and adds simulation tests asserting bounded context inclusion and task-boundary stopping behavior.
Dashboard notes merge robustness
packages/dashboard/workflow/sync-notes.test.mjs
Adds test verifying mergeDashboardNotes preserves malformed JSON files, writes new PR notes correctly, and cleans up temp directories without crashing.
PR report rendering edge cases
packages/pr-report/src/index.test.ts, packages/pr-report/src/report.test.ts
Adds upsertDescription test preserving user hidden comments and renderMarkdown tests ensuring reviewer-context is omitted when no Agent Note data and file paths containing --> are escaped.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • wasabeef/AgentNote#72: Related; both adjust env-fallback recording, post-commit hook behavior, and tests for Codex env fallback.
  • wasabeef/AgentNote#62: Related; touches CLI hook/record code paths and git helper usage (NOTES_REF, gitSafe).
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(record): preserve env fallback prompt context' clearly and concisely summarizes the main change: preserving decision-context prompts in the environment fallback path, which is the primary objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/cli-e2e-smoke

Comment @coderabbitai help to get the list of available commands and usage tips.

Document how regression tests should prefer unique scenarios, characterization coverage, isolated dist CLI smoke tests, and false-positive checks for fallback heuristics.

Release note: skip

Agentnote-Session: 89e518cc-e1cc-46d7-bdd0-86525a708263
@wasabeef wasabeef marked this pull request as ready for review May 12, 2026 14:50
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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/cli/src/commands/e2e-smoke.test.ts`:
- Around line 16-29: The test should fail fast when the built bundle is missing:
in the before() setup where cliPath is defined (variable cliPath) add an upfront
existence check (e.g., fs.existsSync or fs.accessSync) for the dist/cli.js file
and throw a clear error (or call this.skip()/assert.fail) if it does not exist
so the test suite exits with an explicit message instead of producing multiple
spawn errors later; update the before() block (where git(["init"]) is invoked)
to perform this check before creating the temp repo or spawning the CLI.
🪄 Autofix (Beta)

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: cc5acefa-c681-4c5a-ad52-04a7e3e6e4d6

📥 Commits

Reviewing files that changed from the base of the PR and between f3bf00a and 1b4aa3a.

📒 Files selected for processing (6)
  • docs/engineering.md
  • packages/cli/src/agents/codex.test.ts
  • packages/cli/src/commands/e2e-smoke.test.ts
  • packages/dashboard/workflow/sync-notes.test.mjs
  • packages/pr-report/src/index.test.ts
  • packages/pr-report/src/report.test.ts

Comment thread packages/cli/src/commands/e2e-smoke.test.ts Outdated
@wasabeef wasabeef changed the title test: strengthen regression coverage fix(hooks): retry env fallback after empty trailer notes May 12, 2026
Why
Env fallback was correctly recovering Codex/cmux commits, but direct file matching kept only the final implementation prompt. That made PR Report and Dashboard lose the investigation and decision prompts that explain why the change happened.

User impact
Codex env fallback notes now keep bounded preceding decision-context prompts for display while attribution and line counts still use only the direct file-matched transcript rows.

Verification
npm run build
npm run typecheck
npm run lint
env -u CODEX_THREAD_ID node --import tsx/esm --test src/core/record.test.ts
env -u CODEX_THREAD_ID node --import tsx/esm --test src/commands/init.test.ts
env -u CODEX_THREAD_ID npm test

Release note: Codex environment fallback now preserves useful prompt context without loosening AI attribution.
@wasabeef wasabeef changed the title fix(hooks): retry env fallback after empty trailer notes fix(record): preserve env fallback prompt context May 12, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 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/cli/src/commands/e2e-smoke.test.ts`:
- Around line 120-121: The cleanup in the after() hook unconditionally calls
rmSync(testDir...) which throws when testDir was never created (e.g., before()
failed); update the after() hook to guard the removal by checking that testDir
is defined and exists before calling rmSync — reference the after() hook, the
before() assertion that sets testDir, and the testDir variable, and use an
existence check (e.g., existsSync or a truthy check) before invoking rmSync to
avoid a second exception during teardown.
- Around line 278-297: The helpers (git, gitOutput, gitIn, addNote) call
execFileSync("git", ...) directly which bypasses the package's canonical git
wrapper; replace those direct execFileSync usages with the exported git
execution helper from the package's git.ts (the canonical git execution
function), importing it at the top of the test file and calling it with the same
args, cwd and encoding/options so git(), gitOutput(), gitIn(), and addNote()
route all git operations through the shared wrapper instead of calling
execFileSync directly.
- Around line 255-260: The runCli function spawns CLI processes using the full
parent process.env which lets local AGENTNOTE_*, CODEX_*, CLAUDE_*, CURSOR_*,
GEMINI_* (and similar) variables leak into tests; change the spawnSync env
construction in runCli to build a minimal, hermetic environment instead of
spreading process.env — start from a clean object (or copy only a small
whitelist like PATH, NODE_ENV, HOME) set HOME and XDG_CONFIG_HOME as already
done, and explicitly omit or delete any variables with prefixes AGENTNOTE_,
CODEX_, CLAUDE_, CURSOR_, GEMINI_ (and any other agent-related prefixes) so the
spawned CLI cannot observe host agent/session state.
🪄 Autofix (Beta)

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: 8f46f198-8830-48e9-a55a-a64c74a3db07

📥 Commits

Reviewing files that changed from the base of the PR and between 5c67316 and 7c33632.

📒 Files selected for processing (1)
  • packages/cli/src/commands/e2e-smoke.test.ts

Comment thread packages/cli/src/commands/e2e-smoke.test.ts Outdated
Comment thread packages/cli/src/commands/e2e-smoke.test.ts
Comment thread packages/cli/src/commands/e2e-smoke.test.ts Outdated
@wasabeef wasabeef merged commit dff3a30 into main May 12, 2026
11 checks passed
@wasabeef wasabeef deleted the test/cli-e2e-smoke branch May 12, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant