# Impact reports

`codebase-snapshot impact` answers one question before a change is opened for review: **what does
this change reach, and which tests are candidates?** It is not a code graph for browsing. It is a
bounded, evidence-carrying report built from the same import resolver the generator uses, with a
`trust` envelope that says how fresh and complete the answer is.

## Run it

```bash
codebase-snapshot impact --diff HEAD
codebase-snapshot impact --paths src/impact.ts,src/cli.ts --format markdown
codebase-snapshot impact --diff origin/main --tests-paths
codebase-snapshot impact --diff HEAD --run
```

With neither `--diff` nor `--paths`, the base is `HEAD`. The change set includes committed,
staged, unstaged and untracked changes relative to the ref. A ref beginning with `-` is refused;
`shell: false` is used for every git invocation.

The report works without a generated snapshot. A current `manifest.json` is reused, changed and
new files are overlaid in memory, and a repository with no snapshot is scanned in memory. Nothing
is written into the repository. `--no-live` requires the persisted snapshot instead.

## What is in the report

| Field | Meaning |
| :-- | :-- |
| `changed[]` | Path, whether it is in the snapshot, whether it is deleted, and why it is absent when it is. |
| `affected[]` | One entry per impacted file: `distance`, `via`, the exact `specifier`, `confidence` (how the edge resolved), `impactKind` and `matchedSymbols`. |
| `tests[]` | Candidate tests, with the files they cover. These are import relationships, never runtime coverage. |
| `unresolved[]` | Repository-internal imports that did not resolve. Bare packages and Node built-ins are outside the repository and are not listed. |
| `routesAffected[]` | Route files in the changed or affected set, with the methods their summaries recorded. |
| `prunedByBarrel` | Barrel edges rejected because they do not consume the changed symbol. |
| `cycles` | Import cycles in the impacted subgraph, with `--include-cycles`. |
| `imports` | Outgoing dependencies of changed files, with `--include-imports`. |
| `trust` | Index source, freshness, coverage, redaction and omission counts, and named partial reasons. |
| `truncated` / `limits` | Whether `--max-results` cut the list, and the bounds that applied. |

Test files are excluded from `affected[]` and listed in `tests[]`. A file that changed from full to
preview is still a file: the node is present, the body may not be.

## How an edge is decided

1. The changed file is resolved against the manifest. A deleted path, an unknown path, a non-TypeScript
   file and a paths-only run seed a wildcard. A `--diff` run maps the new-side hunks to the exported
   declarations whose line spans they overlap; an edit outside every declaration widens to a wildcard.
2. Reverse importers are walked. The walk reads the importing file's `importBindings` and
   `reExportBindings`, not just the specifier:
   - `import { foo as f }` matches the original `foo`;
   - `export * from "./a"` propagates the symbol set;
   - `export { foo as publicFoo }` maps `foo` to `publicFoo`;
   - `export * as ns` propagates `ns`;
   - CommonJS destructured `require()` and dynamic `import()` are file-level edges;
   - a pure barrel is traversed but not reported as an affected consumer.
3. If a barrel edge matches nothing in the incoming symbol set, it is pruned and counted. A consumer
   of a *different* export is not reported.
4. Direct or transitive importers are reported with the exact hop that reached them. Tests are collected
   when their import consumes the impacted symbol set.

The compiler pass behind `--precise` is bounded to 2,500 files and four seconds. It follows
`getAliasedSymbol` through aliases and returns only path/line/name references, never source text. Above
the cap or past the deadline the report stays partial and says why; it never silently falls back.

## Tests

`tests[]` is a **candidate list**. A candidate test imports a changed or affected file. It may not
exercise the changed behaviour, and no coverage claim is made. `--tests-paths` prints one path per
line for a CI step. `--run` invokes the repository's own runner:

- Vitest: `node node_modules/vitest/vitest.mjs related <changed...> --run`
- Jest: `node node_modules/jest/bin/jest.js --findRelatedTests <changed...> --runInBand`
- node:test: `node --test <candidate tests>`

No package manager, shell or network is used. A change to a build, test or workspace configuration
adds a warning that the selective run may be incomplete; run the full suite too.

## Output

`--format json` is the stable contract and writes one JSON document to stdout. Text goes to stderr,
as every human-facing command does. `--format markdown` writes a PR-ready report to stdout.
`--format pr-comment` is accepted here and by `brief`: `impact` renders the same Markdown
report, while `brief` writes the page-oriented PR comment.

Exit `0` when the report was produced, `1` when the live index cannot be built or an explicit
`--no-live` manifest is missing, and `2` for a usage error.

## What it does not claim

- It is not runtime coverage, a call graph, or a security review.
- It does not resolve bare package specifiers to `node_modules`, or Node built-ins.
- It does not see a dependency created through a dynamic string the parser cannot evaluate; such a
  path is absent rather than guessed.
- A manifest generated from a dirty tree may describe bytes that have already moved. The `trust`
  envelope names that condition; `validate` is the separate proof.

→ [CLI reference](cli.md) · [Impact in MCP](tools.md) · [Brief](brief.md)

## Related

- [Briefs](brief.md) — turn an impact report into a review pack.
- [LLM codebase context](llm-codebase-context.md) — why symbol-pruned context beats a repository dump.
- [All documentation](contents.md) — every guide and reference.
