Skip to content

refactor(screens): extract spinner-state derives from god module REPL.tsx (audit 1.1.1) - #171

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-spinner
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-spinner

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.1 — God-Module Split (2nd extraction, continues PR #168)

Second surgical extraction from REPL.tsx (audit ~/fusion/audit/fusion-code-audit-result-0827.md §1.1.1 "god module"). Follows the PR #168 pattern: extract leaf / pure-helper with zero closure mutation, byte-identical behavior, independently mergeable.

What moved

Two pure useMemo derives (both spinner-visibility state, no React state mutation, no refs) → new src/utils/spinnerState.ts as plain pure functions taking their closure deps as args:

Function REPL.tsx (was) Deps Role
onlySleepToolActive 2032–2044 messages, inProgressToolUseIDs hide spinner when only in-progress tool is Sleep
stopHookSpinnerSuffix 5319–5386 messages, isLoading derive stop-hook spinner suffix string

REPL keeps thin useMemo cache wrappers (deps unchanged) — pure logic + caching split cleanly.

Imports cleaned

3 now-unused REPL imports removed (re-homed into spinnerState.ts): truncateToWidth (format.js), ProgressMessage (message.js type), HookProgress (hooks.js type). count + isInternalBuild kept — still used elsewhere in REPL.

LOC

REPL.tsx 6811 → 6741 (−70 LOC). spinnerState.ts +101 (incl. header comment + 2 functions).

Gates (commit-must-pass)

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 704 pass / 0 fail
  • bun run lint — net-zero 4601 errors (baseline exact match; new file spinnerState.ts clean, 0 new diagnostics)
  • bun run build:dev — pass, 3756 modules

byte-identical

Both derives are pure reads of their args → output identical for same inputs. useMemo deps arrays unchanged ([messages, inProgressToolUseIDs] / [messages, isLoading]). No behavior change, no feature flag.

Continues

#170 design-level split. PR #168 was the 1st extraction (3 leaf components + median() → array.ts, REPL 7096→6811). This is the 2nd. Full 4-6wk split continues in follow-up PRs (REPL() cohesive-subsystem extractions; §1.1.2 ctx seam decision; §1.1.3 layer enforcement; §1.3.1 KV-cache adapter — all multi-session design work).

Co-Authored-By: Claude Fable 5 [email protected]

….tsx (audit 1.1.1)

Second surgical extraction from REPL.tsx (audit §1.1.1 god-module split,
continues PR #168 checkpoint). Two pure useMemo derives — onlySleepToolActive
and stopHookSpinnerSuffix — moved to src/utils/spinnerState.ts as pure
functions taking their closure deps as args. REPL keeps thin useMemo cache
wrappers. Zero closure mutation, zero behavior change.

Removed 3 now-unused REPL imports (truncateToWidth, ProgressMessage,
HookProgress) re-homed into spinnerState.ts. REPL.tsx 6811→6741 (−70 LOC).

Gates: typecheck 0 / 704 tests pass / lint net-zero 4601 / build:dev 3756 modules.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit dd84f68 into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-repl-split-spinner branch August 28, 2026 06:18
dahai80 added a commit that referenced this pull request Aug 28, 2026
…sx (audit 1.1.1) (#172)

Third surgical extraction in the REPL.tsx god-module split (audit §1.1.1).
The three viewed-task derives (viewedTask / viewedTeammateTask / viewedAgentTask)
move from inline in REPL.tsx to a pure-function selector module:
src/tasks/viewedTaskSelector.ts. No React, no side effects — deps as args.

- getViewedTask: raw record lookup by id
- getViewedTeammateTask: teammate-only narrowed (in_progress_teammate)
- getViewedAgentTask: teammate OR local_agent — drives downstream boolean checks

REPL keeps the three const bindings as thin call wrappers (identical names,
identical downstream usage) — pure relocation + import wiring, byte-identical
behavior. Removed now-unused isInProcessTeammateTask guard import from REPL
(sole call site moved out); kept InProcessTeammateTaskState type (still used
at the panel helper) and isLocalAgentTask (two other call sites).

REPL.tsx 6741 → 6732 LOC (-9). viewedTaskSelector.ts +36 LOC (new).
Cohesion win: selector logic now reusable + unit-testable in isolation.

Gates: typecheck 0 / 714 tests pass (+10 new) / lint net-zero vs 4601 baseline
/ build:dev 3757 modules.

Follows PR #168 (leaf components, -285) + PR #171 (spinner derives, -70) in
the multi-session split. Task #170 stays in_progress — full 4-6wk split
continues in follow-up PRs.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…odule (audit 1.1.1) (#174)

Fourth surgical extraction — pure-helper bundle class (matches PR #171
spinnerState.ts pattern). 5 chained pure derives moved out of REPL.tsx:

  isWaitingForApproval  (4 queue/pending inputs → boolean)
  isShowingLocalJSXCommand (toolJSX → boolean, phantom-overlay guard)
  titleIsAnimating      (isLoading + 2 above → boolean)
  sessionStatus         (2 above → TabStatusKind idle/busy/waiting)
  waitingFor            (sessionStatus + queues → string|undefined)

New src/utils/terminalApprovalState.ts (90 LOC):
  - deriveIsWaitingForApproval(input)
  - deriveIsShowingLocalJSXCommand(toolJSX)
  - deriveTerminalApprovalState(input) — aggregate, returns all 5
  Types: TerminalApprovalInput + TerminalApprovalState + ToolJsxLike.

REPL keeps the hook-bound vars (haikuTitle/setHaikuTitle useState,
haikuTitleAttemptedRef useRef, terminalTitleFromRename useAppState,
agentTitle, sessionTitle, terminalTitle) + the two useEffects
(prevent-sleep 1399, PID-file status push 1425). Only the 5 pure
derives (no hooks, no JSX) move out. REPL calls deriveTerminalApprovalState
once, destructures to same const names → downstream reads unchanged
(byte-identical). Removed now-unused TabStatusKind import from REPL
(helper owns the type now).

Why not the #1 survey-stack candidate: survey-stack is a leaf-component
(JSX, React-compiler form to preserve) — higher byte-identical risk.
This pure-helper bundle has no JSX, no hooks — plain functions, lowest
risk, matches the proven PR #171 extraction pattern.

Test: src/__tests__/utils/terminalApprovalState.test.tsx (14 tests):
  - isWaitingForApproval: empty=false, each queue/pending → true
  - isShowingLocalJSXCommand: null/undefined/false, phantom-overlay
    guard (isLocalJSXCommand true + jsx null = false), true case
  - aggregate: idle/busy/waiting + titleIsAnimating suppression,
    waitingFor fallthrough chain (approve→worker→sandbox→dialog→input),
    local-JSX suppresses animation when loading

REPL.tsx 6732 → 6715 (−17). Cumulative off 7096 god module:
  PR#168 −285 + PR#171 −70 + PR#172 −9 + this −17 = −381 LOC.

Gates: typecheck 0 / 735 tests (+14 new) / lint net-zero 4601 /
build:dev 3763 modules.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…t 1.1.1) (#175)

Third spinner-visibility derive (onlySleepToolActive/stopHookSpinnerSuffix landed
in #171) now joined by deriveShowSpinner — completes the spinner cluster in
utils/spinnerState.ts. REPL.tsx 2034-2053 inline 20-line boolean expression
moved out as a pure helper taking an aggregate input object (11 deps).

Byte-identical: helper body is the original expression verbatim; deps passed
eagerly (getCommandQueueLength has no side effects, only reads .length).
REPL keeps the toolJSX/queue/isLoading/etc bindings and calls deriveShowSpinner
once. -6 LOC off the god module (6715 -> 6709).

Types aligned to real sources: userInputOnProcessing is string|undefined
(truthy-checked as in original), pendingWorkerRequest {toolName}|null.

15 new unit tests (spinnerStateShowSpinner.test.ts) cover each gate:
toolJSX showSpinner flag, confirm/prompt queue gating, 4 busy arms
(loading/userInput/teammates/queue), pendingWorkerRequest suppress,
onlySleepToolActive suppress, visibleStreamingText suppress + isBriefOnly
exemption, all-suppressors case.

Gates: typecheck 0 / 750 tests (+15) / lint 4601 net-zero / build:dev 3763.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…State (audit 1.1.1) (#176) (#177)

Sixth surgical extraction for audit §1.1.1 god-module split.
Bundle 3 chained pure derives out of REPL.tsx (was 5748-5769):
  - usesSyncMessages (showStreamingText||!isLoading)
  - displayedMessages (agent view|sync|deferred, ref-preserving)
  - placeholderText (input-baseline gate)

src/utils/messageDisplayState.ts NEW — deriveUsesSyncMessages +
deriveDisplayedMessages + derivePlaceholderText + aggregate
deriveMessageDisplayState. No React, no hooks, deps as args.
Returns ORIGINAL array refs (no spread copy) — preserves ref-identity
for Messages memo + length checks downstream. Byte-identical to inline.

REPL keeps useDeferredValue(messages) + userInputBaselineRef ref;
calls deriveMessageDisplayState once, destructures to SAME const names
→ downstream reads unchanged.

Picked 7-dep bundle over survey #1 getFocusedInputDialog (90 LOC but 23
deps) — strategy = fewest-dep pure-helper = lowest byte-identical risk
(per proven PR #174/#175 pattern).

Tests: messageDisplayState.test.ts 19 tests — usesSyncMessages 3 arms,
displayedMessages ref-identity + agent-override + empty-array,
placeholderText baseline gate + agent suppress, aggregate 7 cases
including ref-identity assertion (not a copy).

REPL.tsx 6709 → 6696 (−13). Cumulative off 7096:
  #168(−285)+#171(−70)+#172(−9)+#174(−17)+#175(−6)+#176(−13) = −400 LOC.

Gates: typecheck 0 / 769 tests (+19) / lint net-zero 4601 / build:dev 3764.

Co-authored-by: Claude Fable 5 <[email protected]>
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