> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sense-lab.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Work on a repository

> Connect a repository, give Sensei a task, and get a verified change as a pull request.

Given a repository and a task, Sensei clones the repository into a sandbox, runs the tests to see what already fails, makes the change, runs the tests again and opens a pull request. A task that is a question is answered and nothing is changed.

## Connect the repository

Open **Runs**, click **Connections** and add the repository, or use the terminal:

```bash theme={null}
sensei repos connect acme/checkout --token <token>
```

The token needs to be able to push and open pull requests. It is stored encrypted and shown afterwards only as its last four characters.

![Connections on the Runs page: a connected repository with the last four characters of its token, tools, settings and secrets, and Slack](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/runs-connections.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=3e545bf513d28007de51ce21ab9f654e)

You can write the repository as an https URL, as `git@host:org/repo`, or as `org/repo` for GitHub.

| Repository | Not connected | Connected with a token |
| - | - | - |
| Public | Read as it is. The result is a patch. | Pull request |
| Private | Cannot be cloned | Pull request |

GitHub and GitLab repositories get pull requests. Working on an existing pull request is for GitHub repositories for now.

## Start the run

In a checkout, the repository defaults to the checkout's origin and the branch to the one you are on:

```bash theme={null}
sensei run "Fix the failing test in the upload client"
```

From anywhere else, name both:

```bash theme={null}
sensei run "Add a retry to the upload client" --repo acme/checkout --ref main
```

To hand Sensei a failure you can reproduce, let the command run it and attach the output:

```bash theme={null}
sensei run "Fix this" --from-failure "pytest tests/test_upload.py -x"
```

## How Sensei sets up

Sensei picks an image, setup commands, a test command and the services the tests need from the repository, and reports the basis for each choice in the run's timeline.

![The start of a run's timeline: the commit cloned, the environment chosen, the services started from the CI workflow, and the tests before any change](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-timeline.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=86d688f577926e904f39a3c14ee0d378)

| Choice | Where it comes from, in order |
| - | - |
| Image | The devcontainer image, the Dockerfile's first `FROM`, a language image chosen from the lockfiles, then a default Python image |
| Setup | The package manager files in the repository |
| Test command | The first test step in a CI workflow, then the default for the language: `pytest`, `npm test`, `go test ./...` or `cargo test` |
| Lint and format checks | The lint and format steps in a CI workflow, such as `ruff check .`, `npm run lint` or `cargo fmt --check`. Up to three. |
| Services | The services declared in a CI workflow, the devcontainer or a compose file, such as a database or a cache. Up to 6. |

Override the test command with `--test-command`. In a definition, `check` sets the test command and `image` sets the image.

A `sensei.yaml` file at the root of the repository sets any of these for every run on it, and is used before what Sensei works out. Values and tokens the tests or the setup need are given to the project as settings and secrets. See [Services, settings and secrets](https://docs.sense-lab.ai/sensei/runs/services-and-settings.md).

![The Environment card on a run's page: the image, language, test and setup commands, where they were read from, the services and the settings](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-environment.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=de46c7c49ac3bab1635a53609109c808)

## How a change is verified

The tests run before any change, so Sensei knows what already fails. After the change they run again, on the test files as they were at the start.

![The Verification card on a run's page: tests passed before and after the change, and the lint check from CI](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-verification.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=16613d3109d3387496a1e474a587a679)

| Verdict | When |
| - | - |
| Verified | The tests pass after the change. The summary says how many passed and how many that failed before now pass. |
| Failed | A test that passed before now fails, or a lint or format check from your CI that passed before now fails |
| Not verified | No change was made, the tests timed out, the same tests fail before and after, or the repository has no test command |

A run whose tests cannot pass because the project was not given a value they need ends **Failed** before any model call and names the value. See [When a run is missing a value](https://docs.sense-lab.ai/sensei/runs/services-and-settings.md#when-a-run-is-missing-a-value).

If the change edits test files, Sensei restores them to the starting commit before the check and says so on the run. The result is against your original tests. A run whose task is about the tests is told it may edit them, and the same restore applies.

### Lint and format checks

When a CI workflow runs a lint or format check, the run does too: once before any change and once on the finished change, test files included. Each check is listed under the verdict with what it printed when it does not pass.

| The check | What the run does |
| - | - |
| Passed before, fails after the change | The run is **Failed**. It waits for you and opens no pull request on its own. |
| Fails before and after | Said under the verdict. The verdict does not change. |
| Could not run in the run's computer | Said under the verdict. The verdict does not change. |

A command that rewrites code, such as `ruff check --fix` or `prettier --write`, is never run as a check. Type checkers are not run.

### More than one attempt

`--attempts 3` runs up to five independent attempts from the same starting point and keeps the best: a verified change first, then an unverified one, then a failed one.

## How the change is delivered

By default Sensei pushes a branch named `sensei/<run id>` and opens a pull request. The pull request body has the task, what changed, the verification verdict and the diff summary.

| Option | Effect |
| - | - |
| `--ask` | Show the verified change and wait for your approval before pushing |
| `--no-pr` | Push the branch and open no pull request |
| `--dry-run` | Push nothing. The patch is the result. |
| `--branch <name>` | Use this branch name |

![The Change card on a run's page: the files changed, with buttons to copy or download the patch and to read the diff](https://mintcdn.com/senselab/7GJRxwA5n_G2FDq5/images/sensei/run-change.png?fit=max\&auto=format\&n=7GJRxwA5n_G2FDq5\&q=85\&s=03fc8e64aad5e405df89b083575f62c0)

To apply a run's change locally:

```bash theme={null}
sensei patch <run> | git apply
```

## Fix an open pull request

```bash theme={null}
sensei pr 212
```

Sensei reads the review comments and the failing checks, adds one commit to the pull request's branch and says what it did in a comment. It never force pushes. You can add a task after the number to say what to do.

The repository must be connected with a token. Pull requests from forks are refused, because Sensei cannot push to a fork's branch.

Review comments and check output are other people's text. Sensei reads them as review of the code and does not take instructions from them.

## Several changes at once

To hand off several changes to the same repository, start them as one batch. Each is worked alone from the same commit, and the verified changes are tested together before the pull requests open. See [Several changes at once](https://docs.sense-lab.ai/sensei/runs/batches.md).

## Ask a question

A task that asks about the repository gets an answer and no change:

```bash theme={null}
sensei run "Give an overview of the services in this repository and how they call each other"
```

The run ends **Done**, and the answer is the result.

## A saved agent on a repository

A definition can name its repository, so the team runs the same work by name:

```yaml theme={null}
agent: repo-check
repo: acme/checkout
ref: main
instructions: Give an overview of the repository and its services.
```

`sensei check` and `sensei push` say which repository the definition names and whether it is connected. A definition that names none starts on an empty computer, or on the repository you pass with `--repo` when you run it.

An agent that works on a repository cannot also list `tools` or use a browser. Do that part in a step before it and pass what it finds as input. See [Steps](https://docs.sense-lab.ai/sensei/runs/steps.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.