@wowok/agent-mcp 2.5.4 → 2.5.5

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 (53) hide show
  1. package/README.md +33 -26
  2. package/dist/knowledge/reward-confirm.d.ts +3 -0
  3. package/dist/knowledge/reward-confirm.js +30 -0
  4. package/dist/knowledge/reward-puzzle.d.ts +1 -0
  5. package/dist/knowledge/reward-puzzle.js +12 -0
  6. package/dist/knowledge/reward-risk.d.ts +4 -1
  7. package/dist/knowledge/reward-risk.js +85 -3
  8. package/dist/knowledge/tools-reference.js +5 -4
  9. package/dist/project/evaluation.d.ts +53 -0
  10. package/dist/project/evaluation.js +853 -0
  11. package/dist/project/graph-builder.d.ts +43 -0
  12. package/dist/project/graph-builder.js +572 -0
  13. package/dist/project/handlers.d.ts +152 -0
  14. package/dist/project/handlers.js +458 -0
  15. package/dist/project/index.d.ts +1 -0
  16. package/dist/project/index.js +24 -1
  17. package/dist/project/query.d.ts +1 -0
  18. package/dist/project/query.js +2 -0
  19. package/dist/project/semantic-assembler.d.ts +93 -0
  20. package/dist/project/semantic-assembler.js +345 -0
  21. package/dist/schema/call/base.js +1 -1
  22. package/dist/schema/project/index.d.ts +1558 -3885
  23. package/dist/schema/project/index.js +357 -961
  24. package/dist/schema/trust/index.d.ts +14 -14
  25. package/dist/schemas/bridge_operation.schema.json +1 -1
  26. package/dist/schemas/guard2file.schema.json +1 -1
  27. package/dist/schemas/index.json +2 -2
  28. package/dist/schemas/machineNode2file.schema.json +1 -1
  29. package/dist/schemas/onchain_operations.schema.json +5 -5
  30. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  31. package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
  32. package/dist/schemas/onchain_operations_contact.schema.json +1 -1
  33. package/dist/schemas/onchain_operations_demand.schema.json +1 -1
  34. package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -2
  35. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -2
  36. package/dist/schemas/onchain_operations_guard.schema.json +1 -1
  37. package/dist/schemas/onchain_operations_machine.schema.json +1 -1
  38. package/dist/schemas/onchain_operations_order.schema.json +1 -1
  39. package/dist/schemas/onchain_operations_payment.schema.json +1 -1
  40. package/dist/schemas/onchain_operations_permission.schema.json +1 -1
  41. package/dist/schemas/onchain_operations_personal.schema.json +1 -1
  42. package/dist/schemas/onchain_operations_progress.schema.json +1 -1
  43. package/dist/schemas/onchain_operations_proof.schema.json +1 -1
  44. package/dist/schemas/onchain_operations_repository.schema.json +1 -1
  45. package/dist/schemas/onchain_operations_reward.schema.json +1 -1
  46. package/dist/schemas/onchain_operations_service.schema.json +1 -1
  47. package/dist/schemas/onchain_operations_treasury.schema.json +1 -1
  48. package/dist/schemas/project_operation.output.json +975 -2471
  49. package/dist/schemas/project_operation.schema.json +207 -534
  50. package/dist/tools/handlers/onchain.js +97 -19
  51. package/dist/tools/handlers/project.js +34 -1046
  52. package/dist/tools/index.js +84 -55
  53. package/package.json +2 -2
@@ -47,1088 +47,484 @@ export const EdgeKindEnum = z.enum([
47
47
  "sub_order",
48
48
  "references",
49
49
  ]);
50
- const PuzzleEntrySchema = z
51
- .object({
52
- puzzle: z
53
- .record(z.unknown())
54
- .describe("Per-object puzzle snapshot. Shape varies per object_type — see knowledge/<obj>-puzzle.ts."),
55
- completeness: z
56
- .record(z.unknown())
57
- .describe("Completeness assessment from checkPuzzleCompleteness(). Shape varies per object."),
58
- missing_dimensions: z
59
- .array(z.string())
60
- .describe("Dimensions still missing for this object (e.g. ['A','B'])."),
61
- })
62
- .strict();
63
50
  export const ProjectOperationInputSchema = z
