src/vs/platform/agentHost/node/localCommands/renameLocalCommand.ts

70 LOC · 67 covered · 3 uncovered · 15 ranges · 1049 concepts · 7 introducers · 506 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 > /*--------------------------------------------------------------------------------------------- agentSideEffects.ts ×51
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 { Disposable } from '../../../../base/common/lifecycle.js';
7 > import { generateUuid } from '../../../../base/common/uuid.js';
8 > import { localize } from '../../../../nls.js';
9 > import { ActionType } from '../../common/state/sessionActions.js';
10 > import { isAhpChatChannel, isDefaultChatUri, parseRequiredSessionUriFromChatUri, ResponsePartKind, type URI as ProtocolURI } from '../../common/state/sessionState.js';
11 > import { parseRenameCommand } from '../agentHostRenameCommand.js';
12 > import { ILocalChatCommand, ILocalChatCommandContext, ILocalChatCommandHandling, ILocalChatCommandRequest, LocalChatCommandRegistry } from './localChatCommand.js';
13 >
14 > /**
15 > * The generic `/rename [title]` command: renames the session (or an individual
16 > * peer chat) instead of forwarding the message to the agent SDK. Intercepted
17 > * for every agent-host session type.
18 > */
19 > export class RenameLocalCommand extends Disposable implements ILocalChatCommand {
20 >
21 > readonly name = 'rename';
22 > readonly recordsLocalTurn = true;
23 >
24 > constructor(private readonly _context: ILocalChatCommandContext) {
25 > super(); agentSideEffects.ts ×6
26 > }
28 > tryHandle(request: ILocalChatCommandRequest): ILocalChatCommandHandling | undefined {
29 > const title = parseRenameCommand(request.text); localChatCommand.ts ×3
30 > if (title === undefined) {
31 > return undefined; bangLocalCommand.ts ×2
32 > }
33 > return { run: async () => this._run(request.turnChannel, request.turnId, title), suggestedTitle: title }; renameLocalCommand.ts ×4
36 > private _run(channel: ProtocolURI, turnId: string, title: string): void {
37 > if (title.length === 0) { renameLocalCommand.ts ×4
38 > // `/rename` with no title: nothing to change; the dispatcher still agentHostSessionTitleController.ts ×1
39 > // completes the turn.
40 > return;
41 > }
42 > const isAdditional = (uri: ProtocolURI): boolean => isAhpChatChannel(uri) && !isDefaultChatUri(uri); renameLocalCommand.ts ×2
43 > const chatTarget = isAdditional(channel) ? channel : undefined; renameLocalCommand.ts ×4
44 > const sessionChannel = isAhpChatChannel(channel) ? parseRequiredSessionUriFromChatUri(channel) : channel;
45 > if (chatTarget) {
46 // Rename only this chat, independently of the session title.
47 this._context.updateChatTitle(sessionChannel, chatTarget, title);
48 this._context.persistSessionFlag(sessionChannel, `customChatTitle:${chatTarget}`, title);
50 > this._context.dispatch(sessionChannel, { type: ActionType.SessionTitleChanged, title });
51 > // Server-dispatched actions bypass `handleAction`, so persist the
52 > // new title here directly (the client-dispatched rename path relies
53 > // on the `SessionTitleChanged` case in `handleAction` instead).
54 > this._context.persistSessionFlag(sessionChannel, 'customTitle', title);
55 > }
56 > // Acknowledge the rename with a brief response so the turn has visible
57 > // content in the transcript.
58 > this._context.dispatch(channel, {
59 > type: ActionType.ChatResponsePart,
60 > turnId,
61 > part: {
62 > kind: ResponsePartKind.Markdown,
63 > id: generateUuid(),
64 > content: localize('agentHostRename.renamed', "Renamed: {0}", title),
65 > },
66 > });
69 >
70 > LocalChatCommandRegistry.register(RenameLocalCommand);