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
@@ -83,6 +83,7 @@ fn build_router(state: AppState, auth: AuthConfig) -> Router {
|
||||
)
|
||||
.route("/api/sessions/{id}/messages", get(sessions::get_messages))
|
||||
.route("/api/sessions/{id}/notepad", get(sessions::get_notepad))
|
||||
.route("/api/sessions/{id}/todos", get(sessions::get_todos))
|
||||
.route("/api/sessions/{id}/chat", post(sessions::session_chat))
|
||||
.route("/api/sessions/{id}/download", get(files::download))
|
||||
.route(
|
||||
|
||||
+46
-9
@@ -30,7 +30,7 @@ use crate::name;
|
||||
use crate::render;
|
||||
use crate::store::{
|
||||
ContextSection, McpConnector, NewMessage, NotepadEntry, Session, SessionSettings, Stats, Store,
|
||||
StoredMessage,
|
||||
StoredMessage, TodoItem,
|
||||
};
|
||||
use crate::window;
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
@@ -277,6 +277,15 @@ pub(crate) async fn get_notepad(
|
||||
Ok(Json(with_store(&st, move |s| s.notepad(&id)).await?))
|
||||
}
|
||||
|
||||
/// `GET /api/sessions/{id}/todos` — the session's task list (read-only
|
||||
/// observability; the agent writes it via the todo tool).
|
||||
pub(crate) async fn get_todos(
|
||||
State(st): State<AppState>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<Json<Vec<TodoItem>>, Error> {
|
||||
Ok(Json(with_store(&st, move |s| s.todos(&id)).await?))
|
||||
}
|
||||
|
||||
/// The stats dashboard payload: persistent history aggregates (from the store)
|
||||
/// plus a live engine status and the since-startup performance gauge, in one
|
||||
/// JSON object so the GUI renders the whole view from a single poll.
|
||||
@@ -563,6 +572,19 @@ pub(crate) async fn session_chat(
|
||||
Ok(v) => v,
|
||||
Err(e) => return e.into_response(),
|
||||
};
|
||||
// The session's task queue: open items become the dynamic <TODO> pinned
|
||||
// section (same seam as the MCP surface), so the prompt and the pre-warm
|
||||
// share a byte-identical prefix.
|
||||
let todos = match with_store(&st, {
|
||||
let id = id.clone();
|
||||
move |s| s.todos(&id)
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(e) => return e.into_response(),
|
||||
};
|
||||
all_sections.extend(context::todo_section(&todos));
|
||||
// Sliding DIALOG window: retain the most recent messages by COUNT (main area
|
||||
// + buffer headroom), with stepped eviction so the prefix stays byte-stable
|
||||
// for KV-cache reuse. Full history stays in SQLite; the agent pins what
|
||||
@@ -572,6 +594,8 @@ pub(crate) async fn session_chat(
|
||||
// trigger compares it against the notepad at turn end to detect a header change
|
||||
// (pre-warm-on-change, chosen over freezing the header).
|
||||
let notepad_fp = context::notepad_fingerprint(¬epad);
|
||||
// Same pre-warm-on-change discipline for the todo header.
|
||||
let todo_fp = context::todo_fingerprint(&todos);
|
||||
let sel = window::select(&history, window_start);
|
||||
if sel.start_id != window_start {
|
||||
let start_id = sel.start_id;
|
||||
@@ -640,6 +664,7 @@ pub(crate) async fn session_chat(
|
||||
let svc_pw = st.service.clone();
|
||||
let store_pw = store.clone();
|
||||
let notepad_fp_pw = notepad_fp.clone();
|
||||
let todo_fp_pw = todo_fp.clone();
|
||||
tokio::spawn(async move {
|
||||
// Streaming model step: emit Delta events while generating (so the GUI
|
||||
// shows thinking + final answer live), then return the accumulated
|
||||
@@ -729,6 +754,7 @@ pub(crate) async fn session_chat(
|
||||
sid.clone(),
|
||||
true,
|
||||
notepad_fp_pw,
|
||||
todo_fp_pw,
|
||||
memory_available,
|
||||
);
|
||||
});
|
||||
@@ -794,6 +820,7 @@ pub(crate) async fn session_chat(
|
||||
let svc_pw = st.service.clone();
|
||||
let agent_pw = body.agent;
|
||||
let notepad_fp_pw = notepad_fp.clone();
|
||||
let todo_fp_pw = todo_fp.clone();
|
||||
let tail = futures::stream::once(async move {
|
||||
let a = acc_end.lock().unwrap().clone();
|
||||
persist_assistant(&store, &sid, &a, prompt_len).await;
|
||||
@@ -803,6 +830,7 @@ pub(crate) async fn session_chat(
|
||||
sid.clone(),
|
||||
agent_pw,
|
||||
notepad_fp_pw,
|
||||
todo_fp_pw,
|
||||
memory_available,
|
||||
);
|
||||
Ok::<_, std::convert::Infallible>(Event::default().data("[DONE]"))
|
||||
@@ -841,6 +869,7 @@ pub(crate) async fn session_chat(
|
||||
id.clone(),
|
||||
body.agent,
|
||||
notepad_fp.clone(),
|
||||
todo_fp.clone(),
|
||||
memory_available,
|
||||
);
|
||||
Json(resp).into_response()
|
||||
@@ -891,17 +920,19 @@ async fn persist_assistant(store: &Arc<dyn Store>, sid: &str, a: &Accum, prompt_
|
||||
/// next prefix will differ from what the engine just cached. Best-effort: skipped
|
||||
/// when the engine is busy, and it never STOPs a running pre-warm (a real turn
|
||||
/// queues on the engine mutex behind it). Not a user turn: no persistence, no
|
||||
/// PerfMeter. Triggers on a pending rotation OR a notepad header change during the
|
||||
/// turn (pre-warm-on-change: the model always sees a fresh notepad, no frozen
|
||||
/// header, no schema migration). Within an agent tool loop the header is composed
|
||||
/// once and `req.messages` is append-only, so mid-loop notepad writes never
|
||||
/// invalidate intermediate steps — this fires once, at turn end, in the idle gap.
|
||||
/// PerfMeter. Triggers on a pending rotation OR a notepad/todo header change
|
||||
/// during the turn (pre-warm-on-change: the model always sees fresh headers, no
|
||||
/// frozen header, no schema migration). Within an agent tool loop the header is
|
||||
/// composed once and `req.messages` is append-only, so mid-loop notepad/todo
|
||||
/// writes never invalidate intermediate steps — this fires once, at turn end,
|
||||
/// in the idle gap.
|
||||
fn schedule_prewarm(
|
||||
service: ChatService,
|
||||
store: Arc<dyn Store>,
|
||||
sid: String,
|
||||
agent_mode: bool,
|
||||
notepad_fp: String,
|
||||
todo_fp: String,
|
||||
memory_available: bool,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
@@ -918,6 +949,7 @@ fn schedule_prewarm(
|
||||
let history = store.message_window(&sid_load, ws).ok()?.0;
|
||||
let sections = store.context_sections().ok()?;
|
||||
let notepad = store.notepad(&sid_load).ok()?;
|
||||
let todos = store.todos(&sid_load).ok()?;
|
||||
let connectors = store.mcp_connectors().ok()?;
|
||||
let user_name = store
|
||||
.get_defaults()
|
||||
@@ -926,12 +958,15 @@ fn schedule_prewarm(
|
||||
.map(|n| n.trim().to_string())
|
||||
.filter(|n| !n.is_empty())
|
||||
.unwrap_or_else(|| "User".to_string());
|
||||
Some((sess, ws, history, sections, notepad, user_name, connectors))
|
||||
Some((
|
||||
sess, ws, history, sections, notepad, todos, user_name, connectors,
|
||||
))
|
||||
})
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
let Some((sess, ws, history, sections, notepad, user_name, connectors)) = loaded else {
|
||||
let Some((sess, ws, history, sections, notepad, todos, user_name, connectors)) = loaded
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let sel = window::select(&history, ws);
|
||||
@@ -950,7 +985,8 @@ fn schedule_prewarm(
|
||||
};
|
||||
let rotation_pending = sel.start_id != cur_start;
|
||||
let notepad_dirty = context::notepad_fingerprint(¬epad) != notepad_fp;
|
||||
if !rotation_pending && !notepad_dirty {
|
||||
let todo_dirty = context::todo_fingerprint(&todos) != todo_fp;
|
||||
if !rotation_pending && !notepad_dirty && !todo_dirty {
|
||||
return;
|
||||
}
|
||||
// Rebuild the SAME curated MCP surface the real turn uses (persisted
|
||||
@@ -958,6 +994,7 @@ fn schedule_prewarm(
|
||||
let (mcp_decls, mcp_sections) = mcp_surface(&connectors, &sess.settings.mcp_enabled);
|
||||
let mut all_sections = sections.clone();
|
||||
all_sections.extend(mcp_sections);
|
||||
all_sections.extend(context::todo_section(&todos));
|
||||
let prefix = context::compose_prefix(
|
||||
&sess,
|
||||
&history[sel.start..],
|
||||
|
||||
Reference in new issue
Block a user