Skip to content

refactor(app): move the roster and local health state into hooks - #1772

Merged
devswha merged 1 commit into
mainfrom
refactor/app-roster-hooks
Oct 23, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/app-roster-hooks

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Wave 8 of the App.tsx split. The plan is .omo/plans/app-stores-split.md in the maintainer's workspace, and plan-reviewer approved it. It follows PR #1771.

This wave moves the PC roster and this PC's health state out of src/App.tsx into two files. Each contiguous block becomes one hook called at that block's own line (rule R1), so effect order is unchanged. In order, that is the recent-folders effect, then polling, then the event stream, as before.

What moves

Hook (file) Block in App.tsx on 58fcc3ae4
useRosterState() (useMachineRoster.ts) 213-214: machines, machineRosterLoaded
useRecentFolderMemory({ machines }) 224-236: the recent-folders effect
useMachinesRef({ machines }) 243: machinesRef and its render-time assignment
useLocalHealth() (useLocalHealth.ts) 247-255: the health book, reads, localHealth, health, localFreshness, shownHealth
useRosterError() 256: error
useRefetchTimer() 398: refetchTimer
useRosterLoader({ … }) 412-478: snapshotRequests, loadRef, reorderCoordinator, load, the polling effect, scheduleRefetch, the refetch cleanup
useRosterEvents({ … }) 482-547: the event-stream effect

Module-level helpers move with the code that uses them, verbatim with their comments:

  • sameData (exported, because useLocalHealth.ts imports it);
  • POLL_MS;
  • REFETCH_DEBOUNCE_MS.

Not purely moved code, three spots:

  • loadHealth: the local health read inside it (7 lines) becomes readLocalHealth, a useCallback(..., []) in useLocalHealth. Its body is those lines verbatim, and it uses only refs and a setter.
    • loadHealth is now await readBridgeHealth(); await readLocalHealth();, with its dependency list still [].
    • Both callbacks are stable, so loadHealth keeps its identity and runs the same code. The polling effect, unlock and lock depend on that identity.
  • The event stream: it reads takeNotificationTargetRef, which App declares further down. So useRosterEvents takes getTakeNotificationTargetRef: () => takeNotificationTargetRef, and the one added line, const takeNotificationTargetRef = getTakeNotificationTargetRef();, opens the message handler. Every other line of the effect is unchanged, and the ref is still read when an event arrives.
  • The effect's dependency list: [locked, scheduleRefetch, dropIn, chime, reorderCoordinator] is unchanged, so the stream resubscribes exactly when it did before.

Departures from the plan's draft:

  • The follow-herdr-focus block stays inside the event-stream effect verbatim, instead of becoming an injected onPaneFocused. Every value it reads is declared above the effect, so it moves as-is.
  • The plan's "probe forgetting" item already moved in wave 6, inside useSessionHistoryList.

Hook ceiling: APP_HOOK_CEILING drops from 107 to 90.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD shows 374 lines as moved. The other 105 lines are:

    • App's narrowed imports, the two new imports and the eight calls;
    • the two lines of loadHealth and the getTakeNotificationTargetRef argument;
    • the new files' imports, params types, signatures, the readLocalHealth wrapper, the getter line and the returns;
    • the ceiling.
  • Moved blocks are exact: every block above, and the health-read lines 404-410, appear byte for byte in the new files. The event-stream block does too, apart from the one getter line.

  • Positions: the line before and after each call is the line that surrounded its block.

  • Typecheck: bun run typecheck passes.

  • Unit tests: 120 pass, 0 fail across 11 files, from:

    HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts src/conventions.test.ts src/lib/healthPresentation.test.ts src/lib/snapshotRequests.test.ts src/lib/workspaceOrder.test.ts src/lib/eventStream.test.ts src/lib/snapshot.test.ts src/lib/recent-directories.test.ts src/lib/preferencesSync.test.ts src/lib/i18n.test.ts scripts/conventions.test.ts

  • bun run check fast: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 57.9s)

  • bun run check integration browser: the browser lane exits 0 (every browser script passed, 1800 s), including the machines, machine conflict and dialog, sidebar machine layout/removal, workspace rows and touch reorder, recent folders, preferences sync, sidebar activity, session history, follow-focus, health-flap, herdr-restart and pending pane switch scripts. The integration lane's only failure is server/api.contract.test.ts "creates, edits, searches, inspects, and closes an owned workspace" (line 1540), which fails the same way on unchanged origin/main on this PC; CI runs that lane in its own environment.

Outside PRs that touch the same files

