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
137 changes: 137 additions & 0 deletions .claude/skills/rpg/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
name: rpg
description: 'Build and query semantic code graphs using RPG-Encoder. Use when the user wants to understand codebase structure, search for code by intent, explore dependencies, analyze change impact, or perform semantic lifting.'
allowed-tools: Bash(rpg-encoder *), Read, Glob, Grep
---

# RPG-Encoder CLI Skill

You have access to `rpg-encoder`, a CLI tool that builds semantic code graphs (Repository Planning Graphs) from any codebase. Use it to understand code structure, search by intent, trace dependencies, and perform autonomous semantic lifting.

## Quick Reference

### Build a graph (run once per repo)

```bash
rpg-encoder build
```

Detects languages automatically, parses all source files, builds structural hierarchy and dependency edges. Creates `.rpg/graph.json`. Use `--force` to rebuild.

### Search for code by intent

```bash
rpg-encoder search "validate user input"
rpg-encoder search "database connection" --mode features
rpg-encoder search "auth" --mode snippets
rpg-encoder search "parse config" --scope DataProcessing
```

Modes: `auto` (default, tries both), `features` (semantic intent), `snippets` (name/path matching).

### Fetch entity details

```bash
rpg-encoder fetch "src/auth.rs:validate_token"
```

Returns entity type, file location, semantic features, source code, and dependency edges (invokes/invoked-by).

### Explore dependency graph

```bash
rpg-encoder explore "src/auth.rs:validate_token" --direction both --depth 3
```

Directions: `up` (what calls it), `down` (what it calls), `both`.

### Show graph statistics

```bash
rpg-encoder info
```

Shows entity count, file count, lifting coverage, hierarchy, functional areas, edge counts.

### Autonomous semantic lifting

```bash
# Estimate cost first
rpg-encoder lift --dry-run

# Lift with Anthropic Haiku (default, cheapest)
rpg-encoder lift --provider anthropic

# Lift with OpenAI GPT-4o-mini
rpg-encoder lift --provider openai --model gpt-4o-mini

# Lift specific scope
rpg-encoder lift --scope "src/auth/**"
```

Performs full autonomous lifting: auto-lift trivial entities, LLM-lift the rest, synthesize file features, discover domains, and assign hierarchy. Saves after each batch for crash recovery.

API key: pass `--api-key KEY` or set `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` env var.

### Incremental update (after code changes)

```bash
rpg-encoder update
rpg-encoder diff # dry-run: see what would change
```

### Export graph

```bash
rpg-encoder export --format dot # Graphviz DOT
rpg-encoder export --format mermaid # Mermaid flowchart
```

### Validate graph integrity

```bash
rpg-encoder validate
```

### Git hook (auto-update on commit)

```bash
rpg-encoder hook install
rpg-encoder hook uninstall
```

## Workflow Patterns

### Understanding a new codebase

1. `rpg-encoder build` to index
2. `rpg-encoder info` to see structure
3. `rpg-encoder search "main entry point"` to find key entities
4. `rpg-encoder explore ENTITY --direction down` to trace call chains

### Finding code by what it does

Use `--mode features` with natural language describing behavior:
```bash
rpg-encoder search "handle authentication" --mode features
rpg-encoder search "serialize data to JSON" --mode features
```

### Change impact analysis

1. Find the entity: `rpg-encoder search "function_name"`
2. See what depends on it: `rpg-encoder explore ENTITY --direction up --depth 3`

### Full semantic analysis

1. `rpg-encoder build` (if not done)
2. `rpg-encoder lift --dry-run` (check cost)
3. `rpg-encoder lift` (run lifting)
4. `rpg-encoder info` (verify coverage)

## Notes

