Skip to content

Commit 2ea0e88

Browse files
ooiuuiivincentkoc
andauthored
fix(cli): show working commands for pinned plugin drift (#95541)
Merged via squash. Prepared head SHA: d41b9b5 Co-authored-by: ooiuuii <[email protected]> Co-authored-by: vincentkoc <[email protected]> Reviewed-by: @vincentkoc
1 parent 77d0dee commit 2ea0e88

6 files changed

Lines changed: 210 additions & 15 deletions

File tree

‎src/cli/daemon-cli/status.print.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,43 @@ describe("printDaemonStatus", () => {
649649
);
650650

651651
expectMockLineContains(runtime.log, "- whatsapp: 2026.5.3 (clawhub)");
652-
expectMockLineContains(runtime.log, "openclaw plugins update <plugin-id>");
652+
expectMockLineContains(runtime.log, "openclaw plugins update whatsapp");
653+
expectMockLineContains(runtime.log, "openclaw gateway restart");
654+
});
655+
656+
it("prints exact package update commands for pinned npm plugin drift in deep mode", () => {
657+
printDaemonStatus(
658+
{
659+
service: {
660+
label: "LaunchAgent",
661+
loaded: true,
662+
loadedText: "loaded",
663+
notLoadedText: "not loaded",
664+
runtime: { status: "running", pid: 8000 },
665+
},
666+
pluginVersionDrift: {
667+
gatewayVersion: "2026.6.10-beta.1",
668+
drifts: [
669+
{
670+
pluginId: "brave",
671+
installedVersion: "2026.6.9",
672+
gatewayVersion: "2026.6.10-beta.1",
673+
source: "npm",
674+
packageName: "@openclaw/brave-plugin",
675+
spec: "@openclaw/[email protected]",
676+
},
677+
],
678+
},
679+
extraServices: [],
680+
},
681+
{ json: false, deep: true },
682+
);
683+
684+
expectMockLineContains(runtime.log, "- brave: 2026.6.9 (npm)");
685+
expectMockLineContains(
686+
runtime.log,
687+
"openclaw plugins update @openclaw/[email protected]",
688+
);
653689
expectMockLineContains(runtime.log, "openclaw gateway restart");
654690
});
655691

