Skip to content

Focus existing Windows Terminal tabs by session - #16

Merged
myunwang merged 6 commits into
myunwang:experimental/windows-terminal-focusfrom
ziyuezhou1:agent/windows-terminal-focus
Aug 13, 2026
Merged

myunwang merged 6 commits into
myunwang:experimental/windows-terminal-focusfrom
ziyuezhou1:agent/windows-terminal-focus

Conversation

@ziyuezhou1

Copy link
Copy Markdown

Scope

This PR contains only the Windows Terminal session-focus work split from #15 and targets the maintainer's experimental/windows-terminal-focus branch.

  • Capture and restore the exact already-open Windows Terminal window/tab route.
  • Focus only that existing tab; never launch wt.exe, create a tab, or resume a CLI.
  • Preserve routes across LLMPET restarts and report closed/missing routes without hiding the session menu.
  • Keep ordinary tab focus unprivileged.
  • Offer elevated-terminal focus as an explicit, default-off tray option with a narrow named-pipe protocol.

Acceptance-point changes

  • The registrar captures the real LLMPET user's name, SID, profile, and caller PID before UAC. After UAC—even when different administrator credentials are entered—it validates the still-running caller's owner SID and Windows session, then registers a Limited, interactive logon task for the captured LLMPET SID. The task runs a launcher as that user; only the launcher starts the fixed elevated broker.
  • The broker is optional and does not set NSIS perMachine or change the release version.
  • A tab route is captured only when the foreground window PID equals the Windows Terminal PID found in the hook's process ancestry, with the same hook-provided WT_SESSION. Background tool hooks reuse the correlated route and cannot cache an arbitrary foreground tab.
  • The broker accepts only health, shutdown, and numeric exact-tab focus requests. It validates the named-pipe server executable and Windows session, and validates that the HWND belongs to Windows Terminal.

Validation

  • npm test passes on Windows (including protocol input restrictions, disconnect/reconnect, foreground-correlation, cache restoration, missing/closed-tab behavior, and the no-per-click-RunAs guarantee).
  • Existing Windows CI now exercises the real isolated scheduled-task registration/query/removal lifecycle when CI=true; it checks the resolved user SID, RunLevel=Limited, interactive logon type, and fixed launcher action.
  • scripts/validate-windows-terminal-focus.ps1 produces JSONL evidence for installer, launcher, broker, task lifecycle, reconnect tests, and correlation; optional window/runtime/PID arguments reproduce live exact-tab focus.
  • Local Windows validation passed for the full test suite and an isolated real task lifecycle; the validation task was removed afterward.
  • All PowerShell helper scripts parse successfully.

No version bump or generated release artifact is included.

@myunwang
myunwang merged commit df97b98 into myunwang:experimental/windows-terminal-focus Aug 13, 2026

Copy link
Copy Markdown
Owner

Thank you again for the thoughtful work, and especially for patiently splitting the Windows Terminal focus changes into a dedicated experimental PR. I’ve now merged #16 into experimental/windows-terminal-focus after running the full test suite.

Sorry this took me a while — work has been especially busy recently, so I wasn’t able to review and handle the PR as promptly as I should have. I really appreciate your patience and your continued contributions to LLMPET. 🙏

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.

2 participants