Repository navigation
agentHost: add a macOS permission setup modal for Computer Use #343308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Giuseppe Cianci (Giuspepe)
merged 3 commits into
main
from
agents/pasted-text-processing
Oct 21, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.