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

Pass the caller's board into create_task and treat explicit workspace_kind=scratch or empty project as no-project so ambient board project_id cannot override MCP args.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
KoNit-K
2026-09-09 15:37:47 +08:00
committed by Teknium
parent 544169a41a
commit dc5c87c6c1
2 changed files with 48 additions and 2 deletions
+37
View File
@@ -469,6 +469,43 @@ def test_create_happy_path(worker_env):
conn.close()
@pytest.mark.parametrize("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
+11 -2
View File
@@ -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"),