From repo4agent
Transform any repository into an agent-native structure. Generates AGENT.md, .agent/MANIFEST.yaml, .agent/INVARIANTS.md, .agent/IMPACT_MAP.yaml, and .agent/TEST_CONTRACTS.yaml — the 5-file metadata layer proven to improve AI agent task success rates by 30+ percentage points. Use when starting a new project or upgrading an existing repo for AI agent workflows.
How this skill is triggered — by the user, by Claude, or both
Slash command
/repo4agent:init-agent-repoThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are executing the `/init-agent-repo` skill. Your job is to analyze the current repository and generate an **agent-native metadata layer** — a set of structured files that dramatically improve AI agent performance on this codebase.
You are executing the /init-agent-repo skill. Your job is to analyze the current repository and generate an agent-native metadata layer — a set of structured files that dramatically improve AI agent performance on this codebase.
Before generating anything, build a complete mental model of the codebase. Read in this order:
src/**/*, lib/**/*, app/**/*, or equivalent**/*.test.*, **/*_test.*, tests/**/* — understand what's covered.env.example, config files, schema definitionsWhile exploring, identify:
// TODO, # FIXME, // HACK, missing validations, incomplete error handlingGenerate all five files. Do not skip any. Create the .agent/ directory if it doesn't exist.
AGENT.md (root of repo)The agent's entry point. Machine-optimized — no prose, only structured information.
# AGENT.md
> Read .agent/INVARIANTS.md and .agent/MANIFEST.yaml BEFORE touching any file.
## Capabilities
| ID | Operation | Handler | Method+Path or Entrypoint |
|----|-----------|---------|--------------------------|
| ... | ... | ... | ... |
## Known Issues (fix before adding features)
| ID | Location | Description |
|----|----------|-------------|
| ... | ... | ... |
## Architecture
- **Language/Runtime**: ...
- **Framework**: ...
- **Data layer**: ...
- **Test runner**: `<exact command to run tests>`
- **Entry point**: ...
## Key Invariants
(List the 3–5 most critical non-obvious constraints. Full details in .agent/INVARIANTS.md)
- INV-001: ...
- INV-002: ...
Rules:
npm test, pytest, go test ./...).agent/MANIFEST.yamlCapability index. Every externally-visible operation gets an entry.
# .agent/MANIFEST.yaml
# Capability index — maps operations to handlers, contracts, side effects, and test coverage.
capabilities:
<domain>.<operation>: # e.g., user.create, auth.login, order.cancel
handler: "src/..." # exact file path
method: "POST /path/:param" # HTTP method+path, CLI command, or function signature
contract: "src/...contract.ts" # types/schema file if it exists, omit if not
side_effects:
- writes_<store> # what persistent state this modifies
- sends_<notification> # emails, webhooks, events emitted
- invalidates_<cache> # cache keys cleared
dependencies:
- "src/shared/..." # shared utilities this calls
known_issues: | # omit if none
"Description of current bug or missing behavior. See INV-XXX."
test_coverage: "tests/...#<describe_block>" # exact test location, or "NONE"
Rules:
handler, side_effects, and test_coverageside_effects is the most important field — this is what agents miss in traditional repostest_coverage is NONE, add a comment: # agent: write tests before editing this.agent/INVARIANTS.mdNon-obvious constraints and known violations. Only document what isn't self-evident from reading the code.
# INVARIANTS.md
# Non-obvious constraints and known violations.
# Read this before making ANY changes.
## Active Violations (fix these first)
### INV-XXX: <short name> (VIOLATED)
- **WHERE**: `src/exact/file.ts` line ~N
- **WHAT**: One sentence describing what invariant is currently broken
- **FIX**: Exact description of what to call/add/change
- **HELPER**: `src/shared/util.ts` already has `functionName()` — use it
- **TEST**: Add assertion to `tests/file.test.ts#describe_block`
## Invariants (must always hold)
### INV-XXX: <short name>
- **RULE**: The constraint that must always be true
- **WHY**: Why this matters (security, consistency, business logic)
- **WHERE ENFORCED**: Which file/function currently enforces this
- **GOTCHA**: The non-obvious way this can be accidentally broken
Rules:
deleteByUserId()" causes agents to call a non-existent method. "Step 1: add deleteByUserId() to src/db.ts — this method does not exist yet. Step 2: call it from the handler." recovers the failure entirely. Always write fix steps in implementation order..agent/IMPACT_MAP.yamlCross-module impact declarations. Converts "unknown unknowns" into "known unknowns."
# .agent/IMPACT_MAP.yaml
# Cross-module impact map.
# "If you change X, you MUST also check/change Y."
impact_map:
"src/exact/file.ts":
affects:
- file: "src/other/file.ts"
reason: "Shares the UserRecord type — schema changes must propagate"
- file: "tests/integration/file.test.ts"
reason: "Integration test mocks this module's output"
depended_on_by:
- "src/module/that/imports/it.ts"
"src/models/Schema.ts":
affects:
- file: "src/..."
reason: "..."
- file: "migrations/..."
reason: "Schema changes require a new migration"
Rules:
.agent/TEST_CONTRACTS.yamlExact test assertions per capability. An agent that knows precisely what the test expects gets it right on the first attempt — no discovery-by-failure loop.
# .agent/TEST_CONTRACTS.yaml
# Exact test assertions per capability.
# Read before writing any implementation — know the target before writing a single line.
contracts:
<domain>.<operation>: # matches MANIFEST.yaml capability key
success:
status: 200 # exact HTTP status code expected
body: # shape of the response body (use null if no body)
field: type # e.g., id: string, token: string
side_effect: | # observable state change the test will verify
"Description of what must be true after this call"
failure_cases:
- trigger: "Description of what input/state triggers the failure"
status: 400 # exact status code for this failure
body:
error: "exact error string or field name"
notes: | # omit if not needed
"Any non-obvious assertion detail the agent would otherwise guess wrong"
Rules:
status must be the exact integer — not a range, not "2xx"side_effect is the most important field for cross-module operations: state that must be verified beyond the HTTP response (e.g., sessions deleted, cache cleared, event emitted)failure_cases only lists cases the tests actually assert — do not invent hypothetical validationstest_coverage: NONE in MANIFEST.yaml, write the contract for what the tests should assert — prefix with # agent: write this testAfter generating all five files:
.agent/ directory contains exactly: MANIFEST.yaml, INVARIANTS.md, IMPACT_MAP.yaml, TEST_CONTRACTS.yamlAGENT.md exists at the repo rootPrint a summary:
✓ AGENT.md — N capabilities indexed, M known issues
✓ .agent/MANIFEST.yaml — N capabilities across D domains
✓ .agent/INVARIANTS.md — N active violations, M invariants
✓ .agent/IMPACT_MAP.yaml — N files mapped
✓ .agent/TEST_CONTRACTS.yaml — N contracts (M with side_effect assertions)
High-value entries:
- INV-XXX: [description] → agents would have missed this
- [capability].known_issues: [description] → cross-module side effect documented
- [capability] contract: [assertion] → prevents over/under-engineering
Next: Run /init-agent-repo again after major refactors to keep metadata current.
deleteSessionsByUserId() in src/shared/db.ts" beats "invalidates sessions"side_effects field is what prevents the "missing edit" failure patternnpx claudepluginhub pinkbubblebubble/repo4agent --plugin repo4agentAnalyzes repository structure to generate or update AGENTS.md contributor guides for AI agents. Supports single-repo and monorepo layouts with update mode that preserves custom sections.
Generates AGENTS.md files in repo folders (root, src/tests/api, monorepos) with build commands, testing, code style, structure, boundaries for coding agents. Only if missing.
Creates, refreshes, or validates repo AGENTS.md files using evidence from files, git history, CI to keep them concise and current. Use when missing, stale, or after refactors/tooling changes.