agentCompletionAttachmentMeta.ts ×7

Frontier kind: Code frontier

unlabeled · c_c9a7c870637d

782 tests · 9386 LOC · 34 files · introduces 0 tests · 133 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
7 ranges133 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
574 ranges9386 lines · 34 files · Browse complete extent
All tests (intent)
782 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 133 introduced LOC across 7 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/meta/agentCompletionAttachmentMeta.ts 133 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentCompletionAttachmentMeta.ts
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 type { SimpleMessageAttachment } from '../state/protocol/state.js';
7 >
8 > /**
9 > * Well-known typed views over a `SimpleMessageAttachment`'s `_meta` bag as
10 > * produced by the `completions` command, populated by the slash-command and
11 > * skill completion providers and read by the session handler. Read the bag
12 > * through {@link readCompletionAttachmentMeta} rather than indexing `_meta`
13 > * directly. Two variants are distinguished by which discriminating key is
14 > * present: a slash command (`command`) or a skill (`uri`).
15 > */
16 >
17 > /**
18 > * A client-side side effect a command completion carries. When present, the
19 > * workbench interprets it on accept (see the shared agent-host completion action
20 > * handler) rather than treating the item as a plain text/reference insertion.
21 > *
22 > * Used by Copilot agent-host permission/mode toggles (e.g. `/yolo`,
23 > * `/autopilot on`): the item applies a well-known session-config change. Whether
24 > * the item leaves text behind is expressed by its `insertText` (empty for a pure
25 > * toggle; `/command ` for an item that keeps the text so an argument can be
26 > * typed, with {@link ICommandCompletionAttachmentMeta.argumentHint} as ghost text).
27 > */
28 > export interface IAgentHostCompletionAction {
29 > /**
30 > * A partial agent-host session-config change to apply when the completion is
31 > * accepted, keyed by well-known session-config property (e.g. `autoApprove`,
32 > * `mode`) to the string-enum value. Applied via the active session's provider
33 > * so the corresponding picker updates reactively.
34 > */
35 > readonly applyConfig?: Readonly<Record<string, string>>;
36 > }
37 >
38 > /**
39 > * The `_meta` shape attached to a `completions` result that resolves to a slash
40 > * command.
41 > */
42 > export interface ICommandCompletionAttachmentMeta {
43 > /** The slash command name (without the leading `/`). */
44 > readonly command: string;
45 > /** Optional human-readable description of the command. */
46 > readonly description?: string;
47 > /**
48 > * Optional hint describing the argument the command expects. Rendered as
49 > * inline placeholder (ghost text) after an accepted command completion.
50 > */
51 > readonly argumentHint?: string;
52 > /**
53 > * Optional client-side action to run when the completion is accepted (e.g. a
54 > * permission/mode session-config toggle). See {@link IAgentHostCompletionAction}.
55 > */
56 > readonly action?: IAgentHostCompletionAction;
57 > }
58 >
59 > /**
60 > * The `_meta` shape attached to a `completions` result that resolves to a skill.
61 > */
62 > export interface ISkillCompletionAttachmentMeta {
63 > /** The skill resource URI as a string. */
64 > readonly uri: string;
65 > /** Optional internal name of the skill. */
66 > readonly name?: string;
67 > /** Optional human-readable display name (e.g. the slash-command name). */
68 > readonly displayName?: string;
69 > /** Optional human-readable description of the skill. */
70 > readonly description?: string;
71 > }
72 >
73 > /**
74 > * A typed, discriminated view over the well-known `completions` attachment
75 > * `_meta` variants. The `kind` discriminant is computed by
76 > * {@link readCompletionAttachmentMeta} from which key is present on the wire; it
77 > * is not itself carried in `_meta`.
78 > */
79 > export type CompletionAttachmentMeta =
80 > | ({ readonly kind: 'command' } & ICommandCompletionAttachmentMeta)
81 > | ({ readonly kind: 'skill' } & ISkillCompletionAttachmentMeta);
82 >
83 > /**
84 > * Reads the well-known `completions` attachment `_meta` keys, classifying the
85 > * bag into a {@link CompletionAttachmentMeta} variant by its discriminating key
86 > * (`command` for a slash command, `uri` for a skill). Returns `undefined` when
87 > * the bag is absent or matches neither variant; wrong-typed keys are dropped.
88 > */
89 > export function readCompletionAttachmentMeta(attachment: SimpleMessageAttachment): CompletionAttachmentMeta | undefined {
90 const meta = attachment._meta;
91 if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
113 return undefined;
114 }
116 > /**
117 > * Serializes a typed {@link ICommandCompletionAttachmentMeta} into the `_meta`
118 > * record, dropping `undefined` entries. Build a slash-command completion's
119 > * `_meta` through this so producers stay in lock-step with
120 > * {@link readCompletionAttachmentMeta}.
121 > */
122 > export function toCommandCompletionAttachmentMeta(meta: ICommandCompletionAttachmentMeta): Record<string, unknown> {
123 const result: Record<string, unknown> = { command: meta.command };
124 if (meta.description !== undefined) {
134 return result;
135 }
137 > /**
138 > * Reads the optional {@link IAgentHostCompletionAction} carried on a command
139 > * completion's raw `_meta` bag (under the `action` key). Kept as the single
140 > * seam consumers use to obtain the action, mirroring {@link getCommandArgumentHint}.
141 > * Returns `undefined` when absent or malformed; wrong-typed sub-fields are dropped.
142 > */
143 > export function getCompletionAction(meta: Record<string, unknown> | undefined): IAgentHostCompletionAction | undefined {
144 if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
145 return undefined;
147 return readCompletionActionMeta(meta['action']);
148 }
150 > /**
151 > * Parses an unknown value into an {@link IAgentHostCompletionAction}. Accepts an
152 > * object with a string-map `applyConfig`; returns `undefined` when no valid
153 > * `applyConfig` is present.
154 > */
155 function readCompletionActionMeta(value: unknown): IAgentHostCompletionAction | undefined {
156 if (!value || typeof value !== 'object' || Array.isArray(value)) {
173 return { applyConfig };
174 }
176 > /**
177 > * Serializes an {@link IAgentHostCompletionAction} into a plain record for the
178 > * `_meta` bag, dropping empty entries. Returns `undefined` when the action
179 > * carries nothing meaningful.
180 > */
181 function toCompletionActionMeta(action: IAgentHostCompletionAction | undefined): Record<string, unknown> | undefined {
182 if (!action?.applyConfig || Object.keys(action.applyConfig).length === 0) {
185 return { applyConfig: { ...action.applyConfig } };
186 }
188 > /**
189 > * Reads the well-known `argumentHint` from a raw completion attachment `_meta`
190 > * bag. Kept as the single seam that consumers use to obtain the hint, so a
191 > * future promotion of `argumentHint` to a first-class attachment field only
192 > * needs to change this reader. Returns `undefined` when absent or wrong-typed.
193 > */
194 > export function getCommandArgumentHint(meta: Record<string, unknown> | undefined): string | undefined {
195 if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
196 return undefined;
198 return typeof meta['argumentHint'] === 'string' ? meta['argumentHint'] : undefined;
199 }
201 > /**
202 > * Serializes a typed {@link ISkillCompletionAttachmentMeta} into the `_meta`
203 > * record, dropping `undefined` entries. Build a skill completion's `_meta`
204 > * through this so producers stay in lock-step with
205 > * {@link readCompletionAttachmentMeta}.
206 > */
207 > export function toSkillCompletionAttachmentMeta(meta: ISkillCompletionAttachmentMeta): Record<string, unknown> {
208 const result: Record<string, unknown> = { uri: meta.uri };
209 if (meta.name !== undefined) {