ClawMetry Query Contract (q/1)

September 4, 2026 ยท View on GitHub

GENERATED FILE, do not edit by hand. Source of truth: clawmetry/query_contract.py. Regenerate with python3 scripts/gen_query_contract_doc.py (CI fails on drift).

The node query surface served by routes/local_query.py (/api/local/* plus the daemon proxy and the cloud relay) is declared in clawmetry/query_contract.py. This document is generated from that registry; CI fails when they disagree.

Evolution rule

Inside q/1 evolution is additive only: new methods and new optional args may be added. Renaming or removing a method, an arg, or a response field requires bumping the contract to q/2. A planned method is a declared target that is not served yet; shipping it means flipping its registry entry to live in the same change (the drift test enforces both directions).

Trust classes

  • plaintext: aggregate counters or metadata the server may see in cleartext (heartbeat piggyback). Never raw content.
  • e2e: session/content-bearing payloads. These only ever leave the machine AES-256-GCM encrypted via the sync daemon snapshot path and must never appear on a plaintext push list.

Non-goals

  • No per-model data in the device-facing glance method. Devices get top-line counters only; model breakdowns live in models.

Methods

MethodStatusTrustBackingArgsDescription
agent_graphliveplaintextquery_agent_graphruntime, since, until, limit (default 500, range 1..2000)Cross-session agent spawn graph: nodes (agent_type+id stats) + spawn edges. Optional runtime arg scopes to one runtime ('openclaw' matches legacy NULL agent_type).
aggregatesliveplaintextquery_aggregatesagent_id, since, untilPer-day rollup of events/tokens/cost (aggregate counters only).
eventslivee2equery_eventssession_id, agent_id, event_type, since, until, limit (default 200, range 1..5000)Raw event rows (tool calls, messages, errors), newest first.
external_callslivee2equery_external_callssession_id, since, until, limit (default 200, range 1..2000)External (non-LLM) API calls captured by the interceptor.
healthliveplaintexthealth(none)Store health snapshot (engine, size, ring depth, flush age).
modelsliveplaintextquery_rollup_model_dailyruntime, since, until, limit (default 1000, range 1..10000)Per-model daily token/cost rollup across runtimes.
replay_eventslivee2equery_replay_eventssession_id (required), limit (default 2000, range 1..10000)Canonical replay-event rows for one session (#4813). Rows in kind-agnostic order; the /api/replay-tree endpoint groups them into turns/delegations/workflows/approvals.
rollup_sessionslivee2equery_rollup_sessionsruntime, limit (default 200, range 1..2000)Per-session materialized summary (title, status, totals, stuck flag).
runtimesliveplaintextquery_rollup_runtime_dailysince, until, limit (default 1000, range 1..10000)Per-runtime daily activity/cost rollup (claude_code, openclaw, ...).
searchlivee2equery_searchq (required), model, status, since, until, limit (default 50, range 1..500)Full-text search over session titles and eval reasons.
session_contextlivee2equery_session_contextsession_id (required), agent_type, limit (default 200, range 1..1000)Inputs & context rows for one session: system prompt, first user prompt, tool definitions, MCP servers, context files and runtime setup captured from context.compiled events. Content is redacted + capped; sha256/size describe the full text.
sessionslivee2equery_sessionsagent_id, since, until, limit (default 100, range 1..2000)One row per session_id with start/end, event count, cost.
similar_sessionslivee2equery_similar_sessionssession_id (required), window_days (default 30, range 1..365), limit (default 10, range 1..50)Runs shaped like this one (WO-60): nearest sessions by tool-call n-gram similarity inside a window, same runtime first, with score, runtime, model, cost, outcome. Carries session titles, so content class.
spanslivee2equery_spanstrace_id, session_id, agent_type, since, until, limit (default 200, range 1..2000)OTel span rows with full filters (trace/session/agent/time).
traceslivee2equery_tracessession_id, agent_type, since, until, limit (default 100, range 1..1000)One row per trace_id with aggregate span stats.
transcriptlivee2equery_eventssession_id (required), limit (default 500, range 1..5000)Alias of events scoped to one required session_id.
transcript_pagelivee2equery_transcript_pagesession_id (required), before_ts, limit (default 150, range 1..250)One older-history page of a session's events, newest-first. before_ts is an exclusive ms-epoch cursor (pass the previous page's next_before_ts to walk backward). Returns {rows, count, has_more, next_before_ts}.
approvalsplannedplaintextquery_approvalsstatus, limit (default 100, range 1..1000)Approval queue metadata (ids, states, timestamps; no content).
brainplannede2equery_eventssession_id, since, limit (default 200, range 1..2000)Reasoning/tool event slice powering the Brain feed.
glanceplannedplaintextrollup_glance(none)Device-facing top-line counters (sessions, cost, alerts). Non-goal: no per-model data in glance.
sessionplannede2equery_sessions_tablesession_id (required)Single-session detail row (title, status, outcome, totals).
usageplannedplaintextrollup_usage_dailyruntime, since, untilDaily token/cost usage series (input/output/cache splits).

Live methods: 17. Planned methods: 5.