Docs / AGENTS · Edit on GitHub

Agent instructions for rgctl

Summary

rgctl is a high-performance Rust code knowledge graph for LLM agents: tree-sitter extraction, typed relations, mmap snapshots, blast-radius / communities / CPG, and JSON-first CLI (-f json).

Your goal when contributing here: preserve ingest scale, query correctness, memory discipline, and deterministic artifacts under .rgctl/ — not add convenience at the cost of Tokio blocking, whole-repo clones, or ungated cold regressions.

Looking for how to use rgctl on another codebase? Install skills (rgctl install --skill --with-commands) or copy docs/agents/USER_AGENTS_TEMPLATE.md into that repo’s AGENTS.md. See docs/guides/agent-commands.md.


Must-follow rules

  • Async vs CPU: Discover/serve use tokio. Do not run heavy CPU (parse, graph analytics, CFG) on the async executor — use spawn_blocking / Rayon where the pipeline already does.
  • Parallel ingest: Per-file plugin extraction runs on the discover worker pool. Do not replace with a serial whole-repo walk when parallel ingest exists.
  • Streaming commits: Emit symbols/relations file-by-file; avoid unbounded Vec<Relation> / whole-repo ASTs before commit (rgctl-extraction spill patterns).
  • Clone hygiene: Prefer &[u8] / Cow / borrows in tree-sitter walkers; Vec::with_capacity when sizes are known; no unwrap() in library paths.
  • Typed graph: Respect EdgeType / node kinds; do not invent ad-hoc string edges for hot paths.
  • Artifacts: Session data lives in {repo}/.rgctl/. Warm caches invalidate wall-time claims.
  • Features: Default semantic embedder is compiled vocab. Do not require ONNX / Python ML unless behind an explicit feature (e.g. semantic-onnx / code-daemon + Git LFS).
  • OpenSpec language work: Still cite openspec/changes/_shared/starting-context.md (pointer here); follow the sections below.

Context & architecture

  • Discover walks the tree, runs language plugins (tree-sitter), builds the graph, writes compact caches to .rgctl/.
  • Query paths are read-oriented and return versioned JSON (schema_version on stdout — never scrape stderr).
  • Analysis (rgctl-analysis) projects CSR / callgraph / centrality / blast-radius / CFG–PDG; see docs/analysis-architecture.md.
  • Languages: crates/rgctl-lang-* + rgctl-plugin-api; register in languages.toml.

Starting context & performance policy

Applies to all extraction / language / discover hot-path work (and OpenSpec *-extraction-depth / add-*-language-support changes).

Implementation model

  1. Async — existing tokio orchestration; offload CPU-heavy work.
  2. Parallel — discover file pool (rayon / workers).
  3. Streaming — incremental graph commit; match extraction spill/channel patterns.
  4. Idiomatic RustResult + thiserror; follow rgctl-lang-java / rgctl-extraction conventions.

Cold profile (mandatory for scale / perf claims)

  1. Release binary only: cargo build --release --bin rgctl
  2. Delete artifacts: rm -rf <corpus>/.rgctl/
  3. Run from inside the corpus (cd example/<corpus> && rgctl discover . -v) — positional . sets session root; -r is ignored when . is passed.
  4. Logging: RUST_LOG=info,profile=info

Deep stage timings and reference machine notes: docs/internal/profile.md · corpora: example/README.md.

Gate A — cross-language regression

CorpusTest gateDiscoverBaseline (ref M3 Pro, +10%)
Linux kernellinux_cold_discover_within_baselinedefault145 s wall
cargo build --release --bin rgctl
cargo test --release --test cold_profile_gates linux_cold_discover_within_baseline -- --ignored --nocapture

Gate B — language-scale (~10k source files)

Language changes add (or document) a language-filtered cold discover on a ~10k-file corpus. Record wall_secs, nodes, functions, index_graph_build from [profile] discover summary; add a gate in tests/cold_profile_gates.rs once baselined (+10%).

Fetch: ./scripts/fetch-profile-repos.sh

LanguageCorpusPathDiscoverEnv override
CLinuxexample/linuxdefaultRGCTL_LINUX_REPO
C++LLVMexample/llvm-project-l cpp on clang/RGCTL_LLVM_REPO
C#Roslynexample/roslyn-l csharp on src/RGCTL_ROSLYN_REPO
GoKubernetesexample/kubernetes-l go on pkg/ cmd/
Javametasfreshexample/metasfresh-4.9.8b--fullMETASFRESH_REPO
JavaScriptNode.jsexample/node-l javascript on test/RGCTL_NODE_REPO
PHPMagento 2example/magento2-l phpRGCTL_MAGENTO2_REPO
PythonHome Assistantexample/home-assistant-l pythonRGCTL_HOME_ASSISTANT_REPO
RubyDiscourseexample/discourse-l ruby
Rustrustcexample/rust-l rustRGCTL_RUST_REPO
TypeScriptVS Codeexample/vscode-l typescript on src/RGCTL_VSCODE_REPO

File counts are approximate (goal O(10⁴) sources). Exclude vendor/, node_modules/, target/, third_party/.


Profiles, tests, and benches

Cargo profiles

ProfileWhen
default / devIterate, unit tests
--releaseDiscover wall times, cold gates, any published timing
cargo bench ([profile.bench])Criterion microbenchmarks

Tests (run what you touched)

KindCommandPractice
Workspacecargo testDefault before merge for touched crates
Release CLI goldenscargo test --release --test subprocess_golden_path (and related)CLI surface changes
Cold profile gatescargo test --release --test cold_profile_gates -- --ignored --nocapture --test-threads=1Perf / extraction / ingest; Gate A for scale-sensitive work
Dashboard / langdashboard_*, langfeature / ecommerce fixture testsWhen that path changes
Corpora./scripts/fetch-profile-repos.shBefore ignored gates needing example/

Warm or partial .rgctl/ invalidates cold timings.

Benches

TargetCommand
Workspacecargo benchparsing, graph, graph_benchmarks, analysis_benchmarks, centrality_benchmarks, community_benchmarks, blast_radius_benchmarks
Snapshot diffcargo bench -p rgctl-graph --bench snapshot_diff

Baselines and notes: docs/internal/profile.md.


Must-read documents

DocWhy
docs/analysis-architecture.mdGraph tiers, spill, CSR
docs/design/blast-radius-design.mdReachability / SCC
docs/internal/profile.mdCold profile deep dive
CONTRIBUTING.mdSetup, tests, PR norms
docs/contributor-checklist.mdLanguage / feature checklist
docs/guides/semantic-search.mdEmbedders (if touching semantic)
openspec/changes/_shared/starting-context.mdOpenSpec pointer (canonical policy is this file)

Build and day-to-day commands

cargo build --release --bin rgctl
./target/release/rgctl --version
cargo test

Dashboard UI changes:

./scripts/build-dashboard.sh   # or dashboard/ npm ci && npm run build
cargo build --release

Code-daemon / ONNX weights: git lfs pull when using that embedder feature.

Dogfood fixtures: rgctl-tests/ (e.g. ecommerce-*). Consumer agent pack: rgctl install --skill --with-commands --tools cursor.


See also