Merge pull request #2808 from pi0/perf/compile-cache

perf(cli): use compile cache (~10% faster)
This commit is contained in:
Vignesh 2026-01-27 13:54:30 -08:00 committed by GitHub
commit 24902880de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 34 additions and 20 deletions

View File

@ -63,6 +63,7 @@ Status: unreleased.
- Config: apply config.env before ${VAR} substitution. (#1813) Thanks @spanishflu-est1918. - Config: apply config.env before ${VAR} substitution. (#1813) Thanks @spanishflu-est1918.
- Slack: clear ack reaction after streamed replies. (#2044) Thanks @fancyboi999. - Slack: clear ack reaction after streamed replies. (#2044) Thanks @fancyboi999.
- macOS: keep custom SSH usernames in remote target. (#2046) Thanks @algal. - macOS: keep custom SSH usernames in remote target. (#2046) Thanks @algal.
- CLI: use Node's module compile cache for faster startup. (#2808) Thanks @pi0.
### Breaking ### Breaking
- **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed). - **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed).

View File

@ -42,7 +42,7 @@ moltbot acp client
moltbot acp client --server-args --url wss://gateway-host:18789 --token <token> moltbot acp client --server-args --url wss://gateway-host:18789 --token <token>
# Override the server command (default: moltbot) # Override the server command (default: moltbot)
moltbot acp client --server "node" --server-args dist/entry.js acp --url ws://127.0.0.1:19001 moltbot acp client --server "node" --server-args moltbot.mjs acp --url ws://127.0.0.1:19001
``` ```
## How to use this ## How to use this

View File

@ -55,9 +55,9 @@ node --import tsx scripts/repro/tsx-name-repro.ts
- Use Node + tsc watch, then run compiled output: - Use Node + tsc watch, then run compiled output:
```bash ```bash
pnpm exec tsc --watch --preserveWatchOutput pnpm exec tsc --watch --preserveWatchOutput
node --watch dist/entry.js status node --watch moltbot.mjs status
``` ```
- Confirmed locally: `pnpm exec tsc -p tsconfig.json` + `node dist/entry.js status` works on Node 25. - Confirmed locally: `pnpm exec tsc -p tsconfig.json` + `node moltbot.mjs status` works on Node 25.
- Disable esbuild keepNames in the TS loader if possible (prevents `__name` helper insertion); tsx does not currently expose this. - Disable esbuild keepNames in the TS loader if possible (prevents `__name` helper insertion); tsx does not currently expose this.
- Test Node LTS (22/24) with `tsx` to see if the issue is Node 25specific. - Test Node LTS (22/24) with `tsx` to see if the issue is Node 25specific.

View File

@ -125,7 +125,7 @@ moltbot health
``` ```
Notes: Notes:
- `pnpm build` matters when you run the packaged `moltbot` binary ([`dist/entry.js`](https://github.com/moltbot/moltbot/blob/main/dist/entry.js)) or use Node to run `dist/`. - `pnpm build` matters when you run the packaged `moltbot` binary ([`moltbot.mjs`](https://github.com/moltbot/moltbot/blob/main/moltbot.mjs)) or use Node to run `dist/`.
- If you run from a repo checkout without a global install, use `pnpm moltbot ...` for CLI commands. - If you run from a repo checkout without a global install, use `pnpm moltbot ...` for CLI commands.
- If you run directly from TypeScript (`pnpm moltbot ...`), a rebuild is usually unnecessary, but **config migrations still apply** → run doctor. - If you run directly from TypeScript (`pnpm moltbot ...`), a rebuild is usually unnecessary, but **config migrations still apply** → run doctor.
- Switching between global and git installs is easy: install the other flavor, then run `moltbot doctor` so the gateway service entrypoint is rewritten to the current install. - Switching between global and git installs is easy: install the other flavor, then run `moltbot doctor` so the gateway service entrypoint is rewritten to the current install.

View File

@ -20,7 +20,7 @@ When the operator says “release”, immediately do this preflight (no extra qu
- [ ] Bump `package.json` version (e.g., `2026.1.26`). - [ ] Bump `package.json` version (e.g., `2026.1.26`).
- [ ] Run `pnpm plugins:sync` to align extension package versions + changelogs. - [ ] Run `pnpm plugins:sync` to align extension package versions + changelogs.
- [ ] Update CLI/version strings: [`src/cli/program.ts`](https://github.com/moltbot/moltbot/blob/main/src/cli/program.ts) and the Baileys user agent in [`src/provider-web.ts`](https://github.com/moltbot/moltbot/blob/main/src/provider-web.ts). - [ ] Update CLI/version strings: [`src/cli/program.ts`](https://github.com/moltbot/moltbot/blob/main/src/cli/program.ts) and the Baileys user agent in [`src/provider-web.ts`](https://github.com/moltbot/moltbot/blob/main/src/provider-web.ts).
- [ ] Confirm package metadata (name, description, repository, keywords, license) and `bin` map points to [`dist/entry.js`](https://github.com/moltbot/moltbot/blob/main/dist/entry.js) for `moltbot`. - [ ] Confirm package metadata (name, description, repository, keywords, license) and `bin` map points to [`moltbot.mjs`](https://github.com/moltbot/moltbot/blob/main/moltbot.mjs) for `moltbot`.
- [ ] If dependencies changed, run `pnpm install` so `pnpm-lock.yaml` is current. - [ ] If dependencies changed, run `pnpm install` so `pnpm-lock.yaml` is current.
2) **Build & artifacts** 2) **Build & artifacts**

View File

@ -180,7 +180,7 @@ If you dont have a global install yet, run the onboarding step via `pnpm molt
Gateway (from this repo): Gateway (from this repo):
```bash ```bash
node dist/entry.js gateway --port 18789 --verbose node moltbot.mjs gateway --port 18789 --verbose
``` ```
## 7) Verify end-to-end ## 7) Verify end-to-end

14
moltbot.mjs Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env node
import module from "node:module";
// https://nodejs.org/api/module.html#module-compile-cache
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
module.enableCompileCache();
} catch {
// Ignore errors
}
}
await import("./dist/entry.js");

View File

@ -8,11 +8,11 @@
".": "./dist/index.js", ".": "./dist/index.js",
"./plugin-sdk": "./dist/plugin-sdk/index.js", "./plugin-sdk": "./dist/plugin-sdk/index.js",
"./plugin-sdk/*": "./dist/plugin-sdk/*", "./plugin-sdk/*": "./dist/plugin-sdk/*",
"./cli-entry": "./dist/entry.js" "./cli-entry": "./moltbot.mjs"
}, },
"bin": { "bin": {
"moltbot": "dist/entry.js", "moltbot": "./moltbot.mjs",
"clawdbot": "dist/entry.js" "clawdbot": "./moltbot.mjs"
}, },
"files": [ "files": [
"dist/acp/**", "dist/acp/**",
@ -56,6 +56,7 @@
"docs/**", "docs/**",
"extensions/**", "extensions/**",
"assets/**", "assets/**",
"moltbot.mjs",
"skills/**", "skills/**",
"patches/**", "patches/**",
"README.md", "README.md",

View File

@ -81,8 +81,8 @@ LOGINCTL
npm install -g --prefix /tmp/npm-prefix "/app/$pkg_tgz" npm install -g --prefix /tmp/npm-prefix "/app/$pkg_tgz"
npm_bin="/tmp/npm-prefix/bin/moltbot" npm_bin="/tmp/npm-prefix/bin/moltbot"
npm_entry="/tmp/npm-prefix/lib/node_modules/moltbot/dist/entry.js" npm_entry="/tmp/npm-prefix/lib/node_modules/moltbot/moltbot.mjs"
git_entry="/app/dist/entry.js" git_entry="/app/moltbot.mjs"
assert_entrypoint() { assert_entrypoint() {
local unit_path="$1" local unit_path="$1"

View File

@ -96,8 +96,8 @@ for arg in "$@"; do
log " CLAWDBOT_GATEWAY_WAIT_SECONDS=0 Wait time before gateway port check (unsigned only)" log " CLAWDBOT_GATEWAY_WAIT_SECONDS=0 Wait time before gateway port check (unsigned only)"
log "" log ""
log "Unsigned recovery:" log "Unsigned recovery:"
log " node dist/entry.js daemon install --force --runtime node" log " node moltbot.mjs daemon install --force --runtime node"
log " node dist/entry.js daemon restart" log " node moltbot.mjs daemon restart"
log "" log ""
log "Reset unsigned overrides:" log "Reset unsigned overrides:"
log " rm ~/.clawdbot/disable-launchagent" log " rm ~/.clawdbot/disable-launchagent"
@ -217,8 +217,8 @@ fi
# When unsigned, ensure the gateway LaunchAgent targets the repo CLI (before the app launches). # When unsigned, ensure the gateway LaunchAgent targets the repo CLI (before the app launches).
# This reduces noisy "could not connect" errors during app startup. # This reduces noisy "could not connect" errors during app startup.
if [ "$NO_SIGN" -eq 1 ] && [ "$ATTACH_ONLY" -ne 1 ]; then if [ "$NO_SIGN" -eq 1 ] && [ "$ATTACH_ONLY" -ne 1 ]; then
run_step "install gateway launch agent (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon install --force --runtime node" run_step "install gateway launch agent (unsigned)" bash -lc "cd '${ROOT_DIR}' && node moltbot.mjs daemon install --force --runtime node"
run_step "restart gateway daemon (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon restart" run_step "restart gateway daemon (unsigned)" bash -lc "cd '${ROOT_DIR}' && node moltbot.mjs daemon restart"
if [[ "${GATEWAY_WAIT_SECONDS}" -gt 0 ]]; then if [[ "${GATEWAY_WAIT_SECONDS}" -gt 0 ]]; then
run_step "wait for gateway (unsigned)" sleep "${GATEWAY_WAIT_SECONDS}" run_step "wait for gateway (unsigned)" sleep "${GATEWAY_WAIT_SECONDS}"
fi fi

View File

@ -86,7 +86,7 @@ const logRunner = (message) => {
}; };
const runNode = () => { const runNode = () => {
const nodeProcess = spawn(process.execPath, ["dist/entry.js", ...args], { const nodeProcess = spawn(process.execPath, ["moltbot.mjs", ...args], {
cwd, cwd,
env, env,
stdio: "inherit", stdio: "inherit",
@ -95,7 +95,6 @@ const runNode = () => {
nodeProcess.on("exit", (exitCode, exitSignal) => { nodeProcess.on("exit", (exitCode, exitSignal) => {
if (exitSignal) { if (exitSignal) {
process.exit(1); process.exit(1);
return;
} }
process.exit(exitCode ?? 1); process.exit(exitCode ?? 1);
}); });
@ -128,11 +127,9 @@ if (!shouldBuild()) {
build.on("exit", (code, signal) => { build.on("exit", (code, signal) => {
if (signal) { if (signal) {
process.exit(1); process.exit(1);
return;
} }
if (code !== 0 && code !== null) { if (code !== 0 && code !== null) {
process.exit(code); process.exit(code);
return;
} }
writeBuildStamp(); writeBuildStamp();
runNode(); runNode();

View File

@ -29,7 +29,7 @@ const compilerProcess = spawn("pnpm", ["exec", compiler, ...watchArgs], {
stdio: "inherit", stdio: "inherit",
}); });
const nodeProcess = spawn(process.execPath, ["--watch", "dist/entry.js", ...args], { const nodeProcess = spawn(process.execPath, ["--watch", "moltbot.mjs", ...args], {
cwd, cwd,
env, env,
stdio: "inherit", stdio: "inherit",

View File

@ -72,6 +72,7 @@ function isGatewayArgv(args: string[]): boolean {
"dist/index.js", "dist/index.js",
"dist/index.mjs", "dist/index.mjs",
"dist/entry.js", "dist/entry.js",
"moltbot.mjs",
"dist/entry.mjs", "dist/entry.mjs",
"scripts/run-node.mjs", "scripts/run-node.mjs",
"src/index.ts", "src/index.ts",