feat(copilotcli):Implement updating plan file in exit plan mode handling#309454
Merged
DonJayamanne merged 2 commits intomainfrom Apr 14, 2026
Merged
feat(copilotcli):Implement updating plan file in exit plan mode handling#309454DonJayamanne merged 2 commits intomainfrom
DonJayamanne merged 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extracts Copilot CLI “exit plan mode” handling into a dedicated handleExitPlanMode helper and adds a new unit test suite, with the goal of supporting updating the SDK session plan when the user edits plan.md during exit-plan approval.
Changes:
- Introduces
exitPlanModeHandler.tsto centralize autopilot/interactive exit-plan decisions and plan syncing logic. - Updates
CopilotCLISessionto delegateexit_plan_mode.requestedhandling to the new helper. - Adds
exitPlanModeHandler.spec.tswith coverage for autopilot/interactive flows and plan file monitoring.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts | New handler + plan file monitor implementation. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSession.ts | Wires the SDK event to the new handler. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/test/exitPlanModeHandler.spec.ts | New unit tests for handler behavior and monitoring. |
Copilot's findings
Comments suppressed due to low confidence (4)
extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts:85
ExitPlanModeEventDatamodelsactions/recommendedActionas required strings, but existing callers/tests show these fields can be omitted (e.g. actions undefined). As written,resolveInteractivewill throw when it doesevent.actions.map(...)ifactionsis missing. Make these fields optional (or default them defensively inhandleExitPlanMode) and ensure all usages tolerateundefined/empty values.
export interface ExitPlanModeEventData {
readonly requestId: string;
readonly actions: string[];
readonly recommendedAction: string;
}
extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts:59
- Plan syncing currently depends on
onDidChangeTextDocumentevents and only writes whendoc.isDirty === false. Saving a document typically does not fire a change event, so if the user saves after the delayer fires (or without a format-on-save edit), the SDK session will never be updated. Consider listening to an explicit save event (preferred) or re-triggering/polling until the document becomes clean while the question is open.
this.add(workspaceService.onDidChangeTextDocument(e => {
if (e.contentChanges.length === 0 || !isEqual(e.document.uri, planUri)) {
return;
}
this._lastChangedDocument = e.document;
this._delayer.trigger(() => this._syncIfSaved());
}));
}
private _syncIfSaved(): void {
const doc = this._lastChangedDocument;
if (!doc || doc.isDirty) {
return;
}
extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts:65
_pendingWriteis replaced on each sync, allowing multiplewritePlancalls to overlap and potentially complete out-of-order (older write finishing last). Chain writes onto the previous promise (serialize) so the final plan content is deterministic, andflush()truly waits for all queued writes.
const content = doc.getText();
this._logService.trace('[ExitPlanModeHandler] Plan file saved by user, syncing to SDK session');
this._pendingWrite = this._session.writePlan(content).catch(err => {
this._logService.error(err, '[ExitPlanModeHandler] Failed to write plan changes to SDK session');
});
}
extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts:186
- Interactive resolution assumes
answer.selected[0]exists wheneverfreeTextis empty. If the UI returns an answer with no selection (orskipped: true), this will respondapproved: truewith an invalid/undefinedselectedAction. Handleanswer.skipped/ empty selections by returning{ approved: false }(or falling back to a safe default fromevent.actions).
if (!answer) {
return { approved: false };
}
if (answer.freeText) {
return { approved: false, feedback: answer.freeText };
}
let selectedAction: ExitPlanModeActionType = answer.selected[0] as ExitPlanModeActionType;
for (const [action, desc] of Object.entries(actionDescriptions)) {
if (desc.label === selectedAction) {
selectedAction = action as ExitPlanModeActionType;
break;
}
}
const autoApproveEdits = permissionLevel === 'autoApprove' ? true : undefined;
return { approved: true, selectedAction, autoApproveEdits };
- Files reviewed: 3/3 changed files
- Comments generated: 2
extensions/copilot/src/extension/chatSessions/copilotcli/node/exitPlanModeHandler.ts
Show resolved
Hide resolved
extensions/copilot/src/extension/chatSessions/copilotcli/node/test/exitPlanModeHandler.spec.ts
Show resolved
Hide resolved
bhavyaus
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.