## §OIP SYSTEM ARTICLE — LEDGER (4 operations)
A generated article for one OIP shelf. It lists every operation in this API/CLI/MCP/device/model/core subsystem, links each leaf article, and gives the ledger path for proof.

### Read Order
- scan operations
- open a leaf doc
- run via run_now or POST /api/dispatch
- open receipt
- repair/replay if needed

### Operations
- **LEDGER_QUERY** — Raw SELECT against the LEDGER D1 binding (loop-shared-events.events table). $1=SQL, rest = bind params. Return
  when: you need to ledger query
  args: $1
  doc: https://miscsubjects.com/api/dispatch?key=LEDGER_QUERY&format=markdown
  run: https://miscsubjects.com/api/dispatch?invoke=LEDGER_QUERY&body=%3Carg1%3E&share=<TOKEN>
  history: https://miscsubjects.com/api/invocations?object_id=LEDGER_QUERY
- **LEDGER** — Read your own ledger to troubleshoot: recent messages, each tool you ran with its output/error, and your reply
  when: you need to ledger
  args: see content
  doc: https://miscsubjects.com/api/dispatch?key=LEDGER&format=markdown
  run: https://miscsubjects.com/api/dispatch?invoke=LEDGER&body=%3Csee%20content%3E&share=<TOKEN>
  history: https://miscsubjects.com/api/invocations?object_id=LEDGER
- **LEDGER_ERRORS** — Return the most recent ledger event whose own response starts with ERR.
  when: Cyrus asks for the last error, recent errors, or why something failed.
  args: none.
  doc: https://miscsubjects.com/api/dispatch?key=LEDGER_ERRORS&format=markdown
  run: https://miscsubjects.com/api/dispatch?invoke=LEDGER_ERRORS&share=<TOKEN>
  history: https://miscsubjects.com/api/invocations?object_id=LEDGER_ERRORS
- **LEDGER_EXEC** — Run a non-SELECT D1 query against the LEDGER database (loop-shared-events). INSERT/UPDATE/DELETE only.
  when: writing audit events or other data to the shared ledger.
  args: $1 = SQL. Pipes inside SQL are preserved. Remaining args = bind params.
  doc: https://miscsubjects.com/api/dispatch?key=LEDGER_EXEC&format=markdown
  run: https://miscsubjects.com/api/dispatch?invoke=LEDGER_EXEC&body=INSERT%20INTO%20events%20(id%2C%20ts%2C%20source%2C%20key%2C%20action%2C%20direction%2C%20status%2C%20request_preview%2C%20response_preview)%20VALUES%20(%3F%2C%20%3F%2C%20'guardian'%2C%20'GUARDIAN_EVENT'%2C%20'check'%2C%20'internal'%2C%20200%2C%20%3F%2C%20%3F)%7Cid%7Cts%7Cpreview%7Cpreview&share=<TOKEN>
  history: https://miscsubjects.com/api/invocations?object_id=LEDGER_EXEC

### Troubleshooting
- If a row's example has placeholders, replace only the placeholder values and preserve separators.
- If a call fails, open its receipt and repair it with POST /api/dispatch {key, body, repairs:'inv_ID'}.
- If token scope denies this system, ask the owner for a row:/rows:/pfx: token scoped to the exact operation set.

Back to the tree: https://miscsubjects.com/api/dispatch?map=1&format=markdown