Skip to content

refactor(terminal): move the grid's and the pane's lifetimes, and the sends into hooks - #1764

Merged
devswha merged 1 commit into
mainfrom
refactor/terminal-lifetime-hooks
Oct 23, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/terminal-lifetime-hooks

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

PR 2 of the PaneTerminal.tsx split. The plan is .omo/plans/paneterminal-split.md in the maintainer's workspace, and plan-reviewer approved it. It follows PR #1758, which moved the mount effect.

This PR moves four blocks out of src/components/PaneTerminal.tsx into four hooks. Each block moves as one unchanged span. Each hook is called at the exact line its block occupied, so hook order, effect order and cleanup order stay as they are. Every effect keeps its dependency list, and every callback keeps its useCallback dependencies.

src/components/PaneTerminal.tsx goes from 1,967 to 1,477 lines.

What moves

Hook Block Deps Returns
src/lib/useTerminalRefits.ts the six theme, font and fit effects (133 lines) 27 nothing
src/lib/usePaneAttach.ts the reset layout effect on a pane or terminal replacement ([paneId, terminalId]) and the two one-line effects after it (80 lines) 50 nothing
src/lib/useTerminalSends.ts the send callbacks and the direct-typing effect (144 lines) 37 sendDraft, discardDraft, submitComposerMessage, sendComposerText, sendTerminalLine, reassertGrid, pressEnter, toggleDirect
src/lib/useComposerSends.ts composerSend and actOnPending (138 lines) 29 composerSend, actOnPending
  • The hooks: each follows useTerminalMount's pattern. A <Name>Deps interface lists every name the block reads from the component, each typed as the component declares it, and the hook destructures it on its first line. A missed name would be a type error.
  • Call order in PaneTerminal.tsx: useTerminalMount, then useTerminalRefits, then usePaneAttach. Further down, where their blocks stood, come useTerminalSends and useComposerSends. usePaneLane(stackRef) does not move.
  • Order pin: src/conventions.test.ts used to check that the mount hook comes before the attach reset effect, found via }, [paneId, terminalId]);. That effect now lives in usePaneAttach, so the pin checks that useTerminalMount( comes before usePaneAttach(. Swapping the two calls fails it.
  • src/lib/i18n.test.ts: PART_FILES.terminal gains lib/useComposerSends.ts, because the moved callbacks' t() keys belong to the terminal part.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD shows 1,009 lines as moved. The other 229 lines are:
    • PaneTerminal.tsx's narrowed imports, the four new imports and the four call lines;
    • the new files' imports, the four Deps interfaces (143 field lines), signatures, destructuring lines and returns;
    • the pin's two-line adaptation and the PART_FILES entry.
  • Moved blocks are exact: each original span (lines 797-929, 931-1010, 1070-1213 and 1386-1523 of PaneTerminal.tsx on e3aec1528) appears byte for byte inside its hook.
  • Typecheck: bun run typecheck passes.
  • Unit tests: HERDR_TEST_MODE=unit bun test src/conventions.test.ts src/lib/i18n.test.ts src/lib/settings.test.ts scripts/conventions.test.ts: 117 pass, 0 fail.
  • bun run check fast: passes (unit 6253 pass, 0 fail, 13 skip in 443 files, 8 at a time, 61.1s)
  • bun run check integration browser: the browser lane exits 0 (every browser script passed, 2085 s), run on this commit before its rebase onto the latest main (which changed only src/App.tsx, src/app-hooks.test.ts and server files). The integration lane had three failures, none in code this PR touches: server/api.contract.test.ts "creates, edits, searches, inspects, and closes an owned workspace" (line 1540, fails the same way on unchanged origin/main on this PC), and two in server/gjc.contract.test.ts ("binds same-cwd panes independently by native PID…", "falls back to scrollback when the native GJC binding is missing": pane.process_info did not yet list the isolated GJC process while another lane ran beside it). Rerun alone, server/gjc.contract.test.ts passes. CI runs the integration lane in its own environment.

Outside PRs that touch the same files

No other maintainer PR touches these files. One outside contributor's PR touches src/components/PaneTerminal.tsx: #1639. git merge-tree shows it still merges cleanly with both main and this branch.

The moved blocks include the attach reset, the queued-input sends and the pending-message actions. A code-review agent's stand-in review may be wanted before the merge.

Move-only: moved blocks plus imports, deps interfaces, four calls, the adapted order pin and one PART_FILES entry. No changelog fragment: users see no change.

… sends into hooks

The four blocks move verbatim into useTerminalRefits, usePaneAttach,
useTerminalSends and useComposerSends, each called where its block stood so
hook and effect order are unchanged.
The order pin now checks useTerminalMount before usePaneAttach.
PART_FILES gains lib/useComposerSends.ts, the file with t() keys.
Plan .omo/plans/paneterminal-split.md PR 2.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between d6bf59b and 088c2dc.

📒 Files selected for processing: 7
  • src/components/PaneTerminal.tsx
  • src/conventions.test.ts
  • src/lib/i18n.test.ts
  • src/lib/useComposerSends.ts
  • src/lib/usePaneAttach.ts
  • src/lib/useTerminalRefits.ts
  • src/lib/useTerminalSends.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: move-only PR (PaneTerminal split, PR 2). As AGENTS.md allows, it merges on its checks without waiting for CodeRabbit.

It moves the queued-input callbacks (composerSend, actOnPending), so the gate review below stands in for the real review AGENTS.md requires.

Diff

  • Comparing removed and added lines, the only differences are:
    • imports;
    • the four *Deps interfaces and their destructures;
    • the four calls and their return destructures;
    • the order pin;
    • i18n PART_FILES.

Gate review (on a different model than the author's): no findings.

  • Replacing the four hook calls with their extracted bodies rebuilds the original component function byte for byte. That proves each block sits at its exact former position, and that hook order, effect order, cleanup order and every dependency list are unchanged.
  • No dep is read before its declaration (no TDZ error), no mutable binding is captured early, and no ref is passed as .current instead of the ref.
  • composerSend and actOnPending are unchanged. Drafts are still held on disconnect, and prompt answers still go through /api/pane/prompt/answer.

Checks

  • 180 unit tests pass: conventions, compose, i18n, pendingMessages, settings.
  • The typecheck passes at this head.
  • terminal-input-regression passes, including pane-reset cancellation.
  • The pin fails if the mount and attach calls are swapped.

Overlap: outside contributor #1639 touches src/components/PaneTerminal.tsx and will need a rebase.

All required checks, the browser lanes included, are green, and no review thread is open.

@devswha
devswha merged commit 2fa93ab into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the refactor/terminal-lifetime-hooks branch October 23, 2026 13:40
devswha added a commit that referenced this pull request Oct 23, 2026
…1767)

PR 3 of 3 of the PaneTerminal.tsx split. The plan is
`.omo/plans/paneterminal-split.md` in the maintainer's workspace, and
plan-reviewer approved it. It follows PR #1758 and PR #1764.

This PR moves the chat lens's terminal logic out of
`src/components/PaneTerminal.tsx` into three hooks. Each block moves as
one unchanged span. Effects keep their dependency lists, and callbacks
keep their `useCallback` dependencies.

`src/components/PaneTerminal.tsx` goes from 1,477 to 1,174 lines. Over
the three PRs it went from 3,665.

## What moves

| Hook | Block | Deps | Returns | Called |
|---|---|---|---|---|
| `src/lib/usePeekReturn.ts` | after a peek: the manual-peek and
auto-return state, the still-open note, the input-row frame watch, and
the peek-end layout effect (153 lines) | 29 | 12 names | where the block
stood |
| `src/lib/useChatCallbacks.ts` | the chat lens's callbacks and state:
conversation watch, terminal output, sent and metadata, greeting room,
prompt, suggestion, restore and pending answer (90 lines) | 12 | 28
names | where the block stood, right after `usePeekReturn` |
| `src/lib/useTypedKeys.ts` | the key bar's `pressKey` and
`toggleModifier` (30 lines), and Hermes' one-Ctrl+C stop guard with
`abortTurn` (34 lines) | 16 | `pressKey`, `toggleModifier`, `abortTurn`
| where the stop block stood |

### Hook and effect order

- **`useTypedKeys`:** the key-bar callbacks used to sit about 15 lines
above the stop block. They have no effects, and only JSX reads them, so
creating them a few hooks later changes nothing. Nothing between the two
old positions reads them.
- **`usePeekReturn` and `useChatCallbacks`:** each sits exactly where
its block was, so their effects run in the same order as before.

### Other changes

- **`StillOpen`:** this was a local type alias inside the component. Two
hooks now use it, so it moves to `src/lib/paneTerminalShared.ts` as an
exported type. Types have no runtime effect.
- **`src/lib/i18n.test.ts`:** `PART_FILES.terminal` gains
`lib/usePeekReturn.ts` and `lib/useTypedKeys.ts`, because their `t()`
keys belong to the terminal part.
- **Imports:** `PaneTerminal.tsx` drops the imports only the moved code
used.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 629
lines as moved. The other 116 lines are:
- `PaneTerminal.tsx`'s narrowed imports, the three new imports and the
three calls;
- the hooks' imports, three `Deps` interfaces (57 field lines),
signatures, destructuring lines and returns;
  - the `StillOpen` type's move;
  - the two `PART_FILES` entries.
- **Moved blocks are exact:** lines 646-735, 819-848 and 863-896 of
`PaneTerminal.tsx` on `2fa93ab49` appear byte for byte in their hooks.
Lines 493-645 do too, apart from the one `StillOpen` line.
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** `HERDR_TEST_MODE=unit bun test src/conventions.test.ts
src/lib/i18n.test.ts src/lib/settings.test.ts
scripts/conventions.test.ts src/lib/terminalPeek.test.ts
src/lib/keyBar.test.ts src/lib/hermesStop.test.ts`: 163 pass, 0 fail.
- `bun run check fast`: passes after the rebase (unit 6253 pass, 0 fail,
13 skip in 443 files, 8 at a time, 57.5s)
- **`bun run check integration browser`:** the browser lane exits 0
(every browser script passed, 1895 s), run on this commit before its
rebase onto the latest main (which changed only `src/App.tsx`,
`src/app-hooks.test.ts`, `src/lib/useSidebarLayout.ts` and server
files). The integration lane's only failure is
`server/api.contract.test.ts` "creates, edits, searches, inspects, and
closes an owned workspace" (line 1540, `/api/pane/files` returns `[]`),
which fails the same way on unchanged `origin/main` on this PC. CI runs
the integration lane in its own environment.

## Outside PRs that touch the same files

No other maintainer PR touches these files. One outside contributor's PR
touches `src/components/PaneTerminal.tsx`: #1639. It already conflicts
with main (`src/lib/i18n.ja.ts`, `src/lib/i18n.ko.ts`,
`src/lib/i18n.zh.ts`) and needs a rebase either way; against this branch
it conflicts in `src/components/PaneTerminal.tsx`, `src/lib/i18n.ja.ts`,
`src/lib/i18n.ko.ts`, `src/lib/i18n.zh.ts`.

The moved blocks include the queued-input stop path, Hermes' stop guard
and the peek's auto-return. A code-review agent's stand-in review may be
wanted before the merge.

Move-only: moved blocks plus imports, deps interfaces, three calls, one
shared type and two `PART_FILES` entries. No changelog fragment: users
see no change.
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