@diviops/mcp-server 1.5.33 → 1.5.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/capability-envelope.d.ts +12 -0
- package/dist/capability-envelope.js +29 -0
- package/dist/index.js +273 -69
- package/dist/preset-cli/cli.js +5 -1
- package/dist/preset-cli/write-path.d.ts +23 -19
- package/dist/preset-cli/write-path.js +47 -39
- package/dist/validate-attrs.d.ts +15 -13
- package/dist/validate-attrs.js +91 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ The skill enforces the Divi block format, the design system, and the response co
|
|
|
83
83
|
|
|
84
84
|
## Tools at a glance
|
|
85
85
|
|
|
86
|
-
The server exposes **
|
|
86
|
+
The server exposes **91 always-on tools** across the categories below. Each category links to representative tools; the full table lives in [server-reference.md](../docs/server-reference.md).
|
|
87
87
|
|
|
88
88
|
| Category | Use case | Tool prefixes |
|
|
89
89
|
|----------|----------|---------------|
|
|
@@ -108,6 +108,7 @@ Additional **conditionally-registered Pro tools** appear only on sites that have
|
|
|
108
108
|
| FluentCart simple product writes (V2) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_product_create`, `diviops_fc_product_update`, `diviops_fc_product_delete` |
|
|
109
109
|
| FluentCart variation read/write (V3) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_variation_list`, `diviops_fc_variation_update` |
|
|
110
110
|
| FluentCart license-settings read/write, incl. update-file pointer + readiness (V3/V3.3) | Pro plugin + FluentCart Pro installed + module enabled | `diviops_fc_license_settings_get`, `diviops_fc_license_settings_update` |
|
|
111
|
+
| FluentCart managed downloads + license changelog (V3.4) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_download_list`, `diviops_fc_download_attach`, `diviops_fc_license_changelog_get`, `diviops_fc_license_changelog_update` |
|
|
111
112
|
| FluentCart order readback + guarded mark-paid (V3.1) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_order_list`, `diviops_fc_order_get`, `diviops_fc_order_mark_paid` |
|
|
112
113
|
| FluentCart license readback (V3.1) | Pro plugin + FluentCart Pro installed + module enabled | `diviops_fc_license_list`, `diviops_fc_license_get`, `diviops_fc_license_activations_list` |
|
|
113
114
|
| FluentCart checkout readiness / gateway inspection (V3.2) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_status`, `diviops_fc_gateway_list`, `diviops_fc_gateway_get` |
|
|
@@ -286,6 +287,18 @@ Every write tool accepts `dry_run: boolean` (default `false`). When `true`, the
|
|
|
286
287
|
|
|
287
288
|
`meta_wp_cli` and `scf_import` do not accept `dry_run` (raw passthrough / upstream gap respectively). `scf_sync` passes `dry_run` through to upstream `wp scf json sync --dry-run`, so its preview is the upstream plain-text summary rather than a plugin-built `data.plan`. For bulk preview-then-commit flows (preset reassign, preset cleanup), see [safety-patterns.md](../docs/safety-patterns.md).
|
|
288
289
|
|
|
290
|
+
Selected guarded post-content write tools also accept `backup: true`. In apply
|
|
291
|
+
mode the Free plugin stores an option-backed rollback snapshot before writing
|
|
292
|
+
and returns `data.backup` evidence with the snapshot id and status. With
|
|
293
|
+
`dry_run: true`, `backup: true` only reports the planned snapshot; it never
|
|
294
|
+
creates an option record.
|
|
295
|
+
|
|
296
|
+
`diviops_rollback_snapshot_restore` restores those snapshots only to their
|
|
297
|
+
captured post/page or Theme Builder layout target. It requires row-level edit
|
|
298
|
+
permission, refuses content or supported Divi post-meta drift before mutation,
|
|
299
|
+
uses the same full-content integrity/readback guard, and has no force override
|
|
300
|
+
or second pre-restore snapshot in this MVP.
|
|
301
|
+
|
|
289
302
|
### `_meta.idempotent` markers
|
|
290
303
|
|
|
291
304
|
Every tool's `_meta.idempotent` field documents how it behaves under repeat calls with identical inputs. Some tools are silent-success idempotent (e.g. `page_trash` on an already-trashed post returns `ok: true` with `data.already_trashed = true`); others are side-effect-equivalent (re-running produces the same final state via different intermediate effects). See [idempotency-audit.md](../docs/idempotency-audit.md) for the per-tool record.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MissingCapabilityError } from "./compatibility.js";
|
|
2
|
+
export type MissingCapabilityMcpResult = {
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Convert a server-side capability gate failure into the canonical DiviOps
|
|
10
|
+
* response envelope carried in MCP text content.
|
|
11
|
+
*/
|
|
12
|
+
export declare function missingCapabilityEnvelope(error: MissingCapabilityError, toolName: string, hint?: string): MissingCapabilityMcpResult;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ErrorCodes, serializeEnvelope, } from "./envelope.js";
|
|
2
|
+
const DEFAULT_HINT = "Update the diviops-agent WP plugin to the version shipped with this MCP server release.";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a server-side capability gate failure into the canonical DiviOps
|
|
5
|
+
* response envelope carried in MCP text content.
|
|
6
|
+
*/
|
|
7
|
+
export function missingCapabilityEnvelope(error, toolName, hint = DEFAULT_HINT) {
|
|
8
|
+
const failure = {
|
|
9
|
+
ok: false,
|
|
10
|
+
error: {
|
|
11
|
+
code: ErrorCodes.CAPABILITY_MISSING,
|
|
12
|
+
message: error.message,
|
|
13
|
+
hint,
|
|
14
|
+
data: {
|
|
15
|
+
capability: error.capability,
|
|
16
|
+
plugin_version: error.pluginVersion,
|
|
17
|
+
tool: toolName,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: serializeEnvelope(failure, toolName),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -13,13 +13,14 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { WPClient } from "./wp-client.js";
|
|
15
15
|
import { MissingCapabilityError, proToolGatesSatisfied, } from "./compatibility.js";
|
|
16
|
+
import { missingCapabilityEnvelope, } from "./capability-envelope.js";
|
|
16
17
|
import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
|
|
17
18
|
import { preflightCrossEnvHeaderSync, } from "./cross-env-preflight/header-preflight.js";
|
|
18
19
|
import { createSourcePayloadRef, loadSourcePayloadRef, } from "./cross-env-preflight/source-payload-ref.js";
|
|
19
20
|
import { optimizeSchema } from "./schema-optimizer.js";
|
|
20
21
|
import { schemaModuleRoute } from "./schema-route.js";
|
|
21
22
|
import { createWpCli } from "./wp-cli.js";
|
|
22
|
-
import {
|
|
23
|
+
import { isolationFailure, scanValueForForeignVarRefs, writerIsolationErrorResult, } from "./validate-attrs.js";
|
|
23
24
|
import { readFileSync, readdirSync } from "fs";
|
|
24
25
|
import { join, dirname } from "path";
|
|
25
26
|
import { fileURLToPath } from "url";
|
|
@@ -279,6 +280,21 @@ function requireCapability(key) {
|
|
|
279
280
|
throw new MissingCapabilityError(key, handshakeState.pluginVersion);
|
|
280
281
|
}
|
|
281
282
|
}
|
|
283
|
+
function backupCapabilityError(toolName, backup) {
|
|
284
|
+
if (!backup)
|
|
285
|
+
return null;
|
|
286
|
+
const key = toolName.replace(/^diviops_/, "") + "_backup";
|
|
287
|
+
try {
|
|
288
|
+
requireCapability(key);
|
|
289
|
+
}
|
|
290
|
+
catch (e) {
|
|
291
|
+
if (e instanceof MissingCapabilityError) {
|
|
292
|
+
return missingCapabilityEnvelope(e, toolName, "Update the diviops-agent WP plugin to a version that supports rollback snapshot backup, or omit backup:true from this call.");
|
|
293
|
+
}
|
|
294
|
+
throw e;
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
282
298
|
// `any` here is deliberate, not laziness. McpServer.registerTool is a
|
|
283
299
|
// multi-overload generic whose `cb`/`InputArgs` machinery doesn't compose
|
|
284
300
|
// with `Parameters<typeof server.registerTool>` (overload collapse to
|
|
@@ -302,10 +318,7 @@ function registerPluginTool(name, config, handler) {
|
|
|
302
318
|
}
|
|
303
319
|
catch (e) {
|
|
304
320
|
if (e instanceof MissingCapabilityError) {
|
|
305
|
-
return
|
|
306
|
-
content: [{ type: "text", text: e.message }],
|
|
307
|
-
isError: true,
|
|
308
|
-
};
|
|
321
|
+
return missingCapabilityEnvelope(e, name);
|
|
309
322
|
}
|
|
310
323
|
throw e;
|
|
311
324
|
}
|
|
@@ -399,6 +412,11 @@ const DRY_RUN_FIELD = z
|
|
|
399
412
|
.optional()
|
|
400
413
|
.default(false)
|
|
401
414
|
.describe("When true, return the change plan { summary, changes[, warnings] } without mutating state.");
|
|
415
|
+
const BACKUP_FIELD = z
|
|
416
|
+
.boolean()
|
|
417
|
+
.optional()
|
|
418
|
+
.default(false)
|
|
419
|
+
.describe("When true on supported content writes, capture a rollback snapshot before applying. dry_run + backup only reports the planned snapshot and does not create one.");
|
|
402
420
|
// ── Read Tools ───────────────────────────────────────────────────────
|
|
403
421
|
registerPluginTool("diviops_page_list", {
|
|
404
422
|
description: "List pages/posts in the WordPress site. Returns title, ID, URL, status, and whether each page uses Divi builder. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
@@ -704,17 +722,7 @@ registerPluginTool("diviops_schema_get_module", {
|
|
|
704
722
|
if (handshakeState.kind === "ok" &&
|
|
705
723
|
!handshakeState.capabilities["schema_get_module_dump_all"]) {
|
|
706
724
|
const err = new MissingCapabilityError("schema_get_module_dump_all", handshakeState.pluginVersion);
|
|
707
|
-
|
|
708
|
-
ok: false,
|
|
709
|
-
error: {
|
|
710
|
-
code: ErrorCodes.CAPABILITY_MISSING,
|
|
711
|
-
message: err.message,
|
|
712
|
-
hint: "Update the diviops-agent WP plugin to a version that exposes the dump-all surface.",
|
|
713
|
-
},
|
|
714
|
-
};
|
|
715
|
-
return {
|
|
716
|
-
content: [{ type: "text", text: serializeEnvelope(failure, "diviops_schema_get_module") }],
|
|
717
|
-
};
|
|
725
|
+
return missingCapabilityEnvelope(err, "diviops_schema_get_module", "Update the diviops-agent WP plugin to a version that exposes the dump-all surface, or use mode:'single'.");
|
|
718
726
|
}
|
|
719
727
|
const result = await wp.requestEnveloped("/schema/module/dump-all");
|
|
720
728
|
return {
|
|
@@ -742,7 +750,7 @@ registerPluginTool("diviops_schema_get_module", {
|
|
|
742
750
|
};
|
|
743
751
|
});
|
|
744
752
|
registerPluginTool("diviops_schema_get_settings", {
|
|
745
|
-
description: "Get Divi site settings including
|
|
753
|
+
description: "Get Divi site settings including site info, builder version, and a narrow public allowlist of non-sensitive Divi theme options (fonts, colors, sizes). Useful for understanding the site context before generating content. Does not expose the raw `et_divi` option bag. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
746
754
|
annotations: { idempotentHint: true },
|
|
747
755
|
_meta: { idempotent: "true" },
|
|
748
756
|
}, async () => {
|
|
@@ -1105,16 +1113,22 @@ registerPluginTool("diviops_page_update_content", {
|
|
|
1105
1113
|
.string()
|
|
1106
1114
|
.describe("Full page content in WordPress block markup format (<!-- wp:divi/section -->...<!-- /wp:divi/section -->)"),
|
|
1107
1115
|
dry_run: DRY_RUN_FIELD,
|
|
1116
|
+
backup: BACKUP_FIELD,
|
|
1108
1117
|
},
|
|
1109
1118
|
annotations: { idempotentHint: false },
|
|
1110
1119
|
_meta: { idempotent: "conditional" },
|
|
1111
|
-
}, async ({ page_id, content, dry_run }) => {
|
|
1112
|
-
const
|
|
1113
|
-
if (
|
|
1114
|
-
return
|
|
1120
|
+
}, async ({ page_id, content, dry_run, backup }) => {
|
|
1121
|
+
const backupGate = backupCapabilityError("diviops_page_update_content", backup);
|
|
1122
|
+
if (backupGate)
|
|
1123
|
+
return backupGate;
|
|
1124
|
+
const isolationGate = writerIsolationErrorResult("diviops_page_update_content", { content });
|
|
1125
|
+
if (isolationGate)
|
|
1126
|
+
return isolationGate;
|
|
1115
1127
|
const body = { content };
|
|
1116
1128
|
if (dry_run)
|
|
1117
1129
|
body.dry_run = true;
|
|
1130
|
+
if (backup)
|
|
1131
|
+
body.backup = true;
|
|
1118
1132
|
const result = await wp.requestEnveloped(`/page/update-content/${page_id}`, {
|
|
1119
1133
|
method: "POST",
|
|
1120
1134
|
body,
|
|
@@ -1205,10 +1219,7 @@ registerPluginTool("diviops_render_preview", {
|
|
|
1205
1219
|
}
|
|
1206
1220
|
catch (e) {
|
|
1207
1221
|
if (e instanceof MissingCapabilityError) {
|
|
1208
|
-
return
|
|
1209
|
-
content: [{ type: "text", text: e.message }],
|
|
1210
|
-
isError: true,
|
|
1211
|
-
};
|
|
1222
|
+
return missingCapabilityEnvelope(e, "diviops_render_preview", "Update the diviops-agent WP plugin to a version that supports page_id rendering, or provide inline content instead.");
|
|
1212
1223
|
}
|
|
1213
1224
|
throw e;
|
|
1214
1225
|
}
|
|
@@ -1245,10 +1256,7 @@ registerPluginTool("diviops_validate_blocks", {
|
|
|
1245
1256
|
}
|
|
1246
1257
|
catch (e) {
|
|
1247
1258
|
if (e instanceof MissingCapabilityError) {
|
|
1248
|
-
return
|
|
1249
|
-
content: [{ type: "text", text: e.message }],
|
|
1250
|
-
isError: true,
|
|
1251
|
-
};
|
|
1259
|
+
return missingCapabilityEnvelope(e, "diviops_validate_blocks", "Update the diviops-agent WP plugin to a version that supports page_id validation, or provide inline content instead.");
|
|
1252
1260
|
}
|
|
1253
1261
|
throw e;
|
|
1254
1262
|
}
|
|
@@ -1277,16 +1285,24 @@ registerPluginTool("diviops_section_append", {
|
|
|
1277
1285
|
.default("end")
|
|
1278
1286
|
.describe('Where to insert: "start" or "end" (default)'),
|
|
1279
1287
|
dry_run: DRY_RUN_FIELD,
|
|
1288
|
+
backup: BACKUP_FIELD,
|
|
1280
1289
|
},
|
|
1281
1290
|
annotations: { idempotentHint: false },
|
|
1282
1291
|
_meta: { idempotent: "false" },
|
|
1283
|
-
}, async ({ page_id, content, position, dry_run }) => {
|
|
1284
|
-
const
|
|
1285
|
-
if (
|
|
1286
|
-
return
|
|
1292
|
+
}, async ({ page_id, content, position, dry_run, backup }) => {
|
|
1293
|
+
const backupGate = backupCapabilityError("diviops_section_append", backup);
|
|
1294
|
+
if (backupGate)
|
|
1295
|
+
return backupGate;
|
|
1296
|
+
const isolationGate = writerIsolationErrorResult("diviops_section_append", {
|
|
1297
|
+
content,
|
|
1298
|
+
});
|
|
1299
|
+
if (isolationGate)
|
|
1300
|
+
return isolationGate;
|
|
1287
1301
|
const body = { content, position: position ?? "end" };
|
|
1288
1302
|
if (dry_run)
|
|
1289
1303
|
body.dry_run = true;
|
|
1304
|
+
if (backup)
|
|
1305
|
+
body.backup = true;
|
|
1290
1306
|
const result = await wp.requestEnveloped(`/section/append/${page_id}`, {
|
|
1291
1307
|
method: "POST",
|
|
1292
1308
|
body,
|
|
@@ -1321,13 +1337,19 @@ registerPluginTool("diviops_section_replace", {
|
|
|
1321
1337
|
.default(1)
|
|
1322
1338
|
.describe("Which match to target (1-based, default: 1)"),
|
|
1323
1339
|
dry_run: DRY_RUN_FIELD,
|
|
1340
|
+
backup: BACKUP_FIELD,
|
|
1324
1341
|
},
|
|
1325
1342
|
annotations: { idempotentHint: false },
|
|
1326
1343
|
_meta: { idempotent: "conditional" },
|
|
1327
|
-
}, async ({ page_id, label, match_text, content, occurrence, dry_run }) => {
|
|
1328
|
-
const
|
|
1329
|
-
if (
|
|
1330
|
-
return
|
|
1344
|
+
}, async ({ page_id, label, match_text, content, occurrence, dry_run, backup }) => {
|
|
1345
|
+
const backupGate = backupCapabilityError("diviops_section_replace", backup);
|
|
1346
|
+
if (backupGate)
|
|
1347
|
+
return backupGate;
|
|
1348
|
+
const isolationGate = writerIsolationErrorResult("diviops_section_replace", {
|
|
1349
|
+
content,
|
|
1350
|
+
});
|
|
1351
|
+
if (isolationGate)
|
|
1352
|
+
return isolationGate;
|
|
1331
1353
|
const body = { content, occurrence };
|
|
1332
1354
|
if (label)
|
|
1333
1355
|
body.label = label;
|
|
@@ -1335,6 +1357,8 @@ registerPluginTool("diviops_section_replace", {
|
|
|
1335
1357
|
body.match_text = match_text;
|
|
1336
1358
|
if (dry_run)
|
|
1337
1359
|
body.dry_run = true;
|
|
1360
|
+
if (backup)
|
|
1361
|
+
body.backup = true;
|
|
1338
1362
|
const result = await wp.requestEnveloped(`/section/replace/${page_id}`, {
|
|
1339
1363
|
method: "POST",
|
|
1340
1364
|
body,
|
|
@@ -1366,10 +1390,14 @@ registerPluginTool("diviops_section_remove", {
|
|
|
1366
1390
|
.default(1)
|
|
1367
1391
|
.describe("Which match to target (1-based, default: 1)"),
|
|
1368
1392
|
dry_run: DRY_RUN_FIELD,
|
|
1393
|
+
backup: BACKUP_FIELD,
|
|
1369
1394
|
},
|
|
1370
1395
|
annotations: { idempotentHint: true },
|
|
1371
1396
|
_meta: { idempotent: "true" },
|
|
1372
|
-
}, async ({ page_id, label, match_text, occurrence, dry_run }) => {
|
|
1397
|
+
}, async ({ page_id, label, match_text, occurrence, dry_run, backup }) => {
|
|
1398
|
+
const backupGate = backupCapabilityError("diviops_section_remove", backup);
|
|
1399
|
+
if (backupGate)
|
|
1400
|
+
return backupGate;
|
|
1373
1401
|
const body = { occurrence };
|
|
1374
1402
|
if (label)
|
|
1375
1403
|
body.label = label;
|
|
@@ -1377,6 +1405,8 @@ registerPluginTool("diviops_section_remove", {
|
|
|
1377
1405
|
body.match_text = match_text;
|
|
1378
1406
|
if (dry_run)
|
|
1379
1407
|
body.dry_run = true;
|
|
1408
|
+
if (backup)
|
|
1409
|
+
body.backup = true;
|
|
1380
1410
|
const result = await wp.requestEnveloped(`/section/remove/${page_id}`, {
|
|
1381
1411
|
method: "POST",
|
|
1382
1412
|
body,
|
|
@@ -1451,13 +1481,19 @@ registerPluginTool("diviops_module_update", {
|
|
|
1451
1481
|
.record(z.string(), z.any())
|
|
1452
1482
|
.describe("Attribute paths (dot notation) and their new values"),
|
|
1453
1483
|
dry_run: DRY_RUN_FIELD,
|
|
1484
|
+
backup: BACKUP_FIELD,
|
|
1454
1485
|
},
|
|
1455
1486
|
annotations: { idempotentHint: false },
|
|
1456
1487
|
_meta: { idempotent: "conditional" },
|
|
1457
|
-
}, async ({ page_id, label, match_text, auto_index, occurrence, attrs, dry_run }) => {
|
|
1458
|
-
const
|
|
1459
|
-
if (
|
|
1460
|
-
return
|
|
1488
|
+
}, async ({ page_id, label, match_text, auto_index, occurrence, attrs, dry_run, backup }) => {
|
|
1489
|
+
const backupGate = backupCapabilityError("diviops_module_update", backup);
|
|
1490
|
+
if (backupGate)
|
|
1491
|
+
return backupGate;
|
|
1492
|
+
const isolationGate = writerIsolationErrorResult("diviops_module_update", {
|
|
1493
|
+
attrs,
|
|
1494
|
+
});
|
|
1495
|
+
if (isolationGate)
|
|
1496
|
+
return isolationGate;
|
|
1461
1497
|
const body = { attrs };
|
|
1462
1498
|
if (auto_index)
|
|
1463
1499
|
body.auto_index = auto_index;
|
|
@@ -1469,6 +1505,8 @@ registerPluginTool("diviops_module_update", {
|
|
|
1469
1505
|
body.occurrence = occurrence;
|
|
1470
1506
|
if (dry_run)
|
|
1471
1507
|
body.dry_run = true;
|
|
1508
|
+
if (backup)
|
|
1509
|
+
body.backup = true;
|
|
1472
1510
|
const result = await wp.requestEnveloped(`/module/update/${page_id}`, {
|
|
1473
1511
|
method: "POST",
|
|
1474
1512
|
body,
|
|
@@ -1526,10 +1564,14 @@ registerPluginTool("diviops_module_move", {
|
|
|
1526
1564
|
.enum(["before", "after"])
|
|
1527
1565
|
.describe("Place the source before or after the target"),
|
|
1528
1566
|
dry_run: DRY_RUN_FIELD,
|
|
1567
|
+
backup: BACKUP_FIELD,
|
|
1529
1568
|
},
|
|
1530
1569
|
annotations: { idempotentHint: false },
|
|
1531
1570
|
_meta: { idempotent: "conditional" },
|
|
1532
|
-
}, async ({ page_id, source_label, source_match_text, source_auto_index, source_occurrence, target_label, target_match_text, target_auto_index, target_occurrence, position, dry_run, }) => {
|
|
1571
|
+
}, async ({ page_id, source_label, source_match_text, source_auto_index, source_occurrence, target_label, target_match_text, target_auto_index, target_occurrence, position, dry_run, backup, }) => {
|
|
1572
|
+
const backupGate = backupCapabilityError("diviops_module_move", backup);
|
|
1573
|
+
if (backupGate)
|
|
1574
|
+
return backupGate;
|
|
1533
1575
|
const body = { position };
|
|
1534
1576
|
if (source_label)
|
|
1535
1577
|
body.source_label = source_label;
|
|
@@ -1549,6 +1591,8 @@ registerPluginTool("diviops_module_move", {
|
|
|
1549
1591
|
body.target_occurrence = target_occurrence;
|
|
1550
1592
|
if (dry_run)
|
|
1551
1593
|
body.dry_run = true;
|
|
1594
|
+
if (backup)
|
|
1595
|
+
body.backup = true;
|
|
1552
1596
|
const result = await wp.requestEnveloped(`/module/move/${page_id}`, {
|
|
1553
1597
|
method: "POST",
|
|
1554
1598
|
body,
|
|
@@ -1569,10 +1613,14 @@ registerPluginTool("diviops_module_lock", {
|
|
|
1569
1613
|
auto_index: z.string().optional().describe('Auto-index in "type:N" format (e.g. "text:3")'),
|
|
1570
1614
|
occurrence: z.number().int().min(1).optional().default(1).describe("Which occurrence when multiple modules share the same label (1-based)"),
|
|
1571
1615
|
dry_run: DRY_RUN_FIELD,
|
|
1616
|
+
backup: BACKUP_FIELD,
|
|
1572
1617
|
},
|
|
1573
1618
|
annotations: { idempotentHint: false },
|
|
1574
1619
|
_meta: { idempotent: "false" },
|
|
1575
|
-
}, async ({ page_id, label, match_text, auto_index, occurrence, dry_run }) => {
|
|
1620
|
+
}, async ({ page_id, label, match_text, auto_index, occurrence, dry_run, backup }) => {
|
|
1621
|
+
const backupGate = backupCapabilityError("diviops_module_lock", backup);
|
|
1622
|
+
if (backupGate)
|
|
1623
|
+
return backupGate;
|
|
1576
1624
|
const body = {};
|
|
1577
1625
|
if (label)
|
|
1578
1626
|
body.label = label;
|
|
@@ -1584,6 +1632,8 @@ registerPluginTool("diviops_module_lock", {
|
|
|
1584
1632
|
body.occurrence = occurrence;
|
|
1585
1633
|
if (dry_run)
|
|
1586
1634
|
body.dry_run = true;
|
|
1635
|
+
if (backup)
|
|
1636
|
+
body.backup = true;
|
|
1587
1637
|
const result = await wp.requestEnveloped(`/module/lock/${page_id}`, { method: "POST", body });
|
|
1588
1638
|
return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_module_lock") }] };
|
|
1589
1639
|
});
|
|
@@ -1597,10 +1647,14 @@ registerPluginTool("diviops_module_unlock", {
|
|
|
1597
1647
|
auto_index: z.string().optional().describe('Auto-index in "type:N" format'),
|
|
1598
1648
|
occurrence: z.number().int().min(1).optional().default(1).describe("Which occurrence when multiple modules share the same label (1-based)"),
|
|
1599
1649
|
dry_run: DRY_RUN_FIELD,
|
|
1650
|
+
backup: BACKUP_FIELD,
|
|
1600
1651
|
},
|
|
1601
1652
|
annotations: { idempotentHint: false },
|
|
1602
1653
|
_meta: { idempotent: "false" },
|
|
1603
|
-
}, async ({ page_id, label, match_text, auto_index, occurrence, dry_run }) => {
|
|
1654
|
+
}, async ({ page_id, label, match_text, auto_index, occurrence, dry_run, backup }) => {
|
|
1655
|
+
const backupGate = backupCapabilityError("diviops_module_unlock", backup);
|
|
1656
|
+
if (backupGate)
|
|
1657
|
+
return backupGate;
|
|
1604
1658
|
const body = {};
|
|
1605
1659
|
if (label)
|
|
1606
1660
|
body.label = label;
|
|
@@ -1612,6 +1666,8 @@ registerPluginTool("diviops_module_unlock", {
|
|
|
1612
1666
|
body.occurrence = occurrence;
|
|
1613
1667
|
if (dry_run)
|
|
1614
1668
|
body.dry_run = true;
|
|
1669
|
+
if (backup)
|
|
1670
|
+
body.backup = true;
|
|
1615
1671
|
const result = await wp.requestEnveloped(`/module/unlock/${page_id}`, { method: "POST", body });
|
|
1616
1672
|
return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_module_unlock") }] };
|
|
1617
1673
|
});
|
|
@@ -1626,10 +1682,14 @@ registerPluginTool("diviops_module_clone", {
|
|
|
1626
1682
|
occurrence: z.number().int().min(1).optional().default(1).describe("Which occurrence when multiple modules share the same label (1-based)"),
|
|
1627
1683
|
position: z.enum(["before", "after"]).optional().default("after").describe('Place the clone "before" or "after" the source module within its parent.'),
|
|
1628
1684
|
dry_run: DRY_RUN_FIELD,
|
|
1685
|
+
backup: BACKUP_FIELD,
|
|
1629
1686
|
},
|
|
1630
1687
|
annotations: { idempotentHint: false },
|
|
1631
1688
|
_meta: { idempotent: "false" },
|
|
1632
|
-
}, async ({ page_id, label, match_text, auto_index, occurrence, position, dry_run }) => {
|
|
1689
|
+
}, async ({ page_id, label, match_text, auto_index, occurrence, position, dry_run, backup }) => {
|
|
1690
|
+
const backupGate = backupCapabilityError("diviops_module_clone", backup);
|
|
1691
|
+
if (backupGate)
|
|
1692
|
+
return backupGate;
|
|
1633
1693
|
const body = {};
|
|
1634
1694
|
if (label)
|
|
1635
1695
|
body.label = label;
|
|
@@ -1643,6 +1703,8 @@ registerPluginTool("diviops_module_clone", {
|
|
|
1643
1703
|
body.position = position;
|
|
1644
1704
|
if (dry_run)
|
|
1645
1705
|
body.dry_run = true;
|
|
1706
|
+
if (backup)
|
|
1707
|
+
body.backup = true;
|
|
1646
1708
|
const result = await wp.requestEnveloped(`/module/clone/${page_id}`, { method: "POST", body });
|
|
1647
1709
|
return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_module_clone") }] };
|
|
1648
1710
|
});
|
|
@@ -1666,11 +1728,11 @@ registerPluginTool("diviops_page_create", {
|
|
|
1666
1728
|
annotations: { idempotentHint: false },
|
|
1667
1729
|
_meta: { idempotent: "false" },
|
|
1668
1730
|
}, async ({ title, content, status, dry_run }) => {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1731
|
+
const isolationGate = writerIsolationErrorResult("diviops_page_create", {
|
|
1732
|
+
content: content ?? "",
|
|
1733
|
+
});
|
|
1734
|
+
if (isolationGate)
|
|
1735
|
+
return isolationGate;
|
|
1674
1736
|
const body = { title, content: content ?? "", status: status ?? "draft" };
|
|
1675
1737
|
if (dry_run)
|
|
1676
1738
|
body.dry_run = true;
|
|
@@ -1776,6 +1838,113 @@ registerPluginTool("diviops_preset_audit_storage", {
|
|
|
1776
1838
|
],
|
|
1777
1839
|
};
|
|
1778
1840
|
});
|
|
1841
|
+
registerPluginTool("diviops_preset_inspect", {
|
|
1842
|
+
description: "Inspect one Divi 5 preset UUID without writing. Returns bucket/type/module/group coordinates, attrs/styleAttrs/renderAttrs, storage path and provenance, block plus preset-chain reference counts with sample consumers, geometry-scope warnings for layout/position/sizing/transform attrs, and a warning when the same UUID also exists in nested D5 or legacy _ng storage. This is intentionally narrower than diviops_preset_audit and has no repair mode. Missing UUID returns not_found.",
|
|
1843
|
+
inputSchema: {
|
|
1844
|
+
preset_id: z.string().min(1).describe("Preset UUID to inspect."),
|
|
1845
|
+
},
|
|
1846
|
+
annotations: { idempotentHint: true },
|
|
1847
|
+
_meta: { idempotent: "true" },
|
|
1848
|
+
}, async ({ preset_id }) => {
|
|
1849
|
+
const result = await wp.requestEnveloped(`/preset/inspect/${encodeURIComponent(preset_id)}`);
|
|
1850
|
+
return {
|
|
1851
|
+
content: [
|
|
1852
|
+
{ type: "text", text: serializeEnvelope(result, "diviops_preset_inspect") },
|
|
1853
|
+
],
|
|
1854
|
+
};
|
|
1855
|
+
});
|
|
1856
|
+
registerPluginTool("diviops_preset_registry_doctor", {
|
|
1857
|
+
description: "Audit the canonical Divi 5 preset registry for non-integer created/updated metadata and stale or failed preset chunk transients. repair=false is always read-only. repair=true only converts parseable ISO timestamps to integer milliseconds, creates a non-autoloaded backup before mutation, preserves unrelated preset payloads, and can optionally clear stale/failed matching chunk transients after a successful repair. Unsupported timestamp values are reported but never normalized." +
|
|
1858
|
+
DRY_RUN_DESC_SUFFIX,
|
|
1859
|
+
inputSchema: {
|
|
1860
|
+
repair: z.boolean().optional().default(false).describe("Enable the narrow ISO timestamp repair path."),
|
|
1861
|
+
clear_chunk_transients: z.boolean().optional().default(false).describe("After successful repair, clear only stale or failed matching Divi preset chunk transients."),
|
|
1862
|
+
dry_run: z.boolean().optional().default(true).describe("Preview repair and transient cleanup without mutation."),
|
|
1863
|
+
limit: z.number().int().min(1).max(500).optional().default(100).describe("Maximum findings and transient rows to return."),
|
|
1864
|
+
},
|
|
1865
|
+
_meta: { idempotent: "conditional" },
|
|
1866
|
+
}, async ({ repair, clear_chunk_transients, dry_run, limit }) => {
|
|
1867
|
+
const result = await wp.requestEnveloped("/preset/registry-doctor", {
|
|
1868
|
+
method: "POST",
|
|
1869
|
+
body: { repair, clear_chunk_transients, dry_run, limit },
|
|
1870
|
+
});
|
|
1871
|
+
return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_preset_registry_doctor") }] };
|
|
1872
|
+
});
|
|
1873
|
+
registerPluginTool("diviops_rollback_snapshot_list", {
|
|
1874
|
+
description: "List DiviOps rollback snapshots from the option-backed store. Free/core storage management read surface; returns metadata only, never stored before.value payloads. Supports target_kind, target_id, status, and limit filters. Results are target-permission filtered; missing-target snapshots are shown only to site admins or the snapshot creator and are payload-redacted. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
1875
|
+
inputSchema: {
|
|
1876
|
+
target_kind: z.string().optional().describe("Optional target kind filter, usually post."),
|
|
1877
|
+
target_id: z.number().int().positive().optional().describe("Optional target post/layout ID filter."),
|
|
1878
|
+
status: z.string().optional().describe("Optional snapshot status filter, such as created or write_applied."),
|
|
1879
|
+
limit: z.number().int().min(1).max(100).optional().default(20).describe("Maximum snapshots to return."),
|
|
1880
|
+
},
|
|
1881
|
+
annotations: { idempotentHint: true },
|
|
1882
|
+
_meta: { idempotent: "true" },
|
|
1883
|
+
}, async ({ target_kind, target_id, status, limit }) => {
|
|
1884
|
+
const params = {};
|
|
1885
|
+
if (target_kind)
|
|
1886
|
+
params.target_kind = target_kind;
|
|
1887
|
+
if (target_id)
|
|
1888
|
+
params.target_id = String(target_id);
|
|
1889
|
+
if (status)
|
|
1890
|
+
params.status = status;
|
|
1891
|
+
if (limit && limit !== 20)
|
|
1892
|
+
params.limit = String(limit);
|
|
1893
|
+
const qs = new URLSearchParams(params).toString();
|
|
1894
|
+
const result = await wp.requestEnveloped(`/rollback-snapshot/list${qs ? `?${qs}` : ""}`);
|
|
1895
|
+
return {
|
|
1896
|
+
content: [
|
|
1897
|
+
{ type: "text", text: serializeEnvelope(result, "diviops_rollback_snapshot_list") },
|
|
1898
|
+
],
|
|
1899
|
+
};
|
|
1900
|
+
});
|
|
1901
|
+
registerPluginTool("diviops_rollback_snapshot_get", {
|
|
1902
|
+
description: "Inspect one rollback snapshot. Free/core storage management read surface. include_value defaults false; true returns the stored before.value and captured side-effect payload only when the referenced target still exists and the caller passes the target-level permission gate. Missing-target snapshots are metadata-only for admins/creators. No restore path in this tool. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
1903
|
+
inputSchema: {
|
|
1904
|
+
snapshot_id: z.string().min(1).describe("Snapshot id returned by diviops_rollback_snapshot_list."),
|
|
1905
|
+
include_value: z.boolean().optional().default(false).describe("Include stored before.value and side-effect payload when target access allows it."),
|
|
1906
|
+
},
|
|
1907
|
+
annotations: { idempotentHint: true },
|
|
1908
|
+
_meta: { idempotent: "true" },
|
|
1909
|
+
}, async ({ snapshot_id, include_value }) => {
|
|
1910
|
+
const params = include_value ? "?include_value=true" : "";
|
|
1911
|
+
const result = await wp.requestEnveloped(`/rollback-snapshot/get/${encodeURIComponent(snapshot_id)}${params}`);
|
|
1912
|
+
return {
|
|
1913
|
+
content: [
|
|
1914
|
+
{ type: "text", text: serializeEnvelope(result, "diviops_rollback_snapshot_get") },
|
|
1915
|
+
],
|
|
1916
|
+
};
|
|
1917
|
+
});
|
|
1918
|
+
registerPluginTool("diviops_rollback_snapshot_delete", {
|
|
1919
|
+
description: "Hard-delete one rollback snapshot option after operator acceptance. Free/core cleanup surface; normally requires target-level permission, with a missing-target cleanup path for site admins or the snapshot creator. Does not expose before.value and does not restore content. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
|
|
1920
|
+
inputSchema: {
|
|
1921
|
+
snapshot_id: z.string().min(1).describe("Snapshot id to delete."),
|
|
1922
|
+
},
|
|
1923
|
+
annotations: { idempotentHint: true },
|
|
1924
|
+
_meta: { idempotent: "true" },
|
|
1925
|
+
}, async ({ snapshot_id }) => {
|
|
1926
|
+
const result = await wp.requestEnveloped(`/rollback-snapshot/delete/${encodeURIComponent(snapshot_id)}`, { method: "POST" });
|
|
1927
|
+
return {
|
|
1928
|
+
content: [
|
|
1929
|
+
{ type: "text", text: serializeEnvelope(result, "diviops_rollback_snapshot_delete") },
|
|
1930
|
+
],
|
|
1931
|
+
};
|
|
1932
|
+
});
|
|
1933
|
+
registerPluginTool("diviops_rollback_snapshot_restore", {
|
|
1934
|
+
description: "Restore one guarded rollback snapshot to its original post/page or Theme Builder layout target. Requires target edit permission, refuses content or captured Divi post-meta checksum drift with conflict before mutation, has no force override, writes through the shared full-content integrity/readback guard, restores captured supported post meta, invalidates Divi cache, and marks restore_applied only after verified readback. dry_run previews without writing. This MVP does not create a second pre-restore snapshot. Returns the standardized envelope.",
|
|
1935
|
+
inputSchema: {
|
|
1936
|
+
snapshot_id: z.string().min(1).describe("Snapshot id to restore."),
|
|
1937
|
+
dry_run: z.boolean().optional().default(false).describe("Preview the checksum-bound restore without mutation."),
|
|
1938
|
+
},
|
|
1939
|
+
_meta: { idempotent: "false" },
|
|
1940
|
+
}, async ({ snapshot_id, dry_run }) => {
|
|
1941
|
+
const result = await wp.requestEnveloped(`/rollback-snapshot/restore/${encodeURIComponent(snapshot_id)}`, { method: "POST", body: { dry_run } });
|
|
1942
|
+
return {
|
|
1943
|
+
content: [
|
|
1944
|
+
{ type: "text", text: serializeEnvelope(result, "diviops_rollback_snapshot_restore") },
|
|
1945
|
+
],
|
|
1946
|
+
};
|
|
1947
|
+
});
|
|
1779
1948
|
registerPluginTool("diviops_preset_cleanup", {
|
|
1780
1949
|
description: 'Clean up presets. Default: remove spam presets. Optional: dedup=true to also remove duplicates, action="rename_strip_prefix" with prefix to strip a name prefix, or action="remove_orphans" with scope="spam"|"all" to remove unreferenced presets. Use dry_run: true (default) to preview the standard `data.plan = { summary, changes[] }` without mutating; legacy removed/renamed/deduped summary arrays are preserved as sibling metadata. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.',
|
|
1781
1950
|
inputSchema: {
|
|
@@ -1844,6 +2013,11 @@ registerPluginTool("diviops_preset_update", {
|
|
|
1844
2013
|
annotations: { idempotentHint: false },
|
|
1845
2014
|
_meta: { idempotent: "conditional" },
|
|
1846
2015
|
}, async ({ preset_id, name, attrs, priority, dry_run }) => {
|
|
2016
|
+
const isolationGate = writerIsolationErrorResult("diviops_preset_update", {
|
|
2017
|
+
attrs,
|
|
2018
|
+
});
|
|
2019
|
+
if (isolationGate)
|
|
2020
|
+
return isolationGate;
|
|
1847
2021
|
const body = { preset_id };
|
|
1848
2022
|
if (name)
|
|
1849
2023
|
body.name = name;
|
|
@@ -1934,6 +2108,11 @@ registerPluginTool("diviops_preset_create", {
|
|
|
1934
2108
|
if (type === "group" && (!group_name || !group_id)) {
|
|
1935
2109
|
throw new Error('type="group" requires both group_name and group_id. Example: group_name="divi/font", group_id="designTitleText".');
|
|
1936
2110
|
}
|
|
2111
|
+
const isolationGate = writerIsolationErrorResult("diviops_preset_create", {
|
|
2112
|
+
attrs,
|
|
2113
|
+
});
|
|
2114
|
+
if (isolationGate)
|
|
2115
|
+
return isolationGate;
|
|
1937
2116
|
const body = { module_name, name, attrs, type };
|
|
1938
2117
|
if (group_name)
|
|
1939
2118
|
body.group_name = group_name;
|
|
@@ -2136,6 +2315,11 @@ registerPluginTool("diviops_library_save", {
|
|
|
2136
2315
|
annotations: { idempotentHint: false },
|
|
2137
2316
|
_meta: { idempotent: "conditional" },
|
|
2138
2317
|
}, async ({ title, content, layout_type, scope, dry_run }) => {
|
|
2318
|
+
const isolationGate = writerIsolationErrorResult("diviops_library_save", {
|
|
2319
|
+
content,
|
|
2320
|
+
});
|
|
2321
|
+
if (isolationGate)
|
|
2322
|
+
return isolationGate;
|
|
2139
2323
|
const body = { title, content, layout_type, scope };
|
|
2140
2324
|
if (dry_run)
|
|
2141
2325
|
body.dry_run = true;
|
|
@@ -2305,13 +2489,22 @@ registerPluginTool("diviops_tb_layout_update", {
|
|
|
2305
2489
|
layout_id: z.number().describe("Layout post ID to update"),
|
|
2306
2490
|
content: z.string().describe("New block markup content"),
|
|
2307
2491
|
dry_run: DRY_RUN_FIELD,
|
|
2492
|
+
backup: BACKUP_FIELD,
|
|
2308
2493
|
},
|
|
2309
2494
|
annotations: { idempotentHint: false },
|
|
2310
2495
|
_meta: { idempotent: "conditional" },
|
|
2311
|
-
}, async ({ layout_id, content, dry_run }) => {
|
|
2496
|
+
}, async ({ layout_id, content, dry_run, backup }) => {
|
|
2497
|
+
const backupGate = backupCapabilityError("diviops_tb_layout_update", backup);
|
|
2498
|
+
if (backupGate)
|
|
2499
|
+
return backupGate;
|
|
2500
|
+
const isolationGate = writerIsolationErrorResult("diviops_tb_layout_update", { content });
|
|
2501
|
+
if (isolationGate)
|
|
2502
|
+
return isolationGate;
|
|
2312
2503
|
const body = { content };
|
|
2313
2504
|
if (dry_run)
|
|
2314
2505
|
body.dry_run = true;
|
|
2506
|
+
if (backup)
|
|
2507
|
+
body.backup = true;
|
|
2315
2508
|
const result = await wp.requestEnveloped(`/theme-builder/layout/update/${layout_id}`, {
|
|
2316
2509
|
method: "PUT",
|
|
2317
2510
|
body,
|
|
@@ -2342,10 +2535,17 @@ registerPluginTool("diviops_tb_layout_block_insert", {
|
|
|
2342
2535
|
.describe("Where to insert relative to the target block."),
|
|
2343
2536
|
content: z.string().describe("One or more serialized Divi blocks to insert"),
|
|
2344
2537
|
dry_run: DRY_RUN_FIELD,
|
|
2538
|
+
backup: BACKUP_FIELD,
|
|
2345
2539
|
},
|
|
2346
2540
|
annotations: { idempotentHint: false },
|
|
2347
2541
|
_meta: { idempotent: "conditional" },
|
|
2348
|
-
}, async ({ layout_id, parent_selector, parent_path, position, content, dry_run }) => {
|
|
2542
|
+
}, async ({ layout_id, parent_selector, parent_path, position, content, dry_run, backup }) => {
|
|
2543
|
+
const backupGate = backupCapabilityError("diviops_tb_layout_block_insert", backup);
|
|
2544
|
+
if (backupGate)
|
|
2545
|
+
return backupGate;
|
|
2546
|
+
const isolationGate = writerIsolationErrorResult("diviops_tb_layout_block_insert", { content });
|
|
2547
|
+
if (isolationGate)
|
|
2548
|
+
return isolationGate;
|
|
2349
2549
|
const body = {
|
|
2350
2550
|
content,
|
|
2351
2551
|
position: position ?? "append",
|
|
@@ -2356,6 +2556,8 @@ registerPluginTool("diviops_tb_layout_block_insert", {
|
|
|
2356
2556
|
body.parent_path = parent_path;
|
|
2357
2557
|
if (dry_run)
|
|
2358
2558
|
body.dry_run = true;
|
|
2559
|
+
if (backup)
|
|
2560
|
+
body.backup = true;
|
|
2359
2561
|
const result = await wp.requestEnveloped(`/theme-builder/layout/block-insert/${layout_id}`, {
|
|
2360
2562
|
method: "POST",
|
|
2361
2563
|
body,
|
|
@@ -2389,6 +2591,9 @@ registerPluginTool("diviops_tb_template_create", {
|
|
|
2389
2591
|
annotations: { idempotentHint: false },
|
|
2390
2592
|
_meta: { idempotent: "false" },
|
|
2391
2593
|
}, async ({ title, condition, header_content, footer_content, dry_run }) => {
|
|
2594
|
+
const isolationGate = writerIsolationErrorResult("diviops_tb_template_create", { header_content, footer_content });
|
|
2595
|
+
if (isolationGate)
|
|
2596
|
+
return isolationGate;
|
|
2392
2597
|
const body = { title, condition, header_content, footer_content };
|
|
2393
2598
|
if (dry_run)
|
|
2394
2599
|
body.dry_run = true;
|
|
@@ -2464,6 +2669,11 @@ registerPluginTool("diviops_canvas_create", {
|
|
|
2464
2669
|
annotations: { idempotentHint: false },
|
|
2465
2670
|
_meta: { idempotent: "conditional" },
|
|
2466
2671
|
}, async ({ title, parent_page_id, content, canvas_id, append_to_main, z_index, dry_run, }) => {
|
|
2672
|
+
const isolationGate = writerIsolationErrorResult("diviops_canvas_create", {
|
|
2673
|
+
content: content ?? "",
|
|
2674
|
+
});
|
|
2675
|
+
if (isolationGate)
|
|
2676
|
+
return isolationGate;
|
|
2467
2677
|
const body = {
|
|
2468
2678
|
title,
|
|
2469
2679
|
parent_page_id,
|
|
@@ -2606,6 +2816,11 @@ registerPluginTool("diviops_canvas_update", {
|
|
|
2606
2816
|
annotations: { idempotentHint: false },
|
|
2607
2817
|
_meta: { idempotent: "conditional" },
|
|
2608
2818
|
}, async ({ canvas_post_id, content, title, append_to_main, z_index, dry_run }) => {
|
|
2819
|
+
const isolationGate = writerIsolationErrorResult("diviops_canvas_update", {
|
|
2820
|
+
content,
|
|
2821
|
+
});
|
|
2822
|
+
if (isolationGate)
|
|
2823
|
+
return isolationGate;
|
|
2609
2824
|
const body = {};
|
|
2610
2825
|
if (content !== undefined)
|
|
2611
2826
|
body.content = content;
|
|
@@ -3843,6 +4058,10 @@ function registerProTools() {
|
|
|
3843
4058
|
withCode("cross_env.source_payload_ref_invalid", err instanceof Error ? err.message : String(err), "Re-run diviops_cross_env_source_export_get and pass the fresh data.source_payload_ref.", { source_payload_ref });
|
|
3844
4059
|
}
|
|
3845
4060
|
}
|
|
4061
|
+
const isolationHits = scanValueForForeignVarRefs(resolvedSourcePayload.markup, "source_payload.markup");
|
|
4062
|
+
if (isolationHits.length > 0) {
|
|
4063
|
+
return isolationFailure("diviops_cross_env_header_apply", isolationHits);
|
|
4064
|
+
}
|
|
3846
4065
|
const targetBody = {
|
|
3847
4066
|
destination_id,
|
|
3848
4067
|
destination_kind: destination_kind ?? "tb_header_layout",
|
|
@@ -4382,22 +4601,7 @@ function registerProTools() {
|
|
|
4382
4601
|
handshakeState.kind === "ok" &&
|
|
4383
4602
|
!handshakeState.capabilities["fluentcart_license_update_file_set"]) {
|
|
4384
4603
|
const err = new MissingCapabilityError("fluentcart_license_update_file_set", handshakeState.pluginVersion);
|
|
4385
|
-
|
|
4386
|
-
ok: false,
|
|
4387
|
-
error: {
|
|
4388
|
-
code: ErrorCodes.CAPABILITY_MISSING,
|
|
4389
|
-
message: err.message,
|
|
4390
|
-
hint: "Update the diviops-agent-pro WP plugin to a version that supports authoring the global_update_file pointer, or omit global_update_file from this call.",
|
|
4391
|
-
},
|
|
4392
|
-
};
|
|
4393
|
-
return {
|
|
4394
|
-
content: [
|
|
4395
|
-
{
|
|
4396
|
-
type: "text",
|
|
4397
|
-
text: serializeEnvelope(failure, "diviops_fc_license_settings_update"),
|
|
4398
|
-
},
|
|
4399
|
-
],
|
|
4400
|
-
};
|
|
4604
|
+
return missingCapabilityEnvelope(err, "diviops_fc_license_settings_update", "Update the diviops-agent-pro WP plugin to a version that supports authoring the global_update_file pointer, or omit global_update_file from this call.");
|
|
4401
4605
|
}
|
|
4402
4606
|
const body = {};
|
|
4403
4607
|
if (enabled !== undefined)
|
package/dist/preset-cli/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ import { emitTextBodyFontGroupPreset, buildTextBodyFontPresetCreateBody, } from
|
|
|
31
31
|
import { emitSpacingGroupPreset, buildSpacingPresetCreateBody, } from "./spacing-emitter.js";
|
|
32
32
|
import { emitNavBlockMarkup, buildNavMarkupBody, parseNavSpecJson, } from "./nav-emitter.js";
|
|
33
33
|
import { EvidenceGateError } from "./registry.js";
|
|
34
|
-
import { applyButtonPreset, applyHeadingFontPreset, applyTextBodyFontPreset, applySpacingPreset, buildClientFromEnv, CredentialsMissingError, CapabilityMissingError, } from "./write-path.js";
|
|
34
|
+
import { applyButtonPreset, applyHeadingFontPreset, applyTextBodyFontPreset, applySpacingPreset, buildClientFromEnv, CredentialsMissingError, CapabilityMissingError, PresetIsolationError, } from "./write-path.js";
|
|
35
35
|
export const EXIT = {
|
|
36
36
|
OK: 0,
|
|
37
37
|
INVALID_INPUT: 1,
|
|
@@ -697,6 +697,10 @@ export async function run(argv, io = realIO, serverVersion) {
|
|
|
697
697
|
io.err(err.message);
|
|
698
698
|
return EXIT.INVALID_INPUT;
|
|
699
699
|
}
|
|
700
|
+
if (err instanceof PresetIsolationError) {
|
|
701
|
+
io.err(err.message);
|
|
702
|
+
return EXIT.INVALID_INPUT;
|
|
703
|
+
}
|
|
700
704
|
io.err(`Write failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
701
705
|
return EXIT.WRITE_ERROR;
|
|
702
706
|
}
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* - `WPClient` from `wp-client.ts` for the HTTP + Basic-Auth machinery.
|
|
7
7
|
* - `WPClient.handshake()` for the plugin capability map.
|
|
8
8
|
*
|
|
9
|
-
* Before any
|
|
10
|
-
* `storage_multipath_probe_v1`
|
|
11
|
-
* contract, shipped in plugin 1.4.9).
|
|
12
|
-
* a write.
|
|
9
|
+
* Before any network call the CLI rejects foreign CSS aliases in attrs, then
|
|
10
|
+
* verifies the plugin handshake reports `storage_multipath_probe_v1` (the
|
|
11
|
+
* storage-path capability contract, shipped in plugin 1.4.9).
|
|
13
12
|
*
|
|
14
13
|
* `--dry-run` never reaches this module: it requires no credentials, no
|
|
15
14
|
* handshake, and no network.
|
|
@@ -17,6 +16,7 @@
|
|
|
17
16
|
import { WPClient } from "../wp-client.js";
|
|
18
17
|
import type { HandshakeResult } from "../compatibility.js";
|
|
19
18
|
import type { DiviopsResponse } from "../envelope.js";
|
|
19
|
+
import { type ForeignVarRef } from "../validate-attrs.js";
|
|
20
20
|
import type { ButtonPresetEntry } from "./button-emitter.js";
|
|
21
21
|
import type { HeadingFontPresetEntry } from "./heading-font-emitter.js";
|
|
22
22
|
import type { TextBodyFontPresetEntry } from "./text-body-font-emitter.js";
|
|
@@ -42,6 +42,12 @@ export declare class CapabilityMissingError extends Error {
|
|
|
42
42
|
readonly pluginVersion: string;
|
|
43
43
|
constructor(capability: string, pluginVersion: string);
|
|
44
44
|
}
|
|
45
|
+
export declare class PresetIsolationError extends Error {
|
|
46
|
+
readonly refs: ForeignVarRef[];
|
|
47
|
+
constructor(refs: ForeignVarRef[]);
|
|
48
|
+
}
|
|
49
|
+
/** Refuse foreign CSS aliases in a preset body before any network call. */
|
|
50
|
+
export declare function assertPresetBodyIsolation(body: Record<string, unknown>): void;
|
|
45
51
|
/** Build a `WPClient` from the standard env vars, or throw if any are absent. */
|
|
46
52
|
export declare function buildClientFromEnv(env?: NodeJS.ProcessEnv): WPClient;
|
|
47
53
|
/**
|
|
@@ -51,20 +57,19 @@ export declare function buildClientFromEnv(env?: NodeJS.ProcessEnv): WPClient;
|
|
|
51
57
|
*/
|
|
52
58
|
export declare function assertStorageCapability(client: PresetWriteClient, serverVersion: string): Promise<HandshakeResult>;
|
|
53
59
|
/**
|
|
54
|
-
* Apply a button preset: capability
|
|
60
|
+
* Apply a button preset: isolation gate, capability gate, then POST.
|
|
55
61
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
62
|
+
* Both gates run BEFORE the write. The write goes through the existing
|
|
63
|
+
* storage-routed route — no plugin route is added here.
|
|
58
64
|
*/
|
|
59
65
|
export declare function applyButtonPreset(client: PresetWriteClient, entry: ButtonPresetEntry, opts: {
|
|
60
66
|
serverVersion: string;
|
|
61
67
|
dry_run?: boolean;
|
|
62
68
|
}): Promise<DiviopsResponse<unknown>>;
|
|
63
69
|
/**
|
|
64
|
-
* Apply a `divi/font` heading group preset:
|
|
65
|
-
* to `/preset/create`. Mirrors `applyButtonPreset`'s sequence
|
|
66
|
-
*
|
|
67
|
-
* existing storage-routed route (no plugin route is added).
|
|
70
|
+
* Apply a `divi/font` heading group preset: isolation gate, capability gate,
|
|
71
|
+
* then POST to `/preset/create`. Mirrors `applyButtonPreset`'s sequence and
|
|
72
|
+
* reuses the existing storage-routed route (no plugin route is added).
|
|
68
73
|
*
|
|
69
74
|
* The `pattern_variant` metadata is intentionally NOT in the wire body —
|
|
70
75
|
* variant selection is a client-side registry-gate decision and the
|
|
@@ -76,10 +81,9 @@ export declare function applyHeadingFontPreset(client: PresetWriteClient, entry:
|
|
|
76
81
|
}): Promise<DiviopsResponse<unknown>>;
|
|
77
82
|
/**
|
|
78
83
|
* Apply a `divi/font-body` body-text group preset for `divi/text`:
|
|
79
|
-
* capability
|
|
80
|
-
* `applyHeadingFontPreset`'s sequence
|
|
81
|
-
*
|
|
82
|
-
* plugin route is added).
|
|
84
|
+
* isolation gate, capability gate, then POST to `/preset/create`. Mirrors
|
|
85
|
+
* `applyHeadingFontPreset`'s sequence and reuses the existing storage-routed
|
|
86
|
+
* route (no plugin route is added).
|
|
83
87
|
*
|
|
84
88
|
* The `pattern_variant` metadata is intentionally NOT in the wire body —
|
|
85
89
|
* variant selection is a client-side registry-gate decision and the
|
|
@@ -90,10 +94,10 @@ export declare function applyTextBodyFontPreset(client: PresetWriteClient, entry
|
|
|
90
94
|
dry_run?: boolean;
|
|
91
95
|
}): Promise<DiviopsResponse<unknown>>;
|
|
92
96
|
/**
|
|
93
|
-
* Apply a `divi/spacing` section group preset:
|
|
94
|
-
* to `/preset/create`. Mirrors `applyTextBodyFontPreset`'s
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
+
* Apply a `divi/spacing` section group preset: isolation gate, capability
|
|
98
|
+
* gate, then POST to `/preset/create`. Mirrors `applyTextBodyFontPreset`'s
|
|
99
|
+
* sequence and reuses the existing storage-routed route (no plugin route is
|
|
100
|
+
* added).
|
|
97
101
|
*
|
|
98
102
|
* Unlike the font emitters, the spacing entry carries `primary_attr_name`
|
|
99
103
|
* (`"module"` for the section cell per the canonical capture), which IS
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* - `WPClient` from `wp-client.ts` for the HTTP + Basic-Auth machinery.
|
|
7
7
|
* - `WPClient.handshake()` for the plugin capability map.
|
|
8
8
|
*
|
|
9
|
-
* Before any
|
|
10
|
-
* `storage_multipath_probe_v1`
|
|
11
|
-
* contract, shipped in plugin 1.4.9).
|
|
12
|
-
* a write.
|
|
9
|
+
* Before any network call the CLI rejects foreign CSS aliases in attrs, then
|
|
10
|
+
* verifies the plugin handshake reports `storage_multipath_probe_v1` (the
|
|
11
|
+
* storage-path capability contract, shipped in plugin 1.4.9).
|
|
13
12
|
*
|
|
14
13
|
* `--dry-run` never reaches this module: it requires no credentials, no
|
|
15
14
|
* handshake, and no network.
|
|
16
15
|
*/
|
|
17
16
|
import { WPClient } from "../wp-client.js";
|
|
17
|
+
import { formatIsolationError, scanAttrsForForeignVarRefs, } from "../validate-attrs.js";
|
|
18
18
|
import { buildPresetCreateBody } from "./button-emitter.js";
|
|
19
19
|
import { buildHeadingFontPresetCreateBody } from "./heading-font-emitter.js";
|
|
20
20
|
import { buildTextBodyFontPresetCreateBody } from "./text-body-font-emitter.js";
|
|
@@ -44,6 +44,24 @@ export class CapabilityMissingError extends Error {
|
|
|
44
44
|
this.name = "CapabilityMissingError";
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
export class PresetIsolationError extends Error {
|
|
48
|
+
refs;
|
|
49
|
+
constructor(refs) {
|
|
50
|
+
super(formatIsolationError("diviops-preset --apply", refs));
|
|
51
|
+
this.refs = refs;
|
|
52
|
+
this.name = "PresetIsolationError";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Refuse foreign CSS aliases in a preset body before any network call. */
|
|
56
|
+
export function assertPresetBodyIsolation(body) {
|
|
57
|
+
const attrs = body.attrs;
|
|
58
|
+
if (typeof attrs !== "object" || attrs === null || Array.isArray(attrs)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const hits = scanAttrsForForeignVarRefs(attrs);
|
|
62
|
+
if (hits.length > 0)
|
|
63
|
+
throw new PresetIsolationError(hits);
|
|
64
|
+
}
|
|
47
65
|
/** Build a `WPClient` from the standard env vars, or throw if any are absent. */
|
|
48
66
|
export function buildClientFromEnv(env = process.env) {
|
|
49
67
|
const url = env.WP_URL ?? "";
|
|
@@ -76,66 +94,60 @@ export async function assertStorageCapability(client, serverVersion) {
|
|
|
76
94
|
}
|
|
77
95
|
return hs;
|
|
78
96
|
}
|
|
97
|
+
async function applyPresetBody(client, body, serverVersion) {
|
|
98
|
+
assertPresetBodyIsolation(body);
|
|
99
|
+
await assertStorageCapability(client, serverVersion);
|
|
100
|
+
return client.requestEnveloped(PRESET_CREATE_ROUTE, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
79
105
|
/**
|
|
80
|
-
* Apply a button preset: capability
|
|
106
|
+
* Apply a button preset: isolation gate, capability gate, then POST.
|
|
81
107
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
108
|
+
* Both gates run BEFORE the write. The write goes through the existing
|
|
109
|
+
* storage-routed route — no plugin route is added here.
|
|
84
110
|
*/
|
|
85
111
|
export async function applyButtonPreset(client, entry, opts) {
|
|
86
|
-
await assertStorageCapability(client, opts.serverVersion);
|
|
87
112
|
const body = buildPresetCreateBody(entry, { dry_run: opts.dry_run });
|
|
88
|
-
return client
|
|
89
|
-
method: "POST",
|
|
90
|
-
body,
|
|
91
|
-
});
|
|
113
|
+
return applyPresetBody(client, body, opts.serverVersion);
|
|
92
114
|
}
|
|
93
115
|
/**
|
|
94
|
-
* Apply a `divi/font` heading group preset:
|
|
95
|
-
* to `/preset/create`. Mirrors `applyButtonPreset`'s sequence
|
|
96
|
-
*
|
|
97
|
-
* existing storage-routed route (no plugin route is added).
|
|
116
|
+
* Apply a `divi/font` heading group preset: isolation gate, capability gate,
|
|
117
|
+
* then POST to `/preset/create`. Mirrors `applyButtonPreset`'s sequence and
|
|
118
|
+
* reuses the existing storage-routed route (no plugin route is added).
|
|
98
119
|
*
|
|
99
120
|
* The `pattern_variant` metadata is intentionally NOT in the wire body —
|
|
100
121
|
* variant selection is a client-side registry-gate decision and the
|
|
101
122
|
* server route accepts only the standard preset-create fields.
|
|
102
123
|
*/
|
|
103
124
|
export async function applyHeadingFontPreset(client, entry, opts) {
|
|
104
|
-
await assertStorageCapability(client, opts.serverVersion);
|
|
105
125
|
const body = buildHeadingFontPresetCreateBody(entry, {
|
|
106
126
|
dry_run: opts.dry_run,
|
|
107
127
|
});
|
|
108
|
-
return client
|
|
109
|
-
method: "POST",
|
|
110
|
-
body,
|
|
111
|
-
});
|
|
128
|
+
return applyPresetBody(client, body, opts.serverVersion);
|
|
112
129
|
}
|
|
113
130
|
/**
|
|
114
131
|
* Apply a `divi/font-body` body-text group preset for `divi/text`:
|
|
115
|
-
* capability
|
|
116
|
-
* `applyHeadingFontPreset`'s sequence
|
|
117
|
-
*
|
|
118
|
-
* plugin route is added).
|
|
132
|
+
* isolation gate, capability gate, then POST to `/preset/create`. Mirrors
|
|
133
|
+
* `applyHeadingFontPreset`'s sequence and reuses the existing storage-routed
|
|
134
|
+
* route (no plugin route is added).
|
|
119
135
|
*
|
|
120
136
|
* The `pattern_variant` metadata is intentionally NOT in the wire body —
|
|
121
137
|
* variant selection is a client-side registry-gate decision and the
|
|
122
138
|
* server route accepts only the standard preset-create fields.
|
|
123
139
|
*/
|
|
124
140
|
export async function applyTextBodyFontPreset(client, entry, opts) {
|
|
125
|
-
await assertStorageCapability(client, opts.serverVersion);
|
|
126
141
|
const body = buildTextBodyFontPresetCreateBody(entry, {
|
|
127
142
|
dry_run: opts.dry_run,
|
|
128
143
|
});
|
|
129
|
-
return client
|
|
130
|
-
method: "POST",
|
|
131
|
-
body,
|
|
132
|
-
});
|
|
144
|
+
return applyPresetBody(client, body, opts.serverVersion);
|
|
133
145
|
}
|
|
134
146
|
/**
|
|
135
|
-
* Apply a `divi/spacing` section group preset:
|
|
136
|
-
* to `/preset/create`. Mirrors `applyTextBodyFontPreset`'s
|
|
137
|
-
*
|
|
138
|
-
*
|
|
147
|
+
* Apply a `divi/spacing` section group preset: isolation gate, capability
|
|
148
|
+
* gate, then POST to `/preset/create`. Mirrors `applyTextBodyFontPreset`'s
|
|
149
|
+
* sequence and reuses the existing storage-routed route (no plugin route is
|
|
150
|
+
* added).
|
|
139
151
|
*
|
|
140
152
|
* Unlike the font emitters, the spacing entry carries `primary_attr_name`
|
|
141
153
|
* (`"module"` for the section cell per the canonical capture), which IS
|
|
@@ -143,12 +155,8 @@ export async function applyTextBodyFontPreset(client, entry, opts) {
|
|
|
143
155
|
* snake_case param and stores it as `primaryAttrName` in the preset.
|
|
144
156
|
*/
|
|
145
157
|
export async function applySpacingPreset(client, entry, opts) {
|
|
146
|
-
await assertStorageCapability(client, opts.serverVersion);
|
|
147
158
|
const body = buildSpacingPresetCreateBody(entry, {
|
|
148
159
|
dry_run: opts.dry_run,
|
|
149
160
|
});
|
|
150
|
-
return client
|
|
151
|
-
method: "POST",
|
|
152
|
-
body,
|
|
153
|
-
});
|
|
161
|
+
return applyPresetBody(client, body, opts.serverVersion);
|
|
154
162
|
}
|
package/dist/validate-attrs.d.ts
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
* Isolation-rule validator: bans cross-system var(--alias) refs in Divi
|
|
3
|
-
* module attrs. See SKILL.md rule 8 and references/module-formats.md
|
|
4
|
-
* §"Design Token References in Attrs".
|
|
5
|
-
*
|
|
6
|
-
* CSS spec: var(--undeclared-name) with no fallback falls through to the
|
|
7
|
-
* property's initial value (0 for padding, browser default for color).
|
|
8
|
-
* Tool reports success, renderer emits ref as-is, page silently breaks.
|
|
9
|
-
*
|
|
10
|
-
* Only var() refs to gcid-* / gvid-* pass — Divi-owned namespaces that
|
|
11
|
-
* auto-resolve via :root. Any other alias is rejected.
|
|
12
|
-
*/
|
|
1
|
+
import { type DiviopsFailure } from "./envelope.js";
|
|
13
2
|
export interface ForeignVarRef {
|
|
14
3
|
alias: string;
|
|
15
4
|
snippet: string;
|
|
16
5
|
location?: string;
|
|
17
6
|
}
|
|
18
7
|
export declare function findForeignVarRefs(value: unknown, location?: string): ForeignVarRef[];
|
|
8
|
+
/**
|
|
9
|
+
* Recursively scan JSON-like values while preserving stable object and array
|
|
10
|
+
* locations. Unsupported object types are ignored rather than coerced.
|
|
11
|
+
*/
|
|
12
|
+
export declare function scanValueForForeignVarRefs(value: unknown, location?: string): ForeignVarRef[];
|
|
13
|
+
/** Scan only the raw content/attrs fields selected by a writer callsite. */
|
|
14
|
+
export declare function scanWriterPayloadForForeignVarRefs(payload: Record<string, unknown>): ForeignVarRef[];
|
|
19
15
|
export declare function scanAttrsForForeignVarRefs(attrs: Record<string, unknown>): ForeignVarRef[];
|
|
20
16
|
export declare function formatIsolationError(tool: string, hits: ForeignVarRef[]): string;
|
|
17
|
+
export declare function isolationFailure(tool: string, hits: ForeignVarRef[]): DiviopsFailure;
|
|
21
18
|
export declare function isolationErrorResult(tool: string, hits: ForeignVarRef[]): {
|
|
22
19
|
content: {
|
|
23
20
|
type: "text";
|
|
24
21
|
text: string;
|
|
25
22
|
}[];
|
|
26
|
-
isError: boolean;
|
|
27
23
|
};
|
|
24
|
+
export declare function writerIsolationErrorResult(tool: string, payload: Record<string, unknown>): {
|
|
25
|
+
content: {
|
|
26
|
+
type: "text";
|
|
27
|
+
text: string;
|
|
28
|
+
}[];
|
|
29
|
+
} | null;
|
package/dist/validate-attrs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ErrorCodes, serializeEnvelope, } from "./envelope.js";
|
|
1
2
|
/**
|
|
2
3
|
* Isolation-rule validator: bans cross-system var(--alias) refs in Divi
|
|
3
|
-
* module attrs. See SKILL.md rule 8 and references/module-formats.md
|
|
4
|
+
* content and module attrs. See SKILL.md rule 8 and references/module-formats.md
|
|
4
5
|
* §"Design Token References in Attrs".
|
|
5
6
|
*
|
|
6
7
|
* CSS spec: var(--undeclared-name) with no fallback falls through to the
|
|
@@ -12,13 +13,30 @@
|
|
|
12
13
|
*/
|
|
13
14
|
const VAR_REF_RE = /var\(\s*--([A-Za-z_][A-Za-z0-9_-]*)/g;
|
|
14
15
|
const ALLOWED_PREFIXES = ["gcid-", "gvid-"];
|
|
16
|
+
/**
|
|
17
|
+
* Decode JSON Unicode escapes that WordPress block serialization preserves in
|
|
18
|
+
* raw comment markup. Escapes preceded by an odd number of extra backslashes
|
|
19
|
+
* represent a literal `\\uXXXX` sequence after JSON parsing and stay untouched.
|
|
20
|
+
*/
|
|
21
|
+
function decodeJsonUnicodeEscapes(value) {
|
|
22
|
+
return value.replace(/\\u([0-9a-fA-F]{4})/g, (match, hex, offset, input) => {
|
|
23
|
+
let precedingBackslashes = 0;
|
|
24
|
+
for (let index = offset - 1; index >= 0 && input[index] === "\\"; index -= 1) {
|
|
25
|
+
precedingBackslashes += 1;
|
|
26
|
+
}
|
|
27
|
+
if (precedingBackslashes % 2 === 1)
|
|
28
|
+
return match;
|
|
29
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
15
32
|
export function findForeignVarRefs(value, location) {
|
|
16
33
|
if (typeof value !== "string" || value.length === 0)
|
|
17
34
|
return [];
|
|
35
|
+
const normalizedValue = decodeJsonUnicodeEscapes(value);
|
|
18
36
|
const hits = [];
|
|
19
37
|
VAR_REF_RE.lastIndex = 0;
|
|
20
38
|
let m;
|
|
21
|
-
while ((m = VAR_REF_RE.exec(
|
|
39
|
+
while ((m = VAR_REF_RE.exec(normalizedValue)) !== null) {
|
|
22
40
|
const alias = m[1];
|
|
23
41
|
if (ALLOWED_PREFIXES.some((p) => alias.startsWith(p)))
|
|
24
42
|
continue;
|
|
@@ -26,25 +44,64 @@ export function findForeignVarRefs(value, location) {
|
|
|
26
44
|
}
|
|
27
45
|
return hits;
|
|
28
46
|
}
|
|
29
|
-
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
if (typeof value !== "object" || value === null)
|
|
49
|
+
return false;
|
|
50
|
+
const prototype = Object.getPrototypeOf(value);
|
|
51
|
+
return prototype === Object.prototype || prototype === null;
|
|
52
|
+
}
|
|
53
|
+
function childLocation(parent, key) {
|
|
54
|
+
return parent ? `${parent}.${key}` : key;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Recursively scan JSON-like values while preserving stable object and array
|
|
58
|
+
* locations. Unsupported object types are ignored rather than coerced.
|
|
59
|
+
*/
|
|
60
|
+
export function scanValueForForeignVarRefs(value, location) {
|
|
30
61
|
const hits = [];
|
|
31
|
-
|
|
32
|
-
|
|
62
|
+
function scan(current, currentLocation) {
|
|
63
|
+
if (typeof current === "string") {
|
|
64
|
+
hits.push(...findForeignVarRefs(current, currentLocation));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(current)) {
|
|
68
|
+
for (let index = 0; index < current.length; index += 1) {
|
|
69
|
+
scan(current[index], `${currentLocation ?? ""}[${index}]`);
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!isPlainObject(current))
|
|
74
|
+
return;
|
|
75
|
+
for (const [key, child] of Object.entries(current)) {
|
|
76
|
+
scan(child, childLocation(currentLocation, key));
|
|
77
|
+
}
|
|
33
78
|
}
|
|
79
|
+
scan(value, location);
|
|
34
80
|
return hits;
|
|
35
81
|
}
|
|
36
|
-
|
|
82
|
+
/** Scan only the raw content/attrs fields selected by a writer callsite. */
|
|
83
|
+
export function scanWriterPayloadForForeignVarRefs(payload) {
|
|
84
|
+
return scanValueForForeignVarRefs(payload);
|
|
85
|
+
}
|
|
86
|
+
export function scanAttrsForForeignVarRefs(attrs) {
|
|
87
|
+
return scanValueForForeignVarRefs(attrs, "attrs");
|
|
88
|
+
}
|
|
89
|
+
function uniqueForeignVarRefs(hits) {
|
|
37
90
|
const uniq = new Map();
|
|
38
|
-
for (const
|
|
39
|
-
const
|
|
40
|
-
if (!uniq.has(
|
|
41
|
-
uniq.set(
|
|
91
|
+
for (const hit of hits) {
|
|
92
|
+
const key = `${hit.snippet}::${hit.location ?? ""}`;
|
|
93
|
+
if (!uniq.has(key))
|
|
94
|
+
uniq.set(key, hit);
|
|
42
95
|
}
|
|
96
|
+
return [...uniq.values()];
|
|
97
|
+
}
|
|
98
|
+
export function formatIsolationError(tool, hits) {
|
|
99
|
+
const uniqueHits = uniqueForeignVarRefs(hits);
|
|
43
100
|
const lines = [
|
|
44
101
|
`Isolation-rule violation in ${tool}: module attrs cannot reference non-Divi CSS aliases.`,
|
|
45
102
|
"",
|
|
46
103
|
"Offending refs:",
|
|
47
|
-
...
|
|
104
|
+
...uniqueHits.map((h) => ` - ${h.snippet}${h.location ? ` (at ${h.location})` : ""}`),
|
|
48
105
|
"",
|
|
49
106
|
"Allowed: var(--gcid-*) and var(--gvid-*) (Divi-owned, auto-emitted to :root).",
|
|
50
107
|
'Canonical form: $variable({"type":"content","value":{"name":"gvid-your-token","settings":{}}})$',
|
|
@@ -53,11 +110,32 @@ export function formatIsolationError(tool, hits) {
|
|
|
53
110
|
];
|
|
54
111
|
return lines.join("\n");
|
|
55
112
|
}
|
|
113
|
+
export function isolationFailure(tool, hits) {
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
error: {
|
|
117
|
+
code: ErrorCodes.INVALID_INPUT,
|
|
118
|
+
message: `Isolation-rule violation in ${tool}: Divi content and attrs cannot reference non-Divi CSS aliases.`,
|
|
119
|
+
hint: "Use var(--gcid-*) or var(--gvid-*), or register the token in Divi Variable Manager and use Divi's canonical $variable(...)$ reference.",
|
|
120
|
+
data: {
|
|
121
|
+
reason: "foreign_css_variable_ref",
|
|
122
|
+
tool,
|
|
123
|
+
refs: uniqueForeignVarRefs(hits),
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
56
128
|
export function isolationErrorResult(tool, hits) {
|
|
57
129
|
return {
|
|
58
130
|
content: [
|
|
59
|
-
{
|
|
131
|
+
{
|
|
132
|
+
type: "text",
|
|
133
|
+
text: serializeEnvelope(isolationFailure(tool, hits), tool),
|
|
134
|
+
},
|
|
60
135
|
],
|
|
61
|
-
isError: true,
|
|
62
136
|
};
|
|
63
137
|
}
|
|
138
|
+
export function writerIsolationErrorResult(tool, payload) {
|
|
139
|
+
const hits = scanWriterPayloadForForeignVarRefs(payload);
|
|
140
|
+
return hits.length > 0 ? isolationErrorResult(tool, hits) : null;
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diviops/mcp-server",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.35",
|
|
4
4
|
"description": "MCP server exposing Divi 5 Visual Builder as tools for Claude",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"build": "tsc",
|
|
22
22
|
"start": "node dist/index.js",
|
|
23
23
|
"dev": "tsc --watch",
|
|
24
|
-
"test": "npm run build && node --test
|
|
24
|
+
"test": "npm run build && node --test dist/__tests__/*.test.js dist/preset-cli/__tests__/*.test.js dist/cross-env-preflight/__tests__/*.test.js",
|
|
25
25
|
"prepublishOnly": "npm run build",
|
|
26
26
|
"regen:skill": "node scripts/regen-module-formats.mjs"
|
|
27
27
|
},
|