feat(client): discovery via a global index (special @index account)

Add a generic discovery-index surface: submitToIndex(ref) deposits a reference
into the index document's inbox; readIndex() returns the materialized entries. A
reserved special account (@index) owns the index document; deposits flow through
the emulated inbox and are materialized by the emulated curator (the dedup/
moderation point). This replaces cross-account fan-out as the discovery path and
is more faithful to the target (a single owned index fed via its inbox). Generic
(the consumer supplies the reference to index). 79 tests pass; tsc rc=0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sylvain Duchesne
2026-07-04 09:33:42 +02:00
parent 7db5eef33f
commit 9951cd5223
5 changed files with 461 additions and 8 deletions
+18 -8
View File
@@ -60,16 +60,26 @@ bound to the developer-user — **not implemented, uncertain**, to explore later
This is why a global-index curator is a **deferred separate package** in this lib
(see the top-level README).
## Polyfill reality (fan-out) vs target (global index)
## Polyfill reality — the fan-out drift is now RESOLVED (special-account index)
What ships in the shared-wallet polyfill today is the **cross-account fan-out over
The shared-wallet polyfill originally shipped a **cross-account fan-out over
every account's public documents** (`store-registry.ts` `listEntityDocs('public')`
/ `resolveReadGraphs`) — one account sees another's public entity **without a
connection**. This ADR classified per-account fan-out as a **drift** to be
replaced by the single global index; the target (inbox-fed global index) remains
valid but the fan-out is the mechanism the shared-wallet staging actually runs on
until the global-index owner is decided. Recorded here as mechanism history — the
resolution belongs to [`../migration-guide.md`](../migration-guide.md).
/ `resolveReadGraphs`) — one account saw another's public entity **without a
connection**. This ADR classified that per-account fan-out as a **drift** to be
replaced by the single global index.
**That drift is now resolved in the polyfill.** The inbox-fed global index of
this ADR is implemented on top of a **RESERVED SPECIAL ACCOUNT** in the shim
(`discovery.ts`, `INDEX_ACCOUNT = "@index"`) that owns the index document while
the target owner stays undecided: `submitToIndex(ref)` deposits into the index
document's inbox; `readIndex()` materializes (dedup) the entries. The app-facing
discovery path is now **read the index**, exactly as this ADR prescribes — NOT
the fan-out. The cross-account fan-out survives only as an **internal lib
fallback** (it still powers per-scope listing like `resolveReadGraphs`), never
the discovery route. The special account is the provisional owner; at migration
it disappears and ownership moves to the decided global-index owner (see
[`../migration-guide.md`](../migration-guide.md)) with the consumer surface
(`submitToIndex` / `readIndex`) unchanged.
## Alternatives rejected (mechanism)