Skip to content

refactor(screens): extract stream message dispatch sub-block (audit 1.1.1 slice #30) - #201

Merged
dahai80 merged 1 commit into
mainfrom
refactor/repl-stream-message-dispatch
Aug 29, 2026
Merged

dahai80 merged 1 commit into
mainfrom
refactor/repl-stream-message-dispatch

Conversation

@dahai80

@dahai80 dahai80 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.1 God-Module Split — slice #30

Extract REPL onQueryEvent → handleMessageFromStream first callback (L2954-3016, 62-LOC message-dispatch sub-block) into src/utils/streamMessageDispatch.ts as createStreamMessageDispatch(ctx) factory returning the (newMessage) => void callback.

What it does

Routes an incoming streamed message to the right setMessages mutation:

  • compact-boundary → replace (or append in fullscreen) + bump conversationId
  • ephemeral tool-progress tick → replace last same-tool tick (no array blowup — 13k+ observed / 120MB transcript)
  • otherwise → append
    Plus proactive setContextBlocked toggle on API errors / success.

Why this slice

Pure-routing sub-block extraction class (proven via slices #19/#25-#29): reads only setters + module helpers, no React hooks, no closures over REPL state beyond the explicitly-passed ctx. ~9 deps via ctx object vs the parent onQueryEvent's 15+ — manageable, avoids the getToolUseContext factory ctx-reconstruct risk (lesson #18).

Byte-identical

Factory passes the same setMessages/setConversationId/proactiveModule the inline closure captured. Removed now-unused isEphemeralToolProgress import (import-cleanup lesson #22); isCompactBoundaryMessage kept (still used at L3073).

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 921 pass
  • bunx biome check — exit 0 (info-only useNodejsImportProtocol matches REPL's pre-existing "crypto" convention)
  • bun run build:dev — pass

Delta

REPL 6034 → 5976 (−58 net). New file 105 LOC. Cumulative across 30 slices: REPL 7096 → 5976 (−1120).

Continues #170 (design-level REPL split). All slices byte-identical, no env gates.

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

….1.1 slice #30)

Extract REPL onQueryEvent → handleMessageFromStream first callback
(L2954-3016, 62-LOC message-dispatch sub-block) into
src/utils/streamMessageDispatch.ts as createStreamMessageDispatch(ctx)
factory returning the (newMessage) => void callback.

Routes incoming streamed message to the right setMessages mutation:
- compact-boundary → replace (or append in fullscreen) + bump conversationId
- ephemeral tool-progress tick → replace last same-tool tick (no array blowup)
- otherwise → append
Plus proactive context-block toggle on API errors / success.

Pure-routing sub-block extraction class (proven via slices #19/#25-#29):
reads only setters + module helpers, no React hooks, no closures over REPL
state beyond the explicitly-passed ctx. ~9 deps via ctx object vs the parent
onQueryEvent's 15+ — manageable, avoids the getToolUseContext factory
ctx-reconstruct risk (lesson #18).

REPL 6034 → 5976 (-58 net). Byte-identical behavior: factory passes the same
setMessages/setConversationId/proactiveModule the inline closure captured.
Removed now-unused isEphemeralToolProgress import (import-cleanup lesson #22);
isCompactBoundaryMessage kept (still used at L3073).

Gates: typecheck 0 / 921 tests pass / biome exit 0 / build:dev pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit b61c92d into main Aug 29, 2026
1 check passed
@dahai80
dahai80 deleted the refactor/repl-stream-message-dispatch branch August 29, 2026 05:32
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