Skip to content

Find the hide CLI when the desktop app starts without the operator's PATH - #166

Merged
yansfil merged 4 commits into
mainfrom
desktop-cli-discovery
Sep 26, 2026
Merged

yansfil merged 4 commits into
mainfrom
desktop-cli-discovery

Conversation

@yansfil

@yansfil yansfil commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Related: #149 (the desktop host)

Summary

Finder나 Dock에서 연 패키지 hide.app은 launchd의 PATH(/usr/bin:/bin:/usr/sbin:/sbin)로 시작합니다.
운영자 머신에서 5초 로그인 셸 조회가 실제 zsh rc(웜 2.4초, 콜드는 더 김)에 타임아웃됐고, 창이 "hide CLI not found"에 머물렀습니다.
이제 CLI 탐색 순서는 HIDE_CLI_PATH -> (비패키지) 워크트리 빌드 -> PATH -> 마지막으로 붙은 CLI -> 로그인 셸 PATH(패키지만, 10초) -> ~/.local/bin, /opt/homebrew/bin, /usr/local/bin입니다.
붙은 CLI는 프로필의 cli-path.json에 기억되어, 두 번째 실행부터는 느린 로그인 셸을 부르지 않습니다.
실패 화면은 그대로이고, 시도한 경로는 모두 한 번씩 로그에 남습니다.

Review

  • 판단해 주세요: 기억한 경로를 PATH 뒤, 로그인 셸 앞에 둔 순서. 로그인 셸이 운영자 의도의 권위지만 비싸서, 기억한 경로가 그 캐시 역할을 합니다
  • 판단해 주세요: 로그인 셸 타임아웃 10초(VS Code shellEnvironmentResolutionTimeout 기본값). 실패는 캐시하지 않아 Retry가 다시 묻습니다
  • 조심해서 볼 파일: desktop/src/main/cli.ts - resolveCli가 async가 됐고 로그인 셸은 앞 단계가 모두 빗나갈 때만 호출됩니다
  • 조심해서 볼 파일: desktop/src/main/host.ts - failure path: 로그인 셸 조회 중 quit/Retry, hide connect 성공 뒤에만 기억을 씁니다
  • 조심해서 볼 파일: desktop/src/main/env.ts - HOME을 레지스트리에 추가. Electron app.getPath("home")은 HOME을 무시해 격리 QA가 운영자 CLI를 찾았습니다
  • 조심해서 볼 파일: desktop/e2e/fixture.ts - 이미 떠 있는 데몬에 다시 붙는 relaunch는 relaunch()로 메인 프로세스에서 창을 읽습니다(아래 Evidence)
  • 로그인 셸은 shell-env처럼 /usr/bin/env DISABLE_AUTO_UPDATE=true ZSH_TMUX_AUTOSTART*=...로 감싸 Oh My Zsh 업데이트 프롬프트와 tmux 자동 시작을 막습니다
  • 설치 디렉터리 목록은 Swift 앱 RuntimeEnvironment.swift의 fallback과 같습니다. jsonFile.ts는 windowState.ts의 원자적 쓰기를 뽑아낸 것입니다

Evidence

  • 확인한 것: pnpm --dir desktop typecheck, lint, test(30개, 새 순서 테스트 6개와 기억 파일 파싱, 실제 /bin/sh 로그인 조회 포함) 통과
  • 확인한 것: pnpm --dir desktop e2e 8/8, 새 discovery 테스트: PATH를 launchd 값으로, HIDE_CLI_PATH 없이, 워크트리 밖으로 복사한 앱에서 ~/.local/bin으로 붙고 cli-path.json을 쓴 뒤 재실행은 remembered로 붙음
  • 확인한 것: 패키지 앱(pnpm --dir desktop package)을 env -i로 launchd 같은 환경, 비공개 HOME/state/profile/socket으로 세 번 실행
  • 3초 걸리는 가짜 로그인 셸 -> login으로 붙고 기억 (cli.login_path elapsed 3243ms)
  • 멈추는 셸 + 기억 있음 -> 셸을 부르지 않고 remembered로 0.1초 안에 붙음
  • 멈추는 셸 + 기억 없음 -> 10004ms에 타임아웃, ~/.local/bin에서 well-known으로 붙음. 사건 시나리오 그대로
  • 각 실행 뒤 비공개 데몬을 hide stop, 남은 프로세스 없음. 운영자 hided와 상태 디렉터리는 건드리지 않음
  • python3 -m unittest discover -s scripts/tests(39), check-no-workstation-identity.sh, check-no-attribution.py 통과
  • 확인한 것: Browser displays in View areas, drawn by the desktop app #164 병합 뒤 CI의 discovery 실패는 relaunch 경합이었습니다. 로컬 반복에서 기존 lifetime도 같은 모양으로 실패했습니다
  • 재실행이 수십 ms 만에 붙으면 Playwright가 status 페이지 -> 데몬 origin 렌더러 교체를 놓칩니다. page가 file://에 머물거나 window 이벤트가 안 옵니다
  • 탐침 스펙으로 확인: 놓친 경우에도 창은 데몬 URL, 로딩 끝, 보임, 셸 DOM 있음. 제품 문제가 아니라 테스트 관측 문제입니다
  • 그래서 두 relaunch는 메인 프로세스로 창을 읽고, cleanup의 rmSync는 ENOTEMPTY를 재시도합니다(main에서도 16회 중 1회 재현)
  • 고친 뒤 lifetime/discovery 반복 30회 통과(운영자 화면 때문에 중간에 멈춤). e2e 창은 여전히 화면에 뜨며, 숨김 실행은 이 PR에 넣지 않았습니다
  • 확인하지 못한 것: Finder/Dock에서 실제로 연 실행(launchd가 준 환경 그대로)과 운영자의 실제 zsh rc. 위 검증은 env -i와 가짜 셸로 흉내낸 것입니다
  • 확인하지 못한 것: Playwright는 앱을 비패키지로 띄우므로 e2e는 로그인 셸 단계를 지나지 않습니다. 그 자리는 단위 테스트와 위 패키지 수동 실행이 덮습니다
  • 확인하지 못한 것: Rust, Swift, web 레인은 이 diff가 건드리지 않아 로컬에서 돌리지 않았습니다. CI가 돌립니다

…PATH

An app opened from Finder or the Dock gets launchd's bare PATH, and the
five-second login-shell probe timed out on a real rc file, leaving the
window on the missing-CLI screen. The search now goes PATH, the CLI that
last attached (remembered under the profile), the login shell with a
ten-second bound and shell-env's Oh My Zsh guards, then ~/.local/bin,
/opt/homebrew/bin and /usr/local/bin. The home directory comes from HOME,
so an isolated instance never finds the operator's CLI.
A relaunch that attaches to a running daemon leaves the status page for
the daemon's origin within tens of milliseconds, and Playwright can lose
that early renderer swap: its page stays on the status page, or no window
event arrives, while the window shows the shell. The lifetime and
discovery relaunches now read the window through the main process. The
fixture cleanup retries ENOTEMPTY while the stopped daemon removes its
files.
@yansfil
yansfil merged commit 0c850d6 into main Sep 26, 2026
7 checks passed
@yansfil
yansfil deleted the desktop-cli-discovery branch September 26, 2026 06:57
yansfil added a commit that referenced this pull request Sep 28, 2026
## Summary

In a browser display, ⌘= / ⌘- / ⌘0 used to hand focus back to the shell
and resize the terminal or editor text, and a trackpad pinch did
nothing.
Now, while a page holds the keyboard, the text-size commands zoom that
page in Chrome's steps (25% to 500%, reset to 100%) and the page keeps
focus.
⌘+ (⌘⇧=) also zooms in, and pinch zoom is enabled up to 3x.
With the shell focused, the same commands size text exactly as before.
Routing is by command id in `DesktopHost.sendCommand`, so a rebound
text-size chord zooms the page too.

![Page A at 125% after two native ⌘= presses with the page
focused](https://github.com/yansfil/pr-assets/blob/main/hide/browser-page-zoom/f2153ed/native-zoom-125.png?raw=true)

## Review

- **Please judge**: ⌘+ is answered by the host before the page, unless
the operator bound ⌘⇧= to a command, in which case that binding wins.
- **Please judge**: zoom is Chromium's per-host level inside a
Workspace's page partition, so same-host pages in one Workspace zoom
together (Chrome behaves the same). Nothing is persisted.
- **Files to watch**: `desktop/src/main/host.ts` - `sendCommand` is the
app-menu path for every command; the zoom branch runs only for the three
text-size ids while a visible page is focused.
- **Files to watch**: `desktop/src/main/browser.ts` - pinch limits are
re-applied on every main-frame `did-navigate`, because they live in the
renderer and a cross-site navigation swaps it (failure path: a rejected
call is logged as `browser.pinch_zoom_failed`).

## Evidence

- **Confirmed**: new desktop e2e `zoom:` drives the menu commands with
the page focused and checks the zoom steps 1.1, 1.25, 1.1, 1, 0.9, 1,
plus ⌘⇧= to 1.1. The page keeps focus throughout and no
`pane_text_scale` / `editor_text_scale` is sent.
- **Confirmed**: the same e2e moves focus to the shell, and
`text_larger` / `text_reset` then send exactly one text-scale event each
while the page zoom stays put.
- **Confirmed**: a CDP pinch gesture raises `visualViewport.scale` above
1.2, and does so again after the page navigates to another site in a new
renderer process (PID checked).
- **Confirmed**: the pinch assertions are not vacuous. With the limits
call removed, the first pinch fails. With it applied only once, the
post-navigation pinch fails.
- **Confirmed**: native keys through macOS. A throwaway spec posted real
CGEvent key presses to the dev app's process on the operator's Mac. With
the page focused: ⌘= 1.1, ⌘= 1.25, ⌘⇧= 1.5, ⌘- 1.25, ⌘0 1, each once.
With the shell focused: ⌘= and ⌘0 each sent one text-scale event and the
page did not zoom.
- **Confirmed**: `browserSync.test.ts` unit-tests the step table against
Chromium's `kPresetZoomFactors`, the clamping at both ends, and off-step
starting values.
- **Confirmed**: the `browser.spec.ts`, `keys.spec.ts` and
`close-policy.spec.ts` desktop suites passed (7/7), along with desktop
typecheck, lint and unit tests (44).
- **Not confirmed**: a physical trackpad pinch. Pinch was proven with
CDP `Input.synthesizePinchGesture`, not by hand.
- **Not confirmed**: the ⌘⇧= override when an operator binds that chord
to a command. It is covered by code only, not by a test.
- **Not confirmed (flaky)**: across repeated local runs, the long
`browser:` test failed some of the time at `browser.spec.ts:350`, the
`enterWorkspace` after a relaunch. That is the known relaunch race from
#166 and outside this diff.

<details><summary>More evidence</summary>

![Page B pinched to about 2x after a cross-site navigation into a new
renderer](https://github.com/yansfil/pr-assets/blob/main/hide/browser-page-zoom/f2153ed/browser-zoom-pinched.png?raw=true)

</details>

**AI tooling**: mostly AI tools. By hand I compared each zoom step,
focus state and text-scale count against the e2e output and the native
key-press transcript.
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