-
Notifications
You must be signed in to change notification settings - Fork 1
Add -a flag to specify target agent (excludes target agent's own paths) #116
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
435ef25
Initial plan
Copilot cebaceb
Add -x flag to exclude rules by CLI name
Copilot ff13b91
Add documentation for -x flag (CLI exclusion)
Copilot 0f51e53
Fix path pattern for .github/agents to properly match subdirectories
Copilot c43cf01
Refactor: Use Agent type instead of string-based excludes, rename Wit…
Copilot d4955e4
Improve: Generate AllAgents() and ParseAgent() error messages dynamic…
Copilot 6fd2032
Merge branch 'main' into copilot/add-option-to-exclude-agent
alexec c18419c
Change flag from -x to -a for agent exclusions
Copilot 7566314
Remove case-insensitive and trim from ParseAgent, add AGENTS.md to co…
Copilot 89610b0
Refactor: Rename from "exclude" to "target agent", add agent as selector
Copilot 7c8ade6
Fix: Exclude ALL agent paths (including target agent), use generic ru…
Copilot b5bd2be
Fix: Exclude only target agent's paths, include other agents and gene…
Copilot b6c2ca3
Changes before error encountered
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package codingcontext | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Agent represents an AI coding agent | ||
| type Agent string | ||
|
|
||
| // Supported agents | ||
| const ( | ||
| AgentCursor Agent = "cursor" | ||
| AgentOpenCode Agent = "opencode" | ||
| AgentCopilot Agent = "copilot" | ||
| AgentClaude Agent = "claude" | ||
| AgentGemini Agent = "gemini" | ||
| AgentAugment Agent = "augment" | ||
| AgentWindsurf Agent = "windsurf" | ||
| AgentCodex Agent = "codex" | ||
| ) | ||
|
|
||
| // AllAgents returns all supported agents | ||
| func AllAgents() []Agent { | ||
| agents := make([]Agent, 0, len(agentPathPatterns)) | ||
| for agent := range agentPathPatterns { | ||
| agents = append(agents, agent) | ||
| } | ||
| return agents | ||
| } | ||
|
|
||
| // ParseAgent parses a string into an Agent type | ||
| func ParseAgent(s string) (Agent, error) { | ||
| agent := Agent(s) | ||
|
|
||
| // Check if agent exists in the path patterns map | ||
| if _, exists := agentPathPatterns[agent]; exists { | ||
| return agent, nil | ||
| } | ||
|
|
||
| // Build list of supported agents for error message | ||
| supported := make([]string, 0, len(agentPathPatterns)) | ||
| for a := range agentPathPatterns { | ||
| supported = append(supported, a.String()) | ||
| } | ||
| return "", fmt.Errorf("unknown agent: %s (supported: %s)", s, strings.Join(supported, ", ")) | ||
| } | ||
|
|
||
| // String returns the string representation of the agent | ||
| func (a Agent) String() string { | ||
| return string(a) | ||
| } | ||
|
|
||
| // PathPatterns returns the path patterns associated with this agent | ||
| func (a Agent) PathPatterns() []string { | ||
| return agentPathPatterns[a] | ||
| } | ||
|
|
||
| // MatchesPath returns true if the given path matches any of the agent's patterns | ||
| func (a Agent) MatchesPath(path string) bool { | ||
| normalizedPath := filepath.ToSlash(path) | ||
| patterns := a.PathPatterns() | ||
|
|
||
| for _, pattern := range patterns { | ||
| if strings.Contains(normalizedPath, pattern) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // agentPathPatterns maps agents to their associated path patterns | ||
| var agentPathPatterns = map[Agent][]string{ | ||
| AgentCursor: { | ||
| ".cursor/", | ||
| ".cursorrules", | ||
| }, | ||
| AgentOpenCode: { | ||
| ".opencode/", | ||
| }, | ||
| AgentCopilot: { | ||
| ".github/copilot-instructions.md", | ||
| ".github/agents/", | ||
| }, | ||
| AgentClaude: { | ||
| ".claude/", | ||
| "CLAUDE.md", | ||
| "CLAUDE.local.md", | ||
| }, | ||
| AgentGemini: { | ||
| ".gemini/", | ||
| "GEMINI.md", | ||
| }, | ||
| AgentAugment: { | ||
| ".augment/", | ||
| }, | ||
| AgentWindsurf: { | ||
| ".windsurf/", | ||
| ".windsurfrules", | ||
| }, | ||
| AgentCodex: { | ||
| ".codex/", | ||
| "AGENTS.md", | ||
| }, | ||
| } | ||
|
|
||
| // TargetAgent represents the agent being used, which excludes that agent's own rules | ||
| // Empty string means no agent specified | ||
| type TargetAgent string | ||
|
|
||
| // String implements the fmt.Stringer interface for TargetAgent | ||
| func (t TargetAgent) String() string { | ||
| return string(t) | ||
| } | ||
|
|
||
| // Set implements the flag.Value interface for TargetAgent | ||
| func (t *TargetAgent) Set(value string) error { | ||
| agent, err := ParseAgent(value) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| *t = TargetAgent(agent) | ||
| return nil | ||
| } | ||
|
|
||
| // ShouldExcludePath returns true if the given path should be excluded based on target agent | ||
| func (t TargetAgent) ShouldExcludePath(path string) bool { | ||
| if t == "" { | ||
| return false | ||
| } | ||
|
|
||
| // Exclude paths from ONLY the target agent | ||
| // The target agent will read its own rules, so we don't need to include them | ||
| // But we might want rules from other agents or generic rules | ||
| return Agent(t).MatchesPath(path) | ||
| } | ||
|
|
||
| // IsSet returns true if a target agent has been specified | ||
| func (t TargetAgent) IsSet() bool { | ||
| return t != "" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.