Skip to content

Errors and exit codes

Exit codes

Exit code Meaning
0 Success (status:"ok"). run returns 0 when it starts the child, including when the child fails or times out; exceeding --grep-limit returns 3 with status:"partial". The child's own code is in exit_code.
1 General error: bad arguments, missing input, boundary violation, I/O failure, lock timeout, syntax error.
2 A precondition did not hold: a selector matched nothing or more than one place, a count or hash guard did not match, or the target changed before tx commit or undo.
3 A read was cut at a limit (status:"partial"). The output is a success, not an error, and carries no error.code. Writes never return 3.

src/dispatch.lisp maps a command result to these codes: :ok to 0, :partial to 3, and an error to the exit code its error.code has in the catalog below.

The error envelope

Every error is one JSON object on standard error:

{"schema_version":2,"status":"error","command":"edit",
 "error":{"code":"selection.ambiguous","message":"...","exit_code":2,
          "repairs":[{"action":"read","detail":"...","command":"aitools read dup.txt"}],
          "candidates":[{"line":1,"text":"x"},{"line":2,"text":"x"}]}}
  • repairs always has at least one entry. make-error-envelope (packages/core/protocol/src/domain/envelope.lisp) signals an internal error rather than build an envelope without one.
  • repairs[].command suggests an aitools invocation. It is not run automatically. Some repairs name only the command to use (aitools read for cat), not a complete invocation.
  • candidates, diagnostics, and conflicts appear only when the error has them.
  • When no command-specific repair applies, the repair is aitools schema <command>.

See JSON output for the field-by-field shape.

error.code catalog

The catalog lives in data/domain/protocol/error-catalog-data.lisp (aitools.data:*protocol-error-codes*); error-code-exit-code in packages/core/protocol/src/domain/error-catalog.lisp reads it. The table below is generated from that data and from the error codes each command schema declares.

error.code Exit code Declared by
argument.invalid 1 search, find, overview, code defs, code refs, read, info, diff, doc get, doc select, doc diff, table read, table agg, archive read, snapshot create, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, history, undo, tx drop, run, wait, signal, bg start, bg logs, bg stop, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, sys tools, sys metrics, sys network, sys snapshot, time now, time convert, time diff, md headings, md read, md replace, util encode, util decode, util redact, util tokens, util calc, util uuid, util random, net get, net head, net resolve, schema, batch
input.not-found 1 search, find, overview, code outline, code defs, code refs, read, info, check, diff, doc get, doc select, doc diff, table read, table agg, archive list, archive read, snapshot diff, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, undo, tx status, tx diff, tx drop, tx rebase, tx commit, tx abort, wait, bg logs, bg status, bg stop, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, md headings, md read, md replace, util encode, util decode, util redact, util tokens, schema, batch
input.not-utf8 1 edit, insert, replace, apply, transform, move-lines, doc set, doc delete, doc merge, doc patch, doc fmt, table set, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, md headings, md read, md replace, util encode, util decode, util redact, util tokens, util calc, batch
input.unsupported-format 1 code outline, read, check, doc get, doc select, doc diff, table read, table agg, archive list, archive read, transcode, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, md headings, md read, md replace, batch
input.unsupported-language 1 code outline, read, archive read, edit, insert, replace, transform, move-lines, batch
input.syntax-error 1 search, read, check, doc get, doc select, doc diff, table read, table agg, archive read, edit, insert, replace, transform, move-lines, transcode, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, run, wait, signal, bg logs, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, time now, time convert, time diff, md headings, md read, md replace, util decode, util calc, batch
input.unsupported-value 1 doc get, doc select, doc diff, doc set, doc delete, doc merge, doc patch, doc fmt, batch
selection.no-match 2 read, archive read, edit, insert, replace, apply, transform, move-lines, doc patch, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org clock report, md read, md replace, batch
selection.ambiguous 2 read, archive read, edit, insert, replace, apply, transform, move-lines, doc patch, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org clock report, batch
selection.count-mismatch 2 edit, insert, replace, transform, move-lines, rm, signal, batch
refusal.target-changed 2 edit, insert, replace, apply, transform, move-lines, write, transcode, move, copy, rm, link, doc set, doc delete, doc merge, doc patch, doc fmt, table set, undo, tx rebase, tx commit, signal, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org table align, org table sort, org table recalculate, org dynamic-block update, md replace, batch
refusal.redacted-input 1 edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org table align, org table sort, org table recalculate, org dynamic-block update, md replace, util decode, batch
refusal.outside-workspace 1 edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, run, org query, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org table align, org table sort, org table recalculate, org dynamic-block update, md replace, util decode, batch
refusal.exists 1 edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, run, util decode, batch
refusal.not-a-file 1 read, check, doc get, doc select, doc diff, table read, table agg, archive list, archive read, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, org query, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org table align, org table sort, org table recalculate, org dynamic-block update, md replace, util decode, batch
refusal.too-large 1 archive list, archive read, copy, archive extract, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, md headings, md read, md replace, net get, batch
environment.io 1 search, read, info, check, diff, doc get, doc select, doc diff, table read, table agg, archive list, archive read, snapshot create, snapshot diff, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, history, undo, tx begin, tx status, tx diff, tx drop, tx rebase, tx commit, tx abort, run, wait, signal, bg start, bg logs, bg status, bg stop, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, md headings, md read, md replace, util encode, util decode, util redact, util tokens, util calc, net get, net head, net resolve, batch
environment.busy 1 read, info, check, doc get, doc select, doc diff, table read, table agg, archive list, archive read, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, undo, tx begin, tx drop, tx rebase, tx commit, tx abort, bg start, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org table align, org table sort, org table recalculate, org dynamic-block update, md replace, util decode, batch
environment.timeout 1 wait, net get, net head, net resolve, batch
environment.unavailable 1 run, wait, bg start, bg logs, bg status, bg stop, sys info, sys procs, sys metrics, sys network, sys disk, sys ports, sys snapshot, time now, time convert, time diff, net get, net head, net resolve, batch
internal.unexpected 1 search, find, overview, code outline, code defs, code refs, edit, insert, replace, apply, transform, move-lines, write, split, transcode, move, copy, rm, mkdir, chmod, link, touch, mktemp, doc set, doc delete, doc merge, doc patch, doc fmt, table set, archive extract, archive create, org outline, org query, org export, org capture, org archive, org todo set, org property set, org property delete, org priority set, org priority delete, org tags add, org tags remove, org tags replace, org heading rename, org checkbox toggle, org planning set, org planning delete, org clock in, org clock out, org agenda, org clock report, org table align, org table sort, org table recalculate, org dynamic-block update, sys info, sys env, sys tools, sys procs, sys metrics, sys network, sys disk, sys ports, sys snapshot, time now, time convert, time diff, md headings, md read, md replace, net get, net head, net resolve, batch

