fix(kanban): update stale read-only docstring + board_exists early-out in board counts

The bridge module docstring still described the API as 'deliberately
read-only' but it now exposes full CRUD (tasks, boards, comments,
links, SSE). Updated to list the supported operations.

For _board_counts_for_slug (the hot path for the board-switcher badge),
added a board_exists() early-out that mirrors the agent's own helper
in plugin_api.py (path.exists() before connect()). This avoids a
redundant init_db()+connect() schema pass per board per list refresh.
connect() already handles auto-init for fresh databases via its
needs_init check, so the extra init_db was unnecessary overhead on
the hot path that scales linearly with board count.

Tests:
- test_board_counts_returns_empty_for_nonexistent_board: verifies the
  early-out (no connect() call, returns {})
- test_board_counts_returns_real_counts_for_populated_board: verifies
  actual per-status counts are returned for existing boards
This commit is contained in:
fxd-jason
2026-05-07 11:53:12 +08:00
committed by test
parent 697a7a10d1
commit a80b7695d8
2 changed files with 78 additions and 8 deletions
+15 -8
View File
@@ -1,9 +1,14 @@
"""Read-only Hermes Kanban bridge for the WebUI.
"""Hermes Kanban bridge for the WebUI.
This module exposes a small WebUI-native API under ``/api/kanban/*`` while
keeping Hermes Agent's ``hermes_cli.kanban_db`` as the only source of truth.
The first integration is deliberately read-only; write/move semantics can be
added in later focused PRs.
This module exposes a full CRUD API under ``/api/kanban/*`` while keeping
Hermes Agent's ``hermes_cli.kanban_db`` as the only source of truth.
Supported operations:
- Task CRUD (create, read, patch, bulk update, archive)
- Multi-board management (list, create, archive, switch)
- Task dependency links (create, delete)
- SSE live event stream for real-time updates
- Comments and worker dispatch integration
"""
from __future__ import annotations
@@ -702,10 +707,12 @@ def _board_meta_dict(meta):
def _board_counts_for_slug(slug):
"""Per-status task counts for a board, used to populate the board
switcher with a live "12 tasks" badge. Mirrors the agent dashboard's
``_board_counts`` helper. Best-effort — empty dict if the board's
sqlite is missing (which can happen on a freshly-created board before
the first task is added)."""
``_board_counts`` helper. Returns an empty dict for boards whose
sqlite file has not been materialized yet (freshly-created boards
with no tasks)."""
kb = _kb()
if not kb.board_exists(slug):
return {}
try:
conn = kb.connect(board=slug)
except Exception: