@diviops/mcp-server 1.5.34 → 1.5.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -13,13 +13,16 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
13
13
  import { z } from "zod";
14
14
  import { WPClient } from "./wp-client.js";
15
15
  import { MissingCapabilityError, proToolGatesSatisfied, } from "./compatibility.js";
16
+ import { missingCapabilityEnvelope, } from "./capability-envelope.js";
16
17
  import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
17
18
  import { preflightCrossEnvHeaderSync, } from "./cross-env-preflight/header-preflight.js";
19
+ import { preflightCrossEnvThemeBuilderLayoutSync, } from "./cross-env-preflight/layout-preflight.js";
20
+ import { crossEnvEvidenceLayoutKinds } from "./cross-env-preflight/layout-capability.js";
18
21
  import { createSourcePayloadRef, loadSourcePayloadRef, } from "./cross-env-preflight/source-payload-ref.js";
19
22
  import { optimizeSchema } from "./schema-optimizer.js";
20
23
  import { schemaModuleRoute } from "./schema-route.js";
21
24
  import { createWpCli } from "./wp-cli.js";
22
- import { findForeignVarRefs, scanAttrsForForeignVarRefs, isolationErrorResult, } from "./validate-attrs.js";
25
+ import { isolationFailure, scanValueForForeignVarRefs, writerIsolationErrorResult, } from "./validate-attrs.js";
23
26
  import { readFileSync, readdirSync } from "fs";
24
27
  import { join, dirname } from "path";
25
28
  import { fileURLToPath } from "url";
@@ -199,12 +202,16 @@ function buildPluginVersionSummary() {
199
202
  function buildMetaInfo() {
200
203
  const fluentCartCapabilityKeys = enabledCapabilityKeys("fluentcart_");
201
204
  const crossEnvCapabilityKeys = enabledCapabilityKeys("cross_env_");
205
+ const managedRecoveryCapabilityKeys = enabledCapabilityKeys("managed_recovery_");
202
206
  const fluentCartTarget = handshakeState.kind === "ok"
203
207
  ? handshakeState.availableTargets.fluentcart ?? null
204
208
  : null;
205
209
  const crossEnvTarget = handshakeState.kind === "ok"
206
210
  ? handshakeState.availableTargets.cross_env ?? null
207
211
  : null;
212
+ const managedRecoveryTarget = handshakeState.kind === "ok"
213
+ ? handshakeState.availableTargets.managed_recovery ?? null
214
+ : null;
208
215
  const fluentCartActive = handshakeState.kind === "ok" &&
209
216
  handshakeState.proActive === true &&
210
217
  fluentCartTarget?.present === true &&
@@ -215,11 +222,18 @@ function buildMetaInfo() {
215
222
  crossEnvTarget?.present === true &&
216
223
  handshakeState.activeModules.cross_env === true &&
217
224
  crossEnvCapabilityKeys.length > 0;
225
+ const managedRecoveryActive = handshakeState.kind === "ok" &&
226
+ handshakeState.proActive === true &&
227
+ managedRecoveryTarget?.present === true &&
228
+ handshakeState.activeModules.managed_recovery === true &&
229
+ managedRecoveryCapabilityKeys.length > 0;
218
230
  const capabilities = fluentCartActive
219
231
  ? [...BASE_META_CAPABILITIES, "fluentcart"]
220
232
  : [...BASE_META_CAPABILITIES];
221
233
  if (crossEnvActive)
222
234
  capabilities.push("cross_env");
235
+ if (managedRecoveryActive)
236
+ capabilities.push("managed_recovery");
223
237
  const tools = buildToolCatalogSummary();
224
238
  return {
225
239
  brand: "DiviOps",
@@ -264,6 +278,14 @@ function buildMetaInfo() {
264
278
  : false,
265
279
  tool_capabilities: crossEnvCapabilityKeys,
266
280
  },
281
+ managed_recovery: {
282
+ target: managedRecoveryTarget,
283
+ active: managedRecoveryActive,
284
+ module_active: handshakeState.kind === "ok"
285
+ ? handshakeState.activeModules.managed_recovery === true
286
+ : false,
287
+ tool_capabilities: managedRecoveryCapabilityKeys,
288
+ },
267
289
  },
268
290
  wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
269
291
  };
@@ -288,10 +310,7 @@ function backupCapabilityError(toolName, backup) {
288
310
  }
289
311
  catch (e) {
290
312
  if (e instanceof MissingCapabilityError) {
291
- return {
292
- content: [{ type: "text", text: e.message }],
293
- isError: true,
294
- };
313
+ return missingCapabilityEnvelope(e, toolName, "Update the diviops-agent WP plugin to a version that supports rollback snapshot backup, or omit backup:true from this call.");
295
314
  }
296
315
  throw e;
297
316
  }
@@ -320,10 +339,7 @@ function registerPluginTool(name, config, handler) {
320
339
  }
321
340
  catch (e) {
322
341
  if (e instanceof MissingCapabilityError) {
323
- return {
324
- content: [{ type: "text", text: e.message }],
325
- isError: true,
326
- };
342
+ return missingCapabilityEnvelope(e, name);
327
343
  }
328
344
  throw e;
329
345
  }
@@ -727,17 +743,7 @@ registerPluginTool("diviops_schema_get_module", {
727
743
  if (handshakeState.kind === "ok" &&
728
744
  !handshakeState.capabilities["schema_get_module_dump_all"]) {
729
745
  const err = new MissingCapabilityError("schema_get_module_dump_all", handshakeState.pluginVersion);
730
- const failure = {
731
- ok: false,
732
- error: {
733
- code: ErrorCodes.CAPABILITY_MISSING,
734
- message: err.message,
735
- hint: "Update the diviops-agent WP plugin to a version that exposes the dump-all surface.",
736
- },
737
- };
738
- return {
739
- content: [{ type: "text", text: serializeEnvelope(failure, "diviops_schema_get_module") }],
740
- };
746
+ return missingCapabilityEnvelope(err, "diviops_schema_get_module", "Update the diviops-agent WP plugin to a version that exposes the dump-all surface, or use mode:'single'.");
741
747
  }
742
748
  const result = await wp.requestEnveloped("/schema/module/dump-all");
743
749
  return {
@@ -1136,9 +1142,9 @@ registerPluginTool("diviops_page_update_content", {
1136
1142
  const backupGate = backupCapabilityError("diviops_page_update_content", backup);
1137
1143
  if (backupGate)
1138
1144
  return backupGate;
1139
- const hits = findForeignVarRefs(content, "content");
1140
- if (hits.length > 0)
1141
- return isolationErrorResult("diviops_page_update_content", hits);
1145
+ const isolationGate = writerIsolationErrorResult("diviops_page_update_content", { content });
1146
+ if (isolationGate)
1147
+ return isolationGate;
1142
1148
  const body = { content };
1143
1149
  if (dry_run)
1144
1150
  body.dry_run = true;
@@ -1234,10 +1240,7 @@ registerPluginTool("diviops_render_preview", {
1234
1240
  }
1235
1241
  catch (e) {
1236
1242
  if (e instanceof MissingCapabilityError) {
1237
- return {
1238
- content: [{ type: "text", text: e.message }],
1239
- isError: true,
1240
- };
1243
+ return missingCapabilityEnvelope(e, "diviops_render_preview", "Update the diviops-agent WP plugin to a version that supports page_id rendering, or provide inline content instead.");
1241
1244
  }
1242
1245
  throw e;
1243
1246
  }
@@ -1274,10 +1277,7 @@ registerPluginTool("diviops_validate_blocks", {
1274
1277
  }
1275
1278
  catch (e) {
1276
1279
  if (e instanceof MissingCapabilityError) {
1277
- return {
1278
- content: [{ type: "text", text: e.message }],
1279
- isError: true,
1280
- };
1280
+ return missingCapabilityEnvelope(e, "diviops_validate_blocks", "Update the diviops-agent WP plugin to a version that supports page_id validation, or provide inline content instead.");
1281
1281
  }
1282
1282
  throw e;
1283
1283
  }
@@ -1314,9 +1314,11 @@ registerPluginTool("diviops_section_append", {
1314
1314
  const backupGate = backupCapabilityError("diviops_section_append", backup);
1315
1315
  if (backupGate)
1316
1316
  return backupGate;
1317
- const hits = findForeignVarRefs(content, "content");
1318
- if (hits.length > 0)
1319
- return isolationErrorResult("diviops_section_append", hits);
1317
+ const isolationGate = writerIsolationErrorResult("diviops_section_append", {
1318
+ content,
1319
+ });
1320
+ if (isolationGate)
1321
+ return isolationGate;
1320
1322
  const body = { content, position: position ?? "end" };
1321
1323
  if (dry_run)
1322
1324
  body.dry_run = true;
@@ -1364,9 +1366,11 @@ registerPluginTool("diviops_section_replace", {
1364
1366
  const backupGate = backupCapabilityError("diviops_section_replace", backup);
1365
1367
  if (backupGate)
1366
1368
  return backupGate;
1367
- const hits = findForeignVarRefs(content, "content");
1368
- if (hits.length > 0)
1369
- return isolationErrorResult("diviops_section_replace", hits);
1369
+ const isolationGate = writerIsolationErrorResult("diviops_section_replace", {
1370
+ content,
1371
+ });
1372
+ if (isolationGate)
1373
+ return isolationGate;
1370
1374
  const body = { content, occurrence };
1371
1375
  if (label)
1372
1376
  body.label = label;
@@ -1506,9 +1510,11 @@ registerPluginTool("diviops_module_update", {
1506
1510
  const backupGate = backupCapabilityError("diviops_module_update", backup);
1507
1511
  if (backupGate)
1508
1512
  return backupGate;
1509
- const hits = scanAttrsForForeignVarRefs(attrs);
1510
- if (hits.length > 0)
1511
- return isolationErrorResult("diviops_module_update", hits);
1513
+ const isolationGate = writerIsolationErrorResult("diviops_module_update", {
1514
+ attrs,
1515
+ });
1516
+ if (isolationGate)
1517
+ return isolationGate;
1512
1518
  const body = { attrs };
1513
1519
  if (auto_index)
1514
1520
  body.auto_index = auto_index;
@@ -1743,11 +1749,11 @@ registerPluginTool("diviops_page_create", {
1743
1749
  annotations: { idempotentHint: false },
1744
1750
  _meta: { idempotent: "false" },
1745
1751
  }, async ({ title, content, status, dry_run }) => {
1746
- if (content) {
1747
- const hits = findForeignVarRefs(content, "content");
1748
- if (hits.length > 0)
1749
- return isolationErrorResult("diviops_page_create", hits);
1750
- }
1752
+ const isolationGate = writerIsolationErrorResult("diviops_page_create", {
1753
+ content: content ?? "",
1754
+ });
1755
+ if (isolationGate)
1756
+ return isolationGate;
1751
1757
  const body = { title, content: content ?? "", status: status ?? "draft" };
1752
1758
  if (dry_run)
1753
1759
  body.dry_run = true;
@@ -1868,6 +1874,23 @@ registerPluginTool("diviops_preset_inspect", {
1868
1874
  ],
1869
1875
  };
1870
1876
  });
1877
+ registerPluginTool("diviops_preset_registry_doctor", {
1878
+ description: "Audit the canonical Divi 5 preset registry for non-integer created/updated metadata and stale or failed preset chunk transients. repair=false is always read-only. repair=true only converts parseable ISO timestamps to integer milliseconds, creates a non-autoloaded backup before mutation, preserves unrelated preset payloads, and can optionally clear stale/failed matching chunk transients after a successful repair. Unsupported timestamp values are reported but never normalized." +
1879
+ DRY_RUN_DESC_SUFFIX,
1880
+ inputSchema: {
1881
+ repair: z.boolean().optional().default(false).describe("Enable the narrow ISO timestamp repair path."),
1882
+ clear_chunk_transients: z.boolean().optional().default(false).describe("After successful repair, clear only stale or failed matching Divi preset chunk transients."),
1883
+ dry_run: z.boolean().optional().default(true).describe("Preview repair and transient cleanup without mutation."),
1884
+ limit: z.number().int().min(1).max(500).optional().default(100).describe("Maximum findings and transient rows to return."),
1885
+ },
1886
+ _meta: { idempotent: "conditional" },
1887
+ }, async ({ repair, clear_chunk_transients, dry_run, limit }) => {
1888
+ const result = await wp.requestEnveloped("/preset/registry-doctor", {
1889
+ method: "POST",
1890
+ body: { repair, clear_chunk_transients, dry_run, limit },
1891
+ });
1892
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_preset_registry_doctor") }] };
1893
+ });
1871
1894
  registerPluginTool("diviops_rollback_snapshot_list", {
1872
1895
  description: "List DiviOps rollback snapshots from the option-backed store. Free/core storage management read surface; returns metadata only, never stored before.value payloads. Supports target_kind, target_id, status, and limit filters. Results are target-permission filtered; missing-target snapshots are shown only to site admins or the snapshot creator and are payload-redacted. Returns the standardized envelope { ok, data?, error: { code, message, hint? } }.",
1873
1896
  inputSchema: {
@@ -2011,6 +2034,11 @@ registerPluginTool("diviops_preset_update", {
2011
2034
  annotations: { idempotentHint: false },
2012
2035
  _meta: { idempotent: "conditional" },
2013
2036
  }, async ({ preset_id, name, attrs, priority, dry_run }) => {
2037
+ const isolationGate = writerIsolationErrorResult("diviops_preset_update", {
2038
+ attrs,
2039
+ });
2040
+ if (isolationGate)
2041
+ return isolationGate;
2014
2042
  const body = { preset_id };
2015
2043
  if (name)
2016
2044
  body.name = name;
@@ -2101,6 +2129,11 @@ registerPluginTool("diviops_preset_create", {
2101
2129
  if (type === "group" && (!group_name || !group_id)) {
2102
2130
  throw new Error('type="group" requires both group_name and group_id. Example: group_name="divi/font", group_id="designTitleText".');
2103
2131
  }
2132
+ const isolationGate = writerIsolationErrorResult("diviops_preset_create", {
2133
+ attrs,
2134
+ });
2135
+ if (isolationGate)
2136
+ return isolationGate;
2104
2137
  const body = { module_name, name, attrs, type };
2105
2138
  if (group_name)
2106
2139
  body.group_name = group_name;
@@ -2303,6 +2336,11 @@ registerPluginTool("diviops_library_save", {
2303
2336
  annotations: { idempotentHint: false },
2304
2337
  _meta: { idempotent: "conditional" },
2305
2338
  }, async ({ title, content, layout_type, scope, dry_run }) => {
2339
+ const isolationGate = writerIsolationErrorResult("diviops_library_save", {
2340
+ content,
2341
+ });
2342
+ if (isolationGate)
2343
+ return isolationGate;
2306
2344
  const body = { title, content, layout_type, scope };
2307
2345
  if (dry_run)
2308
2346
  body.dry_run = true;
@@ -2360,111 +2398,121 @@ registerPluginTool("diviops_tb_layout_get", {
2360
2398
  ],
2361
2399
  };
2362
2400
  });
2363
- registerPluginTool("diviops_cross_env_target_context_get", {
2364
- 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.",
2365
- inputSchema: {
2366
- destination_id: z
2367
- .number()
2368
- .int()
2369
- .positive()
2370
- .describe("Existing target Theme Builder header layout post ID."),
2371
- destination_kind: z
2372
- .enum(["tb_header_layout"])
2373
- .optional()
2374
- .default("tb_header_layout")
2375
- .describe("Destination kind. Only tb_header_layout is supported in this read-only slice."),
2376
- source_asset_hints: z
2377
- .array(z.string())
2378
- .optional()
2379
- .describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
2380
- source_attachment_ids: z
2381
- .array(z.number())
2382
- .optional()
2383
- .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."),
2384
- dry_run: z
2385
- .boolean()
2386
- .optional()
2387
- .default(true)
2388
- .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2389
- },
2390
- annotations: { idempotentHint: true },
2391
- _meta: { idempotent: "true" },
2392
- }, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
2393
- const body = {
2394
- destination_id,
2395
- destination_kind: destination_kind ?? "tb_header_layout",
2396
- };
2397
- if (source_asset_hints && source_asset_hints.length > 0) {
2398
- body.source_asset_hints = source_asset_hints;
2399
- }
2400
- if (source_attachment_ids && source_attachment_ids.length > 0) {
2401
- body.source_attachment_ids = source_attachment_ids;
2402
- }
2403
- const result = await wp.requestEnveloped("/cross-env/target-context", {
2404
- method: "POST",
2405
- body,
2406
- });
2407
- return {
2408
- content: [
2409
- {
2410
- type: "text",
2411
- text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
2412
- },
2413
- ],
2414
- };
2415
- });
2416
- registerPluginTool("diviops_cross_env_source_export_get", {
2417
- 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. The MCP server also writes the exported payload to a bounded local artifact under `.diviops-tmp/cross-env-source-payloads/` and returns `source_payload_ref` so large real headers can be applied later without inlining full markup through the model. This Free/core tool does not write WordPress layouts, upload media, create global colors, reconcile references, expose cookies, nonces, app passwords, signed URLs, query strings, fragments, admin URLs, or arbitrary 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.",
2418
- inputSchema: {
2419
- source_id: z
2420
- .number()
2421
- .int()
2422
- .positive()
2423
- .describe("Existing source Theme Builder header layout post ID."),
2424
- source_kind: z
2425
- .enum(["tb_header_layout"])
2426
- .optional()
2427
- .default("tb_header_layout")
2428
- .describe("Source kind. Only tb_header_layout is supported in this read-only slice."),
2429
- dry_run: z
2430
- .boolean()
2431
- .optional()
2432
- .default(true)
2433
- .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2434
- },
2435
- annotations: { idempotentHint: true },
2436
- _meta: { idempotent: "true" },
2437
- }, async ({ source_id, source_kind }) => {
2438
- const withRef = await wrapResponse(async () => {
2401
+ function registerCrossEnvEvidenceTools() {
2402
+ const capabilities = handshakeState.kind === "ok" ? handshakeState.capabilities : {};
2403
+ const layoutKinds = crossEnvEvidenceLayoutKinds(capabilities);
2404
+ const supportsFooter = layoutKinds.length === 2;
2405
+ const layoutLabel = supportsFooter ? "header or footer" : "header";
2406
+ registerPluginTool("diviops_cross_env_target_context_get", {
2407
+ description: `Export read-only, secret-free target-site context for an offline cross-environment Theme Builder ${supportsFooter ? "header/footer" : "header"} preflight. Returns exact kind/post-type identity, the current post_content checksum without content exposure, canonical template-linkage evidence/digest, dependency evidence, and cache scope. Free/core and read-only: no content, assignment, dependency, or cache mutation.`,
2408
+ inputSchema: {
2409
+ destination_id: z
2410
+ .number()
2411
+ .int()
2412
+ .positive()
2413
+ .describe(`Existing target Theme Builder ${layoutLabel} layout post ID.`),
2414
+ destination_kind: z
2415
+ .enum(layoutKinds)
2416
+ .optional()
2417
+ .default("tb_header_layout")
2418
+ .describe(supportsFooter
2419
+ ? "Destination kind. Header and footer existing-layout evidence is supported."
2420
+ : "Destination kind. This connected plugin proves header evidence only; update it to expose footer support."),
2421
+ source_asset_hints: z
2422
+ .array(z.string())
2423
+ .optional()
2424
+ .describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
2425
+ source_attachment_ids: z
2426
+ .array(z.number())
2427
+ .optional()
2428
+ .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."),
2429
+ dry_run: z
2430
+ .boolean()
2431
+ .optional()
2432
+ .default(true)
2433
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2434
+ },
2435
+ annotations: { idempotentHint: true },
2436
+ _meta: { idempotent: "true" },
2437
+ }, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
2439
2438
  const body = {
2440
- source_id,
2441
- source_kind: source_kind ?? "tb_header_layout",
2439
+ destination_id,
2440
+ destination_kind: destination_kind ?? "tb_header_layout",
2442
2441
  };
2443
- const result = await wp.requestEnveloped("/cross-env/source-export", {
2442
+ if (source_asset_hints && source_asset_hints.length > 0) {
2443
+ body.source_asset_hints = source_asset_hints;
2444
+ }
2445
+ if (source_attachment_ids && source_attachment_ids.length > 0) {
2446
+ body.source_attachment_ids = source_attachment_ids;
2447
+ }
2448
+ const result = await wp.requestEnveloped("/cross-env/target-context", {
2444
2449
  method: "POST",
2445
2450
  body,
2446
2451
  });
2447
- return envelopeMap(result, (data) => ({
2448
- ...data,
2449
- source_payload_ref: createSourcePayloadRef(data),
2450
- _meta: {
2451
- ...(typeof data._meta === "object" &&
2452
- data._meta !== null
2453
- ? (data._meta ?? {})
2454
- : {}),
2455
- source_payload_ref: "server-local artifact handle for diviops_cross_env_header_apply; stores the same source payload under .diviops-tmp/cross-env-source-payloads and is bounded by handle + checksum + TTL",
2456
- },
2457
- }));
2452
+ return {
2453
+ content: [
2454
+ {
2455
+ type: "text",
2456
+ text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
2457
+ },
2458
+ ],
2459
+ };
2458
2460
  });
2459
- return {
2460
- content: [
2461
- {
2462
- type: "text",
2463
- text: serializeEnvelope(withRef, "diviops_cross_env_source_export_get"),
2464
- },
2465
- ],
2466
- };
2467
- });
2461
+ registerPluginTool("diviops_cross_env_source_export_get", {
2462
+ description: `Export read-only, secret-free source-site payload for an offline cross-environment Theme Builder ${supportsFooter ? "header/footer" : "header"} preflight. Returns exact kind/post-type identity, sanitized markup and checksum, dependency inventories, and a bounded source_payload_ref. Free/core and read-only: no WordPress content, assignment, dependency, or cache mutation.`,
2463
+ inputSchema: {
2464
+ source_id: z
2465
+ .number()
2466
+ .int()
2467
+ .positive()
2468
+ .describe(`Existing source Theme Builder ${layoutLabel} layout post ID.`),
2469
+ source_kind: z
2470
+ .enum(layoutKinds)
2471
+ .optional()
2472
+ .default("tb_header_layout")
2473
+ .describe(supportsFooter
2474
+ ? "Source kind. Header and footer existing-layout evidence is supported."
2475
+ : "Source kind. This connected plugin proves header evidence only; update it to expose footer support."),
2476
+ dry_run: z
2477
+ .boolean()
2478
+ .optional()
2479
+ .default(true)
2480
+ .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2481
+ },
2482
+ annotations: { idempotentHint: true },
2483
+ _meta: { idempotent: "true" },
2484
+ }, async ({ source_id, source_kind }) => {
2485
+ const withRef = await wrapResponse(async () => {
2486
+ const body = {
2487
+ source_id,
2488
+ source_kind: source_kind ?? "tb_header_layout",
2489
+ };
2490
+ const result = await wp.requestEnveloped("/cross-env/source-export", {
2491
+ method: "POST",
2492
+ body,
2493
+ });
2494
+ return envelopeMap(result, (data) => ({
2495
+ ...data,
2496
+ source_payload_ref: createSourcePayloadRef(data),
2497
+ _meta: {
2498
+ ...(typeof data._meta === "object" &&
2499
+ data._meta !== null
2500
+ ? (data._meta ?? {})
2501
+ : {}),
2502
+ source_payload_ref: "server-local artifact handle for the Pro cross-env layout apply tools; stores the same source payload under .diviops-tmp/cross-env-source-payloads and is bounded by handle + checksum + TTL",
2503
+ },
2504
+ }));
2505
+ });
2506
+ return {
2507
+ content: [
2508
+ {
2509
+ type: "text",
2510
+ text: serializeEnvelope(withRef, "diviops_cross_env_source_export_get"),
2511
+ },
2512
+ ],
2513
+ };
2514
+ });
2515
+ }
2468
2516
  registerPluginTool("diviops_tb_layout_update", {
2469
2517
  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'." +
2470
2518
  DRY_RUN_DESC_SUFFIX,
@@ -2480,6 +2528,9 @@ registerPluginTool("diviops_tb_layout_update", {
2480
2528
  const backupGate = backupCapabilityError("diviops_tb_layout_update", backup);
2481
2529
  if (backupGate)
2482
2530
  return backupGate;
2531
+ const isolationGate = writerIsolationErrorResult("diviops_tb_layout_update", { content });
2532
+ if (isolationGate)
2533
+ return isolationGate;
2483
2534
  const body = { content };
2484
2535
  if (dry_run)
2485
2536
  body.dry_run = true;
@@ -2523,6 +2574,9 @@ registerPluginTool("diviops_tb_layout_block_insert", {
2523
2574
  const backupGate = backupCapabilityError("diviops_tb_layout_block_insert", backup);
2524
2575
  if (backupGate)
2525
2576
  return backupGate;
2577
+ const isolationGate = writerIsolationErrorResult("diviops_tb_layout_block_insert", { content });
2578
+ if (isolationGate)
2579
+ return isolationGate;
2526
2580
  const body = {
2527
2581
  content,
2528
2582
  position: position ?? "append",
@@ -2568,6 +2622,9 @@ registerPluginTool("diviops_tb_template_create", {
2568
2622
  annotations: { idempotentHint: false },
2569
2623
  _meta: { idempotent: "false" },
2570
2624
  }, async ({ title, condition, header_content, footer_content, dry_run }) => {
2625
+ const isolationGate = writerIsolationErrorResult("diviops_tb_template_create", { header_content, footer_content });
2626
+ if (isolationGate)
2627
+ return isolationGate;
2571
2628
  const body = { title, condition, header_content, footer_content };
2572
2629
  if (dry_run)
2573
2630
  body.dry_run = true;
@@ -2643,6 +2700,11 @@ registerPluginTool("diviops_canvas_create", {
2643
2700
  annotations: { idempotentHint: false },
2644
2701
  _meta: { idempotent: "conditional" },
2645
2702
  }, async ({ title, parent_page_id, content, canvas_id, append_to_main, z_index, dry_run, }) => {
2703
+ const isolationGate = writerIsolationErrorResult("diviops_canvas_create", {
2704
+ content: content ?? "",
2705
+ });
2706
+ if (isolationGate)
2707
+ return isolationGate;
2646
2708
  const body = {
2647
2709
  title,
2648
2710
  parent_page_id,
@@ -2785,6 +2847,11 @@ registerPluginTool("diviops_canvas_update", {
2785
2847
  annotations: { idempotentHint: false },
2786
2848
  _meta: { idempotent: "conditional" },
2787
2849
  }, async ({ canvas_post_id, content, title, append_to_main, z_index, dry_run }) => {
2850
+ const isolationGate = writerIsolationErrorResult("diviops_canvas_update", {
2851
+ content,
2852
+ });
2853
+ if (isolationGate)
2854
+ return isolationGate;
2788
2855
  const body = {};
2789
2856
  if (content !== undefined)
2790
2857
  body.content = content;
@@ -3921,11 +3988,12 @@ const CrossEnvSourcePayloadSchema = z
3921
3988
  .object({
3922
3989
  origin: z.string().describe("Source site origin, e.g. https://source.example."),
3923
3990
  object_kind: z
3924
- .enum(["tb_header_layout"])
3925
- .describe("Source object kind. MVP supports tb_header_layout only."),
3991
+ .enum(["tb_header_layout", "tb_footer_layout"])
3992
+ .describe("Source object kind. Existing header and footer layouts are supported."),
3926
3993
  object_id: z.union([z.number(), z.string()]).optional(),
3927
3994
  object_title: z.string().optional(),
3928
- markup: z.string().describe("Sanitized source header layout block markup."),
3995
+ object_post_type: z.enum(["et_header_layout", "et_footer_layout"]).optional(),
3996
+ markup: z.string().describe("Sanitized source Theme Builder layout block markup."),
3929
3997
  checksum: z
3930
3998
  .string()
3931
3999
  .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
@@ -3937,6 +4005,9 @@ const CrossEnvSourcePayloadSchema = z
3937
4005
  .describe("Referenced attrs.modulePreset IDs from source export; definitions are not included."),
3938
4006
  })
3939
4007
  .passthrough();
4008
+ const CrossEnvHeaderSourcePayloadSchema = CrossEnvSourcePayloadSchema.extend({
4009
+ object_kind: z.literal("tb_header_layout"),
4010
+ });
3940
4011
  const CrossEnvSourcePayloadRefSchema = z
3941
4012
  .object({
3942
4013
  handle: z
@@ -3972,12 +4043,118 @@ function sourceHintsFromPayload(source) {
3972
4043
  ...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
3973
4044
  };
3974
4045
  }
4046
+ const ManagedRecoveryPolicySchema = z
4047
+ .object({
4048
+ version: z.literal(1),
4049
+ enabled: z.boolean(),
4050
+ max_age_days: z.number().int().min(1).max(365),
4051
+ max_snapshots_per_target: z.number().int().min(1).max(100),
4052
+ max_site_snapshots: z.number().int().min(1).max(1000),
4053
+ max_site_bytes: z.number().int().min(1048576).max(536870912),
4054
+ preserve_newest_viable_per_target: z.literal(true),
4055
+ protected_snapshot_ids: z
4056
+ .array(z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{2,127}$/))
4057
+ .max(50),
4058
+ audit_retention_days: z.number().int().min(30).max(2555),
4059
+ })
4060
+ .strict();
4061
+ const ManagedRecoveryRequestIdSchema = z
4062
+ .string()
4063
+ .regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{2,127}$/)
4064
+ .describe("Caller-stable request ID used for confirmation binding and exact replay/conflict detection.");
4065
+ const ManagedRecoveryConfirmationSchema = {
4066
+ confirmation_fingerprint: z
4067
+ .string()
4068
+ .regex(/^sha256:[a-f0-9]{64}$/)
4069
+ .describe("Exact fingerprint returned by the matching preview operation."),
4070
+ confirmation_token: z
4071
+ .string()
4072
+ .min(32)
4073
+ .describe("Short-lived signed token returned by the matching preview operation."),
4074
+ };
3975
4075
  function registerProTools() {
4076
+ registerProTool("diviops_managed_recovery_policy_get", {
4077
+ description: "Inspect the effective/default one-site managed recovery policy and complete metadata-only rollback snapshot inventory (Pro Phase 1A; managed_recovery module). Returns policy checksum/version, inventory checksum/count/bytes, corruption/readiness warnings, and the entitlement-independent Free recovery-data promise. Never returns snapshot payload content, raw historical post-meta, credentials, or confirmation material and never mutates state.",
4078
+ inputSchema: {},
4079
+ annotations: { idempotentHint: true },
4080
+ _meta: { idempotent: "true" },
4081
+ }, async () => {
4082
+ const result = await wp.requestEnveloped("/pro/managed-recovery/policy");
4083
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_policy_get") }] };
4084
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_policy_v1" });
4085
+ registerProTool("diviops_managed_recovery_policy_preview", {
4086
+ description: "Pure-read preview of a complete managed-recovery-policy-v1 proposal (Pro Phase 1A). Validates hard limits, canonicalizes types/ID ordering, recomputes complete inventory, returns deterministic keep/prune/refuse effects with stable reasons and exact byte/count deltas, and issues a maximum-15-minute actor/site/policy/inventory/body-bound confirmation for policy_update. Preview writes no policy, snapshot, cache, or audit state.",
4087
+ inputSchema: {
4088
+ request_id: ManagedRecoveryRequestIdSchema,
4089
+ policy: ManagedRecoveryPolicySchema,
4090
+ },
4091
+ annotations: { idempotentHint: true },
4092
+ _meta: { idempotent: "true" },
4093
+ }, async ({ request_id, policy }) => {
4094
+ const result = await wp.requestEnveloped("/pro/managed-recovery/policy/preview", { method: "POST", body: { request_id, policy } });
4095
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_policy_preview") }] };
4096
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_policy_v1" });
4097
+ registerProTool("diviops_managed_recovery_policy_update", {
4098
+ description: "Apply exactly the one-site managed recovery policy reviewed by policy_preview (Pro Phase 1A). Recomputes current policy and complete inventory, verifies the short-lived actor/site/body/policy/inventory binding, rechecks manage_options immediately before mutation, stores the versioned policy with autoload=no, verifies readback, and appends metadata-only immutable audit evidence. It never prunes snapshots. Exact request replay returns the prior redacted result; conflicting request_id reuse refuses. " +
4099
+ DRY_RUN_DESC_SUFFIX,
4100
+ inputSchema: {
4101
+ request_id: ManagedRecoveryRequestIdSchema,
4102
+ policy: ManagedRecoveryPolicySchema,
4103
+ ...ManagedRecoveryConfirmationSchema,
4104
+ dry_run: DRY_RUN_FIELD,
4105
+ },
4106
+ annotations: { idempotentHint: true },
4107
+ _meta: { idempotent: "conditional" },
4108
+ }, async ({ request_id, policy, confirmation_fingerprint, confirmation_token, dry_run }) => {
4109
+ const body = { request_id, policy, confirmation_fingerprint, confirmation_token };
4110
+ if (dry_run)
4111
+ body.dry_run = true;
4112
+ const result = await wp.requestEnveloped("/pro/managed-recovery/policy/update", { method: "POST", body });
4113
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_policy_update") }] };
4114
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_policy_v1" });
4115
+ registerProTool("diviops_managed_recovery_retention_preview", {
4116
+ description: "Pure-read deterministic retention plan for the active one-site managed recovery policy (Pro Phase 1A). Requires complete non-truncated Free-owned inventory; preserves explicit protections and the newest viable recovery point per target; returns ordered keep/prune/refuse rows, stable reasons, exact IDs and byte/count deltas, and a short-lived retention-only confirmation. Snapshot expiry is advisory evidence, and preview performs zero writes.",
4117
+ inputSchema: { request_id: ManagedRecoveryRequestIdSchema },
4118
+ annotations: { idempotentHint: true },
4119
+ _meta: { idempotent: "true" },
4120
+ }, async ({ request_id }) => {
4121
+ const result = await wp.requestEnveloped("/pro/managed-recovery/retention/preview", { method: "POST", body: { request_id } });
4122
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_retention_preview") }] };
4123
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_retention_v1" });
4124
+ registerProTool("diviops_managed_recovery_retention_apply", {
4125
+ description: "Delete only the exact ordered snapshot IDs reviewed by retention_preview (Pro Phase 1A). Rechecks manage_options, policy, complete inventory, protections, viability, signature, actor/site/body binding, and plan before the first delete, then delegates exact-ID deletion to Free/core. Stops on first failure and reports exact deleted/failed/unattempted byte/count evidence without claiming transaction rollback. Exact request replay is non-mutating; conflicting reuse refuses. " +
4126
+ DRY_RUN_DESC_SUFFIX,
4127
+ inputSchema: {
4128
+ request_id: ManagedRecoveryRequestIdSchema,
4129
+ ...ManagedRecoveryConfirmationSchema,
4130
+ dry_run: DRY_RUN_FIELD,
4131
+ },
4132
+ annotations: { idempotentHint: true },
4133
+ _meta: { idempotent: "conditional" },
4134
+ }, async ({ request_id, confirmation_fingerprint, confirmation_token, dry_run }) => {
4135
+ const body = { request_id, confirmation_fingerprint, confirmation_token };
4136
+ if (dry_run)
4137
+ body.dry_run = true;
4138
+ const result = await wp.requestEnveloped("/pro/managed-recovery/retention/apply", { method: "POST", body });
4139
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_retention_apply") }] };
4140
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_retention_v1" });
4141
+ registerProTool("diviops_managed_recovery_audit_list", {
4142
+ description: "List immutable checksummed metadata-only managed recovery policy/prune audit events (Pro Phase 1A), newest first with bounded pagination. Corrupt events are reported as redacted corruption evidence. Never returns snapshot payload/content, raw post-meta, credentials, signing material, confirmation tokens, or unnecessary URLs/logins.",
4143
+ inputSchema: {
4144
+ page: z.number().int().min(1).max(1000).optional().default(1),
4145
+ per_page: z.number().int().min(1).max(100).optional().default(20),
4146
+ },
4147
+ annotations: { idempotentHint: true },
4148
+ _meta: { idempotent: "true" },
4149
+ }, async ({ page, per_page }) => {
4150
+ const result = await wp.requestEnveloped("/pro/managed-recovery/audit", { params: { page: String(page), per_page: String(per_page) } });
4151
+ return { content: [{ type: "text", text: serializeEnvelope(result, "diviops_managed_recovery_audit_list") }] };
4152
+ }, { target: "managed_recovery", capabilityKey: "managed_recovery_audit_v1" });
3976
4153
  // diviops_cross_env_header_apply — guarded Pro apply for reviewed header preflight
3977
4154
  registerProTool("diviops_cross_env_header_apply", {
3978
4155
  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`, either an inline source export payload or a bounded `source_payload_ref` returned by diviops_cross_env_source_export_get, an existing target `destination_id`, and the reviewed `confirmation_binding.fingerprint` from `diviops-cross-env-preflight`. Large real headers should use `source_payload_ref`; inline `source_payload` remains supported for small/disposable tests. The server loads referenced payload bytes from its own `.diviops-tmp/cross-env-source-payloads/` artifact store, verifies checksum, 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, missing target module preset definitions, 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, preset import/clone, 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.source_payload_ref_invalid, 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.",
3979
4156
  inputSchema: {
3980
- source_payload: CrossEnvSourcePayloadSchema.optional().describe("The `data` object returned by diviops_cross_env_source_export_get on the source site. Use source_payload_ref instead for large real headers."),
4157
+ source_payload: CrossEnvHeaderSourcePayloadSchema.optional().describe("The `data` object returned by diviops_cross_env_source_export_get on the source site. Use source_payload_ref instead for large real headers."),
3981
4158
  source_payload_ref: CrossEnvSourcePayloadRefSchema.optional().describe("Bounded server-local artifact reference returned as data.source_payload_ref by diviops_cross_env_source_export_get. Preferred for large real headers because it avoids inlining full markup through the model."),
3982
4159
  destination_id: z
3983
4160
  .number()
@@ -4016,12 +4193,16 @@ function registerProTools() {
4016
4193
  }
4017
4194
  else {
4018
4195
  try {
4019
- resolvedSourcePayload = loadSourcePayloadRef(source_payload_ref);
4196
+ resolvedSourcePayload = loadSourcePayloadRef(source_payload_ref, "tb_header_layout");
4020
4197
  }
4021
4198
  catch (err) {
4022
4199
  withCode("cross_env.source_payload_ref_invalid", err instanceof Error ? err.message : String(err), "Re-run diviops_cross_env_source_export_get and pass the fresh data.source_payload_ref.", { source_payload_ref });
4023
4200
  }
4024
4201
  }
4202
+ const isolationHits = scanValueForForeignVarRefs(resolvedSourcePayload.markup, "source_payload.markup");
4203
+ if (isolationHits.length > 0) {
4204
+ return isolationFailure("diviops_cross_env_header_apply", isolationHits);
4205
+ }
4025
4206
  const targetBody = {
4026
4207
  destination_id,
4027
4208
  destination_kind: destination_kind ?? "tb_header_layout",
@@ -4072,6 +4253,110 @@ function registerProTools() {
4072
4253
  ],
4073
4254
  };
4074
4255
  }, { target: "cross_env", capabilityKey: "cross_env_header_apply" });
4256
+ registerProTool("diviops_cross_env_layout_apply", {
4257
+ description: "Apply one reviewed Theme Builder header or footer payload to one existing same-kind target layout (Pro tier; cross_env module). Requires fresh Free source/target evidence, the generic versioned confirmation fingerprint, and confirm_apply: true. Independently refuses kind/post-type mismatch, checksum or template-linkage drift, unsafe dependency evidence, off-canvas wiring, foreign CSS variables, invalid serialization, and readback mismatch before claiming success. A converged target returns already_converged without a write or cache mutation; successful mutation returns rollout_applied with readback, checksums, rollback, supported-meta, and cache evidence. Never creates layouts, mutates template assignment, or reconciles dependencies.",
4258
+ inputSchema: {
4259
+ source_payload: CrossEnvSourcePayloadSchema.optional().describe("Free source export payload. Use source_payload_ref for large layouts."),
4260
+ source_payload_ref: CrossEnvSourcePayloadRefSchema.optional().describe("Bounded server-local artifact reference from diviops_cross_env_source_export_get."),
4261
+ destination_id: z.number().int().positive().describe("Existing target Theme Builder layout post ID."),
4262
+ destination_kind: z
4263
+ .enum(["tb_header_layout", "tb_footer_layout"])
4264
+ .describe("Exact target kind; must match source_payload.object_kind."),
4265
+ reviewed_fingerprint: z
4266
+ .string()
4267
+ .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
4268
+ .describe("Reviewed generic confirmation_binding fingerprint."),
4269
+ confirm_apply: z.boolean().describe("Must be true. Missing/false refuses before any target mutation."),
4270
+ },
4271
+ annotations: { idempotentHint: false },
4272
+ _meta: { idempotent: "conditional" },
4273
+ }, async ({ source_payload, source_payload_ref, destination_id, destination_kind, reviewed_fingerprint, confirm_apply, }) => {
4274
+ const result = await wrapResponse(async () => {
4275
+ if (confirm_apply !== true) {
4276
+ withCode("cross_env.confirmation_required", "confirm_apply: true is required before a Theme Builder layout rollout can mutate content.", "Review the generic preflight report, then retry with confirm_apply: true.");
4277
+ }
4278
+ if (source_payload && source_payload_ref) {
4279
+ withCode("invalid_input", "Provide either source_payload or source_payload_ref, not both.", "Use source_payload_ref for large layouts and inline source_payload only for small fixtures.", { fields: ["source_payload", "source_payload_ref"] });
4280
+ }
4281
+ if (!source_payload && !source_payload_ref) {
4282
+ withCode("invalid_input", "Either source_payload or source_payload_ref is required.", "Run diviops_cross_env_source_export_get and pass its fresh payload or reference.", { fields: ["source_payload", "source_payload_ref"] });
4283
+ }
4284
+ let resolvedSourcePayload;
4285
+ if (source_payload) {
4286
+ resolvedSourcePayload = source_payload;
4287
+ }
4288
+ else {
4289
+ try {
4290
+ resolvedSourcePayload = loadSourcePayloadRef(source_payload_ref, destination_kind);
4291
+ }
4292
+ catch (err) {
4293
+ withCode("cross_env.source_payload_ref_invalid", err instanceof Error ? err.message : String(err), "Re-run diviops_cross_env_source_export_get and pass the fresh source_payload_ref.", { source_payload_ref });
4294
+ }
4295
+ }
4296
+ if (resolvedSourcePayload.object_kind !== destination_kind) {
4297
+ withCode("cross_env.layout_kind_mismatch", "Source and target Theme Builder layout kinds must match.", "Export and target the same header or footer kind.", {
4298
+ source_kind: resolvedSourcePayload.object_kind,
4299
+ destination_kind,
4300
+ });
4301
+ }
4302
+ const isolationHits = scanValueForForeignVarRefs(resolvedSourcePayload.markup, "source_payload.markup");
4303
+ if (isolationHits.length > 0) {
4304
+ return isolationFailure("diviops_cross_env_layout_apply", isolationHits);
4305
+ }
4306
+ const targetEnvelope = await wp.requestEnveloped("/cross-env/target-context", {
4307
+ method: "POST",
4308
+ body: {
4309
+ destination_id,
4310
+ destination_kind,
4311
+ ...sourceHintsFromPayload(resolvedSourcePayload),
4312
+ },
4313
+ });
4314
+ if (!targetEnvelope.ok)
4315
+ return targetEnvelope;
4316
+ const report = preflightCrossEnvThemeBuilderLayoutSync({
4317
+ source: resolvedSourcePayload,
4318
+ target: targetEnvelope.data,
4319
+ });
4320
+ const reviewed = normalizeReviewedFingerprint(reviewed_fingerprint);
4321
+ if (report.confirmation_binding.fingerprint !== reviewed) {
4322
+ withCode("cross_env.fingerprint_mismatch", "Reviewed confirmation fingerprint does not match the recomputed current generic preflight report.", "Re-run preflight against the latest target context and confirm the new generic fingerprint.", {
4323
+ reviewed_fingerprint: reviewed,
4324
+ recomputed_fingerprint: report.confirmation_binding.fingerprint,
4325
+ current_destination_checksum: report.target.destination_checksum ?? null,
4326
+ current_template_linkage_digest: report.target.template_linkage_digest ?? null,
4327
+ });
4328
+ }
4329
+ if (report.verdict !== "safe_dry_run") {
4330
+ withCode("cross_env.preflight_not_safe", "Recomputed generic preflight verdict is not safe for layout rollout.", "Resolve blockers/operator actions, then re-run and re-confirm preflight.", {
4331
+ verdict: report.verdict,
4332
+ blockers: report.blockers,
4333
+ operator_actions: report.operator_actions,
4334
+ });
4335
+ }
4336
+ return wp.requestEnveloped("/pro/cross-env/theme-builder/layout/apply", {
4337
+ method: "POST",
4338
+ body: {
4339
+ confirm_apply: true,
4340
+ destination_id,
4341
+ destination_kind,
4342
+ source_payload: resolvedSourcePayload,
4343
+ source_checksum: resolvedSourcePayload.checksum,
4344
+ destination_checksum: report.target.destination_checksum,
4345
+ template_linkage_digest: report.target.template_linkage_digest,
4346
+ reviewed_fingerprint: reviewed,
4347
+ preflight_report: report,
4348
+ },
4349
+ });
4350
+ });
4351
+ return {
4352
+ content: [
4353
+ {
4354
+ type: "text",
4355
+ text: serializeEnvelope(result, "diviops_cross_env_layout_apply"),
4356
+ },
4357
+ ],
4358
+ };
4359
+ }, { target: "cross_env", capabilityKey: "cross_env_layout_apply" });
4075
4360
  // diviops_fc_product_list — bridges /diviops/v1/pro/fluentcart/products
4076
4361
  registerProTool("diviops_fc_product_list", {
4077
4362
  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.",
@@ -4561,22 +4846,7 @@ function registerProTools() {
4561
4846
  handshakeState.kind === "ok" &&
4562
4847
  !handshakeState.capabilities["fluentcart_license_update_file_set"]) {
4563
4848
  const err = new MissingCapabilityError("fluentcart_license_update_file_set", handshakeState.pluginVersion);
4564
- const failure = {
4565
- ok: false,
4566
- error: {
4567
- code: ErrorCodes.CAPABILITY_MISSING,
4568
- message: err.message,
4569
- hint: "Update the diviops-agent-pro WP plugin to a version that supports authoring the global_update_file pointer, or omit global_update_file from this call.",
4570
- },
4571
- };
4572
- return {
4573
- content: [
4574
- {
4575
- type: "text",
4576
- text: serializeEnvelope(failure, "diviops_fc_license_settings_update"),
4577
- },
4578
- ],
4579
- };
4849
+ return missingCapabilityEnvelope(err, "diviops_fc_license_settings_update", "Update the diviops-agent-pro WP plugin to a version that supports authoring the global_update_file pointer, or omit global_update_file from this call.");
4580
4850
  }
4581
4851
  const body = {};
4582
4852
  if (enabled !== undefined)
@@ -5220,6 +5490,10 @@ async function main() {
5220
5490
  handshakeState = { kind: "failed" };
5221
5491
  console.error(`Handshake warning (gate disabled): ${msg}`);
5222
5492
  }
5493
+ // The cross-env evidence schema is additive-capability aware: older Free
5494
+ // plugins retain the existing header-only enum, while current plugins prove
5495
+ // footer support through cross_env_footer_layout_evidence.
5496
+ registerCrossEnvEvidenceTools();
5223
5497
  // Pro coverage-slice registration must run AFTER the handshake so the
5224
5498
  // gates (`pro_active`, `available_targets`, `active_modules`,
5225
5499
  // capability map) reflect the connected site's actual state. On Free