copilotAgent.ts ×12

Frontier kind: Code frontier

unlabeled · c_2ef297676c12

7 tests · 52716 LOC · 300 files · introduces 0 tests · 60 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges60 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5281 ranges52716 lines · 300 files · Browse complete extent
All tests (intent)
7 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: 60 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/copilotAgent.ts 60 introduced LOC · 12 ranges

Open complete file

1612 */
1613 private _ensureEntry(sessionId: string): CopilotSessionEntry {
1614 > let entry = this._sessions.get(sessionId); copilotAgent.ts
1615 > if (!entry) {
1616 entry = new CopilotSessionEntry();
1617 this._sessions.set(sessionId, entry);
1618 }
1619 > return entry; copilotAgent.ts
1620 > }
1621
1622 /**
2341 return;
2342 }
2343 > const parsed = parseChatUri(chat); copilotAgent.ts
2344 > if (!parsed) {
2345 throw new Error(`[Copilot] createChat: malformed chat URI ${chat.toString()}`);
2346 }
2347 > const session = URI.parse(parsed.session); copilotAgent.ts
2348 > const chatKey = chat.toString();
2349 if (this._sessions.get(AgentSession.id(session))?.hasPeerChat(chatKey)) {
2350 // Already live: hand back the existing backing so the orchestrator
2353 return existing ? { providerData: encodeProviderData(existing), backingSession: AgentSession.uri(this.id, existing.sdkSessionId) } : undefined;
2354 }
2355 > const sessionId = AgentSession.id(session); copilotAgent.ts
2356 > let result: IAgentCreateChatResult | undefined;
2357 const queueKey = options?.sideChat ? chatKey : sessionId;
2358 await this._sessionSequencer.queue(queueKey, async () => {
2359 > // Re-check inside the per-session sequencer: the outer `has` check copilotAgent.ts
2360 > // above is only a fast early-out. If two `createChat` calls for the
2361 > // same chat URI race, both can pass that outer check; the sequencer
2362 > // serializes them, so the second task must re-check here to avoid
2363 > // overwriting (and disposing) the chat the first one set.
2364 > if (this._sessions.get(sessionId)?.hasPeerChat(chatKey)) {
2365 const existing = this._chatBackings.get(chatKey);
2366 result = existing ? { providerData: encodeProviderData(existing), backingSession: AgentSession.uri(this.id, existing.sdkSessionId) } : undefined;
2367 return;
2368 }
2369 > const model = options?.model; copilotAgent.ts
2370 > // Resolve the owning session so the new chat inherits its working
2371 > // directory scope. The parent may be provisional (no SDK session
2372 > // yet); in that case use its provisional working directory.
2373 > const parentEntry = this._findAnySession(sessionId);
2374 > const workingDirectory = parentEntry?.workingDirectory
2375 > ?? this._provisionalSessions.get(sessionId)?.workingDirectory;
2376 > const client = await this._ensureClient();
2377 > const chatSdkId = generateUuid();
2378 > // Peer chats share the owning session's ActiveClient so that
2379 > // client tool / customization updates (which are keyed by the
2380 > // session URI via the active-client handles) reach the additional
2381 > // chat's SDK chat. Keying it by the chat URI instead would
2382 > // snapshot empty/stale tools and never see subsequent updates, and
2383 > // would also leak (nothing disposes a chat-keyed ActiveClient).
2384 > const activeClient = this._getOrCreateActiveClient(session, workingDirectory);
2385 > const snapshot = await activeClient.snapshot();
2386 > const shellManager = this._instantiationService.createInstance(ShellManager, chat, workingDirectory);
2387 >
2388 > // Forking: mint the new chat's backing chat by forking the
2389 > // source chat's SDK session at the requested turn (copying its
2390 > // database into the new chat's data dir), then resume it. Otherwise
2391 > // spin up a fresh empty chat.
2392 > let launchPlan: CopilotSessionLaunchPlan;
2393 > let sdkSessionId: string;
2394 > let sideChat: IPersistedChat['sideChat'];
2395 > if (options?.fork) {
2396 if (!workingDirectory) {
2397 throw new Error(`[Copilot] createChat fork: missing working directory for session ${session.toString()}`);
2415 fallback: { model, longContextWindow: this._longContextWindowFor(model?.id), freeLongContext: this._isFreeLongContext(model?.id) },
2416 };
2417 > } else if (options?.sideChat) { copilotAgent.ts
2418 if (!workingDirectory) {
2419 throw new Error(`[Copilot] createChat side chat: missing working directory for session ${session.toString()}`);
2463 };
2464 }
2465 > let agentSession: CopilotAgentSession | undefined; copilotAgent.ts
2466 > try {
2467 > agentSession = this._createAgentSession(launchPlan, workingDirectory, activeClient, { sessionUri: session, chatChannelUri: chat });
2468 > await agentSession.initializeSession();
2469 > if (sideChat) {
2470 sideChat = { ...sideChat, inheritedTurnCount: (await agentSession.getMessages()).length };
2471 }
2472 > if (options?.fork?.turnIdMapping) { copilotAgent.ts
2473 await agentSession.remapTurnIds(options.fork.turnIdMapping);
2474 }
2475 > this._ensureEntry(sessionId).registerPeerChat(chatKey, new CopilotSessionEntry(agentSession)); copilotAgent.ts
2476 > // Record the live backing and hand the opaque blob back to the
2477 > // orchestrator to persist. The agent no longer owns a durable
2478 > // peer-chat catalog (`copilot.chats` is no longer written).
2479 > const backing: IPersistedChat = { sdkSessionId, ...(model ? { model } : {}), ...(sideChat ? { sideChat } : {}) };
2480 > this._chatBackings.set(chatKey, backing);
2481 > result = { providerData: encodeProviderData(backing), backingSession: AgentSession.uri(this.id, sdkSessionId) };
2482 > this._logService.info(`[Copilot] Created additional chat ${chatKey} in session ${session.toString()}${options?.fork ? ' (forked)' : ''}`);
2483 > } catch (error) {
2484 agentSession?.dispose();
2485 throw error;
2486 }
2487 });
2488 > return result; copilotAgent.ts
2489 }
2490