# Repository view protocol contract This document defines the verified protocol boundary supported by the network-backed `camlet repo view` command. It is intentionally narrower than Tangled's complete repository discovery surface. ## Evidence scope The contract was researched and observed on 2026-07-26 against: - Tangled core commit [`e8e27f99d6a62ba46d973f155f5d17ec49703765`](https://tangled.org/tangled.org/core/tree/e8e27f99d6a62ba46d973f155f5d17ec49703765); - the managed `plc.directory`, `knot1.tangled.sh`, and `tngl.sh` services; - AT Protocol specifications and lexicons current on the observation date; - the public Camlet repository DID `did:plc:rvyb4oxpswgjgdvvncihletw`. The sanitized fixtures under `test/contract/fixtures/repo_read/v1` preserve the managed success chain, the knot `404` distinction, selected record and index misses, and Bobbin coverage behavior. Synthetic decoder-mismatch and transport-boundary cases live in the unit tests. Live behavior proves only the observed deployment state, not future availability or a historical protocol guarantee. ## Authoritative read chain ```text repository DID -> resolve repository DID document -> discover knot from #atproto_pds -> knot sh.tangled.repo.describeRepo(repoDid) -> obtain current owner DID and record key -> resolve owner DID document -> discover owner PDS from #atproto_pds -> PDS com.atproto.repo.getRecord(owner, sh.tangled.repo, rkey) -> cross-check repository DID, AT URI, record type, and knot ``` This contract composes Tangled's [`repoverify`](https://tangled.org/tangled.org/core/blob/e8e27f99d6a62ba46d973f155f5d17ec49703765/repoverify/verify.go) path—repository DID to knot to current owner and record key—with the [`AppView ingest`](https://tangled.org/tangled.org/core/blob/e8e27f99d6a62ba46d973f155f5d17ec49703765/appview/ingester_repo.go) invariants that compare the event DID to the knot owner and the record's `repoDid` and `knot` to the repository identity. Camlet obtains that record directly from the owner's PDS. Bobbin is an aggregation and convenience observation source. It is not an authority in this chain and is not a dependency of `repo view`. ## Repository DID resolution The supported profile accepts only `did:plc` repository DIDs and resolves them through the fixed `https://plc.directory` origin: ```http GET https://plc.directory/ Accept: application/did+ld+json, application/json ``` The decoder requires: - `id` exactly equal to the requested DID; - a unique usable service whose ID is `#atproto_pds` or `#atproto_pds`; - service type exactly `AtprotoPersonalDataServer`; - an HTTPS origin-only `serviceEndpoint` using a public DNS hostname, with no user information, path, query, or fragment. Literal IP service endpoints are outside this supported profile. Other DID document fields are not required for this unauthenticated read. Unknown noncritical fields are ignored. Trust-critical duplicate keys are rejected. The relevant identity rules are defined by the AT Protocol [`DID` specification](https://atproto.com/specs/did) and the [`did:plc` resolution specification](https://web.plc.directory/spec/v0.1/did-plc). ## Knot ownership lookup Camlet asks the discovered knot for the current owner and record key: ```http GET /xrpc/sh.tangled.repo.describeRepo?repoDid= Accept: application/json ``` The successful response contains three required fields: ```json { "repoDid": "did:plc:...", "ownerDid": "did:plc:...", "rkey": "repository-record-key" } ``` `repoDid` must equal the requested repository DID. The lexicon permits any syntactically valid owner DID, but this contract accepts only `did:plc`; another valid DID method produces `identity.unsupported_did_method` before endpoint discovery. `rkey` must satisfy the AT Protocol record-key grammar and is case-sensitive. Unknown fields are tolerated. The wire schema is [`sh.tangled.repo.describeRepo`](https://tangled.org/tangled.org/core/blob/e8e27f99d6a62ba46d973f155f5d17ec49703765/lexicons/repo/describeRepo.json). ## Owner PDS lookup The owner DID is resolved through the same fixed PLC origin and service-selection rules. Camlet then reads the current public repository record without authentication: ```http GET /xrpc/com.atproto.repo.getRecord ?repo= &collection=sh.tangled.repo &rkey= Accept: application/json ``` The optional `cid` request parameter is omitted so the PDS returns the most recent record version it serves at request time. The response must be an object containing `uri` and `value`. Its `cid` is optional according to the [`com.atproto.repo.getRecord` lexicon](https://github.com/bluesky-social/atproto/blob/c1b62799f6ce768cb3c44583d0dcdb2f8e924a70/lexicons/com/atproto/repo/getRecord.json). When present, the CID must be a canonical, lowercase-base32 CIDv1 containing a valid multicodec and multihash shape. Other CID encodings are outside this supported profile because observed AT repository record CIDs use this representation. Camlet validates all of the following: 1. the returned AT URI has the owner DID, `sh.tangled.repo` collection, and knot-supplied record key; 2. `value.$type` is exactly `sh.tangled.repo`; 3. `value.repoDid` is present and equals the originally requested repository DID; 4. the record's `knot` hostname matches the repository-DID service hostname ASCII-case-insensitively, and any explicit port matches exactly; the record value must not contain a scheme, path, query, or fragment; 5. required repository-record fields satisfy the current [`sh.tangled.repo` lexicon](https://tangled.org/tangled.org/core/blob/e8e27f99d6a62ba46d973f155f5d17ec49703765/lexicons/repo/repo.json). `createdAt` belongs to the record. It is not the client observation time and does not prove freshness. ## Error classification Status alone is insufficient. Camlet must consider status, content type, and any valid XRPC error envelope. | Stage | Observation | Classification | | --- | --- | --- | | PLC | `404` non-XRPC body | identity not found | | Knot | `400 InvalidRequest` | invalid request or repository DID | | Knot | `404 RepoNotFound` JSON | repository not found on a supported endpoint | | Knot | generic or plain-text `404` | ambiguous: unsupported, legacy, misrouted, or intercepted | | PDS | `400 InvalidRequest` | invalid record request | | PDS | `400 RecordNotFound` | record not found | | Any XRPC | `429` | rate limited; preserve only safe retry metadata | | Any service | `500`, `502`, `503`, or `504` | service or upstream failure | | Any service | redirect | rejected; redirects are disabled | Unknown repository and an unavailable XRPC route are both HTTP `404` in currently observed knots. A structured `RepoNotFound` envelope proves the former. Any other `404` is ambiguous: the endpoint may be unsupported, legacy, misrouted, or intercepted. Camlet must fail closed without copying the current Tangled helper behavior that collapses every `404` into an unsupported-endpoint result. ## Compatibility boundary | Deployment | Handling | | --- | --- | | Knot 1.14+ or a backport with a valid `describeRepo` response | supported | | Knot 1.13 with repository DIDs but no `describeRepo` | typed unsupported/incomplete error | | Knot 1.9-1.12 without repository DIDs | unsupported | | Legacy knot 1.8 or earlier | unsupported | | `did:plc` using an alternate PLC directory | unsupported by this contract | | `did:web` repository or owner identity | unsupported by this contract | | Private/local endpoints or custom certificate authorities | unsupported by this contract | | Literal IPv4 or IPv6 service endpoints | unsupported by this contract | Feature detection is authoritative: a valid `describeRepo` response is supported even if it comes from a backport. Version strings and capability lists are diagnostic only. The version boundaries follow Tangled's [`knot migration guide`](https://docs.tangled.org/migrating-knots-and-spindles). ## Network security boundary All requests are unauthenticated and credential-free, but DID documents contain network-controlled endpoints. The HTTP adapter therefore must: - allow HTTPS only and disable redirects, proxies, cookies, credentials, response retries, and ambient netrc use; another already validated DNS address may be attempted only when no response was received; - apply one operation-wide deadline, with separately bounded connection time; - cap DID and `describeRepo` responses at 64 KiB and `getRecord` at 1 MiB; - request identity encoding and reject unexpected content encodings; - bound response headers and sanitized diagnostic excerpts; - resolve and validate the actual selected peer address for every connection; - reject loopback, private, link-local, multicast, unspecified, reserved, documentation, benchmark, CGNAT, and other IANA special-purpose ranges, including IPv4-mapped IPv6 forms; - preserve the original hostname for TLS verification and HTTP authority after address validation; - parse content types as media types, accepting `application/json` and `application/did+ld+json` with compatible parameters such as `charset=utf-8`, and reject duplicate trust-critical JSON keys; - keep raw response bodies, query strings, IP addresses, and endpoint URLs out of user-facing errors. Any mismatch between repository DID, knot response, owner PDS record, AT URI, or knot origin is a consistency error. `repo view` does not return partially trusted repository metadata. ## Aggregation boundary Bobbin coverage metadata is not proof of per-owner or per-repository completeness. A Bobbin miss must not be reported as authoritative absence, and Bobbin-backed commands must expose aggregation coverage. The dated observation supporting this rule and the remaining research questions are recorded in [`protocol-notes.md`](../protocol-notes.md).