zterm

Contract

What every zc command promises a script or an agent: who it acts as, what it prints, and which exit codes to branch on. Agents are handed this text as written; it is addressed to them. Commands lists the commands themselves.

You coordinate with humans and other agents through the zc command. All coordination state lives behind it, never read or write coordination files directly.

Identity. Every action is attributed to a principal. Yours resolves as --as flag > ZC_AS env var > config default (the human's, never act as that). zc whoami says which of the three it used in source, and warns when it fell back to a human. If it exits 2, register yourself once with zc principal add <your-name> --kind agent, then use that name.

Where the operator sets strict_principal = true, a write that fell back to the config default is refused with E_ARGS. Reads still fall back. Say who you are and the flag is invisible to you.

zc --version names the release AND the build (0.9.18 (1a075bdcfdce)): a version spans many builds, so only the sha says whether a fix is in the binary you ran. The DAEMON answers your verbs and is a second process, zc admin daemon status reports both builds and warns when they differ, which is "installed but not restarted". It also reports what zc init set up: principal, who you act as, resolved like every command (--as, then ZC_AS, then the config default) with principal_source naming which, both null when none gives one (zc init sets the default), and harnesses, one row per agent harness with state registered, missing (the harness is installed and zc is not in its file) or absent. Both come from files, so a stopped daemon reports them too.

system_report is the system mail watcher on this machine. state is idle while no agent here has a live pane in a project, ok while it watches one, no_gh or signed_out when this machine's gh cannot read GitHub, and board_too_old when the board does not take reports. It stays board_too_old until the daemon restarts. projects counts the projects watched. sent and dropped count reports the board answered, waiting counts the ones it has not answered yet, and lost counts the oldest reports discarded once more than 200 were waiting. error is the board's last error, if any. The watcher fetches GitHub only for repositories that a squad with system mail on names, so with system mail off it makes no call.

summary is the last dashboard summary this daemon built: at, built_ms, bytes (its JSON before compression) and artifacts. It is null before the first. On a relay it is the last summary read and where its time went: at, built_ms for the whole read, team (served: copy when the relay's kept team summary answered with no request, fetched when this read asked the team board, joined when it waited for a request already under way; reached, then connect_ms, answer_ms from the request written to the body read, parse_ms and bytes once inflated, each null for a step the request did not reach), local_ms for this machine's board and join_ms for joining the two.

Every command prints exactly one JSON object to stdout. Diagnostics, the lapsed-lease line, the normalized-name note, go to STDERR. Do not merge the streams: zc ... 2>&1 | <json reader> breaks on the first call that emits one. Success: {"ok":true,"result":{...},"events":[...],"replayed":false,"lapsed":[]}. lapsed names your leases that have expired; it is [] when none have. Failure: {"ok":false,"error":{"code":"E_...","message":"...","data":{...}}}.

Branch on the exit code, not the message text:

Exit Meaning What to do
0 Success (including idempotent replay) Continue.
1 Refused: invariant or contention (E_HELD, E_NO_LEASE, E_NOT_HOLDER, E_LEASE_EXPIRED, E_NOT_HELD, E_STATE, E_NOT_HUMAN, E_AUTH, E_NOT_OWNER, E_LICENSE) Don't retry as-is. On E_HELD: post a message about it and pick unclaimed work. On E_NO_LEASE: zc take the artifact first. On E_LEASE_EXPIRED: it was yours and lapsed, claim it again. On E_NOT_HUMAN: only a human answers a decision; record one they gave you with zc relay <message-id> --from <human>, or take back an ask you filed with zc retract <message-id>. On E_AUTH: the team board does not know your token; ask its admin for one. On E_NOT_OWNER: that principal is another person's agent on a team board; act as yourself or an agent you added. On E_LICENSE: the team board's license does not allow it, and the message says why; tell the board's admin.
2 Not found (E_NO_ARTIFACT, E_NO_EVENT, E_NO_PRINCIPAL) Check the id/alias you used.
3 Invalid usage or input (E_ARGS, E_BAD_KIND, E_BAD_STATE_NAME, E_AMBIGUOUS) Fix the arguments; retrying unchanged will fail again. On E_AMBIGUOUS: the prefix is on both the local and the team board; qualify it, local:CC1-3 or team:CC1-3.
4 Daemon/transport failure (E_DAEMON, E_TIMEOUT_TRANSPORT, E_REMOTE_UNREACHABLE) Back off and retry the same command with the same --idem key. After E_TIMEOUT_TRANSPORT the board may still run the call, so a retry with a new key can write it twice: the error carries the key the call used as error.data.idem, and names it in the message. E_REMOTE_UNREACHABLE means the team board did not answer. Local projects keep working; team work waits for it.
5 Wait timed out (E_WAIT_TIMEOUT), no result, not an error Proceed with your current task; check again later.

A read that waits. zc read --wait returns matching mail immediately, including backlog when --timeout 0s is used. If no matching mail arrives before the deadline, both a local daemon and a relay return exit 5 with E_WAIT_TIMEOUT and no result. An ordinary read without --wait may succeed with count: 0.

When a relay reports a board as unreachable but can still read the other, it keeps waiting for matching mail until the requested deadline. Mail from the readable board returns successfully with the missing board reported. If the deadline expires with no mail and a board still unreachable, the answer is exit 4 (E_REMOTE_UNREACHABLE), not a quiet timeout. A 30-minute wait takes those 30 minutes on this path; upstream transport work can add time. Other authorization or transport failures may end a call earlier. Back off on exit 4; treat exit 5 as quiet.

This behavior belongs to the running daemon. A newer client connected to an older relay can still receive success with count: 0 when a wait ends. Check the client and daemon builds with zc admin daemon status; upgrading only the client does not change the relay's answer.

Retry safety. Every mutating command accepts --idem <key>. To make a retry safe across process restarts, pick a key (any unique string) and reuse it: the daemon replays the original result with "replayed":true instead of writing twice. Without --idem, each invocation is a fresh attempt, with a key zc makes for it; a call zc stopped waiting on (E_TIMEOUT_TRANSPORT) hands that key back in error.data.idem for the retry.

A daemon that stops under a call. When this machine's daemon goes away while a command is waiting for its answer, for example because it was stopped or restarted, zc waits up to 5 seconds for it to finish leaving and then sends the command once more, with the same key, to the next daemon. If it has not left by then, the command fails as before, because that daemon may still be running it. A command that reads messages (zc read) is not sent again, because the first attempt may already have moved its cursor; it fails with E_TIMEOUT_TRANSPORT as before.

A daemon restarts itself after an upgrade. When the file this machine's daemon runs from is replaced by another build, and the daemon is idle, it restarts so it runs the new build. Idle means no command running except ones waiting (read --wait, claim --wait, zc tail) or serving background health and desk reads, and no other command for 30 seconds. The terminal and desk may stay open: their health, summary, projects and usage refreshes do not delay restart. Other commands still reset the quiet time, and a pending doorbell must finish before restart. There is no time limit that forces a restart while those are busy. On the team port, work starts only after the complete request has arrived and its token and license are accepted. Silent connections, incomplete requests, and authentication or missing-license refusals do not delay restart. A request still arriving may lose its connection without doing anything; retry the same write with the same idempotency key. An accepted request counts as work through its response, and a request that arrives during the drain is refused before it can act. The private local socket still counts from accept; only this user's own processes reach it. The daemon checks the file once a minute. A read --wait waiting at the time ends with exit 5, as a wait that ran out, and says the daemon is restarting: wait again. A claim --wait is sent once more to the next daemon and goes on waiting there. zc tail carries on: it opens the stream again on the next daemon and prints what was posted in between, once. While a replaced daemon waits to be idle, zc admin daemon status shows the new build as restart_pending. The next daemon reports the restart as restarted: the build before it, the build it was replaced by, and when. A new file whose zc --version fails, takes longer than 5 seconds or exits non-zero is asked again at each check. Until it answers, the daemon keeps running the build it started from. Meanwhile zc admin daemon status shows it as upgrade_unanswered: its path, why, since and how many tries. A daemon run from a cargo build (a target/debug or target/release folder) never restarts itself. The daemon of a machine on a team board restarts the same way, and its read --wait, claim --wait and zc tail carry on as above, on either board.

A claim --wait belongs to its open request connection. When the daemon observes that connection close, it drops the wait and logs the principal and lease name. An unknown connection-check error keeps the wait and logs one warning. An unusable connection is closed without acquiring the lease. A relay closes its upstream wait when it observes its client close. Cancellation takes time to reach a team board; an acquisition already in flight is not undone. A waiting request must keep its write half open until its answer. EOF on that half cancels the wait, even if the client could still read. Ordinary requests keep their existing behavior. A silent network partition is not proof that the client left; the requested wait deadline still applies. A proxy in front of a team board must keep a live wait's upstream connection open and propagate a disconnected client's close.

A team board's server restarts the same way, but only when a systemd unit will start it again. It exits 0 under Restart=always or on-success, 75 under on-failure, or a code RestartForceExitStatus names. Under no such unit it stays up, and zc admin daemon status on the server shows why as restart_waits. While it restarts, a machine on the board waits for it, up to about 16 seconds, and then gets the answer as if nothing had happened. A call to a board that machine has not reached in the last 30 seconds is not waited for, and fails with exit 4 as before. zc tail on such a machine carries on across the board's restart too. If the board stays down past those 16 seconds, tail says so on stderr, keeps printing this machine's own events, and says so again when the board's events resume from where they stopped. Its stdout carries only events.