Skip to content

fix(terminal): type Safari dictation once and keep refused IME text out of the pane - #1850

Merged
devswha merged 4 commits into
mainfrom
chore/terminal-ime-rewrites
Oct 25, 2026
Merged

devswha merged 4 commits into
mainfrom
chore/terminal-ime-rewrites

Conversation

@devswha

@devswha devswha commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

What it does

Dictation into the terminal in Safari (Mac, iPad and iPhone) now types the corrected phrase once. Before, it either lost the phrase or typed every draft of it ("thi", "this", "this is", ...) ahead of the final one. Several related input paths are now safe too:

  • A SwiftKey re-composition of a word already sent no longer types the word twice.
  • With the key bar's Ctrl held, a Korean syllable still being typed in Safari is typed before the chord or key-bar key. Before, the chord took its place and the syllable was lost.
  • Text dictated where it may not go stays out of the pane. A phrase dictated while the pane is view-only is not typed later. One dictated while the pane is not ready waits in the held input until you send or discard it. A pane switch mid-dictation drops it.

Why

Safari reports dictation as insertReplacementText edits that replace the previous guess in place, with no composition events. Stock xterm sent each edit as it came. The xterm 5.5.0 patch now treats a dictation replacement at the caret like the Safari Hangul preedit it already handles: the text waits in the editor, and the next key, paste or blur sends it once. The patch also exposes finishComposition(). The terminal (useTerminalMount, useTypedKeys) calls it to send pending text as text before a held-modifier chord, a navigation key or a key-bar key. It also calls it while a refused context still refuses the text: before the role returns to interact, and into the held draft when readiness returns.

This branch was written before PaneTerminal.tsx was split into hooks. It is rebased onto current main, with its PaneTerminal edits moved into src/lib/useTerminalMount.ts and src/lib/useTypedKeys.ts unchanged in substance. In the xterm patch, main's oscStringState addition and this branch's finishComposition now sit side by side.

Design precedent: native macOS terminals (Terminal.app and iTerm2) keep provisional input as marked text and send only the inserted result to the shell. Dictation and a pending Hangul syllable work the same way here. The DESIGN.md entry under the terminal input notes names the same precedent.

The replay sequences adapt Agent of Empires' tests (MIT, credited in THIRD_PARTY_NOTICES.md). They are synthetic event replays in headless Chrome, not a native keyboard.

Relation to #1654

#1654 (Linux IME digit candidate) edits the same file, patches/@xterm%[email protected], but a different code path: the keydown handling of plain digits on Linux in Terminal.ts. This PR changes CompositionHelper.ts (Safari replacement preedit) and adds the public finishComposition(). Neither fix depends on the other. Whichever merges second needs a rebase of the patch file, plus hunk offsets regenerated with bun patch. The behaviours should not conflict.