- The CLI works from the project root directory. Use `-p /path/to/project` to target a different directory.
- Graph is saved at `.rpg/graph.json` — add `.rpg/` to `.gitignore` or commit it for team sharing.
- Lifting is resumable: if interrupted, re-running `rpg-encoder lift` continues from where it stopped.
- For richer interactive navigation (context packs, impact radius, path finding), use the MCP server instead.
20 changes: 20 additions & 0 deletions .gemini/extensions/rpg/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# RPG-Encoder

RPG-Encoder builds semantic code graphs (Repository Planning Graphs) for AI-assisted code understanding.

## CLI Commands

- `rpg-encoder build` — Index codebase, build graph (run once)
- `rpg-encoder search "query"` — Search entities by intent or name
- `rpg-encoder fetch ENTITY_ID` — Get entity details and source
- `rpg-encoder explore ENTITY_ID` — Trace dependency chains
- `rpg-encoder info` — Show graph statistics
- `rpg-encoder lift` — Autonomous LLM-driven semantic lifting
- `rpg-encoder lift --dry-run` — Estimate lifting cost
- `rpg-encoder update` — Incremental update after code changes
- `rpg-encoder export --format dot|mermaid` — Export graph
- `rpg-encoder validate` — Check graph integrity

## MCP Tools (via extension)

The extension also provides an MCP server with rich navigation tools: `search_node`, `fetch_node`, `explore_rpg`, `context_pack`, `impact_radius`, `plan_change`, `find_paths`, and the full lifting protocol.
13 changes: 13 additions & 0 deletions .gemini/extensions/rpg/commands/rpg-build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[command]
description = "Build a semantic code graph (RPG) from the codebase"

[command.prompt]
text = """
Build a Repository Planning Graph for this codebase using the rpg-encoder CLI.

Run: `rpg-encoder build`

This indexes all source files, detects languages, extracts entities, builds the dependency graph and structural hierarchy. The graph is saved to `.rpg/graph.json`.

If the graph already exists, use `--force` to rebuild. After building, run `rpg-encoder info` to show the result.
"""
22 changes: 22 additions & 0 deletions .gemini/extensions/rpg/commands/rpg-lift.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[command]
description = "Run autonomous LLM-driven semantic lifting on the codebase"

[command.prompt]
text = """
Perform autonomous semantic lifting on this codebase using cheap LLM APIs.

First, estimate the cost: `rpg-encoder lift --dry-run`

Show the estimate to the user. If they approve, run the full lift:
`rpg-encoder lift --provider anthropic`

The lift pipeline:
1. Auto-lifts trivial entities (getters, setters, constructors) without LLM calls
2. Sends remaining entities to the LLM in batches for semantic feature extraction
3. Synthesizes file-level features
4. Discovers functional domains and assigns 3-level hierarchy

Progress is saved after each batch. If interrupted, re-running continues from where it stopped.

After completion, run `rpg-encoder info` to show the updated graph statistics.
"""
15 changes: 15 additions & 0 deletions .gemini/extensions/rpg/commands/rpg-search.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[command]
description = "Search for code entities by intent or keywords"

[command.prompt]
text = """
Search the codebase semantic graph for entities matching the user's query.

Run: `rpg-encoder search "$PROMPT" --mode auto`

Use `--mode features` for intent-based search (e.g., "validate user input", "handle HTTP errors").
Use `--mode snippets` for name/path matching (e.g., "auth", "parse_config").
Use `--scope AREA` to restrict to a functional area.

Show the results and explain what each entity does based on its features and location.
"""
12 changes: 12 additions & 0 deletions .gemini/extensions/rpg/gemini-extension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "rpg-encoder",
"version": "0.7.0",
"description": "Build and query semantic code graphs (Repository Planning Graphs) for AI-assisted code understanding. Provides entity search, dependency exploration, and autonomous LLM-driven semantic lifting.",
"mcpServers": {
"rpg-encoder": {
"command": "npx",
"args": ["-y", "rpg-encoder@latest", "mcp"]
}
},
"contextFileName": "CONTEXT.md"
}