Skip to content

CLI and desktop app: multiple databases with a live, restart-free switcher #1533

Description

@malibio

Overview

Client-side counterpart of ADR-053 (../nodespace-docs/decisions/053-one-daemon-multiple-databases.md): once the daemon serves N databases (#1532), the CLI and Tauri app must let users target, create, and switch databases — live, with no daemon restart.

Problem Statement

The frontend has no database concept beyond a read-only display path. The File-menu "New Database… / Open Database…" flow writes a config value the daemon never reads, then shows a "restart required" notice — a silent no-op end to end. No Tauri command or gRPC call carries a database identifier.

Proposed Solution

Stamp the active database id on every gRPC call, add a switcher UI backed by the new DatabaseService, and delete the dead restart flow. CLI gains database selection flags and subcommands.

Implementation Approach

CLI

  • Global --database <name|id> flag and NODESPACE_DATABASE env var → sets x-ns-database-id metadata on every RPC; absent → default database.
  • nodespace database list|create|register|remove|rename|use subcommands over DatabaseService.
  • Update diagnostics (packages/cli/src/commands/diagnostics.rs) — it calls resolve_db_path() directly today; it must enumerate the registry instead.
  • Update the CLI SKILL.md for the new flags/subcommands (parity obligation with the local agent — see Align CLI + SKILL.md with local-agent capability and guidance (external-harness parity) #1529).

Desktop app

  • GrpcClient (src-tauri/src/grpc_client.rs) stamps x-ns-database-id from the frontend-supplied active database id on every call; single channel unchanged.
  • New database.svelte.ts store (Svelte 5 runes): registry list, active database id, status per database. Switching = set active id, flush and reload all data stores, resubscribe event streams filtered by database_id.
  • Switcher UI in the app chrome showing the active database and a per-entry glyph (local-only / synced). File menu "New Database… / Open Database…" re-wired to DatabaseService.Create/Register with a native folder picker for location.
  • Rewrite settings/sections/database-settings.svelte as database management (list, rename, set default, remove).
  • Delete: select_new_database, reset_database_to_default, restart_app restart flow, and the restartPending notice (src-tauri/src/commands/settings.rs, app-shell.svelte handler).
  • Frontend event listeners filter on database_id from the stream envelope.

Acceptance Criteria

  • User can create a second database from the UI and switch to it without any restart
  • Switcher shows all registered databases with active + sync-state indication
  • All data stores flush and reload on switch; no cross-database data bleed (test with distinct content per database)
  • nodespace --database <name> and NODESPACE_DATABASE route CLI commands to the named database
  • nodespace database subcommands work end-to-end
  • Dead restart flow and its commands are deleted
  • CLI SKILL.md documents the new database selection surface
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • gRPC client: packages/desktop-app/src-tauri/src/grpc_client.rs
  • Settings commands: packages/desktop-app/src-tauri/src/commands/settings.rs
  • Menu wiring: packages/desktop-app/src-tauri/src/lib.rs — menu-select-database event
  • Settings pane: packages/desktop-app/src/lib/components/settings/sections/database-settings.svelte
  • CLI diagnostics: packages/cli/src/commands/diagnostics.rs

Implementation Details

Dependencies

Related Issues

Non-Goals

Multi-window support; per-database sync UI states beyond the local/synced glyph (sync lifecycle is a follow-on issue).

Activity

  1. self-assigned this
    on Jul 7, 2026
  2. mstomar125 commented on Jul 7, 2026

    @mstomar125
    Contributor

    Not picked up today — hard-blocked by #1532.

    The DatabaseService proto, its generated CLI/desktop client stubs, the daemon database registry, and the x-ns-database-id routing + database_id event-envelope contract this ticket consumes do not exist until #1532 lands (the current daemon opens exactly one DB via resolve_db_path()). Even after #1532, the surface is multi-day: a per-call metadata interceptor, a new Tauri command module + menu rewire, a Svelte runes store flushing ~7 data stores + event re-filtering, a settings pane, a CLI database subcommand, and tests across three runners. Ordered after #1532.

  3. mstomar125 commented on Jul 9, 2026

    @mstomar125
    Contributor

    CLI half is up as #1597 — client-side database selection: the x-ns-database-id routing interceptor, the global --database <name|id> / NODESPACE_DATABASE selector (name→id resolved client-side against DatabaseService.List), the nodespace database list|create|register|remove|rename|use subcommands, and a diagnostics rewrite that enumerates the registry. SKILL.md documents the new surface; integration tests cover the registry round-trip, name→id resolution, ambiguity, and cross-database write isolation.

    Remaining for this issue (separate PRs, keeping #1533 open): the desktop half — GrpcClient stamping the active database id, a database.svelte.ts store, the switcher UI, File-menu Create/Register wiring, rewriting the Database settings pane as management, deleting the restart flow, and filtering frontend event listeners on database_id.

  4. mstomar125 commented on Jul 9, 2026

    @mstomar125
    Contributor

    Desktop half is up as #1598 — the sidebar-header database switcher: a DatabaseIdInterceptor stamping x-ns-database-id on the routed clients + set_active_database (rebuilds only the routed clients, bumps a generation watch), the database Tauri commands, a database.svelte.ts store (switch = flush → re-point → clear → reset → reload), the database-switcher.svelte dropdown (active db + local/synced glyph, New…/Open…), a database-settings.svelte management rewrite, and database_id event filtering. The watcher now rides the shared GrpcClient and re-opens WatchNodes on switch. restart_app (orphaned) removed.

    With this + the CLI half (#1597), ADR-053 client selection is functional end to end. Known follow-on hardening: per-request database tagging to close the in-flight-read orphan window on a switch; and a manual GUI click-test on a build with two registered databases.

  5. mstomar125 commented on Jul 9, 2026

    @mstomar125
    Contributor

    Resolved — client-side multi-database selection is functional end to end

    Both halves are merged: the CLI (#1597) and the desktop app (#1598). Every acceptance criterion is met.

    Acceptance criteria

    PRs

    Follow-on (non-blocking, tracked separately)

    • Per-request database tagging to close the in-flight-read orphan window during a switch (a read dispatched against the old database whose response resolves after the cache clear can leave orphan nodes until the next reload).
    • A manual GUI click-test on a build with two registered databases (headless CI can't exercise the visual switch flow) — deferred to a local run.

    Closing as complete. Non-goals (per this issue) remain follow-ons: per-database compute scoping (#1534), per-database cloud sync (#1535), tray/multi-window polish (#1536), registry-driven Pro UI (#1537).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions