refactor(kernel-utils,sheaves): extract positional guard algebra - #1048
Draft
ci-belphegor wants to merge 1 commit into
Draft
refactor(kernel-utils,sheaves): extract positional guard algebra#1048ci-belphegor wants to merge 1 commit into
ci-belphegor wants to merge 1 commit into
Conversation
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
force-pushed
the
grypez/narrowing-2-guard-algebra
branch
from
September 11, 2026 11:42
5542cdb to
fbb54ef
Compare
ci-belphegor
added this pull request to stack #1060
September 11, 2026 11:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Moves the positional guard-algebra helpers out of
@metamask/sheavesand into@metamask/kernel-utils, so the narrowing implementation later in this stack can share them.sheavesalready depends onkernel-utils, so this moves code with the existing dependency edge and adds no new one.Moved:
MethodGuardPayload,getInterfaceMethodGuards,getMethodPayload,buildMethodGuard,asyncifyMethodGuards, andgetGuardAt— the last promoted from a closure insidecollectSheafGuardto a named export.collectSheafGuarditself stays insheavesand 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.tslives insidedescribe('collectSheafGuard')and drives the collector end to end, with the moved functions appearing only as assertion plumbing — they were never tested directly. SincecollectSheafGuardstays insheaves, all of those cases stayed with it and only their import line changed.kernel-utils/src/guard-algebra.test.tsis 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.tsalso needed its import repointed, since it usesasyncifyMethodGuards. 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.