Skip to content

Commit 389d877

Browse files
committed
apply-patch: skip gemini-2.0-flash hunk headers in Add File blocks
Gemini 2.0 Flash emits hunk headers in Add File directives (e.g. "@@ -0,0 +1 @@" or "@@ -0,0 +1,5 @@"). Use "/^@@\s+-0,0\s+\+1(?:,[1-9]\d*)?\s+@@/" to detect and skip these headers. Signed-off-by: Masami HIRATA <[email protected]>
1 parent e9d16d3 commit 389d877

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

codex-cli/src/utils/agent/apply-patch.ts

+5
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ class Parser {
307307

308308
private parse_add_file(): PatchAction {
309309
const lines: Array<string> = [];
310+
// skip new-file hunk header (e.g. "@@ -0,0 +1@@" or "+1,NN@@")
311+
const NEW_FILE_HUNK = /^@@\s+-0,0\s+\+1(?:,[1-9]\d*)?\s+@@/;
310312
while (
311313
!this.is_done([
312314
PATCH_SUFFIX,
@@ -316,6 +318,9 @@ class Parser {
316318
])
317319
) {
318320
const s = this.read_str();
321+
if (NEW_FILE_HUNK.test(s)) {
322+
continue;
323+
}
319324
if (!s.startsWith(HUNK_ADD_LINE_PREFIX)) {
320325
throw new DiffError(`Invalid Add File Line: ${s}`);
321326
}

0 commit comments

Comments
 (0)