docs · reference

JSON output#

Every --json flag prints a versioned JSON document on stdout and nothing else there; notes and errors stay on stderr. Each document carries a schema_version, fields are snake_case, token counts are integers, and money is integer micro-dollars (1,000,000 = $1.00) with an estimate_label, never a formatted string. Within a schema version Hekma only adds fields, so parse what you need and ignore the rest.

Documents at a glance#

CommandShapeschema_version
hekma agent list --jsonOne document: totals and instances2
hekma agent show NAME --jsonOne document: instance2
hekma agent usage [NAME] --jsonOne document: instance and usage, or totals2
hekma agent config get NAME --jsonOne document: entries1
hekma agent logs NAME --jsonNDJSON: one object per line1 (on every line)
hekma agent memory attach ... --jsonOne document1
hekma agent memory detach ... --jsonOne document1
hekma run open|close|show ... --json (Unreleased: after 0.11.0)One document: run1
hekma label set|remove ... --json (Unreleased: after 0.11.0)One document: results1
hekma ps --json (Unreleased: after 0.11.0)One document: items and counts1
hekma agent stop|pause|resume|drain ... --json, hekma run close ... --json (Unreleased: after 0.11.0)One document: results1
hekma budget show|set ... --json (Unreleased: after 0.11.0)One document1
hekma run keys, revoke-keys ... --json (Unreleased: after 0.11.0)One document: keys, or revoked1
Engine events (embedders)transition, budget_breach, usage_update; run, policy, breach_default_upgraded and credential (Unreleased: after 0.11.0)1 (inside each payload)

The version belongs to the kind of content, not the command: list, show and usage share the fleet version (2), and the other families have their own.

Compatibility rule#

These documents, and the exit codes, are a stable interface:

  • Within a schema_version, Hekma only adds fields. An existing field keeps its name, type and meaning.
  • Fields marked optional below are left out when they have no value, rather than printed as null or 0. Treat every optional field as possibly absent.
  • Removing or changing a field raises schema_version. Such a change is announced in the release notes at least one minor release ahead and happens only in a major release.

Check schema_version before you trust the rest of a document, and ignore fields you do not know.

list#

hekma agent list --json prints the whole fleet: fleet totals and one entry per agent.

{
  "schema_version": 2,
  "totals": {
    "total_input_tokens": 2400,
    "total_output_tokens": 600,
    "total_dollars": 14040,
    "dollars_partial": false,
    "unpriced_count": 0,
    "estimate_label": "estimated",
    "total_cached_tokens": 800
  },
  "instances": [
    {
      "name": "worker",
      "kind": "worker",
      "state": "running",
      "restart_count": 0,
      "restart_policy": "on-failure",
      "budget": {
        "cumulative_limit": 6000,
        "cumulative_remaining": 3000,
        "breach_action": "pause"
      },
      "usage": {
        "cumulative_input_tokens": 2400,
        "cumulative_output_tokens": 600,
        "current_run_input_tokens": 1200,
        "current_run_output_tokens": 300,
        "cumulative_dollars": 14040,
        "current_run_dollars": 7020,
        "estimate_label": "estimated",
        "cumulative_cached_tokens": 800,
        "current_run_cached_tokens": 400
      },
      "metering_source": "self-reported",
      "supervision": "detached",
      "agent_home": "/Users/you/Library/Application Support/ktesio/agents/worker"
    }
  ]
}

An empty fleet prints "instances": [] and zero totals.

totals#

FieldTypePresentMeaning
total_input_tokensintegeralwaysCumulative input tokens across all agents (cached tokens included).
total_output_tokensintegeralwaysCumulative output tokens across all agents.
total_cached_tokensintegeroptionalCumulative cached tokens. Absent if any agent's ledger holds usage recorded before Hekma tracked cached tokens.
total_dollarsinteger (micro-dollars)optionalSummed estimated cost of the agents that have a rate. Absent when no agent has one.
dollars_partialbooleanalwaystrue when some agent has usage but no rate, so total_dollars is a lower bound.
unpriced_countintegeralwaysHow many agents with usage were left out of total_dollars; 0 unless dollars_partial is true.
estimate_labelstringoptionalestimated; present when total_dollars is.

Fleet entry#