64
51
  .object({
65
52
  action: z
66
53
  .enum([
67
54
  "list_projects",
68
- "list_objects",
69
- "shareable",
70
- "dependencies",
71
- "referenced_by",
72
- "pre_publish_check",
73
- "cross_project_refs",
74
- "graph_stats",
75
- "save_graph",
76
- "load_graph",
77
- "analyze_intent",
78
- "aggregate_risks",
79
- "generate_deployment_doc",
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",
55
+ "create_project",
56
+ "create_project_from_onchain",
57
+ "update_project",
58
+ "get_project_detail",
59
+ "add_object",
60
+ "remove_object",
61
+ "update_object",
62
+ "create_version",
63
+ "build_graph",
64
+ "get_graph",
65
+ "evaluate_project",
66
+ "save_evaluation",
67
+ "compare_projects",
68
+ "refresh_objects",
69
+ "get_object_diff",
70
+ "delete_project",
97
71
  "assemble_context",
98
72
  ])
99
- .describe("Action to perform. Six categories:\n" +
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" +
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)."),
73
+ .describe("Action to perform. Two categories:\n" +
74
+ "1. Project Entity + Evaluation (15, GLM6): list_projects, create_project, create_project_from_onchain, update_project, get_project_detail, add_object, remove_object, create_version, build_graph, get_graph, evaluate_project, save_evaluation, compare_projects, refresh_objects, get_object_diff. Projects are first-class entities with SQLite persistence, rigid project-object relationships, three-pathway graph construction, and a dual rule-based + LLM-assisted evaluation engine.\n" +
75
+ "2. Context Assembly (1): assemble_context (query on-chain object states + extract embedded history + optional events, and assemble a structured semantic context for LLM consumption). Required input: context_objects (array of object IDs/names). Optional: include_events (query recent state-transition events)."),
107
76
  project: z
108
77
  .string()
109
78
  .optional()
110
- .describe("Project prefix (for list_objects and C1-C4 actions)"),
79
+ .describe("Project prefix (human-readable unique identifier). Used by create_version, build_graph, evaluate_project, etc. Takes precedence resolution: project_id > project (prefix)."),
111
80
  version: z
112
81
  .string()
113
82
  .regex(/^v\d+$/)
114
83
  .optional()
115
- .describe("Project version (e.g. 'v1'). Required for C1-C4 actions."),
116
- object: z
117
- .string()
84
+ .describe("Project version (e.g. 'v1'). Used by create_version."),
85
+ context_objects: z
86
+ .array(z.string())
118
87
  .optional()
119
- .describe("Object name or address (for dependencies / referenced_by / pre_publish_check)"),
120
- fork_to_version: z
121
- .string()
122
- .regex(/^v\d+$/)
88
+ .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."),
89
+ include_events: z
90
+ .boolean()
123
91
  .optional()
124
- .describe("Target version for fork_project (e.g. 'v2'). Must differ from source 'version'."),
125
- fork_to_prefix: z
126
- .string()
92
+ .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."),
93
+ context_network: z
94
+ .enum(["testnet", "mainnet"])
95
+ .optional()
96
+ .describe("Network for assemble_context queries. Defaults to 'testnet' if omitted."),
97
+ filter_status: z
98
+ .enum(["draft", "active", "inactive", "archived"])
127
99
  .optional()
128
- .describe("Target prefix for fork_project. Defaults to source 'project' prefix when omitted."),
129
- user_intent: z
100
+ .describe("Filter list_projects by project status."),
101
+ filter_perspective: z
102
+ .enum(["producer", "consumer", "both"])
103
+ .optional()
104
+ .describe("Filter list_projects by project perspective."),
105
+ filter_network: z
106
+ .enum(["testnet", "mainnet"])
107
+ .optional()
108
+ .describe("Filter list_projects by network."),
109
+ project_name: z
130
110
  .string()
131
111
  .min(1)
112
+ .max(200)
113
+ .optional()
114
+ .describe("Display name for create_project / create_project_from_onchain / update_project. Required when action='create_project'."),
115
+ project_description: z
116
+ .string()
132
117
  .max(2000)
133
118
  .optional()
134
- .describe("Natural-language business intent for analyze_intent (stage 2). Required when action='analyze_intent'."),
135
- industry: IndustryEnum.optional().describe("Industry hint — drives template defaults. Used by analyze_intent and aggregate_risks."),
136
- target_objects: z
119
+ .describe("Project description for create_project / update_project."),
120
+ project_industry: IndustryEnum.optional().describe("Industry tag for create_project. Drives template defaults."),
121
+ project_perspective: z
122
+ .enum(["producer", "consumer", "both"])
123
+ .optional()
124
+ .describe("Project perspective for create_project. 'producer' = build/operate services, 'consumer' = evaluate/buy services, 'both' = dual role. Defaults to 'producer'."),
125
+ project_labels: z
137
126
  .array(z.string())
138
127
  .optional()
139
- .describe("Optional explicit target objects (entry_ids or object_type names) for analyze_intent."),
140
- puzzles: z
141
- .record(z.string(), PuzzleEntrySchema)
128
+ .describe("Free-form labels for create_project / update_project (e.g. ['travel','london','priority'])."),
129
+ service_address: z
130
+ .string()
131
+ .optional()
132
+ .describe("On-chain Service object address. Required for create_project_from_onchain. Optional for create_project (links the project to its core Service)."),
133
+ project_network: z
134
+ .enum(["testnet", "mainnet"])
142
135
  .optional()
143
- .describe("Per-object puzzle snapshots keyed by object_type. Required for aggregate_risks and generate_deployment_doc."),
144
- severity_threshold: z
145
- .enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"])
136
+ .describe("Network the project is bound to. A Service deployed to different networks are different projects. Defaults to 'testnet'."),
137
+ project_id: z
138
+ .string()
146
139
  .optional()
147
- .describe("Severity threshold for aggregate_risks. Risks at or above this level are flagged."),
148
- user_confirmed_high_risks: z
149
- .array(z.string())
140
+ .describe("Project UUID for update_project / get_project_detail / add_object / remove_object / create_version / build_graph / evaluate_project / refresh_objects. Takes precedence over 'project' (prefix) when both are given."),
141
+ project_status: z
142
+ .enum(["draft", "active", "inactive", "archived"])
150
143
  .optional()
151
- .describe("IDs of HIGH risks the user has already confirmed (suppressed in subsequent aggregate_risks)."),
152
- business_intent: z
144
+ .describe("New status for update_project. 'active' projects are live, 'archived' are read-only."),
145
+ object_address: z
153
146
  .string()
154
- .min(1)
155
- .max(500)
156
147
  .optional()
157
- .describe("One-line business intent description for the deployment doc. Required when action='generate_deployment_doc'."),
158
- author: z
148
+ .describe("On-chain object address (0x...) for add_object / remove_object. For add_object, alternatively use object_name to resolve via LocalMark."),
149
+ object_name_add: z
159
150
  .string()
160
151
  .optional()
161
- .describe("Optional author name for the deployment doc meta section."),
162
- objects: z
163
- .array(z
164
- .object({
165
- entry_id: z.string().describe("Stable id '<object_type>:<name>'"),
166
- object_type: ProjectObjectTypeEnum,
167
- name: z.string(),
168
- reused_from: z
169
- .string()
170
- .optional()
171
- .describe("Existing on-chain address or local name if reused"),
172
- publish_required: z
173
- .boolean()
174
- .describe("Whether publish is required (only Service/Machine)"),
175
- description: z.string().optional(),
176
- })
177
- .strict())
152
+ .describe("LocalMark name for add_object (alternative to object_address)."),
153
+ object_type_add: z
154
+ .enum([
155
+ "Service", "Machine", "Guard", "Permission", "Reward", "Arbitration",
156
+ "Progress", "Treasury", "Demand", "Repository", "Contact", "Order",
157
+ "Allocation", "Personal", "Payment", "Proof",
158
+ ])
178
159
  .optional()
179
- .describe("Deployment objects for generate_deployment_doc."),
180
- edges: z
181
- .array(z
182
- .object({
183
- from: z.string(),
184
- to: z.string(),
185
- edge_kind: EdgeKindEnum,
186
- field_path: z.string(),
187
- required_at_publish: z.boolean(),
188
- })
189
- .strict())
160
+ .describe("Object type for add_object."),
161
+ object_role: z
162
+ .enum(["core", "dependency", "reference"])
190
163
  .optional()
191
- .describe("Dependency graph edges for generate_deployment_doc."),
192
- steps: z
193
- .array(z
194
- .object({
195
- step: z.number().int().positive(),
196
- object_type: ProjectObjectTypeEnum,
197
- operation: z.string(),
198
- substep_count: z.number().int().nonnegative(),
199
- depends_on: z.array(z.number().int()),
200
- entry_id: z.string(),
201
- network_phase: z.enum(["testnet", "mainnet", "both"]),
202
- })
203
- .strict())
164
+ .describe("Object role in project for add_object. 'core' = the Service (only one per project), 'dependency' = required binding, 'reference' = optional/auxiliary. Defaults to 'reference'."),
165
+ object_tags_add: z
166
+ .array(z.string())
204
167
  .optional()
205
- .describe("Topological execution plan for generate_deployment_doc."),
206
- scenarios: z
207
- .array(z
208
- .object({
209
- scenario_id: z.string(),
210
- description: z.string(),
211
- primary_object: z.string(),
212
- supporting_objects: z.array(z.string()),
213
- test_step_refs: z.array(z.string()).optional(),
214
- })
215
- .strict())
168
+ .describe("Tags for add_object."),
169
+ object_id_remove: z
170
+ .string()
216
171
  .optional()
217
- .describe("Business scenarios for generate_deployment_doc §7."),
218
- risk_status: z
219
- .enum(["RISK_PASSED", "RISK_BLOCKED", "RISK_PENDING_CONFIRM", "RISK_CANCELLED"])
172
+ .describe("ProjectObject UUID for remove_object (the project_objects.id, NOT the on-chain address)."),
173
+ object_id_update: z
174
+ .string()
220
175
  .optional()
221
- .describe("Risk status from aggregate_risks (for D-16 check)."),
222
- risk_critical_count: z
223
- .number()
224
- .int()
225
- .nonnegative()
176
+ .describe("ProjectObject UUID for update_object (the project_objects.id)."),
177
+ object_name_update: z
178
+ .string()
226
179
  .optional()
227
- .describe("CRITICAL risk count from aggregate_risks."),
228
- risk_high_count: z
229
- .number()
230
- .int()
231
- .nonnegative()
180
+ .describe("New name for update_object."),
181
+ object_type_update: z
182
+ .string()
232
183
  .optional()
233
- .describe("HIGH risk count from aggregate_risks."),
234
- run_scanner: z
235
- .boolean()
184
+ .describe("New type for update_object."),
185
+ object_role_update: z
186
+ .enum(["core", "dependency", "reference"])
236
187
  .optional()
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
- })
188
+ .describe("New role for update_object."),
189
+ object_tags_update: z
190
+ .array(z.string())
258
191
  .optional()
259
- .describe("Gas budget input for stage 4/5 gate (§3.5). Non-blocking; only surfaces a WARN on mainnet."),
260
- network: z
261
- .enum(["testnet", "mainnet"])
192
+ .describe("New tags for update_object."),
193
+ version_description: z
194
+ .string()
195
+ .max(500)
262
196
  .optional()
263
- .describe("Target network for trace_substeps."),
264
- substeps: z
265
- .array(z
266
- .object({
267
- step_id: z.string().regex(/^T\d+\.\d+$/),
268
- parent_step: z.string().regex(/^T\d+$/),
269
- object_type: ProjectObjectTypeEnum,
270
- entry_id: z.string(),
271
- operation_type: z.string(),
272
- network: z.enum(["testnet", "mainnet"]),
273
- input: z.object({
274
- data: z.record(z.unknown()),
275
- input_refs: z.array(z.string()),
276
- }),
277
- output: z
278
- .object({
279
- object_id: z.string().optional(),
280
- tx_digest: z.string().optional(),
281
- })
282
- .partial()
283
- .optional(),
284
- timestamp: z.number().int(),
285
- status: z.enum(["PENDING", "SUCCESS", "FAILED", "SKIPPED"]),
286
- failure_reason: z.string().optional(),
287
- dependencies: z.object({
288
- input_refs: z.array(z.string()),
289
- output_refs: z.array(z.object({
290
- substep_id: z.string(),
291
- field_path: z.string(),
292
- })),
293
- }),
294
- retry_info: z
295
- .object({
296
- original_step_id: z.string(),
297
- retry_count: z.number().int().nonnegative(),
298
- retry_reason: z.string(),
299
- })
300
- .optional(),
301
- })
302
- .strict())
197
+ .describe("Description for create_version."),
198
+ fork_from_version: z
199
+ .string()
303
200
  .optional()
