# The ci workflow `ci` carries Jujutsu topics to trunk: a topic is started, sequenced against the others in flight, preflighted, dispatched to Tangled, cleared by checks built on the exact head, fast-forwarded onto `main`, and parked, with every user-facing landing cut as a CalVer release. It grew inside the [dotfiles](https://tangled.org/schlich.tngl.sh/dotfiles) repository and was split out of it at commit `91bf664f17ae`, whose history keeps every earlier change to these files (`jj log -- jj/ci.nu` there). | Path | What it is | | --- | --- | | `ci.nu`, `ci-launch.nu`, `ci-package.nix` | the workflow, the launcher that picks which `ci.nu` runs, and its package | | `JjCi.qnt`, `lifecycle/` | the protocol as a Quint model and as the statig machine checked against it | | `context-status.nu` | the topic readout for the prompt, the shell, and agent hooks | | `codex-session.nu`, `guard.nu` | Codex task ownership, and the interactive `jj new` guard (Claude Code sessions claim through `context-status guard`) | | `mcp.py`, `mcp-package.nix` | the workflow as MCP tools, run as jobs agents can follow | | `tower/` | `ci tower`, the live terminal view of every topic and run | | `completions.nu`, `workspace.nu`, `describe.nu` | Nushell completions, `jw`, and `jj-describe` | | `.agents/skills/ci` | the agent skill describing when to use each command | | `tests/` | property tests for the helpers, against the model's invariants | ## Using it from a repository A repository takes `ci` as a flake input and installs its packages: `packages..ci` (with `ci tower`), `context-status`, `ci-mcp`, `codex-jj-session`, and `jj-describe`. `lib.nushell` names the files to source for completions, the guard, and `jw`, and `lib.skills.ci` the skill. Every repository runs the `ci.nu` its lock file pins; `nix flake update ci` moves to a newer one. ## Stately dispatch and landing Single-topic `ci dispatch`, `ci dispatch --land`, `ci land`, and `ci queue` use the Stately agent in `agent/machine.mjs`. It names the work that used to live in the landing retry loop: publishing, checking landability, holding (`ci queue`, which ends `held`), approaching the runway (which ends `refused` for `ci land` on a busy runway), refreshing trunk, republishing, proving, clearing, and advancing. Progress reports expose the current state through the existing OSC 7501 and ci log channels. Dispatch ends in `dispatched`; only an explicitly requested landing enters the landing states. Stacked review and train landing keep their separate orchestration. The agent is deterministic and needs no model, provider SDK, or credentials. Nushell executes the existing policy operations under the same topic lock and runway. Clearance must name the published head before advancing; only a lost landing race retries, up to `--attempts`. Conflicts, failed checks, and other command errors stop. Rewritten heads are redispatched and cleared again. No activation is part of this flow. The npm lockfile pins the alpha agent and its exact XState peer. The Nix package fetches those tarballs by their lockfile integrity hashes, without an install script or network access at runtime. This published agent version predates the guide's step helpers, so the host uses XState's pure transition API with a `setupAgent` machine. JSON snapshots move between host steps inside one locked run. They are not durable checkpoints: after interruption, rerun the command to observe repository and remote state afresh rather than replay a remote effect whose outcome may be unknown. For development, install the pinned dependencies in `agent/`, then point both overrides at this checkout when exercising the workflow from another repo: ```nu $env.CI_SCRIPT = '/path/to/ci/ci.nu' $env.CI_AGENT_SCRIPT = '/path/to/ci/agent/cli.mjs' ``` `checks.x86_64-linux.ci-agent` covers dispatch-only termination, runway and clearance ordering, refusal of a busy runway, holding the exact head, stale-head rejection, rewriting and reproving, bounded races, and terminal failures. It uses no repository or remote mutations. The existing Quint and Rust lifecycle model continue to define protocol safety; this command machine refines their Publish, Hold, TakeRunway, GatePasses, and Land operations. ## Protocol `JjCi.qnt` is a finite-state Quint model of topic rebase, conflict resolution, validation, dispatch, the landing clearance, fast-forward landing, and workspace finish. Quint invokes TLC to check its safety and temporal properties exhaustively. Validation records the exact topic head it checked, and dispatch must capture that same head from the current trunk. Landing moves `main` only to the exact head a gate passed, and only from the trunk that head was based on, so `main` never holds a commit no gate ran on. The model intentionally abstracts command failures and detailed multi-revision stack topology; the operational rules below remain authoritative. `lifecycle/` implements the same protocol as an executable hierarchical state machine with [statig](https://crates.io/crates/statig): the control facts (editing, validated, conflicted, delivered, released) are states, and the data facts (heads, trunk, publication, gate verdict) are shared storage. Its tests walk every state of the bounded model, require the machine to accept exactly the events whose Quint action is enabled and to reach the same variables, and check every invariant, so `checks.x86_64-linux.ci-lifecycle` keeps the Rust machine and the specification in step. Change both together. Codex shell commands and OpenCode server shell execution receive a no-op `JJ_EDITOR` and an unpaginated `PAGER`. This keeps agent-run JJ commands from blocking on an editor or pager while leaving the normal interactive shell unchanged. Explicitly supply messages, filesets, revsets, and any available non-interactive flags for commands that prompt for other input. One task owns one topic and one stable change ID. A topic is a revision; a workspace is a working copy for one actor. Topics worked one at a time are sibling changes in the same workspace, and `jj edit` switches between them. A separate workspace is only for an actor that runs concurrently with the current working copy: another agent task, or a build, dev server, or editor whose files must not change underneath it. A topic may contain a series of logically separate JJ changes. Review fixes should be absorbed into the appropriate change instead of appended as "address review" commits. ```nu ci new -m "Topic title" # Start a topic on main@tangled in this workspace. ci start topic-name # Or, when the default checkout is busy: a workspace for this topic. ci status ci sequence # See whether the topic stacks on another in flight. ci rebase # Fetch trunk and rebase the whole topic stack. ci conflicts # Show conflicted revisions and files after a rebase. ci preflight # Run every pre-activation check when requested. ci test # Run tests/*-properties.nu, reporting each property as it finishes. ci review snapshot v1 # Capture the current series for interdiff review. ci dispatch # Push the same topic branch to Tangled. # After editing or absorbing review fixes: ci review snapshot v2 ci interdiff v1 v2 # At topic closeout: ci land # On a clear runway: build the flake checks locally, then fast-forward main. ci land --clearance github # Take clearance from GitHub Actions (or nixbot) instead. ci queue # With a landing in flight: hold the topic; the drainer lands it in turn. ci queue list # The runway, the line of held topics and why each holds its place, recent outcomes. ci queue move first # Move this topic in the line: first, last, up, down, or a position. ci park # Confirm the landing and free the workspace (`land` does it for a `ci start` one). # To drop an undispatched or closed topic instead: ci cancel # After activating the release: ci verify -m "how you tested it" # Occasionally, from any workspace: ci prune # List leaked workspaces and landed branches; --apply removes them. ci sim --shell # Try trunk plus dispatched user-facing topics, unactivated. ``` `ci test [--seed SEED] [SUITE...]` runs a repository's property suites, `tests/*-properties.nu`, each in its own Nushell. Every property prints `ok NAME (N cases)` or `FAIL NAME: MESSAGE` as it finishes, and `ci test` reports each as an OSC 7501 status under `SUITE/NAME`, so `watch-job` shows results as they arrive. A failing suite stops at its first failed property; the other suites still run. The ci MCP server's `property_tests` tool runs it as a job and relays each result line as a progress notification while it waits, returning the parsed `results` and the `failed` property names. ### Naming A topic travels to `main` in flight words: `new`, `sequence`, `preflight` and `sim`, `dispatch`, `land --clearance`, then `park` (or `cancel`), and `verify` once its release runs. The phases follow Wing's split: _preflight_ is everything before activation (evaluation, builds, closure proofs, landing clearance), and _inflight_ is everything on a running machine (activation, the activation log, `ci verify`). A refactor is a change with no inflight effect. Tools keep plain VCS words (`status`, `sync`, `rebase`, `conflicts`), and "release" means only a CalVer tag. The old names (`validate`, `plan`, `refresh`, `preview`, `publish`, `finish`, `abandon`, `tangled stack-publish`, and `land --gate`) still work and print their replacement. `ci new` fetches trunk and runs `jj new main@tangled`, leaving the previous topic untouched as a sibling. An empty working copy that is unnamed, or that an agent session claimed before naming it, becomes the topic in place instead: `ci new` moves it onto `main@tangled` and describes it, so its change ID, and the session's claim on it, stay. It refuses while an active agent session owns another change in the workspace, and in a `ci start` workspace for any topic but the one it was made for; start other work with `ci start` instead. A workspace from `ci start` serves its one topic until `park` or `cancel` removes it, so its name never outlives the topic. `ci start` records the topic's change ID in `.jj/jj-ci-workspace.json`, and every command that checks ownership refuses to run when the working copy is an empty change beside that unlanded topic, as after a manual `jj new main`; the error names the `jj edit` that returns to it. In an interactive Nushell, the `jj` wrapper from `guard.nu` refuses such a `jj new` before it runs when the working copy holds unfinished work, or when it would move the working copy off a change an agent session claimed. Plain `jj new` and `jj new --no-edit` still work, and `^jj new …` leaves the topic on purpose. ## Patch-series review The intended review model is an evolving patch series: ``` v1: A1 -> B1 -> C1 v2: A2 -> B2 -> C2 ``` Each commit should have one logical purpose and should be readable as part of the series. Use `jj edit` to select an earlier change, or use `jj absorb` to move an unambiguous fix into the change that introduced the affected lines. Descendants are rewritten as needed while retaining their change identities. Before each review update, run `ci review snapshot