@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.
Files changed (107) hide show
  1. package/dist/index.js +46 -6
  2. package/dist/knowledge/guard-design-patterns.js +104 -1
  3. package/dist/knowledge/guard-ledger.js +3 -3
  4. package/dist/knowledge/guard-lint.js +3 -3
  5. package/dist/knowledge/guard-risk.js +23 -15
  6. package/dist/knowledge/guard-templates.js +174 -2
  7. package/dist/knowledge/guard-translation.js +3 -3
  8. package/dist/knowledge/index.d.ts +3 -0
  9. package/dist/knowledge/index.js +9 -0
  10. package/dist/knowledge/machine-context.d.ts +1 -1
  11. package/dist/knowledge/machine-context.js +21 -0
  12. package/dist/knowledge/machine-ledger.d.ts +1 -0
  13. package/dist/knowledge/machine-ledger.js +31 -11
  14. package/dist/knowledge/machine-templates.js +32 -78
  15. package/dist/knowledge/mcp-schema-audit.js +3 -2
  16. package/dist/knowledge/overrides-loader.d.ts +13 -0
  17. package/dist/knowledge/overrides-loader.js +67 -0
  18. package/dist/knowledge/payment-risk.d.ts +4 -0
  19. package/dist/knowledge/payment-risk.js +67 -0
  20. package/dist/knowledge/repository-confirm.d.ts +4 -0
  21. package/dist/knowledge/repository-confirm.js +44 -0
  22. package/dist/knowledge/repository-risk.d.ts +8 -2
  23. package/dist/knowledge/repository-risk.js +61 -0
  24. package/dist/knowledge/repository-translation.js +23 -0
  25. package/dist/knowledge/scenario-modes.js +22 -5
  26. package/dist/knowledge/service-templates.js +38 -0
  27. package/dist/knowledge/treasury-templates.js +42 -0
  28. package/dist/loop-engineering/context-collect.d.ts +7 -0
  29. package/dist/loop-engineering/context-collect.js +83 -0
  30. package/dist/loop-engineering/improve.d.ts +29 -0
  31. package/dist/loop-engineering/improve.js +178 -0
  32. package/dist/project/business-puzzle.d.ts +1 -0
  33. package/dist/project/business-puzzle.js +11 -0
  34. package/dist/project/context-assembly.d.ts +16 -0
  35. package/dist/project/context-assembly.js +130 -0
  36. package/dist/project/deployment-doc.d.ts +126 -0
  37. package/dist/project/deployment-doc.js +632 -0
  38. package/dist/project/index.d.ts +25 -0
  39. package/dist/project/index.js +78 -0
  40. package/dist/project/migration.d.ts +22 -0
  41. package/dist/project/migration.js +125 -0
  42. package/dist/project/project-store.d.ts +110 -0
  43. package/dist/project/project-store.js +425 -0
  44. package/dist/project/risk-aggregator.d.ts +7 -0
  45. package/dist/project/risk-aggregator.js +15 -0
  46. package/dist/project/rollback-policy.d.ts +45 -0
  47. package/dist/project/rollback-policy.js +290 -0
  48. package/dist/project/stage-gate.d.ts +49 -0
  49. package/dist/project/stage-gate.js +310 -0
  50. package/dist/schema/call/allocation.d.ts +5 -0
  51. package/dist/schema/call/arbitration.d.ts +5 -0
  52. package/dist/schema/call/base.d.ts +3 -0
  53. package/dist/schema/call/base.js +3 -2
  54. package/dist/schema/call/bridge.d.ts +24 -0
  55. package/dist/schema/call/contact.d.ts +5 -0
  56. package/dist/schema/call/demand.d.ts +5 -0
  57. package/dist/schema/call/guard.d.ts +15 -0
  58. package/dist/schema/call/machine.d.ts +10 -0
  59. package/dist/schema/call/order.d.ts +5 -0
  60. package/dist/schema/call/payment.d.ts +5 -0
  61. package/dist/schema/call/permission.d.ts +5 -0
  62. package/dist/schema/call/personal.d.ts +5 -0
  63. package/dist/schema/call/progress.d.ts +5 -0
  64. package/dist/schema/call/proof.d.ts +10 -0
  65. package/dist/schema/call/repository.d.ts +5 -0
  66. package/dist/schema/call/reward.d.ts +5 -0
  67. package/dist/schema/call/service.d.ts +5 -0
  68. package/dist/schema/call/treasury.d.ts +5 -0
  69. package/dist/schema/operations.d.ts +210 -0
  70. package/dist/schema/operations.js +24 -0
  71. package/dist/schema/project/index.d.ts +2798 -85
  72. package/dist/schema/project/index.js +667 -2
  73. package/dist/schema/query/index.d.ts +601 -0
  74. package/dist/schema/query/index.js +61 -0
  75. package/dist/schemas/bridge_operation.schema.json +4 -0
  76. package/dist/schemas/guard2file.schema.json +4 -0
  77. package/dist/schemas/index.json +1 -1
  78. package/dist/schemas/machineNode2file.schema.json +4 -0
  79. package/dist/schemas/onchain_operations.schema.json +20 -0
  80. package/dist/schemas/onchain_operations_allocation.schema.json +4 -0
  81. package/dist/schemas/onchain_operations_arbitration.schema.json +4 -0
  82. package/dist/schemas/onchain_operations_contact.schema.json +4 -0
  83. package/dist/schemas/onchain_operations_demand.schema.json +4 -0
  84. package/dist/schemas/onchain_operations_gen_passport.schema.json +8 -0
  85. package/dist/schemas/onchain_operations_gen_proof.schema.json +8 -0
  86. package/dist/schemas/onchain_operations_guard.schema.json +4 -577
  87. package/dist/schemas/onchain_operations_machine.schema.json +4 -0
  88. package/dist/schemas/onchain_operations_order.schema.json +4 -0
  89. package/dist/schemas/onchain_operations_payment.schema.json +4 -0
  90. package/dist/schemas/onchain_operations_permission.schema.json +4 -0
  91. package/dist/schemas/onchain_operations_personal.schema.json +4 -0
  92. package/dist/schemas/onchain_operations_progress.schema.json +4 -0
  93. package/dist/schemas/onchain_operations_proof.schema.json +4 -0
  94. package/dist/schemas/onchain_operations_repository.schema.json +4 -0
  95. package/dist/schemas/onchain_operations_reward.schema.json +4 -0
  96. package/dist/schemas/onchain_operations_service.schema.json +4 -0
  97. package/dist/schemas/onchain_operations_treasury.schema.json +4 -0
  98. package/dist/schemas/project_operation.output.json +1955 -0
  99. package/dist/schemas/project_operation.schema.json +133 -2
  100. package/dist/schemas/query_toolkit.output.json +407 -1
  101. package/dist/schemas/query_toolkit.schema.json +132 -0
  102. package/dist/tools/handlers/project.js +788 -2
  103. package/dist/tools/handlers/query.js +38 -2
  104. package/dist/tools/index.js +346 -37
  105. package/dist/tools/wrap.js +61 -7
  106. package/package.json +2 -2
  107. package/dist/schemas/onchain_operations.output.json +0 -2819
@@ -78,10 +78,32 @@ export const ProjectOperationInputSchema = z
78
78
  "aggregate_risks",
79
79
  "generate_deployment_doc",
80
80
  "trace_substeps",
81
+ "get_project_status",
82
+ "load_project",
83
+ "fork_project",
84
+ "export_project",
85
+ "get_project_files",
86
+ "validate_stage_unit",
87
+ "get_stage_assessment",
88
+ "get_stage_risk_policy",
89
+ "get_doc_relations",
90
+ "update_deployment_doc",
91
+ "validate_validation_chain",
92
+ "apply_improvement",
93
+ "get_improvement_queue",
94
+ "get_flywheel_config",
95
+ "rollback_stage",
96
+ "get_reversibility",
97
+ "assemble_context",
81
98
  ])
82
- .describe("Action to perform. Two categories:\n" +
99
+ .describe("Action to perform. Six categories:\n" +
83
100
  "1. Graph Query (10): list_projects, list_objects, shareable, dependencies, referenced_by, pre_publish_check, cross_project_refs, graph_stats, save_graph, load_graph.\n" +
84
- "2. Project-Based Deployment 5-Stage (4): Call IN ORDER — analyze_intent (Stage 2) → aggregate_risks (Stage 3) → generate_deployment_doc (Stage 4) → trace_substeps (Stage 5). Each action's output includes `next_action` telling you which action to call next. Stage 1 (Project Naming) uses the `project` + `version` params."),
101
+ "2. Project-Based Deployment 5-Stage (4): Call IN ORDER — analyze_intent (Stage 2) → aggregate_risks (Stage 3) → generate_deployment_doc (Stage 4) → trace_substeps (Stage 5). Each action's output includes `next_action` telling you which action to call next. Stage 1 (Project Naming) uses the `project` + `version` params.\n" +
102
+ "3. Project Memory Layer (5): load_project, fork_project, export_project, get_project_files, get_project_status.\n" +
103
+ "4. Nested-Autonomy Stage Unit (6): validate_stage_unit, get_stage_assessment, get_stage_risk_policy, get_doc_relations, update_deployment_doc, validate_validation_chain.\n" +
104
+ "5. Distillation Reflow (3): apply_improvement (review + apply a proposal — config_override writes overrides/, source_patch writes patches/), get_improvement_queue (list pending/approved proposals), get_flywheel_config (query reflow loop status).\n" +
105
+ "6. Rollback & Reversibility (2): rollback_stage (evaluate + execute stage rollback with file cleanup — blocked if has_published_object), get_reversibility (query object lifecycle reversibility matrix for risk reminders).\n" +
106
+ "7. Context Assembly (1): assemble_context (query on-chain object states + extract embedded history + optional events, and assemble a structured semantic context for LLM consumption — bridges raw facts to business-understandable context). Required input: context_objects (array of object IDs/names). Optional: include_events (query recent state-transition events)."),
85
107
  project: z
86
108
  .string()
87
109
  .optional()
@@ -95,6 +117,15 @@ export const ProjectOperationInputSchema = z
95
117
  .string()
96
118
  .optional()
97
119
  .describe("Object name or address (for dependencies / referenced_by / pre_publish_check)"),