"Declared by" lists only the commands whose own schema names the code. Three codes can also come from the composition root for any command, whether or not its schema declares them: argument.invalid for usage errors and --lock-timeout values that are not durations, environment.busy when recovery cannot take the workspace lock, and internal.unexpected for an uncaught condition (src/dispatch.lisp).

When each code occurs

error.code Occurs when
argument.invalid Argument parsing fails, a value has the wrong type or range, options that exclude each other are combined, or a required guard or input is missing. It also covers chmod --mode setting a setuid, setgid, or sticky bit, an invalid date for touch --mtime, a non-numeric table agg column, and unknown command names. org query uses it for an invalid or non-minute-aligned --at, an unknown --tz, or an unsupported --dst-policy. Malformed --range and non-ASCII digits in numeric options are invalid too.
input.not-found A file, symbol, JSON Pointer, archive entry, op, tx, bg process, or snapshot does not exist (a true ENOENT). Commands may include candidates for missing files or entries. A file that exists but cannot be read is environment.io, not this code.
input.not-utf8 A text edit, Org read, or Markdown headings/read/replace command receives bytes that are not valid UTF-8.
input.unsupported-format A file is not in a format the command handles (doc, table, archive, check), an encoding is unsupported, an Org read receives binary input or NUL bytes, org export encounters unsupported syntax or a file, ID, or internal link, or an md command receives binary input.
input.unsupported-language The code group, --symbol, or transform --op comment meets a language outside the pattern table.
input.syntax-error check finds a syntax error; a regular expression, diff, Org document, or Org match expression is malformed; a regex exceeds its step limit; a value does not parse (util decode, util calc, time convert); transcode meets bytes it cannot decode; or an md command cannot parse its input. Structured-document reads and writes use this for malformed input; doc set --stdin, doc merge --stdin, and doc patch --stdin use it for malformed JSON. TOML integer range errors use it too. Org parse and match errors include source diagnostics.
input.unsupported-value A YAML or TOML doc read or write encounters a value outside the JSON subset, such as a custom YAML tag, a cyclic alias, duplicate or non-string mapping keys, multiple YAML documents, or a non-finite float.
selection.no-match A selector matches nothing, an apply hunk does not fit, or a JSON Patch test fails. When a command can suggest alternatives, it includes them in candidates; the entries depend on the command.
selection.ambiguous A selector that must be unique matches more than once. The matches come as candidates.
selection.count-mismatch --expect-count differs from the actual count.
refusal.target-changed --expect-hash differs, or the target changed before tx commit, tx rebase, or undo. The paths come as conflicts.
refusal.redacted-input A write's input contains the literal text [REDACTED_SECRET].
refusal.outside-workspace A write would land outside the workspace root, through a symlink that leaves it, or inside the workspace's .git/ (its resolved git directory and common directory). archive extract entry paths and copy --recursive children are routed through the same boundary, so a .git/ entry or nested .git/ is refused. rm also refuses the workspace root, home directory, and paths with .git or .jj components. org agenda and org query use this code when an explicit path resolves outside the workspace. The state directory lives outside the root, so writes there are refused as outside-workspace too.
refusal.exists The destination exists and overwriting was not allowed.
refusal.not-a-file A file-only operation targets a directory, a read targets a FIFO, socket, or device, a text edit targets a binary file, rm targets a non-empty directory, or chmod/touch targets a hard-linked file (link count > 1). The repair command varies by operation.
refusal.too-large Archive operations or copy --recursive exceed their size or entry limit, an Org document exceeds the parser limit, an md input exceeds 16 MiB, or an envelope would exceed the JSON writer's output limit. The output-limit repair is aitools schema <command>; reduce the requested output with a limit or narrower selector.
environment.io A read or write fails, including a permission-denied (EACCES) read of an existing file. read, info, check, diff, Org read commands, and write --content-file report this rather than input.not-found. A failed rename names the blocking destination.
environment.busy The workspace lock is not acquired within --lock-timeout. The repair repeats the same command.
environment.timeout wait exceeds its requested deadline, or an HTTP request or OS name lookup exceeds the net command's total deadline.
environment.unavailable A required executable cannot be started, or an OS facility is unavailable (for example, no source for sys ports).
internal.unexpected An unexpected condition. The repair is aitools schema <command> when the command is known.

