Skip to content

Conversation

@grypez
Copy link
Contributor

@grypez grypez commented Jan 22, 2026

Summary

Replace @endo/bundle-source with vite for vat bundling and remove @endo/import-bundle for bundle loading.

Changes

  • Bundle vats using vite's build() API with IIFE output format
  • Load bundles via Compartment.evaluate() instead of importBundle()
  • Remove @endo/import-bundle dependency from all packages.
  • Remove @endo/bundle-source dependency from all packages except kernel-shims.

Bundle Format

New bundles use vite-iife format:

{
  "moduleFormat": "vite-iife",
  "code": "var __vatExports__ = ...",
  "exports": ["buildRootObject"],
  "modules": { ... }
}

Closes: #742


Note

Replaces Endo tooling with a Vite-based pipeline and a new runtime loader for vats.

  • Bundling: Add vite-based bundler (bundleVat) producing IIFE bundles with __vatExports__; includes export-metadata and strip-comments Rollup plugins
  • CLI: Use Vite bundler in bundle/watch; update README; adjust tests and fixtures to new bundle shape
  • Kernel runtime: Remove @endo/import-bundle; add loadBundle to evaluate IIFE bundles in a SES Compartment; VatSupervisor now fetches bundle text and loads via loadBundle
  • Utils: Introduce VatBundle type and isVatBundle; export from kernel-utils
  • Deps: Drop Endo bundling/import deps; add vite, rollup, acorn; update lockfile
  • Tests: Add coverage for bundler, loader, and comment stripping; update integration tests and test bundle to new format

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

@socket-security
Copy link

socket-security bot commented Jan 22, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedrollup@​4.46.3 ⏵ 4.55.38810010099100

View full report

@grypez grypez force-pushed the grypez/bundle-with-vite branch 3 times, most recently from 504110d to 1a13965 Compare January 22, 2026 15:17
@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 87.91%
⬇️ -0.19%
5735 / 6523
🔵 Statements 87.81%
⬇️ -0.18%
5828 / 6637
🔵 Functions 86.83%
⬇️ -0.27%
1491 / 1717
🔵 Branches 84.24%
⬇️ -0.23%
2080 / 2469
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/app.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
15-155
packages/cli/src/commands/bundle.ts 92.3%
🟰 ±0%
50%
🟰 ±0%
100%
🟰 ±0%
92.3%
🟰 ±0%
72
packages/cli/src/commands/watch.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/cli/src/vite/export-metadata-plugin.ts 0% 0% 0% 0% 23-46
packages/cli/src/vite/strip-comments-plugin.ts 100% 100% 100% 100%
packages/cli/src/vite/vat-bundler.ts 0% 0% 0% 0% 20-59
packages/kernel-utils/src/index.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/kernel-utils/src/vat-bundle.ts 100% 100% 100% 100%
packages/ocap-kernel/src/vats/VatSupervisor.ts 74.64%
🟰 ±0%
44.82%
🟰 ±0%
58.33%
🟰 ±0%
74.64%
🟰 ±0%
122, 133, 141, 179, 217-221, 232, 241-242, 263-265, 268, 272-274, 309, 326-334
packages/ocap-kernel/src/vats/bundle-loader.ts 100% 100% 100% 100%
Generated in workflow #3332 for commit daa5828 by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

@grypez grypez marked this pull request as ready for review January 22, 2026 18:29
@grypez grypez requested a review from a team as a code owner January 22, 2026 18:29
@grypez grypez force-pushed the grypez/bundle-with-vite branch from 1a13965 to b8e02c0 Compare January 22, 2026 18:45
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

Really nice!

cursor[bot]

This comment was marked as outdated.

hasProperty(value, 'moduleFormat') &&
value.moduleFormat === 'iife' &&
hasProperty(value, 'code') &&
typeof value.code === 'string';
Copy link

Choose a reason for hiding this comment

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

Incomplete type guard doesn't validate all VatBundle properties

Medium Severity

The isVatBundle type guard asserts that a value is a VatBundle, but only validates moduleFormat and code properties. The VatBundle type also requires exports: string[] and modules: Record<...> properties. Code that uses this type guard will believe it has a complete VatBundle after the check, but accessing .exports or .modules could return undefined if an incomplete object passed the check.

Fix in Cursor Fix in Web

ecmaVersion: 'latest',
sourceType: 'module',
onComment: comments,
});
Copy link

Choose a reason for hiding this comment

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

Wrong sourceType for parsing IIFE bundle output

Low Severity

The stripCommentsPlugin uses sourceType: 'module' to parse vite's IIFE output, but IIFE bundles are scripts, not modules. Module parsing implies strict mode, which rejects certain legacy JavaScript patterns (octal literals, with statements, etc.). If bundled dependencies contain non-strict-mode code that wasn't transpiled, parse() throws a SyntaxError, preventing comment stripping and causing the build to fail unexpectedly.

Fix in Cursor Fix in Web

grypez and others added 9 commits January 23, 2026 17:02
Drop support for the legacy endoZipBase64 bundle format and remove
the @endo/import-bundle dependency. All vat bundles now use the
vite-iife format loaded via Compartment.evaluate().

- Remove @endo/import-bundle from ocap-kernel dependencies
- Simplify bundle-loader.ts to only support vite-iife format
- Update VatSupervisor to use synchronous loadBundle
- Update CLI tests to mock bundleVat instead of @endo/bundle-source
- Update serve integration test to check vite-iife format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
Reuses the acorn parsing dependency from `@ocap/kernel-agents-repl` to authoritatively scrub comments from vat bundles.

Refs #770

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Replaces the comment scrubber with an AST-based implementation to
reliably remove comments (including those containing `import(`) from
bundled code.
> 
> - Refactors `vite/strip-comments-plugin` to use Acorn (`parse` with
`onComment`) and return unchanged code when no comments are found
> - Adds unit tests for `strip-comments-plugin` covering
single/multi-line comments, strings, regex, templates, and empty input
> - Adds `acorn` dependency in `@ocap/cli` and updates `yarn.lock`
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
3a59ba8. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@grypez grypez force-pushed the grypez/bundle-with-vite branch from fcdd1f3 to cc26d68 Compare January 23, 2026 23:03
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.

assert: globalThis.assert,
...endowments,
...inescapableGlobalProperties,
});
Copy link

Choose a reason for hiding this comment

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

inescapableGlobalProperties treated as regular escapable globals

Medium Severity

The loadBundle function accepts an inescapableGlobalProperties parameter but treats it identically to regular endowments by spreading both into the Compartment constructor. In the original importBundle from @endo/import-bundle, inescapableGlobalProperties had special SES semantics that prevented the evaluated code from shadowing these globals. The current implementation makes them regular globals that can be shadowed by var declarations in the evaluated code. The test only verifies the properties are accessible, not that they're truly inescapable.

Fix in Cursor Fix in Web

@grypez grypez force-pushed the grypez/bundle-with-vite branch from cc26d68 to 44ef8b3 Compare January 24, 2026 23:00
status: substantiated
repro: 763#discussion_r2723046643
status: substantiated
repro: 763#discussion_r2718760552
status: substantiated
repro: 763#discussion_r2723046645
@grypez grypez force-pushed the grypez/bundle-with-vite branch from 44ef8b3 to daa5828 Compare January 25, 2026 19:16
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.

build: Bundle vats with vite

3 participants