From b874a4054911da98cd33bd4acc3ff791859f2525 Mon Sep 17 00:00:00 2001 From: Oleksiy Syvokon Date: Sun, 1 Feb 2026 16:11:20 +0200 Subject: [PATCH] ep: Add V0131GitMergeMarkersPrefix prompt format (#48145) Release Notes: - N/A --- crates/edit_prediction/src/zeta2.rs | 4 +- .../edit_prediction_cli/src/format_prompt.rs | 11 ++-- .../edit_prediction_cli/src/parse_output.rs | 22 +++++-- crates/zeta_prompt/src/zeta_prompt.rs | 65 +++++++++++++++++++ 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/crates/edit_prediction/src/zeta2.rs b/crates/edit_prediction/src/zeta2.rs index 8889f9f4fcf59009b5bcdbd6087cf00522bc9e61..10b7d9dd2f2e59e26e2fd600f290930888036b8c 100644 --- a/crates/edit_prediction/src/zeta2.rs +++ b/crates/edit_prediction/src/zeta2.rs @@ -23,7 +23,9 @@ pub const MAX_CONTEXT_TOKENS: usize = 350; pub fn max_editable_tokens(version: ZetaVersion) -> usize { match version { ZetaVersion::V0112MiddleAtEnd | ZetaVersion::V0113Ordered => 150, - ZetaVersion::V0114180EditableRegion | ZetaVersion::V0120GitMergeMarkers => 180, + ZetaVersion::V0114180EditableRegion => 180, + ZetaVersion::V0120GitMergeMarkers => 180, + ZetaVersion::V0131GitMergeMarkersPrefix => 180, } } diff --git a/crates/edit_prediction_cli/src/format_prompt.rs b/crates/edit_prediction_cli/src/format_prompt.rs index 2e13045511c361919a4e1ae9dada17323d109c2b..daf275f6d33090b0eecb557a9eaf5ede37101dde 100644 --- a/crates/edit_prediction_cli/src/format_prompt.rs +++ b/crates/edit_prediction_cli/src/format_prompt.rs @@ -154,11 +154,14 @@ pub fn zeta2_output_for_patch( result.insert_str(offset, zeta_prompt::CURSOR_MARKER); } - if version == ZetaVersion::V0120GitMergeMarkers { - if !result.ends_with('\n') { - result.push('\n'); + match version { + ZetaVersion::V0120GitMergeMarkers | ZetaVersion::V0131GitMergeMarkersPrefix => { + if !result.ends_with('\n') { + result.push('\n'); + } + result.push_str(zeta_prompt::v0120_git_merge_markers::END_MARKER); } - result.push_str(zeta_prompt::v0120_git_merge_markers::END_MARKER); + _ => (), } Ok(result) diff --git a/crates/edit_prediction_cli/src/parse_output.rs b/crates/edit_prediction_cli/src/parse_output.rs index 5a3a49870ad3e0d3ace594b6613dae9e70df19c2..c965f1785a4b63568372058e3fd6ba9c1861b856 100644 --- a/crates/edit_prediction_cli/src/parse_output.rs +++ b/crates/edit_prediction_cli/src/parse_output.rs @@ -56,7 +56,7 @@ fn extract_zeta2_current_region(prompt: &str, version: ZetaVersion) -> Result { ("<|fim_middle|>current\n", "<|fim_suffix|>") } - ZetaVersion::V0120GitMergeMarkers => ( + ZetaVersion::V0120GitMergeMarkers | ZetaVersion::V0131GitMergeMarkersPrefix => ( zeta_prompt::v0120_git_merge_markers::START_MARKER, zeta_prompt::v0120_git_merge_markers::SEPARATOR, ), @@ -76,7 +76,9 @@ fn extract_zeta2_current_region(prompt: &str, version: ZetaVersion) -> Result { + zeta_prompt::v0131_git_merge_markers_prefix::END_MARKER } + ZetaVersion::V0120GitMergeMarkers => zeta_prompt::v0120_git_merge_markers::END_MARKER, + _ => "", + }; + if !suffix.is_empty() { + new_text = new_text + .strip_suffix(suffix) + .unwrap_or(&new_text) + .to_string(); } let mut old_text_normalized = old_text.clone(); diff --git a/crates/zeta_prompt/src/zeta_prompt.rs b/crates/zeta_prompt/src/zeta_prompt.rs index cb9c839d36b056b57e041f1d530fc0d0cdd239a4..e1c2b7fd23b91326581dd5767d0fbb09c2e6cb32 100644 --- a/crates/zeta_prompt/src/zeta_prompt.rs +++ b/crates/zeta_prompt/src/zeta_prompt.rs @@ -45,6 +45,7 @@ pub enum ZetaVersion { #[default] V0114180EditableRegion, V0120GitMergeMarkers, + V0131GitMergeMarkersPrefix, } impl std::fmt::Display for ZetaVersion { @@ -156,6 +157,9 @@ fn format_zeta_prompt_with_budget( ZetaVersion::V0120GitMergeMarkers => { v0120_git_merge_markers::write_cursor_excerpt_section(&mut cursor_section, input) } + ZetaVersion::V0131GitMergeMarkersPrefix => { + v0131_git_merge_markers_prefix::write_cursor_excerpt_section(&mut cursor_section, input) + } } let cursor_tokens = estimate_tokens(cursor_section.len()); @@ -418,6 +422,67 @@ pub mod v0120_git_merge_markers { } } +pub mod v0131_git_merge_markers_prefix { + //! A prompt that uses git-style merge conflict markers to represent the editable region. + //! + //! Example prompt: + //! + //! <|file_sep|>path/to/target_file.py + //! <|fim_prefix|> + //! code before editable region + //! <<<<<<< CURRENT + //! code that + //! needs to<|user_cursor|> + //! be rewritten + //! ======= + //! <|fim_suffix|> + //! code after editable region + //! <|fim_middle|> + //! + //! Expected output (should be generated by the model): + //! + //! updated + //! code with + //! changes applied + //! >>>>>>> UPDATED + + use super::*; + + pub const START_MARKER: &str = "<<<<<<< CURRENT\n"; + pub const SEPARATOR: &str = "=======\n"; + pub const END_MARKER: &str = ">>>>>>> UPDATED\n"; + + pub fn write_cursor_excerpt_section(prompt: &mut String, input: &ZetaPromptInput) { + let path_str = input.cursor_path.to_string_lossy(); + write!(prompt, "<|file_sep|>{}\n", path_str).ok(); + + prompt.push_str("<|fim_prefix|>"); + prompt.push_str(&input.cursor_excerpt[..input.editable_range_in_excerpt.start]); + prompt.push_str(START_MARKER); + prompt.push_str( + &input.cursor_excerpt + [input.editable_range_in_excerpt.start..input.cursor_offset_in_excerpt], + ); + prompt.push_str(CURSOR_MARKER); + prompt.push_str( + &input.cursor_excerpt + [input.cursor_offset_in_excerpt..input.editable_range_in_excerpt.end], + ); + if !prompt.ends_with('\n') { + prompt.push('\n'); + } + prompt.push_str(SEPARATOR); + + prompt.push_str("<|fim_suffix|>"); + prompt.push_str(&input.cursor_excerpt[input.editable_range_in_excerpt.end..]); + if !prompt.ends_with('\n') { + prompt.push('\n'); + } + + prompt.push_str("<|fim_middle|>"); + } +} + #[cfg(test)] mod tests { use super::*;