Loom Core docs
2026-02 Architecture and Refactor Opportunities
Status: In Progress
Reviewed: 2026-02-17
Window: Commits since 2026-02-15
Executive Summary
The last two days delivered major capability wins (OAuth/RBAC/audit/cost, HUD M3/M4 completion, devbox backend shifts), but the same period shows concentrated churn in a small set of large files. The Feb 17 commit (8c2c50d) already started the daemon call-pipeline and shared agent-contract refactor, so the next focus is to harden and finish those seams before expanding Tier 3 scope.
Tracking
- Harden daemon tool-call pipeline extraction
- Finish agent contract convergence across HUD/CLI/bridge
- Split PresencePanel into feature modules
- Decompose devbox K8s backend responsibilities
- Reduce HUD dist artifact churn
Evidence Snapshot
- 41 commits landed since 2026-02-15.
- Top churn areas:
internal/hud(187 touches),internal/daemon(49),internal/tui(26),cmd/loom(21). - Most frequently touched files in this window include:
internal/hud/frontend/dist/index.html(12)internal/hud/app.go(6)internal/daemon/daemon.go(7)internal/hud/frontend/src/lib/components/PresencePanel.svelte(6)internal/hud/frontend/src/lib/components/TasksPanel.svelte(6)
Priority Opportunities
1) Harden extracted daemon call pipeline (P0)
Why now
- Stage 1 has landed in
8c2c50d:handleCallnow delegates throughinternal/daemon/callpipeline.go. - Remaining risk is correctness drift and future coupling: side effects (audit/cost/cache/metrics) are still tightly bound to daemon internals and need stronger stage-level tests.
Refactor target
- Keep
handleCallorchestration thin indaemon.goand continue decomposing the pipeline internals:- isolate side effects (
audit,cost, cache stats) behind stage helpers - standardize error mapping per stage (parse/auth/cache/route/transport)
- add focused tests for send/recv failure and fallback behavior without touching full daemon boot paths
- isolate side effects (
Definition of done
internal/daemon/callpipeline.gohas unit coverage for all failure classes.internal/daemon/daemon.gocall-path churn drops materially versus previous week.- Existing daemon integration tests remain green.
2) Finish agent contract convergence across HUD/CLI/bridge (P0)
Why now
- Stage 1 has landed in
8c2c50d: shared contracts were introduced ininternal/hud/bridge/agent_contracts.goand adopted for context-inspect + nudge policy surfaces. - Remaining churn is concentrated in still-large surfaces (
internal/hud/bridge/agent.goat 1773 LOC,cmd/loom/cmd_agent.goat 1117 LOC,internal/hud/api_agent.goat 912 LOC).
Refactor target
- Continue contract unification by concern:
- split
cmd/loom/cmd_agent.gosubcommands into per-feature files (context,nudge,dispatch,session) - split
internal/hud/bridge/agent.gointo feature files while retaining one exported bridge API - align error envelope and status-code mapping between HUD handlers and CLI fallback paths
- split
Definition of done
- Cross-surface contracts live in one place and are reused by HUD handlers and CLI.
- Duplicate request parsing/error messages are removed from HUD/CLI leaf paths.
- Negative-path tests cover HTTP and daemon fallback for each shared contract.
3) Split PresencePanel.svelte by feature modules (P1)
Why now
internal/hud/frontend/src/lib/components/PresencePanel.svelteis 1782 LOC and currently owns handoffs, dispatch, nudges, claim bulk actions, diagnostics polling, and policy mutation UI.- This combines unrelated state machines and makes incremental changes risky.
Refactor target
- Break into focused components/stores:
PresenceAgentsTabPresenceClaimsTabPresenceWorktreesTabPresenceHandoffsTabPresenceDiagnosticsTab
- Move API calls into typed client utilities (shared with other panels where possible).
Definition of done
- Parent panel owns tab routing only.
- Each tab has isolated state and tests for polling/mutation behavior.
4) Decompose devbox K8s backend responsibilities (P1)
Why now
internal/devbox/backend/k8s.go(760 LOC) handles configmap lifecycle, build pod specs, wait/poll logic, log parsing, exec wiring, and Kubernetes object construction.- Recent Kaniko -> Buildah and watch-related changes were fast-moving and concentrated here.
Refactor target
- Split by concern:
k8s_build.go(image build path)k8s_runtime.go(start/stop/exec/status)k8s_objects.go(pod/configmap spec builders)k8s_wait.go(watch/poll helpers)
Definition of done
- Build flow and runtime flow test independently.
- Monorepo/NFS path assumptions tested in isolated unit tests.
5) Reduce generated HUD dist churn in feature commits (P2)
Why now
- Dist artifacts are being touched repeatedly alongside feature commits, which increases review noise and obscures behavior changes.
Refactor target
- Decide one policy and enforce it:
- always separate
distregeneration commit, or - generate/verify dist in CI and avoid frequent checked-in rebuild noise.
- always separate
Definition of done
- Team follows one documented policy in
docs/DEV_BUILD_LIFECYCLE.md. - CI verifies policy adherence.
Recommended Focus Order (Next 2 Weeks)
- Week 1: Lock in P0 refactor gains
- Harden
callpipelinewith stage-focused tests and error-mapping cleanup. - Finish contract convergence split for
cmd/loom/cmd_agent.goandinternal/hud/bridge/agent.go.
- Harden
- Week 1.5: Close coverage gap for Issue #2
- Add daemon lifecycle contention/cleanup coverage.
- Add devbox Docker+K8s integration coverage on monorepo/NFS paths.
- Week 2: Observability + UI decomposition
- Execute Issue #12 OTel daemon export pass atop the stabilized call pipeline.
- Split
PresencePanel.svelteinto tab modules to unblock Fleet orchestration UX (Issue #13).
Sources
- Commands run:
git rev-list --count --since='2026-02-15 00:00' HEADgit log --since='2026-02-15 00:00' --pretty=format: --name-only | ... | sort | uniq -c | sort -nrgit log --since='2026-02-15 00:00' --oneline -- <hotspot files>wc -l internal/daemon/*.go internal/hud/*.go internal/hud/bridge/*.go cmd/loom/*.gowc -l internal/hud/frontend/src/App.svelte internal/hud/frontend/src/lib/components/*.svelte ...
- Code references:
internal/daemon/daemon.go:1482internal/daemon/callpipeline.go:1internal/hud/api_agent.go:81internal/hud/api_agent.go:580internal/hud/api_agent.go:665cmd/loom/cmd_agent.go:400cmd/loom/cmd_agent.go:734cmd/loom/cmd_agent.go:816internal/hud/bridge/agent.go:968internal/hud/frontend/src/lib/components/PresencePanel.svelte:21internal/hud/frontend/src/lib/components/PresencePanel.svelte:355internal/devbox/backend/k8s.go:115internal/devbox/backend/k8s.go:507ROADMAP.md:103ROADMAP.md:123