Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Jan 14, 2026

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.

  • Add CapTP endpoints: makeBackgroundCapTP, makeKernelCapTP, and a KernelFacade exposed via E()
  • Update extension and omnium background/offscreen to send/receive CapTP JSON-RPC notifications over streams; define global E and kernel/omnium helpers
  • Refactor kernel worker and Kernel.make(...) to no longer require a command stream; remove kernel RPC handlers/exports and related code paths
  • Add unit/integration tests for CapTP and facade; split vitest configs and add test:integration script + CI job
  • Adjust build/trusted preludes (inline endoify), TS configs, and coverage thresholds; add @endo/captp and @endo/eventual-send deps; simplify Node makeKernel API

Written by Cursor Bugbot for commit fc29d6b. This will update automatically on new commits. Configure here.

rekmarks and others added 4 commits January 14, 2026 11:21
…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 <[email protected]>
…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 <[email protected]>
      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 <[email protected]>
rekmarks and others added 4 commits January 14, 2026 15:29
…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 <[email protected]>
node-version: ${{ matrix.node-version }}
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: yarn build
Copy link
Member Author

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.

@rekmarks
Copy link
Member Author

@claude review

@claude

This comment was marked as resolved.

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.

2 participants