The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): add --body-file to create for shell-proof bodies
Yagna Vudathudaf5e0d7a787
diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.pyindex dc8be95f5df..afa4b0f6473 100644--- a/hermes_cli/kanban.py+++ b/hermes_cli/kanban.py@@ -341,6 +341,16 @@ def _cmd_assignees(args: argparse.Namespace) -> int:def _cmd_create(args: argparse.Namespace) -> int:from agent.delegation_context import is_dispatcher_owned_worker_context+ body = args.body+ body_file = getattr(args, "body_file", None)+ if body is not None and body_file is not None:+ return _err("kanban: --body and --body-file are mutually exclusive", 2)+ if body_file is not None:+ try:+ body = sys.stdin.read() if body_file == "-" else Path(body_file).read_text()+ except OSError as exc:+ return _err(f"kanban: --body-file: {exc}", 2)+try:ws_kind, ws_path = _parse_workspace_flag(args.workspace)branch_name = _parse_branch_flag(getattr(args, "branch", None))@@ -358,7 +368,7 @@ def _cmd_create(args: argparse.Namespace) -> int:"use 1 to trip on the first failure.", 2)with kbc.connect_closing() as conn:task_id = kb.create_task(- conn, title=args.title, body=args.body, assignee=args.assignee,+ conn, title=args.title, body=body, assignee=args.assignee,created_by=args.created_by or _profile_author(),workspace_kind=ws_kind, workspace_path=ws_path, branch_name=branch_name,project_id=getattr(args, "project", None), tenant=args.tenant, priority=args.priority,diff --git a/hermes_cli/kanban_parser.py b/hermes_cli/kanban_parser.pyindex 9c17b1f0f2e..d36cf96f216 100644--- a/hermes_cli/kanban_parser.py+++ b/hermes_cli/kanban_parser.py@@ -148,6 +148,10 @@ _SPECS = [_cmd("create", [_arg("title", help="Task title"),_arg("--body", help="Optional opening post"),+ _arg("--body-file", metavar="PATH",+ help="Read the opening post from a file ('-' = stdin), so bodies with embedded "+ "newlines or flag-like lines survive shell quoting. "+ "Mutually exclusive with --body."),_arg("--assignee", help="Profile name to assign"),_arg("--parent", action="append", default=[], help="Parent task id (repeatable)"),_arg("--workspace",diff --git a/tests/hermes_cli/test_kanban_create_body_file.py b/tests/hermes_cli/test_kanban_create_body_file.pynew file mode 100644index 00000000000..20b113e013e--- /dev/null+++ b/tests/hermes_cli/test_kanban_create_body_file.py@@ -0,0 +1,90 @@+"""`kanban create --body-file` — shell-proof body delivery (#115432).++`--body` is a plain string: embedded newlines and trailing flag-like tokens+(e.g. a body line reading ``--json``) die in shell-to-Python marshalling+(MSYS git-bash / terminal shell=True). ``--body-file <path>|-`` reads the+body from a file (``-`` = stdin) so the bytes never cross the shell.+"""++from __future__ import annotations++import argparse+import io+from pathlib import Path++import pytest++from hermes_cli import kanban as kc+from hermes_cli import kanban_db as kb+from hermes_cli import kanban_db_connect as kbc++BODY = "line one\nline two\n--json\n--body should survive verbatim\n"+++def kanban_home(tmp_path, monkeypatch):+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ kb.init_db()+ return home+++def _build_kanban_parser():+ root = argparse.ArgumentParser(prog="hermes")+ subs = root.add_subparsers()+ return kc.build_parser(subs)+++def _make_create_ns(**overrides):+ ns = argparse.Namespace(+ title="t", body=None, body_file=None, assignee=None,+ created_by="user", workspace="scratch", branch=None, project=None,+ tenant=None, priority=0, parent=None, triage=False,+ idempotency_key=None, max_runtime=None, max_retries=None,+ skills=None, json=False, model_override=None,+ provider_override=None, goal_mode=False, goal_max_turns=None,+ completion_contract=None, initial_status="running",+ )+ for k, v in overrides.items():+ setattr(ns, k, v)+ return ns+++def _latest_body():+ with kbc.connect_closing() as conn:+ tasks = kb.list_tasks(conn)+ assert tasks, "expected _cmd_create to have stored a task"+ return tasks[-1].body+++def test_create_parser_accepts_body_file():+ parser = _build_kanban_parser()+ args = parser.parse_args(["create", "title here", "--body-file", "note.md"])+ assert args.body_file == "note.md"+++def test_create_body_file_preserves_newlines_and_flag_like_lines(kanban_home, tmp_path, capsys):+ f = tmp_path / "body.md"+ f.write_text(BODY)+ rc = kc._cmd_create(_make_create_ns(body_file=str(f)))+ assert rc == 0+ capsys.readouterr()+ assert _latest_body() == BODY+++def test_create_body_file_dash_reads_stdin(kanban_home, monkeypatch, capsys):+ monkeypatch.setattr("sys.stdin", io.StringIO(BODY))+ rc = kc._cmd_create(_make_create_ns(body_file="-"))+ assert rc == 0+ capsys.readouterr()+ assert _latest_body() == BODY+++def test_create_body_and_body_file_conflict(kanban_home, tmp_path, capsys):+ f = tmp_path / "body.md"+ f.write_text(BODY)+ rc = kc._cmd_create(_make_create_ns(body="inline", body_file=str(f)))+ assert rc == 2+ capsys.readouterr()