diff --git a/README.md b/README.md index 1bf342c..cfac78e 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,17 @@ sudo chmod +x /usr/local/bin/coding-context ``` Usage: - coding-context [options] + coding-context [options] [user-prompt] + +Arguments: + + The name of a task file to look up in task search paths (.agents/tasks). + Task files are matched by filename (without .md extension). + + [user-prompt] (optional) + Optional text to append to the task. It can contain slash commands + (e.g., '/command-name') which will be expanded, and parameter + substitution (${param}). Options: -C string @@ -96,7 +106,7 @@ Options: Include rules with matching frontmatter. Can be specified multiple times as key=value. Note: Only matches top-level YAML fields in frontmatter. -a string - Default agent to use if task doesn't specify one. Excludes that agent's own rule paths (since the agent reads those itself). Supported agents: cursor, opencode, copilot, claude, gemini, augment, windsurf, codex. + Target agent to use (excludes rules from that agent's own paths). Supported agents: cursor, opencode, copilot, claude, gemini, augment, windsurf, codex. -w Write rules to agent's config file and output only task to stdout. Requires agent (via task or -a flag). ``` @@ -179,14 +189,15 @@ Each of these would have a corresponding `.md` file (e.g., `triage-bug.md`, `fix The tool assembles the context in the following order: -1. **Rule Files**: It searches a list of predefined locations for rule files (`.md` or `.mdc`). These locations include the current directory, ancestor directories, user's home directory, and system-wide directories. +1. **Rule Files**: It searches for rule files (`.md` or `.mdc`) in directories specified via `-d` flags and automatically-added working directory and home directory. 2. **Rule Bootstrap Scripts**: For each rule file found (e.g., `my-rule.md`), it looks for an executable script named `my-rule-bootstrap`. If found, it runs the script before processing the rule file. These scripts are meant for bootstrapping the environment (e.g., installing tools) and their output is sent to `stderr`, not into the main context. 3. **Filtering**: If `-s` (include) flag is used, it parses the YAML frontmatter of each rule file to decide whether to include it. Note that selectors can only match top-level YAML fields (e.g., `language: go`), not nested fields. 4. **Task Prompt**: It searches for a task file matching the filename (without `.md` extension). Tasks are matched by filename, not by `task_name` in frontmatter. If selectors are provided with `-s`, they are used to filter between multiple task files with the same filename. 5. **Task Bootstrap Script**: For the task file found (e.g., `fix-bug.md`), it looks for an executable script named `fix-bug-bootstrap`. If found, it runs the script before processing the task file. This allows task-specific environment setup or data preparation. -6. **Parameter Expansion**: It substitutes variables in the task prompt using the `-p` flags. -7. **Output**: It prints the content of all included rule files, followed by the expanded task prompt, to standard output. -8. **Token Count**: A running total of estimated tokens is printed to standard error. +6. **User Prompt Appending**: If a user-prompt argument is provided, it is appended to the task content after a delimiter (`---`). +7. **Parameter Expansion**: It substitutes variables in the task prompt and user-prompt using the `-p` flags. +8. **Output**: It prints the content of all included rule files, followed by the expanded task prompt, to standard output. +9. **Token Count**: A running total of estimated tokens is printed to standard error. ### File Search Paths @@ -194,7 +205,6 @@ The tool looks for task and rule files in the following locations, in order of p **Tasks:** - `./.agents/tasks/*.md` (task name matches filename without `.md` extension) -- `~/.agents/tasks/*.md` **Commands** (reusable content blocks referenced via slash commands like `/command-name` inside task content): - `./.agents/commands/*.md` @@ -204,9 +214,9 @@ The tool looks for task and rule files in the following locations, in order of p **Rules:** The tool searches for a variety of files and directories, including: - `CLAUDE.local.md` -- `.agents/rules`, `.cursor/rules`, `.augment/rules`, `.windsurf/rules`, `.opencode/agent`, `.opencode/rules` -- `.github/copilot-instructions.md`, `.github/agents`, `.gemini/styleguide.md` -- `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.codex/AGENTS.md` +- `.agents/rules`, `.cursor/rules`, `.augment/rules`, `.windsurf/rules`, `.opencode/agent` +- `.github/copilot-instructions.md`, `.github/agents`, `.gemini/styleguide.md`, `.augment/guidelines.md` +- `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursorrules`, `.windsurfrules` - User-specific rules in `~/.agents/rules`, `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md`, `~/.gemini/GEMINI.md`, `~/.opencode/rules`, etc. ### Remote File System Support @@ -300,10 +310,10 @@ Deploy the application to production with all safety checks. You can then select the appropriate task using: ```bash # Deploy to staging -coding-context -s environment=staging /deploy +coding-context -s environment=staging deploy # Deploy to production -coding-context -s environment=production /deploy +coding-context -s environment=production deploy ``` #### Task Frontmatter Selectors @@ -328,11 +338,6 @@ When you run this task, it automatically applies the selectors: coding-context implement-feature ``` -This is equivalent to: -```bash -coding-context -s languages=go -s stage=implementation /implement-feature -``` - **Selectors support OR logic for the same key using arrays:** ```markdown --- @@ -394,13 +399,12 @@ This is particularly useful in agentic workflows where an AI agent has already b - Skipping all rules output **Example usage:** - ```bash # Initial task invocation (includes all rules, uses task with resume: false) -coding-context -s resume=false /fix-bug | ai-agent +coding-context -s resume=false fix-bug | ai-agent # Resume the task (skips rules, uses task with resume: true) -coding-context -r /fix-bug | ai-agent +coding-context -r fix-bug | ai-agent ``` **Example task files for resume mode:** @@ -449,7 +453,7 @@ languages: To include this rule only when working on Go code, you would use `-s languages=go`: ```bash -coding-context -s languages=go /fix-bug +coding-context -s languages=go fix-bug ``` This will include all rules with `languages: [ go ]` in their frontmatter, excluding rules for other languages. @@ -468,10 +472,10 @@ Then select only the relevant rules: ```bash # Work on Python code with Python-specific rules -coding-context -s languages=python /fix-bug +coding-context -s languages=python fix-bug # Work on JavaScript code with JavaScript-specific rules -coding-context -s languages=javascript /enhance-feature +coding-context -s languages=javascript enhance-feature ``` **Language Values** @@ -503,42 +507,34 @@ If you need to filter on nested data, flatten your frontmatter structure to use ### Targeting a Specific Agent -When working with a specific AI coding agent, the agent itself will read its own configuration files. The `-a` flag lets you specify which agent you're using, automatically excluding that agent's specific rule paths while including rules from other agents and generic rules. +The `-a` flag specifies which AI coding agent you're using. This information is currently used for: + +1. **Write Rules Mode**: With the `-w` flag, determines where to write rules (e.g., `~/.github/agents/AGENTS.md` for `copilot`) + +> **Note:** Agent-based rule filtering is not currently implemented. All rules are included regardless of the `-a` value. **Supported agents:** -- `cursor` - Excludes `.cursor/rules`, `.cursorrules`; includes other agents and generic rules -- `opencode` - Excludes `.opencode/agent`, `.opencode/command`; includes other agents and generic rules -- `copilot` - Excludes `.github/copilot-instructions.md`, `.github/agents`; includes other agents and generic rules -- `claude` - Excludes `.claude/`, `CLAUDE.md`, `CLAUDE.local.md`; includes other agents and generic rules -- `gemini` - Excludes `.gemini/`, `GEMINI.md`; includes other agents and generic rules -- `augment` - Excludes `.augment/`; includes other agents and generic rules -- `windsurf` - Excludes `.windsurf/`, `.windsurfrules`; includes other agents and generic rules -- `codex` - Excludes `.codex/`, `AGENTS.md`; includes other agents and generic rules +- `cursor` - Cursor IDE +- `opencode` - OpenCode.ai +- `copilot` - GitHub Copilot +- `claude` - Anthropic Claude +- `gemini` - Google Gemini +- `augment` - Augment +- `windsurf` - Windsurf +- `codex` - Codex -**Example: Using Cursor:** +**Example:** ```bash -# When using Cursor, exclude .cursor/ and .cursorrules (Cursor reads those itself) -# But include rules from other agents and generic rules -coding-context -a cursor /fix-bug +# Use with write rules mode +coding-context -a copilot -w fix-bug ``` **How it works:** -- The `-a` flag sets the target agent -- The target agent's own paths are excluded (e.g., `.cursor/` for cursor) -- Rules from other agents are included (e.g., `.opencode/`, `.github/copilot-instructions.md`) -- Generic rules (from `.agents/rules`) are always included -- The agent name is automatically added as a selector, so generic rules can filter themselves with `agent: cursor` in frontmatter - -**Example generic rule with agent filtering:** - -```markdown ---- -agent: cursor ---- -# This rule only applies when using Cursor -Use Cursor-specific features... -``` +- The `-a` flag sets the target agent value +- The agent value is stored in the context for use by the `-w` flag +- With `-w`, the agent determines where to write rules to the user's home directory +- All rules are currently included regardless of agent value **Agent field in task frontmatter:** @@ -551,15 +547,7 @@ agent: cursor # This task automatically sets the agent to cursor ``` -This is useful for tasks designed for specific agents, ensuring the correct agent context is used regardless of command-line flags. - -**Use cases:** -- **Avoid duplication**: The agent reads its own config, so exclude it from the context -- **Cross-agent rules**: Include rules from other agents that might be relevant -- **Generic rules**: Always include generic rules, with optional agent-specific filtering -- **Task-specific agents**: Tasks can enforce a specific agent context - -The exclusion happens before rule processing, so excluded paths are never loaded or counted toward token estimates. +This is useful for tasks designed for specific agents, ensuring the correct agent is set for determining the write path with `-w`. ### Bootstrap Scripts diff --git a/docs/how-to/create-tasks.md b/docs/how-to/create-tasks.md index de12dbd..b88e8d5 100644 --- a/docs/how-to/create-tasks.md +++ b/docs/how-to/create-tasks.md @@ -22,7 +22,7 @@ Please review the code changes with focus on: - Security implications ``` -Save as `.agents/tasks/code-review.md` (or `.agents/commands/code-review.md`). +Save as `.agents/tasks/code-review.md`. Use with: ```bash @@ -51,7 +51,7 @@ coding-context \ -p feature_name="User Authentication" \ -p requirements="OAuth2 support, secure password storage" \ -p success_criteria="All tests pass, security audit clean" \ - /implement-feature + implement-feature ``` ## Multiple Tasks with Selectors diff --git a/docs/how-to/github-actions.md b/docs/how-to/github-actions.md index 901658a..0aa8fc8 100644 --- a/docs/how-to/github-actions.md +++ b/docs/how-to/github-actions.md @@ -209,7 +209,7 @@ Use the `-C` flag to run from a different directory: ```yaml - name: Assemble Context run: | - coding-context -C ./backend -s languages=go /fix-bug > context.txt + coding-context -C ./backend -s languages=go fix-bug > context.txt ``` ## Best Practices diff --git a/docs/index.md b/docs/index.md index 2fcf929..f6bc387 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,7 +19,7 @@ sudo curl -fsL -o /usr/local/bin/coding-context \ sudo chmod +x /usr/local/bin/coding-context # Use with an AI agent -coding-context -p issue_key=BUG-123 -s languages=go /fix-bug | llm -m claude-3-5-sonnet-20241022 +coding-context -p issue_key=BUG-123 -s languages=go fix-bug | llm -m claude-3-5-sonnet-20241022 ``` ## Documentation Structure diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 1622ccf..9cf9398 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -12,7 +12,7 @@ Complete reference for the `coding-context` command-line interface. ## Synopsis ``` -coding-context [options] +coding-context [options] [user-prompt] ``` ## Description @@ -27,13 +27,27 @@ The Coding Context CLI assembles context from rule files and task prompts, perfo Task files can contain slash commands (e.g., `/command-name arg`) which reference command files for modular content reuse. +### `[user-prompt]` (optional) + +**Optional.** Additional text to append to the task content. This text is appended after a delimiter (`---`) and can contain: +- Slash commands (e.g., `/command-name arg`) which will be expanded +- Parameter substitution placeholders (e.g., `${param}`) + +The user-prompt is processed the same way as task file content, allowing you to dynamically extend the task at runtime. + **Examples:** ```bash -# Task name (looks up fix-bug.md task file) +# Task name only (looks up fix-bug.md task file) coding-context fix-bug -# With parameters -coding-context -p issue_key=BUG-123 fix-bug +# Task with user-prompt +coding-context fix-bug "Focus on the authentication module" + +# User-prompt with parameters +coding-context -p issue_key=BUG-123 fix-bug "Check the error logs in /var/log" + +# User-prompt with slash commands +coding-context fix-bug "/pre-checks and then analyze the code" # With selectors coding-context -s languages=go fix-bug @@ -173,23 +187,27 @@ coding-context \ **Type:** String **Default:** (empty) -Specify the target agent being used. When set, this excludes that agent's own rule paths (since the agent reads those itself) while including rules from other agents and generic rules. +Specify the target agent being used. This is currently used for: +1. **Write Rules Mode**: With `-w` flag, determines where to write rules (e.g., `~/.github/agents/AGENTS.md` for copilot) + +> **Note:** Agent-based rule filtering is not currently implemented. All rules are included regardless of the `-a` value. **Supported agents:** `cursor`, `opencode`, `copilot`, `claude`, `gemini`, `augment`, `windsurf`, `codex` **How it works:** -- When `-a cursor` is specified, paths like `.cursor/rules` and `.cursorrules` are excluded -- Rules from other agents (e.g., `.opencode/agent`, `.github/copilot-instructions.md`) are included -- Generic rules from `.agents/rules` are always included -- The agent name is automatically added as a selector for rule filtering +- The agent value is stored in the context (can come from `-a` flag or task frontmatter) +- With `-w` flag, the agent determines the user rules path for writing +- All rules are currently included regardless of agent value + +**Agent Precedence:** +- If a task specifies an `agent` field in its frontmatter, that takes precedence over the `-a` flag +- The `-a` flag is used when the task doesn't specify an agent +- Either the task's agent field or `-a` flag can be used to set the agent **Example:** ```bash -# Using Cursor - excludes .cursor/ paths, includes others -coding-context -a cursor fix-bug - -# Using GitHub Copilot - excludes .github/copilot-instructions.md, includes others -coding-context -a copilot implement-feature +# Use with write rules mode +coding-context -a copilot -w implement-feature ``` **Note:** Task files can override this with an `agent` field in their frontmatter. @@ -240,40 +258,6 @@ coding-context -s languages=go -s priority=high fix-bug coding-context -s environment=production deploy ``` -**Note:** When filtering by language, use `-s languages=go` (plural). The selector key is `languages` (plural), matching the frontmatter field name. - -### `-a ` - -**Type:** String (agent name) -**Default:** (empty) - -Specify the default agent to use. This acts as a fallback if the task doesn't specify an agent in its frontmatter. - -**Supported agents:** -- `cursor` - [Cursor](https://cursor.sh/) -- `opencode` - [OpenCode.ai](https://opencode.ai/) -- `copilot` - [GitHub Copilot](https://github.com/features/copilot) -- `claude` - [Anthropic Claude](https://claude.ai/) -- `gemini` - [Google Gemini](https://gemini.google.com/) -- `augment` - [Augment](https://augmentcode.com/) -- `windsurf` - [Windsurf](https://codeium.com/windsurf) -- `codex` - [Codex](https://codex.ai/) - -**Agent Precedence:** -- If the task specifies an `agent` field in its frontmatter, that agent **overrides** the `-a` flag -- The `-a` flag serves as a **default** agent when the task doesn't specify one -- This allows tasks to specify their preferred agent while supporting a command-line default - -**Examples:** -```bash -# Use copilot as the default agent -coding-context -a copilot fix-bug - -# Task with agent field will override -a flag -# If fix-bug.md has "agent: claude", it will use claude instead of copilot -coding-context -a copilot fix-bug -``` - ### `-w` **Type:** Boolean flag @@ -372,15 +356,18 @@ coding-context fix-bug # Bootstrap scripts can use these variables ### Basic Usage ```bash -# Free-text prompt (used directly as task content) -coding-context "Please help me review this code for security issues" - # Task name lookup coding-context code-review +# Task with user-prompt +coding-context code-review "Focus on security vulnerabilities" + # With parameters coding-context -p pr_number=123 code-review +# User-prompt with parameters +coding-context -p issue=BUG-456 fix-bug "Check the database connection logic" + # With selectors coding-context -s languages=python fix-bug @@ -390,6 +377,9 @@ coding-context \ -s stage=implementation \ -p feature_name="Authentication" \ implement-feature + +# User-prompt with slash commands +coding-context implement-feature "/pre-checks and validate the requirements" ``` ### Working Directory @@ -440,6 +430,9 @@ coding-context -r implement-feature | ai-agent # Claude coding-context fix-bug | claude +# With user-prompt +coding-context fix-bug "Focus on edge cases" | claude + # LLM tool coding-context fix-bug | llm -m claude-3-5-sonnet-20241022 @@ -450,8 +443,8 @@ coding-context code-review | openai api completions.create -m gpt-4 coding-context fix-bug > context.txt cat context.txt | your-ai-agent -# Free-text prompt -coding-context "Please help me debug the auth module" | claude +# User-prompt with parameters +coding-context -p issue=123 fix-bug "Check logs in /var/log" | claude ``` ### Token Monitoring diff --git a/docs/reference/file-formats.md b/docs/reference/file-formats.md index 807240e..c1ad24b 100644 --- a/docs/reference/file-formats.md +++ b/docs/reference/file-formats.md @@ -442,13 +442,10 @@ This prevents command injection where expanded content could trigger further, un ### File Location -Task files must be in one of these directories: -- `./.agents/tasks/` -- `./.cursor/commands/` -- `./.opencode/command/` -- `~/.agents/tasks/` +Task files must be in these directories within any search path directory: +- `.agents/tasks/` -Tasks are matched by filename (without `.md` extension). The `task_name` field in frontmatter is optional and used only for metadata. For example, a file named `fix-bug.md` is matched by the command `/fix-bug`, regardless of whether it has `task_name` in its frontmatter. +Tasks are matched by filename (without `.md` extension). The `task_name` field in frontmatter is optional and used only for metadata. For example, a file named `fix-bug.md` is matched by the task name `fix-bug`, regardless of whether it has `task_name` in its frontmatter. ## Command Files @@ -523,11 +520,10 @@ Commands can also receive inline parameters: ### File Locations -Command files must be in one of these directories: -- `./.agents/commands/` -- `./.cursor/commands/` -- `./.opencode/command/` -- `~/.agents/commands/` +Command files must be in these directories within any search path directory: +- `.agents/commands/` +- `.cursor/commands/` +- `.opencode/command/` Commands are matched by filename (without `.md` extension). For example, a file named `deploy.md` is matched by the slash command `/deploy`. diff --git a/docs/reference/search-paths.md b/docs/reference/search-paths.md index b354675..0ffd7c6 100644 --- a/docs/reference/search-paths.md +++ b/docs/reference/search-paths.md @@ -81,10 +81,7 @@ Rule files are discovered from directories specified via the `-d` flag (plus aut .augment/rules/ .windsurf/rules/ .opencode/agent/ -.opencode/command/ -.opencode/rules/ .github/agents/ -.codex/ ``` **Specific files:** @@ -92,6 +89,7 @@ Rule files are discovered from directories specified via the `-d` flag (plus aut CLAUDE.local.md .github/copilot-instructions.md .gemini/styleguide.md +.augment/guidelines.md ``` **Standard files:** diff --git a/main.go b/main.go index 9004881..58e4279 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,8 @@ func main() { flag.StringVar(&workDir, "C", ".", "Change to directory before doing anything.") flag.BoolVar(&resume, "r", false, "Resume mode: skip outputting rules and select task with 'resume: true' in frontmatter.") - flag.BoolVar(&writeRules, "w", false, "Write rules to the agent's user rules path and only print the prompt to stdout. Requires -a flag.") - flag.Var(&agent, "a", "Target agent to use (excludes rules from other agents). Supported agents: cursor, opencode, copilot, claude, gemini, augment, windsurf, codex.") + flag.BoolVar(&writeRules, "w", false, "Write rules to the agent's user rules path and only print the prompt to stdout. Requires agent (via task 'agent' field or -a flag).") + flag.Var(&agent, "a", "Target agent to use. Required when using -w to write rules to the agent's user rules path. Supported agents: cursor, opencode, copilot, claude, gemini, augment, windsurf, codex.") flag.Var(¶ms, "p", "Parameter to substitute in the prompt. Can be specified multiple times as key=value.") flag.Var(&includes, "s", "Include rules with matching frontmatter. Can be specified multiple times as key=value.") flag.Func("d", "Directory containing rules and tasks. Can be specified multiple times. Supports various protocols via go-getter (http://, https://, git::, s3::, file:// etc.).", func(s string) error {