Repository navigation
CLI: client-side multi-database selection (ADR-053) - #1597
Conversation
Route CLI requests to a specific local database via the x-ns-database-id header and manage the daemon's database registry from the shell. - Add a concrete DatabaseIdInterceptor that stamps the x-ns-database-id routing header, plus intercepted client type aliases (NodeClient, ImportClient, SessionClient, LocalAgentClient) so the data-plane clients stay nameable. The connect* helpers now build clients through the interceptor, applied uniformly even when no database is selected. - Add a global --database <name|id> flag and NODESPACE_DATABASE env var. run() resolves the selection to a registry id once, against DatabaseService.List, before dispatching a data command; the daemon resolves the header as an id only, so names are resolved client-side. - Add `nodespace database list|create|register|remove|rename|use` backed by DatabaseService, with a shared name-or-id resolver that errors clearly on unknown or ambiguous selections. - Rewrite `nodespace diagnostics` to enumerate the registry and run the node/root/schema counts and size-on-disk against the targeted database instead of computing one path from the environment. - Document the flag, env var, and subcommands in SKILL.md. - Extend the CLI integration tests with an in-process routing daemon (DbManagerLayer + DatabaseService + NodeService) covering the registry round-trip, name-to-id resolution, and cross-database write isolation. Implements the client-side half of #1533. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE (confirming re-review) Independently reviewed the full diff against the merged daemon side. The implementation matches the ADR-053 design intent and I verified the contract against the daemon: Verified:
Two non-blocking review findings addressed in
Validation: |
|
APPROVE — the first real client of Verified
TestsStrong: the in-process routing harness ( Note (not a change request)
Merge gateCI |
Summary
Client-side (CLI) half of ADR-053 "One Daemon, Multiple Local Databases" (#1533). Now that the daemon serves N registered databases behind its socket (#1532), this lets the
nodespaceCLI target, create, and manage local databases — the first real client to exerciseDatabaseServiceandx-ns-database-idrouting end to end.This PR is the CLI slice only; the desktop switcher UI / stores / event filtering follow in separate PRs, so it does not close #1533.
Changes
DatabaseIdInterceptor(tonicInterceptor) stampsx-ns-database-idon every data-plane request. It's applied uniformly (even with no selection, where it stamps nothing and the daemon serves its default), so client types stay nameable via aliases (NodeClient,ImportClient,SessionClient,LocalAgentClient). Theconnect*helpers build clients through the interceptor.--database <name|id>/NODESPACE_DATABASE— a global selector resolved once per invocation, before dispatch, againstDatabaseService.List. The daemon resolves the header as an id only, so a name is resolved to its id client-side (exact-id match first, then a unique name match; clear errors on no-match and on ambiguous duplicate names). A--databasethat doesn't resolve fails before the command runs.nodespace database list|create|register|remove|rename|use— registry management overDatabaseService.removeunregisters only and says so (never deletes the file).usemaps toSetDefault(the CLI is stateless; the registry's default is the single source of truth). These subcommands operate on the registry globally and are never routed by--database.nodespace diagnosticsrewritten — enumerates the registry viaList(name, path, default marker, status per database) and runs the node/root/schema counts + size-on-disk against the targeted database (default or--database), instead of computing one path fromresolve_db_path().DbManagerLayer+DatabaseService+NodeServiceover UDS) covering the registry round-trip, name→id resolution, unregistered-selection error, and cross-database write isolation (a write routed to database B is invisible against the default database — no bleed).Validation
cargo fmt --checkclean;cargo clippy -p nodespace-cli --all-targets -- -D warningsclean.cargo test -p nodespace-cli— 5 unit + 14 integration, 0 failures.packages/cliconsumes thenodespace_clilibrary API, so the changedconnect*/diagnosticssignatures affect nothing else; the desktop app consumes the CLI only as a sidecar binary.Community build behavior is unchanged for existing invocations: with no
--database/NODESPACE_DATABASE, every command routes to the daemon's default database exactly as before.