phrour-repograph
by Phrourios
README.md
<!-- phrourios:header:start -->
<p align="center"><img src="https://raw.githubusercontent.com/Phrourios/phrour-repograph/main/assets/banner.svg" alt="PhrourRepograph banner" width="100%"></p>
<p align="center">
<img alt="License: Proprietary" src="https://img.shields.io/badge/license-Proprietary-6F7C80">
<img alt="Python 3.11+" src="https://img.shields.io/badge/python-3.11%2B-3776AB">
<img alt="SEF 1.0" src="https://img.shields.io/badge/SEF-1.0-4FD6CF">
<img alt="Status: 0.1.0 release candidate" src="https://img.shields.io/badge/status-0.1.0-4FD6CF">
</p>
<!-- phrourios:header:end -->
# PhrourRepograph
A persistent cybersecurity graph of code and infrastructure, with deterministic queries.
PhrourRepograph indexes a repository into SQLite once, then answers three questions from the same
graph: what does this change reach, which tests cover it, and which security-relevant node sits
in the path.
Status: 0.1.0, published on PyPI. The Python, infrastructure, detection rule and document
indexers, the graph store, change impact, test selection, CLI and the dual-era MCP server work.
The MCP registry listing is pending.
<!-- phrourios:getting-started:start -->
<!-- phrourios:glance:start -->
## At a glance
| | |
| --- | --- |
| Input | A repository tree |
| Output | SQLite graph and deterministic query results |
| Engine | `phrour-repograph` 0.1.0 |
| License | All rights reserved (Soteria Solutions LLC) |
<!-- phrourios:glance:end -->
## Getting started
Requires Python 3.11 or later. The project has no runtime dependencies.
```bash
# from a checkout (development)
python3 -m pip install -e .
# from PyPI
uvx phrour-repograph --help
pipx install phrour-repograph
python3 -m pip install --user phrour-repograph
phrour-repograph --version
phrour-repograph --help
```
<!-- phrourios:getting-started:end -->
## Research question
Can one persistent graph, built from syntax and configuration without executing anything,
tell a security reviewer where a code or infrastructure change lands, and do it with answers
that stay the same from run to run and from agent to agent?
## What works
- Repository indexing into SQLite. The walk skips VCS, virtualenv and build directories, files
larger than 1 MiB, and private key or `.env` names. Unchanged files are skipped by SHA-256.
- The Python indexer: modules, classes, functions, test functions, imports, local calls, and
inferred attribute references. Each test node gets a `tests` edge to the modules it imports.
- The rules indexer: Sigma and YARA files become `rule` nodes. A MITRE tag becomes a `technique`
node with a `detects` edge. A rule body is never compiled or run.
- The docs indexer: every Markdown file becomes a `doc` node. A link or a path that names a file
in the repo becomes a `documents` edge; a link to another `.md` file becomes `references`.
- The infrastructure indexer: Dockerfile, compose, Kubernetes YAML and Terraform become
`container`, `image`, `service`, `host`, `network`, `port` and `dependency` nodes. Environment
variable names are recorded; their values are not.
- Web entry points: FastAPI and Flask route decorators (`@app.get("/health")`,
`@app.route("/login", methods=[...])`) become `endpoint` nodes that `handles` the handler
function, and confirmed constructors (`app = FastAPI()`, `Flask(__name__)`, `APIRouter()`,
`Blueprint()`) hold them at 1.0; a shape-only match is inferred at 0.9. A repo with exactly
one compose or Kubernetes service exposes its endpoints (`WEB-SVC-1`, 0.9); with two, the
graph refuses to guess. Kubernetes Ingress rules make `ANY /path` endpoints `routes_to`
their backend Service. stdlib `BaseHTTPRequestHandler.do_GET` is an endpoint at 0.9.
`middleware` nodes sit before the service they guard.
- Graph queries: `query`, `search`, `trace`, `paths`, `stats`, `export`, and the `lens` view of
security kinds (`rule`, `control`, `vulnerability`, `identity`, `service`, `technique`,
`endpoint`).
- Change impact: `impact` maps changed files to changed nodes, walks outward up to a depth, and
labels every reached node with depth and the key path that reached it. Inferred edges are
flagged. `impact` and `select-tests` never write the database: pass `--refresh` to index
first, and read `stale_index` in `--json` (a changed file also warns on stderr). A missing
database exits 4 with the `index` command to run.
- Query recipes: `detections` names the rules that detect a technique, `tests-for` names the tests
that reach a file or symbol, and `uncovered` names the modules that no test imports. Each answer
comes from stored edges, with the key chain that supports it.
- Test selection: `select-tests` walks forward from each test node to the changed keys and
returns the tests, each with the key chain that justifies it.
- SEF 1.0 output: `impact --record FILE` writes one evidence record with the indexed file set
hash, findings, evidence and limitations.
- MCP server: newline-delimited JSON-RPC 2.0 over stdio, speaking protocol `2026-07-28`
(stateless) and `2025-11-25` (legacy), refusing `2024-11-05`, `2025-03-26` and `2025-06-18`,
with five read-only tools. See below.
- Workspace indexing: `index --workspace` indexes the root repository and every child git
repository as separate names, and never folds a nested repository into its parent.
- Repository identity: the default repo key is the normalized origin (`github.com/org/repo`;
ssh and https forms name one repo, credentials are stripped). A git checkout with no remote
gets the directory name plus a short hash of its path, so two same-named folders stay apart
and one folder stays stable. A plain (non-git) directory keeps its name. `--repo NAME`
overrides. `stats --json` lists every repo in the database and its counts.
- Trust model: operator-side ignore rules (`--ignore`, config `ignore.paths`) and an origin
allowlist (`trust.allowed_origins`). Nothing inside an indexed repository configures the
indexer, so a project cannot hide its own manifests. See `docs/trust-model.md`.
- Provenance: `provenance KEY` answers why the store believes a node exists - file record
with sha256, justifying edges with recipe, confidence and line, and the run context.
Read-only, printable-escaped, `--json` for scripts.
- Measured on 2026-11-28 on the development workstation: 12 repositories, 318 files, 1384 nodes and 2602 edges in
0.28 s.
## What does not work yet
- YAML and Terraform are read with a line parser for the documented subset, not a full grammar.
A manifest the parser does not recognize is recorded as a file only.
- Call resolution covers named imports, scope-aware. A bound name resolves where it is used:
calls, decorators, `match` class patterns, f-string interiors and first-class references
(`map(m.fn, xs)`); a parameter, local assignment or duplicate import binding shadows or
voids the link at that site instead of guessing. `if TYPE_CHECKING:` blocks bind nothing.
A function-local `from utils import fn` binds inside that function only. Re-export chains
follow at most five hops; a statically bound use is 0.95, a hopped or import-only one 0.90.
Star imports, `getattr`, `importlib` strings and attribute chains deeper than one hop stay
module-granularity: a 0.8 `tests`/0.6 `references` edge, so `--min-confidence 0.9` walks
symbol-level links only. When two files claim one dotted module name, nothing resolves
through that name.
- `uncovered` is an import-level bound, not line coverage. A test that reaches a module through a
fixture, a subprocess or `importlib` is not counted.
- Web routes are patterns, not execution. Class-based views, `include_router` and
`register_blueprint` prefixes, computed paths (`@app.get(f"/x/{v}")`) and reverse proxies
in front of the service are not followed. `middleware` covers decorator and module-level
registrations only.
- No runtime data. There is no execution, no taint tracking, no dynamic dispatch and no network
map.
- No incremental watch mode. Re-indexing parses every changed file again.
- No remote transport for MCP and no authentication. The server is a local stdio process.
## Install and run
```bash
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -e . pytest
python3 -m pytest -q
```
Then, from a repository you want in the graph:
```bash
phrour-repograph --db .phrour-repograph/graph.db init
phrour-repograph --db .phrour-repograph/graph.db index .
phrour-repograph --db .phrour-repograph/graph.db index /home/me/work --workspace
phrour-repograph --db .phrour-repograph/graph.db stats --json
phrour-repograph --db .phrour-repograph/graph.db query --kind function --name parse --json
phrour-repograph --db .phrour-repograph/graph.db search "credential rotation" --json
phrour-repograph --db .phrour-repograph/graph.db trace 'module:repo:pkg.auth' --depth 2 --json
phrour-repograph --db .phrour-repograph/graph.db impact . --since HEAD~1 --json
phrour-repograph --db .phrour-repograph/graph.db impact . --files src/auth.py --json --record impact.sef.json
phrour-repograph --db .phrour-repograph/graph.db select-tests . --files src/auth.py --json
phrour-repograph --db .phrour-repograph/graph.db detections T1071.001 --json
phrour-repograph --db .phrour-repograph/graph.db tests-for file:myrepo:src/auth.py --json
phrour-repograph --db .phrour-repograph/graph.db uncovered --limit 20
phrour-repograph --db .phrour-repograph/graph.db lens --json
```
Every command that prints a result takes `--json`. Exit codes: `0` success, `1` a finding the
caller asked for (no path found, a security node in the impact, an empty lens), `2` a usage
error. `impact` indexes the target repository before it analyses; pass `--no-index` to analyse
the database exactly as it is, for read-only use on a snapshot or a mounted database. The other
commands read the existing database.
<!-- mcp-name: io.github.Phrourios/phrour-repograph -->
## MCP server
`phrour-repograph --db PATH mcp` or `python3 -m phrour_repograph.mcp --db PATH` speaks MCP on stdin and
stdout. Logs never go to stdout. `server.json` next to this README is the registry listing.
The server is dual-era, per the `2026-07-28` protocol revision:
- Modern clients send every request stateless with
`_meta["io.modelcontextprotocol/protocolVersion"]`. `server/discover` answers first and names
the supported versions; a version the server lacks answers `-32022` with that list. Results
carry `resultType`, list results carry `ttlMs` and `cacheScope`.
- Legacy clients (revision `2025-11-25`) may send `initialize` first, or call the read-only
tools directly; plain requests are served statelessly. `ping` works only in this era.
- Revisions `2024-11-05`, `2025-03-26` and `2025-06-18` are refused with the supported list.
Methods: `server/discover`, `tools/list`, `tools/call`, plus legacy `initialize`, `ping` and
notifications. Unknown methods return `-32601`.
Tools:
| Tool | Arguments | Answer |
| --- | --- | --- |
| `query_graph` | `kind`, `name`, `path`, `repo`, `limit` | matching nodes |
| `get_node` | `key` | one node or null |
| `trace_dependencies` | `key`, `depth`, `direction` | reached nodes with the edge that reached each |
| `analyze_change` | `root`, `since`, `files` | changed nodes, impacted nodes, tests, unknowns |
| `select_tests` | `root`, `since`, `files` | tests plus the files a runner needs |
Each tool result is one `content[0]` item of type `text` that holds a JSON string, mirrored as
`structuredContent`. The tools are read-only: they never index, write or execute. Every tool
carries `annotations` (`readOnlyHint` true, `openWorldHint` false).
Client configuration (Claude Desktop, OpenClaw, any stdio client):
```json
{
"mcpServers": {
"phrour-repograph": {
"command": "phrour-repograph",
"args": ["--db", "/path/to/repo/.phrour-repograph/graph.db", "mcp"]
}
}
}
```
## Ontology in one paragraph
Nodes are things: `repository`, `file`, `module`, `class`, `function`, `test`, `doc`, `policy`,
`service`, `container`, `image`, `host`, `network`, `port`, `rule`, `technique`, `dependency`,
`vulnerability`, `control`, `identity`, `device`, `firmware`. Edges are directed and carry a
provenance of `observed` or `inferred` plus a confidence: `contains`, `defines`, `imports`,
`calls`, `references`, `tests`, `exposes`, `depends_on`, `detects`, `documents`, `affects`,
`owns`. The full list with one line each is in `docs/ontology.md`.
## Edge confidence tiers
Every edge carries a provenance and a confidence. The tiers are fixed:
| Tier | Confidence | Meaning | Examples |
| --- | --- | --- | --- |
| observed | 1.0 | the relationship is written literally in a source file | `import`, `defines`, a Markdown link, `FROM ubuntu:22.04`, `depends_on` in Compose |
| statically bound | 0.9 - 0.95 | the import binding is written literally; only the cross-module link is inferred | `from utils import fn` + `fn(x)` -> that symbol (0.95, same for its decorator, `match` pattern and first-class use); a re-export hop (0.90) or a test that binds without calling (0.90, `TS-IMP-1`) |
| heuristic | 0.7 - 0.9 | a parser heuristic or naming convention inferred it | "a test file imports a module, so it tests it" (0.8), a call to an imported name that did not resolve (0.8) |
| weak | 0.4 - 0.6 | a text mention or a guess-shaped link; review before trusting | a bare file path named in prose (0.5), `COPY --from` of a non-stage name (0.6) |
`--min-confidence` (CLI and MCP) drops edges below the threshold before walking, so a review
prompt built only from observed links is one flag away.
## Trust model, in three lines
The indexed tree is data, never configuration: no committed file changes how the indexer runs,
because a project that could would hide the evidence you came for. Ignore rules and the origin
allowlist come from the operator (config, `--trust-file`, `--ignore`) and are reported in every
summary. `provenance KEY` shows the file record and the edges behind any claim the graph makes.
Full model, pattern language and threat notes: [`docs/trust-model.md`](docs/trust-model.md).
## Boundary with ExploitGraph
PhrourRepograph owns the code and infrastructure graph, change impact and test selection. ExploitGraph
owns reachability and exploitability of vulnerabilities. PhrourRepograph may carry a `vulnerability`
node and an `affects` edge because the ontology is shared, but it does not decide whether a flaw
is exploitable.
## No LLM in the query path
Every answer comes from a SQL query, a graph walk or `git diff`. There is no model, no embedding
and no ranking that changes between runs. An agent may read the JSON, but the JSON is the same
for every reader.
## Limits
- A clean impact result is not proof of safety. It means the graph saw no path, and the graph is
static and partial.
- A file that was not indexed (unsupported language, secret-like name, over 1 MiB) cannot appear
in any answer.
- Depth bounds the walk. A dependency beyond the requested depth is invisible.
- Results depend on the git ref you diff against.
<!-- phrourios:standards:start -->
## Standards and references
- [MITRE ATT&CK](https://attack.mitre.org/), The technique framework the detection-rule indexer
maps Sigma and YARA tags onto.
- [SQLite](https://sqlite.org/), The embedded database used for the graph store.
- [Model Context Protocol](https://modelcontextprotocol.io/), The agent interface exposed by the MCP server.
<!-- phrourios:standards:end -->
<!-- phrourios:footer:start -->
## Part of Phrourios Security
Phrourios Security builds security operations you can prove. This project is part of the
[Phrourios portfolio](https://github.com/Phrourios). Every result carries evidence, limits and a reproduction command.
<!-- phrourios:footer:end -->
## License
All rights reserved, Soteria Solutions LLC. See `LICENSE`. Install, run and
unmodified package redistribution for installation are allowed; anything else needs
written permission.
## Contact
- Project contact: [contact@phrourios.com](mailto:contact@phrourios.com).
- Security issues: see [SECURITY.md](SECURITY.md), or email
[security@phrourios.com](mailto:security@phrourios.com). Do not open a public issue.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues