@diviops/mcp-server 1.5.30 → 1.5.32

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.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * `diviops-preset nav` block-markup emitter.
3
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:
4
+ * Emits small, Free-safe Divi 5 navigation skeletons from a compact JSON spec.
5
+ * This MVP is dry-run only: it writes no WordPress content and does not add
6
+ * MCP/plugin routes. The output is serialized Divi block markup with the
7
+ * high-signal nav reliability contracts encoded up front:
8
8
  *
9
9
  * - one leaf `divi/text` button trigger with `aria-controls`;
10
10
  * - one `divi/dropdown` panel with the matching custom `id`;
@@ -12,7 +12,8 @@
12
12
  * - semantic submenu list shape: dropdown as `ul`, links wrapped with
13
13
  * `htmlBefore:"<li>"` / `htmlAfter:"</li>"`;
14
14
  * - non-empty boolean-style custom attrs;
15
- * - wrapper-level tap-highlight suppression and a floating-width CSS guard.
15
+ * - wrapper-level tap-highlight suppression and a CSS-only floating-width
16
+ * guard, because Divi floating dropdowns can ignore VB sizing controls.
16
17
  */
17
18
  const BUILDER_VERSION = "5.7.4";
18
19
  function isPlainObject(value) {
@@ -124,14 +125,28 @@ function serializeBlock(name, attrs, innerBlocks = []) {
124
125
  `<!-- /wp:${blockName} -->`,
125
126
  ].join("\n");
126
127
  }
