Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(todo): handle empty todo list in list_todos

Steven Enamakel301c2c154517
diff --git a/crates/openhuman-core/src/agent/tools/todo.rs b/crates/openhuman-core/src/agent/tools/todo.rs
index f3a26601c2..2b3f7f6f41 100644
--- a/crates/openhuman-core/src/agent/tools/todo.rs
+++ b/crates/openhuman-core/src/agent/tools/todo.rs
@@ -1,16 +1,18 @@
-//! `todo` — unified CRUD tool for the agent's task board.
+//! `todo` — the session's todo list, the way Claude Code and Codex have it.
//!
-//! Dispatches on the `op` field so a single tool exposes
-//! `add` / `edit` / `update_status` / `remove` / `replace` / `clear` /
-//! `list`. The board is persisted to the active thread (when there is
-//! one) via [`crate::agent::todos::ops`]; without a caller thread the
-//! tool falls back to a process-global scratch list. Returns a markdown
-//! rendering so transcripts read cleanly.
+//! One call writes the whole list: `{"todos": [{"content", "status"}]}`.
+//! There is no per-card CRUD, no approval gate, no evidence, no plan; the
+//! list is a progress checklist the model rewrites as it works. It is scoped
+//! to the conversation thread the turn runs in and persists across turns of
+//! that thread via [`crate::agent::todos::ops`]; without a thread (a bare
+//! `execute` in a test) it falls back to a process-global scratch list.
+//! Calling with no `todos` returns the current list.
use crate::agent::harness::fork_context::ParentExecutionContext;
-use crate::agent::todos::ops::{self, BoardLocation, CardPatch};
-use crate::agent::todos::types::{TaskApprovalMode, TaskBoardCard, TaskCardStatus};
+use crate::agent::todos::ops::{self, TodoScope};
+use crate::agent::todos::types::{TaskBoardCard, TaskCardStatus};
use async_trait::async_trait;
+use serde::Deserialize;
use serde_json::json;
use std::sync::Arc;
use tinyagents_harness::context::RunContext;
@@ -59,6 +61,16 @@ impl Default for TodoTool {
}
}
+/// One item as the model writes it. `status` accepts the Claude-style
+/// `pending` / `in_progress` / `completed` plus the older `todo` / `done`
+/// spellings the store already parses.
+#[derive(Deserialize)]
+struct TodoItem {
+ content: String,
+ #[serde(default)]
+ status: Option<String>,
+}
+
#[async_trait]
impl Tool for TodoTool {
fn name(&self) -> &str {
@@ -66,47 +78,32 @@ impl Tool for TodoTool {
}
fn description(&self) -> &str {
- "The thread's visible task list; cards persist across turns. Use for requests with \
- 3+ steps. Keep one `in_progress`; mark cards `done` as soon as they are, and \
- `blocked` with a `blocker`. The board binds automatically; do not pass a thread id."
+ "Your todo list for this conversation. Pass the complete list every time; it \
+ replaces what was there. Use it for work with 3+ steps: write the steps up front, \
+ keep exactly one `in_progress`, mark each `completed` the moment it is done. Omit \
+ `todos` to read the current list."
}
fn parameters_schema(&self) -> serde_json::Value {
- // The parser still accepts `objective`, `plan`, `allowedTools`,
- // `approvalMode` and `acceptanceCriteria` (dispatched boards set them
- // through the task RPCs), but they are not advertised: a chat agent
- // never filled them and each cost every turn a slice of schema.
json!({
"type": "object",
"properties": {
- "op": {
- "type": "string",
- "enum": ["add", "edit", "update_status", "decide_plan", "remove", "replace", "clear", "list"]
- },
- "id": { "type": "string", "description": "Card id (edit/update_status/remove)." },
- "content": { "type": "string", "description": "Card title (add; optional for edit)." },
- "status": {
- "type": "string",
- "enum": ["todo", "pending", "in_progress", "blocked", "done", "completed"]
- },
- "notes": { "type": "string" },
- "blocker": { "type": "string" },
- "approve": {
- "type": "boolean",
- "description": "decide_plan: approve (true) or reject (false) a card awaiting approval."
- },
- "evidence": {
+ "todos": {
"type": "array",
- "description": "Verification output, links or files produced for the card.",
- "items": { "type": "string" }
- },
- "cards": {
- "type": "array",
- "description": "Full card list for op=replace.",
- "items": { "type": "object" }
+ "description": "The full list, in order.",
+ "items": {
+ "type": "object",
+ "properties": {
+ "content": { "type": "string" },
+ "status": {
+ "type": "string",
+ "enum": ["pending", "in_progress", "completed"]
+ }
+ },
+ "required": ["content", "status"]
+ }
}
- },
- "required": ["op"]
+ }
})
}
@@ -137,72 +134,46 @@ impl TodoTool {
parent: Option<ParentExecutionContext>,
tool_context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
- let op = args
- .get("op")
- .and_then(|v| v.as_str())
- .ok_or_else(|| anyhow::anyhow!("missing required field `op`"))?
- .trim()
- .to_string();
-
- let location = current_location(parent.as_ref(), tool_context);
- tracing::debug!(op = %op, thread_id = ?location.thread_id(), "[tool][todo] dispatch");
-
- let result = match op.as_str() {
- "add" => {
- let content = required_string(&args, "content")?;
- let mut patch = patch_from_args(&args)?;
- if patch.approval_mode.is_none() {
- patch.approval_mode = Some(default_task_approval_mode().await);
+ let scope = current_scope(parent.as_ref(), tool_context);
+ tracing::debug!(thread_id = ?scope.thread_id(), "[tool][todo] dispatch");
+
+ let result = match args.get("todos") {
+ None | Some(serde_json::Value::Null) => ops::list(&scope).await,
+ Some(raw) => {
+ let items: Vec<TodoItem> = serde_json::from_value(raw.clone())
+ .map_err(|e| anyhow::anyhow!("invalid `todos`: {e}"))?;
+ let mut cards = Vec::with_capacity(items.len());
+ for item in items {
+ let content = item.content.trim();
+ if content.is_empty() {
+ anyhow::bail!("every todo needs non-empty `content`");
+ }
+ let mut card = TaskBoardCard::new(content);
+ card.status = match item.status.as_deref() {
+ None => TaskCardStatus::Todo,
+ Some(raw) => ops::parse_status(raw).map_err(anyhow::Error::msg)?,
+ };
+ cards.push(card);
}
- ops::add(&location, &content, patch).await
- }
- "edit" => {
- let id = required_string(&args, "id")?;
- let mut patch = patch_from_args(&args)?;
- patch.content = optional_string(&args, "content");
- ops::edit(&location, &id, patch).await
- }
- "update_status" => {
- let id = required_string(&args, "id")?;
- let status = required_string(&args, "status")?;
- let status = ops::parse_status(&status).map_err(anyhow::Error::msg)?;
- ops::update_status(&location, &id, status).await
- }
- "remove" => {
- let id = required_string(&args, "id")?;
- ops::remove(&location, &id).await
- }
- "replace" => {
- let cards = args
- .get("cards")
- .ok_or_else(|| anyhow::anyhow!("missing `cards` for op=replace"))?;
- let cards: Vec<TaskBoardCard> = serde_json::from_value(cards.clone())
- .map_err(|e| anyhow::anyhow!("invalid `cards`: {e}"))?;
- ops::replace(&location, cards).await
- }
- "decide_plan" => {
- let id = required_string(&args, "id")?;
- let approve = args
- .get("approve")
- .and_then(serde_json::Value::as_bool)
- .ok_or_else(|| anyhow::anyhow!("missing required boolean `approve`"))?;
- ops::decide_plan(&location, &id, approve).await
- }
- "clear" => ops::clear(&location).await,
- "list" => ops::list(&location).await,
- other => {
- return Ok(ToolResult::error(format!(
- "unknown op '{other}' (expected \
- add|edit|update_status|decide_plan|remove|replace|clear|list)"
- )));
+ ops::replace(&scope, cards).await
}
};
match result {
Ok(snap) => {
+ let todos: Vec<serde_json::Value> = snap
+ .cards
+ .iter()
+ .map(|card| {
+ json!({
+ "content": card.title,
+ "status": wire_status(card.status),
+ })
+ })
+ .collect();
let payload = json!({
"threadId": snap.thread_id,
- "cards": snap.cards,
+ "todos": todos,
"markdown": snap.markdown,
});
Ok(ToolResult::success(payload.to_string()))
@@ -212,127 +183,40 @@ impl TodoTool {
}
}
-async fn default_task_approval_mode() -> Option<TaskApprovalMode> {
- // Interactive plan review is handled by the `request_plan_review` gate
- // (it parks the live turn), NOT by stamping conversation-thread cards: the
- // background dispatcher never sweeps conversation boards, so a card status
- // can't gate a chat turn. This default therefore just carries the
- // config-driven behaviour for the dispatched boards (`user-tasks` /
- // `task-sources`).
- match crate::config::ops::load_config_with_timeout().await {
- Ok(config) => Some(if config.autonomy.require_task_plan_approval {
- TaskApprovalMode::Required
- } else {
- TaskApprovalMode::NotRequired
- }),
- Err(err) => {
- tracing::debug!(
- error = %err,
- "[tool][todo] failed to load config for task approval default"
- );
- None
- }
+/// The three states the model is told about. Store states the list can no
+/// longer produce (`ready`, `awaiting_approval`, `rejected`, `blocked`) fold
+/// into the nearest one so an old thread still reads sensibly.
+fn wire_status(status: TaskCardStatus) -> &'static str {
+ match status {
+ TaskCardStatus::InProgress => "in_progress",
+ TaskCardStatus::Done | TaskCardStatus::Rejected => "completed",
+ TaskCardStatus::Todo
+ | TaskCardStatus::Ready
+ | TaskCardStatus::AwaitingApproval
+ | TaskCardStatus::Blocked => "pending",
}
}
-fn current_location(
+/// Every agent, the orchestrator included, binds to the conversation thread it
+/// runs in. The orchestrator used to be routed to one app-wide
+/// `orchestrator-tasks` board instead; nothing rendered it, so the list the
+/// model kept was invisible to the thread the user was looking at.
+fn current_scope(
parent: Option<&ParentExecutionContext>,
tool_context: Option<&dyn ToolRunContext>,
-) -> BoardLocation {
+) -> TodoScope {
let Some(parent) = parent else {
- return BoardLocation::Scratch;
+ return TodoScope::Scratch;
};
- // Every agent, the orchestrator included, binds to the conversation thread
- // it is running in. The orchestrator used to be routed to one app-wide
- // `orchestrator-tasks` board instead; that board is deprecated and nothing
- // renders it, so cards written there were invisible to the thread the
- // user was looking at.
let Some(thread_id) = tool_context.and_then(ToolRunContext::thread_id) else {
- return BoardLocation::Scratch;
+ return TodoScope::Scratch;
};
- BoardLocation::Thread {
+ TodoScope::Thread {
workspace_dir: parent.workspace_dir.clone(),
thread_id: thread_id.to_owned(),
}
}
-fn required_string(args: &serde_json::Value, key: &str) -> anyhow::Result<String> {
- let value = args
- .get(key)
- .and_then(|v| v.as_str())
- .ok_or_else(|| anyhow::anyhow!("missing required field `{key}`"))?;
- let trimmed = value.trim();
- if trimmed.is_empty() {
- return Err(anyhow::anyhow!("missing required field `{key}`"));
- }
- Ok(trimmed.to_string())
-}
-
-fn optional_string(args: &serde_json::Value, key: &str) -> Option<String> {
- args.get(key)
- .and_then(|v| v.as_str())
- .map(|s| s.to_string())
-}
-
-fn patch_from_args(args: &serde_json::Value) -> anyhow::Result<CardPatch> {
- let status: Option<TaskCardStatus> = match args.get("status").and_then(|v| v.as_str()) {
- Some(s) => Some(ops::parse_status(s).map_err(anyhow::Error::msg)?),
- None => None,
- };
- let approval_mode = match args.get("approvalMode") {
- Some(value) if value.is_null() => Some(None),
- Some(value) => match value.as_str() {
- Some("required") => Some(Some(TaskApprovalMode::Required)),
- Some("not_required") => Some(Some(TaskApprovalMode::NotRequired)),
- Some(other) => {
- return Err(anyhow::anyhow!(
- "invalid approvalMode '{other}' (expected required|not_required|null)"
- ));
- }
- None => {
- return Err(anyhow::anyhow!(
- "invalid approvalMode type (expected required|not_required|null)"
- ));
- }
- },
- None => None,
- };
- Ok(CardPatch {
- content: None,
- status,
- objective: optional_string(args, "objective"),
- plan: optional_string_array(args, "plan")?,
- allowed_tools: optional_string_array(args, "allowedTools")?,
- approval_mode,
- acceptance_criteria: optional_string_array(args, "acceptanceCriteria")?,
- evidence: optional_string_array(args, "evidence")?,
- notes: optional_string(args, "notes"),
- blocker: optional_string(args, "blocker"),
- source_metadata: None,
- })
-}
-
-fn optional_string_array(
- args: &serde_json::Value,
- key: &str,
-) -> anyhow::Result<Option<Vec<String>>> {
- let Some(value) = args.get(key) else {
- return Ok(None);
- };
- let values = value
- .as_array()
- .ok_or_else(|| anyhow::anyhow!("`{key}` must be an array of strings"))?;
- values
- .iter()
- .map(|item| {
- item.as_str()
- .map(|s| s.to_string())
- .ok_or_else(|| anyhow::anyhow!("`{key}` must be an array of strings"))
- })
- .collect::<anyhow::Result<Vec<_>>>()
- .map(Some)
-}
-
#[cfg(test)]
#[path = "todo_tests.rs"]
mod tests;