Skip to content

The agent that grows with you

fix(kanban): drop the partial kernel-event model from the workflow groundwork

Ben Barclay6fe5dfb1cf2e
diff --git a/hermes_cli/kanban_workflow.py b/hermes_cli/kanban_workflow.py
index 71cc87ea8b6..208cb289436 100644
--- a/hermes_cli/kanban_workflow.py
+++ b/hermes_cli/kanban_workflow.py
@@ -1,22 +1,24 @@
"""Kanban board workflow: the one definition of columns, traits and transitions.
Groundwork for user-defined columns and workflow per board (issue #54818). Target model —
-``tasks.status`` holds a board-defined column key; kernel behavior attaches to
-column *traits*, and kernel events resolve to a column through per-column *edges*
-with a board-wide default, so an automatic transition never has to guess.
-
-Phase 0 (this module): ``DEFAULT_WORKFLOW`` writes today's hardcoded behavior down
-as data, and the scattered status copies (``VALID_STATUSES``, ``BOARD_COLUMNS``, the
-agent-tool enum, CLI icons) derive from it. The kernel does not consult traits or
-edges yet; ``tests/hermes_cli/test_kanban_workflow.py`` pins them to the kernel's real
-behavior so the later phases that switch the kernel over cannot drift silently.
+``tasks.status`` holds a board-defined column key and kernel behavior attaches to
+column *traits*, not to status names.
+
+Phase 0 (this module): ``DEFAULT_WORKFLOW`` writes today's columns and manual move
+matrix down as data, and the scattered status copies (``VALID_STATUSES``,
+``BOARD_COLUMNS``, the agent-tool enum, CLI icons) derive from it. The kernel does not
+consult traits yet. Automatic (kernel-driven) transitions are deliberately NOT modelled
+here: the kernel has ~20 conditional status writes (block routing, crash/reclaim return,
+parent reopen, import, ...) and that model is designed with the kernel switch, so this
+module never publishes a partial contract. ``tests/plugins/test_kanban_workflow_matrix.py``
+pins ``manual`` to the live dashboard API in both directions.
Pure data + stdlib only: ``kanban_db`` imports this module, never the reverse.
"""
from __future__ import annotations
-from dataclasses import dataclass, field
+from dataclasses import dataclass
from types import MappingProxyType
from typing import Iterator, Mapping, Optional
@@ -38,18 +40,6 @@ TRAITS = frozenset({
DECOMPOSE, WAIT_PARENTS, HOLD_TIME, DISPATCH_IMPLEMENT, CLAIMED, HOLD_HUMAN, DISPATCH_REVIEW, TERMINAL,
})
-# --- Kernel events that move a card without a human choosing the target -----------------
-EV_CLAIM = "claim" # dispatcher claims the card
-EV_COMPLETE = "complete" # worker/human completes
-EV_BLOCK = "block" # worker/human blocks
-EV_SCHEDULE = "schedule" # parked on a time gate
-EV_REVIEW = "review" # implementer hands off for review
-EV_CHANGES = "changes" # reviewer requests changes
-EV_PARENTS_DONE = "parents_done" # last open parent is satisfied
-
-EVENTS = frozenset({EV_CLAIM, EV_COMPLETE, EV_BLOCK, EV_SCHEDULE, EV_REVIEW, EV_CHANGES, EV_PARENTS_DONE})
-
-
@dataclass(frozen=True)
class Column:
"""One board column. ``key`` is stable (stored in ``tasks.status``); ``label`` is display-only."""
@@ -61,16 +51,13 @@ class Column:
# Offered as a drag/menu target in board UIs. False for columns a card normally
# reaches only through a verb with extra input (reviewer, wake time) or the kernel.
drag_target: bool = True
- # Per-column event edges; an event missing here falls back to ``Workflow.defaults``.
- on: Mapping[str, str] = field(default_factory=lambda: MappingProxyType({}))
@dataclass(frozen=True)
class Workflow:
- """Columns (board order), default event edges, and the manual move allow-list."""
+ """Columns (board order) and the manual move allow-list."""
columns: tuple
- defaults: Mapping[str, str]
# Manual moves (drag, PATCH status) a human may request: ``src -> {dst}``. Archive is
# always allowed and not listed. Allowed != guaranteed: verbs still apply their own
# gates (parents open, completion evidence).
@@ -92,19 +79,18 @@ class Workflow:
raise ValueError(f"unknown kanban workflow trait {trait!r}")
return tuple(c.key for c in self.columns if trait in c.traits)
- def on_event(self, key: str, event: str) -> str:
- """Column a card in ``key`` moves to when the kernel emits ``event``."""
- if event not in EVENTS:
- raise ValueError(f"unknown kanban workflow event {event!r}")
+ def _require(self, key: str) -> Column:
col = self.column(key)
- if col is not None and event in col.on:
- return col.on[event]
- return self.defaults[event]
+ if col is None:
+ raise ValueError(f"unknown kanban workflow column {key!r}")
+ return col
def can_move(self, src: str, dst: str) -> bool:
"""True when a human may request ``src -> dst`` (archive always allowed)."""
+ self._require(src)
if dst == ARCHIVED:
return True
+ self._require(dst)
return dst in self.manual.get(src, frozenset())
def to_dict(self) -> dict:
@@ -112,16 +98,15 @@ class Workflow:
return {
"columns": [
{"key": c.key, "label": c.label, "icon": c.icon, "traits": sorted(c.traits),
- "drag_target": c.drag_target, "on": dict(c.on)}
+ "drag_target": c.drag_target}
for c in self.columns
],
- "defaults": dict(self.defaults),
"manual": {src: sorted(dsts) for src, dsts in self.manual.items()},
"archived": ARCHIVED,
}
def validate(self) -> None:
- """Raise ``ValueError`` on an inconsistent workflow (unknown keys, dead-end events)."""
+ """Raise ``ValueError`` on an inconsistent workflow (duplicate/unknown keys, no terminal)."""
keys = self.keys()
if len(set(keys)) != len(keys):
raise ValueError(f"duplicate column keys: {keys}")
@@ -132,15 +117,6 @@ class Workflow:
unknown = c.traits - TRAITS
if unknown:
raise ValueError(f"column {c.key!r}: unknown traits {sorted(unknown)}")
- for ev, dst in c.on.items():
- if ev not in EVENTS or dst not in known:
- raise ValueError(f"column {c.key!r}: bad edge {ev!r} -> {dst!r}")
- missing = EVENTS - set(self.defaults)
- if missing:
- raise ValueError(f"no default column for events {sorted(missing)}")
- for ev, dst in self.defaults.items():
- if dst not in known:
- raise ValueError(f"default edge {ev!r} -> unknown column {dst!r}")
for src, dsts in self.manual.items():
if src not in known or not set(dsts) <= known:
raise ValueError(f"manual moves from {src!r} reference unknown columns")
@@ -159,7 +135,7 @@ def _frozen_manual(table: Mapping[str, tuple]) -> Mapping[str, frozenset]:
# Today's board, written down. Column order = dashboard order. ``drag_target=False``
# mirrors the desktop's LOCKED_COLUMNS (review needs a reviewer, scheduled a wake time,
# running is kernel-only). The manual table is the measured PATCH /tasks/{id} matrix on
-# a parentless task; ``test_kanban_workflow.py`` re-measures it against the live code.
+# a parentless task; ``test_kanban_workflow_matrix.py`` re-measures it against the live API.
DEFAULT_WORKFLOW = Workflow(
columns=(
_col("triage", "Triage", "◇", DECOMPOSE),
@@ -171,15 +147,6 @@ DEFAULT_WORKFLOW = Workflow(
_col("review", "Review", "◎", DISPATCH_REVIEW, drag_target=False),
_col("done", "Done", "✓", TERMINAL),
),
- defaults=MappingProxyType({
- EV_CLAIM: "running",
- EV_COMPLETE: "done",
- EV_BLOCK: "blocked",
- EV_SCHEDULE: "scheduled",
- EV_REVIEW: "review",
- EV_CHANGES: "ready",
- EV_PARENTS_DONE: "ready",
- }),
manual=_frozen_manual({
"triage": ("todo", "ready"),
"todo": ("triage", "scheduled", "ready"),
diff --git a/plugins/kanban/dashboard/plugin_api.py b/plugins/kanban/dashboard/plugin_api.py
index 6f2ad504b85..76b21932f6f 100644
--- a/plugins/kanban/dashboard/plugin_api.py
+++ b/plugins/kanban/dashboard/plugin_api.py
@@ -1618,8 +1618,8 @@ _PROFILE_SETTINGS = ("orchestrator_profile", "default_assignee")
@router.get("/workflow")
def get_workflow():
- """Board columns (order, label, icon, traits, drag target), default event edges and
- the manual move allow-list. Every board uses the default workflow today; per-board
+ """Board columns (order, label, icon, traits, drag target) and the manual move
+ allow-list. Every board uses the default workflow today; per-board
workflows (``board.json``) arrive in a later phase behind this same shape."""
return kanban_workflow.DEFAULT_WORKFLOW.to_dict()
diff --git a/tests/hermes_cli/test_kanban_workflow.py b/tests/hermes_cli/test_kanban_workflow.py
index 6c9ee8b1166..6c87eb79c59 100644
--- a/tests/hermes_cli/test_kanban_workflow.py
+++ b/tests/hermes_cli/test_kanban_workflow.py
@@ -1,21 +1,18 @@
-"""Kanban workflow definition: shape, derived copies, and kernel-event edges.
+"""Kanban workflow definition: shape, validation, and the copies that derive from it.
``DEFAULT_WORKFLOW`` is data the kernel does not consult yet (Phase 0 of #54818).
-These tests pin it to what the kernel actually does, so a later phase that switches
-the kernel over to reading the workflow cannot change behavior unnoticed, and a
-kernel change that forgets the workflow fails here.
+The manual move matrix is pinned to the live dashboard API in
+``tests/plugins/test_kanban_workflow_matrix.py``.
"""
from __future__ import annotations
from dataclasses import replace
-from pathlib import Path
from types import MappingProxyType
import pytest
from hermes_cli import kanban_db as kb
-from hermes_cli import kanban_db_connect as kbc
from hermes_cli import kanban_output
from hermes_cli import kanban_workflow as kw
from tools import kanban_tools_schemas
@@ -24,9 +21,6 @@ from tools import kanban_tools_schemas
W = kw.DEFAULT_WORKFLOW
-# --- shape + single source of truth ------------------------------------------------------
-
-
def test_default_workflow_is_valid_and_excludes_archived():
W.validate()
assert kw.ARCHIVED not in W.keys()
@@ -51,40 +45,33 @@ def _all_tool_schemas():
yield value
-def test_every_trait_and_event_is_used_by_the_default():
- # A trait or event no default column uses has no behavior to pin — it would be dead data.
+def test_every_trait_is_used_by_the_default():
+ # A trait no default column carries describes no current behavior — dead data.
for trait in kw.TRAITS:
assert W.keys_with(trait), trait
- assert set(W.defaults) == kw.EVENTS
with pytest.raises(ValueError):
W.keys_with("nope")
-def test_on_event_prefers_column_edge_over_default():
- custom = replace(
- W,
- columns=tuple(replace(c, on=MappingProxyType({kw.EV_COMPLETE: "review"})) if c.key == "ready" else c
- for c in W.columns),
- )
- custom.validate()
- assert custom.on_event("ready", kw.EV_COMPLETE) == "review"
- assert custom.on_event("todo", kw.EV_COMPLETE) == "done"
- with pytest.raises(ValueError):
- custom.on_event("ready", "nope")
-
-
def test_archive_is_always_a_manual_move():
assert all(W.can_move(k, kw.ARCHIVED) for k in W.keys())
assert not any(W.can_move(k, "running") for k in W.keys())
+ lambda: W.can_move("bogus", kw.ARCHIVED),
+ lambda: W.can_move("ready", "bogus"),
+])
+def test_unknown_column_keys_are_rejected_not_defaulted(call):
+ with pytest.raises(ValueError, match="unknown kanban workflow column"):
+ call()
+
+
@pytest.mark.parametrize("mutate, message", [
(lambda w: replace(w, columns=w.columns + (w.columns[0],)), "duplicate"),
(lambda w: replace(w, columns=w.columns + (kw.Column(key=kw.ARCHIVED, label="A"),)), "reserved"),
- (lambda w: replace(w, defaults=MappingProxyType({k: v for k, v in w.defaults.items()
- if k != kw.EV_BLOCK})), "no default"),
- (lambda w: replace(w, defaults=MappingProxyType({**w.defaults, kw.EV_BLOCK: "gone"})), "unknown column"),
(lambda w: replace(w, manual=MappingProxyType({"ready": frozenset({"gone"})})), "manual"),
+ (lambda w: replace(w, manual=MappingProxyType({"gone": frozenset({"ready"})})), "manual"),
(lambda w: replace(w, columns=tuple(replace(c, traits=frozenset()) if c.key == "done" else c
for c in w.columns)), "terminal"),
(lambda w: replace(w, columns=tuple(replace(c, traits=frozenset({"bogus"})) if c.key == "done" else c
@@ -93,59 +80,3 @@ def test_archive_is_always_a_manual_move():
def test_validate_rejects_inconsistent_workflows(mutate, message):
with pytest.raises(ValueError, match=message):
mutate(W).validate()
-
-
-# --- kernel events land where the workflow says --------------------------------------------
-
-
-def conn(tmp_path: Path):
- db = kbc.connect(tmp_path / "kanban.db")
- try:
- yield db
- finally:
- db.close()
-
-
-def _status(conn, task_id: str) -> str:
- return kb.get_task(conn, task_id).status
-
-
-def test_edge_claim(conn):
- tid = kb.create_task(conn, title="t", assignee="builder")
- assert kb.claim_task(conn, tid) is not None
- assert _status(conn, tid) == W.on_event("ready", kw.EV_CLAIM)
-
-
-def test_edge_complete_block_schedule(conn):
- for event, act in (
- (kw.EV_COMPLETE, lambda tid: kb.complete_task(conn, tid, summary="s")),
- (kw.EV_BLOCK, lambda tid: kb.block_task(conn, tid, reason="r")),
- (kw.EV_SCHEDULE, lambda tid: kb.schedule_task(conn, tid, reason="r")),
- ):
- tid = kb.create_task(conn, title=event, assignee="builder")
- assert kb.claim_task(conn, tid) is not None
- assert act(tid)
- assert _status(conn, tid) == W.on_event("running", event), event
-
-
-def test_edge_review_and_changes(conn):
- tid = kb.create_task(conn, title="t", assignee="builder")
- assert kb.claim_task(conn, tid) is not None
- assert kb.request_review(conn, tid, summary="s", reviewer="reviewer")
- assert _status(conn, tid) == W.on_event("running", kw.EV_REVIEW)
- review = kb.claim_review_task(conn, tid, claimer="reviewer:1")
- assert review is not None
- ok, _ = kb.request_changes(conn, tid, reason="fix it", expected_run_id=review.current_run_id)
- assert ok
- assert _status(conn, tid) == W.on_event("running", kw.EV_CHANGES)
-
-
-def test_edge_parents_done(conn):
- parent = kb.create_task(conn, title="p", assignee="builder")
- child = kb.create_task(conn, title="c", assignee="builder", parents=[parent])
- waiting = _status(conn, child)
- assert waiting in W.keys_with(kw.WAIT_PARENTS)
- assert kb.complete_task(conn, parent, summary="s")
- kb.recompute_ready(conn)
- assert _status(conn, child) == W.on_event(waiting, kw.EV_PARENTS_DONE)
diff --git a/tests/plugins/test_kanban_workflow_matrix.py b/tests/plugins/test_kanban_workflow_matrix.py
index e42a429b645..8a4248d4c20 100644
--- a/tests/plugins/test_kanban_workflow_matrix.py
+++ b/tests/plugins/test_kanban_workflow_matrix.py
@@ -78,6 +78,11 @@ def test_manual_moves_match_server(client, src):
r = client.patch(f"/k/tasks/{tid}", json=body)
with kbc.connect_closing() as conn:
landed = kb.get_task(conn, tid).status
+ # A refusal must be a domain rejection (400 bad verb / 409 refused transition);
+ # anything else (5xx, 422) is a bug, never an acceptable "not allowed".
+ if r.status_code not in (200, 400, 409):
+ mismatches.append(f"{src}->{dst}: unexpected HTTP {r.status_code}: {r.text[:200]}")
+ continue
accepted = r.status_code == 200
if accepted != W.can_move(src, dst):
mismatches.append(f"{src}->{dst}: server {r.status_code}, workflow can_move={W.can_move(src, dst)}")