Metadata-Version: 2.4
Name: repo-context-optimizer
Version: 0.2.2
Summary: Deterministic repo context for coding agents: contract Trees, contract diffs, and a map checker. Installed with pip; works on Python, JavaScript, TypeScript, Go, Java, C#, Kotlin, PHP, Ruby, Swift, CSS, SQL, shell, PowerShell, Docker, Protocol Buffers, GraphQL, Python stub files, and Rust (partial).
License-Expression: MIT
Project-URL: Homepage, https://github.com/si4ai/repo-context-optimizer
Project-URL: Adopting rco, https://github.com/si4ai/repo-context-optimizer/blob/main/docs/guide/adopting-rco.md
Keywords: python,javascript,typescript,go,java,csharp,kotlin,php,ruby,swift,css,sql,shell,powershell,rust,docker,protobuf,graphql
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 2 - Pre-Alpha
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: tokens
Requires-Dist: tiktoken; extra == "tokens"
Provides-Extra: test
Requires-Dist: pyyaml==6.0.3; extra == "test"
Dynamic: license-file

# repo-context-optimizer

`rco` gives a coding agent a map of a repo as one JSON object: the signatures of each file, how modules fit together, and the parts of a file that changed. No model, no keys, and no network except tiktoken's one-time encoding download when the tokens extra is installed. Install with `pip install repo-context-optimizer`.

Bugs and requests: https://github.com/si4ai/repo-context-optimizer/issues

## Languages

Works on Python, JS/TS, Go, Java, C#, Kotlin, PHP, Ruby, Swift, CSS, SQL, shell, PowerShell, Docker (Dockerfiles and Compose files), C and C++, COBOL, Terraform and OpenTofu, Protocol Buffers, GraphQL, Python stub files, Vue, Svelte and Astro components, and Rust. You install it with pip, but it reads any repo.

Each row below says what the map holds, which imports become Forest edges, which files `rco tests` takes for tests, what a `--passed` record tells apart, and what was measured. Everything is read from `src/rco/lang`, `src/rco/registry.py`, the [test environments guide](docs/guide/test-environments.md) and the [support matrix](docs/support-matrix.md).

