Repository navigation
refactor(repl): extract setMessages routing (audit §1.1.1 slice #16) - #186
Merged
Merged
Conversation
Extract the setMessages state-sync wrapper from REPL.tsx into a pure helper src/utils/messagesSetter.ts (applySetMessages). No React hooks, no JSX, no await — only side effects are mutating 3 refs (messagesRef/userInputBaselineRef/userMessagePendingRef) and calling rawSetMessages, byte-identical to the inlined useCallback body. The body maintains a ref mirror of the messages array plus two placeholder-tracking refs: (1) compute next (functional action or direct value) and sync messagesRef.current; (2) if next shrank (compact/rewind/clear) clamp baseline to 0 so the placeholder length check can't go stale; (3) if next grew while userMessagePending, inspect the added slice — if it contains a human turn, clear pending (user message landed); otherwise bump baseline to next.length so the placeholder stays visible for async bridge/hook/scheduled messages landing ahead of the user message. REPL keeps a thin useCallback wrapper whose deps array [] is unchanged verbatim (all deps are refs + rawSetMessages captured in the setters object, no closures). Downstream reads the same const name. Tests (src/__tests__/utils/messagesSetter.test.ts, 8 cases) cover: direct-value vs functional action, shrink clamp, grow-with-human (clears pending), grow-without-human (bumps baseline), grow-without- pending (no-op), prepend slice path, and the prev-empty guard. Real isHumanTurn predicate (type==='user' && !isMeta && toolUseResult===undefined) exercised via minimal fake messages. Gates: typecheck 0 / 873 tests / biome clean / build:dev pass. REPL 6455 -> 6434 (-21). Cumulative across 16 slices: -662. 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.
Audit §1.1.1 god-module split — slice #16
Extract the
setMessagesstate-sync wrapper fromsrc/screens/REPL.tsxinto a pure helper.What
src/utils/messagesSetter.ts—applySetMessages(action, setters): no React hooks, no JSX, no async. Side effects: mutate 3 refs (messagesRef/userInputBaselineRef/userMessagePendingRef) + callrawSetMessages. Byte-identical to the inlineduseCallbackbody.src/screens/REPL.tsx—setMessagesuseCallbackreplaced with thin wrapper; deps array[]unchanged verbatim (all deps are refs +rawSetMessagescaptured in the setters object, no closures). Downstream reads same const name.src/__tests__/utils/messagesSetter.test.ts— 8 cases: direct-value vs functional action, shrink clamp, grow-with-human (clears pending), grow-without-human (bumps baseline), grow-without-pending (no-op), prepend slice path, prev-empty guard. RealisHumanTurnpredicate exercised via minimal fake messages.Body semantics (preserved verbatim)
next(functional action or direct value), syncmessagesRef.current.nextshrank (compact/rewind/clear) → clampuserInputBaselineRefto 0 (placeholder length check can't go stale).nextgrew whileuserMessagePending→ inspect added slice: contains human turn → clear pending (user message landed); otherwise bump baseline tonext.length(placeholder stays visible for async bridge/hook/scheduled messages landing ahead of the user message).Gates (all pass)
bun run typecheckbun test src/__tests__/bunx biome check(new files)bun run build:devLOC
REPL 6455 → 6434 (−21). Cumulative across 16 slices: −662.
byte-identical
useCallbackdeps array[]unchanged verbatim → closure identity preserved.isHumanTurnimport kept in REPL (still used at L1492).Co-Authored-By: Claude Fable 5 [email protected]