{
    "table": "api_routes",
    "pk": "name",
    "total": 63,
    "page": 1,
    "per": 25,
    "pages": 3,
    "filter": [],
    "rows": [
        {
            "name": "tickets.recent",
            "method": "GET",
            "sql": "SELECT id,title,severity,status FROM tickets\n   WHERE (COALESCE(:status,'')='' OR status=:status) ORDER BY id DESC LIMIT COALESCE(:n,-1)",
            "auth": "public",
            "params": "{\"status\":\"str\",\"n\":\"int\"}",
            "meta": null
        },
        {
            "name": "authorize_process",
            "method": "POST",
            "sql": "INSERT INTO tickets (ts,updated,component,title,severity,status,body,meta) VALUES (strftime('%s','now'),strftime('%s','now'),:name,'process start','info','AUTHORIZED',:body,:meta)",
            "auth": "token",
            "params": "{\"name\":\"str\",\"body\":\"str\",\"meta\":\"str\"}",
            "meta": null
        },
        {
            "name": "process_status",
            "method": "POST",
            "sql": "UPDATE tickets SET status=:status, updated=strftime('%s','now') WHERE id=:id",
            "auth": "token",
            "params": "{\"status\":\"str\",\"id\":\"int\"}",
            "meta": null
        },
        {
            "name": "processes.running",
            "method": "GET",
            "sql": "SELECT id,component,status,updated FROM tickets WHERE status IN ('AUTHORIZED','RUNNING') ORDER BY id DESC",
            "auth": "public",
            "params": "{}",
            "meta": null
        },
        {
            "name": "agent.register",
            "method": "POST",
            "sql": "INSERT OR REPLACE INTO agents (agent_id,parent,prompt,tools,status,ts) VALUES (:agent_id,:parent,:prompt,:tools,'active',strftime('%s','now'))",
            "auth": "token",
            "params": "{\"agent_id\":\"str\",\"parent\":\"str\",\"prompt\":\"str\",\"tools\":\"str\"}",
            "meta": "record an agent spawn: id + parent + prompt() + tools()"
        },
        {
            "name": "agent.trail",
            "method": "GET",
            "sql": "SELECT m.ts, m.tool, m.intent, m.note FROM memories m WHERE m.session=:agent_id ORDER BY m.ts",
            "auth": "public",
            "params": "{\"agent_id\":\"str!\"}",
            "meta": "the propagation trail for an agent id (tool + intent events, in order)"
        },
        {
            "name": "ticket.approve",
            "method": "POST",
            "sql": "UPDATE tickets SET approval_sig=:approval_sig, updated=strftime('%s','now') WHERE id=:id",
            "auth": "token",
            "params": "{\"id\":\"int!\",\"approval_sig\":\"str!\"}",
            "meta": "attach a wallet signature over the ticket content digest -- the external approval the agent cannot forge"
        },
        {
            "name": "ticket.create",
            "method": "POST",
            "sql": "INSERT INTO tickets (ts, updated, component, title, severity, status, body, patch) VALUES (strftime('%s','now'), strftime('%s','now'), :component, :title, :severity, 'REQUESTED', :body, :patch)",
            "auth": "token",
            "params": "{\"component\":\"str\",\"title\":\"str\",\"severity\":\"str\",\"body\":\"str\",\"patch\":\"str\"}",
            "meta": "file a crank ticket with its change (patch); status REQUESTED, approval is a separate wallet signature"
        },
        {
            "name": "ticket.approval",
            "method": "GET",
            "sql": "SELECT id, component, title, body, patch, status, approval_sig FROM tickets WHERE component=:component ORDER BY id DESC LIMIT 1",
            "auth": "public",
            "params": "{\"component\":\"str\"}",
            "meta": "the latest ticket for a component (content + patch + approval_sig) for crankd to verify + apply"
        },
        {
            "name": "policy.create",
            "method": "POST",
            "sql": "INSERT INTO crank_policies (ts, component, max_version, expires, sig) VALUES (strftime('%s','now'), :component, :max_version, :expires, :sig)",
            "auth": "token",
            "params": "{\"component\":\"str\",\"max_version\":\"str\",\"expires\":\"int\",\"sig\":\"str\"}",
            "meta": "file a wallet-signed standing crank policy for a component (scope: max_version, expiry)"
        },
        {
            "name": "policy.active",
            "method": "GET",
            "sql": "SELECT id, component, max_version, expires, sig FROM crank_policies WHERE component=:component ORDER BY id DESC LIMIT 1",
            "auth": "public",
            "params": "{\"component\":\"str\"}",
            "meta": "the newest standing policy for a component (for crankd to verify + apply bounds)"
        },
        {
            "name": "job.put",
            "method": "POST",
            "sql": "INSERT OR REPLACE INTO crank_jobs (hash, ts, spec) VALUES (:hash, strftime('%s','now'), :spec)",
            "auth": "token",
            "params": "{\"hash\":\"str\",\"spec\":\"str\"}",
            "meta": "store a content-addressed crank job (hash = sha256 of the canonical spec)"
        },
        {
            "name": "job.get",
            "method": "GET",
            "sql": "SELECT hash, ts, spec FROM crank_jobs WHERE hash=:hash",
            "auth": "public",
            "params": "{\"hash\":\"str!\"}",
            "meta": "fetch a content-addressed crank job by hash"
        },
        {
            "name": "run.record",
            "method": "POST",
            "sql": "INSERT INTO crank_runs (ts, component, version, ticket_id, authorized_by, ok, shadow_output, digest)\n   VALUES (strftime('%s','now'), :component, :version, :ticket_id, :authorized_by, :ok, :shadow_output, :digest)",
            "auth": "token",
            "params": "{\"component\":\"str\",\"version\":\"str\",\"ticket_id\":\"int\",\"authorized_by\":\"str\",\"ok\":\"int\",\"shadow_output\":\"str\",\"digest\":\"str\"}",
            "meta": "persist a crank run with its full shadow output (content-addressed by sha256(shadow_output))"
        },
        {
            "name": "run.get",
            "method": "GET",
            "sql": "SELECT id, ts, component, version, ticket_id, authorized_by, ok, shadow_output, digest\n   FROM crank_runs WHERE digest=:digest ORDER BY id DESC",
            "auth": "public",
            "params": "{\"digest\":\"str!\"}",
            "meta": "fetch crank run(s) by the content address of their shadow output"
        },
        {
            "name": "run.recent",
            "method": "GET",
            "sql": "SELECT id, ts, version, ticket_id, authorized_by, ok, digest\n   FROM crank_runs WHERE (COALESCE(:component,'')='' OR component=:component)\n   ORDER BY id DESC LIMIT COALESCE(:n,-1)",
            "auth": "public",
            "params": "{\"component\":\"str\",\"n\":\"int\"}",
            "meta": "list a component's recent crank runs (metadata; use run.get for the full output)"
        },
        {
            "name": "mandate.record",
            "method": "POST",
            "sql": "INSERT INTO mandates (ts, ticket_id, seq, clause, digest)\n   VALUES (strftime('%s','now'), :ticket_id, :seq, :clause, :digest)",
            "auth": "token",
            "params": "{\"ticket_id\":\"int\",\"seq\":\"int\",\"clause\":\"str\",\"digest\":\"str\"}",
            "meta": "record one falsifiable clause of a ticket's mandate"
        },
        {
            "name": "mandate.list",
            "method": "GET",
            "sql": "SELECT seq, clause, digest FROM mandates WHERE ticket_id=:ticket_id ORDER BY seq",
            "auth": "public",
            "params": "{\"ticket_id\":\"int!\"}",
            "meta": "list a ticket's mandate clauses in order"
        },
        {
            "name": "guarantee.record",
            "method": "POST",
            "sql": "INSERT INTO guarantees (ts, ticket_id, version, shadow, guarantee, clause_seq, digest)\n   VALUES (strftime('%s','now'), :ticket_id, :version, :shadow, :guarantee, :clause_seq, :digest)",
            "auth": "token",
            "params": "{\"ticket_id\":\"int\",\"version\":\"str\",\"shadow\":\"str\",\"guarantee\":\"str\",\"clause_seq\":\"int\",\"digest\":\"str\"}",
            "meta": "record one harvested shadow guarantee, attributed to a ticket and bound to a mandate clause"
        },
        {
            "name": "guarantee.list",
            "method": "GET",
            "sql": "SELECT version, shadow, guarantee, clause_seq FROM guarantees WHERE ticket_id=:ticket_id ORDER BY id",
            "auth": "public",
            "params": "{\"ticket_id\":\"int!\"}",
            "meta": "list a ticket's harvested guarantees and the clauses they bind to"
        },
        {
            "name": "binding.record",
            "method": "POST",
            "sql": "INSERT INTO clause_bindings (ts, ticket_id, clause_seq, guarantee_label, digest)\n   VALUES (strftime('%s','now'), :ticket_id, :clause_seq, :guarantee_label, :digest)",
            "auth": "token",
            "params": "{\"ticket_id\":\"int\",\"clause_seq\":\"int\",\"guarantee_label\":\"str\",\"digest\":\"str\"}",
            "meta": "declare that a shadow guarantee label satisfies a mandate clause (applied by crankd at harvest)"
        },
        {
            "name": "binding.list",
            "method": "GET",
            "sql": "SELECT clause_seq, guarantee_label FROM clause_bindings WHERE ticket_id=:ticket_id",
            "auth": "public",
            "params": "{\"ticket_id\":\"int!\"}",
            "meta": "list a ticket's declared guarantee-label -> clause bindings"
        },
        {
            "name": "guarantee.held",
            "method": "GET",
            "sql": "SELECT DISTINCT g.guarantee FROM guarantees g JOIN tickets t ON t.id = g.ticket_id\n   WHERE t.component = :component",
            "auth": "public",
            "params": "{\"component\":\"str\"}",
            "meta": "every guarantee label a component has recorded \u2014 the contract crankd will not let a crank erode"
        },
        {
            "name": "edge.record",
            "method": "POST",
            "sql": "INSERT INTO ticket_edges (ts, parent_id, child_id, kind)\n   VALUES (strftime('%s','now'), :parent_id, :child_id, :kind)",
            "auth": "token",
            "params": "{\"parent_id\":\"int\",\"child_id\":\"int\",\"kind\":\"str\"}",
            "meta": "record a parent->child ticket edge (the owned tree)"
        },
        {
            "name": "children.list",
            "method": "GET",
            "sql": "SELECT e.child_id, e.kind, t.title, t.status, t.component\n   FROM ticket_edges e JOIN tickets t ON t.id = e.child_id\n   WHERE e.parent_id = :parent_id ORDER BY e.child_id DESC",
            "auth": "public",
            "params": "{\"parent_id\":\"int!\"}",
            "meta": "list a ticket's child tickets (the owned tree)"
        }
    ]
}