Unknown command names

A name that is not a registered command returns argument.invalid, exit code 1. src/dispatch-names.lisp chooses the repairs by the kind of name, in this order:

  1. A bare group name (doc, bg, tx) is a real command node with no handler, so the message is <group> requires a subcommand and the repair is aitools schema <group>. That repair is runnable: aitools schema lists a group's subcommands when given the group name (%group-schemas in src/schema.lisp), so it no longer fails with input.not-found.
  2. A retired document command name (json.get, yaml.get, or toml.get; tokenized input such as json get) is resolved through its correspondence-table entry and returns the current doc command's repair. These names are not registered command aliases.
  3. A shell name in the correspondence table (cat, grep, uuid) returns that row's repairs, drawn from aitools.data:*correspondence-table* and shown in Using aitools from an agent.
  4. A group subcommand typed without its group (get, status, logs) returns one run-instead repair per group whose subcommand list holds that name, each the grouped form of the invocation with the group token inserted and the globals and operands kept. This is driven by the live registry (%group-subcommand-repairs in src/dispatch-names.lisp), not by the correspondence table, so status returns aitools bg status and aitools tx status.
  5. Any other name gets the repair aitools schema.
$ aitools cat hello.lisp
{"schema_version":2,"status":"error","command":"cat","error":{"code":"argument.invalid","message":"unknown command cat","exit_code":1,"repairs":[{"action":"run-instead","detail":"Read a file with line numbers and range control.","command":"aitools read"}]}}

$ aitools uuid
{"schema_version":2,"status":"error","command":"uuid","error":{"code":"argument.invalid","message":"unknown command uuid","exit_code":1,"repairs":[{"action":"run-instead","detail":"`uuid` is a group subcommand name; the group prefix is required.","command":"aitools util uuid"}]}}

schema also reports near-miss candidates as an agent types them (doc get, not the dotted dispatch name doc.get); %typed-name in src/schema.lisp builds them from the command schemas.