# Smi

> Turns a ticket into a draft pull request inside your own GitHub Actions, on your own API key. The AI agent never holds a token that can push or open a PR.

Source: https://ebrahimsameh.com/projects/smi/

## The problem

Letting an AI coding agent work on your repository raises one question before any other: what stops it from doing more than you asked? A line in the prompt that says "only open drafts" is a request. The model can ignore it, and an issue body written by someone else can talk it out of it. I wanted the limits to come from GitHub permissions instead.

There's also a fit question. If you already pay for GitHub Copilot, its coding agent has Linear and Slack entry points and a platform-level guarantee that its PRs stay drafts, and you probably don't need Smi. Smi exists for the two things Copilot's agent can't do: it has no alerting integration of any kind (no Sentry, Better Stack, PagerDuty or webhook), and its automation config is private to whoever created it and never enters Git.

## What I built

A toolkit you add to a repository. Label an issue `smi`, and a workflow in your own GitHub Actions runs a model with your own API key, writes a patch, and opens a draft pull request.

## How it works

The workflow has two jobs, and the split between them is the whole security model.

| Job | Credentials | What it does |
| --- | --- | --- |
| `agent` | `contents: read`, only so checkout works on a private repo | Runs the model and writes a patch |
| `ship` | `contents: write`, `pull-requests: write` | Applies the patch and opens a draft PR |

1. An issue gets the `smi` label. Unlabelled issues are ignored and cost nothing.
2. The `agent` job checks out the code with a read-only token, runs the model and produces a patch.
3. `bin/guard.sh` checks the patch for quick feedback.
4. The `ship` job runs `bin/guard.sh` again. This is the check that counts.
5. The `ship` job applies the patch and opens the pull request with `--draft`.

The agent can't open a pull request, push a branch or mark anything ready for review, because its token has no such scope. `--draft` is a literal in a job the agent can't reach, and no config key changes it.

## Decisions and trade-offs

The guard refuses any change under `.github/**`, with no exceptions. An agent that can edit CI can merge its own code. The cost is that Smi will never fix your workflow files for you.

Draft-only is hard-coded. You can't opt out, even on a repo where you'd trust the agent more.

The containment checks ship with the toolkit. `templates/smi-assert.yml` runs them as a `workflow_dispatch` regression test. If it ever passes its negative assertions, the security model is decoration.

For now the install vendors the toolkit into `.smi/`. Once the repo is public, the install becomes a single `uses:` line pointing at the shared workflow, and `.smi/` goes away.

## Status

The core works end to end on a private testbed: a GitHub issue becomes a draft PR. These were verified on real runs:

| Assertion | Result |
| --- | --- |
| PR is opened as a draft | `isDraft=true` |
| Agent-permission token cannot push | `403 Write access to repository not granted` |
| Agent-permission token cannot open a PR | refused |
| An unlabelled issue is ignored | `ship=skipped`, no spend |
| A retry does not open a second PR | `ship=skipped` via branch dedupe |
| Two events 1s apart (`opened` + `labeled`) | exactly one PR |
| CI on a `GITHUB_TOKEN` PR | `action_required`: created but blocked |

Not done yet: Linear and Better Stack ingress are designed but not wired, CI on PRs opened with `GITHUB_TOKEN` is blocked (the last row above), and the source is still private.

Installing it today needs access to the private source. The script vendors the toolkit into `.smi/` and adds `.github/workflows/smi.yml` and `.github/smi.yml`:

```bash
bash bin/install.sh /path/to/your-repo
```

The write-up on the credential split goes into more detail: [Containing an AI coding agent with two GitHub Actions jobs](/blog/agent-in-a-box-smi/).
