src/vs/platform/agentHost/node/agentHostRenameCommand.ts

82 LOC · 82 covered · 0 uncovered · 14 ranges · 1062 concepts · 10 introducers · 520 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentHostRenameCommand.ts ×3
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 { CancellationToken } from '../../../base/common/cancellation.js';
7 > import { localize } from '../../../nls.js';
8 > import type { URI } from '../common/state/protocol/common/state.js';
9 > import { CompletionItem, CompletionItemKind, CompletionsParams } from '../common/state/protocol/commands.js';
10 > import { MessageAttachmentKind } from '../common/state/protocol/state.js';
11 > import { toCommandCompletionAttachmentMeta } from '../common/meta/agentCompletionAttachmentMeta.js';
12 > import { CompletionTriggerCharacter, IAgentHostCompletionItemProvider } from './agentHostCompletions.js';
13 > import { extractLeadingSlashToken, matchesSlashCompletion } from './agentHostSlashCompletion.js';
14 >
15 > /** The generic, agent-agnostic `/rename` slash command name. */
16 > export const RENAME_SLASH_COMMAND = 'rename';
17 >
18 > /**
19 > * Parses a leading `/rename [title]` command at the very start of `prompt`.
20 > *
21 > * Mirrors `parseLeadingSlashCommand` (the Copilot CLI slash parser): the
22 > * command must be `/rename`, followed either by end-of-input or at least one
23 > * whitespace character. `/renamed`, `/rename-foo`, or a leading-space
24 > * `/rename` all return `undefined`. Match is case-sensitive.
25 > *
26 > * Returns the trimmed new title (possibly an empty string when no title is
27 > * supplied) when the prompt is a rename command, or `undefined` when it is not.
28 > * Callers MUST distinguish "not a rename command" (`undefined`) from "rename
29 > * with empty title" (`''`).
30 > */
31 > export function parseRenameCommand(prompt: string): string | undefined {
32 > const match = /^\/rename(?:$|\s+([\s\S]*))/.exec(prompt); agentHostRenameCommand.ts ×2
33 > if (!match) {
34 > return undefined; agentHostRenameCommand.ts ×1
35 > }
36 > return (match[1] ?? '').trim(); agentHostRenameCommand.ts ×2
37 > }
39 > /**
40 > * Generic completion provider that contributes the `/rename` slash command
41 > * for every agent-host session type. Unlike agent-specific slash commands
42 > * (e.g. Copilot's `/compact`), `/rename` is not forwarded to any agent SDK;
43 > * it is intercepted in the agent-host send path and redirected to a
44 > * `SessionTitleChanged` action (see the rename handling in `AgentSideEffects`).
45 > *
46 > * The completion is only offered for sessions that already have history —
47 > * renaming a session before the first turn has no meaningful target.
48 > */
49 > export class AgentHostRenameCompletionProvider implements IAgentHostCompletionItemProvider {
50 > readonly kinds: ReadonlySet<CompletionItemKind> = new Set([CompletionItemKind.UserMessage]);
51 > readonly triggerCharacters = [CompletionTriggerCharacter.Slash] as const;
52 >
53 > constructor(private readonly _hasHistory: (session: URI) => boolean) { }
54 >
55 > async provideCompletionItems(params: CompletionsParams, _token: CancellationToken): Promise<readonly CompletionItem[]> {
56 > const leading = extractLeadingSlashToken(params.text, params.offset); agentHostRenameCommand.ts ×2
57 > if (!leading) {
59 > }
60 > if (!this._hasHistory(params.channel)) { agentHostRenameCommand.ts ×1
62 > }
63 > // `/abc` → typed = 'abc'; empty after just '/' → typed = ''. agentHostRenameCommand.ts ×1
64 > const typed = leading.typed;
65 > if (!matchesSlashCompletion(typed, RENAME_SLASH_COMMAND)) {
67 > }
69 > insertText: '/' + RENAME_SLASH_COMMAND + ' ',
70 > rangeStart: leading.rangeStart,
71 > rangeEnd: leading.rangeEnd,
72 > attachment: {
73 > type: MessageAttachmentKind.Simple,
74 > label: '/' + RENAME_SLASH_COMMAND,
75 > _meta: toCommandCompletionAttachmentMeta({
76 > command: RENAME_SLASH_COMMAND,
77 > description: localize('agentHostSlashCommand.rename.description', "Rename this chat"),
78 > }),
79 > },
80 > }];