diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index 0403f7a..589688a 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -26,7 +26,7 @@ - WebKit2GTK has no WebGL — xterm.js must use Canvas addon explicitly. - Agent sessions use `@anthropic-ai/claude-agent-sdk` query() function (migrated from raw CLI spawning due to piped stdio hang bug). SDK handles subprocess management internally. All output goes through the adapter layer (`src/lib/adapters/sdk-messages.ts`) — SDK message format matches CLI stream-json. -- Sidecar uses a single pre-built bundle (`sidecar/dist/agent-runner.mjs`) that runs on both Deno and Node.js. SidecarCommand struct in sidecar.rs abstracts runtime (Deno preferred for faster startup, Node.js fallback). Communicates with Rust via stdio NDJSON. CLAUDE* env var stripping is dual-layer: (1) Rust SidecarManager uses env_clear() + envs(clean_env) to strip all CLAUDE* vars before spawning the sidecar process, (2) JS runner also strips via SDK's `env` option (defense-in-depth). Without this, nesting detection triggers when BTerminal is launched from a Claude Code terminal. Session stop uses AbortController.abort() (not process.kill()). +- Sidecar uses a single pre-built bundle (`sidecar/dist/agent-runner.mjs`) that runs on both Deno and Node.js. SidecarCommand struct in sidecar.rs abstracts runtime (Deno preferred for faster startup, Node.js fallback). Communicates with Rust via stdio NDJSON. Claude CLI auto-detected at startup via `findClaudeCli()` — checks ~/.local/bin/claude, ~/.claude/local/claude, /usr/local/bin/claude, /usr/bin/claude, then `which claude`. Path passed to SDK via `pathToClaudeCodeExecutable` option. Agents error immediately if CLI not found. CLAUDE* env var stripping is dual-layer: (1) Rust SidecarManager uses env_clear() + envs(clean_env) to strip all CLAUDE* vars before spawning the sidecar process, (2) JS runner also strips via SDK's `env` option (defense-in-depth). Without this, nesting detection triggers when BTerminal is launched from a Claude Code terminal. Session stop uses AbortController.abort() (not process.kill()). `agent-runner-deno.ts` exists as standalone alternative runner but is NOT used by SidecarManager. - AgentPane does NOT stop agents in onDestroy — onDestroy fires on layout remounts, not just explicit close. Stop-on-close is handled by TilingGrid.svelte's onClose handler (checks pane type + session status before calling stopAgent). - Agent dispatcher (`src/lib/agent-dispatcher.ts`) is a singleton that routes sidecar events to the agent store. Also handles subagent pane spawning (SUBAGENT_TOOL_NAMES detection, toolUseToChildPane routing map). - AgentQueryOptions supports `permission_mode` field (flows Rust -> sidecar -> SDK). Defaults to 'bypassPermissions', supports 'default' mode. allowDangerouslySkipPermissions is conditionally set. diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bda855..422f76c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Claude CLI path auto-detection: `findClaudeCli()` in both sidecar runners checks common paths (~/.local/bin/claude, ~/.claude/local/claude, /usr/local/bin/claude, /usr/bin/claude) then falls back to `which`/`where`; resolved path passed to SDK via `pathToClaudeCodeExecutable` option +- Early error reporting when Claude CLI is not found — sidecar emits `agent_error` immediately instead of cryptic SDK failure + ### Fixed - CLAUDE* env var stripping now applied at Rust level in SidecarManager (bterminal-core/src/sidecar.rs): `env_clear()` + `envs(clean_env)` strips all CLAUDE-prefixed vars before spawning sidecar process, providing primary defense against nesting detection (JS-side stripping retained as defense-in-depth) diff --git a/CLAUDE.md b/CLAUDE.md index 1ec75fa..eb58f38 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -24,7 +24,8 @@ Terminal emulator with SSH and Claude Code session management. v1 (GTK3+VTE Pyth | `docs/task_plan.md` | v2 architecture decisions and strategies | | `docs/phases.md` | v2 implementation phases (1-7 + multi-machine A-D) | | `docs/findings.md` | v2 research findings | -| `docs/progress.md` | Session progress log | +| `docs/progress.md` | Session progress log (recent) | +| `docs/progress-archive.md` | Archived progress log (2026-03-05 to 2026-03-06 early) | | `docs/multi-machine.md` | Multi-machine architecture (implemented, Phases A-D) | | `v2/Cargo.toml` | Cargo workspace root (members: src-tauri, bterminal-core, bterminal-relay) | | `v2/bterminal-core/` | Shared crate: EventSink trait, PtyManager, SidecarManager | @@ -67,7 +68,8 @@ Terminal emulator with SSH and Claude Code session management. v1 (GTK3+VTE Pyth | `v2/src/lib/components/Settings/SettingsDialog.svelte` | Settings modal (shell, cwd, max panes, theme) | | `v2/src/lib/adapters/session-bridge.ts` | Session/layout/group persistence IPC wrapper | | `v2/src/lib/components/Markdown/MarkdownPane.svelte` | Markdown file viewer (marked.js + shiki, live reload) | -| `v2/sidecar/agent-runner.ts` | Sidecar source (compiled to .mjs by esbuild) | +| `v2/sidecar/agent-runner.ts` | Sidecar source (compiled to .mjs by esbuild, includes findClaudeCli()) | +| `v2/sidecar/agent-runner-deno.ts` | Standalone Deno sidecar runner (not used by SidecarManager, alternative) | | `v2/sidecar/dist/agent-runner.mjs` | Bundled sidecar (runs on both Deno and Node.js) | | `v2/src/lib/adapters/sdk-messages.test.ts` | Vitest tests for SDK message adapter (25 tests) | | `v2/src/lib/adapters/agent-bridge.test.ts` | Vitest tests for agent IPC bridge (11 tests) | @@ -88,7 +90,7 @@ Terminal emulator with SSH and Claude Code session management. v1 (GTK3+VTE Pyth - Cargo workspace: bterminal-core (shared), bterminal-relay (remote binary), src-tauri (Tauri app) - xterm.js with Canvas addon (no WebGL on WebKit2GTK) - Agent sessions via `@anthropic-ai/claude-agent-sdk` query() function (migrated from raw CLI spawning) -- Sidecar uses SDK internally (single .mjs bundle, Deno-first + Node.js fallback, stdio NDJSON to Rust) +- Sidecar uses SDK internally (single .mjs bundle, Deno-first + Node.js fallback, stdio NDJSON to Rust, auto-detects Claude CLI path via findClaudeCli()) - portable-pty for terminal management (in bterminal-core) - Multi-machine: bterminal-relay WebSocket server + RemoteManager WebSocket client - SQLite session persistence (rusqlite, WAL mode) + layout restore on startup diff --git a/README.md b/README.md index ebd87e8..4cf01fd 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,8 @@ See [docs/multi-machine.md](docs/multi-machine.md) for full architecture details | [docs/task_plan.md](docs/task_plan.md) | v2 architecture decisions, error handling, testing strategy | | [docs/phases.md](docs/phases.md) | v2 implementation phases (1-7 + multi-machine A-D) with checklists | | [docs/findings.md](docs/findings.md) | Research findings (Agent SDK, Tauri, xterm.js, performance) | -| [docs/progress.md](docs/progress.md) | Session-by-session progress log | +| [docs/progress.md](docs/progress.md) | Session-by-session progress log (recent) | +| [docs/progress-archive.md](docs/progress-archive.md) | Archived progress log (2026-03-05 to 2026-03-06 early) | | [docs/multi-machine.md](docs/multi-machine.md) | Multi-machine architecture (implemented, WebSocket relay, reconnection) | ## License diff --git a/TODO.md b/TODO.md index ef99fe5..f4d17b2 100644 --- a/TODO.md +++ b/TODO.md @@ -9,13 +9,13 @@ ## Completed -- [x] **AgentPane onDestroy bug fix** -- Removed onDestroy stopAgent() from AgentPane (fired on layout remounts). Stop-on-close moved to TilingGrid onClose handler. | Done: 2026-03-06 -- [x] **Permission mode passthrough** -- Added permission_mode field flowing Rust -> sidecar -> SDK. Defaults to bypassPermissions, supports default mode. | Done: 2026-03-06 -- [x] **SDK bundling fix** -- Removed --external flag from esbuild build:sidecar. SDK now bundled into agent-runner.mjs. | Done: 2026-03-06 -- [x] **Sidecar SDK migration** -- Migrated both sidecar runners from raw `claude` CLI spawning to `@anthropic-ai/claude-agent-sdk` query(). Fixes silent hang bug (CLI #6775). SDK handles subprocess internally. Added ^0.2.70 dependency, build:sidecar script, updated Deno permissions. | Done: 2026-03-06 -- [x] **Sidecar CLAUDE* env var leak fix** -- Both sidecar runners now strip ALL CLAUDE-prefixed env vars via SDK `env` option. Prevents nesting detection when BTerminal launched from Claude Code terminal. | Done: 2026-03-06 -- [x] **Multi-machine reconnection** -- Exponential backoff reconnection (1s-30s cap) in RemoteManager, attempt_tcp_probe() (TCP-only), frontend reconnection listeners + auto-reconnect. | Done: 2026-03-06 -- [x] **Relay command response propagation** -- Structured responses (pty_created, pong, error) with commandId correlation, send_error() helper. | Done: 2026-03-06 -- [x] **Multi-machine support (Phases A-D)** -- bterminal-core crate extraction, bterminal-relay WebSocket binary, RemoteManager, frontend integration. | Done: 2026-03-06 -- [x] **Agent Teams frontend support** -- Subagent pane spawning, parent/child navigation, message routing by parentId, SUBAGENT_TOOL_NAMES detection in dispatcher. | Done: 2026-03-06 -- [x] **Subagent cost aggregation** -- `getTotalCost()` recursive helper in agents store, total cost shown in parent pane done-bar when children present. | Done: 2026-03-06 +- [x] **Claude CLI path auto-detection** -- findClaudeCli() in both sidecar runners auto-detects Claude CLI path, passes to SDK via pathToClaudeCodeExecutable. Early error if CLI not found. | Done: 2026-03-07 +- [x] **Unified sidecar bundle** -- Single agent-runner.mjs runs on both Deno and Node.js. Rust-side CLAUDE* env var stripping (dual-layer). | Done: 2026-03-07 +- [x] **AgentPane onDestroy bug fix** -- Stop-on-close moved to TilingGrid onClose handler. | Done: 2026-03-06 +- [x] **Permission mode passthrough** -- permission_mode field flowing Rust -> sidecar -> SDK. | Done: 2026-03-06 +- [x] **Sidecar SDK migration** -- Migrated from raw CLI spawning to @anthropic-ai/claude-agent-sdk query(). | Done: 2026-03-06 +- [x] **Sidecar CLAUDE* env var leak fix** -- Strip ALL CLAUDE-prefixed env vars (dual-layer). | Done: 2026-03-06 +- [x] **Multi-machine reconnection** -- Exponential backoff, TCP probe, frontend listeners + auto-reconnect. | Done: 2026-03-06 +- [x] **Multi-machine support (Phases A-D)** -- bterminal-core, bterminal-relay, RemoteManager, frontend. | Done: 2026-03-06 +- [x] **Agent Teams frontend support** -- Subagent pane spawning, parent/child navigation, message routing. | Done: 2026-03-06 +- [x] **Subagent cost aggregation** -- getTotalCost() recursive helper, total cost in parent pane. | Done: 2026-03-06 diff --git a/docs/README.md b/docs/README.md index 81afc47..32a0571 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,5 +19,6 @@ Project documentation lives here. | [task_plan.md](task_plan.md) | v2 architecture decisions, error handling, testing strategy | | [phases.md](phases.md) | v2 implementation phases (1-7 + multi-machine A-D) with checklists | | [findings.md](findings.md) | Research findings (Agent SDK, Tauri, xterm.js, performance) | -| [progress.md](progress.md) | Session-by-session progress log | +| [progress.md](progress.md) | Session-by-session progress log (recent sessions) | +| [progress-archive.md](progress-archive.md) | Archived progress log (2026-03-05 to 2026-03-06 early) | | [multi-machine.md](multi-machine.md) | Multi-machine support architecture (implemented, WebSocket relay, reconnection) | diff --git a/docs/progress-archive.md b/docs/progress-archive.md new file mode 100644 index 0000000..f40f036 --- /dev/null +++ b/docs/progress-archive.md @@ -0,0 +1,180 @@ +# BTerminal v2 — Progress Log (Archive: 2026-03-05 to 2026-03-06 early) + +> Archived from [progress.md](progress.md). Covers research, Phases 1-6, polish, testing, agent teams, and subagent support. + +## Session: 2026-03-05 + +### Research Phase (complete) +- [x] Analyzed current BTerminal v1 codebase (2092 lines Python, GTK3+VTE) +- [x] Queried Memora — no existing BTerminal memories +- [x] Researched Claude Agent SDK — found structured streaming, subagent tracking, hooks +- [x] Researched Tauri + xterm.js ecosystem — found 4+ working projects +- [x] Researched terminal latency benchmarks — xterm.js acceptable for AI output +- [x] Researched 32:9 ultrawide layout patterns +- [x] Evaluated GTK4 vs Tauri vs pure Rust — Tauri wins for this use case +- [x] Created task_plan.md with 8 phases +- [x] Created findings.md with 7 research areas + +### Technology Decision (complete) +- Decision: **Tauri 2.x + Solid.js + Claude Agent SDK + xterm.js** +- Rationale documented in task_plan.md Phase 0 + +### Adversarial Review (complete) +- [x] Spawned devil's advocate agent to attack the plan +- [x] Identified 5 fatal/critical issues: + 1. Node.js sidecar requirement unacknowledged + 2. SDK 0.2.x instability — need abstraction layer + 3. Three-tier observation overengineered — simplified to two-tier + 4. Solid.js ecosystem too small — switched to Svelte 5 + 5. Missing: packaging, error handling, testing, responsive design +- [x] Revised plan (Rev 2) incorporating all corrections +- [x] Added error handling strategy table +- [x] Added testing strategy table +- [x] Defined MVP boundary (Phases 1-4) +- [x] Added responsive layout requirement (1920px degraded mode) + +### Phase 1 Scaffolding (complete) +- [x] Created feature branch `v2-mission-control` +- [x] Initialized Tauri 2.x + Svelte 5 project in `v2/` directory +- [x] Rust backend stubs: main.rs, lib.rs, pty.rs, sidecar.rs, watcher.rs, session.rs +- [x] Svelte frontend: App.svelte with Catppuccin Mocha CSS variables, component stubs +- [x] Node.js sidecar scaffold: agent-runner.ts with NDJSON communication pattern +- [x] Tauri builds and launches (cargo build --release verified) +- [x] Dev scripts: npm run dev, npm run build, npm run tauri dev/build +- [x] 17 operational rules added to `.claude/rules/` +- [x] Project meta files: CLAUDE.md, .claude/CLAUDE.md, TODO.md, CHANGELOG.md +- [x] Documentation structure: docs/README.md, task_plan.md, phases.md, findings.md, progress.md + +### Phase 2: Terminal Pane + Layout (complete) +- [x] Rust PTY backend with portable-pty (PtyManager: spawn, write, resize, kill) +- [x] PTY reader thread emitting Tauri events (pty-data-{id}, pty-exit-{id}) +- [x] Tauri commands: pty_spawn, pty_write, pty_resize, pty_kill +- [x] xterm.js terminal pane with Canvas addon (explicit, no WebGL) +- [x] Catppuccin Mocha theme for xterm.js (16 ANSI colors) +- [x] FitAddon with ResizeObserver + 100ms debounce +- [x] PTY bridge adapter (spawnPty, writePty, resizePty, killPty, onPtyData, onPtyExit) +- [x] CSS Grid tiling layout with 5 presets (1-col, 2-col, 3-col, 2x2, master-stack) +- [x] Layout store with Svelte 5 $state runes and auto-preset selection +- [x] Sidebar with session list, layout preset selector, new terminal button +- [x] Keyboard shortcuts: Ctrl+N new terminal, Ctrl+1-4 focus pane +- [x] PaneContainer with header bar (title, status, close) +- [x] Empty state welcome screen with Ctrl+N hint +- [x] npm dependencies: @xterm/xterm, @xterm/addon-canvas, @xterm/addon-fit +- [x] Cargo dependencies: portable-pty, uuid + +### Phase 3: Agent SDK Integration (complete) +- [x] Rust SidecarManager: spawn Node.js, stdio NDJSON, query/stop/shutdown (sidecar.rs, 218 lines) +- [x] Node.js agent-runner: spawns `claude -p --output-format stream-json`, manages sessions (agent-runner.ts, 176 lines) +- [x] Tauri commands: agent_query, agent_stop, agent_ready in lib.rs +- [x] Sidecar auto-start on app launch +- [x] SDK message adapter: full stream-json parser with 9 typed message types (sdk-messages.ts, 234 lines) +- [x] Agent bridge: Tauri IPC adapter for sidecar communication (agent-bridge.ts, 53 lines) +- [x] Agent dispatcher: routes sidecar events to agent store (agent-dispatcher.ts, 87 lines) +- [x] Agent store: session state with messages, cost tracking (agents.svelte.ts, 91 lines) +- [x] AgentPane component: prompt input, message rendering, stop button, cost display (AgentPane.svelte, 420 lines) +- [x] UI integration: Ctrl+Shift+N for new agent, sidebar agent button, TilingGrid routing + +Architecture decision: Initially used `claude` CLI with `--output-format stream-json`. Migrated to `@anthropic-ai/claude-agent-sdk` query() due to CLI piped stdio hang bug (#6775). SDK outputs same message format, so adapter unchanged. + +### Bug Fix: Svelte 5 Rune File Extensions (2026-03-06) +- [x] Diagnosed blank screen / "rune_outside_svelte" runtime error +- [x] Root cause: store files used `.ts` extension but contain Svelte 5 `$state`/`$derived` runes, which only work in `.svelte` and `.svelte.ts` files +- [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 + +### Phase 5: Agent Tree + Polish (2026-03-06, complete) +- [x] Agent tree visualization (SVG): AgentTree.svelte component with horizontal tree layout, bezier edges, status-colored nodes; agent-tree.ts utility (buildAgentTree, countTreeNodes, subtreeCost) +- [x] Agent tree toggle in AgentPane: collapsible tree view shown when tool_call messages exist +- [x] Global status bar: StatusBar.svelte showing terminal/agent pane counts, active agents with pulse animation, total tokens and cost +- [x] Notification system: notifications.svelte.ts store (notify, dismissNotification, max 5 toasts, 4s auto-dismiss) + ToastContainer.svelte (slide-in animation, color-coded by type) +- [x] Agent dispatcher notifications: toast on agent_stopped (success), agent_error (error), sidecar crash (error), cost result (success with cost/turns) +- [x] Settings dialog: SettingsDialog.svelte modal (default shell, cwd, max panes, theme flavor) with settings-bridge.ts adapter +- [x] Settings backend: settings table (key/value) in session.rs, Tauri commands settings_get/set/list in lib.rs +- [x] Keyboard shortcuts: Ctrl+W close focused pane, Ctrl+, open settings dialog +- [x] CSS grid update: app.css grid-template-rows '1fr' -> '1fr auto' for status bar row +- [x] App.svelte: integrated StatusBar, ToastContainer, SettingsDialog components + +### Phase 6: Packaging + Distribution (2026-03-06) +- [x] Created install-v2.sh — build-from-source installer with 6-step dependency check process +- [x] Updated v2/src-tauri/tauri.conf.json: bundle targets ["deb", "appimage"] +- [x] Regenerated all icons in v2/src-tauri/icons/ from bterminal.svg as RGBA PNGs +- [x] Created .github/workflows/release.yml — CI workflow triggered on v* tags +- [x] Build verified: .deb (4.3 MB), AppImage (103 MB) both built successfully + +### Phase 5 continued: SSH, ctx, themes, detached mode, auto-updater (2026-03-06) +- [x] ctx integration: Rust ctx.rs, 5 Tauri commands, ctx-bridge.ts adapter, ContextPane.svelte +- [x] SSH session management: SshSession struct, ssh-bridge.ts, SshDialog.svelte, SshSessionList.svelte +- [x] Catppuccin theme flavors: Latte/Frappe/Macchiato/Mocha selectable +- [x] Detached pane mode: pop-out windows via URL params +- [x] Syntax highlighting: Shiki lazy singleton (13 languages) +- [x] Tauri auto-updater plugin integrated +- [x] AgentPane markdown rendering with Shiki highlighting + +### Session: 2026-03-06 (continued) — Polish, Testing, Extras + +#### Terminal Copy/Paste + Theme Hot-Swap +- [x] Copy/paste in TerminalPane via Ctrl+Shift+C/V +- [x] Theme hot-swap: onThemeChange() callback registry + +#### Agent Tree Enhancements +- [x] Click tree node -> scroll to message, subtree cost display + +#### Session Resume +- [x] Follow-up prompt input, resume_session_id passed to SDK + +#### Pane Drag-Resize Handles +- [x] Splitter overlays in TilingGrid with mouse drag (min 10% / max 90%) + +#### Auto-Update Workflow Enhancement +- [x] release.yml: signing key env vars, latest.json generation + +#### Deno Sidecar Evaluation +- [x] Created agent-runner-deno.ts proof-of-concept + +#### Testing Infrastructure +- [x] Vitest + Cargo tests: 104 vitest + 29 cargo tests, all passing + +### Session: 2026-03-06 (continued) — Session Groups, Auto-Update Key, Deno Sidecar, Tests + +#### Auto-Update Signing Key +- [x] Generated Tauri signing keypair (minisign), set pubkey in tauri.conf.json + +#### Session Groups/Folders +- [x] group_name column, setPaneGroup, grouped sidebar with collapsible headers + +#### Deno Sidecar Integration (upgraded from PoC) +- [x] SidecarCommand struct, Deno-first resolution, Node.js fallback + +#### E2E/Integration Tests +- [x] layout.test.ts (30), agent-bridge.test.ts (11), agent-dispatcher.test.ts (18), sdk-messages.test.ts (25) +- [x] Total: 104 vitest tests + 29 cargo tests + +### Session: 2026-03-06 (continued) — Agent Teams / Subagent Support + +#### Agent Teams Frontend Support +- [x] Parent/child hierarchy in agent store, subagent detection in dispatcher +- [x] spawnSubagentPane(), toolUseToChildPane routing, parent/child navigation in AgentPane +- [x] 10 new dispatcher tests for subagent routing (28 total, 114 vitest overall) + +#### Subagent Cost Aggregation +- [x] getTotalCost() recursive helper, total cost shown in parent pane + +#### TAURI_SIGNING_PRIVATE_KEY +- [x] Set via `gh secret set` on DexterFromLab/BTerminal GitHub repo diff --git a/docs/progress.md b/docs/progress.md index 914757a..db5608b 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -1,256 +1,6 @@ # BTerminal v2 — Progress Log -## Session: 2026-03-05 - -### Research Phase (complete) -- [x] Analyzed current BTerminal v1 codebase (2092 lines Python, GTK3+VTE) -- [x] Queried Memora — no existing BTerminal memories -- [x] Researched Claude Agent SDK — found structured streaming, subagent tracking, hooks -- [x] Researched Tauri + xterm.js ecosystem — found 4+ working projects -- [x] Researched terminal latency benchmarks — xterm.js acceptable for AI output -- [x] Researched 32:9 ultrawide layout patterns -- [x] Evaluated GTK4 vs Tauri vs pure Rust — Tauri wins for this use case -- [x] Created task_plan.md with 8 phases -- [x] Created findings.md with 7 research areas - -### Technology Decision (complete) -- Decision: **Tauri 2.x + Solid.js + Claude Agent SDK + xterm.js** -- Rationale documented in task_plan.md Phase 0 - -### Adversarial Review (complete) -- [x] Spawned devil's advocate agent to attack the plan -- [x] Identified 5 fatal/critical issues: - 1. Node.js sidecar requirement unacknowledged - 2. SDK 0.2.x instability — need abstraction layer - 3. Three-tier observation overengineered → simplified to two-tier - 4. Solid.js ecosystem too small → switched to Svelte 5 - 5. Missing: packaging, error handling, testing, responsive design -- [x] Revised plan (Rev 2) incorporating all corrections -- [x] Added error handling strategy table -- [x] Added testing strategy table -- [x] Defined MVP boundary (Phases 1-4) -- [x] Added responsive layout requirement (1920px degraded mode) - -### Phase 1 Scaffolding (complete) -- [x] Created feature branch `v2-mission-control` -- [x] Initialized Tauri 2.x + Svelte 5 project in `v2/` directory -- [x] Rust backend stubs: main.rs, lib.rs, pty.rs, sidecar.rs, watcher.rs, session.rs -- [x] Svelte frontend: App.svelte with Catppuccin Mocha CSS variables, component stubs -- [x] Node.js sidecar scaffold: agent-runner.ts with NDJSON communication pattern -- [x] Tauri builds and launches (cargo build --release verified) -- [x] Dev scripts: npm run dev, npm run build, npm run tauri dev/build -- [x] 17 operational rules added to `.claude/rules/` -- [x] Project meta files: CLAUDE.md, .claude/CLAUDE.md, TODO.md, CHANGELOG.md -- [x] Documentation structure: docs/README.md, task_plan.md, phases.md, findings.md, progress.md - -### Phase 2: Terminal Pane + Layout (complete) -- [x] Rust PTY backend with portable-pty (PtyManager: spawn, write, resize, kill) -- [x] PTY reader thread emitting Tauri events (pty-data-{id}, pty-exit-{id}) -- [x] Tauri commands: pty_spawn, pty_write, pty_resize, pty_kill -- [x] xterm.js terminal pane with Canvas addon (explicit, no WebGL) -- [x] Catppuccin Mocha theme for xterm.js (16 ANSI colors) -- [x] FitAddon with ResizeObserver + 100ms debounce -- [x] PTY bridge adapter (spawnPty, writePty, resizePty, killPty, onPtyData, onPtyExit) -- [x] CSS Grid tiling layout with 5 presets (1-col, 2-col, 3-col, 2x2, master-stack) -- [x] Layout store with Svelte 5 $state runes and auto-preset selection -- [x] Sidebar with session list, layout preset selector, new terminal button -- [x] Keyboard shortcuts: Ctrl+N new terminal, Ctrl+1-4 focus pane -- [x] PaneContainer with header bar (title, status, close) -- [x] Empty state welcome screen with Ctrl+N hint -- [x] npm dependencies: @xterm/xterm, @xterm/addon-canvas, @xterm/addon-fit -- [x] Cargo dependencies: portable-pty, uuid - -### Phase 3: Agent SDK Integration (in progress) -- [x] Rust SidecarManager: spawn Node.js, stdio NDJSON, query/stop/shutdown (sidecar.rs, 218 lines) -- [x] Node.js agent-runner: spawns `claude -p --output-format stream-json`, manages sessions (agent-runner.ts, 176 lines) -- [x] Tauri commands: agent_query, agent_stop, agent_ready in lib.rs -- [x] Sidecar auto-start on app launch -- [x] SDK message adapter: full stream-json parser with 9 typed message types (sdk-messages.ts, 234 lines) -- [x] Agent bridge: Tauri IPC adapter for sidecar communication (agent-bridge.ts, 53 lines) -- [x] Agent dispatcher: routes sidecar events to agent store (agent-dispatcher.ts, 87 lines) -- [x] Agent store: session state with messages, cost tracking (agents.svelte.ts, 91 lines) -- [x] AgentPane component: prompt input, message rendering, stop button, cost display (AgentPane.svelte, 420 lines) -- [x] UI integration: Ctrl+Shift+N for new agent, sidebar agent button, TilingGrid routing - -Architecture decision: Initially used `claude` CLI with `--output-format stream-json`. Migrated to `@anthropic-ai/claude-agent-sdk` query() due to CLI piped stdio hang bug (#6775). SDK outputs same message format, so adapter unchanged. - -### Bug Fix: Svelte 5 Rune File Extensions (2026-03-06) -- [x] Diagnosed blank screen / "rune_outside_svelte" runtime error -- [x] Root cause: store files used `.ts` extension but contain Svelte 5 `$state`/`$derived` runes, which only work in `.svelte` and `.svelte.ts` files -- [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 - -### Phase 5: Agent Tree + Polish (2026-03-06, complete) -- [x] Agent tree visualization (SVG): AgentTree.svelte component with horizontal tree layout, bezier edges, status-colored nodes; agent-tree.ts utility (buildAgentTree, countTreeNodes, subtreeCost) -- [x] Agent tree toggle in AgentPane: collapsible tree view shown when tool_call messages exist -- [x] Global status bar: StatusBar.svelte showing terminal/agent pane counts, active agents with pulse animation, total tokens and cost -- [x] Notification system: notifications.svelte.ts store (notify, dismissNotification, max 5 toasts, 4s auto-dismiss) + ToastContainer.svelte (slide-in animation, color-coded by type) -- [x] Agent dispatcher notifications: toast on agent_stopped (success), agent_error (error), sidecar crash (error), cost result (success with cost/turns) -- [x] Settings dialog: SettingsDialog.svelte modal (default shell, cwd, max panes, theme flavor) with settings-bridge.ts adapter -- [x] Settings backend: settings table (key/value) in session.rs, Tauri commands settings_get/set/list in lib.rs -- [x] Keyboard shortcuts: Ctrl+W close focused pane, Ctrl+, open settings dialog -- [x] CSS grid update: app.css grid-template-rows '1fr' -> '1fr auto' for status bar row -- [x] App.svelte: integrated StatusBar, ToastContainer, SettingsDialog components - -### Phase 6: Packaging + Distribution (2026-03-06) -- [x] Created install-v2.sh — build-from-source installer with 6-step dependency check process - - Checks Node.js 20+, Rust 1.77+, system libs (WebKit2GTK, GTK3, GLib, etc.) - - Prompts to install missing packages via apt - - Builds with `npx tauri build`, installs to ~/.local/bin/bterminal-v2 - - Creates desktop entry and installs SVG icon -- [x] Updated v2/src-tauri/tauri.conf.json: bundle targets ["deb", "appimage"], category, descriptions, deb depends, appimage settings -- [x] Regenerated all icons in v2/src-tauri/icons/ from bterminal.svg as RGBA PNGs (32x32, 128x128, 256x256, 512x512, .ico) -- [x] Created .github/workflows/release.yml — CI workflow triggered on v* tags - - Ubuntu 22.04 runner, caches Rust/npm deps - - Builds .deb + AppImage, uploads as GitHub Release artifacts via softprops/action-gh-release@v2 -- [x] Build verified: .deb (4.3 MB), AppImage (103 MB) both built successfully -- [ ] Tauri auto-update plugin deferred (needs signing key + update server) - -### Phase 5 continued: SSH, ctx, themes, detached mode, auto-updater (2026-03-06) -- [x] ctx integration: Rust ctx.rs (read-only CtxDb with SQLITE_OPEN_READ_ONLY), 5 Tauri commands (ctx_list_projects, ctx_get_context, ctx_get_shared, ctx_get_summaries, ctx_search), ctx-bridge.ts adapter, ContextPane.svelte (project selector, tabs for entries/summaries/search) -- [x] SSH session management: SshSession struct + ssh_sessions table in session.rs, 3 Tauri commands (ssh_session_list/save/delete), ssh-bridge.ts adapter, SshDialog.svelte (create/edit modal with validation), SshSessionList.svelte (grouped by folder, color dots) -- [x] TilingGrid SSH routing: SSH pane type routes to TerminalPane with shell=/usr/bin/ssh and constructed args array -- [x] Catppuccin theme flavors: themes.ts with all 4 palettes (Latte/Frappe/Macchiato/Mocha), theme.svelte.ts reactive store, SettingsDialog flavor dropdown, TerminalPane uses getXtermTheme(), persistence via SQLite settings -- [x] Detached pane mode: detach.ts utility (isDetachedMode, getDetachedConfig from URL params), App.svelte renders single pane in full-viewport without chrome when ?detached=1 -- [x] Syntax highlighting: highlight.ts with Shiki lazy singleton (13 preloaded languages, catppuccin-mocha theme), integrated into MarkdownPane and AgentPane text messages -- [x] Tauri auto-updater plugin: tauri-plugin-updater (Rust) + @tauri-apps/plugin-updater (npm) + updater.ts frontend utility -- [x] AgentPane markdown rendering: text messages now rendered as markdown with Shiki highlighting -- [x] New npm dependencies: shiki, @tauri-apps/plugin-updater -- [x] New Rust dependency: tauri-plugin-updater - -### Session: 2026-03-06 (continued) — Polish, Testing, Extras - -#### Terminal Copy/Paste + Theme Hot-Swap -- [x] Copy/paste in TerminalPane via Ctrl+Shift+C/V (attachCustomKeyEventHandler: C copies selection, V reads clipboard and writes to PTY) -- [x] Theme hot-swap: onThemeChange() callback registry in theme.svelte.ts, TerminalPane subscribes and updates term.options.theme on flavor change -- [x] All open terminals now update immediately when theme flavor changes - -#### Agent Tree Enhancements -- [x] Click tree node -> scroll to corresponding message (handleTreeNodeClick in AgentPane, scrollIntoView with smooth behavior) -- [x] Subtree cost display: yellow cost text below each tree node label (subtreeCost from agent-tree.ts, NODE_H increased from 32 to 40) -- [x] Each message div has id="msg-{msg.id}" for scroll targeting - -#### Session Resume -- [x] Follow-up prompt input appears after session completes or errors (if sdkSessionId exists) -- [x] startQuery(text, resume=true) passes resume_session_id to SDK via agent_query -- [x] Styled .follow-up input + button in done-bar and error-bar sections - -#### Pane Drag-Resize Handles -- [x] Splitter overlays in TilingGrid (positioned with fixed CSS, outside grid to avoid layout interference) -- [x] Column splitters: vertical bars between grid columns with mousemove drag -- [x] Row splitters: horizontal bars between grid rows with mousemove drag -- [x] customColumns/customRows $state override preset grid-template; reset on preset change -- [x] Supports 2-col, 3-col, and 2-row layouts with min 10% / max 90% ratio clamping -- [x] .dragging class disables user-select during drag; splitter hover shows accent color at 40% opacity - -#### Auto-Update Workflow Enhancement -- [x] release.yml: TAURI_SIGNING_PRIVATE_KEY + PASSWORD env vars passed to build step -- [x] Generates latest.json for auto-updater (version, pub_date, platform URL, signature from .sig file) -- [x] Uploads latest.json alongside .deb and .AppImage as release artifacts - -#### Deno Sidecar Evaluation -- [x] Created agent-runner-deno.ts proof-of-concept (Deno.Command for claude CLI, TextLineStream for NDJSON) -- [x] Same NDJSON protocol as Node.js version; compiles to single binary with deno compile -- [ ] Not yet integrated with Rust SidecarManager; needs real-world testing - -#### Testing Infrastructure -- [x] Vitest added: vitest ^4.0.18 dev dependency, vite.config.ts test config, npm run test script -- [x] sdk-messages.test.ts: tests for adaptSDKMessage() — init, text, thinking, tool_use, tool_result, cost, unknown types -- [x] agent-tree.test.ts: tests for buildAgentTree(), countTreeNodes(), subtreeCost() -- [x] Cargo: tempfile 3 dev dependency added -- [x] session.rs tests: SessionDb CRUD (sessions, SSH sessions, settings, layout), uses tempfile::tempdir() -- [x] ctx.rs tests: CtxDb error handling with missing database (conn=None) - -### Session: 2026-03-06 (continued) — Session Groups, Auto-Update Key, Deno Sidecar, Tests - -#### Auto-Update Signing Key -- [x] Generated Tauri signing keypair (minisign) -- [x] Set pubkey in tauri.conf.json updater.pubkey field (base64 encoded) -- [x] Private key to be stored as TAURI_SIGNING_PRIVATE_KEY GitHub secret by user - -#### Session Groups/Folders -- [x] Added group_name column to sessions table (session.rs, ALTER TABLE migration with pragma_table_info check) -- [x] Session struct: added group_name field with #[serde(default)] -- [x] SessionDb: update_group(id, group_name) method + save/list queries updated -- [x] Tauri command: session_update_group registered in lib.rs -- [x] Frontend: updateSessionGroup() in session-bridge.ts -- [x] Layout store: Pane.group? field, setPaneGroup(id, group) function in layout.svelte.ts -- [x] SessionList.svelte: grouped sidebar with collapsible headers (arrow + count), right-click to set group via prompt() -- [x] Svelte 5 snippet pattern used for paneItem to avoid duplication across grouped/ungrouped rendering - -#### Deno Sidecar Integration (upgraded from PoC) -- [x] SidecarCommand struct in sidecar.rs: { program, args } abstracts runtime choice -- [x] resolve_sidecar_command(): Deno-first resolution (checks agent-runner-deno.ts + deno availability), Node.js fallback -- [x] Both sidecar runners bundled in tauri.conf.json resources array -- [x] Graceful fallback: if Deno binary not found in PATH, falls back to Node.js with log warning - -#### E2E/Integration Tests -- [x] layout.test.ts (30 tests): addPane, removePane, focusPane, setPreset, autoPreset, getGridTemplate, getPaneGridArea, renamePaneTitle, setPaneGroup -- [x] agent-bridge.test.ts (11 tests): Tauri IPC mock pattern with vi.hoisted(), invoke/listen wrappers -- [x] agent-dispatcher.test.ts (18 tests): sidecar event routing, crash detection, vi.useFakeTimers() for async setTimeout -- [x] sdk-messages.test.ts rewrite (25 tests): removed unused ErrorContent import -- [x] E2E scaffold: v2/tests/e2e/README.md documenting WebDriver approach -- [x] Total: 104 vitest tests + 29 cargo tests, all passing - -Build status: TypeScript 0 errors, Rust 0 errors (1 pre-existing warning), all tests green. - -### Session: 2026-03-06 (continued) — Agent Teams / Subagent Support - -#### Agent Teams Frontend Support -- [x] Agent store: AgentSession extended with parentSessionId?, parentToolUseId?, childSessionIds[] for parent-child hierarchy -- [x] Agent store: createAgentSession() accepts optional parent param, registers bidirectional parent/child links -- [x] Agent store: findChildByToolUseId(parentId, toolUseId), getChildSessions(parentId) query functions -- [x] Agent store: removeAgentSession() cleans up parent's childSessionIds on removal -- [x] Agent dispatcher: SUBAGENT_TOOL_NAMES detection ('Agent', 'Task', 'dispatch_agent') on tool_call events -- [x] Agent dispatcher: spawnSubagentPane() creates child session + layout pane, auto-groups under parent title -- [x] Agent dispatcher: toolUseToChildPane Map routes messages with parentId to correct child pane -- [x] Agent dispatcher: handleAgentEvent() splits messages — parentId-bearing go to child panes, rest to parent -- [x] AgentPane: parent link bar (SUB badge + navigate-to-parent button) -- [x] AgentPane: children bar (chips per child subagent, status-colored, clickable to focus) -- [x] SessionList: subagent panes show '↳' icon instead of '*' - -Design: No separate sidecar process per subagent. Parent's sidecar handles all; routing is purely frontend based on SDK's parentId field. - -### Session: 2026-03-06 (continued) — Subagent Tests, Cost Aggregation, Signing Key - -#### Subagent Dispatcher Tests -- [x] 10 new tests in agent-dispatcher.test.ts for subagent routing: - - spawn subagent pane on Agent/Task tool_call - - skip non-subagent tool_calls (Read, etc.) - - deduplicate panes for same toolUseId - - reuse existing child session from findChildByToolUseId - - route messages with parentId to child pane - - route child init message (sets model, marks running) - - route child cost message (updates cost, marks done) - - fallback title when input has no prompt/name - - fallback group when parent pane not found -- [x] Total: 28 dispatcher tests (18 existing + 10 new), 114 vitest tests overall -- [x] New mocks added: mockCreateAgentSession, mockFindChildByToolUseId, mockAddPane, mockGetPanes, layout.svelte mock - -#### Subagent Cost Aggregation -- [x] getTotalCost(id) recursive helper in agents.svelte.ts — aggregates costUsd, inputTokens, outputTokens across parent + all children via childSessionIds -- [x] AgentPane done-bar: shows "(total: $X.XXXX)" in yellow when child sessions exist and total > parent cost -- [x] .total-cost CSS class: var(--ctp-yellow), 10px font-size - -#### TAURI_SIGNING_PRIVATE_KEY -- [x] Set via `gh secret set` on DexterFromLab/BTerminal GitHub repo +> Earlier sessions (2026-03-05 to 2026-03-06 early): see [progress-archive.md](progress-archive.md) ### Session: 2026-03-06 (continued) — Multi-Machine Architecture Design @@ -349,65 +99,52 @@ Design: No separate sidecar process per subagent. Parent's sidecar handles all; #### CLAUDE* Environment Variable Leak (critical fix) - [x] Diagnosed silent hang in agent sessions when BTerminal launched from Claude Code terminal -- [x] Root cause: Claude Code sets ~8 CLAUDE* env vars (CLAUDECODE, CLAUDE_ORIGPROMPT, CLAUDE_BASH_MAINTAIN_CWD, CLAUDE_BASH_SANDBOX_DIR, etc.) for nesting/sandbox detection. Previous fix only removed CLAUDECODE, but the CLI checks multiple indicators. -- [x] Fixed agent-runner.ts: replaced `{ ...process.env, CLAUDECODE: undefined }` with clean env object filtering out all keys starting with 'CLAUDE' -- [x] Fixed agent-runner-deno.ts: same approach, iterate Deno.env.toObject() and skip CLAUDE-prefixed keys -- [x] Pre-built dist/agent-runner.mjs already updated with the fix +- [x] Root cause: Claude Code sets ~8 CLAUDE* env vars for nesting/sandbox detection +- [x] Fixed both sidecar runners to filter out all keys starting with 'CLAUDE' ### Session: 2026-03-06 (continued) — Sidecar SDK Migration #### Migration from CLI Spawning to Agent SDK -- [x] Diagnosed root cause of silent agent sessions: claude CLI v2.1.69 hangs when spawned via child_process.spawn() with piped stdio (known bug: github.com/anthropics/claude-code/issues/6775) -- [x] Migrated agent-runner.ts from `child_process.spawn('claude', ...)` to `@anthropic-ai/claude-agent-sdk` query() function -- [x] Migrated agent-runner-deno.ts from `Deno.Command('claude', ...)` to `import { query } from "npm:@anthropic-ai/claude-agent-sdk"` -- [x] Added @anthropic-ai/claude-agent-sdk ^0.2.70 as npm dependency -- [x] SDK query() returns async iterable of messages — same format as CLI stream-json, so sdk-messages.ts adapter unchanged -- [x] Session stop now uses AbortController.abort() instead of process.kill() -- [x] CLAUDE* env var stripping preserved via SDK's `env` option in query() options -- [x] Updated sidecar.rs Deno permissions: added --allow-write and --allow-net (required by SDK) -- [x] Added build:sidecar script to package.json (esbuild bundle, SDK included) -- [x] SDK options: permissionMode configurable (default 'bypassPermissions'), allowDangerouslySkipPermissions conditional, 10 allowedTools -- [x] Tested standalone: SDK sidecar successfully produced agent output -- [x] All 114 vitest tests pass, Rust compiles clean +- [x] Diagnosed root cause: claude CLI v2.1.69 hangs with piped stdio (bug #6775) +- [x] Migrated both runners to @anthropic-ai/claude-agent-sdk query() function +- [x] Added build:sidecar script (esbuild bundle, SDK included) +- [x] SDK options: permissionMode configurable, allowDangerouslySkipPermissions conditional #### Bug Found and Fixed -- [x] AgentPane.svelte onDestroy calls stopAgent() on component unmount — kills running sessions when panes are switched/collapsed, not just when explicitly closed (FIXED: see below) +- [x] AgentPane onDestroy killed running sessions on layout remounts (fixed: moved to TilingGrid onClose) ### Session: 2026-03-06 (continued) — Permission Mode, AgentPane Bug Fix, SDK Bundling #### Permission Mode Passthrough -- [x] Added `permission_mode` field to AgentQueryOptions in bterminal-core/src/sidecar.rs -- [x] Added `permissionMode` to QueryMessage interface in both sidecar runners (agent-runner.ts, agent-runner-deno.ts) -- [x] SDK options now use dynamic permissionMode: defaults to 'bypassPermissions', supports 'default' mode -- [x] allowDangerouslySkipPermissions conditionally set based on permissionMode value -- [x] Added `permission_mode` to AgentQueryOptions in agent-bridge.ts frontend adapter +- [x] permission_mode field flows Rust -> sidecar -> SDK, defaults to 'bypassPermissions' #### AgentPane onDestroy Bug Fix -- [x] Removed onDestroy stopAgent() from AgentPane.svelte — it was killing running agents on layout remounts -- [x] Moved stop-on-close logic to TilingGrid.svelte onClose handler: checks pane type is 'agent' and session status is running/starting before stopping -- [x] Added comment in AgentPane explaining why onDestroy must NOT stop agents +- [x] Stop-on-close moved from AgentPane onDestroy to TilingGrid onClose handler #### SDK Bundling Fix -- [x] Removed `--external:@anthropic-ai/claude-agent-sdk` from esbuild build:sidecar script in package.json -- [x] SDK is now bundled into sidecar/dist/agent-runner.mjs (no external dependency at runtime) +- [x] SDK bundled into agent-runner.mjs (no external dependency at runtime) ### Session: 2026-03-07 — Unified Sidecar Bundle #### Sidecar Resolution Simplification -- [x] Consolidated sidecar from two runners (agent-runner-deno.ts + agent-runner.ts) to single pre-built bundle (dist/agent-runner.mjs) -- [x] resolve_sidecar_command() in bterminal-core/src/sidecar.rs: checks deno/node availability upfront, searches for dist/agent-runner.mjs only -- [x] Removed agent-runner-deno.ts from tauri.conf.json resources array (only agent-runner.mjs bundled) -- [x] Same .mjs bundle runs under both Deno and Node.js — no separate TS source needed at runtime -- [x] Error message now includes runtime availability note when neither deno nor node found -- [x] agent-runner-deno.ts file retained in repo for reference but no longer used by SidecarManager +- [x] Consolidated to single pre-built bundle (dist/agent-runner.mjs) running on both Deno and Node.js +- [x] resolve_sidecar_command() checks runtime availability upfront, prefers Deno +- [x] agent-runner-deno.ts retained in repo but not used by SidecarManager ### Session: 2026-03-07 (continued) — Rust-Side CLAUDE* Env Var Stripping #### Dual-Layer Env Var Stripping -- [x] Added CLAUDE* env var stripping in Rust SidecarManager (bterminal-core/src/sidecar.rs) -- [x] Uses env_clear() + envs(clean_env) on Command to strip all CLAUDE-prefixed vars before spawning sidecar process -- [x] This is the primary defense — ensures no CLAUDE* vars reach the sidecar regardless of JS runtime -- [x] JS-side stripping (agent-runner.ts/agent-runner-deno.ts via SDK `env` option) retained as defense-in-depth +- [x] Rust SidecarManager uses env_clear() + envs(clean_env) before spawn (primary defense) +- [x] JS-side stripping retained as defense-in-depth + +### Session: 2026-03-07 (continued) — Claude CLI Path Detection + +#### pathToClaudeCodeExecutable for SDK +- [x] Added findClaudeCli() to agent-runner.ts (Node.js): checks ~/.local/bin/claude, ~/.claude/local/claude, /usr/local/bin/claude, /usr/bin/claude, then falls back to `which claude`/`where claude` +- [x] Added findClaudeCli() to agent-runner-deno.ts (Deno): same candidate paths, uses Deno.statSync() + Deno.Command("which") +- [x] Both runners now pass pathToClaudeCodeExecutable to SDK query() options +- [x] Early error: if Claude CLI not found, agent_error emitted immediately instead of cryptic SDK failure +- [x] CLI path resolved once at sidecar startup, logged for debugging ### Next Steps - [ ] Real-world relay testing (2 machines) diff --git a/docs/task_plan.md b/docs/task_plan.md index 17ddb5a..8e7e3ee 100644 --- a/docs/task_plan.md +++ b/docs/task_plan.md @@ -152,6 +152,7 @@ See [phases.md](phases.md) for the full phased implementation plan. | Permission mode passthrough | AgentQueryOptions.permission_mode flows Rust -> sidecar -> SDK. Defaults to 'bypassPermissions', supports 'default'. Enables non-bypass agent sessions. | 2026-03-06 | | Stop-on-close in TilingGrid, not AgentPane | Removed onDestroy stopAgent() from AgentPane (fired on layout remounts). Stop logic moved to TilingGrid onClose handler — only fires on explicit user close. | 2026-03-06 | | Bundle SDK into sidecar | Removed --external flag from esbuild build:sidecar. SDK bundled into agent-runner.mjs — no runtime dependency on node_modules. | 2026-03-06 | +| pathToClaudeCodeExecutable | Auto-detect Claude CLI path at sidecar startup via findClaudeCli() (checks common paths + `which`). Pass to SDK query() options. Early error if CLI not found. | 2026-03-07 | ## Open Questions