How it was verified

  • scripts/terminal-safari-ime-regression.ts and scripts/terminal-ipad-ime-regression.ts (both called from scripts/ui-regression.ts) gain cases for dictation (with and without Safari's keydown 229), SwiftKey re-compositions, and the refused contexts (role lost mid-syllable, pane not ready with Send and with Discard, held key-bar Ctrl chord, pane switch mid-dictation). Each case asserts the exact WS input frames. Run through bun run check run against an isolated herdr after bun run build:
    • iPad/iPhone replay: PASS on MacIntel, iPad and iPhone platforms.
    • Safari replay: PASS (14 named cases, among them every new dictation, SwiftKey and refused-context case).
    • scripts/ui-regression.ts: PASS (72 suites, including both replays above).
  • The new Safari dictation case fails at the original base (nothing sent), and both refused-dictation cases failed before the second commit's fix. That was recorded on the original branch. Rerun here: this branch's Safari replay, run against origin/main's code without the fix, fails on the first dictation case (dictation replacement commits one corrected phrase: the pane received nothing, \x07 instead of This is a test.\x07).
  • Liveness probe (from the merge pass review): a probe refuses input until its pong and can end between two one-second readiness polls. Text entering the editor while input is refused now marks the refusal, so the pong commits it to the held draft. A new Safari replay case holds the page's ping, dictates, then releases the ping. The phrase and the next key wait in the draft until Send. Without the fix, the case fails, because they reach the pane ("This is a test.a"). With the fix it passes.
  • bun run check fast passed: typecheck, build, and 6380 unit tests with 0 failures.
  • Reviews: omo-native-code-reviewer approved, with no HIGH findings. One porting slip it found (a missing hook dependency) is fixed. Codex (gpt-6-astra) found no HIGH findings.

Known limitations, unchanged from the original design and left for a follow-up:

  • If the pane's readiness comes back in the middle of a dictated phrase, the part dictated so far goes to the held draft. Safari's later corrections of that text are then lost.
  • The held-draft step only covers Safari's replacement preedit. A Gboard or Chrome composition that ends after readiness returns is not held in the draft.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4865b7d and f7c965a.

Files selected for processing: 9
  • DESIGN.md
  • THIRD_PARTY_NOTICES.md
  • changelog.d/terminal-ime-rewrites.md
  • patches/@xterm%[email protected]
  • scripts/terminal-ipad-ime-regression.ts
  • scripts/terminal-safari-ime-regression.ts
  • src/components/PaneTerminal.tsx
  • src/lib/useTerminalMount.ts
  • src/lib/useTypedKeys.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal text entry in Safari on Mac, iPad, and iPhone, including dictation, SwiftKey replacements, and Korean syllables typed while Ctrl is held.
    • Prevented committed text from being duplicated or reordered when using key-bar shortcuts, pasting, or changing panes.
    • Improved handling of unfinished text when input is unavailable or a pane changes, including retaining text as a draft when appropriate.

The pull request updates xterm’s Safari composition handling and connects composition commits to terminal input and readiness transitions. It also expands Safari and iPad IME regression replays and adds related design notes, changelog entries, and attribution.

Changes: Safari terminal IME handling

Layer / File(s) Summary
Composition handling and API
patches/@xterm%[email protected]
The xterm patch handles Hangul and dictation replacement input, tracks deferred composition sends, and adds composition-finishing, textarea viewport, and OSC parser-state APIs.
Terminal commit and readiness integration
src/components/PaneTerminal.tsx, src/lib/useTerminalMount.ts, src/lib/useTypedKeys.ts
The terminal passes a composition-commit callback to mounting and typed-key handling. Pending text is committed around key input and readiness transitions, and held text follows the draft fallback.
IME replay coverage and behavior notes
scripts/terminal-*-ime-regression.ts, DESIGN.md, changelog.d/terminal-ime-rewrites.md, THIRD_PARTY_NOTICES.md
Regression replays cover dictation, SwiftKey edits, key-bar chords, pane changes, and refused-input cases. Design notes, changelog entries, and attribution describe related behavior and test sequences.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Possibly related issues

Suggested reviewers: noobear, suho-han

Merge Risk: Low · up to f7c96

If input becomes ready during dictation, part of a phrase may be held in the draft while later corrections reach the pane. This is a bounded limitation to accept or address before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the primary change: Safari dictation is committed once, and refused IME text stays out of the pane.
Description check Passed The description explains the problem, resulting behavior, implementation scope, validation results, regression coverage, design precedent, and known limitations. It uses equivalent headings instead of…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, resulting behavior, implementation scope, validation results, regression coverage, design precedent, and known limitations. It uses equivalent headings instead of the template's exact "## Change" and "## Validation" headings, but the required information is present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (4 skipped: 4 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • 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 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work for 8f06d2f: REVIEW FAILED on two points. The PR touches held input and patches/, and CodeRabbit was rate-limited, so this comment records the independent review.

  1. Dictation during a short liveness probe can skip the held input. If a probe starts and ends between two readiness samples, inputWasReady stays true. The next commit then sends text that was dictated while input was refused straight to the pane, instead of holding it in the draft. See useTerminalMount.ts:893-904, :1145-1149 and :1276, together with ws.ts:338-344 and :473-482. The PR lists this under "Known limitations", but AGENTS.md says text typed in a refused context waits in a draft. Please keep the refused context across that transition, and add a deterministic test for it.
  2. The PR body doesn't name the design precedent. src/AGENTS.md:6-10 asks for it in both the PR and DESIGN.md. DESIGN.md:2443-2451 names macOS Terminal and iTerm2, but the PR body doesn't. Please add it.

Checked and passing

  • Patch and builds: the xterm patch applies. finishComposition is present in the source, the public API and the typings. The typecheck passes, and the conventions tests pass.
  • Replays:
    • The Safari replay passes 14/14 (headless Chrome with a Safari user agent).
    • The iPad, iPhone and Mac replays pass.
    • terminal-input-regression passes.
    • Component probes for Chrome on Mac and Android composition pass.
  • Behaviour confirmed:
    • A corrected dictation phrase is typed once.
    • A SwiftKey re-composition doesn't type twice.
    • A Hangul syllable is typed before a Ctrl chord.
    • Observe mode refuses the input.
    • Held-draft Send and Discard work.
    • A pane switch cancels pending input.
    • Other browsers are unaffected.
  • THIRD_PARTY_NOTICES is correct.

Not verified: real Safari dictation on a device. All the evidence above comes from synthetic events.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Addressed both points of the merge-pass review in a4cca55.

  1. Dictation during a short liveness probe now goes to the held draft. useTerminalMount listens (capture) for input on xterm's textarea. When text enters the editor while socket.canInput() is false, it clears inputWasReady. The frame that ends the refusal is the probe's pong, which ws.ts passes on to the handlers after endProbe(). On that frame, noteInputReady() sees a not-ready to ready transition and commits the pending phrase into the held draft, before any later key. So the refusal counts even when it starts and ends between two readiness polls.
    • New deterministic case in scripts/terminal-safari-ime-regression.ts. The replay route holds the page's ping, the case starts a probe with an online event, dictates, releases the ping, and waits for the pong. Then it presses a and asserts that nothing reached the pane and that the draft reads This is a test.a. Send then sends it once.
    • Without the fix (useTerminalMount.ts at 8f06d2f, all else equal), the case fails: actual: "This is a test.a\u0007", i.e. the phrase and the key reached the pane. With the fix, the full Safari replay passes.
  2. The PR body now names the design precedent: macOS Terminal.app and iTerm2 keep provisional input as marked text and send only the inserted result, the same as the DESIGN.md entry.

bun run check fast passes on a4cca55: typecheck, build, and 6380 unit tests with 0 failures. The probe item is removed from "Known limitations". The other two limitations are unchanged.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Codex (gpt-6.1-sol, fast, xhigh) reviewed a4cca55. It found no HIGH findings.

  • MEDIUM: a pong that lands in the middle of dictation commits the hypothesis so far, and Safari's later corrections are lost. This is the same limitation already listed under "Known limitations" for readiness returning mid-phrase. It is left for a follow-up, because fixing it means keeping the refused mark on the live preedit until it commits.
  • LOW: without the fix, the new probe case can still pass if the one-second readiness poll happens to tick inside its probe window, which is about 100 ms. With the fix the case passes every time, and without the fix it failed in my run (This is a test.a reached the pane). Pinning the poll would need a fake page clock, and that would also stop the requestAnimationFrame steps the replay depends on, so I left it as is.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: #1852 merged (4865b7d), and this PR now conflicts with main in src/components/PaneTerminal.tsx and src/lib/useTerminalMount.ts. Please rebase onto main and push. The merge pass rechecks only the rebase delta and requeues it.

@devswha
devswha force-pushed the chore/terminal-ime-rewrites branch from a4cca55 to f7c965a Compare October 24, 2026 22:00
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main after #1852 and pushed f7c965a (was a4cca55). The two conflicts were the useTerminalMount dependency list, at the call in PaneTerminal.tsx and at the destructure in src/lib/useTerminalMount.ts. Both sides only added names, so every name from main and from this PR is kept, each in its place. Nothing else changed. bun run check fast (typecheck included) passed before the push. This is a rebase only, so it doesn't need another CodeRabbit review.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: since the rebase onto #1852, Browser regression (ui-regression) fails at f7c965a, and so does the required "Integration and browser" check. See run 40136704607, on runner P620-5.

  • scripts/ui-regression.ts failed on both attempts (exit 1, 124 s and 241 s) with AbortError: The operation was aborted. The last passing step was "key bar while the input line composes: Esc and ^C sent, direct toggle waits, line text kept", so the step right after it timed out.
  • It doesn't look like a flake. ui-regression passed on main's last 3 runs, this PR passed at a4cca55 before the rebase, and no other PR on main fails there.
  • The rebase put this PR's commitPendingText next to fix(terminal): pace attached touch-scroll bursts and end a swipe at every boundary #1852's cancelTouchRef in useTerminalMount and PaneTerminal, and both PRs change how the terminal input line and touch handling interact. That interaction is the likely cause.

Please reproduce it locally with the ui-regression browser script and push a fix. The merge pass rechecks the delta and requeues it; it stays out of the merge queue until then.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass correction: I was wrong to say it was not a flake. Attempt 2 of run 40136704607 passed ui-regression and Integration and browser on the same head (f7c965a), so attempt 1's two AbortErrors were flaky. No change is needed here, and the merge pass queues it again. The flaky timeout after the "key bar while the input line composes" step is worth its own follow-up issue.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

I checked this before pushing anything. The job passes on a rerun of the same head, so I have not pushed a fix.

Rerun: Browser regression (ui-regression) was rerun on f7c965a, with no new commit, and passed at 22:33Z. Integration and browser, Fast checks and Native Windows install are now all green on that head.

Where the failed attempts stopped: both stopped at the same case, but not in the key-bar step. That PASS line is the last top-level one. The browser log's indented ok lines go further, into checkSafariIme (scripts/terminal-safari-ime-regression.ts):

  • the last ok was "refused context: the dictated draft reaches the pane only by Send";
  • about 10.8 s later the run aborted. That matches the 10 s signal() bound in the next case, the liveness-probe dictation case added in this PR's last commit, which fires online and waits for the page's held ping.

Locally:

  • terminal-safari-ime-regression.ts on its own passes on f7c965a.
  • The full ui-regression.ts fails here in all three runs, but earlier, at "Start uses the folder Browse is showing". That assertion passes on main's CI, so it is this machine's environment, and it means the full script never reaches the IME case locally.
  • I also checked whether the case raced the page learning that the bridge answers pings: pingKnown is set only from the snapshot. With the frames logged, the page had the snapshot before the case fired online in every run, so that is not it.

On cancelTouchRef: I don't think that combination is the cause. The rebase only added names to the dependency lists in PaneTerminal/useTerminalMount; no logic changed. The stalled step is a desktop Safari-UA replay with no touch events, so #1852's touch-scroll paths don't run in it.

What I can't rule out: the case waits for a ping that online produces only when no probe is already in flight (ws.ts probe() returns while probeTimer !== null). An earlier probe still awaiting its pong would leave the case waiting until its timeout. That would make it a timing flake of this case, independent of the rebase.

If you want it hardened, I can have the case send online again on each pong until a ping is held, so a probe already in flight can't swallow it. That is event-driven, with no added sleep. Say so and I'll push it; until then f7c965a is unchanged.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

The liveness-probe dictation case is hardened in 9367b3b (test-only; one push).

Cause: the case fired a single online and waited for the page's ping. ws.ts probe() sends nothing while a probe is still in flight (probeTimer !== null). A page-side frame log showed this happening even right after a pong reaches the page: an online dispatched in the same millisecond produced no ping, because the earlier probe had not ended yet. A probe still ending when the case asks therefore leaves it waiting until its 10 s bound, which is the CI hang.

Fix (scripts/terminal-safari-ime-regression.ts):

  • The init script wraps the page's WebSocket.send to note when a ping goes out (pinged).
  • It adds askUntilPing(), which dispatches online and asks again on each animation frame until pinged is set.
  • The case subscribes to the held ping (signal("ping"), 10 s bound) before it starts askUntilPing(). It waits on that frame, with no fixed sleep.

Proof:

  • With one extra online just before the case (a probe in flight, the logged collision), the old case times out on ping and the new one passes.
  • The new case passes 3/3 plain runs.

Checks on 9367b3b:

  • bun run check fast passes.
  • The full scripts/ui-regression.ts still fails on this machine at "Start uses the folder Browse is showing", before it reaches the IME replay, as it did on f7c965a three times. That assertion passes on main's CI, so this run tells nothing about the IME case. CI's browser job is the check that covers it.

The commit is test-only, so it doesn't need another CodeRabbit review.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

The remaining red check on 9367b3b, Browser regression (other scripts), is a failure on main, not in this PR.

Everything else on 9367b3b is green, including Browser regression (ui-regression) with the hardened liveness case, and Native Windows install after its #1833 rerun.

devswha and others added 4 commits October 25, 2026 08:31
Add dictation, SwiftKey and refused-context cases to the Safari and
iPad/iPhone IME replays that scripts/ui-regression.ts already runs.

- Dictation: hypotheses thi -> this -> this is -> this is a test ->
  "This is a test." as insertReplacementText edits, with and without
  Safari's keydown 229, must reach the pane once as the corrected phrase.
- SwiftKey: a composition re-wrapping "test", "tes" extended to "test",
  and a repeated same-word composition must not duplicate the word.
- Refused contexts: a syllable committed after a server-acknowledged
  role loss, a commit while the pane is not ready (held in the draft
  until Send or Discard), a held key-bar Ctrl chord, and a pane switch
  during dictation leave nothing for the next accepted key.
- The Safari helper now waits on EventEmitter/once signals instead of a
  polling loop, and every named assertion logs its pane id and the exact
  JSON-escaped bytes.

Two defects the new cases exposed are fixed:
- Safari dictation was dropped (no keydown) or sent every hypothesis and
  then the phrase again (keydown 229). The xterm patch now starts its
  replacement preedit for an insertReplacementText at the caret, so the
  phrase is committed once by the next key, paste or blur.
- With the key bar's Ctrl held, a pending Safari syllable was sent as the
  chord and lost. The patched xterm exposes finishComposition(), and
  PaneTerminal sends the pending text as an IME commit before a typed
  chord, a held-modifier navigation key or a key-bar key.

The sequences adapt Agent of Empires' tests (MIT, credited in
THIRD_PARTY_NOTICES.md). These are synthetic event replays in headless
Chrome, not a native keyboard.

Checked: the new Safari dictation case fails at origin/main (nothing
sent) and passes with the fix; terminal-safari-ime-regression.ts,
terminal-ipad-ime-regression.ts and ui-regression.ts pass on the
isolated herdr; typecheck, src/lib/draft.test.ts, the conventions tests
and the changelog fragment test pass.
A Safari dictation phrase composed while the terminal was view only, or
while the pane was not ready, could reach the pane with the next key once
the role or readiness came back.

- The xterm patch starts no dictation preedit while the terminal takes no
  input, and PaneTerminal commits any text still pending while observing
  still refuses it, before the role returns to interact.
- Text composed while input was not ready is committed into the held
  draft when readiness returns, before its commit key, and waits there
  for Send or Discard.
- The Safari replay gains both cases: dictation while observing followed
  by an acknowledged return to interact, and dictation while not ready
  with readiness restored before the next key, then Send.

Checked with bun run typecheck, the draft, component, changelog and
conventions tests, and the Safari, iPad and UI regression scripts under
an isolated herdr session; both new replay cases failed before the fix.
A liveness probe refuses terminal input until its pong, and can end
between two one-second readiness polls. Text dictated while its ping
was out then saw input as ready on the next key and went straight to
the pane instead of the held draft.

Text entering the terminal's editor while input is refused now marks
the refusal, so the frame that ends it (the pong) commits that text to
the draft, where it waits for Send or Discard like any other refused
input.

