Skip to content

refactor(repl): extract setInputValue routing (audit §1.1.1 slice #17) - #187

Merged
dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice17-setinputvalue
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice17-setinputvalue

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.1 god-module split, slice #17.

Extract

useCallback body (27 LOC, 3 deps) → pure-helper src/utils/inputValueState.ts applySetInputValue().

Same aggregate-input pattern as slices #15 (composedOnScroll) + #16 (setMessages):

  • Typed InputValueStateSetters (7 fields): trySuggestBgPRIntercept, repinScroll, setInputValueRaw, setIsPromptInputActive, inputValueRef, lastUserScrollTsRef, recentScrollRepinWindowMs.
  • REPL keeps useCallback thin wrapper, deps array [setIsPromptInputActive, repinScroll, trySuggestBgPRIntercept] unchanged verbatim.
  • RECENT_SCROLL_REPIN_WINDOW_MS (REPL-local const = 3000) passed as recentScrollRepinWindowMs field to keep helper pure-agnostic.

Behavior (byte-identical)

  1. trySuggestBgPRIntercept(prev, value) hit → early return (no side effects).
  2. empty→non-empty + scroll-stale (Date.now() - lastUserScrollTsRef >= window) → repinScroll() (fullscreen typing re-pin; lastUserScrollTsRef starts 0 so first keypress always repins).
  3. sync inputValueRef.current + setInputValueRaw(value) + setIsPromptInputActive(value.trim().length > 0).

Tests

src/__tests__/utils/inputValueState.test.ts — 8 cases:

  • empty→non-empty repin + write + activate
  • intercept early-return (no ref write, no setters)
  • non-empty→non-empty no repin (empty→non-empty guard)
  • scroll within-window (no repin) / boundary (repin at >=)
  • empty value deactivate + ref sync
  • whitespace-only → active=false (trim().length > 0)
  • ref syncs BEFORE setters fire

Gates

Gate Result
bun run typecheck 0 errors
bun test src/__tests__/ 881/881 pass (was 873, +8 new)
bunx biome check (new files) clean (no fixes applied)
bun run build:dev ok
REPL import churn zero (git diff grep empty)

LOC

REPL 6434 → 6420 (−14). Cumulative 7096 → 6420 (−676) across 16 slices.

Continues audit §1.1.1 (task #170). Surgical, byte-identical behavior.

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

Extract setInputValue useCallback body (27 LOC, 3 deps) to pure-helper
src/utils/inputValueState.ts applySetInputValue(). Same aggregate-input
pattern as slices #15/#16: typed InputValueStateSetters (7 fields),
REPL keeps useCallback thin wrapper, deps array
[setIsPromptInputActive, repinScroll, trySuggestBgPRIntercept] unchanged
verbatim. RECENT_SCROLL_REPIN_WINDOW_MS (REPL-local const 3000) passed as
recentScrollRepinWindowMs field to keep helper pure-agnostic.

Behavior: (1) trySuggestBgPRIntercept(prev,value) hit -> early return;
(2) empty->non-empty + scroll-stale (>= window) -> repinScroll;
(3) sync inputValueRef.current + setInputValueRaw + setIsPromptInputActive(trim>0).

Tests: 8 cases (repin+write+activate, intercept early-return, non-empty
guard, scroll within-window/boundary, empty deactivate, whitespace guard,
ref-sync-before-setters). 881/881 pass, typecheck 0, biome clean, build:dev ok.

REPL 6434 -> 6420 (-14). Cumulative 7096 -> 6420 (-676) across 16 slices.
Zero REPL import churn. Byte-identical behavior (deps + ref reads unchanged).

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit cb13c5e into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit/repl-split-slice17-setinputvalue branch August 28, 2026 14:36
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