Skip to content

refactor: decompose the well-traveled code paths (exploration 0276) - #401

Merged
crs48 merged 19 commits into
mainfrom
claude/0276-well-traveled-code-paths-churn-weighted-refactor
Jul 7, 2026
Merged

refactor: decompose the well-traveled code paths (exploration 0276)#401
crs48 merged 19 commits into
mainfrom
claude/0276-well-traveled-code-paths-churn-weighted-refactor

Conversation

@crs48

@crs48 crs48 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Implements exploration 0276 — a churn-weighted refactor of the hottest files in the repo. Behavior-preserving decompositions with test protection at every seam.

Theme 1 — data layer (rank 1/3/7 hotspots)

  • sqlite-adapter.ts 4,407 → 3,087 lines: query compiler (query-compiler.ts), dual-mode hydration (hydration.ts), SQL batching helpers, and the three index families (indexing/ behind IndexingStrategy) extracted; emitted SQL verified byte-identical.
  • store.ts 2,763 → ~2,100: transaction executors + deterministic-import orchestration moved behind one narrow WriteExecutionHost seam.
  • One LWW ordering (@xnetjs/core lww.ts, protocol §L1.7) now backs shouldReplace, both SQL ON CONFLICT guards, and change application order — previously implemented 3×. Fixes hub memory storage ordering lamport ties with localeCompare (diverged from SQLite storage + clients). Cross-implementation golden-vector conformance suite added.
  • Reliability lane green (fault injection, restore drills, sim).

Theme 2 — hub server (highest-churn non-barrel file)

  • server.ts 1,750 → 888 lines: the 600-line WebSocket if/else pump becomes an ordered handler registry (src/ws/ + 7 handler modules) with one room-auth path, one error shape, per-message-type metrics — wire behavior unchanged, plus the previously-missing pump-level tests.

Theme 3 — stop web/electron drift

  • usePageComments extracts the ~800-line verbatim comment subsystem both PageViews carried with zero shared commits (web 1,101→701, electron 993→481). Electron-only caret-exit dismiss preserved behind an option; its latent unconditional docId-reset converges on web's guarded variant.
  • DataWorkspaceCore shares the 92%-identical workspace logic (1,060→65 / 1,189→96) with platform deltas as options.
  • scripts/check-view-drift.mjs tripwire warns when one side of a known duplicated pair changes without its twin.
  • CanvasView parity audit spawned as a separate product-decision task (gates full convergence, per 0230 Phase 5).

Theme 4 — provider + shell ergonomics

  • XNetProvider (context.ts 1,213 → ~700) split into provider/ units: init, runtime resolution, hub auth, sync/backup lifecycle, search indexing — with failure-path tests.
  • Web App.tsx 1,009 → 401 (boot orchestrator hooks); electron App.tsx 1,193 → 353 (pure shell reducer + document/palette hooks).
  • Sub-barrel export policy for the 90/87/47-commit barrels documented in CLAUDE.md.

Opportunistic

  • ai-surface: 25 characterization tests first (mutation/rollback/audit had zero), then tool registry + resource URI router — adding a tool now edits one file, not three.
  • CanvasV3: pure viewport math + scene-mutation dispatcher extracted with direct tests.

Validation

Build 52/52 · typecheck 91/91 · tests 10,305 passed (947 files) · reliability lane 20/20 · changeset: core minor (new lww exports), data/plugins/react patch (internal only).

🤖 Generated with Claude Code

xNet Test and others added 18 commits July 6, 2026 15:03
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
One comparator for per-property LWW and change-application order
(lamport, wallTime, author by UTF-16 code units — protocol §L1.7),
plus the SQL ON CONFLICT guard builder, so store/adapter/hub stop
re-implementing the convergence invariant.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…t core LWW (0276)

sqlite-adapter.ts sheds its three heaviest aggregations behind
delegate seams: query-compiler.ts (descriptor→SQL + fused CTE,
flags as explicit inputs), hydration.ts (joined + aggregated modes
sharing one node scaffold), sql-batching.ts (arity buckets/chunking).
store.ts shouldReplace and applyRemoteChanges ordering now delegate
to @xnetjs/core lww; both node_properties ON CONFLICT guards use the
shared SQL builder. Adds compiler unit tests and the cross-
implementation LWW conformance suite (0200 golden ordering).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s (0276)

server.ts drops from 1,750 to 888 lines: the 600-line if/else pump
becomes an ordered handler registry (packages/hub/src/ws/) with one
room-auth resolution path (authorize.ts), one WS error shape
(errors.ts), and per-message-type metrics in dispatch. Wire behavior
unchanged; adds the previously-missing pump-level tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… order (0276)

getNodeChangesSince sorted lamport ties with localeCompare, diverging
from the SQLite storage's BINARY collation and the client's code-unit
tiebreak on case-mixed author DIDs (locale collation is also
non-deterministic across ICU versions). Adopts
compareChangeApplicationOrder from @xnetjs/core and pins the ordering
with a conformance test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…aracterization tests first (0276)

Adds 25 characterization tests pinning tool names/scopes/schemas, the
page-mutation plan→apply→rollback round-trip, audit-log recording, and
every resource URI family — the mutation/rollback path previously had
zero coverage. Then extracts tool definitions+handlers into
self-contained entries (tools/) and readResource string parsing into a
declarative router (resources/). Barrel and public API unchanged;
adding a tool now edits one file instead of three.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…from NodeStore (0276)

Both transaction paths (per-operation slow path, preflight+applyNodeBatch
fast path) and the deterministic-import planner/applier move to
transaction-executor.ts / batch-write-orchestrator.ts, running on one
narrow WriteExecutionHost capability seam. Conflict tracking and event
dispatch are shared by construction. store.ts drops to 2,491 lines
(from 2,763 pre-0276).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
context.ts drops from 1,213 to ~700 lines: initialization (storage →
NodeStore → runtime bridge incl. StrictMode teardown), runtime-bridge
resolution + fallback policy, hub UCAN auth, sync/backup lifecycle,
bridge wiring, hub status, and search indexing each move to
packages/react/src/provider/ hooks with explicit inputs. Behavior
unchanged (existing worker-fallback/fail-closed tests pass); adds
auth-unit failure-path tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…her from CanvasV3 (0276)

viewport-math.ts (240 lines of pure coordinate/rect transforms, now
directly tested) and scene-mutations.ts (the shared doc.transact →
iterate → onSceneMutation pattern behind applyPosition/Lock/Properties
updates) move out of the 7.7k-line CanvasV3.tsx. All 938 canvas tests
green. Adds the branch changeset (core minor for the new lww exports;
data/plugins/react internal-only patches).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…dapter (0276)

The three index families move to store/indexing/ behind a shared
IndexingStrategy interface (sync/rebuild/plan per family), with
table-existence memos owned by each family instance. Adapter drops
3,712 -> 3,087 lines; emitted SQL verified byte-identical; public API
unchanged. 250 store tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… from App.tsx (0276)

Web App.tsx (1,009 -> 401 lines): the boot state machine, the ~280-line
storage-init effect, the three durability watchers, and the PWA install
prompt move to apps/web/src/boot/ hooks. Electron App.tsx (1,193 -> 353):
ShellState becomes a pure dispatch-table reducer with the overlay
transition-timer semantics preserved, and document/palette handlers move
to apps/electron/src/renderer/shell/ hooks. 777 app tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…across web/electron (0276)

usePageComments (packages/editor) absorbs the ~800-line verbatim comment
state machine both PageViews carried with zero shared commits: popover
state/grace timers, mark restoration, orphaned-thread assembly, and all
action handlers. Electron's caret-exit dismiss survives behind an
option; its unconditional docId-reset (latent mount bug) converges on
web's guarded variant. DataWorkspaceCore (packages/views) hosts the 92%-
identical workspace logic with platform deltas as options (canvas-frame
insert on electron, feed enrichment + moderation gate on web).
PageView: 1,101->701 (web) / 993->481 (electron). DataWorkspaceView:
1,060->65 / 1,189->96. 3,580 tests green across editor/electron/dom.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
check-view-drift.mjs warns when a diff touches one side of a known
duplicated view pair without its twin (9 pairs); --strict exits 1.
Wired as pnpm check:view-drift.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…(0276)

The security regression greps App.tsx source; the hub-session URL
handling it pins moved to apps/web/src/boot/use-boot-sequence.ts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@crs48
crs48 temporarily deployed to pr-401 July 6, 2026 23:41 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Preview removed for PR #401.

github-actions Bot added a commit that referenced this pull request Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🖼️ UI changes in this PR

Interactions

🎬 Open a canvas

Open a canvas

▶ Watch MP4

🎬 Create a page and use the editor

Create a page and use the editor

▶ Watch MP4

Auto-captured by CI · run. Informational — not a blocking check.

github-actions Bot added a commit that referenced this pull request Jul 6, 2026

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallow found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@crs48
crs48 temporarily deployed to pr-401 July 6, 2026 23:58 — with GitHub Actions Inactive
github-actions Bot added a commit that referenced this pull request Jul 7, 2026
@crs48
crs48 merged commit d3d1c6e into main Jul 7, 2026
16 of 19 checks passed
@crs48
crs48 deleted the claude/0276-well-traveled-code-paths-churn-weighted-refactor branch July 7, 2026 00:16
github-actions Bot added a commit that referenced this pull request Jul 7, 2026
crs48 added a commit that referenced this pull request Jul 7, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @xnetjs/core@0.3.0

### Minor Changes

