Skip to content

fix(github-copilot): enforce apply_patch writes from Codex models - #84

Open
rudratoshs wants to merge 1 commit into
nizos:mainfrom
rudratoshs:fix/copilot-apply-patch-writes
Open

rudratoshs wants to merge 1 commit into
nizos:mainfrom
rudratoshs:fix/copilot-apply-patch-writes

Conversation

@rudratoshs

Copy link
Copy Markdown

What / why

Codex models running inside GitHub Copilot CLI send file edits as apply_patch, but the github-copilot adapter only modelled bash / create / edit. An apply_patch payload therefore fell through to the passthrough branch and was treated as a no-op command, so enforceTdd() and file-scoped rules never saw the write. TDD blocking that works for Claude models was silently bypassed for Codex ones — matching the report in #56.

What changed

  • Model apply_patch in the copilot adapter, mirroring the existing codex adapter: split the patch into one write action per file (so files 2..N aren't skipped by path-scoped rules or per-file enforceTdd), and add apply_patch to the passthrough exclusion list so a malformed patch surfaces as a parse error instead of passing through silently.
  • Extract the per-file patch split into a shared src/vendors/apply-patch.ts and use it from both the codex and copilot adapters, so the two stay identical (same pattern as the existing shared apply-edit.ts).
  • The raw patch text arrives directly as toolArgs (as captured from the Copilot hook in --agent github-copilot misses Codex apply_patch writes (Claude path works) #56). An { input } object form (object or JSON-string) is also accepted, mirroring the string→object move objectOrJsonString already handles for the other tools.

Tests

Added to github-copilot/adapter.test.ts: single-file apply_patch → write action, multi-file split → one write per file, { input } object form, and a headerless patch → parse error. I confirmed the new tests fail on main (the writes pass through unchecked) and pass with the fix. Full npm run checks is green (lint, format, typecheck, 554 tests, build).

Note

Scope is deliberately limited to the enforcement (parseAction) path that #56 reports. History reconstruction (event.ts) doesn't special-case apply_patch for the codex adapter either, so I left that untouched for parity rather than widening this change.

Closes #56

Codex models running inside Copilot CLI send edits as apply_patch, but
the github-copilot adapter only modelled bash/create/edit. An apply_patch
payload fell through to the passthrough branch and became a no-op command,
so enforceTdd() and file-scoped rules never saw the write — TDD blocking
that works for Claude models was silently bypassed for Codex ones.

Model apply_patch in the copilot adapter, mirroring the codex adapter:
split the patch into one write action per file so files 2..N are not
skipped by path-scoped rules, and exclude apply_patch from passthrough so
a malformed patch surfaces as a parse error rather than passing through.
The per-file split is shared via a new vendors/apply-patch module so both
adapters stay identical. The raw patch text arrives as toolArgs (as
captured from the hook); an { input } object form is accepted too.

Closes nizos#56

This branch has not been deployed

No deployments
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.

--agent github-copilot misses Codex apply_patch writes (Claude path works)

1 participant