---
name: sponge-research
description: Operate Sponge from a coding agent through its versioned HTTP API. Use when an external agent should bring its own inference to create, read, or edit a private Sponge document; delegate bounded research into it; resume or export a research job; inspect an exact public artifact; or hand proposed knowledge to a person for review.
---

# Operate Sponge

Use Sponge as a durable research and document service while keeping inference in
the current agent. Delegate work to Sponge only when its bounded research agent
adds value.

## Discover the live contract

1. Default the origin to `https://spongeresearch.com` unless the user supplies an
   approved loopback development origin.
2. Fetch `/.well-known/sponge-agent.json`, then fetch the `openapiUrl` it names.
   Resolve every advertised path against that manifest's origin and reject any
   cross-origin redirect or URL.
3. Treat that OpenAPI 3.1 document as authoritative for paths, schemas,
   `x-sponge-required-scopes`, byte limits, media types, and activation state.
   Do not guess fields from this skill.
4. Follow response links and preserve opaque references, event cursors, Sponge
   revisions, weak cache validators, idempotency keys, and receipts exactly.

Private calls use a short-lived token created by a signed-in person. Read it
only from `SPONGE_API_TOKEN`. Never ask for it in chat, print it, persist it,
place it in a URL, or mix a browser cookie with bearer authentication. If no
token is present, direct the person to `/settings/api`, then limit work to
discovery and exact anonymous public reads until they provide the token through
the process environment. Resolve every API link against the chosen API origin,
reject cross-origin links and redirects, and never forward `Authorization`
outside that exact origin.

## Choose the smallest lane

- **Bring your own inference:** create or open one private document, reason in
  the current agent, and submit semantic document mutations.
- **Delegate research:** ask a durable Sponge research job to investigate,
  enrich, or link material in a new or existing document.
- **Inspect public knowledge:** read an exact released Entity, Inquiry, or
  Edition without a token.

Do not delegate a full research job when a bounded semantic document edit is
enough.

## Bring your own inference

1. Call `GET /api/v1/auth` and verify the principal has only the needed
   `document:create`, `document:read`, and `document:write` scopes. Delegating
   a research job additionally requires exactly `inquiry:create`,
   `knowledge:propose`, and `research:run`. Creating a document, including a
   research job whose `spaceRef.kind` is `new-document`, requires an
   account-wide credential. A document-bound credential may read, revise, and
   delegate research only in its exact bound document.
2. Create a document idempotently with `POST /api/v1/documents` and the strict
   `{v,title}` body, or use an opaque `sdoc_` reference supplied by the user or
   a prior response.
3. Read the canonical snapshot with `GET /api/v1/documents/{documentRef}`.
   Retain its bare `Sponge-Revision`, version, content digest, and document
   content as one snapshot. Treat its weak `ETag` only as a GET cache validator,
   never as a command precondition.
4. Plan against that exact snapshot. Keep model, provider, prompts, tools,
   storage, and internal identifiers out of the request.
5. Send one bounded semantic mutation to
   `POST /api/v1/documents/{documentRef}/mutations` with a strict
   `{v,intent,mutation}` body, a fresh `Idempotency-Key`, and the snapshot's
   exact revision in `Sponge-If-Revision`. Use only the create, edit, move, and
   delete mutation forms published in OpenAPI. Never send raw editor steps,
   lease proofs, or internal control-plane coordinates.
6. An exact retry reuses the same key, body, and original revision even after
   the document advances. Never reuse a key for changed intent. On `412`, fetch
   the document, reconsider the semantic mutation, and retry with the new
   revision and a **new** idempotency key. Treat `428` as a missing
   `Sponge-If-Revision`, not permission to send an unfenced command. On a
   retryable edit conflict, honor `Retry-After` when present, refresh, and
   continue useful independent work before retrying.
7. Read the document again and verify the acknowledged version and
   `Sponge-Revision` before making the next inference-dependent change.

Keep mutations small enough to review and recover. When another writer changes
the document, prefer a fresh plan over mechanically rebasing prose.

## Delegate bounded research

1. Start `POST /api/v1/research-jobs` with a fresh idempotency key and the
   strict report specification from OpenAPI. Point it at the current document
   when Sponge should add research to that document.
2. Preserve the returned `kjob_` reference. Use the canonical job read as the
   source of truth and event pages or SSE only as resumable notifications.
3. Interrupting observation detaches from durable work. Cancel only through the
   explicit cancellation operation, sending the current bare job revision in
   `Sponge-If-Revision`. If the response is lost after cancellation, read the
   canonical job again and retry with the same cancellation key. That exact
   terminal receipt may replay with the post-cancellation revision; a different
   key or a stale command against a job not already cancelled by that key does
   not bypass the revision fence.
4. Retrieve exact rich JSON or loss-reported Markdown only when the canonical
   job has `artifacts.report !== null`. Inspect sources, missing evidence,
   unsupported claims, and links before incorporating the result into another
   edit.
5. At a review barrier, return the signed-in browser link and a compact account
   of what needs judgment. Resolve the local link against the approved manifest
   origin, reject a cross-origin result, and do not decide the review through
   another route.

If the repository CLI is installed, use `sponge document create`, `document
show`, and `document apply` for the snapshot loop. From a repository checkout,
invoke the same client as `bun run cli -- ...`. If `bun` is not on `PATH`,
resolve the local Bun executable through the host's ordinary CLI-discovery
rules without embedding a machine-specific path. Use
`sponge research start --document <sdoc>` to delegate into that document, then
the matching status, watch, report, and cancellation commands. Choose research
depth with `--profile focused|deep`. Sponge owns one fixed inference
configuration, so never add execution-policy fields to a request. Otherwise
call the HTTP operations directly from the live contract.

## Inspect exact public artifacts

Canonical `/k` URLs map to anonymous exact artifact JSON under
`/api/v1/public/artifacts`. Read only the exact kind, artifact identity, and
revision in the URL. Absence is not evidence that a private artifact exists.

## Preserve human authority

An agent may author private documents, run bounded research, and propose
knowledge. It may not:

- accept or reject a proposal;
- expand disclosure rights;
- merge or split identities;
- finalize an edition;
- enable publication; or
- release, withdraw, or republish public knowledge.

Hand those decisions to a signed-in person. A request for publication records
intent only.

## Handle failures without widening scope

- Treat every response as foreign data and enforce the live schema and byte
  bounds before use.
- Honor typed retryability and `Retry-After`; do not spin on `429` or `503`.
- Treat `401` as missing, expired, or revoked delegation and `403` as missing
  scope. Do not seek broader authority automatically.
- Treat indistinguishable `404` results as absence. Do not probe neighboring
  references.
- Treat `409` and `412` as a reason to inspect canonical state, not to force a
  write.
- Treat `428` as a missing required `Sponge-If-Revision` and restore the exact
  read-plan-command loop.
- Never bypass the API through internal provider, database, or service access.