The Safari replay holds the page's ping, dictates, releases it and
checks that the phrase and the next key wait in the draft until Send.
The case fails without the fix (the phrase and key reach the pane) and
passes with it.
@devswha
devswha force-pushed the chore/terminal-ime-rewrites branch from 9367b3b to c37bfbf Compare October 24, 2026 23:32
@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main after #1916 (80b1af8), which fixed main's chat-local-send-follow-demo-regression.ts failure, and pushed c37bfbf (was 9367b3b). The rebase was clean, with no conflicts and nothing else changed. bun run check fast passed before the push. A fresh CI run now tests this PR against the green main, so the inherited Browser regression (other scripts) red should clear.

@devswha

devswha commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED. This PR changes held input and patches/, and CodeRabbit was rate-limited, so per AGENTS.md this records the independent review. It sits alongside the earlier comment.

Lane Verdict Confidence
QA (code-review agent's matrix + the merge pass's Safari rerun; artifacts kept) PASS at a4cca55 -
Code review (omo-native-code-reviewer, programming + remove-ai-slops) PASS (WATCH) -
Gate round 1 (8f06d2f) REJECT: dictation during a short liveness probe skipped the held input; no precedent in the PR body HIGH
Gate round 2 (a4cca55) APPROVE HIGH

What was checked

  • Patch: the xterm 5.5.0 patch applies, and finishComposition is in the source, the public API and the typings. The typecheck passes, and so do the conventions tests.
  • Replays:
    • The Safari replay passes 14/14, now including the probe case. It runs in headless Chrome with a Safari user agent.
    • The iPad, iPhone and Mac replays pass.
    • terminal-input-regression passes.
    • The Chrome-on-Mac and Android composition probes pass.
  • Behaviour:
    • A corrected dictation phrase is typed once.
    • A SwiftKey re-composition isn't typed twice.
    • A Hangul syllable is typed before the Ctrl chord.
    • Observe mode refuses input.
    • Held-draft Send and Discard work.
    • A pane switch drops pending input.
    • Other browsers are unaffected.
    • THIRD_PARTY_NOTICES is correct.
  • Round 1 findings, fixed in a4cca55:
    • Text dictated during a liveness probe is now held. Reverting those 10 lines fails the new assertion.
    • The PR body names native macOS terminals (Terminal.app and iTerm2) as the precedent, which matches DESIGN.md.

