Skip to content

The HTTP API

For anyone integrating with the daemon over HTTP rather than the CLI. After this page you will know the transport and socket path, how requests are authenticated, the response envelope every endpoint uses, and where the generated endpoint table lives.

The Agent Factory daemon exposes a small JSON API — a 1:1 mirror of the session and task operations the af CLI performs — over a local Unix socket. It is the same daemon core (#960 single-writer model) the TUI and af sessions / af tasks commands already drive, reached over HTTP instead of the internal net/rpc control socket, so the two surfaces can never diverge.

This page is a hand-written guide to the transport, auth, and envelope; the enumerated endpoint table is generated from the route catalog (see HTTP API reference). There is deliberately no OpenAPI/Swagger document in v1. To discover the surface from the command line without reading this file, run:

af api          # human-readable catalog: socket path, auth model, every endpoint + a curl example
af api --json   # the same catalog as JSON, wrapped in the shared {data,error} envelope

af api is read-only and local: it prints the catalog and the resolved socket path but never dials the socket or starts the daemon. Its catalog is derived from the daemon's actual route table, so it always matches what the server serves.

Transport & socket path

The API is served over a dedicated Unix socket:

$AGENT_FACTORY_HOME/daemon-http.sock

$AGENT_FACTORY_HOME is where Agent Factory keeps its state. It resolves as:

  1. the AGENT_FACTORY_HOME environment variable, if set (with a leading ~ / ~/ expanded); otherwise
  2. the default config dir, ~/.agent-factory.

So on a default install the socket is ~/.agent-factory/daemon-http.sock. af api prints the resolved path for your environment.

The socket is created when the daemon starts (on demand — a bare af launch starts it, or via an autostart unit — see tasks.md). If the socket does not exist, the daemon is not running.

Authentication

On this socket there is no token. Authentication is the filesystem:

  • The socket is a Unix domain socket, reachable only from the local host — never the network.
  • It is created with 0600 permissions (owner read/write only), so only the user who owns the daemon process can connect. Group and other have no access.

This matches the model of the daemon's internal control socket. It is a single-user, local-only API by design: anyone who can read the socket already runs as your user and could drive af directly, so no additional secret buys anything. Do not proxy this socket to a network interface.

Reaching the daemon from another machine

To drive the daemon from a different host — a remote TUI, or the browser web client — don't proxy this socket. SSH to the host and run af there, or expose the HTTP+token TCP listener to the network (it's on by default on loopback; point network.listen_addr at a routable host:port). The listener is plain HTTP — front it with a TLS-terminating proxy or a private network. Both are covered in Remote daemon access. The TCP listener answers only requests whose Host names this daemon (localhost, loopback IPs, its own address, or a network.allowed_hosts entry) and refuses any other with 421 Misdirected Request before routing — see Host names the daemon answers to. It also refuses any cross-site browser request, and any POST, PUT, PATCH or DELETE that does not send Content-Type: application/json (even with no body) — see Cross-site browser requests. The Unix socket has neither check: a browser cannot reach it, and the curl --unix-socket … -d examples below keep working.

Response envelope

Every response — success or failure, on every endpoint — is the same {data, error} JSON envelope shape the CLI's --json flag emits. HTTP errors additionally carry the daemon outcome markers described below.

A success carries the payload under data with error: null:

{
  "data": { "ok": true },
  "error": null
}

A failure sets data: null and populates error.message:

{
  "data": null,
  "error": {
    "message": "agent-factory daemon is starting (restoring sessions); retry shortly",
    "daemon_rejected": true
  }
}

Both members always serialize (no omitempty), so a consumer can branch on error === null without a presence check. Every response sets Content-Type: application/json.

Ordinary errors emitted by the daemon's HTTP handler include error.daemon_rejected: true, an optional boolean identifying a daemon rejection. Only the boolean true counts; strings and other truthy values do not. A JSON error body or a 500/503 status alone does not establish that provenance: a reverse proxy may return its own error after forwarding a mutation that the daemon accepted. Clients must treat an unmarked 5xx, a lost reply, or an unfamiliar error envelope as an uncertain outcome, check the session's state, and avoid automatically retrying the mutation. The web client also treats 502 and 504 as uncertain even if a marker is present, since the daemon does not emit those gateway statuses. The marker is a protocol convention, not authentication against a proxy that deliberately copies it.

error.code: "proposal_conflict" is the one failure that also carries data: a 409 from SaveProposalDoc puts the three versions of the doc there so the editor can show the conflict. Every other failure keeps data: null.

