agent-exec
Non-interactive agent job runner. Runs commands as background jobs and returns structured JSON on stdout.
Output Contract
- stdout: JSON only — every command prints exactly one JSON object
- stderr: Diagnostic logs (controlled by
RUST_LOGor-v/-vvflags)
This separation lets agents parse stdout reliably without filtering log noise.
Installation
Quick Start
Short-lived job (run → wait → tail)
Run a command, wait for it to finish, then read its output:
# 1. Start the job (returns immediately with a job_id)
JOB=
# 2. Wait for completion
# 3. Read output
Example output of tail:
Long-running job (run → status → tail)
Start a background job, poll its status, then read its output:
# 1. Start the job (returns immediately with a job_id)
JOB=
# 2. Check status
# 3. Stream output tail
# 4. Wait for completion
Timeout and force-kill
Run a job with a timeout; SIGTERM after 5 s, SIGKILL after 2 s more:
Commands
run — start a background job
Key options:
| Flag | Default | Description |
|---|---|---|
--snapshot-after <ms> |
10000 | Wait N ms before returning (0 = return immediately) |
--timeout <ms> |
0 (none) | Kill job after N ms |
--kill-after <ms> |
0 | ms after SIGTERM to send SIGKILL |
--tail-lines <N> |
50 | Lines of output captured in the snapshot |
--cwd <dir> |
inherited | Working directory |
--env KEY=VALUE |
— | Set environment variable (repeatable) |
--mask KEY |
— | Redact secret values from JSON output (repeatable) |
--wait |
false | Block until the job reaches a terminal state |
--wait-poll-ms <ms> |
200 | Poll interval used with --wait |
--notify-command <JSON_ARGV> |
— | Run a command when the job finishes; event JSON is sent on stdin |
--notify-file <PATH> |
— | Append a job.finished event as NDJSON |
status — get job state
Returns running, exited, killed, or failed, plus exit_code when finished.
tail — read output
Returns the last N lines of stdout and stderr.
wait — block until done
Polls until the job finishes or the timeout elapses.
kill — send signal
list — list jobs
Job Finished Events
When run is called with --notify-command or --notify-file, agent-exec emits a job.finished event after the job reaches a terminal state.
--notify-commandruns the provided argv without a shell and writes the event JSON to stdin.--notify-fileappends the event as a single NDJSON line.completion_event.jsonis also written in the job directory with the event plus sink delivery results.
Example:
Command sink example:
For command sinks, the event JSON is written to stdin and these environment variables are set:
AGENT_EXEC_EVENT_PATH: path to the persistedcompletion_event.jsonAGENT_EXEC_JOB_ID: finished job idAGENT_EXEC_EVENT_TYPE: currentlyjob.finished
Example job.finished payload:
If the job is killed by a signal, state becomes killed, exit_code may be absent, and signal is populated when available.
Logging
Logs go to stderr only. Use -v / -vv or RUST_LOG:
RUST_LOG=debug
Development