feat(coding-agent): cache compiled Node CLI modules

This commit is contained in:
Armin Ronacher 2026-09-20 11:44:20 +02:00
parent b73412a378
commit 60740991c0
2 changed files with 13 additions and 4 deletions

View file

@ -38,6 +38,7 @@
### Changed
- Enabled Node's persistent compile cache before loading the bundled CLI runtime, reducing repeat launch time.
- Made `--resume` session results appear progressively, using file modification times to prioritize all-folder loading and cancelling outstanding transcript reads after selection.
- Reduced `--continue` startup time by checking candidate session headers in modification-time order and stopping after the newest matching session.
- Replaced the external native clipboard dependency with bundled asynchronous macOS, Windows, and X11 helpers while preserving platform command and OSC 52 fallbacks ([#9163](https://github.com/earendil-works/pi/pull/9163)).

View file

@ -1,6 +1,6 @@
#!/usr/bin/env node
import { chmodSync, existsSync, mkdirSync, rmSync } from "node:fs";
import { chmodSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { isBuiltin } from "node:module";
import { dirname, join, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
@ -162,7 +162,7 @@ const mainResult = await build({
...commonBuildOptions(),
entryNames: "[name]",
entryPoints: {
cli: join(codingAgentDistDir, "cli.js"),
"cli-runtime": join(codingAgentDistDir, "cli.js"),
index: join(codingAgentDistDir, "index.js"),
"rpc-entry": join(codingAgentDistDir, "rpc-entry.js"),
},
@ -206,9 +206,17 @@ if (dirname(imageResizeOutput) !== dirname(imageResizeWorkerOutput)) {
}
validateExternalImports([mainResult.metafile, lazyResult.metafile]);
const cliLauncher = `#!/usr/bin/env node
import { createRequire, enableCompileCache } from "node:module";
enableCompileCache();
createRequire(import.meta.url)("./cli-runtime.js");
`;
writeFileSync(join(bundleDir, "cli.js"), cliLauncher);
chmodSync(join(bundleDir, "cli.js"), 0o755);
chmodSync(join(bundleDir, "rpc-entry.js"), 0o755);
const files = new Set([...Object.keys(mainResult.metafile.outputs), ...Object.keys(lazyResult.metafile.outputs)]).size;
const mib = outputBytes([mainResult.metafile, lazyResult.metafile]) / (1024 * 1024);
const files =
new Set([...Object.keys(mainResult.metafile.outputs), ...Object.keys(lazyResult.metafile.outputs)]).size + 1;
const mib = (outputBytes([mainResult.metafile, lazyResult.metafile]) + cliLauncher.length) / (1024 * 1024);
console.log(`Built ${relative(repoRoot, bundleDir)} (${files} files, ${mib.toFixed(1)} MiB)`);