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