Skip to content

refactor(kernel-utils,sheaves): extract positional guard algebra - #1048

Draft
ci-belphegor wants to merge 1 commit into
grypez/narrowing-1-docsfrom
grypez/narrowing-2-guard-algebra
Draft

refactor(kernel-utils,sheaves): extract positional guard algebra#1048
ci-belphegor wants to merge 1 commit into
grypez/narrowing-1-docsfrom
grypez/narrowing-2-guard-algebra

Conversation

@ci-belphegor

Copy link
Copy Markdown

Explanation

Moves the positional guard-algebra helpers out of @metamask/sheaves and into @metamask/kernel-utils, so the narrowing implementation later in this stack can share them. sheaves already depends on kernel-utils, so this moves code with the existing dependency edge and adds no new one.

Moved: MethodGuardPayload, getInterfaceMethodGuards, getMethodPayload, buildMethodGuard, asyncifyMethodGuards, and getGuardAt — the last promoted from a closure inside collectSheafGuard to a named export.

collectSheafGuard itself stays in sheaves and remains exported. It implements the positional OR direction, which is the exact dual of the AND direction narrowing needs.

Notes for reviewers

This is not a literal move, in one respect. Every case in sheaves/src/guard.test.ts lives inside describe('collectSheafGuard') and drives the collector end to end, with the moved functions appearing only as assertion plumbing — they were never tested directly. Since collectSheafGuard stays in sheaves, all of those cases stayed with it and only their import line changed. kernel-utils/src/guard-algebra.test.ts is therefore new direct unit tests rather than relocated ones. The alternative was to build the narrowing algebra on functions that had only ever been exercised indirectly.

sheaves/src/sheafify.ts also needed its import repointed, since it uses asyncifyMethodGuards. The alternative was leaving a re-export shim behind, which would have defeated the extraction.

No behavior change. sheaves' export list is unchanged.

Stack

PR 2 of 12. Base: #1047.

Move the shared positional traversal over @endo/patterns method guards out
of sheaves and into kernel-utils, where a second consumer can reach it.
collectSheafGuard's local getGuardAt closure becomes a named export;
everything else moves verbatim. sheaves keeps collectSheafGuard and its
module-local unionGuard, and imports the rest across the dependency edge
it already had.

No behavior change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ci-belphegor
ci-belphegor force-pushed the grypez/narrowing-2-guard-algebra branch from 5542cdb to fbb54ef Compare September 11, 2026 11:42
@ci-belphegor
ci-belphegor added this pull request to stack #1060 September 11, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant