Skip to content

refactor: architecture governance — unify atomicfile/tailcatpool/web engine, enforce layer boundaries, decompose god files - #1249

Merged
kyya merged 9 commits into
mainfrom
refactor/arch-governance
Nov 28, 2026
Merged

kyya merged 9 commits into
mainfrom
refactor/arch-governance

Conversation

@kyya

@kyya kyya commented Nov 28, 2026

Copy link
Copy Markdown

Note (REVIEW.md): This PR edits tools/verify/ (arch.go, arch_test.go, main.go, main_test.go) to add pure read-only Go package layer-boundary enforcement and generated-SSOT drift test triggers.

Problem

Across the codebase, several parallel implementations and oversized mixed-concern files had accumulated:

  1. Two copy-pasted tailcat client pools (internal/rex/remote.go and ios/tailnet/tailcat.go) had already drifted in cancel handling, close blocking, and HalfCloser forwarding (docs/lessons.md, tailcat: a connection open across a server restart keeps the dead client #751).
  2. 10+ hand-rolled atomic file writers across internal/* and root *.go had inconsistent safety (fixed .tmp races in internal/rex/remote.go, unchecked json.MarshalIndent error in internal/rexapi/lan.go, temp-file leak in brand_fetch.go, missing Windows rename retry).
  3. Dead code flagged by go run ./tools/verify -audit (extPane.kind, placeholderExt.kind), duplicated copyDir (internal/ext vs internal/iconpack), hand-rolled cmpOr/itoa, and scattered CLAUDE_CONFIG_DIR/CODEX_HOME/XDG_CONFIG_HOME resolution.
  4. Web client duplicated el() 12 times, openDB() twice, and ~95% of tailengine.ts/catengine.ts.
  5. Oversized mixed-concern files (state.go 3,452L, internal/rexapi/layout.go 2,130L, internal/cli/commands.go 1,656L) hindered navigability and parallel changes.
  6. Package layer boundaries and cross-platform SSOT drift (assets/brands.json, internal/rexproto/protocol.json) were not checked by tools/verify.

Change

  • Dead code & enforceable architecture (2f940b3f): Removed unused paneExt.kind() (extPane.kind, placeholderExt.kind) and orphan comments in browser.go; added tools/verify/arch.go (archBoundariesCheck, pure read-only go/parser check for leaf packages, internal/rex, and ios/tailnet boundaries) and SSOT drift triggers in tools/verify/main.go.
  • Canonical internal/atomicfile (2ea22008): Extracted Write, WriteSync, and WriteJSON (os.CreateTemp + Chmod + Windows retry Rename) and migrated all 10+ call sites, deleting old copies.
  • Canonical internal/tailcatpool (0b964add, eba32ae0): Unified desktop (internal/rex/remote.go) and iOS (ios/tailnet/tailcat.go + lifecycle.go) tailcat client pools into a single leaf package, deleting ~400 lines of duplicated pool code and ensuring lock-order safety (KeyFn invoked without holding Pool.mu; SetTailcatHosts unlocks tcMu before KeepOnly).
  • Shared backend & path helpers (1c1a1020): Exported streaming ext.CopyDir and migrated internal/iconpack, replaced cmpOr/itoa with stdlib cmp.Or/strconv.Itoa, and centralized XDGConfigHome/ClaudeConfigDir/CodexHome in internal/homedir.
  • Web deduplication (127b8ca9): Extracted web/src/dom.ts (el), web/src/idb.ts (openDB, fixing CRLF in catstore.ts), and web/src/wasmengine.ts (shared loader/socket/transport for tailengine.ts and catengine.ts, keeping separate on-demand chunks).
  • God-file decomposition (02e8d860, f795862c): Pure domain-boundary moves splitting state.go (3,452L → 1,465L) into float.go/paneattach.go/reconcile.go/panemove.go/notify.go, internal/cli/commands.go (1,656L → 936L) into hosts_cmd.go/remote_cmd.go/run_cmd.go, and internal/rexapi/layout.go (2,130L → 1,047L) into layout_spec.go/layout_focus.go/layout_blocks.go.

Test

  • Added unit tests for internal/atomicfile, internal/tailcatpool (verified with -race), internal/homedir agent config resolution, and tools/verify/arch.go (TestArchBoundariesRepo, TestArchBoundariesViolations).
  • Ran full go run ./tools/verify, go run ./tools/verify -audit, and go test -race ./internal/tailcatpool + go test ./internal/rex -run TestTailcat + go test ./ios/tailnet -run TestTailcat after independent review fixes.

Verified: go run ./tools/verify: gofmt passed; arch boundaries passed; vet linux passed; vet windows passed; vet darwin passed; build linux/amd64 passed; build linux/arm64 passed; build windows/amd64 passed; build darwin/arm64 passed; web typecheck passed; golangci-lint passed; web test passed; go test passed; go test root skipped; ios xcodebuild NOT VERIFIED

@kyya
kyya merged commit ebd692b into main Nov 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant