agentService.ts ×10

Frontier kind: Code frontier

unlabeled · c_803aa5070196

6 tests · 51957 LOC · 304 files · introduces 0 tests · 83 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges83 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5504 ranges51957 lines · 304 files · Browse complete extent
All tests (intent)
6 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: 83 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentService.ts 83 introduced LOC · 10 ranges

Open complete file

1872 const parsedSubagent = parseSubagentSessionUri(resource);
1873 if (parsedSubagent) {
1874 > await this._restoreSubagentSession(resourceStr, parsedSubagent.parentSession); agentService.ts
1875 } else {
1876 await this.restoreSession(resource);
3666 */
3667 private async _restoreSubagentSession(subagentUri: string, parentSession: URI): Promise<void> {
3668 > if (this._stateManager.getSessionState(subagentUri)) { agentService.ts
3669 return;
3670 }
3672 > const inFlight = this._restoreSubagentInFlight.get(subagentUri);
3673 > if (inFlight) {
3674 return inFlight;
3675 }
3677 > const restore = this._doRestoreSubagentSession(subagentUri, parentSession);
3678 > this._restoreSubagentInFlight.set(subagentUri, restore);
3679 > try {
3680 > await restore;
3681 > } finally {
3682 > if (this._restoreSubagentInFlight.get(subagentUri) === restore) {
3683 > this._restoreSubagentInFlight.delete(subagentUri);
3684 > }
3685 > }
3686 > }
3687
3688 private async _doRestoreSubagentSession(subagentUri: string, parentSession: URI): Promise<void> {
3689 > // Ensure the parent session is loaded first agentService.ts
3690 > const parentSessionKey = parentSession.toString();
3691 > if (!this._stateManager.getSessionState(parentSessionKey)) {
3692 try {
3693 await this.restoreSession(parentSession);
3697 }
3698 }
3700 > const parentState = this._stateManager.getSessionState(parentSessionKey);
3701 > if (!parentState) {
3702 return;
3703 }
3705 > // Search completed turns and active turn for the subagent content metadata
3706 > const allTurns = [...parentState.turns];
3707 > if (parentState.activeTurn) {
3708 allTurns.push(parentState.activeTurn as Turn);
3709 }
3711 > let subagentContent: ToolResultSubagentContent | undefined;
3712 > for (const turn of allTurns) {
3713 > for (const part of turn.responseParts) {
3714 > if (part.kind === ResponsePartKind.ToolCall) {
3715 > const tc = part.toolCall;
3716 > // Check both completed and running tool calls — running
3717 > // tool calls receive subagent content via ContentChanged
3718 > const content = tc.status === ToolCallStatus.Completed
3719 > ? tc.content
3720 : (tc.status === ToolCallStatus.Running ? tc.content : undefined);
3721 > if (content) { agentService.ts
3722 > for (const c of content) {
3723 > if (c.type === ToolResultContentType.Subagent && c.resource === subagentUri) {
3724 > subagentContent = c;
3725 > break;
3726 > }
3727 > }
3728 > }
3729 > }
3730 > }
3731 > if (subagentContent) {
3732 > break;
3733 > }
3734 > }
3735 >
3736 > // Load the subagent's turns from the agent (which knows how to
3737 > // extract them from the parent session's event log).
3738 > let childTurns: readonly Turn[] = [];
3739 > const agent = this._findProviderForSession(parentSession);
3740 > if (agent) {
3741 > try {
3742 > childTurns = await this._getChatMessages(agent, URI.parse(subagentUri));
3743 > } catch (err) {
3744 this._logService.warn(`[AgentService] Failed to load subagent turns for ${subagentUri}`, err);
3745 }
3746 > } agentService.ts
3747 >
3748 > // Use metadata from subagent content if available, otherwise synthesize
3749 > const title = subagentContent?.title ?? 'Subagent';
3750 >
3751 > const subagentNow = new Date().toISOString();
3752 > // Local turns for a subagent chat are persisted in the parent session's
3753 > // database (its chat URI resolves to the parent session), keyed by the
3754 > // subagent chat URI.
3755 > const mergedChildTurns = await this._interleaveLocalTurns(parentSession.toString(), subagentUri, childTurns);
3756 > this._stateManager.restoreSession(
3757 > {
3758 > resource: subagentUri,
3759 > provider: 'subagent',
3760 > title,
3761 > status: SessionStatus.Idle,
3762 > createdAt: subagentNow,
3763 > modifiedAt: subagentNow,
3764 > ...(parentState?.project ? { project: parentState.project } : {}),
3765 > },
3766 > mergedChildTurns,
3767 > );
3768 > this._logService.info(`[AgentService] Restored subagent session: ${subagentUri} with ${childTurns.length} turn(s)`);
3769 > }
3770
3771 /**