Each element of instances (and the instance object of show) has these fields.

FieldTypePresentMeaning
namestringalwaysThe agent's name.
kindstringalwaysThe adapter kind, such as acp or a manifest's [adapter] kind.
statestringalwaysregistered, starting, running, paused, stopping, stopped or failed.
restart_countintegeralwaysConsecutive restarts by the restart policy.
restart_policystringalwayson-failure or never.
failed_causestringoptionalWhy the agent failed. Present only when state is failed.
budgetobject or nullalwaysThe budget, or null when no budget is configured.
usageobjectalwaysThe usage totals; all zeros for an agent that never reported any.
metering_sourcestringalwaysself-reported or engine-observed.
acp_context_usageobjectoptionalacp agents only, while a live connection has reported its context window. See ACP fields.
usage_gapobjectoptionalacp agents only, when the ledger holds no usage for them. See ACP fields.
supervisionstringoptionaldetached or session while a live process is recorded; absent otherwise. See supervision.
recorded_statestringoptionalUnreleased: after 0.11.0. Present only when the shown state differs from the stored one: a running or paused agent whose process is gone is shown as failed, with a failed_cause naming the pid and no supervision, and its stored state is kept here. Reads write nothing; the next write records the change. See Reads never write.
breach_default_upgradedbooleanoptionalUnreleased: after 0.11.0. true on an agent the breach-default upgrade keeps on pause; absent otherwise.
agent_homestringalwaysAbsolute path of the Agent Home.

budget object#

Each limit field is present only when that budget is set; each dollar field only when a rate is also set.

FieldTypeMeaning
per_run_limit, per_run_remainingintegerToken ceiling for the current run, and what is left.
cumulative_limit, cumulative_remainingintegerLifetime token ceiling, and what is left.
per_run_cost_cap, per_run_dollars_remaininginteger (micro-dollars)Dollar ceiling for the current run, and what is left.
cumulative_cost_cap, cumulative_dollars_remaininginteger (micro-dollars)Lifetime dollar ceiling, and what is left.
estimate_labelstringestimated; present with the dollar fields.
breach_actionstringAlways present: pause, stop or warn; block (Unreleased: after 0.11.0) — settable through config set only on engine-observed agents — the wire fence.

Remaining values never go below 0.

usage object#

FieldTypePresentMeaning
cumulative_input_tokensintegeralwaysInput tokens over the agent's life, cached tokens included.
cumulative_output_tokensintegeralwaysOutput tokens over the agent's life.
current_run_input_tokensintegeralwaysInput tokens in the current run.
current_run_output_tokensintegeralwaysOutput tokens in the current run.
cumulative_cached_tokensintegeroptionalThe cached part of cumulative_input_tokens. Absent when older usage without a cached count is in scope.
current_run_cached_tokensintegeroptionalThe cached part of current_run_input_tokens.
cumulative_dollarsinteger (micro-dollars)optionalEstimated lifetime cost. Present only with a rate.
current_run_dollarsinteger (micro-dollars)optionalEstimated cost of the current run. Present only with a rate.
estimate_labelstringoptionalestimated; present with the dollar fields.

Cached tokens are a subset of input tokens. Add input and output for the total; never add cached on top. These totals equal the usage ledger exactly.

ACP fields#

Two optional fields appear only on acp agents. Every other kind leaves them out.

acp_context_usage is the agent's own report of its session context window. It is context usage, not billable usage: Hekma never adds it to the ledger or to budgets.

FieldTypeMeaning
usedinteger, optionalTokens currently in the context window.
sizeinteger, optionalThe context window size.
costobject, optionalThe agent's own cost figure: amount (string) and currency (string).

usage_gap appears when an acp agent's ledger holds no usage at all, and says which usage sources Hekma tried:

FieldTypeMeaning
observedstringconfigured or not-configured: whether metering.upstream_base_url is set.
sentinelstringlines-seen or no-lines-seen: whether the agent printed any KTESIO_USAGE lines on stderr.
context_usage_reportedbooleanWhether the agent reported its context window.
noticestringOne sentence a person can read.
{
  "schema_version": 2,
  "instance": {
    "name": "coder",
    "kind": "acp",
    "state": "registered",
    "restart_count": 0,
    "restart_policy": "on-failure",
    "budget": null,
    "usage": {
      "cumulative_input_tokens": 0,
      "cumulative_output_tokens": 0,
      "current_run_input_tokens": 0,
      "current_run_output_tokens": 0,
      "cumulative_cached_tokens": 0,
      "current_run_cached_tokens": 0
    },
    "metering_source": "self-reported",
    "usage_gap": {
      "observed": "not-configured",
      "sentinel": "no-lines-seen",
      "context_usage_reported": false,
      "notice": "no billing-grade usage in the ledger — tiers attempted: observed: not-configured; sentinel: no-lines-seen; no context usage reported (ACP usage_update is context-grain, never billed)"
    },
    "agent_home": "/Users/you/Library/Application Support/ktesio/agents/coder"
  }
}

show#

hekma agent show NAME --json prints one fleet entry under instance, with the same fields and rules as a list entry.

{
  "schema_version": 2,
  "instance": {
    "name": "worker",
    "kind": "worker",
    "state": "running",
    "restart_count": 0,
    "restart_policy": "on-failure",
    "budget": {
      "cumulative_limit": 6000,
      "cumulative_remaining": 3000,
      "breach_action": "pause"
    },
    "usage": {
      "cumulative_input_tokens": 2400,
      "cumulative_output_tokens": 600,
      "current_run_input_tokens": 1200,
      "current_run_output_tokens": 300,
      "cumulative_dollars": 14040,
      "current_run_dollars": 7020,
      "estimate_label": "estimated",
      "cumulative_cached_tokens": 800,
      "current_run_cached_tokens": 400
    },
    "metering_source": "self-reported",
    "supervision": "detached",
    "agent_home": "/Users/you/Library/Application Support/ktesio/agents/worker"
  }
}

The capability declaration that the human show prints is not in this document.

usage#

With a name, hekma agent usage NAME --json prints the agent's usage object:

{
  "schema_version": 2,
  "instance": "worker",
  "usage": {
    "cumulative_input_tokens": 2400,
    "cumulative_output_tokens": 600,
    "current_run_input_tokens": 1200,
    "current_run_output_tokens": 300,
    "cumulative_dollars": 14040,
    "current_run_dollars": 7020,
    "estimate_label": "estimated",
    "cumulative_cached_tokens": 800,
    "current_run_cached_tokens": 400
  }
}

Note that instance is a plain string here, the agent's name, while in show it is an object.

Without a name, hekma agent usage --json prints the fleet totals, the same object list --json carries:

{
  "schema_version": 2,
  "totals": {
    "total_input_tokens": 2400,
    "total_output_tokens": 600,
    "total_dollars": 14040,
    "dollars_partial": false,
    "unpriced_count": 0,
    "estimate_label": "estimated",
    "total_cached_tokens": 800
  }
}

config get#

hekma agent config get NAME --json prints every effective config value; with a key, the entries list holds just that key.

{
  "schema_version": 1,
  "entries": [
    {
      "key": "agent.api_key",
      "value": "secret:****",
      "source": "instance",
      "unvalidated": true
    },
    {
      "key": "budget.tokens.cumulative",
      "value": "6000",
      "source": "instance",
      "unvalidated": false
    },
    {
      "key": "model",
      "value": "gpt-4o-mini",
      "source": "instance",
      "unvalidated": false
    }
  ]
}
FieldTypeMeaning
entries[].keystringThe dotted key. Entries are sorted by key.
entries[].valuestringThe value as text, even for numbers. A secret:NAME value reads secret:**** unless you pass --reveal.
entries[].sourcestringThe layer the value came from: engine-default, kind-default, instance or invocation-override.
entries[].unvalidatedbooleantrue for agent.* keys, which Hekma does not check.

With no config set, entries is an empty list. A key with no value is an error (exit code 2) and prints nothing on stdout.

logs#

hekma agent logs NAME --json prints newline-delimited JSON: one complete object per line, in capture order. The shape is the same with --follow, so you can process each line as it arrives. An empty log prints nothing.

