Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 8, 2025

Overview

This PR implements the infrastructure needed for the "Accept" workflow for AI code edits, as described in the issue. After receiving an AI response, users should be able to click an "Accept" button to accept the changes, clear the chat history, and continue with a fresh conversation.

Problem

Currently, there's no mechanism to:

  1. Disable text entry after an AI response (to prevent new requests while reviewing changes)
  2. Clear the chat history after accepting AI changes
  3. Control the workflow from parent applications like VizHub

Solution

This PR adds two new optional parameters to VZCodeContext that enable parent applications to implement the Accept workflow:

1. enableAIChatTextEntry (boolean, default: true)

Controls whether the chat input is enabled or disabled:

  • When true: Users can type in the chat input (default behavior)
  • When false: Chat textarea and send button are disabled

2. clearChatHistory (callback function)

A callback function that parent applications can provide to clear chat messages when the Accept button is clicked.

Implementation Details

The implementation follows a clean separation of concerns:

  • VZCode provides the infrastructure (parameters and UI controls)
  • Parent applications (like VizHub) implement the workflow logic (Accept button rendering, chat clearing, state management)

Workflow Sequence

  1. User sends an AI request
  2. AI responds with code edits
  3. Parent app sets enableAIChatTextEntry={false} to disable input
  4. Parent app renders "Accept", "Undo", and "Try Harder" buttons via additionalWidgets
  5. User clicks "Accept"
  6. Parent app's Accept handler calls clearChatHistory() and sets enableAIChatTextEntry={true}
  7. User can now type a new message

Code Example

Parent applications can use the new parameters like this:

<VZCodeProvider
  enableAIChatTextEntry={isTextEntryEnabled}
  clearChatHistory={() => {
    // Clear messages from current chat
    submitOperation((content) => ({
      ...content,
      chats: {
        ...content.chats,
        [chatId]: {
          ...content.chats[chatId],
          messages: [],
        },
      },
    }));
    // Re-enable text entry
    setIsTextEntryEnabled(true);
  }}
  additionalWidgets={({ chatId, messageId }) => (
    <div>
      <button onClick={handleUndo}>Undo</button>
      <button onClick={handleTryHarder}>Try Harder</button>
      <button onClick={handleAccept}>Accept</button>
    </div>
  )}
  // ... other props
/>

Changes Made

  • src/client/VZCodeContext/types.ts: Added type definitions for enableAIChatTextEntry and clearChatHistory
  • src/client/VZCodeContext/useVZCodeState.ts: Accept and pass through new parameters
  • src/client/VZSidebar/AIChat/ChatInput.tsx: Disable textarea and send button based on enableTextEntry prop
  • src/client/VZSidebar/AIChat/index.tsx: Extract enableAIChatTextEntry from context and pass to ChatInput
  • ACCEPT_WORKFLOW.md: Complete documentation with usage examples

Screenshots

Normal state - text entry enabled (default):

AI Chat Text Enabled

User can type messages:

AI Chat With Text

When enableAIChatTextEntry={false}, the textarea becomes disabled (grayed out) and the send button is disabled, preventing users from submitting new requests.

Testing

  • ✅ All 117 tests pass (1 skipped as expected)
  • ✅ Build completes successfully
  • ✅ Type checking passes with no new errors
  • ✅ Code formatted with Prettier
  • ✅ Manual testing confirms text input control works correctly
  • ✅ No breaking changes - all parameters are optional with sensible defaults

Documentation

See ACCEPT_WORKFLOW.md for complete implementation guide including:

  • Detailed parameter descriptions
  • Full code examples for parent applications
  • Workflow sequence documentation

Next Steps

The actual "Accept" button rendering and chat clearing logic will be implemented in the parent project (VizHub) using the infrastructure provided by this PR.

Original prompt

This section details on the original issue you should resolve

<issue_title>"Accept" workflow for AI Code Edits</issue_title>
<issue_description>The user should be able to click an "Accept" button, alongside the existing "Undo" and "Try Harder" buttons, after receiving an AI result.

It should not be possible to type into the text area until the user clicks "Accept" (assume there's a parameter enableAIChatTextEntry we can pass into VZCodeContext - we will implement that in the other project later).

After clicking "Accept", the chat history should be cleared, and the user should be able to enter text again.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1165

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add accept button to AI code edits workflow Add Accept workflow infrastructure for AI code edits Oct 8, 2025
Copilot AI requested a review from curran October 8, 2025 15:26
Copilot finished work on behalf of curran October 8, 2025 15:26
@curran curran closed this Nov 8, 2025
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.

"Accept" workflow for AI Code Edits

2 participants