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
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Usage:
Options:
-C string
Change to directory before doing anything. (default ".")
-d value
Remote directory containing rules and tasks. Can be specified multiple times. Supports various protocols via go-getter (http://, https://, git::, s3::, etc.).
-p value
Parameter to substitute in the prompt. Can be specified multiple times as key=value.
-r Resume mode: skip outputting rules and select task with 'resume: true' in frontmatter.
Expand All @@ -70,8 +72,9 @@ Options:
Note: Only matches top-level YAML fields in frontmatter.
```

### Example
### Examples

**Basic usage with local files:**
```bash
coding-context-cli -p jira_issue_key=PROJ-1234 fix-bug | llm -m gemini-pro
```
Expand All @@ -85,6 +88,27 @@ This command will:
6. Print the combined context (rules + task) to `stdout`.
7. Pipe the output to another program (in this case, `llm`).

**Using remote directories:**
```bash
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
-d s3::https://s3.amazonaws.com/my-bucket/coding-standards \
fix-bug | llm -m gemini-pro
```

This command will:
1. Download remote directories using go-getter
2. Search for rules and tasks in the downloaded directories
3. Combine them with local rules and tasks
4. Apply the same processing as with local files

The `-d` flag supports various protocols via go-getter:
- `http://` and `https://` - HTTP/HTTPS URLs
- `git::` - Git repositories
- `s3::` - S3 buckets
- `file://` - Local file paths
- And more (see go-getter documentation)

### Example Tasks

The `<task-name>` is the value of the `task_name` field in the frontmatter of task files. Here are some common examples:
Expand Down Expand Up @@ -129,6 +153,61 @@ The tool searches for a variety of files and directories, including:
- User-specific rules in `~/.agents/rules`, `~/.claude/CLAUDE.md`, `~/.opencode/rules`, etc.
- System-wide rules in `/etc/agents/rules`, `/etc/opencode/rules`.

### Remote File System Support

The tool supports loading rules and tasks from remote locations via HTTP/HTTPS URLs. This enables:

- **Shared team guidelines**: Host coding standards on a central server
- **Organization-wide rules**: Distribute common rules across multiple projects
- **Version-controlled context**: Serve rules from Git repositories
- **Dynamic rules**: Update shared rules without modifying individual repositories

**Usage:**

```bash
# Clone a Git repository containing rules
coding-context-cli -d git::https://github.com/company/shared-rules.git fix-bug

# Use multiple remote sources
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
-d https://cdn.company.com/coding-standards \
deploy

# Mix local and remote directories
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
-s language=Go \
implement-feature
```

**Supported protocols (via go-getter):**
- `http://` and `https://` - HTTP/HTTPS URLs (downloads tar.gz, zip, or directories)
- `git::` - Git repositories (e.g., `git::https://github.com/user/repo.git`)
- `s3::` - S3 buckets (e.g., `s3::https://s3.amazonaws.com/bucket/path`)
- `file://` - Local file paths
- And more - see [go-getter documentation](https://github.com/hashicorp/go-getter)

**Important notes:**
- Remote directories are downloaded to a temporary location
- Bootstrap scripts work in downloaded directories
- Downloaded directories are cleaned up after execution
- Supports all standard directory structures (`.agents/rules`, `.agents/tasks`, etc.)

**Example: Using a Git repository:**

```bash
# Use a specific branch or tag
coding-context-cli \
-d 'git::https://github.com/company/shared-rules.git?ref=v1.0' \
fix-bug

# Use a subdirectory within the repo
coding-context-cli \
-d 'git::https://github.com/company/mono-repo.git//coding-standards' \
implement-feature
```

## File Formats

### Task Files
Expand Down
191 changes: 191 additions & 0 deletions examples/remote-rules-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Remote Directory Example

This example demonstrates how to use remote directories with coding-context-cli.

## Use Case

You have coding standards and tasks in a central Git repository or other remote location that you want to share across multiple projects. Instead of duplicating these files in each repository, you can load them from a remote directory.

## Example Setup

### 1. Create a Remote Repository

Create a Git repository with your shared rules and tasks:

```
shared-rules/
├── .agents/
│ ├── rules/
│ │ ├── coding-standards.md
│ │ ├── security-guidelines.md
│ │ └── testing-best-practices.md
│ └── tasks/
│ ├── code-review.md
│ └── fix-security-issue.md
└── README.md
```

### 2. Create Rule Files

**Example: `.agents/rules/coding-standards.md`**

```markdown
---
language: Go
---
# Go Coding Standards

- Use `gofmt` for formatting
- Write tests for all public functions
- Use meaningful variable names
- Add comments for exported functions
```

### 3. Use the Remote Directory

```bash
# Clone from Git repository
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
fix-bug

# Use a specific branch or tag
coding-context-cli \
-d 'git::https://github.com/company/shared-rules.git?ref=v1.0' \
implement-feature

# Use a subdirectory within the repo
coding-context-cli \
-d 'git::https://github.com/company/mono-repo.git//coding-standards' \
refactor-code

# Mix local and remote directories
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
-s language=Go \
implement-feature
```

## Supported Protocols

The `-r` flag uses HashiCorp's go-getter library, which supports many protocols:

### Git Repositories

```bash
# HTTPS
coding-context-cli -d git::https://github.com/company/rules.git fix-bug

# SSH
coding-context-cli -d git::git@github.com:company/rules.git fix-bug

# With authentication token
coding-context-cli -d 'git::https://token@github.com/company/rules.git' fix-bug

# Specific branch
coding-context-cli -d 'git::https://github.com/company/rules.git?ref=main' fix-bug

# Specific tag
coding-context-cli -d 'git::https://github.com/company/rules.git?ref=v1.0.0' fix-bug

# Specific commit
coding-context-cli -d 'git::https://github.com/company/rules.git?ref=abc123' fix-bug

# Subdirectory (note the double slash)
coding-context-cli -d 'git::https://github.com/company/mono.git//standards' fix-bug
```

### HTTP/HTTPS

```bash
# Download and extract tar.gz
coding-context-cli -d https://example.com/rules.tar.gz fix-bug

# Download and extract zip
coding-context-cli -d https://example.com/rules.zip fix-bug

# File server directory
coding-context-cli -d https://example.com/rules/ fix-bug
```

### S3 Buckets

```bash
# S3 bucket
coding-context-cli -d s3::https://s3.amazonaws.com/bucket/rules fix-bug

# With region
coding-context-cli -d s3::https://s3-us-west-2.amazonaws.com/bucket/rules fix-bug
```

### Local Files

```bash
# Local directory (useful for testing)
coding-context-cli -d file:///path/to/local/rules fix-bug
```

## Real-World Example: GitHub Repository

```bash
# Load organization-wide coding standards from GitHub
coding-context-cli \
-d git::https://github.com/company/shared-rules.git \
-p component=auth \
fix-security-issue | llm -m claude-3-sonnet
```

## Benefits

1. **Centralized Management**: Update rules in one place, all projects get the latest version
2. **Version Control**: Use git tags/branches to manage different versions of rules
3. **No Duplication**: Don't need to copy rules into every repository
4. **Easy Distribution**: Share rules across teams and organizations
5. **Mix and Match**: Combine remote directories with local project-specific rules
6. **Full Feature Support**: Bootstrap scripts work in downloaded directories

## Important Notes

- Remote directories are downloaded to a temporary location
- Downloaded directories are cleaned up after execution
- Bootstrap scripts are supported in remote directories
- All standard directory structures are supported (`.agents/rules`, `.agents/tasks`, etc.)
- Downloads happen on each invocation (use git caching for better performance)

## Troubleshooting

### Remote directory not accessible

Check:
1. URL is accessible (test with git clone or curl)
2. Authentication is configured (SSH keys, tokens, etc.)
3. Correct protocol prefix (git::, s3::, etc.)
4. Network connectivity

### Performance concerns

- Remote directories are downloaded on every run
- Use git shallow clones for large repos (automatically done by go-getter)
- Consider local caching strategies for frequently used remote directories
- Use specific tags/commits for reproducible builds

## Advanced: Multiple Remote Sources

You can combine multiple remote directories:

```bash
# Load from multiple sources
coding-context-cli \
-d git::https://github.com/company/standards.git \
-d git::https://github.com/team/project-rules.git \
-d https://cdn.company.com/shared-rules.tar.gz \
implement-feature
```

This allows for:
- Company-wide standards from one repo
- Team-specific rules from another repo
- Project-specific rules from a CDN
- Local rules in the current directory

All sources are merged together and processed as if they were in a single directory.
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ module github.com/kitproj/coding-context-cli
go 1.24.4

require go.yaml.in/yaml/v2 v2.4.2

require (
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.0 // indirect
github.com/hashicorp/go-getter/v2 v2.2.3 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.1.0 // indirect
github.com/klauspost/compress v1.11.2 // indirect
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-getter/v2 v2.2.3 h1:6CVzhT0KJQHqd9b0pK3xSP0CM/Cv+bVhk+jcaRJ2pGk=
github.com/hashicorp/go-getter/v2 v2.2.3/go.mod h1:hp5Yy0GMQvwWVUmwLs3ygivz1JSLI323hdIE9J9m7TY=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/klauspost/compress v1.11.2 h1:MiK62aErc3gIiVEtyzKfeOHgW7atJb5g/KNX5m3c2nQ=
github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/ulikunitz/xz v0.5.8 h1:ERv8V6GKqVi23rgu5cj9pVfVzJbOqAY2Ntl88O6c2nQ=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
Loading