Skip to content

fix(core): restore patch tool parity#37709

Open
rekram1-node wants to merge 3 commits into
v2from
fix-patch
Open

fix(core): restore patch tool parity#37709
rekram1-node wants to merge 3 commits into
v2from
fix-patch

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • restore V1 patch behavior while keeping the V2 patch tool name and vocabulary
  • match parser acceptance, add overwrite, move, EOF-anchor, BOM, and whitespace behavior
  • accept an initial update chunk without @@ and normalize CRLF patch delimiters without removing intentional carriage returns
  • convert derivation exceptions into ordinary actionable tool failures
  • compute each structured file diff once and derive both counts and formatted output from it
  • update Codex and GPT system prompts to reference patch instead of apply_patch

Testing

  • bun typecheck from packages/core
  • bun test test/patch.test.ts test/tool-patch.test.ts from packages/core (26 passed)
  • bun test test/patch.test.ts test/tool-patch.test.ts test/plugin/system-prompt.test.ts from packages/core before the syntax follow-up (30 passed)

Remaining Codex parity

  • reject malformed headers, invalid hunk lines, empty chunks, and empty/no-op updates instead of silently accepting them
  • require *** End of File chunks to match at EOF rather than falling back to an earlier match
  • include patch line, operation, path, and underlying filesystem or matching context in failures
  • include existing destination content in structured diffs when an add or move overwrites a file

Further follow-up

These differences remain open rather than being deferred by a product decision:

  • determine whether move execution should gain coordinated source verification and two-target mutation safety
  • improve exact or explicitly inexact committed-change accounting after partial failures
  • evaluate the remaining parser/application performance differences
  • decide whether any Codex success-output grouping is desirable beyond OpenCode’s current operation-ordered plain output

Current scope decisions

  • omit Lark/freeform tooling until the V2 tool infrastructure supports it
  • do not copy Codex permission behavior because OpenCode uses a different permission model
  • leave invalid UTF-8 behavior unchanged for now while preserving OpenCode BOM handling
  • omit Codex-specific streamed previews, multiple-environment routing, shell interception, and standalone executable integration

Review

  • independently compared against the Codex patch parser and tool implementation
  • ported Codex coverage for implicit initial update chunks and CRLF line-ending behavior

@rekram1-node
rekram1-node force-pushed the fix-patch branch 3 times, most recently from be0ba65 to 87f4648 Compare July 19, 2026 04:51
@rekram1-node
rekram1-node changed the base branch from dev to v2 July 19, 2026 04:51
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