@diviops/mcp-server 1.5.28 → 1.5.30

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.
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * Usage:
10
10
  * diviops-preset button [options] Emit a divi/button group preset
11
+ * diviops-preset nav [options] Emit a Divi nav drawer block skeleton
11
12
  * diviops-preset --help Show help
12
13
  *
13
14
  * Modes:
@@ -27,6 +28,7 @@ import { type ButtonEmitterInput } from "./button-emitter.js";
27
28
  import { type HeadingFontEmitterInput } from "./heading-font-emitter.js";
28
29
  import { type TextBodyFontEmitterInput } from "./text-body-font-emitter.js";
29
30
  import { type SpacingEmitterInput } from "./spacing-emitter.js";
31
+ import { type NavEmitterInput } from "./nav-emitter.js";
30
32
  export declare const EXIT: {
31
33
  readonly OK: 0;
32
34
  readonly INVALID_INPUT: 1;
@@ -60,6 +62,8 @@ export declare function buildHeadingFontInput(parsed: ParsedArgs): HeadingFontEm
60
62
  export declare function buildTextBodyFontInput(parsed: ParsedArgs): TextBodyFontEmitterInput;
61
63
  /** Map parsed `spacing` options into the spacing emitter input shape. */
62
64
  export declare function buildSpacingInput(parsed: ParsedArgs): SpacingEmitterInput;
65
+ /** Map parsed `nav` options into the nav block-markup emitter input shape. */
66
+ export declare function buildNavInput(parsed: ParsedArgs): NavEmitterInput;
63
67
  /**
64
68
  * Run the CLI. Returns the structured exit code (does NOT call
65
69
  * `process.exit` — the thin bin wrapper does). `io` is injectable so
@@ -8,6 +8,7 @@
8
8
  *
9
9
  * Usage:
10
10
  * diviops-preset button [options] Emit a divi/button group preset
11
+ * diviops-preset nav [options] Emit a Divi nav drawer block skeleton
11
12
  * diviops-preset --help Show help
12
13
  *
13
14
  * Modes:
@@ -23,10 +24,12 @@
23
24
  * 3 capability-missing (plugin lacks storage_multipath_probe_v1)
24
25
  * 4 write / network error
25
26
  */
27
+ import { readFileSync } from "fs";
26
28
  import { emitButtonGroupPreset, buildPresetCreateBody, } from "./button-emitter.js";
27
29
  import { emitHeadingFontGroupPreset, buildHeadingFontPresetCreateBody, UnsupportedVariantCombinationError, } from "./heading-font-emitter.js";
28
30
  import { emitTextBodyFontGroupPreset, buildTextBodyFontPresetCreateBody, } from "./text-body-font-emitter.js";
29
31
  import { emitSpacingGroupPreset, buildSpacingPresetCreateBody, } from "./spacing-emitter.js";
32
+ import { emitNavBlockMarkup, buildNavMarkupBody, parseNavSpecJson, } from "./nav-emitter.js";
30
33
  import { EvidenceGateError } from "./registry.js";
31
34
  import { applyButtonPreset, applyHeadingFontPreset, applyTextBodyFontPreset, applySpacingPreset, buildClientFromEnv, CredentialsMissingError, CapabilityMissingError, } from "./write-path.js";
32
35
  export const EXIT = {
@@ -50,6 +53,8 @@ USAGE
50
53
  for divi/text (Pattern A only)
51
54
  diviops-preset spacing [options] Emit a divi/spacing group preset
52
55
  (currently divi/section only)
56
+ diviops-preset nav [options] Emit a small Divi nav drawer
57
+ block-markup skeleton
53
58
  diviops-preset --help Show this help
54
59
 
55
60
  MODE
@@ -159,6 +164,18 @@ spacing OPTIONS (sparse-emit per axis; paired sync flags per axis)
159
164
  --margin-sync-horizontal <on|off>
160
165
  Same paired-siblings rule as padding.
161
166
 
167
+ nav OPTIONS (dry-run block markup only; --apply is refused)
168
+ --name <string> Output/display name (required).
169
+ --spec <json> Compact nav spec JSON. Mutually exclusive with
170
+ --spec-file.
171
+ --spec-file <path> Read compact nav spec JSON from disk.
172
+
173
+ Spec shape:
174
+ {"label":"Menu","idPrefix":"main-nav","items":[
175
+ {"label":"Home","url":"/"},
176
+ {"label":"Products","links":[{"label":"Overview","url":"/products"}]}
177
+ ]}
178
+
162
179
  EXIT CODES
163
180
  0 success 1 invalid input 2 evidence-gate refusal
164
181
  3 capability missing 4 write error
@@ -217,6 +234,8 @@ const VALUE_FLAGS = new Set([
217
234
  "--padding-sync-horizontal",
218
235
  "--margin-sync-vertical",
219
236
  "--margin-sync-horizontal",
237
+ "--spec",
238
+ "--spec-file",
220
239
  ]);
221
240
  /** Parse argv (after `node script`) into a structured shape. Throws on unknown flags. */
222
241
  export function parseArgs(argv) {
@@ -286,6 +305,7 @@ const KNOWN_COMMANDS = new Set([
286
305
  "heading-font",
287
306
  "text-body-font",
288
307
  "spacing",
308
+ "nav",
289
309
  ]);
290
310
  /** Map parsed `button` options into the emitter input shape. */
291
311
  export function buildButtonInput(parsed) {
@@ -512,6 +532,30 @@ export function buildSpacingInput(parsed) {
512
532
  input.margin = margin;
513
533
  return input;
514
534
  }
535
+ /** Map parsed `nav` options into the nav block-markup emitter input shape. */
536
+ export function buildNavInput(parsed) {
537
+ const opt = (k) => {
538
+ const v = parsed.options.get(k);
539
+ return typeof v === "string" ? v : undefined;
540
+ };
541
+ const name = opt("--name");
542
+ if (!name) {
543
+ throw new UsageError("nav command requires --name <string>.");
544
+ }
545
+ const inlineSpec = opt("--spec");
546
+ const specFile = opt("--spec-file");
547
+ if (inlineSpec && specFile) {
548
+ throw new UsageError("nav command accepts either --spec or --spec-file, not both.");
549
+ }
550
+ if (!inlineSpec && !specFile) {
551
+ throw new UsageError("nav command requires --spec <json> or --spec-file <path>.");
552
+ }
553
+ const specJson = inlineSpec ?? readFileSync(specFile, "utf-8");
554
+ return {
555
+ name,
556
+ spec: parseNavSpecJson(specJson),
557
+ };
558
+ }
515
559
  /**
516
560
  * Run the CLI. Returns the structured exit code (does NOT call
517
561
  * `process.exit` — the thin bin wrapper does). `io` is injectable so
@@ -575,6 +619,17 @@ export async function run(argv, io = realIO, serverVersion) {
575
619
  dryRunBody = buildSpacingPresetCreateBody(entry, { dry_run: true });
576
620
  applyFn = (client, sv) => applySpacingPreset(client, entry, { serverVersion: sv });
577
621
  }
622
+ else if (parsed.command === "nav") {
623
+ if (parsed.apply) {
624
+ throw new UsageError("nav command is dry-run block-markup only in this MVP; --apply is not supported.");
625
+ }
626
+ const input = buildNavInput(parsed);
627
+ const entry = emitNavBlockMarkup(input);
628
+ dryRunBody = buildNavMarkupBody(entry, { dry_run: true });
629
+ applyFn = async () => {
630
+ throw new Error("nav command has no apply mode.");
631
+ };
632
+ }
578
633
  else {
579
634
  // Defensive: a new entry in KNOWN_COMMANDS without a dispatch
580
635
  // branch here would silently break dry-run/apply. parseArgs
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `diviops-preset nav` block-markup emitter.
3
+ *
4
+ * Emits a small, Free-safe Divi 5 navigation drawer skeleton from a compact
5
+ * JSON spec. This MVP is dry-run only: it writes no WordPress content and
6
+ * does not add MCP/plugin routes. The output is serialized Divi block markup
7
+ * with the high-signal nav reliability contracts encoded up front:
8
+ *
9
+ * - one leaf `divi/text` button trigger with `aria-controls`;
10
+ * - one `divi/dropdown` panel with the matching custom `id`;
11
+ * - `forceVisible:"whileInBuilder"` for Visual Builder editability;
12
+ * - semantic submenu list shape: dropdown as `ul`, links wrapped with
13
+ * `htmlBefore:"<li>"` / `htmlAfter:"</li>"`;
14
+ * - non-empty boolean-style custom attrs;
15
+ * - wrapper-level tap-highlight suppression and a floating-width CSS guard.
16
+ */
17
+ export interface NavLinkSpec {
18
+ label: string;
19
+ url: string;
20
+ target?: "off" | "on" | "_self" | "_blank";
21
+ }
22
+ interface ParsedNavLinkSpec {
23
+ label: string;
24
+ url: string;
25
+ target: "off" | "on";
26
+ }
27
+ interface ParsedNavSectionSpec {
28
+ label: string;
29
+ links: ParsedNavLinkSpec[];
30
+ }
31
+ interface ParsedNavSpec {
32
+ label?: string;
33
+ idPrefix?: string;
34
+ items: Array<ParsedNavLinkSpec | ParsedNavSectionSpec>;
35
+ }
36
+ export interface NavItemSpec {
37
+ label: string;
38
+ url?: string;
39
+ target?: NavLinkSpec["target"];
40
+ links?: NavLinkSpec[];
41
+ }
42
+ export interface NavSpec {
43
+ label?: string;
44
+ idPrefix?: string;
45
+ items: NavItemSpec[];
46
+ }
47
+ export interface NavEmitterInput {
48
+ name: string;
49
+ spec: NavSpec;
50
+ }
51
+ export interface NavMarkupEntry {
52
+ type: "block_markup";
53
+ format: "divi_block_markup";
54
+ name: string;
55
+ markup: string;
56
+ notes: string[];
57
+ }
58
+ export declare function parseNavSpec(raw: unknown): ParsedNavSpec;
59
+ export declare function parseNavSpecJson(json: string): ParsedNavSpec;
60
+ export declare function emitNavBlockMarkup(input: NavEmitterInput): NavMarkupEntry;
61
+ export declare function buildNavMarkupBody(entry: NavMarkupEntry, opts?: {
62
+ dry_run?: boolean;
63
+ }): Record<string, unknown>;
64
+ export {};
@@ -0,0 +1,328 @@
1
+ /**
2
+ * `diviops-preset nav` block-markup emitter.
3
+ *
4
+ * Emits a small, Free-safe Divi 5 navigation drawer skeleton from a compact
5
+ * JSON spec. This MVP is dry-run only: it writes no WordPress content and
6
+ * does not add MCP/plugin routes. The output is serialized Divi block markup
7
+ * with the high-signal nav reliability contracts encoded up front:
8
+ *
9
+ * - one leaf `divi/text` button trigger with `aria-controls`;
10
+ * - one `divi/dropdown` panel with the matching custom `id`;
11
+ * - `forceVisible:"whileInBuilder"` for Visual Builder editability;
12
+ * - semantic submenu list shape: dropdown as `ul`, links wrapped with
13
+ * `htmlBefore:"<li>"` / `htmlAfter:"</li>"`;
14
+ * - non-empty boolean-style custom attrs;
15
+ * - wrapper-level tap-highlight suppression and a floating-width CSS guard.
16
+ */
17
+ const BUILDER_VERSION = "5.7.4";
18
+ function isPlainObject(value) {
19
+ return !!value && typeof value === "object" && !Array.isArray(value);
20
+ }
21
+ function assertNonEmptyString(value, field) {
22
+ if (typeof value !== "string" || value.trim() === "") {
23
+ throw new Error(`nav spec requires non-empty ${field}.`);
24
+ }
25
+ return value.trim();
26
+ }
27
+ function normalizeTarget(target) {
28
+ if (target === undefined || target === "off" || target === "_self") {
29
+ return "off";
30
+ }
31
+ if (target === "on" || target === "_blank") {
32
+ return "on";
33
+ }
34
+ throw new Error(`nav spec link target must be "off", "on", "_self", or "_blank"; got ${JSON.stringify(target)}.`);
35
+ }
36
+ function slugifyId(value) {
37
+ const slug = value
38
+ .trim()
39
+ .toLowerCase()
40
+ .replace(/[^a-z0-9_-]+/g, "-")
41
+ .replace(/^-+|-+$/g, "");
42
+ return slug || "nav";
43
+ }
44
+ function textContent(html) {
45
+ return {
46
+ content: {
47
+ innerContent: {
48
+ desktop: {
49
+ value: html,
50
+ },
51
+ },
52
+ },
53
+ };
54
+ }
55
+ function htmlAttrs(value) {
56
+ return {
57
+ module: {
58
+ advanced: {
59
+ html: {
60
+ desktop: {
61
+ value,
62
+ },
63
+ },
64
+ },
65
+ },
66
+ };
67
+ }
68
+ function mergeObjects(...objects) {
69
+ const merged = {};
70
+ for (const object of objects) {
71
+ for (const [key, value] of Object.entries(object)) {
72
+ if (isPlainObject(value) && isPlainObject(merged[key])) {
73
+ merged[key] = mergeObjects(merged[key], value);
74
+ }
75
+ else {
76
+ merged[key] = value;
77
+ }
78
+ }
79
+ }
80
+ return merged;
81
+ }
82
+ function customAttributes(attributes) {
83
+ return {
84
+ module: {
85
+ decoration: {
86
+ attributes: {
87
+ desktop: {
88
+ value: {
89
+ attributes: attributes.map((attr) => ({
90
+ targetElement: "main",
91
+ ...attr,
92
+ })),
93
+ },
94
+ },
95
+ },
96
+ },
97
+ },
98
+ };
99
+ }
100
+ function withBuilderVersion(attrs) {
101
+ return { ...attrs, builderVersion: BUILDER_VERSION };
102
+ }
103
+ function escapeBlockJson(json) {
104
+ return json
105
+ .replace(/\\\\/g, "\\u005c")
106
+ .replace(/\\"/g, "\\u0022")
107
+ .replace(/&/g, "\\u0026")
108
+ .replace(/</g, "\\u003c")
109
+ .replace(/>/g, "\\u003e")
110
+ .replace(/--/g, "\\u002d\\u002d");
111
+ }
112
+ function serializeAttrs(attrs) {
113
+ return escapeBlockJson(JSON.stringify(withBuilderVersion(attrs)));
114
+ }
115
+ function serializeBlock(name, attrs, innerBlocks = []) {
116
+ const blockName = `divi/${name}`;
117
+ const serializedAttrs = serializeAttrs(attrs);
118
+ if (innerBlocks.length === 0) {
119
+ return `<!-- wp:${blockName} ${serializedAttrs} /-->`;
120
+ }
121
+ return [
122
+ `<!-- wp:${blockName} ${serializedAttrs} -->`,
123
+ ...innerBlocks,
124
+ `<!-- /wp:${blockName} -->`,
125
+ ].join("\n");
126
+ }
127
+ function rootNavBlock(label, panelId, children) {
128
+ const css = "selector{-webkit-tap-highlight-color:transparent;}" +
129
+ "selector a:focus-visible,selector button:focus-visible{outline:2px solid currentColor;outline-offset:3px;}" +
130
+ "selector .et_pb_dropdown,selector .et_pb_dropdown_content{width:min(100vw,24rem);max-width:calc(100vw - 2rem);}";
131
+ return serializeBlock("group", mergeObjects(htmlAttrs({ elementType: "nav" }), customAttributes([
132
+ { name: "aria-label", value: label },
133
+ { name: "data-diviops-nav", value: "true" },
134
+ ]), {
135
+ module: {
136
+ decoration: {
137
+ layout: {
138
+ desktop: {
139
+ value: {
140
+ display: "flex",
141
+ flexDirection: "column",
142
+ gap: "0px",
143
+ },
144
+ },
145
+ },
146
+ },
147
+ },
148
+ css: {
149
+ desktop: {
150
+ value: {
151
+ freeForm: css,
152
+ },
153
+ },
154
+ },
155
+ }), [
156
+ serializeBlock("text", mergeObjects(htmlAttrs({ elementType: "button" }), customAttributes([
157
+ { name: "aria-controls", value: panelId },
158
+ { name: "aria-expanded", value: "false" },
159
+ { name: "data-diviops-nav-trigger", value: "true" },
160
+ ]), textContent(`<span>${escapeHtml(label)}</span>`))),
161
+ ...children,
162
+ ]);
163
+ }
164
+ function dropdownBlock(panelId, children) {
165
+ return serializeBlock("dropdown", mergeObjects(htmlAttrs({ elementType: "ul" }), customAttributes([
166
+ { name: "id", value: panelId },
167
+ { name: "role", value: "menu" },
168
+ { name: "aria-hidden", value: "true" },
169
+ ]), {
170
+ module: {
171
+ meta: {
172
+ meta: {
173
+ forceVisible: {
174
+ desktop: {
175
+ value: "whileInBuilder",
176
+ },
177
+ },
178
+ },
179
+ },
180
+ advanced: {
181
+ dropdown: {
182
+ desktop: {
183
+ value: {
184
+ showOn: "click",
185
+ position: "floating",
186
+ direction: "below",
187
+ alignment: "start",
188
+ },
189
+ },
190
+ },
191
+ },
192
+ decoration: {
193
+ layout: {
194
+ desktop: {
195
+ value: {
196
+ display: "flex",
197
+ flexDirection: "column",
198
+ gap: "0px",
199
+ },
200
+ },
201
+ },
202
+ },
203
+ },
204
+ }), children);
205
+ }
206
+ function linkBlock(link) {
207
+ return serializeBlock("link", mergeObjects(htmlAttrs({
208
+ htmlBefore: '<li role="none">',
209
+ htmlAfter: "</li>",
210
+ }), customAttributes([{ name: "role", value: "menuitem" }]), {
211
+ link: {
212
+ innerContent: {
213
+ desktop: {
214
+ value: {
215
+ text: link.label,
216
+ url: link.url,
217
+ target: link.target,
218
+ },
219
+ },
220
+ },
221
+ },
222
+ }));
223
+ }
224
+ function sectionLabelBlock(label) {
225
+ return serializeBlock("text", mergeObjects(htmlAttrs({ elementType: "li" }), customAttributes([{ name: "data-diviops-nav-section", value: "true" }]), textContent(`<span>${escapeHtml(label)}</span>`)));
226
+ }
227
+ function escapeHtml(value) {
228
+ return value
229
+ .replace(/&/g, "&amp;")
230
+ .replace(/</g, "&lt;")
231
+ .replace(/>/g, "&gt;")
232
+ .replace(/"/g, "&quot;");
233
+ }
234
+ function parseLinkSpec(raw, field) {
235
+ if (!isPlainObject(raw)) {
236
+ throw new Error(`nav spec ${field} must be an object.`);
237
+ }
238
+ const label = assertNonEmptyString(raw.label, `${field}.label`);
239
+ const url = assertNonEmptyString(raw.url, `${field}.url`);
240
+ const target = normalizeTarget(raw.target);
241
+ return { label, url, target };
242
+ }
243
+ export function parseNavSpec(raw) {
244
+ if (!isPlainObject(raw)) {
245
+ throw new Error("nav spec must be a JSON object.");
246
+ }
247
+ const itemsRaw = raw.items;
248
+ if (!Array.isArray(itemsRaw) || itemsRaw.length === 0) {
249
+ throw new Error("nav spec requires a non-empty items array.");
250
+ }
251
+ const spec = {
252
+ items: itemsRaw.map((itemRaw, itemIndex) => {
253
+ if (!isPlainObject(itemRaw)) {
254
+ throw new Error(`nav spec items[${itemIndex}] must be an object.`);
255
+ }
256
+ const label = assertNonEmptyString(itemRaw.label, `items[${itemIndex}].label`);
257
+ if (Array.isArray(itemRaw.links)) {
258
+ if (itemRaw.links.length === 0) {
259
+ throw new Error(`nav spec items[${itemIndex}].links must not be empty.`);
260
+ }
261
+ return {
262
+ label,
263
+ links: itemRaw.links.map((link, linkIndex) => parseLinkSpec(link, `items[${itemIndex}].links[${linkIndex}]`)),
264
+ };
265
+ }
266
+ return parseLinkSpec(itemRaw, `items[${itemIndex}]`);
267
+ }),
268
+ };
269
+ if (raw.label !== undefined) {
270
+ spec.label = assertNonEmptyString(raw.label, "label");
271
+ }
272
+ if (raw.idPrefix !== undefined) {
273
+ spec.idPrefix = assertNonEmptyString(raw.idPrefix, "idPrefix");
274
+ }
275
+ return spec;
276
+ }
277
+ export function parseNavSpecJson(json) {
278
+ let parsed;
279
+ try {
280
+ parsed = JSON.parse(json);
281
+ }
282
+ catch (err) {
283
+ throw new Error(`nav spec must be valid JSON: ${err instanceof Error ? err.message : String(err)}`);
284
+ }
285
+ return parseNavSpec(parsed);
286
+ }
287
+ export function emitNavBlockMarkup(input) {
288
+ const name = assertNonEmptyString(input.name, "name");
289
+ const spec = parseNavSpec(input.spec);
290
+ const label = spec.label ?? name;
291
+ const idPrefix = slugifyId(spec.idPrefix ?? name);
292
+ const panelId = `${idPrefix}-panel`;
293
+ const listChildren = [];
294
+ for (const item of spec.items) {
295
+ if ("links" in item) {
296
+ listChildren.push(sectionLabelBlock(item.label));
297
+ for (const link of item.links) {
298
+ listChildren.push(linkBlock(link));
299
+ }
300
+ }
301
+ else {
302
+ listChildren.push(linkBlock(item));
303
+ }
304
+ }
305
+ const markup = rootNavBlock(label, panelId, [dropdownBlock(panelId, listChildren)]);
306
+ return {
307
+ type: "block_markup",
308
+ format: "divi_block_markup",
309
+ name,
310
+ markup,
311
+ notes: [
312
+ "Dry-run only: no WordPress write path is invoked.",
313
+ "Use targeted create/clone/tree-surgery flows for placement; do not route this through whole-layout update paths.",
314
+ ],
315
+ };
316
+ }
317
+ export function buildNavMarkupBody(entry, opts = {}) {
318
+ const body = {
319
+ type: entry.type,
320
+ format: entry.format,
321
+ name: entry.name,
322
+ markup: entry.markup,
323
+ notes: entry.notes,
324
+ };
325
+ if (opts.dry_run)
326
+ body.dry_run = true;
327
+ return body;
328
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@diviops/mcp-server",
3
- "version": "1.5.28",
3
+ "version": "1.5.30",
4
4
  "description": "MCP server exposing Divi 5 Visual Builder as tools for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
8
  "diviops-mcp": "dist/index.js",
9
- "diviops-preset": "dist/preset-cli/bin.js"
9
+ "diviops-preset": "dist/preset-cli/bin.js",
10
+ "diviops-cross-env-preflight": "dist/cross-env-preflight/bin.js"
10
11
  },
11
12
  "files": [
12
13
  "dist/**/*",
@@ -20,7 +21,7 @@
20
21
  "build": "tsc",
21
22
  "start": "node dist/index.js",
22
23
  "dev": "tsc --watch",
23
- "test": "npm run build && node --test \"dist/preset-cli/__tests__/*.test.js\"",
24
+ "test": "npm run build && node --test \"dist/preset-cli/__tests__/*.test.js\" \"dist/cross-env-preflight/__tests__/*.test.js\"",
24
25
  "prepublishOnly": "npm run build",
25
26
  "regen:skill": "node scripts/regen-module-formats.mjs"
26
27
  },