Repository navigation
refactor(screens): extract rewindConversationTo + restoreMessageSync into rewindMessageState (audit 1.1.1) - #180
Merged
Conversation
…into rewindMessageState (audit 1.1.1) Slice #10 of the REPL.tsx god-module split (audit §1.1.1). Extract the rewindConversationTo + restoreMessageSync useCallback bodies (~90 LOC) into a pure-helper bundle at src/utils/rewindMessageState.ts. No React, no JSX, no hooks — calls only passed setters + direct pure-fn imports. REPL keeps thin useCallback wrappers (deps arrays verbatim, ref-assign preserved) so downstream reads the same const names → byte-identical. setConversationId wrapped with a lambda to satisfy Dispatch<SetStateAction> contravariance (useState(randomUUID()) infers a template-literal UUID type; helper param typed ReturnType<typeof randomUUID>). feature("CONTEXT_COLLAPSE") dynamic require relocates verbatim (bun:bundle macro, string-literal arg, cross-file DCE safe). Removed two now-unused REPL imports (resetMicrocompactState, ImageBlockParam). Gates: typecheck 0 / 842 tests pass (+12 new helper tests) / lint clean / build:dev ok. REPL 6628 → 6565 (−63). Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80
added a commit
that referenced
this pull request
Aug 28, 2026
…it slice #11) (#181) audit §1.1.1 god-module split. Extract the 35-LOC spinner-tip pick useCallback body from REPL.tsx into src/utils/spinnerTipPicker.ts as a pure-helper bundle (no React, no JSX, no hooks). REPL keeps a thin useCallback wrapper (deps array [setAppState, theme] unchanged verbatim) that passes refs + setters via a typed SpinnerTipPickerSetters object; downstream reads the same const name (byte-identical). Also fixes 3 pre-existing typecheck errors in the slice #10 test file rewindMessageState.test.ts (committed in PR #180), per the rule that any failing case must be located+fixed regardless of relation to the current change: - makeSetters messagesRef typed {current: Message[]} not {current: unknown[]} - promptSuggestion toEqual cast to Record<string, unknown> (prev literal narrowed the type, excess-prop check on the 5-field literal failed) - spyOn logSpy dropped 'as never' so .mockRestore() is not on 'never' REPL 6565 → 6538 (−27); cumulative off 7096 now −558. Gates: typecheck 0 / test 842 pass / lint clean / build:dev pass. Co-authored-by: Claude Fable 5 <[email protected]>
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.
Summary
Slice #10 of the REPL.tsx god-module split (audit §1.1.1). Extracts the
rewindConversationTo+restoreMessageSyncuseCallbackbodies (~90 LOC) into a pure-helper bundle atsrc/utils/rewindMessageState.ts.Approach
Pure-helper bundle pattern (proven lowest byte-identical risk):
useCallbackwrappers (deps arrays verbatim,restoreMessageSyncRef.current = restoreMessageSyncref-assign preserved) → downstream reads same const names → byte-identical.setConversationIdwrapped with a lambda at both call sites to satisfyDispatch<SetStateAction>contravariance:useState(randomUUID())infers a template-literal UUID type; helper param typedReturnType<typeof randomUUID>.feature("CONTEXT_COLLAPSE")dynamicrequirerelocates verbatim —bun:bundlemacro, string-literal arg, cross-file DCE safe.resetMicrocompactState,ImageBlockParam).LOC
REPL 6628 → 6565 (−63). Real-body win (slice #9 regressed because trivial OR-chains had no body to amortize call-object overhead; this slice moves ~90 LOC of real compute).
Verification
bun run typecheckbun test src/__tests__/bunx biome check(new files)bun run build:devNew tests cover real branching: message-not-found early-return,
lastIndexOflast-match,setAppStatepermission-mode restore (differs/none/same),promptSuggestionreset,textForResubmittext path, base64 image-paste restore (explicitimagePasteIds+ fallbackindex+1), non-base64 skip (empty map), no-image skip.feature("CONTEXT_COLLAPSE")branch is compile-time dead underbun test(no flag) → not tested per Rule 9.Related
~/fusion/audit/fusion-code-audit-result-0827.md§1.1.1Co-Authored-By: Claude Fable 5 [email protected]