дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-28 13:32:29 +02:00
fix(agents): title a task from the prompt's text outside code fences
A prompt that opened with a pasted fenced block (a log, a code sample) was titled from the first line inside the block until the generated title arrived. A line outside the fences now wins; a prompt that is one fenced block is still titled from inside it.
Цей коміт міститься в:
1 джерело
77c531b9ca
коміт
bbfcdda0c1
2 files changed
+19
-3
No files matched your search
@@ -4245,11 +4245,24 @@ fn file_uri(path: &Path) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// The title of a task: the first line of the prompt that says something. A pasted Markdown
|
||||
/// block opens with a code fence (```` ```text ````), which names no task.
|
||||
/// The title of a task: the first line of the prompt that says something. Text inside a code
|
||||
/// fence (```` ```text ````) is pasted material, so a line outside the fences wins; a prompt
|
||||
/// that is all one pasted block still names its task from inside it.
|
||||
fn title_of(prompt: &AgentPrompt) -> String {
|
||||
let is_fence = |l: &str| l.starts_with("```") || l.starts_with("~~~");
|
||||
let line = prompt.text.lines().map(str::trim).find(|l| !l.is_empty() && !is_fence(l));
|
||||
let (mut outside, mut inside, mut fenced) = (None, None, false);
|
||||
for l in prompt.text.lines().map(str::trim) {
|
||||
if is_fence(l) {
|
||||
fenced = !fenced;
|
||||
} else if !l.is_empty() {
|
||||
let slot = if fenced { &mut inside } else { &mut outside };
|
||||
slot.get_or_insert(l);
|
||||
if outside.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let line = outside.or(inside);
|
||||
let line = match line {
|
||||
Some(l) => l.to_owned(),
|
||||
None => prompt.files.first().map(|f| file_name(&f.0)).unwrap_or_else(|| "Image".into()),
|
||||
|
||||
@@ -1736,6 +1736,9 @@ fn prompts_become_acp_content_blocks() {
|
||||
assert_eq!(title_of(&AgentPrompt { files: p.files.clone(), ..AgentPrompt::default() }), "my file.rs");
|
||||
let pasted = AgentPrompt { text: "```text\n\n ## Fix the tab title\n```".into(), ..AgentPrompt::default() };
|
||||
assert_eq!(title_of(&pasted), "## Fix the tab title");
|
||||
let fenced_first =
|
||||
AgentPrompt { text: "```txt\nlog line\n```\nWhy does this fail?".into(), ..AgentPrompt::default() };
|
||||
assert_eq!(title_of(&fenced_first), "Why does this fail?");
|
||||
assert!(clean(text(" ")).is_none());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача