@diviops/mcp-server 1.5.29 → 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.
package/dist/index.js CHANGED
@@ -12,8 +12,9 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
12
12
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
13
  import { z } from "zod";
14
14
  import { WPClient } from "./wp-client.js";
15
- import { MissingCapabilityError } from "./compatibility.js";
15
+ import { MissingCapabilityError, proToolGatesSatisfied } from "./compatibility.js";
16
16
  import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
17
+ import { preflightCrossEnvHeaderSync, } from "./cross-env-preflight/header-preflight.js";
17
18
  import { optimizeSchema } from "./schema-optimizer.js";
18
19
  import { schemaModuleRoute } from "./schema-route.js";
19
20
  import { createWpCli } from "./wp-cli.js";
@@ -86,6 +87,95 @@ const server = new McpServer({
86
87
  version: SERVER_VERSION,
87
88
  });
88
89
  let handshakeState = { kind: "pending" };
90
+ const BASE_META_CAPABILITIES = [
91
+ "pages",
92
+ "modules",
93
+ "presets",
94
+ "library",
95
+ "theme_builder",
96
+ "canvas",
97
+ "variables",
98
+ "templates",
99
+ "icons",
100
+ "validation",
101
+ "preview",
102
+ ];
103
+ function enabledCapabilityKeys(prefix) {
104
+ if (handshakeState.kind !== "ok")
105
+ return [];
106
+ const state = handshakeState;
107
+ return Object.keys(state.capabilities)
108
+ .filter((key) => state.capabilities[key])
109
+ .filter((key) => (prefix ? key.startsWith(prefix) : true))
110
+ .sort();
111
+ }
112
+ function buildMetaInfo() {
113
+ const fluentCartCapabilityKeys = enabledCapabilityKeys("fluentcart_");
114
+ const crossEnvCapabilityKeys = enabledCapabilityKeys("cross_env_");
115
+ const fluentCartTarget = handshakeState.kind === "ok"
116
+ ? handshakeState.availableTargets.fluentcart ?? null
117
+ : null;
118
+ const crossEnvTarget = handshakeState.kind === "ok"
119
+ ? handshakeState.availableTargets.cross_env ?? null
120
+ : null;
121
+ const fluentCartActive = handshakeState.kind === "ok" &&
122
+ handshakeState.proActive === true &&
123
+ fluentCartTarget?.present === true &&
124
+ handshakeState.activeModules.fluentcart === true &&
125
+ fluentCartCapabilityKeys.length > 0;
126
+ const crossEnvActive = handshakeState.kind === "ok" &&
127
+ handshakeState.proActive === true &&
128
+ crossEnvTarget?.present === true &&
129
+ handshakeState.activeModules.cross_env === true &&
130
+ crossEnvCapabilityKeys.length > 0;
131
+ const capabilities = fluentCartActive
132
+ ? [...BASE_META_CAPABILITIES, "fluentcart"]
133
+ : [...BASE_META_CAPABILITIES];
134
+ if (crossEnvActive)
135
+ capabilities.push("cross_env");
136
+ return {
137
+ brand: "DiviOps",
138
+ server: "diviops-mcp",
139
+ version: SERVER_VERSION,
140
+ license: "MIT",
141
+ capabilities,
142
+ handshake: handshakeState.kind === "ok"
143
+ ? {
144
+ state: "ok",
145
+ plugin_version: handshakeState.pluginVersion,
146
+ capability_count: enabledCapabilityKeys().length,
147
+ }
148
+ : { state: handshakeState.kind },
149
+ pro: handshakeState.kind === "ok"
150
+ ? {
151
+ active: handshakeState.proActive,
152
+ version: handshakeState.proVersion ?? null,
153
+ }
154
+ : {
155
+ active: false,
156
+ version: null,
157
+ },
158
+ slices: {
159
+ fluentcart: {
160
+ target: fluentCartTarget,
161
+ active: fluentCartActive,
162
+ module_active: handshakeState.kind === "ok"
163
+ ? handshakeState.activeModules.fluentcart === true
164
+ : false,
165
+ tool_capabilities: fluentCartCapabilityKeys,
166
+ },
167
+ cross_env: {
168
+ target: crossEnvTarget,
169
+ active: crossEnvActive,
170
+ module_active: handshakeState.kind === "ok"
171
+ ? handshakeState.activeModules.cross_env === true
172
+ : false,
173
+ tool_capabilities: crossEnvCapabilityKeys,
174
+ },
175
+ },
176
+ wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
177
+ };
178
+ }
89
179
  function requireCapability(key) {
90
180
  // Only gate when we have a real capability map. On handshake failure,
91
181
  // bypass the gate so the underlying request surfaces the actual cause
@@ -177,14 +267,7 @@ function registerLocalTool(name, config, handler) {
177
267
  function registerProTool(name, config, handler, gates) {
178
268
  if (handshakeState.kind !== "ok")
179
269
  return;
180
- if (!handshakeState.proActive)
181
- return;
182
- const target = handshakeState.availableTargets[gates.target];
183
- if (!target || target.present !== true)
184
- return;
185
- if (handshakeState.activeModules[gates.target] !== true)
186
- return;
187
- if (!handshakeState.capabilities[gates.capabilityKey])
270
+ if (!proToolGatesSatisfied(handshakeState, gates))
188
271
  return;
189
272
  recordIdempotent(name, config?._meta);
190
273
  server.registerTool(name, config, handler);
@@ -278,6 +361,61 @@ registerPluginTool("diviops_page_get_layout", {
278
361
  ],
279
362
  };
280
363
  });
364
+ registerPluginTool("diviops_module_get", {
365
+ description: 'Get one targeted Divi module/block from a page, post, or Theme Builder layout by auto_index (e.g. "text:5"), admin label, or text content. Uses the same selector validation as diviops_module_update: pass exactly one of auto_index, label, or match_text; use occurrence with duplicate labels. Default mode returns identity, block name, admin label, auto_index, text preview, source bounds, and a compact attr summary. Use full: true to include decoded attrs and raw serialized block markup for the matched module only. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; missing module returns code "not_found" with error.data = { target_kind: "module", target_mode, target_value, page_id }.',
366
+ inputSchema: {
367
+ page_id: z
368
+ .number()
369
+ .int()
370
+ .describe("WordPress post/layout ID whose Divi block content should be searched"),
371
+ label: z
372
+ .string()
373
+ .optional()
374
+ .describe("Admin label of the module (exact match)"),
375
+ match_text: z
376
+ .string()
377
+ .optional()
378
+ .describe("Text to find in module attrs/innerContent (case-insensitive substring, first match)"),
379
+ auto_index: z
380
+ .string()
381
+ .optional()
382
+ .describe('Auto-index target in "type:N" format (e.g. "text:5", "icon:3"). Get from diviops_page_get_layout.'),
383
+ occurrence: z
384
+ .number()
385
+ .int()
386
+ .min(1)
387
+ .optional()
388
+ .default(1)
389
+ .describe("Which occurrence to target when multiple modules share the same label (1-based)"),
390
+ full: z
391
+ .boolean()
392
+ .optional()
393
+ .default(false)
394
+ .describe("Include decoded attrs and raw serialized block markup for the matched module only"),
395
+ },
396
+ annotations: { idempotentHint: true },
397
+ _meta: { idempotent: "true" },
398
+ }, async ({ page_id, label, match_text, auto_index, occurrence, full }) => {
399
+ const params = {};
400
+ if (auto_index)
401
+ params.auto_index = auto_index;
402
+ if (label)
403
+ params.label = label;
404
+ if (match_text)
405
+ params.match_text = match_text;
406
+ if (occurrence > 1)
407
+ params.occurrence = String(occurrence);
408
+ if (full)
409
+ params.full = "true";
410
+ const qs = new URLSearchParams(params).toString();
411
+ const suffix = qs ? `?${qs}` : "";
412
+ const result = await wp.requestEnveloped(`/module/get/${page_id}${suffix}`);
413
+ return {
414
+ content: [
415
+ { type: "text", text: serializeEnvelope(result, "diviops_module_get") },
416
+ ],
417
+ };
418
+ });
281
419
  registerPluginTool("diviops_schema_list_modules", {
282
420
  description: "List all available Divi modules (block types) with their names, titles, and categories. Use this to discover what modules can be used in layouts. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
283
421
  annotations: { idempotentHint: true },
@@ -1750,6 +1888,98 @@ registerPluginTool("diviops_tb_layout_get", {
1750
1888
  ],
1751
1889
  };
1752
1890
  });
1891
+ registerPluginTool("diviops_cross_env_target_context_get", {
1892
+ description: "Export read-only, secret-free target-site context for the offline cross-environment Theme Builder header preflight. Produces JSON suitable for `diviops-cross-env-preflight --target`: target origin derived from WordPress, destination header layout metadata, a sha256 checksum of current target layout post_content without exposing raw content, target global colors, built-in customizer color IDs, sha256 value evidence for user/customizer global colors, defensible attachment candidates/remaps from optional source asset hints, and cache_scope. This Free/core tool does not write layouts, upload media, create global colors, or expose cookies, nonces, app passwords, signed URLs, query strings, fragments, or local filesystem paths. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; unsupported destination_kind returns invalid_input, and missing/non-header layouts return not_found.",
1893
+ inputSchema: {
1894
+ destination_id: z
1895
+ .number()
1896
+ .int()
1897
+ .positive()
1898
+ .describe("Existing target Theme Builder header layout post ID."),
1899
+ destination_kind: z
1900
+ .enum(["tb_header_layout"])
1901
+ .optional()
1902
+ .default("tb_header_layout")
1903
+ .describe("Destination kind. Only tb_header_layout is supported in this read-only slice."),
1904
+ source_asset_hints: z
1905
+ .array(z.string())
1906
+ .optional()
1907
+ .describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
1908
+ source_attachment_ids: z
1909
+ .array(z.number())
1910
+ .optional()
1911
+ .describe("Optional numeric source attachment IDs found in source markup. A remap is emitted only when exactly one source ID and one exact target candidate are present."),
1912
+ dry_run: z
1913
+ .boolean()
1914
+ .optional()
1915
+ .default(true)
1916
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
1917
+ },
1918
+ annotations: { idempotentHint: true },
1919
+ _meta: { idempotent: "true" },
1920
+ }, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
1921
+ const body = {
1922
+ destination_id,
1923
+ destination_kind: destination_kind ?? "tb_header_layout",
1924
+ };
1925
+ if (source_asset_hints && source_asset_hints.length > 0) {
1926
+ body.source_asset_hints = source_asset_hints;
1927
+ }
1928
+ if (source_attachment_ids && source_attachment_ids.length > 0) {
1929
+ body.source_attachment_ids = source_attachment_ids;
1930
+ }
1931
+ const result = await wp.requestEnveloped("/cross-env/target-context", {
1932
+ method: "POST",
1933
+ body,
1934
+ });
1935
+ return {
1936
+ content: [
1937
+ {
1938
+ type: "text",
1939
+ text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
1940
+ },
1941
+ ],
1942
+ };
1943
+ });
1944
+ registerPluginTool("diviops_cross_env_source_export_get", {
1945
+ description: "Export read-only, secret-free source-site payload for the offline cross-environment Theme Builder header preflight. Produces JSON suitable for `diviops-cross-env-preflight --source`: source origin, `tb_header_layout` metadata, sanitized markup, bare sha256 checksum of that exported markup, export timestamp, DiviOps plugin version, and best-effort attachment inventory from markup media URLs and attachment IDs. This Free/core tool does not write layouts, upload media, create global colors, reconcile references, expose cookies, nonces, app passwords, signed URLs, query strings, fragments, admin URLs, or local filesystem paths. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; unsupported source_kind returns invalid_input, and missing/non-header source layouts return not_found.",
1946
+ inputSchema: {
1947
+ source_id: z
1948
+ .number()
1949
+ .int()
1950
+ .positive()
1951
+ .describe("Existing source Theme Builder header layout post ID."),
1952
+ source_kind: z
1953
+ .enum(["tb_header_layout"])
1954
+ .optional()
1955
+ .default("tb_header_layout")
1956
+ .describe("Source kind. Only tb_header_layout is supported in this read-only slice."),
1957
+ dry_run: z
1958
+ .boolean()
1959
+ .optional()
1960
+ .default(true)
1961
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
1962
+ },
1963
+ annotations: { idempotentHint: true },
1964
+ _meta: { idempotent: "true" },
1965
+ }, async ({ source_id, source_kind }) => {
1966
+ const body = {
1967
+ source_id,
1968
+ source_kind: source_kind ?? "tb_header_layout",
1969
+ };
1970
+ const result = await wp.requestEnveloped("/cross-env/source-export", {
1971
+ method: "POST",
1972
+ body,
1973
+ });
1974
+ return {
1975
+ content: [
1976
+ {
1977
+ type: "text",
1978
+ text: serializeEnvelope(result, "diviops_cross_env_source_export_get"),
1979
+ },
1980
+ ],
1981
+ };
1982
+ });
1753
1983
  registerPluginTool("diviops_tb_layout_update", {
1754
1984
  description: "Update a Theme Builder layout's block markup (header, body, or footer). Replaces the full content. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; missing layout_id returns ok:false with code 'not_found'." +
1755
1985
  DRY_RUN_DESC_SUFFIX,
@@ -2553,30 +2783,11 @@ registerLocalTool("diviops_meta_ping", {
2553
2783
  };
2554
2784
  });
2555
2785
  registerLocalTool("diviops_meta_info", {
2556
- description: "Returns DiviOps MCP server identity, version, license type, and available capabilities. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
2786
+ description: "Returns DiviOps MCP server identity, version, license type, available capability groups, WP-CLI allowlist, and plugin handshake/slice state including Pro and FluentCart target readiness. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
2557
2787
  annotations: { idempotentHint: true },
2558
2788
  _meta: { idempotent: "true" },
2559
2789
  }, async () => {
2560
- const response = await wrapResponse(async () => ({
2561
- brand: "DiviOps",
2562
- server: "diviops-mcp",
2563
- version: SERVER_VERSION,
2564
- license: "MIT",
2565
- capabilities: [
2566
- "pages",
2567
- "modules",
2568
- "presets",
2569
- "library",
2570
- "theme_builder",
2571
- "canvas",
2572
- "variables",
2573
- "templates",
2574
- "icons",
2575
- "validation",
2576
- "preview",
2577
- ],
2578
- wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
2579
- }));
2790
+ const response = await wrapResponse(async () => buildMetaInfo());
2580
2791
  return {
2581
2792
  content: [
2582
2793
  { type: "text", text: serializeEnvelope(response, "diviops_meta_info") },
@@ -3077,7 +3288,7 @@ registerPluginTool("diviops_variable_used_on_page", {
3077
3288
  };
3078
3289
  });
3079
3290
  registerPluginTool("diviops_meta_flush_cache", {
3080
- description: "Flush Divi's compiled static CSS cache under wp-content/et-cache/. wp cache flush does NOT touch these files — the frontend can keep serving stale CSS after a preset/variable/module mutation until the cache is cleared. Delegates to Divi's native ET_Core_PageResource::remove_static_resources when available (response backend: \"divi_native\"), which additionally clears Theme Builder CSS scattered across other post dirs, archive/taxonomy/home/notfound CSS, the object cache, module features cache, post features cache, Google Fonts cache, dynamic assets cache, and post meta caches. Falls back to a targeted filesystem walk of numeric-named et-cache subdirs when the Divi class is absent (backend: \"fs_fallback\"). Provide exactly one selector — no site-wide default to prevent accidental full flush. Idempotent: missing cache root returns 200 with empty list. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; namespace-specific error codes: meta_flush_cache.unwritable (filesystem refused), meta_flush_cache.fs_init_failed (WP_Filesystem could not authenticate)." +
3291
+ description: "Flush Divi's compiled static CSS cache under wp-content/et-cache/. wp cache flush does NOT touch these files — the frontend can keep serving stale CSS after a preset/variable/module mutation until the cache is cleared. Delegates to Divi's native ET_Core_PageResource::remove_static_resources when available (response backend: \"divi_native\"), which additionally clears Theme Builder CSS scattered across other post dirs, archive/taxonomy/home/notfound CSS, the object cache, module features cache, post features cache, Google Fonts cache, dynamic assets cache, and post meta caches. Falls back to a targeted filesystem walk of numeric-named et-cache subdirs when the Divi class is absent (backend: \"fs_fallback\"). Provide exactly one selector — no site-wide default to prevent accidental full flush. Optional cleanup_dynamic_assets=true explicitly deletes and reports _divi_dynamic_assets_cached_feature_used postmeta for the selected target IDs; cleanup_canvas_refs=true also deletes _divi_dynamic_assets_canvases_used and is only appropriate when canvas/off-canvas references are affected. Dynamic-assets postmeta cleanup is supported with post_id or all (bounded to posts that already carry the selected meta keys), not after. Idempotent: missing cache root returns 200 with empty list and repeat postmeta cleanup reports absent keys. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; namespace-specific error codes: meta_flush_cache.unwritable (filesystem refused), meta_flush_cache.fs_init_failed (WP_Filesystem could not authenticate)." +
3081
3292
  DRY_RUN_DESC_SUFFIX +
3082
3293
  " Note: in `after` mode the dry-run plan reports the cutoff only — accurate file count requires the live mtime walk.",
3083
3294
  inputSchema: {
@@ -3099,10 +3310,20 @@ registerPluginTool("diviops_meta_flush_cache", {
3099
3310
  .optional()
3100
3311
  .describe("Unix timestamp — flush Divi CSS files (et-*.css) with mtime strictly greater than this value. Useful for flushing entries touched since a known deployment or mutation batch. Native backend does a single-pass filesystem sweep covering numeric post dirs AND archive/taxonomy/home/notfound/global subtrees in one walk (Visual Builder -vb-* runtime CSS preserved); fs_fallback iterates numeric post dirs whose latest file mtime > after. `flushed` lists numeric post_ids whose files were actually deleted; `skipped` lists numeric post_ids that exist but had no files pass the filter."),
3101
3312
  dry_run: DRY_RUN_FIELD,
3313
+ cleanup_dynamic_assets: z
3314
+ .boolean()
3315
+ .optional()
3316
+ .default(false)
3317
+ .describe("Explicitly delete and report Divi's _divi_dynamic_assets_cached_feature_used postmeta for the selected post_id, or for all posts that already carry selected dynamic-assets postmeta when all=true. Supported with post_id or all only."),
3318
+ cleanup_canvas_refs: z
3319
+ .boolean()
3320
+ .optional()
3321
+ .default(false)
3322
+ .describe("Opt-in canvas/off-canvas cleanup. Requires cleanup_dynamic_assets=true and also deletes _divi_dynamic_assets_canvases_used. Use only when canvas/off-canvas references are affected."),
3102
3323
  },
3103
3324
  annotations: { idempotentHint: true },
3104
3325
  _meta: { idempotent: "true" },
3105
- }, async ({ post_id, all, after, dry_run }) => {
3326
+ }, async ({ post_id, all, after, dry_run, cleanup_dynamic_assets, cleanup_canvas_refs }) => {
3106
3327
  const body = {};
3107
3328
  if (post_id !== undefined)
3108
3329
  body.post_id = post_id;
@@ -3112,6 +3333,10 @@ registerPluginTool("diviops_meta_flush_cache", {
3112
3333
  body.after = after;
3113
3334
  if (dry_run)
3114
3335
  body.dry_run = true;
3336
+ if (cleanup_dynamic_assets)
3337
+ body.cleanup_dynamic_assets = true;
3338
+ if (cleanup_canvas_refs)
3339
+ body.cleanup_canvas_refs = true;
3115
3340
  const result = await wp.requestEnveloped("/meta/flush-cache", {
3116
3341
  method: "POST",
3117
3342
  body,
@@ -3132,7 +3357,132 @@ registerPluginTool("diviops_meta_flush_cache", {
3132
3357
  //
3133
3358
  // Run inside `registerProTools()` rather than at module load because the
3134
3359
  // gates read handshakeState which is `pending` until `main()` runs.
3360
+ const CrossEnvSourceAttachmentSchema = z
3361
+ .object({
3362
+ id: z.number().int().positive().optional(),
3363
+ url: z.string().optional(),
3364
+ path: z.string().optional(),
3365
+ filename: z.string().optional(),
3366
+ mime: z.string().optional(),
3367
+ })
3368
+ .passthrough();
3369
+ const CrossEnvSourcePayloadSchema = z
3370
+ .object({
3371
+ origin: z.string().describe("Source site origin, e.g. https://source.example."),
3372
+ object_kind: z
3373
+ .enum(["tb_header_layout"])
3374
+ .describe("Source object kind. MVP supports tb_header_layout only."),
3375
+ object_id: z.union([z.number(), z.string()]).optional(),
3376
+ object_title: z.string().optional(),
3377
+ markup: z.string().describe("Sanitized source header layout block markup."),
3378
+ checksum: z
3379
+ .string()
3380
+ .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
3381
+ .describe("sha256 checksum of source_payload.markup from source export."),
3382
+ attachments: z.array(CrossEnvSourceAttachmentSchema).optional(),
3383
+ })
3384
+ .passthrough();
3385
+ function normalizeReviewedFingerprint(value) {
3386
+ return value.trim().replace(/^sha256:/i, "").toLowerCase();
3387
+ }
3388
+ function sourceHintsFromPayload(source) {
3389
+ const hints = new Set();
3390
+ const ids = new Set();
3391
+ for (const attachment of source.attachments ?? []) {
3392
+ if (typeof attachment.id === "number" && Number.isInteger(attachment.id) && attachment.id > 0) {
3393
+ ids.add(attachment.id);
3394
+ }
3395
+ for (const value of [attachment.path, attachment.url, attachment.filename]) {
3396
+ if (typeof value === "string" && value.trim())
3397
+ hints.add(value.trim());
3398
+ }
3399
+ }
3400
+ return {
3401
+ ...(hints.size > 0 ? { source_asset_hints: [...hints].sort((a, b) => a.localeCompare(b)) } : {}),
3402
+ ...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
3403
+ };
3404
+ }
3135
3405
  function registerProTools() {
3406
+ // diviops_cross_env_header_apply — guarded Pro apply for reviewed header preflight
3407
+ registerProTool("diviops_cross_env_header_apply", {
3408
+ description: "Apply a reviewed cross-environment Theme Builder header payload into an existing target header layout (Pro tier; requires the cross_env Pro module). This first MVP is intentionally narrow: it requires `confirm_apply: true`, a source export payload with checksum, an existing target `destination_id`, and the reviewed `confirmation_binding.fingerprint` from `diviops-cross-env-preflight`. The server re-exports current target context, reruns the TypeScript preflight engine, refuses fingerprint mismatch, unsafe verdicts, destination checksum drift, missing/ambiguous attachment remaps, missing global-color value evidence, and off-canvas/canvas references, then calls the Pro route with the verified plan. The Pro route re-loads the destination post, verifies the current checksum again, builds content only from source-origin upload URL rewrites and proven attachment-ID remaps, writes with readback/rollback evidence, and runs Divi static-resource cleanup plus explicit _divi_dynamic_assets_cached_feature_used cleanup. No media upload/import, global-color creation/import, new layout creation, off-canvas reconcile, public/store/license change, or live-site smoke is performed by this tool. Returns the standardized envelope { ok, data?, error: { code, message, hint?, data? } }. Error codes include cross_env.confirmation_required, cross_env.fingerprint_mismatch, cross_env.preflight_not_safe, cross_env.destination_checksum_drift, cross_env.source_checksum_mismatch, cross_env.content_write_corruption, invalid_input, not_found, forbidden, and wp_error.",
3409
+ inputSchema: {
3410
+ source_payload: CrossEnvSourcePayloadSchema.describe("The `data` object returned by diviops_cross_env_source_export_get on the source site."),
3411
+ destination_id: z
3412
+ .number()
3413
+ .int()
3414
+ .positive()
3415
+ .describe("Existing target Theme Builder header layout post ID."),
3416
+ destination_kind: z
3417
+ .enum(["tb_header_layout"])
3418
+ .optional()
3419
+ .default("tb_header_layout")
3420
+ .describe("Destination kind. MVP supports tb_header_layout only."),
3421
+ reviewed_fingerprint: z
3422
+ .string()
3423
+ .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
3424
+ .describe("Reviewed confirmation_binding.fingerprint from the safe preflight report."),
3425
+ confirm_apply: z
3426
+ .boolean()
3427
+ .describe("Must be true. Missing/false refuses before any target mutation."),
3428
+ },
3429
+ annotations: { idempotentHint: false },
3430
+ _meta: { idempotent: "conditional" },
3431
+ }, async ({ source_payload, destination_id, destination_kind, reviewed_fingerprint, confirm_apply, }) => {
3432
+ const result = await wrapResponse(async () => {
3433
+ if (confirm_apply !== true) {
3434
+ withCode("cross_env.confirmation_required", "confirm_apply: true is required before a cross-env header apply can mutate content.", "Review the preflight report, then retry with confirm_apply: true.");
3435
+ }
3436
+ const targetBody = {
3437
+ destination_id,
3438
+ destination_kind: destination_kind ?? "tb_header_layout",
3439
+ ...sourceHintsFromPayload(source_payload),
3440
+ };
3441
+ const targetEnvelope = await wp.requestEnveloped("/cross-env/target-context", { method: "POST", body: targetBody });
3442
+ if (!targetEnvelope.ok)
3443
+ return targetEnvelope;
3444
+ const report = preflightCrossEnvHeaderSync({
3445
+ source: source_payload,
3446
+ target: targetEnvelope.data,
3447
+ });
3448
+ const reviewed = normalizeReviewedFingerprint(reviewed_fingerprint);
3449
+ if (report.confirmation_binding.fingerprint !== reviewed) {
3450
+ withCode("cross_env.fingerprint_mismatch", "Reviewed confirmation fingerprint does not match the recomputed current preflight report.", "Re-run diviops-cross-env-preflight against the latest target context and confirm the new fingerprint.", {
3451
+ reviewed_fingerprint: reviewed,
3452
+ recomputed_fingerprint: report.confirmation_binding.fingerprint,
3453
+ current_destination_checksum: report.target.destination_checksum ?? null,
3454
+ });
3455
+ }
3456
+ if (report.verdict !== "safe_dry_run") {
3457
+ withCode("cross_env.preflight_not_safe", "Recomputed preflight verdict is not safe for this MVP apply path.", "Resolve blockers/operator actions, then re-run and re-confirm preflight.", {
3458
+ verdict: report.verdict,
3459
+ blockers: report.blockers,
3460
+ operator_actions: report.operator_actions,
3461
+ });
3462
+ }
3463
+ return wp.requestEnveloped("/pro/cross-env/header-layout/apply", {
3464
+ method: "POST",
3465
+ body: {
3466
+ confirm_apply: true,
3467
+ destination_id,
3468
+ destination_kind: destination_kind ?? "tb_header_layout",
3469
+ source_payload,
3470
+ source_checksum: source_payload.checksum,
3471
+ destination_checksum: report.target.destination_checksum,
3472
+ reviewed_fingerprint: reviewed,
3473
+ preflight_report: report,
3474
+ },
3475
+ });
3476
+ });
3477
+ return {
3478
+ content: [
3479
+ {
3480
+ type: "text",
3481
+ text: serializeEnvelope(result, "diviops_cross_env_header_apply"),
3482
+ },
3483
+ ],
3484
+ };
3485
+ }, { target: "cross_env", capabilityKey: "cross_env_header_apply" });
3136
3486
  // diviops_fc_product_list — bridges /diviops/v1/pro/fluentcart/products
3137
3487
  registerProTool("diviops_fc_product_list", {
3138
3488
  description: "List FluentCart Pro products (Pro tier; requires FluentCart Pro installed + activated). Returns a paginated summary list with product identity (id, title, slug, status), variation_type, variants_count, and min/max price. Filterable by `search` (LIKE post_title), `type` (one of physical/digital/subscription/onetime/simple/variations), and `status` (one of publish/draft/pending/private/trash; default returns publish+draft+pending+private). Read-only. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }; the success payload is { products: ProductSummary[], pagination: { page, per_page, total, total_pages }, filters: { search, type, status } }. Error codes: invalid_input (HTTP 400) when type/status filter is out of range; fluentcart.module_inactive (HTTP 412) when FluentCart is uninstalled or the diviops-agent-pro module toggle is off; fluentcart.query_failed (HTTP 500) when the underlying FluentCart model query raises an exception (message field carries the upstream exception). Use this before authoring a Divi commerce page to identify which product IDs / types to render.",
@@ -4246,6 +4596,7 @@ async function main() {
4246
4596
  kind: "ok",
4247
4597
  capabilities: hs.capabilities,
4248
4598
  pluginVersion: hs.plugin_version,
4599
+ proVersion: hs.pro_version,
4249
4600
  proActive: hs.pro_active === true,
4250
4601
  availableTargets: hs.available_targets ?? {},
4251
4602
  activeModules: hs.active_modules ?? {},
@@ -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