Skip to content

C1a: Consolidate the node-CRUD transport layer — fold tauri-commands node half into backendAdapter #1251

Closed

Description

@malibio

Spun off from architectural-audit tracking issue #1228, finding C1 (five stacked wrappers around node CRUD). Verified against main on 2026-05-30; the audit's line counts and its "merge backend-adapter + tauri-commands" framing were partly wrong and are corrected below. This is C1a (the concrete transport-consolidation half); the audit's "data-vs-hierarchy ownership split" is deferred as C1b — see Coordination.

Problem

The audit described a clean stack tauri-commands.ts → backend-adapter.ts → shared-node-store → reactive-node-service and said "merge the transport layers." The real picture (verified):

  • services/backend-adapter.ts (682 lines) is the actual transport layer: it defines interface BackendAdapter, the input types, and three implementations — TauriAdapter (uses invoke()), HttpAdapter (uses fetch() to the dev-proxy), MockAdapter (test no-ops) — selected by getBackendAdapter() and exported as the backendAdapter singleton.
  • services/tauri-commands.ts (548 lines) has two unrelated halves:
    • Node-CRUD half (lines ~53–216): a pure pass-through facade — every function just calls backendAdapter.* (e.g. getChildren → backendAdapter.getChildren). This is a redundant fourth wrapper that adds nothing.
    • Non-node half (lines ~236–547): direct invoke() wrappers for local-agent, chat-model, PTY, capture-settings, and agent-availability commands. These legitimately bypass BackendAdapter (which is node-CRUD-shaped) and are consumed directly by components.

So the redundancy the audit flagged is specifically the node-CRUD pass-through half of tauri-commands.ts. The fix: delete that half and route its consumers straight at backendAdapter, leaving tauri-commands.ts as the non-node Tauri-command module only.

One inconsistency to clean up: services/reactive-node-service.svelte.ts:37 imports moveNode from ./tauri-commands instead of calling backendAdapter.moveNode like all its sibling calls. Note: this is NOT a correctness bug — that moveNode facade itself delegates to backendAdapter, so browser/HTTP mode works today — but it is an inconsistent access path to normalize as part of this cleanup.

Target architecture

  • backend-adapter.ts stays the single transport boundary. TauriAdapter, HttpAdapter, MockAdapter keep their three implementations and the backendAdapter singleton. All node-CRUD marshaling and withDiagnosticLogging stay here — they already live in TauriAdapter; do not move them.
  • tauri-commands.ts becomes non-node Tauri commands only (local-agent, chat-model, PTY, capture-settings, availability). Its node-CRUD functions and node-type re-exports are deleted.
  • Node-CRUD consumers import from backend-adapter directly (backendAdapter.getNode(id) etc.), not through a facade.
  • Optional: rename tauri-commands.ts → tauri-system-commands.ts to reflect its narrowed role (removes the misleading "all Tauri commands" implication). If renamed, update all importers. Lower-risk alternative: keep the filename, just empty out the node half. Either is acceptable.

File-by-file changes

services/tauri-commands.ts — delete the node-CRUD half and node-type re-exports:

  • Remove functions (~lines 53–216): createNode, getNode, updateNode, updateTaskNode, deleteNode, getChildren, getDescendants, getChildrenTree, moveNode, createMention, deleteMention, getOutgoingMentions, getIncomingMentions, getMentioningRoots, queryNodes, mentionAutocomplete, createContainerNode.
  • Remove the backendAdapter import and the node-type re-export block.
  • Keep everything from ~line 218 onward (the isTauri() helper, local-agent, chat-model, PTY, capture-settings, availability commands and their interface exports). Untouched.

services/backend-adapter.ts — no logic change required. TauriAdapter.createNode (~137–152) and createContainerNode (~308–321) keep their camelCase marshaling; all methods keep withDiagnosticLogging. The insertPosition factory + InsertPosition type already live here.

services/shared-node-store.svelte.ts — currently import * as tauriCommands from './tauri-commands' (~line 28), using 7 node functions: createNode, deleteNode, getChildren, getChildrenTree, getNode, updateNode, updateTaskNode. Replace with import { backendAdapter } from './backend-adapter' and swap each tauriCommands.X(...) → backendAdapter.X(...).

services/reactive-node-service.svelte.ts — remove import { moveNode as moveNodeCommand } from './tauri-commands' (line 37) and call backendAdapter.moveNode(...) at the existing moveNodeCommand(...) call site(s). It already imports the InsertPosition type from backend-adapter (line 38); add the backendAdapter value import if not already present.

