Skip to content

Fix npx command parsing to support --yes and -y flags#2299

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-npx-command-parsing
Oct 24, 2025
Merged

Fix npx command parsing to support --yes and -y flags#2299
pelikhan merged 6 commits into
mainfrom
copilot/fix-npx-command-parsing

Conversation

Copilot AI commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Problem

The npx package validation was incorrectly treating flags like -y and --yes as package names. When compiling workflows, the output showed:

ℹ ✓ npm package validated: -y

This occurred in three scenarios:

  1. Direct npx commands: npx -y @github/copilot@0.0.350
  2. String-format MCP tools: mcp: "npx -y @modelcontextprotocol/server-filesystem /tmp"
  3. Structured MCP configs: command: npx, args: ["-y", "@microsoft/markitdown"]

Solution

Updated the npx command parsing to skip flag arguments before extracting package names, following the same pattern used by the existing extractUvFromCommands and extractPipFromCommands functions.

Changes

  1. pkg/workflow/npm.go - Modified extractNpxFromCommands() to iterate through words after npx and skip any arguments starting with - or --:

    // Skip flags and find the first package name
    for j := i + 1; j < len(words); j++ {
        pkg := words[j]
        pkg = strings.TrimRight(pkg, "&|;")
        if !strings.HasPrefix(pkg, "-") {
            packages = append(packages, pkg)
            break
        }
    }
  2. pkg/workflow/validation.go - Updated collectPackagesFromWorkflow() to:

    • Parse string-format MCP tools using the extraction function
    • Skip flags when iterating through structured args arrays
  3. pkg/workflow/runtime_setup.go - Extended detectFromMCPConfigs() to handle string-format MCP tools, ensuring Node.js runtime is detected for workflows using npx commands

  4. pkg/workflow/validation_test.go - Added test coverage for:

    • npx with -y flag
    • npx with --yes flag
    • npx with multiple flags
    • npx with flags and shell operators

Results

After the fix, package validation correctly identifies the actual packages:

ℹ ✓ npm package validated: @modelcontextprotocol/server-filesystem
ℹ ✓ npm package validated: @github/copilot@0.0.350
ℹ ✓ npm package validated: @microsoft/markitdown

All existing tests pass, and the new test cases ensure proper handling of npx flags across different workflow formats.

Original prompt

Fix the npx command parsing to support the --yes and -y flags. The compile shows the following output which shows a parsing error:

ℹ ✓ npm package validated: -y

💡 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.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 24, 2025 16:59
@github-actions

Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Copilot AI and others added 3 commits October 24, 2025 17:01
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix npx command parsing for --yes and -y flags Fix npx command parsing to support --yes and -y flags Oct 24, 2025
Copilot AI requested a review from pelikhan October 24, 2025 17:09
@pelikhan pelikhan merged commit c116041 into main Oct 24, 2025
9 of 14 checks passed
@pelikhan pelikhan deleted the copilot/fix-npx-command-parsing branch October 24, 2025 17:10
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