Skip to content

Open the new tab chord where the keyboard is - #244

Merged
yansfil merged 8 commits into
mainfrom
feat/new-tab-where-keyboard-is
Sep 28, 2026
Merged

yansfil merged 8 commits into
mainfrom
feat/new-tab-where-keyboard-is

Conversation

@yansfil

@yansfil yansfil commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #239

Summary

Closes #239.

Command T (Option T in a browser) always created an agent tab in the Agent column's active area, even with the keyboard in a side panel View area.
It now follows the recorded keyboard owner, as the close chord does, through a new newTabPolicy beside closeShortcutPolicy:

  • Keyboard in a panel View area: that area's New tab, a browser display with no address and the address field focused.
  • Keyboard in an Agent pane: an agent tab at the end of the Agent area showing that pane.
  • Anywhere else (sidebar, Overview, tools, Agent controls, closed panel): the Agent active area, as before.

The desktop menu's New tab reaches the same action.
To deliver a chord pressed in a native page, the host hands focus back to the shell, and the browser re-announces focus on the element that had it before the page.
The recorder used to treat that as a move, so Command T from a page opened an agent tab and Command W closed the pane that had held the keyboard earlier.
It now ignores that re-announcement while the delivered command runs, which fixes both chords; once the command has run, the owner follows the shell element holding the keyboard, so after any other command from a page (Command B, say) the next chord acts where the operator types.
The View strip's + shows the chord, and docs/UI_BEHAVIOR.md no longer calls the View New tab "the file palette".

Keyboard in the note.txt editor, Option T: a New tab browser display in the View strip with the address focused, the agent tab count unchanged

After: the keyboard was in the note.txt editor, and Option T opened New tab beside it in the View strip; before, it added a zsh tab to the Agent column.

Review

  • Please judge: the page's owner lasts only while the command it handed back for runs (noteCommandDelivered in web/src/keyboard.ts onCommand). After Command T from a page, the owner is the terminal until the new display's address takes focus, a moment later.
  • Please judge: the + tooltip in the View strip now shows the chord, the way the Agent strip already does, even though it only applies while that area holds the keyboard.
  • Files to watch: web/src/viewFocus.ts installKeyboardOwner and noteCommandDelivered - the ignored refocus sits on the high-frequency focus path, one comparison per event; the settle runs once per menu command, and both change the Command W owner too.
  • Files to watch: web/src/actions.ts newTabFocused - it reads the drawn View frame and the drawn Agent frame, and a stale frame would send the tab to the wrong column.
  • The web pane case cannot tell the routings apart: focusing a pane activates its area, and a core area focus moves the keyboard to that area's pane. When a second client sent focus_area, the keyboard followed into the other area. So a pane owner in one area with a different active area cannot be driven, and the pane test stays a regression guard.

Evidence

  • Confirmed:
    • Desktop e2e new-tab.spec.ts: a terminal held the keyboard, then the native page did, then the shell got focus back.
      • The menu's New tab then opens a View tab with a focused, empty address, and there is no agent tab.
      • The menu's Close tab closes the page's display, and both panes stay.
      • The page takes the keyboard, then Command E runs from the menu: the next Close tab closes the terminal's pane, and the page's display stays.
      • A click back into a terminal makes New tab an agent tab again.
    • Mutation, refocus ignore removed: the desktop test fails at the Command T step, with View tabs still at 1.
    • Mutation, settle after the command removed: the desktop test fails at the Command E step, with the pane still there.
    • The desktop test runs at a CI runner's 1024-point window with the sidebar hidden, and passed 5 times in a row next to desktop close-policy; desktop keys and desktop also pass.
    • focusPageTakingAppFocus in the desktop test is the one place it steals the app's focus.
    • Web e2e new-tab.spec.ts:
      • Keyboard in a View area: Option T opens a second View tab with a focused, empty address, and the agent tab count stays at 2.
      • Keyboard in a pane in either of two Agent areas: the tab lands in that area.
      • Keyboard on the panel toggle: the tab lands in the active area.
    • Mutation: with new_tab routed back to createTab, the web View case fails.
    • Unit tests: viewFocus.test.ts covers View, pane, tools, none, the Agent controls, a closed panel, another Workspace and a vanished pane.
    • Gates: scripts/verify-web.sh passes, as do web e2e new-tab and close-policy, check-no-workstation-identity.sh and check-design-contract.mjs.
  • Not confirmed:
    • The re-announced focus is replayed in the test, not produced by macOS. On the test machine, Electron cannot become the key window (isFocused() stays false after app.focus({ steal: true })), and the existing browser.spec.ts zoom test fails at the same poll there.
    • Playwright also emulates page focus, so a real hand-back may not reach the shell under test. The test takes the host's real path wherever the window can be key.
    • No native Command T keystroke was pressed in the installed app.
