Skip to content

Commit f2646be

Browse files
authored
docs: clarify disabled plugin reinstall behavior (#134875)
* docs: clarify disabled plugin reinstall behavior * docs: distinguish update consent from plugin activation
1 parent e6ae941 commit f2646be

5 files changed

Lines changed: 75 additions & 16 deletions

File tree

‎docs/cli/plugins.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ third-party packages, and non-npm sources are not rewritten.
198198
<Accordion title="--force confirmation and reinstall vs update">
199199
`--force` confirms a non-ClawHub source without prompting. It does not bypass `security.installPolicy` or remaining install safety checks. When the plugin or hook pack is already installed, it also reuses the existing target and overwrites it in place. Use it after reviewing an arbitrary npm, local, archive, git, or marketplace source, or when intentionally reinstalling the same id. For routine upgrades of an already tracked npm plugin, prefer `openclaw plugins update <id-or-npm-spec>`.
200200

201+
Reinstalling preserves an authored `plugins.entries.<id>.enabled: false`. `--force` does not approve capabilities: when no valid prior acceptance can be reused, review and accept them before the install commits. Use `openclaw plugins enable <id>` to activate the plugin afterward. See [Capability consent](/plugins/manage-plugins#capability-consent).
202+
201203
If you run `plugins install` for a plugin id that is already installed, OpenClaw stops and points you at `plugins update <id-or-npm-spec>` for a normal upgrade, or at `plugins install <package> --force` when you genuinely want to overwrite the current install from a different source. Arbitrary sources still show the interactive provenance warning; noninteractive installs must pass `--force` after review. Trusted ClawHub and OpenClaw-catalog sources do not need it. With `--link`, `--force` confirms the source but does not change the linked-path install mode.
202204

203205
</Accordion>

‎docs/plugins/manage-plugins.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ enabled plugins require fresh consent when the new artifact declares additional
126126
capabilities; unchanged or narrower
127127
surfaces can refresh an existing valid acceptance. Updating a disabled
128128
plugin preserves disablement and defers any required consent until enablement.
129-
Reinstalling through `plugins install` activates the plugin and must satisfy
130-
consent before activation.
129+
Reinstalling through `plugins install` also preserves an authored `enabled: false`,
130+
but requires consent before committing the install when no valid acceptance can
131+
be reused. Run `openclaw plugins enable <plugin-id>` to activate it afterward.
131132

132133
Already-enabled third-party legacy installations remain usable without an initial review;
133134
disabling and re-enabling them requires consent. Setup rechecks consent when

‎scripts/e2e/lib/plugin-update/consent-scenario.mjs‎

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ import os from "node:os";
88
import path from "node:path";
99
import { setTimeout as delay } from "node:timers/promises";
1010
import { fixtureCapabilityConsentArgs } from "../package-compat.mjs";
11+
import { readPluginInstallIndex } from "../plugin-index-sqlite.mjs";
1112
import { observePostCoreCommand } from "./process-observer.mjs";
1213

14+
// Without a core tarball, run only the plugin reinstall boundary against the supplied CLI.
1315
export async function runConsentScenario(entry, coreTarball) {
14-
assert(entry && coreTarball, "expected installed entry and canonical core tarball");
15-
const coreHash = createHash("sha256");
16-
for await (const chunk of fs.createReadStream(coreTarball)) {
17-
coreHash.update(chunk);
16+
assert(entry, "expected CLI entry");
17+
let coreTarballSha256;
18+
if (coreTarball) {
19+
const coreHash = createHash("sha256");
20+
for await (const chunk of fs.createReadStream(coreTarball)) {
21+
coreHash.update(chunk);
22+
}
23+
coreTarballSha256 = coreHash.digest("hex");
1824
}
19-
const coreTarballSha256 = coreHash.digest("hex");
2025
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-update-consent-"));
2126
const pluginId = "update-consent-fixture";
2227
const packageName = `@acme/${pluginId}`;
@@ -147,16 +152,19 @@ export async function runConsentScenario(entry, coreTarball) {
147152
process.env.npm_config_registry = process.env.NPM_CONFIG_REGISTRY;
148153
}
149154

150-
async function snapshot(label, version) {
155+
async function snapshot(label, version, enabled = true) {
151156
const report = JSON.parse(
152157
(await cli(label, ["plugins", "inspect", pluginId, "--runtime", "--json"])).output,
153158
);
154-
assert.equal(report.plugin.status, "loaded");
159+
assert.equal(report.plugin.status, enabled ? "loaded" : "disabled");
160+
assert.equal(report.plugin.enabled, enabled);
161+
const config = JSON.parse(fs.readFileSync(process.env.OPENCLAW_CONFIG_PATH, "utf8"));
162+
assert.equal(config.plugins.entries[pluginId].enabled, enabled);
155163
const record = report.install;
156164
assert.equal(record.version, `${version}.0.0`);
157165
assert.deepEqual(
158166
report.tools.flatMap((tool) => tool.names).toSorted(),
159-
expectedSurface(version).tools,
167+
enabled ? expectedSurface(version).tools : [],
160168
);
161169
const surface = expectedSurface(version);
162170
assert.deepEqual(record.acceptedSurface, surface);
@@ -169,8 +177,11 @@ export async function runConsentScenario(entry, coreTarball) {
169177
assert(record.acceptedSurfaceAt);
170178
const bytes = fs.readFileSync(path.join(record.installPath, "index.js"), "utf8");
171179
assert.equal(bytes, artifacts.get(version).code);
180+
const pkg = JSON.parse(fs.readFileSync(path.join(record.installPath, "package.json"), "utf8"));
181+
assert.equal(pkg.version, `${version}.0.0`);
172182
snapshots.push({
173183
label,
184+
enabled,
174185
record,
175186
payloadSha256: createHash("sha256").update(bytes).digest("hex"),
176187
});
@@ -221,14 +232,58 @@ export async function runConsentScenario(entry, coreTarball) {
221232
}),
222233
);
223234
fs.writeFileSync(path.join(dir, "index.js"), code);
224-
const tarball = path.join(root, `fixture-${version}.tgz`);
225-
execFileSync("tar", ["-czf", tarball, "-C", path.dirname(dir), "package"]);
235+
const filename = execFileSync("npm", ["pack", "--pack-destination", root, "--silent"], {
236+
cwd: dir,
237+
encoding: "utf8",
238+
}).trim();
239+
const tarball = path.join(root, filename);
226240
artifacts.set(version, {
227241
tarball,
228242
code,
229243
integrity: `sha512-${createHash("sha512").update(fs.readFileSync(tarball)).digest("base64")}`,
230244
});
231245
}
246+
const reinstall = (version) => [
247+
"plugins",
248+
"install",
249+
`npm-pack:${artifacts.get(version).tarball}`,
250+
"--force",
251+
];
252+
await cli("reinstall-initial", [...reinstall(1), "--accept-capabilities"]);
253+
await snapshot("reinstall-initial-state", 1);
254+
await cli("disable", ["plugins", "disable", pluginId]);
255+
await cli("reinstall-unchanged", reinstall(1));
256+
const disabled = await snapshot("reinstall-unchanged-disabled", 1, false);
257+
const configBefore = fs.readFileSync(process.env.OPENCLAW_CONFIG_PATH, "utf8");
258+
const indexBefore = readPluginInstallIndex();
259+
assert.deepEqual(indexBefore.installRecords[pluginId], disabled.record);
260+
const rejected = await cli("reinstall-widened-denied", reinstall(2), { allowFailure: true });
261+
assert.equal(rejected.code, 1, `${rejected.output}\n${rejected.diagnostic}`);
262+
assert.match(rejected.output + rejected.diagnostic, /requires capability consent/i);
263+
assert.equal(fs.readFileSync(process.env.OPENCLAW_CONFIG_PATH, "utf8"), configBefore);
264+
assert.deepEqual(readPluginInstallIndex(), indexBefore);
265+
assert.deepEqual(await snapshot("reinstall-denied-preserved", 1, false), disabled);
266+
await cli("reinstall-widened-accepted", [...reinstall(2), "--accept-capabilities"]);
267+
const acceptedDisabled = await snapshot("reinstall-accepted-disabled", 2, false);
268+
assert.deepEqual(readPluginInstallIndex().installRecords[pluginId], acceptedDisabled.record);
269+
await cli("reinstall-enable", ["plugins", "enable", pluginId]);
270+
assert.deepEqual(await snapshot("reinstall-enabled", 2), acceptedDisabled);
271+
const reinstallAssertions = [
272+
"unchanged forced reinstall reuses acceptance and preserves authored disablement",
273+
"widened forced reinstall without consent preserves config, package, and SQLite index",
274+
"accepted forced reinstall replaces package and acceptance while remaining disabled",
275+
"explicit enable activates the reviewed replacement",
276+
];
277+
if (!coreTarball) {
278+
console.log(
279+
JSON.stringify(
280+
{ status: "passed", root, assertions: reinstallAssertions, runs, snapshots },
281+
null,
282+
2,
283+
),
284+
);
285+
return;
286+
}
232287
await serve(1);
233288
await cli("initial-install", [
234289
"plugins",
@@ -319,6 +374,7 @@ export async function runConsentScenario(entry, coreTarball) {
319374
root,
320375
coreTarballSha256,
321376
assertions: [
377+
...reinstallAssertions,
322378
"no-consent preserves old payload and record",
323379
"repair accepts exact surface and integrity",
324380
"acceptance grants no future widening",

‎src/plugins/capability-consent.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ describe("plugin capability consent", () => {
505505
},
506506
);
507507

508-
it("requires consent when reinstalling a previously disabled plugin will enable it", async () => {
508+
it("rejects reinstall without capability consent even when the plugin is disabled", async () => {
509509
const rootDir = createArtifactFixture({
510510
"package.json": { openclaw: { extensions: ["./index.js"] } },
511511
"index.js": "export {};",

‎src/plugins/capability-consent.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ async function resolvePluginArtifactCapabilityConsent(params: {
273273
resolveAcceptedSurfaceCurrent(params.previousRecord, params.previousDeclared) &&
274274
resolvePluginInstallRecordIntegrity(params.previousRecord) !== undefined;
275275
acceptanceCurrent = !hasWidening && priorAcceptanceCurrent;
276-
// Managed installs activate the package, even when its previous version was disabled.
277-
// Update-only flows preserve disablement in preparePluginUpdateCapabilityConsent instead.
276+
// Reinstalls preserve authored disablement; required consent still precedes commit.
277+
// Only update-only flows defer it in preparePluginUpdateCapabilityConsent.
278278
}
279279
const acknowledgment =
280280
official || !params.enabled || acceptanceCurrent
@@ -329,7 +329,7 @@ export function createManagedPluginArtifactConsentHandler(params: {
329329
beforePersistentEffect?: () => void | Promise<void>;
330330
previousRecords?: Record<string, PluginInstallRecord>;
331331
previousPluginOwners?: ReadonlyMap<string, string>;
332-
/** Update-only flows preserve disablement; ordinary installs activate the package. */
332+
/** Update-only flows may defer consent while every known package entry is disabled. */
333333
updatingPluginIds?: readonly string[];
334334
}): {
335335
onBeforePluginArtifactCommit: PluginInstallArtifactConsentHandler;

0 commit comments

Comments
 (0)