generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add CapTP infrastructure for kernel communication #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rekmarks
wants to merge
17
commits into
main
Choose a base branch
from
rekm/captp-infrastructure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,275
−554
Conversation
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
…tion
Implements userspace E() infrastructure using @endo/captp to enable
the background script to use E() naturally with kernel objects.
Key changes:
- Add CapTP setup on kernel side (kernel-browser-runtime):
- kernel-facade.ts: Creates kernel facade exo with makeDefaultExo
- kernel-captp.ts: Sets up CapTP endpoint with kernel facade as bootstrap
- message-router.ts: Routes messages between kernel RPC and CapTP
- Add CapTP setup on background side (omnium-gatherum):
- background-captp.ts: Sets up CapTP endpoint to connect to kernel
- types.ts: TypeScript types for the kernel facade
- Update message streams to use JsonRpcMessage for bidirectional support
- CapTP messages wrapped in JSON-RPC notifications: { method: 'captp', params: [msg] }
- Make E globally available in background via defineGlobals()
- Expose omnium.getKernel() for obtaining kernel remote presence
Usage:
const kernel = await omnium.getKernel();
const status = await E(kernel).getStatus();
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…cture Completes the migration from JSON-RPC to CapTP for background ↔ kernel communication and harmonizes the extension and omnium-gatherum packages. Remove the Kernel internal RPC infrastructure entirely: - Remove commandStream parameter from Kernel constructor and make() method - Remove #commandStream and #rpcService private fields - Remove #handleCommandMessage method and stream draining logic - Delete packages/ocap-kernel/src/rpc/kernel/ directory (contained only ping handler) - Update all Kernel.make() call sites across packages The Kernel no longer accepts or processes JSON-RPC commands directly. All external communication now flows through CapTP via the KernelFacade. Move background CapTP infrastructure from omnium-gatherum to kernel-browser-runtime: - Move background-captp.ts to packages/kernel-browser-runtime/src/ - Export from kernel-browser-runtime index: makeBackgroundCapTP, isCapTPNotification, getCapTPMessage, makeCapTPNotification, and related types - Delete packages/omnium-gatherum/src/captp/ directory - Delete packages/kernel-browser-runtime/src/kernel-worker/captp/message-router.ts (no longer needed since all communication uses CapTP) Both omnium-gatherum and extension now import CapTP utilities from kernel-browser-runtime. Update extension to use CapTP/E() instead of RpcClient: - Replace RpcClient with makeBackgroundCapTP in background.ts - Add getKernel() method to globalThis.kernel for E() usage - Update ping() to use E(kernel).ping() instead of rpcClient.call() - Remove @metamask/kernel-rpc-methods and @MetaMask/ocap-kernel dependencies Harmonize extension trusted prelude setup with omnium: - Delete extension separate dev-console.js and background-trusted-prelude.js - Add global.d.ts with TypeScript declarations for E and kernel globals - Both packages now use the same pattern: defineGlobals() call at module top Remove unused dependencies flagged by depcheck: - kernel-browser-runtime: Remove @endo/promise-kit - extension: Remove @MetaMask/ocap-kernel, @metamask/utils - kernel-test: Remove @metamask/streams, @metamask/utils - nodejs: Remove @metamask/utils - omnium-gatherum: Remove @endo/captp, @endo/marshal, @metamask/kernel-rpc-methods, @MetaMask/ocap-kernel, @metamask/utils Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive tests for the CapTP infrastructure:
- background-captp.test.ts: Tests for utility functions and makeBackgroundCapTP
- kernel-facade.test.ts: Tests for facade delegation to kernel methods
- kernel-captp.test.ts: Tests for makeKernelCapTP factory
- captp.integration.test.ts: Full round-trip E() tests with real endoify
Configure vitest with inline projects to use different setupFiles:
- Unit tests use mock-endoify for isolated testing
- Integration tests use real endoify for CapTP/E() functionality
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ntegration Split the vitest configuration into two separate files to fix issues with tests running from the repo root: - vitest.config.ts: Unit tests with mock-endoify - vitest.integration.config.ts: Integration tests with node-endoify Add test:integration script to run integration tests separately. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rekmarks
commented
Jan 15, 2026
| node-version: ${{ matrix.node-version }} | ||
| env: | ||
| PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 | ||
| - run: yarn build |
Member
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I hate that we have to build before anything except the e2e tests but we already live in sin so this is fine for now. I'm of a mind to start caching builds in CI after this PR.
packages/kernel-browser-runtime/src/kernel-worker/captp/kernel-facade.test.ts
Outdated
Show resolved
Hide resolved
Member
Author
|
@claude review |
This comment was marked as resolved.
This comment was marked as resolved.
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.
Answers @kumavis's challenge of "What're you afraid of CapTP or something?" by replacing our kernel JSON-RPC API with
E()on a facet of the kernel. This makes it easy to expose as much of the kernel API as we want via eventual send, and allows us to benefit from pipelining internally. In addition, it facilitates the removal of the command stream and the related RPC API logic. Finally, a number of rationalizations are applied to the extension and omnium.This PR is part of a stack followed by: #752, #753, and #754
Note
Introduces CapTP-based communication and removes the kernel command-stream JSON-RPC path.
makeBackgroundCapTP,makeKernelCapTP, and aKernelFacadeexposed via E()background/offscreento send/receive CapTP JSON-RPC notifications over streams; define globalEandkernel/omniumhelpersKernel.make(...)to no longer require a command stream; remove kernel RPC handlers/exports and related code pathstest:integrationscript + CI job@endo/captpand@endo/eventual-senddeps; simplify NodemakeKernelAPIWritten by Cursor Bugbot for commit fc29d6b. This will update automatically on new commits. Configure here.