Skip to content

fix: record Codex edits made through the unified exec tool#85

Merged
wasabeef merged 2 commits into
mainfrom
fix/issue-83-codex-nested-exec
Jul 8, 2026
Merged

fix: record Codex edits made through the unified exec tool#85
wasabeef merged 2 commits into
mainfrom
fix/issue-83-codex-nested-exec

Conversation

@wasabeef

@wasabeef wasabeef commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • parse nested tools.apply_patch(...) / tools.exec_command(...) calls inside custom_tool_call: exec transcript entries with a bounded JavaScript tokenizer (string literals and comments are skipped, so quoted or commented tool references never attribute)
  • extract inline patch text for file attribution and line stats, and treat cmd: string arguments as shell-mutation evidence
  • mark nested apply_patch calls as mutating even when the patch text is built dynamically, so commit-level attribution can still recover the commit
  • keep direct apply_patch / exec_command transcript formats unchanged

Root cause

Codex CLI 0.142.5 (unified executor) records file edits as JavaScript nested inside custom_tool_call: exec instead of direct apply_patch tool calls. The transcript parser only recognized direct tool calls, so nested edits produced neither files_touched nor mutation evidence, and Agent Note safely declined to write a git note.

User impact

Codex commits made through the unified exec tool now record git notes with file attribution and an AI Ratio in PR Report and Dashboard. Read-only nested calls do not create false-positive attribution.

Validation

  • CLI build, typecheck, and lint
  • CLI tests: 491 passed (4 new regression tests covering nested patch extraction, nested mutating commands, dynamically built patches, and quoted/commented references)
  • End-to-end test records a git note with attribution.method: line and ai_ratio: 100 from a Codex 0.142.5-shaped transcript

Closes #83

🧑💬🤖 Agent Note

Total AI Ratio: █░░░░░░░ 9%
Model: claude-fable-5

Commit AI Ratio Prompts Files
75023aa fix(codex): attribute nested exec tool calls from current Codex transcripts ░░░░░ 7% 2 cli.js 👤, codex.test.ts 🤖, codex.ts 🤖, codex.test.ts 👤
41996c0 refactor(codex): name the nested cmd key regex █████ 100% 1 cli.js 👤, codex.ts 🤖
💬 Prompts & Responses (3 total)

75023aa fix(codex): attribute nested exec tool calls from current Codex transcripts

🧑 Prompt

M packages/cli/dist/cli.js
M packages/cli/src/agents/codex.test.ts
M packages/cli/src/agents/codex.ts
M packages/cli/src/commands/codex.test.ts

の変更を確認してほしい。

#83

の修正した

🧑 Prompt

修正が必要なものは修正作業を行ってから PR 作成してほしい

41996c0 refactor(codex): name the nested cmd key regex

🧑 Prompt

#85 (comment)

Summary by CodeRabbit

  • New Features

    • Improved Codex transcript handling to recognize nested tool usage inside exec calls.
    • Better reports now include nested tools like patching and command execution when they appear in wrapped transcripts.
  • Bug Fixes

    • File-change and line-attribution details are now captured more reliably for nested patch content.
    • Read-only or quoted tool mentions are no longer misclassified as mutations.
    • Nested patch and command activity is now reflected more accurately in notes and interaction summaries.

…cripts

Why
Codex CLI 0.142.5 records unified-executor edits as JavaScript nested
inside custom_tool_call exec entries instead of direct apply_patch tool
calls. The transcript parser only recognized direct tool calls, so
nested edits produced no file or mutation evidence and commits were
left without an Agent Note git note.

User impact
Codex commits made through the unified exec tool now record git notes
with file attribution and an AI ratio. Nested apply_patch calls whose
patch text is built dynamically still count as mutation evidence, and
read-only or quoted nested references do not create false attribution.

Verification
npm run build --prefix packages/cli
npm run typecheck --prefix packages/cli
npm run lint --prefix packages/cli
npm test --prefix packages/cli (491 passed)

Release note: Codex edits made through the unified exec tool are now recorded with file attribution and an AI ratio.