More evidence

Keyboard in the right Agent area's pane, then in the left one: each Option T added a tab to that area.

Two Agent areas with two tabs each

AI tooling: Mostly AI tools; the routing, the refocus rule, the doc wording and each e2e assertion were checked against the issue and review by hand, and both e2e tests were checked by mutation.

Command T (Option T in a browser) now follows the recorded keyboard owner,
as the close chord does: in a panel View area it opens that area's New tab,
a browser display with no address and the address field focused; in an
Agent pane it adds an agent tab at the end of the area showing that pane;
anywhere else it keeps the Agent active area. The desktop menu's New tab
reaches the same action, including while a native page holds the keyboard.

The View strip's New tab now shows the chord, and UI_BEHAVIOR no longer
calls it the file palette.
… the columns plainly

The desktop test now waits for the page to report focus in the key window,
so the menu click takes the path a real Command T does, handing the
keyboard back to the shell first.
…r a menu command

To deliver a menu command pressed in a native page, the desktop host
focuses the shell, and the browser announces focus again on the element
that had it before the page. The keyboard owner recorder took that as a
move, so Command T opened an agent tab and Command W closed the pane that
had held the keyboard before the page. The recorder now ignores focus on
that element until a pointer press or focus lands anywhere else.

The desktop test replays that hand-back after a terminal held the
keyboard, for both chords, and fails without the fix.
… has run

The host hands the keyboard to the shell for every menu command pressed in
a native page, not only Command T and Command W. The page stayed the owner
until the next pointer press or focus elsewhere, so after Command B from a
page, typing went to the terminal while the next Command W closed the
page's display. The command now runs with the page's owner, and once it
has run the owner follows the shell element holding the keyboard.