120
+ fork_to_version: z
121
+ .string()
122
+ .regex(/^v\d+$/)
123
+ .optional()
124
+ .describe("Target version for fork_project (e.g. 'v2'). Must differ from source 'version'."),
125
+ fork_to_prefix: z
126
+ .string()
127
+ .optional()
128
+ .describe("Target prefix for fork_project. Defaults to source 'project' prefix when omitted."),
98
129
  user_intent: z
99
130
  .string()
100
131
  .min(1)
@@ -204,6 +235,28 @@ export const ProjectOperationInputSchema = z
204
235
  .boolean()
205
236
  .optional()
206
237
  .describe("Whether to run deployment-scanner validation after generating the doc. Defaults to true."),
238
+ gas_budget: z
239
+ .object({
240
+ network: z.enum(["testnet", "mainnet"]),
241
+ already_spent_gas: z
242
+ .number()
243
+ .int()
244
+ .nonnegative()
245
+ .optional()
246
+ .describe("Gas already spent on-chain in MIST (from telemetry). Defaults to 0."),
247
+ estimated_rerun_gas: z
248
+ .number()
249
+ .int()
250
+ .nonnegative()
251
+ .optional()
252
+ .describe("Estimated gas to re-run remaining ops in MIST. Auto-computed from estimateDeploymentGas when omitted."),
253
+ warning: z
254
+ .string()
255
+ .optional()
256
+ .describe("Custom warning text. Defaults to a computed cost summary."),
257
+ })
258
+ .optional()
259
+ .describe("Gas budget input for stage 4/5 gate (§3.5). Non-blocking; only surfaces a WARN on mainnet."),
207
260
  network: z
208
261
  .enum(["testnet", "mainnet"])
209
262
  .optional()
@@ -249,8 +302,81 @@ export const ProjectOperationInputSchema = z
249
302
  .strict())
250
303
  .optional()
251
304
  .describe("Substep records for trace_substeps."),
305
+ target_stage: z
306
+ .number()
307
+ .int()
308
+ .min(1)
309
+ .max(5)
310
+ .optional()
311
+ .describe("Stage number (1-5) for validate_stage_unit, get_stage_assessment, get_stage_risk_policy, and rollback_stage (the stage to rollback to). Required by these 4 actions."),
312
+ proposal_id: z
313
+ .string()
314
+ .optional()
315
+ .describe("Improvement proposal ID (for apply_improvement). Required by apply_improvement."),
316
+ review_status: z
317
+ .enum(["approved", "rejected", "applied"])
318
+ .optional()
319
+ .describe("New review status to set (for apply_improvement). 'approved' triggers application (config_override or source_patch); 'rejected' marks as rejected; 'applied' marks as already applied."),
320
+ queue_filter_status: z
321
+ .enum(["pending", "approved", "rejected", "applied"])
322
+ .optional()
323
+ .describe("Filter the improvement queue by review_status (for get_improvement_queue)."),
324
+ queue_filter_type: z
325
+ .string()
326
+ .optional()
327
+ .describe("Filter the improvement queue by proposal type (for get_improvement_queue)."),
328
+ queue_filter_priority: z
329
+ .string()
330
+ .optional()
331
+ .describe("Filter the improvement queue by priority P0/P1/P2/P3 (for get_improvement_queue)."),
332
+ dry_run: z
333
+ .boolean()
334
+ .optional()
335
+ .describe("When true, rollback_stage only evaluates the policy and returns the cleanup plan WITHOUT executing the rollback. Defaults to false (execute)."),
336
+ query_object_type: z
337
+ .string()
338
+ .optional()
339
+ .describe("Object type for get_reversibility query (e.g. 'service', 'machine', 'guard'). When omitted, returns the full matrix."),
340
+ query_lifecycle_state: z
341
+ .enum(["created", "referenced", "published", "bound"])
342
+ .optional()
343
+ .describe("Object lifecycle state for get_reversibility query. When omitted, returns all lifecycle states for the given object_type."),
344
+ context_objects: z
345
+ .array(z.string())
346
+ .optional()
347
+ .describe("Object IDs (0x...) or LocalMark names to assemble context for. Required when action='assemble_context'. The current on-chain state of each object will be queried and enriched with semantic annotations."),
348
+ include_events: z
349
+ .boolean()
350
+ .optional()
351
+ .describe("When true, assemble_context also queries recent state-transition events (NewOrderEvent, ProgressEvent, ArbEvent, etc.). Events are the real-time transition log — convergent and bounded. Defaults to false. Note: object-embedded history (ProgressSession.forwards, Order.disputes) is ALWAYS extracted automatically — no flag needed."),
352
+ context_network: z
353
+ .enum(["testnet", "mainnet"])
354
+ .optional()
355
+ .describe("Network for assemble_context queries. Defaults to 'testnet' if omitted."),
252
356
  })
253
357
  .strict();
