2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { matchesFuzzy2 } from '../../../base/common/filters.js';
7
>
import { localize } from '../../../nls.js';
8
>
import { SessionConfigKey } from './sessionConfigKeys.js';
9
>
10
>
/**
11
>
* Copilot agent-host "config action" slash commands: workbench-defined slash
12
>
* commands that toggle a well-known session-config property (the `autoApprove`
13
>
* permissions axis and/or the `mode` axis) instead of driving a chat turn.
14
>
*
15
>
* The Copilot agent owns the `autoApprove`/`mode` schema, so these commands are
16
>
* produced server-side (see the Copilot slash-command completion provider) and
17
>
* carry an `action` bag on their completion `_meta`. The workbench interprets
18
>
* that bag on accept — applying the config via the active session's provider so
19
>
* the permission/mode pickers update reactively — while the send path
20
>
* (`CopilotAgentSession.send`) re-applies the change and strips the leading
21
>
* token so it is not dispatched to the runtime as a runtime command.
22
>
*
23
>
* Values below are the well-known enum members of the Copilot platform session
24
>
* schema (`autoApprove`: `default` | `autoApprove`; `mode`: `interactive` |
25
>
* `plan` | `autopilot`).
26
>
*/
27
>
28
>
const AUTO_APPROVE_BYPASS = 'autoApprove';
29
>
const AUTO_APPROVE_DEFAULT = 'default';
30
>
const MODE_INTERACTIVE = 'interactive';
31
>
const MODE_PLAN = 'plan';
32
>
const MODE_AUTOPILOT = 'autopilot';
33
>
34
>
/**
35
>
* A single flattened completion form of a config-action slash command (the bare
36
>
* command or one of its named sub-arguments), ready to be emitted as a
37
>
* completion item.
38
>
*/
39
>
export interface ICopilotConfigSlashCommandItem {
40
>
/**
41
>
* The text inserted when accepted. Empty for a pure toggle (nothing is left
42
>
* in the input); `/command ` (trailing space) for an item that keeps the text
43
>
* so an argument can be typed.
44
>
*/
45
>
readonly insertText: string;
46
>
/** The display label shown in the picker (e.g. `/autopilot on`). */
47
>
readonly label: string;
48
>
/** The command name (without the leading `/`). */
49
>
readonly command: string;
50
>
/** Human-readable description shown in completion detail. */
51
>
readonly description: string;
52
>
/** Argument hint (ghost text) shown after acceptance for keep-text items. */
53
>
readonly argumentHint?: string;
54
>
/** The session-config change applied when accepted. */
55
>
readonly applyConfig: Readonly<Record<string, string>>;
56
>
/** Sort key used to order completions. */
57
>
readonly sortText: string;
58
>
}
59
>
60
>
/** Internal catalog descriptor for one form of a config-action command. */
61
>
interface IConfigSlashOption {
62
>
/** Named sub-argument (e.g. `on`/`off`), or `undefined` for the bare command. */
63
>
readonly arg?: string;
64
>
readonly detail: string;
65
>
readonly config: Readonly<Record<string, string>>;
66
>
/**
67
>
* When set, the option is a keep-text form: it inserts `/command ` and shows
68
>
* this hint as ghost text so an argument can be typed. When omitted, the
69
>
* option is a pure toggle that inserts nothing.
70
>
*/
71
>
readonly argumentHint?: string;
72
>
}
73
>
74
>
interface IConfigSlashCommand {
75
>
readonly command: string;
76
>
readonly sortText: string;
77
>
readonly options: readonly IConfigSlashOption[];
78
>
}
79
>
80
function setBypassDetail(): string { return localize('copilotConfigSlash.yolo', "Set permissions to bypass approvals"); }
81
function setDefaultDetail(): string { return localize('copilotConfigSlash.default', "Set permissions back to default"); }