304
- .describe("Substep records for trace_substeps."),
305
- target_stage: z
201
+ .describe("Source version for create_version (fork objects + graph from this version)."),
202
+ max_depth: z
306
203
  .number()
307
204
  .int()
308
205
  .min(1)
309
206
  .max(5)
310
207
  .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"])
208
+ .describe("Max recursion depth for Pathway 1 (internal reference derivation) in build_graph. Default 3."),
209
+ enable_registrar: z
210
+ .boolean()
322
211
  .optional()
323
- .describe("Filter the improvement queue by review_status (for get_improvement_queue)."),
324
- queue_filter_type: z
325
- .string()
212
+ .describe("Enable Pathway 2 (Registrar inbound query) in build_graph. Default true."),
213
+ enable_potential: z
214
+ .boolean()
326
215
  .optional()
327
- .describe("Filter the improvement queue by proposal type (for get_improvement_queue)."),
328
- queue_filter_priority: z
329
- .string()
216
+ .describe("Enable Pathway 3 (potential relationship detection) in build_graph. Default false."),
217
+ evaluation_type: z
218
+ .enum(["risk", "trust", "completeness", "value", "worth_buying"])
330
219
  .optional()
331
- .describe("Filter the improvement queue by priority P0/P1/P2/P3 (for get_improvement_queue)."),
332
- dry_run: z
220
+ .describe("Evaluation type for evaluate_project. risk/trust/completeness are rule-based (computed locally). worth_buying/value require LLM assistance (returns a prompt for the caller to process)."),
221
+ refresh_before_eval: z
333
222
  .boolean()
334
223
  .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
224
+ .describe("When true, evaluate_project refreshes object cache from chain before evaluating. Default false."),
225
+ eval_score: z
226
+ .number()
227
+ .min(0)
228
+ .max(100)
229
+ .optional()
230
+ .describe("Overall evaluation score (0-100) for save_evaluation."),
231
+ eval_summary: z
337
232
  .string()
233
+ .max(1000)
338
234
  .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"])
235
+ .describe("Evaluation summary for save_evaluation."),
236
+ eval_details: z
237
+ .record(z.unknown())
342
238
  .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
239
+ .describe("Structured evaluation details for save_evaluation (criterion_scores, findings, etc.)."),
240
+ compare_project_ids: z
345
241
  .array(z.string())
242
+ .min(2)
346
243
  .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()
244
+ .describe("Array of project IDs to compare (for compare_projects). Minimum 2."),
245
+ diff_address: z
246
+ .string()
350
247
  .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"])
248
+ .describe("Object address for get_object_diff."),
249
+ diff_from_time: z
250
+ .number()
251
+ .int()
354
252
  .optional()
355
- .describe("Network for assemble_context queries. Defaults to 'testnet' if omitted."),
356
- })
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).");
380
- const ItemsResult = (action) => z.object({
381
- action: z.literal(action),
382
- items: z
383
- .array(z.record(z.unknown()))
384
- .describe("List of result items. Each item is an untyped record — shape varies per query."),
385
- });
386
- const AnalyzeIntentResultSchema = z
387
- .object({
388
- action: z.literal("analyze_intent"),
389
- intent_parsed: z.object({
390
- primary_object: z.string(),
391
- secondary_objects: z.array(z.string()),
392
- detected_scenes: z.array(z.object({
393
- object: z.string(),
394
- scene_id: z.string(),
395
- })),
396
- industry: z.string(),
397
- keyword_matches: z.array(z.object({
398
- keyword: z.string(),
399
- category: z.string(),
400
- matched_objects: z.array(z.string()),
401
- required_level: z.enum(["R", "C", "OPTIONAL"]),
402
- match_count: z.number().int(),
403
- })),
404
- }),
405
- puzzles: z.record(z.string(), PuzzleEntrySchema),
406
- overall_completeness: z.enum(["complete", "partial", "empty"]),
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'])."),
411
- next_action: z
412
- .enum(["aggregate_risks", "none"])
413
- .describe("Next project_operation action to call. 'aggregate_risks' when puzzles are complete enough; 'none' if user must fill missing fields first."),
414
- warnings: z.array(z.string()),
415
- gate_validation: GateValidationSchema,
416
- })
417
- .strict();
418
- const AggregateRisksResultSchema = z
419
- .object({
420
- action: z.literal("aggregate_risks"),
421
- namespace: z.object({
422
- prefix: z.string(),
423
- version: z.string(),
424
- industry: z.string().optional(),
425
- }),
426
- findings: z.array(z.object({
427
- risk_rule_id: z.string(),
428
- object_type: z.string(),
429
- entry_id: z.string(),
430
- severity: z.enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]),
431
- message: z.string(),
432
- fix_suggestion: z.string(),
433
- details: z
434
- .object({
435
- field_path: z.string().optional(),
436
- rule_source: z.string().optional(),
437
- })
438
- .partial()
439
- .optional(),
440
- })),
441
- severity_summary: z.object({
442
- CRITICAL: z.number().int(),
443
- HIGH: z.number().int(),
444
- MEDIUM: z.number().int(),
445
- LOW: z.number().int(),
446
- INFO: z.number().int(),
447
- }),
448
- status: z.enum([
449
- "RISK_PASSED",
450
- "RISK_BLOCKED",
451
- "RISK_PENDING_CONFIRM",
452
- "RISK_CANCELLED",
453
- ]),
454
- pending_confirmations: z
455
- .array(z.object({
456
- risk_rule_id: z.string(),
457
- description: z.string(),
458
- fix_suggestion: z.string(),
459
- object_type: z.string(),
460
- entry_id: z.string(),
461
- }))
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
- })))
253
+ .describe("Start timestamp (ms) for get_object_diff."),
254
+ diff_to_time: z
255
+ .number()
256
+ .int()
471
257
  .optional()