{"schema_version":1,"instance":"worker","stream":"agent-out","at":"2026-10-22T19:07:20Z","text":"worker ready, model=gpt-4o-mini"}
{"schema_version":1,"instance":"worker","stream":"agent-out","at":"2026-10-22T19:07:20Z","text":"KTESIO_USAGE {\"sequence\": 0, \"input_tokens\": 1200, \"output_tokens\": 300, \"cached_tokens\": 400}"}
{"schema_version":1,"instance":"worker","stream":"engine","at":"2026-10-22T19:07:20Z","text":"engine: starting -> running"}
FieldTypeMeaning
schema_versioninteger1.
instancestringThe agent's name.
streamstringagent-out (the agent's stdout), agent-err (its stderr) or engine (a line Hekma wrote).
atstringUTC timestamp with whole seconds. Several lines often share one; keep the line order rather than sorting by time.
textstringThe line, without its trailing newline.

memory attach#

hekma agent memory attach NAME --kind KIND --json:

{
  "schema_version": 1,
  "instance": "worker",
  "kind": "filesystem",
  "guarantee": "managed_dir_byte_durable",
  "dir": "/Users/you/Library/Application Support/ktesio/agents/worker/memory",
  "declared": true
}
FieldTypeMeaning
instancestringThe agent's name.
kindstringfilesystem or native.
guaranteestringmanaged_dir_byte_durable for filesystem (the folder exists and its files survive restarts unchanged), home_persistence_only for native (only the Agent Home is kept).
dirstringThe memory folder's path. For native this is where it would be; nothing is created.
declaredbooleantrue when the backing is filesystem and the agent's adapter maps the memory.dir key, so the agent will receive the path. Always false for native.

A native attach reads "kind": "native", "guarantee": "home_persistence_only" and "declared": false.

memory detach#

hekma agent memory detach NAME --json confirms the detach and nothing more; the folder and its files stay on disk.

{
  "schema_version": 1,
  "instance": "worker"
}

hekma run#

Unreleased: after 0.11.0. hekma run is on Hekma's main branch and ships in the next release.

hekma run open, close and show with --json print one Run (close with --selector or --dry-run prints the results document instead). This is a child Run after close:

{
  "schema_version": 1,
  "run": {
    "run_id": "run_01M76G5X0YP30AXB9BXRA00GPF",
    "control_depth": "announced",
    "wire_path": false,
    "status": "ended",
    "anomalies": [],
    "parent_run_id": "run_01M76G5WZWBJ6WQMQP5EVHM6A3",
    "instance": "worker",
    "process_owner": false,
    "end_cause": "closed",
    "created_at": "2026-11-11T23:48:05Z",
    "updated_at": "2026-11-11T23:48:05Z",
    "ended_at": "2026-11-11T23:48:05Z",
    "labels": [
      {
        "key": "task",
        "value": "review",
        "source": "caller"
      }
    ],
    "limits": {
      "token_per_run": 20000,
      "breach_action": "warn"
    },
    "policy": {
      "tokens": {
        "per_run": 20000,
        "cumulative": null
      },
      "dollars": {
        "per_run": null,
        "cumulative": null
      },
      "action": "warn",
      "effective_action": "warn",
      "scent_check": "off",
      "rate": null,
      "sources": {
        "tokens_per_run": "run",
        "tokens_cumulative": "unset",
        "dollars_per_run": "unset",
        "dollars_cumulative": "unset",
        "breach_action": "run",
        "scent_check": "default",
        "rate": "unset"
      }
    },
    "usage": {
      "input_tokens": 0,
      "output_tokens": 0,
      "cached_tokens": 0,
      "cost_micros": 0,
      "estimate": "estimated"
    },
    "open_children": 0
  }
}
FieldTypePresentMeaning
run_idstringalwaysrun_ and a ULID, so ids sort by creation time. Ids recorded by 0.11.0 (run-…) stay valid.
control_depthstringalwaysThe Control Depth: supervised for an agent's own Run, announced for a child Run inside it.
wire_pathbooleanalwaysWhether the Run's model calls pass through Hekma's metering listener. A supervised Run with false is shown as supervised (no wire).
statusstringalwaysThe Run Status: active, held or ended.
anomaliesarray of stringsalwaysThe Run's Anomalies, such as failed or breach.
parent_run_idstringoptionalThe parent Run, for a child Run.
instancestringoptionalThe agent the Run belongs to.
process_ownerbooleanalwaystrue for the Run that owns the agent's process; such a Run is ended with hekma agent stop, not close.
end_causestringoptionalWhy the Run ended, once it has, for example closed.
created_at, updated_at, ended_atstringended_at optionalUTC timestamps.
labelsarrayalwaysEach label's key, value and source (bound or caller); a bound label also has origin, config or label-verb.
limitsobjectalwaysThe Run's own ceilings, such as token_per_run and their breach_action; empty when it has none.
policyobjectalwaysThe Run's resolved limits, after the Run's own limits, the agent's configuration and every matching Policy: the tokens and dollars ceilings (per_run, cumulative; null when unset), the action and the effective_action after the depth fallback, scent_check, the rate, and sources, which says where each one comes from (see hekma budget).
usageobjectalwaysTokens of the Run and its children, and cost_micros with its estimate label.
open_childrenintegeralwaysHow many child Runs are open.

hekma label#

Unreleased: after 0.11.0. hekma label is on Hekma's main branch and ships in the next release.

hekma label set and remove with --json print one result per Run the target or Selector matched:

{
  "schema_version": 1,
  "verb": "label",
  "dry_run": false,
  "matched": 1,
  "results": [
    {
      "run_id": "run_01M76G2GZDTHGJV3X7EP61Y78C",
      "outcome": "labeled",
      "labels": [
        {
          "key": "env",
          "value": "prod",
          "source": "bound",
          "origin": "label-verb"
        },
        {
          "key": "team",
          "value": "payments",
          "source": "bound",
          "origin": "config"
        },
        {
          "key": "tier",
          "value": "gold",
          "source": "bound",
          "origin": "label-verb"
        }
      ],
      "prior_labels": [
        {
          "key": "env",
          "value": "prod",
          "source": "bound",
          "origin": "label-verb"
        },
        {
          "key": "team",
          "value": "payments",
          "source": "bound",
          "origin": "config"
        }
      ]
    }
  ]
}
FieldTypeMeaning
verbstringAlways label here. Every set-taking verb prints this same document and names itself (below).
dry_runbooleantrue for --dry-run: nothing was written.
matchedintegerHow many Runs the target or Selector matched.
results[].run_idstringThe Run.
results[].outcomestringlabeled, unchanged, would-label (with --dry-run) or refused.
results[].labels, results[].prior_labelsarrayThe Run's labels after the change (or as planned) and before, in the shape of a Run's labels. Absent on a refusal.
results[].errorobjectOn a refusal only: code and message.

A refusal carries a stable code, for example:

{
  "run_id": "run_01M76G5WZWBJ6WQMQP5EVHM6A3",
  "outcome": "refused",
  "error": {
    "code": "label-from-config",
    "message": "label `team` on Run `run_01M76G5WZWBJ6WQMQP5EVHM6A3` comes from the configuration key `labels.team` of agent `worker`, so it cannot be removed from the Run — change it with `hekma agent config set worker labels.team <value>`, or override it on the Run with `hekma label set run_01M76G5WZWBJ6WQMQP5EVHM6A3 team=<value>`"
  }
}

The label refusals are label-from-config (the label comes from configuration), label-not-bound (removing a caller label, one the Run's Caller set when it opened the Run) and run-ended (the Run has ended). label-bound, a caller label on a key that is already bound, is refused when a child Run is opened, not here. The command's exit code is the first failure's; see hekma label.

hekma ps#

Unreleased: after 0.11.0. hekma ps is on Hekma's main branch and ships in the next release.

hekma ps --json prints one document, the same one GET /v0/runs serves (see the Control API):

{"schema_version": 1, "view", "selector", "items", "next_cursor", "counts"}
FieldTypeMeaning
viewstringexceptions (the default) or all.
selectorstringThe Selector the listing was filtered by, if any.
itemsarrayOne object per listed Run, newest first.
next_cursorstringThe cursor for the next page, or null exactly when the read is exhausted. A final page that is exactly full carries none.
countsobjectlisted (what the active view matches) and healthy_open (open Runs with nothing to report).

Each item flattens the Run's fields (run_id, control_depth, wire_path, status, anomalies, instance, timestamps, as in hekma run) and adds:

FieldMeaning
labelsEach label with its source and, for bound labels, its origin.
usageThe Run's subtree usage.
cumulative_usageThe agent's cumulative usage, on process-owning rows only: a shared pot is not a per-Run figure.
latchedThe latched breaches, as [{dimension, scope, action}].
budgetThe headroom against the Run's resolved limits: the same field names as a budget object, plus the names of the Policies that supply them (policies), each limit's source (sources) and the effective_action after the depth fallback. Dollar figures appear only where a Rate prices them; an unpriced cap shows the unpriced-model Anomaly instead.
kept_on_pausePresent where the breach-default upgrade holds the agent on pause.

Results of the lifecycle verbs#

Unreleased: after 0.11.0. On Hekma's main branch and shipping in the next release.

hekma agent stop, pause, resume and drain print the same results document as hekma label with --json, for one agent or Run as for a Selector's set. So does hekma run close with --selector or --dry-run; closing one Run by id prints the Run.

{"schema_version": 1, "verb", "dry_run", "matched", "results": [{"run_id", "outcome", "instance", "error"}]}

verb names the command (stop, pause, resume, drain, close). Each result's outcome is the verb's past tense (stopped, paused, resumed, drained, closed), would-stop and its kin under --dry-run, or refused with error (code and message). instance is the agent's Fleet row after the act; a close result carries the closed Run as run instead, a drain result adds completed and waited_ms, and a --dry-run result names the agent as agent. The exit code is the first failure's class, with the number of failures in its message; see Selectors on the lifecycle verbs.

hekma budget#

Unreleased: after 0.11.0. hekma budget is on Hekma's main branch and ships in the next release.

hekma budget set --json prints the results document with verb budget. Each Run's result carries its outcome (raised, lowered, cleared, set, unchanged or would-set), the Run's own limits before and after, the resolved limits with their sources, what the change fired or re-armed, run_scoped: true and a note saying the limit ends with the Run. A source is the string run, instance, default or unset, the object {"policy": "<name>"} for a Policy, or caller where a Caller's tighter limit applies. The text output writes a Policy source as policy:<name>.

hekma budget show --json prints, per Run, each ceiling with its source, usage and headroom, the Breach Action, the latched breaches and the limits set on the Run itself. With --selector or with no target it lists Runs as hekma ps --all does and pages with --limit and --cursor: the document then has next_cursor.

hekma run keys and revoke-keys#

Unreleased: after 0.11.0. Run Keys are on Hekma's main branch and ship in the next release.

hekma run keys RUN --json lists a Run's credentials by token id, never by value. This is a child Run's pair after hekma run revoke-keys:

{
  "schema_version": 1,
  "run_id": "run_01M7TPDWV2TP4XZRJ4M4BR3X4S",
  "keys": [
    {
      "token_id": "802e4f6cbe1f",
      "class": "run-key",
      "state": "revoked",
      "issued_at": "2026-11-19T20:02:07Z",
      "revoked_at": "2026-11-19T20:02:07Z",
      "revoke_cause": "operator"
    },
    {
      "token_id": "04c7eb8a1e78",
      "class": "refresh",
      "state": "revoked",
      "issued_at": "2026-11-19T20:02:07Z",
      "revoked_at": "2026-11-19T20:02:07Z",
      "revoke_cause": "operator"
    }
  ]
}

An active key has no revoked_at or revoke_cause, and a supervised agent's key also carries its launch_generation. hekma run revoke-keys RUN --json prints what it revoked:

{
  "cascade": true,
  "reuse_cleared": false,
  "revoked": [
    {
      "cascaded": false,
      "class": "run-key",
      "run_id": "run_01M7TPDWV2TP4XZRJ4M4BR3X4S",
      "token_id": "802e4f6cbe1f"
    },
    {
      "cascaded": false,
      "class": "refresh",
      "run_id": "run_01M7TPDWV2TP4XZRJ4M4BR3X4S",
      "token_id": "04c7eb8a1e78"
    }
  ],
  "run_id": "run_01M7TPDWV2TP4XZRJ4M4BR3X4S",
  "schema_version": 1
}

cascaded is true for a credential issued under the Run's own, such as a child Run's key, and reuse_cleared says whether the credential-reuse Anomaly was cleared. hekma run open --print-key --json adds a credentials object beside run, with run_key, refresh_credential, token_id and refresh_token_id; it is the only document that ever carries a key.

Engine events#

A program that embeds the engine can subscribe to events. Each event is one of three payloads wrapped with a kind tag; the payload carries its own schema_version (1 for all three). The CLI does not print events, but it writes the same transition and breach records, without the kind tag, as JSON Lines to logs/instance.log and logs/breaches.log in the Agent Home. On Hekma's main branch (Unreleased: after 0.11.0) those records live in the state database, and the two files are still written after each commit as copies. A fourth kind, run, reports changes to Runs (below). Events, resync and diagnostics covers subscribing and catching up after a gap.

transition#

Sent after every lifecycle change. This one is an agent paused by a token budget:

{
  "kind": "transition",
  "schema_version": 1,
  "instance": "spender",
  "prior_state": "running",
  "new_state": "paused",
  "cause": {
    "kind": "budget-exceeded",
    "scope": "cumulative",
    "dimension": "tokens",
    "limit": 3000,
    "observed": 3600
  },
  "at": "2026-10-22T19:11:09Z"
}
FieldTypeMeaning
instancestringThe agent's name.
prior_state, new_statestringThe states before and after.
causeobjectWhy it changed, tagged by cause.kind (below).
atstringUTC timestamp.
cause.kindExtra fieldsWhen
commandcommand (for example "start")An operator command.
adapter-readynoneThe process is up after a start.
launch-errordetailThe launch failed.
stop-gracefulnoneThe process exited within the stop window.
stop-forceddetailThe process was killed after the window.
pause-best-effort, resume-best-effortdetailA pause or resume on a best-effort declaration, or with no process held.
detached-resumeddetailHekma woke an operator-paused detached agent as the command exited.
crasheddetailThe process exited on its own, or was gone when a command looked for it.
restartedcount, waited_msThe restart policy started it again.
budget-exceededscope, dimension, limit, observed; with a dollar budget also dollar_limit, dollar_observed, estimate_labelA budget breach paused or stopped it.
readiness-timeout (Unreleased: after 0.11.0)probe, waited_msThe declared readiness probe never passed; the agent is failed and is not restarted.
unresponsive (Unreleased: after 0.11.0)check, failing_for_ms; optional detailThe declared liveness check failed for its whole window.
restart-requested (Unreleased: after 0.11.0)code; optional detailThe agent exited with a code its adapter declares as a relaunch request.
clean-exit (Unreleased: after 0.11.0)codeThe agent exited with a code its adapter declares as a clean finish; it is stopped.
pause-cooperative, resume-cooperative (Unreleased: after 0.11.0)commandA declared pause or resume command ran.
drain-stopped (Unreleased: after 0.11.0)completed, waited_msdrain stopped the agent; completed is false when the wait ran out or the agent ended on its own.

New cause kinds may be added within version 1; handle unknown ones. A program built against an older hekma-engine rejects a cause kind it does not know, so read events from a newer Hekma with a parser that accepts unknown kinds.

budget_breach#

Sent once per budget per run when a budget is crossed, whatever the breach action:

{
  "kind": "budget_breach",
  "schema_version": 1,
  "instance": "spender",
  "run_id": "run-1792696267061924000-0",
  "scope": "cumulative",
  "dimension": "tokens",
  "limit": 3000,
  "observed": 3600,
  "action": "pause",
  "metering_source": "self-reported",
  "at": "2026-10-22T19:11:09Z"
}
FieldTypePresentMeaning
run_idstringalwaysThe run the breach happened in.
scopestringalwaysper-run or cumulative.
dimensionstringalwaystokens or dollars.
limit, observedintegeralwaysThe ceiling and the value that crossed it, in tokens, or in micro-dollars for a dollar breach.
dollar_limit, dollar_observedinteger (micro-dollars)dollar breachesThe same values, as money.
estimate_labelstringdollar breachesestimated.
actionstringalwaysThe breach action taken: pause, stop or warn; block (Unreleased: after 0.11.0) — the wire fence.
metering_sourcestringalwaysWhere the usage came from.

usage_update#

Sent each time a usage event is written to the ledger. A replayed event (same run and sequence) is not written again and sends nothing.

{
  "kind": "usage_update",
  "schema_version": 1,
  "event": {
    "instance": "spender",
    "run_id": "run-1792696267061924000-0",
    "input_tokens": 1000,
    "output_tokens": 200,
    "cached_tokens": 100,
    "metering_source": "self-reported",
    "sequence": 2,
    "occurred_at": "2026-10-22T19:11:09Z"
  }
}
FieldTypeMeaning
event.instancestringThe agent's name.
event.run_idstringThe run the usage belongs to.
event.input_tokens, event.output_tokensintegerTokens in this event; input includes cached.
event.cached_tokensinteger or nullThe cached part of the input. null only for usage recorded before Hekma tracked cached tokens.
event.metering_sourcestringself-reported or engine-observed.
event.sequenceintegerThe per-run number used to drop replays. Self-reporting agents supply it; Hekma assigns it for observed usage.
event.occurred_atstringUTC timestamp.

This example was built from a usage row the v0.11.0 binary wrote to its ledger during the same run as the breach above; the field names and order are those of the engine's event type.

run#

Unreleased: after 0.11.0. Run events are on Hekma's main branch and ship in the next release.

Sent when a Run is created, ends, or changes its depth, status, Anomalies or labels, right after the event that caused it: a breach is followed by its Run's breach Anomaly, and a lifecycle transition by its Run's status change. The payload's schema_version is 1.

FieldTypeMeaning
changestringcreated, depth-changed, status-changed, anomalies-changed, labels-changed, limits-changed (Unreleased: after 0.11.0, on main) or ended.
run_id, parent_run_id, instancestringThe Run, its parent (child Runs only) and its agent (when it has one).
control_depth, wire_path, status, anomalies, labelsThe Run after the change, as in hekma run --json.
prior_status, prior_control_depth, prior_wire_path, prior_labelsOptional: the value before, on the change that moved it.
limits, prior_limitsOptional: on limits-changed, the Run's own limits after and before. The event schema stays 1.
causestringOptional: why it changed; on labels-changed, label-verb or config; on limits-changed, the actor that set the limits.
policiesarray of stringsOptional: the names of the Policies that supply the Run's limits.
limits_layerstringOptional: on limits-changed, which layer of the Run's limits changed, run (the Operator's or a Host's) or caller (a Run Key's).
atstringUTC timestamp.

policy and breach_default_upgraded#

Unreleased: after 0.11.0. On Hekma's main branch and shipping in the next release.

The bus, the SSE stream and the export carry two more event kinds (and credential, below). policy reports a Policy created, changed or deleted: its payload names which under change, as the run event does, with the matched and fallback counts. breach_default_upgraded is recorded once, when the first open of an upgraded state directory keeps agents on pause: its instances lists each such agent by name, with config_written saying whether pause was written into its configuration. The OTLP v1 export ignores both, and every run event.

credential#

Unreleased: after 0.11.0. On Hekma's main branch and shipping in the next release.

Sent when a Run Key or refresh credential is issued, rotated by a refresh, revoked, or presented a second time. It names the credential by token id, never by value. These two are a child Run's key being issued and then revoked through the Control API's revoke-keys route, which is what hekma run revoke-keys calls:

{"kind":"credential","schema_version":1,"change":"issued","class":"run-key","token_id":"9dfac718f809","run_id":"run_01M7TPEB6XE5WDBTE21QRNBVJH","issued_by":"operator","at":"2026-11-19T20:02:22Z"}
{"kind":"credential","schema_version":1,"change":"revoked","class":"run-key","token_id":"9dfac718f809","run_id":"run_01M7TPEB6XE5WDBTE21QRNBVJH","cause":"operator","at":"2026-11-19T20:02:22Z"}
FieldTypeMeaning
changestringissued, rotated, revoked or reuse-detected.
classstringrun-key or refresh.
token_idstringThe credential's 12-character id, as hekma run keys shows it.
run_idstringThe Run the credential belongs to.
launch_generation, issued_by, prior_token_id, causeOptional: the launch a supervised agent's key was issued for, who issued it, the credential a refresh replaced, and why it was revoked.
atstringUTC timestamp.