@diviops/mcp-server 1.5.35 → 1.5.37

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 CHANGED
@@ -112,7 +112,8 @@ Additional **conditionally-registered Pro tools** appear only on sites that have
112
112
  | FluentCart order readback + guarded mark-paid (V3.1) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_order_list`, `diviops_fc_order_get`, `diviops_fc_order_mark_paid` |
113
113
  | FluentCart license readback (V3.1) | Pro plugin + FluentCart Pro installed + module enabled | `diviops_fc_license_list`, `diviops_fc_license_get`, `diviops_fc_license_activations_list` |
114
114
  | FluentCart checkout readiness / gateway inspection (V3.2) | Pro plugin + FluentCart installed + module enabled | `diviops_fc_status`, `diviops_fc_gateway_list`, `diviops_fc_gateway_get` |
115
- | Cross-env guarded apply | Pro plugin + `cross_env` module enabled | `diviops_cross_env_header_apply` |
115
+ | Cross-env reviewed layout rollout | Pro plugin + `cross_env` module enabled | `diviops_cross_env_header_apply`, `diviops_cross_env_layout_apply` |
116
+ | Managed recovery Phase 1A | Pro plugin + opt-in `managed_recovery` module enabled | `diviops_managed_recovery_policy_get`, `diviops_managed_recovery_policy_preview`, `diviops_managed_recovery_policy_update`, `diviops_managed_recovery_retention_preview`, `diviops_managed_recovery_retention_apply`, `diviops_managed_recovery_audit_list` |
116
117
 
117
118
  When the gates are not satisfied, the tools simply don't appear on the MCP surface — no error envelope, no missing-capability hint. See the `diviops-fluentcart` skill bundle for the operator-side guide.
118
119
 
@@ -172,8 +173,13 @@ diviops-cross-env-preflight --source source.json --target target.json --dry-run
172
173
 
173
174
  This command reads two secret-free JSON files and prints a report. It does not
174
175
  connect to WordPress, does not accept credentials, and has no write/apply path.
175
- The MVP supports `tb_header_layout` source payloads preflighted against an
176
- existing `tb_header_layout` target context. It reports source-domain upload URL
176
+ The CLI supports `tb_header_layout` and `tb_footer_layout` source payloads
177
+ preflighted against existing same-kind targets. Header-only inputs retain the
178
+ shipped header-v1 report/fingerprint; footer inputs use the generic layout-v1
179
+ binding by default. Pass `--contract layout-v1` to emit the generic binding for
180
+ a header rollout through `diviops_cross_env_layout_apply`; `--contract
181
+ header-v1` explicitly selects the compatibility contract and accepts header
182
+ inputs only. It reports source-domain upload URL
177
183
  rewrites, attachment remap status, `gcid-*` target resolution including Divi
178
184
  built-in customizer colors, resolved target global-color value evidence,
179
185
  referenced `modulePreset` target-presence status, off-canvas/canvas refusal, and
@@ -183,8 +189,14 @@ target identity/current target checksum, rewrite plan, cache plan,
183
189
  blocker/operator-action codes, reference-resolution summaries, target module
184
190
  preset resolution, and the per-`gcid` value evidence for target colors
185
191
  referenced by the source layout.
186
- The fingerprint is reviewed-plan evidence for the Pro-gated
187
- `diviops_cross_env_header_apply` tool. The CLI itself still has no apply path.
192
+ The fingerprint is reviewed-plan evidence for the Pro-gated compatibility
193
+ `diviops_cross_env_header_apply` or generic `diviops_cross_env_layout_apply`
194
+ tool. The CLI itself still has no apply path.
195
+
196
+ The Free plugin advertises `cross_env_footer_layout_evidence` when its source
197
+ export and target-context routes support footer kinds. The server selects those
198
+ two tools' public enums only after handshake: older or unproven plugins retain
199
+ the shipped header-only schemas instead of advertising unsupported footer input.
188
200
 
189
201
  To collect the source JSON from the source WordPress site, call the Free/core
190
202
  read-only MCP tool `diviops_cross_env_source_export_get` and save the returned
@@ -198,8 +210,8 @@ filesystem paths.
198
210
 
199
211
  The MCP server also writes the same source payload to a bounded local artifact
200
212
  under `.diviops-tmp/cross-env-source-payloads/` and returns
201
- `data.source_payload_ref`. Use that reference for large real headers when
202
- calling the Pro `diviops_cross_env_header_apply` tool; it avoids asking an LLM
213
+ `data.source_payload_ref`. Use that reference for large real layouts when
214
+ calling a Pro layout apply tool; it avoids asking an LLM
203
215
  to re-emit large markup byte-for-byte. The reference is a server-created handle
204
216
  plus checksum, not an arbitrary filesystem path.
205
217
 
@@ -218,6 +230,11 @@ entries that are referenced by source markup.
218
230
  It also includes target D5 module preset IDs, without preset definitions, so the
219
231
  preflight can fail closed when source markup references a module preset the
220
232
  target site does not have.
233
+ For header/footer generic preflight it also includes exact target post type and
234
+ a canonical template-linkage digest over the active Theme Builder master ID,
235
+ its exact `_et_template` order, and linked-template slot, enabled, condition,
236
+ and exclusion evidence. Empty linkage uses `master_template_ids: []` and
237
+ `links: []`; assignment state is evidence only and is never mutated by rollout.
221
238
 
222
239
  Workflow:
223
240
 
@@ -225,12 +242,15 @@ Workflow:
225
242
  returned `data` object as `source.json`.
226
243
  2. Call `diviops_cross_env_target_context_get` on the target site and save the
227
244
  returned `data` object as `target.json`.
228
- 3. Run `diviops-cross-env-preflight --source source.json --target target.json --dry-run`.
245
+ 3. Run `diviops-cross-env-preflight --source source.json --target target.json --dry-run --contract layout-v1`
246
+ for `diviops_cross_env_layout_apply`. Omit the contract flag (or select
247
+ `header-v1`) only for the compatibility header apply tool.
229
248
 
230
249
  `--apply` is intentionally refused. To mutate a target, use the separate
231
- Pro-gated `diviops_cross_env_header_apply` tool with the reviewed fingerprint
232
- and either inline `source_payload` for small/disposable tests or
233
- `source_payload_ref` for large real headers. That MVP still refuses media
250
+ Pro-gated `diviops_cross_env_layout_apply` tool with the generic reviewed
251
+ fingerprint and either inline `source_payload` for small/disposable tests or
252
+ `source_payload_ref` for large layouts. The existing header tool remains the
253
+ header-v1 compatibility path. Both refuse media
234
254
  upload/import, global color creation/import, off-canvas reconcile, and new
235
255
  target layout creation.
236
256
 
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { preflightCrossEnvHeaderSync, } from "./header-preflight.js";
3
+ import { preflightCrossEnvThemeBuilderLayoutSync } from "./layout-preflight.js";
3
4
  export const EXIT = {
4
5
  OK: 0,
5
6
  INVALID_INPUT: 1,
@@ -7,16 +8,20 @@ export const EXIT = {
7
8
  const HELP = `diviops-cross-env-preflight — dry-run cross-environment layout safety reports
