The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): align kanban edit and paused cron listing
fangliquanflq3f399c0bd457
diff --git a/hermes_cli/cron.py b/hermes_cli/cron.pyindex af415ab86e6..a5f1407495b 100644--- a/hermes_cli/cron.py+++ b/hermes_cli/cron.py@@ -168,7 +168,12 @@ _STATE_BADGES = {"paused": ("[paused]", Colors.YELLOW), "completed": ("[completedef cron_list(show_all: bool = False):"""List all scheduled jobs."""from cron.jobs import effective_job_state, list_jobs- jobs = list_jobs(include_disabled=show_all)+ jobs = list_jobs(include_disabled=True)+ if not show_all:+ jobs = [+ job for job in jobs+ if job.get("enabled", True) or effective_job_state(job) == "paused"+ ]if not jobs:print(color("No scheduled jobs.\nCreate one with 'hermes cron create ...' "diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.pyindex 8e85ea4ffdb..8c146d36553 100644--- a/hermes_cli/kanban.py+++ b/hermes_cli/kanban.py@@ -947,13 +947,29 @@ def _cmd_complete(args: argparse.Namespace) -> int:def _cmd_edit(args: argparse.Namespace) -> int:- metadata, rc = _parse_metadata_flag(getattr(args, "metadata", None))+ result = getattr(args, "result", None)+ raw_metadata = getattr(args, "metadata", None)+ summary = getattr(args, "summary", None)+ title = getattr(args, "title", None)+ body = getattr(args, "body", None)+ priority = getattr(args, "priority", None)+ if result is None and (summary is not None or raw_metadata is not None):+ return _err("kanban edit: --summary and --metadata require --result", 2)+ if all(value is None for value in (title, body, priority, result)):+ return _err("kanban edit: provide --title, --body, --priority, or --result", 2)+ metadata, rc = _parse_metadata_flag(raw_metadata)if rc:return rcwith kbc.connect_closing() as conn:- ok = kb.edit_completed_task_result(conn, args.task_id, result=args.result,- summary=getattr(args, "summary", None), metadata=metadata)- return _ok_or_err(ok, f"cannot edit {args.task_id} (unknown id or task is not done)", f"Edited {args.task_id}")+ ok = kb.edit_task(+ conn, args.task_id, title=title, body=body, priority=priority,+ result=result, summary=summary, metadata=metadata,+ )+ return _ok_or_err(+ ok,+ f"cannot edit {args.task_id} (unknown id, or --result used on a task that is not done)",+ f"Edited {args.task_id}",+ )def _commented(conn, reason: Optional[str], author, prefix: str, op):diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 960936560b7..87d676113b0 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -3073,17 +3073,49 @@ def _unique_attachment_path(directory: Path, filename: str, used: set[Path]) ->return candidate-def edit_completed_task_result(- conn: sqlite3.Connection, task_id: str, *, result: str, summary: Optional[str] = None,+def edit_task(+ conn: sqlite3.Connection, task_id: str, *, title: Optional[str] = None,+ body: Optional[str] = None, priority: Optional[int] = None,+ result: Optional[str] = None, summary: Optional[str] = None,metadata: Optional[dict] = None,) -> bool:- """Backfill the user-visible result for an already completed task."""- handoff_summary = summary if summary is not None else result+ """Edit task fields, optionally backfilling a completed task's result."""+ changed_fields = [+ field for field, value in (("title", title), ("body", body), ("priority", priority))+ if value is not None+ ]with write_txn(conn):- if _task_status(conn, task_id) != "done":+ status = _task_status(conn, task_id)+ if status is None or (result is not None and status != "done"):+ return False+ assignments = []+ params = []+ for field, value in (("title", title), ("body", body), ("priority", priority)):+ if value is not None:+ assignments.append(f"{field} = ?")+ params.append(value)+ if result is not None:+ assignments.append("result = ?")+ params.append(result)+ changed_fields.append("result")+ if not assignments:return False- conn.execute("UPDATE tasks SET result = ? WHERE id = ?", (result, task_id))- run = conn.execute(+ conn.execute(+ f"UPDATE tasks SET {', '.join(assignments)} WHERE id = ?",+ (*params, task_id),+ )+ if priority is not None:+ _append_event(conn, task_id, "reprioritized", {"priority": priority})+ if result is None:+ non_priority_fields = [field for field in changed_fields if field != "priority"]+ if non_priority_fields:+ _append_event(conn, task_id, "edited", {"fields": non_priority_fields})+ else:+ handoff_summary = summary if summary is not None else result+ changed_fields.append("summary")+ if metadata is not None:+ changed_fields.append("metadata")+ run = conn.execute("""SELECT id FROM task_runsWHERE task_id = ?@@ -3093,30 +3125,39 @@ def edit_completed_task_result(""",(task_id,),).fetchone()- if run is None:- run_id = _synthesize_ended_run(- conn, task_id, outcome="completed", summary=handoff_summary, metadata=metadata,- )- else:- run_id = int(run["id"])- conn.execute("UPDATE task_runs SET summary = ? WHERE id = ?", (handoff_summary, run_id))- if metadata is not None:- conn.execute(- "UPDATE task_runs SET metadata = ? WHERE id = ?",- (json.dumps(metadata, ensure_ascii=False), run_id),+ if run is None:+ run_id = _synthesize_ended_run(+ conn, task_id, outcome="completed", summary=handoff_summary, metadata=metadata,)- _append_event(- conn, task_id, "edited",- {- "fields": ["result", "summary"] + (["metadata"] if metadata is not None else []),- "result_len": len(result) if result else 0,- "summary": _first_line(handoff_summary, 400) or None,- },- run_id=run_id,- )+ else:+ run_id = int(run["id"])+ conn.execute("UPDATE task_runs SET summary = ? WHERE id = ?", (handoff_summary, run_id))+ if metadata is not None:+ conn.execute(+ "UPDATE task_runs SET metadata = ? WHERE id = ?",+ (json.dumps(metadata, ensure_ascii=False), run_id),+ )+ _append_event(+ conn, task_id, "edited",+ {+ "fields": ["result", "summary"] + (["metadata"] if metadata is not None else []),+ "result_len": len(result) if result else 0,+ "summary": _first_line(handoff_summary, 400) or None,+ },+ run_id=run_id,+ )+ notify_task_updated(conn, task_id, changed_fields)return True+def edit_completed_task_result(+ conn: sqlite3.Connection, task_id: str, *, result: str, summary: Optional[str] = None,+ metadata: Optional[dict] = None,+) -> bool:+ """Backfill the user-visible result for an already completed task."""+ return edit_task(conn, task_id, result=result, summary=summary, metadata=metadata)++def block_task(conn: sqlite3.Connection, task_id: str, *, reason: Optional[str] = None,kind: Optional[str] = None, expected_run_id: Optional[int] = None,diff --git a/hermes_cli/kanban_parser.py b/hermes_cli/kanban_parser.pyindex d36cf96f216..f75a44eda05 100644--- a/hermes_cli/kanban_parser.py+++ b/hermes_cli/kanban_parser.py@@ -294,9 +294,12 @@ _SPECS = [], help="Mark one or more tasks done"),_cmd("edit", [_TASK_ID,- _arg("--result", required=True, help="Backfilled task result text for a done task"),+ _arg("--title", help="Replace the task title"),+ _arg("--body", help="Replace the task body"),+ _arg("--priority", type=int, help="Replace the task priority"),+ _arg("--result", help="Backfilled task result text for a done task"),*_STEP_HANDOFF,- ], help="Edit recovery fields on an already-completed task"),+ ], help="Edit task fields or recovery fields on an already-completed task"),_cmd("block", [_TASK_ID,_arg("reason", nargs="*", help="Reason (also appended as a comment)"),diff --git a/hermes_cli/subcommands/cron.py b/hermes_cli/subcommands/cron.pyindex 9baa530c86d..365ac5368b5 100644--- a/hermes_cli/subcommands/cron.py+++ b/hermes_cli/subcommands/cron.py@@ -18,7 +18,7 @@ def build_cron_parser(subparsers, *, cmd_cron: Callable) -> None:cron_subparsers = cron_parser.add_subparsers(dest="cron_command")cron_list = cron_subparsers.add_parser("list", help="List scheduled jobs")- _flag(cron_list, "--all", help="Include disabled jobs")+ _flag(cron_list, "--all", help="Include disabled and completed jobs")cron_create = cron_subparsers.add_parser("create", aliases=["add"], help="Create a scheduled job")diff --git a/tests/hermes_cli/test_cron.py b/tests/hermes_cli/test_cron.pyindex 4300cfbf5fd..9da7444e2ee 100644--- a/tests/hermes_cli/test_cron.py+++ b/tests/hermes_cli/test_cron.py@@ -8,7 +8,7 @@ from types import SimpleNamespaceimport pytest-from cron.jobs import create_job, get_job, list_jobs, load_jobs, save_jobs+from cron.jobs import create_job, get_job, list_jobs, load_jobs, pause_job, save_jobsfrom hermes_cli import cron as cron_clifrom hermes_cli.cron import cron_commandfrom hermes_cli.subcommands.cron import build_cron_parser@@ -260,6 +260,18 @@ class TestCronDoctor:class TestCronListStatusRendering:"""`cron list` must never paint an undelivered run as a success (#83993)."""+ def test_default_list_includes_paused_jobs(self, tmp_cron_dir, capsys, monkeypatch):+ monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [1])+ job = create_job(prompt="Paused digest", schedule="every 1h")+ pause_job(job["id"])++ cron_command(Namespace(cron_command="list", all=False))++ out = capsys.readouterr().out+ assert job["id"] in out+ assert "[paused]" in out+ assert "No scheduled jobs" not in out+def test_delivery_failed_is_not_green_ok(self, tmp_cron_dir, capsys, monkeypatch):monkeypatch.setattr("hermes_cli.gateway.find_gateway_pids", lambda: [1])# capsys is not a tty, so force colors on to check the paint itself.diff --git a/tests/hermes_cli/test_kanban_cli.py b/tests/hermes_cli/test_kanban_cli.pyindex 079148f1e91..7ffee70c80c 100644--- a/tests/hermes_cli/test_kanban_cli.py+++ b/tests/hermes_cli/test_kanban_cli.py@@ -72,6 +72,22 @@ def test_kanban_show_text_renders_graph_with_open_connection(kanban_home):assert "Cannot operate on a closed database" not in output+def test_kanban_edit_updates_documented_task_fields(kanban_home):+ with kbc.connect_closing() as conn:+ task_id = kb.create_task(conn, title="old title", body="old body", priority=2)++ output = kc.run_slash(+ f"edit {task_id} --title 'new title' --body 'new body' --priority 70"+ )++ assert f"Edited {task_id}" in output+ with kbc.connect_closing() as conn:+ task = kb.get_task(conn, task_id)+ events = kb.list_events(conn, task_id)+ assert (task.title, task.body, task.priority) == ("new title", "new body", 70)+ assert any(event.kind == "reprioritized" for event in events)++def test_worker_link_preserves_foreign_child_rules(kanban_home, monkeypatch):with kbc.connect_closing() as conn:worker = kb.create_task(conn, title="worker")