# Extension modules

> Plug your own code into Visto AI to add ticket context and acceptance criteria, send chat notices, forward alerts and collect feedback.

Web page: https://visto-ai.com/docs/extension-modules/

An extension module is a small piece of your own code that Visto AI loads once, when it starts. It is how you connect the reviewer to the tools your team already uses: a ticket system, a chat tool, an on-call pager, a feedback button. Visto AI ships no module and knows no particular ticket or chat product, so you write the few lines that talk to yours. With no module configured, everything works as before.

To let the review model search your documentation while it reviews, use an [MCP server](https://visto-ai.com/docs/mcp-tools/) instead.

## What a module can do

A module provides one or more of four parts:

| Part | What it does | Typical use |
|---|---|---|
| `context` | Gives the reviewer text about the pull request, and a list of acceptance criteria | Look up the ticket named in the branch or title, and return its description and criteria |
| `notify` | Is told once about every published review | Post a message to the team's chat channel, or to the author |
| `alert` | Receives every alert the service raises | Forward alerts to a pager or a chat channel |
| `route` | Answers HTTP requests under `/extensions/<name>/` | Collect a thumbs up or down on a review, or receive a callback from another tool |

A module runs inside the service, in the same process, with its environment, secrets, database connection and network. Visto AI does not sandbox it. **Load only code you trust.**

## Turn it on

Name each module in the config's `extensions` block. Secrets go in `options` by reference, never as plain text:

```yaml
extensions:
  - name: example
    module: ./extensions/extension-example.ts
    options:
      secret: { env: EXAMPLE_FEEDBACK_SECRET }
```

`name` appears in logs and in the module's route. `module` is a path (relative to the config file when it starts with `./` or `../`) or the name of an installed package. `options` is handed to the module as written, with every `{ env: NAME }` replaced by that variable's value. A module that cannot be loaded stops the start, so a broken module is noticed at once.

A module needs a restart to pick up changes: it is loaded once and lives as long as the process.

### Under Docker

The image holds only the service's own code and packages, so mount a folder with your module next to the config. The provided `compose.yaml` has the line ready to uncomment:

```yaml
    volumes:
      - ./config.local.yml:/config/config.yml:ro
      - ./extensions:/config/extensions:ro
```

Put the file in `./extensions/` and name it in the config as `./extensions/<file>`. A mounted module can use Node's built-in modules and `fetch`, but it cannot import the image's packages. If it needs a package, ship a `node_modules` folder beside it or build your own image on top of Visto AI's. [The extension contract](https://visto-ai.com/docs/extension-contract/#under-docker) has the details, including which TypeScript a `.ts` module may use.

## A short example

[examples/extension-example.ts](https://raw.githubusercontent.com/visto-ai/visto-ai/0faf484aa43f4fcdc1f30c1d5c056ea26c1c0d32/examples/extension-example.ts) is a complete module that works. It returns a fixed piece of context with two criteria, logs every published review, and accepts feedback at `POST /extensions/example/feedback`. In outline:

```ts
import type { ExtensionFactory } from '../src/extensions/types.ts';

const example: ExtensionFactory = (setup) => ({
  async context(pr) {
    // A real module would look up the ticket of `pr` here.
    return {
      status: 'ok',
      label: 'ticket SHOP-12',
      text: 'Customers can save a card for later payments.',
      criteria: ['A saved card can be removed.', 'The card number is never logged.'],
    };
  },
  async notify(notice) {
    setup.log({ what: 'review_published', run: notice.run, needs_human: notice.needsHuman });
  },
});

export default example;
```

The default export is a function that the service calls once with the module's name, its options, a `log` function and a `reportFeedback` function. It returns an object with the parts it provides. The types live in [src/extensions/types.ts](https://raw.githubusercontent.com/visto-ai/visto-ai/0faf484aa43f4fcdc1f30c1d5c056ea26c1c0d32/src/extensions/types.ts). Import them with `import type`, which Node erases at run time, so the import path does not need to exist inside the container.

To try the example, copy it into your `extensions` folder, set `EXAMPLE_FEEDBACK_SECRET`, and use the config block above.

## Ticket context and acceptance criteria

When a `context` part returns text, the review model sees it inside data markers, after a line that says it is data: it may explain what the change is meant to do, but it never changes the rules and is no evidence that the code is right.

When it returns criteria, the review gets an `Acceptance criteria` section, after `Human review` and before `Findings`. It starts with a count line (for example `2 met, 0 not met, 1 not verified.`), then one line per criterion, marked `[met]`, `[not met]` or `[not verified]`, with the model's note. The model judges each criterion it can. Visto AI checks every row, merges the rows from several batches (`not met` wins over `met`, `met` over `not verified`), and writes the criterion's text itself, inside a code span, so a mention, a link or HTML in it has no effect.

Keep these points in mind:

- **Criteria decide nothing.** They do not change the verdict, the score or the merge gate, and an unmet criterion is not a finding. A pull request that meets none of its criteria can still pass the gate.
- **Rows can carry over.** In an incremental review or a re-check, a criterion the model does not judge keeps its row from the newest published review that has rows, tagged `_(kept from an earlier review)_`. A kept `met` can be stale if a later push removed the code that met it. A criterion no review has judged is tagged `_(not judged in this review)_`.
- **A criterion is matched by its exact text.** Change one character and it starts again as not verified.
- **Files come first.** Extension text and criteria are shown only when they cost the files nothing: no more cutting and no extra file left unreviewed. Texts give way first, then criteria, and the review's audit records `extension_context_cut`.
- **What is posted is public.** Criteria are written in the review, and the model may quote the ticket text. Anyone who can read the pull request can read both. Return `skipped` for a pull request whose ticket must stay private.
- **Forks get nothing.** For a pull request from a fork, or one whose origin cannot be told, no module is asked. Each is recorded as `skipped`, with `from_fork` or `origin_unknown`.

## Chat notices

A `notify` part is told about each published review once, re-checks included, as the last step of the review job. The notice carries the repository, the number, the title, the author, the review's link, whether a person is needed, the highest score, the count of findings by severity, and the review's body. Treat the title and body as untrusted text wherever you send them.

The run is stamped before notifiers are called, so a notice is never sent twice, and one lost to a crash or a failing notifier is not sent again. Nothing is sent in dry run.

## Feedback

A `route` part can collect a thumbs up or down on a review and pass it to `reportFeedback`. Visto AI stores one answer per run and person (by git login, in lower case, latest wins) in `visto_ai.review_feedback`. Only a published run can be answered. The page of one review in [the UI](https://visto-ai.com/docs/the-ui/) shows the feedback counts and the newest reasons. To read it all:

```bash
docker compose exec db psql -U postgres -d visto -c "select run, owner, repo, number, login, vote, reason, extension, at from visto_ai.review_feedback order by at desc limit 20"
```

Routes are public: your module must check every request itself, for example with a shared secret compared in constant time, as the example does. Whoever passes that check can answer for any login, so the number of rows for one run is not bounded.

## Limits

| What | Limit |
|---|---|
| Modules | 20 |
| Text from one module | 8,000 characters |
| Text from all modules together | 24,000 characters |
| Label of a text | 80 characters |
| One criterion | 300 characters |
| Criteria from all modules together | 30 |
| Time for `context` | 30 seconds (all modules are asked at once) |
| Time for `notify` | 10 seconds |
| Time for `alert` | 5 seconds |
| Time for `route` | 10 seconds; the caller then gets `500` |
| Requests held by one module's route | 10 at once; more get `503 busy` |
| Body of a route request | 1 MiB |

At about three characters to a token, the text limits come to about 11,000 tokens, repeated in every model call of a review. A slow `context` part adds up to 30 seconds to every review, and a `notify` part that hangs holds the job's place in the queue for its 10 seconds.

## Status and alerts

Each review records how every module's `context` part did (`ok`, `empty`, `skipped` or `error`, with a short code) in `review_runs.result` under `dependencies.extensions`, and in the `review` log line as `extensions` (null with no module). A review that ends before the modules are asked, because the pull request has no changed file or its file list cannot be read, records none.

| Alert | When |
|---|---|
| `extension_error` | A module's `context`, `notify` or `route` part starts failing |
| `extension_ok` | It works again |

`empty` and `skipped` are not failures. A module that fails for some pull requests and not others alerts at every change, and a restart forgets the state, so the alert is raised again.

## Related

- [The extension contract](https://visto-ai.com/docs/extension-contract/): the full reference for module authors.
- [MCP tools](https://visto-ai.com/docs/mcp-tools/): give the review model tools from MCP servers.
- [How a review runs](https://visto-ai.com/docs/how-a-review-runs/): where extension context fits in a review.
