Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(chat): expose the project/chat library over REST, mounted and tagged
rubenluetke10-beep5d432bc0163a
diff --git a/jarvis/ui/web/chat_library_routes.py b/jarvis/ui/web/chat_library_routes.pynew file mode 100644index 0000000000..a71b87d846--- /dev/null+++ b/jarvis/ui/web/chat_library_routes.py@@ -0,0 +1,293 @@+"""REST API for the project/chat library — the new chat surface's sidebar.++Endpoints (mounted by the WebServer in ``_build_app()``):++ GET /api/chat-library/projects → every project+ POST /api/chat-library/projects → open/create one+ PATCH /api/chat-library/projects/{pid} → rename, pin, archive+ DELETE /api/chat-library/projects/{pid} → forget it and its chats+ GET /api/chat-library/projects/{pid}/chats → that project's chats+ POST /api/chat-library/projects/{pid}/chats → start a chat+ PATCH /api/chat-library/projects/{pid}/chats/{tid} → rename, archive, retarget+ DELETE /api/chat-library/projects/{pid}/chats/{tid} → forget one chat++**Listing is deliberately two calls, not one.** A project's chats load when the+project is opened, never with the project list — the sidebar of somebody with+forty repos and a thousand conversations has to arrive in one small response,+and it does: the project list carries a COUNT per project, not the chats. That+is the whole reason :mod:`jarvis.agentic_ide.library` stores one file per+project.++Neither does any of this return message CONTENT. A chat row is a title, an+agent, a timestamp and a one-line preview; opening the conversation is a+separate call against the coding CLI's own transcript. So this router has no+Brain dependency, no session dependency and no filesystem cost beyond a few+small JSON reads — it works headless and on a fresh install with no keys at all+(CLAUDE.md §3).++``exists`` on a project is reported rather than acted on. A folder can be+missing because an external drive is unplugged or a network share is late, and+deleting somebody's chat history over a late mount is not a trade this feature+gets to make: the row says the folder is unreachable and stays.+"""++from __future__ import annotations++from pathlib import Path+from typing import Any++from fastapi import APIRouter, HTTPException+from pydantic import BaseModel, Field++from jarvis.agentic_ide import library++router = APIRouter(prefix="/api/chat-library", tags=["chat-library"])+++# --------------------------------------------------------------------------- #+# payloads+# --------------------------------------------------------------------------- #+++class ProjectOut(BaseModel):+ """One project as the sidebar needs it."""++ id: str+ path: str+ name: str+ color: str | None = None+ pinned: bool = False+ archived: bool = False+ created_at: float = 0.0+ last_opened_at: float = 0.0+ #: Is the folder reachable on this machine right now? Reported, never acted+ #: on — see the module docstring.+ exists: bool = True+ #: How many live chats it holds. The COUNT travels with the list; the chats+ #: themselves do not.+ chats: int = 0+++class ProjectsOut(BaseModel):+ projects: list[ProjectOut]+++class OpenProjectIn(BaseModel):+ path: str = Field(..., min_length=1)+ name: str | None = None+++class PatchProjectIn(BaseModel):+ name: str | None = None+ color: str | None = None+ pinned: bool | None = None+ archived: bool | None = None+++class ChatOut(BaseModel):+ """One chat row. Metadata only — never a message."""++ id: str+ project_id: str+ title: str = ""+ agent: str = ""+ model: str | None = None+ account: str | None = None+ #: The live pane this chat is attached to, if any. Null means the+ #: conversation exists but nothing is running — the normal resting state.+ terminal: str | None = None+ #: Can this chat be reopened in its CLI? False for a conversation the CLI+ #: never gave us a handle for; the UI offers a fresh start instead of a+ #: resume that would silently begin from nothing.+ resumable: bool = False+ created_at: float = 0.0+ updated_at: float = 0.0+ archived: bool = False+ preview: str = ""+ prompts_sent: int = 0+++class ChatsOut(BaseModel):+ chats: list[ChatOut]+++class CreateChatIn(BaseModel):+ agent: str = Field(..., min_length=1)+ model: str | None = None+ account: str | None = None+ title: str = ""+++class PatchChatIn(BaseModel):+ title: str | None = None+ archived: bool | None = None+ model: str | None = None+ account: str | None = None+++class RemovedOut(BaseModel):+ removed: bool+++# --------------------------------------------------------------------------- #+# helpers+# --------------------------------------------------------------------------- #+++def _folder_exists(path: str) -> bool:+ """Is the project's folder reachable? Any OS complaint reads as "no".++ A permission error, a dead network share and a genuinely missing directory+ all mean the same thing to the caller — the folder cannot be opened right+ now — so they are not distinguished here.+ """+ try:+ return Path(path).is_dir()+ except OSError:+ return False+++def _project_out(project: library.Project) -> ProjectOut:+ return ProjectOut(+ **project.to_dict(),+ exists=_folder_exists(project.path),+ chats=len(library.list_threads(project.id)),+ )+++def _chat_out(thread: library.Thread) -> ChatOut:+ data: dict[str, Any] = thread.to_dict()+ resume = data.pop("resume", None)+ return ChatOut(**data, resumable=bool(resume))+++def _require_project(project_id: str) -> library.Project:+ project = library.get_project(project_id)+ if project is None:+ raise HTTPException(status_code=404, detail="No such project")+ return project+++# --------------------------------------------------------------------------- #+# projects+# --------------------------------------------------------------------------- #++[email protected]("/projects", response_model=ProjectsOut, summary="Every project and its chat count")+def list_projects(include_archived: bool = False) -> ProjectsOut:+ return ProjectsOut(+ projects=[_project_out(p) for p in library.list_projects(include_archived=include_archived)]+ )++[email protected]("/projects", response_model=ProjectOut, summary="Open a folder as a project")+def open_project(body: OpenProjectIn) -> ProjectOut:+ """Idempotent by folder: opening the same repo again returns the same project.++ Deliberately does NOT check that the folder exists. Registering a project on+ a drive that is currently unplugged is a reasonable thing to do, and the+ response says so via ``exists`` — refusing here would make the library+ disagree with itself, since a project whose folder vanishes later is kept.+ """+ project = library.ensure_project(body.path, name=body.name)+ return _project_out(project)+++ "/projects/{project_id}", response_model=ProjectOut, summary="Rename, pin or archive a project"+)+def patch_project(project_id: str, body: PatchProjectIn) -> ProjectOut:+ updated = library.update_project(+ project_id,+ name=body.name,+ color=body.color,+ pinned=body.pinned,+ archived=body.archived,+ )+ if updated is None:+ raise HTTPException(status_code=404, detail="No such project")+ return _project_out(updated)+++ "/projects/{project_id}",+ response_model=RemovedOut,+ summary="Forget a project and every chat in it",+ # Destructive and not undoable: the chat list goes with the project. The+ # folder and the coding CLIs' own conversations are untouched.+ openapi_extra={"x-jarvis-dangerous": True},+)+def delete_project(project_id: str) -> RemovedOut:+ return RemovedOut(removed=library.delete_project(project_id))+++# --------------------------------------------------------------------------- #+# chats+# --------------------------------------------------------------------------- #+++ "/projects/{project_id}/chats",+ response_model=ChatsOut,+ summary="One project's chats, newest first",+)+def list_chats(project_id: str, include_archived: bool = False) -> ChatsOut:+ _require_project(project_id)+ return ChatsOut(+ chats=[+ _chat_out(t)+ for t in library.list_threads(project_id, include_archived=include_archived)+ ]+ )+++ "/projects/{project_id}/chats", response_model=ChatOut, summary="Start a chat in a project"+)+def create_chat(project_id: str, body: CreateChatIn) -> ChatOut:+ """A new chat starts untitled and unattached.++ Nothing is launched here — no pane, no process, no tokens. A chat becomes+ live when the first prompt is sent, which is what makes creating one free+ and makes an accidental one visibly a blank rather than a running agent.+ """+ _require_project(project_id)+ library.touch_project(project_id)+ thread = library.create_thread(+ project_id,+ agent=body.agent,+ model=body.model,+ account=body.account,+ title=body.title,+ )+ return _chat_out(thread)+++ "/projects/{project_id}/chats/{chat_id}",+ response_model=ChatOut,+ summary="Rename or archive a chat",+)+def patch_chat(project_id: str, chat_id: str, body: PatchChatIn) -> ChatOut:+ changes = {k: v for k, v in body.model_dump().items() if v is not None}+ if not changes:+ existing = library.get_thread(project_id, chat_id)+ if existing is None:+ raise HTTPException(status_code=404, detail="No such chat")+ return _chat_out(existing)+ updated = library.update_thread(project_id, chat_id, **changes)+ if updated is None:+ raise HTTPException(status_code=404, detail="No such chat")+ return _chat_out(updated)+++ "/projects/{project_id}/chats/{chat_id}",+ response_model=RemovedOut,+ summary="Forget one chat",+ # The library entry goes; the coding CLI's own conversation on disk stays.+ # It is that CLI's data, written before Jarvis was involved.+ openapi_extra={"x-jarvis-dangerous": True},+)+def delete_chat(project_id: str, chat_id: str) -> RemovedOut:+ return RemovedOut(removed=library.delete_thread(project_id, chat_id))diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.pyindex 6346c0c75e..7bbe2f190f 100644--- a/jarvis/ui/web/server.py+++ b/jarvis/ui/web/server.py@@ -320,6 +320,7 @@ class WebServer:from .board_routes import (router as board_router,)+ from .chat_library_routes import router as chat_library_routerfrom .chats_routes import router as chats_routerfrom .claude_routes import router as claude_routerfrom .cli_routes import router as cli_router@@ -455,6 +456,10 @@ class WebServer:# workspace above; adds the folder picker, call-signs, transcripts, and# the focused coding mode.app.include_router(agentic_ide_router)+ # The project/chat library behind the chat surface's sidebar. Pure file+ # store, no Brain and no session dependency — it lists on a fresh+ # install with no keys and answers headless.+ app.include_router(chat_library_router)# Contacts section — user-curated address book (pure file store, no Brain dep).app.include_router(contacts_router)app.include_router(dictionary_router)diff --git a/tests/unit/agentic_ide/test_chat_library_routes.py b/tests/unit/agentic_ide/test_chat_library_routes.pynew file mode 100644index 0000000000..ce8e44862f--- /dev/null+++ b/tests/unit/agentic_ide/test_chat_library_routes.py@@ -0,0 +1,207 @@+"""The chat library's REST surface — what the sidebar is allowed to cost.++The properties under test are the ones that decide whether this scales past the+maintainer's own machine: listing projects must not load their chats, listing+chats must not load their messages, and an unreachable folder must be reported+rather than cleaned up.+"""++from __future__ import annotations++from pathlib import Path++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from jarvis.agentic_ide import library+from jarvis.ui.web.chat_library_routes import router+++def client() -> TestClient:+ app = FastAPI()+ app.include_router(router)+ return TestClient(app)+++def test_the_project_list_carries_counts_not_chats(client: TestClient, tmp_path: Path) -> None:+ """A thousand conversations must not travel with a forty-project sidebar.++ The list may look at each project's chat file to COUNT, but the chats+ themselves never leave the server — and no message file is opened at all,+ because this router never touches one.+ """+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")+ for i in range(3):+ library.create_thread(project.id, agent="claude", title=f"chat {i}")++ body = client.get("/api/chat-library/projects").json()++ assert len(body["projects"]) == 1+ entry = body["projects"][0]+ assert entry["chats"] == 3+ # The count is the ONLY thing the list says about them.+ assert "threads" not in entry+ assert "preview" not in entry+++def test_chats_load_only_when_the_project_is_asked_for(client: TestClient, tmp_path: Path) -> None:+ """Two calls, on purpose: the second one is what a click pays for."""+ for name in ("left", "right"):+ (tmp_path / name).mkdir()+ left = library.ensure_project(tmp_path / "left")+ right = library.ensure_project(tmp_path / "right")+ library.create_thread(left.id, agent="claude", title="only mine")++ body = client.get(f"/api/chat-library/projects/{left.id}/chats").json()+ other = client.get(f"/api/chat-library/projects/{right.id}/chats").json()++ assert [c["title"] for c in body["chats"]] == ["only mine"]+ assert other["chats"] == []+++def test_a_chat_row_never_carries_a_message(client: TestClient, tmp_path: Path) -> None:+ """The row is a title, an agent and a one-line preview — never a transcript.++ The conversation lives in the coding CLI's own files and is fetched+ separately; a row that carried it would make opening the sidebar as+ expensive as opening every chat in it.+ """+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")+ thread = library.create_thread(project.id, agent="codex")+ library.update_thread(project.id, thread.id, preview="last thing said")++ row = client.get(f"/api/chat-library/projects/{project.id}/chats").json()["chats"][0]++ assert row["preview"] == "last thing said"+ assert "messages" not in row+ # The resume handle is an internal pointer, not something the UI needs the+ # contents of — it is reported as a yes/no.+ assert "resume" not in row+ assert row["resumable"] is False+++def test_an_unreachable_folder_is_reported_not_cleaned_up(+ client: TestClient, tmp_path: Path+) -> None:+ """An unplugged drive is a temporary state, not permission to delete history."""+ folder = tmp_path / "repo"+ folder.mkdir()+ project = library.ensure_project(folder)+ library.create_thread(project.id, agent="claude")+ folder.rmdir()++ entry = client.get("/api/chat-library/projects").json()["projects"][0]++ assert entry["id"] == project.id+ assert entry["exists"] is False+ assert entry["chats"] == 1+++def test_opening_a_project_is_idempotent(client: TestClient, tmp_path: Path) -> None:+ """Every entry point can just open — none has to check first."""+ (tmp_path / "repo").mkdir()++ first = client.post("/api/chat-library/projects", json={"path": str(tmp_path / "repo")}).json()+ second = client.post("/api/chat-library/projects", json={"path": str(tmp_path / "repo")}).json()++ assert first["id"] == second["id"]+ assert len(client.get("/api/chat-library/projects").json()["projects"]) == 1+++def test_a_folder_that_is_not_there_can_still_be_registered(+ client: TestClient, tmp_path: Path+) -> None:+ """Refusing here would make the library disagree with itself.++ A project whose folder vanishes LATER is kept (see the test above), so+ refusing to create one whose folder is missing NOW would be two rules for+ the same situation. The response says the folder is unreachable instead.+ """+ response = client.post("/api/chat-library/projects", json={"path": str(tmp_path / "not-there")})++ assert response.status_code == 200+ assert response.json()["exists"] is False+++def test_archiving_hides_a_chat_without_destroying_it(client: TestClient, tmp_path: Path) -> None:+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")+ thread = library.create_thread(project.id, agent="claude", title="old work")++ client.patch(+ f"/api/chat-library/projects/{project.id}/chats/{thread.id}",+ json={"archived": True},+ )++ assert client.get(f"/api/chat-library/projects/{project.id}/chats").json()["chats"] == []+ archived = client.get(+ f"/api/chat-library/projects/{project.id}/chats",+ params={"include_archived": True},+ ).json()["chats"]+ assert [c["title"] for c in archived] == ["old work"]+++def test_renaming_a_chat_survives_the_next_read(client: TestClient, tmp_path: Path) -> None:+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")+ thread = library.create_thread(project.id, agent="claude")++ client.patch(+ f"/api/chat-library/projects/{project.id}/chats/{thread.id}",+ json={"title": "Wake path"},+ )++ rows = client.get(f"/api/chat-library/projects/{project.id}/chats").json()["chats"]+ assert [c["title"] for c in rows] == ["Wake path"]+++def test_deleting_a_chat_is_idempotent(client: TestClient, tmp_path: Path) -> None:+ """A double-click on delete must not become an error the user has to read."""+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")+ thread = library.create_thread(project.id, agent="claude")+ path = f"/api/chat-library/projects/{project.id}/chats/{thread.id}"++ assert client.delete(path).json() == {"removed": True}+ second = client.delete(path)+ assert second.status_code == 200+ assert second.json() == {"removed": False}+++def test_unknown_ids_are_a_404_not_an_empty_list(client: TestClient) -> None:+ """ "No such project" and "a project with no chats" are different answers."""+ assert client.get("/api/chat-library/projects/nope/chats").status_code == 404+ assert client.patch("/api/chat-library/projects/nope", json={"name": "x"}).status_code == 404+ assert (+ client.patch("/api/chat-library/projects/nope/chats/nope", json={"title": "x"}).status_code+ == 404+ )+++def test_creating_a_chat_starts_nothing(client: TestClient, tmp_path: Path) -> None:+ """No pane, no process, no tokens — a chat goes live on its first prompt."""+ (tmp_path / "repo").mkdir()+ project = library.ensure_project(tmp_path / "repo")++ row = client.post(+ f"/api/chat-library/projects/{project.id}/chats", json={"agent": "claude"}+ ).json()++ assert row["terminal"] is None+ assert row["prompts_sent"] == 0+ assert row["title"] == ""+++def test_destructive_routes_declare_themselves(client: TestClient) -> None:+ """The danger flag is what keeps a delete out of an unattended yes (CLAUDE.md §5)."""+ schema = client.get("/openapi.json").json()["paths"]++ for path in (+ "/api/chat-library/projects/{project_id}",+ "/api/chat-library/projects/{project_id}/chats/{chat_id}",+ ):+ assert schema[path]["delete"]["x-jarvis-dangerous"] is True