@diviops/mcp-server 1.5.34 → 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 +2 -1
- package/dist/capability-envelope.d.ts +12 -0
- package/dist/capability-envelope.js +29 -0
- package/dist/index.js +86 -61
- 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` |
|
|
@@ -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";
|
|
@@ -288,10 +289,7 @@ function backupCapabilityError(toolName, backup) {
|
|
|
288
289
|
}
|
|
289
290
|
catch (e) {
|
|
290
291
|
if (e instanceof MissingCapabilityError) {
|
|
291
|
-
return
|
|
292
|
-
content: [{ type: "text", text: e.message }],
|
|
293
|
-
isError: true,
|
|
294
|
-
};
|
|
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.");
|
|
295
293
|
}
|
|
296
294
|
throw e;
|
|
297
295
|
}
|
|
@@ -320,10 +318,7 @@ function registerPluginTool(name, config, handler) {
|
|
|
320
318
|
}
|
|
321
319
|
catch (e) {
|
|
322
320
|
if (e instanceof MissingCapabilityError) {
|
|
323
|
-
return
|
|
324
|
-
content: [{ type: "text", text: e.message }],
|
|
325
|
-
isError: true,
|
|
326
|
-
};
|
|
321
|
+
return missingCapabilityEnvelope(e, name);
|
|
327
322
|
}
|
|
328
323
|
throw e;
|
|
329
324
|
}
|
|
@@ -727,17 +722,7 @@ registerPluginTool("diviops_schema_get_module", {
|
|
|
727
722
|
if (handshakeState.kind === "ok" &&
|
|
728
723
|
!handshakeState.capabilities["schema_get_module_dump_all"]) {
|
|
729
724
|
const err = new MissingCapabilityError("schema_get_module_dump_all", handshakeState.pluginVersion);
|
|
730
|
-
|
|
731
|
-
ok: false,
|
|
732
|
-
error: {
|
|
733
|
-
code: ErrorCodes.CAPABILITY_MISSING,
|
|
734
|
-
message: err.message,
|
|
735
|
-
hint: "Update the diviops-agent WP plugin to a version that exposes the dump-all surface.",
|
|
736
|
-
},
|
|
737
|
-
};
|
|
738
|
-
return {
|
|
739
|
-
content: [{ type: "text", text: serializeEnvelope(failure, "diviops_schema_get_module") }],
|
|
740
|
-
};
|
|
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'.");
|
|
741
726
|
}
|
|
742
727
|
const result = await wp.requestEnveloped("/schema/module/dump-all");
|
|
743
728
|
return {
|
|
@@ -1136,9 +1121,9 @@ registerPluginTool("diviops_page_update_content", {
|
|
|
1136
1121
|
const backupGate = backupCapabilityError("diviops_page_update_content", backup);
|
|
1137
1122
|
if (backupGate)
|
|
1138
1123
|
return backupGate;
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1141
|
-
return
|
|
1124
|
+
const isolationGate = writerIsolationErrorResult("diviops_page_update_content", { content });
|
|
1125
|
+
if (isolationGate)
|
|
1126
|
+
return isolationGate;
|
|
1142
1127
|
const body = { content };
|
|
1143
1128
|
if (dry_run)
|
|
1144
1129
|
body.dry_run = true;
|
|
@@ -1234,10 +1219,7 @@ registerPluginTool("diviops_render_preview", {
|
|
|
1234
1219
|
}
|
|
1235
1220
|
catch (e) {
|
|
1236
1221
|
if (e instanceof MissingCapabilityError) {
|
|
1237
|
-
return
|
|
1238
|
-
content: [{ type: "text", text: e.message }],
|
|
1239
|
-
isError: true,
|
|
1240
|
-
};
|
|
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.");
|
|
1241
1223
|
}
|
|
1242
1224
|
throw e;
|
|
1243
1225
|
}
|
|
@@ -1274,10 +1256,7 @@ registerPluginTool("diviops_validate_blocks", {
|
|
|
1274
1256
|
}
|
|
1275
1257
|
catch (e) {
|
|
1276
1258
|
if (e instanceof MissingCapabilityError) {
|
|
1277
|
-
return
|
|
1278
|
-
content: [{ type: "text", text: e.message }],
|
|
1279
|
-
isError: true,
|
|
1280
|
-
};
|
|
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.");
|
|
1281
1260
|
}
|
|
1282
1261
|
throw e;
|
|
1283
1262
|
}
|
|
@@ -1314,9 +1293,11 @@ registerPluginTool("diviops_section_append", {
|
|
|
1314
1293
|
const backupGate = backupCapabilityError("diviops_section_append", backup);
|
|
1315
1294
|
if (backupGate)
|
|
1316
1295
|
return backupGate;
|
|
1317
|
-
const
|
|
1318
|
-
|
|
1319
|
-
|
|
1296
|
+
const isolationGate = writerIsolationErrorResult("diviops_section_append", {
|
|
1297
|
+
content,
|
|
1298
|
+
});
|
|
1299
|
+
if (isolationGate)
|
|
1300
|
+
return isolationGate;
|
|
1320
1301
|
const body = { content, position: position ?? "end" };
|
|
1321
1302
|
if (dry_run)
|
|
1322
1303
|
body.dry_run = true;
|
|
@@ -1364,9 +1345,11 @@ registerPluginTool("diviops_section_replace", {
|
|
|
1364
1345
|
const backupGate = backupCapabilityError("diviops_section_replace", backup);
|
|
1365
1346
|
if (backupGate)
|
|
1366
1347
|
return backupGate;
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1348
|
+
const isolationGate = writerIsolationErrorResult("diviops_section_replace", {
|
|
1349
|
+
content,
|
|
1350
|
+
});
|
|
1351
|
+
if (isolationGate)
|
|
1352
|
+
return isolationGate;
|
|
1370
1353
|
const body = { content, occurrence };
|
|
1371
1354
|
if (label)
|
|
1372
1355
|
body.label = label;
|
|
@@ -1506,9 +1489,11 @@ registerPluginTool("diviops_module_update", {
|
|
|
1506
1489
|
const backupGate = backupCapabilityError("diviops_module_update", backup);
|
|
1507
1490
|
if (backupGate)
|
|
1508
1491
|
return backupGate;
|
|
1509
|
-
const
|
|
1510
|
-
|
|
1511
|
-
|
|
1492
|
+
const isolationGate = writerIsolationErrorResult("diviops_module_update", {
|
|
1493
|
+
attrs,
|
|
1494
|
+
});
|
|
1495
|
+
if (isolationGate)
|
|
1496
|
+
return isolationGate;
|
|
1512
1497
|
const body = { attrs };
|
|
1513
1498
|
if (auto_index)
|
|
1514
1499
|
body.auto_index = auto_index;
|
|
@@ -1743,11 +1728,11 @@ registerPluginTool("diviops_page_create", {
|
|
|
1743
1728
|
annotations: { idempotentHint: false },
|
|
1744
1729
|
_meta: { idempotent: "false" },
|
|
1745
1730
|
}, async ({ title, content, status, dry_run }) => {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1731
|
+
const isolationGate = writerIsolationErrorResult("diviops_page_create", {
|
|
1732
|
+
content: content ?? "",
|
|
1733
|
+
});
|
|
1734
|
+
if (isolationGate)
|
|
1735
|
+
return isolationGate;
|
|
1751
1736
|
const body = { title, content: content ?? "", status: status ?? "draft" };
|
|
1752
1737
|
if (dry_run)
|
|
1753
1738
|
body.dry_run = true;
|
|
@@ -1868,6 +1853,23 @@ registerPluginTool("diviops_preset_inspect", {
|
|
|
1868
1853
|
],
|
|
1869
1854
|
};
|
|
1870
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
|
+
});
|
|
1871
1873
|
registerPluginTool("diviops_rollback_snapshot_list", {
|
|
1872
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? } }.",
|
|
1873
1875
|
inputSchema: {
|
|
@@ -2011,6 +2013,11 @@ registerPluginTool("diviops_preset_update", {
|
|
|
2011
2013
|
annotations: { idempotentHint: false },
|
|
2012
2014
|
_meta: { idempotent: "conditional" },
|
|
2013
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;
|
|
2014
2021
|
const body = { preset_id };
|
|
2015
2022
|
if (name)
|
|
2016
2023
|
body.name = name;
|
|
@@ -2101,6 +2108,11 @@ registerPluginTool("diviops_preset_create", {
|
|
|
2101
2108
|
if (type === "group" && (!group_name || !group_id)) {
|
|
2102
2109
|
throw new Error('type="group" requires both group_name and group_id. Example: group_name="divi/font", group_id="designTitleText".');
|
|
2103
2110
|
}
|
|
2111
|
+
const isolationGate = writerIsolationErrorResult("diviops_preset_create", {
|
|
2112
|
+
attrs,
|
|
2113
|
+
});
|
|
2114
|
+
if (isolationGate)
|
|
2115
|
+
return isolationGate;
|
|
2104
2116
|
const body = { module_name, name, attrs, type };
|
|
2105
2117
|
if (group_name)
|
|
2106
2118
|
body.group_name = group_name;
|
|
@@ -2303,6 +2315,11 @@ registerPluginTool("diviops_library_save", {
|
|
|
2303
2315
|
annotations: { idempotentHint: false },
|
|
2304
2316
|
_meta: { idempotent: "conditional" },
|
|
2305
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;
|
|
2306
2323
|
const body = { title, content, layout_type, scope };
|
|
2307
2324
|
if (dry_run)
|
|
2308
2325
|
body.dry_run = true;
|
|
@@ -2480,6 +2497,9 @@ registerPluginTool("diviops_tb_layout_update", {
|
|
|
2480
2497
|
const backupGate = backupCapabilityError("diviops_tb_layout_update", backup);
|
|
2481
2498
|
if (backupGate)
|
|
2482
2499
|
return backupGate;
|
|
2500
|
+
const isolationGate = writerIsolationErrorResult("diviops_tb_layout_update", { content });
|
|
2501
|
+
if (isolationGate)
|
|
2502
|
+
return isolationGate;
|
|
2483
2503
|
const body = { content };
|
|
2484
2504
|
if (dry_run)
|
|
2485
2505
|
body.dry_run = true;
|
|
@@ -2523,6 +2543,9 @@ registerPluginTool("diviops_tb_layout_block_insert", {
|
|
|
2523
2543
|
const backupGate = backupCapabilityError("diviops_tb_layout_block_insert", backup);
|
|
2524
2544
|
if (backupGate)
|
|
2525
2545
|
return backupGate;
|
|
2546
|
+
const isolationGate = writerIsolationErrorResult("diviops_tb_layout_block_insert", { content });
|
|
2547
|
+
if (isolationGate)
|
|
2548
|
+
return isolationGate;
|
|
2526
2549
|
const body = {
|
|
2527
2550
|
content,
|
|
2528
2551
|
position: position ?? "append",
|
|
@@ -2568,6 +2591,9 @@ registerPluginTool("diviops_tb_template_create", {
|
|
|
2568
2591
|
annotations: { idempotentHint: false },
|
|
2569
2592
|
_meta: { idempotent: "false" },
|
|
2570
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;
|
|
2571
2597
|
const body = { title, condition, header_content, footer_content };
|
|
2572
2598
|
if (dry_run)
|
|
2573
2599
|
body.dry_run = true;
|
|
@@ -2643,6 +2669,11 @@ registerPluginTool("diviops_canvas_create", {
|
|
|
2643
2669
|
annotations: { idempotentHint: false },
|
|
2644
2670
|
_meta: { idempotent: "conditional" },
|
|
2645
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;
|
|
2646
2677
|
const body = {
|
|
2647
2678
|
title,
|
|
2648
2679
|
parent_page_id,
|
|
@@ -2785,6 +2816,11 @@ registerPluginTool("diviops_canvas_update", {
|
|
|
2785
2816
|
annotations: { idempotentHint: false },
|
|
2786
2817
|
_meta: { idempotent: "conditional" },
|
|
2787
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;
|
|
2788
2824
|
const body = {};
|
|
2789
2825
|
if (content !== undefined)
|
|
2790
2826
|
body.content = content;
|
|
@@ -4022,6 +4058,10 @@ function registerProTools() {
|
|
|
4022
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 });
|
|
4023
4059
|
}
|
|
4024
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
|
+
}
|
|
4025
4065
|
const targetBody = {
|
|
4026
4066
|
destination_id,
|
|
4027
4067
|
destination_kind: destination_kind ?? "tb_header_layout",
|
|
@@ -4561,22 +4601,7 @@ function registerProTools() {
|
|
|
4561
4601
|
handshakeState.kind === "ok" &&
|
|
4562
4602
|
!handshakeState.capabilities["fluentcart_license_update_file_set"]) {
|
|
4563
4603
|
const err = new MissingCapabilityError("fluentcart_license_update_file_set", handshakeState.pluginVersion);
|
|
4564
|
-
|
|
4565
|
-
ok: false,
|
|
4566
|
-
error: {
|
|
4567
|
-
code: ErrorCodes.CAPABILITY_MISSING,
|
|
4568
|
-
message: err.message,
|
|
4569
|
-
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.",
|
|
4570
|
-
},
|
|
4571
|
-
};
|
|
4572
|
-
return {
|
|
4573
|
-
content: [
|
|
4574
|
-
{
|
|
4575
|
-
type: "text",
|
|
4576
|
-
text: serializeEnvelope(failure, "diviops_fc_license_settings_update"),
|
|
4577
|
-
},
|
|
4578
|
-
],
|
|
4579
|
-
};
|
|
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.");
|
|
4580
4605
|
}
|
|
4581
4606
|
const body = {};
|
|
4582
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
|
},
|