error.code: "mutation_committed" is the existing, separate outcome marker for a mutation that reached durable storage before a follow-up failed. It takes precedence over daemon_rejected if both occur: surface the detail without retrying the completed mutation. The daemon omits daemon_rejected from these committed-outcome envelopes. CLI --json ordinary errors retain their existing shape without the HTTP provenance marker.

error.code: "project_rebound" (status 409, with daemon_rejected: true) is the refusal both rebind routes give a compare-and-set rebind — see Rebinding a project. Nothing was written, so it is a definitive refusal, not an uncertain outcome.

error.code: "daemon_restarting" (status 503, with daemon_rejected: true) says the daemon refused the request without running it because it is restarting: whoever stopped it starts its successor (af upgrade, af daemon restart, af daemon adopt, the CLI auto-update, or a systemctl --user restart of its unit). Retry the request, and it reaches the successor. Classify the refusal by its code, never by error.message, whose wording may change.

Status codes

Status Meaning
200 OK Success. data holds the response payload; error is null.
400 Bad Request The request body was not valid JSON, or it carried a field this daemon does not recognize (see Unknown fields).
404 Not Found Unknown route (e.g. POST /v1/Nope), or an id-keyed tab RPC (CloseTab/RenameTab/ReorderTab) whose tab_id was resolved against the roster but vanished before the mutation committed (a concurrent close won the race); error.code is tab_gone. A tab_id that was never in the roster is a 500 — resolveTabTarget refuses to fall back to the name or index and returns a descriptive error.message instead.
405 Method Not Allowed Wrong verb — RPC routes are POST-only; /v1/health is GET-only.
409 Conflict POST /v1/RebindProject and POST /v1/RebindProjectGuarded: part of the request's expected pair no longer matches the project's record — expected_root against the recorded root, expected_checkout_id against the recorded checkout marker (which a same-path reclone or repair rotates) — because another rebind or re-clone landed first. error.code is project_rebound. See Rebinding a project.
409 Conflict SaveProposalDoc: the save conflicts with a newer edit and nothing was committed. error.code is proposal_conflict, and data is not null — it holds {ours, theirs, base, head} (see docs/dev/proposals/proposal-mode/api.md).
413 Request Entity Too Large The body exceeded the 16 MiB cap. The request is rejected, never truncated-then-processed — the daemon is never reached.
503 Service Unavailable The daemon refused the request without running it, because of where it is in its lifecycle. A daemon that is starting, validating an upgrade, handing off to one, or restarting (error.code is daemon_restarting) refuses only for a moment, so retry. A daemon shutting down for good answers "agent-factory daemon is shutting down; retry after it restarts": retry once a daemon is running again.
500 Internal Server Error The handler ran but returned an error (validation failure, not-found session, a disabled task refused by TriggerTask, etc.). error.message carries the detail.

The status maps the transport outcome; a business-logic failure (e.g. "session not found") is a 500 with a descriptive error.message, not a bare status.

Unknown fields

How the daemon treats a request field it does not recognize depends on whether the request identifies itself as an af client, because the same unknown field means opposite things to the two kinds of caller.

Hand-authored requests (curl, af api, your own scripts) are decoded strictly: an unrecognized key is a 400. This is deliberate. An unknown key is almost always a typo, and dropping it silently can widen what an RPC does — a typo'd repo_idd leaves repo_id empty, which turns a one-repo Snapshot into an all-repo Snapshot. Failing loudly is the safer answer:

$ curl --unix-socket ~/.agent-factory/daemon-http.sock \
    -X POST http://af/v1/Snapshot -d '{"repo_idd":"typo"}'
{"data":null,"error":{"message":"malformed JSON request body: json: unknown field \"repo_idd\"","daemon_rejected":true}}

Requests carrying the X-AF-Client-Version header — which the af TUI and CLI send automatically — are decoded leniently: unrecognized keys are ignored. The daemon is upgraded independently of its clients, so a client newer than the daemon legitimately sends fields the daemon has never heard of. Fields are additive and never renamed, so ignoring an unknown one is always safe, whereas rejecting it would turn every version skew into a hard failure.

The bundled web UI sends the header too and is decoded leniently. Its service worker and an already-open tab can outlive a daemon restart, so RestoreSession.expected_daemon_boot_id is sent only after a Snapshot supplies a boot_id; a current daemon refuses a mismatch before restore admission, while a legacy Snapshot keeps the older request shape.

Setting the header by hand is supported but simply opts you out of typo checking — it is not an authentication or trust boundary.

Note this lenient decoding only exists in daemons that ship with it. If a newer client talks to an older daemon, that daemon still rejects the newer field, and af clients report it as a version skew:

daemon is out of date and rejected the "tab_id" field this client sent —
restart it with `af daemon restart`

Restarting the daemon (so it matches the af binary on disk) is the fix.

Warm-up behavior

