Skip to content

feat: npm command confirmation feature #1581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Stijnus
Copy link
Collaborator

@Stijnus Stijnus commented Mar 30, 2025

This PR is for #1396

NPM Command Confirmation Feature

Summary of Changes

We implemented a confirmation system for npm commands that:

  1. Provides users with explicit "Yes, setup and start" or "No, skip for now" options
  2. Properly executes npm commands in the WebContainer terminal when users choose to proceed
  3. Gives feedback to users via chat messages and toast notifications

Key Files Modified

  1. app/components/chat/MessageProcessor.tsx (Created)

    • Processes pending messages for commands
    • Detects and executes npm installation and dev server startup commands
    • Provides visual confirmation of command execution
  2. app/lib/stores/workbench.ts (Modified)

    • Added pendingMessages atom to store messages pending command execution
    • Added registerArtifact and getArtifact methods to manage artifacts
    • Modified addCommandsMessage to work with React hooks properly

Technical Implementation Details

  1. Fixed React Hooks Issue

    • Replaced direct hook calls with an atom-based approach using pendingMessages
    • Created a React component MessageProcessor to safely use hooks
  2. Command Execution

    • Implemented special handling for "npm install" and "npm run dev" commands
    • Directly executes commands with the terminal interface instead of relying on empty action objects
    • Added proper sequencing of commands with delays to ensure stability
  3. User Feedback

    • Added confirmation messages in the chat interface after actions complete
    • Added toast notifications for command progress and completion
    • Different confirmation messages based on whether setup was completed or skipped

Key Benefits

  1. Improved User Experience

    • Clear choices for users when setting up projects
    • Visual feedback for command execution process
    • Explicit confirmation of successful setup or choice to skip
  2. Increased Stability

    • More reliable execution of npm commands
    • Graceful error handling with helpful error messages
    • Proper sequencing of commands with delays
image

# NPM Command Confirmation Feature

## Summary of Changes

We implemented a confirmation system for npm commands that:

1. Provides users with explicit "Yes, setup and start" or "No, skip for now" options
2. Properly executes npm commands in the WebContainer terminal when users choose to proceed
3. Gives feedback to users via chat messages and toast notifications

## Key Files Modified

1. **app/components/chat/MessageProcessor.tsx** (Created)
   - Processes pending messages for commands
   - Detects and executes npm installation and dev server startup commands
   - Provides visual confirmation of command execution

2. **app/lib/stores/workbench.ts** (Modified)
   - Added `pendingMessages` atom to store messages pending command execution
   - Added `registerArtifact` and `getArtifact` methods to manage artifacts
   - Modified `addCommandsMessage` to work with React hooks properly

## Technical Implementation Details

1. **Fixed React Hooks Issue**
   - Replaced direct hook calls with an atom-based approach using `pendingMessages`
   - Created a React component `MessageProcessor` to safely use hooks

2. **Command Execution**
   - Implemented special handling for "npm install" and "npm run dev" commands
   - Directly executes commands with the terminal interface instead of relying on empty action objects
   - Added proper sequencing of commands with delays to ensure stability

3. **User Feedback**
   - Added confirmation messages in the chat interface after actions complete
   - Added toast notifications for command progress and completion
   - Different confirmation messages based on whether setup was completed or skipped

## Key Benefits

1. **Improved User Experience**
   - Clear choices for users when setting up projects
   - Visual feedback for command execution process
   - Explicit confirmation of successful setup or choice to skip

2. **Increased Stability**
   - More reliable execution of npm commands
   - Graceful error handling with helpful error messages
   - Proper sequencing of commands with delays
@Stijnus Stijnus self-assigned this Mar 30, 2025
@Stijnus Stijnus added the feature A pretty vague description of how a capability of our software can be added or improved. label Mar 31, 2025
@Stijnus Stijnus requested review from xKevIsDev and leex279 March 31, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A pretty vague description of how a capability of our software can be added or improved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant