fix: align TodoWrite memory model with task system docs

This commit is contained in:
Gui-Yue
2026-05-21 23:31:30 +08:00
parent 1baf1aca5a
commit 6d48bc978b
17 changed files with 85 additions and 72 deletions

View File

@@ -28,7 +28,7 @@ Run: python s06_subagent/code.py
Needs: pip install anthropic python-dotenv + ANTHROPIC_API_KEY in .env
"""
import os, subprocess, json
import os, subprocess
from pathlib import Path
try:
@@ -45,9 +45,9 @@ if os.getenv("ANTHROPIC_BASE_URL"):
os.environ.pop("ANTHROPIC_AUTH_TOKEN", None)
WORKDIR = Path.cwd()
TASKS_DIR = WORKDIR / ".tasks"; TASKS_DIR.mkdir(exist_ok=True)
client = Anthropic(base_url=os.getenv("ANTHROPIC_BASE_URL"))
MODEL = os.environ["MODEL_ID"]
CURRENT_TODOS: list[dict] = []
SYSTEM = (
f"You are a coding agent at {WORKDIR}. "
@@ -122,19 +122,19 @@ def run_glob(pattern: str) -> str:
return f"Error: {e}"
def run_todo_write(todos: list) -> str:
global CURRENT_TODOS
for i, t in enumerate(todos):
if "content" not in t or "status" not in t:
return f"Error: todos[{i}] missing 'content' or 'status'"
if t["status"] not in ("pending", "in_progress", "completed"):
return f"Error: todos[{i}] has invalid status '{t['status']}'"
tasks_file = TASKS_DIR / "current_todos.json"
tasks_file.write_text(json.dumps(todos, indent=2, ensure_ascii=False))
CURRENT_TODOS = todos
lines = ["\n\033[33m## Current Tasks\033[0m"]
for t in todos:
for t in CURRENT_TODOS:
icon = {"pending": " ", "in_progress": "\033[36m▸\033[0m", "completed": "\033[32m✓\033[0m"}[t["status"]]
lines.append(f" [{icon}] {t['content']}")
print("\n".join(lines))
return f"Updated {len(todos)} tasks"
return f"Updated {len(CURRENT_TODOS)} tasks"
def extract_text(content) -> str:
"""Extract text from message content blocks."""