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

推荐订阅源

The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
月光博客
月光博客
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
有赞技术团队
有赞技术团队
V
V2EX
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
腾讯CDC
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog

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(plugins): cache runtime deps scans · openclaw/opencla...
steipete · 2026-04-29 · via Recent Commits to openclaw:main

@@ -76,12 +76,26 @@ const BUNDLED_RUNTIME_MIRROR_PLUGIN_REGION_RE = /(?:^|\n)\/\/#region extensions\

7676

const BUNDLED_RUNTIME_MIRROR_IMPORT_SPECIFIER_RE =

7777

/(?:^|[;\n])\s*(?:import|export)\s+(?:[^'"()]+?\s+from\s+)?["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)|\brequire\(\s*["']([^"']+)["']\s*\)/g;

7878

const NPM_EXECPATH_ENV_KEY = "npm_execpath";

79+

const MAX_RUNTIME_DEPS_FILE_CACHE_ENTRIES = 2048;

79808081

const registeredBundledRuntimeDepNodePaths = new Set<string>();

8182

const bundledRuntimeMirrorMaterializeCache = new Map<

8283

string,

8384

{ signature: string; materialize: boolean }

8485

>();

86+

const runtimeDepsTextFileCache = new Map<string, { signature: string; value: string }>();

87+

const runtimeDepsJsonObjectCache = new Map<

88+

string,

89+

{ signature: string; value: JsonObject | null }

90+

>();

91+

const runtimeDepsImportSpecifierCache = new Map<

92+

string,

93+

{ signature: string; value: readonly string[] }

94+

>();

95+

const runtimeMirrorMaterializeImportSpecifierCache = new Map<

96+

string,

97+

{ signature: string; value: readonly string[] }

98+

>();

859986100

export type BundledRuntimeDepsNpmRunner = {

87101

command: string;

@@ -98,17 +112,19 @@ function statSignature(stat: Pick<fs.Stats, "dev" | "ino" | "size" | "mtimeMs">)

98112

}

99113100114

function computeBundledRuntimeMirrorDistFileMaterialization(sourcePath: string): boolean {

101-

let source: string;

102-

try {

103-

source = fs.readFileSync(sourcePath, "utf8");

104-

} catch {

115+

const signature = getRuntimeDepsFileSignature(sourcePath);

116+

const source = readRuntimeDepsTextFile(sourcePath, signature);

117+

if (source === null) {

105118

return false;

106119

}

107120

if (BUNDLED_RUNTIME_MIRROR_PLUGIN_REGION_RE.test(source)) {

108121

return true;

109122

}

110-

for (const match of source.matchAll(BUNDLED_RUNTIME_MIRROR_IMPORT_SPECIFIER_RE)) {

111-

const specifier = match[1] ?? match[2] ?? match[3] ?? "";

123+

for (const specifier of readRuntimeMirrorMaterializeImportSpecifiers(

124+

sourcePath,

125+

signature,

126+

source,

127+

)) {

112128

if (

113129

specifier !== "" &&

114130

!specifier.startsWith(".") &&

@@ -279,17 +295,132 @@ function readInstalledDependencyVersion(rootDir: string, depName: string): strin

279295

}

280296281297

function readJsonObject(filePath: string): JsonObject | null {

298+

const signature = getRuntimeDepsFileSignature(filePath);

299+

const cached = signature ? runtimeDepsJsonObjectCache.get(filePath) : undefined;

300+

if (cached?.signature === signature) {

301+

return cached.value;

302+

}

303+

const source = readRuntimeDepsTextFile(filePath, signature);

304+

if (source === null) {

305+

cacheRuntimeDepsJsonObject(filePath, signature, null);

306+

return null;

307+

}

282308

try {

283-

const parsed = JSON.parse(fs.readFileSync(filePath, "utf8")) as unknown;

309+

const parsed = JSON.parse(source) as unknown;

284310

if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {

311+

cacheRuntimeDepsJsonObject(filePath, signature, null);

285312

return null;

286313

}

287-

return parsed as JsonObject;

314+

const value = parsed as JsonObject;

315+

cacheRuntimeDepsJsonObject(filePath, signature, value);

316+

return value;

317+

} catch {

318+

cacheRuntimeDepsJsonObject(filePath, signature, null);

319+

return null;

320+

}

321+

}

322+323+

function readRuntimeDepsTextFile(filePath: string, signature?: string | null): string | null {

324+

const fileSignature = signature ?? getRuntimeDepsFileSignature(filePath);

325+

const cached = fileSignature ? runtimeDepsTextFileCache.get(filePath) : undefined;

326+

if (cached?.signature === fileSignature) {

327+

return cached.value;

328+

}

329+

try {

330+

const value = fs.readFileSync(filePath, "utf8");

331+

if (fileSignature) {

332+

rememberRuntimeDepsCacheEntry(runtimeDepsTextFileCache, filePath, {

333+

signature: fileSignature,

334+

value,

335+

});

336+

}

337+

return value;

288338

} catch {

289339

return null;

290340

}

291341

}

292342343+

function readRuntimeDepsImportSpecifiers(

344+

filePath: string,

345+

signature: string | null,

346+

source: string,

347+

): readonly string[] {

348+

const cached = signature ? runtimeDepsImportSpecifierCache.get(filePath) : undefined;

349+

if (cached?.signature === signature) {

350+

return cached.value;

351+

}

352+

const value = extractStaticRuntimeImportSpecifiers(source);

353+

if (signature) {

354+

rememberRuntimeDepsCacheEntry(runtimeDepsImportSpecifierCache, filePath, { signature, value });

355+

}

356+

return value;

357+

}

358+359+

function readRuntimeMirrorMaterializeImportSpecifiers(

360+

filePath: string,

361+

signature: string | null,

362+

source: string,

363+

): readonly string[] {

364+

const cached = signature ? runtimeMirrorMaterializeImportSpecifierCache.get(filePath) : undefined;

365+

if (cached?.signature === signature) {

366+

return cached.value;

367+

}

368+

const value = extractRuntimeMirrorMaterializeImportSpecifiers(source);

369+

if (signature) {

370+

rememberRuntimeDepsCacheEntry(runtimeMirrorMaterializeImportSpecifierCache, filePath, {

371+

signature,

372+

value,

373+

});

374+

}

375+

return value;

376+

}

377+378+

function extractRuntimeMirrorMaterializeImportSpecifiers(source: string): string[] {

379+

const specifiers = new Set<string>();

380+

for (const match of source.matchAll(BUNDLED_RUNTIME_MIRROR_IMPORT_SPECIFIER_RE)) {

381+

const specifier = match[1] ?? match[2] ?? match[3];

382+

if (specifier) {

383+

specifiers.add(specifier);

384+

}

385+

}

386+

return [...specifiers];

387+

}

388+389+

function getRuntimeDepsFileSignature(filePath: string): string | null {

390+

try {

391+

const stat = fs.statSync(filePath, { bigint: true });

392+

if (!stat.isFile()) {

393+

return null;

394+

}

395+

return [

396+

stat.dev.toString(),

397+

stat.ino.toString(),

398+

stat.size.toString(),

399+

stat.mtimeNs.toString(),

400+

].join(":");

401+

} catch {

402+

return null;

403+

}

404+

}

405+406+

function cacheRuntimeDepsJsonObject(

407+

filePath: string,

408+

signature: string | null,

409+

value: JsonObject | null,

410+

): void {

411+

if (!signature) {

412+

return;

413+

}

414+

rememberRuntimeDepsCacheEntry(runtimeDepsJsonObjectCache, filePath, { signature, value });

415+

}

416+417+

function rememberRuntimeDepsCacheEntry<T>(cache: Map<string, T>, key: string, value: T): void {

418+

if (cache.size >= MAX_RUNTIME_DEPS_FILE_CACHE_ENTRIES && !cache.has(key)) {

419+

cache.delete(cache.keys().next().value as string);

420+

}

421+

cache.set(key, value);

422+

}

423+293424

function sleepSync(ms: number): void {

294425

Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);

295426

}

@@ -686,9 +817,13 @@ function collectRootDistMirroredRuntimeDeps(params: {

686817

rootDir: distDir,

687818

skipTopLevelDirs: new Set(["extensions"]),

688819

})) {

689-

const source = fs.readFileSync(filePath, "utf8");

820+

const signature = getRuntimeDepsFileSignature(filePath);

821+

const source = readRuntimeDepsTextFile(filePath, signature);

822+

if (source === null) {

823+

continue;

824+

}

690825

const relativePath = path.relative(distDir, filePath).replaceAll(path.sep, "/");

691-

for (const specifier of extractStaticRuntimeImportSpecifiers(source)) {

826+

for (const specifier of readRuntimeDepsImportSpecifiers(filePath, signature, source)) {

692827

const dependencyName = packageNameFromSpecifier(specifier);

693828

if (!dependencyName) {

694829

continue;