Merge pull request #342 from Bill-Billion/codex/fix-todo-write-string-input

fix: handle todo_write string inputs
This commit is contained in:
gui-yue
2026-06-03 23:33:36 +08:00
committed by GitHub
8 changed files with 403 additions and 172 deletions

View File

@@ -32,7 +32,7 @@ Builds on s07 (skill loading). Usage:
Needs: pip install anthropic python-dotenv + ANTHROPIC_API_KEY in .env
"""
import os, subprocess, json, time
import ast, json, os, subprocess, time
from pathlib import Path
try:
@@ -165,13 +165,31 @@ def run_glob(pattern: str) -> str:
return "\n".join(results) if results else "(no matches)"
except Exception as e: return f"Error: {e}"
def _normalize_todos(todos):
if isinstance(todos, str):
try:
todos = json.loads(todos)
except json.JSONDecodeError:
try:
todos = ast.literal_eval(todos)
except (SyntaxError, ValueError):
return None, "Error: todos must be a list or JSON array string"
if not isinstance(todos, list):
return None, "Error: todos must be a list"
for i, t in enumerate(todos):
if not isinstance(t, dict):
return None, f"Error: todos[{i}] must be an object"
if "content" not in t or "status" not in t:
return None, f"Error: todos[{i}] missing 'content' or 'status'"
if t["status"] not in ("pending", "in_progress", "completed"):
return None, f"Error: todos[{i}] has invalid status '{t['status']}'"
return todos, None
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']}'"
todos, error = _normalize_todos(todos)
if error:
return error
CURRENT_TODOS = todos
lines = ["\n\033[33m## Current Tasks\033[0m"]
for t in CURRENT_TODOS: