Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/lib/stylelint/vscode-known-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,7 @@
"--comment-thread-editor-font-weight",
"--comment-thread-state-color",
"--comment-thread-state-background-color",
"--computer-use-setup-stroke",
"--inline-edit-border-radius",
"--vscode-inline-chat-affordance-height",
"--collapse-from-width",
Expand Down
5 changes: 5 additions & 0 deletions src/vs/base/browser/ui/dialog/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
align-self: baseline;
}

.monaco-dialog-box .dialog-message-row > .dialog-icon.custom-icon {
display: flex;
flex: 0 0 auto;
}

.monaco-dialog-box:not(.align-vertical) .dialog-message-row .dialog-message-container {
align-self: stretch; /* fill row height so overflow-y scrolling works */
}
Expand Down
10 changes: 9 additions & 1 deletion src/vs/base/browser/ui/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface IDialogOptions {
readonly renderBody?: (container: HTMLElement) => void;
readonly renderFooter?: (container: HTMLElement) => void;
readonly icon?: ThemeIcon;
/** Renders an icon of the owner's, such as an app's image, in place of {@link icon} and the {@link type}'s codicon. */
readonly renderIcon?: (container: HTMLElement) => void;
readonly buttonOptions?: Array<undefined | { sublabel?: string; styleButton?: (button: IButton) => void }>;
readonly primaryButtonDropdown?: IButtonWithDropdownOptions;
readonly disableCloseAction?: boolean;
Expand Down Expand Up @@ -183,6 +185,10 @@ export class Dialog extends Disposable {
const messageRowElement = this.element.appendChild($('.dialog-message-row'));
this.iconElement = messageRowElement.appendChild($('#monaco-dialog-icon.dialog-icon'));
this.iconElement.setAttribute('aria-label', this.getIconAriaLabel());
if (this.options.renderIcon) {
this.iconElement.classList.add('custom-icon');
this.options.renderIcon(this.iconElement);
Comment thread
Giuspepe marked this conversation as resolved.
Resolved
}
this.messageContainer = messageRowElement.appendChild($('.dialog-message-container'));

const hasDetail = !!this.options.detail || !!this.options.detailElement;
Expand Down Expand Up @@ -533,7 +539,9 @@ export class Dialog extends Disposable {

this.iconElement.classList.remove(...ThemeIcon.asClassNameArray(Codicon.dialogError), ...ThemeIcon.asClassNameArray(Codicon.dialogWarning), ...ThemeIcon.asClassNameArray(Codicon.dialogInfo), ...ThemeIcon.asClassNameArray(Codicon.loading), spinModifierClassName);

if (this.options.icon) {
if (this.options.renderIcon) {
// The owner rendered the icon.
} else if (this.options.icon) {
this.iconElement.classList.add(...ThemeIcon.asClassNameArray(this.options.icon));
} else {
switch (this.options.type) {
Expand Down
5 changes: 5 additions & 0 deletions src/vs/platform/agentHost/common/agentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,11 @@ export interface IAgentHostManagementService {
* machine is fully awake, rather than asleep or in a background maintenance wake.
*/
setSystemFullyAwake(fullyAwake: boolean): Promise<void>;
/**
* Local-only bridge for the owning client process to report that macOS changed which apps it trusts to control the
* computer through Accessibility.
*/
reportMacAccessibilityTrustChange(): Promise<void>;
shutdown(): Promise<void>;
getNetworkDiagnosticsInfo(): Promise<IAgentHostNetworkDiagnosticsInfo>;
getManagedSettingsDiagnostics(): Promise<readonly IAgentHostManagedSettingsDiagnostics[]>;
Expand Down
165 changes: 165 additions & 0 deletions src/vs/platform/agentHost/common/computerUse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/**
* VS Code extension contract for setting up the macOS permissions of GitHub's Computer Use plugin. The local macOS
* Agent Host publishes {@link IComputerUseStatusV1} as the root transient value {@link COMPUTER_USE_STATUS_KEY};
* clients send {@link IComputerUseRequest}s through {@link COMPUTER_USE_REQUEST_KEY}. Both ride namespaced root config
* values, not AHP proper, so hosts without the feature publish nothing and clients keep the ordinary elicitation UI.
*
* The host stays authoritative: a permission is `granted` only after Copilot Computer Use's helper verified it, and
* every operation runs through the plugin's own MCP connection, which the Copilot runtime owns. Values read off the
* wire go through the validating readers in `common/meta/computerUse.ts`; never cast them.
*/

// #region Keys

/** Root transient value carrying the host's {@link IComputerUseStatusV1}. Absent when the host cannot set up Computer Use. */
export const COMPUTER_USE_STATUS_KEY = 'vscode.computerUse.status';

/**
* Root config key a client writes an {@link IComputerUseRequest} to. The host claims the request's nonce and clears the
* key before acting, so a repeated identical gesture still lands.
*/
export const COMPUTER_USE_REQUEST_KEY = 'vscode.computerUse.request';

/**
* Namespaced `_meta` key on the chat input request that stands for a setup in the chat. Clients that understand it
* show a setup entry point; others render the request's ordinary questions, which remain answerable.
*/
export const COMPUTER_USE_SETUP_META_KEY = 'vscode.computerUse.setup';

// #endregion

// #region Status

/** The macOS permissions Copilot Computer Use requires before any of its tools run. */
export const computerUsePermissions = ['accessibility', 'screenRecording'] as const;
export type ComputerUsePermission = typeof computerUsePermissions[number];

/** `unknown` until the helper reported the permission in this Agent Host process. */
export const computerUsePermissionStates = ['granted', 'notGranted', 'unknown'] as const;
export type ComputerUsePermissionState = typeof computerUsePermissionStates[number];

/**
* - `needsPermissions`: the plugin waits for the user to choose an action.
* - `working`: an action was sent and the plugin has not reported its outcome yet.
* - `ready`: the plugin verified both permissions and resumed the operation that was waiting.
* - `ended`: the setup closed without readiness; see {@link IComputerUseSetupV1.error}.
*/
export const computerUseSetupStates = ['needsPermissions', 'working', 'ready', 'ended'] as const;
export type ComputerUseSetupState = typeof computerUseSetupStates[number];

/**
* - `request`: show the native macOS permission prompt for a permission.
* - `openSettings`: open the permission's pane in System Settings.
* - `recheck`: restart Copilot Computer Use's helper, which some grants need to take effect, and verify again.
*/
export const computerUseActions = ['request', 'openSettings', 'recheck'] as const;
export type ComputerUseAction = typeof computerUseActions[number];

/** Actions that must carry {@link IComputerUseRequest.permission}. */
export const computerUsePermissionActions: readonly ComputerUseAction[] = ['request', 'openSettings'];

export interface IComputerUsePermissionStatusV1 {
readonly permission: ComputerUsePermission;
readonly state: ComputerUsePermissionState;
}

/** An action the plugin accepts for a setup now. */
export interface IComputerUseSetupActionV1 {
readonly action: ComputerUseAction;
/** Present exactly for {@link computerUsePermissionActions}. */
readonly permission?: ComputerUsePermission;
}

/** A user-facing failure; `message` is localized by the host. `code` stays an open string so newer codes reach older clients, which show `message`. */
export interface IComputerUseErrorV1 {
readonly code: string;
readonly message: string;
}

/** One chat turn waiting for Computer Use permissions. */
export interface IComputerUseSetupV1 {
readonly id: string;
/** Chat channel URI of the turn that waits. */
readonly chat: string;
readonly state: ComputerUseSetupState;
/** Increments every time the plugin reports the permissions again; requests must name the current round. */
readonly round: number;
/** What the plugin accepts now. Empty unless {@link state} is `needsPermissions`. */
readonly actions: readonly IComputerUseSetupActionV1[];
readonly error?: IComputerUseErrorV1;
}

/** The action in flight. At most one runs at a time across all setups, because they share one helper and one set of native prompts. */
export interface IComputerUseOperationV1 {
readonly setupId: string;
readonly action: ComputerUseAction;
readonly permission?: ComputerUsePermission;
}

export interface IComputerUseStatusV1 {
readonly schemaVersion: 1;
/** Every required permission, in {@link computerUsePermissions} order, with its last verified state. These are machine-wide: all setups share them. */
readonly permissions: readonly IComputerUsePermissionStatusV1[];
/** Epoch ms of the last verification; absent while every permission is `unknown`. */
readonly verifiedAt?: number;
readonly operation?: IComputerUseOperationV1;
/** Setups that wait for the user, run an action, or finished recently; oldest first. */
readonly setups: readonly IComputerUseSetupV1[];
/** The app that macOS grants the permissions to. */
readonly helperApp?: IComputerUseHelperAppV1;
}

/** Copilot Computer Use, the app macOS lists under each permission in System Settings. */
export interface IComputerUseHelperAppV1 {
/** Absolute path of the app bundle. Clients that can drag files offer it for dragging into a System Settings list that doesn't show it. */
readonly path: string;
/** The app's icon as a PNG data URL, once the host read it. */
readonly icon?: string;
}

// #endregion

// #region Requests

/** The value a client writes to {@link COMPUTER_USE_REQUEST_KEY}. */
export interface IComputerUseRequest {
/** Fresh per gesture; the host ignores nonces it has already seen. */
readonly nonce: string;
readonly setupId: string;
/** The {@link IComputerUseSetupV1.round} the user acted on; the host drops requests for an older round. */
readonly round: number;
readonly action: ComputerUseAction;
readonly permission?: ComputerUsePermission;
}

const MAX_ID_LENGTH = 256;

function isBoundedId(value: unknown): value is string {
return typeof value === 'string' && value.length > 0 && value.length <= MAX_ID_LENGTH;
}

/** Whether `value` is a well-formed {@link IComputerUseRequest}, including the permission each action requires. */
export function isComputerUseRequest(value: unknown): value is IComputerUseRequest {
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return false;
}
const request: Partial<Record<keyof IComputerUseRequest, unknown>> = value;
const action = computerUseActions.find(candidate => candidate === request.action);
if (!isBoundedId(request.nonce) || !isBoundedId(request.setupId) || !action) {
return false;
}
if (typeof request.round !== 'number' || !Number.isSafeInteger(request.round) || request.round < 0) {
return false;
}
if (request.permission !== undefined && !computerUsePermissions.some(permission => permission === request.permission)) {
return false;
}
return computerUsePermissionActions.includes(action) === (request.permission !== undefined);
}

// #endregion
18 changes: 18 additions & 0 deletions src/vs/platform/agentHost/common/meta/computerUse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { COMPUTER_USE_STATUS_KEY, type IComputerUseStatusV1 } from '../computerUse.js';
import type { RootState } from '../state/protocol/state.js';
import { readComputerUseStatus } from './vscode/computerUse.js';

export { readComputerUseSetupCard, readComputerUseStatus, withComputerUseSetupCard, type IComputerUseSetupCard } from './vscode/computerUse.js';

/** Reads the Computer Use setup status a host published as `vscode.computerUse.status`; `undefined` (keep the ordinary elicitation UI) for hosts that don't implement it. */
export function readComputerUseStatusFromRootState(state: RootState | Error | undefined): IComputerUseStatusV1 | undefined {
if (!state || state instanceof Error) {
return undefined;
}
return readComputerUseStatus(state.config?.values[COMPUTER_USE_STATUS_KEY]);
}
Loading
Loading