‎src/cli/daemon-cli/status.print.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { classifySystemdUnavailableDetail } from "../../daemon/systemd-unavailab
1818
import { resolveControlUiLinks } from "../../gateway/control-ui-links.js";
1919
import { formatGatewayRestartHandoffDiagnostic } from "../../infra/restart-handoff.js";
2020
import { isWSLEnv } from "../../infra/wsl.js";
21+
import { resolvePluginVersionDriftUpdateCommand } from "../../plugins/plugin-version-drift.js";
2122
import { defaultRuntime } from "../../runtime.js";
2223
import { shortenHomePath } from "../../utils.js";
2324
import { formatCliCommand } from "../command-format.js";
@@ -327,9 +328,7 @@ export function printDaemonStatus(status: DaemonStatus, opts: { json: boolean; d
327328
isSystemdUnavailableDetail(service.runtime?.detail);
328329
if (systemdUnavailable) {
329330
const serviceEnv = service.command?.environment ?? process.env;
330-
const container = Boolean(
331-
resolveDaemonContainerContext(serviceEnv),
332-
);
331+
const container = Boolean(resolveDaemonContainerContext(serviceEnv));
333332
defaultRuntime.error(errorText("systemd user services unavailable."));
334333
for (const hint of renderSystemdUnavailableHints({
335334
wsl: isWSLEnv(serviceEnv),
@@ -483,9 +482,20 @@ export function printDaemonStatus(status: DaemonStatus, opts: { json: boolean; d
483482
`- ${warnText(entry.pluginId)}: ${entry.installedVersion} (${sourceLabel}) → expected ${drift.gatewayVersion}`,
484483
);
485484
}
486-
defaultRuntime.log(
487-
`${label("Fix:")} ${formatCliCommand("openclaw plugins update <plugin-id>")} for each drifted plugin, then ${formatCliCommand("openclaw gateway restart")}.`,
485+
const updateCommands = drift.drifts.map((entry) =>
486+
formatCliCommand(resolvePluginVersionDriftUpdateCommand(entry)),
488487
);
488+
if (updateCommands.length === 1) {
489+
defaultRuntime.log(
490+
`${label("Fix:")} ${updateCommands[0]} && ${formatCliCommand("openclaw gateway restart")}.`,
491+
);
492+
} else {
493+
defaultRuntime.log(`${label("Fix:")} update each drifted plugin:`);
494+
for (const command of updateCommands) {
495+
defaultRuntime.log(`- ${command}`);
496+
}
497+
defaultRuntime.log(`Then run ${formatCliCommand("openclaw gateway restart")}.`);
498+
}
489499
} else {
490500
defaultRuntime.log(
491501
infoText(

‎src/commands/doctor-workspace-status.test.ts‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,54 @@ describe("noteWorkspaceStatus", () => {
205205
}
206206
});
207207

208+
it("uses package-version update commands for exact npm plugin drift", async () => {
209+
const noteSpy = await runNoteWorkspaceStatusForTest(
210+
createPluginLoadResult({
211+
plugins: [
212+
createPluginRecord({
213+
id: "brave",
214+
name: "Brave",
215+
origin: "global",
216+
source: "/tmp/brave/index.js",
217+
}),
218+
],
219+
}),
220+
[],
221+
{
222+
cfg: {
223+
plugins: {
224+
entries: {
225+
brave: { enabled: true },
226+
},
227+
},
228+
},
229+
pluginVersionDrift: {
230+
gatewayVersion: "2026.6.10-beta.1",
231+
drifts: [
232+
{
233+
pluginId: "brave",
234+
installedVersion: "2026.6.9",
235+
gatewayVersion: "2026.6.10-beta.1",
236+
source: "npm",
237+
packageName: "@openclaw/brave-plugin",
238+
spec: "@openclaw/[email protected]",
239+
},
240+
],
241+
},
242+
},
243+
);
244+
try {
245+
const driftCalls = noteSpy.mock.calls.filter(([, title]) => title === "Plugin version drift");
246+
expect(driftCalls).toHaveLength(1);
247+
const [[body]] = driftCalls;
248+
expect(body).toContain("openclaw plugins update @openclaw/[email protected]");
249+
expect(body).not.toContain("openclaw plugins update brave");
250+
expect(body).toContain("openclaw gateway restart");
251+
} finally {
252+
noteSpy.mockRestore();
253+
}
254+
});
255+
208256
it("omits plugin version drift when no daemon status report is supplied", async () => {
209257
const noteSpy = await runNoteWorkspaceStatusForTest(
210258
createPluginLoadResult({
@@ -324,7 +372,10 @@ describe("noteWorkspaceStatus", () => {
324372
}
325373
});
326374

327-
const makeSkill = (skillKey: string, fields: { eligible: boolean; platformIncompatible: boolean }) =>
375+
const makeSkill = (
376+
skillKey: string,
377+
fields: { eligible: boolean; platformIncompatible: boolean },
378+
) =>
328379
({
329380
skillKey,
330381
disabled: false,

‎src/commands/doctor-workspace-status.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { note } from "../../packages/terminal-core/src/note.js";
33
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
44
import { formatCliCommand } from "../cli/command-format.js";
55
import type { OpenClawConfig } from "../config/types.openclaw.js";
6-
import type { PluginVersionDriftReport } from "../plugins/plugin-version-drift.js";
6+
import {
7+
resolvePluginVersionDriftUpdateCommand,
8+
type PluginVersionDriftReport,
9+
} from "../plugins/plugin-version-drift.js";
710
import {
811
buildPluginCompatibilityWarnings,
912
buildPluginRegistrySnapshotReport,
@@ -62,6 +65,9 @@ function notePluginVersionDrift(drift: PluginVersionDriftReport | undefined) {
6265
return;
6366
}
6467
const singleDrift = drift.drifts.length === 1 ? drift.drifts[0] : undefined;
68+
const updateCommands = drift.drifts.map((entry) =>
69+
formatCliCommand(resolvePluginVersionDriftUpdateCommand(entry)),
70+
);
6571
const lines = [
6672
`${drift.drifts.length} active official plugin${
6773
drift.drifts.length === 1 ? "" : "s"
@@ -71,12 +77,12 @@ function notePluginVersionDrift(drift: PluginVersionDriftReport | undefined) {
7177
return `- ${entry.pluginId}: ${entry.installedVersion} (${sourceLabel}) -> expected ${drift.gatewayVersion}`;
7278
}),
7379
singleDrift
74-
? `Fix: ${formatCliCommand(
75-
`openclaw plugins update ${singleDrift.pluginId}`,
76-
)} && ${formatCliCommand("openclaw gateway restart")}.`
77-
: `Fix: ${formatCliCommand(
78-
"openclaw plugins update <plugin-id>",
79-
)} for each drifted plugin, then ${formatCliCommand("openclaw gateway restart")}.`,
80+
? `Fix: ${updateCommands[0]} && ${formatCliCommand("openclaw gateway restart")}.`
81+
: [
82+
"Fix each drifted plugin:",
83+
...updateCommands.map((command) => `- ${command}`),
84+
`Then run ${formatCliCommand("openclaw gateway restart")}.`,
85+
].join("\n"),
8086
];
8187
note(lines.join("\n"), "Plugin version drift");
8288
}

‎src/plugins/plugin-version-drift.test.ts‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import { describe, expect, it } from "vitest";
33
import type { OpenClawConfig } from "../config/types.js";
44
import type { PluginInstallRecord } from "../config/types.plugins.js";
5-
import { detectPluginVersionDrift } from "./plugin-version-drift.js";
5+
import {
6+
detectPluginVersionDrift,
7+
resolvePluginVersionDriftUpdateCommand,
8+
} from "./plugin-version-drift.js";
69

710
function npmRecord(
811
version: string,
@@ -318,3 +321,69 @@ describe("detectPluginVersionDrift", () => {
318321
expect(result.drifts.map((d) => d.pluginId)).toEqual(["discord", "matrix", "whatsapp"]);
319322
});
320323
});
324+
325+
describe("resolvePluginVersionDriftUpdateCommand", () => {
326+
it("uses an exact npm package target when the drifted install is pinned", () => {
327+
expect(
328+
resolvePluginVersionDriftUpdateCommand({
329+
pluginId: "brave",
330+
installedVersion: "2026.6.9",
331+
gatewayVersion: "2026.6.10-beta.1",
332+
source: "npm",
333+
packageName: "@openclaw/brave-plugin",
334+
spec: "@openclaw/[email protected]",
335+
}),
336+
).toBe("openclaw plugins update @openclaw/[email protected]");
337+
});
338+
339+
it("parses the package name from exact npm specs when drift metadata is sparse", () => {
340+
expect(
341+
resolvePluginVersionDriftUpdateCommand({
342+
pluginId: "brave",
343+
installedVersion: "2026.6.9",
344+
gatewayVersion: "2026.6.10-beta.1",
345+
source: "npm",
346+
spec: "@openclaw/[email protected]",
347+
}),
348+
).toBe("openclaw plugins update @openclaw/[email protected]");
349+
});
350+
351+
it("prefers the parsed exact npm spec package over inconsistent drift metadata", () => {
352+
expect(
353+
resolvePluginVersionDriftUpdateCommand({
354+
pluginId: "brave",
355+
installedVersion: "2026.6.9",
356+
gatewayVersion: "2026.6.10-beta.1",
357+
source: "npm",
358+
packageName: "@openclaw/other-plugin",
359+
spec: "@openclaw/[email protected]",
360+
}),
361+
).toBe("openclaw plugins update @openclaw/[email protected]");
362+
});
363+
364+
it("keeps plugin-id updates for floating npm install records", () => {
365+
expect(
366+
resolvePluginVersionDriftUpdateCommand({
367+
pluginId: "brave",
368+
installedVersion: "2026.6.9",
369+
gatewayVersion: "2026.6.10-beta.1",
370+
source: "npm",
371+
packageName: "@openclaw/brave-plugin",
372+
spec: "@openclaw/brave-plugin",
373+
}),
374+
).toBe("openclaw plugins update brave");
375+
});
376+
377+
it("keeps plugin-id updates when the gateway version is not a registry version", () => {
378+
expect(
379+
resolvePluginVersionDriftUpdateCommand({
380+
pluginId: "brave",
381+
installedVersion: "2026.6.9",
382+
gatewayVersion: "unknown",
383+
source: "npm",
384+
packageName: "@openclaw/brave-plugin",
385+
spec: "@openclaw/[email protected]",
386+
}),
387+
).toBe("openclaw plugins update brave");
388+
});
389+
});

‎src/plugins/plugin-version-drift.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ export type PluginVersionDriftReport = {
2323
drifts: PluginVersionDriftEntry[];
2424
};
2525

26+
function resolveExactNpmPinPackageName(entry: PluginVersionDriftEntry): string | undefined {
27+
if (entry.source !== "npm" || !entry.spec) {
28+
return undefined;
29+
}
30+
const parsed = parseRegistryNpmSpec(entry.spec);
31+
if (parsed?.selectorKind !== "exact-version") {
32+
return undefined;
33+
}
34+
return parsed.name;
35+
}
36+
37+
/** Exact npm pins need a package@version target; id-only updates preserve the old pin. */
38+
export function resolvePluginVersionDriftUpdateCommand(entry: PluginVersionDriftEntry): string {
39+
const exactNpmPackageName = resolveExactNpmPinPackageName(entry);
40+
if (exactNpmPackageName) {
41+
const exactNpmTarget = `${exactNpmPackageName}@${entry.gatewayVersion}`;
42+
if (parseRegistryNpmSpec(exactNpmTarget)?.selectorKind === "exact-version") {
43+
return `openclaw plugins update ${exactNpmTarget}`;
44+
}
45+
}
46+
return `openclaw plugins update ${entry.pluginId}`;
47+
}
48+
2649
/**
2750
* Strip a trailing build qualifier (e.g. `2026.5.4-1` -> `2026.5.4`) so that
2851
* a gateway packaged as `2026.5.4-1` is not reported as drifted from a

0 commit comments

Comments
 (0)