Skip to content

Commit 411df59

Browse files
authored
fix(plugins): resolve official plugin install aliases
Resolve bare official external plugin IDs through the official catalog before generic npm fallback, preserving explicit npm semantics and catalog integrity through the hook-pack fallback.\n\nFixes #76373.\n\nThanks @bek91 and @vincentkoc.
1 parent f696be9 commit 411df59

6 files changed

Lines changed: 262 additions & 1 deletion

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Docs: https://docs.openclaw.ai
2222
- Docker/Gateway: pass Docker setup `.env` values into gateway and CLI containers and preserve exec SecretRef `passEnv` keys in managed service plans, so 1Password Connect-backed Discord tokens keep resolving after doctor or plugin repair. Thanks @vincentkoc.
2323
- Control UI/WebChat: explain compaction boundaries in chat history and link directly to session checkpoint controls so pre-compaction turns no longer look silently lost after refresh. Fixes #76415. Thanks @BunsDev.
2424
- Channels/WhatsApp: attach native outbound mention metadata for group text and media captions by resolving `@+<digits>` and `@<digits>` tokens against WhatsApp participant data, including LID groups. Fixes #39879; carries forward #56863. Thanks @kengi1437, @joe2643, and @fridayck.
25+
- Plugins/install: resolve bare official external plugin IDs such as `brave` through the official catalog when no bundled source is available, so packaged installs fetch the intended scoped npm package instead of an unrelated unscoped package. Fixes #76373. Thanks @bek91 and @vincentkoc.
2526
- Gateway/sessions: keep async `sessions.list` title and preview hydration bounded to transcript head/tail reads so Control UI polling cannot full-scan large session transcripts every refresh. Thanks @vincentkoc.
2627
- Gateway/sessions: keep agent runtime metadata on lightweight `sessions.list` rows so model-only session patches do not make Control UI lose runtime identity. Thanks @vincentkoc.
2728
- Gateway/sessions: keep bulk `sessions.list` rows lightweight by skipping per-row transcript usage fallback, display model inference, and plugin projection, avoiding event-loop stalls in large session stores. Thanks @Marvinthebored and @vincentkoc.

‎src/cli/plugin-install-plan.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
resolveBundledInstallPlanForCatalogEntry,
66
resolveBundledInstallPlanBeforeNpm,
77
resolveBundledInstallPlanForNpmFailure,
8+
resolveOfficialExternalInstallPlanBeforeNpm,
89
} from "./plugin-install-plan.js";
910