**What `--passed` always keys on.** 0.1.9 keyed a record on the git tree only. Since 0.2.0 a record also carries a digest of the test environment: os, arch, libc, os version, container image (`none` outside a container; inside one rco needs `RCO_CONTAINER_IMAGE` or podman's image id, else every test runs), the CI matrix leg, `TZ`, `LC_ALL` and `LANG`, plus the per-language parts in the table. A record from another environment, an old record with no digest, or an environment rco cannot read gives the usual selection and skips nothing. Python, Go, JS/TS and Rust narrow to test functions (`path::name`) when a test names a changed function, measured on the selection fixtures at `f48a51e` (2026-12-04, America/Los_Angeles); Java narrows in a probe but no fixture mutation reaches it. Every other language selects whole test files.

| Language | Map: what is extracted | Imports and edges | `rco tests`: test files, and what the pass record also tells apart | Measured savings |
|---|---|---|---|---|
| Python | Public classes, functions, methods with signatures, type hints and first docstring line; `UPPER_CASE` constants; annotated fields; `__all__`; argparse commands and flags; HTTP routes | `import` and `from ... import`, relative too, by longest in-repo dotted name; stdlib and third party ignored | `test_*.py`, `*_test.py`; test-function selection.<br>Record: `python` (or `python3`) and in-tree `.venv`, `venv`, `.tox/*`, `.nox/*`: version, flags, the declared dependency closure as installed, `.pth` and editable sources; `PYTHONHASHSEED`, `PYTHONOPTIMIZE`, `PYTHONPATH`, `PYTEST_ADDOPTS` | django 3.3% total, -0.1% median, 4/0/6; transformers 36.4% total, 28.5% median, 10/0/0 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: django 3.4%, transformers 36.5%). Older pack figure, not comparable: django 57.3%, transformers 86.3% at `8730f35` |
| JavaScript and TypeScript | exported names (every top-level name not starting with `_` in a script) | `import ... from`, `export ... from`, `require("...")`, `import("...")` with a literal; relative paths (extension, `index`, `.js` to `.ts`) and workspace packages by `package.json` name. `tsconfig` path aliases are not read | `*.test.*`, `*.spec.*`, `__tests__/`.<br>Record: `node --version`, `NODE_OPTIONS`, `NODE_ENV`, `NODE_PATH`, the Bun or Deno version when the tree has their files (a Bun-only or Deno-only runner stays detected); lock: `package-lock.json`, `npm-shrinkwrap.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lock`, `bun.lockb`, `deno.lock`, else the packages in `node_modules`, Yarn Plug'n'Play's `.pnp.cjs`, and linked packages' files | vite 60.8% total, 61.9% median, 7/3/0 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: vite 61.0%). Older pack figure, not comparable: vite 77.4% at `8730f35` |
| Go | exported (capitalized) names | `import "..."` and import blocks, resolved through `go.mod` module paths to one file of the package (the first non-test file by name). `rco tests` still reaches the other files and `_test.go` of that package (0.2.1) | `*_test.go`.<br>Record: `go version`, `go env` (GOOS, GOARCH, CGO_ENABLED, the `CGO_*FLAGS`, GOFLAGS, GOEXPERIMENT, CC and more), `GODEBUG`, `GOWORK`; lock: `go.sum`, else `go list -m all` or the modules `go list -deps -test` uses | cli/cli 70.2% total, 0.2% median, 4/0/6 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: cli/cli 70.5%). Older pack figure, not comparable: cli/cli 83.4% at `8730f35` |
| Java | `public` and `protected` classes, interfaces, enums, records, annotations with their methods, fields, constants | `import`, `import static`, wildcard imports, and same-package use, across source roots | `*Test`, `*Tests`, `*IT`, `*TestCase`, `Test*`, and files under `test/` or `tests/`.<br>Record: `java -version`, JAVA_HOME's JDK, Gradle and Maven property variables; lock: `gradle.lockfile` in every Gradle project; Maven: `mvn dependency:list`; Gradle without locks is not detected, so tests run | guava 58.5% total, 65.3% median, 8/0/2 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: guava 58.6%). Older pack figure, not comparable: guava 82.6% at `7cbc034` |
| C# | `public` and `protected` types (class, struct, interface, enum, record, delegate) with methods, properties, fields, events, constants | `using`, `global using`, `using static`, aliases, by namespace; `<ProjectReference>` in `.csproj` | `*Test`, `*Tests`, `*TestCase`, `*Fixture`, files under `test/` or `tests/`, `*.Tests`, `*.Test` and `*.UnitTests` projects.<br>Record: `dotnet --version`, `dotnet --list-runtimes`, roll-forward, host environment and globalization variables; lock: `packages.lock.json` in every project, else `dotnet restore` and `dotnet list package` | Newtonsoft.Json 63.7% total, 69.8% median, 10/0/0; serilog 36.2% total, 38.0% median, 7/0/3 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: Newtonsoft.Json 63.8%, serilog 36.6%). Older pack figure, not comparable: Newtonsoft.Json 78.5%, serilog 60.6% at `7cbc034` |
| Kotlin | classes, interfaces, objects, enums, type aliases; top-level functions and properties; extension functions; anything not `private` or `internal` | `import`, wildcard, `as` aliases, and same-package declarations; Java files too | `*Test`, `*Tests`, `*IT`, `*TestCase`, `*Spec`, files under `test/` or `tests/`, `*Test` source sets.<br>Record: as Java | okhttp 28.3% total, 31.9% median, 7/0/3, Java and Kotlin together (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: okhttp 29.3%). Older pack figure, not comparable: okhttp 70.7% at `7cbc034` |
| PHP | Top-level functions and constants; classes, interfaces, traits, enums with `public` and `protected` members | `use` (also `function` and `const`), `require` and `include` with a literal path, `composer.json` PSR-4 `autoload` and `autoload-dev` | `*Test`, `*Tests`, `*TestCase`, files under `test/` or `tests/`.<br>Record: `php -v`, `php -m`, every effective ini setting, `PHP_INI_SCAN_DIR`, `PHPRC`, `XDEBUG_MODE`, `XDEBUG_CONFIG`; lock: `composer.lock`, else `composer show --no-interaction` | laravel/framework 19.8% total, 27.1% median, 8/0/2 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: laravel/framework 21.1%). Older pack figure, not comparable: laravel/framework 62.4% at `7cbc034` |
| Ruby | classes and modules by full constant path with methods, attributes, aliases, constants; `private` and `protected` honored | `require`, `require_relative`, `load`, `autoload` with literal paths or `__dir__`/`__FILE__` joins; load paths from Gemfile, gemspec and Rakefile; constant references | `*_spec.rb`, `*_test.rb`, `test_*.rb`, files under `spec/` or `test/`.<br>Record: `ruby -v`, `RUBYOPT`, `RUBYLIB`, `GEM_HOME`, `GEM_PATH`, `BUNDLE_*`, Bundler's `.bundle/config`; lock: `Gemfile.lock`, else `gem list` and `bundle list` | rubocop 23.1% total, 9.3% median, 7/0/3 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: rubocop 23.5%). Older pack figure, not comparable: rubocop 38.7% over 317 commits at `11afa3c` |
| Rust | `pub` items | The crate module tree as rustc builds it: `mod x;` (`x.rs`, `x/mod.rs`, inline, `#[path]`), `use` with `crate::`, `self::`, `super::`, child modules, workspace crates and brace groups, `pub use` re-exports. Files no crate root reaches use the directory rule. ripgrep `3e85c6c`: 78 of 105 files have an edge (37 of 105 on 0.1.8) | `.rs` files directly in `tests/` or `test/`; inline unit tests have no file of their own.<br>Record: `rustc -vV`, the rustc and rustdoc flag variables, the target, `RUSTC` and its wrappers, `RUSTUP_TOOLCHAIN`, `CARGO_TARGET_*`, `CARGO_PROFILE_*`, cargo config files outside the tree; lock: `Cargo.lock`, else `cargo metadata` | ripgrep 35.3% total, 49.3% median, 6/3/1 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles; 0.2.1 `b1a9eb1d` gives the same) |
| Swift | classes, structs, enums, protocols, actors, extensions, type aliases, functions, methods, `init`, `subscript`, properties; `open`, `public` or `package` | `import Module` (also `@testable` and kind imports), resolved to `Package.swift` targets (default `Sources/<Target>`), else to the files that declare the module | `*Test`, `*Tests`, `*Spec`, files under `Tests/`, `tests/`, `Test/` or `test/`.<br>Record: `swift --version`, `DEVELOPER_DIR`, `SDKROOT`; lock: `Package.resolved`, else the pins `swift package resolve` writes; no root `Package.swift` is not detected | Alamofire 37.0% total, 40.5% median, 9/0/1 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: Alamofire 37.6%). Older pack figure, not comparable: Alamofire 56.6% over 100 commits at `14467c9` |
| CSS | Top-level rules and at-rules by selector or prelude; custom properties of `:root`, `:host` and `html` | `@import` and `url()` | no test file pattern, so tests run under another language.<br>Record: nothing of its own | pdf.js CSS-only 40.1% at `39d574ca`; the-mill Wall 0%; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| SQL | Tables, views, columns, indexes, procedures and functions from MySQL, PostgreSQL and SQLite DDL | none: SQL files import nothing | no test file pattern.<br>Record: nothing of its own; `rco verify --schema` reads a SQL dump | not measured at `f48a51e`: no pinned repo in the 0.2.2 set |
| shell | Functions | `source` and `.` | no test file pattern; a script a test names by path is a reader.<br>Record: nothing of its own | nvm 0.0% total, 0.0% median, 0/10/0, every commit a skip (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles, `rco map` JSON plus changed files; 0.2.1 `b1a9eb1d` same method: nvm 0%). Older pack figure, not comparable: nvm 0% at `8730f35` |
| PowerShell | Functions | dot-sourcing and `Import-Module` | no test file pattern.<br>Record: nothing of its own | not measured at `f48a51e`: no pinned repo in the 0.2.2 set |
| Docker | Dockerfile stages, base images, `COPY`/`ADD`, `RUN`, `ARG`/`ENV`, `ENTRYPOINT`/`CMD`; Compose services, `build`, `image`, `depends_on`, with `x-` anchors and merge keys | `COPY`/`ADD` sources, Compose `build` to its Dockerfile, `env_file`, `include`, `extends` | no test files of its own: a change selects every test when CI, the top-level Makefile or a test file uses containers, else the tests that read the file.<br>Record: in a container, each `FROM` and Compose image by digest (`@sha256:` pinned, else `crane`, `skopeo` or `docker buildx imagetools`; one that none resolves is not detected, so tests run); outside one, a fixed value | awesome-compose Docker only 18.0% (median of arms) at `8730f35` and `0b2fd01`; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| Protocol Buffers | package, import, options, message fields, enums, services and rpcs | `import` paths; tests reach the file through generated stubs | tests that reach it through generated stubs, or every test when no other language reaches it.<br>Record: `protoc --version` and `buf --version` (`absent` when missing), well-known types beside `protoc`; `PROTOC`, `PROTOC_INCLUDE` | feast 66.0% total, 87.7% median at `1c6641b36`; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| GraphQL | top-level type, input, query, mutation, fragment by name | `#import`; graphql-codegen outputs link their schema and documents | test selection as for Protocol Buffers.<br>Record: nothing of its own; graphql-codegen is a JavaScript package the JS lock already keys | not measured on a public repo; not remeasured at `f48a51e` |
| Stub files (`.pyi`) | Python members in a SRCMODULE | beside the `.py`, or alone for a compiled module; a type-checker test links every `.pyi` | test selection as measured on numpy.<br>Record: nothing of its own; mypy is a Python package the Python probe already keys | numpy 4.2% total, 1.1% median at `660310cc4d`; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| C and C++ | header declarations: functions, classes and their public members, structs, enums, typedefs, `#define` macros | `#include` (beside the file, then include directories CMake, Makefile `-I` or meson name, then `include/` and `src/`), a header's same-stem source, the files one CMake command builds | `test_*`, `*_test`, `*-test`, `*_tests`, `*_unittest`, `*Test`, `*Tests`; every test when CI, the top-level Makefile or a test file runs a script suite (`runtest`, `tclsh`, `bats`, `pytest`, `prove`).<br>Record: `cc --version`, `c++ --version`, `CC`, `CXX`, the flag and search-path variables, `CMAKE_BUILD_TYPE` and the other CMake variables; lock: `conan.lock`, `vcpkg-lock.json`, else not detected (runs) | redis 54.4% total, -36.9% median, 2/0/8 (last 10, `f48a51e`, 2026-12-04 America/Los_Angeles; 0.2.1 `b1a9eb1d` gives the same); test selection on fmt `50ba042`, newest 120 commits: 0 misses (28 commits were false skips before) |
| Terraform and OpenTofu | variables with type and default, outputs, module calls with source and version, resources, data, locals, required providers; `terraform test` runs | `var.`, `local.`, `module.`, `data.` and resource references to the declaring file of the same module, local module sources, `${path.module}` files, a test file to the module it runs against | `*.tftest.hcl`, `*.tofutest.hcl`: the test files that reach the change; every test when Terratest, kitchen-terraform or Python `tftest` drive it.<br>Record: `terraform version -json`, `TF_CLI_ARGS*`, `TF_VAR_*`, `TF_WORKSPACE`, `TF_CLI_CONFIG_FILE`, `probe:terraform` (remote modules); lock: `.terraform.lock.hcl` in each tested module, else not detected (runs) | terraform-aws-eks 60.8%, aws-ia/terraform-aws-vpc 57.1% (median of arms, Terraform only) at `8730f35` with Terraform grafted on; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| COBOL | programs with `USING`/`RETURNING`, paragraphs and sections, `ENTRY` points, level 01 and 77 data items with their PIC; fixed and free format | `COPY` to the copybook, `CALL "name"` and `EXEC CICS LINK`/`XCTL` through `PROGRAM-ID` | the tests that read the file; every test when CI or a test file runs `cobolcheck`, `zunit`, `runtest`, `bats`, `pytest` or `prove`.<br>Record: `cobc --version`, `COB_COPY_DIR`, `COBCPY` and the other `COB_*` variables; no lock to read | carddemo 76.5% (median of arms, 7 commits) at `59cc6c2`; cobol-programming-course 44.4% (66 commits) at `780b1c9`; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| Vue, Svelte and Astro | script exports; a `component` node with props and events | `<script>` and Astro frontmatter imports, `src=` blocks, `<style>` `@import` | no component test-file pattern of its own: the JS/TS tests that import them run under the JavaScript row.<br>Record: nothing of its own; `node --version` and the JS/TS locks key them | component files only: element-plus 30.3%, starlight 12.8%, skeleton 4.5% at `8730f35` plus lang/sfc; not remeasured at `f48a51e`: no pinned repo in the 0.2.2 set |
| any other language | the file shows by path | none | none | not measured |

