Repository navigation
refactor(repl): extract setResponseLength pure helper (audit §1.1.1 slice #18) - #188
Merged
Merged
Conversation
…lice #18) Extract the 16-LOC setResponseLength useCallback body from REPL.tsx into a pure routing helper src/utils/responseLengthState.ts. The body mutates two refs (responseLengthRef + apiMetricsRef) with no JSX, hooks, or async — a pure-helper extraction (lowest byte-identical risk class, same proven pattern as slice #17 applySetInputValue). REPL keeps a thin useCallback wrapper (deps [] unchanged) calling applySetResponseLengthImpl once; downstream reads the same const name → byte-identical behavior. The 3 body comments move into the helper file header (equivalent semantic documentation). Gates: typecheck 0 / 887 tests pass (+6 new for the helper) / biome clean (1 noNonNullAssertion warning = pre-existing style, original body used the same `!`) / build:dev passes / zero REPL import churn. REPL: 6420 → 6415 (−5 net), cumulative −681 across 17 slices (7096 → 6415). 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
Audit §1.1.1 god-module split — slice #18. Extracts the 16-LOC
setResponseLengthuseCallbackbody fromsrc/screens/REPL.tsxinto a pure routing helpersrc/utils/responseLengthState.ts.Extraction class
Pure-helper (lowest byte-identical risk). The body:
responseLengthRef+apiMetricsRef)applySetInputValue)REPL keeps a thin
useCallbackwrapper (deps[]unchanged) callingapplySetResponseLengthImplonce. Downstream reads the same const name → byte-identical behavior. The 3 body comments move into the helper file header (equivalent semantic documentation).Behavior preserved
setResponseLength(f):responseLengthRef.current = f(prev)(always)> prev(growth, not flat/shrink) → update the last metrics entry:lastTokenTime = now+endResponseLength = new valuelength > 0guard)Gates
bun run typecheck— 0 errorsbun test src/__tests__/— 887 pass (+6 new for the helper)bunx biome check— clean (1noNonNullAssertionwarning = pre-existing style; original body used the same!)bun run build:dev— passesTests
New
src/__tests__/utils/responseLengthState.test.ts(6 tests, 15 assertions): f(prev) application, growth updates last entry (mockedDate.now), flat no-op, shrink no-op, empty-array safe no-op, last-entry-only update.Progress
REPL: 6420 → 6415 (−5 net). Cumulative −681 across 17 slices (7096 → 6415).
Co-Authored-By: Claude Fable 5 [email protected]