Harden bundle against host's boundary-less import regex (#14) #15
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/14-host-import-regex"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #14.
Root cause
Hermes Desktop's runtime loader (
apps/desktop/src/contrib/runtime-loader.ts) scans plugin bundles with— no word boundary before
from. Our bundle inlines Temml (LaTeX, #7), whose symbol table contains"\\mapsfrom"and"\\xtofrom". In the minified output…mapsfrom",!0);o(i,f,"…is read as an import of,!0);o(i,f,— the garbage specifiers in the error. Our own lint uses\bfrom, so it never caught it.Fix
desktop/scripts/harden-bundle.mjs(new): post-build pass that rewritesfrom/importglued to an identifier char and followed by a quote (mapsfrom"→mapsfro\x6d"). That can only occur inside a string/regex/template literal, where the hex escape is semantically identical; real import statements are untouched.desktop/esbuild.config.mjs: runs the pass after every build (single and--watch) before lint.desktop/scripts/lint-bundle.mjs+scripts/install.py: additionally check with the host's exact regex, so a future vendored string cannot regress this. Verified both reject the unhardened bundle.desktop/test/harden-bundle.test.ts: host regex misreads the Temml snippet; hardened output is invisible to it and evaluates to identical strings; real imports untouched; idempotent.AGENTS.md,desktop/README.md,design.md.Verification
npm run build→ lint ok; host regex overdist/plugin.jsnow yields only@hermes/plugin-sdk, react, react/jsx-runtimenpm test25/25,npm run typecheckcleanscripts/install.pyto refresh~/.hermes/plugins/hermes-learning/desktop/plugin.js.The proper upstream fix is
\bfrom/\bimportin hermes-agent'simportSpecifierRe; this keeps the plugin working on current hosts regardless.