Repository navigation
Description
Spun off from architectural-audit tracking issue #1228, finding C1 (five stacked wrappers around node CRUD). Verified against
mainon 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 definesinterface BackendAdapter, the input types, and three implementations —TauriAdapter(usesinvoke()),HttpAdapter(usesfetch()to the dev-proxy),MockAdapter(test no-ops) — selected bygetBackendAdapter()and exported as thebackendAdaptersingleton.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 bypassBackendAdapter(which is node-CRUD-shaped) and are consumed directly by components.
- Node-CRUD half (lines ~53–216): a pure pass-through facade — every function just calls
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.tsstays the single transport boundary.TauriAdapter,HttpAdapter,MockAdapterkeep their three implementations and thebackendAdaptersingleton. All node-CRUD marshaling andwithDiagnosticLoggingstay here — they already live inTauriAdapter; do not move them.tauri-commands.tsbecomes 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-adapterdirectly (backendAdapter.getNode(id)etc.), not through a facade. - Optional: rename
tauri-commands.ts→tauri-system-commands.tsto 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
backendAdapterimport 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 }, callbackendAdapter.getNode(id).services/navigation-service.ts— dynamicconst { getNode } = await import('./tauri-commands')→const { backendAdapter } = await import('./backend-adapter'), thenbackendAdapter.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 throughbackendAdapter. -
shared-node-store.svelte.tscallsbackendAdapter.*for all 7 node operations (notauriCommands.*). -
reactive-node-service.svelte.tsno longer importsmoveNodefromtauri-commands; it callsbackendAdapter.moveNode(...). -
node-card-inline.svelteandnavigation-service.tsimportgetNodeviabackendAdapter. - Non-node consumers unchanged in behavior; if the module was renamed, only their import paths changed.
-
TauriAdapterfield marshaling andwithDiagnosticLoggingunchanged and still applied to every node-CRUD call. -
bun run testandbun run checkpass with no new failures vs baseline.
Testing
- Adapter parity:
MockAdapter/HttpAdapter/TauriAdapterall still satisfyBackendAdapter;backend-adapter.test.tspasses unchanged. - Browser/HTTP mode must still work: the store and service now call
backendAdapter.*, which selectsHttpAdapteroutside Tauri. Verify no remaining node-CRUD path assumes Tauriinvoke. - No import breakage: ~10
backendAdapterimporters + the non-nodetauri-commandsimporters must all resolve.bun run checkcatches dangling imports. bun run test:allbefore 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→getMentioningContainersname mismatch: the old facade exposedgetMentioningRoots; the adapter method isgetMentioningContainers. No current consumer uses it outside the store, but grep before deleting.
Coordination
- Unblocked — both blockers are merged. C2 (C2: Make structureTree the single source of truth for hierarchy — unify dual sync paths + invariant check #1247) merged as C2: Make structureTree single source of truth — unify dual sync paths + invariant check #1250, and C2b (C2b: Remove the Node.parentId field entirely (follow-up to #1247) #1248) has merged. Both rewrote/finalized
shared-node-store.svelte.tsandreactive-node-service.svelte.ts(structureTree authoritative,Node.parentIdfield removed). This issue touches only the transport import paths in those two files, not their hierarchy/sync logic — minimal overlap, but pull latestmainbefore starting. - C3 (move ordering to daemon, not yet filed) will further change the move path; routing through
backendAdapter.moveNodehere is forward-compatible — it's the seam C3 builds on. - C1b (the "data-vs-hierarchy ownership split" from the audit) is intentionally NOT in this issue. It was too entangled with C2b/C3 to scope cleanly; now that C2/C2b have landed, re-audit the store/service boundary once C3 is filed, then file C1b against the settled data model. Tracked on Architectural audit (post-daemon + post-SQLite): structural findings & improvement plan #1228.
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
malibio commentedon May 30, 2026
Frontend baseline: 3922 passed (132 test files)
C1a: Consolidate the node-CRUD transport layer — fold tauri-commands …
C1a: Consolidate the node-CRUD transport layer — fold tauri-commands …