Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

When gh aw add owner/repo/workflow-name fails because the workflow doesn't exist, users get generic help text with no indication of what workflows are actually available in the installed package.

Changes

  • New function displayAvailableWorkflows(): Lists all workflows from the installed package with example commands
  • Enhanced error path in addWorkflowWithTracking(): Calls displayAvailableWorkflows() when workflow not found, falls back to generic help on failure
  • Tests: Coverage for listing workflows, version handling, and edge cases (empty package, missing package)

Example

Before:

✗ Workflow 'workflows/daily-news.md' not found.

To add workflows to your project:
=================================
Use the 'add' command with repository/workflow specifications:
  gh aw add owner/repo/workflow-name

After:

✗ Workflow 'workflows/daily-news.md' not found.

ℹ Available workflows in githubnext/agentics:

  • ci-doctor
  • daily-plan
  • weekly-summary

Example:
  gh aw add githubnext/agentics/ci-doctor
Original prompt

When the add command tries to add a workflow name that does not exist, show the list of potential workflow names to the user. Reuse the code that lists the workflow names.

WRONG

@pelikhan ➜ /workspaces/gh-aw (main) $ ./gh-aw add githubnext/agentics/daily-news
Package githubnext/agentics already exists. Updating...
Successfully installed package: githubnext/agentics
✗ Workflow 'workflows/daily-news.md' not found.

To add workflows to your project:
=================================
Use the 'add' command with repository/workflow specifications:
  gh aw add owner/repo/workflow-name
  gh aw add owner/repo/workflow-name@version

Example:
  gh aw add githubnext/agentics/ci-doctor
  gh aw add githubnext/agentics/daily-plan@main
✗ failed to add workflow 'githubnext/agentics/workflows/daily-news.md': workflow not found: workflows/daily-news.md

BETTER: suggest list of availabe names.


💡 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 and others added 2 commits November 7, 2025 02:51
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] Suggest available workflow names when not found Show available workflows when workflow not found in add command Nov 7, 2025
Copilot AI requested a review from pelikhan November 7, 2025 03:05
Copilot finished work on behalf of pelikhan November 7, 2025 03:05
@pelikhan pelikhan marked this pull request as ready for review November 7, 2025 03:18
Copilot AI review requested due to automatic review settings November 7, 2025 03:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the add command's error handling by displaying available workflows from an installed package when a specific workflow is not found, providing more helpful guidance to users.

Key Changes:

  • Added displayAvailableWorkflows() function that lists workflows from installed packages with examples
  • Modified error handling in addWorkflowWithTracking() to call the new function before falling back to generic help
  • Added comprehensive test coverage for the new functionality including edge cases (no workflows, package not found, with/without version)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pkg/cli/add_workflow_not_found_test.go New test file with 4 test cases covering workflow listing scenarios: basic display, version handling, empty package, and missing package
pkg/cli/add_command.go Added displayAvailableWorkflows() function and integrated it into workflow-not-found error flow to provide contextual help instead of generic instructions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +320 to +326
// Extract workflow name from path (remove .md extension and path)
workflowName := strings.TrimSuffix(filepath.Base(workflow), ".md")

// For workflows in workflows/ directory, show simplified name
if strings.HasPrefix(workflow, "workflows/") {
workflowName = strings.TrimSuffix(strings.TrimPrefix(workflow, "workflows/"), ".md")
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated workflow name extraction logic: The logic for extracting workflow names from paths (lines 320-326) is duplicated almost identically in lines 344-348 for the example workflow. Consider extracting this into a small helper function to avoid code duplication and make the logic easier to maintain.

Copilot uses AI. Check for mistakes.
w.Close()
os.Stderr = oldStderr
var buf bytes.Buffer
buf.ReadFrom(r)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error check: The return value from buf.ReadFrom(r) is not checked. While this is unlikely to fail in tests, it's best practice to check errors, especially since other I/O operations in the same tests do check errors.

Suggested change
buf.ReadFrom(r)
if _, err := buf.ReadFrom(r); err != nil {
t.Fatalf("Failed to read from pipe: %v", err)
}

Copilot uses AI. Check for mistakes.
w.Close()
os.Stderr = oldStderr
var buf bytes.Buffer
buf.ReadFrom(r)
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error check: The return value from buf.ReadFrom(r) is not checked. While this is unlikely to fail in tests, it's best practice to check errors, especially since other I/O operations in the same tests do check errors.

Suggested change
buf.ReadFrom(r)
if _, err := buf.ReadFrom(r); err != nil {
t.Fatalf("Failed to read from pipe: %v", err)
}

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 3b9b621 into main Nov 7, 2025
22 checks passed
@pelikhan pelikhan deleted the copilot/show-available-workflow-names branch November 7, 2025 03:22
github-actions bot added a commit that referenced this pull request Nov 7, 2025
Update documentation to reflect recent feature changes and improvements.

Changes made:
- Remove outdated bash wildcard restriction in strict mode (PR #3407)
- Update CLI documentation for improved workflow discovery (PR #3402, #3406)
- Document wildcard workflow addition with better error handling (PR #3404)
- Update security guide to use neutral language about wildcards

Referenced PRs:
- #3407 - Remove bash wildcard restriction in strict mode
- #3406 - Display workflow list as table with ID, Name, and Description
- #3402 - Show available workflows when workflow not found in add command
- #3404 - Emit warning instead of error when wildcard adds encounter existing workflows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
pelikhan pushed a commit that referenced this pull request Nov 7, 2025
Update documentation to reflect recent feature changes and improvements.

Changes made:
- Remove outdated bash wildcard restriction in strict mode (PR #3407)
- Update CLI documentation for improved workflow discovery (PR #3402, #3406)
- Document wildcard workflow addition with better error handling (PR #3404)
- Update security guide to use neutral language about wildcards

Referenced PRs:
- #3407 - Remove bash wildcard restriction in strict mode
- #3406 - Display workflow list as table with ID, Name, and Description
- #3402 - Show available workflows when workflow not found in add command
- #3404 - Emit warning instead of error when wildcard adds encounter existing workflows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
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