No other maintainer PR touches these files. One outside contributor's PR touches src/App.tsx: #1427. It already conflicts with main, and needs a rebase either way.

No changelog fragment: users see no change.

Nine App blocks become calls at their own lines: useRosterState, useRecentFolderMemory,
useMachinesRef, useLocalHealth, useRosterError, useRefetchTimer, useRosterLoader and useRosterEvents.
loadHealth keeps its [] deps and now awaits readBridgeHealth and readLocalHealth.
The event stream reads takeNotificationTargetRef through a getter at event time; its deps are unchanged.
APP_HOOK_CEILING is lowered to 90.
Plan: .omo/plans/app-stores-split.md wave 8.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 58fcc3a and c7970c8.

📒 Files selected for processing: 4
  • src/App.tsx
  • src/app-hooks.test.ts
  • src/lib/useLocalHealth.ts
  • src/lib/useMachineRoster.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Refactor
    • Updated how machine roster and health information is managed behind the scenes.
    • Existing roster updates, health checks, event handling, and refresh behavior remain unchanged.
    • No new user-facing features or behavior changes are included in this update.

App now wires dedicated hooks for local health, roster state, polling, and machine events. The hooks track health reads, load roster and health data, coordinate snapshots and reorder checks, and process machine events. The hook-count ceiling is reduced from 107 to 90.

Changes: App health and roster hooks

Layer / File(s) Summary
Health and roster state
src/lib/useLocalHealth.ts, src/lib/useMachineRoster.ts, src/App.tsx
useLocalHealth tracks local health reads and derives confirmed health and failure counts. Roster hooks provide state, recent-folder memory, machine references, errors, and refetch timer state.
Roster loading and polling
src/lib/useMachineRoster.ts
useRosterLoader coordinates roster reads with snapshots and workspace reorder verification. It polls based on document visibility and lock state, processes URL auth tokens, handles 401 errors, and debounces refetches.
Machine event handling and App wiring
src/lib/useMachineRoster.ts, src/App.tsx, src/app-hooks.test.ts
useRosterEvents processes machine events and stream lifecycle callbacks. App wires the hooks, and the hook-count ceiling changes from 107 to 90.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to c7970

This refactor moves roster, health, polling and event-stream code into hooks without changing behavior. No concrete risk was found, so it is ready to merge after the normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: moving roster and local health state from App.tsx into hooks.
Description check Passed The description explains the change, documents implementation details and behavioral constraints, and lists validation results, including the known baseline integration failure.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: this PR moves the roster loader, including the token-from-URL, authenticate and verifySourceBoot flows, and the event stream. Per AGENTS.md, this comment records the review that stands in for a full one.

Review: a gate reviewer on a different model than the author's, plus the merge pass's own checks. No findings.

  • Reconstruction: expanding every hook back into App and reversing the three documented adaptations reproduces App.tsx at 58fcc3a byte for byte, apart from imports. The three adaptations:
    • readLocalHealth;
    • the getTakeNotificationTargetRef getter;
    • sameData/POLL_MS/REFETCH_DEBOUNCE_MS moving with their users.
  • Effect order: recent-folders, then polling, then the event stream, unchanged relative to every other App effect.
  • Event stream: its dependency array is unchanged, so it resubscribes exactly as before. The getter still reads takeNotificationTargetRef when an event arrives.
  • Auth and polling: the auth sequence inside useRosterLoader is unchanged and in the same order, and polling cadence is the same. No new herdr requests.
  • Hook count: counted on the TypeScript AST, 107 → 90.
  • Tests at this head:
    • 80 unit tests pass (event stream, snapshot requests, workspace order, health, follow-focus, auth link, recent folders, app-hooks, conventions);
    • the typecheck passes;
    • health-flap-demo-regression (transient health recovery, health scope and capability) exits 0 on a fresh build.

All required checks are green and no review thread is open.

@devswha
devswha merged commit 3a449c9 into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/app-roster-hooks branch October 23, 2026 19:14
devswha added a commit that referenced this pull request Oct 23, 2026
)

Wave 9 of the App.tsx split. The plan is
`.omo/plans/app-stores-split.md` in the maintainer's workspace, and
plan-reviewer approved it. It follows PR #1772.

This wave moves the pane lens and the split view out of `src/App.tsx`
into two files. Each contiguous block becomes one hook called at that
block's own line (rule R1), so hook order is unchanged. In particular,
the `lastKeyAt` keydown capture listener still registers after the
sidebar's Escape listener, and the split validation and drag-listener
effects run where they did.

## What moves

| Hook (file) | Block in App.tsx on `3a449c96c` |
|---|---|
| `useSplitRecheck()` (`useSplitView.ts`) | 256-258: `otherRecheck`,
`otherRosterTick` |
| `usePaneLensState()` (`usePaneLens.ts`) | 293-295: `lens`, `viewPicks`
|
| `useSplitState()` (`useSplitView.ts`) | 296-335: split state,
`soloSlot`, `endSplit`, `splitRef`, `splitShownRef`, `lastKeyAtRef` and
its listener, the drop preview state, `paneAreaRef`, `tabDrag` |
| `usePaneLens({ … })` (`usePaneLens.ts`) | 578-595: `lenses`,
`lensKey`, `notificationView`, the lens settled during render, the
alert's lens override |
| `usePaneViewPicks({ … })` (`usePaneLens.ts`) | 608-627: `pickView`,
`setView` |
| `useSplitLayout({ … })` (`useSplitView.ts`) | 632-791: the other
half's derivation, the validation effect, `applySplit` / `activateSlot`
/ `closeSlot` / `selectInSlot` / `dockSide` / `dockAt`, the `onDrop`
effect, the tab-drag effect, the drag handlers, the window drag
listeners |

**Unchanged structure:**
- **Lens settled during render:** `usePaneLens` still calls `setLens`
and `setTerminalPeek` during render. It runs on App's fiber, exactly as
the inline code did.
- **Plain functions:** the split's plain functions stay plain functions,
not wrapped in `useCallback`.
- **Render-time ref assignments:** `splitShownRef.current = splitOn` and
the `otherTabRef` lines stay render-time.
- **Dependency lists:** every dependency list is byte-identical.
- **What stays in App:** `usePhoneSheetBack` for the peek stays in App
at its line. Line 262 inside `rosterIn` also stays: it reads the ref and
setter that `useSplitRecheck` returns.

**Module-level helpers** move verbatim with their comments: `storedView`
to `usePaneLens.ts`, and `SELECTION_KEY`, `StoredSelection`,
`storedSelection` and `storeSelection` to `useSplitView.ts`. App imports
back the ones it still calls. No copies are left behind.

**Not purely moved code (type-only):** four `split!` non-null assertions
in the pane-area JSX (`split!.active`, `split!.other.machineId`,
`split!.other.paneId`, `slotSide(split!, slot)`).
- **Why they're needed:** `splitOn` used to be computed in App, and its
`split !== null` narrowed `split` for TypeScript in the JSX. Returned
from the hook, it is a plain boolean, so the narrowing is gone.
- **Why it's only types:** each site is reached only when `splitOn` (or
`!active`) holds, so `split` is non-null there. The emitted JavaScript
is unchanged.

**Hook ceiling:** `APP_HOOK_CEILING` drops from 90 to 62.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 590
lines as moved. The other 108 lines are:
  - App's narrowed imports, the two new imports and the six calls;
  - the four `split!` lines;
  - the new files' imports, params types, signatures and returns;
  - the `export` keywords on the moved helpers;
  - the ceiling.
- **Moved blocks are exact:** all six blocks above appear byte for byte
in the new files.
- **Positions:** the line before and after each call is the line that
surrounded its block. Two pairs of blocks were adjacent, so their calls
are adjacent too.
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** **109 pass, 0 fail across 8 files**, from:

`HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts
src/conventions.test.ts scripts/conventions.test.ts
src/lib/split.test.ts src/lib/paneLens.test.ts
src/lib/terminalPeek.test.ts src/lib/panePresentation.test.ts
src/lib/i18n.test.ts`
- `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443
files, 8 at a time, 57.8s)
- **`bun run check integration browser`:** the browser lane exits 0
(every browser script passed, 1786 s), including the split view, header
lens switch, default view, phone split grid, tab menu, notification
view, pane find, render crash, terminal autoswitch and ui regressions.
The integration lane's only failure is `server/api.contract.test.ts`
"creates, edits, searches, inspects, and closes an owned workspace"
(line 1540), which fails the same way on unchanged `origin/main` on this
PC; CI runs that lane in its own environment.

## Outside PRs that touch the same files

No other maintainer PR touches these files. Outside contributor PRs that
touch `src/App.tsx` and will need a rebase: #1427.

No changelog fragment: users see no change.
devswha added a commit that referenced this pull request Oct 23, 2026
…1774)

Wave 10, the last wave of the App.tsx split. The plan is
`.omo/plans/app-stores-split.md` in the maintainer's workspace, and
plan-reviewer approved it. It follows PR #1773.

This wave moves the selection, link landing, notification targets and
the address bar out of `src/App.tsx` into two files. The selection code
is interleaved with code that stays in App, such as `useSplitRecheck`,
`useSidebarLayout`, `useScreenWakeLock` and the auth callbacks. So each
contiguous block becomes one hook called at that block's own line (rule
R1). Effect, layout-effect and listener order are unchanged. In
particular:
- The pane `popstate` listener still registers before the New-workspace
dialog's `popstate` listener, which stays in App.
- `selectionRef` is still marked in its `useLayoutEffect` at commit.

## What moves

| Hook (file) | Block in App.tsx on `3f0cfcee8` |
|---|---|
| `useSelectedMachine` (`useSelection.ts`) | 158-163:
`selectedMachineId`, `selectedMachine`, `snapshot` |
| `useSelectionState` | 178-207: `selectedPaneId`,
`notificationViewTarget`, `terminalPeek`/`endPeek`, `pendingLink`,
`linkLanded`, `rosterSeq`/`linkSince`/`selectionSince`,
`rosterTick`/`linkTick` |
| `useLinkLanding` | 209-234: `rosterIn`, `pendingFile`,
`selectionHint`, the header note and its timer, `note`, `autoSelected` |
| `useSelectionMark` | 236-242: `selectionRef` and its layout effect |
| `useSelectTarget` | 323-415: `selectedMachineRef`, `selectTarget` and
its ref, the selection validation effect, the stored-selection effect |
| `useSelectPane` | 417-424: `selectPane` |
| `useNotificationTargets` | 428-449: `takeNotificationTarget`, its ref,
the `onNotificationTarget` effect |
| `useSelectedPane` | 452: `selectedPane` (`useScreenWakeLock` at 453
stays in App) |
| `useSelectedLayout` | 454-472: `selectedWorkspace`, `selectedLayout`,
`presentedPaneId`, the zoom-redirect layout effect |
| `useAddressBar` (`useAddressBar.ts`) | 507-603: `writtenLink`,
`poppedTo`, `newSessionOpenRef`, the link inputs, the file release
effect, the URL-writing effect, the link's pending-file effect, the pane
`popstate` effect |
| `useMachineGone` (`useSelection.ts`) | 749-763: the removed-PC effect
|

**Unchanged:**
- **Dependency lists:** every one is byte-identical.
- **Render-time assignments:** `selectedMachineRef.current = …`,
`selectTargetRef.current = …`, `takeNotificationTargetRef.current = …`
and `newSessionOpenRef.current = …` stay render-time.
- **Stored-selection helpers:** `storedSelection` and `storeSelection`
are imported from `useSplitView.ts` (PR #1773), not copied.
- **Follow-focus:** the block the plan listed here already moved,
verbatim, with the event stream in PR #1772.

**Hook ceiling:** `APP_HOOK_CEILING` drops from 62 to 24.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 671
lines as moved. The other 184 lines are:
  - App's narrowed imports, the two new imports and the eleven calls;
- the new files' imports, params types, two local type aliases
(`SelectionHint`, `SelectTarget`), signatures and returns;
  - the ceiling.
- **Moved blocks are exact:** all eleven blocks above appear byte for
byte in the new files.
- **Positions:** the line before and after each call is the line that
surrounded its block on main.
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** **119 pass, 0 fail across 10 files**, from:

`HERDR_TEST_MODE=unit bun test src/app-hooks.test.ts
src/conventions.test.ts scripts/conventions.test.ts
src/lib/deepLink.test.ts src/lib/notificationTarget.test.ts
src/lib/selectionMark.test.ts src/lib/followFocus.test.ts
src/lib/sheetHistory.test.ts src/lib/settingsHistory.test.ts
src/lib/i18n.test.ts`
- `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443
files, 8 at a time, 57.8s)
- **`bun run check integration browser`:** the browser lane exits 0
(every browser script passed, 1801 s), including the deep link,
notification startup and view, pending pane switch, machine dialog and
conflict, file viewer Back/Forward, settings pages, sidebar activity,
mobile tabs and ui regressions. The integration lane's only failure is
`server/api.contract.test.ts` "creates, edits, searches, inspects, and
closes an owned workspace" (line 1540), which fails the same way on
unchanged `origin/main` on this PC; CI runs that lane in its own
environment.

## Outside PRs that touch the same files

No other maintainer PR touches these files. Outside contributor PRs that
touch `src/App.tsx` and will need a rebase: #1427.

No changelog fragment: users see no change.
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