Skip to content

Conversation

@rekmarks
Copy link
Member

@rekmarks rekmarks commented Jan 28, 2026

Summary

This PR consolidates several refactoring improvements to improve code organization and reduce circular dependencies:

  1. Migrate endoify setup to kernel-shims: Moved Node.js-specific initialization from @ocap/nodejs to @metamask/kernel-shims/endoify-node
  2. Rationalize globalThis.kernel: Simplified global kernel API in extension and omnium-gatherum packages
  3. Improve dependency management: Enhanced linting configuration and removed unused dependencies

Motivation

  • The endoify setup logic was split between @ocap/nodejs and @metamask/kernel-shims, creating circular dependency patterns
  • Multiple packages were importing endoify from @ocap/nodejs when it logically belongs in the shims package
  • The globalThis.kernel API had unnecessary wrapper methods (ping(), getKernel()) when a direct reference would suffice

Changes

Endoify consolidation

  • Created @metamask/kernel-shims/endoify-node for Node.js-specific lockdown initialization
  • Removed @ocap/nodejs/endoify-mjs and @ocap/nodejs/endoify-ts exports
  • Updated all test setup files and worker scripts to use @metamask/kernel-shims/endoify-node
  • Added @libp2p/webrtc as peer dependency to kernel-shims (imports before lockdown to modify globals)

Global API rationalization

Before:

globalThis.kernel = {
  ping: () => Promise<void>,
  getKernel: () => Promise<KernelFacade>
}

After:

globalThis.kernel: KernelFacade | Promise<KernelFacade>

This simplification:

  • Reduces API surface area
  • Eliminates wrapper methods
  • Provides direct access to kernel facade
  • Usage becomes E(globalThis.kernel).ping() instead of kernel.ping()

Dependency improvements

  • Configured depcheck to ignore dist/ directories (avoids false positives from build artifacts)
  • Added @libp2p/webrtc to depcheck ignores (peer dependency of kernel-shims)
  • Removed @ocap/nodejs from @metamask/kernel-browser-runtime devDependencies (was only used for test setup)
  • Added proper test dependencies to packages that were inheriting them transitively

Test plan

  • All unit tests pass: yarn test:dev:quiet
  • Integration tests pass in affected packages
  • Extension loads and communicates with kernel
  • Omnium-gatherum loads and communicates with kernel
  • No regressions in kernel initialization or CapTP communication

Files changed

  • 30 files changed, 89 insertions(+), 133 deletions(-)
  • Net reduction of 44 lines while improving code organization

🤖 Generated with Claude Code


Note

Centralizes Node.js lockdown/init and streamlines extension globals.

  • Adds @metamask/kernel-shims/endoify-node, copies it during build, and declares @libp2p/webrtc as a peer dependency; all Node.js tests/workers now import this shim
  • Removes endoify exports from @ocap/nodejs and related imports; cleans up devDeps (e.g., drops @ocap/nodejs from kernel-browser-runtime tests)
  • Simplifies globalThis.kernel to KernelFacade | Promise<KernelFacade> and updates extension/omnium backgrounds to set globalThis.kernel and use E(globalThis.kernel).ping(); updates type declarations accordingly
  • Improves dependency tooling: depcheck now ignores dist/ and @libp2p/webrtc; updates LavaMoat allowScripts entry
  • Keeps CapTP flow intact while removing wrapper methods and redundant plumbing

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

rekmarks and others added 6 commits January 27, 2026 20:18
Set globalThis.kernel in the extension and omnium to the kernel itself. Remove
ping and getKernel methods from background console interface. The kernel
exposes ping().
…helpers

- Remove packages/nodejs/src/env/endoify.ts re-export, use @metamask/kernel-shims/node-endoify directly
- Update vitest configs to use kernel-shims for setup files
- Remove inline endoify imports from test files (now handled by vitest setup)
- Fix test helpers to handle SubclusterLaunchResult return type from launchSubcluster()
- Add kernel-shims dependency to kernel-test and nodejs-test-workers packages
- Set coverage thresholds to 0 temporarily

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e configs

- Fix accidentally broken nodejs vat worker (which broke all tests relying
  on it)
- Rename node-endoify.js to endoify-node.js for consistency
- Update package.json export from ./node-endoify to ./endoify-node
- Update all vitest configs to use the new export path
- Update depcheckrc.yml ignore pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rekmarks rekmarks requested a review from a team as a code owner January 28, 2026 04:34
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 88.6%
⬆️ +0.16%
5764 / 6505
🔵 Statements 88.48%
⬆️ +0.16%
5856 / 6618
🔵 Functions 87.64%
⬆️ +0.41%
1504 / 1716
🔵 Branches 84.81%
⬇️ -0.14%
2078 / 2450
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/extension/src/background.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
15-171
packages/extension/src/global.d.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/nodejs-test-workers/src/workers/mock-fetch.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
6-36
packages/nodejs/src/vat/vat-worker.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
8-28
packages/omnium-gatherum/src/background.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
20-228
packages/omnium-gatherum/src/global.d.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Generated in workflow #3395 for commit b3afe55 by the Vitest Coverage Report Action

@rekmarks rekmarks changed the title refactor: Consolidate endoify setup and rationalize global APIs refactor: Consolidate endoify setup and rationalize exension globals Jan 28, 2026
rekmarks and others added 2 commits January 27, 2026 20:51
The endoify-node export was pointing to src/endoify-node.js, but the
files array only includes dist/, causing the file to be missing from
published packages.

The file cannot be bundled because it imports @libp2p/webrtc (a peer
dependency), so the build script now copies it to dist/ instead.

Changes:
- Update build script to copy endoify-node.js to dist/
- Update package.json export to point to dist/endoify-node.js
- Update source comment to reflect new build process

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify the build script by using the built-in copyFile function
instead of manually reading and writing the file.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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