Skip to content

useCoder: split into 12 domain sub-hooks under src/coder/ (#1447 pass I) - #1462

Merged
currentbits merged 14 commits into
mainfrom
coder/refactor-i-split-usecoder-into-sub-hooks-32bffe
Oct 5, 2026
Merged

currentbits merged 14 commits into
mainfrom
coder/refactor-i-split-usecoder-into-sub-hooks-32bffe

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Round 4, pass I of #1447. useCoder was one ~3,500-line hook holding all renderer-side app state. Its domain logic now lives in 12 sub-hooks under src/coder/, which useCoder composes. The state map, domains and reasoning are in docs/superpowers/specs/2026-10-05-usecoder-split.md.

Sub-hook Lines Domain
useCoderThreadActions 901 per-thread actions
useCoderWorkspace 395 worktree, diff, files, attachments
useCoderRuns 372 thread create/fork, run start/rewind
useCoderGitHub 269 push, PR, checkout, issues
useCoderAgentTools 215 agent config, MCP, skills, harness, CLI
useCoderWorkflows 214 workflows, automations, workflow runs
useCoderRepoTools 188 git sync, dev servers, merge lanes, terminal
useCoderThreadRemoval 148 delete/restore/purge thread, remove project
useCoderMemory 115 memory and code map
useCoderProjects 109 project CRUD
useCoderUpdates 56 updater actions
useCoderInsights 55 activity, usage, digest, crew reads

Two plain modules, webAttachments.ts and errorMessage.ts, hold the non-hook helpers. src/useCoder.ts: 4,510 → 2,119 lines.

What stays in useCoder:

  • The core: all state, the refs, the boot effect and the 8 effects. Their order matters, for example selectedRef updating before the detail-load effect reads it.
  • A few small leftover runs, too small to be worth a sub-hook.

Checked

  • Effect order: the 12 sub-hooks contain no effects; they are useCallback/useMemo groups only. A script compares the original and the new useCoder with each sub-hook expanded at its call site. Both give the same 8 effects in the same order.
  • Public shape: useCoder's return object has the same 220 keys as main, with no spreads.
  • Pure move, ignoring indentation: the only non-move lines are the sub-hook calls and their argument objects. Bodies and dependency arrays are verbatim, and state setters stay out of deps, as before.
  • npm run typecheck and npx vite build are clean. Renderer suite: 2701/2701, 0 cancelled (TAP count).

🤖 Generated with Claude Code

Willem and others added 14 commits October 5, 2026 11:28
…1447)

Verbatim move of the contiguous searchMemory..loadCodeMap block; the
sub-hook is called where the block was, so the flattened hook order is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…useCoderAgentTools (#1447)

Verbatim move of the contiguous lintAgentConfig..listCliSessions block,
called where the block was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CoderInsights (#1447)

Verbatim move of the contiguous listActivity..crewIntegration block,
called where the block was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… into useCoderRepoTools (#1447)

Verbatim move of the contiguous gitSyncInfo..terminal block, called where
the block was. setSpotlight's setProjects is now a parameter; it is the
same stable setter, so its [api] deps keep their meaning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Verbatim move of the contiguous addProject..updateProject block, called
where the block was. errorMessage moves verbatim to src/coder/errorMessage.ts
(gains only `export`) so sub-hooks can share it without importing useCoder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Verbatim move of the contiguous failUpdate..downloadUpdate block, called
where the block was. failUpdate stays internal to the sub-hook. The hourly
check effect and UPDATE_CHECK_INTERVAL_MS stay in useCoder.ts:
test/updateCheck.test.tsx reads that file's source for the interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…useCoderWorkflows (#1447)

Verbatim move of the contiguous refreshWorkflows..removeWorkflow block
(it includes startWorkflowRun/retryWorkflowAgent, which sat between the
template and automation callbacks), called where the block was.
upsertWorkflow moves with its only caller. Inputs are the same values the
closures read before; deps arrays are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ub (#1447)

Verbatim move of the contiguous pushBranch..fetchIssue block, called where
the block was. Inputs are the same values the closures read before (stable
setters, refs, applyThreads/applyThreadUpdate, and selectedThreadId); deps
arrays are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oderWorkspace (#1447)

Verbatim move of the contiguous listBaseBranches..dropAttachmentFiles
block, called where the block was; saveAttachmentFile stays internal to
the sub-hook (it was never returned). The web attachment helpers move
verbatim to src/coder/webAttachments.ts; the three the sub-hook calls
gain `export`. None were exported from useCoder.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ions (#1447)

Verbatim move of the contiguous stopRun..requestTeachReview block (39
useCallbacks, no effects), called where the block was. Inputs are the same
values the closures read before (stable setters, refs, applyThreads, and
selectedThreadId); deps arrays are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nto useCoderRuns (#1447)

Verbatim move of the contiguous createThread..rewindAndResubmit block,
called where the block was. projects, settings and selectedProjectId are
passed as the same per-render values createThread's deps listed, so its
identity changes on exactly the same renders as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ject into useCoderThreadRemoval (#1447)

Verbatim move of the contiguous deleteThread..removeProject block, called
where the block was. refreshTrashed and applyThreads are passed in; both
keep their identities (deps [api] and []), so these callbacks' deps keep
their meaning. applyThreadUpdate stays in useCoder: three sub-hooks take it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 7d349ce into main Oct 5, 2026
6 checks passed
@currentbits
currentbits deleted the coder/refactor-i-split-usecoder-into-sub-hooks-32bffe branch October 5, 2026 11:18
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