The daemon binds its sockets before it finishes restoring sessions. During that window:

  • GET /v1/health answers immediately (it is a pure liveness probe) — it does not wait for the restore.
  • State-dependent routes (session and task RPCs) return an error envelope with the message agent-factory daemon is starting (restoring sessions); retry shortly. Treat it as retryable: the daemon is alive; the same request succeeds once the restore completes.

Endpoints

The full, enumerated route table — every method, path, and request-body field — is generated from the daemon's route catalog and lives in the HTTP API reference. It cannot drift from the server: the same catalog backs the mux, the af api command, and that page. Request-body fields are the JSON keys of each RPC request struct; a route with no listed fields accepts an empty body (-d '{}' or no -d at all).

GET /v1/health is the one non-POST route: a liveness probe (alias for the internal Ping RPC) that answers even while the daemon is restoring sessions, with response data of { "ok": true }.

Rebinding a project

POST /v1/RebindProject moves a registered project's stable id to the checkout at path. It accepts an optional observed pair — expected_root, the root the caller last saw the project bound to, and expected_checkout_id, the checkout marker behind it (the root and checkout_id from POST /v1/ListProjects):

curl --unix-socket ~/.agent-factory/daemon-http.sock \
    -X POST http://af/v1/RebindProject -d '{"id":"prj_…","path":"/home/me/src/repo","expected_root":"/home/me/old/repo","expected_checkout_id":"chk_…"}'

With either expected field set, the rebind is a compare-and-set on the pair. The daemon applies it only if the registry still records that root and that checkout id when the registry lock is taken — the checkout half is what sees a reclone or repair at the same path, which keeps the root spelling but mints a new marker — so of two rebinds made from the same observed pair, exactly one applies. The other gets 409 with error.code: "project_rebound", and its message names the root and checkout the project is bound to now. Re-read the registry, show the user the current pair, and retry with it if they still want the move. A request whose path is already the recorded root and whose checkout still matches also succeeds, so a retried request that already landed is not refused.

expected_root and expected_checkout_id are optional. A request that omits both is applied whatever the project is bound to, so the last writer wins — what clients written before the fields existed send, never refused for the omission. The TUI and web client send the pair they displayed. af projects rebind does not; it rebinds unconditionally, as before.

A daemon that predates the fields treats them like any unknown fields (see Unknown fields). It rejects a hand-authored request with 400. For a request with X-AF-Client-Version, such as the TUI's, it ignores them and applies the rebind without the check — which is why a guarded client sends the pair to POST /v1/RebindProjectGuarded instead: that route exists only on daemons that implement the precondition, so a daemon that predates it answers its marked 404 and the client surfaces an upgrade refusal rather than silently downgrading to last writer wins. The route is the capability check — atomic with the mutation, where a GET /v1/health probe answered by one daemon could never vouch for the sibling a proxy might route the mutation to. RebindProjectGuarded refuses a request that omits both expected fields; last-writer-wins stays on POST /v1/RebindProject.

Not in the catalog. The generated table is af api's discovery surface — the client-facing session and task RPCs — so the daemon serves several routes it does not list. They fall into three groups:

  • Internal JSON-envelope RPCs, same shape as the cataloged ones but deliberately unadvertised as public API: POST /v1/Preview (the TUI's render path), POST /v1/PauseStatusPoll and POST /v1/ResumeStatusPoll (attach coordination), POST /v1/HandoffSessionV2 (the version-bound account-aware handoff transport), and POST /v1/WorkspaceFacts (reads a session's workspace for kill confirmations: the off-box TUI's remote measurement of what a kill destroys, and the web client's local kept-branch lookup).
  • Non-RPC surfaces, which speak something other than the envelope: the WebSocket planes GET /v1/sessions/{id}/stream, GET /v1/sessions/{id}/stream-info and GET /v1/events; the config-assistant trio on /v1/config-assistant and the account-login stream GET /v1/account-login/stream (bare-session PTY WebSockets that serve no Instance); GET /v1/auth-info, the tokenless probe that reports whether this peer must present a token (see remote daemon access); GET /v1/preview-auth; POST /v1/editor-origin, which mints a session's editor-origin bootstrap URL for a remote viewer (see Web UI); and the web-tab reverse proxy under /v1/webtab/.
  • The profiling endpoint, GET /v1/debug/pprof/{profile}, when it is switched on. It is off by default, is served on this socket only and never on network.listen_addr, and returns the ordinary 404 unknown-route envelope while it is off. Its handlers are net/http/pprof's, mounted with the same GET-only method qualification the stdlib uses. See Profiling the daemon.

