@apexops/cli 0.10.0-next.1 → 0.10.0-next.2

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.
Files changed (29) hide show
  1. package/assets/client-projections/github-copilot-cli/.github/agents/apex-architect.agent.md +26 -16
  2. package/assets/client-projections/github-copilot-cli/.github/agents/apex-operator.agent.md +7 -3
  3. package/assets/client-projections/github-copilot-cli/.github/agents/apex-planner.agent.md +13 -8
  4. package/assets/client-projections/github-copilot-cli/.github/agents/apex-requirements.agent.md +32 -22
  5. package/assets/client-projections/github-copilot-cli/.github/agents/apex.agent.md +15 -6
  6. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-architect.agent.md +26 -16
  7. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-codegen.agent.md +6 -3
  8. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-operator.agent.md +7 -3
  9. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-planner.agent.md +13 -8
  10. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-requirements.agent.md +32 -22
  11. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-reviewer.agent.md +16 -7
  12. package/assets/client-projections/github-copilot-vscode/.github/agents/apex-validator.agent.md +11 -5
  13. package/assets/client-projections/github-copilot-vscode/.github/agents/apex.agent.md +15 -6
  14. package/assets/config/runtime-bundle.v1.json +7 -7
  15. package/assets/customizations/.github/agents/apex-architect.agent.md +26 -16
  16. package/assets/customizations/.github/agents/apex-codegen.agent.md +6 -3
  17. package/assets/customizations/.github/agents/apex-operator.agent.md +7 -3
  18. package/assets/customizations/.github/agents/apex-planner.agent.md +13 -8
  19. package/assets/customizations/.github/agents/apex-requirements.agent.md +32 -22
  20. package/assets/customizations/.github/agents/apex-reviewer.agent.md +16 -7
  21. package/assets/customizations/.github/agents/apex-validator.agent.md +11 -5
  22. package/assets/customizations/.github/agents/apex.agent.md +15 -6
  23. package/assets/customizations/manifest.json +1 -1
  24. package/assets/manifest.json +61 -61
  25. package/dist/service.d.ts +22 -0
  26. package/dist/service.js +278 -0
  27. package/dist/version.d.ts +1 -1
  28. package/dist/version.js +1 -1
  29. package/package.json +5 -5
package/dist/service.js CHANGED
@@ -1078,6 +1078,42 @@ export class ApexService {
1078
1078
  }),
1079
1079
  legacy,
1080
1080
  });
