feat(kvb-agent-optimize): index repositories as a code graph for agents
The new category agent holds skills that act on an agent's own setup. kvb-agent-optimize sets up the general code index codebase-memory-mcp (MIT, fully local) for every repository in scope and tightens its agent instructions: agents.py reports whether AGENTS.md exists, whether CLAUDE.md and GEMINI.md point to it, dead relative links, whether it names the index, whether the binary is installed and the git state of the shared snapshot; the operator installs the index through kvb-org-operator; the agent indexes with index_repository and check_index_coverage, asks whether the snapshot is shared, sends code questions to the graph first, audits the instructions with prompt-audit and confirms every change. A domain graph the generic index cannot see goes to the line that owns the repository. kvb-optimize runs it as step 9, so kvb-dream does too. test_naming lists the category, test_dream the optimizer, and test_agent_optimize covers the checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
269590a93d
commit
43b0949f6b
7 files changed
+255
-4
No files matched your search
@@ -0,0 +1,66 @@
|
||||
---
|
||||
name: kvb-agent-optimize
|
||||
description: >
|
||||
Make a repository easy for agents: a code graph index (codebase-memory-mcp)
|
||||
and lean agent instructions. Trigger on /kvb-agent-optimize; kvb-optimize
|
||||
runs it.
|
||||
---
|
||||
|
||||
An agent that queries a graph reads a fraction of what an agent exploring
|
||||
file by file reads, and short, current, consistent instructions get followed.
|
||||
This skill sets up the general code index,
|
||||
[codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp) (MIT,
|
||||
fully local), and tightens the agent instructions of every repository in
|
||||
scope: the current one, or those `kvb-optimize` hands over.
|
||||
|
||||
## Step 1: inventory
|
||||
|
||||
`${CLAUDE_SKILL_DIR}/scripts/agents.py --repo <dir>` prints one line per
|
||||
check: AGENTS.md, whether CLAUDE.md and GEMINI.md point to it, dead relative
|
||||
links in it, whether it names the index, whether the index binary is
|
||||
installed, and the state of the shared snapshot
|
||||
`.codebase-memory/graph.db.zst`.
|
||||
|
||||
## Step 2: index
|
||||
|
||||
- **Binary missing**: installing registers an MCP server in the agent
|
||||
configuration, so it is the operator's step; hand these to the
|
||||
`kvb-org-operator` skill and continue after the restart:
|
||||
|
||||
```bash
|
||||
yay -S codebase-memory-mcp-bin
|
||||
claude plugin marketplace add DeusData/codebase-memory-mcp
|
||||
claude plugin install codebase-memory@codebase-memory
|
||||
```
|
||||
|
||||
- **Index** with the MCP tool `index_repository` on the repository path, then
|
||||
`check_index_coverage`; every file kind it leaves out is a finding.
|
||||
- **Snapshot**: ask whether the repository shares its graph. Shared: run
|
||||
`index_repository` with `persistence: true` and commit
|
||||
`.codebase-memory/graph.db.zst` at a fixed cadence (every commit of it adds
|
||||
a full blob; Git LFS avoids that). Not shared: add `.codebase-memory/` to
|
||||
`.gitignore`, and every agent indexes on its own.
|
||||
- **Domain graphs** the generic index cannot see, such as dependencies a
|
||||
project declares in its own metadata, belong to the line that owns the
|
||||
repository: record them as its task in the `kvb-org-rasci` register, never
|
||||
build them here.
|
||||
|
||||
## Step 3: instructions
|
||||
|
||||
- AGENTS.md is the single source; CLAUDE.md and GEMINI.md only point to it
|
||||
(`@AGENTS.md`).
|
||||
- AGENTS.md sends code questions to the graph first (`search_graph`,
|
||||
`trace_path`, `get_architecture`) and to grep only after it.
|
||||
- `/claude-api prompt-audit` over AGENTS.md and the files it references finds
|
||||
stale, duplicate and contradicting rules; the dead links of step 1 join its
|
||||
findings.
|
||||
|
||||
## Step 4: confirm
|
||||
|
||||
One `AskUserQuestion` per improvement, `multiSelect: false`: the change, its
|
||||
evidence, and `Apply now`, `Record as a task`, `Skip`. No repository file
|
||||
changes before the answer, and nothing is committed.
|
||||
|
||||
## Output
|
||||
|
||||
| Repository | Check | Before | After | Action |
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Report how ready a repository is for agents: instructions, pointers, code index.
|
||||
|
||||
Args:
|
||||
--repo: path of the repository.
|
||||
|
||||
Output:
|
||||
one tab-separated line per check: check, state, detail. States are ok,
|
||||
missing, drift, or for the snapshot tracked, ignored or untracked.
|
||||
|
||||
Exit codes:
|
||||
0 report printed, 2 usage error.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
POINTERS = ("CLAUDE.md", "GEMINI.md")
|
||||
INDEX = "codebase-memory-mcp"
|
||||
SNAPSHOT = ".codebase-memory/graph.db.zst"
|
||||
LINK = re.compile(r"\]\(([^)\s#]+)")
|
||||
|
||||
|
||||
def fail(message: str) -> None:
|
||||
print(f"agents: {message}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
def git_ok(repo: Path, *args: str) -> bool:
|
||||
return subprocess.run(["git", *args], cwd=repo, capture_output=True, check=False).returncode == 0
|
||||
|
||||
|
||||
def snapshot_state(repo: Path) -> str:
|
||||
if not (repo / SNAPSHOT).exists():
|
||||
return "missing"
|
||||
if git_ok(repo, "ls-files", "--error-unmatch", SNAPSHOT):
|
||||
return "tracked"
|
||||
if git_ok(repo, "check-ignore", "-q", SNAPSHOT):
|
||||
return "ignored"
|
||||
return "untracked"
|
||||
|
||||
|
||||
def checks(repo: Path) -> list[tuple[str, str, str]]:
|
||||
agents = repo / "AGENTS.md"
|
||||
text = agents.read_text(encoding="utf-8") if agents.is_file() else ""
|
||||
rows = [("AGENTS.md", "ok" if text else "missing", "single source of the agent instructions")]
|
||||
for name in POINTERS:
|
||||
pointer = repo / name
|
||||
if pointer.is_file():
|
||||
points = "AGENTS.md" in pointer.read_text(encoding="utf-8")
|
||||
rows.append((name, "ok" if points else "drift", f"{'points' if points else 'does not point'} to AGENTS.md"))
|
||||
dead = sorted(
|
||||
{
|
||||
target
|
||||
for target in LINK.findall(text)
|
||||
if ":" not in target and not (repo / target).exists()
|
||||
}
|
||||
)
|
||||
rows.append(("links", "drift" if dead else "ok", ", ".join(dead) or "every relative link resolves"))
|
||||
rows.append(("index-pointer", "ok" if INDEX in text else "missing", f"AGENTS.md names {INDEX}"))
|
||||
rows.append(("index-binary", "ok" if shutil.which(INDEX) else "missing", f"{INDEX} on PATH"))
|
||||
rows.append(("snapshot", snapshot_state(repo), SNAPSHOT))
|
||||
return rows
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--repo", required=True)
|
||||
args = parser.parse_args()
|
||||
repo = Path(args.repo)
|
||||
if not repo.is_dir():
|
||||
fail(f"{repo} is not a directory")
|
||||
for row in checks(repo):
|
||||
print("\t".join(row))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -26,8 +26,10 @@ inventory is skipped with one line.
|
||||
7. `kvb-code-refactor`: bring the uncommitted changes up to the project's
|
||||
standards.
|
||||
8. `kvb-code-tune`: optimize the hot paths the evidence measured.
|
||||
9. `kvb-think-gaps`: find the missing work and hand each pick to
|
||||
`kvb-create-requirement`.
|
||||
9. `kvb-agent-optimize`: index every repository in scope as a code graph
|
||||
and tighten its agent instructions.
|
||||
10. `kvb-think-gaps`: find the missing work and hand each pick to
|
||||
`kvb-create-requirement`.
|
||||
|
||||
## Questions
|
||||
|
||||
|
||||
Reference in new issue
Block a user