Collapse the duplicated declarations before the fleet store adds a fifth #176
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lz/agent-nexus#176
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A simplification audit of the two MCP specs found ~290 lines removable today, independent of either spec, of which ~175 is pure declaration collapse at near-zero risk. This issue is that work.
It is sequenced first deliberately. The fleet status layer adds a fifth declaration of the workspace and session shapes, a fifth spelling of the
healthy | unhealthy | unknownunion (already written four times), and a new SSE wire shape. Collapsing afterwards means editing five copies instead of one, and every parity test that would otherwise have to be written is a test that cannot exist once there is a single declaration.A1 — the server re-declares the wire shapes (~−82)
lib/api/types.tsis canonical and browser-safe, and has zero imports (verified; positive control:lib/attention.tshas 2). The server already imports from it at runtime —db/schema.ts, andmcp/projection.tspullsWORKER_STATUSES/SESSION_STATUSESas values.Duplicates to delete, each replaced by an import:
lib/server/workers/service.ts:48WorkerDTOlib/server/workers/service.ts:686WorkerHealthReport(canonical:WorkerHealthDTO)lib/server/sessions/service.ts:21SessionDTOlib/server/sessions/service.ts:1079lib/server/previews/types.ts:5PreviewDTOvslib/api/types.ts:172— unguarded by any parity test, so confirm they are actually identical before collapsingThen delete
lib/api/worker-dto-parity.test.ts.The duplication's stated justification is false. That test's docblock claims "neither can import the other". Only one direction is illegal. Server importing a browser-safe module is legal and shipped; the reverse is also shipped — eight client files
import typefrom$lib/server/artifacts/types, which is whyArtifactDTOis declared once while everything else is declared twice.Do not touch
MountSpec/MOUNT_KINDS/DEFAULT_NFS_OPTIONS, the token scope set,McpStatusDTO,CimdClientDTO— AGENTS.md names those as deliberate, and their canonical copies are under$lib/serverand/or are runtime values the browser needs.The gate is
pnpm typecheck(svelte-check), NOTpnpm build.vite.config.tscarries onlysveltekit()andscripts/build-server.mjsis a bare esbuild bundle; both strip types without checking. A green build over a broken DTO reads as success. Negative control: add a field to the canonicalWorkerDTO, confirmpnpm typecheckgoes red insideworkerRowToDTO.A2 — one
sessionBasePath(kind, worktreeName)(~−40)The worktree path formula is written out eight times outside
sessions/service.ts— six server routes, plus the client copy atlib/components/main-page/scope.ts:45whose own comment already complains it "was written out identically in four places".New
src/lib/session-path.ts, outside$lib/server(thegit-ref.ts/cimd-url.ts/workspace-state.tsprecedent) soscope.tsconsumes the same implementation.Hazard to preserve: the call sites do not agree on how they ask. Five test
worktreeName === 'workspace'(a NAME test);submit/+server.tstestssess.kind === 'workspace_shell'(a KIND test). They agree only becausecreateSessionreserves the nameworkspace. Take the kind as the parameter and pin that akind='session'row namedworkspaceis impossible.A3 —
ATTENTION_STATESdeclared twice (~−37)lib/server/sessions/attention.ts:14andlib/api/types.ts:130, pinned by a parity test. Server becomes a one-line re-export; the parity test goes.hooks-parity.test.tsand thez.enum(ATTENTION_STATES)onPOST /api/agent/eventsmust keep resolving and keep proving the set.A4 — five private
readJsonBodycopies (~−35)lib/server/lib/http.tsexports it and 17+ routes import it. Byte-identical private copies insettings/mounts,workers,workers/[id]/sessions,auth/setup,connections. Verify each is genuinely identical first.Cheap prerequisites worth folding in
WorkerHealthDTOfields —containerState,tmuxRunning,recentLogshave zero.sveltereaders (positive control:degradedhits six components). This also removes atailLogscall per poll. Do it before the fleet store: if they survive into the store they also reachGET /api/workers, which is mapped inTOKEN_ROUTESand is projected bymcp/projection.ts— an API-visible removal instead of an internal one.execProbeand the 20-iteration exit-code poll (execProbeexists twice; the poll four times) so the fleet layer's residual prober inherits one copy.Rejected, recorded so it is not reproposed
Workspace/Sessionclasses. Nothing is deleted by it, and the natural implementation is a module-level registry keyed by id — which exists twice, once per bundle, with neither build warning (facts #25, #31).lib/workspace-state.tsand computingrunning/readyserver-side. Makesprojection.test.ts's generated equivalence suite vacuous (w.running === w.running).SessionHealthDTO.windowPresent.SettingsPanel.svelte:263reads it; without it a normally-exited agent paints red.configparameter to asingletonsimport. Breaks the DI atretry.test.ts:57andspawn-mounts-dto.test.ts, and adds a cross-bundle cycle surface. Worth recording that 4 of 6 sites are pure pass-through so it is not rediscovered.Done when
One declaration per shape,
pnpm typecheckproven to catch a divergence by negative control, and every deleted test accompanied by a statement of why the property it protected is now structurally impossible rather than merely untested.