472
- .describe("Fix suggestions grouped by object_type for better readability."),
473
- calibrated_at: z.number().int(),
474
- warnings: z.array(z.string()),
475
- can_proceed: z
476
- .boolean()
477
- .describe("Whether the user can proceed to the next stage. False only when CRITICAL risks exist."),
478
- next_action: z
479
- .enum(["generate_deployment_doc", "fix_risks", "none"])
480
- .describe("Next project_operation action. 'generate_deployment_doc' when can_proceed=true; 'fix_risks' when CRITICAL risks exist; 'none' for other cases."),
481
- user_action_required: z
482
- .string()
483
- .describe("Human-readable next-step guidance."),
484
- gate_validation: GateValidationSchema,
258
+ .describe("End timestamp (ms) for get_object_diff."),
485
259
  })
486
260
  .strict();
487
- const GenerateDeploymentDocResultSchema = z
261
+ const AssembleContextResultSchema = z
488
262
  .object({
489
- action: z.literal("generate_deployment_doc"),
490
- markdown: z.string().describe("Complete deployment MD document (§0-§7)"),
491
- meta: z.object({
492
- project_prefix: z.string(),
493
- version: z.string(),
494
- generated_at: z.string().describe("ISO timestamp"),
495
- object_count: z.number().int(),
496
- step_count: z.number().int(),
497
- }),
498
- validation: z
499
- .object({
500
- valid: z.boolean(),
501
- checks: z.array(z.object({
502
- check_id: z.string(),
503
- description: z.string(),
504
- status: z.enum(["PASS", "FAIL", "WARN"]),
505
- notes: z.string().optional(),
506
- })),
507
- errors: z.array(z.string()),
508
- })
263
+ action: z.literal("assemble_context"),
264
+ objects: z
265
+ .array(z.unknown())
266
+ .describe("Current on-chain states of the requested objects (from query_objects)."),
267
+ events: z
268
+ .array(z.unknown())
509
269
  .optional()
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
- })
270
+ .describe("Recent state-transition events (only when include_events=true). " +
271
+ "Includes NewOrderEvent, ProgressEvent, ArbEvent, etc."),
272
+ embedded_history: z
273
+ .record(z.string(), z.unknown())
522
274
  .optional()
523
- .describe("Gas cost estimate for deploying all objects."),
524
- persisted: z
275
+ .describe("Operation history extracted from object states — NOT from tx queries. " +
276
+ "Progress objects: session.forwards (who did what, when, accomplished). " +
277
+ "Order objects: disputes, claimed_by, progress_object. " +
278
+ "This is the CORRECT history source: convergent, no infinite recursion."),
279
+ semantic_summary: z
280
+ .unknown()
281
+ .optional()
282
+ .describe("Business semantic annotations generated by buildDataSemantic — " +
283
+ "maps raw object fields to business-meaningful concepts for LLM consumption."),
284
+ context_digest: z
285
+ .string()
286
+ .describe("Unique digest for this assembled context (SHA of object IDs + versions + timestamp). " +
287
+ "Use for caching or to detect state changes between two assembly calls."),
288
+ next_action: z
289
+ .string()
290
+ .describe("Suggested next action: use onchain_transaction to verify a specific past tx, " +
291
+ "or proceed with onchain_operations to modify state, or re-call assemble_context " +
292
+ "after state changes."),
293
+ flywheel_collected: z
525
294
  .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."),
295
+ signature_recorded: z.boolean().describe("Whether the experience signature was recorded in the real-time experience layer."),
296
+ proposal_created: z.boolean().describe("Whether an improvement proposal was created for the offline distillation flywheel."),
297
+ proposal_id: z.string().optional().describe("The proposal ID, if created."),
532
298
  })
533
299
  .optional()
534
- .describe("Nested-autonomy doc set persistence result (§11). Present when the doc set was successfully written to disk."),
535
- can_proceed: z
536
- .boolean()
537
- .describe("Whether the user can proceed to stage 5. False when D-errors exist."),
538
- next_action: z
539
- .enum(["trace_substeps", "fix_doc_errors", "none"])
540
- .describe("Next project_operation action. 'trace_substeps' when can_proceed=true; 'fix_doc_errors' when D-errors exist; 'none' for other cases."),
541
- user_action_required: z.string(),
542
- gate_validation: GateValidationSchema,
300
+ .describe("Distillation flywheel collection result. Non-blocking — may be undefined if collection fails. " +
301
+ "When present, the assembled context has been fed back into the experience layer and/or improvement queue."),
543
302
  })
