Skip to content

Extract chatStore.ts WebSocket handlers into domain modules - #28

Merged
pufit merged 2 commits into
mainfrom
pufit/extract-chatstore-ws-handlers
Apr 6, 2026
Merged

pufit merged 2 commits into
mainfrom
pufit/extract-chatstore-ws-handlers

Conversation

@pufit

@pufit pufit commented Apr 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Extract the 600-line handleWSMessage switch from chatStore.ts (1307→484 lines) into 4 domain-specific handler modules + 2 helper modules
  • Eliminate all 18 as any casts via proper Extract<WSMessage, { type }> discriminated union narrowing
  • Deduplicate done/stopped panel cleanup into shared finalizeRunningPanels()
  • No component import changes — purely internal reorganization

New file structure

web/src/stores/
├── chatStore.ts              # Thin: state + actions + 30-line dispatcher
├── handlers/
│   ├── streamingHandlers.ts  # thinking, token, tool_use, tool_result, done, stopped, error
│   ├── sessionHandlers.ts    # session_updated/status/switched/forked/resumed/archived/running, answer_injected
│   ├── panelHandlers.ts      # plan_update, subagent_start, subagent_complete, hoa_progress
│   └── auxiliaryHandlers.ts  # interaction, file_changed, notification(s), background_tasks_update
├── helpers/
│   ├── blockHelpers.ts       # appendBlockToPanel, updateToolResultInPanel, auto-close timers
│   └── bufferReplay.ts       # applyStreamEvent, rebuildPanelTabsFromBuffer, deriveStatus, extractTodos

Test plan

  • npm run build passes (tsc + vite)
  • Streaming works — send a message, tokens flow in real-time
  • Session switch restores buffered streaming state
  • Sub-agent panel opens/completes/auto-closes
  • Stop button works, notifications popup, file changes indicator updates

Generated by Nerve

pufit added 2 commits April 6, 2026 16:54
Break the 1307-line monolithic chatStore into a thin dispatcher (484 lines)
plus domain-specific handler and helper modules:

- handlers/streamingHandlers.ts — thinking, token, tool_use, tool_result, done, stopped, error
- handlers/sessionHandlers.ts — 8 session lifecycle handlers + answer_injected
- handlers/panelHandlers.ts — plan_update, subagent_start/complete, hoa_progress
- handlers/auxiliaryHandlers.ts — interaction, file_changed, notifications, background_tasks
- helpers/blockHelpers.ts — panel block append/update, auto-close timers
- helpers/bufferReplay.ts — session reconnect replay, deriveStatus, extractTodos

Eliminates all 18 `as any` casts via proper Extract<WSMessage, { type }> narrowing.
Deduplicates done/stopped panel cleanup into shared finalizeRunningPanels().
No component import changes — purely internal reorganization.
Update web-ui.md stores section and nerve-dev SKILL.md project layout
to reflect the new handlers/ and helpers/ directory structure.
@pufit
pufit merged commit 16a0b1d into main Apr 6, 2026
@pufit
pufit deleted the pufit/extract-chatstore-ws-handlers branch April 6, 2026 21:01
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