Skip to content

refactor(screens): extract companion layout derives into companionLayoutState (audit 1.1.1) - #178

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-companion-bundle
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-companion-bundle

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

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 + types ToolJsxLayoutLike / 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

  • REPL keeps all useState/useRef bindings (toolJSX, focusedInputDialog, showBashesDialog, transcriptCols via useTerminalSize()), calls the helper once, destructures to the SAME const names → downstream reads byte-identical.
  • centeredModal uses ?.jsx ?? null instead of toolJSX!.jsx to avoid the noNonNullAssertion lint rule while staying byte-identical (when toolJsxCentered is true, toolJSX is necessarily non-null since centering requires isLocalJSXCommand === true, which requires toolJSX non-null).
  • Removed now-unused MIN_COLS_FOR_FULL_SPRITE REPL import (sole consumer moved out). isFullscreenEnvEnabled kept (16 other call sites). CompanionFloatingBubble + CompanionSprite kept (JSX render refs).

Tests

25 new tests in src/__tests__/utils/companionLayoutState.test.ts:

  • narrow threshold (below/at/wide)
  • 7 visible-gate cases (shouldHidePromptInput, focused dialog, bashes string+true, both absent/false)
  • 5 centered cases (fullscreen × local-jsx matrix incl null/absent isLocalJSXCommand)
  • 3 centeredModal cases (passthrough, not-centered null, null-jsx-when-centered)
  • 7 aggregate cases incl shouldHidePromptInput-suppresses-visibility-but-still-centers

isFullscreenEnvEnabled reads FUSION_CODE_NO_FLICKER env — each test sets/clears it deterministically (truthy=1→true, falsy=0→false), afterEach restores.

Gates

  • bun run typecheck — 0 errors
  • bun 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, pass

Cumulative

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]

…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]>
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