1081
+ if (descriptor.id === "requirements" && renderedDocument !== undefined) {
1082
+ await this.materializeRequirementsReviewPackage(run, requirementsOutput.value, renderedDocument.outputHash, events);
1083
+ }
1084
+ if (descriptor.id === "requirements-review") {
1085
+ await this.materializeRequirementsChallengeFindings(run, outputs[0].value);
1086
+ }
1087
+ if (descriptor.id === "architecture") {
1088
+ const architectureOutput = outputs.find(({ kind }) => kind === "architecture");
1089
+ const costOutput = outputs.find(({ kind }) => kind === "cost-estimate");
1090
+ const decisionsOutput = outputs.find(({ kind }) => kind === "workload-decision-manifest");
1091
+ if (architectureOutput === undefined || costOutput === undefined || decisionsOutput === undefined) {
1092
+ throw new ApexError("APEX_INTERNAL", "Architecture review package is missing an accepted output", EXIT_CODES.internal);
1093
+ }
1094
+ await this.materializeArchitectureReviewPackage(run, architectureOutput.value, costOutput.value, decisionsOutput.value, outputHashes);
1095
+ }
1096
+ if (descriptor.id === "architecture-review") {
1097
+ await this.materializeArchitectureChallengeFindings(run, outputs[0].value);
1098
+ }
1099
+ if (descriptor.id === "plan") {
1100
+ const intentOutput = outputs.find(({ kind }) => kind === "implementation-intent");
1101
+ const bindingOutput = outputs.find(({ kind }) => kind === "iac-binding");
1102
+ const inputsOutput = outputs.find(({ kind }) => kind === "environment-inputs");
1103
+ if (intentOutput === undefined || bindingOutput === undefined || inputsOutput === undefined) {
1104
+ throw new ApexError("APEX_INTERNAL", "Planner review package is missing an accepted output", EXIT_CODES.internal);
1105
+ }
1106
+ await this.materializePlanReviewPackage(run, intentOutput.value, bindingOutput.value, inputsOutput.value, outputHashes);
1107
+ }
1108
+ if (descriptor.id === "plan-review") {
1109
+ await this.materializePlanChallengeFindings(run, outputs[0].value);
1110
+ }
1111
+ if (descriptor.reviewSubject !== undefined) {
1112
+ await this.materializeReviewerSummary(run, descriptor.reviewSubject, outputs[0].value);
1113
+ }
1114
+ if (descriptor.id === "validation-bicep" || descriptor.id === "validation-terraform") {
1115
+ await this.materializeValidationReport(run, outputs[0].value, descriptor.id);
1116
+ }
1081
1117
  if (descriptor.reviewSubject !== undefined) {
1082
1118
  if (reviewBlockers.length === 0 && descriptor.gate !== undefined) {
1083
1119
  await this.openRunGate(await this.currentRun(), descriptor.gate, dependencyHash);
@@ -1097,6 +1133,172 @@ export class ApexService {
1097
1133
  outputHash: await this.objects.putJson({ contentType: "text/markdown", content }),
1098
1134
  };
1099
1135
  }
1136
+ requirementsReviewDirectory(run) {
1137
+ return join(this.root, "agent-output", run.projectId, run.runId);
1138
+ }
1139
+ reviewMarkdownText(value) {
1140
+ return value.replaceAll("\\", "\\\\").replaceAll("|", "\\|").replaceAll("\r\n", "\n").replaceAll("\n", "<br>");
1141
+ }
1142
+ async materializeRequirementsReviewPackage(run, requirements, requirementsDocumentHash, events) {
1143
+ const directory = this.requirementsReviewDirectory(run);
1144
+ const document = await this.objects.getJson(requirementsDocumentHash);
1145
+ if (document.contentType !== "text/markdown") {
1146
+ throw new ApexError("APEX_INTERNAL", "Requirements review document is invalid", EXIT_CODES.internal);
1147
+ }
1148
+ const input = this.recordedRequirementsInput(events) ?? {};
1149
+ const text = (value) => {
1150
+ if (value === undefined)
1151
+ return "Deferred";
1152
+ if (typeof value === "string")
1153
+ return this.reviewMarkdownText(value);
1154
+ if (Array.isArray(value))
1155
+ return value.map((item) => this.reviewMarkdownText(item)).join(", ");
1156
+ if (value.kind === "budget")
1157
+ return `${value.amount} ${this.reviewMarkdownText(value.currency)} monthly`;
1158
+ if (value.kind === "recovery")
1159
+ return `RTO ${value.rtoMinutes} minutes; RPO ${value.rpoMinutes} minutes`;
1160
+ if (value.kind === "data-classification")
1161
+ return this.reviewMarkdownText(value.classification);
1162
+ if (value.kind === "compliance")
1163
+ return value.scopes.map((scope) => this.reviewMarkdownText(scope)).join(", ");
1164
+ return value.kind === "deferred" ? `Deferred to ${this.reviewMarkdownText(value.owner)}` : "Unknown";
1165
+ };
1166
+ const list = (value) => {
1167
+ if (!Array.isArray(value) || value.length === 0)
1168
+ return "- None recorded.";
1169
+ return value.map((item) => `- ${this.reviewMarkdownText(item)}`).join("\n");
1170
+ };
1171
+ await mkdir(directory, { recursive: true });
1172
+ await Promise.all([
1173
+ atomicWriteBytes(join(directory, "01-requirements.md"), Buffer.from(document.content, "utf8")),
1174
+ atomicWriteBytes(join(directory, "README.md"), Buffer.from(`# ${this.reviewMarkdownText(run.projectId)}\n\nGenerated Gate 1 review package for run \`${this.reviewMarkdownText(run.runId)}\`. The APEX kernel state remains authoritative.\n\n- Environment: ${this.reviewMarkdownText(run.environment)}\n- Business context: ${this.reviewMarkdownText(requirements.businessContext ?? "Deferred")}\n- Requirements document hash: ${requirementsDocumentHash}\n- Review status: challenger findings pending\n`, "utf8")),
1175
+ atomicWriteBytes(join(directory, "service-recommendations.md"), Buffer.from(`# Service Recommendations\n\nThese are user-reviewed candidate services, not Architecture decisions.\n\n## Candidate Services\n${list(input["service-preferences"])}\n\n## Recommendation Rationale\n${this.reviewMarkdownText(requirements.architectureHandoff ?? "Architecture must evaluate the candidate services against approved requirements and current evidence.")}\n\n## Constraints\n- Retained services: ${text(input["retained-services"])}\n- Prohibited services: ${text(input["prohibited-services"])}\n- Environment overrides: ${text(input["environment-overrides"])}\n\nArchitecture must validate candidates against approved requirements, governance, and current evidence.\n`, "utf8")),
1176
+ atomicWriteBytes(join(directory, "sku-preferences.md"), Buffer.from(`# SKU Preferences\n\nUser constraints only. Architecture owns SKU selection.\n\n- Preference: ${text(input["sku-preferences"])}\n- Budget posture: ${text(input.budget)}\n- Scale: ${text(input.scale)}\n`, "utf8")),
1177
+ atomicWriteBytes(join(directory, "challenger-findings.md"), Buffer.from("# Challenger Findings\n\nRequirements challenger review is pending. Gate 1 cannot be approved until the reviewer completes this document.\n", "utf8")),
1178
+ ]);
1179
+ }
1180
+ async materializeRequirementsChallengeFindings(run, review) {
1181
+ const findings = review.findings.length === 0
1182
+ ? "No challenger findings remain open."
1183
+ : review.findings
1184
+ .map(({ id, severity, title, detail, resolution }) => `## ${this.reviewMarkdownText(id)}: ${this.reviewMarkdownText(title)}\n\n- Severity: ${this.reviewMarkdownText(severity)}\n- Finding: ${this.reviewMarkdownText(detail)}${resolution === undefined ? "" : `\n- Resolution: ${this.reviewMarkdownText(resolution)}`}`)
1185
+ .join("\n\n");
1186
+ await atomicWriteBytes(join(this.requirementsReviewDirectory(run), "challenger-findings.md"), Buffer.from(`# Challenger Findings\n\n${findings}\n`, "utf8"));
1187
+ }
1188
+ architectureReviewDirectory(run) {
1189
+ return join(this.root, "agent-output", run.projectId, run.runId, "architecture");
1190
+ }
1191
+ async materializeArchitectureReviewPackage(run, architecture, cost, decisions, hashes) {
1192
+ const directory = this.architectureReviewDirectory(run);
1193
+ const list = (items) => items.length === 0 ? "- None." : items.map((item) => `- ${this.reviewMarkdownText(item)}`).join("\n");
1194
+ const table = (headers, rows) => [
1195
+ `| ${headers.join(" | ")} |`,
1196
+ `| ${headers.map(() => "---").join(" | ")} |`,
1197
+ ...rows.map((row) => `| ${row.join(" | ")} |`),
1198
+ ].join("\n");
1199
+ const costRows = cost.lineItems.map((item) => [
1200
+ this.reviewMarkdownText(item.service),
1201
+ this.reviewMarkdownText(item.sku),
1202
+ String(item.quantity),
1203
+ `${item.monthlyCost.toFixed(2)} ${this.reviewMarkdownText(cost.currency)}`,
1204
+ this.reviewMarkdownText(item.uncertainty.confidence),
1205
+ ]);
1206
+ const skuRows = decisions.skuDecisions.map((decision) => [
1207
+ this.reviewMarkdownText(decision.logicalId),
1208
+ this.reviewMarkdownText(decision.service),
1209
+ this.reviewMarkdownText(decision.sku),
1210
+ String(decision.quantity),
1211
+ this.reviewMarkdownText(decision.rationale),
1212
+ ]);
1213
+ await mkdir(directory, { recursive: true });
1214
+ await Promise.all([
1215
+ atomicWriteBytes(join(directory, "README.md"), Buffer.from(`# ${this.reviewMarkdownText(architecture.title)}\n\nGenerated Gate 2 review package for run \`${this.reviewMarkdownText(run.runId)}\`. The APEX kernel state remains authoritative.\n\n- Architecture hash: ${hashes.architecture}\n- Cost estimate hash: ${hashes["cost-estimate"]}\n- Decision manifest hash: ${hashes["workload-decision-manifest"]}\n- Review status: challenger findings pending\n`, "utf8")),
1216
+ atomicWriteBytes(join(directory, "architecture-assessment.md"), Buffer.from(`# Architecture Assessment\n\n## Summary\n\n${this.reviewMarkdownText(architecture.summary)}\n\n## Components\n\n${table(["ID", "Service", "Purpose", "Requirements"], architecture.components.map((component) => [
1217
+ this.reviewMarkdownText(component.id),
1218
+ this.reviewMarkdownText(component.service),
1219
+ this.reviewMarkdownText(component.purpose),
1220
+ component.requirementIds.map((id) => this.reviewMarkdownText(id)).join(", "),
1221
+ ]))}\n\n## Five WAF Pillars\n\n### Security\n\n${list(architecture.decisions)}\n\n### Reliability\n\n${list(decisions.sloDecisions.map((decision) => `${decision.logicalId}: ${decision.availabilityPercent}% availability, RTO ${decision.rtoMinutes}m, RPO ${decision.rpoMinutes}m`))}\n\n### Performance Efficiency\n\n- Review component capacity and scale decisions in the SKU comparison.\n\n### Cost Optimization\n\n- Review the current evidence-backed cost estimate.\n\n### Operational Excellence\n\n${list(architecture.risks)}\n\n## Alternatives And Trade-offs\n\nUser-confirmed decisions:\n${list(architecture.decisions)}\n\n## Risks\n\n${list(architecture.risks)}\n`, "utf8")),
1222
+ atomicWriteBytes(join(directory, "cost-estimate.md"), Buffer.from(`# Cost Estimate\n\n- Pricing date: ${this.reviewMarkdownText(cost.pricingDate)}\n- Monthly total: ${cost.totalMonthlyCost.toFixed(2)} ${this.reviewMarkdownText(cost.currency)}\n\n## Line Items\n\n${table(["Service", "SKU", "Quantity", "Monthly", "Confidence"], costRows)}\n\n## Evidence Appendix\n\n${cost.lineItems.map((item) => `- ${this.reviewMarkdownText(item.service)} / ${this.reviewMarkdownText(item.sku)}: ${this.reviewMarkdownText(item.source.provider)} — ${this.reviewMarkdownText(item.source.uri)} — retrieved ${this.reviewMarkdownText(item.source.retrievedAt)}; uncertainty ${this.reviewMarkdownText(item.uncertainty.basis)}`).join("\n")}\n\n## Assumptions\n\n${list(cost.assumptions)}\n`, "utf8")),
1223
+ atomicWriteBytes(join(directory, "sku-comparison.md"), Buffer.from(`# SKU Comparison\n\n${table(["Logical ID", "Service", "Selected SKU", "Quantity", "Rationale"], skuRows)}\n\nThese are user-confirmed Architecture decisions. Alternatives and rejected options must be recorded in the architecture assessment before Gate 2 approval.\n`, "utf8")),
1224
+ atomicWriteBytes(join(directory, "challenger-findings.md"), Buffer.from("# Challenger Findings\n\nArchitecture challenger review is pending. Gate 2 cannot be approved until the reviewer completes this document.\n", "utf8")),
1225
+ ]);
1226
+ }
1227
+ async materializeArchitectureChallengeFindings(run, review) {
1228
+ const findings = review.findings.length === 0
1229
+ ? "No challenger findings remain open."
1230
+ : review.findings
1231
+ .map(({ id, severity, title, detail, resolution }) => `## ${this.reviewMarkdownText(id)}: ${this.reviewMarkdownText(title)}\n\n- Severity: ${this.reviewMarkdownText(severity)}\n- Finding: ${this.reviewMarkdownText(detail)}${resolution === undefined ? "" : `\n- Resolution: ${this.reviewMarkdownText(resolution)}`}`)
1232
+ .join("\n\n");
1233
+ await atomicWriteBytes(join(this.architectureReviewDirectory(run), "challenger-findings.md"), Buffer.from(`# Challenger Findings\n\n${findings}\n`, "utf8"));
1234
+ }
1235
+ planReviewDirectory(run) {
1236
+ return join(this.root, "agent-output", run.projectId, run.runId, "plan");
1237
+ }
1238
+ async materializePlanReviewPackage(run, intent, binding, inputs, hashes) {
1239
+ const directory = this.planReviewDirectory(run);
1240
+ const table = (headers, rows) => [
1241
+ `| ${headers.join(" | ")} |`,
1242
+ `| ${headers.map(() => "---").join(" | ")} |`,
1243
+ ...rows.map((row) => `| ${row.join(" | ")} |`),
1244
+ ].join("\n");
1245
+ const resourceRows = intent.resources.map((resource) => [
1246
+ this.reviewMarkdownText(resource.id),
1247
+ this.reviewMarkdownText(resource.type),
1248
+ this.reviewMarkdownText(resource.purpose),
1249
+ resource.dependsOn.map((dependency) => this.reviewMarkdownText(dependency)).join(", "),
1250
+ resource.controls.map((control) => this.reviewMarkdownText(control)).join(", "),
1251
+ ]);
1252
+ const bindingRows = Object.entries(binding.resourceBindings).map(([id, value]) => [
1253
+ this.reviewMarkdownText(id),
1254
+ this.reviewMarkdownText(value.implementation),
1255
+ this.reviewMarkdownText(value.version),
1256
+ this.reviewMarkdownText(JSON.stringify(value.parameters)),
1257
+ ]);
1258
+ const inputRows = Object.entries(inputs.inputs).map(([name, value]) => [
1259
+ this.reviewMarkdownText(name),
1260
+ value.kind === "value" ? "value" : "secret-reference",
1261
+ this.reviewMarkdownText(value.kind === "value" ? String(value.value) : `${value.provider}:${value.reference}`),
1262
+ ]);
1263
+ await mkdir(directory, { recursive: true });
1264
+ await Promise.all([
1265
+ atomicWriteBytes(join(directory, "README.md"), Buffer.from(`# Implementation Plan\n\nGenerated Gate 3 review package for run \`${this.reviewMarkdownText(run.runId)}\`. The APEX kernel state remains authoritative.\n\n- Intent hash: ${hashes["implementation-intent"]}\n- Binding hash: ${hashes["iac-binding"]}\n- Environment input hash: ${hashes["environment-inputs"]}\n- Review status: challenger findings pending\n`, "utf8")),
1266
+ atomicWriteBytes(join(directory, "implementation-plan.md"), Buffer.from(`# Implementation Plan\n\n## Logical Resources\n\n${table(["ID", "Type", "Purpose", "Depends On", "Controls"], resourceRows)}\n\n## Outputs\n\n${intent.outputs.map((output) => `- ${this.reviewMarkdownText(output)}`).join("\n")}\n\n## Source Artifacts\n\n${Object.entries(intent.sourceHashes)
1267
+ .map(([kind, hash]) => `- ${this.reviewMarkdownText(kind)}: ${hash}`)
1268
+ .join("\n")}\n`, "utf8")),
1269
+ atomicWriteBytes(join(directory, "iac-binding.md"), Buffer.from(`# IaC Binding\n\n- Track: ${this.reviewMarkdownText(binding.track)}\n- Intent hash: ${binding.intentHash}\n\n${table(["Logical ID", "Implementation", "Version", "Parameters"], bindingRows)}\n`, "utf8")),
1270
+ atomicWriteBytes(join(directory, "environment-inputs.md"), Buffer.from(`# Environment Inputs\n\n- Environment: ${this.reviewMarkdownText(inputs.environment)}\n\n${table(["Name", "Kind", "Reference or Value"], inputRows)}\n`, "utf8")),
1271
+ atomicWriteBytes(join(directory, "challenger-findings.md"), Buffer.from("# Challenger Findings\n\nImplementation-plan challenger review is pending. Gate 3 cannot be approved until the reviewer completes this document.\n", "utf8")),
1272
+ ]);
1273
+ }
1274
+ async materializePlanChallengeFindings(run, review) {
1275
+ const findings = review.findings.length === 0
1276
+ ? "No challenger findings remain open."
1277
+ : review.findings
1278
+ .map(({ id, severity, title, detail, resolution }) => `## ${this.reviewMarkdownText(id)}: ${this.reviewMarkdownText(title)}\n\n- Severity: ${this.reviewMarkdownText(severity)}\n- Finding: ${this.reviewMarkdownText(detail)}${resolution === undefined ? "" : `\n- Resolution: ${this.reviewMarkdownText(resolution)}`}`)
1279
+ .join("\n\n");
1280
+ await atomicWriteBytes(join(this.planReviewDirectory(run), "challenger-findings.md"), Buffer.from(`# Challenger Findings\n\n${findings}\n`, "utf8"));
1281
+ }
1282
+ async materializeReviewerSummary(run, subject, review) {
1283
+ const findings = review.findings.length === 0
1284
+ ? "No findings remain open."
1285
+ : review.findings
1286
+ .map(({ id, severity, disposition, title, detail, evidenceRefs, resolution }) => `## ${this.reviewMarkdownText(id)}: ${this.reviewMarkdownText(title)}\n\n- Severity: ${this.reviewMarkdownText(severity)}\n- Disposition: ${this.reviewMarkdownText(disposition)}\n- Finding: ${this.reviewMarkdownText(detail)}\n- Evidence: ${evidenceRefs.map((reference) => this.reviewMarkdownText(reference)).join(", ") || "None"}${resolution === undefined ? "" : `\n- Resolution: ${this.reviewMarkdownText(resolution)}`}`)
1287
+ .join("\n\n");
1288
+ const directory = join(this.root, "agent-output", run.projectId, run.runId, "reviews");
1289
+ await mkdir(directory, { recursive: true });
1290
+ await atomicWriteBytes(join(directory, `${subject}-findings.md`), Buffer.from(`# ${this.reviewMarkdownText(subject)} Challenger Findings\n\n- Reviewed artifact kind: ${this.reviewMarkdownText(review.subjectKind)}\n- Review subject hash: ${review.subjectHash}\n- Reviewed at: ${this.reviewMarkdownText(review.reviewedAt)}\n\n${findings}\n`, "utf8"));
1291
+ }
1292
+ async materializeValidationReport(run, evidence, taskType) {
1293
+ const directory = join(this.root, "agent-output", run.projectId, run.runId, "validation");
1294
+ const entries = evidence.entries.length === 0
1295
+ ? "- No validation evidence entries were produced."
1296
+ : evidence.entries
1297
+ .map(({ kind, hash, bytes, required, retention }) => `- ${this.reviewMarkdownText(kind)}: ${hash} (${bytes} bytes; ${required ? "required" : "optional"}; ${this.reviewMarkdownText(retention)})`)
1298
+ .join("\n");
1299
+ await mkdir(directory, { recursive: true });
1300
+ await atomicWriteBytes(join(directory, "validation-report.md"), Buffer.from(`# Validation Report\n\n- Task: ${this.reviewMarkdownText(taskType)}\n- Track: ${this.reviewMarkdownText(run.iacTool)}\n- Created: ${this.reviewMarkdownText(evidence.createdAt)}\n- Verdict: accepted deterministic validation evidence\n\n## Validator Evidence\n\n${entries}\n\nThe Validator reports evidence only. Artifact repair, risk acceptance, and gate decisions remain with their authorized owners.\n`, "utf8"));
1301
+ }
1100
1302
  async requirementsDocumentMarkdown(value, artifactHash) {
1101
1303
  if (!Value.Check(RequirementsV1Schema, value)) {
1102
1304
  throw new ApexError("APEX_INTERNAL", "Requirements document source is invalid", EXIT_CODES.internal);
@@ -1272,6 +1474,8 @@ export class ApexService {
1272
1474
  ...(previewHash === undefined ? {} : { previewHash }),
1273
1475
  ...(validatorIds.length === 0 ? {} : { validatorIds }),
1274
1476
  }, gateNumber === 4 ? (events.at(-1)?.hash ?? null) : undefined);
1477
+ if (gateNumber === 4)
1478
+ await this.materializeOperationsApprovalPackage(run, approval, approvalHash);
1275
1479
  return approval;
1276
1480
  }
1277
1481
  async preview(options) {
@@ -1343,6 +1547,7 @@ export class ApexService {
1343
1547
  ...(validation.omittedValidatorIds.length === 0 ? {} : { omittedValidatorIds: validation.omittedValidatorIds }),
1344
1548
  ...(attestationHash === undefined ? {} : { attestationHash }),
1345
1549
  });
1550
+ await this.materializeOperationsPreviewPackage(run, preview, previewObjectHash);
1346
1551
  await this.openRunGate(await this.currentRun(), 4, preview.previewHash);
1347
1552
  return preview;
1348
1553
  }
