Files
orca/src/main/runtime/runtime-desktop-surface.ts
T
Jinjing 8fc1698ebb Add Resource Manager PTY inventory and checked terminal termination (#31593)
* feat(resources): end local terminals with checked identity checks

- Add a PTYs view to the Resource Manager that lists local terminals and can end one. Before stopping, the host confirms the terminal's incarnation, agent ownership, and attachments. This prevents ending a same-ID replacement that started after the list was read.
- Bump the daemon protocol to v50 and gate the new fenced kill on it. Older daemons ignore the extra fields, so the client refuses End instead of sending an unchecked kill.
- Admit diagnostic reads (PTY listing and memory snapshot) only while the Resources view is visible, so a hidden window does no background scanning.
- Report incarnation and host on spawn and exit events so the renderer can match them to the terminal it showed.
- Replace the popover's terminal-session list with the new inventory and move memory polling into the Resources view.

* Show unrouted daemon PTYs in the Resource Manager

* Simplify PTY controls and clarify safe termination

* Format local build compatibility protocol lists

* Add PTY resource management localization strings

* Harden PTY resource manager test fixtures

* Use typed IPC event in PTY kill test fixture

* Refine local PTY resource view model typing

* Refine local PTY resource view model typing

* Include local host identity in PTY lifecycle event tests
2026-10-22 12:20:01 -07:00

52 lines
2.5 KiB
TypeScript

import type { BrowserWindow, IpcMainEvent, WebContents } from 'electron'
/**
* The desktop facilities `OrcaRuntimeService` uses, which a Node host does not have.
*
* Three sites, all optional by nature: a native notification toast, a lookup of the
* authoritative renderer window, and one ipcMain channel used only by the
* renderer-backed tab-create fallback. With no renderer that fallback is unreachable —
* `createTerminal` already takes the background spawn branch when there is no
* authoritative window (#10333) — so a Node host needs none of them.
*
* Defaults are inert rather than throwing, for the same reason as the PTY bindings: a
* host with no desktop legitimately has nothing here, and that is not a downgrade.
* Where absence IS user-visible — a notification that would have been shown — the
* runtime already routes to paired clients, which is the better destination anyway.
*/
export type RuntimeDesktopSurface = {
/** Headless hosts retain the formatter's English defaults. */
translateNotification?(key: string, fallback: string): string
/** This machine's own idle state; undefined is unknown. Absent on hosts with no desktop. */
isAwayForMobileNotifications?(): boolean | undefined
/** Show a native notification. Returns false when the host cannot, so callers can say so. */
showNotification(input: { title: string; body: string }): boolean
/** The renderer window with this id, or null when there is no desktop. */
findWindowById(id: number): BrowserWindow | null
isResourceViewVisible?(sender: WebContents): boolean
onIpc(channel: string, listener: (event: IpcMainEvent, ...args: never[]) => void): void
removeIpcListener(channel: string, listener: (...args: never[]) => void): void
/** Re-encodes as a PNG fitting `maxEdge`; null if undecodable. Absent on Node hosts. */
encodeRepoIconPng?(bytes: Uint8Array, maxEdge: number): Uint8Array | null
/** A GET answering redirects with the 3xx, without proxy login; absent where fetch already does. */
fetchRepoIcon?(url: string, init: RequestInit): Promise<Response>
}
const inertDesktopSurface: RuntimeDesktopSurface = {
showNotification: () => false,
findWindowById: () => null,
onIpc: () => {},
removeIpcListener: () => {}
}
let current: RuntimeDesktopSurface = inertDesktopSurface
export function setRuntimeDesktopSurface(surface: RuntimeDesktopSurface | null): void {
current = surface ?? inertDesktopSurface
}
export function getRuntimeDesktopSurface(): RuntimeDesktopSurface {
return current
}