Skip to content

Commit 4f47c89

Browse files
grypezclaude
andcommitted
docs(kernel-utils): documentation pass for sheaf module
- LIFT.md: fix exhaustion description to match actual error shape - README.md: remove stale "registry" and "tracks" claims post-revocation-removal - types.ts: remove "revocable" from Sheaf method docs; clarify when to use global section variants vs explicit-guard variants - USAGE.md: use makeSection (public API) in single-provider example; clarify proxyLift vs yield* for lift composition Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 04e180f commit 4f47c89

4 files changed

Lines changed: 28 additions & 15 deletions

File tree

packages/kernel-utils/src/sheaf/LIFT.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ The sheaf drives it with the following protocol:
3333
of every error thrown so far (cumulative, not just the last). The coroutine
3434
receives this as the resolved value of its `yield` expression.
3535
6. **Exhausted** — if the generator returns without yielding, the sheaf
36-
rethrows the last error.
36+
throws `new Error('No viable section for <method>', { cause: errors })`
37+
where `errors` is the full accumulated list of every failure so far.
3738

3839
Most lifts express a fixed priority order and can ignore the error input:
3940

packages/kernel-utils/src/sheaf/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Runtime capability routing adapted from sheaf theory in algebraic topology.
44

55
`sheafify({ name, sections })` produces a **sheaf** — an authority manager
6-
over a presheaf of capabilities. The sheaf grants dispatch sections via
7-
`getSection` and tracks all delegated authority.
6+
over a presheaf of capabilities. The sheaf produces dispatch sections via
7+
`getSection`, each of which routes invocations through the presheaf.
88

99
See [USAGE.md](./USAGE.md) for annotated examples and [LIFT.md](./LIFT.md) for
1010
the lift coroutine protocol and semantic equivalence assumption.
@@ -52,7 +52,8 @@ context.
5252
> identical metadata and collapsed to one representative.
5353
5454
**Sheaf** — The authority manager returned by `sheafify`. Holds the presheaf
55-
data (captured at construction time) and a registry of all granted sections.
55+
data (sections frozen at construction time) and exposes factory methods that
56+
produce dispatch exos on demand.
5657

5758
```
5859
const sheaf = sheafify({ name: 'Wallet', sections });

packages/kernel-utils/src/sheaf/USAGE.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ as a placeholder:
88

99
```ts
1010
import { M } from '@endo/patterns';
11-
import { makeDefaultExo } from '<internal>';
12-
import { sheafify, noopLift } from '@metamask/kernel-utils';
11+
import { sheafify, makeSection, noopLift } from '@metamask/kernel-utils';
1312

1413
const priceGuard = M.interface('PriceService', {
1514
getPrice: M.callWhen(M.await(M.string())).returns(M.await(M.number())),
1615
});
1716

18-
const priceExo = makeDefaultExo('PriceService', priceGuard, {
17+
const priceExo = makeSection('PriceService', priceGuard, {
1918
async getPrice(token) {
2019
return fetchPrice(token);
2120
},
@@ -161,5 +160,8 @@ import {
161160
before passing to `inner`
162161
- **`fallthrough(liftA, liftB)`** — try all candidates from `liftA` first;
163162
if all fail, try `liftB`
164-
- **`proxyLift(inner)`** — forward yielded candidates up and error arrays down;
165-
useful when wrapping a lift in middleware
163+
- **`proxyLift(gen)`** — forward yielded candidates up and error arrays down
164+
to an already-started generator; useful when you need to add logic between
165+
yields (logging, counting, conditional abort). For simple sequential
166+
composition (`fallthrough`, `withFilter`) you do not need `proxyLift`
167+
`yield*` forwards `.next(value)` to the delegated iterator automatically.

packages/kernel-utils/src/sheaf/types.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ export type Lift<MetaData extends Record<string, unknown>> = (
8888
/**
8989
* A sheaf: an authority manager over a presheaf.
9090
*
91-
* Produces revocable dispatch sections via `getSection` and tracks all
92-
* granted authority for auditing and revocation.
91+
* Produces dispatch sections via `getSection`, each routing invocations
92+
* through the presheaf sections supplied at construction time.
9393
*/
9494
export type Sheaf<MetaData extends Record<string, unknown>> = {
9595
/**
96-
* Produce a revocable dispatch exo over the given guard.
96+
* Produce a dispatch exo over the given guard.
9797
*
9898
* Returns `object` rather than a typed exo because the guard is passed
9999
* dynamically at call time — TypeScript cannot propagate the method
@@ -102,7 +102,7 @@ export type Sheaf<MetaData extends Record<string, unknown>> = {
102102
*/
103103
getSection: (opts: { guard: InterfaceGuard; lift: Lift<MetaData> }) => object;
104104
/**
105-
* Produce a revocable discoverable dispatch exo over the given guard.
105+
* Produce a discoverable dispatch exo over the given guard.
106106
*
107107
* Returns `object` for the same reason as `getSection`.
108108
*/
@@ -112,13 +112,22 @@ export type Sheaf<MetaData extends Record<string, unknown>> = {
112112
schema: Record<string, MethodSchema>;
113113
}) => object;
114114
/**
115-
* Produce a revocable dispatch exo over the full union guard of all presheaf sections.
115+
* Produce a dispatch exo over the full union guard of all presheaf sections.
116+
*
117+
* Prefer `getSection` with an explicit guard when the guard is statically
118+
* known — it makes the capability's scope visible at the call site. Use the
119+
* global variant when sections are assembled dynamically at runtime and the
120+
* union guard is not known until after `sheafify` runs.
116121
*
117122
* @deprecated Provide an explicit guard via getSection instead.
118123
*/
119124
getGlobalSection: (opts: { lift: Lift<MetaData> }) => object;
120125
/**
121-
* Produce a revocable discoverable dispatch exo over the full union guard of all presheaf sections.
126+
* Produce a discoverable dispatch exo over the full union guard of all presheaf sections.
127+
*
128+
* Prefer `getDiscoverableSection` with an explicit guard when the guard is
129+
* statically known. Use the global variant when sections are assembled
130+
* dynamically and the union guard is not known until after `sheafify` runs.
122131
*
123132
* @deprecated Provide an explicit guard via getDiscoverableSection instead.
124133
*/

0 commit comments

Comments
 (0)