544
303
  .strict();
545
- const TraceSubstepsResultSchema = z
304
+ const ProjectObjectSchema = z
546
305
  .object({
547
- action: z.literal("trace_substeps"),
548
- namespace: z.object({
549
- prefix: z.string(),
550
- version: z.string(),
551
- }),
552
- network: z.enum(["testnet", "mainnet"]),
553
- coherent: z
554
- .boolean()
555
- .describe("True when no dangling/circular/missing/cross-step issues."),
556
- dangling_inputs: z.array(z.object({
557
- substep_id: z.string(),
558
- missing_ref: z.string(),
559
- field_path: z.string(),
560
- })),
561
- circular_refs: z.array(z.object({
562
- cycle: z.array(z.string()),
563
- })),
564
- missing_outputs: z.array(z.object({
565
- substep_id: z.string(),
566
- expected_field: z.string(),
567
- dependent_substeps: z.array(z.string()),
568
- })),
569
- cross_step_breaks: z.array(z.object({
570
- source_step: z.string(),
571
- target_step: z.string(),
572
- missing_field: z.string(),
573
- })),
574
- step_details: z.array(z.object({
575
- parent_step: z.string(),
576
- total_substeps: z.number().int(),
577
- successful: z.number().int(),
578
- failed: z.number().int(),
579
- pending: z.number().int(),
580
- skipped: z.number().int(),
581
- substep_ids: z.array(z.string()),
582
- })),
583
- topological_order: z.array(z.string()),
584
- d10_check: z.object({
585
- check_id: z.literal("D-10"),
586
- description: z.string(),
587
- status: z.enum(["PASS", "FAIL", "WARN"]),
588
- }),
589
- can_proceed: z
590
- .boolean()
591
- .describe("Whether deployment can complete. False when D-10 fails or substeps FAILED."),
592
- next_action: z
593
- .enum(["deploy", "fix_substeps", "none"])
594
- .describe("Next action. 'deploy' when can_proceed=true (execute substeps via onchain_operations); 'fix_substeps' when issues exist; 'none' when done."),
595
- user_action_required: z.string(),
596
- gate_validation: GateValidationSchema,
306
+ id: z.string().describe("ProjectObject UUID (project_objects.id)."),
307
+ projectId: z.string().describe("Owning project UUID."),
308
+ objectAddress: z.string().describe("On-chain object address (0x...)."),
309
+ objectType: z.string().nullable().describe("Object type (Service, Machine, etc.) or null if unknown."),
310
+ objectName: z.string().nullable().describe("LocalMark name or null."),
311
+ role: z.enum(["core", "dependency", "reference"]).describe("Object role in project."),
312
+ tags: z.array(z.string()).nullable().describe("Tags array or null."),
313
+ addedAt: z.number().describe("Timestamp (ms) when added to project."),
314
+ metadata: z.record(z.unknown()).nullable().describe("Arbitrary metadata key-value pairs or null."),
597
315
  })
598
316
  .strict();
599
- const GetProjectStatusResultSchema = z
317
+ const ProjectSchema = z
600
318
  .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(),
319
+ id: z.string().describe("Project UUID."),
320
+ prefix: z.string().describe("Human-readable unique prefix."),
321
+ name: z.string().describe("Display name."),
322
+ description: z.string().nullable(),
323
+ industry: z.string().nullable(),
324
+ perspective: z.enum(["producer", "consumer", "both"]),
325
+ status: z.enum(["draft", "active", "inactive", "archived"]),
326
+ labels: z.array(z.string()).nullable(),
327
+ currentVersion: z.string().nullable().describe("Current version tag (e.g. 'v1')."),
328
+ serviceAddress: z.string().nullable().describe("Core Service on-chain address (producer projects)."),
329
+ defaultAccount: z.string().nullable(),
330
+ network: z.string().describe("Network the project is bound to."),
331
+ createdAt: z.number(),
332
+ updatedAt: z.number(),
333
+ metadata: z.record(z.unknown()).nullable().describe("Arbitrary metadata key-value pairs or null."),
614
334
  })
615
335
  .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."),
336
+ const ProjectListItemSchema = ProjectSchema.extend({
337
+ objectCount: z.number().describe("Number of objects in this project (from project_objects table)."),
338
+ objectTypes: z.array(z.string()).describe("Distinct object types in this project (e.g. ['Service','Machine'])."),
628
339
  });
629
- const LoadProjectResultSchema = z
340
+ const ListProjectsResultSchema = z
630
341
  .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(),
342
+ action: z.literal("list_projects"),
343
+ items: z.array(ProjectListItemSchema).describe("GLM6 projects from SQLite (first-class entities, with object summary)."),
344
+ total: z.number().describe("Total number of projects returned."),
678
345
  })
679
346
  .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
- })
347
+ const CreateProjectResultSchema = z
348
+ .object({ action: z.literal("create_project"), project: ProjectSchema.describe("The created project.") })
700
349
  .strict();
701
- const ExportProjectResultSchema = z
350
+ const CreateProjectFromOnchainResultSchema = z
702
351
  .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(),
