@diviops/mcp-server 1.5.34 → 1.5.36
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 +33 -12
- package/dist/capability-envelope.d.ts +12 -0
- package/dist/capability-envelope.js +29 -0
- package/dist/cross-env-preflight/cli.js +28 -9
- package/dist/cross-env-preflight/header-preflight.d.ts +4 -0
- package/dist/cross-env-preflight/layout-capability.d.ts +3 -0
- package/dist/cross-env-preflight/layout-capability.js +6 -0
- package/dist/cross-env-preflight/layout-preflight.d.ts +89 -0
- package/dist/cross-env-preflight/layout-preflight.js +202 -0
- package/dist/cross-env-preflight/source-payload-ref.d.ts +1 -1
- package/dist/cross-env-preflight/source-payload-ref.js +4 -1
- package/dist/index.js +439 -165
- 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/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.36",
|
|
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
|
},
|