Skip to content

🤖 refactor: decompose the ChatInput composer into deep hooks - #4013

Open
ibetitsmike wants to merge 18 commits into
mike/arch-turn-context-assemblerfrom
mike/arch-composer-hooks
Open

🤖 refactor: decompose the ChatInput composer into deep hooks#4013
ibetitsmike wants to merge 18 commits into
mike/arch-turn-context-assemblerfrom
mike/arch-composer-hooks

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Decomposes the 4,011-line ChatInput composer (ChatInputInner: 27 useState / 37 useRef / 32 useEffect conflating 7 concerns) into three deep hooks plus a pure send-preflight function, with a net -142 LOC delta. Behavior-preserving: no UX, keybind, or feature changes.

Background

Refactor #7 from the 2026-08-29 architecture review (evidence at f04e0f8a3). Every keystroke re-evaluated all 32 effects; the ~570-line send preflight and the four suggestion channels were untestable without DOM, and the four channels duplicated the same cursor/token logic.

Implementation

  • useComposerSuggestions (~500 lines): unifies the four suggestion channels (slash command, @-mention, skill, symbol) behind a single cursor/token seam. Self-contained per repo guidance: derives experiments, plugin enablement, and draft-discovery state internally; the boundary is the input seam plus identity. The token matcher is a pure exported function with DOM-free tests.
  • useComposerAttachments (~190): attachment state, processing counts, PDF/media-type validation, paste/drop/pick entry points, and draft-attachment persistence.
  • useComposerDraft (~160): storage-key scoping (workspace/creation/pending-draft), input persistence and restore across workspace switches, draft-review lifecycle.
  • prepareMessagePayload (~140): pure payload assembly extracted from handleSend; the remaining orchestrator is guard, async resolution, prepare, dispatch. Covered by table-driven unit tests, including the compaction-metadata ref gate (proven red-green).
  • index.tsx: 4,011 to 2,924 lines; effects reduced (32 to ~22). No manual memoization anywhere in the new hooks (React Compiler convention); the two effects that previously leaned on useCallback identity now key on data (editingMessage?.id) or hand out latest-ref wrappers (onReady API), and the document keydown listener uses a latest-ref handler attached only on visibility.
  • Caret state is keyed to the input it was measured against, falling back to end-of-text for external input changes (draft restores, persisted-state writes), preserving pre-extraction semantics; symbol auto-conversion propagates the converted text/cursor into the seam.

Net LOC

  • Production: +1,170 / -1,309 (-139)
  • Tests: +294 / -297 (-3)

Irreducible additions: useComposerSuggestions consolidates four previously duplicated channel implementations behind one seam (replacing ~640 deleted lines from index.tsx/CommandSuggestions.tsx); prepareMessagePayload + its tests (+211) make the send preflight unit-testable for the first time, offset by pruning mock-heavy structure-asserting tests (CommandSuggestions.test.tsx -79, symbolShortcuts.test.ts -92 net, collapsed into table-driven cases).

Validation

  • Remote dogfood UAT (regression-focused): 27 scenarios at desktop and 375 px widths, endorsed PASS covering typing, all four suggestion channels, attachments (image + PDF, button/paste/drag-drop), draft save/restore across workspace switches, edit mode + boundary confirm, destructive-command modal, Escape/Enter keybinds, and send/queue during a live stream. Both anomalies found were proven pre-existing via target-vs-base comparison.
  • Review-round hardening: CI caught two real regressions that were bisected and fixed with deterministic local repros: a stale suggestion caret when input is written externally (jest fileMentionsWithSlashCommands) and an edit-populate effect that clobbered in-progress edit text once draft helpers lost useCallback identity (e2e review.spec). Both suites now pass locally and in CI, alongside make static-check and whole-file bun runs of all touched test files.

Risks

Highest-traffic UI surface in the app. The riskiest moves are the unified suggestion token seam (channel trigger/filter/selection semantics), the send preflight extraction, and the effect re-keying described above. Mitigated by the new pure unit tests, the full UAT regression pass, the e2e/jest coverage that already caught the two regressions, and keeping ChatInputProps/ChatInputAPI unchanged.


Generated with xum • Model: anthropic:claude-fable-5 • Thinking: xhigh • Cost: $155.26

Stack

Layer 8/10 of the architecture refactor stack (net -5,101 LOC overall). This PR's diff is only this layer, against mike/arch-turn-context-assembler.

@chatgpt-codex-connector

This comment has been minimized.

@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

This comment has been minimized.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e4d1387ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/browser/features/ChatInput/useComposerSuggestions.ts Outdated
Comment thread src/browser/features/ChatInput/useComposerSuggestions.ts Outdated
Comment thread src/browser/features/ChatInput/prepareMessagePayload.ts Outdated
Comment thread src/browser/features/ChatInput/useComposerSuggestions.ts
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 0029120994

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

This comment has been minimized.

@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

This comment has been minimized.

@chatgpt-codex-connector

This comment has been minimized.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d92b0b4b6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d92b0b4b6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/browser/features/ChatInput/useComposerSuggestions.ts
Comment thread src/browser/features/ChatInput/index.tsx Outdated
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ce45d50a5c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

This comment has been minimized.

@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 74d4e1380b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

This comment has been minimized.

@ibetitsmike
ibetitsmike force-pushed the mike/arch-composer-hooks branch from 74d4e13 to 6ea1b80 Compare August 30, 2026 16:39
@ibetitsmike
ibetitsmike changed the base branch from main to mike/arch-turn-context-assembler August 30, 2026 16:39
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

This comment has been minimized.

@ibetitsmike
ibetitsmike force-pushed the mike/arch-composer-hooks branch from 6ea1b80 to 33414ea Compare August 30, 2026 17:13
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

This comment has been minimized.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 33414ea75e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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