Skip to content

refactor(screens): extract showSpinner derive into spinnerState (audit 1.1.1) - #175

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-survey-stack-extract
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-survey-stack-extract

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.1 — god-module split, 5th surgical slice

Extracts the third spinner-visibility derive (deriveShowSpinner) from REPL.tsx into utils/spinnerState.ts, completing the spinner cluster started in #171 (onlySleepToolActive + stopHookSpinnerSuffix).

Change

  • REPL.tsx:2034-2053 — 20-line inline boolean expression → single deriveShowSpinner({...}) call (12 lines).
  • utils/spinnerState.ts — +deriveShowSpinner + ShowSpinnerInput type + ToolJsxSpinnerLike minimal shape. Helper body is the original expression verbatim.
  • REPL keeps all bindings (toolJSX, toolUseConfirmQueue, isLoading, userInputOnProcessing, hasRunningTeammates, getCommandQueueLength(), pendingWorkerRequest, onlySleepToolActive, visibleStreamingText, isBriefOnly) and passes them eagerly as an aggregate input object.

Byte-identical

  • Helper body = original expression, char-for-char.
  • getCommandQueueLength() has no side effects (reads .length only) → eager evaluation safe; original short-circuit only avoided the call, not a side effect.
  • Types aligned to real sources: userInputOnProcessing: string | undefined (truthy-checked, matches REPL:1138 useState<string | undefined>), pendingWorkerRequest: { toolName: string } | null (matches AppStateStore:384).

Tests

src/__tests__/utils/spinnerStateShowSpinner.test.ts — 15 new tests covering each gate: toolJSX showSpinner flag (true/false), confirm/prompt queue gating (before busy), 4 busy arms (loading / userInput / teammates / commandQueue), pendingWorkerRequest suppress, onlySleepToolActive suppress, visibleStreamingText suppress + isBriefOnly exemption, combined all-suppressors case.

Gates

Gate Result
bun run typecheck 0 errors
bun test src/__tests__/ 750 pass (+15)
bun run lint 4601 errors net-zero (pre-existing baseline)
bun run build:dev passes, 3763 modules

God-module reduction

REPL.tsx 6715 → 6709 LOC (−6). Cumulative off the 7096-LOC original: #168 (−285) + #171 (−70) + #172 (−9) + #174 (−17) + this (−6) = −387 LOC.

Continues the 4-6wk §1.1.1 split per [[audit-1-1-1-repl-split-checkpoint]]. Each slice independently mergeable.

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

…t 1.1.1)

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
dahai80 merged commit 2df8293 into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-survey-stack-extract branch August 28, 2026 07:47
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