Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/content/docs/status.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Status of all agentic workflows. [Browse source files](https://github.com/github
| [Basic Research Agent](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/research.md) | copilot | [![Basic Research Agent](https://github.com/githubnext/gh-aw/actions/workflows/research.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/research.lock.yml) | - | - |
| [Blog Auditor](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/blog-auditor.md) | claude | [![Blog Auditor](https://github.com/githubnext/gh-aw/actions/workflows/blog-auditor.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/blog-auditor.lock.yml) | `0 12 * * 3` | - |
| [Brave Web Search Agent](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/brave.md) | copilot | [![Brave Web Search Agent](https://github.com/githubnext/gh-aw/actions/workflows/brave.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/brave.lock.yml) | - | `/brave` |
| [Changeset Generator](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/changeset.md) | copilot | [![Changeset Generator](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml) | - | - |
| [Changeset Generator](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/changeset.md) | copilot | [![Changeset Generator](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml) | `0 */2 * * *` | - |

Copilot AI Nov 12, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] This change to the Changeset Generator schedule (from - to 0 */2 * * *) appears unrelated to the package extraction framework refactoring. Consider moving this to a separate commit or PR to maintain clear separation of concerns.

Suggested change
| [Changeset Generator](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/changeset.md) | copilot | [![Changeset Generator](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml) | `0 */2 * * *` | - |
| [Changeset Generator](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/changeset.md) | copilot | [![Changeset Generator](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/changeset.lock.yml) | - | - |

Copilot uses AI. Check for mistakes.
| [CI Failure Doctor](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/ci-doctor.md) | copilot | [![CI Failure Doctor](https://github.com/githubnext/gh-aw/actions/workflows/ci-doctor.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/ci-doctor.lock.yml) | - | - |
| [CLI Consistency Checker](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/cli-consistency-checker.md) | copilot | [![CLI Consistency Checker](https://github.com/githubnext/gh-aw/actions/workflows/cli-consistency-checker.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/cli-consistency-checker.lock.yml) | `0 13 * * 1-5` | - |
| [CLI Version Checker](https://github.com/githubnext/gh-aw/blob/main/.github/workflows/cli-version-checker.md) | copilot | [![CLI Version Checker](https://github.com/githubnext/gh-aw/actions/workflows/cli-version-checker.lock.yml/badge.svg)](https://github.com/githubnext/gh-aw/actions/workflows/cli-version-checker.lock.yml) | `0 15 * * *` | - |
Expand Down
37 changes: 15 additions & 22 deletions pkg/workflow/dependabot.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,29 +603,22 @@ func extractGoPackages(workflowData *WorkflowData) []string {
// extractGoFromCommands extracts Go package paths from command strings
func extractGoFromCommands(commands string) []string {
var packages []string
lines := strings.Split(commands, "\n")

for _, line := range lines {
// Look for "go install <package>" or "go get <package>" patterns
words := strings.Fields(line)
for i, word := range words {
if word == "go" && i+1 < len(words) {
cmd := words[i+1]
if cmd == "install" || cmd == "get" {
// Find the package path
for j := i + 2; j < len(words); j++ {
pkg := words[j]
pkg = strings.TrimRight(pkg, "&|;")
// Skip flags (start with - or --)
if !strings.HasPrefix(pkg, "-") {
packages = append(packages, pkg)
break
}
}
}
}
}

// Extract "go install <package>" pattern
installExtractor := PackageExtractor{
CommandNames: []string{"go"},
RequiredSubcommand: "install",
TrimSuffixes: "&|;",
}
packages = append(packages, installExtractor.ExtractPackages(commands)...)

// Extract "go get <package>" pattern
getExtractor := PackageExtractor{
CommandNames: []string{"go"},
RequiredSubcommand: "get",
TrimSuffixes: "&|;",
}
packages = append(packages, getExtractor.ExtractPackages(commands)...)

return packages
}
Expand Down
31 changes: 5 additions & 26 deletions pkg/workflow/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,17 @@
// For detailed documentation, see specs/validation-architecture.md
package workflow

import (
"strings"
)

// extractNpxPackages extracts npx package names from workflow data
func extractNpxPackages(workflowData *WorkflowData) []string {
return collectPackagesFromWorkflow(workflowData, extractNpxFromCommands, "npx")
}

// extractNpxFromCommands extracts npx package names from command strings
func extractNpxFromCommands(commands string) []string {
var packages []string
lines := strings.Split(commands, "\n")

for _, line := range lines {
// Look for "npx <package>" pattern
words := strings.Fields(line)
for i, word := range words {
if word == "npx" && i+1 < len(words) {
// Skip flags and find the first package name
for j := i + 1; j < len(words); j++ {
pkg := words[j]
pkg = strings.TrimRight(pkg, "&|;")
// Skip flags (start with - or --)
if !strings.HasPrefix(pkg, "-") {
packages = append(packages, pkg)
break
}
}
}
}
extractor := PackageExtractor{
CommandNames: []string{"npx"},
RequiredSubcommand: "",
TrimSuffixes: "&|;",
}

return packages
return extractor.ExtractPackages(commands)
}
154 changes: 154 additions & 0 deletions pkg/workflow/package_extraction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Package workflow provides generic package extraction utilities for agentic workflows.
//
// # Package Extraction Framework
//
// This file provides a generic framework for extracting package names from command strings.
// The PackageExtractor type can be configured to handle different package managers
// (npm, pip, uv, go, etc.) with minimal code duplication.
//
// # Usage Example
//
// extractor := PackageExtractor{
// CommandNames: []string{"pip", "pip3"},
// RequiredSubcommand: "install",
// TrimSuffixes: "&|;",
// }
// packages := extractor.ExtractPackages("pip install requests")
// // Returns: []string{"requests"}
//
// For package-specific extraction, see npm.go, pip.go, and dependabot.go.
// For validation, see validation.go.
package workflow

import (
"strings"
)

// PackageExtractor provides a configurable framework for extracting package names
// from command-line strings. It can be configured to handle different package
// managers (npm, pip, uv, go) by setting the appropriate command names and options.
type PackageExtractor struct {
// CommandNames is the list of command names to look for (e.g., ["pip", "pip3"])
CommandNames []string

// RequiredSubcommand is the subcommand that must follow the command name
// (e.g., "install" for pip). If empty, the package name is expected immediately
// after the command name (e.g., "npx <package>").
RequiredSubcommand string

// TrimSuffixes is a string of characters to trim from the end of package names
// (e.g., "&|;" for shell operators)
TrimSuffixes string
}

// ExtractPackages extracts package names from command strings using the configured
// extraction rules. It processes multi-line command strings and returns all found
// package names.
//
// The extraction process:
// 1. Split commands by newlines
// 2. Split each line into words
// 3. Find command name matches
// 4. If RequiredSubcommand is set, look for that subcommand
// 5. Skip flags (words starting with -)
// 6. Extract package name and trim configured suffixes
// 7. Return first package found per command invocation
//
// Example usage:
//
// extractor := PackageExtractor{
// CommandNames: []string{"pip", "pip3"},
// RequiredSubcommand: "install",
// TrimSuffixes: "&|;",
// }
// packages := extractor.ExtractPackages("pip install requests==2.28.0")
// // Returns: []string{"requests==2.28.0"}
func (pe *PackageExtractor) ExtractPackages(commands string) []string {
var packages []string
lines := strings.Split(commands, "\n")

for _, line := range lines {
words := strings.Fields(line)
for i, word := range words {
// Check if this word matches one of our command names
if !pe.isCommandName(word) {
continue
}

// If we have a required subcommand, find it first
if pe.RequiredSubcommand != "" {
pkg := pe.extractWithSubcommand(words, i)
if pkg != "" {
packages = append(packages, pkg)
}
} else {
// No subcommand required - package comes directly after command
pkg := pe.extractDirectPackage(words, i)
if pkg != "" {
packages = append(packages, pkg)
}
}
}
}

return packages
}

// isCommandName checks if the given word matches any of the configured command names
func (pe *PackageExtractor) isCommandName(word string) bool {
for _, cmdName := range pe.CommandNames {
if word == cmdName {
return true
}
}
return false
}

// extractWithSubcommand extracts a package name when a required subcommand must be present
// (e.g., "pip install <package>")
func (pe *PackageExtractor) extractWithSubcommand(words []string, commandIndex int) string {
// Look for the required subcommand after the command name
for j := commandIndex + 1; j < len(words); j++ {
if words[j] == pe.RequiredSubcommand {
// Found the subcommand - now find the package name
return pe.findPackageName(words, j+1)
}
}
return ""
}

// extractDirectPackage extracts a package name that comes directly after the command
// (e.g., "npx <package>")
func (pe *PackageExtractor) extractDirectPackage(words []string, commandIndex int) string {
if commandIndex+1 >= len(words) {
return ""
}
return pe.findPackageName(words, commandIndex+1)
}

// findPackageName finds and processes the package name starting at the given index.
// It skips flags (words starting with -) and returns the first non-flag word,
// trimming configured suffixes.
//
// This method is exported to allow special-case extraction patterns (like uv)
// to reuse the package finding logic.
func (pe *PackageExtractor) FindPackageName(words []string, startIndex int) string {
return pe.findPackageName(words, startIndex)
}

// findPackageName is the internal implementation of FindPackageName
func (pe *PackageExtractor) findPackageName(words []string, startIndex int) string {
for i := startIndex; i < len(words); i++ {
pkg := words[i]
// Skip flags (start with - or --)
if strings.HasPrefix(pkg, "-") {
continue
}
// Trim configured suffixes (e.g., shell operators)
if pe.TrimSuffixes != "" {
pkg = strings.TrimRight(pkg, pe.TrimSuffixes)
}
return pkg
}
return ""
}
Loading