352
+ action: z.literal("create_project_from_onchain"),
353
+ project: ProjectSchema.describe("The created consumer project."),
354
+ objects: z.array(ProjectObjectSchema).describe("Objects discovered from on-chain Service + graph traversal."),
355
+ graphEdgeCount: z.number().describe("Number of relationship edges discovered and persisted."),
713
356
  })
714
357
  .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
- })
358
+ const UpdateProjectResultSchema = z
359
+ .object({ action: z.literal("update_project"), project: ProjectSchema.describe("The updated project.") })
728
360
  .strict();
729
- const ValidateStageUnitResultSchema = z
361
+ const GetProjectDetailResultSchema = z
730
362
  .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)."),
363
+ action: z.literal("get_project_detail"),
364
+ project: ProjectSchema,
365
+ objects: z.array(ProjectObjectSchema).describe("Project objects (rigid relationships)."),
366
+ graphEdgeCount: z.number().describe("Number of persisted graph edges."),
367
+ evaluations: z
368
+ .array(z.object({
369
+ id: z.string(),
370
+ evalType: z.enum(["risk", "trust", "completeness", "value", "worth_buying"]),
371
+ score: z.number().nullable(),
372
+ summary: z.string().nullable(),
373
+ evaluatedAt: z.number(),
374
+ }).strict())
375
+ .describe("Stored evaluation results (most recent first)."),
376
+ versions: z
377
+ .array(z.object({
378
+ version: z.string(),
379
+ description: z.string().nullable(),
380
+ createdAt: z.number(),
381
+ }).strict())
382
+ .describe("Project version history."),
751
383
  })
752
384
  .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
- })
385
+ const AddObjectResultSchema = z
386
+ .object({ action: z.literal("add_object"), object: ProjectObjectSchema.describe("The added project-object relationship.") })
387
+ .strict();
388
+ const RemoveObjectResultSchema = z
389
+ .object({ action: z.literal("remove_object"), removed: z.literal(true).describe("Always true — confirms removal.") })
777
390
  .strict();
778
- const GetStageRiskPolicyResultSchema = z
391
+ const UpdateObjectResultSchema = z
779
392
  .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)."),
393
+ action: z.literal("update_object"),
394
+ object: ProjectObjectSchema.describe("The updated project-object relationship."),
814
395
  })
815
396
  .strict();
816
- const GetDocRelationsResultSchema = z
397
+ const CreateVersionResultSchema = z
817
398
  .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)."),
399
+ action: z.literal("create_version"),
400
+ version: z.object({
401
+ version: z.string().describe("Version tag (e.g. 'v2')."),
402
+ description: z.string().nullable(),
403
+ createdAt: z.number(),
404
+ }).strict(),
862
405
  })
863
406
  .strict();
864
- const UpdateDeploymentDocResultSchema = z
407
+ const BuildGraphResultSchema = z
865
408
  .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."),
409
+ action: z.literal("build_graph"),
410
+ nodeCount: z.number().describe("Total nodes in the constructed graph."),
411
+ edgeCount: z.number().describe("Total edges (after conflict resolution + dedup)."),
412
+ edgesBySource: z.record(z.string(), z.number()).describe("Edge counts by source: { internal: N, registrar: N, potential: N }."),
413
+ reputationCount: z.number().describe("Number of objects with Registrar reputation data."),
414
+ builtAt: z.number().describe("Build timestamp (ms)."),
886
415
  })
887
416
  .strict();
888
- const ValidateValidationChainResultSchema = z
417
+ const GetGraphResultSchema = z
889
418
  .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()),
419
+ action: z.literal("get_graph"),
420
+ edges: z.array(z.object({
421
+ sourceObject: z.string(),
422
+ targetObject: z.string(),
423
+ edgeSource: z.enum(["internal", "registrar", "potential"]),
424
+ relationshipType: z.string(),
425
+ fieldName: z.string().nullable(),
426
+ depth: z.number(),
427
+ verified: z.boolean(),
428
+ weight: z.number(),
429
+ direction: z.string().nullable(),
430
+ }).strict()).describe("Persisted graph edges."),
918
431
  })
919
432
  .strict();
920
- const ApplyImprovementResultSchema = z
433
+ const EvaluateProjectResultSchema = z
921
434
  .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."),
435
+ action: z.literal("evaluate_project"),
436
+ evaluationType: z.enum(["risk", "trust", "completeness", "value", "worth_buying"]),
437
+ score: z.number().describe("Overall score (0-100, higher = better). 0 when needsLlm=true."),
438
+ summary: z.string(),
439
+ criterionScores: z.array(z.object({
440
+ name: z.string(), score: z.number(), weight: z.number(), rationale: z.string(),
441
+ }).strict()).describe("Per-criterion scores. Empty when needsLlm=true."),
442
+ findings: z.array(z.object({
443
+ criterion: z.string(),
444
+ severity: z.enum(["critical", "warning", "info"]),
445
+ message: z.string(),
446
+ deduction: z.number(),
447
+ }).strict()).describe("Negative findings (deductions). Empty when needsLlm=true."),
448
+ strengths: z.array(z.string()).describe("Positive evidence. Empty when needsLlm=true."),
449
+ needsLlm: z.boolean().describe("True for worth_buying/value evaluations. When true, process the llmPrompt with an LLM and call save_evaluation to store the result."),
450
+ llmPrompt: z.string().optional().describe("Present when needsLlm=true. Send this prompt to an LLM, parse the JSON response, and call save_evaluation."),
451
+ evaluationId: z.string().describe("ID of the stored evaluation record (for rule-based types). Empty for LLM-assisted types."),
942
452
  })