Reading a session's screen. PreviewSession takes { "id": "<session-id>", "lines": <1-40> } and returns { "text": "…" }: the last lines lines (default 40) of the session's agent tab as plain text. Escape sequences and control characters other than newline and tab are removed, and trailing blank rows are dropped. It is read only and sits behind the same authentication as every other route; it does not accept the scoped sandbox credential. id is the session's stable id (id in a Snapshot row); a title does not resolve. An unknown id, an archived session, a session that is not running, and one being deleted are errors, never empty text. For other tabs, scrollback, or raw escapes, use af sessions preview.

Response shapes. These are not part of the generated request-field catalog, so they are documented here. CreateSession returns { "instance": <session> }; Snapshot returns { "instances": [<session>…] }; ArchiveSession returns { "ok": true, "archived_path": "…" }; RestoreArchived returns { "ok": true, "worktree_path": "…" }; SendPrompt returns { "ok": true, "status": "delivered" | "not-delivered" | "sent-unverified" | "could-not-confirm" }; sent-unverified means the paste and Enter were accepted while a readable pane did not render exact prompt content; could-not-confirm means the pane observer itself was unavailable. Neither status claims delivery. PruneSessions returns { "ok": true, "older_than": "<duration>", "archived_before": "<rfc3339>", "candidates": [<entry>…], "skipped"?: [<entry>…], "reclaimable_bytes": <int>, "warnings"?: [<string>…] }: without "apply" it is the read-only dry run for the archived-session reclaim — it lists in candidates each archived session a reclaim would remove — { "id"?, "title", "repo_id", "branch", "archived_at", "reclaimable_bytes" } — while af writes nothing: no deletion, no record update, no git write. With "apply": true it deletes exactly the worktrees that same verdict lists — the branch is always kept and each deleted row stays as a tombstone marked pruned — and the response gains "applied": true, "pruned": [<entry>…] (the rows whose worktree was deleted), "incomplete": [<entry>…] (deletion started but the record is not final; a re-run finishes them), "reclaimed_estimate_bytes" (an "up to" sum of the pruned rows' allocated-size estimates, never measured free space), and "free_bytes_before"/"free_bytes_after"/ "free_bytes_known" (the measured free space on the archive filesystem(s) around the run, so reflinks and shared extents surface as a visible gap rather than silent credit). "only": [<session id>…] binds an apply to the plan a caller already saw and confirmed — the CLI sends it after the operator approves the dry-run listing — and is refused on a dry run. skipped entries ({ "id"?, "title", "repo_id", "reason" }) were evaluated and refused; one marked "interrupted": true had an earlier apply not finish and belongs in a re-run's plan. An archived worktree still holding uncommitted or ignored files is refused, not counted: the kept branch does not contain them and they are the only copy — restore the session or clean the tree first. older_than is required and must be a positive duration measured from each session's archive time; the request needs a scope — repo_id or all: true, which are mutually exclusive. reclaimable_bytes counts allocated disk blocks (st_blocks × 512, like du): sparse holes are not counted, and a hard-linked file is credited only when deleting the tree removes its last link. It is an upper bound on what a deletion frees, not apparent file size: extents shared with a copy-on-write reflink clone outside the tree are still counted, so on Btrfs/XFS the free space recovered can be less than the total. A session whose recorded origin repository is gone is refused — with the repo deleted there is no kept branch, so the archived worktree may be the last copy of the work; DeliverPrompt returns { "status": "started" | "sent" }; CreateTab returns { "id"?: "<stable-tab-id>", "name": "<resolved-tab-name>", "tmux_name"?: "<tmux-session>" } (id is the stable tab id minted by the daemon, which an older daemon may omit; tmux_name is the tmux session the tab was spawned under, omitted for a web/vscode tab that owns no PTY; it normally tracks the name but diverges after a rename, so read it from the response rather than re-deriving it); CloseTab returns { "name": "<resolved-tab-name>" }; RenameTab returns { "name": "<resolved-tab-name>" }; ReorderTab returns { "name": "<resolved-tab-name>", "index": <int> }; ListTasks returns { "tasks": [<task>…] }; AddTask and UpdateTask return { "ok": true, "task": <task> } (the stored record; an older daemon omits AddTask's); the rest return { "ok": true }. AddTask's task is the bare stored record — the daemon sets it before reloading schedules and, unlike UpdateTask's live-enriched record, never attaches the live schedule-health fields (arming, next_run_at) that the next sentence attributes to every returned task; and a sandbox-credential AddTask receives a narrowed projection (sandboxSafeTask) that withholds persisted fields such as project_path, repo_id, host, and program. The request task field of AddTask is a full task object — the CLI/TUI build and validate it, and the daemon re-validates and owns the write. UpdateTask instead takes a target id and a FIELD-LEVEL update patch carrying only the fields to change (e.g. { "id": "ab12cd34", "update": { "enabled": false } }): the daemon merges the patch onto the freshly-loaded record under its file lock and leaves every unspecified field — and the scheduler-owned fields — as-stored, so a single-field edit cannot clobber a concurrent edit another client made (#1700). Both mutating calls take an optional actor naming the calling surface (cli, tui, api, daemon-upgrade) for the task's audit trail; a client that sends none is recorded from the transport, so an HTTP caller is api (#3623). TriggerTask takes the same optional actor, recorded as a triggered entry when the manual fire lands — scheduled cron and watch fires write no entry (#6318). Every task the daemon returns carries its schedule health — overdue, missed_occurrences, and, from the live scheduler entry, next_run_at and arming — derived at read time and never stored. See tasks.md for the task shape and Is it actually firing? for what those mean.

Session JSON timestamps (af sessions list --json and session responses) use RFC 3339 timestamps:

Field Meaning
created_at When the session was created.
updated_at When the session state last mutated: lifecycle, identity, prompt delivery, tab roster, or pane activity. Reads, serialization, and cache refreshes do not advance it.
archived_at When the session's archive move committed; --older-than for PruneSessions is measured from it. Omitted on live sessions; records archived before the field existed report nothing and prune falls back to updated_at.

updated_at survives saves and restarts. Older records retain their last save time; a missing or zero stored value falls back to created_at when loaded.

Snapshot accepts additive list filters in the request body: live: true excludes archived sessions; statuses is an array of lifecycle names (running, ready, lost, dead, archived, or limit-reached) matched as OR alternatives; created_after is an RFC 3339 creation-time lower bound; and limit is a positive maximum row count. These filters compose, run after repo_id scoping, and are applied by the daemon before the response is encoded. Omitting every filter preserves the complete response and its existing stable order.

UpdateTask, RemoveTask, and TriggerTask also accept an optional expect object — { "enforce": true, "project_path": "/repos/alpha" } — asserting the project the task was bound to when the caller authorized it. The daemon re-checks it against the freshly-loaded record inside the same locked operation and refuses the write if the task has since been re-bound, so a client that checks scope in one request and mutates in another cannot act on a task that moved projects in between. Omitting expect (or sending enforce: false) skips the check, which is what a caller with no project context does — existing clients are unaffected.

Session state names

The <session> objects above spell three of their enums twice, on purpose (#3631).

status, liveness and tabs[].kind are integers and stay integers — external scripts already decode them as numbers, and retyping them would break every one of those consumers. Beside each sits a string twin that names the same value, so a payload can be read without consulting Go source:

Integer Twin Vocabulary
status status_name running, ready, loading, deleting, dead, lost, archived
liveness liveness_name running, ready, lost, dead, archived, limit-reached
tabs[].kind tabs[].kind_name agent, shell, process, web, vscode

The twins are always present — never omitted, even when the integer beside them is (liveness carries omitempty) — and they are derived by whichever binary encodes the payload rather than stored, so a record read off disk or received from an older daemon is named correctly all the same. Nothing decodes them back: a client that sends one is ignored.

liveness_name is the vocabulary the statuses filter above accepts, and it is resolved by the SAME derivation the filter runs — including the fallback to the legacy status int for a record written before liveness existed. So the round trip holds: every row a statuses value selects reports that value as its liveness_name, and vice versa.

That derivation refuses to guess. A record whose liveness cannot be resolved — one from a daemon predating liveness that was caught mid-create or mid-kill, so its only state is a transient status, or one carrying a status this af does not know — reports liveness_name: "" and is selected by no statuses value. It is still listed; it simply does not claim a state it is not in. Such a row still names its own legacy axis (status_name: "deleting"), so the pair says exactly what is known.

status_name names the LEGACY composed axis, which is not always the same answer, and the difference is the reason both fields exist:

  • loading and deleting are in-flight operations with no liveness of their own, so no statuses word can select them.
  • A session parked at a usage-limit wall has no legacy status value at all: it composes to ready (status: 1, status_name: "ready") while liveness_name reports limit-reached. Filter and branch on liveness_name; read status_name only when you are reading status.

tabs[].kind_name uses the same words as tab_kinds[].kind — the two arrays no longer disagree about what a kind is. Every creatable kind's name is also its --kind / CreateTab kind value, so a tab's reported kind can be handed straight back to a create call; agent and process are named but are not creatable (see tab_kinds for what a session will accept).

An integer this binary does not recognize — a record from a newer af — names itself "" rather than guessing a word, in every one of the three twins.

Session idle diagnosis

The <session> objects above mirror af sessions list output. Two of their fields carry the daemon's idle diagnosis (#3168, #3175) and deserve a contract statement, because reading more into them than they promise is exactly the mistake they were designed to prevent:

idle_reason (string, omitted when no reason is established) — the daemon's mechanically established explanation for why a session is not doing visible work. The vocabulary is closed:

Value The daemon observed
usage-limit The session is parked at a usage-limit wall.
process-exited The agent process is gone — the row's liveness is Lost or Dead.
restore-gave-up The process is gone and automatic Lost-session recovery has stopped — it exhausted its failed-attempt budget, it confirmed enough restore-and-die cycles to conclude the agent cannot stay up, or a requested archive left the row fenced because the user asked for the session to stop. See lost_restore_failure below for the verdicts.
restore-waiting-on-environment The process is gone and automatic Lost-session recovery is parked on an environmental failure — a condition outside the session itself, such as a full disk, not a session defect — and retries on a capped backoff without spending the structural attempt budget. See lost_restore_wait below.
recreate-pending A recognized recreate notice is waiting, unacknowledged, on the root session.
prompt-not-delivered The last prompt send observed that the prompt did not arrive.
delivery-unconfirmed The last send ended sent-unverified or could-not-confirm (uncertainty, not failure — see SendPrompt above), and no pane change has been observed since.
no-pane-change-since-delivery The last prompt was delivered, and the pane has not changed since.
settled-after-pane-change The row settled back to Ready, and the pane changed after the last prompt attempt. When later churn resolves an unconfirmed send, this is all af reports — it never retroactively claims delivery (#3162).

lost_restore_failure (object, omitted unless the row is fenced) — the durable terminal result: { "attempts": 6, "error": "...", "kind": "..." }. The session remains Lost, and the daemon does not automatically retry it again. An explicit restore remains available; a successful runtime replacement clears the field. Because it is stored on the session record, daemon restarts and the TUI, web, and HTTP clients retain the same last error.

kind is the verdict discriminator (omitted — never "" — on rows written before it existed):

  • Failed-attempt exhaustion (kind absent) — attempts counts consecutive FAILED restore attempts that spent the structural budget (6 by default), and error is the last attempt's failure: the spawn died before it could be confirmed alive, the preserve push failed, and so on.
  • Confirmed-flap give-up (kind absent) — attempts counts CONFIRMED SUCCESSFUL restores (4 inside a 30-minute window) that each went lost again anyway, and error begins the session was confirmed restored N times in 30m0s and went lost again each time. Four successes are not four failures: a consumer that renders this as "4 attempts failed" inverts the evidence — every one of those spawns worked, and the agent exited after it was confirmed up.
  • archive-did-not-finish — a REQUESTED archive did not finish: its teardown refused, or the committed archive was rolled back after a later step failed. attempts is 1 (no restore ever ran), and error begins archive did not finish — retry the archive, or restore the session to resume it. The session stays down until the archive is retried or the session is restored; the automatic loop never restarts it.

The confirmed-flap count is in-memory evidence only: it does not survive a daemon restart the way this record does, and a restart re-opens the count at zero while the durable verdict stands.

Clients that render a row detail should prefer the verdict-aware form: for kind: "archive-did-not-finish" show error as written; for absent or unknown kind show restore gave up after N attempt(s): error. Rows with an unrecognized kind are still terminal fences — the verdict vocabulary is open, the fence semantics are not.

lost_restore_wait (object, omitted unless automatic recovery is waiting on the environment) — the non-terminal counterpart of lost_restore_failure: { "attempts": 3, "error": "..." }. attempts counts consecutive environmental failures in the current episode and error is the last observed environmental error, sanitized the same way. The session remains Lost and the daemon keeps retrying on a capped backoff — these attempts do NOT draw down the budget lost_restore_failure reports against. A successful restore, a runtime replacement, a structural failure, or a kill tombstone clears the field, and a row that reloads inert — one no automatic retry can ever reach, such as a sandbox session after a daemon restart — drops it on load rather than report an armed retry that does not exist.

last_pane_churn_at (RFC 3339 timestamp, omitted when no churn is on record) — when the daemon last observed the session's pane render different bytes. The evidence is cleared when the agent process is replaced, so a retired process's output is never attributed to its successor.

No value in this vocabulary means "the task finished" — and none means "asked a question" or "wedged". The daemon observes pane churn (bytes changing in a terminal) and prompt-delivery evidence, not the meaning of the agent's output. A completed task, a question waiting for your answer, and a stuck agent can render exactly alike, so af reports the observation — settled-after-pane-change — and leaves the interpretation to you: read the pane. An absent idle_reason is likewise "no reason established" (the row is working, an operation is in flight, or there is no delivery evidence yet), not "all clear".

The vocabulary can grow. Treat an unknown value as no reason — the TUI and web rows render no idle-reason label for values they don't know, so an older client never mislabels a newer daemon's observation.

Session operation state

Other <session> fields describe an operation in flight rather than an idle verdict. They are diagnostic: they report what the daemon is doing to the row, not a state to filter or branch lifecycle decisions on.

in_flight_op (integer, omitted when 0) — the client/executor operation overlaid on the row's liveness right now: 1 creating, 2 killing, 3 archiving, 4 restoring, 5 a handoff between its outgoing and incoming runtime, 6 a limit resume re-spawning the runtime. It is process-local by design — disk writers scrub it before persistence, so a record read off disk or a row after a daemon restart reports none even when a recovery is genuinely mid-flight — and it can legitimately disagree with a request the client just sent, since the op may have been raised after the snapshot was taken. Read it to explain why a row is ignoring a gesture; never read its absence as proof that nothing is in flight.

pending_account_swap (object, omitted when absent) — the committed account swap whose replacement runtime still owes the session its notice and stored task. Unlike in_flight_op it is durable: it survives a daemon restart because the obligation does. While it is present, competing lifecycle actions and tab spawns on the row are refused, and the refusal names the one admitted retry — af sessions handoff --account <to> -- <title>, which the pending-swap fence recognizes as the recorded transaction's retry rather than a new one. The object's to names the committed target account and from the outgoing one (omitted for the ambient identity); the rest is recovery bookkeeping — conversation carry and delivery evidence — that consumers should treat as opaque rather than a vocabulary.

off_box_swap_in_flight (object, omitted when absent) — the durable record of an off-box account swap prepared for sending but with no reconciled verdict yet (#7793). The record is written before the request crosses to the host, so a daemon restart after the write but before the send still finds the field present and reconciles a "never ran" verdict; treat its presence as evidence of a durably prepared swap, not proof the request crossed. Like pending_account_swap it is durable: it survives a daemon restart because the unresolved swap does, and its presence is the admission fence — a further swap, relaunch, reprovision, recovery, and archive are refused while it stays. The fence clears only on a definite verdict from the agent-server (a daemon restart re-runs the reconcile before anything binds) or af sessions kill; no operator verb lifts it yet (#7797). The object's to names the target account and from the outgoing one (omitted for the ambient identity); the rest is recovery bookkeeping that consumers should treat as opaque rather than a vocabulary.

Session warnings

Session objects also carry daemon-projected warnings as additive, omitted-when-empty fields. Three are single strings — archive_warning (an incomplete archive's bounded notice), callback_unavailable (why the session has no af callback), and setup_hook_failed (why a session's non-blocking daemon-side setup did not fully run) — and one is a list:

agent_config_skipped (array of strings, omitted when empty) — one agent:file: <reason> entry per declared sandbox_agent_config file the session's account-scope placement refused: missing, unreadable, not a regular file, unparsable, or pushing the placement archive over its 64 MiB bound. On an account swap to a scope-discovered agent (Codex or Gemini), af's own agent-factory skill rides the same list when the policy snapshot that decides whether to stage it cannot be read or parsed. Recorded at provision and refreshed by every reprovision and account swap that stages a scope, so a clean placement clears it and the row never warns about a file the live scope now holds. Every surface renders the joined entries under the af agent config skipped: prefix.

setup_hook_failed (string, omitted when empty) — an opaque note on why a session's non-blocking daemon-side setup did not fully run: a setup_commands hook failure, or post_worktree_commands that did not run because the project config could not be resolved (a read that timed out (#7079) or a config the repo answered as invalid (#7084)), or because the durable run list for the post-worktree hooks could not be persisted before starting. For the setup_commands case, the note is produced once the setup pipeline is running: when the staging root is unusable, when a staging directory cannot be created, when a Docker payload transfer or worktree-overlay step fails, or when an entry fails, times out, cannot start, or cannot open its output log. (An in-repo setup_commands document cannot be loaded is logged rather than reported here — the session proceeds without running its setup and the field stays empty.) The pre-entry and transfer forms carry a plain reason string. An entry failure always carries the entry index; it adds the retained output log once a log could be opened, and the exit status or timeout once the command actually started. None of these block the session; the note persists on the row (in the same durability class as callback_unavailable) so every surface can render af setup hook failed: … rather than leaving the operator to wonder why the workspace is missing its setup. See backends.md for the hook contract.

Config reads

POST /v1/GetConfig returns every user-facing config key as a ConfigEntry row — key, type, default, purpose, value, and the rest — plus path, the global config.toml. POST /v1/ExplainConfig explains one key: every source candidate and why it won, was shadowed, was absent, or is disallowed. Both read on-disk config fresh on every call.

Both accept an optional repo_path: a project on the daemon's host, absolute or starting with ~/ (expanded against the daemon host's home). A relative path is refused, because the daemon has no access to your working directory. A linked worktree resolves to its main checkout, the same project af config get --repo <path> reads.

Without repo_path, both routes answer exactly as they always have; the response does not carry any of the fields below. With it:

  • GetConfig returns the project's effective values — what af uses for sessions in that project, the same values af config get --repo prints. Each row a non-global layer supplies carries two more fields:
  • scope (string, omitted on global rows) names that layer: project (the checked-in .agent-factory/config.toml or the legacy per-repo file, or a root_agent the project resolves itself), personal (the machine-local per-project layer af config set --project writes), project+personal (a table whose entries came from both), or personal-ignored (a personal value is stored but not applied, so value is still the global value — today only branch_prefix). This is an open set. Treat any value you do not recognize as "the effective value comes from a non-global layer" rather than rejecting it, so a layer af adds later does not break your client.
  • global_value (string) is the global file's value in the same form — the value POST /v1/SetConfigValue writes. It is omitted when the global value is empty, so read a missing global_value on a scoped row as "".

A row without scope is the global row, exactly as a read without repo_path returns it. The response also carries project_root, the repository root the daemon resolved: the scope the rows were actually read in. - If the project cannot be resolved, GetConfig still succeeds: the rows are the global ones, project_root is absent, and project_error says why — for example not a git repository: /srv/app. The message names only the path you sent, never other paths on the daemon's host. If you sent repo_path and get neither project_root nor project_error, the daemon predates the field and the rows are global. - ExplainConfig explains the key in that project and sets the response's scope to project (it is global otherwise). An explain that cannot resolve the project is refused with the same requested-path-only message rather than answering with a global trace.

Writes stay global. SetConfigValue and UnsetConfigValue always edit the global file, so an edit on a scoped row changes global_value. It changes value only where the project still inherits from the global file — another entry of a merged table such as program_overrides, or a personal-ignored row — so read GetConfig with the same repo_path again after a write rather than assuming either way. Seed an edit field from global_value on a scoped row, and say on screen that the edit is global. The TUI's , editor and the web Config view both do this.

Examples

Health check:

curl --unix-socket ~/.agent-factory/daemon-http.sock http://localhost/v1/health
# {"data":{"ok":true},"error":null}

List every session (all repos):

curl --unix-socket ~/.agent-factory/daemon-http.sock \
  http://localhost/v1/Snapshot -d '{}'

Send a prompt into an existing session:

curl --unix-socket ~/.agent-factory/daemon-http.sock \
  http://localhost/v1/SendPrompt \
  -d '{"title":"fix-auth","prompt":"run the tests and report failures"}'
# {"data":{"ok":true,"status":"delivered"},"error":null}

List tasks (no body needed):

curl --unix-socket ~/.agent-factory/daemon-http.sock http://localhost/v1/ListTasks -d '{}'

Wrong verb → 405:

curl -i --unix-socket ~/.agent-factory/daemon-http.sock http://localhost/v1/ListTasks
# HTTP/1.1 405 Method Not Allowed
# {"data":null,"error":{"message":"method GET not allowed; use POST","daemon_rejected":true}}

Oversize body → 413 (rejected, never processed):

head -c 20000000 /dev/zero | tr '\0' 'a' \
  | curl -i --unix-socket ~/.agent-factory/daemon-http.sock \
      http://localhost/v1/AddTask --data-binary @-
# HTTP/1.1 413 Request Entity Too Large
# {"data":null,"error":{"message":"request body exceeds 16777216-byte limit: …","daemon_rejected":true}}

Relationship to the CLI

The HTTP API and af sessions / af tasks are two front-ends over one daemon core. Prefer the CLI for interactive and scripting use — it handles daemon startup, --repo resolution, and flag validation for you. Reach for the HTTP API when you want to call the daemon from a language or tool without shelling out to af, from inside an agent, or from a small local service. Both emit the identical {data, error} envelope, so a consumer written against one reads the other unchanged.

Task completion choices

POST /v1/ListOnComplete accepts {} and returns a shared-envelope payload whose values array contains {value, hint} options, for example {"value":"kill","hint":"deletes the run's session and its branch — permanent"}. Values follow task.OnCompleteValues() order, least destructive first. Clients should render this catalog rather than copy the enum or consequence wording. The default is the first option. Send on_complete on the task in AddTask, or on update in UpdateTask; send the selected verb unchanged. The store canonicalizes keep to empty on both create and update. Completion policies apply only to spawned sessions, so tasks with target_session must use empty.