Skip to content

refactor(screens): extract rewindConversationTo + restoreMessageSync into rewindMessageState (audit 1.1.1) - #180

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

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-rewind-restore-bundle

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Slice #10 of the REPL.tsx god-module split (audit §1.1.1). Extracts the rewindConversationTo + restoreMessageSync useCallback bodies (~90 LOC) into a pure-helper bundle at src/utils/rewindMessageState.ts.

Approach

Pure-helper bundle pattern (proven lowest byte-identical risk):

  • No React, no JSX, no hooks — helper calls only passed setters + direct pure-fn imports.
  • REPL keeps thin useCallback wrappers (deps arrays verbatim, restoreMessageSyncRef.current = restoreMessageSync ref-assign preserved) → downstream reads same const names → byte-identical.
  • setConversationId wrapped with a lambda at both call sites 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).

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

Gate Result
bun run typecheck 0 errors
bun test src/__tests__/ 842 pass / 0 fail (+12 new helper tests)
bunx biome check (new files) clean
bun run build:dev ok

New tests cover real branching: message-not-found early-return, lastIndexOf last-match, setAppState permission-mode restore (differs/none/same), promptSuggestion reset, textForResubmit text path, base64 image-paste restore (explicit imagePasteIds + fallback index+1), non-base64 skip (empty map), no-image skip. feature("CONTEXT_COLLAPSE") branch is compile-time dead under bun test (no flag) → not tested per Rule 9.

Related

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

…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
dahai80 merged commit a9f9a3b into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-rewind-restore-bundle branch August 28, 2026 10:36
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]>
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