fix(tools): make apply_patch replacement explicit and compatible#4476
Conversation
|
Thanks @Angel-Hair for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
2d71857 to
82a9c35
Compare
…t detection The 'changes' parameter name is easily confused with 'patch'. When both are passed simultaneously, 'changes' silently takes precedence and 'patch' is discarded with no error or warning. - Rename JSON schema key and all internal references from 'changes' to 'replace' - Add explicit error when both 'patch' and 'replace' are passed simultaneously - Update function names, enum variants, error messages, and tests accordingly Fixes: apply_patch changes/replace ambiguity
82a9c35 to
a1980c0
Compare
Keep replace as the canonical full-file mode while accepting the legacy changes payload through one normalized parser. Reject every mixed-mode pair before preflight or writes, and route policy, approval, diagnostics, and UI consumers through the same contract. Also repairs the three schema-note regressions reported by CI run 29601773843. Follow-up to PR Hmbown#4476 by @Angel-Hair. Signed-off-by: Hunter B <hmbown@gmail.com>
|
Maintainer compatibility amendment is now on the contributor branch at The original report and contributor commit remain intact. The follow-up keeps Verification on the identical final source tree: 29 apply-patch tests; Responses and schema-sanitizer regressions; repo-law, approval-key, approval-preview, edited-path, and tool-routing coverage; Thank you @Angel-Hair for finding and fixing the silent precedence bug. |
Summary
apply_patchaccepts achangesparameter that performs full file replacement, not patching. The name is easily confused with thepatchparameter (which applies a unified diff). When both are passed simultaneously,changessilently takes precedence andpatchis discarded — no error, no warning, and the file is overwritten with only thechangescontent.Root cause
In
execute(), thechangesbranch returns immediately if present, making thepatchbranch unreachable. The JSON schema declaresoneOfmutual exclusivity, but this is advisory — the Rust handler enforces precedence, not rejection.Fix
changestoreplaceacross JSON schema, code, function names, enum variants, error messages, and testspatchandreplaceare present, return an error telling the model to choose oneTesting
cargo fmt -- --checkcargo clippy -p codewhale-tui(zero warnings)cargo check -p codewhale-tuicargo test -p codewhale-tui -- tools::apply_patch(26/26 passed)Checklist