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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
雷峰网
雷峰网
博客园_首页
小众软件
小众软件
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
U
Unit 42
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure 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): recover managed npm install ledger · opencl...
steipete · 2026-05-04 · via Recent Commits to openclaw:main

@@ -1,5 +1,8 @@

1+

import fs from "node:fs";

2+

import path from "node:path";

13

import type { PluginInstallRecord } from "../config/types.plugins.js";

24

import { readJsonFile, readJsonFileSync } from "../infra/json-files.js";

5+

import { resolveDefaultPluginNpmDir, validatePluginId } from "./install-paths.js";

36

import {

47

resolveInstalledPluginIndexStorePath,

58

type InstalledPluginIndexStoreOptions,

@@ -30,6 +33,111 @@ function readRecordMap(value: unknown): Record<string, PluginInstallRecord> | nu

3033

return records;

3134

}

323536+

function readJsonObjectFileSync(filePath: string): Record<string, unknown> | null {

37+

try {

38+

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

39+

return isRecord(parsed) ? parsed : null;

40+

} catch {

41+

return null;

42+

}

43+

}

44+45+

function readStringRecord(value: unknown): Record<string, string> {

46+

if (!isRecord(value)) {

47+

return {};

48+

}

49+

const record: Record<string, string> = {};

50+

for (const [key, raw] of Object.entries(value).toSorted(([left], [right]) =>

51+

left.localeCompare(right),

52+

)) {

53+

if (typeof raw === "string" && raw.trim()) {

54+

record[key] = raw.trim();

55+

}

56+

}

57+

return record;

58+

}

59+60+

function hasPackagePluginMetadata(manifest: Record<string, unknown>): boolean {

61+

const openclaw = manifest.openclaw;

62+

if (!isRecord(openclaw)) {

63+

return false;

64+

}

65+

const extensions = openclaw.extensions;

66+

return Array.isArray(extensions) && extensions.some((entry) => typeof entry === "string");

67+

}

68+69+

function readManifestPluginId(packageDir: string): string | undefined {

70+

const manifest = readJsonObjectFileSync(path.join(packageDir, "openclaw.plugin.json"));

71+

const id = typeof manifest?.id === "string" ? manifest.id.trim() : "";

72+

return id || undefined;

73+

}

74+75+

function resolveRecoveredManagedNpmPluginId(params: {

76+

packageName: string;

77+

packageDir: string;

78+

}): string | undefined {

79+

const packageManifest = readJsonObjectFileSync(path.join(params.packageDir, "package.json"));

80+

if (!packageManifest || !hasPackagePluginMetadata(packageManifest)) {

81+

return undefined;

82+

}

83+

const packageName =

84+

typeof packageManifest.name === "string" && packageManifest.name.trim()

85+

? packageManifest.name.trim()

86+

: params.packageName;

87+

const pluginId = readManifestPluginId(params.packageDir) ?? packageName;

88+

return validatePluginId(pluginId) ? undefined : pluginId;

89+

}

90+91+

function buildRecoveredManagedNpmInstallRecords(

92+

options: InstalledPluginIndexStoreOptions = {},

93+

): Record<string, PluginInstallRecord> {

94+

const npmRoot = options.stateDir

95+

? path.join(options.stateDir, "npm")

96+

: resolveDefaultPluginNpmDir(options.env);

97+

const rootManifest = readJsonObjectFileSync(path.join(npmRoot, "package.json"));

98+

const dependencies = readStringRecord(rootManifest?.dependencies);

99+

const records: Record<string, PluginInstallRecord> = {};

100+

for (const [packageName, dependencySpec] of Object.entries(dependencies)) {

101+

const packageDir = path.join(npmRoot, "node_modules", packageName);

102+

let stat: fs.Stats;

103+

try {

104+

stat = fs.statSync(packageDir);

105+

} catch {

106+

continue;

107+

}

108+

if (!stat.isDirectory()) {

109+

continue;

110+

}

111+

const pluginId = resolveRecoveredManagedNpmPluginId({ packageName, packageDir });

112+

if (!pluginId) {

113+

continue;

114+

}

115+

const packageManifest = readJsonObjectFileSync(path.join(packageDir, "package.json"));

116+

const version =

117+

typeof packageManifest?.version === "string" && packageManifest.version.trim()

118+

? packageManifest.version.trim()

119+

: undefined;

120+

records[pluginId] = {

121+

source: "npm",

122+

spec: `${packageName}@${dependencySpec}`,

123+

installPath: packageDir,

124+

...(version ? { version, resolvedName: packageName, resolvedVersion: version } : {}),

125+

...(version ? { resolvedSpec: `${packageName}@${version}` } : {}),

126+

};

127+

}

128+

return records;

129+

}

130+131+

function mergeRecoveredManagedNpmInstallRecords(

132+

persisted: Record<string, PluginInstallRecord> | null,

133+

options: InstalledPluginIndexStoreOptions,

134+

): Record<string, PluginInstallRecord> {

135+

return {

136+

...buildRecoveredManagedNpmInstallRecords(options),

137+

...persisted,

138+

};

139+

}

140+33141

function extractPluginInstallRecordsFromPersistedInstalledPluginIndex(

34142

index: unknown,

35143

): Record<string, PluginInstallRecord> | null {

@@ -66,11 +174,21 @@ export function readPersistedInstalledPluginIndexInstallRecordsSync(

66174

export async function loadInstalledPluginIndexInstallRecords(

67175

params: InstalledPluginIndexStoreOptions = {},

68176

): Promise<Record<string, PluginInstallRecord>> {

69-

return cloneInstallRecords((await readPersistedInstalledPluginIndexInstallRecords(params)) ?? {});

177+

return cloneInstallRecords(

178+

mergeRecoveredManagedNpmInstallRecords(

179+

await readPersistedInstalledPluginIndexInstallRecords(params),

180+

params,

181+

),

182+

);

70183

}

7118472185

export function loadInstalledPluginIndexInstallRecordsSync(

73186

params: InstalledPluginIndexStoreOptions = {},

74187

): Record<string, PluginInstallRecord> {

75-

return cloneInstallRecords(readPersistedInstalledPluginIndexInstallRecordsSync(params) ?? {});

188+

return cloneInstallRecords(

189+

mergeRecoveredManagedNpmInstallRecords(

190+

readPersistedInstalledPluginIndexInstallRecordsSync(params),

191+

params,

192+

),

193+

);

76194

}