@@ -1390,9 +1595,64 @@ export class ApexService {
1390
1595
  evidenceMode: validation.evidenceMode,
1391
1596
  ...(validation.omittedValidatorIds.length === 0 ? {} : { omittedValidatorIds: validation.omittedValidatorIds }),
1392
1597
  });
1598
+ await this.materializeOperationsPreviewPackage(run, preview, previewObjectHash);
1393
1599
  await this.openRunGate(await this.currentRun(), 4, preview.previewHash);
1394
1600
  return preview;
1395
1601
  }
1602
+ operationsReviewDirectory(run) {
1603
+ return join(this.root, "agent-output", run.projectId, run.runId, "operations");
1604
+ }
1605
+ async materializeOperationsPreviewPackage(run, preview, previewObjectHash) {
1606
+ const directory = this.operationsReviewDirectory(run);
1607
+ const changes = preview.changes.length === 0
1608
+ ? "- No changes."
1609
+ : preview.changes
1610
+ .map(({ resourceId, action, material, details }) => {
1611
+ const detail = details === undefined ? "" : `: ${this.reviewMarkdownText(details)}`;
1612
+ return `- ${this.reviewMarkdownText(action)} ${this.reviewMarkdownText(resourceId)}${material ? " (material)" : ""}${detail}`;
1613
+ })
1614
+ .join("\n");
1615
+ const previewContent = [
1616
+ "# Deployment Preview",
1617
+ "",
1618
+ `- Operation: ${this.reviewMarkdownText(preview.operation)}`,
1619
+ `- Target: ${this.reviewMarkdownText(preview.target)}`,
1620
+ `- Expires: ${this.reviewMarkdownText(preview.expiresAt)}`,
1621
+ "- Recipient: bound by the Gate 4 approval evidence",
1622
+ "",
1623
+ "## Changes",
1624
+ "",
1625
+ changes,
1626
+ "",
1627
+ "## Blockers",
1628
+ "",
1629
+ preview.blockers.length === 0
1630
+ ? "- None."
1631
+ : preview.blockers.map((blocker) => `- ${this.reviewMarkdownText(blocker)}`).join("\n"),
1632
+ "",
1633
+ ].join("\n");
1634
+ await mkdir(directory, { recursive: true });
1635
+ await Promise.all([
1636
+ atomicWriteBytes(join(directory, "README.md"), Buffer.from(`# Operations Review\n\nGenerated from exact kernel evidence for run \`${this.reviewMarkdownText(run.runId)}\`. The APEX kernel state remains authoritative.\n\n- Preview hash: ${preview.previewHash}\n- Preview object hash: ${previewObjectHash}\n- Gate 4 status: pending human terminal approval\n`, "utf8")),
1637
+ atomicWriteBytes(join(directory, "deployment-preview.md"), Buffer.from(previewContent, "utf8")),
1638
+ ]);
1639
+ }
1640
+ async materializeOperationsApprovalPackage(run, approval, approvalHash) {
1641
+ const content = [
1642
+ "# Gate 4 Approval",
1643
+ "",
1644
+ `- Decision: ${this.reviewMarkdownText(approval.decision)}`,
1645
+ `- Actor: ${this.reviewMarkdownText(approval.actor)}`,
1646
+ `- Recipient: ${this.reviewMarkdownText(approval.recipientIdentity ?? "Unavailable")}`,
1647
+ `- Preview hash: ${approval.previewHash ?? "Unavailable"}`,
1648
+ `- Approval hash: ${approvalHash}`,
1649
+ `- Expires: ${approval.expiresAt === undefined ? "Unavailable" : this.reviewMarkdownText(approval.expiresAt)}`,
1650
+ "",
1651
+ "This approval authorizes only the exact preview above.",
1652
+ "",
1653
+ ].join("\n");
1654
+ await atomicWriteBytes(join(this.operationsReviewDirectory(run), "approval.md"), Buffer.from(content, "utf8"));
1655
+ }
1396
1656
  async currentPreview() {
1397
1657
  const run = await this.currentRun();
1398
1658
  const events = await this.journal(run).replay();
@@ -2496,6 +2756,23 @@ export class ApexService {
2496
2756
  return typeof text === "string" && text.length > 0 ? [`${id}: ${text}`] : [];
2497
2757
  });
