agent: Use default prompts from prompt library in system prompt (#28915)
Related to #28490. - Default prompts from the prompt library are now included as "user rules" in the system prompt. - Presence of these user rules is shown at the beginning of the thread in the UI. _ Now uses an `Entity<PromptStore>` instead of an `Arc<PromptStore>`. Motivation for this is emitting a `PromptsUpdatedEvent`. - Now disallows concurrent reloading of the system prompt. Before this change it was possible for reloads to race. Release Notes: - agent: Added support for including default prompts from the Prompt Library as "user rules" in the system prompt. --------- Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
parent
eea6cfb383
commit
502a0f6535
12 changed files with 433 additions and 165 deletions
|
@ -19,20 +19,29 @@ use util::{ResultExt, get_system_shell};
|
|||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ProjectContext {
|
||||
pub worktrees: Vec<WorktreeContext>,
|
||||
/// Whether any worktree has a rules_file. Provided as a field because handlebars can't do this.
|
||||
pub has_rules: bool,
|
||||
pub default_user_rules: Vec<DefaultUserRulesContext>,
|
||||
/// `!default_user_rules.is_empty()` - provided as a field because handlebars can't do this.
|
||||
pub has_default_user_rules: bool,
|
||||
pub os: String,
|
||||
pub arch: String,
|
||||
pub shell: String,
|
||||
}
|
||||
|
||||
impl ProjectContext {
|
||||
pub fn new(worktrees: Vec<WorktreeContext>) -> Self {
|
||||
pub fn new(
|
||||
worktrees: Vec<WorktreeContext>,
|
||||
default_user_rules: Vec<DefaultUserRulesContext>,
|
||||
) -> Self {
|
||||
let has_rules = worktrees
|
||||
.iter()
|
||||
.any(|worktree| worktree.rules_file.is_some());
|
||||
Self {
|
||||
worktrees,
|
||||
has_rules,
|
||||
has_default_user_rules: !default_user_rules.is_empty(),
|
||||
default_user_rules,
|
||||
os: std::env::consts::OS.to_string(),
|
||||
arch: std::env::consts::ARCH.to_string(),
|
||||
shell: get_system_shell(),
|
||||
|
@ -40,6 +49,12 @@ impl ProjectContext {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct DefaultUserRulesContext {
|
||||
pub title: Option<String>,
|
||||
pub contents: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WorktreeContext {
|
||||
pub root_name: String,
|
||||
|
@ -377,3 +392,30 @@ impl PromptBuilder {
|
|||
self.handlebars.lock().render("suggest_edits", &())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_assistant_system_prompt_renders() {
|
||||
let worktrees = vec![WorktreeContext {
|
||||
root_name: "path".into(),
|
||||
abs_path: Path::new("/some/path").into(),
|
||||
rules_file: Some(RulesFileContext {
|
||||
path_in_worktree: Path::new(".rules").into(),
|
||||
abs_path: Path::new("/some/path/.rules").into(),
|
||||
text: "".into(),
|
||||
}),
|
||||
}];
|
||||
let default_user_rules = vec![DefaultUserRulesContext {
|
||||
title: Some("Rules title".into()),
|
||||
contents: "Rules contents".into(),
|
||||
}];
|
||||
let project_context = ProjectContext::new(worktrees, default_user_rules);
|
||||
PromptBuilder::new(None)
|
||||
.unwrap()
|
||||
.generate_assistant_system_prompt(&project_context)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue