Skip to content

refactor(screens): extract 3 leaf components + median from god module REPL.tsx (audit 1.1.1 checkpoint) - #168

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-checkpoint
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-checkpoint

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Audit §1.1.1 flags src/screens/REPL.tsx as a 7096-LOC god module — render tree + keybindings + task lists + compaction + tool permissions + session management all in one file. This PR is the first surgical extraction checkpoint toward the multi-session split.

Extracted (props-in / JSX-out, no REPL state closure)

Target What moved Why leaf-safe
src/components/AnimatedTerminalTitle.tsx 960ms animation-tick title setter Returns null (pure side-effect); tick now re-renders only this leaf, not the whole REPL tree
src/components/TranscriptModeFooter.tsx transcript-mode footer + dynamic keybinding hints Static JSX from props
src/components/TranscriptSearchBar.tsx less-style / search bar Owns only its local index-warm + query effects
median() → src/utils/array.ts ttft/otps multi-request median Pure fn, primitives only, no side effects

Details

  • React-Compiler compiled form preserved verbatim on the 2 compiled components ($ = _c() memo cache, 0 slot reads) — shipped source style (Rule 11). The source-style hand-written component stays hand-written.
  • Removed 4 now-unused REPL.tsx imports (sole consumers moved out): figures, useTerminalTitle, useShortcutDisplay, useSearchInput. Kept useTerminalFocus (still used at the focus-check site).
  • REPL.tsx 7096 → 6811 LOC (−285). Removed 293 lines, added 19 (imports + relocation comment).

Byte-identical behavior

Pure relocation + import wiring — no logic change. Animation behavior, footer rendering, search-bar behavior, and median computation are unchanged; same components render at the same usage sites.

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 704 pass / 0 fail
  • bun run lint — net-zero vs baseline (4601 errors, all pre-existing repo-wide)
  • bun run build:dev — passes (built ./fusion-code-dev)

Scope note

This is a checkpoint, not the complete 1.1.1 fix. The 4-6 week full split (extracting cohesive subsystems from the giant REPL() function, ctx seam decision 1.1.2, layer enforcement 1.1.3) continues in follow-up PRs. Each checkpoint is independently mergeable + verifiable (Rule 10).

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

… REPL.tsx (audit 1.1.1 checkpoint)

Audit 1.1.1 flags src/screens/REPL.tsx as a 7096-LOC god module rendering
tree + keybindings + task lists + compaction + tool permissions + session
management in one file. This is the first surgical extraction checkpoint
toward the multi-session split.

Extracted (props-in / JSX-out, no REPL state closure):
- AnimatedTerminalTitle.tsx — 960ms animation tick now re-renders only this
  leaf (returns null, pure side-effect) instead of the whole REPL tree.
- TranscriptModeFooter.tsx — transcript-mode footer with dynamic keybinding hints.
- TranscriptSearchBar.tsx — less-style / search bar.
- median() -> src/utils/array.ts — pure fn for ttft/otps multi-request median.

React-Compiler compiled form ($ = _c() memo cache, $[i] slot reads) preserved
verbatim on the 2 compiled components; the source-style hand-written component
stays hand-written. Removed 4 now-unused REPL.tsx imports: figures,
useTerminalTitle, useShortcutDisplay, useSearchInput (sole consumers moved out).

REPL.tsx 7096 -> 6811 LOC (-285). Byte-identical behavior: pure relocation +
import wiring, no logic change. Gates: typecheck 0 errors, 704 tests pass,
lint net-zero vs baseline (4601), build:dev passes.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 1628230 into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-repl-split-checkpoint branch August 28, 2026 04:06
dahai80 added a commit that referenced this pull request Aug 28, 2026
….tsx (audit 1.1.1) (#171)

Second surgical extraction from REPL.tsx (audit §1.1.1 god-module split,
continues PR #168 checkpoint). Two pure useMemo derives — onlySleepToolActive
and stopHookSpinnerSuffix — moved to src/utils/spinnerState.ts as pure
functions taking their closure deps as args. REPL keeps thin useMemo cache
wrappers. Zero closure mutation, zero behavior change.

Removed 3 now-unused REPL imports (truncateToWidth, ProgressMessage,
HookProgress) re-homed into spinnerState.ts. REPL.tsx 6811→6741 (−70 LOC).

Gates: typecheck 0 / 704 tests pass / lint net-zero 4601 / build:dev 3756 modules.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…sx (audit 1.1.1) (#172)

Third surgical extraction in the REPL.tsx god-module split (audit §1.1.1).
The three viewed-task derives (viewedTask / viewedTeammateTask / viewedAgentTask)
move from inline in REPL.tsx to a pure-function selector module:
src/tasks/viewedTaskSelector.ts. No React, no side effects — deps as args.

- getViewedTask: raw record lookup by id
- getViewedTeammateTask: teammate-only narrowed (in_progress_teammate)
- getViewedAgentTask: teammate OR local_agent — drives downstream boolean checks

REPL keeps the three const bindings as thin call wrappers (identical names,
identical downstream usage) — pure relocation + import wiring, byte-identical
behavior. Removed now-unused isInProcessTeammateTask guard import from REPL
(sole call site moved out); kept InProcessTeammateTaskState type (still used
at the panel helper) and isLocalAgentTask (two other call sites).

REPL.tsx 6741 → 6732 LOC (-9). viewedTaskSelector.ts +36 LOC (new).
Cohesion win: selector logic now reusable + unit-testable in isolation.

Gates: typecheck 0 / 714 tests pass (+10 new) / lint net-zero vs 4601 baseline
/ build:dev 3757 modules.

Follows PR #168 (leaf components, -285) + PR #171 (spinner derives, -70) in
the multi-session split. Task #170 stays in_progress — full 4-6wk split
continues in follow-up PRs.

Co-authored-by: Claude Fable 5 <[email protected]>
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