Skip to content

Commit cc4cc83

Browse files
authored
refactor(acpx): remove dead config keys (#120937)
1 parent 13cb098 commit cc4cc83

8 files changed

Lines changed: 113 additions & 184 deletions

File tree

‎extensions/acpx/doctor-contract-api.test.ts‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// ACPX tests cover doctor migration of legacy runtime state.
1+
// ACPX tests cover doctor repair of legacy config and runtime state.
22
import fs from "node:fs/promises";
33
import os from "node:os";
44
import path from "node:path";
55
import { expectDefined } from "@openclaw/normalization-core";
6+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
67
import {
78
createPluginStateKeyedStoreForTests,
89
resetPluginStateStoreForTests,
@@ -12,7 +13,12 @@ import type {
1213
PluginDoctorStateMigrationContext,
1314
} from "openclaw/plugin-sdk/runtime-doctor-migrations";
1415
import { afterEach, beforeEach, describe, expect, it } from "vitest";
15-
import { stateMigrations } from "./doctor-contract-api.js";
16+
import {
17+
legacyConfigRules,
18+
normalizeCompatibilityConfig,
19+
stateMigrations,
20+
} from "./doctor-contract-api.js";
21+
import { AcpxPluginConfigSchema } from "./src/config-schema.js";
1622
import { openAcpxProcessLeaseStateStore, type AcpxProcessLease } from "./src/process-lease.js";
1723
import {
1824
ACPX_GATEWAY_INSTANCE_KEY,
@@ -23,6 +29,60 @@ import {
2329
type AcpxGatewayInstanceRecord,
2430
} from "./src/state.js";
2531

32+
describe("acpx doctor config repair", () => {
33+
it("flags both retired config keys for openclaw doctor --fix", () => {
34+
expect(legacyConfigRules).toEqual([
35+
expect.objectContaining({
36+
path: ["plugins", "entries", "acpx", "config", "strictWindowsCmdWrapper"],
37+
message: expect.stringContaining("openclaw doctor --fix"),
38+
}),
39+
expect.objectContaining({
40+
path: ["plugins", "entries", "acpx", "config", "queueOwnerTtlSeconds"],
41+
message: expect.stringContaining("openclaw doctor --fix"),
42+
}),
43+
]);
44+
});
45+
46+
it("removes retired config before strict plugin validation", () => {
47+
const config = {
48+
plugins: {
49+
entries: {
50+
acpx: {
51+
enabled: true,
52+
config: {
53+
cwd: "/tmp/acpx",
54+
strictWindowsCmdWrapper: false,
55+
queueOwnerTtlSeconds: 30,
56+
},
57+
},
58+
},
59+
},
60+
} as OpenClawConfig;
61+
62+
const result = normalizeCompatibilityConfig({ cfg: config });
63+
64+
expect(result.changes).toEqual([
65+
"Removed retired ACPX plugin config: plugins.entries.acpx.config.strictWindowsCmdWrapper, plugins.entries.acpx.config.queueOwnerTtlSeconds.",
66+
]);
67+
expect(result.config.plugins?.entries?.acpx).toEqual({
68+
enabled: true,
69+
config: { cwd: "/tmp/acpx" },
70+
});
71+
expect(
72+
AcpxPluginConfigSchema.safeParse(result.config.plugins?.entries?.acpx?.config).success,
73+
).toBe(true);
74+
expect(config.plugins?.entries?.acpx?.config).toEqual({
75+
cwd: "/tmp/acpx",
76+
strictWindowsCmdWrapper: false,
77+
queueOwnerTtlSeconds: 30,
78+
});
79+
expect(normalizeCompatibilityConfig({ cfg: result.config })).toEqual({
80+
config: result.config,
81+
changes: [],
82+
});
83+
});
84+
});
85+
2686
function createDoctorContext(env: NodeJS.ProcessEnv): PluginDoctorStateMigrationContext {
2787
return {
2888
openPluginStateKeyedStore<T>(options: OpenKeyedStoreOptions) {

‎extensions/acpx/doctor-contract-api.ts‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// ACPX doctor contract migrates shipped plugin-owned runtime state.
1+
// ACPX doctor contract repairs shipped config and migrates plugin-owned runtime state.
22
import fs from "node:fs/promises";
33
import path from "node:path";
4+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
45
import {
56
archiveLegacyStateSource,
7+
asObjectRecord,
68
type PluginDoctorStateMigration,
79
} from "openclaw/plugin-sdk/runtime-doctor-migrations";
810
import {
@@ -21,6 +23,47 @@ import {
2123
type AcpxGatewayInstanceRecord,
2224
} from "./src/state.js";
2325

26+
const ACPX_CONFIG_PATH = ["plugins", "entries", "acpx", "config"] as const;
27+
const RETIRED_ACPX_CONFIG_KEYS = ["strictWindowsCmdWrapper", "queueOwnerTtlSeconds"] as const;
28+
29+
/** Retired ACPX config that `openclaw doctor --fix` removes before strict validation. */
30+
export const legacyConfigRules = RETIRED_ACPX_CONFIG_KEYS.map((key) => ({
31+
path: [...ACPX_CONFIG_PATH, key],
32+
message: `${[...ACPX_CONFIG_PATH, key].join(".")} is retired and ignored by the embedded ACPX runtime. Run "openclaw doctor --fix".`,
33+
}));
34+
35+
/** Removes retired plugin-owned config without keeping runtime compatibility keys. */
36+
export function normalizeCompatibilityConfig({ cfg }: { cfg: OpenClawConfig }): {
37+
config: OpenClawConfig;
38+
changes: string[];
39+
} {
40+
const entry = asObjectRecord(cfg.plugins?.entries?.acpx);
41+
const pluginConfig = asObjectRecord(entry?.config);
42+
const retiredKeys = RETIRED_ACPX_CONFIG_KEYS.filter((key) =>
43+
Object.hasOwn(pluginConfig ?? {}, key),
44+
);
45+
if (!pluginConfig || retiredKeys.length === 0) {
46+
return { config: cfg, changes: [] };
47+
}
48+
49+
const nextConfig = structuredClone(cfg);
50+
const nextEntry = asObjectRecord(nextConfig.plugins?.entries?.acpx);
51+
const nextPluginConfig = asObjectRecord(nextEntry?.config);
52+
if (!nextPluginConfig) {
53+
return { config: cfg, changes: [] };
54+
}
55+
for (const key of retiredKeys) {
56+
delete nextPluginConfig[key];
57+
}
58+
59+
return {
60+
config: nextConfig,
61+
changes: [
62+
`Removed retired ACPX plugin config: ${retiredKeys.map((key) => [...ACPX_CONFIG_PATH, key].join(".")).join(", ")}.`,
63+
],
64+
};
65+
}
66+
2467
function resolveLegacyGatewayInstancePath(stateDir: string): string {
2568
return path.join(stateDir, ACPX_LEGACY_GATEWAY_INSTANCE_FILE);
2669
}

‎extensions/acpx/openclaw.plugin.json‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"id": "acpx",
33
"doctorContract": {
4+
"configRepair": true,
45
"stateMigrations": true
56
},
67
"activation": {
@@ -40,18 +41,11 @@
4041
"openClawToolsMcpBridge": {
4142
"type": "boolean"
4243
},
43-
"strictWindowsCmdWrapper": {
44-
"type": "boolean"
45-
},
4644
"timeoutSeconds": {
4745
"type": "number",
4846
"minimum": 0.001,
4947
"default": 120
5048
},
51-
"queueOwnerTtlSeconds": {
52-
"type": "number",
53-
"minimum": 0
54-
},
5549
"piSessionCatalog": {
5650
"type": "object",
5751
"additionalProperties": false,
@@ -90,6 +84,7 @@
9084
"type": "object",
9185
"additionalProperties": {
9286
"type": "object",
87+
"additionalProperties": false,
9388
"properties": {
9489
"command": {
9590
"type": "string",
@@ -132,21 +127,11 @@
132127
"help": "Default off. When enabled, inject the built-in OpenClaw core-tools MCP server into embedded ACP sessions so ACP agents can call selected built-in tools such as cron.",
133128
"advanced": true
134129
},
135-
"strictWindowsCmdWrapper": {
136-
"label": "Strict Windows cmd Wrapper",
137-
"help": "Legacy compatibility field. The current embedded acpx/runtime package uses its own Windows command resolution behavior. Setting this to false is accepted for compatibility and logged as ignored.",
138-
"advanced": true
139-
},
140130
"timeoutSeconds": {
141131
"label": "Runtime Operation Timeout Seconds",
142132
"help": "Timeout for embedded ACP runtime startup and control operations. ACP turns use OpenClaw agent/run timeouts.",
143133
"advanced": true
144134
},
145-
"queueOwnerTtlSeconds": {
146-
"label": "Queue Owner TTL Seconds",
147-
"help": "Reserved compatibility field for the older embedded ACPX queue-owner path. Accepted for compatibility and logged as ignored.",
148-
"advanced": true
149-
},
150135
"piSessionCatalog.enabled": {
151136
"label": "Pi Session Catalog",
152137
"help": "Auto-detect Pi sessions on the Gateway and paired nodes, then show them in the sessions sidebar."

‎extensions/acpx/src/config-schema.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export type AcpxPluginConfig = {
3939
nonInteractivePermissions?: AcpxNonInteractivePermissionPolicy;
4040
pluginToolsMcpBridge?: boolean;
4141
openClawToolsMcpBridge?: boolean;
42-
strictWindowsCmdWrapper?: boolean;
4342
timeoutSeconds?: number;
44-
queueOwnerTtlSeconds?: number;
4543
piSessionCatalog?: { enabled?: boolean };
4644
mcpServers?: Record<string, McpServerConfig>;
4745
agents?: Record<string, { command: string; args?: string[] }>;
@@ -56,13 +54,7 @@ export type ResolvedAcpxPluginConfig = {
5654
nonInteractivePermissions: AcpxNonInteractivePermissionPolicy;
5755
pluginToolsMcpBridge: boolean;
5856
openClawToolsMcpBridge: boolean;
59-
strictWindowsCmdWrapper: boolean;
6057
timeoutSeconds?: number;
61-
queueOwnerTtlSeconds: number;
62-
legacyCompatibilityConfig: {
63-
strictWindowsCmdWrapper?: boolean;
64-
queueOwnerTtlSeconds?: number;
65-
};
6658
mcpServers: Record<string, McpServerConfig>;
6759
agents: Record<string, string>;
6860
};
@@ -107,17 +99,10 @@ export const AcpxPluginConfigSchema = z.strictObject({
10799
openClawToolsMcpBridge: z
108100
.boolean({ error: "openClawToolsMcpBridge must be a boolean" })
109101
.optional(),
110-
strictWindowsCmdWrapper: z
111-
.boolean({ error: "strictWindowsCmdWrapper must be a boolean" })
112-
.optional(),
113102
timeoutSeconds: z
114103
.number({ error: "timeoutSeconds must be a number >= 0.001" })
115104
.min(0.001, { error: "timeoutSeconds must be a number >= 0.001" })
116105
.default(DEFAULT_ACPX_TIMEOUT_SECONDS),
117-
queueOwnerTtlSeconds: z
118-
.number({ error: "queueOwnerTtlSeconds must be a number >= 0" })
119-
.min(0, { error: "queueOwnerTtlSeconds must be a number >= 0" })
120-
.optional(),
121106
piSessionCatalog: z
122107
.strictObject({
123108
enabled: z.boolean({ error: "piSessionCatalog.enabled must be a boolean" }).default(true),

‎extensions/acpx/src/config.test.ts‎

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import fs from "node:fs";
33
import { createRequire } from "node:module";
44
import path from "node:path";
5+
import { buildPluginConfigSchema } from "openclaw/plugin-sdk/plugin-entry";
56
import { describe, expect, it } from "vitest";
7+
import { AcpxPluginConfigSchema } from "./config-schema.js";
68
import { resolveAcpxPluginConfig, resolveAcpxPluginRoot } from "./config.js";
79

810
const requireFromTest = createRequire(import.meta.url);
@@ -188,100 +190,8 @@ describe("embedded acpx plugin config", () => {
188190
fs.readFileSync(path.join(pluginRoot, "openclaw.plugin.json"), "utf8"),
189191
) as { configSchema?: unknown };
190192

191-
expect(manifest.configSchema).toStrictEqual({
192-
type: "object",
193-
additionalProperties: false,
194-
properties: {
195-
cwd: {
196-
type: "string",
197-
minLength: 1,
198-
},
199-
stateDir: {
200-
type: "string",
201-
minLength: 1,
202-
},
203-
permissionMode: {
204-
type: "string",
205-
enum: ["approve-all", "approve-reads", "deny-all"],
206-
},
207-
nonInteractivePermissions: {
208-
type: "string",
209-
enum: ["deny", "fail"],
210-
},
211-
pluginToolsMcpBridge: {
212-
type: "boolean",
213-
},
214-
openClawToolsMcpBridge: {
215-
type: "boolean",
216-
},
217-
strictWindowsCmdWrapper: {
218-
type: "boolean",
219-
},
220-
timeoutSeconds: {
221-
type: "number",
222-
minimum: 0.001,
223-
default: 120,
224-
},
225-
queueOwnerTtlSeconds: {
226-
type: "number",
227-
minimum: 0,
228-
},
229-
piSessionCatalog: {
230-
type: "object",
231-
additionalProperties: false,
232-
properties: {
233-
enabled: {
234-
type: "boolean",
235-
default: true,
236-
},
237-
},
238-
},
239-
probeAgent: {
240-
type: "string",
241-
minLength: 1,
242-
},
243-
mcpServers: {
244-
type: "object",
245-
additionalProperties: {
246-
type: "object",
247-
properties: {
248-
command: {
249-
type: "string",
250-
minLength: 1,
251-
description: "Command to run the MCP server",
252-
},
253-
args: {
254-
type: "array",
255-
items: { type: "string" },
256-
description: "Arguments to pass to the command",
257-
},
258-
env: {
259-
type: "object",
260-
additionalProperties: { type: "string" },
261-
description: "Environment variables for the MCP server",
262-
},
263-
},
264-
required: ["command"],
265-
},
266-
},
267-
agents: {
268-
type: "object",
269-
additionalProperties: {
270-
type: "object",
271-
properties: {
272-
command: {
273-
type: "string",
274-
minLength: 1,
275-
},
276-
args: {
277-
type: "array",
278-
items: { type: "string" },
279-
},
280-
},
281-
required: ["command"],
282-
},
283-
},
284-
},
285-
});
193+
expect(buildPluginConfigSchema(AcpxPluginConfigSchema).jsonSchema).toEqual(
194+
manifest.configSchema,
195+
);
286196
});
287197
});

‎extensions/acpx/src/config.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export function resolveAcpxPluginRoot(moduleUrl: string = import.meta.url): stri
101101

102102
const DEFAULT_PERMISSION_MODE: AcpxPermissionMode = "approve-reads";
103103
const DEFAULT_NON_INTERACTIVE_POLICY: AcpxNonInteractivePermissionPolicy = "fail";
104-
const DEFAULT_QUEUE_OWNER_TTL_SECONDS = 0.1;
105-
const DEFAULT_STRICT_WINDOWS_CMD_WRAPPER = true;
106104

107105
type ParseResult =
108106
| { ok: true; value: AcpxPluginConfig | undefined }
@@ -270,14 +268,7 @@ export function resolveAcpxPluginConfig(params: {
270268
normalized.nonInteractivePermissions ?? DEFAULT_NON_INTERACTIVE_POLICY,
271269
pluginToolsMcpBridge,
272270
openClawToolsMcpBridge,
273-
strictWindowsCmdWrapper:
274-
normalized.strictWindowsCmdWrapper ?? DEFAULT_STRICT_WINDOWS_CMD_WRAPPER,
275271
timeoutSeconds: normalized.timeoutSeconds ?? DEFAULT_ACPX_TIMEOUT_SECONDS,
276-
queueOwnerTtlSeconds: normalized.queueOwnerTtlSeconds ?? DEFAULT_QUEUE_OWNER_TTL_SECONDS,
277-
legacyCompatibilityConfig: {
278-
strictWindowsCmdWrapper: normalized.strictWindowsCmdWrapper,
279-
queueOwnerTtlSeconds: normalized.queueOwnerTtlSeconds,
280-
},
281272
mcpServers,
282273
agents,
283274
};

0 commit comments

Comments
 (0)