358
+ const GateValidationSchema = z
359
+ .object({
360
+ stage: z.number().int().min(1).max(5),
361
+ passed: z.boolean().describe("True when no FAIL checks exist."),
362
+ checks: z.array(z.object({
363
+ dimension: z.enum([
364
+ "semantic",
365
+ "tools",
366
+ "reversibility",
367
+ "risk",
368
+ "isolation",
369
+ "gas_budget",
370
+ ]),
371
+ status: z.enum(["PASS", "FAIL", "WARN"]),
372
+ message: z.string(),
373
+ })),
374
+ blocking_issues: z.array(z.string()),
375
+ warnings: z.array(z.string()),
376
+ can_proceed: z.boolean(),
377
+ })
378
+ .optional()
379
+ .describe("Stage gate validation result (6 dimensions: semantic/tools/reversibility/risk/isolation/gas_budget).");
254
380
  const ItemsResult = (action) => z.object({
255
381
  action: z.literal(action),
256
382
  items: z
@@ -279,10 +405,14 @@ const AnalyzeIntentResultSchema = z
279
405
  puzzles: z.record(z.string(), PuzzleEntrySchema),
280
406
  overall_completeness: z.enum(["complete", "partial", "empty"]),
281
407
  next_step: z.string(),
408
+ recommended_creation_order: z
409
+ .array(z.string())
410
+ .describe("Recommended object creation order based on dependency topology (e.g. ['permission','progress','guard','allocation','machine','service'])."),
282
411
  next_action: z
283
412
  .enum(["aggregate_risks", "none"])
284
413
  .describe("Next project_operation action to call. 'aggregate_risks' when puzzles are complete enough; 'none' if user must fill missing fields first."),
285
414
  warnings: z.array(z.string()),
415
+ gate_validation: GateValidationSchema,
286
416
  })
287
417
  .strict();
288
418
  const AggregateRisksResultSchema = z
@@ -330,6 +460,16 @@ const AggregateRisksResultSchema = z
330
460
  entry_id: z.string(),
331
461
  }))
332
462
  .optional(),
463
+ fix_suggestions_grouped: z
464
+ .record(z.string(), z.array(z.object({
465
+ risk_rule_id: z.string(),
466
+ severity: z.enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]),
467
+ message: z.string(),
468
+ fix_suggestion: z.string(),
469
+ entry_id: z.string(),
470
+ })))
471
+ .optional()
472
+ .describe("Fix suggestions grouped by object_type for better readability."),
333
473
  calibrated_at: z.number().int(),
334
474
  warnings: z.array(z.string()),
335
475
  can_proceed: z
@@ -341,6 +481,7 @@ const AggregateRisksResultSchema = z
341
481
  user_action_required: z
342
482
  .string()
343
483
  .describe("Human-readable next-step guidance."),
484
+ gate_validation: GateValidationSchema,
344
485
  })
345
486
  .strict();
346
487
  const GenerateDeploymentDocResultSchema = z
@@ -367,6 +508,30 @@ const GenerateDeploymentDocResultSchema = z
367
508
  })
368
509
  .optional()
369
510
  .describe("Scanner validation result. Present when run_scanner=true."),
511
+ estimated_gas: z
512
+ .object({
513
+ total_gas_mist: z.number().int().describe("Estimated total gas in MIST (1 WOW = 10^9 MIST)."),
514
+ per_object: z.array(z.object({
515
+ entry_id: z.string(),
516
+ object_type: z.string(),
517
+ create_gas_mist: z.number().int(),
518
+ publish_gas_mist: z.number().int(),
519
+ })),
520
+ publish_gas_mist: z.number().int().describe("Gas for publish operations only."),
521
+ })
522
+ .optional()
523
+ .describe("Gas cost estimate for deploying all objects."),
524
+ persisted: z
525
+ .object({
526
+ all_files: z
527
+ .array(z.string())
528
+ .describe("Project-relative paths of all generated files (27 total)."),
529
+ all_stages_passed: z
530
+ .boolean()
531
+ .describe("Whether all 5 stage gates passed validation."),
532
+ })
533
+ .optional()
534
+ .describe("Nested-autonomy doc set persistence result (§11). Present when the doc set was successfully written to disk."),
370
535
  can_proceed: z
371
536
  .boolean()
372
537
  .describe("Whether the user can proceed to stage 5. False when D-errors exist."),
@@ -374,6 +539,7 @@ const GenerateDeploymentDocResultSchema = z
374
539
  .enum(["trace_substeps", "fix_doc_errors", "none"])
375
540
  .describe("Next project_operation action. 'trace_substeps' when can_proceed=true; 'fix_doc_errors' when D-errors exist; 'none' for other cases."),
376
541
  user_action_required: z.string(),
542
+ gate_validation: GateValidationSchema,
377
543
  })
378
544
  .strict();
379
545
  const TraceSubstepsResultSchema = z
@@ -427,6 +593,488 @@ const TraceSubstepsResultSchema = z
427
593
  .enum(["deploy", "fix_substeps", "none"])
428
594
  .describe("Next action. 'deploy' when can_proceed=true (execute substeps via onchain_operations); 'fix_substeps' when issues exist; 'none' when done."),
429
595
  user_action_required: z.string(),