2498
2758
  const unknowns = requirements.filter(({ status }) => status !== "confirmed").map(({ statement }) => statement);
2759
+ const text = (id) => {
2760
+ const value = this.renderInputValue(input?.[id]);
2761
+ return typeof value === "string" && value.length > 0 ? value : undefined;
2762
+ };
2763
+ const joinValues = (...ids) => {
2764
+ const values = ids.map(text).filter((value) => value !== undefined);
2765
+ return values.length === 0 ? undefined : values.join("; ");
2766
+ };
2767
+ const reviewFields = {
2768
+ businessContext: joinValues("industry", "delivery-scenario", "workload-pattern"),
2769
+ successCriteria: text("scale"),
2770
+ nonFunctionalRequirements: text("availability-recovery") ?? text("recovery"),
2771
+ securityAndCompliance: joinValues("security-controls", "compliance", "authentication", "data-sensitivity"),
2772
+ budgetAndOperations: joinValues("budget", "operations"),
2773
+ regionalConstraints: text("region"),
2774
+ architectureHandoff: text("service-preferences"),
2775
+ };
2499
2776
  return {
2500
2777
  requirements: requirements.length > 0
2501
2778
  ? requirements
@@ -2510,6 +2787,7 @@ export class ApexService {
2510
2787
  ],
2511
2788
  assumptions,
2512
2789
  unknowns,
2790
+ ...Object.fromEntries(Object.entries(reviewFields).filter(([, value]) => value !== undefined)),
2513
2791
  };
