The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(kanban): board export/import REST endpoints
Brooklyn Nicholson5e550838f703
diff --git a/plugins/kanban/dashboard/plugin_api.py b/plugins/kanban/dashboard/plugin_api.pyindex 83fe126eb33..9a76f1d8523 100644--- a/plugins/kanban/dashboard/plugin_api.py+++ b/plugins/kanban/dashboard/plugin_api.py@@ -2374,6 +2374,26 @@ class RenameBoardBody(BaseModel):project_id: Optional[str] = None+# Board transfer exchanges filesystem PATHS, not bytes — same contract as+# profile export/import, and for the same reason: the clients that drive it+# (desktop, dashboard) run the native save/open dialog on the machine that+# hosts the backend, so a path is all either side needs.++class ExportBoardBody(BaseModel):+ # Where to write the archive. Empty → a staging path under the kanban root.+ output: str = ""+ attachments: bool = True+ logs: bool = False+++class ImportBoardBody(BaseModel):+ # Path to a board .tar.gz on the backend's filesystem.+ archive: str+ # Override the slug from the archive. Collisions auto-suffix either way.+ slug: Optional[str] = None+ switch: bool = False++def _resolve_project(ref: Optional[str]) -> tuple[Optional[str], Optional[str], Optional[str]]:"""Resolve a project id/slug to ``(id, name, primary_path)``.@@ -2586,6 +2606,70 @@ def delete_board(slug: str, delete: bool = Query(False, description="Hard-deletereturn {"result": res, "current": kanban_db.get_current_board()}[email protected]("/boards/{slug}/export")+async def export_board_endpoint(slug: str, body: ExportBoardBody):+ """Write ``slug`` to a portable archive; return the path written."""+ from hermes_cli import kanban_transfer++ output = (body.output or "").strip()+ if not output:+ staging = kanban_db.kanban_home() / "kanban" / "board-exports"+ try:+ staging.mkdir(parents=True, exist_ok=True)+ except OSError as exc:+ raise HTTPException(+ status_code=500, detail=f"Could not create export directory: {exc}"+ )+ stamp = time.strftime("%Y%m%d-%H%M%S")+ output = str(staging / f"{slug}-{stamp}.tar.gz")++ loop = asyncio.get_running_loop()+ try:+ result = await loop.run_in_executor(+ None,+ lambda: kanban_transfer.export_board(+ slug, output,+ include_attachments=body.attachments,+ include_logs=body.logs,+ ),+ )+ except FileNotFoundError as exc:+ raise HTTPException(status_code=404, detail=str(exc))+ except ValueError as exc:+ raise HTTPException(status_code=400, detail=str(exc))+ except Exception as exc:+ log.exception("POST /boards/%s/export failed", slug)+ raise HTTPException(status_code=500, detail=str(exc))+ return result++[email protected]("/boards/import")+async def import_board_endpoint(body: ImportBoardBody):+ """Import a board archive as a NEW board; return the landed board."""+ from hermes_cli import kanban_transfer++ archive = (body.archive or "").strip()+ if not archive:+ raise HTTPException(status_code=400, detail="archive path is required")++ loop = asyncio.get_running_loop()+ try:+ result = await loop.run_in_executor(+ None,+ lambda: kanban_transfer.import_board(+ archive, (body.slug or "").strip() or None, activate=body.switch+ ),+ )+ except FileNotFoundError as exc:+ raise HTTPException(status_code=404, detail=str(exc))+ except ValueError as exc:+ raise HTTPException(status_code=400, detail=str(exc))+ except Exception as exc:+ log.exception("POST /boards/import failed")+ raise HTTPException(status_code=500, detail=str(exc))+ return {**result, "current": kanban_db.get_current_board()}++@router.post("/boards/{slug}/switch")def switch_board(slug: str):"""Persist ``slug`` as the active board for subsequent CLI / slash calls.diff --git a/tests/plugins/test_kanban_board_lifecycle_api.py b/tests/plugins/test_kanban_board_lifecycle_api.pynew file mode 100644index 00000000000..172e4849fb1--- /dev/null+++ b/tests/plugins/test_kanban_board_lifecycle_api.py@@ -0,0 +1,87 @@+"""Kanban dashboard plugin: board rename + delete over the REST surface.++The desktop board switcher drives both from its kebab menu and reads+``result.new_path`` back to tell the user where an archived board went, so+these assert the response shape as well as the on-disk outcome.+"""++from __future__ import annotations++import importlib.util+import sys+from pathlib import Path++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from hermes_cli import kanban_db as kb+++def _load_plugin_router():+ repo_root = Path(__file__).resolve().parents[2]+ plugin_file = repo_root / "plugins" / "kanban" / "dashboard" / "plugin_api.py"+ spec = importlib.util.spec_from_file_location("hermes_kanban_plugin_lifecycle_test", plugin_file)+ mod = importlib.util.module_from_spec(spec)+ sys.modules[spec.name] = mod+ spec.loader.exec_module(mod)+ return mod.router+++def client(tmp_path, monkeypatch):+ home = tmp_path / ".hermes"+ home.mkdir()+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ kb.init_db()++ app = FastAPI()+ app.include_router(_load_plugin_router(), prefix="/api/plugins/kanban")+ return TestClient(app)+++def test_rename_board_keeps_slug(client):+ client.post("/api/plugins/kanban/boards", json={"slug": "widget", "name": "Widget"})++ r = client.patch("/api/plugins/kanban/boards/widget", json={"name": "Gadget"})+ assert r.status_code == 200, r.text+ assert r.json()["board"] == {**r.json()["board"], "slug": "widget", "name": "Gadget"}++ listed = next(b for b in client.get("/api/plugins/kanban/boards").json()["boards"] if b["slug"] == "widget")+ assert listed["name"] == "Gadget"+++def test_delete_board_archives_and_reverts_current(client):+ client.post("/api/plugins/kanban/boards", json={"slug": "widget", "name": "Widget"})+ client.post("/api/plugins/kanban/tasks?board=widget", json={"title": "do the thing"})+ kb.set_current_board("widget")++ r = client.delete("/api/plugins/kanban/boards/widget")+ assert r.status_code == 200, r.text+ body = r.json()+ assert body["result"]["action"] == "archived"+ assert body["current"] == "default"++ # The switcher shows this path, so it must point at real recoverable data.+ archived = Path(body["result"]["new_path"])+ assert archived.is_dir()+ assert (archived / "kanban.db").exists()+ assert not kb.board_dir("widget").exists()++ assert all(b["slug"] != "widget" for b in client.get("/api/plugins/kanban/boards").json()["boards"])+++def test_delete_board_hard_leaves_nothing(client):+ client.post("/api/plugins/kanban/boards", json={"slug": "widget"})++ r = client.delete("/api/plugins/kanban/boards/widget?delete=true")+ assert r.status_code == 200, r.text+ assert r.json()["result"]["action"] == "deleted"+ assert not kb.board_dir("widget").exists()+++def test_delete_default_board_is_refused(client):+ r = client.delete("/api/plugins/kanban/boards/default")+ assert r.status_code == 400+ assert "default" in r.json()["detail"]