8
9
 
9
10
  USAGE
10
- diviops-cross-env-preflight --source source.json --target target.json --dry-run
11
+ diviops-cross-env-preflight --source source.json --target target.json --dry-run [--contract <auto|header-v1|layout-v1>]
11
12
 
12
13
  OPTIONS
13
- --source <path> Secret-free source layout payload JSON.
14
- --target <path> Secret-free target context JSON.
15
- --dry-run Required/default. Produce a report only; no WordPress writes.
16
- --apply Refused. No write/apply path exists in this MVP.
17
- --help Show this help.
14
+ --source <path> Secret-free source layout payload JSON.
15
+ --target <path> Secret-free target context JSON.
16
+ --contract <version> auto (default), header-v1, or layout-v1. Use layout-v1
17
+ for diviops_cross_env_layout_apply, including headers.
18
+ --dry-run Required/default. Produce a report only; no WordPress writes.
19
+ --apply Refused. No write/apply path exists in this MVP.
20
+ --help Show this help.
18
21
 
19
- The MVP supports tb_header_layout -> tb_header_layout preflight only.`;
22
+ Supported kinds are tb_header_layout and tb_footer_layout. Existing header-only
23
+ inputs retain the shipped header-v1 report and fingerprint contract unless
24
+ --contract layout-v1 is explicitly selected.`;
20
25
  function parseArgs(argv) {
21
26
  const parsed = { help: false };
22
27
  for (let i = 0; i < argv.length; i++) {
@@ -30,7 +35,7 @@ function parseArgs(argv) {
30
35
  if (token === "--apply") {
31
36
  throw new Error("--apply is not supported; this MVP is preflight-only.");
32
37
  }
33
- if (token === "--source" || token === "--target") {
38
+ if (token === "--source" || token === "--target" || token === "--contract") {
34
39
  const value = argv[i + 1];
35
40
  if (value === undefined || value.startsWith("--")) {
36
41
  throw new Error(`${token} requires a value.`);
@@ -39,6 +44,12 @@ function parseArgs(argv) {
39
44
  parsed.source = value;
40
45
  if (token === "--target")
41
46
  parsed.target = value;
47
+ if (token === "--contract") {
48
+ if (!["auto", "header-v1", "layout-v1"].includes(value)) {
49
+ throw new Error("--contract must be auto, header-v1, or layout-v1.");
50
+ }
51
+ parsed.contract = value;
52
+ }
42
53
  i++;
43
54
  continue;
44
55
  }
@@ -69,7 +80,15 @@ export async function runCli(argv, io) {
69
80
  source: readJsonFile(parsed.source),
70
81
  target: readJsonFile(parsed.target),
71
82
  };
72
- const report = preflightCrossEnvHeaderSync(input);
83
+ const contract = parsed.contract ?? "auto";
84
+ const headerPair = input.source.object_kind === "tb_header_layout" &&
85
+ input.target.destination_kind === "tb_header_layout";
86
+ if (contract === "header-v1" && !headerPair) {
87
+ throw new Error("--contract header-v1 requires tb_header_layout source and target inputs.");
88
+ }
89
+ const report = contract === "layout-v1" || (contract === "auto" && !headerPair)
90
+ ? preflightCrossEnvThemeBuilderLayoutSync(input)
91
+ : preflightCrossEnvHeaderSync(input);
73
92
  io.out(JSON.stringify(report, null, 2));
74
93
  return EXIT.OK;
75
94
  }
@@ -12,6 +12,7 @@ export interface SourceLayoutPayload {
12
12
  object_kind: CrossEnvObjectKind | string;
13
13
  object_id?: number | string;
14
14
  object_title?: string;
15
+ object_post_type?: string;
15
16
  markup: string;
16
17
  checksum?: string;
17
18
  attachments?: SourceAttachmentInventoryItem[];
@@ -37,7 +38,10 @@ export interface TargetLayoutContext {
37
38
  destination_kind: CrossEnvObjectKind | string;
38
39
  destination_id?: number | string;
39
40
  destination_title?: string;
41
+ destination_post_type?: string;
40
42
  destination_checksum?: string | Sha256Checksum;
43
+ template_linkage?: unknown;
44
+ template_linkage_digest?: Sha256Checksum;
41
45
  attachment_remaps?: Record<string, unknown>;
42
46
  attachments?: TargetAttachmentInventoryItem[];
43
47
  global_colors?: unknown;
@@ -0,0 +1,3 @@
1
+ export declare const CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY: "cross_env_footer_layout_evidence";
2
+ export type CrossEnvEvidenceLayoutKind = "tb_header_layout" | "tb_footer_layout";
3
+ export declare function crossEnvEvidenceLayoutKinds(capabilities: Record<string, boolean>): ["tb_header_layout"] | ["tb_header_layout", "tb_footer_layout"];
@@ -0,0 +1,6 @@
1
+ export const CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY = "cross_env_footer_layout_evidence";
2
+ export function crossEnvEvidenceLayoutKinds(capabilities) {
3
+ return capabilities[CROSS_ENV_FOOTER_LAYOUT_EVIDENCE_CAPABILITY] === true
4
+ ? ["tb_header_layout", "tb_footer_layout"]
5
+ : ["tb_header_layout"];
6
+ }
@@ -0,0 +1,89 @@
1
+ import { type CrossEnvVerdict, type GcidReference, type ModulePresetReference, type OffCanvasReference, type PreflightIssue, type Sha256Checksum, type SourceLayoutPayload, type TargetLayoutContext, type AttachmentReference, type UrlOccurrence } from "./header-preflight.js";
2
+ export declare const THEME_BUILDER_LAYOUT_KIND_POST_TYPES: {
3
+ readonly tb_header_layout: "et_header_layout";
4
+ readonly tb_footer_layout: "et_footer_layout";
5
+ };
6
+ export type CrossEnvThemeBuilderLayoutKind = keyof typeof THEME_BUILDER_LAYOUT_KIND_POST_TYPES;
7
+ export declare const THEME_BUILDER_LAYOUT_VALIDATOR_VERSION: "diviops.cross_env.theme_builder_layout.validator.v1";
8
+ export interface CrossEnvThemeBuilderLayoutPreflightInput {
9
+ source: SourceLayoutPayload;
10
+ target: TargetLayoutContext;
11
+ }
12
+ export interface CrossEnvThemeBuilderLayoutPreflightReport {
13
+ type: "cross_env_theme_builder_layout_preflight";
14
+ dry_run: true;
15
+ verdict: CrossEnvVerdict;
16
+ validator_contract: {
17
+ version: typeof THEME_BUILDER_LAYOUT_VALIDATOR_VERSION;
18
+ serialization: "wordpress_divi_full_content.v1";
19
+ };
20
+ source: {
21
+ origin: string;
22
+ object_kind: string;
23
+ object_id?: number | string;
24
+ object_title?: string;
25
+ object_post_type?: string;
26
+ checksum: {
27
+ algorithm: "sha256";
28
+ provided?: string;
29
+ computed: string;
30
+ matches: boolean | null;
31
+ };
32
+ };
33
+ target: {
34
+ origin: string;
35
+ destination_kind: string;
36
+ destination_id?: number | string;
37
+ destination_title?: string;
38
+ destination_post_type?: string;
39
+ cache_scope?: string;
40
+ destination_checksum?: Sha256Checksum;
41
+ template_linkage?: unknown;
42
+ template_linkage_digest?: Sha256Checksum;
43
+ };
44
+ findings: {
45
+ urls: {
46
+ by_host: Record<string, string[]>;
47
+ occurrences: UrlOccurrence[];
48
+ };
49
+ attachments: AttachmentReference[];
50
+ global_colors: GcidReference[];
51
+ module_presets: ModulePresetReference[];
52
+ off_canvas: OffCanvasReference[];
53
+ };
54
+ source_origin_rule: {
55
+ normalized_origin: string;
56
+ rewrite_scope: "same_origin_wp_uploads_only";
57
+ };
58
+ rewrite_plan: {
59
+ url_rewrites: Array<{
60
+ from: string;
61
+ to: string;
62
+ }>;
63
+ attachment_replacements: Array<{
64
+ from_source_id: number;
65
+ to_target_id: number;
66
+ proof?: string;
67
+ }>;
68
+ third_party_urls_kept: string[];
69
+ missing_attachment_remaps: number[];
70
+ };
71
+ cache_plan: {
72
+ scope: string;
73
+ steps: Array<{
74
+ kind: string;
75
+ target: string;
76
+ note: string;
77
+ }>;
78
+ };
79
+ blockers: PreflightIssue[];
80
+ operator_actions: PreflightIssue[];
81
+ notes: string[];
82
+ confirmation_binding: {
83
+ schema: "diviops.cross_env.theme_builder_layout_preflight.confirmation_binding.v1";
84
+ algorithm: "sha256";
85
+ fingerprint: string;
86
+ input: Record<string, unknown>;
87
+ };
88
+ }
89
+ export declare function preflightCrossEnvThemeBuilderLayoutSync(input: CrossEnvThemeBuilderLayoutPreflightInput): CrossEnvThemeBuilderLayoutPreflightReport;
@@ -0,0 +1,202 @@
1
+ import { createHash } from "node:crypto";
2
+ import { preflightCrossEnvHeaderSync, } from "./header-preflight.js";
3
+ export const THEME_BUILDER_LAYOUT_KIND_POST_TYPES = {
4
+ tb_header_layout: "et_header_layout",
5
+ tb_footer_layout: "et_footer_layout",
6
+ };
7
+ export const THEME_BUILDER_LAYOUT_VALIDATOR_VERSION = "diviops.cross_env.theme_builder_layout.validator.v1";
8
+ function sha256(value) {
9
+ return createHash("sha256").update(value).digest("hex");
10
+ }
11
+ function canonicalize(value) {
12
+ if (Array.isArray(value))
13
+ return value.map(canonicalize);
14
+ if (!value || typeof value !== "object")
15
+ return value;
16
+ return Object.fromEntries(Object.entries(value)
17
+ .filter(([, nested]) => nested !== undefined)
18
+ .sort(([a], [b]) => a.localeCompare(b))
19
+ .map(([key, nested]) => [key, canonicalize(nested)]));
20
+ }
21
+ function canonicalJson(value) {
22
+ return JSON.stringify(canonicalize(value));
23
+ }
24
+ function isSha256Digest(value) {
25
+ if (!value || typeof value !== "object")
26
+ return false;
27
+ const record = value;
28
+ return (record.algorithm === "sha256" &&
29
+ typeof record.computed === "string" &&
30
+ /^[a-f0-9]{64}$/i.test(record.computed));
31
+ }
32
+ function stableIssues(issues) {
33
+ return issues
34
+ .map((issue) => ({ code: issue.code, detail: issue.detail ?? null }))
35
+ .sort((a, b) => canonicalJson(a).localeCompare(canonicalJson(b)));
36
+ }
37
+ function expectedPostType(kind) {
38
+ return THEME_BUILDER_LAYOUT_KIND_POST_TYPES[kind];
39
+ }
40
+ function replaceCacheDestinationKind(target, kind) {
41
+ return target.replace(/^tb_header_layout(?=#|$)/, kind);
42
+ }
43
+ export function preflightCrossEnvThemeBuilderLayoutSync(input) {
44
+ // The shipped header-v1 engine remains the immutable compatibility analyzer.
45
+ // The generic contract reuses its hazard inventory while owning a distinct
46
+ // report and fingerprint namespace.
47
+ const base = preflightCrossEnvHeaderSync({
48
+ source: { ...input.source, object_kind: "tb_header_layout" },
49
+ target: { ...input.target, destination_kind: "tb_header_layout" },
50
+ });
51
+ const blockers = [...base.blockers];
52
+ const operatorActions = [...base.operator_actions];
53
+ const sourceKind = String(input.source.object_kind ?? "");
54
+ const targetKind = String(input.target.destination_kind ?? "");
55
+ const sourceExpectedType = expectedPostType(sourceKind);
56
+ const targetExpectedType = expectedPostType(targetKind);
57
+ if (!sourceExpectedType) {
58
+ blockers.push({
59
+ code: "unsupported_source_kind",
60
+ message: "Only tb_header_layout and tb_footer_layout sources are supported.",
61
+ detail: { received: sourceKind },
62
+ });
63
+ }
64
+ if (!targetExpectedType) {
65
+ blockers.push({
66
+ code: "unsupported_destination_kind",
67
+ message: "Only tb_header_layout and tb_footer_layout destinations are supported.",
68
+ detail: { received: targetKind },
69
+ });
70
+ }
71
+ if (sourceExpectedType && targetExpectedType && sourceKind !== targetKind) {
72
+ blockers.push({
73
+ code: "layout_kind_mismatch",
74
+ message: "Source and target Theme Builder layout kinds must match.",
75
+ detail: { source_kind: sourceKind, destination_kind: targetKind },
76
+ });
77
+ }
78
+ if (sourceExpectedType && input.source.object_post_type !== sourceExpectedType) {
79
+ blockers.push({
80
+ code: "source_post_type_mismatch",
81
+ message: "Source post type does not match its declared layout kind.",
82
+ detail: {
83
+ kind: sourceKind,
84
+ expected: sourceExpectedType,
85
+ actual: input.source.object_post_type ?? null,
86
+ },
87
+ });
88
+ }
89
+ if (targetExpectedType && input.target.destination_post_type !== targetExpectedType) {
90
+ blockers.push({
91
+ code: "destination_post_type_mismatch",
92
+ message: "Target post type does not match its declared layout kind.",
93
+ detail: {
94
+ kind: targetKind,
95
+ expected: targetExpectedType,
96
+ actual: input.target.destination_post_type ?? null,
97
+ },
98
+ });
99
+ }
100
+ if (!isSha256Digest(input.target.template_linkage_digest)) {
101
+ operatorActions.push({
102
+ code: "missing_template_linkage_digest",
103
+ message: "Provide the canonical target template-linkage digest before apply confirmation.",
104
+ });
105
+ }
106
+ const cachePlan = {
107
+ ...base.cache_plan,
108
+ steps: base.cache_plan.steps.map((step) => ({
109
+ ...step,
110
+ target: replaceCacheDestinationKind(step.target, targetKind),
111
+ })),
112
+ };
113
+ const sourceOriginRule = {
114
+ normalized_origin: base.source.origin,
115
+ rewrite_scope: "same_origin_wp_uploads_only",
116
+ };
117
+ const validatorContract = {
118
+ version: THEME_BUILDER_LAYOUT_VALIDATOR_VERSION,
119
+ serialization: "wordpress_divi_full_content.v1",
120
+ };
121
+ const verdict = blockers.length > 0
122
+ ? "refused"
123
+ : operatorActions.length > 0
124
+ ? "operator_action_required"
125
+ : "safe_dry_run";
126
+ const reportWithoutBinding = {
127
+ type: "cross_env_theme_builder_layout_preflight",
128
+ dry_run: true,
129
+ verdict,
130
+ validator_contract: validatorContract,
131
+ source: {
132
+ ...base.source,
133
+ object_kind: sourceKind,
134
+ object_post_type: input.source.object_post_type,
135
+ },
136
+ target: {
137
+ ...base.target,
138
+ destination_kind: targetKind,
139
+ destination_post_type: input.target.destination_post_type,
140
+ template_linkage: input.target.template_linkage,
141
+ template_linkage_digest: input.target.template_linkage_digest,
142
+ },
143
+ findings: base.findings,
144
+ source_origin_rule: sourceOriginRule,
145
+ rewrite_plan: base.rewrite_plan,
146
+ cache_plan: cachePlan,
147
+ blockers,
148
+ operator_actions: operatorActions,
149
+ notes: [
150
+ "Preflight only: Free/core evidence and CLI do not mutate WordPress.",
151
+ "The generic binding is distinct from the shipped header-v1 fingerprint.",
152
+ "Template linkage is drift evidence only and never authorizes assignment mutation.",
153
+ ],
154
+ };
155
+ const bindingInput = {
156
+ source: {
157
+ origin: reportWithoutBinding.source.origin,
158
+ object_kind: sourceKind,
159
+ object_id: reportWithoutBinding.source.object_id,
160
+ object_post_type: input.source.object_post_type,
161
+ checksum: {
162
+ algorithm: "sha256",
163
+ computed: reportWithoutBinding.source.checksum.computed,
164
+ },
165
+ },
166
+ target: {
167
+ origin: reportWithoutBinding.target.origin,
168
+ destination_kind: targetKind,
169
+ destination_id: reportWithoutBinding.target.destination_id,
170
+ destination_post_type: input.target.destination_post_type,
171
+ destination_checksum: reportWithoutBinding.target.destination_checksum ?? null,
172
+ template_linkage_digest: input.target.template_linkage_digest ?? null,
173
+ cache_scope: reportWithoutBinding.target.cache_scope ?? null,
174
+ },
175
+ source_origin_rule: sourceOriginRule,
176
+ rewrite_plan: reportWithoutBinding.rewrite_plan,
177
+ cache_plan: cachePlan,
178
+ dependency_evidence: {
179
+ attachment_remap_proof: reportWithoutBinding.findings.attachments,
180
+ global_color_resolution: reportWithoutBinding.findings.global_colors,
181
+ module_preset_resolution: reportWithoutBinding.findings.module_presets,
182
+ off_canvas: {
183
+ refused: reportWithoutBinding.findings.off_canvas.length > 0,
184
+ refs: reportWithoutBinding.findings.off_canvas,
185
+ },
186
+ },
187
+ blockers: stableIssues(blockers),
188
+ operator_actions: stableIssues(operatorActions),
189
+ validator_contract: validatorContract,
190
+ };
191
+ const schema = "diviops.cross_env.theme_builder_layout_preflight.confirmation_binding.v1";
192
+ const canonicalInput = canonicalize(bindingInput);
193
+ return {
194
+ ...reportWithoutBinding,
195
+ confirmation_binding: {
196
+ schema,
197
+ algorithm: "sha256",
198
+ fingerprint: sha256(canonicalJson({ schema, input: canonicalInput })),
199
+ input: canonicalInput,
200
+ },
201
+ };
202
+ }
@@ -17,4 +17,4 @@ export interface SourcePayloadRefEnvelope {
17
17
  };
18
18
  }
19
19
  export declare function createSourcePayloadRef(payload: SourceLayoutPayload): SourcePayloadRef;
20
- export declare function loadSourcePayloadRef(ref: unknown): SourceLayoutPayload;
20
+ export declare function loadSourcePayloadRef(ref: unknown, expectedKind?: string): SourceLayoutPayload;
@@ -106,7 +106,7 @@ export function createSourcePayloadRef(payload) {
106
106
  ...(expiresAt ? { expires_at: expiresAt } : {}),
107
107
  };
108
108
  }
109
- export function loadSourcePayloadRef(ref) {
109
+ export function loadSourcePayloadRef(ref, expectedKind) {
110
110
  if (!ref || typeof ref !== "object" || Array.isArray(ref)) {
111
111
  throw new Error("source_payload_ref must be an object.");
112
112
  }
@@ -174,5 +174,8 @@ export function loadSourcePayloadRef(ref) {
174
174
  if (computed !== expected) {
175
175
  throw new Error("source_payload_ref checksum does not match artifact markup.");
176
176
  }
177
+ if (expectedKind !== undefined && payload.object_kind !== expectedKind) {
178
+ throw new Error(`source_payload_ref kind does not match destination kind (${String(payload.object_kind)} != ${expectedKind}).`);
179
+ }
177
180
  return { ...payload, checksum: computed };
178
181
  }
package/dist/index.js CHANGED
@@ -16,6 +16,8 @@ import { MissingCapabilityError, proToolGatesSatisfied, } from "./compatibility.
16
16
  import { missingCapabilityEnvelope, } from "./capability-envelope.js";
17
17
  import { ErrorCodes, envelopeMap, recordIdempotent, serializeEnvelope, withCode, wrapResponse, } from "./envelope.js";
18
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";
19
21
  import { createSourcePayloadRef, loadSourcePayloadRef, } from "./cross-env-preflight/source-payload-ref.js";
20
22
  import { optimizeSchema } from "./schema-optimizer.js";
21
23
  import { schemaModuleRoute } from "./schema-route.js";
@@ -200,12 +202,16 @@ function buildPluginVersionSummary() {
200
202
  function buildMetaInfo() {
201
203
  const fluentCartCapabilityKeys = enabledCapabilityKeys("fluentcart_");
202
204
  const crossEnvCapabilityKeys = enabledCapabilityKeys("cross_env_");
205
+ const managedRecoveryCapabilityKeys = enabledCapabilityKeys("managed_recovery_");
203
206
  const fluentCartTarget = handshakeState.kind === "ok"
204
207
  ? handshakeState.availableTargets.fluentcart ?? null
205
208
  : null;
206
209
  const crossEnvTarget = handshakeState.kind === "ok"
207
210
  ? handshakeState.availableTargets.cross_env ?? null
208
211
  : null;
212
+ const managedRecoveryTarget = handshakeState.kind === "ok"
213
+ ? handshakeState.availableTargets.managed_recovery ?? null
214
+ : null;
209
215
  const fluentCartActive = handshakeState.kind === "ok" &&
210
216
  handshakeState.proActive === true &&
211
217
  fluentCartTarget?.present === true &&
@@ -216,11 +222,18 @@ function buildMetaInfo() {
216
222
  crossEnvTarget?.present === true &&
217
223
  handshakeState.activeModules.cross_env === true &&
218
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;
219
230
  const capabilities = fluentCartActive
220
231
  ? [...BASE_META_CAPABILITIES, "fluentcart"]
221
232
  : [...BASE_META_CAPABILITIES];
222
233
  if (crossEnvActive)
223
234
  capabilities.push("cross_env");
235
+ if (managedRecoveryActive)
236
+ capabilities.push("managed_recovery");
224
237
  const tools = buildToolCatalogSummary();
225
238
  return {
226
239
  brand: "DiviOps",
@@ -265,6 +278,14 @@ function buildMetaInfo() {
265
278
  : false,
266
279
  tool_capabilities: crossEnvCapabilityKeys,
267
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
+ },
268
289
  },
269
290
  wp_cli: wpCli ? wpCli.getAllowedCommands() : false,
270
291
  };
@@ -2377,111 +2398,121 @@ registerPluginTool("diviops_tb_layout_get", {
2377
2398
  ],
2378
2399
  };
2379
2400
  });
2380
- registerPluginTool("diviops_cross_env_target_context_get", {
2381
- 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.",
2382
- inputSchema: {
2383
- destination_id: z
2384
- .number()
2385
- .int()
2386
- .positive()
2387
- .describe("Existing target Theme Builder header layout post ID."),
2388
- destination_kind: z
2389
- .enum(["tb_header_layout"])
2390
- .optional()
2391
- .default("tb_header_layout")
2392
- .describe("Destination kind. Only tb_header_layout is supported in this read-only slice."),
2393
- source_asset_hints: z
2394
- .array(z.string())
2395
- .optional()
2396
- .describe("Optional source upload paths, asset URLs, or basenames used to search target media candidates. Query strings, fragments, and credentials are stripped from output."),
2397
- source_attachment_ids: z
2398
- .array(z.number())
2399
- .optional()
2400
- .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."),
2401
- dry_run: z
2402
- .boolean()
2403
- .optional()
2404
- .default(true)
2405
- .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2406
- },
2407
- annotations: { idempotentHint: true },
2408
- _meta: { idempotent: "true" },
2409
- }, async ({ destination_id, destination_kind, source_asset_hints, source_attachment_ids, }) => {
2410
- const body = {
2411
- destination_id,
2412
- destination_kind: destination_kind ?? "tb_header_layout",
2413
- };
2414
- if (source_asset_hints && source_asset_hints.length > 0) {
2415
- body.source_asset_hints = source_asset_hints;
2416
- }
2417
- if (source_attachment_ids && source_attachment_ids.length > 0) {
2418
- body.source_attachment_ids = source_attachment_ids;
2419
- }
2420
- const result = await wp.requestEnveloped("/cross-env/target-context", {
2421
- method: "POST",
2422
- body,
2423
- });
2424
- return {
2425
- content: [
2426
- {
2427
- type: "text",
2428
- text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
2429
- },
2430
- ],
2431
- };
2432
- });
2433
- registerPluginTool("diviops_cross_env_source_export_get", {
2434
- 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.",
2435
- inputSchema: {
2436
- source_id: z
2437
- .number()
2438
- .int()
2439
- .positive()
2440
- .describe("Existing source Theme Builder header layout post ID."),
2441
- source_kind: z
2442
- .enum(["tb_header_layout"])
2443
- .optional()
2444
- .default("tb_header_layout")
2445
- .describe("Source kind. Only tb_header_layout is supported in this read-only slice."),
2446
- dry_run: z
2447
- .boolean()
2448
- .optional()
2449
- .default(true)
2450
- .describe("Accepted for workflow symmetry; the tool is always read-only and never mutates state."),
2451
- },
2452
- annotations: { idempotentHint: true },
2453
- _meta: { idempotent: "true" },
2454
- }, async ({ source_id, source_kind }) => {
2455
- 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, }) => {
2456
2438
  const body = {
2457
- source_id,
2458
- source_kind: source_kind ?? "tb_header_layout",
2439
+ destination_id,
2440
+ destination_kind: destination_kind ?? "tb_header_layout",
2459
2441
  };
2460
- 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", {
2461
2449
  method: "POST",
2462
2450
  body,
2463
2451
  });
2464
- return envelopeMap(result, (data) => ({
2465
- ...data,
2466
- source_payload_ref: createSourcePayloadRef(data),
2467
- _meta: {
2468
- ...(typeof data._meta === "object" &&
2469
- data._meta !== null
2470
- ? (data._meta ?? {})
2471
- : {}),
2472
- 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",
2473
- },
2474
- }));
2452
+ return {
2453
+ content: [
2454
+ {
2455
+ type: "text",
2456
+ text: serializeEnvelope(result, "diviops_cross_env_target_context_get"),
2457
+ },
2458
+ ],
2459
+ };
2475
2460
  });
2476
- return {
2477
- content: [
2478
- {
2479
- type: "text",
2480
- text: serializeEnvelope(withRef, "diviops_cross_env_source_export_get"),
2481
- },
2482
- ],
2483
- };
2484
- });
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
+ }
2485
2516
  registerPluginTool("diviops_tb_layout_update", {
2486
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'." +
2487
2518
  DRY_RUN_DESC_SUFFIX,
@@ -3957,11 +3988,12 @@ const CrossEnvSourcePayloadSchema = z
3957
3988
  .object({
3958
3989
  origin: z.string().describe("Source site origin, e.g. https://source.example."),
3959
3990
  object_kind: z
3960
- .enum(["tb_header_layout"])
3961
- .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."),
3962
3993
  object_id: z.union([z.number(), z.string()]).optional(),
3963
3994
  object_title: z.string().optional(),
3964
- 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."),
3965
3997
  checksum: z
3966
3998
  .string()
3967
3999
  .regex(/^(sha256:)?[a-fA-F0-9]{64}$/)
@@ -3973,6 +4005,9 @@ const CrossEnvSourcePayloadSchema = z
3973
4005
  .describe("Referenced attrs.modulePreset IDs from source export; definitions are not included."),
3974
4006
  })
3975
4007
  .passthrough();
4008
+ const CrossEnvHeaderSourcePayloadSchema = CrossEnvSourcePayloadSchema.extend({
4009
+ object_kind: z.literal("tb_header_layout"),
4010
+ });
3976
4011
  const CrossEnvSourcePayloadRefSchema = z
3977
4012
  .object({
3978
4013
  handle: z
@@ -4008,12 +4043,118 @@ function sourceHintsFromPayload(source) {
4008
4043
  ...(ids.size > 0 ? { source_attachment_ids: [...ids].sort((a, b) => a - b) } : {}),
4009
4044
  };
4010
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
+ };
4011
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" });
4012
4153
  // diviops_cross_env_header_apply — guarded Pro apply for reviewed header preflight
4013
4154
  registerProTool("diviops_cross_env_header_apply", {
4014
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.",
4015
4156
  inputSchema: {
4016
- 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."),
4017
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."),
4018
4159
  destination_id: z
4019
4160
  .number()
@@ -4052,7 +4193,7 @@ function registerProTools() {
4052
4193
  }
4053
4194
  else {
4054
4195
  try {
4055
- resolvedSourcePayload = loadSourcePayloadRef(source_payload_ref);
4196
+ resolvedSourcePayload = loadSourcePayloadRef(source_payload_ref, "tb_header_layout");
4056
4197
  }
4057
4198
  catch (err) {
4058
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 });
@@ -4112,6 +4253,110 @@ function registerProTools() {
4112
4253
  ],
4113
4254
  };
4114
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" });
4115
4360
  // diviops_fc_product_list — bridges /diviops/v1/pro/fluentcart/products
4116
4361
  registerProTool("diviops_fc_product_list", {
4117
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.",
@@ -5245,6 +5490,10 @@ async function main() {
5245
5490
  handshakeState = { kind: "failed" };
5246
5491
  console.error(`Handshake warning (gate disabled): ${msg}`);
5247
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();
5248
5497
  // Pro coverage-slice registration must run AFTER the handshake so the
5249
5498
  // gates (`pro_active`, `available_targets`, `active_modules`,
5250
5499
  // capability map) reflect the connected site's actual state. On Free
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diviops/mcp-server",
3
- "version": "1.5.35",
3
+ "version": "1.5.37",
4
4
  "description": "MCP server exposing Divi 5 Visual Builder as tools for Claude",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",