Skip to content

refactor(screens): extract restoreReadFileState to pure helper (REPL split slice #12) - #182

Merged
dahai80 merged 1 commit into
mainfrom
refactor/slice12-restore-readfile-state
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
refactor/slice12-restore-readfile-state

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Context

audit §1.1.1 god-module split (task #170). Continues the multi-session REPL.tsx extraction series (slices #168-#181 landed). This slice extracts the restoreReadFileState useCallback body into a pure helper.

Change

  • NEW src/utils/readFileStateRestore.ts — pure helper restoreReadFileState(messages, cwd, setters). No React, no JSX, no hooks. Only side effect: mutates the two passed-in refs (readFileState.current = mergeFileStateCaches(...), bashTools.current.add(tool)), matching the original deps=[] useCallback body verbatim. Exports RestoreReadFileStateSetters type.
  • MOD src/screens/REPL.tsx — import the helper as restoreReadFileStateImpl; replace the useCallback body with a thin wrapper that forwards { readFileState, bashTools }. Downstream reads the same const restoreReadFileState name → byte-identical. Two now-unused imports dropped (mergeFileStateCaches, extractBashToolsFromMessages).
  • NEW src/__tests__/utils/readFileStateRestore.test.ts — 5 cases: bashTools accumulation, cross-call Set union (no dup), readFileState.current ref reassignment (merge returns clone → new ref), non-bash tool_use skip, non-string command skip.

byte-identical proof

deps=[] on the REPL useCallback is unchanged (no closure deps — refs are passed in). The helper reproduces the exact mutation order (merge then add). Downstream call sites read the same const restoreReadFileState and pass the same args. Off = today's behavior (no env gate needed — this is a pure extraction, no new behavior).

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 847 pass / 0 fail
  • bunx biome check on new files — clean (REPL.tsx baseline net-zero, untouched)
  • bun run build:dev — 3769 modules, ./fusion-code-dev built

REPL 6538 → 6529 (−9 LOC; −567 cumulative off 7096 baseline).

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

…split slice #12)

audit 1.1.1 god-module split. Extract the restoreReadFileState useCallback
body from REPL.tsx into a pure helper src/utils/readFileStateRestore.ts.
No React, no JSX, no hooks; only side effect mutates the two passed-in refs
(readFileState.current = mergeFileStateCaches, bashTools.current.add),
matching the original deps=[] useCallback verbatim. REPL keeps a thin
useCallback wrapper (deps unchanged); downstream reads the same const name
-> byte-identical. Two now-unused imports dropped (mergeFileStateCaches,
extractBashToolsFromMessages).

Tests: src/__tests__/utils/readFileStateRestore.test.ts (5 cases) assert
bashTools accumulation, cross-call Set union, readFileState.current ref
reassignment (merge returns clone), non-bash skip, non-string-command skip.

Gates: typecheck 0 / 847 tests / lint clean new files / build:dev 3769 modules.
REPL 6538 -> 6529 (-9 LOC; -567 cumulative off 7096 baseline).

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit ef118cb into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the refactor/slice12-restore-readfile-state branch August 28, 2026 13:11
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