# Repository config

> Use a .abstraction/config.yaml file to choose what Abstraction reads and reviews in your repository.

Abstraction analyzes your whole repository, apart from a few folders it skips
by default. To change that, add this file to the root of your repository:

```text
.abstraction/
  config.yaml
```

The file is part of your code, so you change it in a pull request like any
other file. Abstraction only reads the one at the repository root.

You don't have to write it from scratch. If your repository has no config
yet, Abstraction suggests one after the first analysis, based on what it
found. Open
**Admin → Repositories**, select **Review** next to **Repository config**, and
then **Open pull request**.

## A first config

```yaml
version: 1

rules:
  - path: "examples/**"
    treat: ignore
  - path: "docs/**"
    treat: index
  - path: "**/fixtures/**"
    review: ignore
```

This config:

- skips the `examples` folder completely,
- keeps `docs` searchable but doesn't analyze the code in it,
- leaves changes to fixture files out of pull request reviews.

## The format

- **`version`** must be `1`.
- **`rules`** is a list. Each rule has a **`path`** and at least one of
  **`treat`** and **`review`**.

### `treat`: what gets analyzed

| `treat`   | What happens                                                      |
|-----------|-------------------------------------------------------------------|
| `ignore`  | Abstraction never reads the files.                                |
| `index`   | The files are searchable, but their code isn't analyzed.          |
| `analyze` | The files are fully analyzed. Files no rule matches get this too. |

Abstraction only finds packages in analyzed folders. It finds a package by its
manifest file, such as `go.mod`, `package.json` or `pyproject.toml`. A
`go.mod` in an indexed folder is just a file. So if you don't want a folder
like `examples` showing up as a package, set it to `ignore` or `index`.

### `review`: what pull request reviews look at

The only value is `ignore`. Changes to matching files are left out of every
pull request review, so checks don't report findings on them. Use it for
fixtures, test data or generated code.

- You still see the changes in the review's **Changes** page.
- A pull request that only changes ignored files isn't reviewed.
- A renamed file is only left out when both its old and new paths match.

A rule can set `treat`, `review`, or both:

```yaml
  - path: "**/testdata/**"
    treat: index
    review: ignore
```

## Which rule wins

Rules are checked from top to bottom, and **the last rule that matches wins**.
This is how `.gitignore` works. Put broad rules first and exceptions below
them.

`treat` and `review` are decided separately. A rule that only sets `review`
doesn't change how a file is treated, and the other way around.

A rule that matches a folder applies to everything in it. Unlike `.gitignore`,
a later rule can bring back a folder inside an ignored one.

### Built-in defaults

Abstraction starts from these rules, and your file comes after them:

- Folders whose names start with a dot, like `.github`, are indexed.
- `testdata`, `vendor` and `node_modules` folders are ignored.
- Lock files are ignored: `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`,
  `go.sum`, `Cargo.lock`, `poetry.lock`, `uv.lock` and others.
- Indexed files larger than 256 KB are skipped.

Because your rules come last, they can undo a default. For example, if your
`testdata` folder holds code you want analyzed, add a rule that sets it to
`analyze`.

## Path patterns

Paths are relative to the repository root and use `/` between folders.

- A pattern **without** `/` matches a file or folder name anywhere.
  `testdata` matches every folder called `testdata`, and `*.min.js` matches
  every file ending in `.min.js`.
- A pattern **with** `/` matches the full path from the root. `docs/*.md`
  matches `docs/intro.md` but not `docs/guides/setup.md`.

| Pattern          | Matches                                         |
|------------------|-------------------------------------------------|
| `*`              | Any characters in one file or folder name       |
| `**`             | Any number of folders, including none           |
| `?`              | One character                                   |
| `[abc]`, `[a-z]` | One character from the list or range            |
| `{a,b}`          | Either `a` or `b`                               |

So `**/testdata/**` matches a `testdata` folder at the root and at any depth,
and `docs/**/*.md` matches both `docs/intro.md` and `docs/guides/setup.md`.

A pattern can't start or end with `/`. There's no `!` to exclude a path. To
make an exception, add another rule after it.

## Example

A repository with example projects, generated API code, and a parser whose
test data is real code:

```yaml
version: 1

rules:
  - path: "examples/**"
    treat: ignore
  - path: "*.min.js"
    treat: ignore
  - path: "api/gen/**"
    treat: index
    review: ignore
  - path: "parser/testdata/**"
    treat: index
  - path: "parser/testdata/corpus/**"
    treat: analyze
```

| File                             | Rule that wins               | Result                          |
|----------------------------------|------------------------------|---------------------------------|
| `examples/demo/go.mod`           | `examples/**`                | Ignored, so no package          |
| `web/static/app.min.js`          | `*.min.js`                   | Ignored                         |
| `api/gen/types.go`               | `api/gen/**`                 | Indexed, left out of reviews    |
| `parser/testdata/README.md`      | `parser/testdata/**`         | Indexed                         |
| `parser/testdata/corpus/go.mod`  | `parser/testdata/corpus/**`  | Analyzed, so it's a package     |
| `internal/testdata/fixture.json` | Built-in `testdata` default  | Ignored                         |
| `cmd/server/main.go`             | None                         | Analyzed                        |

`parser/testdata/corpus/go.mod` matches two rules. The corpus rule comes
later, so it wins.

## When you change the file

- **Pull request reviews use the config in the pull request.** If a pull
  request changes `.abstraction/config.yaml`, its own review already follows
  the new rules. Your tracked branch picks up the change once it's merged.
- **A mistake doesn't stop the analysis.** If a rule has an unknown key, a
  wrong value or a bad pattern, that rule is skipped and the others still
  apply. If the file isn't valid YAML, none of its rules apply.
- **Deleting the file** removes your rules. The built-in defaults still apply.

## Checks in your repository

You can also keep [checks](https://docs.abstraction.dev/code-review/checks.md) in your repository. Put
them in an `.abstraction/checks` folder, in files ending in `.abstrcheck.yaml`.
The folder can be at the repository root or inside any package:

```text
.abstraction/
  config.yaml
  checks/
    billing.abstrcheck.yaml
```

```yaml
version: 1

checks:
  - name: stripe-sdk-only-from-billing
    filters:
      paths: ["billing/**"]
    steps:
      - aql:
          comment: Only billing's Stripe adapter may call the Stripe SDK.
          query: |
            let sdk     = functions().filterInPackageWithName("github.com/stripe/stripe-go*")
            let adapter = functions().filterInPackageWithName("billing").filterInFileWithName("internal/stripe/*")
            assertNotEmpty(adapter)
            assertSubset(sdk.callers().filterPkgCategory(PkgCategory.Main).setTestVisibility(TestVisibility.Exclude), adapter)
```

Pull request reviews run these checks next to your workspace's checks:

- A check runs when the pull request changes a file in the package that holds
  it. At the repository root, that's any file.
- `paths` are relative to that package and narrow when the check runs. The
  query still sees all of your code.
- The review uses the check files in the pull request, so a new check already
  runs on the pull request that adds it.
- Parsing is strict. One unknown key or bad value skips the whole file.

The easiest way to write one is to ask your coding agent, with the
[`abstraction-checks` skill](https://docs.abstraction.dev/mcp/skills.md) installed. It tests the query
against your main branch before you commit it.

## Next steps

- [Set up code review](https://docs.abstraction.dev/code-review/getting-started.md)
- [Checks](https://docs.abstraction.dev/code-review/checks.md)
