copilotSessionLauncher.ts ×9

Frontier kind: Code frontier

unlabeled · c_ed18c4327fec

29 tests · 30643 LOC · 151 files · introduces 0 tests · 110 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges110 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2631 ranges30643 lines · 151 files · Browse complete extent
All tests (intent)
29 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.

3 files ranked by introduced lines: 110 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts 93 introduced LOC · 9 ranges

Open complete file

379
380 async launch(plan: CopilotSessionLaunchPlan, runtime: ICopilotSessionRuntime): Promise<CopilotSessionWrapper> {
381 > const config = await this._buildSessionConfig(plan, runtime); copilotSessionLauncher.ts
382 > const sandboxConfig = this._computeSandboxConfig();
383 > if (plan.kind === 'create') {
384 return this._createSession(plan, config, sandboxConfig);
385 }
430 return wrapper;
431 }
433
434 private async _createSession(plan: ICopilotCreateSessionLaunchPlan, config: CopilotSessionLaunchConfig, sandboxConfig: ISdkSandboxConfig | undefined): Promise<CopilotSessionWrapper> {
460 */
461 private _computeSandboxConfig(): ISdkSandboxConfig | undefined {
462 > const enableCustomTerminalTool = this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.EnableCustomTerminalTool) === true; copilotSessionLauncher.ts
463 > if (enableCustomTerminalTool) {
464 return undefined;
465 }
466 > return buildSandboxConfigForSdk(process.platform, this._configurationService.getRootValue(sandboxConfigSchema, AgentHostSandboxConfigKey.Sandbox)); copilotSessionLauncher.ts
467 > }
468
469 /**
528
529 private async _buildSessionConfig(plan: CopilotSessionLaunchPlan, runtime: ICopilotSessionRuntime): Promise<CopilotSessionLaunchConfig> {
530 > const plugins = plan.snapshot.plugins; copilotSessionLauncher.ts
531 > // Synthesize BYOK provider/model config (empty when BYOK is gated off or the
532 > // renderer reports no BYOK models), merged into the returned config so both
533 > // createSession and resumeSession advertise the models to the runtime.
534 > const byok = await this._resolveByokSessionConfig(plan.sessionId);
535 > const enableCustomTerminalTool = this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.EnableCustomTerminalTool) === true;
536 > let shellTools: Awaited<ReturnType<typeof createShellTools>> = [];
537 > if (enableCustomTerminalTool) {
538 if (!plan.shellManager) {
539 throw new Error(`ShellManager is required to launch Copilot session '${plan.sessionId}'`);
541 shellTools = await createShellTools(plan.shellManager, this._terminalManager, this._logService, request => runtime.requestUnsandboxedCommandConfirmation(request));
542 }
543 > // Rely on the SDK to discover most agents/skills/etc. from `pluginDirectories` copilotSessionLauncher.ts
544 > // instead of feeding them explicitly, to avoid duplicates. Custom agents are the
545 > // exception: the SDK validates the session-start `agent:` against `customAgents`
546 > // by name, so the selected agent is force-included (see `toSdkSessionCustomAgents`).
547 > const pluginsWithoutDirs = plugins.filter(p => !p.pluginDir || p.pluginDir.scheme !== Schemas.file);
548 > const customAgents = await toSdkSessionCustomAgents(plugins, plan.resolvedAgentName, this._fileService);
549 > const skillDirectories = toSdkSkillDirectories(pluginsWithoutDirs.flatMap(p => p.skills));
550 > const instructionDirectories = toSdkInstructionDirectories(plugins.flatMap(p => p.instructions));
551 > const model = plan.kind === 'create' ? plan.model : plan.fallback.model;
552 > const clientToolNames = clientToolNamesFromSnapshot(plan.snapshot);
553 > // Prompt routing and capability decisions use the family-aliased
554 > // selection; the wire model id in _createSession comes from plan.model
555 > // and is unaffected.
556 > const effectiveModel = applyModelFamilyAlias(model, this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.ModelCapabilityOverrides));
557 > if (model && effectiveModel !== model) {
558 this._logService.info(`[Copilot:${plan.sessionId}] Model capability override: routing prompt for '${model.id}' as family '${effectiveModel?.id}'`);
559 }
560 > const toolSearchActive = this._configurationService.getRootValue(copilotCliConfigSchema, CopilotCliConfigKey.ToolSearchEnabled) === true copilotSessionLauncher.ts
561 && agentHostModelSupportsToolSearch(effectiveModel?.id)
562 && clientToolNames.has(CLIENT_TOOL_SEARCH_REFERENCE_NAME);
563 > const promptContext: IAgentHostPromptContext = { copilotSessionLauncher.ts
564 > getSetting: key => this._configurationService.getRootValue(copilotCliConfigSchema, key),
565 > hasClientTool: name => clientToolNames.has(name),
566 > workspaceless: plan.workspaceless === true,
567 > toolSearchActive,
568 > };
569 > // Resolved once per (re)launch — the SDK has no mid-session system-message
570 > // update, so this reflects the model/tools/settings at launch time. Log a
571 > // summary at info for prompt observability; the full config at trace.
572 > const systemMessage = agentHostPromptRegistry.resolveSystemMessageConfig(effectiveModel, promptContext);
573 > this._logService.info(`[Copilot:${plan.sessionId}] Resolved system message: ${describeSystemMessageConfig(systemMessage)}`);
574 > if (this._logService.getLevel() <= LogLevel.Trace) {
575 // Guarded: a `replace`-mode prompt's content can be multiple KB, so only
576 // serialize it when trace output is actually emitted.
577 this._logService.trace(`[Copilot:${plan.sessionId}] System message config: ${JSON.stringify(systemMessage, (_key, value) => typeof value === 'function' ? '[transform fn]' : value)}`);
578 }
579 > return { copilotSessionLauncher.ts
580 > ...byok,
581 > clientName: AGENT_HOST_COPILOT_CLIENT_NAME,
582 > enableMcpApps: true,
583 > enableFileHooks: true,
584 > enableConfigDiscovery: true,
585 > requestExtensions: false, // force-disable copilot extension management tools (otherwise enabled in experimental mode)
586 > onPermissionRequest: request => runtime.handlePermissionRequest(request),
587 > onUserInputRequest: (request, invocation) => runtime.handleUserInputRequest(request, invocation),
588 > onElicitationRequest: context => runtime.handleElicitationRequest(context),
589 > onMcpAuthRequest: (request, context) => runtime.handleMcpAuthRequest(request, context),
590 > hooks: toSdkHooks(pluginsWithoutDirs.flatMap(p => p.hooks), {
591 > onPreToolUse: input => runtime.handlePreToolUse(input),
592 > onPostToolUse: input => runtime.handlePostToolUse(input),
593 > }),
594 > mcpServers: { ...toSdkMcpServersFromConfigMap(plan.snapshot.mcpServers), ...toSdkMcpServers(pluginsWithoutDirs.flatMap(p => p.mcpServers)) },
595 > onExitPlanModeRequest: (request, invocation) => runtime.handleExitPlanModeRequest(request, invocation),
596 > workingDirectory: plan.workingDirectory?.fsPath,
597 > customAgents,
598 > agent: plan.resolvedAgentName,
599 > skillDirectories,
600 > instructionDirectories,
601 > systemMessage,
602 > toolSearch: toolSearchActive ? { enabled: true, deferThreshold: 1 } : { enabled: false },
603 > pluginDirectories: coalesce(plugins.map(p => p.pluginDir))
604 > .filter(d => d.scheme === Schemas.file).map(d => d.fsPath),
605 > tools: [...shellTools, ...runtime.createClientSdkTools(), ...runtime.createServerSdkTools()],
606 > // Pass the GitHub token at the session level. The SDK's
607 > // client-level `gitHubToken` authenticates the CLI process,
608 > // but each session also needs its own token resolved into a
609 > // GitHub identity (login, Copilot plan, endpoints) to drive
610 > // model routing and quota — without this the session
611 > // errors with "Session was not created with authentication
612 > // info or custom provider" on first send. See #318693.
613 > gitHubToken: plan.githubToken,
614 > // Enable infinite sessions so the SDK provisions a workspace
615 > // directory (containing `plan.md`, `checkpoints/`, `files/`).
616 > // The workspace is required for plan mode to work — without
617 > // it, `rpc.plan.read()` returns `path: null` and the SDK
618 > // never emits `exit_plan_mode.requested`.
619 > infiniteSessions: { enabled: true },
620 > // Per-session remote export: the client-level `--remote` flag
621 > // (enableRemoteSessions) enables the CLI capability, but each
622 > // session must opt in via `remoteSession` to actually export
623 > // events. Without this, sessions default to "off".
624 > remoteSession: this._configurationService.getRootValue(platformRootSchema, AgentHostSessionSyncEnabledConfigKey) === true ? 'export' : undefined,
625 > enableManagedSettings: true,
626 > };
627 > }
628 }
src/vs/platform/agentHost/node/copilot/prompts/systemMessage.ts 13 introduced LOC · 2 ranges

Open complete file

101 */
102 export function describeSystemMessageConfig(config: SystemMessageConfig): string {
103 > if (config.mode === 'replace') { systemMessage.ts
104 return `mode=replace (content length ${config.content.length})`;
105 }
106 > if (config.mode === 'customize') { systemMessage.ts
107 > const parts = Object.entries(config.sections ?? {}).map(([name, override]) => {
108 > const action = override?.action;
109 > return `${name}:${typeof action === 'function' ? 'transform' : action}`;
110 > });
111 > // The customize convenience `content` is appended after all sections; note
112 > // it so the summary doesn't understate what was sent.
113 > const content = config.content ? ` +content(length ${config.content.length})` : '';
114 > return `mode=customize sections=[${parts.join(', ')}]${content}`;
115 > }
116 > return `mode=append (content length ${config.content?.length ?? 0})`;
117 > }
src/vs/platform/agentHost/node/copilot/copilotPluginConverters.ts 4 introduced LOC · 2 ranges

Open complete file

50 */
51 export function toSdkMcpServersFromConfigMap(servers: Record<string, unknown>): Record<string, MCPServerConfig> {
52 > const result: Record<string, MCPServerConfig> = {}; copilotPluginConverters.ts
53 > for (const [name, config] of Object.entries(servers)) {
54 if (isSupportedMcpServerConfiguration(config)) {
55 result[name] = toSdkMcpServer(name, config);
56 }
57 }
58 > return result; copilotPluginConverters.ts
59 > }
60
61 /**