# Protocol API
<!--
ref: @protocol/protocol-api
type: appendix
tags: [API, protocol management, automation, data handling]
triggers: [create protocol, fetch protocol, update entry, delete entry]
trigger_prompt: When a user needs to interact with protocol data, whether for creating new entries, fetching existing ones, or managing updates and deletions.
category: meta
last_reviewed: 2026-04-30
complements: [@protocol/api-reference, @integrations/curly]
audience: [agent-author, terminal-only]
version: 58
updated_at: 2026-11-25T16:14:15.935Z
-->
The protocol.supply endpoint reference: `(repo, path, slug)` addressing with its 300/409 collision rules, entry and impulse CRUD, append/digest body shapes, auth, repos, tokens, ingest, search operators, the 100-req/hr limit, and the two publish gotchas — stacked `*Related:*` footers and the `?scrub=missing` default.
> **Looking for the why-not-just-the-what?** See [@protocol/api-reference](/@protocol/api-reference.md) for the verbose mental-model + patterns companion. **Machine-readable spec:** `GET /openapi.json` returns the full OpenAPI 3 schema.
## Addressing — (repo, path, slug)
The uniqueness scope for entries is **`(repo, path, slug)`** (DB constraint: UNIQUE `(repo_id, path, slug, version)`). The same slug may exist at different paths within one repo — **slug alone does not identify an entry.**
- **Write path-aware.** `POST /entry` takes `path` explicitly. `POST /entry/publish` resolves its upsert target only at the declared path (explicit option > frontmatter `path:` > filePath-derived > root). A flat publish can no longer clobber or relocate a same-slug entry at another path.
- **Slug-addressed PUT/PATCH** (`/repo/{repo}/entry/{slug}` and file ops) resolve exactly when `path` is given (query or body). Without it: a repo-unique slug resolves; an ambiguous slug returns **409 Conflict** listing every path-qualified ref — pick one and retry with `path`.
- **Bare-slug GET** (`/@{repo}/{slug}`): a root-exact match wins; otherwise a single same-slug match at another path serves (back-compat); **2+ matches return 300 Multiple Choices** with the full ref list. Fetch path-qualified (`/@{repo}/{path}/{slug}`) whenever the entry has a path.
- **Refs are path-qualified everywhere they render** — search results, related-protocols footers, bootstrap. Use the ref exactly as given; don't strip the path.
- **Avoiding collisions:** keep slugs unique per repo where you control naming, carry the full path-qualified ref in anything you store, and never write with bare-slug surfaces into a repo that has same-slug entries across paths.
- **`?legacySlugFallback=true`** (deprecated, publish only) restores the old any-path adoption behavior for explicit migrations. Do not use in normal flows.
## Discovery
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | / | - | API overview (same as /llms.txt) |
| GET | /llms.txt | - | API overview for LLMs |
| GET | /openapi.json | - | OpenAPI/Swagger spec |
| GET | /robots.txt | - | Bot access rules |
| GET | /browse | - | Browse public protocols |
## Protocols (read)
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | /bootstrap.md | - | Core protocols for session start |
| GET | /@{repo}/{slug}.md | - | Fetch protocol by ref. Path-qualified form `/@{repo}/{path...}/{slug}.md` is exact; bare-slug GET serves a unique match, returns **300 Multiple Choices** + ref list when 2+ same-slug entries exist at different paths. |
| GET | /search.md?q= | - | Search protocols (full-text) |
| GET | /fetch.md?include= | - | Batch fetch (comma-separated refs) |
| GET | /fetch?id= | - | Batch fetch by entry id (comma-separated). An unknown id, or one in a repo you cannot read, reports as not found |
| GET | /entry/{id} | - | Fetch by id: exactly what the entry's canonical ref serves (md/json, `?max` `?section` `?peek` (deprecated, use `?trunc=`) `?trunc` `?key`). An id you cannot read is a plain 404 |
| GET | /entry/{id}/raw | Yes (owner/admin) | The body as first submitted, stored only when a scrub/normalize pass changed it. `altered: false` with `rawContent: null` means nothing changed it: `content` is the original |
**`?section=rows` on a registry** serves its work list: the rows table a whole fetch appends (up to 200 rows; it names `GET /entry/{id}/rows` as the full set, and says how many rows it left out), without the body. Bound it with `?trunc=N`; `?max=` with any `?section=` is a 400. A body heading named `rows` wins, so an existing address never changes meaning. A registry's section-miss 404 lists `rows` among the valid slugs. *Lands on next deploy (commit `734ee10`); until then `?section=rows` is a 404 and `GET /entry/{id}/rows` is the bounded form.*
## Protocols (write)
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| POST | /entry/publish | Yes | Create or replace from full markdown. Body: `{repoId, content}`. `repoId` is canonical (the `repo_xxx` id from `/repo`); slug is accepted as fallback but may fail with `"Repo 'X' not found"` on cross-owner publishes — pass the explicit `repo_xxx` id when in doubt. Upsert resolves ONLY at the entry's declared path (explicit `path` option > frontmatter `path:` > filePath-derived > root) — idempotent on `(repo, path, slug)`, never cross-path. The old any-path slug fallback is gone; `?legacySlugFallback=true` (deprecated) restores it for explicit migrations only. See *Addressing* above. Query flags: `?scrub=missing\|full\|none` (default `missing`), `?derive=true` for a sync LLM call returning `derived:` in the response. See *Publish gotchas* below. |
| POST | /entry | Yes | Create from structured fields (title, content, tags, …). Same query flags as publish: `?scrub=`, `?derive=true`. |
| POST | /entry/generate | Yes | AI-generate a draft entry from a prompt |
| POST | /entry/refine | Yes | AI-refine an existing draft (suggestions, restructuring) |
| PUT | /entry/{id} | Yes | Replace top-level fields, creates new version. Same query flags as publish: `?scrub=`, `?derive=true`, plus legacy `?regenerate=true\|false`. |
| PUT | /entry/{id}/completed | Yes | Mark entry as completed (impulse-style lifecycle on entries) |
| PATCH | /entry/{id} | Yes | String-replace inside content (`old_string` → `new_string`) |
| DELETE | /entry/{id} | Yes | Soft-delete entry |
| GET | /entry/{id}/version | Read | Version history, version DESC. On a public repo, non-stewards get prior versions as metadata only (`redacted: true`, no body); a tombstoned version carries `tombstoned: true` |
| POST | /entry/{id}/version/tombstone | Repo owner | `{from, to?}` — irreversibly wipe prior versions' content (number, date, author kept). Never the head; publish a correction first. Returns `{id, tombstoned:[N…]}`; idempotent |
| DELETE | /entry/{id}/version?from=&to= | Repo owner | Hard-delete prior versions. Numbers are never reused; `slug_N` for a deleted N serves the head. Never the head. Returns `{id, deleted:[N…]}`. Scoped OAuth tokens are refused on both |
| GET | /entry/{id}/rows/{rowId}/versions | Read | A registry row's history, version DESC. Same rule: on a public repo (or via a share link) non-stewards get prior versions as metadata only (`redacted: true`, empty `data`, the live key) |
| POST | /entry/{id}/rows/{rowId}/versions/tombstone | Repo owner | `{from, to?}` — irreversibly wipe prior row versions' data (a renamed key takes the live key). Never the live version. Returns `{rowId, tombstoned:[N…]}` |
| DELETE | /entry/{id}/rows/{rowId}/versions?from=&to= | Repo owner | Hard-delete prior row versions; numbers are never reused. Never the live version; a deleted row's whole history is in reach. Returns `{rowId, deleted:[N…]}`. Scoped OAuth tokens are refused |
| POST | /entry/{id}/append | Yes | Append a block to content (see body below) |
| POST | /@{repo}/{slug}/append | Yes | Same as above, addressed by canonical ref |
### Publish gotchas (round-tripping an edit)
If you fetch a protocol, edit it, and re-publish via `POST /entry/publish`, these server behaviors will bite you — and read the response's `warnings` array every time (see 4):
**1. The fetch endpoint appends runtime `*Related:*` footers; the source does not.**
`GET /@{repo}/{slug}` (and `.md`) appends one or more `\n---\n\n*Related: @x · @y · …*` blocks at the end of the rendered body. These are computed from related-link suggestions at render time — they are **not** in the stored source. If you re-publish the fetch output verbatim, those footers get persisted into source, and the *next* fetch appends *another* set on top of them. After three or four edit cycles you'll have a pile of stacked, near-duplicate "Related" blocks. Strip everything from the first `^---$` line whose next non-blank line starts with `*Related:` to EOF before re-publishing.
**2. The async scrub fills *missing* generated fields by default (changed 2026-05-31).**
After a successful publish, an async LLM pass re-derives the five generated fields (`short`, `summary`, `tags`, `triggers`, `trigger_prompt`) from the body. The default mode is `missing` — fills only fields the author left blank; author-supplied values are preserved verbatim. Override per-call:
- `?scrub=full` — overwrite all five (pre-2026-05-29 behavior)
- `?scrub=missing` — explicit form of the default
- `?scrub=none` — skip the LLM pass entirely (alias: legacy `?regenerate=false`)
- `?derive=true` — run the LLM **synchronously** and return the full LLM-derived field set in a `derived:` block on the response. Apply policy still respects `?scrub=`, so `?derive=true&scrub=none` is a preview-only call. Use this when you want to see what scrub thought before deciding whether to PUT a suggested value.
**3. On `POST /entry/publish`, `path` is honoured ONLY in frontmatter — and a wrong path still returns 200.**
Measured 2026-08-15, three-way controlled test on one file:
| where `path` is supplied | resulting entry path |
|---|---|
| `path` field in the POST body | `""` (root) — ignored |
| `?path=<value>` on the query string | `""` (root) — ignored |
| `path:` line in the content's YAML frontmatter | the requested path — works |
Why a careful reader gets this wrong: the resolution ladder *"explicit `path` option > frontmatter `path:` > filePath-derived > root"* is stated for **two different endpoints**. For `POST /entry` it is accurate — that endpoint does take `path` explicitly. For `POST /entry/publish` the documented body is `{repoId, content}`, with no `path` field, so the ladder's first rung is one a publish caller cannot reach. For publish, the document's own lines — frontmatter `path:`, or the path inside a `ref:` line (since 2026-09-26, see 4) — are the only option.
The failure mode is the dangerous part: a misplaced publish returns **HTTP 200 with a real entry id**, indistinguishable from a correct one. The entry is simply at root, where it is invisible to path-qualified fetches and absent from `/ls/@{repo}/{path}` — so any pipeline using a path listing as its ground truth will treat the content as never published and re-create it indefinitely.
**Callers should compare the `path` in the response to the path they intended and treat a mismatch as a failure.** A 200-with-an-id looks identical whether or not the entry landed where you asked, which is what makes it insufficient as a receipt.
Related, same family: the publish response echoes the submitted `content` back. Any client-side check that text-scans the whole response — for `"rate limit"`, an error string, a marker word — can match text the client itself just submitted. Parse the JSON and test fields such as `statusCode`; never text-scan a payload that contains your own content.
Fields outside the generated five — `ref`, `type`, `category`, `last_reviewed`, `complements`, `audience`, `aliases`, `parentRef` — always persist verbatim and are never touched by scrub.
**Every write verb echoes the whole entity — redirect it or pay for it twice.** `POST /entry/publish`, `PUT /entry/{id}`, `PATCH /entry/{id}`, `POST /impulse`, `PATCH /impulse/{id}` and `POST /impulse/{id}/log` all return the full object on success: entry `content` in its entirety, or an impulse's complete `content` plus every historical `log` row *and* the same rows again under `digest`. You already hold what you just wrote, so the response is pure duplication.
Measured 2026-09-15, one session: a single `POST /impulse/{id}/log` on a well-logged impulse returned ~15k tokens, and a `PATCH /entry/{id}` on an 8.5 KB protocol returned ~10k. Neither carried one fact the caller did not already have. Two calls, ~25k tokens, and because cost is `turns x carried window` every later turn re-billed them.
So: `> /dev/null` on the write, then confirm with a cheap targeted read.
```bash
curly protocol "/impulse/{id}/log" -X POST -d @body.json > /dev/null 2>&1
curly protocol "/impulse/{id}?format=json" 2>/dev/null | python3 -c 'import sys,json;print(json.load(sys.stdin)["status"])'
```
The confirmation matters — a suppressed write is a silent write, and `exit 0` from `curly` is not proof the server accepted it. Read back the one field that should have changed, never the whole object.
This bites hardest on impulses that have accumulated log history, which is exactly the impulses worth logging to: the better the record, the more expensive each append. An impulse with a long `log` array is a write target to be especially careful with, not a reason to log less.
**4. Your address lines decide where the publish lands (#217, 2026-09-26).**
The address is `(repo, path, slug)`. `path:` and `slug:` win; when either is absent, the `ref:` line (frontmatter, or the `<!-- ref: … -->` comment a fetch emits) supplies it; otherwise the path is root and the slug comes from the H1. A publish never fails over its address, but the response `warnings` array says when the document and the result disagree: a `ref:` contradicted by `path:`/`slug:`, a `ref:` naming another repo, or **a new entry created while the same slug exists at another path** — which is what dropping the `path:` line does. That last one is a fork, not an update: the original is untouched. Republish with its path to update it, and delete the stray.
**5. The review is queued, never awaited (#216, 2026-09-26).**
`POST /entry`, `/entry/publish` and `/entry/appendix` return `review: {status: "pending" | "skipped"}` instead of an inline grade. The LLM review runs later, oldest first, and lands on the entry as `reviewStatus` (`pending` → `running` → `done` | `failed`, or `skipped`) and `reviewResult` (`{grade, issues, summary}`, or `{error}`). Read it back with `GET /entry/{id}?format=json` when you want it. Skip it with `?review=false`: bulk uploads should, since a corpus of thousands is thousands of LLM calls. An account can default it off, and a global switch can stop it entirely. Raw entries are never reviewed. An unchanged re-publish keeps the version's existing review.
## Impulses
Actionable rows — tasks, scheduled triggers, lifecycle goals. Native columns: `type`, `assignee`, `status`, `state`, `digest`, plus `metadata` (kind-specific config). See `@protocol/api-reference` for the data model.
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | /impulse?repoId=&type=&assignee=&status=&category= | - | List impulses with native filters; also `?metadata.<key>=`, `?origin.platform=` / `.channel=` / `.thread_id=` (an unknown `origin.*` key is a 400), and the dimension filters `?project=` / `?tag=` / `?anyTag=` / `?ancestor=` (see **Project and tags** below; same on `/impulse/mine` and bulk). `state=` was retired in V78 and is a 400 |
| GET | /impulse/{id} | - | Read one impulse (resolves ephemeral `templateId@iso` refs) |
| POST | /impulse/{id}/wait | Yes | Register `{waiter, note?}` as blocked on this impulse (idempotent per waiter); `DELETE /impulse/{id}/wait?waiter=` withdraws; `GET /impulse/{id}/waiters` lists them |
| GET | /impulse/waiting?waiter= | Yes | What a waiter is still blocked on, oldest first, each with `openedAt`, `ageSec`, `stale` (past `?older_than=` seconds, default 86400). `?since=<iso>` returns waits satisfied since then instead. `?stale=true` (waiter optional) lists every unanswered ask you can see. Scoped to repos you own or belong to |
| POST | /impulse | Yes | Create one |
| POST | /impulse/batch | Yes | Create many in one call |
| PUT | /impulse/{id} | Yes | Replace top-level fields |
| PATCH | /impulse/{id} | Yes | Merge-patch (RFC 7396, one level into metadata) |
| DELETE | /impulse/{id} | Yes | Delete (templates with instances refused) |
| POST | /impulse/{id}/complete | Yes | Set `status: done`, `completed: 100` |
| POST | /impulse/{id}/cancel | Yes | Set `status: canceled` (or exdate for ephemeral refs) |
| POST | /impulse/{id}/reopen | Yes | Set `status: open` |
| POST | /impulse/{id}/materialize | Yes | Create an instance from a template |
| POST | /impulse/{id}/append | Yes | Append a block to `content` (same body as entry append, no `if_version`) |
| POST | /impulse/{id}/digest | Yes | Append a structured audit entry to `digest` (see body below) |
| PATCH | /impulse/{id}/state | Yes | **Retired: 410 Gone.** The lifecycle is one field; PATCH `status` or `category` on `/impulse/{id}` |
**Origin — where the work began (#189).** `POST /impulse` (or a PATCH on a row without one) accepts `origin: {platform, channel, thread_id?, message_id?, url?, actor?}`. `platform` must be one of `slack | peer | email | web | cli | human`, and `channel` is required. For `peer`, `channel` is the asking runner and `thread_id` its dispatch or claim id. **It is immutable once set:** a different origin, or `null` over an existing one, is a **409 `IMPULSE_ORIGIN_IMMUTABLE`** and refuses the whole write. The same origin again is a no-op, so retries are safe. It is echoed on reads, on completion, on claim-complete and in `/impulse/next` candidates, so whoever finishes the work can answer into the thread it came from.
**Project and tags — the dimensions to organize work by (#354).** Every impulse reads back `project` (a lowercase slug or `null`) and `tags` (an array of lowercase slugs, `[]` when untagged). Both are typed columns, so file them as top-level fields, never in `metadata`. Writes normalize: trim, lowercase, spaces become `-`, tags are deduped; a slug matches `^[a-z0-9][a-z0-9._-]*$`, at most 20 tags of 50 chars each, project at most 100 chars. `POST`, `PUT` and `PATCH` take `project` (send `null` to clear; `none` is reserved and refused) and `tags` (replaces the whole set). `PATCH` also takes `addTags` / `removeTags`, applied in one UPDATE so concurrent writers do not clobber each other; sending `tags` with either is a 400. Filters, which AND with each other and with `origin.thread_id`: `?project=a,b` (any of; `none` = no project) · `?tag=x&tag=y` or `?tag=x,y` (has ALL) · `?anyTag=x,y` (has ANY) · `?ancestor=<ipls_id>` (every descendant, not just children) · `?parentId=` on `/impulse/mine`. For one release a create or PATCH that sends `metadata.project` / `metadata.client` / `metadata.tags` without the typed field is mirrored into the column and answers with an authoring warning; after that the metadata key is just metadata.
## Runners — the roster
`GET /runner` lists your account's runners: id, `type`, `lanes`, `pools`, `capacity`, `lastSeen` and `effectiveState` (`idle|busy|asleep|halted|unknown`). Filters: `?lane=`, `?pool=`, `?state=`, `?type=`. `GET /runner/:id` returns one runner. Another account's id answers 404.
**Register** with `PUT /runner/:id`, body `{type, lanes?, pools?, capacity?, state?, capabilities?, note?, staleAfterSec?}`. It is a full PUT, so a field you leave out goes back to its default. An id another account holds is a **409**. A token pinned to a repo or team, or a learning token, gets a **403**, because a runner serves the whole account. You don't have to register: an ask on `GET /impulse/next?runner=<id>` adds you to the roster too. Field meanings and the ask loop are in `@protocol/dispatch-protocol` §1.
**From an MCP client** (claude.ai connector, Claude Duet), `protocol_call` reaches exactly three runner routes: `GET /runner`, `GET /runner/:id` and `PUT /runner/:id`. The PUT needs the `write:impulses` scope. Any other method or deeper path is refused before it reaches REST.
```
protocol_call {"method":"GET","path":"/runner"}
protocol_call {"method":"PUT","path":"/runner/duet","body":{"type":"ephemeral","lanes":["<you>+duet"]}}
```
## File appendices — list, fetch, reference
A file appendix is a file stored on an entry (a script, a config, an image), never loaded into context: it is downloaded when it runs. **Read it by ref, at `<entry ref>_/<filename>`; write it by entry id.** The two are different routes on purpose (read by ref, write by id), and the id-addressed `GET /entry/{id}/file/{filename}` does not exist: it is a 404, not "this file can't be read back".
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | /@{repo}/[{path}/]{slug}_/{filename} | Per repo | The file's bytes. `Content-Type` is the stored type; `X-Content-Hash` is the sha256 of the whole stored file. A binary is streamed through the API (see *How binaries are served*). Missing file: **404** `File "x" not found`. A child's file: `@repo/parent_/child_/tool.mjs` |
| GET | /entry/{id}/files | Per repo | List: `{slug, files: [{filename, hash, size, contentType, url}]}`. `url` is the file's `_/` API path, never a storage URL |
| POST | /entry/{id}/file | Write | Create or replace by `filename`. Body below. **201** with the stored row |
| PUT | /entry/{id}/file/{filename} | Write | Same, filename in the URL; body without `filename`. **200** |
| DELETE | /entry/{id}/file/{filename} | Write | **204** |
**Body.** `{filename, content}` for text. Binary goes as `base64`: the server uploads it to Protocol's object storage and serves it from there. Optional: `contentType` (otherwise inferred from the extension: `.sh` → `text/x-shellscript`, `.mjs` → `application/octet-stream`) and `size`. `filename` is required on POST (**400** without it). Every file write bumps the entry's `version`. A `fileUrl` is accepted only for a file hosted elsewhere; a `fileUrl` pointing into Protocol's own storage is refused (**400** `fileUrl may not point into Protocol storage; send the bytes as base64`), because only the server may name its storage keys.
```bash
curly protocol "/entry/$ID/file" -X POST -d '{"filename":"tool.mjs","content":"…"}' # write
curly protocol "/entry/$ID/file" -X POST -d "{\"filename\":\"a.png\",\"base64\":\"$(base64 < a.png)\"}" # binary
curly protocol "/entry/$ID/files" # list
curly protocol "@integrations/loom_/loom.mjs" -o loom.mjs # fetch
```
**How binaries are served.**
There is no CDN and no public link. A binary sent as `base64` is stored as a **private** object; its storage URL answers 403 to everyone, and nothing the API returns contains it. The only way to the bytes is the `_/` route, which checks read access on the entry first and then streams the object through.
- **Same access as the entry.** Anyone who can read the entry gets the bytes. Anyone else → **403**, anonymous included, even if they hold an old storage URL.
- **Ranges work.** Send `Range: bytes=0-99` → **206** with `Content-Range: bytes 0-99/20497`; a range past the end → **416**. Large files stream without being buffered, so resuming a big download is fine.
- **Never cached publicly.** Binary responses carry `Cache-Control: private, no-store`. Fetch again rather than sharing a URL.
- **A file stored as an external `fileUrl`** (hosted somewhere else) answers **302** to that URL. Protocol does not proxy or guard it, so its privacy is whatever that host gives it.
- **Storage not configured → 503** `File storage is not configured`, on both read and upload. A server never falls back to a public host instead (from the deploy after 2026-11-16; earlier builds sent the upload to a public CDN).
- **Row present, object missing → 404** `File "x" not found`. The server logs it as `object missing from bucket`.
**Working with file appendices.**
- **Which files an entry has:** a whole fetch's identity block carries `files: [loom.mjs]` beside `appendixes:`, and `?trunc=N` keeps that block when N reaches it. `?peek=true` (deprecated) gives only the count (`files: 1`); `?max=` drops the line. `/entry/{id}/files` is the full list with hashes.
- **Verify the bytes with `hash` / `X-Content-Hash`, never `size`.** `size` counts characters, not bytes: a 19,438-byte script with non-ASCII text lists `size: 18736`, while its sha256 matches the header exactly.
- **A bounded read is bounded.** `?trunc=` / `?max=` on a text file cut it and say so in `X-Truncated: kept=3 total=342`; `X-Content-Hash` still names the whole file. An SVG or image is served whole, with `X-Budget-Declined`.
- **Access follows the entry.** A public repo's files read anonymously; a private one's answer 403 without access. Per source, a share link's `?key=` opens the entry's files too, on both the `_/` read and the list.
- **A deleted entry's files are gone from the API** (404), even though the stored object may still exist until it is swept.
- **Reference a file by its `_/` ref** in prose and code, e.g. `@integrations/loom_/loom.mjs`. A `/search` hit inside a file carries that ref in `file` (see *Search*). The ~100 KB guidance for entry bodies does not apply here: a file appendix never enters context (a 138 KB script round-tripped byte-identical, 2026-09-10).
Verified against api.protocol.supply 2026-11-10 (#206); binary serving re-verified 2026-11-16 (owner 206 with `Content-Range`, out-of-range 416, anonymous 403 on both the API route and the storage URL, list `url` is the API path). The 503 paths are verified from source, not live.
## Append — body shape
`POST /entry/{id}/append`, `POST /@{repo}/{slug}/append`, and `POST /impulse/{id}/append` take the same body. Only `text` is required.
```json
{
"text": "## 2026-04-29\n- did X\n",
"position": "end",
"section": null,
"ensure_heading": true,
"case_sensitive": false,
"separator": "\n\n",
"if_version": null
}
```
| Field | Default | Notes |
|---|---|---|
| `text` | required | Block to insert. Trailing newline optional; server normalizes. |
| `position` | `"end"` | `"end"` (body end) or `"start"` (after frontmatter). Ignored when `section` is set. |
| `section` | null | Heading anchor, e.g. `"## Daily Logs"`. New block lands at end of section. |
| `ensure_heading` | `true` | If `section` is missing: `true` creates it at end-of-body; `false` returns 404. |
| `case_sensitive` | `false` | Section matching is case- and whitespace-tolerant by default — `## Daily Logs` ≡ `## daily logs` ≡ `## daily logs `. Existing canonical spelling preserved. Set `true` for byte-exact. |
| `separator` | `"\n\n"` | Newlines between existing content and new text. `"\n"` for list continuation. |
| `if_version` | null | (entries only) Optimistic concurrency. 409 if latest != value. |
## Digest — body shape
`POST /impulse/{id}/digest` takes a structured audit entry (not free-form markdown). For free-form on an impulse, use `/impulse/{id}/append` instead.
```json
{
"action": "claim",
"agent": "my-agent",
"at": "2026-04-29T08:30:00Z",
"note": "starting draft"
}
```
`agent` defaults to the authed user; `at` defaults to the server clock. Action vocabulary: `claim`, `release`, `prep_done`, `nudge_sent`, `complete`, `skipped`, `note` (open list).
Each successful write creates a new version on entries; impulses overwrite (digest is the audit trail). See `@protocol/append` for the cookbook covering all three append surfaces.
## Auth
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| POST | /auth | - | Login (+ optional `apiTokenCreate:true` for durable key) |
| DELETE | /auth | JWT | Logout |
| POST | /auth/magic-link | - | Send magic link email |
| POST | /auth/magic-link/signup | - | Create account + send magic link |
## Repositories
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | /repo | - | List repositories |
| POST | /repo | Yes | Create repository |
| GET | /repo/{repoSlug} | - | Get repo details |
| PUT | /repo/{repoSlug} | Yes | Update repo |
| DELETE | /repo/{repoSlug} | Yes | Delete repo |
| GET | /repo/{repoSlug}/entries | - | List entries in repo |
| GET | /repo/{repoSlug}/top-fetched | - | Most-fetched entries in repo |
| POST | /repo/{repoSlug}/publish | Yes | Publish protocols (bulk). Body: `{files: [{path, content}]}` |
| GET | /repo/{repoSlug}/export | - | Export repo as markdown |
## Team Members
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| GET | /repo/{repoSlug}/members | Owner | List members |
| POST | /repo/{repoSlug}/members | Owner | Add member by email |
| DELETE | /repo/{repoSlug}/members/{memberId} | Owner | Remove member |
## Repo Access Requests
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| POST | /repo/access/request | Yes | Request access to a repo |
| GET | /repo/access/pending | Owner | List pending access requests on repos you own |
| GET | /repo/access/my-requests | Yes | List access requests you've submitted |
| POST | /repo/access/{id}/respond | Owner | Approve or deny a request |
| DELETE | /repo/access/{id} | Yes | Withdraw a request |
Roles: `admin` (read+write), `member` (read only).
## API Tokens
| Method | Path | Auth | Description |
|--------|------|------|-------------|
| POST | /token | Yes | Create durable API token |
| GET | /token | Yes | List your tokens |
| DELETE | /token/{id} | Yes | Revoke a token |
## Search Operators
`tag:testing` `repo:protocol` `type:reference` `"exact phrase"` `-exclude` `-tag:deprecated` `*wildcard*`
The same operators work in the markdown form (`/search.md`, `curly protocol "search?q=..."`) and in JSON (`/search?q=...&format=json`). Imported raw bodies are left out unless you ask for them with `type:raw`.
**JSON rows** come back as `{ content: [...], total, pageable, meta }`. `total` is the real match count, not the page size. Each row carries:
| Field | Meaning |
|-------|---------|
| `ref` | Address to fetch: `@repo/[path/]slug`, or `@repo/parent_/slug` for a child |
| `score` | Rank score; higher is better. Only meaningful within one response |
| `matchedIn` | Where the hit landed: `slug`, `title`, `alias`, `named` (the query contains this entry's multi-word slug or title as a phrase), `tag`, `trigger`, `slug_prefix`, `content`, `row`, `file`, `some_terms` (matched some of the words, added below the all-words matches when fewer than 10 match every word), or `substring`. Absent when the query has no text |
| `snippet` | Excerpt around the hit, with matches wrapped in `[hl]…[/hl]` |
| `id`, `title`, `repo`, `type`, `tags`, `short`, `updatedAt` | From the entry, so you can triage without fetching it. `id` is the stable handle for writes; `ref` is what you fetch |
| `summary` | The entry's generated two-sentence summary — enough to decide whether to load it, then fetch with `?max=`. Absent when the entry has none. Markdown results carry it as a `summary:` line |
| `file` | Present when the hit was in a file appendix: the file's `_/` ref |
| `row` | Present when the hit was in a registry row: `/entry/<id>/rows/<rowId>` |
| `matchedTerms` | Only on a relaxed search: how many of the query words this row matched. The envelope's `meta.relaxed` (`terms`, `strictBelow`) is present only when that fallback ran |
## The `?max=` header
A condensed fetch (`?max=`) opens with a header comment such as `<!-- ref:@protocol/loop condensed max=800c effective=800c returned=800c src=11259c … -->`. `max` is the budget after quantizing to the ladder. `effective` is the body measured in the unit you asked for. `returned` is always the body's size in **characters**, whatever unit you asked for. `src` is the size of the uncondensed source. Parse the fields by name: `returned=` was added after `effective=`, and older parsers that ignore it still work.
An entry that already fits the budget, or any budget at the ladder top (`20000t` / `80000c`), is served whole under `<!-- ref:… full max=… effective=… returned=…c condensed=no — fits the budget, served whole -->`. There, `effective` and `returned` measure the whole markdown served: the identity block, the body, a registry's rows, resolved includes and the Related footer. The response header `X-Protocol-Condensed: max=…; effective=…; returned=…c; condensed=no` carries the same numbers. On a JSON fetch, that header's `effective` measures the envelope's `content` (the body; a registry's rows are in the `rows` sidecar).
## Rate Limits
1,000 requests/hour per API token; 300/hour for anonymous callers, counted by client IP. A token is its own bucket, so several agents under one account do not throttle each other. Response headers on every request: `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (unix seconds). Over the ceiling: HTTP 429 with `Retry-After`. `/health` and `/billing/webhook` are exempt. The window is a fixed clock hour, and a refused request still counts against it.
## Bulk impulse metadata
Re-keying or cleaning `metadata` across many impulses is one request, not one per row (#207). Three pieces.
**Remove a key.** `PATCH /impulse/{id}` with `{"unsetMetadata": ["old_key"]}`. `{"old_key": null}` does NOT remove it: it stores a JSON null and the key stays, on purpose, because `metadata.revive: null` is a sentinel callers and the escalation code read. A key named in both `metadata` and `unsetMetadata` is a 400; removing a key the row never had is a 200 no-op; `PUT` refuses `unsetMetadata` (it replaces `metadata` wholesale, so send the object without the key).
**Read by key.** `GET /impulse?repoId=…&hasMetadata=old_key` (also `/impulse/mine` and the facet census) returns the rows that CARRY the key whatever its value, a stored null included; `hasMetadata=a,b` or a repeated param ANDs, at most 20 keys, and `X-Total-Count` is the filtered total. It is the same validator as bulk `filter.hasMetadata`, so the two select the same rows; pair it with `?metadata.<key>=value` for equality. A key no row carries answers an empty page and `X-Total-Count: 0`; a malformed value is a 400 naming `hasMetadata`, never a dropped filter.
**Write many rows.** `POST /impulse/bulk`, at most 500 rows per call, selected by exactly one of `ids` or `filter` (`filter.repoId` is required; a bulk write is never estate-wide):
```bash
# rename a key across every row that carries it, dry run first
curly protocol /impulse/bulk -X POST -d '{"filter":{"repoId":"@me/ops","hasMetadata":["agentclaw_id"]},"patch":{"metadata":{"ticker_id":"T"},"unsetMetadata":["agentclaw_id"]},"dryRun":true}'
```
- `filter.metadata` (`{"owner":"agentclaw"}`) matches exact text, the same as `?metadata.owner=agentclaw`; `filter.hasMetadata` (`["k"]`, up to 20) matches rows that carry the key whatever its value, a stored null included.
- The `filter` arm writes only on an explicit `"dryRun": false`; the `ids` arm writes unless `"dryRun": true`.
- The response is per row: `rows[]` with `eligible` and a `reason` for every refusal, and `applied` counted from the UPDATE's own RETURNING. A refused row never fails the batch.
**Read the totals before you trust a batch.** The response carries `matched` (capped at 500), `totalMatching` (not capped) and `truncated`. A filter that matches 1,232 rows answers `matched: 500, totalMatching: 1232, truncated: true`; a short batch looks exactly like a small population, so run it again until `truncated` is false (rows already changed drop out as `already matches`). A dry run also returns `sample`: the first 5 eligible rows with each touched key's `from` and `to` (`(absent)` and `(unset)` are the two non-values).
**Refuse rows that changed since you read them.** Impulses have no version column; `updatedAt` is the token. Every verdict row carries `updatedAt`; send `"expect": {"ipls_…": "<updatedAt>"}` and a named row whose `updatedAt` has moved comes back `eligible: false` with a `stale:` reason while the rest land. The check is inside the UPDATE, so a write that lands between the read and the write is refused too (`stale or deleted between the read and the write`).
Writing metadata one row at a time with `PUT` built from a read is the failure this replaces: a stale read silently reverts whatever changed in between.
---
*Related: `@content/youtube/dan-martell/it-s-actually-pretty-easy-to-get-ahead-of-99-of-people-with-ai` · `@content/youtube/dan-martell/i-tested-500-ai-tools-these-will-make-you-rich` · `@content/youtube/tiago-forte/build-a-business-that-runs-itself-5-stages-of-ai-integration` · `@content/youtube/steph-france/ai-agents-automation-spectrum` · `@integrations/notion`*
---
*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*
*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*