utopia-ia/elffuss-code public
| .. | ||
| src/ | ||
| .node-version | 7 B | |
| .npmrc | 78 B | |
| README.md | 6.9 KiB | |
| build.mjs | 4.5 KiB | |
| check-output.mjs | 5.8 KiB | |
| package-lock.json | 32.8 KiB | |
| package.json | 796 B | |
| postbuild.mjs | 7.5 KiB | |
| sweep-allowlist.json | 2.2 KiB | |
| sweep.mjs | 6.9 KiB | |
| verify-repro.mjs | 4.1 KiB | |
| vite.config.mjs | 4.5 KiB | |
README.md
Level 2 vendor bundle
The runtime that lets Elffuss Code run the code of VS Code web extensions:
a headless VS Code (@codingame/monaco-vscode-api 37.3.11, VS Code 1.138.0)
that runs inside a sandbox iframe on a separate site with no network. Code's
own JavaScript stays buildless; only this bundle is built, and only here.
This folder is the only place in the repository where npm runs.
What it produces
Three single-file ES modules, gzipped, plus the licences of what they bundle:
| File | Role |
|---|---|
sandbox-main.js.gz | VS Code services, extension manager, hidden mirror editor |
exthost-worker.js.gz | the extension host, which runs extension code in a worker |
editor-worker.js.gz | VS Code's editor worker for the mirror editor |
LICENSES.txt | every bundled package's licence |
They go to web/vendor/x2/<buildId>/, which git ignores. The buildId is the
first 16 hex characters of a sha256 over the files' hashes, so it changes
exactly when the bytes change. The build also writes
web/js/ext2/vendor-manifest.json (committed, a few KB): sizes, the sha256 of
each raw file and an SRI value for each .gz. Code's page checks both before
it hands a byte to the sandbox (web/js/ext2/vendor.js).
Not shipped: jschardet (LGPL-2.1), the code-page tables of
@vscode/iconv-lite-umd, @vscode/diff (a wasm binary and its own worker)
and VS Code's keyboard layout tables. src/stubs/ replaces them with small
stand-ins; the sandbox only ever sees UTF-8 text and never receives key
events.
Build
cd vendor/vscode-ext2
npm ci --ignore-scripts # .npmrc also sets ignore-scripts
node build.mjs
build.mjs refuses to run on any Node version other than .node-version, or
when an installed package differs from the lockfile. It fails, writing
nothing, when:
- the path sweep finds anything (below);
- an entry produces more than one file;
- the three
.gzfiles together exceed 2.8 MB (BUDGET_GZinpostbuild.mjs).
The .gz files are written by postbuild.mjs itself (level 9, no time stamp,
no OS byte). Their bytes depend on Node's zlib, so they are reproducible for
the pinned Node version on the same CPU architecture; the raw files, and so
the buildId, do not depend on zlib.
Checks
node verify-repro.mjs # two clean builds in different folders: byte-identical, equal to the committed manifest
node sweep.mjs # sweep the built folder named by the manifest
node sweep.mjs --list <dir> # print every generic hit with its context, to review an allowlist change
node check-output.mjs # the built folder against the manifest: only its files, SRI, sha256, sweep
verify-repro.mjs needs 15 GB of free disk and puts its temporary folders
under $X2_REPRO_TMP (default: the system temp folder).
The sweep fails on the user name, the home folder, the build folder or the
repository folder anywhere in the output, including inside base64 data:
URLs. Generic patterns (home prefixes of macOS, Linux and Windows, file URLs
and source-map comments) are allowed only when the exact hit is listed in
sweep-allowlist.json with its count. A hit is identified by the sha256 of
the literal it sits in (up to 40 characters either side, cut at quotes and
line breaks), so renamed minified code around it does not change the list,
but any new literal, or a different count, fails the build. Today's allowed
hits are VS Code's own help-text example paths and its file-URL checks.
Where it is served from
From Code's own origin, https://code.elffuss.com/vendor/x2/<buildId>/…, with:
location ^~ /vendor/x2/ { default_type application/octet-stream; gzip off;
add_header Cache-Control "public, max-age=31536000, immutable";
add_header X-Content-Type-Options nosniff always; }
application/octet-stream keeps browsers from decoding the .gz on their own:
the page decompresses it with DecompressionStream, then checks the sha256 of
the raw bytes. That works whatever transfer compression a proxy adds.
Cache-Control has no always, so nginx adds it only to successful responses.
With always, a 404 for a build that is not on the server yet would be cached
as immutable for a year; because the buildId is a content hash, uploading
the same bytes afterwards would not reach the browsers that cached the
failure: only a new buildId would. tests/x2_headers.mjs (H5) checks that a
missing file is not cached that way, also against a deployment.
Nothing is published to npm or a CDN, and nothing large goes into git.
Deploy
- Merge first. Only this branch's
deploy.shprotectsvendor/x2/from itsrsync --delete; a Code deploy from a tree without that filter (main today) deletes the uploaded bundle.deploy-vendor.shrefuses to run untilmain'sdeploy.shhas the filter. ./deploy-vendor.sh(repository root; readsELFFUSS_HOSTandELFFUSS_KEY, likedeploy.sh). It checks the local folder against the manifest (check-output.mjs: exactly the manifest's files and nothing else), uploads only those files withrsync --ignore-existing(never--delete), then requires the server's folder to hold exactly those files with the manifest's sha256 sums../deploy.sh, which ships the manifest naming the newbuildId. A normal deploy neither uploads nor deletes anything undervendor/x2/. Once level 2 is live (the manifest enabled andweb/js/ext2/config.jsnaming a sandbox for Code), it refuses to ship a manifest whose build the server does not hold, byte for byte (check-output.mjs --manifest-sums, from the manifest alone).
If a browser still finds a build missing (a partial upload, a pruned
rollback), level 2 fails closed and the default path is unaffected; the
failure is not cached as long as Cache-Control has no always (above). Old
builds stay until a manual prune keeps the last three; reverting the
manifest and redeploying is the rollback. Setting "enabled": false in the
manifest is the global kill switch.
Upgrade checklist
- Bump the exact versions in
package.json(all@codingame/*packages and themonaco-editoralias together). npm install --ignore-scripts, thennode build.mjs,node verify-repro.mjsandnode sweep.mjs. Review any allowlist change with--list.- Check that the library's
webWorkerExtensionHostIframe.htmlstill matchessandbox/x2/v1/exthost-iframe.htmlapart from the CSP meta, and that its inline-script hash is unchanged. - Diff the API-surface snapshot (
tests/x2-surface.json, rewritten withnode tests/x2_smoke.mjs --update) and review the RPC allowlist (web/js/ext2/rpc-allowlist.json): every actor must be either allowed or listed indeniedActors, andnode tests/x2_unit.mjsfails until it is. - Run all suites in both modes, plus the canary.
- Re-run the runtime census (
tests/x2_census.mjs).
No library source is patched on disk; every hook is a runtime wrap in
web/js/ext2/sandbox-relay.js.