Agentnote-Session: 4a6d322d-5afe-45e3-a11b-cf15d0e740a9
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds static-analysis recovery of nested tool calls (tools.apply_patch, tools.exec_command) embedded in JavaScript source passed to Codex's exec tool invocations. extractInteractions now attributes nested tools, mutation markers, and file/line evidence accordingly, with new unit and integration test coverage.

Changes

Nested exec tool call attribution

Layer / File(s) Summary
Nested evidence recovery utilities
packages/cli/src/agents/codex.ts
New helper functions scan exec source text for tools.apply_patch(...) and tools.exec_command(...) calls and extract string-literal patch/command inputs.
Interaction extraction wiring
packages/cli/src/agents/codex.ts
extractInteractions computes nested exec evidence, appends nested tool names, marks apply_patch/exec_command as mutating, and derives patchInputs for file/line-stat attribution from nested evidence.
Unit tests for nested attribution
packages/cli/src/agents/codex.test.ts
New buildNestedExecTranscript helper and tests cover static patch text, dynamic patch text, mutating exec_command, and quoted/commented false-positive avoidance.
Integration test for hook flow
packages/cli/src/commands/codex.test.ts
New buildNestedExecPatchTranscript helper and an end-to-end test verify git-note attribution, ai_ratio, files_touched, and tools list from a nested exec transcript.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Transcript
  participant extractInteractions
  participant NestedEvidenceHelper
  participant Interaction
  participant GitNote

  Transcript->>extractInteractions: custom_tool_call "exec" with input source
  extractInteractions->>NestedEvidenceHelper: scan source for tools.apply_patch/exec_command
  NestedEvidenceHelper-->>extractInteractions: nested tool names, patch/command inputs
  extractInteractions->>Interaction: append nested tools & mutation markers
  extractInteractions->>Interaction: attribute files_touched/line_stats
  Interaction->>GitNote: record ai_ratio and file attribution
Loading

Possibly related PRs

  • wasabeef/AgentNote#72: Both PRs modify packages/cli/src/agents/codex.ts transcript interaction extraction around exec/apply_patch evidence and mutation tagging, extended here to nested exec tool calls.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests address nested exec transcripts, preserve direct tool support, and cover false-positive avoidance and AI ratio attribution.
Out of Scope Changes check ✅ Passed The changes stay focused on nested exec attribution and regression tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: recording Codex edits made through the unified exec tool.
✨ 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 fix/issue-83-codex-nested-exec

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/agents/codex.ts`:
- Around line 249-256: The inline regex inside the stringLiterals filter in
codex.ts should be hoisted into a named module-level const with a short intent
comment, matching the existing style of SHELL_MUTATION_COMMAND_RE. Move the
`cmd:`/quoted `cmd` key matcher out of the callback, give it a descriptive name
like NESTED_CMD_KEY_RE, and update the filter in commandInputs to reference that
constant so the mutation-evidence heuristic is easier to read and maintain.
🪄 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: 451e7b86-640e-4aa9-8dd1-c24ca07777e7

📥 Commits

Reviewing files that changed from the base of the PR and between 0b9201a and 75023aa.

⛔ Files ignored due to path filters (1)
  • packages/cli/dist/cli.js is excluded by !**/dist/**, !**/dist/**
📒 Files selected for processing (3)
  • packages/cli/src/agents/codex.test.ts
  • packages/cli/src/agents/codex.ts
  • packages/cli/src/commands/codex.test.ts

Comment thread packages/cli/src/agents/codex.ts
Hoist the inline mutation-evidence regex into NESTED_CMD_KEY_RE with an
intent comment, matching how SHELL_MUTATION_COMMAND_RE is declared.
Addresses CodeRabbit review feedback on PR #85.

Release note: skip

Agentnote-Session: 4a6d322d-5afe-45e3-a11b-cf15d0e740a9
@wasabeef wasabeef merged commit 789fdd0 into main Jul 8, 2026
11 checks passed
@wasabeef wasabeef deleted the fix/issue-83-codex-nested-exec branch July 8, 2026 07:36
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.

bug(codex): nested exec tool calls are not attributed from current transcripts

1 participant