943
453
  .strict();
944
- const GetImprovementQueueResultSchema = z
454
+ const SaveEvaluationResultSchema = z
945
455
  .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(),
456
+ action: z.literal("save_evaluation"),
457
+ evaluation: z.object({
458
+ id: z.string(),
459
+ evalType: z.enum(["risk", "trust", "completeness", "value", "worth_buying"]),
460
+ score: z.number().nullable(),
461
+ summary: z.string().nullable(),
462
+ evaluatedAt: z.number(),
463
+ }).strict().describe("The stored evaluation record."),
966
464
  })
967
465
  .strict();
968
- const GetFlywheelConfigResultSchema = z
466
+ const CompareProjectsResultSchema = z
969
467
  .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."),
468
+ action: z.literal("compare_projects"),
469
+ evaluationType: z.enum(["risk", "trust", "completeness", "value", "worth_buying"]),
470
+ ranking: z.array(z.object({
471
+ projectId: z.string(),
472
+ projectName: z.string(),
473
+ score: z.number().nullable(),
474
+ summary: z.string().nullable(),
475
+ evaluatedAt: z.number().nullable(),
476
+ }).strict()).describe("Projects sorted by score descending (nulls last)."),
477
+ bestProjectId: z.string().nullable().describe("Project ID with the highest score, or null if none have evaluations."),
990
478
  })
991
479
  .strict();
992
- const RollbackStageResultSchema = z
480
+ const RefreshObjectsResultSchema = z
993
481
  .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."),
482
+ action: z.literal("refresh_objects"),
483
+ refreshedCount: z.number().describe("Number of objects re-fetched from chain."),
484
+ failedCount: z.number().describe("Number of objects that failed to refresh."),
485
+ refreshedAt: z.number().describe("Refresh timestamp (ms)."),
1015
486
  })
1016
487
  .strict();
1017
- const GetReversibilityResultSchema = z
488
+ const DeleteProjectResultSchema = z
1018
489
  .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."),
490
+ action: z.literal("delete_project"),
491
+ deleted: z.literal(true).describe("Always true — confirms deletion of the project and all associated objects, evaluations, versions, and graph edges."),
1035
492
  })
1036
493
  .strict();
1037
- const AssembleContextResultSchema = z
494
+ const GetObjectDiffResultSchema = z
1038
495
  .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."),
496
+ action: z.literal("get_object_diff"),
497
+ address: z.string(),
498
+ fromTime: z.number(),
499
+ toTime: z.number(),
500
+ changedFields: z.array(z.object({
501
+ fieldPath: z.string().describe("Dotted field path (e.g. 'machine', 'sales[0].price')."),
502
+ oldValue: z.unknown().describe("Previous value (null if field was added)."),
503
+ newValue: z.unknown().describe("New value (null if field was removed)."),
504
+ changeType: z.enum(["added", "removed", "modified"]),
505
+ }).strict()).describe("Changed fields between the two timestamps."),
1078
506
  })
1079
507
  .strict();
1080
508
  export const ProjectOperationOutputSchema = z
1081
509
  .object({
1082
510
  result: z.discriminatedUnion("action", [
1083
- ItemsResult("list_projects"),
1084
- ItemsResult("list_objects"),
1085
- ItemsResult("shareable"),
1086
- ItemsResult("dependencies"),
1087
- ItemsResult("referenced_by"),
1088
- z.object({
1089
- action: z.literal("pre_publish_check"),
1090
- warnings: z
1091
- .array(z.string())
1092
- .describe("Pre-publish warnings. Empty array means no issues detected."),
1093
- }),
1094
- ItemsResult("cross_project_refs"),
1095
- z.object({
1096
- action: z.literal("graph_stats"),
1097
- stats: z
1098
- .record(z.unknown())
1099
- .describe("Object dependency graph statistics (counts, depth, etc.)."),
1100
- }),
1101
- z.object({
1102
- action: z.literal("save_graph"),
1103
- saved: z.literal(true).describe("Always true — confirms the graph was saved."),
1104
- path: z.string().describe("Filesystem path where the graph was saved."),
1105
- }),
1106
- z.object({
1107
- action: z.literal("load_graph"),
1108
- loaded: z
1109
- .boolean()
1110
- .describe("Whether the graph was successfully loaded from disk."),
1111
- }),
1112
- AnalyzeIntentResultSchema,
1113
- AggregateRisksResultSchema,
1114
- GenerateDeploymentDocResultSchema,
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,
511
+ ListProjectsResultSchema,
512
+ CreateProjectResultSchema,
513
+ CreateProjectFromOnchainResultSchema,
514
+ UpdateProjectResultSchema,
515
+ GetProjectDetailResultSchema,
516
+ AddObjectResultSchema,
517
+ RemoveObjectResultSchema,
518
+ UpdateObjectResultSchema,
519
+ CreateVersionResultSchema,
520
+ BuildGraphResultSchema,
521
+ GetGraphResultSchema,
522
+ EvaluateProjectResultSchema,
523
+ SaveEvaluationResultSchema,
524
+ CompareProjectsResultSchema,
525
+ RefreshObjectsResultSchema,
526
+ GetObjectDiffResultSchema,
527
+ DeleteProjectResultSchema,
1132
528
  AssembleContextResultSchema,
1133
529
  ]).describe("Query result — shape depends on action"),
1134
530
  })