2514
2792
  }
2515
2793
  renderInputValue(value) {
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const APEX_VERSION: "0.10.0-next.1";
1
+ export declare const APEX_VERSION: "0.10.0-next.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const APEX_VERSION = "0.10.0-next.1";
1
+ export const APEX_VERSION = "0.10.0-next.2";
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexops/cli",
3
- "version": "0.10.0-next.1",
3
+ "version": "0.10.0-next.2",
4
4
  "description": "Portable no-shell CLI and MCP facade for APEX",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,10 +32,10 @@
32
32
  "assets"
33
33
  ],
34
34
  "dependencies": {
35
- "@apexops/capabilities": "0.10.0-next.1",
36
- "@apexops/contracts": "0.10.0-next.1",
37
- "@apexops/kernel": "0.10.0-next.1",
38
- "@apexops/renderers": "0.10.0-next.1",
35
+ "@apexops/capabilities": "0.10.0-next.2",
36
+ "@apexops/contracts": "0.10.0-next.2",
37
+ "@apexops/kernel": "0.10.0-next.2",
38
+ "@apexops/renderers": "0.10.0-next.2",
39
39
  "@azure/mcp": "3.0.0-beta.37",
40
40
  "@hono/node-server": "2.0.11",
41
41
  "@modelcontextprotocol/sdk": "1.29.0",