The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): an explicit scratch workspace never inherits the board's project
Tekniumb7bef048611c
diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.pyindex 70eb8b45478..689dbfca61d 100644--- a/hermes_cli/kanban.py+++ b/hermes_cli/kanban.py@@ -63,10 +63,11 @@ def _run_state_kwargs(args: argparse.Namespace, cmd: str) -> tuple[Optional[dictreturn ({} if st is None else {"state_type": st, "state_name": sn}), 0-def _parse_workspace_flag(value: str) -> tuple[str, Optional[str]]:- """``--workspace`` -> ``(kind, path|None)``: ``scratch``, ``worktree``, ``worktree:<p>``, ``dir:<p>``."""+def _parse_workspace_flag(value: Optional[str]) -> tuple[Optional[str], Optional[str]]:+ """``--workspace`` -> ``(kind, path|None)``: ``scratch``, ``worktree``, ``worktree:<p>``, ``dir:<p>``.+ Omitted -> ``(None, None)`` so ``create_task`` can tell "default" from an explicit scratch."""if not value:- return ("scratch", None)+ return (None, None)v = value.strip()if v in {"scratch", "worktree"}:return (v, None)diff --git a/hermes_cli/kanban_db.py b/hermes_cli/kanban_db.pyindex 96a13d6ea3f..ec7f16f05ef 100644--- a/hermes_cli/kanban_db.py+++ b/hermes_cli/kanban_db.py@@ -1221,7 +1221,7 @@ def _normalize_task_skills(skills: Optional[Iterable[str]]) -> Optional[list[strdef create_task(conn: sqlite3.Connection, *, title: str, body: Optional[str] = None,assignee: Optional[str] = None, created_by: Optional[str] = None,- workspace_kind: str = "scratch", workspace_path: Optional[str] = None,+ workspace_kind: Optional[str] = None, workspace_path: Optional[str] = None,branch_name: Optional[str] = None, tenant: Optional[str] = None, priority: int = 0,parents: Iterable[str] = (), triage: bool = False, idempotency_key: Optional[str] = None,max_runtime_seconds: Optional[int] = None, skills: Optional[Iterable[str]] = None,@@ -1245,6 +1245,8 @@ def create_task(dependency edges; an explicit ``session_id`` still wins.``project_source_task_id``: cross-profile fallback when ``project_id`` is notin the active profile's projects.db — see ``_resolve_project_link``.+ ``workspace_kind=None`` (omitted) inherits a project-scoped board's project;+ an explicit ``"scratch"`` or ``project_id=""`` is a request for no project."""from hermes_cli.kanban_db_graph import initial_task_state, inherit_creator_originfrom hermes_cli.kanban_pr_acceptance import validate_contract@@ -1257,6 +1259,17 @@ def create_task(raise ValueError("title is required")if initial_status not in VALID_INITIAL_STATUSES:raise ValueError(f"initial_status must be one of {sorted(VALID_INITIAL_STATUSES)}")+ # A project-scoped board anchors every new task to its project's repo+ # (deterministic worktree + branch) without each surface repeating it.+ # An explicit ``scratch`` (or ``project_id=""``) is a request for no project:+ # it must not be upgraded to a worktree in the board's repo (#106342).+ if project_id is None and workspace_kind != "scratch":+ try:+ project_id = (_board_meta_for(board).get("project_id") or "").strip() or None+ except Exception:+ pass+ if workspace_kind is None:+ workspace_kind = "scratch"if workspace_kind not in VALID_WORKSPACE_KINDS:raise ValueError(f"workspace_kind must be one of {sorted(VALID_WORKSPACE_KINDS)}, "@@ -1267,14 +1280,6 @@ def create_task(if branch_name and workspace_kind != "worktree":raise ValueError("branch_name is only valid for worktree workspaces")- # A project-scoped board anchors every new task to its project's repo- # (deterministic worktree + branch) without each surface repeating it.- if project_id is None:- try:- project_id = (_board_meta_for(board).get("project_id") or "").strip() or None- except Exception:- pass-project_id, project_obj, project_repo, workspace_kind = _resolve_project_link(conn, project_id, project_source_task_id, workspace_kind, workspace_path)diff --git a/hermes_cli/kanban_parser.py b/hermes_cli/kanban_parser.pyindex 85977d02516..ea7188dbaae 100644--- a/hermes_cli/kanban_parser.py+++ b/hermes_cli/kanban_parser.py@@ -150,8 +150,9 @@ _SPECS = [_arg("--body", help="Optional opening post"),_arg("--assignee", help="Profile name to assign"),_arg("--parent", action="append", default=[], help="Parent task id (repeatable)"),- _arg("--workspace", default="scratch",- help="scratch | worktree | worktree:<path> | dir:<path> (default: scratch)"),+ _arg("--workspace",+ help="scratch | worktree | worktree:<path> | dir:<path> (default: scratch; "+ "an explicit 'scratch' also opts out of a project-scoped board's project)"),_arg("--branch", help="Branch name for worktree tasks, e.g. wt/t6-wire"),_arg("--project",help="Link to a project (id or slug). Anchors the task's "diff --git a/hermes_cli/kanban_swarm.py b/hermes_cli/kanban_swarm.pyindex e450f6d43e1..1a807f17c84 100644--- a/hermes_cli/kanban_swarm.py+++ b/hermes_cli/kanban_swarm.py@@ -115,7 +115,7 @@ def create_swarm(synthesizer_title: str = "Synthesize swarm outputs",tenant: Optional[str] = None,created_by: str = "swarm-orchestrator",- workspace_kind: str = "scratch",+ workspace_kind: Optional[str] = None,workspace_path: Optional[str] = None,priority: int = 0,idempotency_key: Optional[str] = None,@@ -166,7 +166,7 @@ def _create_swarm_uncommitted(conn: sqlite3.Connection, *, goal: str, workers: Iterable[SwarmWorkerSpec],verifier_assignee: str, synthesizer_assignee: str, root_title: Optional[str],verifier_title: str, synthesizer_title: str, tenant: Optional[str], created_by: str,- workspace_kind: str, workspace_path: Optional[str], priority: int, idempotency_key: Optional[str],+ workspace_kind: Optional[str], workspace_path: Optional[str], priority: int, idempotency_key: Optional[str],) -> SwarmCreated:"""Create the swarm graph inside the caller's transaction: planning root(``blocked`` until the caller activates it), parallel workers, a verifierdiff --git a/plugins/kanban/dashboard/plugin_api.py b/plugins/kanban/dashboard/plugin_api.pyindex e2dfe82abcc..b15ed8af72e 100644--- a/plugins/kanban/dashboard/plugin_api.py+++ b/plugins/kanban/dashboard/plugin_api.py@@ -376,7 +376,7 @@ class CreateTaskBody(BaseModel):assignee: Optional[str] = Nonetenant: Optional[str] = Nonepriority: int = 0- workspace_kind: str = "scratch"+ workspace_kind: Optional[str] = None # None = scratch, or the board project's worktree when scopedworkspace_path: Optional[str] = Noneparents: list[str] = Field(default_factory=list)triage: bool = Falsediff --git a/tests/hermes_cli/test_kanban_board_project.py b/tests/hermes_cli/test_kanban_board_project.pyindex 2830c9238f0..c08bcde5a8a 100644--- a/tests/hermes_cli/test_kanban_board_project.py+++ b/tests/hermes_cli/test_kanban_board_project.py@@ -86,3 +86,24 @@ def test_create_task_explicit_project_beats_board(fresh_home, tmp_path):assert kb.get_task(conn, tid).project_id == task_projfinally:conn.close()+++def test_create_task_explicit_scratch_beats_board(fresh_home, tmp_path):+ """#106342: every surface (CLI --workspace scratch, dashboard workspace_kind,+ tool) funnels here; an explicit scratch on a project-scoped board must stay+ scratch, while an omitted kind still inherits the project worktree."""+ repo = tmp_path / "repo"+ repo.mkdir()+ with pdb.connect_closing() as pconn:+ proj_id = pdb.create_project(pconn, name="Widget", primary_path=str(repo))++ kb.create_board("scoped3", name="Scoped3", project_id=proj_id)+ conn = kbc.connect(board="scoped3")+ try:+ scratch = kb.get_task(conn, kb.create_task(+ conn, title="explicit scratch", board="scoped3", workspace_kind="scratch"))+ assert (scratch.workspace_kind, scratch.project_id) == ("scratch", None)+ default = kb.get_task(conn, kb.create_task(conn, title="default", board="scoped3"))+ assert (default.workspace_kind, default.project_id) == ("worktree", proj_id)+ finally:+ conn.close()diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.pyindex a970314efe8..1542e06957e 100644--- a/tests/tools/test_kanban_tools.py+++ b/tests/tools/test_kanban_tools.py@@ -469,15 +469,15 @@ def test_create_happy_path(worker_env):conn.close()[email protected]("explicit", [- {"workspace_kind": "scratch"},- {"project": ""},-])[email protected]("explicit", [{"workspace_kind": "scratch"}, {"project": ""}])[email protected]("target_scoped", [False, True])def test_create_explicit_scratch_ignores_ambient_board_project(- worker_env, tmp_path, explicit,+ worker_env, tmp_path, explicit, target_scoped,):+ """#106342: an explicit scratch / empty project wins over the project the+ session's current board (and, when scoped, the target board itself) carries.+ Omitting both still inherits the target board's project."""from hermes_cli import kanban_db as kb- from hermes_cli import kanban_db_connect as kbcfrom hermes_cli import projects_db as pdbfrom tools import kanban_tools as kt@@ -485,25 +485,17 @@ def test_create_explicit_scratch_ignores_ambient_board_project(repo.mkdir()with pdb.connect_closing() as pconn:project_id = pdb.create_project(pconn, name="Ambient", primary_path=str(repo))-kb.write_board_metadata("default", project_id=project_id)- kb.create_board("target", name="Target", project_id="")-- result = json.loads(kt._handle_create({- "board": "target",- "title": "stay scratch",- "assignee": "peer",- **explicit,- }))+ kb.create_board("target", name="Target", project_id=project_id if target_scoped else "")- assert result["ok"] is True- assert result["project_id"] is None- assert result["workspace_kind"] == "scratch"+ def create(**extra):+ result = json.loads(kt._handle_create(+ {"board": "target", "title": "card", "assignee": "peer", **extra}))+ assert result["ok"] is True+ return result["workspace_kind"], result["project_id"]- with kbc.connect_closing(board="target") as conn:- control = kb.create_task(- conn, title="direct scratch", board="target", workspace_kind="scratch")- assert kb.get_task(conn, control).project_id is None+ assert create(**explicit) == ("scratch", None)+ assert create() == (("worktree", project_id) if target_scoped else ("scratch", None))def test_link_happy_path(worker_env):diff --git a/tools/kanban_tools.py b/tools/kanban_tools.pyindex 893d64218c3..57128b41915 100644--- a/tools/kanban_tools.py+++ b/tools/kanban_tools.py@@ -823,15 +823,8 @@ def _handle_create(args: dict, **kw) -> str:# mutate review evidence or race its checkout). Project identity is the one safe thing# to inherit implicitly (the DB turns it into a fresh per-task worktree).workspace_kind, workspace_path = args.get("workspace_kind"), args.get("workspace_path")- # See #67567.- project_arg_present = "project" in args or "project_id" in args+ # See #67567. ``project=""`` is an explicit "no project" (no ``or`` collapse, #106342).project_id = args["project"] if "project" in args else args.get("project_id")- # An explicit scratch request suppresses board project inheritance, while an- # explicit project may still intentionally turn scratch into a project worktree.- if not project_arg_present and "workspace_kind" in args and workspace_kind == "scratch":- project_id = ""- workspace_args_omitted = not any(- key in args for key in ("project", "project_id", "workspace_kind", "workspace_path"))project_source_task_id = Nonetriage, skills, goal_mode = (_parse_bool_arg(args, "triage"), _coerce_str_list(args.get("skills"), "skills", "skill names"),@@ -847,16 +840,16 @@ def _handle_create(args: dict, **kw) -> str:# The worker/API runtime may be transient; the owning task's origin is durable.session_id = (args.get("session_id") or (self_task.session_id if self_task else None)or _current_origin_session_id() or os.environ.get("HERMES_SESSION_ID"))- if workspace_args_omitted:+ if project_id is None and workspace_kind is None and workspace_path is None:if self_task is not None and self_task.project_id:project_id, project_source_task_id = self_task.project_id, self_task.idnew_tid = kb.create_task(conn, title=str(title).strip(), body=args.get("body"), assignee=str(assignee),parents=tuple(parents), tenant=args.get("tenant") or os.environ.get("HERMES_TENANT"),priority=_opt_int(args.get("priority"), 0),- workspace_kind=str(workspace_kind if workspace_kind is not None else "scratch"),- workspace_path=workspace_path, project_id=project_id,- # Keep metadata inheritance scoped to the same board DB opened above.+ workspace_kind=workspace_kind, workspace_path=workspace_path, project_id=project_id,+ # Board-project inheritance must read the board this call opened, not the+ # session's current board.board=args.get("board"),project_source_task_id=project_source_task_id, triage=triage,creator_task_id=self_tid,