Skip to content

Comments

add clearAndImplement command#3882

Open
bhavyaus wants to merge 2 commits intomainfrom
dev/bhavyau/clear-implement-plan
Open

add clearAndImplement command#3882
bhavyaus wants to merge 2 commits intomainfrom
dev/bhavyau/clear-implement-plan

Conversation

@bhavyaus
Copy link
Contributor

No description provided.

@bhavyaus bhavyaus marked this pull request as ready for review February 20, 2026 02:50
Copilot AI review requested due to automatic review settings February 20, 2026 02:50
@bhavyaus bhavyaus force-pushed the dev/bhavyau/clear-implement-plan branch from ce8bfa2 to 7311dff Compare February 20, 2026 02:50
@bhavyaus bhavyaus requested a review from digitarald February 20, 2026 02:51
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new /clearAndImplement slash command to the agent participant that allows users to start a fresh implementation session with the plan from session memory, avoiding context bloat from the planning conversation.

Changes:

  • Adds /clearAndImplement slash command that creates a new chat session and copies plan.md to the new session's memory
  • Updates the Plan agent's "Start Implementation" handoff button to use /clearAndImplement instead of a plain text prompt
  • Exports MEMORY_BASE_DIR from memoryTool.tsx and adds commands and window to vscodeTypes for accessing VS Code APIs
  • Includes test updates reflecting the handoff button changes

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/vscodeTypes.ts Exports commands and window namespaces from VS Code API for accessing command execution and active chat panel session resource
src/util/common/test/shims/vscodeTypesShim.ts Adds test shims for the new commands and window exports
src/extension/tools/node/memoryTool.tsx Exports MEMORY_BASE_DIR constant for use in planAgentProvider
src/extension/intents/node/agentIntent.ts Adds handler for clearAndImplement command that delegates to the IRunCommandExecutionService
src/extension/common/constants.ts Maps clearAndImplement command to Agent intent
src/extension/agents/vscode-node/planAgentProvider.ts Implements the core clearAndImplement logic including command registration, session memory copying, and new chat creation
src/extension/agents/vscode-node/test/planAgentProvider.spec.ts Updates test expectations to reflect the new handoff button label and prompt changes
package.json Adds clearAndImplement to the agent participant's command contributions
package.nls.json Adds localized description for the clearAndImplement command
Comments suppressed due to low confidence (3)

src/extension/agents/vscode-node/planAgentProvider.ts:355

  • The command execution at line 307 (fallback path) and line 336 (error path) use _sendChatQuery('Start implementation') which sends an in-session handoff. However, the successful path at lines 352-355 uses executeCommand('workbench.action.chat.open', ...) with mode: 'agent' and query: 'Start implementation'. These two code paths may produce different user experiences. Consider whether the fallback and error paths should also use the same command and options as the success path, or document why they should differ.
			await this._sendChatQuery('Start implementation');
			return;
		}

		// Listen for the new session resource BEFORE creating the chat
		let eventDisposable: vscode.Disposable | undefined;
		const eventPromise = new Promise<vscode.Uri | undefined>(resolve => {
			eventDisposable = vscode.window.onDidChangeActiveChatPanelSessionResource(newResource => {
				resolve(newResource);
			});
		});
		const newSessionPromise = raceTimeout(eventPromise, NEW_SESSION_RESOURCE_TIMEOUT_MS).finally(() => {
			eventDisposable?.dispose();
		});

		// Create a new chat session
		await this.runCommandService.executeCommand('workbench.action.chat.newChat');

		// Wait for the new session resource
		let newSessionResource = vscode.window.activeChatPanelSessionResource;
		if (newSessionResource && newSessionResource.toString() !== currentSessionResource.toString()) {
			// Fast path: resource already changed, dispose listener immediately
			eventDisposable?.dispose();
		} else {
			newSessionResource = await newSessionPromise;
		}

		if (!newSessionResource) {
			this.logService.warn('[PlanAgentProvider] Failed to get new session resource');
			await this._sendChatQuery('Start implementation');
			return;
		}

		// Copy plan.md to the new session's memory
		const newSessionId = extractSessionId(newSessionResource.toString());
		const newSessionDir = vscode.Uri.joinPath(
			URI.from(storageUri), MEMORY_BASE_DIR, newSessionId
		);
		await createDirectoryIfNotExists(this.fileSystemService, newSessionDir);

		const newPlanUri = vscode.Uri.joinPath(newSessionDir, 'plan.md');
		await this.fileSystemService.writeFile(newPlanUri, planContent);
		this.logService.trace(`[PlanAgentProvider] Copied plan.md from session ${currentSessionId} to ${newSessionId}`);

		// Open in agent mode with "Start implementation"
		await this.runCommandService.executeCommand('workbench.action.chat.open', {
			mode: 'agent',
			query: 'Start implementation',
		});

src/extension/intents/node/agentIntent.ts:28

  • Import order is inconsistent with the codebase convention. Imports from ../../../vscodeTypes should be grouped together after all platform imports (from ../../../platform/) and before extension-level imports (from ../../). This import should be moved to line 33, after the blank line following IWorkspaceService import and before the blank line that precedes the util imports.
import { ChatResponseProgressPart2 } from '../../../vscodeTypes';

src/extension/agents/vscode-node/planAgentProvider.ts:332

  • There's a potential race condition where the event listener may not be properly disposed if the promise resolves before reaching the fast path check. If newSessionResource is already set when accessed at line 326 but the event fires between line 326 and line 329, the event could resolve the promise, which would trigger the finally cleanup at line 318-320, and then the code would also call dispose() again at line 329, resulting in a double-dispose. While this is generally safe for VS Code disposables, it would be cleaner to ensure the listener is only disposed once. Consider wrapping the fast path disposal in a check or using a flag to prevent double disposal.
		let newSessionResource = vscode.window.activeChatPanelSessionResource;
		if (newSessionResource && newSessionResource.toString() !== currentSessionResource.toString()) {
			// Fast path: resource already changed, dispose listener immediately
			eventDisposable?.dispose();
		} else {
			newSessionResource = await newSessionPromise;
		}

@bhavyaus bhavyaus force-pushed the dev/bhavyau/clear-implement-plan branch from 7311dff to a7cbbde Compare February 20, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant