@wowok/agent-mcp 2.3.13 → 2.3.16

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 (194) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/config/runtime.d.ts +26 -0
  4. package/dist/config/runtime.js +217 -0
  5. package/dist/customer/industry-risks.d.ts +36 -0
  6. package/dist/customer/industry-risks.js +424 -0
  7. package/dist/customer/info-puzzle.d.ts +102 -0
  8. package/dist/customer/info-puzzle.js +312 -0
  9. package/dist/customer/order-monitor.d.ts +75 -0
  10. package/dist/customer/order-monitor.js +327 -0
  11. package/dist/customer/order-strategy.d.ts +36 -0
  12. package/dist/customer/order-strategy.js +373 -0
  13. package/dist/customer/post-purchase.d.ts +42 -0
  14. package/dist/customer/post-purchase.js +350 -0
  15. package/dist/customer/reminder-system.d.ts +42 -0
  16. package/dist/customer/reminder-system.js +295 -0
  17. package/dist/customer/risk-assessment.d.ts +8 -0
  18. package/dist/customer/risk-assessment.js +337 -0
  19. package/dist/customer/types.d.ts +193 -0
  20. package/dist/customer/types.js +13 -0
  21. package/dist/customer/user-preferences.d.ts +67 -0
  22. package/dist/customer/user-preferences.js +451 -0
  23. package/dist/experience/experience-reuse.d.ts +10 -0
  24. package/dist/experience/experience-reuse.js +103 -0
  25. package/dist/experience/index.d.ts +6 -0
  26. package/dist/experience/index.js +5 -0
  27. package/dist/experience/intent-distill.d.ts +3 -0
  28. package/dist/experience/intent-distill.js +83 -0
  29. package/dist/experience/realtime-feedback.d.ts +5 -0
  30. package/dist/experience/realtime-feedback.js +77 -0
  31. package/dist/experience/types.d.ts +50 -0
  32. package/dist/experience/types.js +1 -0
  33. package/dist/experience/user-profile.d.ts +25 -0
  34. package/dist/experience/user-profile.js +171 -0
  35. package/dist/harness/checkpoint.d.ts +8 -0
  36. package/dist/harness/checkpoint.js +129 -0
  37. package/dist/harness/index.d.ts +33 -0
  38. package/dist/harness/index.js +75 -0
  39. package/dist/harness/plan.d.ts +18 -0
  40. package/dist/harness/plan.js +252 -0
  41. package/dist/harness/recover.d.ts +17 -0
  42. package/dist/harness/recover.js +139 -0
  43. package/dist/harness/types.d.ts +137 -0
  44. package/dist/harness/types.js +1 -0
  45. package/dist/harness/verify.d.ts +42 -0
  46. package/dist/harness/verify.js +237 -0
  47. package/dist/index.js +667 -201
  48. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  49. package/dist/knowledge/acquisition-flywheel.js +183 -0
  50. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  51. package/dist/knowledge/arbitration-trust.js +117 -0
  52. package/dist/knowledge/audit-rules.d.ts +28 -0
  53. package/dist/knowledge/audit-rules.js +141 -0
  54. package/dist/knowledge/demand-matching.d.ts +29 -0
  55. package/dist/knowledge/demand-matching.js +132 -0
  56. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  57. package/dist/knowledge/dynamic-pricing.js +87 -0
  58. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  59. package/dist/knowledge/flywheel-loop.js +378 -0
  60. package/dist/knowledge/glossary.d.ts +18 -0
  61. package/dist/knowledge/glossary.js +209 -0
  62. package/dist/knowledge/index.d.ts +64 -0
  63. package/dist/knowledge/index.js +66 -0
  64. package/dist/knowledge/industry-evolution.d.ts +82 -0
  65. package/dist/knowledge/industry-evolution.js +323 -0
  66. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  67. package/dist/knowledge/industry-generalizer.js +381 -0
  68. package/dist/knowledge/industry-registry.d.ts +49 -0
  69. package/dist/knowledge/industry-registry.js +167 -0
  70. package/dist/knowledge/intent-metrics.d.ts +42 -0
  71. package/dist/knowledge/intent-metrics.js +566 -0
  72. package/dist/knowledge/process-model.d.ts +24 -0
  73. package/dist/knowledge/process-model.js +160 -0
  74. package/dist/knowledge/reputation-rules.d.ts +42 -0
  75. package/dist/knowledge/reputation-rules.js +99 -0
  76. package/dist/knowledge/reward-templates.d.ts +25 -0
  77. package/dist/knowledge/reward-templates.js +125 -0
  78. package/dist/knowledge/safety-rules.d.ts +36 -0
  79. package/dist/knowledge/safety-rules.js +171 -0
  80. package/dist/knowledge/tool-constraints.d.ts +30 -0
  81. package/dist/knowledge/tool-constraints.js +185 -0
  82. package/dist/knowledge/trust-metrics.d.ts +37 -0
  83. package/dist/knowledge/trust-metrics.js +138 -0
  84. package/dist/loop-engineering/aggregate.d.ts +50 -0
  85. package/dist/loop-engineering/aggregate.js +132 -0
  86. package/dist/loop-engineering/diagnose.d.ts +22 -0
  87. package/dist/loop-engineering/diagnose.js +273 -0
  88. package/dist/loop-engineering/improve.d.ts +26 -0
  89. package/dist/loop-engineering/improve.js +229 -0
  90. package/dist/loop-engineering/index.d.ts +4 -0
  91. package/dist/loop-engineering/index.js +4 -0
  92. package/dist/loop-engineering/pipeline.d.ts +17 -0
  93. package/dist/loop-engineering/pipeline.js +56 -0
  94. package/dist/mode-market/index.d.ts +3 -0
  95. package/dist/mode-market/index.js +3 -0
  96. package/dist/mode-market/registry.d.ts +53 -0
  97. package/dist/mode-market/registry.js +124 -0
  98. package/dist/mode-market/review.d.ts +27 -0
  99. package/dist/mode-market/review.js +214 -0
  100. package/dist/mode-market/submission.d.ts +25 -0
  101. package/dist/mode-market/submission.js +85 -0
  102. package/dist/project/graph.d.ts +71 -0
  103. package/dist/project/graph.js +314 -0
  104. package/dist/project/index.d.ts +62 -0
  105. package/dist/project/index.js +167 -0
  106. package/dist/project/namespace.d.ts +62 -0
  107. package/dist/project/namespace.js +181 -0
  108. package/dist/project/query.d.ts +40 -0
  109. package/dist/project/query.js +110 -0
  110. package/dist/safety/confirm-gate.d.ts +15 -0
  111. package/dist/safety/confirm-gate.js +44 -0
  112. package/dist/safety/index.d.ts +3 -0
  113. package/dist/safety/index.js +3 -0
  114. package/dist/safety/preview.d.ts +2 -0
  115. package/dist/safety/preview.js +36 -0
  116. package/dist/schema/call/allocation.d.ts +55 -40
  117. package/dist/schema/call/arbitration.d.ts +201 -186
  118. package/dist/schema/call/base.d.ts +2104 -24
  119. package/dist/schema/call/base.js +168 -22
  120. package/dist/schema/call/bridge-handler.js +36 -18
  121. package/dist/schema/call/bridge.d.ts +777 -120
  122. package/dist/schema/call/bridge.js +13 -2
  123. package/dist/schema/call/contact.d.ts +15 -0
  124. package/dist/schema/call/demand.d.ts +69 -54
  125. package/dist/schema/call/guard.d.ts +125 -80
  126. package/dist/schema/call/handler.d.ts +5 -1
  127. package/dist/schema/call/handler.js +108 -3
  128. package/dist/schema/call/index.d.ts +1 -0
  129. package/dist/schema/call/index.js +1 -0
  130. package/dist/schema/call/machine.d.ts +830 -800
  131. package/dist/schema/call/order.d.ts +27 -12
  132. package/dist/schema/call/payment.d.ts +15 -0
  133. package/dist/schema/call/permission.d.ts +15 -0
  134. package/dist/schema/call/personal.d.ts +15 -0
  135. package/dist/schema/call/progress.d.ts +21 -6
  136. package/dist/schema/call/proof.d.ts +42 -12
  137. package/dist/schema/call/proof.js +3 -3
  138. package/dist/schema/call/repository.d.ts +91 -76
  139. package/dist/schema/call/reward.d.ts +51 -36
  140. package/dist/schema/call/semantic.d.ts +24 -0
  141. package/dist/schema/call/semantic.js +981 -0
  142. package/dist/schema/call/service.d.ts +444 -429
  143. package/dist/schema/call/treasury.d.ts +219 -204
  144. package/dist/schema/common/index.js +3 -3
  145. package/dist/schema/local/index.d.ts +341 -74
  146. package/dist/schema/local/index.js +44 -7
  147. package/dist/schema/messenger/index.d.ts +1034 -92
  148. package/dist/schema/messenger/index.js +18 -0
  149. package/dist/schema/operations.d.ts +2634 -1817
  150. package/dist/schema/operations.js +16 -5
  151. package/dist/schema/query/index.d.ts +2293 -2289
  152. package/dist/schema/query/index.js +34 -28
  153. package/dist/schemas/account_operation.output.json +28 -16
  154. package/dist/schemas/account_operation.schema.json +2 -2
  155. package/dist/schemas/bridge_operation.output.json +520 -0
  156. package/dist/schemas/bridge_operation.schema.json +15 -0
  157. package/dist/schemas/guard2file.schema.json +15 -0
  158. package/dist/schemas/index.json +1 -1
  159. package/dist/schemas/local_info_operation.output.json +26 -0
  160. package/dist/schemas/local_info_operation.schema.json +1 -1
  161. package/dist/schemas/local_mark_operation.output.json +27 -1
  162. package/dist/schemas/local_mark_operation.schema.json +4 -4
  163. package/dist/schemas/machineNode2file.schema.json +15 -0
  164. package/dist/schemas/messenger_operation.output.json +549 -0
  165. package/dist/schemas/messenger_operation.schema.json +21 -0
  166. package/dist/schemas/onchain_events.output.json +3 -0
  167. package/dist/schemas/onchain_operations.output.json +814 -37
  168. package/dist/schemas/onchain_operations.schema.json +117 -40
  169. package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
  170. package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
  171. package/dist/schemas/onchain_operations_contact.schema.json +26 -9
  172. package/dist/schemas/onchain_operations_demand.schema.json +26 -9
  173. package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
  174. package/dist/schemas/onchain_operations_guard.schema.json +26 -9
  175. package/dist/schemas/onchain_operations_machine.schema.json +92 -32
  176. package/dist/schemas/onchain_operations_order.schema.json +26 -9
  177. package/dist/schemas/onchain_operations_payment.schema.json +26 -9
  178. package/dist/schemas/onchain_operations_permission.schema.json +26 -9
  179. package/dist/schemas/onchain_operations_personal.schema.json +26 -9
  180. package/dist/schemas/onchain_operations_progress.schema.json +26 -9
  181. package/dist/schemas/onchain_operations_repository.schema.json +26 -9
  182. package/dist/schemas/onchain_operations_reward.schema.json +26 -9
  183. package/dist/schemas/onchain_operations_service.schema.json +26 -9
  184. package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
  185. package/dist/schemas/onchain_table_data.output.json +224 -69
  186. package/dist/schemas/onchain_table_data.schema.json +2 -2
  187. package/dist/schemas/query_toolkit.schema.json +5 -1
  188. package/dist/telemetry/index.d.ts +19 -0
  189. package/dist/telemetry/index.js +112 -0
  190. package/dist/telemetry/redact.d.ts +2 -0
  191. package/dist/telemetry/redact.js +23 -0
  192. package/dist/telemetry/storage.d.ts +8 -0
  193. package/dist/telemetry/storage.js +80 -0
  194. package/package.json +6 -3
@@ -0,0 +1,252 @@
1
+ export const SCENARIO_REGISTRY = [
2
+ {
3
+ name: "freelance",
4
+ keywords: ["freelance", "service", "deliverable", "client", "gig", "consult", "design", "develop"],
5
+ description: "Service delivery with escrow: publish → order → deliver → accept → withdraw",
6
+ default_permissions: { provider: 1000, customer: "namedOperator", arbiter: 1500 },
7
+ objects: [
8
+ { type: "Permission", reversible: true, dependencies: [], user_decisions: ["reuse existing or create new?"], estimated_time: "2min" },
9
+ { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "description", "token_type"], estimated_time: "3min" },
10
+ { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["state graph", "operators"], estimated_time: "10min" },
11
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["guard table", "submission fields"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
12
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["refund guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
13
+ { type: "Allocation", reversible: true, dependencies: ["Service", "Guard"], user_decisions: ["sharing ratios", "allocators"], estimated_time: "5min" },
14
+ ],
15
+ phases: [
16
+ { name: "Foundation", object_types: ["Permission", "Service"] },
17
+ { name: "Business Logic", object_types: ["Machine"] },
18
+ { name: "Trust Layer", object_types: ["Guard"] },
19
+ { name: "Revenue", object_types: ["Allocation"] },
20
+ { name: "Publish", object_types: ["Service"] },
21
+ ],
22
+ },
23
+ {
24
+ name: "rental",
25
+ keywords: ["rent", "rental", "lease", "property", "item", "deposit", "tenant", "landlord"],
26
+ description: "Item rental with deposit: publish → rent → inspect → return/refund",
27
+ default_permissions: { provider: 1000, customer: "namedOperator", arbiter: 1500 },
28
+ objects: [
29
+ { type: "Permission", reversible: true, dependencies: [], user_decisions: ["reuse existing or create new?"], estimated_time: "2min" },
30
+ { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "deposit amount", "rental terms"], estimated_time: "3min" },
31
+ { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["rental states", "return/inspect flow"], estimated_time: "10min" },
32
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["return guard", "damage guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
33
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["refund guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
34
+ { type: "Allocation", reversible: true, dependencies: ["Service", "Guard"], user_decisions: ["deposit/refund allocation", "damage compensation"], estimated_time: "5min" },
35
+ ],
36
+ phases: [
37
+ { name: "Foundation", object_types: ["Permission", "Service"] },
38
+ { name: "Business Logic", object_types: ["Machine"] },
39
+ { name: "Trust Layer", object_types: ["Guard"] },
40
+ { name: "Revenue", object_types: ["Allocation"] },
41
+ { name: "Publish", object_types: ["Service"] },
42
+ ],
43
+ },
44
+ {
45
+ name: "digital_goods",
46
+ keywords: ["digital", "download", "ebook", "software", "license", "instant", "content"],
47
+ description: "Instant digital delivery: publish → buy → instant delivery",
48
+ default_permissions: { provider: 1000, customer: "namedOperator" },
49
+ objects: [
50
+ { type: "Permission", reversible: true, dependencies: [], estimated_time: "2min" },
51
+ { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "price", "delivery method"], estimated_time: "3min" },
52
+ { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["instant delivery states"], estimated_time: "5min" },
53
+ { type: "Allocation", reversible: true, dependencies: ["Service"], user_decisions: ["revenue split"], estimated_time: "3min" },
54
+ ],
55
+ phases: [
56
+ { name: "Foundation", object_types: ["Permission", "Service"] },
57
+ { name: "Business Logic", object_types: ["Machine"] },
58
+ { name: "Revenue", object_types: ["Allocation"] },
59
+ { name: "Publish", object_types: ["Service"] },
60
+ ],
61
+ },
62
+ {
63
+ name: "travel_package",
64
+ keywords: ["travel", "tour", "trip", "package", "booking", "itinerary", "vacation", "hotel"],
65
+ description: "Multi-stage service with milestones: publish → book → itinerary → complete",
66
+ default_permissions: { provider: 1000, customer: "namedOperator", arbiter: 1500 },
67
+ objects: [
68
+ { type: "Permission", reversible: true, dependencies: [], estimated_time: "2min" },
69
+ { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "package details", "pricing tiers"], estimated_time: "5min" },
70
+ { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["booking states", "milestone flow", "cancellation"], estimated_time: "15min" },
71
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["booking guard", "cancellation guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
72
+ { type: "Allocation", reversible: true, dependencies: ["Service", "Guard"], user_decisions: ["milestone payments", "refund policy"], estimated_time: "5min" },
73
+ ],
74
+ phases: [
75
+ { name: "Foundation", object_types: ["Permission", "Service"] },
76
+ { name: "Business Logic", object_types: ["Machine"] },
77
+ { name: "Trust Layer", object_types: ["Guard"] },
78
+ { name: "Revenue", object_types: ["Allocation"] },
79
+ { name: "Publish", object_types: ["Service"] },
80
+ ],
81
+ },
82
+ {
83
+ name: "general",
84
+ keywords: [],
85
+ description: "Fallback for unmatched scenarios — generic service template",
86
+ default_permissions: { provider: 1000, customer: "namedOperator" },
87
+ objects: [
88
+ { type: "Permission", reversible: true, dependencies: [], estimated_time: "2min" },
89
+ { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "description", "token_type"], estimated_time: "3min" },
90
+ { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["state graph"], estimated_time: "10min" },
91
+ { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["guard requirements"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
92
+ { type: "Allocation", reversible: true, dependencies: ["Service"], user_decisions: ["sharing"], estimated_time: "5min" },
93
+ ],
94
+ phases: [
95
+ { name: "Foundation", object_types: ["Permission", "Service"] },
96
+ { name: "Business Logic", object_types: ["Machine"] },
97
+ { name: "Trust Layer", object_types: ["Guard"] },
98
+ { name: "Revenue", object_types: ["Allocation"] },
99
+ { name: "Publish", object_types: ["Service"] },
100
+ ],
101
+ },
102
+ ];
103
+ export function classifyIntent(userInput) {
104
+ const lower = userInput.toLowerCase();
105
+ let bestMatch = null;
106
+ let bestScore = 0;
107
+ let matchedKeywords = [];
108
+ for (const scenario of SCENARIO_REGISTRY) {
109
+ if (scenario.keywords.length === 0)
110
+ continue;
111
+ const hits = scenario.keywords.filter((kw) => lower.includes(kw));
112
+ if (hits.length > bestScore) {
113
+ bestScore = hits.length;
114
+ bestMatch = scenario;
115
+ matchedKeywords = hits;
116
+ }
117
+ }
118
+ if (bestMatch && bestScore > 0) {
119
+ const confidence = Math.min(bestScore / 3, 1.0);
120
+ return {
121
+ scenario: bestMatch.name,
122
+ matched_keywords: matchedKeywords,
123
+ confidence,
124
+ fallback: false,
125
+ };
126
+ }
127
+ return {
128
+ scenario: "general",
129
+ matched_keywords: [],
130
+ confidence: 0.3,
131
+ fallback: true,
132
+ };
133
+ }
134
+ let nodeIdCounter = 0;
135
+ function nextNodeId(type) {
136
+ nodeIdCounter++;
137
+ return `${type.toLowerCase()}_${nodeIdCounter}`;
138
+ }
139
+ export function generateODG(userInput, taskId) {
140
+ const classification = classifyIntent(userInput);
141
+ const template = SCENARIO_REGISTRY.find((s) => s.name === classification.scenario) ?? SCENARIO_REGISTRY[SCENARIO_REGISTRY.length - 1];
142
+ const objects = template.objects.map((obj) => ({
143
+ id: nextNodeId(obj.type),
144
+ type: obj.type,
145
+ status: "not_created",
146
+ reversible: obj.reversible,
147
+ dependencies: [],
148
+ user_decisions: obj.user_decisions,
149
+ risk_flags: obj.risk_flags,
150
+ estimated_time: obj.estimated_time,
151
+ }));
152
+ const typeToLatestId = new Map();
153
+ for (const obj of objects) {
154
+ const depTypes = template.objects.find((t) => t.type === obj.type)?.dependencies ?? [];
155
+ obj.dependencies = depTypes
156
+ .map((depType) => typeToLatestId.get(depType))
157
+ .filter((id) => id !== undefined);
158
+ typeToLatestId.set(obj.type, obj.id);
159
+ }
160
+ const phases = template.phases.map((phase) => {
161
+ const phaseObjectIds = objects
162
+ .filter((obj) => phase.object_types.includes(obj.type))
163
+ .map((obj) => obj.id);
164
+ return { name: phase.name, objects: phaseObjectIds };
165
+ });
166
+ return {
167
+ task_id: taskId ?? `task_${Date.now()}`,
168
+ scenario: classification.scenario,
169
+ objects,
170
+ phases,
171
+ };
172
+ }
173
+ export function identifyDecisionPoints(odg) {
174
+ const decisions = [];
175
+ const scenario = SCENARIO_REGISTRY.find((s) => s.name === odg.scenario);
176
+ decisions.push({
177
+ round: "R1",
178
+ question: `I've classified your intent as "${odg.scenario}". Is this correct?`,
179
+ options: ["Yes, correct", "No, let me clarify"],
180
+ });
181
+ decisions.push({
182
+ round: "R2",
183
+ question: "Do you have existing Permission objects to reuse, or should I create a new one?",
184
+ options: ["Create new", "Reuse existing", "Show me what I have"],
185
+ });
186
+ decisions.push({
187
+ round: "R3",
188
+ question: "What is the service name, description, and pricing token?",
189
+ options: ["WOW (default)", "USDT", "USDC", "Custom token"],
190
+ default: "WOW (default)",
191
+ });
192
+ if (scenario?.default_permissions.arbiter) {
193
+ decisions.push({
194
+ round: "R4",
195
+ question: "Permission model: provider=1000, customer uses namedOperator, arbiter=1500. Adjust?",
196
+ options: ["Use defaults", "Customize"],
197
+ default: "Use defaults",
198
+ });
199
+ }
200
+ decisions.push({
201
+ round: "R5",
202
+ question: "What are the service states and transitions? (entry → states → terminals)",
203
+ options: ["Use scenario template", "Custom design"],
204
+ });
205
+ const guardNodes = odg.objects.filter((o) => o.type === "Guard");
206
+ if (guardNodes.length > 0) {
207
+ decisions.push({
208
+ round: "R6",
209
+ question: `${guardNodes.length} Guard(s) needed. What should each Guard verify?`,
210
+ options: ["Withdrawal guard", "Refund guard", "Delivery guard", "Custom"],
211
+ });
212
+ }
213
+ decisions.push({
214
+ round: "R7",
215
+ question: "How should revenue be split? (e.g., merchant 80%, platform 20%)",
216
+ options: ["100% to merchant", "80/20 split", "Custom split"],
217
+ default: "100% to merchant",
218
+ });
219
+ return decisions;
220
+ }
221
+ export function detectCycles(odg) {
222
+ const visited = new Set();
223
+ const stack = new Set();
224
+ const cycleNodes = [];
225
+ function dfs(nodeId, path) {
226
+ if (stack.has(nodeId)) {
227
+ const cycleStart = path.indexOf(nodeId);
228
+ cycleNodes.push(...path.slice(cycleStart), nodeId);
229
+ return true;
230
+ }
231
+ if (visited.has(nodeId))
232
+ return false;
233
+ visited.add(nodeId);
234
+ stack.add(nodeId);
235
+ const node = odg.objects.find((o) => o.id === nodeId);
236
+ if (node) {
237
+ for (const dep of node.dependencies) {
238
+ if (dfs(dep, [...path, nodeId]))
239
+ return true;
240
+ }
241
+ }
242
+ stack.delete(nodeId);
243
+ return false;
244
+ }
245
+ for (const obj of odg.objects) {
246
+ if (!visited.has(obj.id)) {
247
+ if (dfs(obj.id, []))
248
+ return cycleNodes;
249
+ }
250
+ }
251
+ return null;
252
+ }
@@ -0,0 +1,17 @@
1
+ import type { RecoveryAction, RecoveryStrategy } from "./types.js";
2
+ export interface RecoveryRule {
3
+ error_code: string;
4
+ strategy: RecoveryStrategy;
5
+ max_attempts: number;
6
+ automation: "full" | "semi" | "manual";
7
+ detail: string;
8
+ user_prompt?: string;
9
+ adjusted_params?: Record<string, unknown>;
10
+ }
11
+ export declare const RECOVERY_RULES: Record<string, RecoveryRule>;
12
+ export declare function resetAttempts(operationId: string): void;
13
+ export declare function recover(errorCode: string, operationId: string, context?: {
14
+ operation_type?: string;
15
+ data?: Record<string, unknown>;
16
+ }): RecoveryAction;
17
+ export declare function getBackoffDelay(attempt: number): number;
@@ -0,0 +1,139 @@
1
+ export const RECOVERY_RULES = {
2
+ insufficient_balance: {
3
+ error_code: "insufficient_balance",
4
+ strategy: "claim_faucet",
5
+ max_attempts: 3,
6
+ automation: "semi",
7
+ detail: "1. Claim faucet tokens (testnet) 2. Prompt user to top up (mainnet) 3. Retry original operation",
8
+ user_prompt: "Insufficient balance for gas or operation. On testnet, claim faucet tokens. On mainnet, please top up your wallet and retry.",
9
+ },
10
+ network_error: {
11
+ error_code: "network_error",
12
+ strategy: "retry",
13
+ max_attempts: 5,
14
+ automation: "full",
15
+ detail: "Exponential backoff retry: 1s / 2s / 4s / 8s / 16s. Switch RPC node if available.",
16
+ },
17
+ guard_rejected: {
18
+ error_code: "guard_rejected",
19
+ strategy: "fill_submission",
20
+ max_attempts: 2,
21
+ automation: "semi",
22
+ detail: "1. Parse Guard table structure 2. Prompt user to fill submission fields 3. Resubmit with call_with_submission",
23
+ user_prompt: "Guard verification rejected. Please fill in the required submission data and resubmit.",
24
+ },
25
+ immutable_violation: {
26
+ error_code: "immutable_violation",
27
+ strategy: "recreate",
28
+ max_attempts: 1,
29
+ automation: "semi",
30
+ detail: "1. Stop modification attempt 2. Evaluate creating a new object as replacement 3. Re-plan affected phases",
31
+ user_prompt: "Cannot modify an immutable object. A new object must be created as a replacement. Confirm to proceed with recreation.",
32
+ },
33
+ permission_denied: {
34
+ error_code: "permission_denied",
35
+ strategy: "switch_account",
36
+ max_attempts: 2,
37
+ automation: "semi",
38
+ detail: "1. Query object's permission_guard 2. List accounts with permission 3. Switch account or prompt user to add permission",
39
+ user_prompt: "Current account lacks permission for this operation. Switch to an authorized account or update the Permission object.",
40
+ },
41
+ object_not_found: {
42
+ error_code: "object_not_found",
43
+ strategy: "query_and_retry",
44
+ max_attempts: 3,
45
+ automation: "semi",
46
+ detail: "1. Re-query the object (may be sync delay) 2. If truly absent, search for similar objects 3. Prompt user to reselect",
47
+ user_prompt: "Referenced object not found. It may be a synchronization delay. Retrying... If the issue persists, please select a valid object.",
48
+ },
49
+ state_conflict: {
50
+ error_code: "state_conflict",
51
+ strategy: "adjust_params",
52
+ max_attempts: 2,
53
+ automation: "full",
54
+ detail: "1. Query object's current true state 2. Update ODG status annotations 3. Adjust subsequent operations (e.g., skip completed steps)",
55
+ },
56
+ invalid_parameter: {
57
+ error_code: "invalid_parameter",
58
+ strategy: "adjust_params",
59
+ max_attempts: 2,
60
+ automation: "semi",
61
+ detail: "1. Query the relevant schema 2. Auto-fix obvious errors (e.g., BigInt vs string) 3. If unfixable, prompt user",
62
+ user_prompt: "Parameter validation failed. Please check the parameter types and values against the schema and retry.",
63
+ },
64
+ unknown: {
65
+ error_code: "unknown",
66
+ strategy: "escalate_human",
67
+ max_attempts: 1,
68
+ automation: "manual",
69
+ detail: "1. Report full error context to telemetry 2. Escalate to human intervention 3. Flag for Loop Engineering rule addition",
70
+ user_prompt: "An unclassified error occurred. Please review the error details and contact support if needed. This error has been logged for tool improvement.",
71
+ },
72
+ };
73
+ const operationAttempts = new Map();
74
+ function getAttemptCount(operationId, errorCode) {
75
+ const opMap = operationAttempts.get(operationId);
76
+ if (!opMap)
77
+ return 0;
78
+ return opMap.get(errorCode) ?? 0;
79
+ }
80
+ function incrementAttempt(operationId, errorCode) {
81
+ if (!operationAttempts.has(operationId)) {
82
+ operationAttempts.set(operationId, new Map());
83
+ }
84
+ const opMap = operationAttempts.get(operationId);
85
+ const current = (opMap.get(errorCode) ?? 0) + 1;
86
+ opMap.set(errorCode, current);
87
+ return current;
88
+ }
89
+ function getTotalAttempts(operationId) {
90
+ const opMap = operationAttempts.get(operationId);
91
+ if (!opMap)
92
+ return 0;
93
+ let total = 0;
94
+ for (const count of opMap.values())
95
+ total += count;
96
+ return total;
97
+ }
98
+ export function resetAttempts(operationId) {
99
+ operationAttempts.delete(operationId);
100
+ }
101
+ export function recover(errorCode, operationId, context) {
102
+ const rule = RECOVERY_RULES[errorCode] ?? RECOVERY_RULES.unknown;
103
+ const TOTAL_RETRY_LIMIT = 5;
104
+ const totalAttempts = getTotalAttempts(operationId);
105
+ const typeAttempts = getAttemptCount(operationId, errorCode);
106
+ if (totalAttempts >= TOTAL_RETRY_LIMIT) {
107
+ return {
108
+ strategy: "stop",
109
+ should_retry: false,
110
+ max_attempts: TOTAL_RETRY_LIMIT,
111
+ current_attempt: totalAttempts,
112
+ detail: `Total retry limit (${TOTAL_RETRY_LIMIT}) reached for operation ${operationId}. Escalating to human intervention.`,
113
+ user_prompt: "Maximum retry attempts reached. Manual intervention required.",
114
+ };
115
+ }
116
+ if (typeAttempts >= rule.max_attempts) {
117
+ return {
118
+ strategy: "escalate_human",
119
+ should_retry: false,
120
+ max_attempts: rule.max_attempts,
121
+ current_attempt: typeAttempts,
122
+ detail: `Per-error-code retry limit (${rule.max_attempts}) reached for ${errorCode}. Escalating to human.`,
123
+ user_prompt: `Recovery attempts for ${errorCode} exhausted. Manual intervention required.`,
124
+ };
125
+ }
126
+ const currentAttempt = incrementAttempt(operationId, errorCode);
127
+ return {
128
+ strategy: rule.strategy,
129
+ should_retry: rule.automation === "full" || currentAttempt < rule.max_attempts,
130
+ max_attempts: rule.max_attempts,
131
+ current_attempt: currentAttempt,
132
+ adjusted_params: rule.adjusted_params,
133
+ user_prompt: rule.user_prompt,
134
+ detail: rule.detail,
135
+ };
136
+ }
137
+ export function getBackoffDelay(attempt) {
138
+ return Math.pow(2, attempt - 1) * 1000;
139
+ }
@@ -0,0 +1,137 @@
1
+ export type ObjectType = "Permission" | "Service" | "Machine" | "Guard" | "Allocation" | "Progress" | "Repository" | "Treasury" | "Reward" | "Demand" | "Order" | "Arbitration" | "Contact" | "Personal" | "Payment";
2
+ export type ObjectStatus = "not_created" | "created_unpublished" | "published" | "failed";
3
+ export interface ODGNode {
4
+ id: string;
5
+ type: ObjectType;
6
+ status: ObjectStatus;
7
+ reversible: boolean;
8
+ dependencies: string[];
9
+ user_decisions?: string[];
10
+ risk_flags?: string[];
11
+ estimated_time?: string;
12
+ address?: string;
13
+ }
14
+ export interface ODGPhase {
15
+ name: string;
16
+ objects: string[];
17
+ description?: string;
18
+ }
19
+ export interface ODG {
20
+ task_id: string;
21
+ scenario: string;
22
+ objects: ODGNode[];
23
+ phases: ODGPhase[];
24
+ }
25
+ export interface ExpectedObject {
26
+ role: string;
27
+ expect_fields?: Record<string, unknown>;
28
+ }
29
+ export interface ExpectedFundFlow {
30
+ role: string;
31
+ amount?: string;
32
+ coinType?: string;
33
+ from?: string | null;
34
+ to?: string | null;
35
+ }
36
+ export interface ExpectedEvent {
37
+ type: string;
38
+ expect_count?: string;
39
+ }
40
+ export interface ExpectedResult {
41
+ operation: string;
42
+ intent: string;
43
+ pre_conditions: Array<{
44
+ check: string;
45
+ error: string;
46
+ }>;
47
+ expected: {
48
+ result_type: "transaction" | "submission" | "error" | "data" | "null";
49
+ semantic_created?: ExpectedObject[];
50
+ semantic_modified?: ExpectedObject[];
51
+ semantic_released?: ExpectedFundFlow[];
52
+ events?: ExpectedEvent[];
53
+ state_transition?: {
54
+ from: string;
55
+ to: string;
56
+ };
57
+ };
58
+ post_verification?: Array<{
59
+ tool: string;
60
+ params: Record<string, unknown>;
61
+ assert: string;
62
+ }>;
63
+ }
64
+ export type VerifyStatus = "pass" | "warn" | "fail";
65
+ export interface VerifyMismatch {
66
+ dimension: "created" | "modified" | "released" | "state" | "event";
67
+ expected: string;
68
+ actual: string;
69
+ severity: VerifyStatus;
70
+ detail: string;
71
+ }
72
+ export interface VerifyReport {
73
+ status: VerifyStatus;
74
+ mismatches: VerifyMismatch[];
75
+ summary: string;
76
+ timestamp: string;
77
+ }
78
+ export type RecoveryStrategy = "retry" | "claim_faucet" | "fill_submission" | "recreate" | "switch_account" | "query_and_retry" | "adjust_params" | "escalate_human" | "stop";
79
+ export interface RecoveryAction {
80
+ strategy: RecoveryStrategy;
81
+ should_retry: boolean;
82
+ adjusted_params?: Record<string, unknown>;
83
+ user_prompt?: string;
84
+ max_attempts: number;
85
+ current_attempt: number;
86
+ detail: string;
87
+ }
88
+ export type PhaseStatus = "in_progress" | "completed" | "failed";
89
+ export interface Checkpoint {
90
+ checkpoint_id: string;
91
+ task_id: string;
92
+ timestamp: string;
93
+ phase: string;
94
+ phase_status: PhaseStatus;
95
+ odg_snapshot: Record<string, {
96
+ status: ObjectStatus;
97
+ address?: string;
98
+ reversible: boolean;
99
+ tested?: boolean;
100
+ }>;
101
+ user_decisions: Record<string, unknown>;
102
+ operation_log: Array<{
103
+ op_id: string;
104
+ tool: string;
105
+ params?: Record<string, unknown>;
106
+ result_digest?: string;
107
+ status: VerifyStatus;
108
+ }>;
109
+ next_phase: string;
110
+ semantic_summary: {
111
+ total_ops: number;
112
+ success_ops: number;
113
+ failed_ops: number;
114
+ recoveries: number;
115
+ };
116
+ }
117
+ export interface ScenarioTemplate {
118
+ name: string;
119
+ keywords: string[];
120
+ objects: Array<Omit<ODGNode, "id" | "status" | "address">>;
121
+ phases: Array<{
122
+ name: string;
123
+ object_types: ObjectType[];
124
+ }>;
125
+ default_permissions: {
126
+ provider?: number;
127
+ customer?: "namedOperator";
128
+ arbiter?: number;
129
+ };
130
+ description: string;
131
+ }
132
+ export interface HarnessContext {
133
+ odg?: ODG;
134
+ current_phase?: string;
135
+ checkpoint?: Checkpoint;
136
+ user_decisions?: Record<string, unknown>;
137
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import type { ExpectedResult, VerifyReport } from "./types.js";
2
+ export interface VerifyInput {
3
+ expected: ExpectedResult;
4
+ actual: {
5
+ result_type?: string;
6
+ semantic?: {
7
+ intent?: string;
8
+ status?: string;
9
+ summary?: string;
10
+ created?: Array<{
11
+ id: string;
12
+ role: string;
13
+ immutable?: boolean;
14
+ }>;
15
+ modified?: Array<{
16
+ id: string;
17
+ role: string;
18
+ }>;
19
+ released?: Array<{
20
+ amount: string;
21
+ coinType: string;
22
+ role: string;
23
+ from?: string | null;
24
+ to?: string | null;
25
+ }>;
26
+ events?: Array<{
27
+ event_type: string;
28
+ business_meaning: string;
29
+ category: string;
30
+ }>;
31
+ next_actions?: Array<{
32
+ action: string;
33
+ priority: string;
34
+ }>;
35
+ warnings?: string[];
36
+ };
37
+ error_code?: string;
38
+ error?: string;
39
+ };
40
+ }
41
+ export declare function verify(input: VerifyInput): VerifyReport;
42
+ export declare function generateExpected(operation: string, intent: string, operationType: string, data?: Record<string, unknown>): ExpectedResult;