Combine zeta and zeta2 edit prediction providers (#43284)

We've realized that a lot of the logic within an
`EditPredictionProvider` is not specific to a particular edit prediction
model / service. Rather, it is just the generic state management
required to perform edit predictions at all in Zed. We want to move to a
setup where there's one "built-in" edit prediction provider in Zed,
which can be pointed at different edit prediction models. The only logic
that is different for different models is how we construct the prompt,
send the request, and parse the output.

This PR also changes the behavior of the staff-only `zeta2` feature flag
so that in only gates your *ability* to use Zeta2, but you can still use
your local settings file to choose between different edit prediction
models/services: zeta1, zeta2, and sweep.

This PR also makes zeta1's outcome reporting and prediction-rating
features work with all prediction models, not just zeta1.

To do:
* [x] remove duplicated logic around sending cloud requests between
zeta1 and zeta2
* [x] port the outcome reporting logic from zeta to zeta2.
* [x] get the "rate completions" modal working with all EP models
   * [x] display edit prediction diff
   * [x] show edit history events
* [x] remove the original `zeta` crate.

Release Notes:

- N/A

---------

Co-authored-by: Agus Zubiaga <agus@zed.dev>
Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Max Brunsfeld
2025-11-24 22:17:48 -08:00
committed by GitHub
co-authored by Agus Zubiaga Ben Kunkle
parent 17d7988ad4
commit 9122dd2d70
41 changed files with 5030 additions and 6225 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ use ui::{
v_flex,
};
use workspace::Item;
use zeta2::{
use zeta::{
Zeta, ZetaContextRetrievalDebugInfo, ZetaContextRetrievalStartedDebugInfo, ZetaDebugInfo,
ZetaSearchQueryDebugInfo,
};
+153 -425
View File
@@ -1,30 +1,26 @@
mod zeta2_context_view;
use std::{cmp::Reverse, path::PathBuf, str::FromStr, sync::Arc};
use std::{str::FromStr, sync::Arc, time::Duration};
use chrono::TimeDelta;
use client::{Client, UserStore};
use cloud_llm_client::predict_edits_v3::{
DeclarationScoreComponents, PredictEditsRequest, PromptFormat,
};
use cloud_llm_client::predict_edits_v3::PromptFormat;
use collections::HashMap;
use editor::{Editor, EditorEvent, EditorMode, ExcerptRange, MultiBuffer};
use editor::{Editor, EditorEvent, EditorMode, MultiBuffer};
use feature_flags::FeatureFlagAppExt as _;
use futures::{FutureExt, StreamExt as _, channel::oneshot, future::Shared};
use gpui::{
CursorStyle, Empty, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task,
WeakEntity, actions, prelude::*,
Empty, Entity, EventEmitter, FocusHandle, Focusable, Subscription, Task, WeakEntity, actions,
prelude::*,
};
use language::{Buffer, DiskState};
use ordered_float::OrderedFloat;
use project::{Project, WorktreeId, telemetry_snapshot::TelemetrySnapshot};
use language::Buffer;
use project::{Project, telemetry_snapshot::TelemetrySnapshot};
use ui::{ButtonLike, ContextMenu, ContextMenuEntry, DropdownMenu, KeyBinding, prelude::*};
use ui_input::InputField;
use util::{ResultExt, paths::PathStyle, rel_path::RelPath};
use util::ResultExt;
use workspace::{Item, SplitDirection, Workspace};
use zeta2::{
AgenticContextOptions, ContextMode, DEFAULT_SYNTAX_CONTEXT_OPTIONS, Zeta, Zeta2FeatureFlag,
ZetaDebugInfo, ZetaEditPredictionDebugInfo, ZetaOptions,
use zeta::{
AgenticContextOptions, ContextMode, DEFAULT_SYNTAX_CONTEXT_OPTIONS, EditPredictionInputs, Zeta,
Zeta2FeatureFlag, ZetaDebugInfo, ZetaEditPredictionDebugInfo, ZetaOptions,
};
use edit_prediction_context::{EditPredictionContextOptions, EditPredictionExcerptOptions};
@@ -99,7 +95,6 @@ pub struct Zeta2Inspector {
cursor_context_ratio_input: Entity<InputField>,
max_prompt_bytes_input: Entity<InputField>,
context_mode: ContextModeState,
active_view: ActiveView,
zeta: Entity<Zeta>,
_active_editor_subscription: Option<Subscription>,
_update_state_task: Task<()>,
@@ -113,21 +108,14 @@ pub enum ContextModeState {
},
}
#[derive(PartialEq)]
enum ActiveView {
Context,
Inference,
}
struct LastPrediction {
context_editor: Entity<Editor>,
prompt_editor: Entity<Editor>,
retrieval_time: TimeDelta,
request_time: Option<TimeDelta>,
retrieval_time: Duration,
request_time: Option<Duration>,
buffer: WeakEntity<Buffer>,
position: language::Anchor,
state: LastPredictionState,
request: PredictEditsRequest,
inputs: EditPredictionInputs,
project_snapshot: Shared<Task<Arc<TelemetrySnapshot>>>,
_task: Option<Task<()>>,
}
@@ -175,7 +163,6 @@ impl Zeta2Inspector {
focus_handle: cx.focus_handle(),
project: project.clone(),
last_prediction: None,
active_view: ActiveView::Inference,
max_excerpt_bytes_input: Self::number_input("Max Excerpt Bytes", window, cx),
min_excerpt_bytes_input: Self::number_input("Min Excerpt Bytes", window, cx),
cursor_context_ratio_input: Self::number_input("Cursor Context Ratio", window, cx),
@@ -305,7 +292,7 @@ impl Zeta2Inspector {
ContextMode::Syntax(context_options) => {
let max_retrieved_declarations = match &this.context_mode {
ContextModeState::Llm => {
zeta2::DEFAULT_SYNTAX_CONTEXT_OPTIONS.max_retrieved_declarations
zeta::DEFAULT_SYNTAX_CONTEXT_OPTIONS.max_retrieved_declarations
}
ContextModeState::Syntax {
max_retrieved_declarations,
@@ -340,22 +327,10 @@ impl Zeta2Inspector {
fn update_last_prediction(
&mut self,
prediction: zeta2::ZetaDebugInfo,
prediction: zeta::ZetaDebugInfo,
window: &mut Window,
cx: &mut Context<Self>,
) {
let project = self.project.read(cx);
let path_style = project.path_style(cx);
let Some(worktree_id) = project
.worktrees(cx)
.next()
.map(|worktree| worktree.read(cx).id())
else {
log::error!("Open a worktree to use edit prediction debug view");
self.last_prediction.take();
return;
};
self._update_state_task = cx.spawn_in(window, {
let language_registry = self.project.read(cx).languages().clone();
async move |this, cx| {
@@ -364,11 +339,10 @@ impl Zeta2Inspector {
return;
};
for ext in prediction
.request
.referenced_declarations
.inputs
.included_files
.iter()
.filter_map(|snippet| snippet.path.extension())
.chain(prediction.request.excerpt_path.extension())
.filter_map(|file| file.path.extension())
{
if !languages.contains_key(ext) {
// Most snippets are gonna be the same language,
@@ -391,90 +365,6 @@ impl Zeta2Inspector {
let json_language = language_registry.language_for_name("Json").await.log_err();
this.update_in(cx, |this, window, cx| {
let context_editor = cx.new(|cx| {
let mut excerpt_score_components = HashMap::default();
let multibuffer = cx.new(|cx| {
let mut multibuffer = MultiBuffer::new(language::Capability::ReadOnly);
let excerpt_file = Arc::new(ExcerptMetadataFile {
title: RelPath::unix("Cursor Excerpt").unwrap().into(),
path_style,
worktree_id,
});
let excerpt_buffer = cx.new(|cx| {
let mut buffer =
Buffer::local(prediction.request.excerpt.clone(), cx);
if let Some(language) = prediction
.request
.excerpt_path
.extension()
.and_then(|ext| languages.get(ext))
{
buffer.set_language(language.clone(), cx);
}
buffer.file_updated(excerpt_file, cx);
buffer
});
multibuffer.push_excerpts(
excerpt_buffer,
[ExcerptRange::new(text::Anchor::MIN..text::Anchor::MAX)],
cx,
);
let mut declarations =
prediction.request.referenced_declarations.clone();
declarations.sort_unstable_by_key(|declaration| {
Reverse(OrderedFloat(declaration.declaration_score))
});
for snippet in &declarations {
let snippet_file = Arc::new(ExcerptMetadataFile {
title: RelPath::unix(&format!(
"{} (Score: {})",
snippet.path.display(),
snippet.declaration_score
))
.unwrap()
.into(),
path_style,
worktree_id,
});
let excerpt_buffer = cx.new(|cx| {
let mut buffer = Buffer::local(snippet.text.clone(), cx);
buffer.file_updated(snippet_file, cx);
if let Some(ext) = snippet.path.extension()
&& let Some(language) = languages.get(ext)
{
buffer.set_language(language.clone(), cx);
}
buffer
});
let excerpt_ids = multibuffer.push_excerpts(
excerpt_buffer,
[ExcerptRange::new(text::Anchor::MIN..text::Anchor::MAX)],
cx,
);
let excerpt_id = excerpt_ids.first().unwrap();
excerpt_score_components
.insert(*excerpt_id, snippet.score_components.clone());
}
multibuffer
});
let mut editor =
Editor::new(EditorMode::full(), multibuffer, None, window, cx);
editor.register_addon(ZetaContextAddon {
excerpt_score_components,
});
editor
});
let ZetaEditPredictionDebugInfo {
response_rx,
position,
@@ -606,7 +496,6 @@ impl Zeta2Inspector {
let project_snapshot_task = TelemetrySnapshot::new(&this.project, cx);
this.last_prediction = Some(LastPrediction {
context_editor,
prompt_editor: cx.new(|cx| {
let buffer = cx.new(|cx| {
let mut buffer =
@@ -632,7 +521,7 @@ impl Zeta2Inspector {
.foreground_executor()
.spawn(async move { Arc::new(project_snapshot_task.await) })
.shared(),
request: prediction.request,
inputs: prediction.inputs,
_task: Some(task),
});
cx.notify();
@@ -664,9 +553,6 @@ impl Zeta2Inspector {
let Some(last_prediction) = self.last_prediction.as_mut() else {
return;
};
if !last_prediction.request.can_collect_data {
return;
}
let project_snapshot_task = last_prediction.project_snapshot.clone();
@@ -718,7 +604,7 @@ impl Zeta2Inspector {
id = request_id,
kind = kind,
text = text,
request = last_prediction.request,
request = last_prediction.inputs,
project_snapshot = project_snapshot,
);
})
@@ -727,17 +613,6 @@ impl Zeta2Inspector {
.detach();
}
fn focus_feedback(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if let Some(last_prediction) = self.last_prediction.as_mut() {
if let LastPredictionState::Success {
feedback_editor, ..
} = &mut last_prediction.state
{
feedback_editor.focus_handle(cx).focus(window);
}
};
}
fn render_options(&self, window: &mut Window, cx: &mut Context<Self>) -> Div {
v_flex()
.gap_2()
@@ -747,11 +622,11 @@ impl Zeta2Inspector {
.justify_between()
.child(
ui::Button::new("reset-options", "Reset")
.disabled(self.zeta.read(cx).options() == &zeta2::DEFAULT_OPTIONS)
.disabled(self.zeta.read(cx).options() == &zeta::DEFAULT_OPTIONS)
.style(ButtonStyle::Outlined)
.size(ButtonSize::Large)
.on_click(cx.listener(|this, _, window, cx| {
this.set_options_state(&zeta2::DEFAULT_OPTIONS, window, cx);
this.set_options_state(&zeta::DEFAULT_OPTIONS, window, cx);
})),
),
)
@@ -915,42 +790,6 @@ impl Zeta2Inspector {
)
}
fn render_tabs(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
if self.last_prediction.is_none() {
return None;
};
Some(
ui::ToggleButtonGroup::single_row(
"prediction",
[
ui::ToggleButtonSimple::new(
"Context",
cx.listener(|this, _, _, cx| {
this.active_view = ActiveView::Context;
cx.notify();
}),
),
ui::ToggleButtonSimple::new(
"Inference",
cx.listener(|this, _, window, cx| {
this.active_view = ActiveView::Inference;
this.focus_feedback(window, cx);
cx.notify();
}),
),
],
)
.style(ui::ToggleButtonGroupStyle::Outlined)
.selected_index(if self.active_view == ActiveView::Context {
0
} else {
1
})
.into_any_element(),
)
}
fn render_stats(&self) -> Option<Div> {
let Some(prediction) = self.last_prediction.as_ref() else {
return None;
@@ -970,15 +809,15 @@ impl Zeta2Inspector {
)
}
fn render_duration(name: &'static str, time: Option<chrono::TimeDelta>) -> Div {
fn render_duration(name: &'static str, time: Option<Duration>) -> Div {
h_flex()
.gap_1()
.child(Label::new(name).color(Color::Muted).size(LabelSize::Small))
.child(match time {
Some(time) => Label::new(if time.num_microseconds().unwrap_or(0) >= 1000 {
format!("{} ms", time.num_milliseconds())
Some(time) => Label::new(if time.as_micros() >= 1000 {
format!("{} ms", time.as_millis())
} else {
format!("{} µs", time.num_microseconds().unwrap_or(0))
format!("{} µs", time.as_micros())
})
.size(LabelSize::Small),
None => Label::new("...").size(LabelSize::Small),
@@ -1006,144 +845,135 @@ impl Zeta2Inspector {
}
fn render_last_prediction(&self, prediction: &LastPrediction, cx: &mut Context<Self>) -> Div {
match &self.active_view {
ActiveView::Context => div().size_full().child(prediction.context_editor.clone()),
ActiveView::Inference => h_flex()
.items_start()
.w_full()
.flex_1()
.border_t_1()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().editor_background)
.child(
v_flex()
.flex_1()
.gap_2()
.p_4()
.h_full()
.child(
h_flex()
.justify_between()
.child(ui::Headline::new("Prompt").size(ui::HeadlineSize::XSmall))
.child(match prediction.state {
LastPredictionState::Requested
| LastPredictionState::Failed { .. } => ui::Chip::new("Local")
.bg_color(cx.theme().status().warning_background)
.label_color(Color::Success),
LastPredictionState::Success { .. } => ui::Chip::new("Cloud")
.bg_color(cx.theme().status().success_background)
.label_color(Color::Success),
}),
)
.child(prediction.prompt_editor.clone()),
)
.child(ui::vertical_divider())
.child(
v_flex()
.flex_1()
.gap_2()
.h_full()
.child(
v_flex()
.flex_1()
.gap_2()
.p_4()
.child(
ui::Headline::new("Model Response")
.size(ui::HeadlineSize::XSmall),
)
.child(match &prediction.state {
LastPredictionState::Success {
model_response_editor,
..
} => model_response_editor.clone().into_any_element(),
LastPredictionState::Requested => v_flex()
.gap_2()
.child(Label::new("Loading...").buffer_font(cx))
.into_any_element(),
LastPredictionState::Failed { message } => v_flex()
.gap_2()
.max_w_96()
.child(Label::new(message.clone()).buffer_font(cx))
.into_any_element(),
}),
)
.child(ui::divider())
.child(
if prediction.request.can_collect_data
&& let LastPredictionState::Success {
feedback_editor,
feedback: feedback_state,
h_flex()
.items_start()
.w_full()
.flex_1()
.border_t_1()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().editor_background)
.child(
v_flex()
.flex_1()
.gap_2()
.p_4()
.h_full()
.child(
h_flex()
.justify_between()
.child(ui::Headline::new("Prompt").size(ui::HeadlineSize::XSmall))
.child(match prediction.state {
LastPredictionState::Requested
| LastPredictionState::Failed { .. } => ui::Chip::new("Local")
.bg_color(cx.theme().status().warning_background)
.label_color(Color::Success),
LastPredictionState::Success { .. } => ui::Chip::new("Cloud")
.bg_color(cx.theme().status().success_background)
.label_color(Color::Success),
}),
)
.child(prediction.prompt_editor.clone()),
)
.child(ui::vertical_divider())
.child(
v_flex()
.flex_1()
.gap_2()
.h_full()
.child(
v_flex()
.flex_1()
.gap_2()
.p_4()
.child(
ui::Headline::new("Model Response").size(ui::HeadlineSize::XSmall),
)
.child(match &prediction.state {
LastPredictionState::Success {
model_response_editor,
..
} = &prediction.state
{
v_flex()
.key_context("Zeta2Feedback")
.on_action(cx.listener(Self::handle_rate_positive))
.on_action(cx.listener(Self::handle_rate_negative))
} => model_response_editor.clone().into_any_element(),
LastPredictionState::Requested => v_flex()
.gap_2()
.p_2()
.child(feedback_editor.clone())
.child(
h_flex()
.justify_end()
.w_full()
.child(
ButtonLike::new("rate-positive")
.when(
*feedback_state == Some(Feedback::Positive),
|this| this.style(ButtonStyle::Filled),
.child(Label::new("Loading...").buffer_font(cx))
.into_any_element(),
LastPredictionState::Failed { message } => v_flex()
.gap_2()
.max_w_96()
.child(Label::new(message.clone()).buffer_font(cx))
.into_any_element(),
}),
)
.child(ui::divider())
.child(
if let LastPredictionState::Success {
feedback_editor,
feedback: feedback_state,
..
} = &prediction.state
{
v_flex()
.key_context("Zeta2Feedback")
.on_action(cx.listener(Self::handle_rate_positive))
.on_action(cx.listener(Self::handle_rate_negative))
.gap_2()
.p_2()
.child(feedback_editor.clone())
.child(
h_flex()
.justify_end()
.w_full()
.child(
ButtonLike::new("rate-positive")
.when(
*feedback_state == Some(Feedback::Positive),
|this| this.style(ButtonStyle::Filled),
)
.child(
KeyBinding::for_action(
&Zeta2RatePredictionPositive,
cx,
)
.child(
KeyBinding::for_action(
&Zeta2RatePredictionPositive,
cx,
)
.size(TextSize::Small.rems(cx)),
.size(TextSize::Small.rems(cx)),
)
.child(ui::Icon::new(ui::IconName::ThumbsUp))
.on_click(cx.listener(|this, _, window, cx| {
this.handle_rate_positive(
&Zeta2RatePredictionPositive,
window,
cx,
);
})),
)
.child(
ButtonLike::new("rate-negative")
.when(
*feedback_state == Some(Feedback::Negative),
|this| this.style(ButtonStyle::Filled),
)
.child(
KeyBinding::for_action(
&Zeta2RatePredictionNegative,
cx,
)
.child(ui::Icon::new(ui::IconName::ThumbsUp))
.on_click(cx.listener(
|this, _, window, cx| {
this.handle_rate_positive(
&Zeta2RatePredictionPositive,
window,
cx,
);
},
)),
)
.child(
ButtonLike::new("rate-negative")
.when(
*feedback_state == Some(Feedback::Negative),
|this| this.style(ButtonStyle::Filled),
)
.child(
KeyBinding::for_action(
&Zeta2RatePredictionNegative,
cx,
)
.size(TextSize::Small.rems(cx)),
)
.child(ui::Icon::new(ui::IconName::ThumbsDown))
.on_click(cx.listener(
|this, _, window, cx| {
this.handle_rate_negative(
&Zeta2RatePredictionNegative,
window,
cx,
);
},
)),
),
)
.into_any()
} else {
Empty.into_any_element()
},
),
),
}
.size(TextSize::Small.rems(cx)),
)
.child(ui::Icon::new(ui::IconName::ThumbsDown))
.on_click(cx.listener(|this, _, window, cx| {
this.handle_rate_negative(
&Zeta2RatePredictionNegative,
window,
cx,
);
})),
),
)
.into_any()
} else {
Empty.into_any_element()
},
),
)
}
}
@@ -1178,8 +1008,7 @@ impl Render for Zeta2Inspector {
.h_full()
.justify_between()
.child(self.render_options(window, cx))
.gap_4()
.children(self.render_tabs(cx)),
.gap_4(),
)
.child(ui::vertical_divider())
.children(self.render_stats()),
@@ -1187,104 +1016,3 @@ impl Render for Zeta2Inspector {
.child(self.render_content(window, cx))
}
}
// Using same approach as commit view
struct ExcerptMetadataFile {
title: Arc<RelPath>,
worktree_id: WorktreeId,
path_style: PathStyle,
}
impl language::File for ExcerptMetadataFile {
fn as_local(&self) -> Option<&dyn language::LocalFile> {
None
}
fn disk_state(&self) -> DiskState {
DiskState::New
}
fn path(&self) -> &Arc<RelPath> {
&self.title
}
fn full_path(&self, _: &App) -> PathBuf {
self.title.as_std_path().to_path_buf()
}
fn file_name<'a>(&'a self, _: &'a App) -> &'a str {
self.title.file_name().unwrap()
}
fn path_style(&self, _: &App) -> PathStyle {
self.path_style
}
fn worktree_id(&self, _: &App) -> WorktreeId {
self.worktree_id
}
fn to_proto(&self, _: &App) -> language::proto::File {
unimplemented!()
}
fn is_private(&self) -> bool {
false
}
}
struct ZetaContextAddon {
excerpt_score_components: HashMap<editor::ExcerptId, DeclarationScoreComponents>,
}
impl editor::Addon for ZetaContextAddon {
fn to_any(&self) -> &dyn std::any::Any {
self
}
fn render_buffer_header_controls(
&self,
excerpt_info: &multi_buffer::ExcerptInfo,
_window: &Window,
_cx: &App,
) -> Option<AnyElement> {
let score_components = self.excerpt_score_components.get(&excerpt_info.id)?.clone();
Some(
div()
.id(excerpt_info.id.to_proto() as usize)
.child(ui::Icon::new(IconName::Info))
.cursor(CursorStyle::PointingHand)
.tooltip(move |_, cx| {
cx.new(|_| ScoreComponentsTooltip::new(&score_components))
.into()
})
.into_any(),
)
}
}
struct ScoreComponentsTooltip {
text: SharedString,
}
impl ScoreComponentsTooltip {
fn new(components: &DeclarationScoreComponents) -> Self {
Self {
text: format!("{:#?}", components).into(),
}
}
}
impl Render for ScoreComponentsTooltip {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div().pl_2().pt_2p5().child(
div()
.elevation_2(cx)
.py_1()
.px_2()
.child(ui::Label::new(self.text.clone()).buffer_font(cx)),
)
}
}