copilotAgentSession.ts ×23

Frontier kind: Code frontier

unlabeled · c_05edd6f91da9

259 tests · 43094 LOC · 242 files · introduces 0 tests · 128 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
25 ranges128 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3829 ranges43094 lines · 242 files · Browse complete extent
All tests (intent)
259 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.

2 files ranked by introduced lines: 128 introduced LOC across 25 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts 118 introduced LOC · 23 ranges

Open complete file

673
674 private get _storageUri(): URI {
675 > return isDefaultChatUri(this._chatChannelUri) ? this.sessionUri : this._chatChannelUri; copilotAgentSession.ts
676 > }
677
678 /**
722
723 constructor(
724 > options: ICopilotAgentSessionOptions, copilotAgentSession.ts
725 > @IInstantiationService private readonly _instantiationService: IInstantiationService,
726 > @ILogService private readonly _logService: ILogService,
727 > @ISessionDataService sessionDataService: ISessionDataService,
728 > @IFileService private readonly _fileService: IFileService,
729 > @INativeEnvironmentService private readonly _environmentService: INativeEnvironmentService,
730 > @IAgentConfigurationService private readonly _configurationService: IAgentConfigurationService,
731 > @IAgentHostStateManager private readonly _stateManager: AgentHostStateManager,
732 > @ITelemetryService private readonly _telemetryService: ITelemetryService,
733 > @ICopilotApiService private readonly _copilotApiService: ICopilotApiService,
734 > ) {
735 > super();
736 > this.sessionId = options.rawSessionId;
737 > this.sessionUri = options.sessionUri;
738 > this._slashCommandProvider = new CopilotSlashCommandProvider(() => this._wrapper.session.rpc.commands.list({ includeBuiltins: true, includeSkills: true, includeClientCommands: true }).then(c => c.commands), this._logService);
739 > this._chatChannelUri = options.chatChannelUri;
740 > this._onDidSessionProgress = options.onDidSessionProgress;
741 > this._sessionLauncher = options.sessionLauncher;
742 > this._launchPlan = options.launchPlan;
743 > this._isLaunchTokenStillCurrent = options.isLaunchTokenCurrent ?? (() => true);
744 > this._shellManager = options.shellManager;
745 > this._nonPtyShellTerminals = this._register(this._instantiationService.createInstance(NonPtyShellTerminalStreams, options.sessionUri));
746 > this._workingDirectory = options.workingDirectory;
747 > this._customizationDirectory = options.customizationDirectory;
748 > this._serverToolHost = options.serverToolHost;
749 > this._platform = options.platform ?? process.platform;
750 > this._telemetryReporter = new AgentHostTelemetryReporter(this._telemetryService);
751 > this._repoInfoTelemetry = this._register(this._instantiationService.createInstance(AgentHostRepoInfoTelemetry, this._telemetryReporter));
752 >
753 > this._appliedSnapshot = options.clientSnapshot ?? { tools: [], plugins: [], mcpServers: {} };
754 > this._clientToolNames = clientToolNamesFromSnapshot(this._appliedSnapshot);
755 > const model = this._launchPlan.kind === 'create' ? this._launchPlan.model : this._launchPlan.fallback.model;
756 > // Capability decisions use the family-aliased selection so an aliased
757 > // preview model agrees with the launcher's tool-search gating (which
758 > // also aliases before checking); the wire model id is unaffected.
759 > const effectiveModel = applyModelFamilyAlias(model, this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.ModelCapabilityOverrides));
760 > this._toolSearchActive = this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.ToolSearchEnabled) === true
761 && agentHostModelSupportsToolSearch(effectiveModel?.id)
762 && this._clientToolNames.has(CLIENT_TOOL_SEARCH_REFERENCE_NAME);
763 > // Share the agent's live ActiveClientToolSet when provided so client copilotAgentSession.ts
764 > // contributions (and owner identity) are observed at stamp time.
765 > // Standalone / test construction uses a fresh empty registry, which
766 > // leaves client tool calls unstamped (no owning client).
767 > this._activeClientToolSet = options.activeClientToolSet ?? new ActiveClientToolSet();
768 >
769 > this._databaseRef = sessionDataService.openDatabase(this._storageUri);
770 > this._register(toDisposable(() => this._databaseRef.dispose()));
771 > this._sessionDataDir = sessionDataService.getSessionDataDir(this._storageUri);
772 >
773 > this._editTracker = this._instantiationService.createInstance(FileEditTracker, this._storageUri.toString(), this._databaseRef.object);
774 >
775 > this._mcpCustomizations = this._register(this._instantiationService.createInstance(McpCustomizationController, {
776 > providerId: this.sessionUri.scheme,
777 > sessionId: this.sessionId,
778 > sessionUri: this.sessionUri,
779 > resolveChildId: options.resolveMcpChildId,
780 > emit: action => this._emitAction(action),
781 > }));
782 >
783 > this._register(toDisposable(() => this._denyPendingPermissions()));
784 > this._register(toDisposable(() => this._shellManager?.dispose()));
785 > this._register(toDisposable(() => this._cancelPendingUserInputs()));
786 > this._register(toDisposable(() => this._cancelPendingElicitations()));
787 > this._register(toDisposable(() => this._cancelPendingPlanReviews()));
788 > this._register(toDisposable(() => this._drainPendingSteeringFlips()));
789 > this._register(toDisposable(() => this._cancelPendingMcpSamplings()));
790 > this._register(toDisposable(() => this._cancelPendingMcpAuthRequests()));
791 >
792 > // When a shell tool associates a terminal with a tool call, fire a
793 > // tool_content_changed event so the UI can connect to the terminal
794 > // while the command is still running.
795 > if (this._shellManager) {
796 this._register(this._shellManager.onDidAssociateTerminal(({ toolCallId, terminalUri, displayName }) => {
797 const tracked = this._activeToolCalls.get(toolCallId);
814 }));
815 }
816 > this._register(toDisposable(() => this._cancelPendingClientToolCalls())); copilotAgentSession.ts
817 > this._register(toDisposable(() => {
818 > for (const pending of this._pendingAutoApprovals.values()) {
819 pending.complete(undefined);
820 }
821 > this._pendingAutoApprovals.clear(); copilotAgentSession.ts
822 > }));
823 > }
824
825 // ---- AgentSignal helpers ------------------------------------------------
890 */
891 private _drainPendingSteeringFlips(): void {
892 > if (this._pendingSteeringFlips.size === 0) { copilotAgentSession.ts
893 return;
894 }
1292 */
1293 async initializeSession(): Promise<void> {
1294 > const wrapper = await this._sessionLauncher.launch(this._launchPlan, this._createRuntimeAdapter()); copilotAgentSession.ts
1295 // The session may have been disposed while we were awaiting the
1296 // launcher. If so, dispose the freshly-created wrapper and
1310 // see them as server-provided. Execution happens in-process via the SDK
1311 // tool handlers built in `_createServerSdkTools`.
1312 > this._serverToolHost?.advertise(this._storageUri.toString()); copilotAgentSession.ts
1313 > }
1314
1315 private _setPromptCacheState(promptCache: { readonly modelId: string; readonly cacheExpiresAt: string } | undefined): void {
1319
1320 private _createRuntimeAdapter(): ICopilotSessionRuntime {
1321 > return { copilotAgentSession.ts
1322 > handlePermissionRequest: request => this._handlePermissionRequest(request),
1323 > handleExitPlanModeRequest: (request, invocation) => this._handleExitPlanModeRequest(request, invocation),
1324 > handleUserInputRequest: (request, invocation) => this._handleUserInputRequest(request, invocation),
1325 > handleElicitationRequest: context => this._handleElicitationRequest(context),
1326 > handleMcpAuthRequest: request => this._handleMcpAuthRequest(request),
1327 > requestUnsandboxedCommandConfirmation: request => this._requestUnsandboxedCommandConfirmation(request),
1328 > createClientSdkTools: () => this._createClientSdkTools(),
1329 > createServerSdkTools: () => this._createServerSdkTools(),
1330 > handlePreToolUse: input => this._handlePreToolUse(input),
1331 > handlePostToolUse: input => this._handlePostToolUse(input),
1332 > };
1333 > }
1334
1335 async resolveMcpAuthentication(params: AuthenticateParams): Promise<boolean> {
1481
1482 private _cancelPendingMcpAuthRequests(): void {
1483 > for (const pending of this._pendingMcpAuthRequests.values()) { copilotAgentSession.ts
1484 pending.deferred.complete({ kind: 'cancelled' });
1485 }
1486 > this._pendingMcpAuthRequests.clear(); copilotAgentSession.ts
1487 > }
1488
1489 private _cancelPendingMcpAuthRequestsForServer(serverName: string): void {
4545
4546 private _denyPendingPermissions(): void {
4547 > for (const [toolCallId, deferred] of this._pendingPermissions) { copilotAgentSession.ts
4548 this._deletePendingEditContent(toolCallId);
4549 deferred.complete({ kind: 'reject' });
4550 }
4551 > this._pendingPermissions.clear(); copilotAgentSession.ts
4552 > this._approvedDuplicablePermissionSignatures.clear();
4553 > }
4554
4555 /**
4569
4570 private _cancelPendingUserInputs(): void {
4571 > for (const [, pending] of this._pendingUserInputs) { copilotAgentSession.ts
4572 pending.deferred.complete({ response: ChatInputResponseKind.Cancel });
4573 }
4574 > this._pendingUserInputs.clear(); copilotAgentSession.ts
4575 > }
4576
4577 private _cancelPendingElicitations(): void {
4578 > for (const [, pending] of this._pendingElicitations) { copilotAgentSession.ts
4579 pending.deferred.complete({ response: ChatInputResponseKind.Cancel });
4580 }
4581 > this._pendingElicitations.clear(); copilotAgentSession.ts
4582 > }
4583
4584 private _cancelPendingPlanReviews(): void {
4585 > for (const [, pending] of this._pendingPlanReviews) { copilotAgentSession.ts
4586 pending.deferred.complete({ approved: false });
4587 }
4588 > this._pendingPlanReviews.clear(); copilotAgentSession.ts
4589 > }
4590
4591 private _cancelPendingMcpSamplings(): void {
4592 > const pending = Array.from(this._pendingMcpSamplings); copilotAgentSession.ts
4593 > this._pendingMcpSamplings.clear();
4594 > for (const requestId of pending) {
4595 this._wrapper.session.rpc.mcp.cancelSamplingExecution({ requestId }).catch(() => {
4596 // Best-effort: SDK may have already torn down.
4597 });
4598 }
4600
4601 private _cancelPendingClientToolCalls(): void {
4602 > this._pendingClientToolCalls.denyAll({ textResultForLlm: 'Tool call cancelled: session ended', resultType: 'failure', error: 'Session ended' }); copilotAgentSession.ts
4603 > }
4604 }
4605
src/vs/platform/agentHost/node/copilot/copilotNonPtyShellTerminals.ts 10 introduced LOC · 2 ranges

Open complete file

70
71 constructor(
72 > private readonly _sessionUri: URI, copilotNonPtyShellTerminals.ts
73 > @IAgentHostTerminalManager private readonly _terminalManager: IAgentHostTerminalManager,
74 > ) {
75 > super();
76 >
77 > this._register(toDisposable(() => {
78 > for (const stream of this._streams.values()) {
79 if (stream.created) {
80 this._terminalManager.disposeTerminal(stream.uri);
81 }
82 }
83 > this._streams.clear(); copilotNonPtyShellTerminals.ts
84 > }));
85 > }
86
87 /**