ai-agent-context
v0.3.7
Published
Git-native context layer for AI coding agents: scan a repository into a structured, versionable .agent/ knowledge layer and query it (CLI + programmatic API).
Maintainers
Readme
ai-agent-context CLI
Command-line interface for ai-agent-context.
This package provides the user-facing CLI commands for scanning repositories and querying context.
Installation
npm install -g ai-agent-contextOr use without installation:
npx agent-context <command>Commands
init
Initialize context for a repository.
agent-context initCreates:
.agent/directory.agent/config.json- Configuration file.agent/.gitignore- Git ignore for local cache
Options:
--force- Overwrite existing configuration
scan
Scan the repository and generate context.
agent-context scanOptions:
--force- Ignore cache and re-scan all files--dry-run- Scan without writing to disk--quiet- Minimal output--json- JSON output format
context
Compact repository context summary with optional limits.
agent-context context --max-modules 10 --max-entry-points 10 --max-conventions 5 --max-decisions 5task <description>
Get bounded, task-oriented context for an agent.
agent-context task "add idempotent payment retries" --target src/payments --max-modules 5
agent-context task "add idempotent payment retries" --jsonimpact <target>
Show bounded local Git history for a module:
agent-context history src/models --limit-history 20
agent-context history src/models --jsonrevision-diff
Show paths changed between local revisions:
agent-context revision-diff --revision HEAD~1 --base HEAD
agent-context revision-diff --revision HEAD~1 --jsonGet the bounded impact set for a proposed change.
agent-context impact src/payments --max-files 100
agent-context impact src/payments --jsonexplain
Explain a module or file.
agent-context explain <path>Options:
--json- JSON output format
Example:
agent-context explain src/paymentsdiff
Show context changes since last scan.
agent-context diffOptions:
--json- JSON output format
status
Show repository context status.
agent-context statusverify
Validates persisted context without modifying it. Returns a non-zero exit code for missing, invalid, schema-mismatched, config-stale, or working-tree-drifted context.
agent-context verify --jsonclean
Remove generated context.
agent-context cleanOptions:
--force- Skip confirmation
search
Search repository context.
agent-context search <query>Options:
--json- JSON output format--limit <n>- Limit results
Examples
Initial Setup
# Initialize context
agent-context init
# Scan repository
agent-context scan
# Check status
agent-context statusExplaining Modules
# Explain a module
agent-context explain src/payments
# Explain a specific file
agent-context explain src/payments/payment-service.ts
# Get JSON output
agent-context explain src/payments --jsonChecking Changes
# Scan after making changes
agent-context scan
# Review changes
agent-context diff
# See what changed in architecture
agent-context diff --json | jq '.architecture'CI/CD Integration
# Quiet mode for CI
agent-context scan --quiet
# JSON output for automation
agent-context scan --json > context-scan.jsonOutput Formats
Human-Readable
The default output is human-readable with colored sections:
Payments
Path:
src/payments
Entry points:
src/payments/index.ts
Responsibilities:
payment processing
refunds
Stripe integration
Depends on:
UserRepository
EventBus
StripeAdapter
Used by:
CheckoutService
SubscriptionServiceJSON
Use --json for machine-readable output:
agent-context explain src/payments --jsonReturns structured JSON suitable for parsing by tools and AI agents.
Configuration
The CLI reads configuration from .agent/config.json:
{
"version": 1,
"root": ".",
"include": ["src/**", "packages/**"],
"exclude": ["node_modules/**", "dist/**", "build/**", ".git/**"],
"languages": ["typescript", "javascript"],
"features": {
"architecture": true,
"dependencies": true,
"conventions": true,
"decisions": true,
"git": true
}
}CLI flags override configuration:
agent-context scan --include "custom/**" --exclude "test/**"Exit Codes
0- Success1- Error2- Configuration error
Tips
Incremental Scanning
The CLI uses incremental scanning by default. Only changed files are re-analyzed.
# First scan (full)
agent-context scan
# Subsequent scans (incremental)
agent-context scanCI/CD
For CI/CD, use quiet mode:
agent-context scan --quietLarge Repositories
For large repositories, consider:
- Excluding unnecessary directories
- Limiting the languages analyzed
- Using
--forceonly when needed
Troubleshooting
"No usable .agent/ context found"
Run agent-context init followed by agent-context scan.
"Git signals: unavailable"
Ensure the repository is a Git repository.
"Failed to parse file"
The scanner continues even if some files fail to parse. Use --verbose for details.
Security
The CLI is local-only. Sensitive files are excluded, symlinks are not followed by default, and verify is read-only. See the repository SECURITY.md.
License
MIT
