diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index 9108e27..398425e 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -4,7 +4,7 @@ - v1 is a single-file Python app (`bterminal.py`). Changes are localized. - v2 docs are in `docs/`. Architecture decisions are in `docs/task_plan.md`. -- Phase 3 (Agent SDK Integration) core is complete. Needs testing and polish (markdown rendering, sidecar crash detection, auto-scroll lock). +- MVP complete (Phases 1-4). Phase 3 polish done (crash detection, restart UI, auto-scroll lock). Phase 4 done (SQLite sessions, file watcher, markdown viewer). - Consult Memora (tag: `bterminal`) before making architectural changes. ## Documentation References @@ -30,6 +30,9 @@ - Agent dispatcher (`src/lib/agent-dispatcher.ts`) is a singleton that routes sidecar events to the agent store. - Maximum 4 active xterm.js instances to avoid WebKit2GTK memory issues. - Store files using Svelte 5 runes (`$state`, `$derived`) MUST have `.svelte.ts` extension (not `.ts`). Import with `.svelte` suffix. Plain `.ts` compiles but fails at runtime with "rune_outside_svelte". +- Session persistence uses rusqlite (bundled) with WAL mode. Data dir: `dirs::data_dir()/bterminal/sessions.db`. +- Layout store persists to SQLite on every addPane/removePane/setPreset change (fire-and-forget). Restores on app startup via `restoreFromDb()`. +- File watcher uses notify crate v6, watches parent directory (NonRecursive), emits `file-changed` Tauri events. ## Memora Tags diff --git a/CHANGELOG.md b/CHANGELOG.md index 0708f89..2b063c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- SQLite session persistence with rusqlite (bundled, WAL mode) — sessions table + layout_state singleton (Phase 4) +- Session CRUD: save, delete, update_title, touch with 7 Tauri commands (Phase 4) +- Layout restore on app startup — panes and preset restored from database (Phase 4) +- File watcher backend using notify crate v6 — watches files, emits Tauri events on change (Phase 4) +- MarkdownPane component with marked.js rendering, Catppuccin-themed styles, and live reload (Phase 4) +- Sidebar "M" button for opening markdown/text files via file picker (Phase 4) +- Session bridge adapter for Tauri IPC (session + layout persistence wrappers) (Phase 4) +- File bridge adapter for Tauri IPC (watch, unwatch, read, onChange wrappers) (Phase 4) +- Sidecar crash detection — dispatcher listens for process exit, marks running sessions as error (Phase 3 polish) +- Sidecar restart UI — "Restart Sidecar" button in AgentPane error bar (Phase 3 polish) +- Auto-scroll lock — disables auto-scroll when user scrolls up, shows "Scroll to bottom" button (Phase 3 polish) +- Agent restart Tauri command (agent_restart) (Phase 3 polish) +- Agent pane with prompt input, structured message rendering, stop button, and cost display (Phase 3) + ### Fixed - Svelte 5 rune stores (layout, agents, sessions) renamed from `.ts` to `.svelte.ts` — runes only work in `.svelte` and `.svelte.ts` files, plain `.ts` caused "rune_outside_svelte" runtime error (blank screen) - Updated all import paths to use `.svelte` suffix for store modules - -### Added -- Agent pane with prompt input, structured message rendering, stop button, and cost display (Phase 3) - Node.js sidecar manager (Rust) for spawning and communicating with agent-runner via stdio NDJSON (Phase 3) - Agent-runner sidecar: spawns `claude` CLI with `--output-format stream-json` for structured agent output (Phase 3) - SDK message adapter parsing stream-json into 9 typed message types: init, text, thinking, tool_call, tool_result, status, cost, error, unknown (Phase 3) diff --git a/README.md b/README.md index da7c0b4..3e3265d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Terminal with session panel (MobaXterm-style), built with GTK 3 + VTE. Catppuccin Mocha theme. -> **v2 in progress (Phase 3 in progress):** Redesign as a multi-session Claude agent dashboard using Tauri 2.x + Svelte 5. Working multi-pane terminal with PTY backend, agent panes with structured output from `claude` CLI, CSS Grid tiling, and Catppuccin theme on branch `v2-mission-control`. See [docs/task_plan.md](docs/task_plan.md) for architecture and [docs/phases.md](docs/phases.md) for implementation plan. +> **v2 MVP complete (Phase 4 done):** Multi-session Claude agent dashboard using Tauri 2.x + Svelte 5. Features: multi-pane terminal with PTY backend, agent panes with structured output from `claude` CLI, SQLite session persistence with layout restore, live markdown file viewer, CSS Grid tiling, and Catppuccin theme. Branch `v2-mission-control`. See [docs/task_plan.md](docs/task_plan.md) for architecture and [docs/phases.md](docs/phases.md) for implementation plan. ![BTerminal](screenshot.png) diff --git a/TODO.md b/TODO.md index 6cb5cf2..807c320 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,20 @@ -# BTerminal — TODO +# BTerminal -- TODO ## Active -- [ ] **Phase 3: Agent SDK Integration (polish)** — Markdown rendering in agent text, sidecar crash detection/restart, auto-scroll lock, testing. -- [ ] **Phase 4: Session Management + Markdown** — SQLite persistence, session CRUD, file watcher, markdown rendering. MVP ship after this phase. -- [ ] **Pane drag-resize handles** — Deferred from Phase 2, current presets sufficient for MVP. -- [ ] **Copy/paste (Ctrl+Shift+C/V)** — Deferred from Phase 2. -- [ ] **Evaluate Deno as sidecar runtime** — Single binary, better packaging than Node.js. Test SDK compatibility. +- [ ] **Phase 5: Agent Tree + Polish** -- Agent tree visualization (SVG), global status bar, notifications, settings dialog, ctx integration. +- [ ] **Phase 6: Packaging + Distribution** -- install.sh v2, AppImage, .deb, GitHub Actions CI, auto-update. +- [ ] **Markdown rendering in agent text messages** -- Currently plain text; needs marked.js integration in AgentPane text blocks. +- [ ] **Testing** -- vitest for sdk-messages adapter, cargo test for sidecar/session/watcher, Playwright for e2e. +- [ ] **Pane drag-resize handles** -- Deferred from Phase 2, current presets sufficient for MVP. +- [ ] **Copy/paste (Ctrl+Shift+C/V)** -- Deferred from Phase 2. +- [ ] **Session resume (SDK resumeSessionId)** -- Allow resuming previous agent sessions. +- [ ] **Evaluate Deno as sidecar runtime** -- Single binary, better packaging than Node.js. Test SDK compatibility. +- [ ] **Syntax highlighting in markdown viewer** -- Shiki integration deferred for bundle size. ## Completed -- [x] **Phase 3: Agent SDK Integration (core)** — Sidecar manager, agent-runner (claude CLI subprocess), SDK message adapter (stream-json), agent pane with message rendering/cost/stop. | Done: 2026-03-06 -- [x] **Phase 2: Terminal Pane + Layout** — PTY backend (portable-pty), xterm.js + Canvas addon, CSS Grid tiling (5 presets), sidebar, keyboard shortcuts. | Done: 2026-03-05 -- [x] **Phase 1: Project Scaffolding** — Tauri 2.x + Svelte 5 scaffolded in `v2/`, Catppuccin theme, Rust stubs, sidecar scaffold. | Done: 2026-03-05 +- [x] **Phase 4: Session Management + Markdown Viewer** -- SQLite persistence (rusqlite, WAL), session CRUD, layout restore on startup, file watcher (notify crate), MarkdownPane with marked.js and Catppuccin styles, sidebar file picker. | Done: 2026-03-06 +- [x] **Phase 3: Agent SDK Integration (core + polish)** -- Sidecar manager with restart, crash detection, auto-scroll lock, agent pane with messages/cost/stop/restart. | Done: 2026-03-06 +- [x] **Phase 2: Terminal Pane + Layout** -- PTY backend (portable-pty), xterm.js + Canvas addon, CSS Grid tiling (5 presets), sidebar, keyboard shortcuts. | Done: 2026-03-05 +- [x] **Phase 1: Project Scaffolding** -- Tauri 2.x + Svelte 5 scaffolded in `v2/`, Catppuccin theme, Rust stubs, sidecar scaffold. | Done: 2026-03-05 diff --git a/docs/phases.md b/docs/phases.md index 5ff7723..30a761a 100644 --- a/docs/phases.md +++ b/docs/phases.md @@ -107,19 +107,19 @@ bterminal-v2/ --- -## Phase 3: Agent SDK Integration [status: in_progress] — MVP +## Phase 3: Agent SDK Integration [status: complete] — MVP ### Backend - [x] Node.js sidecar: spawns `claude` CLI with `--output-format stream-json` (not Agent SDK query() — avoids npm dep + version churn) - [x] Sidecar communication: Rust spawns Node.js, stdio NDJSON - [x] Sidecar lifecycle: auto-start on app launch, shutdown on exit -- [ ] Sidecar lifecycle: detect crash, offer restart in UI -- [x] Tauri commands: agent_query, agent_stop, agent_ready +- [x] Sidecar lifecycle: detect crash, offer restart in UI (agent_restart command + restart button) +- [x] Tauri commands: agent_query, agent_stop, agent_ready, agent_restart ### Frontend - [x] SDK message adapter: parses stream-json into 9 typed AgentMessage types (abstraction layer) - [x] Agent bridge: Tauri IPC adapter (invoke + event listeners) -- [x] Agent dispatcher: singleton routing sidecar events to store +- [x] Agent dispatcher: singleton routing sidecar events to store, crash detection - [x] Agent store: session state, message history, cost tracking (Svelte 5 $state) - [x] Agent pane: renders structured messages - [x] Text -> plain text (markdown rendering deferred) @@ -132,7 +132,7 @@ bterminal-v2/ - [ ] Subagent spawn -> tree node + optional new pane (Phase 5) - [x] Agent status indicator (starting/running/done/error) - [x] Start/stop agent from UI (prompt form + stop button) -- [ ] Auto-scroll with scroll-lock on user scroll-up +- [x] Auto-scroll with scroll-lock on user scroll-up - [ ] Session resume (SDK `resume: sessionId`) - [x] Keyboard: Ctrl+Shift+N new agent - [x] Sidebar: agent session button @@ -141,21 +141,23 @@ bterminal-v2/ --- -## Phase 4: Session Management + Markdown Viewer [status: not_started] — MVP +## Phase 4: Session Management + Markdown Viewer [status: complete] — MVP ### Sessions -- [ ] SQLite persistence for sessions (rusqlite) -- [ ] Session types: SSH, Claude CLI, Agent SDK, Local Shell -- [ ] Session CRUD in sidebar -- [ ] Session groups/folders -- [ ] Remember last layout on restart +- [x] SQLite persistence for sessions (rusqlite with bundled feature) +- [x] Session types: terminal, agent, markdown (SSH via terminal args) +- [x] Session CRUD: save, delete, update_title, touch (last_used_at) +- [ ] Session groups/folders (deferred — not needed for MVP) +- [x] Remember last layout on restart (preset + pane_ids in layout_state table) +- [x] Auto-restore panes on app startup (restoreFromDb in layout store) ### Markdown Viewer -- [ ] File watcher (notify crate) -> Tauri events -> frontend -- [ ] Markdown rendering (marked.js or remark) -- [ ] Syntax highlighting (Shiki) -- [ ] Open from sidebar or from agent output file references -- [ ] Debounce file watcher (200ms) +- [x] File watcher (notify crate v6) -> Tauri events -> frontend +- [x] Markdown rendering (marked.js) +- [ ] Syntax highlighting (Shiki) — deferred, adds significant bundle size +- [x] Open from sidebar (file picker button "M") +- [x] Catppuccin-themed markdown styles (h1-h3, code, pre, tables, blockquotes) +- [x] Live reload on file change **Milestone: After Phase 4 = MVP ship.** Full session management, structured agent panes, terminal panes, markdown viewer. diff --git a/docs/progress.md b/docs/progress.md index 0ac1bae..d5c070b 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -80,9 +80,25 @@ Architecture decision: Uses `claude` CLI with `--output-format stream-json` inst - [x] Renamed: `layout.ts` -> `layout.svelte.ts`, `agents.ts` -> `agents.svelte.ts`, `sessions.ts` -> `sessions.svelte.ts` - [x] Updated all import paths in 5 files to use `.svelte` suffix (e.g., `from './stores/layout.svelte'`) +### Phase 3 Polish (2026-03-06) +- [x] Sidecar crash detection: dispatcher listens for sidecar-exited event, marks running sessions as error +- [x] Restart UI: "Restart Sidecar" button in AgentPane error bar, calls agent_restart command +- [x] Auto-scroll lock: scroll handler disables auto-scroll when user scrolls >50px from bottom, "Scroll to bottom" button appears + +### Phase 4: Session Management + Markdown Viewer (2026-03-06) +- [x] rusqlite 0.31 (bundled) + dirs 5 + notify 6 added to Cargo.toml +- [x] SessionDb: SQLite with WAL mode, sessions table + layout_state singleton +- [x] Session CRUD: list, save, delete, update_title, touch (7 Tauri commands) +- [x] Frontend session-bridge.ts: typed invoke wrappers for all session/layout commands +- [x] Layout store wired to persistence: addPane/removePane/focusPane/setPreset all persist +- [x] restoreFromDb() on app startup restores panes in layout order +- [x] FileWatcherManager: notify crate watches files, emits Tauri "file-changed" events +- [x] MarkdownPane component: marked.js rendering, Catppuccin-themed styles, live reload +- [x] Sidebar "M" button opens file picker for .md/.markdown/.txt files +- [x] TilingGrid routes markdown pane type to MarkdownPane component + ### Next Steps - [ ] Markdown rendering in agent text messages -- [ ] Sidecar crash detection and restart UI -- [ ] Auto-scroll lock on user scroll-up - [ ] Testing: vitest for sdk-messages adapter, cargo test for sidecar -- [ ] Begin Phase 4: Session Management + Markdown Viewer +- [ ] Phase 5: Agent Tree + Polish +- [ ] Phase 6: Packaging + Distribution diff --git a/docs/task_plan.md b/docs/task_plan.md index aa2e6f3..3c869a8 100644 --- a/docs/task_plan.md +++ b/docs/task_plan.md @@ -3,7 +3,7 @@ ## Goal Redesign BTerminal from a GTK3 terminal emulator into a **multi-session Claude agent dashboard** optimized for 32:9 ultrawide (5120x1440). Simultaneous visibility of all active sessions, agent tree visualization, inline markdown rendering, maximum information density. -## Status: BUILDING (Phase 3 in progress — Rev 2) +## Status: MVP COMPLETE (Phase 4 done — Rev 2) ---