Skip to content

refactor(screens): extract terminal/approval state derives from god module (audit 1.1.1) - #174

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-terminal-approval-state
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-terminal-approval-state

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

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 of REPL.tsx into a testable helper module.

What moved

src/utils/terminalApprovalState.ts (NEW, 90 LOC) — 5 pure derives that were inline in REPL:

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

Exports: deriveIsWaitingForApproval, deriveIsShowingLocalJSXCommand, deriveTerminalApprovalState (aggregate returning all 5) + types TerminalApprovalInput/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 two useEffects that read the derives (prevent-sleep, PID-file status push). REPL calls deriveTerminalApprovalState once, destructures to the same const names → all downstream reads are byte-identical. Removed the now-unused TabStatusKind import 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 → true
  • isShowingLocalJSXCommand: null/undefined=false; phantom-overlay guard (isLocalJSXCommand: true + jsx: null → false, the deadlock-prevention case); true case
  • aggregate: idle/busy/waiting states + titleIsAnimating suppression; waitingFor fallthrough chain (approve <tool> → worker request → sandbox request → dialog open → input needed); local-JSX suppresses animation even when loading

Progress

REPL.tsx 6732 → 6715 (−17). Cumulative off the 7096-LOC god module:

PR Extraction −LOC
#168 leaf components (AnimatedTerminalTitle/TranscriptModeFooter/TranscriptSearchBar) + median() −285
#171 spinnerState pure-helper bundle −70
#172 viewedTaskSelector pure-helper selector −9
this terminalApprovalState pure-helper bundle −17
cumulative −381

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 735 pass (721 + 14 new)
  • bun run lint — net-zero vs baseline 4601
  • bun run build:dev — 3763 modules

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

…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]>
@dahai80
dahai80 merged commit 196e5bc into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-terminal-approval-state branch August 28, 2026 07:30
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