Repository navigation
refactor(screens): extract companion layout derives into companionLayoutState (audit 1.1.1) - #178
Merged
Merged
Conversation
…outState (audit 1.1.1) 4 chained pure derives moved out of REPL.tsx (was 5777-5799): - deriveCompanionNarrow (transcriptCols < MIN_COLS_FOR_FULL_SPRITE) - deriveCompanionVisible (!shouldHidePromptInput && !focusedInputDialog && !showBashesDialog) - deriveToolJsxCentered (isFullscreenEnvEnabled() && isLocalJSXCommand === true) - deriveCenteredModal (centered ? toolJSX.jsx : null) Aggregate deriveCompanionLayoutState + types ToolJsxLayoutLike / CompanionLayoutInput / CompanionLayoutState. isFullscreenEnvEnabled() is a runtime env check (utils/fullscreen.ts) with no React deps, safe to call from a pure function. centeredModal uses `?.jsx ?? null` instead of `toolJSX!.jsx` to avoid noNonNullAssertion while staying byte-identical (centered true ⇒ toolJSX non-null). REPL keeps all useState/useRef bindings (toolJSX, focusedInputDialog, showBashesDialog, transcriptCols via useTerminalSize), calls helper once, destructures to SAME const names → downstream reads byte-identical. Removed now-unused MIN_COLS_FOR_FULL_SPRITE REPL import (sole consumer moved out); isFullscreenEnvEnabled kept (16 other call sites). 25 new tests (companionLayoutState.test.ts): narrow threshold, 7 visible-gate cases (shouldHidePromptInput/focusedInputDialog/bashes string+true), 5 centered cases (fullscreen×local-jsx matrix incl null/absent), 3 centeredModal cases, 7 aggregate cases incl shouldHidePromptInput-suppresses-but-centers. Gates: typecheck 0 / 794 tests (+25) / lint net-zero 4601 (new files clean) / build:dev 3765 modules. Cumulative god-module reduction off 7096: -405 LOC (REPL now 6691). Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Aug 28, 2026
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.
Audit §1.1.1 god-module split — slice #7
Extracts the companion-sprite layout derive bundle from
REPL.tsx(7096-LOC god module) into a pure helper. Continues the proven fewest-dep-first extraction strategy.What moves
4 chained pure derives (REPL.tsx:5777-5799) → new
src/utils/companionLayoutState.ts:deriveCompanionNarrow—transcriptCols < MIN_COLS_FOR_FULL_SPRITE(narrow-terminal row-stacking flag)deriveCompanionVisible—!toolJSX?.shouldHidePromptInput && !focusedInputDialog && !showBashesDialog(sprite visibility gate)deriveToolJsxCentered—isFullscreenEnvEnabled() && toolJSX?.isLocalJSXCommand === true(fullscreen modal-slot routing)deriveCenteredModal—toolJsxCentered ? toolJSX.jsx : null(modal passthrough)Plus aggregate
deriveCompanionLayoutState+ typesToolJsxLayoutLike/CompanionLayoutInput/CompanionLayoutState.Why this slice
6 deps — fewest of remaining survey pool (vs globalKeybindingProps 9 deps, getFocusedInputDialog 23 deps). Per the proven strategy (PR #168–#177), fewest-dep pure-helper bundles carry the lowest byte-identical risk.
isFullscreenEnvEnabled()is a runtime env check (utils/fullscreen.ts) with no React dependency, safe to call from a pure function.Byte-identical
useState/useRefbindings (toolJSX,focusedInputDialog,showBashesDialog,transcriptColsviauseTerminalSize()), calls the helper once, destructures to the SAME const names → downstream reads byte-identical.centeredModaluses?.jsx ?? nullinstead oftoolJSX!.jsxto avoid thenoNonNullAssertionlint rule while staying byte-identical (whentoolJsxCenteredis true,toolJSXis necessarily non-null since centering requiresisLocalJSXCommand === true, which requirestoolJSXnon-null).MIN_COLS_FOR_FULL_SPRITEREPL import (sole consumer moved out).isFullscreenEnvEnabledkept (16 other call sites).CompanionFloatingBubble+CompanionSpritekept (JSX render refs).Tests
25 new tests in
src/__tests__/utils/companionLayoutState.test.ts:shouldHidePromptInput, focused dialog, bashes string+true, both absent/false)isLocalJSXCommand)shouldHidePromptInput-suppresses-visibility-but-still-centersisFullscreenEnvEnabledreadsFUSION_CODE_NO_FLICKERenv — each test sets/clears it deterministically (truthy=1→true, falsy=0→false),afterEachrestores.Gates
bun run typecheck— 0 errorsbun test src/__tests__/— 794 pass (+25 new)bun run lint— 4601 errors (net-zero vs baseline; new files clean)bun run build:dev— 3765 modules, passCumulative
REPL.tsx 6704 → 6691 (−13 this PR). Cumulative off the 7096-LOC original: −405 LOC across PR #168, #171, #172, #174, #175, #177, + this.
Task #170 (design-level REPL split) stays in_progress — multi-session, full 4-6wk split continues.
Co-Authored-By: Claude Fable 5 [email protected]