Repository navigation
refactor: the conversation runs in a controller outside React, split by concern; useConversation renders its store - #145
Merged
bencode merged 2 commits intoOct 13, 2026
Conversation
…ssion helpers as pure modules, the history list and the draft save queue on their own
…by concern into drafts, agent session, navigation, run, settings, titles and history; useConversation only renders its store
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.
Stacked on #144. Merge that first; this PR then retargets to
main.What
features/conversation/use-conversation.ts(945 lines) was one hook. It held all of these, with state shared through 17 refs:That orchestration now runs in a controller outside React, split by concern.
useConversationcreates the controller, renders its store and feeds it what lives in React (the draft attachments and the memory switch). Its return shape is unchanged, so the panel, composer and context are untouched.features/conversation/use-conversation/)index.tscontroller.tscreateConversationController: builds the store, runtime and draft queue; the public APIstate.tsConversationState(rendered, a zustand vanilla store, as incore/agent/background.ts),Runtime(the former refs),Ctxdrafts.tsagent-session.tsnavigation.tsrun.tssettings.tstitles.tshistory.tsmessages.ts,session.ts,draft-queue.tsEach module exports plain
(ctx, …)functions, and the imports run one way: history ← drafts ← titles / agent-session ← navigation, run, settings ← controller ← hook. Function bodies, messages and ordering are carried over. ReadingactiveRef.currentbecamestore.getState().active, which is just as synchronous.Three things differ, none of them visibly:
configureModelreads the current phase rather than the one closed over at render.toolsis taken once, when the controller is created.useWorkspaceToolsmemoizes it on stable inputs only, so it never changed in practice.Tests
Rendering from a zustand store (
useSyncExternalStore) happens sooner than batcheduseStateupdates did. Two integration tests waited for one signal and then asserted a second, asynchronous one synchronously:Those follow-up assertions now wait (
findByRole/waitFor). Each test passes 10 of 10 in isolation, andpnpm checkpasses twice in a row.End to end (local server, agent-browser)
/compact(40.5K to 21.1K): the summary and usage survive a reloadTurning memory off is not distinguished by this check: the model repeated its earlier answer. That path is the same
memoryChangedcode as turning it on.