- [#401](#401)
[`92708ab`](92708ab)
Thanks [@crs48](https://github.com/crs48)! - Add the shared
Last-Write-Wins ordering module to `@xnetjs/core`
  (`compareChangeApplicationOrder`, `compareLwwStamps`, `lwwWins`,
`lwwUpdateGuardSql`, `LwwStamp`) — the single canonical LWW comparison
used
  across the stack (protocol §L1.7).

`@xnetjs/data`, `@xnetjs/plugins`, and `@xnetjs/react` adopt it and
receive
  internal decompositions of their most-churned modules (NodeStore query
  compiler/hydration/transaction execution, ai-surface tool registry and
resource URI router, XNetProvider provider units). No public API changes
in
  those packages.
## @xnetjs/abuse@0.3.0

### Patch Changes

- Updated dependencies []:
  - @xnetjs/crypto@0.3.0
  - @xnetjs/identity@0.3.0
## @xnetjs/cli@0.0.8

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/plugins@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/identity@0.3.0
  - @xnetjs/runtime@0.1.4
  - @xnetjs/sync@0.3.0
  - @xnetjs/sqlite@0.3.0
## @xnetjs/crypto@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
## @xnetjs/data@0.3.0

### Patch Changes

- [#401](#401)
[`92708ab`](92708ab)
Thanks [@crs48](https://github.com/crs48)! - Add the shared
Last-Write-Wins ordering module to `@xnetjs/core`
  (`compareChangeApplicationOrder`, `compareLwwStamps`, `lwwWins`,
`lwwUpdateGuardSql`, `LwwStamp`) — the single canonical LWW comparison
used
  across the stack (protocol §L1.7).

`@xnetjs/data`, `@xnetjs/plugins`, and `@xnetjs/react` adopt it and
receive
  internal decompositions of their most-churned modules (NodeStore query
  compiler/hydration/transaction execution, ai-surface tool registry and
resource URI router, XNetProvider provider units). No public API changes
in
  those packages.

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/identity@0.3.0
  - @xnetjs/storage@0.3.0
  - @xnetjs/sync@0.3.0
  - @xnetjs/sqlite@0.3.0
## @xnetjs/data-bridge@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/sync@0.3.0
  - @xnetjs/sqlite@0.3.0
## @xnetjs/history@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/sync@0.3.0
## @xnetjs/identity@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/crypto@0.3.0
## @xnetjs/plugins@0.3.0

### Patch Changes

- [#401](#401)
[`92708ab`](92708ab)
Thanks [@crs48](https://github.com/crs48)! - Add the shared
Last-Write-Wins ordering module to `@xnetjs/core`
  (`compareChangeApplicationOrder`, `compareLwwStamps`, `lwwWins`,
`lwwUpdateGuardSql`, `LwwStamp`) — the single canonical LWW comparison
used
  across the stack (protocol §L1.7).

`@xnetjs/data`, `@xnetjs/plugins`, and `@xnetjs/react` adopt it and
receive
  internal decompositions of their most-churned modules (NodeStore query
  compiler/hydration/transaction execution, ai-surface tool registry and
resource URI router, XNetProvider provider units). No public API changes
in
  those packages.

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/abuse@0.3.0
## @xnetjs/react@0.3.0

### Patch Changes

- [#401](#401)
[`92708ab`](92708ab)
Thanks [@crs48](https://github.com/crs48)! - Add the shared
Last-Write-Wins ordering module to `@xnetjs/core`
  (`compareChangeApplicationOrder`, `compareLwwStamps`, `lwwWins`,
`lwwUpdateGuardSql`, `LwwStamp`) — the single canonical LWW comparison
used
  across the stack (protocol §L1.7).

`@xnetjs/data`, `@xnetjs/plugins`, and `@xnetjs/react` adopt it and
receive
  internal decompositions of their most-churned modules (NodeStore query
  compiler/hydration/transaction execution, ai-surface tool registry and
resource URI router, XNetProvider provider units). No public API changes
in
  those packages.

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/plugins@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/data-bridge@0.3.0
  - @xnetjs/history@0.3.0
  - @xnetjs/identity@0.3.0
  - @xnetjs/runtime@0.1.4
  - @xnetjs/sync@0.3.0
## @xnetjs/runtime@0.1.4

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/data@0.3.0
  - @xnetjs/plugins@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/data-bridge@0.3.0
  - @xnetjs/history@0.3.0
  - @xnetjs/identity@0.3.0
  - @xnetjs/storage@0.3.0
  - @xnetjs/sync@0.3.0
## @xnetjs/storage@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/sqlite@0.3.0
## @xnetjs/sync@0.3.0

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/core@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/identity@0.3.0
## @xnetjs/sqlite@0.3.0


## xnet-cloud@0.0.6

### Patch Changes

- Updated dependencies []:
  - @xnetjs/cloud@0.0.1
  - @xnetjs/crypto@0.3.0
## @xnetjs/brain@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/vectors@0.0.1
## @xnetjs/comms@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/crypto@0.3.0
## @xnetjs/dashboard@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/plugins@0.3.0
  - @xnetjs/react@0.3.0
  - @xnetjs/social@0.0.7
## @xnetjs/labs@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/plugins@0.3.0
## @xnetjs/licenses@0.0.7

### Patch Changes

- Updated dependencies []:
  - @xnetjs/crypto@0.3.0
## @xnetjs/maps@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
## @xnetjs/server@0.0.6

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/crypto@0.3.0
  - @xnetjs/data-bridge@0.3.0
  - @xnetjs/identity@0.3.0
## @xnetjs/social@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
  - @xnetjs/crypto@0.3.0
## @xnetjs/unreal@0.0.7

### Patch Changes

- Updated dependencies
[[`92708ab`](92708ab)]:
  - @xnetjs/data@0.3.0
## xnet-desktop@0.3.0

Desktop shell release riding the @xnetjs/core 0.3.0 train.
Desktop-specific changes are not tracked here; see the core packages'
changelogs for what shipped.
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.

2 participants