The desktop test covers Command B then Command W closing the terminal's
pane, and waits for the page's focus through a counter installed before
the page is entered.
yansfil added a commit that referenced this pull request Sep 28, 2026
…one test fixtures (#245)

Related: 2a8e6d1 is on `feat/overview-lenses` (#238); the maintenance
guard was found while working on #242. This lands both on `main`.

## Summary

- The clone test fixtures (`hide-host/tests/clone.rs`,
`herdr-core/src/runtime/tests/repository_clone.rs`) commit, then run a
local `git clone --bare`.
- `git commit` starts a detached `git maintenance run --auto`, which can
pack and prune loose objects while the clone is still copying them.
- On macOS CI runners this fails a random clone test with "failed to
copy file ... No such file or directory" in the fixture, before the code
under test runs.
- Tonight it failed the `rust workspace` lane of #242 (twice), #243 and
#244, always at `clone.rs:24`.
- The fixtures' `git` calls now turn off auto maintenance and auto gc,
and the bare origin is cloned with `--no-local` (a pack through Git's
transport, no file copy). Test-only.

## Review

- **Please decide**: whether landing this on `main` before #238 is fine;
2a8e6d1 is identical to the commit on `feat/overview-lenses`, so #238
merges over it cleanly.
- **Files to watch**: `herdr-core/src/runtime/tests/repository_clone.rs`
- preventive: the same fixture shape, not observed failing.

## Evidence

- **Confirmed**: `cargo test -p hide-host --test clone` passes 5/5
locally; the hide-host race reproduced locally under forced background
gc before the maintenance guard and not after (measured while working on
#242).
- **Not confirmed**: the flake rate on CI after the change beyond this
PR's own runs; the herdr-core fixture never reproduced.

**AI tooling**: mostly AI tools; the diff is three cherry-picked
commits, compared by hand.
A CI runner's screen is 1024 points wide, where the side panel covers the
agents while the sidebar shows, so the terminal click landed on the page's
slot. The test sizes the window to 1024 points, hides the sidebar, clicks
each terminal at its left edge, and uses Command E as the other command
since it leaves the agents uncovered. The helper that steals the app's
focus is named for it.
yansfil added a commit that referenced this pull request Sep 28, 2026
Related: #232, #244

## Summary

Closes #232.
Desktop e2e windows used to come to the front and take the keyboard:
`show()` activates the app, and a second launch called `show()` plus
`focus()`.
Under a `--hide-show-inactive` switch that only `desktop/e2e/fixture.ts`
passes, the host now calls `showInactive()` and then `blur()`: the
window appears without activating the app and is sent behind every other
window.
A Finder, Dock or `open` launch carries no switch and keeps `show()` /
`show()+focus()`.
The claim is enforced on every run: the fixture preloads
`desktop/e2e/focus-guard.cjs`, which records each time the app becomes
active or a window takes the keyboard. Any test not tagged
`@needs-focus` that recorded one fails.
Two tests need the key window and are tagged `@needs-focus`, and each
focuses its window explicitly: browser zoom and close-policy's
browser-page step. Close-policy's other Command W coverage stays
untagged. `pnpm --dir desktop e2e --grep-invert @needs-focus` skips the
tagged tests.

No screenshot: the change is window ordering and activation, and native
window capture is refused on this machine's locked session (see
Evidence).

## Review

- **Please judge**: no off-screen placement.
macOS clamps a framed window so part of it stays on the display. On the
1920x1080 display, asked x=-2000 landed at x=-760 (a 40 px strip);
x=2420 landed at 1880; y=1580 landed at 969; y=-2000 landed at 30.
Sending the window to the back does more: `showInactive()` alone put the
test window at z=0 above all 12 other app windows, and `blur()` moved it
to z=12, behind all of them, still painting at 60 fps with no activation
event.
- **Please judge**: `sendCommand`'s `webContents.focus()` (`host.ts`) is
not gated. It runs only after a browser page was given native focus
(`webContents.isFocused()`), which only `@needs-focus` specs do.
`docs/ARCHITECTURE.md` now lists it, along with minimized-window
restore, the folder picker sheet and Reveal in Finder, as the paths the
switch does not cover.
- **Please judge**: CI runs the full suite, `@needs-focus` included, and
CI launches also use the switch. This reads "CI keeps its current
behavior" as "CI still runs everything".
- **Please judge**: `pnpm --dir desktop e2e` locally still runs the two
`@needs-focus` tests, which take focus. Should the local default exclude
them unless `CI` is set?
- **Files to watch**: `desktop/e2e/fixture.ts` - every spec now imports
`test` from it, and `launch` throws otherwise.
- **Files to watch**: `desktop/src/main/host.ts` `present()` - the only
show path; with no switch it must stay `show()` / `show()+focus()`.
- **Coordination**: after this merges, #244
(`desktop/e2e/new-tab.spec.ts`) will not compile or run until it changes
three things:
it imports `test` from `./fixture`, not `@playwright/test` (`launch`
throws otherwise);
it drops `{ switches: [...] }`, which `launch` no longer accepts, so the
build fails as it stands;
and it tags its `electron.focus({ steal: true })` test with
`NEEDS_FOCUS`, or the focus guard fails it.
- **Follow-up**: the second-launch process in `desktop.spec.ts`'s
lifetime test runs without the guard or the switch. It quits at the
single-instance check before `ready`, and the first instance decides the
behavior.

## Evidence

- **Confirmed (CI, b214785)**: `verify` green. The desktop e2e ran 21
tests in macos-15's unlocked session: 20 passed and 1 skipped
(remote-workspace).
Both `@needs-focus` tests passed, and the focus guard found no
activation in any of the 18 untagged tests.
- **Confirmed (local, locked session)**: final head, full `pnpm --dir
desktop e2e`: 18 passed, 1 skipped, 2 failed. The skip is
remote-workspace, which needs `HIDE_E2E_SSH_PORT`.
The two failures are the `@needs-focus` tests, which fail the same way
on `main` here: on a locked session nothing can become the key window.
- **Confirmed**: an activation probe (run-local `-r` preload wrapping
`BrowserWindow.show/showInactive/focus`, `app.focus`,
`webContents.focus`).
On `main`: 24 `show()`, plus `show()`+`focus()` on the second-launch
reopen.
On this branch: the host calls only `showInactive()`. The
`app.focus`/`focus` calls all come from the two `@needs-focus` tests.
- **Confirmed**: a guard report write that fails is logged to stderr,
not thrown. Teardown closes any app a test left running before it
removes the report folder. A test that timed out with its app running
left no app process behind.
- **Confirmed**: the guard catches reports. In a throwaway spec, a
synthetic `browser-window-focus` after launch failed the untagged test
and passed the tagged one. A report written the moment the guard loads,
before Playwright attaches, did the same.
- **Confirmed**: desktop typecheck, lint and vitest (48); the `scripts`
lane (unittest 32, identity and invariant scripts).
- **Not confirmed, operator check for the morning**: this Mac's session
was locked for every run (`CGSSessionScreenIsLocked`), and on it even
`app.focus({ steal: true })` activates nothing.
So the frontmost-app record (sampled every 0.5 s; `loginwindow` via
lsappinfo and `Preview` via System Events throughout, on `main` too)
cannot tell the old behavior from the new.
The guard likewise never fires locally; CI's unlocked session above is
where it ran for real.
Morning check: run `pnpm --dir desktop e2e --grep-invert @needs-focus`
while working in another app, and record `osascript -e 'tell application
"System Events" to get name of first process whose frontmost is true'`
before, during and after.
- **Not confirmed, operator check for the morning**: occluded painting
as pixels. `screencapture -l` was refused on the locked screen, and
Electron's `capturePage()` renders on demand, so it proves nothing about
occlusion.
The only local signal: a covered window's `requestAnimationFrame`
counter kept advancing at about 60 fps with `visibilityState` "visible",
under a covering window at a higher layer and after `blur()`.
Morning check: capture a covered test window twice by window id and
compare.

**AI tooling**: mostly AI tooling; no person has yet watched a run on an
unlocked Mac.
… as needing focus

The fixture now adds the occluded-window switch itself and fails a test
that brings the app forward unless it is tagged, so the new-tab test takes
test and NEEDS_FOCUS from the fixture and launches without switches.
@yansfil
yansfil merged commit ff15bd1 into main Sep 28, 2026
7 checks passed
@yansfil
yansfil deleted the feat/new-tab-where-keyboard-is branch September 28, 2026 13:59
yansfil added a commit that referenced this pull request Oct 29, 2026
…ir causes (#1833)

Closes with-hide/hide-private#256
Closes with-hide/hide-private#244
Closes with-hide/hide-private#226
Closes with-hide/hide-private#267
Closes with-hide/hide-private#163
Closes with-hide/hide-private#266
Closes with-hide/hide-private#230
Closes with-hide/hide-private#264
Closes with-hide/hide-private#265
Closes with-hide/hide-private#212
Closes with-hide/hide-private#141
Closes with-hide/hide-private#282
Related: with-hide/hide-private#326 (제품 쪽 후속), #1811

## Summary

Windows에서 데스크톱 앱 시작·정리와 hided daemon 수명 테스트가 가끔 실패하던 것을 원인별로 고칩니다. 제한
시간과 재시도는 그대로입니다.
가장 잦던 실패(#256)는 job에서 처음 시작하는 Windows PowerShell과 새 `hided`의 cold 비용이 첫
테스트의 제한 시간 안에 들어간 것이었고, 테스트 전에 한 번 먼저 시작합니다.
정리 실패(#244 등)는 Playwright의 `app.close()`가 앱 프로세스가 끝나기 전에 돌아오는 것이었고,
fixture가 그 프로세스의 종료까지 기다립니다.
hided 테스트의 private Herdr는 pane shell까지 끝난 뒤에 폴더를 지웁니다. 나머지는 테스트가 잘못 기대하던
것(아직 없는 파일 읽기, delta 모양, 탭 선택 순서)을 계약대로 고쳤습니다. 제품 코드는 바뀌지 않습니다.

스크린샷 없음: 화면과 제품 코드를 건드리지 않음(e2e fixture와 테스트만).

<details><summary>이슈별 원인과 처리</summary>

- **#256** Add a project(Windows desktop job의 첫 테스트): Herdr는 cmd.exe
pane에서 agent를 `powershell.exe -NoLogo -NoProfile -EncodedCommand`로
띄웁니다(Herdr v0.9.5 `interactive_shell_command`). desktop lane은 첫 테스트 전에
PowerShell을 한 번도 돌리지 않아, 첫 `agent start` 두 개가 46초(제한 30초) 걸렸고 이후 시작은
0.35초였습니다(run 40821395497). web lane은 globalSetup의 `endVctip`이
PowerShell을 먼저 돌려 이 실패가 없습니다. 10-23에는 같은 첫 테스트에서 job의 첫 `hided` 시작이 24초
걸려 "hided did not respond"가 됐습니다(run 39930517565, 평소 0.4-0.9초). -> 두
entry point가 같은 `prepareWindowsRun`으로 Herdr와 같은 형태의 PowerShell 시작과
`hided node --version`을 테스트 전에 한 번 하고 걸린 시간을 출력합니다. desktop에는 없던
`endVctip`도 함께 합니다.
- **#244 #226 #267** "candidate exit unconfirmed": Windows에서 Playwright는
Electron을 cmd.exe 아래에서 띄우고(`shell: true`), `close()`는 앱의 디버그 파이프가 닫히면
context가 disposed되어 `TargetClosedError`를 삼키고 돌아옵니다(playwright-core
1.63). 기록된 프로세스(cmd.exe)는 그 뒤에 끝나고, cleanup은 바로 `exitCode`를 읽었습니다. ->
fixture의 `close()`가 그 프로세스의 `exit`까지 10초 안에서 기다리고, 넘으면 pid를 말하며
실패합니다(home은 보존).
- **#163** product analytics: `expect.poll`은 콜백이 던진 오류를 재시도하지 않습니다.
daemon의 첫 저장 전에 `core-state.json`을 읽어 ENOENT로 즉시 실패했습니다. -> 없는 파일은 "아직
저장 안 됨"으로 읽고, 다른 오류는 그대로 던집니다.
- **#266** handshake: semantic delta는 한 burst에서 바뀐 필드를 모두 싣습니다. 느린
runner에서는 시작 직후의 link backfill이 UI 변경과 같은 frame에 `navigator`를 실었습니다(실패
로그에 `backfill.done`). -> "navigator가 없다" 대신 "partial delta가 싣는 필드는 모두 그
reader가 가진 값과 다르고, 전체보다 적다"를 단언합니다.
- **#230** hide-ai usage: usage child는 `fake-claude.cmd` -> `python`이고 그
step이 job의 첫 python 실행입니다(보통 0.9-3.7초, 나쁜 run 21-30초). -> TESTING.md
Rust 규칙 8의 `stand_ins::ready_with_args`로 fake를 먼저 한 번 시작합니다(`FAKE_ENV`
lock 안에서).
- **#264 #265 #212** connect_stop: 이 step이 job의 첫 debug `hided` 시작입니다.
보통 0.8-1.2초, 나쁜 run은 세 테스트가 함께 10-18초, 그 재시도도 6-10초(첫 시작의 cold 비용이 끝나는
시점까지 기다린 것과 맞음). -> 같은 규칙으로 `hide connect` 전에 `hided node --version`을 한
번 시작합니다.

- **#141** New tab: 새 탭은 선택되기 전에 먼저 그려집니다. 테스트는 탭 수가 늘고 선택이 draft가 아니면
선택된 탭을 읽었는데, 이전 탭 `w1:t1`도 그 조건을 만족해 이전 탭을 읽었습니다. -> 메뉴 단계가 이미 하듯 선택이 이전
탭을 떠날 때까지 기다립니다.
- **#282** real_herdr: 마지막 실패는 fixture 폴더 삭제가 os error 32(다른 프로세스가 사용
중)였습니다. `PrivateHerdr::stop`은 server 프로세스만 기다렸고, Windows에서 pane
shell(cwd가 fixture 안)이 server보다 오래 삽니다. -> server를 `OwnedChild`(Windows
Job)로 시작하고, stop은 `capture_until`로 server와 그 트리 전체가 끝날 때까지 기다립니다(30초,
넘으면 트리를 끝내고 오류).

</details>

## Review

- **판단해 주세요**: 첫 시작을 미리 내는 세 곳(#256 #230 #264류)은 테스트가 재는 것과 무관한 cold
비용이라 TESTING.md 규칙 8을 따랐습니다. 다만 실제 PC의 첫 agent 시작·첫 hided 시작에서도 보일 수 있어
제품 쪽은 with-hide/hide-private#326으로 남겼습니다.
- **판단해 주세요**: #266 단언은 원래 계약(UI 변경 delta는 바뀌지 않은 section을 싣지 않음)을 약하게
하지 않습니다. 예전에는 `navigator` 하나만 봤고, 이제는 실린 모든 필드가 바뀐 것인지와 전체보다 적은지를 봅니다.
`navigator`는 실제로 바뀌었을 때만 실릴 수 있습니다.
- **조심해서 볼 파일**: `hided/tests/it/support/private_herdr.rs` - 23곳이 쓰는
fixture의 stop이 이제 트리 종료까지 확인합니다(failure path: 남은 pane이 있으면 오류).
- **조심해서 볼 파일**: `desktop/e2e/fixture.ts` - Playwright
`ElectronApplication.close`를 감쌉니다(failure path: 끝나지 않는 프로세스는 10초 뒤 pid와
함께 실패, home 보존).
- **조심해서 볼 파일**: `web/e2e/platform-fixture.ts` `prepareWindowsRun` - 두
e2e entry point의 Windows 준비 순서(PowerShell, hided, 마지막 compile 뒤 vctip).

## Evidence

- **확인한 것 (원인)**: #256 실패 6건이 모두 job의 첫 테스트였고, 최근 30 run 중 1건 실패;
artifact의 Herdr 로그로 첫 시작 46초/14.5초/이후 0.35초를 쟀습니다.
- **확인한 것 (원인)**: #244의 반환 경로는 playwright-core 1.63
`ElectronApplication.close()`와 `launchProcess`(`shell: true`, `close`
이벤트) 소스로 확인했습니다.
- **확인한 것**: `fixture-cleanup.unit.ts`의 새 두 테스트가 수정 전 코드(exit 대기 제거)에서
실패하고 수정 후 통과. desktop unit 28 files 295 passed.
- **확인한 것**: desktop typecheck(e2e 포함), web/desktop lint,
`verify-cargo.sh fmt-check` 통과.
- **확인한 것 (CI 반복)**: 0c6740300에서 verify 40854250922를 두 번(attempt 1, 2)
돌려 둘 다 통과, 재시도 0, flaky 보고 없음. Windows desktop e2e 19/19 두 번(첫 테스트 포함),
macOS desktop 58+61 두 번, Rust 6231/6231 두 번, Windows check와 Windows web
e2e 통과. 미리 치른 첫 PowerShell 시작은 2.5-5.6 s, Windows usage 테스트 1회차는 첫
Python 시작이 20.7 s 걸렸지만 기한 밖에서 치러져 통과했습니다.
- **확인한 것**: 2934e82b7의 #266 assertion은 Linux·Windows에서 결정적으로
실패했습니다(`rest`가 바뀌지 않은 delta는 `rest: null`을 보냄). 0c6740300이 그 frame을 건너뛰게
고쳤고, 위 두 번의 run에서 통과했습니다.
- **확인하지 못한 것**: 이 Mac에서 Windows를 돌릴 수 없어 Windows 동작은 이 PR의 CI Windows
job으로 확인합니다. 디스크 여유가 2-5 GB라 Rust 테스트(handshake, connect_stop, hide-ai)와
e2e는 로컬에서 빌드하지 못했고 CI로 확인합니다.

<details><summary>Verification record</summary>

- base: main d8da3e4
- head: 0c67403, verify 40854250922 attempt 1, 2 success
- 범위에서 뺀 것(증거는 각 이슈 코멘트에): #214 #169 #254 #255 #280, #324(이번 원인은 트리 누락이
아님)

</details>
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.

⌘T opens a new tab where the keyboard is: the focused View area or the Agent area

1 participant