596
+ gate_validation: GateValidationSchema,
597
+ })
598
+ .strict();
599
+ const GetProjectStatusResultSchema = z
600
+ .object({
601
+ action: z.literal("get_project_status"),
602
+ project: z.string(),
603
+ version: z.string(),
604
+ stage: z.number().int().min(1).max(5),
605
+ stage_name: z.string(),
606
+ stage_description: z.string(),
607
+ next_action: z.string().describe("The next project_operation action to call."),
608
+ can_proceed: z.boolean(),
609
+ last_updated: z.number().int().optional().describe("Timestamp of last stage update (ms)."),
610
+ risk_status: z.string().optional(),
611
+ risk_can_proceed: z.boolean().optional(),
612
+ doc_generated: z.boolean().optional(),
613
+ trace_coherent: z.boolean().optional(),
614
+ })
615
+ .strict();
616
+ const LoadProjectListItemSchema = z.object({
617
+ prefix: z.string(),
618
+ version: z.string(),
619
+ dir_name: z.string(),
620
+ initialized: z.boolean(),
621
+ archived: z.boolean(),
622
+ needs_migration: z.boolean().describe("Whether schema_version differs from current."),
623
+ forked_from: z.string().optional(),
624
+ chain_exists: z.boolean().describe("Whether the project prefix exists on-chain."),
625
+ sync_status: z
626
+ .enum(["synced", "local_only", "archived", "uninitialized"])
627
+ .describe("Cross-validation of local filesystem vs chain truth."),
628
+ });
629
+ const LoadProjectResultSchema = z
630
+ .object({
631
+ action: z.literal("load_project"),
632
+ items: z.array(LoadProjectListItemSchema).optional(),
633
+ total: z.number().int().optional(),
634
+ project: z.string().optional(),
635
+ version: z.string().optional(),
636
+ local_exists: z.boolean().optional(),
637
+ manifest: z
638
+ .object({
639
+ schema_version: z.string(),
640
+ mcp_version: z.string(),
641
+ prefix: z.string(),
642
+ version: z.string(),
643
+ created_at: z.string(),
644
+ updated_at: z.string(),
645
+ forked_from: z.string().optional(),
646
+ needs_recalibration: z.boolean().optional(),
647
+ })
648
+ .optional(),
649
+ stage_state: z
650
+ .object({
651
+ stage: z.number().int().min(1).max(5),
652
+ updated_at: z.number().int(),
653
+ has_published_object: z.boolean(),
654
+ archived: z.boolean(),
655
+ })
656
+ .partial()
657
+ .optional(),
658
+ sync_status: z
659
+ .object({
660
+ local_exists: z.boolean(),
661
+ initialized: z.boolean(),
662
+ needs_migration: z.boolean(),
663
+ archived: z.boolean(),
664
+ })
665
+ .optional(),
666
+ migration: z
667
+ .object({
668
+ migrated: z.boolean().describe("Whether a migration was performed."),
669
+ from_version: z.string(),
670
+ to_version: z.string(),
671
+ steps_executed: z.array(z.string()),
672
+ backup_path: z.string().optional(),
673
+ needs_recalibration: z.boolean(),
674
+ message: z.string(),
675
+ })
676
+ .optional(),
677
+ message: z.string().optional(),
678
+ })
679
+ .strict();
680
+ const ForkProjectResultSchema = z
681
+ .object({
682
+ action: z.literal("fork_project"),
683
+ new_prefix: z.string(),
684
+ new_version: z.string(),
685
+ new_path: z.string().describe("Absolute filesystem path of the new project directory."),
686
+ forked_from: z
687
+ .string()
688
+ .describe("Absolute path of the source project directory."),
689
+ copied_files: z
690
+ .array(z.string())
691
+ .describe("Project-relative paths of copied files (excludes stage.json + audit.jsonl)."),
692
+ copied_file_count: z.number().int(),
693
+ warning: z
694
+ .string()
695
+ .describe("Project isolation notice — forked project must re-create its own objects."),
696
+ next_action: z
697
+ .literal("analyze_intent")
698
+ .describe("The forked project starts at stage 2 (analyze_intent)."),
699
+ })
700
+ .strict();
701
+ const ExportProjectResultSchema = z
702
+ .object({
703
+ action: z.literal("export_project"),
704
+ project: z.string(),
705
+ version: z.string(),
706
+ files: z.array(z.object({
707
+ path: z.string().describe("Project-relative file path."),
708
+ size: z.number().int().describe("File size in bytes."),
709
+ kind: z.enum(["json", "markdown", "jsonl", "other"]),
710
+ content: z.string().describe("File content (text)."),
711
+ })),
712
+ total_files: z.number().int(),
713
+ })
714
+ .strict();
715
+ const GetProjectFilesResultSchema = z
716
+ .object({
717
+ action: z.literal("get_project_files"),
718
+ project: z.string(),
719
+ version: z.string(),
720
+ files: z.array(z.object({
721
+ path: z.string().describe("Project-relative file path."),
722
+ size: z.number().int().describe("File size in bytes."),
723
+ kind: z.enum(["json", "markdown", "jsonl", "other"]),
724
+ mtime: z.number().int().describe("Last modified time (ms)."),
725
+ })),
726
+ total_files: z.number().int(),
727
+ })
728
+ .strict();
729
+ const ValidateStageUnitResultSchema = z
730
+ .object({
731
+ action: z.literal("validate_stage_unit"),
732
+ project: z.string(),
733
+ version: z.string(),
734
+ stage: z.number().int().min(1).max(5),
735
+ valid: z
736
+ .boolean()
737
+ .describe("True when all 4 stage unit files exist and pass consistency checks."),
738
+ missing_files: z
739
+ .array(z.string())
740
+ .describe("Project-relative paths of missing stage unit files (empty if all present)."),
741
+ checks: z.array(z.object({
742
+ check_id: z.string(),
743
+ status: z.enum(["pass", "fail", "warn"]),
744
+ message: z.string(),
745
+ })),
746
+ blocking_issues: z.array(z.string()),
747
+ stage_passed: z
748
+ .boolean()
749
+ .optional()
750
+ .describe("From verification.json stage_passed field (undefined if file missing)."),
751
+ })
752
+ .strict();
753
+ const GetStageAssessmentResultSchema = z
754
+ .object({
755
+ action: z.literal("get_stage_assessment"),
756
+ project: z.string(),
757
+ version: z.string(),
758
+ stage: z.number().int().min(1).max(5),
759
+ found: z.boolean(),
760
+ assessment: z
761
+ .object({
762
+ stage: z.number().int().min(1).max(5),
763
+ assessed_at: z.number().int(),
764
+ goal_completion: z.record(z.number()),
765
+ findings: z.array(z.object({
766
+ finding_id: z.string(),
767
+ severity: z.enum(["info", "warn", "critical"]),
768
+ criterion_id: z.string(),
769
+ description: z.string(),
770
+ evidence: z.unknown(),
771
+ })),
772
+ recommendations: z.array(z.string()),
773
+ })
774
+ .optional()
775
+ .describe("The stage assessment object (from assessment.json)."),
776
+ })
777
+ .strict();
778
+ const GetStageRiskPolicyResultSchema = z
779
+ .object({
780
+ action: z.literal("get_stage_risk_policy"),
781
+ project: z.string(),
782
+ version: z.string(),
783
+ stage: z.number().int().min(1).max(5),
784
+ found: z.boolean(),
785
+ risk_policy: z
786
+ .object({
787
+ stage: z.number().int().min(1).max(5),
788
+ risks: z.array(z.object({
789
+ risk_id: z.string(),
790
+ category: z.enum([
791
+ "naming",
792
+ "dependency",
793
+ "operational",
794
+ "financial",
795
+ "security",
796
+ ]),
797
+ description: z.string(),
798
+ likelihood: z.enum(["low", "medium", "high"]),
799
+ impact: z.enum(["low", "medium", "high", "critical"]),
800
+ mitigation: z.string(),
801
+ owner: z.enum(["ai", "user", "system"]),
802
+ })),
803
+ active_controls: z.array(z.object({
804
+ control_id: z.string(),
805
+ control_type: z.enum(["preventive", "detective", "corrective"]),
806
+ target_risk: z.string(),
807
+ implementation: z.string(),
808
+ verified: z.boolean(),
809
+ })),
810
+ residual_risks: z.array(z.string()),
811
+ })
812
+ .optional()
813
+ .describe("The stage risk policy object (from risk-policy.json)."),
814
+ })
815
+ .strict();
816
+ const GetDocRelationsResultSchema = z
817
+ .object({
818
+ action: z.literal("get_doc_relations"),
819
+ project: z.string(),
820
+ version: z.string(),
821
+ found: z.boolean(),
822
+ relations: z
823
+ .object({
824
+ version: z.string(),
825
+ generated_at: z.number().int(),
826
+ project_invariants: z.array(z.object({
827
+ invariant_id: z.string(),
828
+ description: z.string(),
829
+ verified_by_stages: z.array(z.number().int()),
830
+ })),
831
+ stage_units: z.array(z.object({
832
+ stage: z.number().int().min(1).max(5),
833
+ goal_id: z.string(),
834
+ assessment_id: z.string(),
835
+ risk_policy_id: z.string(),
836
+ verification_id: z.string(),
837
+ artifacts: z.array(z.string()),
838
+ })),
839
+ derivations: z.array(z.object({
840
+ source_type: z.enum(["project_invariant", "project_goal"]),
841
+ source_id: z.string(),
842
+ target_type: z.enum(["stage_goal", "stage_risk", "stage_verification"]),
843
+ target_stage: z.number().int().min(1).max(5),
844
+ target_id: z.string(),
845
+ derivation_logic: z.string(),
846
+ })),
847
+ propagation_rules: z.array(z.object({
848
+ rule_id: z.string(),
849
+ trigger: z.object({
850
+ stage: z.number().int(),
851
+ event: z.enum(["verification_passed", "verification_failed"]),
852
+ }),
853
+ effect: z.object({
854
+ target: z.enum(["project_invariant", "next_stage"]),
855
+ action: z.enum(["verify", "block"]),
856
+ }),
857
+ })),
858
+ impact_map: z.record(z.array(z.string())),
859
+ })
860
+ .optional()
861
+ .describe("The validation chain graph (from relations.json)."),
862
+ })
863
+ .strict();
864
+ const UpdateDeploymentDocResultSchema = z
865
+ .object({
866
+ action: z.literal("update_deployment_doc"),
867
+ project: z.string(),
868
+ version: z.string(),
869
+ updated: z.boolean().describe("Whether the deployment doc set was regenerated."),
870
+ updated_files: z
871
+ .array(z.string())
872
+ .describe("Project-relative paths of regenerated files."),
873
+ updated_file_count: z.number().int(),
874
+ all_stages_passed: z
875
+ .boolean()
876
+ .describe("Whether all stages passed their D-checks after the update."),
877
+ impact_summary: z
878
+ .object({
879
+ stages_affected: z.array(z.number().int()).describe("Stage numbers whose content changed."),
880
+ relations_rebuilt: z.boolean().describe("Whether relations.json was regenerated."),
881
+ })
882
+ .describe("Summary of what changed (based on relations.json impact analysis)."),
883
+ next_action: z
884
+ .enum(["validate_validation_chain", "trace_substeps", "none"])
885
+ .describe("Next action: validate the chain after update, or proceed to trace_substeps."),
886
+ })
887
+ .strict();
888
+ const ValidateValidationChainResultSchema = z
889
+ .object({
890
+ action: z.literal("validate_validation_chain"),
891
+ project: z.string(),
892
+ version: z.string(),
893
+ valid: z
894
+ .boolean()
895
+ .describe("True when derivation, propagation, cross-stage, and impact-map checks all pass."),
896
+ derivation_checks: z.array(z.object({
897
+ check_id: z.string(),
898
+ status: z.enum(["pass", "fail", "warn"]),
899
+ message: z.string(),
900
+ })),
901
+ propagation_checks: z.array(z.object({
902
+ check_id: z.string(),
903
+ status: z.enum(["pass", "fail", "warn"]),
904
+ message: z.string(),
905
+ })),
906
+ cross_stage_checks: z.array(z.object({
907
+ check_id: z.string(),
908
+ status: z.enum(["pass", "fail", "warn"]),
909
+ message: z.string(),
910
+ })),
911
+ impact_map_checks: z.array(z.object({
912
+ check_id: z.string(),
913
+ status: z.enum(["pass", "fail", "warn"]),
914
+ message: z.string(),
915
+ })),
916
+ blocking_issues: z.array(z.string()),
917
+ warnings: z.array(z.string()),
918
+ })
919
+ .strict();
920
+ const ApplyImprovementResultSchema = z
921
+ .object({
922
+ action: z.literal("apply_improvement"),
923
+ proposal_id: z.string(),
924
+ previous_status: z.string(),
925
+ new_status: z.string(),
926
+ applied: z
927
+ .boolean()
928
+ .describe("Whether the proposal was applied (true for approved+config_override, true for approved+source_patch producing patch file)."),
929
+ apply_mode: z.enum(["config_override", "source_patch"]),
930
+ override_file: z
931
+ .string()
932
+ .optional()
933
+ .describe("Path of the override file written (config_override only)."),
934
+ patch_file: z
935
+ .string()
936
+ .optional()
937
+ .describe("Path of the patch file written (source_patch only)."),
938
+ message: z.string(),
939
+ next_action: z
940
+ .enum(["get_improvement_queue", "get_flywheel_config", "none"])
941
+ .describe("Next action: check more proposals or view flywheel status."),
942
+ })
943
+ .strict();
944
+ const GetImprovementQueueResultSchema = z
945
+ .object({
946
+ action: z.literal("get_improvement_queue"),
947
+ total: z.number().int(),
948
+ filtered_count: z.number().int(),
949
+ proposals: z.array(z.object({
950
+ proposal_id: z.string(),
951
+ source_diagnosis_id: z.string(),
952
+ type: z.string(),
953
+ priority: z.string(),
954
+ automation: z.enum(["full", "semi", "manual"]),
955
+ apply_mode: z.enum(["config_override", "source_patch"]),
956
+ override_category: z.string().optional(),
957
+ title: z.string(),
958
+ description: z.string(),
959
+ target: z.string(),
960
+ review_status: z.enum(["pending", "approved", "rejected", "applied"]),
961
+ ab_test_recommended: z.boolean(),
962
+ persisted_at: z.string().optional(),
963
+ reviewed_at: z.string().optional(),
964
+ })),
965
+ summary: z.string(),
966
+ })
967
+ .strict();
968
+ const GetFlywheelConfigResultSchema = z
969
+ .object({
970
+ action: z.literal("get_flywheel_config"),
971
+ queue_path: z.string(),
972
+ overrides_dir: z.string(),
973
+ patches_dir: z.string(),
974
+ total_proposals: z.number().int(),
975
+ pending_count: z.number().int(),
976
+ approved_count: z.number().int(),
977
+ applied_count: z.number().int(),
978
+ rejected_count: z.number().int(),
979
+ override_files: z.array(z.string()),
980
+ recent_proposals: z.array(z.object({
981
+ proposal_id: z.string(),
982
+ type: z.string(),
983
+ priority: z.string(),
984
+ review_status: z.enum(["pending", "approved", "rejected", "applied"]),
985
+ title: z.string(),
986
+ })),
987
+ reflow_status: z
988
+ .enum(["active", "idle", "blocked"])
989
+ .describe("active=pending proposals exist; idle=no proposals; blocked=approved but not applied."),
990
+ })
991
+ .strict();
992
+ const RollbackStageResultSchema = z
993
+ .object({
994
+ action: z.literal("rollback_stage"),
995
+ success: z.boolean().describe("Whether the rollback was executed (or would be, if dry_run=false)."),
996
+ dry_run: z.boolean().describe("Whether this was a policy evaluation only (no execution)."),
997
+ target_stage: z.number().int().min(1).max(5),
998
+ previous_stage: z.number().int().min(1).max(5),
999
+ allowed: z.boolean().describe("Whether the rollback is allowed by policy."),
1000
+ block_reason: z.string().optional().describe("Present when allowed=false — explains why rollback is blocked."),
1001
+ files_to_clean: z
1002
+ .array(z.string())
1003
+ .describe("Files/directories that will be (or were) deleted during rollback."),
1004
+ files_cleaned: z
1005
+ .array(z.string())
1006
+ .describe("Files/directories actually deleted (empty in dry_run mode)."),
1007
+ warnings: z.array(z.string()).describe("Non-blocking warnings (e.g., data loss reminder)."),
1008
+ iteration_strategy: z.object({
1009
+ strategy: z.enum(["in_place", "fork"]),
1010
+ reason: z.string(),
1011
+ fork_to_version: z.string().optional(),
1012
+ published_objects: z.array(z.string()).optional(),
1013
+ }),
1014
+ message: z.string().describe("Human-readable summary."),
1015
+ })
1016
+ .strict();
1017
+ const GetReversibilityResultSchema = z
1018
+ .object({
1019
+ action: z.literal("get_reversibility"),
1020
+ query: z
1021
+ .object({
1022
+ object_type: z.string().optional(),
1023
+ lifecycle_state: z.string().optional(),
1024
+ })
1025
+ .describe("The query parameters used (empty = full matrix returned)."),
1026
+ entries: z.array(z.object({
1027
+ object_type: z.string(),
1028
+ lifecycle_state: z.enum(["created", "referenced", "published", "bound"]),
1029
+ struct_reversible: z.enum(["reversible", "limited", "immutable"]),
1030
+ behavior_reversible: z.boolean(),
1031
+ gas_impact: z.enum(["low", "medium", "high", "none"]),
1032
+ explanation: z.string(),
1033
+ })),
1034
+ total: z.number().int().describe("Number of matrix entries returned."),
1035
+ })
1036
+ .strict();
1037
+ const AssembleContextResultSchema = z
1038
+ .object({
1039
+ action: z.literal("assemble_context"),
1040
+ objects: z
1041
+ .array(z.unknown())
1042
+ .describe("Current on-chain states of the requested objects (from query_objects)."),
1043
+ events: z
1044
+ .array(z.unknown())
1045
+ .optional()
1046
+ .describe("Recent state-transition events (only when include_events=true). " +
1047
+ "Includes NewOrderEvent, ProgressEvent, ArbEvent, etc."),
1048
+ embedded_history: z
1049
+ .record(z.string(), z.unknown())
1050
+ .optional()
1051
+ .describe("Operation history extracted from object states — NOT from tx queries. " +
1052
+ "Progress objects: session.forwards (who did what, when, accomplished). " +
1053
+ "Order objects: disputes, claimed_by, progress_object. " +
1054
+ "This is the CORRECT history source: convergent, no infinite recursion."),
1055
+ semantic_summary: z
1056
+ .unknown()
1057
+ .optional()
1058
+ .describe("Business semantic annotations generated by buildDataSemantic — " +
1059
+ "maps raw object fields to business-meaningful concepts for LLM consumption."),
1060
+ context_digest: z
1061
+ .string()
1062
+ .describe("Unique digest for this assembled context (SHA of object IDs + versions + timestamp). " +
1063
+ "Use for caching or to detect state changes between two assembly calls."),
1064
+ next_action: z
1065
+ .string()
1066
+ .describe("Suggested next action: use onchain_transaction to verify a specific past tx, " +
1067
+ "or proceed with onchain_operations to modify state, or re-call assemble_context " +
1068
+ "after state changes."),
1069
+ flywheel_collected: z
1070
+ .object({
1071
+ signature_recorded: z.boolean().describe("Whether the experience signature was recorded in the real-time experience layer."),
1072
+ proposal_created: z.boolean().describe("Whether an improvement proposal was created for the offline distillation flywheel."),
1073
+ proposal_id: z.string().optional().describe("The proposal ID, if created."),
1074
+ })
1075
+ .optional()
1076
+ .describe("Distillation flywheel collection result. Non-blocking — may be undefined if collection fails. " +
1077
+ "When present, the assembled context has been fed back into the experience layer and/or improvement queue."),
430
1078
  })