Not verified: real Safari dictation on a device. All the evidence above comes from synthetic events.

Follow-ups (MINOR):

  • The new probe regression doesn't pin the 1 s readiness poll, so whether it catches the old bug can depend on scheduling.
  • Replay helpers are duplicated across the two IME scripts.

All required checks are green, and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit 9d80e8e into main Oct 25, 2026
11 checks passed
@devswha
devswha deleted the chore/terminal-ime-rewrites branch October 25, 2026 01:11
devswha added a commit that referenced this pull request Oct 25, 2026
Ovis for Mac now opens Ovis itself in its own window, as a native app.
Until now it was a setup helper: status, the phone's QR code and an
"Open in browser" button ("ovis 앱 실행해보니까 QR 이랑 브라우저에서 열기가 나오는데 그냥 바로
네이티브 앱처럼 실행하게는 할수는 없나?").

## What changes

- **The window is Ovis.** Once the server runs, the main window is a
WKWebView on the server's address (`scripts/plugin.ts status`, e.g.
`http://127.0.0.1:7317`). It has a Dock icon, Cmd+W and Cmd+Q, and keeps
its size and place. Its scene id is new (`ovis`): macOS keeps a window's
frame by its id, and the old `main` frame is the 520-wide setup window,
which an update would otherwise open the page in.
- **Setup moves to a menu.** Ovis → Phone Setup… opens the setup and the
phone's QR code in a window of their own (it also opens by itself after
an Install from the app). The main window shows the setup first only
while Ovis is not installed or not running. File → Open in Browser stays
(it opens the page as it is), and View → Reload is Cmd+R. No menu item
takes a Cmd+Shift letter: those are the page's own shortcuts
(`src/lib/shortcuts.ts`).
- **Links.** Main-frame navigation stays on the server's origin. A
same-origin new tab ("Open in a new tab" of a file) opens another Ovis
window once its page commits (a new tab that turns into a download
leaves no empty window), and an empty `window.open()` waits for its
first address. Only the Ovis page itself opens app windows, and they
outlive the page that opened them. Any other http, https or mailto
address goes to the default browser; another app's link (a web panel's
site can make one) asks first, as Safari does. A file dropped where the
page takes none is not loaded in its place. Frames inside the page (web
panels) may still show any site.
- **Reconnect.** Every 3 s the app checks `/api/health?scope=bridge`,
which needs no sign-in and leaves herdr alone. Only Ovis's own answer
counts (`ok` and `bridge_protocol`, as `scripts/plugin.ts` checks), and
a redirect is not followed, so another program on a port Ovis left
cannot hide its new address. A running page reconnects by itself when
the server is back within about 15 s and keeps what was open in it, and
it says itself when the server it meets was updated ("Save any unsent
drafts, then Reload app"). A page that did not load, or whose code never
started (its HTML loaded, its scripts did not), loads again once the
server answers. After five misses (about 15 s) the app reads the status
again: a new port is followed, and a stopped server shows the setup's
Start (the page, and what was open in it, go). The window goes back to
Ovis by itself once the server runs again, however it was started. A
check that started before Install, Restart or Remove never puts its
result over theirs.
- **Browser features.**
- Ovis's own downloads go to Downloads under a free name, and the Dock's
Downloads stack bounces. A download from another site, such as one in a
web panel, opens in the default browser instead, which asks as it does
for any site.
  - File fields open the file panel.
- The microphone is granted to the Ovis page itself; anything else, such
as a web panel's site, gets WebKit's own prompt.
- macOS asks once, with usage strings for Downloads, the microphone and
speech recognition, in English and Korean
(`Resources/ko.lproj/InfoPlist.strings`).
- A signed build carries the hardened runtime's
`com.apple.security.device.audio-input` entitlement
(`app/mac/Ovis.entitlements`, passed by `build.sh`).
- **User agent.** It ends like Safari's (`Version/<installed Safari>
Safari/605.1.15`), then `OvisMac/<version>`. Our xterm.js patch turns on
macOS Hangul handling only when the user agent says Safari, and a
WKWebView's default does not. Without that, Korean in the terminal comes
out as jamo (checked below). `OvisMac` lets the client count the window
as the installed app, so the sidebar no longer offers "Install app" with
"Choose File, then Add to Dock" inside the app (`src/lib/nativeApp.ts`,
`src/lib/install.ts`).
- The app still never stops herdr.

The design follows the Claude and Codex desktop apps: the product's UI
in its own window, with links to other sites sent to the default
browser. Setup sits behind a menu item, the way those apps keep account
and device setup out of the main window.

**Not available in a WKWebView: web notifications and Web Push.** The
page's alert settings already report push as unsupported there (its test
button is disabled), while in-app alerts still work. macOS notifications
from the app itself, through a small script bridge, are a later step.

## Checked on the test MacBook Air (eamac, macOS 27.0.1)

These ran on a fresh `/tmp` clone of this branch, built with
`app/mac/build.sh`, with the real install (plugin v0.4.13) and herdr
already running. Screen capture is blocked over ssh, so the evidence is
accessibility-tree dumps.

| Check | Result |
| --- | --- |
| Launch with the server running | The window's web area is at
`http://127.0.0.1:7317/` showing Ovis ("연결됨"), 1200×800, with no setup
text. `lsappinfo` reports a Foreground app (Dock icon). |
| Launch with an empty home (`CFFIXED_USER_HOME`) | The Install view,
with no web area. |
| Menus | Ovis: Phone Setup… (no key). File: Open in Browser. View:
Reload ⌘R. Pressing Phone Setup… opens a window with the QR code, the
phone address, Restart and Remove…. |
| External link (Settings → About, `target=_blank`) | Chrome, the
default browser, opens it in front. The Ovis window stays at
`http://127.0.0.1:7317/?settings=about`. |
| Cmd+W, Cmd+Q, size | Cmd+W closes the Phone Setup window. The window
was set to 1000×700, then Cmd+Q, then relaunched: 1000×700. Cmd+W on the
main window quits. |
| Short outage | With the command palette open, `plugin.ts stop` for 9
s, then `start`. 30 s later the palette is still open, so the page was
not reloaded; closing it shows "연결됨", so the page reconnected by itself.
|
| Long outage | After 25 s down, the window shows "꺼져 있음" with Start.
`plugin.ts start` from the CLI brings the web area back 2 s later.
Launched while the server was down: Start, then Ovis 3 s after a CLI
start. `herdr status server`: `running: true` throughout. |
| Page shortcut | Cmd+Shift+K opens the command palette with its search
field focused. |
| Paste | `pbcopy` then Cmd+V in a terminal pane: the pane's line reads
`ovis-paste-ok`. |
| Korean IME in the terminal | 2-Set Korean through System Events, keys
`g k s r m f space`: the pane reads `한글`. **Control:** the same build
with the user agent tail cut to `OvisMac/<ver>` reads `ㅎㄱ`. |
| Download | FileViewer's Download link. macOS asks for Downloads with
our text, and after Allow `~/Downloads/ovis-maw-download.txt` (24 B) is
written, and a second download of it lands as `ovis-maw-download 2.txt`.
Before the usage string was added, the prompt had an empty reason line;
a denied prompt shows an error sheet. |
| Upload | Attach file opens the file panel (`open-panel` sheet), and
Cancel closes it. |
| New tab of a file the page can't show | "Open in a new tab" of a 2 KB
binary downloads it to `~/Downloads` (same bytes), and no empty window
is left (one window). |
| Web panel | A terminal link to `http://localhost:18765/panel.html`
(another port, so another origin): a plain click opens Chrome, a
Shift-click the web panel. In the panel, `window.open('about:blank')`
returns null ("popup-refused") and opens no window. A `target=_blank`
link to `x-apple.systempreferences:` shows the sheet "이 링크를 “시스템 설정”에서
열까요?" with the URL, and Cancel closes it. |
| Same-origin new tab | "Open in a new tab" of a file opens a second
Ovis window showing the file, and Cmd+W closes only that window. With
the popup open, a 20 s outage replaced the main page (setup, then Ovis
again); the popup stayed and Cmd+W still closed it. |
| Microphone, signed build | Developer ID signed:
`flags=0x10000(runtime)`, entitlements `{audio-input: true}`, `codesign
--verify --strict` OK. Dictation brings up the speech recognition and
microphone prompts with our strings, then dictation runs. **Control:**
the same build re-signed without entitlements gives no prompt, and the
page shows "마이크 권한이 거부되었습니다". |

Not checked at runtime: a file dropped onto the page (a Finder drag
cannot be synthesized over ssh) and dark-mode colours (no screen
capture). Both are WebKit's own behaviour plus the policy in
`WebPage.swift`, and the cover shown while the page loads uses the
window's background colour, so a dark window does not flash white.

`src/lib/install.test.ts` gains a case: the Mac app's user agent counts
as installed and Safari's does not. Dropping `|| inMacApp()` fails it.
The app has no Swift tests; `swift build` (arm64 and x86_64) passes on
eamac with Swift 6.4 and no warnings beyond x86_64's deprecation.

## Windows (WebView2), for the win-setup-app

The same approach fits Windows: WebView2 is Edge's engine, preinstalled
on Windows 11 (and on Windows 10 through Edge), and the WinForms control
runs on .NET Framework 4.8. Its events map one to one:
- `NavigationStarting` and `NewWindowRequested` keep the origin in the
app and send other addresses to the browser.
- `PermissionRequested` grants the microphone.
- `DownloadStarting` handles downloads.
- `NotificationReceived` turns web notifications into Windows ones,
which a WKWebView cannot do. Web Push is unavailable there too.

The costs:
- The app is no longer a single ~55 KB exe: it ships
`Microsoft.Web.WebView2.Core/WinForms.dll` and `WebView2Loader.dll`, or
embeds them.
- A machine without the runtime needs the Evergreen bootstrapper.
- The xterm Hangul path is Safari-only, so Chromium's IME behaviour
applies, as in Chrome today.

## Review

- **Code-review agent (omo-native-code-reviewer): APPROVE in all three
rounds**, with no CRITICAL or HIGH findings. Round 1 found four MEDIUMs,
and each is fixed:
- Reloading after an outage threw away page state. Now a loaded page
reconnects by itself, and only a page that failed to load is reloaded.
- A background refresh overwrote a running Install or Restart. Now a
work generation invalidates it.
- Popups belonged to the main page's controller. Now they sit in an
app-lifetime registry.
- Unknown URL schemes went to NSWorkspace without asking. Now the app
asks first.
- Round 2 found two problems: minimized popups were released when a
download ended, and popups that failed before commit were never
released. Both are fixed in 09d6702.
- Round 3 found LOWs L1 (the root check now runs after one miss), L4 (a
closed popup's download error now shows on the main window) and L5
(comment reflow); all three are fixed in 2b5d50e. L2 and L3 remain
notes: three recovery paths have no runtime run, and the build is
checked on the macOS 27 SDK only.
- Two round-1 LOWs were left as they are: a Restart that fails while the
page is shown does not switch the window to Start, and a naming nit.
- **Codex (gpt-6.1-sol, xhigh reasoning).**
  - Round 1 found four MEDIUMs, all fixed:
- Another program's 200 on the old port hid Ovis's new address. Now only
Ovis's own `/api/health?scope=bridge` answer counts.
    - A refresh overwrote Install or Restart.
- Script-filled `about:blank` popups from a web panel stayed hidden.
They are now refused.
- Concurrent same-name downloads collided. Names are now reserved
centrally.
- Round 2 found two MEDIUMs and a LOW: a minimized popup was released
when a download ended, an interrupted React bootstrap no longer
recovered, and a popup that failed before commit was kept. All three are
fixed in 09d6702.
  - Round 3: APPROVE.
- A last short review covered the LOW fixes in 2b5d50e and the rebase
onto main a1e4f8b: APPROVE, no findings. In `git range-diff` every
patch is unchanged. Upstream touched only
`.github/workflows/mac-dmg.yml` here, and it still builds and signs
through `app/mac/build.sh`, which passes `Ovis.entitlements` and copies
`ko.lproj`.
- **Merge-pass gate review of 2b5d50e** asked for two fixes, both in
6b9712f and checked on eamac against a control build:
- A web panel's downloads were saved without asking. Now only an Ovis
page's downloads are saved, and any other site's opens in the default
browser.
- The health check followed redirects. Now a redirect counts as a miss.
- Its follow-up, keeping a draft when the app moves to a new port, is
left for a change of its own.
- **After the rebase:**
  - `bun run check fast` is green (6719 unit tests).
- On eamac, a fresh clone of the rebased branch builds with only the
x86_64 deprecation warning. It launches straight into Ovis: the web area
is at `http://127.0.0.1:7317/?ws=…&view=terminal` and reads "연결됨", with
no setup, QR or Open in browser view.
- Korean 2-Set input (`g k s r m f space`) still composes `한글` in the
terminal pane. #1850 changed the Safari-gated xterm IME path this window
relies on, so this was checked again.

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 26, 2026
Closes #1046. Related: #1635 (not implemented here, see below).

## What

On a touch screen the terminal's key bar gets a **Show keyboard / Hide
keyboard** control (`[data-key="keyboard"]`), after the Input line
switch and Paste. It moves the soft keyboard without changing the input
mode:

- **Show** focuses the field of the current input mode inside the tap,
so a phone raises its keyboard: the input line, or xterm's own textarea
in direct typing. The bar is not shown while the masked input is.
- **Hide** blurs this pane's focused field only; a sibling pane, or the
control itself focused from a hardware keyboard, is left alone.
- Its name, glyph (`PanelBottomOpen` / `PanelBottomClose`) and
`aria-pressed` follow the keyboard state `lib/viewport.ts` measured
(`data-keyboard`), never the focus. A hardware keyboard, or an occlusion
the browser cannot report, reads as down.
- It sends no key or input, changes no setting or mode, and fits or
resizes nothing (the grid under a keyboard stays, #1045). While an
application has focus reporting on (DECSET 1004), xterm reports its
textarea's focus and blur as `ESC [ I` / `ESC [ O`. The control holds a
flag around its own `focus()` / `blur()`, and `onData` drops exactly
those two reports while the flag is held. A focus the user makes still
reports.
- While a word is being composed in either field, a direct commit is
still pending, or Paste is still reading the clipboard, the control is
`aria-disabled` and refuses the tap in place. That keeps the
composition, and keeps a paste's own focus from bringing a hidden
keyboard back. View only has no control. Held, ended and offline panes
show a disabled one.
- Safari's Hangul and dictation preedit has no composition events and
waits for the next key, paste or blur (the xterm patch from #1850).
Hide's blur types it, the same way a key-bar key types it first.
Refusing instead would leave Hide refused after every word typed that
way.
- Unlike the keys, it is a Tab stop with its localized name as a
tooltip. Disabled keys draw in `--text-dim`, and the bar's focus ring is
drawn inside the key so the scroller no longer clips it.

**Design reference:** the platform's own dismiss key (iPadOS's keyboard
key, Android's ▽). It lives in the key bar with the mode switch, because
this app keeps its touch controls in the bar and its menus. That is
where it differs from agent-of-empires' floating `KeyboardFab`. It also
follows the measured keyboard rather than input focus, as the issue
asks. DESIGN.md has the entry. No code was copied.

## Not in this PR: the rest of #1046

#1046 also proposes an optional arrow-joystick key and light haptic
feedback. Neither is here. The maintainer's status on #1046 named the
keyboard key as the work left to ship. If the joystick should stay
tracked, change `Closes` to `Refs`, or keep the item on #1053.

## Not in this PR: #1635

#1635 proposes an opt-in "keyboard only when I ask" model: a setting
that sets `inputmode="none"` on every terminal field while the keyboard
is hidden, with the mode switch moved to a long press. That is a
separate, larger design, and the control here does not do it. Taps on
the grid, the line and the key bar behave as they do on main. This
control would be the natural toggle for that model if it lands.

## Tests and checks

- `src/lib/keyboard.test.ts`: `keyboardToggleAction` and
`subscribeKeyboardUp`.
- `scripts/terminal-keyboard-demo-regression.ts` (browser lane), on the
real client over the demo transport as a phone. It checks:
- focus of the current mode's field, the measured state, and the draft
and caret;
  - that a composition refuses the tap;
  - that a sibling pane is never touched;
  - view only, held, offline and ended panes;
- no focus reports with DECSET 1004 on, while the user's own focus still
reports;
  - that no input, keys, resize or take-over frame is sent.

  It also writes a 390 / 1440, light / dark, en / ko capture set.
- Determinism (the open item on #1046): the captures used to wait for
the demo's one-shot finish droplet to attach. The page's clock runs on
its own while the page and its fonts load, so a slow load let the
droplet expire before that wait, and the run hung. The captures now run
the clock past the completion and do not draw the droplet (as
`sidebar-filter-demo-regression.ts` does), so no step waits on a
transient.
- `scripts/key-bar-customization-demo-regression.ts`: an empty key list
keeps the fixed controls `direct`, `paste`, `keyboard`.

## Reviews

- omo-native-code-reviewer: APPROVE, no blockers. Fixed: Hide during a
pending Paste was undone by the paste's own focus (now refused),
DESIGN.md wording about the fixed controls and Paste's note, and the
masked-input branch of Show, which the bar could never reach (removed).
- Codex (gpt-6.1-sol, xhigh): three Medium findings.
  - The i18n entries belonged in the terminal dictionary part. Fixed.
- Safari's replacement preedit is not refused. Kept on purpose, see
above.
- Show in one split pane makes a focused sibling pane report its blur
(`ESC [ O`). Kept: the sibling really loses the focus, and a tap into
this pane's line does the same. Refusing Show there would leave the
selected pane without its keyboard. DESIGN.md now says this.

## Local checks

- `bun run check fast` passed on the pushed commit: workflow syntax,
generated types and themes, typecheck, build and unit tests.
- `terminal-keyboard-demo-regression.ts` passed 3 runs in a row (2
before the review fixes, 1 on the final commit).
`keyboard-viewport-demo-regression.ts` and
`key-bar-customization-demo-regression.ts` passed.
- 390 and 1440 captures checked by eye: the order is Input line, Paste,
keyboard control; the glyph and pressed state follow the measured
keyboard; the desktop has no key bar and is unchanged.

Co-authored-by: mp <mp@local>
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