Token density per language (node kinds, `sig`, `doc`, `lines`, and what each command supports) is in [Commands by language](#commands-by-language). How the digest is built: [test environments](docs/guide/test-environments.md). Each sha and source: [support matrix](docs/support-matrix.md).

Two things set rco apart from grep, ctags and other search tools:

- **Token density: the agent reads only the fields it needs.** rco answers with a JSON object, so an agent takes `parts`, a signature or a line range and skips the rest. The map may hold more than a task needs, which is safer than holding too little and scanning again. grep and similar tools print lines, and an agent reads that output top to bottom, then often searches again.
- **The measure is tokens to finish a task, not the size of one command's output.** A short grep output that leads to rereading files and more searches can cost more in the end. rco is judged by the tokens an agent spends to complete a task with it and without it: [the proof](#the-proof-tokens-to-finish-a-task).

### If you are an agent

## rco: look up the map before the code
- Run `rco map --preload` once per checkout.
- Before you read code, run `rco map --for FILE...` for the files you will touch. It prints JSON.
- Do not read a source file top to bottom: `parts` has each `--for` file's nodes and what `changed` against `base`. Open the file only to edit at the part you looked up.
- The map is JSON, not text to grep: look things up with `rco map --get NAME`, `--search REGEX` or `--list [KIND|PATH]` (each returns a list). Open a raw file only when the map does not answer.
- If `built.behind` is not 0, run `rco map --preload` and map again; read any file in `built.differs` directly. If `built.source` is `worktree`, the map already has those uncommitted edits.
- To test a change, run `pytest $(rco tests BASE HEAD --list)` instead of the full suite.
  By default that is the direct set: only the tests that directly reach the change. Add `--cautious` (or `cautious = true` under `[tests]` in `rco.toml`) when nothing runs the full suite later; it widens wherever rco is unsure. [How selection can miss a failure](docs/guide/test-selection.md) lists every way, with what catches each.
- After a compaction, rerun `rco map --for FILE...` instead of rereading the files.

## The proof: tokens to finish a task

An agent that has to change a file usually greps for names, then reads whole files to see the signatures around them; most of those tokens go to finding its way, not editing. So rco is measured by the tokens an agent spends to complete a task with rco and without it (grep, ctags and reading files), counting rereads and repeated searches, and whether the answer is right.

Five tasks on rco's own history at release/0.2.1 `c082ebd1d7a1`, tiktoken `o200k_base`, printed by `rco baseline --tasks`. This is a **modeled agent, not a live agent run**: rco is charged only for the JSON fields the task reads plus any follow-up file slices; grep or git for its full stdout plus re-scans and follow-up slices. Which fields a task reads is a judgement fixed in the code. Truth answers come from git or ctags, never from rco. The run, its inputs and limits: [docs/baseline/rel021-tasks-c082ebd.md](docs/baseline/rel021-tasks-c082ebd.md). Run it on your repo with `rco baseline --tasks`.

| task | tokens rco | tokens grep / git | right? |
|---|---|---|---|
| T1 find a definition and open it | 330 | 432 | both; reading the definition (303) is most of each |
| T2 which tests to run for a commit | 408 | 3,325 | both include the test the commit changed; rco lists 57 test files, grep 75 |
| T3 can a branch merge onto another | 9 | 23 | both; the git side is the truth |
| T4 contract changes of a commit | 392 | 314 | both cover the 7 public definitions that changed |
| T5 merge order of two branches | 66 | 83 | both; the git side is three merge-tree calls |

On this one commit and branch pair rco cost less on T1, T2, T3 and T5 and more on T4. What rco prints is often much more than what the task reads (T5: 66 used of 12,128 printed): the map offers more, and the modeled agent reads the fields it needs. `rco baseline --grep` is not that measurement: it estimates, per commit, the outlined parts of the files that commit changed against `ctags -x` plus a grep of those files, with no callers, field-selective reads, follow-up reads or multi-step tasks. The earlier modeled run at 0.1.9 is kept in [docs/baseline/rel019-c58e371-task-cost.md](docs/baseline/rel019-c58e371-task-cost.md).

Earlier estimates, from the replay definition at rco `8730f35` (changed files plus their one-hop imports, budget 12000, tiktoken `o200k_base`): what an agent would read per commit with and without rco, not a run of an agent on a task. They have not been remeasured with `rco baseline`. Source: [the `8730f35` comparison](docs/baseline/main-8730f35-compare.md).

- **Saved 45% to 65% of tokens on our own repos** since 1 Nov 2026 (win/tie/loss): md2xarticle `e0eee6f` 45.2% (18 commits, 13/5/0), this repo 62.5% (149, 121/20/8), the-mill `f6daf98` 64.8% (298, 205/88/5). **rco lost on 13 commits**, all after the same-folder import change, where the map followed those imports and cost more than reading the files.
- **grep and ctags saved more on the same commits.** Where rco sent a map, % saved for rco / aider's map at rco's size / ctags / grep of changed names: this repo (129 commits) 63.7 / 63.7 / 67.8 / 71.0, the-mill (210) 71.1 / 71.2 / 71.5 / 73.5. ctags and grep there borrowed rco's import graph and changed-name list, so a compact outline, not rco alone, is what saves the tokens.
- **Not measured: a live agent's tokens to finish a task, and whether it does the task better.** The task table above is a model of an agent.

What each command prints next to the grep, git or ctags sequence it replaces, with right-or-wrong checks and timings, is an appendix: [output size per command, not task cost](docs/baseline/rel019-c58e371-task-cost.md#appendix-output-size-not-task-cost). Grep often prints less per command; that is not what a task costs.

## 30-second start

```
pip install "repo-context-optimizer[tokens]"   # tiktoken adds real token counts
cd your-repo
rco baseline                    # does it help on your repo? estimates your last 10 code commits
rco baseline --grep             # the same commits, estimated for grep plus ctags
rco map --for src/cli.py        # what an agent looks up before editing src/cli.py
rco init --agents               # point AGENTS.md and similar files at `rco map`
```

**CI runs only the tests that matter, and never reruns tests that already passed on the same code.** `rco tests` picks the tests a change can reach; with `--passed` it picks nothing when the tree under test already passed, and only the tests for what changed since when it did not. It keys on the git tree, so squash, rebase and merge commits, a merge queue, and the push after a merge all get it. On this repo, PR #190's merge-queue run ran 934 tests in 4m45s after its pull request had passed them; its base had moved 6 files since, and with the pull request's record `rco tests --passed` selects 48 test files (197 test IDs) for that run. `rco init --ci-tests` writes the workflow. Setting rco up for a team repo: [adopting rco](https://github.com/si4ai/repo-context-optimizer/blob/main/docs/guide/adopting-rco.md), then [GitHub setup](docs/github-setup.md).

## Commands

Ten commands, no setup: the map is built from git and cached in `.rco/` as it is read. Every command prints JSON by default and also takes `--repo PATH` (default `.`), `--format json|markdown` (markdown renders the same object) and `--out FILE`.

```mermaid
flowchart LR
    rco((rco)) --> map["map<br/>--for --list --search --get<br/>--preload --clear --name"] & tree["tree<br/>--for"] & forest["forest"]
    rco --> diff["diff<br/>--staged --worktree"] & tests["tests<br/>--staged --worktree<br/>--ignore --list<br/>--passed --record"] & mc["merge-check<br/>--onto --base --head<br/>--order --planned"]
    rco --> suspects["suspects<br/>--diff --staged --worktree<br/>--min-confidence --ignore<br/>--scope --strict"] & baseline["baseline<br/>--last --since --grep<br/>--pr --max-files --tasks"] & verify["verify<br/>--schema --openapi<br/>--help-text"] & init["init<br/>--agents --hooks --remove-hooks<br/>--metrics --ci-tests<br/>--no-config --no-ci"] & fp["fingerprint<br/>--call --key --keys-from<br/>--dir --generate"]
```

| Command and flag | what it does | what it is for |
|---|---|---|
| `rco map` | the repo map at a commit (default `HEAD`) as JSON: the Forest plus every Tree; fills the cache as it reads | an agent's first look at a repo |
| `--for FILE...` | only the modules that own those files and their neighbors, the signatures of the files they import, and each file's `parts` and what `changed` | before editing: what to know about those files without reading them |
| `--list [KIND\|PATH]` / `--search REGEX` / `--get NAME` | nodes from the map as a JSON list, filtered by kind or path, by name pattern, or by exact name | looking a name up instead of grepping |
| `--preload [--name NAME]` | builds and stores the map for a commit ahead of time and moves a named pointer (default `main`) | warming the cache in CI or after a merge |
| `--clear [--name NAME]` | empties this repo's cache (Trees, prose, pointers); never touches git or sources | starting the cache over |
| `rco tree` | the Trees (signatures) of a commit | reading a module's contract |
| `--for PATH...` | only the modules that own those paths | narrowing to one area |
| `rco forest` | how the modules fit together at a commit | seeing the shape of a repo |
| `rco diff` | added, removed and changed signatures, flags, columns and routes between two commits, with callers | reviewing what a change does to its contract |
| `--staged` / `--worktree` | diffs the index or the working tree against `HEAD` | checking edits before you commit |
| `rco tests` | the tests that can see the changes between two commits, through imports and file names | running only the tests a change can affect |
| `--staged` / `--worktree` | uses the index or working tree as the head | picking tests before you commit |
| `--ignore GLOB` | drops changed paths no test reads (repeatable) | keeping data-only changes from running everything |
| `--list` | the pytest node IDs a change reaches (or whole test files), one per line | feeding `pytest` in CI |
| `--record` / `--passed RECORD` | `--record` names `HEAD`'s tree, parents and environment digest; `--passed` (repeatable) takes records of trees that passed in this environment: none when `HEAD`'s tree is one, else the diff from the nearest, else `BASE` | never rerunning tests on code that already passed |
| `rco merge-check` | per `BRANCH` given: text conflicts onto `--onto` (default branch), and whether it uses what this PR (`--base`..`--head`) changed; exit 1 only on a text conflict | knowing before a merge which branches break |
| `--order` | for two or more branches: what each changes that another uses, and a safe merge order | planning the order of several merges |
| `--planned FILE` / `--card NAME` / `--others FILE` | a card's planned file list (FILE, or - for stdin) and, with `--others`, the other cards' lists: a hint of overlap with those lists and the BRANCHes; never blocks | seeing overlap at claim time |
| `rco suspects` | lines worth a second look in a commit: file, line, which of 11 signs (hidden execution, obfuscation, install hooks, auth backdoors, trigger conditions, network, exfiltration, process and file abuse, supply chain, weakened checks, out-of-place code) and why; candidates, never a verdict | reading code you did not write; see [rco suspects](#rco-suspects-lines-worth-a-second-look) for what it cannot find |
| `--diff [BASE [HEAD]]` / `--scope GLOB` | only the lines a change adds, plus a check removed, a power gained, a lock file alone, vendored edits; `--scope` flags changed files outside the paths the change states | reviewing a pull request |
| `--min-confidence low\|medium\|high` / `--ignore GLOB` / `--strict` | the lowest confidence listed (default medium); paths not read (repeatable); exit 1 when anything is listed (default exit 0) | tuning noise, and gating CI |
| `rco fingerprint` | one hash per key of a function's output over a fixed corpus (`--call MODULE:FUNCTION`, `--key`, `--dir`, `--generate`), printed as JSON | letting `rco tests` skip a shared module's dependents when its output did not change (`[[tests.fingerprint]]`) |
| `rco baseline` | per-commit token estimate of the outlined changed parts over the last 10 code commits | finding out whether rco helps on your repo |
| `--last N` / `--since DATE` | which commits to estimate | A longer window, or a roll-up since a date |
| `--grep` | the same commits estimated for one fixed ctags plus grep run | comparing rco with grep on your own history |
| `--pr N` | the commits of pull request N | measuring one pull request in CI |
| `--max-files N` | skips commits that change more code files (default 50) | keeping bulk changes out of the estimate |
| `--tasks` | tokens to finish five fixed tasks, rco against grep or git, each with a truth answer; a modeled agent, not a live run | measuring tokens to finish a task, not only a commit outline |
| `rco verify` | compares the map with real outputs you captured; exit 1 on a mismatch | proving the map matches the running system |
| `--schema` / `--openapi` / `--help-text CMD=FILE` | A SQL schema dump, an OpenAPI document, or a saved `--help` (repeatable) | checking tables, routes or CLI flags |
| `rco init` | writes `rco.toml` and a CI report job, keeping any file that exists | one-step setup |
| `--agents` | writes the agent block above into `AGENTS.md` and similar files | pointing agents at the map |
| `--hooks` / `--remove-hooks` | adds or removes a post-merge hook that preloads the map | keeping the cache warm locally |
| `--metrics` | adds a CI step that runs `baseline --pr` and uploads the report | tracking savings per pull request |
| `--ci-tests` | writes `.github/workflows/rco-tests.yml`: pytest on what `rco tests` selects, records each green tree, reads earlier records back | CI that runs only the tests that matter, once per tree |
| `--no-config` / `--no-ci` | skips `rco.toml` or the workflow | setting up only part |

```mermaid
flowchart LR
    G["git commit"] -->|"map reads a commit not stored yet: lazy fill"| S[("store in .rco/<br/>Trees keyed by content hash<br/>commits indexed by sha, named pointers")]
    G -->|"map --preload: fill ahead, move a pointer"| S
    C["map --clear"] -->|"empties Trees, prose, pointers; never git"| S
```
The cache: `map` fills it lazily, `--preload` fills it ahead, `--clear` empties it, and entries are keyed by content, so a rerun writes nothing new. Exit codes, JSON fields and examples are in [docs/commands.md](docs/commands.md).
## `rco suspects`: lines worth a second look

`rco suspects` reads a commit (or, with `--diff`, a pull request) and lists lines a reviewer should read twice: file, line, which of 11 signs it is, and why. Run it before you trust code you did not write, or as a CI step on a pull request.

**It cannot prove that code is safe.** An empty report does not mean the code is safe. It reads text shapes on one line at a time (and a few lines together), so it will not catch a well-hidden backdoor, logic that is only wrong in context, or a malicious dependency: it reads how dependencies are named, pinned and sourced, never the code inside them. Every finding is a candidate to read, not a verdict, and every report says so.

| Sign | What it looks for |
|---|---|
| 1 hidden-execution | `eval`/`exec` of built-up values, decode then run, unsafe deserialization, `Function(...)`, PowerShell `iex`, request input to an execute call |
| 2 obfuscation | packed or minified source, long escape runs, `chr()` chains, JSFuck-style text, mixed-script look-alike words, long encoded blobs, bidi and zero-width characters |
| 3 install-hooks | `curl ... | sh`, npm lifecycle scripts, `.pth` imports, `setup.py` that runs commands, in-tree build backends, `build.rs`, Composer hooks, workflow steps |
| 4 auth-backdoor | credentials and key shapes in source, a fixed value that always passes a credential check, fixed admin names, names such as `skip_auth` |
| 5 trigger-condition | code gated on a date, host name, user, environment value, day of week, random draw or run counter |
| 6 network | reverse-shell shapes, hard-coded public addresses, raw listeners, mining pools, DNS built from data |
| 7 exfiltration | reads of secret stores or the environment next to a send |
| 8 process-file-abuse | shell spawns and `sh -c`, world-writable or set-uid files, writes to startup places, `PATH` hijack |
| 9 supply-chain | unpinned or URL dependencies, names one edit from a popular package, lock file changed alone, vendored code edited, actions pinned to a branch |
| 10 weakened-check | TLS checks off, auth decorators removed, tests skipped or deleted, CI gate steps removed, `continue-on-error`, workflow write permission |
| 11 out-of-place | a file that gains network, process, dynamic-execution or secret-reading power it did not have, and a file outside the scope the change states |

Each finding has a confidence: `high` (rarely benign), `medium` (usually worth a look) or `low` (shown only with `--min-confidence low`). The default is `medium`. A file under a test path is one step lower, except the rules about tests themselves. The command exits 0 with findings; `--strict` exits 1 when anything is listed. `--ignore GLOB` skips paths (repeatable). It reads git objects only (`--staged` and `--worktree` read the index and the working tree), and the output is the same twice.

`--diff [BASE [HEAD]]` reads only lines the change adds. A line that moved, or a reformat, is not new. It adds what only a change shows: an auth check, a test or a CI gate step removed, a file that gained a power, a lock file changed without its manifest, vendored code edited, a test file deleted. `--scope GLOB` (repeatable) names the paths the change says it touches; any other changed file is listed.

### How well it works

The seeded cases are small files, each written from the shape of a public incident or a known class of backdoor, with the line and sign that should be found; the benign cases are look-alikes (a test password, an `eval` in a docstring, a config with a lock file). Precision is found / (found + false positives), counted per (file, line, sign). Recall counts only what was seeded, and the same authors wrote the rules and the seeds, so recall here is an upper bound. `tools/suspects_measure.py` reruns the tables below (`--set dev|held|diff|all`, `--min-confidence`), and a test fails if the README table no longer matches its output.

The held-out set (126 cases) was written after the rules were frozen at commit `76d98f0`, and its first run is the honest estimate. First run, medium or higher:

| sign | seeded | found | false positives | precision | recall |
|---|---|---|---|---|---|
| 1 hidden-execution | 16 | 13 | 2 | 0.87 | 0.81 |
| 2 obfuscation | 8 | 6 | 0 | 1.00 | 0.75 |
| 3 install-hooks | 7 | 7 | 1 | 0.88 | 1.00 |
| 4 auth-backdoor | 8 | 2 | 0 | 1.00 | 0.25 |
| 5 trigger-condition | 5 | 3 | 0 | 1.00 | 0.60 |
| 6 network | 8 | 6 | 0 | 1.00 | 0.75 |
| 7 exfiltration | 5 | 4 | 0 | 1.00 | 0.80 |
| 8 process-file-abuse | 15 | 13 | 2 | 0.87 | 0.87 |
| 9 supply-chain | 8 | 8 | 1 | 0.89 | 1.00 |
| 10 weakened-check | 9 | 8 | 0 | 1.00 | 0.89 |
| all | 89 | 70 | 6 | 0.92 | 0.79 |

That run found 19 misses and 6 false positives. After it, the rules were widened for the misses a general shape could fix (a socket word in `fsockopen`, `instance_eval`, `.then(eval)`, `__import__(...).system`, `skip_before_action`, a weekday gate, mining pools, `$(env)`, `reg add ... Run`, JSFuck text, mixed-script words), and narrowed after a review of real repos (below). The held-out set is therefore now a dev set too. Current numbers over all three sets (123 + 126 dev and held-out cases, 21 diff cases), tuned on all of them, medium or higher:

<!-- suspects-table:medium -->
| sign | seeded | found | false positives | precision | recall |
|---|---|---|---|---|---|
| 1 hidden-execution | 36 | 36 | 2 | 0.95 | 1.00 |
| 2 obfuscation | 22 | 22 | 0 | 1.00 | 1.00 |
| 3 install-hooks | 19 | 19 | 1 | 0.95 | 1.00 |
| 4 auth-backdoor | 17 | 13 | 0 | 1.00 | 0.76 |
| 5 trigger-condition | 10 | 9 | 0 | 1.00 | 0.90 |
| 6 network | 18 | 18 | 0 | 1.00 | 1.00 |
| 7 exfiltration | 9 | 9 | 0 | 1.00 | 1.00 |
| 8 process-file-abuse | 33 | 33 | 2 | 0.94 | 1.00 |
| 9 supply-chain | 18 | 17 | 1 | 0.94 | 0.94 |
| 10 weakened-check | 19 | 19 | 0 | 1.00 | 1.00 |
| 11 out-of-place | 2 | 2 | 0 | 1.00 | 1.00 |
| all | 203 | 197 | 6 | 0.97 | 0.97 |
<!-- /suspects-table -->

At `--min-confidence low` the same cases give more false positives, which is the point of the threshold (unpinned dependencies, environment gates, tag-pinned actions, debug flags and deleted tests are low by design):

<!-- suspects-table:low -->
| sign | seeded | found | false positives | precision | recall |
|---|---|---|---|---|---|
| 1 hidden-execution | 36 | 36 | 2 | 0.95 | 1.00 |
| 2 obfuscation | 22 | 22 | 1 | 0.96 | 1.00 |
| 3 install-hooks | 19 | 19 | 1 | 0.95 | 1.00 |
| 4 auth-backdoor | 17 | 13 | 1 | 0.93 | 0.76 |
| 5 trigger-condition | 10 | 10 | 2 | 0.83 | 1.00 |
| 6 network | 18 | 18 | 5 | 0.78 | 1.00 |
| 7 exfiltration | 9 | 9 | 3 | 0.75 | 1.00 |
| 8 process-file-abuse | 33 | 33 | 5 | 0.87 | 1.00 |
| 9 supply-chain | 18 | 18 | 15 | 0.55 | 1.00 |
| 10 weakened-check | 19 | 19 | 0 | 1.00 | 1.00 |
| 11 out-of-place | 2 | 2 | 2 | 0.50 | 1.00 |
| all | 203 | 199 | 37 | 0.84 | 0.98 |
<!-- /suspects-table -->

Known false-positive kinds in the sets: a shell `eval` in a script that only builds a prompt, `eval` named in a docstring, an npm `postinstall` that only builds, and a color-name package. Two more are real shell spawns (a Gradle `sh -c` and a Go `exec.Command("/bin/sh")`) that the seeded case did not list, counted as false positives anyway. Known misses: credential gates that read a request field through a framework helper, a token split over two adjacent literals, a Django `DEBUG` branch that returns true, and a run counter that is not named like one.

On real code with no known malicious part (pytest, pip, pygments, packaging, pluggy, the-mill, md2xarticle and rco itself; 3,065 files), medium or higher gave 64 findings. Reading each one, 60 were the real shape in a place that is meant (`eval` in a test runner, `verify=False` in an SSL helper, a `systemctl enable` in an installer, a planted key in a fixture), and 4 were the wrong reading (a string that tells a user to run `bash -c`). A first pass over the same repos gave 191 findings. Reading them showed rule faults (names inside tables of built-in words, a rule that read `token == "with"`, `schtasks` in prose, comparisons with `CERT_NONE`, extras read as packages), which were fixed, so this review is tuned too. No repo here had a malicious part, so it says how noisy the report is, not how many bad lines it finds. Scanning rco's own seeded cases and rule source lists 174 findings at medium on purpose: those files hold the shapes.

Every language in the registry has at least one seeded case, and a test fails when one has none. The rules read text shapes shared by many languages and never branch on a language id (`tests/test_no_language_branches.py` applies). Cases that are not covered: vendored code that differs from its upstream (it needs the upstream copy, which is offline), look-alike letters inside a string, identifiers in non-Latin scripts, a one-line minified `package.json`, macOS- and Windows-specific persistence beyond the listed places, and anything split over more than a few lines.

## Commands by language

Every map node has `kind`, `name` and `path`, plus `sig`, `doc` and `children` where the language has them. `lines` is only for Python and stub files (`.pyi`) today. `rco map --for FILE` puts each file's nodes in `parts`. `rco baseline` uses those outlined parts for every language with an extractor. `rco init --ci-tests` writes a pytest workflow. `unknown` means not verified. Command cells (map, tree, forest, diff, tests, verify, merge-check, baseline) were measured fresh on rco `f48a51e`, 2026-12-04 (America/Los_Angeles): on a small polyglot sample repo (one class, function and test per language, plus a two-branch `merge-check`), on the contract fixtures and on pinned repositories. Savings cells were remeasured only for languages with a pinned repository in the 0.2.2 set; the rest keep their earlier figures and say why. Per-cell numbers, sources and the cells that could not be measured: [rco 0.2.2 remeasure](docs/baseline/rel-022-measure.md). The limits below, and how the digest is built: [support matrix](docs/support-matrix.md#commands-by-language) and [test environments](docs/guide/test-environments.md). Savings shas: [support matrix](docs/support-matrix.md).

| Language | map / tree nodes (`attrs.kind`) | `sig` | `doc` | `lines` | `forest` | `diff` callers | `rco tests` | `verify` | `merge-check` uses | scanner fingerprint key |
|---|---|---|---|---|---|---|---|---|---|---|
| Python | `pymodule`, `class`, `function`, `method`, `field`, `constant`; `command`, `flag`; `route` | type hints | first docstring line | yes | edges; entry points; owns commands and routes | yes, through imports, `self` and annotations | test functions (`path::test_fn`) | `--schema` no; `--openapi` and `--help-text` yes | yes | no key |
| JavaScript and TypeScript | `srcmodule`, `class` (class, interface, enum, type), `function`, `method`, `field`, `constant`; `command`, `flag`, `route` | types | leading comment | no | edges; `package.json` directories are modules | yes | test functions (`path::name`) when a test names the changed function, else whole test files | no | yes | `js` |
| Go | `srcmodule`, `class` (struct, interface, alias, impl, type), `function`, `method`, `field`, `constant`; `command`, `flag` (cobra, 0.2.2) | yes | leading comment | no | edges (an import still links one file of the package) | yes, including same-package tests | test functions (`path::TestName`) when a test names the changed function; other files and `_test.go` of the same package are whole test files (0.2.1) | no | yes (documented; same-package callers in `diff`) | `go` |
| Java | `srcmodule`, `class` (class, interface, enum, record, annotation), `method`, `field`, `constant`; `command`, `flag`, `route` | yes | leading comment | no | edges | yes | test functions (`path::method`) when a test body names a changed method (probe only; no fixture mutation reaches it), else whole test files | no | yes | `java` |
| C# | `srcmodule`, `class` (class, struct, interface, enum, record, delegate), `method`, `field`, `constant` | yes | leading comment, XML tags kept | no | edges | yes | whole test files | no | yes | `csharp` |
| Kotlin | `srcmodule`, `class` (class, interface, object, enum, annotation, typealias), `function`, `method`, `field`, `constant`; `command`, `flag`, `route` | yes | leading comment | no | edges | yes | whole test files | no | yes | `kotlin` |
| PHP | `srcmodule`, `class` (class, interface, trait, enum), `function`, `method`, `field`, `constant` | yes | leading comment | no | edges | yes for `->`, `?->` and `::` (sample at `f48a51e`: 2 callers) | whole test files | no | yes (`php/Use.php:open`) | `php` |
| Ruby | `srcmodule`, `class` (class, module), `function`, `method`, `field`, `constant` | parameter names | leading comment | no | edges | yes | whole test files | no | yes | `ruby` |
| Rust | `srcmodule`, `class` (struct, enum, trait, mod, type, impl), `function`, `method`, `field`, `constant`; `command`, `flag`, `route` | yes | leading comment | no | edges; `Cargo.toml` directories are modules | yes | test functions (`path::name`) in `tests/` files when a test names the changed function, else whole test files | no | yes | `rust` |
| Swift | `srcmodule`, `class` (struct, enum, protocol, actor, extension, typealias), `function`, `method`, `field`, `constant` | yes | leading comment | no | edges | yes | whole test files | no | yes | `swift` |
| shell, PowerShell | `srcmodule`, `function` | parameters (`()` in shell) | leading comment | no | edges | yes | none: no test file pattern | no | yes for PowerShell; shell not measured: the two-branch run changed no shell function | `sh` |
| CSS | `srcmodule`, `field` (rule or at-rule), `constant` (custom property) | none | file comment | no | edges | no callers (an added rule lists its own file line) | none: no test file pattern | no | file overlap only; no symbol uses | `css` |
| SQL | `table`, `view`, `column`, `index`, `procedure` | column types | leading `--` comment or COMMENT | no | none; owns tables and views | no callers; columns and tables change | a changed `.sql` file selects every test unless a code file names it | `--schema` yes | none found | no key |
| Docker | `srcmodule`, `class` (stage, service), `function` (CMD, ENTRYPOINT, HEALTHCHECK), `field`, `constant` | yes | none found | no | edges | no callers; `CMD` changes show | none of its own: every test when CI, the Makefile or a test uses containers, else tests that name the file | no | none found | `sh` |
| Protocol Buffers | `srcmodule`, `class` (message, enum, service, import), `field`, `method`, `constant` | fields and rpcs | none found (`//` comments not on nodes) | no | `import` edges; generated stubs depend on the `.proto` | added fields show; no callers found | tests through generated stubs, or every test when no other language reaches it | no | none found | `go` |
| GraphQL | `srcmodule`, `class` (type, input, interface, union, enum), `field` | yes: field types (5 of 13 fixture nodes, 4 of 7 on the sample) | file comment | no | `#import` edges | added types show; a field-only change does not (Trees hold top-level types only); no callers found | as Protocol Buffers; when no other language reaches it, every test runs | no | none found | `sh` |
| Stub files (`.pyi`) | Python members in a `srcmodule` (lang `pyi`) | type hints | file docstring | yes | beside the `.py`, or alone for a compiled module | yes; in this run callers were only inside the stub | a type-checker test links every `.pyi`; a Python test that imports the stub is selected | no | none found | no key |
| C and C++ | header declarations: functions, classes and public members, structs, unions, enums, typedefs, macros; a source file is its path and include edges | yes | file comment | no | `#include`, same-stem source, files one CMake command builds | yes, in including `.c` files and tests | `test_*`, `*_test`, `*-test`, `*_tests`, `*_unittest`, `*Test`, `*Tests`; every test when CI, the Makefile or a test file runs a script suite; a same-stem test was selected | no | yes | `c` |
| Terraform and OpenTofu | `variable` (FIELD), `output` (EXPORT), `module` / `resource` / `data` (CLASS), `run` (FUNCTION), `locals` (CONSTANT) | type and default on variables | variable `description` | no | references to the declaring file, local module sources, `${path.module}`, a test file to its module | variable changes show; no callers found | `*.tftest.hcl` or `*.tofutest.hcl` that reach the change; every test when Terratest, kitchen-terraform or Python `tftest` drive it | no | none found | no key |
| COBOL | `class` (program), `field` (level 01 / 77), `procedure` | program `USING` only (1 of 4 fixture nodes); none on the sample | program comment | no | `COPY`, `CALL` and `EXEC CICS LINK`/`XCTL` | procedure add/remove show; no callers found | the tests that read the file; every test when CI or a test file runs `cobolcheck`, `zunit`, `runtest`, `bats`, `pytest` or `prove` | no | none found | no key |
| Vue, Svelte and Astro | `class` (component), `field`, `function`, `constant`; an `interface` of props | yes | leading comment | no | `<script>` and frontmatter imports, `src=` blocks, `<style>` `@import` | export changes show; no callers found | no component test-file pattern; the JS/TS tests that import them are selected | no | none found | `js` |

The scanner fingerprint key is the key this repo's `[[tests.fingerprint]]` entry hashes for the scanner mode the language's extractor uses (`rco fingerprint` over `rco.lang.engine._scan`; the 13 keys are c, csharp, css, go, java, js, kotlin, php, ruby, rust, sh, swift and plain, the scan with no mode). A change only to the shared scanner whose hashes stay the same runs only the scanner's own tests; a language with a changed key runs the selected tests that name it. "no key": the language's extractor does not use the shared scanner, so the fingerprint never narrows for it. Measured on this repo: a refactor of the shared scanner that changes no output runs 2 test files instead of about 170. Per-language savings from the fingerprint are not measured: only this repo has a `[[tests.fingerprint]]` entry. The `rco tests` column was measured at `f48a51e`: Python, Go, JS/TS and Rust narrow to test functions on the fixtures and Java on a probe; the other languages run whole test files.

Limits measured at rco 0.2.1 (`fffa2a4e`) and rechecked at `f48a51e` (2026-12-04): a `.sql` change with no code-file name still selects every test. Go `rco tests` now selects other files and `_test.go` of the same package (0.2.1); an import edge still links only the first non-test `.go` file of the package by name. Stub files emit `lines`; other non-Python languages still do not. On ripgrep `3e85c6c` at rco `b1a9eb1d` and `f48a51e` (2026-12-04, America/Los_Angeles), 78 of 105 `.rs` files have an edge, and the last-10 replay saved 35.3% total, 49.3% median, 6/3/1, so Rust is shipped.

### Contract parity

What each language owes, from `src/rco/lang/contracts.py`, the source of record. `required` is emitted today, and `tests/lang/test_contracts.py` checks it on that language's fixture under `tests/fixtures/contracts`. `planned` is a contract the language has that rco does not emit yet; the same test fails when it starts to show, so the cell moves to `required` in that change. `n/a` is the count of items the language has no form of. The items: `src/rco/lang/contracts.py`.

<!-- contracts:begin (generated by tools/contracts_matrix.py; edit src/rco/lang/contracts.py) -->
| Language | required (emitted and tested) | planned (not emitted yet) | optional | n/a |
|---|---|---|---|---|
| Python | 21: `class`, `function`, `method`, `field`, `constant`, `command`, `flag`, `route`, `sig`, `doc`, `lines`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges`, `entry_points`, `owns.commands`, `owns.routes`, `test_functions` | 1: `deps` | none | 8 |
| JavaScript and TypeScript | 19: `class`, `function`, `method`, `field`, `constant`, `command`, `flag`, `route`, `sig`, `doc`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges`, `owns.commands`, `owns.routes`, `test_functions`, `vis` | 3: `lines`, `entry_points`, `deps` | none | 8 |
| Go | 16: `class`, `function`, `method`, `field`, `constant`, `command`, `flag`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.alias`, `edges`, `entry_points`, `owns.commands`, `test_functions` | 4: `route`, `lines`, `owns.routes`, `deps` | none | 10 |
| Java | 19: `class`, `method`, `field`, `constant`, `command`, `flag`, `route`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `edges`, `entry_points`, `owns.commands`, `owns.routes`, `test_functions`, `vis` | 2: `lines`, `deps` | none | 9 |
| C# | 12: `class`, `method`, `field`, `constant`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `edges`, `vis` | 9: `command`, `flag`, `route`, `lines`, `entry_points`, `owns.commands`, `owns.routes`, `deps`, `test_functions` | none | 9 |
| Kotlin | 20: `class`, `function`, `method`, `field`, `constant`, `command`, `flag`, `route`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges`, `entry_points`, `owns.commands`, `owns.routes`, `vis` | 3: `lines`, `deps`, `test_functions` | none | 7 |
| PHP | 12: `class`, `function`, `method`, `field`, `constant`, `sig`, `doc`, `shape.interface`, `shape.enum`, `shape.enum_members`, `edges`, `vis` | 9: `command`, `flag`, `route`, `lines`, `entry_points`, `owns.commands`, `owns.routes`, `deps`, `test_functions` | none | 9 |
| Ruby | 10: `class`, `function`, `method`, `field`, `constant`, `sig`, `doc`, `shape.struct`, `edges`, `vis` | 9: `command`, `flag`, `route`, `lines`, `entry_points`, `owns.commands`, `owns.routes`, `deps`, `test_functions` | none | 11 |
| Rust | 21: `class`, `function`, `method`, `field`, `constant`, `command`, `flag`, `route`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges`, `entry_points`, `owns.commands`, `owns.routes`, `test_functions`, `vis` | 2: `lines`, `deps` | none | 7 |
| Swift | 14: `class`, `function`, `method`, `field`, `constant`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges`, `vis` | 9: `command`, `flag`, `route`, `lines`, `entry_points`, `owns.commands`, `owns.routes`, `deps`, `test_functions` | none | 7 |
| C and C++ | 11: `class`, `function`, `field`, `constant`, `sig`, `doc`, `shape.struct`, `shape.enum`, `shape.enum_members`, `shape.alias`, `edges` | 7: `command`, `flag`, `lines`, `entry_points`, `owns.commands`, `deps`, `test_functions` | `method` | 11 |
| shell, PowerShell | 4: `function`, `sig`, `doc`, `edges` | 5: `command`, `flag`, `lines`, `entry_points`, `owns.commands` | none | 21 |
| Stub files (`.pyi`) | 13: `class`, `function`, `method`, `field`, `constant`, `sig`, `doc`, `lines`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `shape.alias` | 0: none | `edges` | 16 |
| Vue, Svelte and Astro | 6: `class`, `field`, `constant`, `sig`, `doc`, `edges` | 1: `lines` | `function`, `shape.interface` | 21 |
| CSS | 4: `field`, `constant`, `doc`, `edges` | 1: `lines` | none | 25 |
| SQL | 8: `table`, `view`, `column`, `index`, `procedure`, `sig`, `doc`, `owns.tables` | 1: `lines` | none | 21 |
| Docker | 5: `class`, `function`, `field`, `constant`, `sig` | 2: `lines`, `entry_points` | `doc`, `edges` | 21 |
| Protocol Buffers | 8: `class`, `method`, `field`, `sig`, `shape.struct`, `shape.enum`, `shape.enum_members`, `edges` | 2: `doc`, `lines` | `constant` | 19 |
| GraphQL | 9: `class`, `field`, `sig`, `doc`, `shape.struct`, `shape.interface`, `shape.enum`, `shape.enum_members`, `edges` | 1: `lines` | none | 20 |
| Terraform and OpenTofu | 7: `class`, `field`, `constant`, `export`, `sig`, `doc`, `edges` | 2: `lines`, `deps` | `function` | 20 |
| COBOL | 6: `class`, `field`, `procedure`, `sig`, `doc`, `edges` | 1: `lines` | none | 23 |
<!-- contracts:end -->

## Repo types and planned work

| Status | Languages and repo types | Token savings |
|---|---|---|
| 🗓️ upcoming, no date | A concept classifier for prose (`map --search` matches only node and module names today, so a prose phrase finds nothing); richer map nodes (signatures, imports, callers) and other optimizations in progress | not measured |
| ⚪ fallback, dropped | Any other language: the file shows by path. Dropped: none yet. A dropped language is a deliberate decision and is never deleted; each one is listed with `dropped_reason` (one line), `evidence` (path to the replay result), `dropped_on` (date) and `revisit_when`, the same four fields as [the concept taxonomy](docs/baseline/concepts.md). A language listed nowhere here is a real gap, to be added as planned | not measured |
| ✅ repo types | Single package, monorepo, polyglot, submodules (skipped with a note), LFS (opaque), empty repo | not measured by type |

- **Not measured:** the pass record's saving, and a live agent's tokens to finish a task.

## How rco is built

```mermaid
flowchart TB
    A["11 commands<br/>commands/: one Spec each"] --> B["Map layer<br/>core/: build, forest, diff, refs"]
    B --> S["Cache<br/>store/: SQLite, filled on read"]
    B --> C["File graph<br/>imports, edges"]
    C --> D["Language registry"]
    D --> E["lang/&lt;language&gt;/ on a shared engine"]
    E --> F["Shared base<br/>gitread, canon, model, output"]
```

Deterministic, one design for every language, checked in CI and with SPIN, and measured with losses counted: [docs/architecture.md](docs/architecture.md) has why, the layers and the module behind each command. Design, roadmap and process: [docs/design/](docs/design/).
## Documentation and license

[Commands](docs/commands.md), [support matrix](docs/support-matrix.md), [architecture](docs/architecture.md), [adopting rco](https://github.com/si4ai/repo-context-optimizer/blob/main/docs/guide/adopting-rco.md), [GitHub setup](docs/github-setup.md), [cloud agents](docs/guide/cloud-agents.md), [changelog](CHANGELOG.md). MIT; see [LICENSE](LICENSE).
