@wowok/agent-mcp 2.5.1 → 2.5.3
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 +46 -6
- package/dist/knowledge/guard-design-patterns.js +104 -1
- package/dist/knowledge/guard-ledger.js +3 -3
- package/dist/knowledge/guard-lint.js +3 -3
- package/dist/knowledge/guard-risk.js +23 -15
- package/dist/knowledge/guard-templates.js +174 -2
- package/dist/knowledge/guard-translation.js +3 -3
- package/dist/knowledge/index.d.ts +3 -0
- package/dist/knowledge/index.js +9 -0
- package/dist/knowledge/machine-context.d.ts +1 -1
- package/dist/knowledge/machine-context.js +21 -0
- package/dist/knowledge/machine-ledger.d.ts +1 -0
- package/dist/knowledge/machine-ledger.js +31 -11
- package/dist/knowledge/machine-templates.js +32 -78
- package/dist/knowledge/mcp-schema-audit.js +3 -2
- package/dist/knowledge/overrides-loader.d.ts +13 -0
- package/dist/knowledge/overrides-loader.js +67 -0
- package/dist/knowledge/payment-risk.d.ts +4 -0
- package/dist/knowledge/payment-risk.js +67 -0
- package/dist/knowledge/repository-confirm.d.ts +4 -0
- package/dist/knowledge/repository-confirm.js +44 -0
- package/dist/knowledge/repository-risk.d.ts +8 -2
- package/dist/knowledge/repository-risk.js +61 -0
- package/dist/knowledge/repository-translation.js +23 -0
- package/dist/knowledge/scenario-modes.js +22 -5
- package/dist/knowledge/service-templates.js +38 -0
- package/dist/knowledge/treasury-templates.js +42 -0
- package/dist/loop-engineering/context-collect.d.ts +7 -0
- package/dist/loop-engineering/context-collect.js +83 -0
- package/dist/loop-engineering/improve.d.ts +29 -0
- package/dist/loop-engineering/improve.js +178 -0
- package/dist/project/business-puzzle.d.ts +1 -0
- package/dist/project/business-puzzle.js +11 -0
- package/dist/project/context-assembly.d.ts +16 -0
- package/dist/project/context-assembly.js +130 -0
- package/dist/project/deployment-doc.d.ts +126 -0
- package/dist/project/deployment-doc.js +632 -0
- package/dist/project/index.d.ts +25 -0
- package/dist/project/index.js +78 -0
- package/dist/project/migration.d.ts +22 -0
- package/dist/project/migration.js +125 -0
- package/dist/project/project-store.d.ts +110 -0
- package/dist/project/project-store.js +425 -0
- package/dist/project/risk-aggregator.d.ts +7 -0
- package/dist/project/risk-aggregator.js +15 -0
- package/dist/project/rollback-policy.d.ts +45 -0
- package/dist/project/rollback-policy.js +290 -0
- package/dist/project/stage-gate.d.ts +49 -0
- package/dist/project/stage-gate.js +310 -0
- package/dist/schema/call/allocation.d.ts +5 -0
- package/dist/schema/call/arbitration.d.ts +5 -0
- package/dist/schema/call/base.d.ts +3 -0
- package/dist/schema/call/base.js +3 -2
- package/dist/schema/call/bridge.d.ts +24 -0
- package/dist/schema/call/contact.d.ts +5 -0
- package/dist/schema/call/demand.d.ts +5 -0
- package/dist/schema/call/guard.d.ts +15 -0
- package/dist/schema/call/machine.d.ts +10 -0
- package/dist/schema/call/order.d.ts +5 -0
- package/dist/schema/call/payment.d.ts +5 -0
- package/dist/schema/call/permission.d.ts +5 -0
- package/dist/schema/call/personal.d.ts +5 -0
- package/dist/schema/call/progress.d.ts +5 -0
- package/dist/schema/call/proof.d.ts +10 -0
- package/dist/schema/call/repository.d.ts +5 -0
- package/dist/schema/call/reward.d.ts +5 -0
- package/dist/schema/call/service.d.ts +5 -0
- package/dist/schema/call/treasury.d.ts +5 -0
- package/dist/schema/operations.d.ts +210 -0
- package/dist/schema/operations.js +24 -0
- package/dist/schema/project/index.d.ts +2798 -85
- package/dist/schema/project/index.js +667 -2
- package/dist/schema/query/index.d.ts +601 -0
- package/dist/schema/query/index.js +61 -0
- package/dist/schemas/bridge_operation.schema.json +4 -0
- package/dist/schemas/guard2file.schema.json +4 -0
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/machineNode2file.schema.json +4 -0
- package/dist/schemas/onchain_operations.schema.json +20 -0
- package/dist/schemas/onchain_operations_allocation.schema.json +4 -0
- package/dist/schemas/onchain_operations_arbitration.schema.json +4 -0
- package/dist/schemas/onchain_operations_contact.schema.json +4 -0
- package/dist/schemas/onchain_operations_demand.schema.json +4 -0
- package/dist/schemas/onchain_operations_gen_passport.schema.json +8 -0
- package/dist/schemas/onchain_operations_gen_proof.schema.json +8 -0
- package/dist/schemas/onchain_operations_guard.schema.json +4 -577
- package/dist/schemas/onchain_operations_machine.schema.json +4 -0
- package/dist/schemas/onchain_operations_order.schema.json +4 -0
- package/dist/schemas/onchain_operations_payment.schema.json +4 -0
- package/dist/schemas/onchain_operations_permission.schema.json +4 -0
- package/dist/schemas/onchain_operations_personal.schema.json +4 -0
- package/dist/schemas/onchain_operations_progress.schema.json +4 -0
- package/dist/schemas/onchain_operations_proof.schema.json +4 -0
- package/dist/schemas/onchain_operations_repository.schema.json +4 -0
- package/dist/schemas/onchain_operations_reward.schema.json +4 -0
- package/dist/schemas/onchain_operations_service.schema.json +4 -0
- package/dist/schemas/onchain_operations_treasury.schema.json +4 -0
- package/dist/schemas/project_operation.output.json +1955 -0
- package/dist/schemas/project_operation.schema.json +133 -2
- package/dist/schemas/query_toolkit.output.json +407 -1
- package/dist/schemas/query_toolkit.schema.json +132 -0
- package/dist/tools/handlers/project.js +788 -2
- package/dist/tools/handlers/query.js +38 -2
- package/dist/tools/index.js +346 -37
- package/dist/tools/wrap.js +61 -7
- package/package.json +2 -2
- package/dist/schemas/onchain_operations.output.json +0 -2819
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { join } from "path";
|
|
1
2
|
const STANDARD_TOPO_ORDER = [
|
|
2
3
|
"permission", "treasury", "allocation", "guard", "machine",
|
|
3
4
|
"service", "order", "progress", "arb", "reward",
|
|
@@ -300,6 +301,43 @@ export function generateDeploymentDoc(input) {
|
|
|
300
301
|
];
|
|
301
302
|
return sections.filter((s) => s.length > 0).join("\n");
|
|
302
303
|
}
|
|
304
|
+
export function estimateDeploymentGas(input) {
|
|
305
|
+
const GAS_RATES = {
|
|
306
|
+
permission: { create: 20_000_000, publish: 0 },
|
|
307
|
+
progress: { create: 40_000_000, publish: 0 },
|
|
308
|
+
guard: { create: 30_000_000, publish: 0 },
|
|
309
|
+
allocation: { create: 40_000_000, publish: 0 },
|
|
310
|
+
machine: { create: 50_000_000, publish: 200_000_000 },
|
|
311
|
+
service: { create: 50_000_000, publish: 100_000_000 },
|
|
312
|
+
arb: { create: 40_000_000, publish: 0 },
|
|
313
|
+
treasury: { create: 30_000_000, publish: 0 },
|
|
314
|
+
demand: { create: 40_000_000, publish: 0 },
|
|
315
|
+
repository: { create: 40_000_000, publish: 0 },
|
|
316
|
+
reward: { create: 30_000_000, publish: 0 },
|
|
317
|
+
};
|
|
318
|
+
const perObject = [];
|
|
319
|
+
let totalGas = 0;
|
|
320
|
+
let publishGas = 0;
|
|
321
|
+
for (const obj of input.objects) {
|
|
322
|
+
const rate = GAS_RATES[obj.object_type] ?? { create: 40_000_000, publish: 0 };
|
|
323
|
+
const createGas = obj.reused_from ? 0 : rate.create;
|
|
324
|
+
const pubGas = obj.publish_required ? rate.publish : 0;
|
|
325
|
+
const objTotal = createGas + pubGas;
|
|
326
|
+
perObject.push({
|
|
327
|
+
entry_id: obj.entry_id,
|
|
328
|
+
object_type: obj.object_type,
|
|
329
|
+
create_gas_mist: createGas,
|
|
330
|
+
publish_gas_mist: pubGas,
|
|
331
|
+
});
|
|
332
|
+
totalGas += objTotal;
|
|
333
|
+
publishGas += pubGas;
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
total_gas_mist: totalGas,
|
|
337
|
+
per_object: perObject,
|
|
338
|
+
publish_gas_mist: publishGas,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
303
341
|
export function validateDeploymentDoc(input) {
|
|
304
342
|
const errors = [];
|
|
305
343
|
const checks = [];
|
|
@@ -430,3 +468,597 @@ function runDCheck(item, input) {
|
|
|
430
468
|
export function getStandardTopoOrder() {
|
|
431
469
|
return [...STANDARD_TOPO_ORDER];
|
|
432
470
|
}
|
|
471
|
+
import { saveProjectFile, saveProjectMarkdown, ensureProjectDir, deploymentDir, } from "./project-store.js";
|
|
472
|
+
const STAGE_D_CHECKS = {
|
|
473
|
+
1: ["D-01", "D-02", "D-03", "D-04"],
|
|
474
|
+
2: ["D-05", "D-06", "D-07"],
|
|
475
|
+
3: ["D-18"],
|
|
476
|
+
4: ["D-08", "D-09", "D-11", "D-12"],
|
|
477
|
+
5: ["D-10"],
|
|
478
|
+
};
|
|
479
|
+
const CROSS_STAGE_D_CHECKS = ["D-13", "D-14", "D-15", "D-16", "D-17"];
|
|
480
|
+
const STAGE_GOALS = {
|
|
481
|
+
1: {
|
|
482
|
+
stage: 1,
|
|
483
|
+
goal_statement: "Establish a valid and unique project namespace",
|
|
484
|
+
derived_from: ["unique_identity", "traceable_versioning"],
|
|
485
|
+
success_criteria: [
|
|
486
|
+
{ criterion_id: "namespace_prefix_nonempty", description: "Project prefix is non-empty and follows naming regex", measurable: true, target_value: "^[a-z][a-z0-9_]{2,63}$" },
|
|
487
|
+
{ criterion_id: "version_format_valid", description: "Version follows v<n> format", measurable: true, target_value: "^v\\d+$" },
|
|
488
|
+
{ criterion_id: "entry_id_unique", description: "All entry_ids are unique within the project", measurable: true },
|
|
489
|
+
],
|
|
490
|
+
},
|
|
491
|
+
2: {
|
|
492
|
+
stage: 2,
|
|
493
|
+
goal_statement: "Build a complete and cycle-free object dependency graph",
|
|
494
|
+
derived_from: ["dag_no_cycle", "complete_dependency"],
|
|
495
|
+
success_criteria: [
|
|
496
|
+
{ criterion_id: "odg_nodes_complete", description: "All required objects are defined", measurable: true },
|
|
497
|
+
{ criterion_id: "odg_edges_legal", description: "All edges reference defined nodes", measurable: true },
|
|
498
|
+
{ criterion_id: "odg_no_cycle", description: "Dependency graph has no cycles", measurable: true },
|
|
499
|
+
{ criterion_id: "scenario_coverage", description: "Declared scenarios are covered by steps", measurable: true },
|
|
500
|
+
],
|
|
501
|
+
},
|
|
502
|
+
3: {
|
|
503
|
+
stage: 3,
|
|
504
|
+
goal_statement: "Calibrate risks and confirm all CRITICAL risks resolved",
|
|
505
|
+
derived_from: ["risk_acknowledged"],
|
|
506
|
+
success_criteria: [
|
|
507
|
+
{ criterion_id: "no_critical_risk", description: "No CRITICAL risks remain (risk_status != RISK_BLOCKED)", measurable: true, target_value: "0" },
|
|
508
|
+
{ criterion_id: "high_risk_confirmed", description: "All HIGH risks are user-confirmed", measurable: true },
|
|
509
|
+
],
|
|
510
|
+
},
|
|
511
|
+
4: {
|
|
512
|
+
stage: 4,
|
|
513
|
+
goal_statement: "Generate a complete deployment document with valid steps",
|
|
514
|
+
derived_from: ["deployable_to_mainnet"],
|
|
515
|
+
success_criteria: [
|
|
516
|
+
{ criterion_id: "steps_sequential", description: "Step IDs are sequential and unique", measurable: true },
|
|
517
|
+
{ criterion_id: "deps_consistent", description: "Step dependencies are consistent with ODG", measurable: true },
|
|
518
|
+
{ criterion_id: "testnet_mainnet_symmetric", description: "testnet and mainnet phases are symmetric", measurable: true },
|
|
519
|
+
{ criterion_id: "no_d_error", description: "No D-FAIL errors", measurable: true, target_value: "0" },
|
|
520
|
+
],
|
|
521
|
+
},
|
|
522
|
+
5: {
|
|
523
|
+
stage: 5,
|
|
524
|
+
goal_statement: "Trace substeps coherently across the deployment",
|
|
525
|
+
derived_from: ["deployment_complete"],
|
|
526
|
+
success_criteria: [
|
|
527
|
+
{ criterion_id: "substeps_coherent", description: "No dangling inputs, circular refs, missing outputs, cross-step breaks", measurable: true },
|
|
528
|
+
{ criterion_id: "no_failed_substep", description: "No substep is in FAILED state", measurable: true },
|
|
529
|
+
],
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
const STAGE_RISK_POLICIES = {
|
|
533
|
+
1: {
|
|
534
|
+
stage: 1,
|
|
535
|
+
risks: [
|
|
536
|
+
{ risk_id: "R1-01", category: "naming", description: "Namespace prefix conflicts with existing project", likelihood: "medium", impact: "medium", mitigation: "Check existing projects before committing namespace", owner: "user" },
|
|
537
|
+
{ risk_id: "R1-02", category: "naming", description: "Version format inconsistent", likelihood: "low", impact: "low", mitigation: "Validate version regex", owner: "ai" },
|
|
538
|
+
],
|
|
539
|
+
active_controls: [
|
|
540
|
+
{ control_id: "C1-01", control_type: "preventive", target_risk: "R1-01", implementation: "stage gate checks prefix uniqueness", verified: true },
|
|
541
|
+
{ control_id: "C1-02", control_type: "preventive", target_risk: "R1-02", implementation: "schema validation enforces ^v\\d+$", verified: true },
|
|
542
|
+
],
|
|
543
|
+
residual_risks: [],
|
|
544
|
+
},
|
|
545
|
+
2: {
|
|
546
|
+
stage: 2,
|
|
547
|
+
risks: [
|
|
548
|
+
{ risk_id: "R2-01", category: "dependency", description: "Missing dependencies (dangling refs)", likelihood: "medium", impact: "high", mitigation: "D-02 check in stage gate", owner: "ai" },
|
|
549
|
+
{ risk_id: "R2-02", category: "dependency", description: "Circular dependencies in ODG", likelihood: "low", impact: "critical", mitigation: "Topological sort detects cycles", owner: "ai" },
|
|
550
|
+
{ risk_id: "R2-03", category: "operational", description: "Cross-project reference (project isolation violation §3.0)", likelihood: "low", impact: "critical", mitigation: "cross_project_reference_check in stage gate", owner: "ai" },
|
|
551
|
+
],
|
|
552
|
+
active_controls: [
|
|
553
|
+
{ control_id: "C2-01", control_type: "detective", target_risk: "R2-01", implementation: "D-02 dangling check", verified: true },
|
|
554
|
+
{ control_id: "C2-02", control_type: "detective", target_risk: "R2-02", implementation: "cycle detection", verified: true },
|
|
555
|
+
{ control_id: "C2-03", control_type: "preventive", target_risk: "R2-03", implementation: "cross-prefix reference scan", verified: true },
|
|
556
|
+
],
|
|
557
|
+
residual_risks: [],
|
|
558
|
+
},
|
|
559
|
+
3: {
|
|
560
|
+
stage: 3,
|
|
561
|
+
risks: [
|
|
562
|
+
{ risk_id: "R3-01", category: "operational", description: "Unresolved CRITICAL risks", likelihood: "medium", impact: "critical", mitigation: "Block at stage gate until resolved", owner: "user" },
|
|
563
|
+
{ risk_id: "R3-02", category: "operational", description: "Risk confirmation expired (stale)", likelihood: "low", impact: "medium", mitigation: "Re-confirm before deployment", owner: "user" },
|
|
564
|
+
],
|
|
565
|
+
active_controls: [
|
|
566
|
+
{ control_id: "C3-01", control_type: "preventive", target_risk: "R3-01", implementation: "D-16 blocks when risk_status=RISK_BLOCKED", verified: true },
|
|
567
|
+
],
|
|
568
|
+
residual_risks: [],
|
|
569
|
+
},
|
|
570
|
+
4: {
|
|
571
|
+
stage: 4,
|
|
572
|
+
risks: [
|
|
573
|
+
{ risk_id: "R4-01", category: "operational", description: "Step numbering gaps", likelihood: "low", impact: "medium", mitigation: "D-08 sequential check", owner: "ai" },
|
|
574
|
+
{ risk_id: "R4-02", category: "financial", description: "Mainnet gas budget exceeded", likelihood: "medium", impact: "high", mitigation: "gas_budget_check in stage gate", owner: "user" },
|
|
575
|
+
{ risk_id: "R4-03", category: "operational", description: "Irreversible operation requested", likelihood: "low", impact: "critical", mitigation: "Object lifecycle matrix check (§3.2)", owner: "user" },
|
|
576
|
+
],
|
|
577
|
+
active_controls: [
|
|
578
|
+
{ control_id: "C4-01", control_type: "detective", target_risk: "R4-01", implementation: "D-08 check", verified: true },
|
|
579
|
+
{ control_id: "C4-02", control_type: "detective", target_risk: "R4-02", implementation: "gas estimation", verified: true },
|
|
580
|
+
],
|
|
581
|
+
residual_risks: ["Gas costs are estimates; actual mainnet gas may differ"],
|
|
582
|
+
},
|
|
583
|
+
5: {
|
|
584
|
+
stage: 5,
|
|
585
|
+
risks: [
|
|
586
|
+
{ risk_id: "R5-01", category: "operational", description: "Substep linkage breaks (dangling/circular/missing)", likelihood: "medium", impact: "high", mitigation: "D-10 substep trace", owner: "ai" },
|
|
587
|
+
{ risk_id: "R5-02", category: "operational", description: "Observe records missing", likelihood: "low", impact: "medium", mitigation: "Append-only audit.jsonl", owner: "ai" },
|
|
588
|
+
{ risk_id: "R5-03", category: "operational", description: "State drift between substeps and stage state", likelihood: "low", impact: "high", mitigation: "Cross-stage check with stage 4", owner: "ai" },
|
|
589
|
+
],
|
|
590
|
+
active_controls: [
|
|
591
|
+
{ control_id: "C5-01", control_type: "detective", target_risk: "R5-01", implementation: "substep-trace.ts coherent check", verified: true },
|
|
592
|
+
],
|
|
593
|
+
residual_risks: [],
|
|
594
|
+
},
|
|
595
|
+
};
|
|
596
|
+
const PROJECT_INVARIANTS = [
|
|
597
|
+
{ invariant_id: "unique_identity", description: "Project has a unique prefix and version", verified_by_stages: [1] },
|
|
598
|
+
{ invariant_id: "traceable_versioning", description: "All objects trace to a specific project version", verified_by_stages: [1] },
|
|
599
|
+
{ invariant_id: "dag_no_cycle", description: "Object dependency graph has no cycles", verified_by_stages: [2] },
|
|
600
|
+
{ invariant_id: "complete_dependency", description: "All dependencies are resolved", verified_by_stages: [2] },
|
|
601
|
+
{ invariant_id: "project_isolation", description: "No cross-project object references (§3.0)", verified_by_stages: [2] },
|
|
602
|
+
{ invariant_id: "risk_acknowledged", description: "All CRITICAL risks are resolved", verified_by_stages: [3] },
|
|
603
|
+
{ invariant_id: "deployable_to_mainnet", description: "Deployment doc is complete and error-free", verified_by_stages: [4] },
|
|
604
|
+
{ invariant_id: "deployment_complete", description: "Substeps are coherent and traceable", verified_by_stages: [5] },
|
|
605
|
+
];
|
|
606
|
+
function runStageDChecks(stage, input) {
|
|
607
|
+
const checks = STAGE_D_CHECKS[stage];
|
|
608
|
+
const fullResult = validateDeploymentDoc(input);
|
|
609
|
+
const out = [];
|
|
610
|
+
for (const checkId of checks) {
|
|
611
|
+
const found = fullResult.checks.find((c) => c.check_id === checkId);
|
|
612
|
+
if (found) {
|
|
613
|
+
out.push({
|
|
614
|
+
check_id: found.check_id,
|
|
615
|
+
status: found.status.toLowerCase(),
|
|
616
|
+
message: found.notes ?? "",
|
|
617
|
+
evidence: found.description,
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return out;
|
|
622
|
+
}
|
|
623
|
+
function renderStageNamespaceContent(input) {
|
|
624
|
+
const lines = [];
|
|
625
|
+
lines.push(`# Stage 1: Namespace — ${input.project_prefix}_${input.version}`, "");
|
|
626
|
+
lines.push("## Namespace Configuration", "");
|
|
627
|
+
lines.push(`- **Prefix**: \`${input.project_prefix}\``);
|
|
628
|
+
lines.push(`- **Version**: \`${input.version}\``);
|
|
629
|
+
lines.push(`- **Namespace tag**: \`project:${input.project_prefix}_${input.version}\``);
|
|
630
|
+
lines.push(`- **Business intent**: ${input.business_intent}`);
|
|
631
|
+
lines.push(`- **Industry**: ${input.industry}`);
|
|
632
|
+
if (input.author)
|
|
633
|
+
lines.push(`- **Author**: ${input.author}`);
|
|
634
|
+
lines.push("");
|
|
635
|
+
lines.push("## Object Naming", "");
|
|
636
|
+
lines.push("| entry_id | object_type | name |");
|
|
637
|
+
lines.push("|----------|-------------|------|");
|
|
638
|
+
for (const o of input.objects) {
|
|
639
|
+
lines.push(`| ${o.entry_id} | ${o.object_type} | ${o.name} |`);
|
|
640
|
+
}
|
|
641
|
+
lines.push("");
|
|
642
|
+
return lines.join("\n");
|
|
643
|
+
}
|
|
644
|
+
function renderStagePuzzleContent(input) {
|
|
645
|
+
const lines = [];
|
|
646
|
+
lines.push(`# Stage 2: Business Puzzle — ${input.project_prefix}_${input.version}`, "");
|
|
647
|
+
lines.push("## Object Dependency Graph (ODG)", "");
|
|
648
|
+
lines.push("### Nodes", "");
|
|
649
|
+
lines.push("| entry_id | object_type | name | publish_required |");
|
|
650
|
+
lines.push("|----------|-------------|------|------------------|");
|
|
651
|
+
for (const o of input.objects) {
|
|
652
|
+
lines.push(`| ${o.entry_id} | ${o.object_type} | ${o.name} | ${o.publish_required} |`);
|
|
653
|
+
}
|
|
654
|
+
lines.push("");
|
|
655
|
+
lines.push("### Edges", "");
|
|
656
|
+
lines.push("| from | to | edge_kind | field_path | required_at_publish |");
|
|
657
|
+
lines.push("|------|----|-----------|-------------|---------------------|");
|
|
658
|
+
for (const e of input.edges) {
|
|
659
|
+
lines.push(`| ${e.from} | ${e.to} | ${e.edge_kind} | ${e.field_path} | ${e.required_at_publish} |`);
|
|
660
|
+
}
|
|
661
|
+
lines.push("");
|
|
662
|
+
if (input.scenarios && input.scenarios.length > 0) {
|
|
663
|
+
lines.push("### Scenarios", "");
|
|
664
|
+
lines.push("| scenario_id | description | primary_object |");
|
|
665
|
+
lines.push("|-------------|-------------|----------------|");
|
|
666
|
+
for (const s of input.scenarios) {
|
|
667
|
+
lines.push(`| ${s.scenario_id} | ${s.description} | ${s.primary_object} |`);
|
|
668
|
+
}
|
|
669
|
+
lines.push("");
|
|
670
|
+
}
|
|
671
|
+
return lines.join("\n");
|
|
672
|
+
}
|
|
673
|
+
function renderStageRiskContent(input) {
|
|
674
|
+
const lines = [];
|
|
675
|
+
lines.push(`# Stage 3: Risk Calibration — ${input.project_prefix}_${input.version}`, "");
|
|
676
|
+
lines.push("## Risk Status Summary", "");
|
|
677
|
+
lines.push(`- **risk_status**: ${input.risk_status ?? "(not provided)"}`);
|
|
678
|
+
lines.push(`- **CRITICAL count**: ${input.risk_critical_count ?? 0}`);
|
|
679
|
+
lines.push(`- **HIGH count**: ${input.risk_high_count ?? 0}`);
|
|
680
|
+
lines.push("");
|
|
681
|
+
lines.push("## D-Check Results (Stage 3 subset: D-18)", "");
|
|
682
|
+
const checks = runStageDChecks(3, input);
|
|
683
|
+
lines.push("| check_id | status | message |");
|
|
684
|
+
lines.push("|----------|--------|---------|");
|
|
685
|
+
for (const c of checks) {
|
|
686
|
+
lines.push(`| ${c.check_id} | ${c.status} | ${c.message} |`);
|
|
687
|
+
}
|
|
688
|
+
lines.push("");
|
|
689
|
+
return lines.join("\n");
|
|
690
|
+
}
|
|
691
|
+
function renderStageStepsContent(input) {
|
|
692
|
+
const lines = [];
|
|
693
|
+
lines.push(`# Stage 4: Deployment Steps — ${input.project_prefix}_${input.version}`, "");
|
|
694
|
+
lines.push("## Topological Execution Plan", "");
|
|
695
|
+
lines.push("| step | object_type | operation | substep_count | depends_on | entry_id | network_phase |");
|
|
696
|
+
lines.push("|------|-------------|-----------|---------------|------------|----------|---------------|");
|
|
697
|
+
for (const s of input.steps) {
|
|
698
|
+
lines.push(`| ${s.step} | ${s.object_type} | ${s.operation} | ${s.substep_count} | [${s.depends_on.join(", ")}] | ${s.entry_id} | ${s.network_phase} |`);
|
|
699
|
+
}
|
|
700
|
+
lines.push("");
|
|
701
|
+
lines.push("## D-Check Results (Stage 4 subset: D-08/D-09/D-11/D-12)", "");
|
|
702
|
+
const checks = runStageDChecks(4, input);
|
|
703
|
+
lines.push("| check_id | status | message |");
|
|
704
|
+
lines.push("|----------|--------|---------|");
|
|
705
|
+
for (const c of checks) {
|
|
706
|
+
lines.push(`| ${c.check_id} | ${c.status} | ${c.message} |`);
|
|
707
|
+
}
|
|
708
|
+
lines.push("");
|
|
709
|
+
return lines.join("\n");
|
|
710
|
+
}
|
|
711
|
+
function renderStageSubstepsContent(input) {
|
|
712
|
+
const lines = [];
|
|
713
|
+
lines.push(`# Stage 5: Substep Trace — ${input.project_prefix}_${input.version}`, "");
|
|
714
|
+
lines.push("> Substep records are appended at runtime (substeps-<network>.jsonl).", "");
|
|
715
|
+
lines.push("> This file records the validation summary.", "");
|
|
716
|
+
lines.push("");
|
|
717
|
+
lines.push("## D-Check Results (Stage 5 subset: D-10)", "");
|
|
718
|
+
lines.push("> D-10 is delegated to substep-trace.ts (C4) — populated at runtime.", "");
|
|
719
|
+
lines.push("| check_id | status | message |");
|
|
720
|
+
lines.push("|----------|--------|---------|");
|
|
721
|
+
lines.push("| D-10 | pending | delegated to substep-trace (C4) |");
|
|
722
|
+
lines.push("");
|
|
723
|
+
return lines.join("\n");
|
|
724
|
+
}
|
|
725
|
+
const STAGE_CONTENT_RENDERERS = {
|
|
726
|
+
1: renderStageNamespaceContent,
|
|
727
|
+
2: renderStagePuzzleContent,
|
|
728
|
+
3: renderStageRiskContent,
|
|
729
|
+
4: renderStageStepsContent,
|
|
730
|
+
5: renderStageSubstepsContent,
|
|
731
|
+
};
|
|
732
|
+
function generateStageAssessment(stage, input) {
|
|
733
|
+
const goal = STAGE_GOALS[stage];
|
|
734
|
+
const goalCompletion = {};
|
|
735
|
+
const findings = [];
|
|
736
|
+
const recommendations = [];
|
|
737
|
+
const dChecks = runStageDChecks(stage, input);
|
|
738
|
+
const failedChecks = dChecks.filter((c) => c.status === "fail");
|
|
739
|
+
for (const criterion of goal.success_criteria) {
|
|
740
|
+
let completion = 1.0;
|
|
741
|
+
const relatedCheck = dChecks.find((c) => criterion.criterion_id.includes(c.check_id.toLowerCase()));
|
|
742
|
+
if (relatedCheck) {
|
|
743
|
+
if (relatedCheck.status === "fail")
|
|
744
|
+
completion = 0.3;
|
|
745
|
+
else if (relatedCheck.status === "warn")
|
|
746
|
+
completion = 0.7;
|
|
747
|
+
}
|
|
748
|
+
if (failedChecks.length > 0 && !relatedCheck) {
|
|
749
|
+
completion = 0.5;
|
|
750
|
+
}
|
|
751
|
+
goalCompletion[criterion.criterion_id] = completion;
|
|
752
|
+
if (completion < 1.0) {
|
|
753
|
+
findings.push({
|
|
754
|
+
finding_id: `F-${stage}-${criterion.criterion_id}`,
|
|
755
|
+
severity: completion < 0.5 ? "critical" : "warn",
|
|
756
|
+
criterion_id: criterion.criterion_id,
|
|
757
|
+
description: `Criterion "${criterion.description}" not fully met`,
|
|
758
|
+
evidence: relatedCheck ? relatedCheck.message : "stage D-checks failed",
|
|
759
|
+
});
|
|
760
|
+
recommendations.push(`Address ${criterion.criterion_id}: ${criterion.description}`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
stage,
|
|
765
|
+
assessed_at: Date.now(),
|
|
766
|
+
goal_completion: goalCompletion,
|
|
767
|
+
findings,
|
|
768
|
+
recommendations,
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function generateStageVerification(stage, input) {
|
|
772
|
+
const goal = STAGE_GOALS[stage];
|
|
773
|
+
const dChecks = runStageDChecks(stage, input);
|
|
774
|
+
const goalVerification = {};
|
|
775
|
+
for (const criterion of goal.success_criteria) {
|
|
776
|
+
const relatedCheck = dChecks.find((c) => criterion.criterion_id.includes(c.check_id.toLowerCase()));
|
|
777
|
+
const passed = relatedCheck ? relatedCheck.status === "pass" : dChecks.every((c) => c.status !== "fail");
|
|
778
|
+
goalVerification[criterion.criterion_id] = {
|
|
779
|
+
passed,
|
|
780
|
+
evidence: relatedCheck ? relatedCheck.message : "all stage D-checks passed",
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
const blockingIssues = [];
|
|
784
|
+
for (const check of dChecks) {
|
|
785
|
+
if (check.status === "fail") {
|
|
786
|
+
blockingIssues.push(`${check.check_id}: ${check.message}`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const crossStageChecks = [];
|
|
790
|
+
if (stage === 2) {
|
|
791
|
+
crossStageChecks.push({
|
|
792
|
+
check_id: "CS-2-1",
|
|
793
|
+
involves_stages: [1, 2],
|
|
794
|
+
description: "All object names start with the project prefix",
|
|
795
|
+
passed: input.objects.every((o) => o.name.startsWith(input.project_prefix)),
|
|
796
|
+
evidence: `prefix=${input.project_prefix}`,
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
if (stage === 4) {
|
|
800
|
+
const entryIds = new Set(input.objects.map((o) => o.entry_id));
|
|
801
|
+
crossStageChecks.push({
|
|
802
|
+
check_id: "CS-4-2",
|
|
803
|
+
involves_stages: [2, 4],
|
|
804
|
+
description: "All steps reference defined objects",
|
|
805
|
+
passed: input.steps.every((s) => entryIds.has(s.entry_id)),
|
|
806
|
+
evidence: `${input.steps.length} steps checked`,
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
const stagePassed = blockingIssues.length === 0;
|
|
810
|
+
return {
|
|
811
|
+
stage,
|
|
812
|
+
verified_at: Date.now(),
|
|
813
|
+
goal_verification: goalVerification,
|
|
814
|
+
d_checks: dChecks,
|
|
815
|
+
cross_stage_checks: crossStageChecks,
|
|
816
|
+
stage_passed: stagePassed,
|
|
817
|
+
blocking_issues: blockingIssues,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function generateValidationChainGraph(input) {
|
|
821
|
+
const derivations = [];
|
|
822
|
+
const propagationRules = [];
|
|
823
|
+
for (const inv of PROJECT_INVARIANTS) {
|
|
824
|
+
for (const stageNum of inv.verified_by_stages) {
|
|
825
|
+
const stageGoal = STAGE_GOALS[stageNum];
|
|
826
|
+
derivations.push({
|
|
827
|
+
source_type: "project_invariant",
|
|
828
|
+
source_id: inv.invariant_id,
|
|
829
|
+
target_type: "stage_goal",
|
|
830
|
+
target_stage: stageNum,
|
|
831
|
+
target_id: `goal-stage-${stageNum}`,
|
|
832
|
+
derivation_logic: `invariant "${inv.invariant_id}" is verified by stage ${stageNum} goal "${stageGoal.goal_statement}"`,
|
|
833
|
+
});
|
|
834
|
+
propagationRules.push({
|
|
835
|
+
rule_id: `PR-${inv.invariant_id}-${stageNum}`,
|
|
836
|
+
trigger: { stage: stageNum, event: "verification_failed" },
|
|
837
|
+
effect: { target: "project_invariant", action: "block" },
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const stageUnits = [1, 2, 3, 4, 5].map((stage) => ({
|
|
842
|
+
stage,
|
|
843
|
+
goal_id: `goal-stage-${stage}`,
|
|
844
|
+
assessment_id: `assessment-stage-${stage}`,
|
|
845
|
+
risk_policy_id: `risk-policy-stage-${stage}`,
|
|
846
|
+
verification_id: `verification-stage-${stage}`,
|
|
847
|
+
artifacts: [
|
|
848
|
+
`0${stage}-<name>/README.md`,
|
|
849
|
+
`0${stage}-<name>/assessment.json`,
|
|
850
|
+
`0${stage}-<name>/risk-policy.json`,
|
|
851
|
+
`0${stage}-<name>/verification.json`,
|
|
852
|
+
`0${stage}-<name>/content.md`,
|
|
853
|
+
],
|
|
854
|
+
}));
|
|
855
|
+
const impactMap = {
|
|
856
|
+
"puzzle.json": ["02-puzzle/*", "04-steps/*", "README.md"],
|
|
857
|
+
"risk.json": ["03-risk/*", "04-steps/*", "README.md"],
|
|
858
|
+
"stage.json": ["README.md"],
|
|
859
|
+
"substeps-testnet.jsonl": ["05-substeps/*", "README.md"],
|
|
860
|
+
"substeps-mainnet.jsonl": ["05-substeps/*", "README.md"],
|
|
861
|
+
};
|
|
862
|
+
return {
|
|
863
|
+
version: "1.0.0",
|
|
864
|
+
generated_at: Date.now(),
|
|
865
|
+
project_invariants: PROJECT_INVARIANTS,
|
|
866
|
+
stage_units: stageUnits,
|
|
867
|
+
derivations,
|
|
868
|
+
propagation_rules: propagationRules,
|
|
869
|
+
impact_map: impactMap,
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function renderProjectReadme(input, relations) {
|
|
873
|
+
const lines = [];
|
|
874
|
+
lines.push(`# ${input.project_prefix}_${input.version} — Project Deployment`, "");
|
|
875
|
+
lines.push("> **Nested-autonomy deployment documentation set**. ", "");
|
|
876
|
+
lines.push("> Project-level file: goals + invariants + stage index + global ODG + resume entry.", "");
|
|
877
|
+
lines.push("> Each stage has its own subdirectory with goal/assessment/risk-policy/verification/content.", "");
|
|
878
|
+
lines.push("");
|
|
879
|
+
lines.push("## 🔄 Project Resume (entry point for any AI / user)", "");
|
|
880
|
+
lines.push(`- **Project**: ${input.project_prefix}_${input.version}`);
|
|
881
|
+
lines.push(`- **Business intent**: ${input.business_intent}`);
|
|
882
|
+
lines.push(`- **Industry**: ${input.industry}`);
|
|
883
|
+
lines.push(`- **Generated at**: ${isoNow()}`);
|
|
884
|
+
lines.push(`- **Schema version**: ${relations.version}`);
|
|
885
|
+
lines.push("- **Next step**: read stage completion index below, then open the relevant stage subdirectory", "");
|
|
886
|
+
lines.push("> Project isolation principle (§3.0): each project deploys its OWN objects;", "");
|
|
887
|
+
lines.push("> cross-project object reuse is forbidden; fork creates a new version that re-creates objects.", "");
|
|
888
|
+
lines.push("");
|
|
889
|
+
lines.push("## §1 Project Goals + Invariants", "");
|
|
890
|
+
lines.push("**Goal**: " + input.business_intent, "");
|
|
891
|
+
lines.push("### Invariants (derived to stage goals via validation chain)", "");
|
|
892
|
+
lines.push("| invariant_id | description | verified_by_stages |");
|
|
893
|
+
lines.push("|--------------|-------------|---------------------|");
|
|
894
|
+
for (const inv of relations.project_invariants) {
|
|
895
|
+
lines.push(`| ${inv.invariant_id} | ${inv.description} | [${inv.verified_by_stages.join(", ")}] |`);
|
|
896
|
+
}
|
|
897
|
+
lines.push("");
|
|
898
|
+
lines.push("## §2 Naming Conventions", "");
|
|
899
|
+
lines.push("- Project prefix regex: `^[a-z][a-z0-9_]{2,63}$`");
|
|
900
|
+
lines.push("- Version format: `v<n>` (e.g. `v1`, `v2`)");
|
|
901
|
+
lines.push("- Namespace tag: `project:<prefix>_<version>`");
|
|
902
|
+
lines.push("- Object naming: `<project>_<type>_<version>`");
|
|
903
|
+
lines.push("");
|
|
904
|
+
lines.push("## §3 Standard Topological Order (shared across stages)", "");
|
|
905
|
+
lines.push("```");
|
|
906
|
+
lines.push(STANDARD_TOPO_ORDER.join(" → "));
|
|
907
|
+
lines.push("```", "");
|
|
908
|
+
lines.push("## §4 D-Check Definitions (18 checks, definitions only — results per stage)", "");
|
|
909
|
+
lines.push("| check_id | description |");
|
|
910
|
+
lines.push("|----------|-------------|");
|
|
911
|
+
for (const item of D_CHECK_ITEMS) {
|
|
912
|
+
lines.push(`| ${item.id} | ${item.description} |`);
|
|
913
|
+
}
|
|
914
|
+
lines.push("");
|
|
915
|
+
lines.push("## §5 Stage Completion Index", "");
|
|
916
|
+
lines.push("> Auto-generated; reflects current state of stage subdirectories.", "");
|
|
917
|
+
lines.push("| Stage | Name | Status | Completion | Last Verified | Passed | Blocking |");
|
|
918
|
+
lines.push("|-------|------|--------|------------|----------------|--------|----------|");
|
|
919
|
+
const stageNames = {
|
|
920
|
+
1: "namespace", 2: "puzzle", 3: "risk", 4: "steps", 5: "substeps",
|
|
921
|
+
};
|
|
922
|
+
for (const stage of [1, 2, 3, 4, 5]) {
|
|
923
|
+
lines.push(`| ${stage} | ${stageNames[stage]} | pending | 0% | - | ⏳ | - |`);
|
|
924
|
+
}
|
|
925
|
+
lines.push("> Note: this table is regenerated on each `generate_deployment_doc` call; runtime", "");
|
|
926
|
+
lines.push("> execution (stage 5 substeps) updates the `05-substeps/` subdirectory append-only.", "");
|
|
927
|
+
lines.push("");
|
|
928
|
+
lines.push("## §6 Global Object Dependency Graph (ODG)", "");
|
|
929
|
+
lines.push("### Nodes", "");
|
|
930
|
+
lines.push("| entry_id | object_type | name | publish_required | description |");
|
|
931
|
+
lines.push("|----------|-------------|------|------------------|-------------|");
|
|
932
|
+
for (const o of input.objects) {
|
|
933
|
+
lines.push(`| ${o.entry_id} | ${o.object_type} | ${o.name} | ${o.publish_required} | ${o.description ?? ""} |`);
|
|
934
|
+
}
|
|
935
|
+
lines.push("");
|
|
936
|
+
lines.push("### Edges", "");
|
|
937
|
+
lines.push("| from | to | edge_kind | field_path | required_at_publish |");
|
|
938
|
+
lines.push("|------|----|-----------|-------------|---------------------|");
|
|
939
|
+
for (const e of input.edges) {
|
|
940
|
+
lines.push(`| ${e.from} | ${e.to} | ${e.edge_kind} | ${e.field_path} | ${e.required_at_publish} |`);
|
|
941
|
+
}
|
|
942
|
+
lines.push("");
|
|
943
|
+
const dangling = input.edges.filter((e) => !input.objects.find((o) => o.entry_id === e.from) ||
|
|
944
|
+
!input.objects.find((o) => o.entry_id === e.to));
|
|
945
|
+
lines.push("### Dependency Summary", "");
|
|
946
|
+
lines.push(`- Total nodes: ${input.objects.length}`);
|
|
947
|
+
lines.push(`- Total edges: ${input.edges.length}`);
|
|
948
|
+
lines.push(`- Dangling dependencies: ${dangling.length}`);
|
|
949
|
+
lines.push(`- Cross-project references: 0 (project isolation §3.0 enforced)`, "");
|
|
950
|
+
lines.push("");
|
|
951
|
+
lines.push("## §7 Cross-Stage Relations (Validation Chain)", "");
|
|
952
|
+
lines.push("### Invariant → Stage Goal Derivations", "");
|
|
953
|
+
lines.push("| Invariant | Stage | Stage Goal |");
|
|
954
|
+
lines.push("|-----------|-------|------------|");
|
|
955
|
+
for (const link of relations.derivations) {
|
|
956
|
+
lines.push(`| ${link.source_id} | ${link.target_stage} | ${link.derivation_logic} |`);
|
|
957
|
+
}
|
|
958
|
+
lines.push("");
|
|
959
|
+
lines.push("### Stage Dependencies (sequential)", "");
|
|
960
|
+
lines.push("| Upstream | Downstream | Reason |");
|
|
961
|
+
lines.push("|---------|-----------|--------|");
|
|
962
|
+
lines.push("| stage 1 (namespace) | stage 2 (puzzle) | Namespace must be set before object naming |");
|
|
963
|
+
lines.push("| stage 2 (puzzle) | stage 3 (risk) | Puzzle must be complete before risk assessment |");
|
|
964
|
+
lines.push("| stage 2 (puzzle) | stage 4 (steps) | Puzzle determines deployment step order |");
|
|
965
|
+
lines.push("| stage 3 (risk) | stage 4 (steps) | Risks must be confirmed before execution |");
|
|
966
|
+
lines.push("| stage 4 (steps) | stage 5 (substeps) | Steps must be defined before substep tracing |");
|
|
967
|
+
lines.push("");
|
|
968
|
+
lines.push("## §8 Gas / Faucet Rules", "");
|
|
969
|
+
lines.push("- testnet: gas is free (faucet) — encourage experimentation,回退无成本");
|
|
970
|
+
lines.push("- mainnet: gas is real — 回退后重跑有真实成本, WARN before rollback");
|
|
971
|
+
lines.push("- Reversibility is determined by object lifecycle (§3.2), NOT by network");
|
|
972
|
+
lines.push("");
|
|
973
|
+
lines.push("## §9 Stage Subdirectory Index", "");
|
|
974
|
+
lines.push("| Stage | Directory | README | Assessment | Risk Policy | Verification | Content |");
|
|
975
|
+
lines.push("|-------|-----------|--------|------------|-------------|--------------|---------|");
|
|
976
|
+
for (const stage of [1, 2, 3, 4, 5]) {
|
|
977
|
+
const dir = `0${stage}-${stageNames[stage]}/`;
|
|
978
|
+
lines.push(`| ${stage} | [${dir}](./${dir}) | [README.md](./${dir}README.md) | [assessment.json](./${dir}assessment.json) | [risk-policy.json](./${dir}risk-policy.json) | [verification.json](./${dir}verification.json) | [content.md](./${dir}content.md) |`);
|
|
979
|
+
}
|
|
980
|
+
lines.push("");
|
|
981
|
+
return lines.join("\n");
|
|
982
|
+
}
|
|
983
|
+
function renderStageReadme(stage, input) {
|
|
984
|
+
const goal = STAGE_GOALS[stage];
|
|
985
|
+
const lines = [];
|
|
986
|
+
const stageNames = {
|
|
987
|
+
1: "namespace", 2: "puzzle", 3: "risk", 4: "steps", 5: "substeps",
|
|
988
|
+
};
|
|
989
|
+
lines.push(`# Stage ${stage}: ${stageNames[stage]} — ${input.project_prefix}_${input.version}`, "");
|
|
990
|
+
lines.push("> **Nested-autonomy unit**: this stage is self-governing.", "");
|
|
991
|
+
lines.push("> See [../README.md](../README.md) for project-level goals + invariants.", "");
|
|
992
|
+
lines.push("");
|
|
993
|
+
lines.push("## Stage Goal (derived from project invariants)", "");
|
|
994
|
+
lines.push(`**Statement**: ${goal.goal_statement}`, "");
|
|
995
|
+
lines.push(`**Derived from**: ${goal.derived_from.join(", ")}`, "");
|
|
996
|
+
lines.push("");
|
|
997
|
+
lines.push("### Success Criteria", "");
|
|
998
|
+
lines.push("| criterion_id | description | measurable | target |");
|
|
999
|
+
lines.push("|--------------|-------------|------------|--------|");
|
|
1000
|
+
for (const c of goal.success_criteria) {
|
|
1001
|
+
lines.push(`| ${c.criterion_id} | ${c.description} | ${c.measurable} | ${c.target_value ?? "-"} |`);
|
|
1002
|
+
}
|
|
1003
|
+
lines.push("");
|
|
1004
|
+
lines.push("## Stage Files", "");
|
|
1005
|
+
lines.push("- `assessment.json` — stage assessment (completion per criterion)");
|
|
1006
|
+
lines.push("- `risk-policy.json` — stage-specific risks + controls");
|
|
1007
|
+
lines.push("- `verification.json` — stage verification (goal + D-checks + cross-stage)");
|
|
1008
|
+
lines.push("- `content.md` — stage content (actual deployment data)");
|
|
1009
|
+
lines.push("");
|
|
1010
|
+
return lines.join("\n");
|
|
1011
|
+
}
|
|
1012
|
+
export function generateDeploymentDocSet(prefix, version, input) {
|
|
1013
|
+
if (input.project_prefix !== prefix) {
|
|
1014
|
+
throw new Error(`generateDeploymentDocSet: input.project_prefix (${input.project_prefix}) does not match prefix (${prefix})`);
|
|
1015
|
+
}
|
|
1016
|
+
if (input.version !== version) {
|
|
1017
|
+
throw new Error(`generateDeploymentDocSet: input.version (${input.version}) does not match version (${version})`);
|
|
1018
|
+
}
|
|
1019
|
+
const depDir = deploymentDir(prefix, version);
|
|
1020
|
+
ensureProjectDir(prefix, version);
|
|
1021
|
+
const relations = generateValidationChainGraph(input);
|
|
1022
|
+
const allFiles = [];
|
|
1023
|
+
const stageDirs = {
|
|
1024
|
+
1: "", 2: "", 3: "", 4: "", 5: "",
|
|
1025
|
+
};
|
|
1026
|
+
const stageNames = {
|
|
1027
|
+
1: "namespace", 2: "puzzle", 3: "risk", 4: "steps", 5: "substeps",
|
|
1028
|
+
};
|
|
1029
|
+
let allStagesPassed = true;
|
|
1030
|
+
for (const stage of [1, 2, 3, 4, 5]) {
|
|
1031
|
+
const stageDir = `deployment/0${stage}-${stageNames[stage]}`;
|
|
1032
|
+
stageDirs[stage] = join(depDir, `0${stage}-${stageNames[stage]}`);
|
|
1033
|
+
const readmeMd = renderStageReadme(stage, input);
|
|
1034
|
+
saveProjectMarkdown(prefix, version, `${stageDir}/README.md`, readmeMd);
|
|
1035
|
+
allFiles.push(`${stageDir}/README.md`);
|
|
1036
|
+
const assessment = generateStageAssessment(stage, input);
|
|
1037
|
+
saveProjectFile(prefix, version, `${stageDir}/assessment.json`, assessment);
|
|
1038
|
+
allFiles.push(`${stageDir}/assessment.json`);
|
|
1039
|
+
const riskPolicy = STAGE_RISK_POLICIES[stage];
|
|
1040
|
+
saveProjectFile(prefix, version, `${stageDir}/risk-policy.json`, riskPolicy);
|
|
1041
|
+
allFiles.push(`${stageDir}/risk-policy.json`);
|
|
1042
|
+
const verification = generateStageVerification(stage, input);
|
|
1043
|
+
if (!verification.stage_passed)
|
|
1044
|
+
allStagesPassed = false;
|
|
1045
|
+
saveProjectFile(prefix, version, `${stageDir}/verification.json`, verification);
|
|
1046
|
+
allFiles.push(`${stageDir}/verification.json`);
|
|
1047
|
+
const contentMd = STAGE_CONTENT_RENDERERS[stage](input);
|
|
1048
|
+
saveProjectMarkdown(prefix, version, `${stageDir}/content.md`, contentMd);
|
|
1049
|
+
allFiles.push(`${stageDir}/content.md`);
|
|
1050
|
+
}
|
|
1051
|
+
const readmeMd = renderProjectReadme(input, relations);
|
|
1052
|
+
saveProjectMarkdown(prefix, version, "deployment/README.md", readmeMd);
|
|
1053
|
+
allFiles.push("deployment/README.md");
|
|
1054
|
+
saveProjectFile(prefix, version, "deployment/relations.json", relations);
|
|
1055
|
+
allFiles.push("deployment/relations.json");
|
|
1056
|
+
return {
|
|
1057
|
+
readme_path: join(depDir, "README.md"),
|
|
1058
|
+
relations_path: join(depDir, "relations.json"),
|
|
1059
|
+
stage_dirs: stageDirs,
|
|
1060
|
+
all_files: allFiles,
|
|
1061
|
+
relations,
|
|
1062
|
+
all_stages_passed: allStagesPassed,
|
|
1063
|
+
};
|
|
1064
|
+
}
|