CLI and APIs
Wait for CI, merges and pushes with src
Your agent pushed a fix, and now it waits for CI, or for the merge queue to merge the pull request. A loop that runs src pr checks or src pr view every few seconds wastes calls, and it sees the result late.
7 min read
src watch keeps a live stream open to the forge. It prints each change as one JSON line at the moment that the change happens.
1. Wait for the checks of your pull request
src watch checks 7 --exit-status
{"type":"checks","pr":7}
{"type":"checks","pr":7}
- Each line says that the checks of pull request 7 changed.
- The command stops when the head commit has checks and none of them is pending.
- With
--exit-status, it exits with 1 when a check failed, and with 0 when all passed. - If the checks are already done when you start, it exits at once and prints nothing.
Then read the result with src pr checks 7.
2. Wait until your pull request merges
You added the pull request to the merge queue (src pr queue add 7) or turned on merge when ready (src pr merge 7 --auto --squash). Now wait for the merge:
src watch pr 7 --exit-status
{"type":"item","kind":"pull","number":7,"state":"open"}
{"type":"checks","pr":7}
{"type":"item","kind":"pull","number":7,"state":"merged"}
- The command stops at the line that says
"state":"merged", at the moment that the pull request merges. - If the pull request merged before you started,
srcprints itsmergedline and exits at once. You never wait for a change that already happened. - It also stops when the pull request closes without a merge, and when it leaves the merge queue or merge when ready turns off without a merge, for example after a failed check. Then nothing merges it any more. With
--exit-status, it then exits with 1.src pr view 7 --commentsshows why it left. - If the pull request is not in the merge queue and merge when ready is off, nothing merges it.
srcwrites a warning that says so, with thesrc pr queue add 7command, and then waits until a person merges or closes the pull request. src watch issue 12stops when the issue closes, for example when the release job closes a staged issue.
Do not filter the lines yourself to find the merge, for example with grep merged. Use the exit code of the command. Then src pr view 7 --json mergeCommit,mergedAt gives the merge commit and the time.
3. Wait for one CI run
src watch run 4c1d9a2e-7b3f-41a0-9c55-2f8e6d0b1a37 --exit-status
{"type":"run","id":"4c1d9a2e-7b3f-41a0-9c55-2f8e6d0b1a37","workflow":"test","ref":"refs/heads/fix-login","headSha":"9f2c4e1a7b3d5f6081c2e4a6b8d0f1a3c5e7b9d2","pr":7,"status":"running","conclusion":null}
{"type":"run","id":"4c1d9a2e-7b3f-41a0-9c55-2f8e6d0b1a37","workflow":"test","ref":"refs/heads/fix-login","headSha":"9f2c4e1a7b3d5f6081c2e4a6b8d0f1a3c5e7b9d2","pr":7,"status":"completed","conclusion":"failure"}
- The command stops when the run completes.
- With
--exit-status, it exits with 1 when the conclusion is notsuccess. - If the run is already complete when you start,
srcprints its state as onerunline, then exits.
Get the run id from src run list.
4. Follow the log of one CI job
A job runs for minutes, and you want to see its output while it runs. Give the run and the job name, and add --log:
src watch job "test (shard: 1)" --run 4c1d9a2e-7b3f-41a0-9c55-2f8e6d0b1a37 --log --exit-status
test (shard: 1) Install Done in 4.2s
test (shard: 1) Test FAIL src/login.test.ts
--logprints the new lines of the log as text, in the format ofsrc run view --log: the job, the step and the line, with tabs between them.- With
--run, the job is its name or its job id.src run view <run>lists the jobs. - The command stops when the job completes. With
--exit-status, it exits with 1 when the conclusion is notsuccess.
Without --log, src watch job <job id> takes the job id only, and prints one log line each time a step gets new lines:
{"type":"log","job":"job-7","step":2,"lines":140,"finished":false}
{"type":"log","job":"job-7","step":2,"lines":212,"finished":true}
The databaseId of each job in src run view <run> --json jobs is its job id.
5. Wait for a push
src watch --events push --branch main --timeout 600
{"type":"push","ref":"refs/heads/main","head":"3b7e0c9d1f2a4b6c8e0d2f4a6c8e0b2d4f6a8c0e"}
headis the tip of the branch when the forge read the event. It isnullwhen the branch was deleted.- A push, a merge on the forge, and a branch that GitHub sync moved each give a
pushline. - Without
--timeout, this scope runs until you press Ctrl+C.
Done
Your agent waits for CI, and then for the merge, with one command each. It reacts when the result comes:
src watch checks 7 --exit-status && echo "CI passed"
src watch pr 7 --exit-status && echo "Merged"
For a person in a terminal, src run watch <run> and src pr checks 7 --watch show a table, and they draw it again at each change of the run or the checks. See Use the gh commands that you know.
What to watch
| Scope | You get |
|---|---|
none, or repo | Every change of the repository. |
pr <number> | The pull request, its checks, and the pushes to its head branch when that branch is in this repository. Stops when it merges or closes, or when it leaves the merge queue or merge when ready turns off. |
issue <number> | The issue. Stops when it closes. |
checks <number> | The checks of the pull request. Stops when they are done. |
run <id> | The CI run. Stops when it completes. |
job <id> | The log of the CI job. Stops when the job completes. |
With pr and checks, you get no run lines. A checks line tells you that the CI of the pull request changed.
The events
| Line | Meaning |
|---|---|
{"type":"item","kind":"pull","number":7,"state":"open"} | An issue or a pull request changed, for example a new comment or a merge. kind is issue or pull. state is open, closed or merged at the time the forge read the event. |
{"type":"checks","pr":7} | The checks of a pull request changed. |
{"type":"push","ref":"refs/heads/main","head":"..."} | A branch or a tag moved. |
{"type":"run","id":"...","status":"completed","conclusion":"success",...} | A CI run changed. It also has workflow, ref, headSha and pr. |
{"type":"log","job":"...","step":2,"lines":140,"finished":false} | Step step of the job has lines lines now. Steps count from 0. finished is true when the step ended. |
{"type":"reset"} | The forge could not keep the changes since your last read. Read the state again. |
You get only the events that your login can read:
- A
pushneeds read access to the code. - A
checksline needs read access to pull requests and CI. - A
logline needs read access to CI. - A run of a hidden workflow never gives a line. The log of its jobs is for admins only.
Flags
--events item,checks,push,run: only these kinds of events.--branch <name>: leave out the pushes and the runs of other branches.--timeout <seconds>: stop after this time.--exit-status: exit with 1 when the pull request closed without a merge, or the run, a check or the job failed. Not withrepo, which never stops by itself.--run <run id>: the run of the job. Only withjob.--log: print the new log lines as text. Only withjob, and it needs--run.-R <owner>/<repo>: watch another repository.
The job scope takes no --events and no --branch.
Exit codes
| Code | When |
|---|---|
0 | The pull request merged or closed, the issue closed, the run, the checks or the job are done, or --timeout ended a repo watch. |
1 | With --exit-status, the pull request closed or left the merge queue without a merge, or the run, a check or the job failed. |
8 | --timeout ended a pr, issue, run, checks or job watch before it was done. |
When the connection drops
- The forge ends each stream after 60 seconds.
srcopens the next one at once, from the last event it got, so it loses no event. - If the forge cannot answer or is busy,
srctries again after 1, 2, 4, 8 and 16 seconds. Then it stops with the error. - On a forge with no stream,
src watchasks the wait route of the forge again and again. You get the same lines.
A tool that does not use src gets the same events over REST or MCP. See Wait for changes over REST and the wait_for_events tool in MCP tools.