Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Users previously faced a two-step confirmation dance ('create''uncommitted-changes') with separate auth handling, making it unclear what permissions were needed upfront. The flow also mixed modal dialogs with chat confirmations.

Changes

New Single Confirmation Flow

  • prepareAndShowDelegateConfirmation() - Checks git state (uncommitted changes) and auth state (permissive session) upfront before showing confirmation
  • Dynamic button generation - Buttons adapt to actual state:
    • Clean repo, auth ready: Delegate, Cancel
    • Uncommitted changes only: Commit and Delegate, Delegate without committing, Cancel
    • Auth needed only: Allow and Delegate, Cancel
    • Both conditions: Commit and Allow, Allow without committing, Cancel
  • Auto-commit handling - When enabled, bypasses git confirmation and sets flag directly

Button-Based Action Routing

Updated handleConfirmationData() to extract action from request.prompt (format: "ButtonText: \"Title\""):

case DelegateConfirmationStep:
    const promptLower = request.prompt.toLowerCase();
    const needsAuthAction = promptLower.includes('allow');
    const needsCommitAction = promptLower.includes('commit') || promptLower.includes('push');
    
    if (needsAuthAction) {
        await this._authenticationService.getPermissiveGitHubSession({ createIfNone: true });
    }
    if (needsCommitAction) {
        data.metadata.autoPushAndCommit = true;
    }

Flow Simplification

  • chatParticipantImpl() - Calls prepareAndShowDelegateConfirmation() for new sessions (untitled and normal chat)
  • Backward compatibility - Kept 'create' and UncommittedChangesStep handling for in-flight sessions

Type Updates

export const DelegateConfirmationStep = 'delegate';

interface ConfirmationMetadata {
    // ... existing fields
    hasUncommittedChanges?: boolean;
    needsAuthUpgrade?: boolean;
}

Testing

Added unit tests covering button generation logic for all state combinations and button text detection patterns.

Original prompt

implement this plan

The user has attached the following uncommitted or modified files as relevant context:
Untitled-1

Single Confirmation Flow Refactoring Plan

Overview

Consolidate the multi-step confirmation flow into a single unified confirmation that checks all prerequisites upfront and presents dynamic buttons based on the current state (git changes, auth requirements).

Current Problems

  • Two-step confirmation dance: 'create''uncommitted-changes'
  • Separate auth confirmation handling with authPermissionPrompted flag
  • Modal dialogs mixed with chat confirmations
  • Complex state tracking across multiple methods
  • Difficult to understand control flow

New Design

Single Confirmation Step

Replace 'create' and UncommittedChangesStep with a single DelegateConfirmationStep constant.

Upfront State Checking

Before showing confirmation, check:

  1. Git state: Are there uncommitted changes?
  2. Auth state: Does user need permissive session upgrade?
  3. Config state: Is auto-commit enabled?

Dynamic Button Generation

Based on state combination, show appropriate buttons (this is just an example):

Git Changes Auth Needed Buttons Shown
No No Delegate, Cancel
No Yes Allow and Delegate, Cancel
Yes No Commit and Delegate, Delegate without committing, Cancel
Yes Yes Commit and Allow, Allow without committing, Cancel

Button-Based Action Routing

In handleConfirmationData(), determine action based on which button was clicked:

  • Buttons with "Commit"/"Push" → set autoPushAndCommit = true
  • Buttons with "Allow" → trigger auth upgrade
  • Then proceed to delegation

Implementation Changes

1. Update Type Definitions (lines 28-34)

export const DelegateConfirmationStep = 'delegate';

interface ConfirmationMetadata {
	prompt: string;
	references?: readonly vscode.ChatPromptReference[];
	chatContext: vscode.ChatContext;
	hasUncommittedChanges?: boolean;
	needsAuthUpgrade?: boolean;
	buttonPressed?: string;
}

2. New Method: prepareAndShowDelegateConfirmation()

Replaces: tryHandleUncommittedChanges()

Responsibilities:

  • Check git state via IGitService
  • Check auth state via IAuthenticationChatUpgradeService.shouldRequestPermissiveSessionUpgrade()
  • Build dynamic message string
  • Generate button array based on state
  • Call stream.confirmation() once with all state

3. Simplified handleConfirmationData() (lines ~570-603)

Single switch case for DelegateConfirmationStep:

  1. Extract button pressed from confirmation data
  2. If button includes "Allow" → call getPermissiveGitHubSession({ createIfNone: true })
  3. If button includes "Commit"/"Push" → set metadata.autoPushAndCommit = true
  4. Route to doUntitledCreation() or createDelegatedChatSession()

4. Update chatParticipantImpl() (lines ~765-900)

Simplify to three paths:

  1. Has confirmation data: Route to handleConfirmationData()
  2. Untitled or new session: Call prepareAndShowDelegateConfirmation()
  3. Follow-up to existing session: Proceed directly (no confirmation)

Remove:

  • Two-stage confirmation logic
  • Separate auth confirmation branch
  • Inline tryHandleUncommittedChanges() calls

5. Methods to Remove

  • tryHandleUncommittedChanges() (lines ~650-737) - logic moves to prepareAndShowDelegateConfirmation()
  • No need for modal dialog code with "Learn more" link

Backward Compatibility

Keep fallback for old-style auth confirmations with authPermissionPrompted flag for any in-flight sessions.

Benefits

  1. Single decision point: User sees all requirements at once
  2. Clearer UX: No surprising second confirmation
  3. Simpler code: One confirmation handler instead of nested cases
  4. Better testability: State checking isolated in single method
  5. Easier to extend: Add new prerequisites by updating button logic

Testing Considerations

Test matrix for button combinations:

  • Clean repo, no auth needed → basic delegate
  • Uncommitted changes only → commit options
  • Auth upgrade only → allow option
  • Both needed → combined options
  • Auto-commit enabled → skips git buttons
  • Follow-up comments → no confirmation

Edge Cases

  • Git API unavailable → proceed without git checks
  • Auth service error → proceed without auth checks
  • User cancels → show cancellation message
  • Untitled sessions → same flow, different telemetry

Untitled-1

[Chronological Review: The conversation began with the user requesting the implementation of a refactoring plan for a confirmation flow. The user provided an overview of the current problems and a new design for a single confirmation step. The user then requested to implement this plan, followed by a command to delegate the task to a cloud agent.]

[Intent Mapping:

  • User requested to "implement this plan" referring to the single confirm...

Created from VS Code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Refactor multi-step confirmation flow into single step Consolidate multi-step delegate confirmation into single upfront check Nov 19, 2025
Copilot AI requested a review from joshspicer November 19, 2025 19:31
Copilot finished work on behalf of joshspicer November 19, 2025 19:31
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.

2 participants