1011
describe("plugin install plan helpers", () => {
@@ -36,6 +37,55 @@ describe("plugin install plan helpers", () => {
3637
expect(result).toBeNull();
3738
});
3839

40+
it("resolves exact official external plugin ids before npm fallback", () => {
41+
const findOfficialExternalPlugin = vi.fn().mockReturnValue({
42+
pluginId: "brave",
43+
npmSpec: "@openclaw/brave-plugin",
44+
expectedIntegrity: "sha512-brave",
45+
});
46+
47+
const result = resolveOfficialExternalInstallPlanBeforeNpm({
48+
rawSpec: "brave",
49+
findOfficialExternalPlugin,
50+
});
51+
52+
expect(findOfficialExternalPlugin).toHaveBeenCalledWith("brave");
53+
expect(result).toEqual({
54+
pluginId: "brave",
55+
npmSpec: "@openclaw/brave-plugin",
56+
expectedIntegrity: "sha512-brave",
57+
});
58+
});
59+
60+
it("skips official external plan for explicit npm selectors", () => {
61+
const findOfficialExternalPlugin = vi.fn();
62+
63+
expect(
64+
resolveOfficialExternalInstallPlanBeforeNpm({
65+
rawSpec: "brave@beta",
66+
findOfficialExternalPlugin,
67+
}),
68+
).toBeNull();
69+
expect(
70+
resolveOfficialExternalInstallPlanBeforeNpm({
71+
rawSpec: "@openclaw/brave-plugin",
72+
findOfficialExternalPlugin,
73+
}),
74+
).toBeNull();
75+
expect(findOfficialExternalPlugin).not.toHaveBeenCalled();
76+
});
77+
78+
it("skips official external plan without an npm install spec", () => {
79+
const result = resolveOfficialExternalInstallPlanBeforeNpm({
80+
rawSpec: "brave",
81+
findOfficialExternalPlugin: vi.fn().mockReturnValue({
82+
pluginId: "brave",
83+
}),
84+
});
85+
86+
expect(result).toBeNull();
87+
});
88+
3989
it("prefers bundled catalog plugin by id before npm spec", () => {
4090
const findBundledSource = vi
4191
.fn()

‎src/cli/plugin-install-plan.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ type BundledLookup = (params: {
77
value: string;
88
}) => BundledPluginSource | undefined;
99

10+
type OfficialExternalPluginLookup = (pluginId: string) =>
11+
| {
12+
pluginId: string;
13+
npmSpec?: string;
14+
expectedIntegrity?: string;
15+
}
16+
| undefined;
17+
1018
function isBareNpmPackageName(spec: string): boolean {
1119
const trimmed = spec.trim();
1220
return /^[a-z0-9][a-z0-9-._~]*$/.test(trimmed);
@@ -65,6 +73,25 @@ export function resolveBundledInstallPlanBeforeNpm(params: {
6573
};
6674
}
6775

76+
export function resolveOfficialExternalInstallPlanBeforeNpm(params: {
77+
rawSpec: string;
78+
findOfficialExternalPlugin: OfficialExternalPluginLookup;
79+
}): { pluginId: string; npmSpec: string; expectedIntegrity?: string } | null {
80+
if (!isBareNpmPackageName(params.rawSpec)) {
81+
return null;
82+
}
83+
const entry = params.findOfficialExternalPlugin(params.rawSpec);
84+
const npmSpec = entry?.npmSpec?.trim();
85+
if (!entry?.pluginId || !npmSpec) {
86+
return null;
87+
}
88+
return {
89+
pluginId: entry.pluginId,
90+
npmSpec,
91+
...(entry.expectedIntegrity ? { expectedIntegrity: entry.expectedIntegrity } : {}),
92+
};
93+
}
94+
6895
export function resolveBundledInstallPlanForNpmFailure(params: {
6996
rawSpec: string;
7097
code?: string;

‎src/cli/plugins-cli-test-helpers.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const installPluginFromNpmSpec: AsyncUnknownMock = vi.fn();
7878
export const installPluginFromPath: AsyncUnknownMock = vi.fn();
7979
export const installPluginFromClawHub: AsyncUnknownMock = vi.fn();
8080
export const parseClawHubPluginSpec: Mock<ParseClawHubPluginSpecFn> = vi.fn();
81+
export const findBundledPluginSourceMock: UnknownMock = vi.fn();
8182
export const installHooksFromNpmSpec: AsyncUnknownMock = vi.fn();
8283
export const installHooksFromPath: AsyncUnknownMock = vi.fn();
8384
export const recordHookInstall: UnknownMock = vi.fn();
@@ -485,6 +486,26 @@ vi.mock("../plugins/install.js", () => ({
485486
)) as (typeof import("../plugins/install.js"))["installPluginFromPath"],
486487
}));
487488

489+
vi.mock("../plugins/bundled-sources.js", async (importOriginal) => {
490+
const actual = await importOriginal<typeof import("../plugins/bundled-sources.js")>();
491+
return {
492+
...actual,
493+
findBundledPluginSource: ((
494+
...args: Parameters<
495+
(typeof import("../plugins/bundled-sources.js"))["findBundledPluginSource"]
496+
>
497+
) => {
498+
if (findBundledPluginSourceMock.getMockImplementation()) {
499+
return invokeMock<
500+
Parameters<(typeof import("../plugins/bundled-sources.js"))["findBundledPluginSource"]>,
501+
ReturnType<(typeof import("../plugins/bundled-sources.js"))["findBundledPluginSource"]>
502+
>(findBundledPluginSourceMock, ...args);
503+
}
504+
return actual.findBundledPluginSource(...args);
505+
}) as (typeof import("../plugins/bundled-sources.js"))["findBundledPluginSource"],
506+
};
507+
});
508+
488509
vi.mock("../plugins/git-install.js", () => ({
489510
installPluginFromGitSpec: ((
490511
...args: Parameters<(typeof import("../plugins/git-install.js"))["installPluginFromGitSpec"]>
@@ -621,6 +642,7 @@ export function resetPluginsCliTestState() {
621642
installPluginFromPath.mockReset();
622643
installPluginFromClawHub.mockReset();
623644
parseClawHubPluginSpec.mockReset();
645+
findBundledPluginSourceMock.mockReset();
624646
installHooksFromNpmSpec.mockReset();
625647
installHooksFromPath.mockReset();
626648
recordHookInstall.mockReset();

‎src/cli/plugins-cli.install.test.ts‎

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
applyExclusiveSlotSelection,
99
buildPluginSnapshotReport,
1010
enablePluginInConfig,
11+
findBundledPluginSourceMock,
1112
installHooksFromNpmSpec,
1213
installHooksFromPath,
1314
installPluginFromClawHub,
@@ -652,7 +653,91 @@ describe("plugins cli install", () => {
652653
});
653654
});
654655

655-
it("installs bare plugin specs through npm without ClawHub lookup", async () => {
656+
it("resolves exact official external plugin ids through their npm package", async () => {
657+
const cfg = createEmptyPluginConfig();
658+
const enabledCfg = createEnabledPluginConfig("brave");
659+
loadConfig.mockReturnValue(cfg);
660+
findBundledPluginSourceMock.mockReturnValue(undefined);
661+
installPluginFromNpmSpec.mockResolvedValue(createNpmPluginInstallResult("brave"));
662+
enablePluginInConfig.mockReturnValue({ config: enabledCfg });
663+
applyExclusiveSlotSelection.mockReturnValue({
664+
config: enabledCfg,
665+
warnings: [],
666+
});
667+
668+
await runPluginsCommand(["plugins", "install", "brave"]);
669+
670+
expect(findBundledPluginSourceMock).toHaveBeenCalledWith({
671+
lookup: { kind: "pluginId", value: "brave" },
672+
});
673+
expect(installPluginFromClawHub).not.toHaveBeenCalled();
674+
expect(installPluginFromNpmSpec).toHaveBeenCalledWith(
675+
expect.objectContaining({
676+
spec: "@openclaw/brave-plugin",
677+
expectedPluginId: "brave",
678+
}),
679+
);
680+
expect(writePersistedInstalledPluginIndexInstallRecords).toHaveBeenCalledWith({
681+
brave: expect.objectContaining({
682+
source: "npm",
683+
spec: "@openclaw/brave-plugin",
684+
installPath: cliInstallPath("brave"),
685+
version: "1.2.3",
686+
}),
687+
});
688+
expect(writeConfigFile).toHaveBeenCalledWith(enabledCfg);
689+
});
690+
691+
it("passes official external catalog integrity to npm installs", async () => {
692+
const cfg = createEmptyPluginConfig();
693+
const enabledCfg = createEnabledPluginConfig("wecom");
694+
loadConfig.mockReturnValue(cfg);
695+
findBundledPluginSourceMock.mockReturnValue(undefined);
696+
installPluginFromNpmSpec.mockResolvedValue(createNpmPluginInstallResult("wecom"));
697+
enablePluginInConfig.mockReturnValue({ config: enabledCfg });
698+
applyExclusiveSlotSelection.mockReturnValue({
699+
config: enabledCfg,
700+
warnings: [],
701+
});
702+
703+
await runPluginsCommand(["plugins", "install", "wecom"]);
704+
705+
expect(installPluginFromNpmSpec).toHaveBeenCalledWith(
706+
expect.objectContaining({
707+
spec: "@wecom/[email protected]",
708+
expectedPluginId: "wecom",
709+
expectedIntegrity:
710+
"sha512-bnzfdIEEu1/LFvcdyjaTkyxt27w6c7dqhkPezU62OWaqmcdFsUGR3T55USK/O9pIKsNcnL1Tnu1pqKYCWHFgWQ==",
711+
}),
712+
);
713+
});
714+
715+
it("passes official external catalog integrity to hook-pack fallback", async () => {
716+
loadConfig.mockReturnValue(createEmptyPluginConfig());
717+
findBundledPluginSourceMock.mockReturnValue(undefined);
718+
installPluginFromNpmSpec.mockResolvedValue({
719+
ok: false,
720+
error: "package.json missing openclaw.extensions",
721+
code: "missing_openclaw_extensions",
722+
});
723+
installHooksFromNpmSpec.mockResolvedValue({
724+
ok: false,
725+
error:
726+
"aborted: npm package integrity drift detected for @wecom/[email protected]",
727+
});
728+
729+
await expect(runPluginsCommand(["plugins", "install", "wecom"])).rejects.toThrow("__exit__:1");
730+
731+
expect(installHooksFromNpmSpec).toHaveBeenCalledWith(
732+
expect.objectContaining({
733+
spec: "@wecom/[email protected]",
734+
expectedIntegrity:
735+
"sha512-bnzfdIEEu1/LFvcdyjaTkyxt27w6c7dqhkPezU62OWaqmcdFsUGR3T55USK/O9pIKsNcnL1Tnu1pqKYCWHFgWQ==",
736+
}),
737+
);
738+
});
739+
740+
it("installs ordinary bare plugin specs through npm without ClawHub lookup", async () => {
656741
const cfg = createEmptyPluginConfig();
657742
const enabledCfg = createEnabledPluginConfig("demo");
658743
loadConfig.mockReturnValue(cfg);
@@ -735,6 +820,34 @@ describe("plugins cli install", () => {
735820
expect(writeConfigFile).toHaveBeenCalledWith(enabledCfg);
736821
});
737822

823+
it("keeps npm-prefixed official plugin ids on explicit npm semantics", async () => {
824+
const cfg = createEmptyPluginConfig();
825+
const enabledCfg = createEnabledPluginConfig("brave");
826+
827+
loadConfig.mockReturnValue(cfg);
828+
installPluginFromNpmSpec.mockResolvedValue(createNpmPluginInstallResult("brave"));
829+
enablePluginInConfig.mockReturnValue({ config: enabledCfg });
830+
recordPluginInstall.mockReturnValue(enabledCfg);
831+
applyExclusiveSlotSelection.mockReturnValue({
832+
config: enabledCfg,
833+
warnings: [],
834+
});
835+
836+
await runPluginsCommand(["plugins", "install", "npm:brave"]);
837+
838+
expect(installPluginFromNpmSpec).toHaveBeenCalledWith(
839+
expect.objectContaining({
840+
spec: "brave",
841+
}),
842+
);
843+
expect(installPluginFromNpmSpec).toHaveBeenCalledWith(
844+
expect.not.objectContaining({
845+
expectedPluginId: "brave",
846+
}),
847+
);
848+
expect(installPluginFromClawHub).not.toHaveBeenCalled();
849+
});
850+
738851
it("passes the active profile extensions dir to npm installs", async () => {
739852
const extensionsDir = useProfileExtensionsDir();
740853
const cfg = createEmptyPluginConfig();

‎src/cli/plugins-install-command.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import {
2121
installPluginFromMarketplace,
2222
resolveMarketplaceInstallShortcut,
2323
} from "../plugins/marketplace.js";
24+
import {
25+
getOfficialExternalPluginCatalogEntry,
26+
resolveOfficialExternalPluginId,
27+
resolveOfficialExternalPluginInstall,
28+
} from "../plugins/official-external-plugin-catalog.js";
2429
import { tracePluginLifecyclePhaseAsync } from "../plugins/plugin-lifecycle-trace.js";
2530
import { validateJsonSchemaValue } from "../plugins/schema-validator.js";
2631
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
@@ -36,6 +41,7 @@ import {
3641
import {
3742
resolveBundledInstallPlanBeforeNpm,
3843
resolveBundledInstallPlanForNpmFailure,
44+
resolveOfficialExternalInstallPlanBeforeNpm,
3945
} from "./plugin-install-plan.js";
4046
import {
4147
createHookPackInstallLogger,
@@ -231,11 +237,13 @@ async function tryInstallHookPackFromNpmSpec(params: {
231237
installMode: "install" | "update";
232238
spec: string;
233239
pin?: boolean;
240+
expectedIntegrity?: string;
234241
runtime?: RuntimeEnv;
235242
}): Promise<{ ok: true } | { ok: false; error: string }> {
236243
const result = await installHooksFromNpmSpec({
237244
spec: params.spec,
238245
mode: params.installMode,
246+
...(params.expectedIntegrity ? { expectedIntegrity: params.expectedIntegrity } : {}),
239247
logger: createHookPackInstallLogger(params.runtime),
240248
});
241249
if (!result.ok) {
@@ -269,12 +277,16 @@ async function tryInstallPluginOrHookPackFromNpmSpec(params: {
269277
safetyOverrides: InstallSafetyOverrides;
270278
allowBundledFallback: boolean;
271279
extensionsDir: string;
280+
expectedPluginId?: string;
281+
expectedIntegrity?: string;
272282
runtime?: RuntimeEnv;
273283
}): Promise<{ ok: true } | { ok: false }> {
274284
const result = await installPluginFromNpmSpec({
275285
...params.safetyOverrides,
276286
mode: params.installMode,
277287
spec: params.spec,
288+
...(params.expectedPluginId ? { expectedPluginId: params.expectedPluginId } : {}),
289+
...(params.expectedIntegrity ? { expectedIntegrity: params.expectedIntegrity } : {}),
278290
extensionsDir: params.extensionsDir,
279291
logger: createPluginInstallLogger(params.runtime),
280292
});
@@ -305,6 +317,7 @@ async function tryInstallPluginOrHookPackFromNpmSpec(params: {
305317
installMode: params.installMode,
306318
spec: params.spec,
307319
pin: params.pin,
320+
expectedIntegrity: params.expectedIntegrity,
308321
runtime: params.runtime,
309322
});
310323
if (hookFallback.ok) {
@@ -747,6 +760,41 @@ export async function runPluginInstallCommand(params: {
747760
return;
748761
}
749762

763+
const officialExternalPlan = resolveOfficialExternalInstallPlanBeforeNpm({
764+
rawSpec: raw,
765+
findOfficialExternalPlugin: (pluginId) => {
766+
const entry = getOfficialExternalPluginCatalogEntry(pluginId);
767+
const resolvedPluginId = entry ? resolveOfficialExternalPluginId(entry) : undefined;
768+
const install = entry ? resolveOfficialExternalPluginInstall(entry) : null;
769+
const npmSpec = install?.npmSpec;
770+
return resolvedPluginId && npmSpec
771+
? {
772+
pluginId: resolvedPluginId,
773+
npmSpec,
774+
...(install.expectedIntegrity ? { expectedIntegrity: install.expectedIntegrity } : {}),
775+
}
776+
: undefined;
777+
},
778+
});
779+
if (officialExternalPlan) {
780+
const npmResult = await tryInstallPluginOrHookPackFromNpmSpec({
781+
snapshot,
782+
installMode,
783+
spec: officialExternalPlan.npmSpec,
784+
pin: opts.pin,
785+
safetyOverrides,
786+
allowBundledFallback: false,
787+
extensionsDir,
788+
expectedPluginId: officialExternalPlan.pluginId,
789+
expectedIntegrity: officialExternalPlan.expectedIntegrity,
790+
runtime,
791+
});
792+
if (!npmResult.ok) {
793+
return runtime.exit(1);
794+
}
795+
return;
796+
}
797+
750798
const clawhubSpec = parseClawHubPluginSpec(raw);
751799
if (clawhubSpec) {
752800
const result = await installPluginFromClawHub({

0 commit comments

Comments
 (0)