惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Vercel News
Vercel News
L
LangChain Blog
B
Blog RSS Feed
Y
Y Combinator Blog
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
V
V2EX
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
D
Docker
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
月光博客
月光博客

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(cli): scope packaged compile cache · openclaw/opencla...
steipete · 2026-04-30 · via Recent Commits to openclaw:main

@@ -1,9 +1,11 @@

11

#!/usr/bin/env node

2233

import { spawnSync } from "node:child_process";

4-

import { existsSync, readFileSync } from "node:fs";

4+

import { existsSync, readFileSync, statSync } from "node:fs";

55

import { access } from "node:fs/promises";

66

import module from "node:module";

7+

import os from "node:os";

8+

import path from "node:path";

79

import { fileURLToPath } from "node:url";

810911

const MIN_NODE_MAJOR = 22;

@@ -46,6 +48,41 @@ const isSourceCheckoutLauncher = () =>

4648

const isNodeCompileCacheDisabled = () => process.env.NODE_DISABLE_COMPILE_CACHE !== undefined;

4749

const isNodeCompileCacheRequested = () =>

4850

process.env.NODE_COMPILE_CACHE !== undefined && !isNodeCompileCacheDisabled();

51+

const sanitizeCompileCachePathSegment = (value) => {

52+

const normalized = value.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "");

53+

return normalized.length > 0 ? normalized : "unknown";

54+

};

55+

const readPackageVersion = () => {

56+

try {

57+

const parsed = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));

58+

if (typeof parsed?.version === "string" && parsed.version.trim().length > 0) {

59+

return parsed.version;

60+

}

61+

} catch {

62+

// Fall through to an install-metadata-only cache key.

63+

}

64+

return "unknown";

65+

};

66+

const resolvePackagedCompileCacheDirectory = () => {

67+

const packageJsonUrl = new URL("./package.json", import.meta.url);

68+

const version = sanitizeCompileCachePathSegment(readPackageVersion());

69+

let installMarker = "no-package-json";

70+

try {

71+

const stat = statSync(packageJsonUrl);

72+

installMarker = `${Math.trunc(stat.mtimeMs)}-${stat.size}`;

73+

} catch {

74+

// Package archives should always have package.json, but keep startup best-effort.

75+

}

76+

const baseDirectory = isNodeCompileCacheRequested()

77+

? process.env.NODE_COMPILE_CACHE

78+

: path.join(os.tmpdir(), "node-compile-cache");

79+

return path.join(

80+

baseDirectory,

81+

"openclaw",

82+

version,

83+

sanitizeCompileCachePathSegment(installMarker),

84+

);

85+

};

49865087

const respawnWithoutCompileCacheIfNeeded = () => {

5188

if (!isSourceCheckoutLauncher()) {

@@ -79,10 +116,46 @@ const respawnWithoutCompileCacheIfNeeded = () => {

7911680117

respawnWithoutCompileCacheIfNeeded();

81118119+

const respawnWithPackagedCompileCacheIfNeeded = () => {

120+

if (isSourceCheckoutLauncher() || isNodeCompileCacheDisabled()) {

121+

return false;

122+

}

123+

if (process.env.OPENCLAW_PACKAGED_COMPILE_CACHE_RESPAWNED === "1") {

124+

return false;

125+

}

126+

const currentDirectory = module.getCompileCacheDir?.();

127+

if (!currentDirectory) {

128+

return false;

129+

}

130+

const desiredDirectory = resolvePackagedCompileCacheDirectory();

131+

if (path.resolve(currentDirectory) === path.resolve(desiredDirectory)) {

132+

return false;

133+

}

134+

const env = {

135+

...process.env,

136+

NODE_COMPILE_CACHE: desiredDirectory,

137+

OPENCLAW_PACKAGED_COMPILE_CACHE_RESPAWNED: "1",

138+

};

139+

const result = spawnSync(

140+

process.execPath,

141+

[...process.execArgv, fileURLToPath(import.meta.url), ...process.argv.slice(2)],

142+

{

143+

stdio: "inherit",

144+

env,

145+

},

146+

);

147+

if (result.error) {

148+

throw result.error;

149+

}

150+

process.exit(result.status ?? 1);

151+

};

152+153+

respawnWithPackagedCompileCacheIfNeeded();

154+82155

// https://nodejs.org/api/module.html#module-compile-cache

83156

if (module.enableCompileCache && !isNodeCompileCacheDisabled() && !isSourceCheckoutLauncher()) {

84157

try {

85-

module.enableCompileCache();

158+

module.enableCompileCache(resolvePackagedCompileCacheDirectory());

86159

} catch {

87160

// Ignore errors

88161

}