Repository navigation
refactor(screens): extract terminal/approval state derives from god module (audit 1.1.1) - #174
Merged
Merged
Conversation
…odule (audit 1.1.1) 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]>
This was referenced Aug 28, 2026
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]>
This was referenced Aug 28, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audit §1.1.1 god-module split — fourth surgical extraction. Pure-helper bundle class, matches the proven PR #171 (
spinnerState.ts) pattern. Moves 5 chained pure derives out ofREPL.tsxinto a testable helper module.What moved
src/utils/terminalApprovalState.ts(NEW, 90 LOC) — 5 pure derives that were inline in REPL:isWaitingForApprovalisShowingLocalJSXCommandtoolJSXtitleIsAnimatingisLoading+ 2 abovesessionStatusTabStatusKindidle/busy/waitingwaitingForsessionStatus+ queuesExports:
deriveIsWaitingForApproval,deriveIsShowingLocalJSXCommand,deriveTerminalApprovalState(aggregate returning all 5) + typesTerminalApprovalInput/TerminalApprovalState/ToolJsxLike.What stays in REPL
The hook-bound vars that feed these derives:
haikuTitle/setHaikuTitle(useState),haikuTitleAttemptedRef(useRef),terminalTitleFromRename(useAppState),agentTitle,sessionTitle,terminalTitle. Plus the twouseEffects that read the derives (prevent-sleep, PID-file status push). REPL callsderiveTerminalApprovalStateonce, destructures to the same const names → all downstream reads are byte-identical. Removed the now-unusedTabStatusKindimport from REPL (the helper owns the type now).Why this over the #1 survey candidate
The survey ranked survey-stack (#1, 66 LOC leaf-component) above this (#2, 45 LOC pure-helper bundle). I picked #2: survey-stack is JSX with React-compiler form to preserve — higher byte-identical risk. This pure-helper bundle has no JSX, no hooks — plain functions, lowest risk, exactly the PR #171 pattern. Survey-stack is a strong next slice.
Test
src/__tests__/utils/terminalApprovalState.test.tsx(14 tests, 28 assertions):isWaitingForApproval: empty=false; each of the 4 queues/pending → trueisShowingLocalJSXCommand: null/undefined=false; phantom-overlay guard (isLocalJSXCommand: true+jsx: null→ false, the deadlock-prevention case); true casetitleIsAnimatingsuppression;waitingForfallthrough chain (approve <tool>→worker request→sandbox request→dialog open→input needed); local-JSX suppresses animation even when loadingProgress
REPL.tsx 6732 → 6715 (−17). Cumulative off the 7096-LOC god module:
Gates
bun run typecheck— 0 errorsbun test src/__tests__/— 735 pass (721 + 14 new)bun run lint— net-zero vs baseline 4601bun run build:dev— 3763 modulesCo-Authored-By: Claude Fable 5 [email protected]