431
1079
  .strict();
432
1080
  export const ProjectOperationOutputSchema = z
@@ -465,6 +1113,23 @@ export const ProjectOperationOutputSchema = z
465
1113
  AggregateRisksResultSchema,
466
1114
  GenerateDeploymentDocResultSchema,
467
1115
  TraceSubstepsResultSchema,
1116
+ GetProjectStatusResultSchema,
1117
+ LoadProjectResultSchema,
1118
+ ForkProjectResultSchema,
1119
+ ExportProjectResultSchema,
1120
+ GetProjectFilesResultSchema,
1121
+ ValidateStageUnitResultSchema,
1122
+ GetStageAssessmentResultSchema,
1123
+ GetStageRiskPolicyResultSchema,
1124
+ GetDocRelationsResultSchema,
1125
+ UpdateDeploymentDocResultSchema,
1126
+ ValidateValidationChainResultSchema,
1127
+ ApplyImprovementResultSchema,
1128
+ GetImprovementQueueResultSchema,
1129
+ GetFlywheelConfigResultSchema,
1130
+ RollbackStageResultSchema,
1131
+ GetReversibilityResultSchema,
1132
+ AssembleContextResultSchema,
468
1133
  ]).describe("Query result — shape depends on action"),
469
1134
  })
470
1135
  .strict();