Open History to see the last commit
1import type {
2 VcsCreateRefInput,
3 VcsCreateRefResult,
4 VcsCreateWorktreeInput,
5 VcsCreateWorktreeResult,
6 VcsInitInput,
7 VcsListRefsInput,
8 VcsListRefsResult,
9 VcsPullInput,
10 VcsPullResult,
11 VcsRemoveWorktreeInput,
12 VcsSwitchRefInput,
13 VcsSwitchRefResult,
14 GitPreparePullRequestThreadInput,
15 GitPreparePullRequestThreadResult,
16 GitPullRequestRefInput,
17 GitResolvePullRequestResult,
18 VcsStatusInput,
19 VcsStatusResult,
20} from "./git.ts";
21import type {
22 ReviewDiffFileContentsInput,
23 ReviewDiffFileContentsResult,
24 ReviewDiffPreviewInput,
25 ReviewDiffPreviewResult,
26} from "./review.ts";
27import type { FilesystemBrowseInput, FilesystemBrowseResult } from "./filesystem.ts";
28import type { AssetCreateUrlInput, AssetCreateUrlResult } from "./assets.ts";
29import type {
30 ProjectListEntriesInput,
31 ProjectListEntriesResult,
32 ProjectReadFileInput,
33 ProjectReadFileResult,
34 ProjectSearchEntriesInput,
35 ProjectSearchEntriesResult,
36 ProjectWriteFileInput,
37 ProjectWriteFileResult,
38} from "./project.ts";
39import type {
40 TerminalAttachInput,
41 TerminalAttachStreamEvent,
42 TerminalClearInput,
43 TerminalCloseInput,
44 TerminalMetadataStreamEvent,
45 TerminalOpenInput,
46 TerminalResizeInput,
47 TerminalRestartInput,
48 TerminalSessionSnapshot,
49 TerminalWriteInput,
50} from "./terminal.ts";
51import * as Schema from "effect/Schema";
52import type {
53 DiscoveredLocalServerList,
54 PreviewCloseInput,
55 PreviewEvent,
56 PreviewListInput,
57 PreviewListResult,
58 PreviewNavigateInput,
59 PreviewOpenInput,
60 PreviewRefreshInput,
61 PreviewReportStatusInput,
62 PreviewResizeInput,
63 PreviewSessionSnapshot,
64} from "./preview.ts";
65import {
66 PreviewAutomationClickInput,
67 PreviewAutomationEvaluateInput,
68 PreviewAutomationHost,
69 PreviewAutomationHostFocus,
70 PreviewAutomationPressInput,
71 PreviewAutomationResponse,
72 PreviewAutomationScrollInput,
73 PreviewAutomationSnapshot,
74 PreviewAutomationStatus,
75 PreviewAutomationStreamEvent,
76 PreviewAutomationTypeInput,
77 PreviewAutomationWaitForInput,
78} from "./previewAutomation.ts";
79import type {
80 ClientOrchestrationCommand,
81 OrchestrationGetFullThreadDiffInput,
82 OrchestrationGetFullThreadDiffResult,
83 OrchestrationGetTurnDiffInput,
84 OrchestrationGetTurnDiffResult,
85 OrchestrationShellSnapshot,
86 OrchestrationShellStreamItem,
87 OrchestrationSubscribeThreadInput,
88 OrchestrationThreadStreamItem,
89} from "./orchestration.ts";
90import { EnvironmentId } from "./baseSchemas.ts";
91import { AuthAccessTokenResult, AuthSessionState, AuthWebSocketTicketResult } from "./auth.ts";
92import { AdvertisedEndpoint } from "./remoteAccess.ts";
93import { ExecutionEnvironmentDescriptor } from "./environment.ts";
94import type { ClientSettings, QuitConfirmationMode } from "./settings.ts";
95import type { EditorId } from "./editor.ts";
96import type {
97 SourceControlCloneRepositoryInput,
98 SourceControlCloneRepositoryResult,
99 SourceControlPublishRepositoryInput,
100 SourceControlPublishRepositoryResult,
101 SourceControlRepositoryInfo,
102 SourceControlRepositoryLookupInput,
103} from "./sourceControl.ts";
104import type {
105 DesktopAppActivationRequest,
106 DesktopAppActivationResponse,
107} from "./desktopAppActivation.ts";
108
109export interface ContextMenuItem<T extends string = string> {
110 id: T;
111 label: string;
112 destructive?: boolean;
113 disabled?: boolean;
114 /** Renders as a non-interactive section header label. Web fallback only — stripped on desktop native menus. */
115 header?: boolean;
116 /** Icon keyword resolved by the web fallback. Stripped on desktop native menus. */
117 icon?: string;
118 /** Inserts a visual section divider immediately before this item. */
119 separatorBefore?: boolean;
120 children?: readonly ContextMenuItem<T>[];
121}
122
123export type QuitShortcutHintEvent =
124 | { readonly state: "down"; readonly mode: Exclude<QuitConfirmationMode, "direct"> }
125 | { readonly state: "up" };
126
127export interface ContextMenuItemSchemaType {
128 readonly id: string;
129 readonly label: string;
130 readonly destructive?: boolean;
131 readonly disabled?: boolean;
132 readonly header?: boolean;
133 readonly icon?: string;
134 readonly separatorBefore?: boolean;
135 readonly children?: readonly ContextMenuItemSchemaType[];
136}
137
138export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Schema.Struct({
139 id: Schema.String,
140 label: Schema.String,
141 destructive: Schema.optionalKey(Schema.Boolean),
142 disabled: Schema.optionalKey(Schema.Boolean),
143 header: Schema.optionalKey(Schema.Boolean),
144 icon: Schema.optionalKey(Schema.String),
145 separatorBefore: Schema.optionalKey(Schema.Boolean),
146 children: Schema.optionalKey(
147 Schema.Array(
148 Schema.suspend((): Schema.Codec<ContextMenuItemSchemaType> => ContextMenuItemSchema),
149 ),
150 ),
151});
152
153export type DesktopUpdateStatus =
154 | "disabled"
155 | "idle"
156 | "checking"
157 | "up-to-date"
158 | "available"
159 | "downloading"
160 | "downloaded"
161 | "error";
162
163export type DesktopRuntimeArch = "arm64" | "x64" | "other";
164export type DesktopTheme = "light" | "dark" | "system";
165export type DesktopUpdateChannel = "latest" | "nightly";
166export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
167
168export const DesktopUpdateStatusSchema = Schema.Literals([
169 "disabled",
170 "idle",
171 "checking",
172 "up-to-date",
173 "available",
174 "downloading",
175 "downloaded",
176 "error",
177]);
178export const DesktopRuntimeArchSchema = Schema.Literals(["arm64", "x64", "other"]);
179export const DesktopThemeSchema = Schema.Literals(["light", "dark", "system"]);
180export const DesktopUpdateChannelSchema = Schema.Literals(["latest", "nightly"]);
181export const DesktopAppStageLabelSchema = Schema.Literals(["Alpha", "Dev", "Nightly"]);
182
183export interface DesktopAppBranding {
184 baseName: string;
185 stageLabel: DesktopAppStageLabel;
186 displayName: string;
187}
188
189export const DesktopAppBrandingSchema = Schema.Struct({
190 baseName: Schema.String,
191 stageLabel: DesktopAppStageLabelSchema,
192 displayName: Schema.String,
193});
194
195export interface DesktopRuntimeInfo {
196 hostArch: DesktopRuntimeArch;
197 appArch: DesktopRuntimeArch;
198 runningUnderArm64Translation: boolean;
199}
200
201export interface DesktopUpdateState {
202 enabled: boolean;
203 status: DesktopUpdateStatus;
204 channel: DesktopUpdateChannel;
205 currentVersion: string;
206 hostArch: DesktopRuntimeArch;
207 appArch: DesktopRuntimeArch;
208 runningUnderArm64Translation: boolean;
209 availableVersion: string | null;
210 downloadedVersion: string | null;
211 releaseNotes: ReadonlyArray<DesktopUpdateReleaseNote>;
212 omittedReleaseCount: number;
213 downloadPercent: number | null;
214 checkedAt: string | null;
215 message: string | null;
216 errorContext: "check" | "download" | "install" | null;
217 canRetry: boolean;
218}
219
220export interface DesktopUpdateReleaseNote {
221 version: string;
222 items: ReadonlyArray<string>;
223 totalItems: number;
224}
225
226export const DesktopUpdateReleaseNoteSchema = Schema.Struct({
227 version: Schema.String,
228 items: Schema.Array(Schema.String),
229 totalItems: Schema.Number,
230});
231
232export const DesktopUpdateStateSchema = Schema.Struct({
233 enabled: Schema.Boolean,
234 status: DesktopUpdateStatusSchema,
235 channel: DesktopUpdateChannelSchema,
236 currentVersion: Schema.String,
237 hostArch: DesktopRuntimeArchSchema,
238 appArch: DesktopRuntimeArchSchema,
239 runningUnderArm64Translation: Schema.Boolean,
240 availableVersion: Schema.NullOr(Schema.String),
241 downloadedVersion: Schema.NullOr(Schema.String),
242 releaseNotes: Schema.Array(DesktopUpdateReleaseNoteSchema),
243 omittedReleaseCount: Schema.Number,
244 downloadPercent: Schema.NullOr(Schema.Number),
245 checkedAt: Schema.NullOr(Schema.String),
246 message: Schema.NullOr(Schema.String),
247 errorContext: Schema.NullOr(Schema.Literals(["check", "download", "install"])),
248 canRetry: Schema.Boolean,
249});
250
251export interface DesktopUpdateActionResult {
252 accepted: boolean;
253 completed: boolean;
254 state: DesktopUpdateState;
255}
256
257export const DesktopUpdateActionResultSchema = Schema.Struct({
258 accepted: Schema.Boolean,
259 completed: Schema.Boolean,
260 state: DesktopUpdateStateSchema,
261});
262
263export interface DesktopUpdateCheckResult {
264 checked: boolean;
265 state: DesktopUpdateState;
266}
267
268export const DesktopUpdateCheckResultSchema = Schema.Struct({
269 checked: Schema.Boolean,
270 state: DesktopUpdateStateSchema,
271});
272
273// Stable id for the Windows-native primary backend. Desktop side wraps
274// this with a brand inside DesktopBackendManager; web side keeps it as
275// a plain string so the env-runtime can compare against it without
276// importing brand machinery from the desktop package.
277export const PRIMARY_LOCAL_ENVIRONMENT_ID = "primary";
278
279export interface DesktopEnvironmentBootstrap {
280 // Stable backend instance id (e.g. "primary" or "wsl:ubuntu"). The
281 // web env runtime keys local environments off this so projects
282 // routed to a specific backend reopen against the same one.
283 id: string;
284 label: string;
285 // Concrete WSL distro used by the current backend run. This stays separate
286 // from id because a default-tracking instance keeps the stable
287 // "wsl:default" IPC target while each run launches a specific distro.
288 runningDistro?: string | null;
289 httpBaseUrl: string | null;
290 wsBaseUrl: string | null;
291 bootstrapToken?: string;
292}
293
294export const DesktopEnvironmentBootstrapSchema = Schema.Struct({
295 id: Schema.String,
296 label: Schema.String,
297 runningDistro: Schema.optionalKey(Schema.NullOr(Schema.String)),
298 httpBaseUrl: Schema.NullOr(Schema.String),
299 wsBaseUrl: Schema.NullOr(Schema.String),
300 bootstrapToken: Schema.optionalKey(Schema.String),
301});
302
303export const DesktopSshEnvironmentTargetSchema = Schema.Struct({
304 alias: Schema.String,
305 hostname: Schema.String,
306 username: Schema.NullOr(Schema.String),
307 port: Schema.NullOr(Schema.Number),
308});
309export type DesktopSshEnvironmentTarget = typeof DesktopSshEnvironmentTargetSchema.Type;
310
311export type DesktopSshHostSource = "ssh-config" | "known-hosts";
312export const DesktopSshHostSourceSchema = Schema.Literals(["ssh-config", "known-hosts"]);
313
314export interface DesktopDiscoveredSshHost extends DesktopSshEnvironmentTarget {
315 source: DesktopSshHostSource;
316}
317
318export const DesktopDiscoveredSshHostSchema = Schema.Struct({
319 alias: Schema.String,
320 hostname: Schema.String,
321 username: Schema.NullOr(Schema.String),
322 port: Schema.NullOr(Schema.Number),
323 source: DesktopSshHostSourceSchema,
324});
325
326export interface DesktopSshEnvironmentBootstrap {
327 target: DesktopSshEnvironmentTarget;
328 httpBaseUrl: string;
329 wsBaseUrl: string;
330 pairingToken: string | null;
331 remotePort?: number;
332 remoteServerKind?: "external" | "managed";
333}
334
335export const DesktopSshEnvironmentBootstrapSchema = Schema.Struct({
336 target: DesktopSshEnvironmentTargetSchema,
337 httpBaseUrl: Schema.String,
338 wsBaseUrl: Schema.String,
339 pairingToken: Schema.NullOr(Schema.String),
340 remotePort: Schema.optionalKey(Schema.Number),
341 remoteServerKind: Schema.optionalKey(Schema.Literals(["external", "managed"])),
342});
343
344export interface DesktopSshPasswordPromptRequest {
345 requestId: string;
346 destination: string;
347 username: string | null;
348 prompt: string;
349 expiresAt: string;
350}
351
352export const DesktopSshPasswordPromptCancelledType = "ssh-password-prompt-cancelled" as const;
353
354export const DesktopSshPasswordPromptCancelledResultSchema = Schema.Struct({
355 type: Schema.Literal(DesktopSshPasswordPromptCancelledType),
356 message: Schema.String,
357});
358
359export const DesktopSshEnvironmentEnsureOptionsSchema = Schema.Struct({
360 issuePairingToken: Schema.optionalKey(Schema.Boolean),
361});
362
363export const DesktopSshEnvironmentEnsureInputSchema = Schema.Struct({
364 target: DesktopSshEnvironmentTargetSchema,
365 options: Schema.optionalKey(DesktopSshEnvironmentEnsureOptionsSchema),
366});
367
368export const DesktopSshEnvironmentEnsureResultSchema = Schema.Union([
369 DesktopSshEnvironmentBootstrapSchema,
370 DesktopSshPasswordPromptCancelledResultSchema,
371]);
372
373export const DesktopSshHttpBaseUrlInputSchema = Schema.Struct({
374 httpBaseUrl: Schema.String,
375});
376
377export const DesktopSshBearerRequestInputSchema = Schema.Struct({
378 httpBaseUrl: Schema.String,
379 bearerToken: Schema.String,
380});
381
382export const DesktopSshBearerBootstrapInputSchema = Schema.Struct({
383 httpBaseUrl: Schema.String,
384 credential: Schema.String,
385});
386
387export const DesktopSshPasswordPromptResolutionInputSchema = Schema.Struct({
388 requestId: Schema.String,
389 password: Schema.NullOr(Schema.String),
390});
391
392export const PersistedSavedEnvironmentRecordSchema = Schema.Struct({
393 environmentId: EnvironmentId,
394 label: Schema.String,
395 wsBaseUrl: Schema.String,
396 httpBaseUrl: Schema.String,
397 createdAt: Schema.String,
398 lastConnectedAt: Schema.NullOr(Schema.String),
399 desktopSsh: Schema.optionalKey(DesktopSshEnvironmentTargetSchema),
400 relayManaged: Schema.optionalKey(
401 Schema.Struct({
402 relayUrl: Schema.String,
403 }),
404 ),
405});
406export type PersistedSavedEnvironmentRecord = typeof PersistedSavedEnvironmentRecordSchema.Type;
407
408export type DesktopServerExposureMode = "local-only" | "network-accessible";
409
410export const DesktopServerExposureModeSchema = Schema.Literals([
411 "local-only",
412 "network-accessible",
413]);
414
415export interface DesktopServerExposureState {
416 mode: DesktopServerExposureMode;
417 endpointUrl: string | null;
418 advertisedHost: string | null;
419 tailscaleServeEnabled: boolean;
420 tailscaleServePort: number;
421}
422
423export const DesktopServerExposureStateSchema = Schema.Struct({
424 mode: DesktopServerExposureModeSchema,
425 endpointUrl: Schema.NullOr(Schema.String),
426 advertisedHost: Schema.NullOr(Schema.String),
427 tailscaleServeEnabled: Schema.Boolean,
428 tailscaleServePort: Schema.Number,
429});
430
431export interface PickFolderOptions {
432 initialPath?: string | null;
433 // When set, the desktop dialog opens against the named backend's
434 // filesystem instead of the primary's. Used by callers that already
435 // know which local environment they're targeting (e.g. opening a
436 // project that lives inside WSL). Omitting it keeps the historical
437 // behavior so non-WSL users never see a different picker.
438 targetEnvironmentId?: string;
439}
440
441export const PickFolderOptionsSchema = Schema.Struct({
442 initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
443 targetEnvironmentId: Schema.optionalKey(Schema.String),
444});
445
446/**
447 * A file returned by the desktop theme-file picker. Oversized files carry an
448 * empty text so the renderer can reject them by size without the main
449 * process ever holding their contents.
450 */
451export interface PickedThemeFile {
452 name: string;
453 size: number;
454 text: string;
455}
456
457export const PickedThemeFileSchema = Schema.Struct({
458 name: Schema.String,
459 size: Schema.Number,
460 text: Schema.String,
461});
462
463export interface DesktopWslDistro {
464 name: string;
465 isDefault: boolean;
466 version: 1 | 2;
467}
468
469export const DesktopWslDistroSchema = Schema.Struct({
470 name: Schema.String,
471 isDefault: Schema.Boolean,
472 version: Schema.Literals([1, 2]),
473});
474
475export interface DesktopWslState {
476 // True when the user has opted the WSL backend in; the actual backend
477 // process is registered with the desktop pool independently of this
478 // flag and may take a moment to come up after the user enables it.
479 enabled: boolean;
480 // null means "track the current WSL default distro".
481 distro: string | null;
482 available: boolean;
483 // When true (and `enabled` is also true) the desktop runs only the
484 // WSL backend as the primary; the Windows-side Node backend is not
485 // started. Toggling this requires an app restart because the
486 // primary backend's spec is captured once at layer init.
487 wslOnly: boolean;
488 distros: readonly DesktopWslDistro[];
489 // Reason the dual-mode WSL backend last failed preflight (no node, wrong
490 // version, missing build tools), or null. Surfaced inline in Connections
491 // settings. Always null in wsl-only mode — that path shows a dialog and
492 // falls back to Windows instead.
493 preflightError: string | null;
494}
495
496export const DesktopWslStateSchema = Schema.Struct({
497 enabled: Schema.Boolean,
498 distro: Schema.NullOr(Schema.String),
499 available: Schema.Boolean,
500 wslOnly: Schema.Boolean,
501 distros: Schema.Array(DesktopWslDistroSchema),
502 preflightError: Schema.NullOr(Schema.String),
503});
504
505/**
506 * Renderer-facing snapshot of a desktop preview tab. Mirrors the main-process
507 * PreviewTabState shape but uses serialisable primitives only.
508 */
509export type DesktopPreviewNavStatus =
510 | { kind: "Idle" }
511 | { kind: "Loading"; url: string; title: string }
512 | { kind: "Success"; url: string; title: string }
513 | {
514 kind: "LoadFailed";
515 url: string;
516 title: string;
517 code: number;
518 description: string;
519 };
520
521/**
522 * Emulated `prefers-color-scheme` for the guest page. "system" clears the
523 * override so the page follows the OS appearance.
524 */
525export type DesktopPreviewColorScheme = "system" | "light" | "dark";
526
527export const DesktopPreviewColorSchemeSchema: Schema.Codec<DesktopPreviewColorScheme> =
528 Schema.Literals(["system", "light", "dark"]);
529
530export const FAVICON_DATA_URL_MAX_LENGTH = 8192;
531export const FAVICON_CAPTURED_AT_MAX = 8_640_000_000_000_000;
532
533export interface DesktopPreviewFavicon {
534 dataUrl: string;
535 pageUrl: string;
536 capturedAt: number;
537}
538
539export const DesktopPreviewFaviconSchema: Schema.Codec<DesktopPreviewFavicon> = Schema.Struct({
540 dataUrl: Schema.String.check(
541 Schema.isMaxLength(FAVICON_DATA_URL_MAX_LENGTH),
542 Schema.isPattern(/^data:image\/png;base64,[a-z0-9+/]+={0,2}$/i),
543 ),
544 pageUrl: Schema.String.check(Schema.isMaxLength(2_048)),
545 capturedAt: Schema.Number.check(
546 Schema.isFinite(),
547 Schema.isGreaterThanOrEqualTo(0),
548 Schema.isLessThanOrEqualTo(FAVICON_CAPTURED_AT_MAX),
549 ),
550});
551
552export interface DesktopPreviewTabState {
553 tabId: string;
554 webContentsId: number | null;
555 navStatus: DesktopPreviewNavStatus;
556 canGoBack: boolean;
557 canGoForward: boolean;
558 /** Current zoom factor (1.0 = 100%). */
559 zoomFactor: number;
560 /** Whether this tab is currently mirrored into a desktop picture-in-picture window. */
561 pictureInPicture: boolean;
562 colorScheme: DesktopPreviewColorScheme;
563 /**
564 * Whether the user has silenced this tab. Per tab rather than per origin, so
565 * two tabs on the same site mute independently. Survives navigation and
566 * webview swaps, but is dropped when the tab closes.
567 */
568 audioMuted: boolean;
569 /**
570 * Whether the guest is currently emitting audio. Observed from Chromium, and
571 * independent of {@link audioMuted}: a muted tab that is playing still reports
572 * `true`, which is what lets the tab strip distinguish "muted and making
573 * sound" from "muted and silent".
574 */
575 audible: boolean;
576 controller: "human" | "agent" | "none";
577 favicon?: DesktopPreviewFavicon;
578 updatedAt: string;
579}
580
581export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed()).check(
582 Schema.isNonEmpty(),
583);
584
585export const DesktopPreviewAutomationStatusSchema = Schema.Struct({
586 ...PreviewAutomationStatus.fields,
587 tabId: Schema.NullOr(DesktopPreviewTabIdSchema),
588});
589export type DesktopPreviewAutomationStatus = typeof DesktopPreviewAutomationStatusSchema.Type;
590
591export const DesktopPreviewNavStatusSchema = Schema.Union([
592 Schema.Struct({ kind: Schema.Literal("Idle") }),
593 Schema.Struct({
594 kind: Schema.Literal("Loading"),
595 url: Schema.String,
596 title: Schema.String,
597 }),
598 Schema.Struct({
599 kind: Schema.Literal("Success"),
600 url: Schema.String,
601 title: Schema.String,
602 }),
603 Schema.Struct({
604 kind: Schema.Literal("LoadFailed"),
605 url: Schema.String,
606 title: Schema.String,
607 code: Schema.Number,
608 description: Schema.String,
609 }),
610]);
611
612export interface DesktopPreviewPointerEvent {
613 tabId: string;
614 phase: "move" | "click";
615 x: number;
616 y: number;
617 sequence: number;
618 createdAt: string;
619}
620
621/**
622 * Static config a renderer needs to mount a preview `<webview>`. Returned
623 * atomically by `DesktopPreviewBridge.getPreviewConfig()` so the renderer
624 * doesn't have to wait on three separate IPC round-trips before the webview
625 * can attach.
626 */
627export interface DesktopPreviewWebviewConfig {
628 /** `persist:t3code-preview` (or whatever the desktop chose). */
629 partition: string;
630 /**
631 * Canonical `<webview webpreferences="...">` string. Encodes the security
632 * posture (sandboxed but contextIsolation off so the picker preload can
633 * read the page's React DevTools hook). Always present.
634 */
635 webPreferences: string;
636 /**
637 * Absolute `file://`-style URL to the picker preload bundle. Set to null
638 * when the bundle isn't present (older builds, broken install) — the
639 * renderer must then disable element-pick affordances.
640 */
641 preloadUrl: string | null;
642}
643
644export const DesktopPreviewWebviewConfigSchema: Schema.Codec<DesktopPreviewWebviewConfig> =
645 Schema.Struct({
646 partition: Schema.String,
647 webPreferences: Schema.String,
648 preloadUrl: Schema.NullOr(Schema.String),
649 });
650
651export interface DesktopPreviewAnnotationTheme {
652 colorScheme: "light" | "dark";
653 radius: string;
654 background: string;
655 foreground: string;
656 popover: string;
657 popoverForeground: string;
658 primary: string;
659 primaryForeground: string;
660 muted: string;
661 mutedForeground: string;
662 accent: string;
663 accentForeground: string;
664 border: string;
665 input: string;
666 ring: string;
667 fontSans: string;
668 fontMono: string;
669}
670
671export const DesktopPreviewAnnotationThemeSchema: Schema.Codec<DesktopPreviewAnnotationTheme> =
672 Schema.Struct({
673 colorScheme: Schema.Literals(["light", "dark"]),
674 radius: Schema.String,
675 background: Schema.String,
676 foreground: Schema.String,
677 popover: Schema.String,
678 popoverForeground: Schema.String,
679 primary: Schema.String,
680 primaryForeground: Schema.String,
681 muted: Schema.String,
682 mutedForeground: Schema.String,
683 accent: Schema.String,
684 accentForeground: Schema.String,
685 border: Schema.String,
686 input: Schema.String,
687 ring: Schema.String,
688 fontSans: Schema.String,
689 fontMono: Schema.String,
690 });
691
692export interface DesktopPreviewRecordingFrame {
693 tabId: string;
694 data: string;
695 width: number;
696 height: number;
697 receivedAt: string;
698}
699
700export interface DesktopPreviewRecordingArtifact {
701 id: string;
702 tabId: string;
703 path: string;
704 mimeType: string;
705 sizeBytes: number;
706 createdAt: string;
707}
708
709export const DesktopPreviewRecordingArtifactSchema: Schema.Codec<DesktopPreviewRecordingArtifact> =
710 Schema.Struct({
711 id: Schema.String,
712 tabId: DesktopPreviewTabIdSchema,
713 path: Schema.String,
714 mimeType: Schema.String,
715 sizeBytes: Schema.Int,
716 createdAt: Schema.String,
717 });
718
719export interface DesktopPreviewScreenshotArtifact {
720 id: string;
721 tabId: string;
722 path: string;
723 mimeType: "image/png";
724 sizeBytes: number;
725 createdAt: string;
726}
727
728export const DesktopPreviewScreenshotArtifactSchema: Schema.Codec<DesktopPreviewScreenshotArtifact> =
729 Schema.Struct({
730 id: Schema.String,
731 tabId: DesktopPreviewTabIdSchema,
732 path: Schema.String,
733 mimeType: Schema.Literal("image/png"),
734 sizeBytes: Schema.Int,
735 createdAt: Schema.String,
736 });
737
738/**
739 * Single stack frame captured by react-grab's `getElementContext`. We surface
740 * the source file/line so coding agents can jump straight to the JSX that
741 * produced the picked DOM node.
742 */
743export interface PickedElementStackFrame {
744 functionName: string | null;
745 fileName: string | null;
746 lineNumber: number | null;
747 columnNumber: number | null;
748}
749
750export const PickedElementStackFrameSchema: Schema.Codec<PickedElementStackFrame> = Schema.Struct({
751 functionName: Schema.NullOr(Schema.String),
752 fileName: Schema.NullOr(Schema.String),
753 lineNumber: Schema.NullOr(Schema.Number),
754 columnNumber: Schema.NullOr(Schema.Number),
755});
756
757/**
758 * A successful element pick from the preview webview. All fields are
759 * best-effort — pages that don't ship a React fiber tree (or aren't running
760 * in dev) will still produce a usable payload (selector + html preview),
761 * just without component / source attribution.
762 */
763export interface PickedElementPayload {
764 /** URL of the page the element was picked on. */
765 pageUrl: string;
766 /** Optional `<title>` of that page (best-effort). */
767 pageTitle: string | null;
768 /** Lowercase tag name, e.g. `"button"`. */
769 tagName: string;
770 /** CSS selector resolving back to the element on a re-render. */
771 selector: string | null;
772 /** Truncated outer-HTML preview (matches react-grab's `htmlPreview`). */
773 htmlPreview: string;
774 /** Nearest React component display name, or null when unavailable. */
775 componentName: string | null;
776 /** First source-mapped stack frame (file + line of the JSX source). */
777 source: PickedElementStackFrame | null;
778 /** Full owner-stack frames; can be empty. Useful for richer context. */
779 stack: ReadonlyArray<PickedElementStackFrame>;
780 /** Author CSS only (UA defaults stripped) — react-grab's `styles`. */
781 styles: string;
782 /** Wall-clock pick time as ISO-8601 string. */
783 pickedAt: string;
784}
785
786export const PickedElementPayloadSchema: Schema.Codec<PickedElementPayload> = Schema.Struct({
787 pageUrl: Schema.String,
788 pageTitle: Schema.NullOr(Schema.String),
789 tagName: Schema.String,
790 selector: Schema.NullOr(Schema.String),
791 htmlPreview: Schema.String,
792 componentName: Schema.NullOr(Schema.String),
793 source: Schema.NullOr(PickedElementStackFrameSchema),
794 stack: Schema.Array(PickedElementStackFrameSchema),
795 styles: Schema.String,
796 pickedAt: Schema.String,
797});
798
799export interface PreviewAnnotationRect {
800 x: number;
801 y: number;
802 width: number;
803 height: number;
804}
805
806export const PreviewAnnotationRectSchema: Schema.Codec<PreviewAnnotationRect> = Schema.Struct({
807 x: Schema.Number,
808 y: Schema.Number,
809 width: Schema.Number,
810 height: Schema.Number,
811});
812
813export interface PreviewAnnotationPoint {
814 x: number;
815 y: number;
816}
817
818export const PreviewAnnotationPointSchema: Schema.Codec<PreviewAnnotationPoint> = Schema.Struct({
819 x: Schema.Number,
820 y: Schema.Number,
821});
822
823export interface PreviewAnnotationElementTarget {
824 id: string;
825 element: PickedElementPayload;
826 rect: PreviewAnnotationRect;
827}
828
829export const PreviewAnnotationElementTargetSchema: Schema.Codec<PreviewAnnotationElementTarget> =
830 Schema.Struct({
831 id: Schema.String,
832 element: PickedElementPayloadSchema,
833 rect: PreviewAnnotationRectSchema,
834 });
835
836export interface PreviewAnnotationRegionTarget {
837 id: string;
838 rect: PreviewAnnotationRect;
839}
840
841export const PreviewAnnotationRegionTargetSchema: Schema.Codec<PreviewAnnotationRegionTarget> =
842 Schema.Struct({
843 id: Schema.String,
844 rect: PreviewAnnotationRectSchema,
845 });
846
847export interface PreviewAnnotationStrokeTarget {
848 id: string;
849 color: string;
850 width: number;
851 points: ReadonlyArray<PreviewAnnotationPoint>;
852 bounds: PreviewAnnotationRect;
853}
854
855export const PreviewAnnotationStrokeTargetSchema: Schema.Codec<PreviewAnnotationStrokeTarget> =
856 Schema.Struct({
857 id: Schema.String,
858 color: Schema.String,
859 width: Schema.Number,
860 points: Schema.Array(PreviewAnnotationPointSchema),
861 bounds: PreviewAnnotationRectSchema,
862 });
863
864export interface PreviewAnnotationStyleChange {
865 targetId: string;
866 selector: string | null;
867 property: string;
868 previousValue: string;
869 value: string;
870}
871
872export const PreviewAnnotationStyleChangeSchema: Schema.Codec<PreviewAnnotationStyleChange> =
873 Schema.Struct({
874 targetId: Schema.String,
875 selector: Schema.NullOr(Schema.String),
876 property: Schema.String,
877 previousValue: Schema.String,
878 value: Schema.String,
879 });
880
881export interface PreviewAnnotationScreenshot {
882 dataUrl: string;
883 width: number;
884 height: number;
885 cropRect: PreviewAnnotationRect;
886}
887
888export const PreviewAnnotationScreenshotSchema: Schema.Codec<PreviewAnnotationScreenshot> =
889 Schema.Struct({
890 dataUrl: Schema.String,
891 width: Schema.Number,
892 height: Schema.Number,
893 cropRect: PreviewAnnotationRectSchema,
894 });
895
896/**
897 * A submitted preview annotation. One annotation may reference multiple DOM
898 * elements, freeform regions, and ink strokes. The desktop main process adds
899 * the screenshot after the guest preload submits the structured draft.
900 */
901export interface PreviewAnnotationPayload {
902 id: string;
903 pageUrl: string;
904 pageTitle: string | null;
905 comment: string;
906 elements: ReadonlyArray<PreviewAnnotationElementTarget>;
907 regions: ReadonlyArray<PreviewAnnotationRegionTarget>;
908 strokes: ReadonlyArray<PreviewAnnotationStrokeTarget>;
909 styleChanges: ReadonlyArray<PreviewAnnotationStyleChange>;
910 screenshot: PreviewAnnotationScreenshot | null;
911 createdAt: string;
912}
913
914export const PreviewAnnotationPayloadSchema: Schema.Codec<PreviewAnnotationPayload> = Schema.Struct(
915 {
916 id: Schema.String,
917 pageUrl: Schema.String,
918 pageTitle: Schema.NullOr(Schema.String),
919 comment: Schema.String,
920 elements: Schema.Array(PreviewAnnotationElementTargetSchema),
921 regions: Schema.Array(PreviewAnnotationRegionTargetSchema),
922 strokes: Schema.Array(PreviewAnnotationStrokeTargetSchema),
923 styleChanges: Schema.Array(PreviewAnnotationStyleChangeSchema),
924 screenshot: Schema.NullOr(PreviewAnnotationScreenshotSchema),
925 createdAt: Schema.String,
926 },
927);
928
929export type PreviewAnnotationSubmission = "attach" | "send";
930export const PreviewAnnotationSubmissionSchema: Schema.Codec<PreviewAnnotationSubmission> =
931 Schema.Literals(["attach", "send"]);
932
933export interface PreviewAnnotationSubmissionResult {
934 annotation: PreviewAnnotationPayload;
935 submission: PreviewAnnotationSubmission;
936}
937export const PreviewAnnotationSubmissionResultSchema: Schema.Codec<PreviewAnnotationSubmissionResult> =
938 Schema.Struct({
939 annotation: PreviewAnnotationPayloadSchema,
940 submission: PreviewAnnotationSubmissionSchema,
941 });
942
943export const DesktopPreviewTabInputSchema = Schema.Struct({
944 tabId: DesktopPreviewTabIdSchema,
945});
946
947/**
948 * Tab creation carries the client's configured browser defaults so the guest
949 * is born already zoomed and color-scheme-emulated. Applying them after
950 * creation instead would paint one frame at 100%/system first, which reads as
951 * a flash on every tab open. Both fields are optional so an older renderer
952 * still gets the historical defaults.
953 */
954export const DesktopPreviewCreateTabInputSchema = Schema.Struct({
955 tabId: DesktopPreviewTabIdSchema,
956 zoomFactor: Schema.optional(Schema.Number.check(Schema.isGreaterThan(0))),
957 colorScheme: Schema.optional(DesktopPreviewColorSchemeSchema),
958});
959
960export interface DesktopPreviewTabDefaults {
961 readonly zoomFactor?: number | undefined;
962 readonly colorScheme?: DesktopPreviewColorScheme | undefined;
963}
964
965export const DesktopPreviewRegisterWebviewInputSchema = Schema.Struct({
966 tabId: DesktopPreviewTabIdSchema,
967 webContentsId: Schema.Int.check(Schema.isGreaterThan(0)),
968});
969
970export const DesktopPreviewNavigateInputSchema = Schema.Struct({
971 tabId: DesktopPreviewTabIdSchema,
972 url: Schema.String,
973});
974
975export const DesktopPreviewConfigInputSchema = Schema.Struct({
976 environmentId: EnvironmentId,
977});
978
979export const DesktopPreviewSetColorSchemeInputSchema = Schema.Struct({
980 tabId: DesktopPreviewTabIdSchema,
981 colorScheme: DesktopPreviewColorSchemeSchema,
982});
983
984export const DesktopPreviewSetAudioMutedInputSchema = Schema.Struct({
985 tabId: DesktopPreviewTabIdSchema,
986 audioMuted: Schema.Boolean,
987});
988
989export const DesktopPreviewAnnotationThemeInputSchema = Schema.Struct({
990 theme: DesktopPreviewAnnotationThemeSchema,
991});
992
993export const DesktopPreviewArtifactInputSchema = Schema.Struct({
994 path: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
995});
996
997export const DesktopPreviewRecordingSaveInputSchema = Schema.Struct({
998 tabId: DesktopPreviewTabIdSchema,
999 mimeType: Schema.String.check(Schema.isTrimmed()).check(Schema.isNonEmpty()),
1000 data: Schema.Uint8Array,
1001});
1002
1003export const DesktopPreviewAutomationClickInputSchema = Schema.Struct({
1004 tabId: DesktopPreviewTabIdSchema,
1005 input: PreviewAutomationClickInput,
1006});
1007
1008export const DesktopPreviewAutomationTypeInputSchema = Schema.Struct({
1009 tabId: DesktopPreviewTabIdSchema,
1010 input: PreviewAutomationTypeInput,
1011});
1012
1013export const DesktopPreviewAutomationPressInputSchema = Schema.Struct({
1014 tabId: DesktopPreviewTabIdSchema,
1015 input: PreviewAutomationPressInput,
1016});
1017
1018export const DesktopPreviewAutomationScrollInputSchema = Schema.Struct({
1019 tabId: DesktopPreviewTabIdSchema,
1020 input: PreviewAutomationScrollInput,
1021});
1022
1023export const DesktopPreviewAutomationEvaluateInputSchema = Schema.Struct({
1024 tabId: DesktopPreviewTabIdSchema,
1025 input: PreviewAutomationEvaluateInput,
1026});
1027
1028export const DesktopPreviewAutomationWaitForInputSchema = Schema.Struct({
1029 tabId: DesktopPreviewTabIdSchema,
1030 input: PreviewAutomationWaitForInput,
1031});
1032
1033export interface DesktopBridge {
1034 getAppBranding: () => DesktopAppBranding | null;
1035 /** The desktop client's OS platform, read from Electron's preload process. */
1036 getClientPlatform?: () => string;
1037 /**
1038 * The OS locale as a BCP-47 tag, which the renderer cannot read for itself:
1039 * the packaged app ships only the `en-US` Chromium locale pak, so
1040 * `navigator.language` and the default `Intl` locale are pinned to `en-US`
1041 * regardless of OS settings.
1042 */
1043 getSystemLocale?: () => string | null;
1044 // One bootstrap per pool instance currently registered with bootstrap
1045 // info (omits instances whose backend hasn't produced a config yet).
1046 // The primary backend is identified by id === PRIMARY_LOCAL_ENVIRONMENT_ID.
1047 getLocalEnvironmentBootstraps: () => readonly DesktopEnvironmentBootstrap[];
1048 getLocalEnvironmentBearerToken: () => Promise<string>;
1049 getClientSettings: () => Promise<ClientSettings | null>;
1050 setClientSettings: (settings: ClientSettings) => Promise<void>;
1051 getConnectionCatalog?: () => Promise<string | null>;
1052 setConnectionCatalog?: (catalog: string) => Promise<boolean>;
1053 clearConnectionCatalog?: () => Promise<void>;
1054 discoverSshHosts: () => Promise<readonly DesktopDiscoveredSshHost[]>;
1055 ensureSshEnvironment: (
1056 target: DesktopSshEnvironmentTarget,
1057 options?: { issuePairingToken?: boolean },
1058 ) => Promise<DesktopSshEnvironmentBootstrap>;
1059 disconnectSshEnvironment: (target: DesktopSshEnvironmentTarget) => Promise<void>;
1060 fetchSshEnvironmentDescriptor: (httpBaseUrl: string) => Promise<ExecutionEnvironmentDescriptor>;
1061 bootstrapSshBearerSession: (
1062 httpBaseUrl: string,
1063 credential: string,
1064 ) => Promise<AuthAccessTokenResult>;
1065 fetchSshSessionState: (httpBaseUrl: string, bearerToken: string) => Promise<AuthSessionState>;
1066 issueSshWebSocketTicket: (
1067 httpBaseUrl: string,
1068 bearerToken: string,
1069 ) => Promise<AuthWebSocketTicketResult>;
1070 onSshPasswordPrompt: (listener: (request: DesktopSshPasswordPromptRequest) => void) => () => void;
1071 resolveSshPasswordPrompt: (requestId: string, password: string | null) => Promise<void>;
1072 getServerExposureState: () => Promise<DesktopServerExposureState>;
1073 setServerExposureMode: (mode: DesktopServerExposureMode) => Promise<DesktopServerExposureState>;
1074 setTailscaleServeEnabled: (input: {
1075 readonly enabled: boolean;
1076 readonly port?: number;
1077 }) => Promise<DesktopServerExposureState>;
1078 getAdvertisedEndpoints: () => Promise<readonly AdvertisedEndpoint[]>;
1079 getWslState: () => Promise<DesktopWslState>;
1080 setWslBackendEnabled: (enabled: boolean) => Promise<DesktopWslState>;
1081 setWslDistro: (distro: string | null) => Promise<DesktopWslState>;
1082 setWslOnly: (enabled: boolean) => Promise<DesktopWslState>;
1083 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1084 /** Optional while older desktop shells can host a newer web client. */
1085 pickProjectFavicon?: (initialPath?: string) => Promise<string | null>;
1086 /**
1087 * Multi-select JSON file picker that opens in the VS Code extensions
1088 * directory when one exists. Optional: older desktop builds lack it, and
1089 * web callers fall back to a plain file input.
1090 */
1091 pickThemeFiles?: () => Promise<readonly PickedThemeFile[] | null>;
1092 setTheme: (theme: DesktopTheme) => Promise<void>;
1093 showContextMenu: <T extends string>(
1094 items: readonly ContextMenuItem<T>[],
1095 position?: { x: number; y: number },
1096 ) => Promise<T | null>;
1097 openExternal: (url: string) => Promise<boolean>;
1098 /**
1099 * Probe this desktop machine for installed remote-capable editor CLIs
1100 * (used for remote open-in-editor deep links). Optional: older desktop
1101 * builds lack it; callers fall back to VS Code only.
1102 */
1103 probeRemoteEditors?: () => Promise<readonly EditorId[]>;
1104 onMenuAction: (listener: (action: string) => void) => () => void;
1105 /**
1106 * Quit-confirmation hint pushes. Optional: older desktop builds never emit
1107 * them.
1108 */
1109 onQuitShortcut?: (listener: (event: QuitShortcutHintEvent) => void) => () => void;
1110 getWindowFullscreenState: () => boolean;
1111 onWindowFullscreenStateChange: (listener: (fullscreen: boolean) => void) => () => void;
1112 getUpdateState: () => Promise<DesktopUpdateState>;
1113 setUpdateChannel: (channel: DesktopUpdateChannel) => Promise<DesktopUpdateState>;
1114 checkForUpdate: () => Promise<DesktopUpdateCheckResult>;
1115 downloadUpdate: () => Promise<DesktopUpdateActionResult>;
1116 installUpdate: () => Promise<DesktopUpdateActionResult>;
1117 onUpdateState: (listener: (state: DesktopUpdateState) => void) => () => void;
1118 /** Present when the desktop shell accepts `t3 app` activation requests. */
1119 appActivation?: {
1120 setReady: (ready: boolean) => Promise<void>;
1121 complete: (response: DesktopAppActivationResponse) => Promise<void>;
1122 onRequest: (listener: (request: DesktopAppActivationRequest) => void) => () => void;
1123 };
1124 /**
1125 * Desktop-only preview surface. Present iff the renderer is hosted by the
1126 * Electron desktop build; web builds have `preview === undefined`.
1127 */
1128 preview?: DesktopPreviewBridge;
1129}
1130
1131/** Renderer callback invoked by Electron with a fresh user gesture before display-media capture. */
1132export const DESKTOP_PREVIEW_RECORDING_CAPTURE_TRIGGER = "__t3DesktopPreviewRecordingCapture";
1133
1134export interface DesktopPreviewBridge {
1135 createTab: (tabId: string, defaults?: DesktopPreviewTabDefaults) => Promise<void>;
1136 closeTab: (tabId: string) => Promise<void>;
1137 registerWebview: (tabId: string, webContentsId: number) => Promise<void>;
1138 navigate: (tabId: string, url: string) => Promise<void>;
1139 goBack: (tabId: string) => Promise<void>;
1140 goForward: (tabId: string) => Promise<void>;
1141 refresh: (tabId: string) => Promise<void>;
1142 zoomIn: (tabId: string) => Promise<void>;
1143 zoomOut: (tabId: string) => Promise<void>;
1144 resetZoom: (tabId: string) => Promise<void>;
1145 /** Reload bypassing the HTTP cache. */
1146 hardReload: (tabId: string) => Promise<void>;
1147 /**
1148 * Emulate `prefers-color-scheme` on the guest page ("system" clears the
1149 * override). Persists per tab and is re-applied across webview swaps.
1150 */
1151 setColorScheme: (tabId: string, colorScheme: DesktopPreviewColorScheme) => Promise<void>;
1152 /**
1153 * Silence the tab's audio output. Persists per tab and is re-applied across
1154 * webview swaps, but is dropped when the tab closes. Muting a silent tab is
1155 * allowed; it simply takes effect once the page plays something.
1156 */
1157 setAudioMuted: (tabId: string, audioMuted: boolean) => Promise<void>;
1158 /** Open the guest webview's DevTools (detached). */
1159 openDevTools: (tabId: string) => Promise<void>;
1160 /** Drop cookies + storage data for the preview partition (all tabs). */
1161 clearCookies: () => Promise<void>;
1162 /** Drop the HTTP cache for the preview partition (all tabs). */
1163 clearCache: () => Promise<void>;
1164 /**
1165 * One-shot config for mounting a preview `<webview>`. Replaces three
1166 * earlier round-trip calls (`getBrowserPartition`, `getWebviewPreferences`,
1167 * `getPickPreloadPath`) so adding a new field here only requires touching
1168 * the contract + main, not the renderer's mount logic.
1169 */
1170 getPreviewConfig: (environmentId: EnvironmentId) => Promise<DesktopPreviewWebviewConfig>;
1171 setAnnotationTheme: (theme: DesktopPreviewAnnotationTheme) => Promise<void>;
1172 /**
1173 * Activate the in-page element picker for the given tab. Resolves with
1174 * the picked annotation and its attach/send intent, or `null` when the
1175 * user cancels (Escape / nav). The promise rejects if the picker can't be
1176 * activated (no webview, etc.).
1177 */
1178 pickElement: (tabId: string) => Promise<PreviewAnnotationSubmissionResult | null>;
1179 /** Cancel an in-flight preview annotation session. */
1180 cancelPickElement: (tabId: string) => Promise<void>;
1181 captureScreenshot: (tabId: string) => Promise<DesktopPreviewScreenshotArtifact>;
1182 revealArtifact: (path: string) => Promise<void>;
1183 copyArtifactToClipboard: (path: string) => Promise<void>;
1184 pictureInPicture: {
1185 open: (tabId: string) => Promise<void>;
1186 close: (tabId: string) => Promise<void>;
1187 };
1188 recording: {
1189 startScreencast: (tabId: string) => Promise<void>;
1190 stopScreencast: (tabId: string) => Promise<void>;
1191 save: (
1192 tabId: string,
1193 mimeType: string,
1194 data: Uint8Array,
1195 ) => Promise<DesktopPreviewRecordingArtifact>;
1196 onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
1197 };
1198 automation: {
1199 status: (tabId: string) => Promise<DesktopPreviewAutomationStatus>;
1200 snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
1201 click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
1202 type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;
1203 press: (tabId: string, input: PreviewAutomationPressInput) => Promise<void>;
1204 scroll: (tabId: string, input: PreviewAutomationScrollInput) => Promise<void>;
1205 evaluate: (tabId: string, input: PreviewAutomationEvaluateInput) => Promise<unknown>;
1206 waitFor: (tabId: string, input: PreviewAutomationWaitForInput) => Promise<void>;
1207 };
1208 onStateChange: (listener: (tabId: string, state: DesktopPreviewTabState) => void) => () => void;
1209 onPointerEvent: (listener: (event: DesktopPreviewPointerEvent) => void) => () => void;
1210}
1211
1212export type ConfirmDialogVariant = "default" | "destructive";
1213
1214export interface ConfirmDialogOptions {
1215 readonly variant?: ConfirmDialogVariant;
1216}
1217
1218/**
1219 * APIs bound to the local app shell, not to any particular backend environment.
1220 *
1221 * These capabilities describe the desktop/browser host that the user is
1222 * currently running: dialogs, external-link opening, context menus, and
1223 * app-level settings/config access. They must not be used as a proxy for
1224 * "whatever environment the user is targeting", because in a multi-environment
1225 * world the local shell and a selected backend environment are distinct
1226 * concepts.
1227 */
1228export interface LocalApi {
1229 dialogs: {
1230 pickFolder: (options?: PickFolderOptions) => Promise<string | null>;
1231 confirm: (message: string, options?: ConfirmDialogOptions) => Promise<boolean>;
1232 };
1233 shell: {
1234 openExternal: (url: string) => Promise<void>;
1235 };
1236 contextMenu: {
1237 show: <T extends string>(
1238 items: readonly ContextMenuItem<T>[],
1239 position?: { x: number; y: number },
1240 ) => Promise<T | null>;
1241 close: () => Promise<void>;
1242 };
1243 persistence: {
1244 getClientSettings: () => Promise<ClientSettings | null>;
1245 setClientSettings: (settings: ClientSettings) => Promise<void>;
1246 };
1247}
1248
1249/**
1250 * APIs bound to a specific backend environment connection.
1251 *
1252 * These operations must always be routed with explicit environment context.
1253 * They represent remote stateful capabilities such as orchestration, terminal,
1254 * project, VCS, and provider operations. In multi-environment mode, each environment gets
1255 * its own instance of this surface, and callers should resolve it by
1256 * `environmentId` rather than reaching through the local desktop bridge.
1257 */
1258export interface EnvironmentApi {
1259 terminal: {
1260 open: (input: typeof TerminalOpenInput.Encoded) => Promise<TerminalSessionSnapshot>;
1261 attach: (
1262 input: typeof TerminalAttachInput.Encoded,
1263 callback: (event: TerminalAttachStreamEvent) => void,
1264 options?: {
1265 onResubscribe?: () => void;
1266 },
1267 ) => () => void;
1268 write: (input: typeof TerminalWriteInput.Encoded) => Promise<void>;
1269 resize: (input: typeof TerminalResizeInput.Encoded) => Promise<void>;
1270 clear: (input: typeof TerminalClearInput.Encoded) => Promise<void>;
1271 restart: (input: typeof TerminalRestartInput.Encoded) => Promise<TerminalSessionSnapshot>;
1272 close: (input: typeof TerminalCloseInput.Encoded) => Promise<void>;
1273 onMetadata: (
1274 callback: (event: TerminalMetadataStreamEvent) => void,
1275 options?: {
1276 onResubscribe?: () => void;
1277 },
1278 ) => () => void;
1279 };
1280 projects: {
1281 listEntries: (input: ProjectListEntriesInput) => Promise<ProjectListEntriesResult>;
1282 readFile: (input: ProjectReadFileInput) => Promise<ProjectReadFileResult>;
1283 searchEntries: (input: ProjectSearchEntriesInput) => Promise<ProjectSearchEntriesResult>;
1284 writeFile: (input: ProjectWriteFileInput) => Promise<ProjectWriteFileResult>;
1285 };
1286 filesystem: {
1287 browse: (input: FilesystemBrowseInput) => Promise<FilesystemBrowseResult>;
1288 };
1289 assets: {
1290 createUrl: (input: AssetCreateUrlInput) => Promise<AssetCreateUrlResult>;
1291 };
1292 sourceControl: {
1293 lookupRepository: (
1294 input: SourceControlRepositoryLookupInput,
1295 ) => Promise<SourceControlRepositoryInfo>;
1296 cloneRepository: (
1297 input: SourceControlCloneRepositoryInput,
1298 ) => Promise<SourceControlCloneRepositoryResult>;
1299 publishRepository: (
1300 input: SourceControlPublishRepositoryInput,
1301 ) => Promise<SourceControlPublishRepositoryResult>;
1302 };
1303 vcs: {
1304 listRefs: (input: VcsListRefsInput) => Promise<VcsListRefsResult>;
1305 createWorktree: (input: VcsCreateWorktreeInput) => Promise<VcsCreateWorktreeResult>;
1306 removeWorktree: (input: VcsRemoveWorktreeInput) => Promise<void>;
1307 createRef: (input: VcsCreateRefInput) => Promise<VcsCreateRefResult>;
1308 switchRef: (input: VcsSwitchRefInput) => Promise<VcsSwitchRefResult>;
1309 init: (input: VcsInitInput) => Promise<void>;
1310 pull: (input: VcsPullInput) => Promise<VcsPullResult>;
1311 refreshStatus: (input: VcsStatusInput) => Promise<VcsStatusResult>;
1312 onStatus: (
1313 input: VcsStatusInput,
1314 callback: (status: VcsStatusResult) => void,
1315 options?: {
1316 onResubscribe?: () => void;
1317 },
1318 ) => () => void;
1319 };
1320 git: {
1321 resolvePullRequest: (input: GitPullRequestRefInput) => Promise<GitResolvePullRequestResult>;
1322 preparePullRequestThread: (
1323 input: GitPreparePullRequestThreadInput,
1324 ) => Promise<GitPreparePullRequestThreadResult>;
1325 };
1326 review: {
1327 getDiffPreview: (input: ReviewDiffPreviewInput) => Promise<ReviewDiffPreviewResult>;
1328 getDiffFileContents: (
1329 input: ReviewDiffFileContentsInput,
1330 ) => Promise<ReviewDiffFileContentsResult>;
1331 };
1332 orchestration: {
1333 dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
1334 getTurnDiff: (input: OrchestrationGetTurnDiffInput) => Promise<OrchestrationGetTurnDiffResult>;
1335 getFullThreadDiff: (
1336 input: OrchestrationGetFullThreadDiffInput,
1337 ) => Promise<OrchestrationGetFullThreadDiffResult>;
1338 getArchivedShellSnapshot: () => Promise<OrchestrationShellSnapshot>;
1339 subscribeShell: (
1340 callback: (event: OrchestrationShellStreamItem) => void,
1341 options?: {
1342 onResubscribe?: () => void;
1343 },
1344 ) => () => void;
1345 subscribeThread: (
1346 input: OrchestrationSubscribeThreadInput,
1347 callback: (event: OrchestrationThreadStreamItem) => void,
1348 options?: {
1349 onResubscribe?: () => void;
1350 },
1351 ) => () => void;
1352 };
1353 preview: {
1354 open: (input: typeof PreviewOpenInput.Encoded) => Promise<PreviewSessionSnapshot>;
1355 navigate: (input: typeof PreviewNavigateInput.Encoded) => Promise<PreviewSessionSnapshot>;
1356 resize: (input: typeof PreviewResizeInput.Encoded) => Promise<PreviewSessionSnapshot>;
1357 refresh: (input: typeof PreviewRefreshInput.Encoded) => Promise<void>;
1358 close: (input: typeof PreviewCloseInput.Encoded) => Promise<void>;
1359 list: (input: typeof PreviewListInput.Encoded) => Promise<PreviewListResult>;
1360 reportStatus: (input: typeof PreviewReportStatusInput.Encoded) => Promise<void>;
1361 automation: {
1362 connect: (
1363 input: PreviewAutomationHost,
1364 callback: (event: PreviewAutomationStreamEvent) => void,
1365 options?: { onResubscribe?: () => void },
1366 ) => () => void;
1367 respond: (response: PreviewAutomationResponse) => Promise<void>;
1368 focusHost: (input: PreviewAutomationHostFocus) => Promise<void>;
1369 };
1370 onEvent: (
1371 callback: (event: PreviewEvent) => void,
1372 options?: { onResubscribe?: () => void },
1373 ) => () => void;
1374 subscribePorts: (
1375 callback: (servers: DiscoveredLocalServerList) => void,
1376 options?: { onResubscribe?: () => void },
1377 ) => () => void;
1378 };
1379}