@diviops/mcp-server 1.5.31 → 1.5.33
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 +23 -13
- package/dist/compatibility.d.ts +11 -0
- package/dist/cross-env-preflight/header-preflight.d.ts +7 -0
- package/dist/cross-env-preflight/header-preflight.js +94 -0
- package/dist/index.js +376 -13
- package/dist/preset-cli/cli.d.ts +1 -1
- package/dist/preset-cli/cli.js +12 -3
- package/dist/preset-cli/nav-emitter.d.ts +17 -6
- package/dist/preset-cli/nav-emitter.js +148 -36
- package/dist/wp-cli.d.ts +20 -0
- package/dist/wp-cli.js +114 -4
- package/dist/wp-client.js +5 -0
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `diviops-preset nav` block-markup emitter.
|
|
3
3
|
*
|
|
4
|
-
* Emits
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
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
|
export interface NavLinkSpec {
|
|
18
19
|
label: string;
|
|
@@ -30,8 +31,12 @@ interface ParsedNavSectionSpec {
|
|
|
30
31
|
}
|
|
31
32
|
interface ParsedNavSpec {
|
|
32
33
|
label?: string;
|
|
34
|
+
desktopLabel?: string;
|
|
35
|
+
mobileLabel?: string;
|
|
33
36
|
idPrefix?: string;
|
|
34
37
|
items: Array<ParsedNavLinkSpec | ParsedNavSectionSpec>;
|
|
38
|
+
desktopItems?: Array<ParsedNavLinkSpec | ParsedNavSectionSpec>;
|
|
39
|
+
mobileItems?: Array<ParsedNavLinkSpec | ParsedNavSectionSpec>;
|
|
35
40
|
}
|
|
36
41
|
export interface NavItemSpec {
|
|
37
42
|
label: string;
|
|
@@ -41,12 +46,18 @@ export interface NavItemSpec {
|
|
|
41
46
|
}
|
|
42
47
|
export interface NavSpec {
|
|
43
48
|
label?: string;
|
|
49
|
+
desktopLabel?: string;
|
|
50
|
+
mobileLabel?: string;
|
|
44
51
|
idPrefix?: string;
|
|
45
|
-
items
|
|
52
|
+
items?: NavItemSpec[];
|
|
53
|
+
desktopItems?: NavItemSpec[];
|
|
54
|
+
mobileItems?: NavItemSpec[];
|
|
46
55
|
}
|
|
56
|
+
export type NavEmitterMode = "drawer" | "responsive_split";
|
|
47
57
|
export interface NavEmitterInput {
|
|
48
58
|
name: string;
|
|
49
59
|
spec: NavSpec;
|
|
60
|
+
mode?: NavEmitterMode;
|
|
50
61
|
}
|
|
51
62
|
export interface NavMarkupEntry {
|
|
52
63
|
type: "block_markup";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `diviops-preset nav` block-markup emitter.
|
|
3
3
|
*
|
|
4
|
-
* Emits
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
248
|
-
|
|
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:
|
|
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
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
302
|
-
|
|
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, [
|
|
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,26 @@ interface WpCliConfig {
|
|
|
13
13
|
/** Custom WP-CLI command prefix for containerized environments (e.g. "ddev wp"). */
|
|
14
14
|
wpCliCmd?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Validate a parsed command against the allowlist.
|
|
18
|
+
* Checks the first 1-3 args against allowed command prefixes (supports
|
|
19
|
+
* 2-word commands like "post list" and 3-word like "post meta get").
|
|
20
|
+
*/
|
|
21
|
+
declare function isCommandAllowed(args: string[]): {
|
|
22
|
+
allowed: boolean;
|
|
23
|
+
reason?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Parse a command string into an array of arguments.
|
|
27
|
+
* Handles quoted strings (single and double quotes).
|
|
28
|
+
*/
|
|
29
|
+
declare function parseCommand(command: string): string[];
|
|
30
|
+
declare function normalizeWpCliPathArgs(args: string[], wpPath: string): string[];
|
|
31
|
+
export declare const __wpCliTesting: {
|
|
32
|
+
isCommandAllowed: typeof isCommandAllowed;
|
|
33
|
+
parseCommand: typeof parseCommand;
|
|
34
|
+
normalizeWpCliPathArgs: typeof normalizeWpCliPathArgs;
|
|
35
|
+
};
|
|
16
36
|
export declare function createWpCli(config: WpCliConfig): {
|
|
17
37
|
/**
|
|
18
38
|
* 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.
|
|
@@ -27,6 +27,9 @@ const DEFAULT_COMMANDS = [
|
|
|
27
27
|
'post meta list',
|
|
28
28
|
'post meta set',
|
|
29
29
|
'post meta update',
|
|
30
|
+
// Taxonomy assignments (read-only). Assignment writes (`post term add/set/remove`)
|
|
31
|
+
// stay unsupported until a concrete workflow justifies a typed or extended path.
|
|
32
|
+
'post term list',
|
|
30
33
|
// Post types (read-only)
|
|
31
34
|
'post-type list',
|
|
32
35
|
'post-type get',
|
|
@@ -188,13 +191,18 @@ function parseCommand(command) {
|
|
|
188
191
|
let inDouble = false;
|
|
189
192
|
for (let i = 0; i < command.length; i++) {
|
|
190
193
|
const ch = command[i];
|
|
191
|
-
|
|
194
|
+
const next = command[i + 1];
|
|
195
|
+
if (ch === '\\' && !inSingle && next !== undefined) {
|
|
196
|
+
current += next;
|
|
197
|
+
i++;
|
|
198
|
+
}
|
|
199
|
+
else if (ch === "'" && !inDouble) {
|
|
192
200
|
inSingle = !inSingle;
|
|
193
201
|
}
|
|
194
202
|
else if (ch === '"' && !inSingle) {
|
|
195
203
|
inDouble = !inDouble;
|
|
196
204
|
}
|
|
197
|
-
else if (ch
|
|
205
|
+
else if (/\s/.test(ch) && !inSingle && !inDouble) {
|
|
198
206
|
if (current.length > 0) {
|
|
199
207
|
args.push(current);
|
|
200
208
|
current = '';
|
|
@@ -209,6 +217,108 @@ function parseCommand(command) {
|
|
|
209
217
|
}
|
|
210
218
|
return args;
|
|
211
219
|
}
|
|
220
|
+
function isWithinWpPath(candidate, wpPath) {
|
|
221
|
+
const absolute = resolve(candidate);
|
|
222
|
+
const root = resolve(wpPath);
|
|
223
|
+
return absolute === root || absolute.startsWith(root + sep);
|
|
224
|
+
}
|
|
225
|
+
function normalizePathValue(value, wpPath) {
|
|
226
|
+
return isAbsolute(value) ? value : resolve(wpPath, value);
|
|
227
|
+
}
|
|
228
|
+
function coalesceSplitPathValue(args, startIndex, wpPath) {
|
|
229
|
+
const first = args[startIndex];
|
|
230
|
+
if (first === undefined) {
|
|
231
|
+
return { value: '', nextIndex: startIndex };
|
|
232
|
+
}
|
|
233
|
+
const normalizedFirst = normalizePathValue(first, wpPath);
|
|
234
|
+
if (!isAbsolute(first)) {
|
|
235
|
+
if (existsSync(normalizedFirst)) {
|
|
236
|
+
return { value: normalizedFirst, nextIndex: startIndex + 1 };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const root = resolve(wpPath);
|
|
241
|
+
if (isWithinWpPath(normalizedFirst, root) && existsSync(normalizedFirst)) {
|
|
242
|
+
return { value: normalizedFirst, nextIndex: startIndex + 1 };
|
|
243
|
+
}
|
|
244
|
+
const couldBeWpPathSplit = root.startsWith(resolve(first) + ' ');
|
|
245
|
+
if (!couldBeWpPathSplit && !isWithinWpPath(normalizedFirst, root)) {
|
|
246
|
+
return { value: normalizedFirst, nextIndex: startIndex + 1 };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
let bestParentMatch = null;
|
|
250
|
+
for (let endIndex = startIndex + 1; endIndex < args.length; endIndex++) {
|
|
251
|
+
if (args[endIndex]?.startsWith('--'))
|
|
252
|
+
break;
|
|
253
|
+
const joined = args.slice(startIndex, endIndex + 1).join(' ');
|
|
254
|
+
const normalized = normalizePathValue(joined, wpPath);
|
|
255
|
+
if (!isWithinWpPath(normalized, wpPath)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (existsSync(normalized)) {
|
|
259
|
+
return { value: normalized, nextIndex: endIndex + 1 };
|
|
260
|
+
}
|
|
261
|
+
if (existsSync(dirname(normalized))) {
|
|
262
|
+
bestParentMatch = { value: normalized, nextIndex: endIndex + 1 };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return bestParentMatch ?? { value: normalizedFirst, nextIndex: startIndex + 1 };
|
|
266
|
+
}
|
|
267
|
+
function normalizePositionalPathArg(args, pathIndex, wpPath) {
|
|
268
|
+
if (args[pathIndex] === undefined || args[pathIndex]?.startsWith('--')) {
|
|
269
|
+
return args;
|
|
270
|
+
}
|
|
271
|
+
const before = args.slice(0, pathIndex);
|
|
272
|
+
const { value, nextIndex } = coalesceSplitPathValue(args, pathIndex, wpPath);
|
|
273
|
+
return [...before, value, ...args.slice(nextIndex)];
|
|
274
|
+
}
|
|
275
|
+
function normalizeDirFlagArgs(args, wpPath) {
|
|
276
|
+
const normalized = [];
|
|
277
|
+
for (let i = 0; i < args.length; i++) {
|
|
278
|
+
const arg = args[i];
|
|
279
|
+
if (arg === '--dir' && args[i + 1] !== undefined) {
|
|
280
|
+
const { value, nextIndex } = coalesceSplitPathValue(args, i + 1, wpPath);
|
|
281
|
+
normalized.push(arg, value);
|
|
282
|
+
i = nextIndex - 1;
|
|
283
|
+
}
|
|
284
|
+
else if (arg?.startsWith('--dir=')) {
|
|
285
|
+
const rawValue = arg.slice('--dir='.length);
|
|
286
|
+
const synthetic = [rawValue, ...args.slice(i + 1)];
|
|
287
|
+
const { value, nextIndex } = coalesceSplitPathValue(synthetic, 0, wpPath);
|
|
288
|
+
normalized.push(`--dir=${value}`);
|
|
289
|
+
i += nextIndex - 1;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
normalized.push(arg);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return normalized;
|
|
296
|
+
}
|
|
297
|
+
function normalizeWpCliPathArgs(args, wpPath) {
|
|
298
|
+
const threeWord = args.slice(0, 3).join(' ');
|
|
299
|
+
const twoWord = args.slice(0, 2).join(' ');
|
|
300
|
+
const oneWord = args[0];
|
|
301
|
+
if (oneWord === 'eval-file' || oneWord === 'import') {
|
|
302
|
+
return normalizePositionalPathArg(args, 1, wpPath);
|
|
303
|
+
}
|
|
304
|
+
if (twoWord === 'acf export' || twoWord === 'acf import') {
|
|
305
|
+
return normalizePositionalPathArg(args, 2, wpPath);
|
|
306
|
+
}
|
|
307
|
+
if (threeWord === 'scf json import' || threeWord === 'acf json import') {
|
|
308
|
+
return normalizePositionalPathArg(args, 3, wpPath);
|
|
309
|
+
}
|
|
310
|
+
if (oneWord === 'export' ||
|
|
311
|
+
threeWord === 'scf json export' ||
|
|
312
|
+
threeWord === 'acf json export') {
|
|
313
|
+
return normalizeDirFlagArgs(args, wpPath);
|
|
314
|
+
}
|
|
315
|
+
return args;
|
|
316
|
+
}
|
|
317
|
+
export const __wpCliTesting = {
|
|
318
|
+
isCommandAllowed,
|
|
319
|
+
parseCommand,
|
|
320
|
+
normalizeWpCliPathArgs,
|
|
321
|
+
};
|
|
212
322
|
/**
|
|
213
323
|
* Find the latest installed version of a Local lightning-service.
|
|
214
324
|
* Scans ~/Library/Application Support/Local/lightning-services/ for directories
|
|
@@ -467,7 +577,7 @@ export function createWpCli(config) {
|
|
|
467
577
|
* verbatim instead of being mis-split.
|
|
468
578
|
*/
|
|
469
579
|
async run(command) {
|
|
470
|
-
return runArgv(parseCommand(command));
|
|
580
|
+
return runArgv(normalizeWpCliPathArgs(parseCommand(command), config.wpPath));
|
|
471
581
|
},
|
|
472
582
|
/**
|
|
473
583
|
* 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.
|
|
3
|
+
"version": "1.5.33",
|
|
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
|
},
|