127
- function rootNavBlock(label, panelId, children) {
128
+ function disabledOnAttrs(values) {
129
+ return {
130
+ module: {
131
+ decoration: {
132
+ disabledOn: {
133
+ desktop: { value: values.desktop },
134
+ tablet: { value: values.tablet },
135
+ phone: { value: values.phone },
136
+ },
137
+ },
138
+ },
139
+ };
140
+ }
141
+ function rootNavBlock(label, panelId, children, opts = {}) {
128
142
  const css = "selector{-webkit-tap-highlight-color:transparent;}" +
129
143
  "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);}";
144
+ "selector .et_pb_dropdown,selector .et_pb_dropdown_content{width:clamp(16rem,calc(100vw - 2rem),32rem)!important;min-width:0!important;max-width:none!important;}";
131
145
  return serializeBlock("group", mergeObjects(htmlAttrs({ elementType: "nav" }), customAttributes([
132
146
  { name: "aria-label", value: label },
133
147
  { name: "data-diviops-nav", value: "true" },
134
- ]), {
148
+ ...(opts.customAttributes ?? []),
149
+ ]), opts.extraAttrs ?? {}, {
135
150
  module: {
136
151
  decoration: {
137
152
  layout: {
@@ -161,6 +176,31 @@ function rootNavBlock(label, panelId, children) {
161
176
  ...children,
162
177
  ]);
163
178
  }
179
+ function responsiveNavShellBlock(children) {
180
+ return serializeBlock("group", mergeObjects(htmlAttrs({ elementType: "div" }), customAttributes([{ name: "data-diviops-responsive-nav", value: "true" }]), {
181
+ module: {
182
+ decoration: {
183
+ layout: {
184
+ desktop: {
185
+ value: {
186
+ display: "flex",
187
+ flexDirection: "row",
188
+ alignItems: "center",
189
+ gap: "16px",
190
+ },
191
+ },
192
+ tablet: {
193
+ value: {
194
+ flexDirection: "column",
195
+ alignItems: "stretch",
196
+ gap: "0px",
197
+ },
198
+ },
199
+ },
200
+ },
201
+ },
202
+ }), children);
203
+ }
164
204
  function dropdownBlock(panelId, children) {
165
205
  return serializeBlock("dropdown", mergeObjects(htmlAttrs({ elementType: "ul" }), customAttributes([
166
206
  { name: "id", value: panelId },
@@ -240,38 +280,62 @@ function parseLinkSpec(raw, field) {
240
280
  const target = normalizeTarget(raw.target);
241
281
  return { label, url, target };
242
282
  }
283
+ function parseNavItems(itemsRaw, field) {
284
+ if (!Array.isArray(itemsRaw) || itemsRaw.length === 0) {
285
+ throw new Error(`nav spec requires a non-empty ${field} array.`);
286
+ }
287
+ return itemsRaw.map((itemRaw, itemIndex) => {
288
+ if (!isPlainObject(itemRaw)) {
289
+ throw new Error(`nav spec ${field}[${itemIndex}] must be an object.`);
290
+ }
291
+ const label = assertNonEmptyString(itemRaw.label, `${field}[${itemIndex}].label`);
292
+ if (Array.isArray(itemRaw.links)) {
293
+ if (itemRaw.links.length === 0) {
294
+ throw new Error(`nav spec ${field}[${itemIndex}].links must not be empty.`);
295
+ }
296
+ return {
297
+ label,
298
+ links: itemRaw.links.map((link, linkIndex) => parseLinkSpec(link, `${field}[${itemIndex}].links[${linkIndex}]`)),
299
+ };
300
+ }
301
+ return parseLinkSpec(itemRaw, `${field}[${itemIndex}]`);
302
+ });
303
+ }
243
304
  export function parseNavSpec(raw) {
244
305
  if (!isPlainObject(raw)) {
245
306
  throw new Error("nav spec must be a JSON object.");
246
307
  }
247
- const itemsRaw = raw.items;
248
- if (!Array.isArray(itemsRaw) || itemsRaw.length === 0) {
308
+ const items = raw.items !== undefined ? parseNavItems(raw.items, "items") : undefined;
309
+ const desktopItems = raw.desktopItems !== undefined
310
+ ? parseNavItems(raw.desktopItems, "desktopItems")
311
+ : undefined;
312
+ const mobileItems = raw.mobileItems !== undefined
313
+ ? parseNavItems(raw.mobileItems, "mobileItems")
314
+ : undefined;
315
+ if (!items && !desktopItems && !mobileItems) {
249
316
  throw new Error("nav spec requires a non-empty items array.");
250
317
  }
251
318
  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
- }),
319
+ items: items ?? desktopItems ?? mobileItems ?? [],
268
320
  };
269
321
  if (raw.label !== undefined) {
270
322
  spec.label = assertNonEmptyString(raw.label, "label");
271
323
  }
324
+ if (raw.desktopLabel !== undefined) {
325
+ spec.desktopLabel = assertNonEmptyString(raw.desktopLabel, "desktopLabel");
326
+ }
327
+ if (raw.mobileLabel !== undefined) {
328
+ spec.mobileLabel = assertNonEmptyString(raw.mobileLabel, "mobileLabel");
329
+ }
272
330
  if (raw.idPrefix !== undefined) {
273
331
  spec.idPrefix = assertNonEmptyString(raw.idPrefix, "idPrefix");
274
332
  }
333
+ if (desktopItems) {
334
+ spec.desktopItems = desktopItems;
335
+ }
336
+ if (mobileItems) {
337
+ spec.mobileItems = mobileItems;
338
+ }
275
339
  return spec;
276
340
  }
277
341
  export function parseNavSpecJson(json) {
@@ -287,22 +351,68 @@ export function parseNavSpecJson(json) {
287
351
  export function emitNavBlockMarkup(input) {
288
352
  const name = assertNonEmptyString(input.name, "name");
289
353
  const spec = parseNavSpec(input.spec);
354
+ const mode = input.mode ?? "drawer";
290
355
  const label = spec.label ?? name;
291
356
  const idPrefix = slugifyId(spec.idPrefix ?? name);
292
357
  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));
358
+ const buildListChildren = (items) => {
359
+ const listChildren = [];
360
+ for (const item of items) {
361
+ if ("links" in item) {
362
+ listChildren.push(sectionLabelBlock(item.label));
363
+ for (const link of item.links) {
364
+ listChildren.push(linkBlock(link));
365
+ }
366
+ }
367
+ else {
368
+ listChildren.push(linkBlock(item));
299
369
  }
300
370
  }
301
- else {
302
- listChildren.push(linkBlock(item));
303
- }
371
+ return listChildren;
372
+ };
373
+ if (mode === "responsive_split") {
374
+ const desktopPanelId = `${idPrefix}-desktop-panel`;
375
+ const mobilePanelId = `${idPrefix}-mobile-panel`;
376
+ const desktopLabel = spec.desktopLabel ?? `${label} desktop`;
377
+ const mobileLabel = spec.mobileLabel ?? `${label} mobile`;
378
+ const desktopItems = spec.desktopItems ?? spec.items;
379
+ const mobileItems = spec.mobileItems ?? spec.items;
380
+ const markup = responsiveNavShellBlock([
381
+ rootNavBlock(desktopLabel, desktopPanelId, [dropdownBlock(desktopPanelId, buildListChildren(desktopItems))], {
382
+ customAttributes: [{ name: "data-diviops-nav-unit", value: "desktop" }],
383
+ extraAttrs: disabledOnAttrs({
384
+ desktop: "off",
385
+ tablet: "on",
386
+ phone: "on",
387
+ }),
388
+ }),
389
+ rootNavBlock(mobileLabel, mobilePanelId, [dropdownBlock(mobilePanelId, buildListChildren(mobileItems))], {
390
+ customAttributes: [{ name: "data-diviops-nav-unit", value: "mobile" }],
391
+ extraAttrs: disabledOnAttrs({
392
+ desktop: "on",
393
+ tablet: "off",
394
+ phone: "off",
395
+ }),
396
+ }),
397
+ ]);
398
+ return {
399
+ type: "block_markup",
400
+ format: "divi_block_markup",
401
+ name,
402
+ markup,
403
+ notes: [
404
+ "Dry-run only: no WordPress write path is invoked.",
405
+ "Responsive split output contains two sibling nav units: desktop is disabled on tablet/phone, and mobile is disabled on desktop.",
406
+ "The split uses native Divi disabledOn visibility and emits no breakpoint JavaScript.",
407
+ "Use targeted create/clone/tree-surgery flows for placement; do not route this through whole-layout update paths.",
408
+ "Floating dropdown width is controlled by emitted CSS; Divi VB sizing controls may not constrain floating panels.",
409
+ "If custom runtime code observes style and writes style, guard unrendered dropdowns with getClientRects().length and make style writes idempotent.",
410
+ ],
411
+ };
304
412
  }
305
- const markup = rootNavBlock(label, panelId, [dropdownBlock(panelId, listChildren)]);
413
+ const markup = rootNavBlock(label, panelId, [
414
+ dropdownBlock(panelId, buildListChildren(spec.items)),
415
+ ]);
306
416
  return {
307
417
  type: "block_markup",
308
418
  format: "divi_block_markup",
@@ -311,6 +421,8 @@ export function emitNavBlockMarkup(input) {
311
421
  notes: [
312
422
  "Dry-run only: no WordPress write path is invoked.",
313
423
  "Use targeted create/clone/tree-surgery flows for placement; do not route this through whole-layout update paths.",
424
+ "Floating dropdown width is controlled by emitted CSS; Divi VB sizing controls may not constrain floating panels.",
425
+ "If custom runtime code observes style and writes style, guard unrendered dropdowns with getClientRects().length and make style writes idempotent.",
314
426
  ],
315
427
  };
316
428
  }
package/dist/wp-cli.d.ts CHANGED
@@ -13,6 +13,16 @@ interface WpCliConfig {
13
13
  /** Custom WP-CLI command prefix for containerized environments (e.g. "ddev wp"). */
14
14
  wpCliCmd?: string;
15
15
  }
16
+ /**
17
+ * Parse a command string into an array of arguments.
18
+ * Handles quoted strings (single and double quotes).
19
+ */
20
+ declare function parseCommand(command: string): string[];
21
+ declare function normalizeWpCliPathArgs(args: string[], wpPath: string): string[];
22
+ export declare const __wpCliTesting: {
23
+ parseCommand: typeof parseCommand;
24
+ normalizeWpCliPathArgs: typeof normalizeWpCliPathArgs;
25
+ };
16
26
  export declare function createWpCli(config: WpCliConfig): {
17
27
  /**
18
28
  * Execute a WP-CLI command from a string. Parsed via parseCommand
package/dist/wp-cli.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { execFile } from 'child_process';
9
9
  import { readdirSync, readFileSync, existsSync } from 'fs';
10
10
  import { homedir } from 'os';
11
- import { join } from 'path';
11
+ import { dirname, isAbsolute, join, resolve, sep } from 'path';
12
12
  import { resolveSafeFsRoot, fsValidationDisabled, ensureSafeFsRoot, matchFsSensitiveCommand, validateFilesystemFlags, } from './wp-cli-fs-validator.js';
13
13
  /**
14
14
  * Default WP-CLI commands — safe for public distribution.
@@ -188,13 +188,18 @@ function parseCommand(command) {
188
188
  let inDouble = false;
189
189
  for (let i = 0; i < command.length; i++) {
190
190
  const ch = command[i];
191
- if (ch === "'" && !inDouble) {
191
+ const next = command[i + 1];
192
+ if (ch === '\\' && !inSingle && next !== undefined) {
193
+ current += next;
194
+ i++;
195
+ }
196
+ else if (ch === "'" && !inDouble) {
192
197
  inSingle = !inSingle;
193
198
  }
194
199
  else if (ch === '"' && !inSingle) {
195
200
  inDouble = !inDouble;
196
201
  }
197
- else if (ch === ' ' && !inSingle && !inDouble) {
202
+ else if (/\s/.test(ch) && !inSingle && !inDouble) {
198
203
  if (current.length > 0) {
199
204
  args.push(current);
200
205
  current = '';
@@ -209,6 +214,107 @@ function parseCommand(command) {
209
214
  }
210
215
  return args;
211
216
  }
217
+ function isWithinWpPath(candidate, wpPath) {
218
+ const absolute = resolve(candidate);
219
+ const root = resolve(wpPath);
220
+ return absolute === root || absolute.startsWith(root + sep);
221
+ }
222
+ function normalizePathValue(value, wpPath) {
223
+ return isAbsolute(value) ? value : resolve(wpPath, value);
224
+ }
225
+ function coalesceSplitPathValue(args, startIndex, wpPath) {
226
+ const first = args[startIndex];
227
+ if (first === undefined) {
228
+ return { value: '', nextIndex: startIndex };
229
+ }
230
+ const normalizedFirst = normalizePathValue(first, wpPath);
231
+ if (!isAbsolute(first)) {
232
+ if (existsSync(normalizedFirst)) {
233
+ return { value: normalizedFirst, nextIndex: startIndex + 1 };
234
+ }
235
+ }
236
+ else {
237
+ const root = resolve(wpPath);
238
+ if (isWithinWpPath(normalizedFirst, root) && existsSync(normalizedFirst)) {
239
+ return { value: normalizedFirst, nextIndex: startIndex + 1 };
240
+ }
241
+ const couldBeWpPathSplit = root.startsWith(resolve(first) + ' ');
242
+ if (!couldBeWpPathSplit && !isWithinWpPath(normalizedFirst, root)) {
243
+ return { value: normalizedFirst, nextIndex: startIndex + 1 };
244
+ }
245
+ }
246
+ let bestParentMatch = null;
247
+ for (let endIndex = startIndex + 1; endIndex < args.length; endIndex++) {
248
+ if (args[endIndex]?.startsWith('--'))
249
+ break;
250
+ const joined = args.slice(startIndex, endIndex + 1).join(' ');
251
+ const normalized = normalizePathValue(joined, wpPath);
252
+ if (!isWithinWpPath(normalized, wpPath)) {
253
+ continue;
254
+ }
255
+ if (existsSync(normalized)) {
256
+ return { value: normalized, nextIndex: endIndex + 1 };
257
+ }
258
+ if (existsSync(dirname(normalized))) {
259
+ bestParentMatch = { value: normalized, nextIndex: endIndex + 1 };
260
+ }
261
+ }
262
+ return bestParentMatch ?? { value: normalizedFirst, nextIndex: startIndex + 1 };
263
+ }
264
+ function normalizePositionalPathArg(args, pathIndex, wpPath) {
265
+ if (args[pathIndex] === undefined || args[pathIndex]?.startsWith('--')) {
266
+ return args;
267
+ }
268
+ const before = args.slice(0, pathIndex);
269
+ const { value, nextIndex } = coalesceSplitPathValue(args, pathIndex, wpPath);
270
+ return [...before, value, ...args.slice(nextIndex)];
271
+ }
272
+ function normalizeDirFlagArgs(args, wpPath) {
273
+ const normalized = [];
274
+ for (let i = 0; i < args.length; i++) {
275
+ const arg = args[i];
276
+ if (arg === '--dir' && args[i + 1] !== undefined) {
277
+ const { value, nextIndex } = coalesceSplitPathValue(args, i + 1, wpPath);
278
+ normalized.push(arg, value);
279
+ i = nextIndex - 1;
280
+ }
281
+ else if (arg?.startsWith('--dir=')) {
282
+ const rawValue = arg.slice('--dir='.length);
283
+ const synthetic = [rawValue, ...args.slice(i + 1)];
284
+ const { value, nextIndex } = coalesceSplitPathValue(synthetic, 0, wpPath);
285
+ normalized.push(`--dir=${value}`);
286
+ i += nextIndex - 1;
287
+ }
288
+ else {
289
+ normalized.push(arg);
290
+ }
291
+ }
292
+ return normalized;
293
+ }
294
+ function normalizeWpCliPathArgs(args, wpPath) {
295
+ const threeWord = args.slice(0, 3).join(' ');
296
+ const twoWord = args.slice(0, 2).join(' ');
297
+ const oneWord = args[0];
298
+ if (oneWord === 'eval-file' || oneWord === 'import') {
299
+ return normalizePositionalPathArg(args, 1, wpPath);
300
+ }
301
+ if (twoWord === 'acf export' || twoWord === 'acf import') {
302
+ return normalizePositionalPathArg(args, 2, wpPath);
303
+ }
304
+ if (threeWord === 'scf json import' || threeWord === 'acf json import') {
305
+ return normalizePositionalPathArg(args, 3, wpPath);
306
+ }
307
+ if (oneWord === 'export' ||
308
+ threeWord === 'scf json export' ||
309
+ threeWord === 'acf json export') {
310
+ return normalizeDirFlagArgs(args, wpPath);
311
+ }
312
+ return args;
313
+ }
314
+ export const __wpCliTesting = {
315
+ parseCommand,
316
+ normalizeWpCliPathArgs,
317
+ };
212
318
  /**
213
319
  * Find the latest installed version of a Local lightning-service.
214
320
  * Scans ~/Library/Application Support/Local/lightning-services/ for directories
@@ -467,7 +573,7 @@ export function createWpCli(config) {
467
573
  * verbatim instead of being mis-split.
468
574
  */
469
575
  async run(command) {
470
- return runArgv(parseCommand(command));
576
+ return runArgv(normalizeWpCliPathArgs(parseCommand(command), config.wpPath));
471
577
  },
472
578
  /**
473
579
  * Execute a WP-CLI command from a pre-built argv array. Skips
package/dist/wp-client.js CHANGED
@@ -378,6 +378,11 @@ export class WPClient {
378
378
  Array.isArray(result.active_modules)) {
379
379
  result.active_modules = {};
380
380
  }
381
+ if (result.plugins === null ||
382
+ typeof result.plugins !== 'object' ||
383
+ Array.isArray(result.plugins)) {
384
+ result.plugins = {};
385
+ }
381
386
  return result;
382
387
  }
383
388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diviops/mcp-server",
3
- "version": "1.5.30",
3
+ "version": "1.5.32",
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 \"dist/preset-cli/__tests__/*.test.js\" \"dist/cross-env-preflight/__tests__/*.test.js\"",
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
  },