agentService.ts ×17

Frontier kind: Code frontier

unlabeled · c_b42d6f528f20

45 tests · 49909 LOC · 290 files · introduces 0 tests · 65 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges65 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5105 ranges49909 lines · 290 files · Browse complete extent
All tests (intent)
45 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: 65 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentService.ts 65 introduced LOC · 17 ranges

Open complete file

2382
2383 async restoreSession(session: URI): Promise<void> {
2384 > const sessionStr = session.toString(); agentService.ts
2385 >
2386 > // Already in state manager - nothing to do.
2387 > if (this._stateManager.getSessionState(sessionStr)) {
2388 return;
2389 }
2391 > const inFlight = this._restoreSessionInFlight.get(sessionStr);
2392 > if (inFlight) {
2393 return inFlight;
2394 }
2396 > const restore = this._doRestoreSession(session, sessionStr);
2397 > this._restoreSessionInFlight.set(sessionStr, restore);
2398 > try {
2399 > await restore;
2400 > } finally {
2401 > if (this._restoreSessionInFlight.get(sessionStr) === restore) {
2402 > this._restoreSessionInFlight.delete(sessionStr);
2403 > }
2404 > }
2405 > }
2406
2407 private async _doRestoreSession(session: URI, sessionStr: string): Promise<void> {
2408 > if (this._stateManager.getSessionState(sessionStr)) { agentService.ts
2409 return;
2410 }
2412 > const agent = this._findProviderForSession(session);
2413 > if (!agent) {
2414 throw new ProtocolError(AHP_SESSION_NOT_FOUND, `No agent for session: ${sessionStr}`);
2415 }
2417 > const meta = await this._getSessionMetadataForRestore(agent, session);
2418 > if (!meta) {
2419 throw new ProtocolError(AHP_SESSION_NOT_FOUND, `Session not found on backend: ${sessionStr}`);
2420 }
2434 // Check for persisted metadata in the session database
2435 let title = meta.summary ?? 'Session';
2436 > let isRead: boolean | undefined; agentService.ts
2437 > let isArchived: boolean | undefined;
2438 > let persistedConfigValues: Record<string, string> | undefined;
2439 > let changes: ChangesSummary | undefined;
2440 > let gitMetadata: Record<string, string | undefined> | undefined;
2441 > let changesetMetadata: Record<string, string | undefined> | undefined;
2442 > let sessionMetadata: Record<string, unknown> | undefined;
2443 > const ref = this._sessionDataService.tryOpenDatabase?.(session);
2444 > if (ref) {
2445 try {
2446 const db = await ref;
2537 createdAt: new Date(meta.startTime).toISOString(),
2538 modifiedAt: new Date(meta.modifiedTime).toISOString(),
2539 > ...(meta.project ? { project: { uri: meta.project.uri.toString(), displayName: meta.project.displayName } } : {}), agentService.ts
2540 > changes: meta.changes ?? changes,
2541 > workingDirectories: meta.workingDirectory ? [meta.workingDirectory.toString()] : undefined,
2542 > _meta: (sessionMetadata || meta._meta) ? { ...(meta._meta ?? {}), ...(sessionMetadata ?? {}) } : undefined,
2543 > };
2544 >
2545 > const [defaultDraft, defaultChatTitle] = await Promise.all([
2546 > this._getChatDraft(session, defaultChatUri),
2547 > this._readPersistedChatTitle(session, defaultChatUri),
2548 > ]);
2549 const mergedTurns = await this._interleaveLocalTurns(sessionStr, defaultChatUri.toString(), turns);
2550 this._stateManager.restoreSession(summary, mergedTurns, { draft: defaultDraft, defaultChatTitle });
2585 // chat-view); now that `summary.workingDirectory` is populated,
2586 // re-triggering the refresh dispatches to the compute path.
2587 > this._changesetCoordinator.onSessionRestored(sessionStr, changesetMetadata ?? {}); agentService.ts
2588 >
2589 > // Restore persisted `_meta` (e.g. git state) onto the new session
2590 > // state. This dispatches a SessionMetaChanged action.
2591 > if (meta._meta) {
2592 this._stateManager.setSessionMeta(sessionStr, meta._meta);
2593 }
2609 })
2610 : Promise.resolve(undefined),
2611 > ...promises agentService.ts
2612 > ]);
2613 if (restoredConfig) {
2614 this._stateManager.setSessionConfig(sessionStr, restoredConfig);
2617 // snapshot after selecting an existing session contains effective
2618 // instructions/agents without waiting for a follow-up republish.
2619 > if (restoredCustomizations && restoredCustomizations.length > 0) { agentService.ts
2620 this._stateManager.setSessionCustomizations(sessionStr, restoredCustomizations);
2621 }
2628 // Check for a GitHub pull request associated with the session's branch.
2629 void this._gitStateService.attachSessionGitHubPullRequest(sessionStr);
2630 > } agentService.ts
2631
2632 /**
3040
3041 private async _getSessionMetadataForRestore(agent: IAgent, session: URI): Promise<IAgentSessionMetadata | undefined> {
3042 > const sessionStr = session.toString(); agentService.ts
3043 > if (agent.getSessionMetadata) {
3044 > try {
3045 > return await this._withWorktreeProject(session, await agent.getSessionMetadata(session));
3046 > } catch (err) {
3047 if (err instanceof ProtocolError) {
3048 throw err;
3058 }
3059 }
3060 > } agentService.ts
3061
3062 // Older providers only expose catalog enumeration. Keep the fallback so
3064 // blocking session open on a full catalog refresh.
3065 return this._withWorktreeProject(session, await this._getSessionMetadataFromCatalog(agent, session));
3066 > } agentService.ts
3067
3068 /**
3073 */
3074 private async _withWorktreeProject(session: URI, meta: IAgentSessionMetadata | undefined): Promise<IAgentSessionMetadata | undefined> {
3075 > if (!meta || !this._worktree) { agentService.ts
3076 > return meta;
3077 > }
3078 const project = await this._worktree.resolveWorktreeProject(session);
3079 > return project ? { ...meta, project } : meta; agentService.ts
3080 > }
3081
3082 private async _getSessionMetadataFromCatalog(agent: IAgent, session: URI): Promise<IAgentSessionMetadata | undefined> {