# Dev mode

A dev chat is an AI chat on a GitHub repository: the agent works in a clone in the chat's runtime, on its own branch, and members push and open pull requests with their own GitHub account.

## How the pieces fit

| Piece | Set up by | Used for |
|---|---|---|
| The workspace's GitHub App | an admin, in **Workspace settings > GitHub** | listing the repositories, cloning and fetching with short-lived read-only tokens, pull request and check events |
| A member's GitHub account | each member, in **Profile > Connections** | pushes and pull requests, authored by that member |
| The runtime | the chat's first prompt | the clone, where the agent edits, builds and commits |
| The Spyria server | always | pushing and calling GitHub's API |

A member's GitHub token never enters a runtime or a browser. The runtime hands the server only the new commits of the working branch (at most 12 MB); the server checks them and pushes with the publishing member's token, never forcing. The agent reaches GitHub through server-side tools (`push_branch`, `open_pull_request`, `read_checks`…), since `git push`, `gh` and the API have no credential inside the runtime.

## Repositories

A workspace uses exactly the repositories granted to its GitHub App's installations; to add one, change the installation on GitHub. In **Workspace settings > GitHub**, each repository has a checkbox per workspace role (all ticked by default) deciding who may start a dev chat on it.

The App needs **Contents**, **Pull requests** and **Workflows** write, and **Issues**, **Checks**, **Actions** and **Metadata** read. An App created before Spyria asked for **Issues**, **Actions** or **Workflows** must have them added on GitHub and accepted on the installation.

## Clone and setup script

When the runtime starts, Spyria clones the repository with a read-only token the agent never sees, and checks out the chat's working branch (`spyria/<chat name>-<id>`). Commits are authored by the chat owner. Rules files come with the clone: Pi and Codex read `AGENTS.md`, Claude Code `CLAUDE.md`.

The setup command is set per repository in **Workspace settings > Runtimes > Setup commands**, with a default for the others; nothing runs without one, so set `sh .spyria/setup.sh` to run a script in the repository. Setup:

- runs after the clone and before the agent starts, with live output, without any token, for up to 45 minutes; a failure is shown and the agent starts anyway;
- runs again on every runtime restart, so make it safe and fast to run twice;
- is readable by every member, so it must hold no secret.

What it installs reaches the agent, the gate commands and git hooks: `~/.local/bin`, `~/.bun/bin`, `~/.cargo/bin`, `~/.deno/bin`, `~/go/bin` and mise shims are on `PATH`, and directories written to `$SPYRIA_PATH` and `NAME=value` lines to `$SPYRIA_ENV` are added, like GitHub Actions' `$GITHUB_PATH` and `$GITHUB_ENV`. Package downloads are cached per repository and chat owner on each host.

### Runtimes kept ready

A repository can keep up to 5 runtimes ready (0 by default), cloned on the default branch with setup already run, so a new dev chat on that branch starts at once. After setup succeeds in a runtime kept ready, the host keeps a snapshot every new runtime of the repository starts from. The snapshot is shared by every chat on the repository on that host: keep secrets out of what setup writes to disk.

## Quality gates

With quality gates on, the agent checks its own work before the owner sees it: it calls `finish_work`, then Spyria runs the repository's gates in order.

| Gate | Passes when |
|---|---|
| **Command** | a command run in the runtime, with setup's `PATH`, exits 0 within its timeout |
| **Code review** | a fresh subagent reviewing the diff against the rules files finds nothing important; nits and pre-existing findings never block |
| **Pull request** | the branch is pushed and the pull request opened or updated, with the owner's account and `finish_work`'s title and description |
| **CI** | every check of the pushed commit passes; if the pull request conflicts with its base, the base is merged in the runtime first and the agent resolves any conflict |

Each gate but the pull request either sends the failure back to the agent, up to a number of times set per gate, or hands over to the owner. After a fix, the gates run again from the first. The default set is a code review, the pull request and CI.

The run hands over to the owner when every gate passed ("Ready for your review on pull request #N"), a gate keeps failing, the agent ends a turn without `finish_work`, the run hits its time or cost limit or an AI budget, a member writes in the chat, the owner or an Editor presses **Stop**, or the gates are turned off. Only the owner's prompts start a run, and the gates' messages run on the owner's key.

Admins with **Connect GitHub** set the gates in **Workspace settings > Quality gates**: default rules, and rules per repository, each with its switch (off by default), gates, a time limit (4 hours by default) and an optional cost limit. Every member can read them, so commands must hold no secret.