Skip to content

The agent that grows with you

fix(kanban): honor explicit scratch/project on MCP kanban_create

KoNit-Kdc5c87c6c11f
diff --git a/tests/tools/test_kanban_tools.py b/tests/tools/test_kanban_tools.py
index 7454d95b3f4..a970314efe8 100644
--- a/tests/tools/test_kanban_tools.py
+++ b/tests/tools/test_kanban_tools.py
@@ -469,6 +469,43 @@ def test_create_happy_path(worker_env):
conn.close()
[email protected]("explicit", [
+ {"workspace_kind": "scratch"},
+ {"project": ""},
+])
+def test_create_explicit_scratch_ignores_ambient_board_project(
+ worker_env, tmp_path, explicit,
+):
+ from hermes_cli import kanban_db as kb
+ from hermes_cli import kanban_db_connect as kbc
+ from hermes_cli import projects_db as pdb
+ from tools import kanban_tools as kt
+
+ repo = tmp_path / "repo"
+ 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,
+ }))
+
+ assert result["ok"] is True
+ assert result["project_id"] is None
+ assert result["workspace_kind"] == "scratch"
+
+ 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
+
+
def test_link_happy_path(worker_env):
from hermes_cli import kanban_db as kb
from hermes_cli import kanban_db_connect as kbc
diff --git a/tools/kanban_tools.py b/tools/kanban_tools.py
index f062c8a5733..893d64218c3 100644
--- a/tools/kanban_tools.py
+++ b/tools/kanban_tools.py
@@ -824,7 +824,14 @@ def _handle_create(args: dict, **kw) -> str:
# 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_id = args.get("project") or args.get("project_id")
+ project_arg_present = "project" in args or "project_id" in args
+ 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 = None
triage, skills, goal_mode = (
_parse_bool_arg(args, "triage"), _coerce_str_list(args.get("skills"), "skills", "skill names"),
@@ -840,7 +847,7 @@ 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 project_id is None and workspace_kind is None and workspace_path is None:
+ if workspace_args_omitted:
if self_task is not None and self_task.project_id:
project_id, project_source_task_id = self_task.project_id, self_task.id
new_tid = kb.create_task(
@@ -849,6 +856,8 @@ def _handle_create(args: dict, **kw) -> str:
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.
+ board=args.get("board"),
project_source_task_id=project_source_task_id, triage=triage,
creator_task_id=self_tid,
idempotency_key=args.get("idempotency_key"),