jouet wait
jouet wait blocks until a condition holds, then prints one summary. It replaces sleep N; check; repeat loops, which spend a model turn on every check and are often blocked by the agent's harness.
The wait an agent needs most is on a pull request's CI. jouet wait ci with no arguments follows the checks of the current branch's PR, and returns as soon as one fails, with the failed step's log. Here it waits on the release check of a mise PR:
$ jouet wait ci 15195 --repo jdx/mise --check release --log-lines 15
[3s] ci jdx/mise#15195: head moved from e44754d to 843cc16
[3s] ci jdx/mise#15195: release fail
FAIL jdx/mise#15195 @ 843cc16 0 pass, 1 fail, 0 skipped, 0 pending (3s)
FAIL release step "Require auto-merge on the release PR" required
https://github.com/jdx/mise/actions/runs/41083340820/job/124157989724
Run echo "::error title=Release dry run not armed::Enable auto-merge on this pull request ..."
##[error]Enable auto-merge on this pull request to build and test the release tarballs.
##[error]Process completed with exit code 1.
full log: ~/.local/state/jouet/logs/jdx-mise-job-124157989724.logA hand-written loop around gh falls into two traps here. gh run view --log-failed refuses while the run is still in progress, so a failure cannot be read until every other job finishes. A conflicted pull request never gets pull_request CI, so the loop waits forever. jouet wait ci reads the failed job's log as soon as that job ends, and returns conflict at once for a conflicted PR.
Pick a subject
| Waiting for | Run |
|---|---|
| A pull request's checks | jouet wait ci |
| One GitHub Actions run or GitLab pipeline | jouet wait run 41083340820 |
| A pull request to be mergeable, merged, approved or ready | jouet wait pr --until merged |
| A server to log a line | jouet wait log app.log --match 'Listening on' |
| A port to accept connections | jouet wait port 3000 |
| A URL to answer | jouet wait http http://localhost:3000/health |
| A file to appear, or to contain a line | jouet wait file out/done.txt --contains ok |
| A process to exit | jouet wait pid 4242 |
| A command to succeed | jouet wait cmd -- pg_isready -h localhost |
A jouet job to end, or to be ready | jouet wait job test |
| A pitchfork daemon to be ready, or to stop | jouet wait daemon api |
Every subject takes --timeout (default 30m) and exits 124 when it runs out, so running the same command again keeps waiting.
Synopsis
jouet wait ci [PR] [--sha SHA] [--required] [--check GLOB]... [--ignore GLOB]...
[--all] [--log-lines N] [--no-logs] [--appear-timeout DUR]
jouet wait run RUN [--log-lines N] [--no-logs]
jouet wait pr [PR] --until mergeable|merged|closed|approved|checks-registered|ready|any-change
jouet wait file PATH [--contains REGEX] [--gone]
jouet wait log PATH --match REGEX [--from-start]
jouet wait port ADDR [--closed]
jouet wait http URL [--status CODE] [--contains REGEX] [--expect ASSERTION]...
jouet wait pid PID
jouet wait cmd [--expect-exit N] -- CMD...
jouet wait job ID [--until exited|ready] [--port N | --http URL] [--log-lines N] [--no-logs]
jouet wait daemon ID [--until ready|stopped] [--port N | --http URL] [--log-lines N] [--no-logs]
common: --timeout DUR (default 30m) --interval DUR (default 10s, backs off to 60s)
--json | --jsonl --quietEach flag is described in the CLI reference. PR is a number, a URL, owner/repo#123 or a branch, and defaults to the current branch's PR; --repo names the repository for a bare number or branch. RUN is a run ID, or an Actions run or GitLab pipeline URL.
Several subjects save a log under jouet's log directory: $JOUET_LOG_DIR, else $XDG_STATE_HOME/jouet/logs (~/.local/state/jouet/logs by default). This page calls it <log dir>.
Waiting on CI: wait ci
wait ci [PR] waits until every check on the PR's head commit has finished, or until one fails.
- Which commit. It follows the PR head. When a new commit is pushed (by an autofix bot, say), it switches to that commit, emits
head_changed, and reportshead_changed: true.--sha SHAwaits on one commit instead; the SHA needs at least 7 hex characters. - When it returns. On the first failed or cancelled check, with exit
1, unless--allis given. Skipped, neutral and stale checks count as passing. - Rerun checks. For GitHub Actions checks with the same name, jouet ignores an older workflow run only when it can identify a newer run of the same workflow, branch, event and check. If the identity is unavailable or ambiguous, it keeps the checks rather than assuming they are duplicates.
- Which checks.
--requiredkeeps only the checks that branch protection requires.--check GLOBand--ignore GLOBselect checks by name, where*matches any run of characters and?any one character. Both can be repeated. - Checks that will never come. A conflicted PR returns
conflictwith exit4, becausepull_requestworkflows do not run until it is rebased. jouet believes a conflict once GitHub reports it again at least 10 seconds later: for a moment after a push, GitHub's API still answers for the old head, so a conflict that a rebase has fixed can still look unfixed. If no checks appear on the commit within--appear-timeout(default3m), the result isno_checkswith exit1. Usewait pr --until checks-registeredright after pushing if you only want to know that CI has started. - Failure logs. For each failed GitHub Actions job, jouet fetches that job's log, which GitHub serves once the job is done even while the rest of the run is in progress. It cuts out the failed step, strips timestamps and ANSI colours, and keeps the step's last
--log-lineslines (default60;0keeps the whole step), plus earlier lines matchingerror|FAILED|panicked|assertwith two lines of context. Every gap is marked... N lines skipped. The full log is saved once to<log dir>/<owner>-<repo>-job-<id>.log, and its path is printed. Checks that are not Actions jobs report their name, conclusion and URL only.--no-logsskips all of this. - Trying the fix locally. When jactionlint is installed, each failed Actions job ends with
locally: jouet ci run WORKFLOW --check NAME. That command runs the job on this machine withjouet ci run, so a fix can be tried before it is pushed. - Base branch moved. When new commits on the base branch touch files this PR changes, a
base_touchedevent names the files, and the wait keeps going. This works on GitHub only so far. - GitLab, Forgejo and Entire. On GitLab the checks are the head's commit statuses, which hold its pipeline jobs: a job allowed to fail counts as skipped, every other job is required, and a failed job's trace is excerpted like an Actions log. On Forgejo the checks are the head's commit statuses, where Forgejo Actions reports; its API has no job logs, so a failed check keeps its URL. On a repository Entire hosts, the checks are the trail's check runs and its blocking gates as one Entire Gates check, with no logs. Neither Forgejo nor Entire says which checks are required, so
--requiredexits4there; name the checks with--checkinstead.--jsonaddshostfor a PR off GitHub. See GitLab, Forgejo and Entire.
The first word of the text result is PASS, FAIL, PENDING (on timeout), CONFLICT or NO_CHECKS.
--json prints repo, pr, head_sha, head_changed, result (success, failure, timeout, conflict or no_checks), elapsed_s, counts and checks. A failed check also carries failed_step, log_excerpt, log_truncated, log_path and, with jactionlint installed, local. The Entire Gates check carries its gates under entire, and counts.derived counts it when it is not a failure of CI. --jsonl adds check_registered, check_completed, head_changed, base_touched and rate_limited events.
Entire Gates
An Entire Gates check is derived, rather than a failure of CI, when it fails only because other checks failed, because the branch is behind or conflicting with its base, or because the trail still waits for an approval. A derived failure does not end the wait, so a rerun of the real failures is waited for rather than cut short by the old gate result. It is counted as derived, gets no FAIL block, and a closing line points at the real cause:
FAIL jdx/mise#15220 @ e96d4ee 52 pass, 1 fail, 31 skipped, 0 pending, 1 derived (3s)
FAIL release step "Require auto-merge on the release PR" required
...
Entire Gates fails for nothing CI did: checks: CI checks have not passed
the failed checks above are the causeFor a branch that is not up to date, the closing line gives the command that merges its base. An Entire Gates check that fails on open findings is a real failure: its gates are shown in the FAIL block, with a line pointing at jouet pr threads PR, which lists them.
Polling cost and shared state
- Checks are polled over GitHub's REST API with
If-None-Match, so a poll that finds nothing new is a304that does not count against the rate limit. - When the rate limit is used up, the wait sleeps until it resets if that comes before
--timeout, and otherwise exits5. - Every
wait cion the same PR shares one state file,$XDG_STATE_HOME/jouet/watch/<owner>-<repo>-<pr>.json(with-<sha>added for a--shawait), guarded by a lock. A wait polls GitHub only when that state is older than its own interval, so a second wait on the same PR, from another session or another agent, reads what the first one fetched instead of polling again. A restarted wait replays the events it missed for the current head, markedreplayed: true.
One run: wait run
wait run RUN waits for one GitHub Actions run or GitLab pipeline. It returns when the run completes, or on its first failed job, with the same log excerpts as wait ci.
It exits 4 on Forgejo, whose Actions runs jouet reads only through the commit statuses that wait ci follows, and on a repository Entire hosts, which has no runs.
Pull request state: wait pr
wait pr [PR] --until CONDITION waits on the pull request itself. Each condition exits 0 when it is met and 1 when it can no longer be met:
--until | Met when | Exits 1 when |
|---|---|---|
mergeable | GitHub reports the PR mergeable. UNKNOWN, while GitHub is still computing it, keeps the wait going | the PR conflicts with its base |
merged | the PR is merged | it is closed without merging |
closed | it is closed or merged | |
approved | the review decision is approved | changes are requested |
checks-registered | any check exists on the head commit | |
ready | the PR has no pr status attention codes and no pending checks | conflict, checks_failing, changes_requested or unresolved_threads appears, since only the agent can clear those |
any-change | anything changes: a push, a check result, a review, the number of unresolved threads, or the PR's state |
Every condition except closed counts a merged PR as met and a PR closed without merging as failed. As with wait ci, a conflict fails mergeable and ready only once GitHub reports it again at least 10 seconds later.
any-change prints the one change it saw, so wait pr --until any-change --jsonl under Claude Code's Monitor tool is a way to babysit a PR.
Local conditions
These subjects watch the machine the wait runs on. They stay deliberately small: starting and supervising long-running services, with their ready checks, is pitchfork's job, and one-off background work is jouet job's.
A log line: wait log
wait log PATH --match REGEX follows the file like tail -F and prints the first appended line that matches. It starts at the current end of the file, so lines already there do not count unless --from-start is given.
That matters after a restart. An agent restarts a server and waits for it, but app.log still holds the lines from the last run:
until grep -q 'Listening on' app.log; do
sleep 2
doneThe old "Listening on" line matches straight away, so the loop exits before this server is up, and if the server never gets there, the loop never ends. jouet wait log reads only what is appended after it starts, and gives up at --timeout:
$ jouet wait log app.log --match 'Listening on' --timeout 2m
[0s] log app.log: following
[10s] log app.log: matched
MET log app.log: matched (10s)
12:06:31 Listening on http://localhost:3000A file that does not exist yet is waited for and then read from its start. When the file is rotated (the path now names a different file) or truncated, it is read again from its start. A line still being written is matched too.
A file: wait file
wait file PATH waits until something exists at the path, a file or a directory. With --contains REGEX, it waits until a line of the file matches, and prints that line. With --gone, it waits until nothing exists at the path. --contains and --gone cannot be given together.
A port: wait port
wait port ADDR waits until a TCP connection to ADDR succeeds, or with --closed until every address it resolves to refuses connections. ADDR is host:port, [v6]:port, or a bare port, which means localhost.
Each connection attempt gives up after 5 seconds. A timeout or an unreachable network says nothing about the port, so it keeps the wait going, with or without --closed.
A URL: wait http
wait http URL sends a GET to an http:// or https:// URL until it answers with a 2xx status, or exactly --status CODE. Redirects are followed unless --status asks for a 3xx.
- With
--contains REGEX, a line of the body must match too, and that line is printed. - With
--expect ASSERTION, which can be repeated, every assertion must hold too. They are the assertionsjouet httptakes, such as--expect 'jsonpath $.ready == true', and the state line names the one that fails.
Each request gives up after 30 seconds, or at --timeout if that comes first. When it needs the body, jouet reads up to 16 MiB of it; a longer body counts as unreachable, and the wait goes on.
A process: wait pid
wait pid PID waits until the process exits. The process does not have to be jouet's child.
A command: wait cmd
wait cmd -- CMD... runs the command every interval until it exits with --expect-exit (default 0). It runs the command directly, not through a shell, so write sh -c '...' for pipes or &&.
It prints the last run's exit code and its last 20 output lines, and saves the full output of the last run to <log dir>/wait-cmd-<time>-<pid>.log. A run still going at the timeout is stopped, though every run gets at least one interval, so --timeout 0 runs the command once. A program that does not exist exits 3.
A background job: wait job
wait job ID waits until a jouet job ends. It exits 0 when the job exited 0 or was stopped, and 1, with the end of its log, when it exited with another code. With --until ready, it waits instead until the job's ready check passes. See jouet job.
A pitchfork daemon: wait daemon
wait daemon ID is for a project's long-running services, the daemons pitchfork runs; one-off work is wait job's. It waits until a daemon is ready, or with --until stopped until it no longer runs. It reads pitchfork status ID --json in the current directory, so a short ID such as api resolves in this project's namespace; namespace/api names one from anywhere.
$ jouet wait daemon web --http http://127.0.0.1:28932/ --timeout 30s --interval 1s
[0s] daemon web: stopped
[1s] daemon web: running, http http://127.0.0.1:28932/ unreachable: io: Connection refused (os error 111)
[2s] daemon web: running, http http://127.0.0.1:28932/ status 200
MET daemon web: running, http http://127.0.0.1:28932/ status 200 (2s)pitchfork run and pitchfork start already wait for their own ready check before they return. wait daemon is for a daemon something else started or restarted: a file watcher, pitchfork restart in the background, another session, or the supervisor at boot.
- Ready. pitchfork's JSON does not say whether its own ready check has passed: a daemon is
runningas soon as its process starts. So ready meansrunningand, when there is somewhere to ask, answering there:--port N(localhost's port accepts connections),--http URL(a 2xx answer), or else the port pitchfork says the daemon binds, when it says one. A oneshot daemon that hascompletedcounts as ready. - Failure. A daemon that is
erroredorfailedends the wait at once with exit1andFAILED, even while it would otherwise keep waiting. Then, and on a timeout, jouet prints the end of the daemon's log, cut likewait ci's excerpts: its last--log-lineslines (default60;0keeps all of it), plus earlier lines matchingerror|FAILED|panicked|assertwith two lines of context, with every gap marked. pitchfork keeps logs in a database rather than in files, so jouet saves a copy to<log dir>/wait-daemon-<id>-<time>-<pid>.logand prints its path.--no-logsskips this. - Exit codes.
3when pitchfork has no daemon by that ID,4when pitchfork is not installed.
$ jouet wait daemon api --log-lines 8
[0s] daemon api: errored (exit code 1)
FAILED daemon api: errored (exit code 1) after 0s
... 197 lines skipped
request 198 ok
request 199 ok
request 200 ok
Error: listen EADDRINUSE: address already in use :::3000
at Server.listen
at main
Node.js v22.11.0
full log: ~/.local/state/jouet/logs/wait-daemon-myproj-api-1793408181687-1915723.logTimeouts and polling
The first check is immediate. After that, the time between checks starts at --interval and grows by half again after each check that saw no change, up to 60 seconds (or --interval, if that is longer): with the default 10s, the gaps are 10, 15 and 22.5 seconds, then about 34 and 51, then 60. It drops back to --interval when the state changes.
No wait runs past --timeout, and there is one last check at it, so --timeout 0 checks exactly once. On timeout, jouet exits 124 and says how many checks ran:
$ jouet wait port 3000 --timeout 5s
[0s] port localhost:3000: closed
TIMEOUT port localhost:3000: closed after 5s (2 checks); run it again to keep waitingRunning the same command again keeps waiting. A new wait ci reads the shared state the last one left, and replays the events it missed.
Long waits from an agent
Run long waits as background tasks where the harness supports it (Claude Code's run_in_background, which notifies the agent when the command exits). Otherwise, pass a --timeout shorter than the harness's command timeout and run the command again on exit 124.
Output
$ jouet wait log app.log --match 'Listening on'
[0s] log app.log: missing
[4s] log app.log: matched
MET log app.log: matched (4s)
Listening on http://localhost:3000- Progress goes to stderr. For a person at a terminal, one status line is redrawn every second. For agents, pipes and CI, each change of state is one line, so a backgrounded wait's log grows only when something happens.
- The result goes to stdout. For the local subjects and
wait pr, its first word isMETorTIMEOUT, andwait pr,wait jobandwait daemonalso haveFAILED. A timeout says how many checks ran.wait ciandwait runstart with the words described above. --jsonprints one document. For the local subjects, it holdssubject,target,result(met,failedortimeout), the laststate,elapsed_sandchecks, plus the subject's own fields:line,status,exit_code,output,output_truncatedandlog_path. Empty fields are left out, as in{"subject":"port","target":"localhost:3000","result":"timeout","state":"closed","elapsed_s":5,"checks":2}.--jsonlprints one{"event":"state",...}line for each change of state (and, for the GitHub subjects, their own events), then the result document tagged"event":"result". Under Claude Code's Monitor tool, each line becomes a notification.--jsonand--jsonlcannot be given together.--quietprints no progress and no text result, only the exit code. JSON is still printed when it is asked for.
Exit codes
| Code | Meaning |
|---|---|
0 | The condition was met |
1 | It can no longer be met: a check failed, no checks appeared, the PR was closed, changes were requested, the job exited with an error, the daemon errored |
2 | Bad arguments, such as an invalid duration or regex |
3 | The PR, run, job or pitchfork daemon does not exist, or wait cmd's program does not |
4 | The PR is conflicted, so no pull_request CI will run; the forge cannot do what was asked (wait run on Forgejo or Entire, --required where the forge does not say which checks are required); or wait daemon found no pitchfork |
5 | Authentication, network or rate-limit failure talking to GitHub |
124 | Still waiting at --timeout; run the same command again to keep waiting |