Component / service consumers of the node-CRUD half — repoint to backend-adapter:

  • components/chat/node-card-inline.svelte — import { getNode } from '$lib/services/tauri-commands' → import { backendAdapter }, call backendAdapter.getNode(id).
  • services/navigation-service.ts — dynamic const { getNode } = await import('./tauri-commands') → const { backendAdapter } = await import('./backend-adapter'), then backendAdapter.getNode(...).

Non-node component importers — DO NOT TOUCH. These import the non-node half and keep working as-is: design/components/base-node.svelte, stores/model-store.svelte.ts, stores/agent-store.svelte.ts, components/agent/pty-terminal.svelte, the three components/viewers/ai-chat-*.svelte files. If you rename tauri-commands.ts, update these import paths but change nothing else.

Tests — move mocks/spies from the node-CRUD facade to backend-adapter:

  • tests/services/shared-node-store.test.ts, shared-node-store-coverage.test.ts, shared-node-store-extended.test.ts, integration/rapid-hierarchy-operations.test.ts — spyOn(tauri-commands, 'getChildrenTree'|'getNode'|...) → vi.spyOn(backendAdapter, ...).
  • tests/services/tauri-commands.test.ts — reduce to the non-node commands that remain (or rename alongside the module).
  • tests/services/backend-adapter.test.ts — already exercises the adapters; should pass unchanged.

Acceptance criteria

  • Node-CRUD functions removed from tauri-commands.ts; the file exports only non-node Tauri commands.
  • No production node-CRUD code path imports tauri-commands; all route through backendAdapter.
  • shared-node-store.svelte.ts calls backendAdapter.* for all 7 node operations (no tauriCommands.*).
  • reactive-node-service.svelte.ts no longer imports moveNode from tauri-commands; it calls backendAdapter.moveNode(...).
  • node-card-inline.svelte and navigation-service.ts import getNode via backendAdapter.
  • Non-node consumers unchanged in behavior; if the module was renamed, only their import paths changed.
  • TauriAdapter field marshaling and withDiagnosticLogging unchanged and still applied to every node-CRUD call.
  • bun run test and bun run check pass with no new failures vs baseline.

Testing

  • Adapter parity: MockAdapter/HttpAdapter/TauriAdapter all still satisfy BackendAdapter; backend-adapter.test.ts passes unchanged.
  • Browser/HTTP mode must still work: the store and service now call backendAdapter.*, which selects HttpAdapter outside Tauri. Verify no remaining node-CRUD path assumes Tauri invoke.
  • No import breakage: ~10 backendAdapter importers + the non-node tauri-commands importers must all resolve. bun run check catches dangling imports.
  • bun run test:all before PR.

Risks

  • Rename churn: if you rename tauri-commands.ts, ~8 non-node importers + several test files change paths. Prefer the rename only if clean; otherwise keep the filename and empty the node half.
  • Test mock surface shift: the largest mechanical cost is moving spyOn(tauri-commands, ...) → spyOn(backendAdapter, ...) across the store test files. These guard OCC/sync behavior — do it carefully.
  • getMentioningRoots → getMentioningContainers name mismatch: the old facade exposed getMentioningRoots; the adapter method is getMentioningContainers. No current consumer uses it outside the store, but grep before deleting.

Coordination

Standard NodeSpace startup / PR sequence

git status + git pull origin main on primary checkout, then EnterWorktree({name: "issue-<N>-c1a-transport-consolidation"}). Inside the worktree: bun install, bun run test (baseline), bun run gh:comment <N> "Frontend baseline: X passed", bun run gh:assign <N> "@me", bun run gh:status <N> "In Progress". Use createLogger (no raw console.*), no any, no lint suppression, bun run test (NEVER bun test). Before PR: bun run test:all (no new failures), bun run check, bun run quality:fix + commit (then git status, revert unrelated reformats). bun run gh:pr <N>. Run /pragmatic-code-review. After approval: gh pr view <PR#>, ExitWorktree({action: "remove", discard_changes: true}), gh pr merge <PR#> --squash --delete-branch, git pull origin main, bun run gh:status <N> "Done".


Spun off from #1228 (architectural audit), finding C1 (the C1a transport-consolidation half).

Activity

  1. malibio commented on May 30, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 3922 passed (132 test files)

  2. self-assigned this
    on May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions