The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): preserve Discord thread route anchors
KoNit-K38bda39562e6
diff --git a/hermes_cli/kanban.py b/hermes_cli/kanban.pyindex 689dbfca61d..22cd5a51503 100644--- a/hermes_cli/kanban.py+++ b/hermes_cli/kanban.py@@ -1074,6 +1074,14 @@ def _cmd_stats(args: argparse.Namespace) -> int:def _cmd_notify_subscribe(args: argparse.Namespace) -> int:+ delivery_metadata = {+ key: value+ for key, value in (+ ("parent_chat_id", getattr(args, "parent_chat_id", None)),+ ("guild_id", getattr(args, "guild_id", None)),+ )+ if value+ }with kbc.connect_closing() as conn:if kb.get_task(conn, args.task_id) is None:return _err(f"no such task: {args.task_id}")@@ -1083,6 +1091,7 @@ def _cmd_notify_subscribe(args: argparse.Namespace) -> int:user_id_alt=getattr(args, "user_id_alt", None),notifier_profile=args.notifier_profile or _profile_author(),delivery_mode=getattr(args, "delivery_mode", None),+ delivery_metadata=delivery_metadata or None,)print(f"Subscribed {args.platform}:{args.chat_id}" + (f":{args.thread_id}" if args.thread_id else "")+ f" to {args.task_id}")diff --git a/hermes_cli/kanban_db_notify.py b/hermes_cli/kanban_db_notify.pyindex c612631cc08..4a36fe8f75b 100644--- a/hermes_cli/kanban_db_notify.py+++ b/hermes_cli/kanban_db_notify.py@@ -86,7 +86,9 @@ def add_notify_sub(omitting it would key the wake into a different session. ``None`` keeps anexisting row's value. ``delivery_mode``: ``None`` leaves an existing rowuntouched, an explicit valid value is last-write-wins, unknown falls back- to ``"notify"``. New subs start caught up (``last_event_id`` =+ to ``"notify"``. ``delivery_metadata`` merges supplied routing anchors+ into an existing row so re-subscribing never discards them. New subs start+ caught up (``last_event_id`` =``MAX(task_events.id)``) so the notifier never replays history at boot."""valid_mode = delivery_mode if delivery_mode in _NOTIFY_DELIVERY_MODES else None@@ -94,9 +96,17 @@ def add_notify_sub(# the delivery. A plain 'notify' default would leave those subs with no# delivery mechanism at all. Explicit modes still win.insert_mode = valid_mode or ("notify+wake" if platform == "api_server" else "notify")- metadata_json = _encode_notify_delivery_metadata(delivery_metadata)key = _sub_key(task_id, platform, chat_id, thread_id)with _kb.write_txn(conn):+ existing = conn.execute(+ "SELECT delivery_metadata FROM kanban_notify_subs " + _SUB_KEY_WHERE,+ key,+ ).fetchone()+ existing_metadata = _decode_notify_delivery_metadata(existing["delivery_metadata"]) if existing else {}+ merged_metadata = dict(existing_metadata)+ if delivery_metadata:+ merged_metadata.update(delivery_metadata)+ metadata_json = _encode_notify_delivery_metadata(merged_metadata) if merged_metadata else Noneconn.execute("""INSERT OR IGNORE INTO kanban_notify_subs@@ -111,7 +121,8 @@ def add_notify_sub(insert_mode, metadata_json, int(time.time()), task_id,),)- # chat_type / delivery_mode / delivery_metadata are last-write-wins;+ # chat_type / delivery_mode are last-write-wins; delivery metadata+ # preserves existing routing fields while supplied fields overwrite them.# user_id_alt and notifier_profile only self-heal legacy rows lacking one.for column, value, fill_only in (("chat_type", chat_type, False),diff --git a/hermes_cli/kanban_parser.py b/hermes_cli/kanban_parser.pyindex d6e598ea1bd..e3cb0371d1c 100644--- a/hermes_cli/kanban_parser.py+++ b/hermes_cli/kanban_parser.py@@ -373,6 +373,10 @@ _SPECS = [help="Originating source chat_type, recorded so the active-wake delivery ""modes resolve the operator's real session. Omit to leave an ""existing sub unchanged (new subs default to 'dm')."),+ _arg("--parent-chat-id",+ help="Parent channel ID for a thread or forum post, used for multiplex profile routing."),+ _arg("--guild-id",+ help="Discord guild ID, used for multiplex profile routing."),_arg("--notifier-profile",help="Profile gateway that owns/delivers this subscription (default: active profile)"),# choices: single source of truth shared with the DB/watcher enum.diff --git a/tests/hermes_cli/test_kanban_notify.py b/tests/hermes_cli/test_kanban_notify.pyindex a06b34a1f7f..6f4e2b656ed 100644--- a/tests/hermes_cli/test_kanban_notify.py+++ b/tests/hermes_cli/test_kanban_notify.py@@ -3,6 +3,7 @@ import pytestfrom pathlib import Pathfrom types import SimpleNamespace+from hermes_cli import kanban as kcfrom hermes_cli import kanban_db as kbfrom hermes_cli import kanban_db_connect as kbcfrom hermes_cli import kanban_db_notify as kbn@@ -85,6 +86,33 @@ def test_notify_sub_delivery_mode_persists_and_last_write_wins(kanban_home):conn.close()+def test_notify_subscribe_cli_records_discord_multiplex_anchors(kanban_home):+ """The CLI must persist thread route anchors without dropping existing metadata."""+ import argparse++ with kbc.connect() as conn:+ tid = kb.create_task(conn, title="thread route", assignee="worker")+ kbn.add_notify_sub(+ conn, task_id=tid, platform="discord", chat_id="thread",+ thread_id="thread", delivery_metadata={"chat_type": "thread", "existing": "keep"},+ )++ parser = argparse.ArgumentParser()+ kc.build_parser(parser.add_subparsers(dest="command"))+ args = parser.parse_args([+ "kanban", "notify-subscribe", tid, "--platform", "discord", "--chat-id", "thread",+ "--thread-id", "thread", "--chat-type", "thread", "--parent-chat-id", "parent",+ "--guild-id", "guild",+ ])+ assert kc.kanban_command(args) == 0++ with kbc.connect() as conn:+ sub = kbn.list_notify_subs(conn, tid)[0]+ assert sub["delivery_metadata"] == {+ "chat_type": "thread", "existing": "keep", "parent_chat_id": "parent", "guild_id": "guild",+ }++def test_child_task_inherits_parent_delivery_mode(kanban_home):"""Graph children inherit the parent's ACK edge AND its delivery_mode."""import hermes_cli.kanban_db as kb