agent: per-session todo queue (todo tool, pinned TODO section, GUI panel)
Persistent task list (pending/doing/done) with never-reused seq from a per-session high-water mark; open items injected as a dynamic TODO section with pre-warm-on-change; read-only GUI panel + i18n; TOOL_USE manual extended. Docs updated; agent-feedback memory Q&A exchange and AGENT_RULES seed rules included. Verified: 245 passed / 6 ignored, clippy+fmt clean; dogfooded live.
This commit is contained in:
1 parent
f74d53e446
commit
9b05592efb
16 files changed
+1067
-21
No files matched your search
+68
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
use crate::api::types::{now_unix, ChatMessage, Role};
|
||||
use crate::i18n::t;
|
||||
use crate::store::{ContextSection, NotepadEntry, Session, StoredMessage};
|
||||
use crate::store::{ContextSection, NotepadEntry, Session, StoredMessage, TodoItem};
|
||||
|
||||
/// Compose the full context message list: static sections, then the DIALOG region.
|
||||
/// `user_content` is the new turn's typed text plus attachment context.
|
||||
@@ -194,6 +194,36 @@ pub fn notepad_fingerprint(notepad: &[NotepadEntry]) -> String {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/// The rendered `<TODO>` body: one `seq [status] content` line per OPEN item
|
||||
/// (pending/doing), in store order (seq). Done items stay in the Store for
|
||||
/// history/GUI but never enter the prompt. Like the notepad fingerprint this is
|
||||
/// exactly the injected header body, so it doubles as the pre-warm-on-change
|
||||
/// trigger; `updated_at` is excluded (an identical re-set is not a change).
|
||||
pub fn todo_fingerprint(todos: &[TodoItem]) -> String {
|
||||
todos
|
||||
.iter()
|
||||
.filter(|i| i.status != "done")
|
||||
.map(|i| format!("{} [{}] {}", i.seq, i.status, i.content.replace('\n', " ")))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/// The dynamic `<TODO>` pinned section, built from the session's open tasks
|
||||
/// (None when there are none). Appended to the static sections like the MCP
|
||||
/// surface, so the real turn and the cache pre-warm share a byte-identical
|
||||
/// prefix with no extra compositor parameter.
|
||||
pub fn todo_section(todos: &[TodoItem]) -> Option<ContextSection> {
|
||||
let body = todo_fingerprint(todos);
|
||||
if body.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(ContextSection {
|
||||
name: "TODO".into(),
|
||||
content: body,
|
||||
position: 3,
|
||||
})
|
||||
}
|
||||
|
||||
fn role_of(s: &str) -> Role {
|
||||
match s {
|
||||
"system" | "developer" => Role::System,
|
||||
@@ -631,4 +661,41 @@ mod tests {
|
||||
assert_eq!(notepad_fingerprint(&d), "state: coding now");
|
||||
assert_eq!(notepad_fingerprint(&[]), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn todo_section_renders_open_items_only_and_fingerprint_ignores_done() {
|
||||
let item = |seq: i64, status: &str, content: &str, updated_at: i64| TodoItem {
|
||||
seq,
|
||||
content: content.into(),
|
||||
status: status.into(),
|
||||
created_at: 0,
|
||||
updated_at,
|
||||
};
|
||||
let todos = vec![
|
||||
item(1, "doing", "wire the tool", 1),
|
||||
item(2, "done", "design the schema", 5),
|
||||
item(3, "pending", "write\ntests", 1),
|
||||
];
|
||||
let sec = todo_section(&todos).unwrap();
|
||||
assert_eq!(sec.name, "TODO");
|
||||
assert_eq!(
|
||||
sec.content,
|
||||
"1 [doing] wire the tool\n3 [pending] write tests"
|
||||
);
|
||||
// updated_at does not affect the rendered body (no wasted pre-warm).
|
||||
let bumped = vec![
|
||||
item(1, "doing", "wire the tool", 999),
|
||||
item(3, "pending", "write\ntests", 999),
|
||||
];
|
||||
assert_eq!(todo_fingerprint(&todos), todo_fingerprint(&bumped));
|
||||
// A status change IS a change.
|
||||
let moved = vec![
|
||||
item(1, "done", "wire the tool", 1),
|
||||
item(3, "pending", "write\ntests", 1),
|
||||
];
|
||||
assert_ne!(todo_fingerprint(&todos), todo_fingerprint(&moved));
|
||||
// All done (or empty) -> no section at all.
|
||||
assert!(todo_section(&[item(2, "done", "x", 0)]).is_none());
|
||||
assert!(todo_section(&[]).is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user