@wowok/agent-mcp 2.7.1 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/customer-advice.js +1 -130
  4. package/dist/customer/index.js +1 -11
  5. package/dist/customer/industry-risks.js +1 -438
  6. package/dist/customer/info-puzzle.js +1 -681
  7. package/dist/customer/order-monitor.js +1 -328
  8. package/dist/customer/order-strategy.js +1 -373
  9. package/dist/customer/post-purchase.js +1 -351
  10. package/dist/customer/preorder-compare.js +1 -34
  11. package/dist/customer/reminder-system.js +1 -316
  12. package/dist/customer/risk-assessment.js +1 -397
  13. package/dist/customer/types.js +1 -13
  14. package/dist/customer/user-preferences.js +1 -460
  15. package/dist/evaluation/arbitration-game.d.ts +9 -2
  16. package/dist/evaluation/arbitration-game.js +1 -48
  17. package/dist/evaluation/builtins/demand-match.js +1 -153
  18. package/dist/evaluation/builtins/index.js +1 -10
  19. package/dist/evaluation/builtins/service-risk.js +1 -55
  20. package/dist/evaluation/capability.js +1 -13
  21. package/dist/evaluation/composer.js +1 -40
  22. package/dist/evaluation/engine.js +1 -175
  23. package/dist/evaluation/extract.js +1 -115
  24. package/dist/evaluation/game-strategy.d.ts +27 -0
  25. package/dist/evaluation/game-strategy.js +1 -0
  26. package/dist/evaluation/gap.js +1 -100
  27. package/dist/evaluation/index.d.ts +1 -0
  28. package/dist/evaluation/index.js +1 -11
  29. package/dist/evaluation/node-game.d.ts +31 -3
  30. package/dist/evaluation/node-game.js +1 -57
  31. package/dist/evaluation/region.js +1 -36
  32. package/dist/evaluation/types.d.ts +1 -0
  33. package/dist/evaluation/types.js +1 -1
  34. package/dist/evaluation/user-injection.js +1 -27
  35. package/dist/experience/experience-reuse.js +1 -103
  36. package/dist/experience/index.js +1 -5
  37. package/dist/experience/intent-distill.js +1 -83
  38. package/dist/experience/realtime-feedback.js +1 -94
  39. package/dist/experience/types.js +1 -1
  40. package/dist/experience/user-profile.js +1 -171
  41. package/dist/extensions/business-modules.js +1 -287
  42. package/dist/extensions/capability-manifest.js +1 -781
  43. package/dist/extensions/constraint-registry.js +1 -198
  44. package/dist/extensions/index.js +1 -6
  45. package/dist/extensions/metric-registry.js +1 -257
  46. package/dist/extensions/mode-evaluator.js +1 -170
  47. package/dist/extensions/modes.js +1 -499
  48. package/dist/extensions/registry.js +1 -717
  49. package/dist/extensions/types.js +1 -1
  50. package/dist/harness/auto-escalation.js +1 -68
  51. package/dist/harness/checkpoint.js +1 -129
  52. package/dist/harness/index.js +1 -78
  53. package/dist/harness/plan.js +1 -315
  54. package/dist/harness/recover.js +1 -139
  55. package/dist/harness/types.js +1 -1
  56. package/dist/harness/verify.js +1 -237
  57. package/dist/index.js +1 -273
  58. package/dist/intent/enrich.js +1 -67
  59. package/dist/intent/index.js +1 -60
  60. package/dist/intent/matcher.js +1 -81
  61. package/dist/intent/store.js +1 -55
  62. package/dist/intent/types.js +1 -10
  63. package/dist/knowledge/acquisition-flywheel.js +1 -192
  64. package/dist/knowledge/allocation-confirm.js +1 -534
  65. package/dist/knowledge/allocation-context.js +1 -249
  66. package/dist/knowledge/allocation-ledger.js +1 -463
  67. package/dist/knowledge/allocation-puzzle.js +1 -298
  68. package/dist/knowledge/allocation-risk.js +1 -568
  69. package/dist/knowledge/allocation-templates.js +1 -970
  70. package/dist/knowledge/allocation-translation.js +1 -585
  71. package/dist/knowledge/arb-risk.js +1 -210
  72. package/dist/knowledge/arbitration-confirm.js +1 -559
  73. package/dist/knowledge/arbitration-context.js +1 -505
  74. package/dist/knowledge/arbitration-ledger.js +1 -521
  75. package/dist/knowledge/arbitration-puzzle.js +1 -304
  76. package/dist/knowledge/arbitration-risk.js +1 -423
  77. package/dist/knowledge/arbitration-templates.js +1 -276
  78. package/dist/knowledge/arbitration-translation.js +1 -487
  79. package/dist/knowledge/arbitration-trust.js +1 -117
  80. package/dist/knowledge/audit-rules.js +1 -141
  81. package/dist/knowledge/bridge-risk.js +1 -263
  82. package/dist/knowledge/contact-risk.js +1 -200
  83. package/dist/knowledge/contact-templates.js +1 -60
  84. package/dist/knowledge/demand-confirm.js +1 -206
  85. package/dist/knowledge/demand-matching.js +1 -132
  86. package/dist/knowledge/demand-risk.js +1 -240
  87. package/dist/knowledge/demand-translation.js +1 -354
  88. package/dist/knowledge/deployment-scanner.js +1 -823
  89. package/dist/knowledge/dynamic-pricing.js +1 -87
  90. package/dist/knowledge/examples-scanner-cli.js +1 -26
  91. package/dist/knowledge/examples-scanner.js +1 -843
  92. package/dist/knowledge/flywheel-loop.js +1 -404
  93. package/dist/knowledge/fund-layer.js +1 -973
  94. package/dist/knowledge/glossary.js +1 -211
  95. package/dist/knowledge/guard-confirm.js +1 -406
  96. package/dist/knowledge/guard-context.js +1 -287
  97. package/dist/knowledge/guard-design-patterns.js +1 -360
  98. package/dist/knowledge/guard-ledger.js +1 -260
  99. package/dist/knowledge/guard-lint.js +1 -670
  100. package/dist/knowledge/guard-migration.js +1 -228
  101. package/dist/knowledge/guard-puzzle.js +1 -805
  102. package/dist/knowledge/guard-render.js +1 -700
  103. package/dist/knowledge/guard-risk.js +1 -1879
  104. package/dist/knowledge/guard-submission-prompt.js +1 -171
  105. package/dist/knowledge/guard-templates.js +1 -1105
  106. package/dist/knowledge/guard-translation.js +1 -1119
  107. package/dist/knowledge/index.js +1 -436
  108. package/dist/knowledge/industry-evolution.js +1 -323
  109. package/dist/knowledge/industry-generalizer.js +1 -381
  110. package/dist/knowledge/industry-registry.js +1 -174
  111. package/dist/knowledge/intent-metrics.d.ts +4 -3
  112. package/dist/knowledge/intent-metrics.js +1 -566
  113. package/dist/knowledge/machine-confirm.js +1 -559
  114. package/dist/knowledge/machine-context.js +1 -833
  115. package/dist/knowledge/machine-ledger.js +1 -338
  116. package/dist/knowledge/machine-puzzle.js +1 -494
  117. package/dist/knowledge/machine-render.js +1 -565
  118. package/dist/knowledge/machine-risk.js +1 -669
  119. package/dist/knowledge/machine-templates.js +1 -1597
  120. package/dist/knowledge/machine-topology.js +1 -234
  121. package/dist/knowledge/machine-translation.js +1 -513
  122. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  123. package/dist/knowledge/mcp-schema-audit.js +1 -777
  124. package/dist/knowledge/onchain-constants.js +1 -35
  125. package/dist/knowledge/order-confirm.js +1 -573
  126. package/dist/knowledge/order-context.js +1 -390
  127. package/dist/knowledge/order-ledger.js +1 -341
  128. package/dist/knowledge/order-puzzle.js +1 -255
  129. package/dist/knowledge/order-risk.js +1 -653
  130. package/dist/knowledge/order-templates.js +1 -368
  131. package/dist/knowledge/order-translation.js +1 -550
  132. package/dist/knowledge/overrides-loader.js +1 -65
  133. package/dist/knowledge/passport-confirm.js +1 -531
  134. package/dist/knowledge/passport-context.js +1 -306
  135. package/dist/knowledge/passport-ledger.js +1 -282
  136. package/dist/knowledge/passport-puzzle.js +1 -333
  137. package/dist/knowledge/passport-risk.js +1 -450
  138. package/dist/knowledge/passport-templates.js +1 -568
  139. package/dist/knowledge/passport-translation.js +1 -516
  140. package/dist/knowledge/payment-risk.js +1 -249
  141. package/dist/knowledge/permission-confirm.js +1 -426
  142. package/dist/knowledge/permission-context.js +1 -224
  143. package/dist/knowledge/permission-ledger.js +1 -403
  144. package/dist/knowledge/permission-puzzle.js +1 -173
  145. package/dist/knowledge/permission-risk.js +1 -411
  146. package/dist/knowledge/permission-templates.js +1 -234
  147. package/dist/knowledge/permission-translation.js +1 -350
  148. package/dist/knowledge/personal-risk.js +1 -212
  149. package/dist/knowledge/process-model.js +1 -160
  150. package/dist/knowledge/progress-confirm.js +1 -456
  151. package/dist/knowledge/progress-context.js +1 -452
  152. package/dist/knowledge/progress-ledger.js +1 -330
  153. package/dist/knowledge/progress-puzzle.js +1 -219
  154. package/dist/knowledge/progress-risk.js +1 -461
  155. package/dist/knowledge/progress-templates.js +1 -228
  156. package/dist/knowledge/progress-translation.js +1 -405
  157. package/dist/knowledge/proof-confirm.js +1 -187
  158. package/dist/knowledge/proof-risk.js +1 -207
  159. package/dist/knowledge/proof-translation.js +1 -283
  160. package/dist/knowledge/registrar-risk.js +1 -217
  161. package/dist/knowledge/repository-confirm.js +1 -286
  162. package/dist/knowledge/repository-risk.js +1 -373
  163. package/dist/knowledge/repository-translation.js +1 -445
  164. package/dist/knowledge/reputation-rules.js +1 -99
  165. package/dist/knowledge/resource-risk.js +1 -157
  166. package/dist/knowledge/reward-confirm.js +1 -526
  167. package/dist/knowledge/reward-context.js +1 -504
  168. package/dist/knowledge/reward-ledger.js +1 -502
  169. package/dist/knowledge/reward-puzzle.js +1 -300
  170. package/dist/knowledge/reward-risk.js +1 -627
  171. package/dist/knowledge/reward-templates.js +1 -197
  172. package/dist/knowledge/reward-translation.js +1 -501
  173. package/dist/knowledge/safety-rules.js +1 -404
  174. package/dist/knowledge/scenario-modes.js +1 -321
  175. package/dist/knowledge/service-confirm.js +1 -807
  176. package/dist/knowledge/service-context.js +1 -403
  177. package/dist/knowledge/service-ledger.js +1 -609
  178. package/dist/knowledge/service-puzzle.js +1 -236
  179. package/dist/knowledge/service-risk.js +1 -651
  180. package/dist/knowledge/service-templates.js +1 -456
  181. package/dist/knowledge/service-translation.js +1 -622
  182. package/dist/knowledge/template-registry.js +1 -353
  183. package/dist/knowledge/tool-constraints.js +1 -195
  184. package/dist/knowledge/tools-reference.js +1 -178
  185. package/dist/knowledge/treasury-confirm.js +1 -512
  186. package/dist/knowledge/treasury-context.js +1 -363
  187. package/dist/knowledge/treasury-ledger.js +1 -300
  188. package/dist/knowledge/treasury-puzzle.js +1 -216
  189. package/dist/knowledge/treasury-risk.js +1 -440
  190. package/dist/knowledge/treasury-templates.js +1 -358
  191. package/dist/knowledge/treasury-translation.js +1 -498
  192. package/dist/knowledge/trust-metrics.js +1 -198
  193. package/dist/knowledge/util-risk.js +1 -135
  194. package/dist/loop-engineering/aggregate.js +1 -132
  195. package/dist/loop-engineering/context-collect.js +1 -83
  196. package/dist/loop-engineering/diagnose.js +1 -273
  197. package/dist/loop-engineering/improve.js +1 -405
  198. package/dist/loop-engineering/index.js +1 -4
  199. package/dist/loop-engineering/pipeline.js +1 -56
  200. package/dist/mode-market/index.js +1 -3
  201. package/dist/mode-market/registry.js +1 -124
  202. package/dist/mode-market/review.js +1 -214
  203. package/dist/mode-market/submission.js +1 -85
  204. package/dist/participation/collaborator-interest.d.ts +23 -0
  205. package/dist/participation/collaborator-interest.js +1 -0
  206. package/dist/participation/customer-interest.d.ts +25 -0
  207. package/dist/participation/customer-interest.js +1 -0
  208. package/dist/participation/merchant-interest.js +1 -100
  209. package/dist/participation/radar-core.d.ts +13 -3
  210. package/dist/participation/radar-core.js +1 -269
  211. package/dist/participation/supplier-interest.d.ts +25 -0
  212. package/dist/participation/supplier-interest.js +1 -0
  213. package/dist/persona/analyzer.js +1 -66
  214. package/dist/persona/bridge.js +1 -86
  215. package/dist/persona/defaults.js +1 -195
  216. package/dist/persona/experience-bridge.js +1 -23
  217. package/dist/persona/index.js +1 -71
  218. package/dist/persona/model.js +1 -111
  219. package/dist/persona/store.js +1 -62
  220. package/dist/persona/types.d.ts +3 -1
  221. package/dist/persona/types.js +1 -5
  222. package/dist/project/business-puzzle.js +1 -383
  223. package/dist/project/context-assembly.js +1 -254
  224. package/dist/project/deployment-bridge.js +1 -120
  225. package/dist/project/deployment-doc.js +1 -1126
  226. package/dist/project/edit-planner.js +1 -1342
  227. package/dist/project/evaluation.js +1 -2011
  228. package/dist/project/game-theory.js +1 -177
  229. package/dist/project/graph-builder.js +1 -656
  230. package/dist/project/graph.js +1 -340
  231. package/dist/project/handlers.js +1 -1784
  232. package/dist/project/index.d.ts +1 -0
  233. package/dist/project/index.js +1 -301
  234. package/dist/project/intent-analyzer.js +1 -149
  235. package/dist/project/machine-nodes.js +1 -36
  236. package/dist/project/merchant-guide.js +1 -264
  237. package/dist/project/migration.js +1 -125
  238. package/dist/project/mode-actions.js +1 -309
  239. package/dist/project/namespace.js +1 -206
  240. package/dist/project/participation-radar.js +1 -428
  241. package/dist/project/pipeline-actions.js +1 -109
  242. package/dist/project/project-store.js +1 -422
  243. package/dist/project/query.js +1 -153
  244. package/dist/project/reverse-mapping.d.ts +34 -0
  245. package/dist/project/reverse-mapping.js +1 -0
  246. package/dist/project/risk-aggregator.js +1 -295
  247. package/dist/project/rollback-policy.js +1 -290
  248. package/dist/project/semantic-assembler.js +1 -345
  249. package/dist/project/semantic-graph.js +1 -292
  250. package/dist/project/stage-gate.js +1 -369
  251. package/dist/project/substep-trace.js +1 -332
  252. package/dist/project/task-tracker.js +1 -78
  253. package/dist/role/derivation.d.ts +18 -0
  254. package/dist/role/derivation.js +1 -0
  255. package/dist/role/index.d.ts +5 -0
  256. package/dist/role/index.js +1 -0
  257. package/dist/role/model.d.ts +8 -0
  258. package/dist/role/model.js +1 -0
  259. package/dist/role/resolution.d.ts +11 -0
  260. package/dist/role/resolution.js +1 -0
  261. package/dist/role/types.d.ts +11 -0
  262. package/dist/role/types.js +1 -0
  263. package/dist/rules.js +1 -52
  264. package/dist/safety/confirm-gate.js +1 -88
  265. package/dist/safety/index.js +1 -3
  266. package/dist/safety/preview.js +1 -52
  267. package/dist/schema/call/allocation.js +1 -34
  268. package/dist/schema/call/arbitration.js +1 -113
  269. package/dist/schema/call/base.d.ts +15 -15
  270. package/dist/schema/call/base.js +1 -370
  271. package/dist/schema/call/bridge-handler.js +1 -265
  272. package/dist/schema/call/bridge.d.ts +7 -7
  273. package/dist/schema/call/bridge.js +1 -458
  274. package/dist/schema/call/contact.js +1 -37
  275. package/dist/schema/call/demand.js +1 -47
  276. package/dist/schema/call/guard.js +1 -161
  277. package/dist/schema/call/handler.js +1 -322
  278. package/dist/schema/call/index.js +1 -20
  279. package/dist/schema/call/machine.js +1 -193
  280. package/dist/schema/call/order.js +1 -35
  281. package/dist/schema/call/payment.js +1 -37
  282. package/dist/schema/call/permission-handler.js +1 -54
  283. package/dist/schema/call/permission.js +1 -105
  284. package/dist/schema/call/personal.js +1 -78
  285. package/dist/schema/call/progress.js +1 -47
  286. package/dist/schema/call/proof.js +1 -33
  287. package/dist/schema/call/repository.js +1 -77
  288. package/dist/schema/call/reward.js +1 -30
  289. package/dist/schema/call/semantic.js +1 -1679
  290. package/dist/schema/call/service.js +1 -184
  291. package/dist/schema/call/treasury.js +1 -71
  292. package/dist/schema/common/index.js +1 -407
  293. package/dist/schema/config/index.js +1 -68
  294. package/dist/schema/evaluation/index.d.ts +213 -16
  295. package/dist/schema/evaluation/index.js +1 -356
  296. package/dist/schema/index.js +1 -17
  297. package/dist/schema/intent-radar/index.d.ts +13 -13
  298. package/dist/schema/intent-radar/index.js +1 -89
  299. package/dist/schema/local/index.d.ts +21 -21
  300. package/dist/schema/local/index.js +1 -927
  301. package/dist/schema/local/wip.js +1 -187
  302. package/dist/schema/messenger/index.d.ts +7 -7
  303. package/dist/schema/messenger/index.js +1 -475
  304. package/dist/schema/operations.d.ts +7 -7
  305. package/dist/schema/operations.js +1 -520
  306. package/dist/schema/persona/index.d.ts +54 -54
  307. package/dist/schema/persona/index.js +1 -148
  308. package/dist/schema/project/index.d.ts +94 -48
  309. package/dist/schema/project/index.js +1 -2057
  310. package/dist/schema/query/index.d.ts +423 -7
  311. package/dist/schema/query/index.js +1 -1646
  312. package/dist/schema/schema-query/index.js +1 -104
  313. package/dist/schema/schema-version.js +1 -76
  314. package/dist/schema/sync-layer4.js +1 -286
  315. package/dist/schema/task-status.js +1 -36
  316. package/dist/schema/trust/index.js +1 -314
  317. package/dist/schema/utils/guard-parser.js +1 -419
  318. package/dist/schema/utils/guard-query-utils.js +1 -46
  319. package/dist/schema/utils/node-parser.js +1 -369
  320. package/dist/schema/utils/object-type-utils.js +1 -35
  321. package/dist/schema/utils/permission-index-utils.js +1 -7
  322. package/dist/schema/utils/permission-machine-check.js +1 -121
  323. package/dist/schema/utils/skills-recommendation.js +1 -77
  324. package/dist/schema-query/index.js +1 -810
  325. package/dist/schemas/account_operation.output.json +5 -2
  326. package/dist/schemas/bridge_operation.output.json +5 -2
  327. package/dist/schemas/evaluation_operation.output.json +112 -7
  328. package/dist/schemas/evaluation_operation.schema.json +93 -6
  329. package/dist/schemas/index.json +1 -1
  330. package/dist/schemas/intent_radar.output.json +4 -1
  331. package/dist/schemas/intent_radar.schema.json +4 -1
  332. package/dist/schemas/local_info_operation.output.json +5 -2
  333. package/dist/schemas/local_mark_operation.output.json +5 -2
  334. package/dist/schemas/messenger_operation.output.json +5 -2
  335. package/dist/schemas/onchain_events.output.json +5 -2
  336. package/dist/schemas/onchain_operations.output.json +5 -2
  337. package/dist/schemas/onchain_operations.schema.json +4 -4
  338. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  339. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  340. package/dist/schemas/onchain_operations_service.schema.json +1 -1
  341. package/dist/schemas/onchain_table_data.output.json +6 -3
  342. package/dist/schemas/persona_operation.output.json +4 -1
  343. package/dist/schemas/persona_operation.schema.json +4 -1
  344. package/dist/schemas/project_operation.output.json +28 -8
  345. package/dist/schemas/query_toolkit.output.json +8 -5
  346. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  347. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  348. package/dist/telemetry/index.js +1 -112
  349. package/dist/telemetry/redact.js +1 -23
  350. package/dist/telemetry/storage.js +1 -80
  351. package/dist/tools/handlers/bridge.js +1 -1
  352. package/dist/tools/handlers/config.js +1 -74
  353. package/dist/tools/handlers/evaluation.js +1 -123
  354. package/dist/tools/handlers/file-export.js +1 -90
  355. package/dist/tools/handlers/intent-radar.js +1 -76
  356. package/dist/tools/handlers/local.js +1 -53
  357. package/dist/tools/handlers/messenger.js +1 -188
  358. package/dist/tools/handlers/onchain.js +1 -1180
  359. package/dist/tools/handlers/persona.js +1 -89
  360. package/dist/tools/handlers/project.js +1 -211
  361. package/dist/tools/handlers/query.js +1 -434
  362. package/dist/tools/handlers/schema-query.js +1 -176
  363. package/dist/tools/handlers/task-status.js +1 -26
  364. package/dist/tools/handlers/trust.js +1 -380
  365. package/dist/tools/handlers/wip.js +1 -90
  366. package/dist/tools/index.js +1 -1382
  367. package/dist/tools/retry.js +1 -85
  368. package/dist/tools/rules-hook.js +1 -23
  369. package/dist/tools/shared.js +1 -130
  370. package/dist/tools/types.js +1 -1
  371. package/dist/tools/upgrade-check.d.ts +19 -0
  372. package/dist/tools/upgrade-check.js +1 -0
  373. package/dist/tools/wip-deploy-assist.js +1 -306
  374. package/dist/tools/wrap.js +1 -500
  375. package/package.json +4 -2
@@ -1 +1 @@
1
- export {};
1
+ export{};
@@ -1,68 +1 @@
1
- import { getHarnessTier, setHarnessTier } from "../config/runtime.js";
2
- const state = {
3
- current_tier: "lightweight",
4
- history: [],
5
- recent_failures: [],
6
- };
7
- const REPEATED_FAILURE_WINDOW_MS = 60_000;
8
- const REPEATED_FAILURE_THRESHOLD = 3;
9
- export function isFullTier(tier) {
10
- return tier === "full";
11
- }
12
- export function shouldRunHeavyHooks() {
13
- return isFullTier(getHarnessTier());
14
- }
15
- export function shouldRunLightHooks() {
16
- const tier = getHarnessTier();
17
- return tier === "lightweight" || tier === "full";
18
- }
19
- export function recordCriticalRisk(description) {
20
- return escalate("E1_CRITICAL_RISK", `CRITICAL risk detected: ${description}`);
21
- }
22
- export function recordCriticalOperation(operation, errorCode) {
23
- return escalate("E2_OPERATION_CRITICAL", `Operation '${operation}' returned CRITICAL error: ${errorCode}`);
24
- }
25
- export function recordSubstepFailure(detail) {
26
- return escalate("E3_SUBSTEP_FAILURE", `Substep trace reported failure: ${detail}`);
27
- }
28
- export function recordOperationFailure(operation, errorCode) {
29
- const now = Date.now();
30
- state.recent_failures.push({ timestamp: now, operation, error_code: errorCode });
31
- state.recent_failures = state.recent_failures.filter((f) => now - f.timestamp <= REPEATED_FAILURE_WINDOW_MS);
32
- if (state.recent_failures.length >= REPEATED_FAILURE_THRESHOLD) {
33
- const summary = state.recent_failures
34
- .map((f) => `${f.operation}:${f.error_code}`)
35
- .join(", ");
36
- return escalate("E4_REPEATED_FAILURE", `Repeated failures (${state.recent_failures.length} in ${REPEATED_FAILURE_WINDOW_MS / 1000}s): ${summary}`);
37
- }
38
- return null;
39
- }
40
- export function getEscalationState() {
41
- return {
42
- current_tier: getHarnessTier(),
43
- history: [...state.history],
44
- recent_failures: [...state.recent_failures],
45
- };
46
- }
47
- export function resetEscalation() {
48
- state.history = [];
49
- state.recent_failures = [];
50
- setHarnessTier("lightweight");
51
- state.current_tier = "lightweight";
52
- }
53
- function escalate(trigger, reason) {
54
- const fromTier = getHarnessTier();
55
- if (fromTier !== "lightweight")
56
- return null;
57
- const event = {
58
- trigger,
59
- timestamp: new Date().toISOString(),
60
- reason,
61
- from_tier: fromTier,
62
- to_tier: "full",
63
- };
64
- setHarnessTier("full");
65
- state.current_tier = "full";
66
- state.history.push(event);
67
- return event;
68
- }
1
+ import{getHarnessTier,setHarnessTier}from'../config/runtime.js';const state={'current_tier':'lightweight','history':[],'recent_failures':[]},REPEATED_FAILURE_WINDOW_MS=0xea60,REPEATED_FAILURE_THRESHOLD=0x3;export function isFullTier(a){return a==='full';}export function shouldRunHeavyHooks(){return isFullTier(getHarnessTier());}export function shouldRunLightHooks(){const a=getHarnessTier();return a==='lightweight'||a==='full';}export function recordCriticalRisk(a){return escalate('E1_CRITICAL_RISK','CRITICAL\x20risk\x20detected:\x20'+a);}export function recordCriticalOperation(a,b){return escalate('E2_OPERATION_CRITICAL','Operation\x20\x27'+a+'\x27\x20returned\x20CRITICAL\x20error:\x20'+b);}export function recordSubstepFailure(a){return escalate('E3_SUBSTEP_FAILURE','Substep\x20trace\x20reported\x20failure:\x20'+a);}export function recordOperationFailure(a,b){const c=Date['now']();state['recent_failures']['push']({'timestamp':c,'operation':a,'error_code':b}),state['recent_failures']=state['recent_failures']['filter'](d=>c-d['timestamp']<=REPEATED_FAILURE_WINDOW_MS);if(state['recent_failures']['length']>=REPEATED_FAILURE_THRESHOLD){const d=state['recent_failures']['map'](e=>e['operation']+':'+e['error_code'])['join'](',\x20');return escalate('E4_REPEATED_FAILURE','Repeated\x20failures\x20('+state['recent_failures']['length']+'\x20in\x20'+REPEATED_FAILURE_WINDOW_MS/0x3e8+'s):\x20'+d);}return null;}export function getEscalationState(){return{'current_tier':getHarnessTier(),'history':[...state['history']],'recent_failures':[...state['recent_failures']]};}export function resetEscalation(){state['history']=[],state['recent_failures']=[],setHarnessTier('lightweight'),state['current_tier']='lightweight';}function escalate(a,b){const c=getHarnessTier();if(c!=='lightweight')return null;const d={'trigger':a,'timestamp':new Date()['toISOString'](),'reason':b,'from_tier':c,'to_tier':'full'};return setHarnessTier('full'),state['current_tier']='full',state['history']['push'](d),d;}
@@ -1,129 +1 @@
1
- import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, unlinkSync, openSync, closeSync } from "fs";
2
- import { join } from "path";
3
- import { getWowMcpDir } from "@wowok/wowok";
4
- const CHECKPOINT_ROOT = join(getWowMcpDir(), "checkpoints");
5
- function getTaskDir(taskId) {
6
- return join(CHECKPOINT_ROOT, taskId);
7
- }
8
- function getCheckpointPath(taskId, checkpointId) {
9
- return join(getTaskDir(taskId), `${checkpointId}.json`);
10
- }
11
- function getLatestPath(taskId) {
12
- return join(getTaskDir(taskId), "latest.json");
13
- }
14
- function acquireLock(filePath) {
15
- const lockPath = filePath + ".lock";
16
- try {
17
- const fd = openSync(lockPath, "wx");
18
- closeSync(fd);
19
- return true;
20
- }
21
- catch {
22
- return false;
23
- }
24
- }
25
- function releaseLock(filePath) {
26
- const lockPath = filePath + ".lock";
27
- try {
28
- unlinkSync(lockPath);
29
- }
30
- catch {
31
- }
32
- }
33
- export function saveCheckpoint(cp) {
34
- const taskDir = getTaskDir(cp.task_id);
35
- if (!existsSync(taskDir)) {
36
- mkdirSync(taskDir, { recursive: true });
37
- }
38
- const cpPath = getCheckpointPath(cp.task_id, cp.checkpoint_id);
39
- const latestPath = getLatestPath(cp.task_id);
40
- if (!acquireLock(cpPath)) {
41
- throw new Error(`Cannot acquire lock for checkpoint ${cp.checkpoint_id} — another process may be writing`);
42
- }
43
- try {
44
- writeFileSync(cpPath, JSON.stringify(cp, null, 2), "utf8");
45
- writeFileSync(latestPath, JSON.stringify(cp, null, 2), "utf8");
46
- }
47
- finally {
48
- releaseLock(cpPath);
49
- }
50
- }
51
- export function loadCheckpoint(taskId, checkpointId) {
52
- const cpPath = getCheckpointPath(taskId, checkpointId);
53
- if (!existsSync(cpPath))
54
- return null;
55
- try {
56
- const raw = readFileSync(cpPath, "utf8");
57
- return JSON.parse(raw);
58
- }
59
- catch {
60
- return null;
61
- }
62
- }
63
- export function loadLatestCheckpoint(taskId) {
64
- const latestPath = getLatestPath(taskId);
65
- if (!existsSync(latestPath))
66
- return null;
67
- try {
68
- const raw = readFileSync(latestPath, "utf8");
69
- return JSON.parse(raw);
70
- }
71
- catch {
72
- return null;
73
- }
74
- }
75
- export function listCheckpoints(taskId) {
76
- const taskDir = getTaskDir(taskId);
77
- if (!existsSync(taskDir))
78
- return [];
79
- const files = readdirSync(taskDir)
80
- .filter((f) => f.endsWith(".json") && f !== "latest.json")
81
- .sort();
82
- return files
83
- .map((f) => {
84
- try {
85
- const raw = readFileSync(join(taskDir, f), "utf8");
86
- return JSON.parse(raw);
87
- }
88
- catch {
89
- return null;
90
- }
91
- })
92
- .filter((cp) => cp !== null);
93
- }
94
- export function listTasks() {
95
- if (!existsSync(CHECKPOINT_ROOT))
96
- return [];
97
- return readdirSync(CHECKPOINT_ROOT, { withFileTypes: true })
98
- .filter((d) => d.isDirectory())
99
- .map((d) => d.name);
100
- }
101
- export function deleteCheckpoint(taskId, checkpointId) {
102
- const cpPath = getCheckpointPath(taskId, checkpointId);
103
- if (existsSync(cpPath)) {
104
- if (!acquireLock(cpPath)) {
105
- throw new Error(`Cannot acquire lock for deletion of ${checkpointId}`);
106
- }
107
- try {
108
- unlinkSync(cpPath);
109
- }
110
- finally {
111
- releaseLock(cpPath);
112
- }
113
- }
114
- }
115
- export function createCheckpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary) {
116
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
117
- return {
118
- checkpoint_id: `CP-${phase.replace(/\s+/g, "")}-${phaseStatus}-${timestamp}`,
119
- task_id: taskId,
120
- timestamp: new Date().toISOString(),
121
- phase,
122
- phase_status: phaseStatus,
123
- odg_snapshot: odgSnapshot,
124
- user_decisions: userDecisions,
125
- operation_log: operationLog,
126
- next_phase: nextPhase,
127
- semantic_summary: semanticSummary,
128
- };
129
- }
1
+ import{existsSync,mkdirSync,writeFileSync,readFileSync,readdirSync,unlinkSync,openSync,closeSync}from'fs';import{join}from'path';import{getWowMcpDir}from'@wowok/wowok';const CHECKPOINT_ROOT=join(getWowMcpDir(),'checkpoints');function getTaskDir(a){return join(CHECKPOINT_ROOT,a);}function getCheckpointPath(a,b){return join(getTaskDir(a),b+'.json');}function getLatestPath(a){return join(getTaskDir(a),'latest.json');}function acquireLock(a){const b=a+'.lock';try{const c=openSync(b,'wx');return closeSync(c),!![];}catch{return![];}}function releaseLock(a){const b=a+'.lock';try{unlinkSync(b);}catch{}}export function saveCheckpoint(a){const b=getTaskDir(a['task_id']);!existsSync(b)&&mkdirSync(b,{'recursive':!![]});const c=getCheckpointPath(a['task_id'],a['checkpoint_id']),d=getLatestPath(a['task_id']);if(!acquireLock(c))throw new Error('Cannot\x20acquire\x20lock\x20for\x20checkpoint\x20'+a['checkpoint_id']+'\x20—\x20another\x20process\x20may\x20be\x20writing');try{writeFileSync(c,JSON['stringify'](a,null,0x2),'utf8'),writeFileSync(d,JSON['stringify'](a,null,0x2),'utf8');}finally{releaseLock(c);}}export function loadCheckpoint(a,b){const c=getCheckpointPath(a,b);if(!existsSync(c))return null;try{const d=readFileSync(c,'utf8');return JSON['parse'](d);}catch{return null;}}export function loadLatestCheckpoint(a){const b=getLatestPath(a);if(!existsSync(b))return null;try{const c=readFileSync(b,'utf8');return JSON['parse'](c);}catch{return null;}}export function listCheckpoints(a){const b=getTaskDir(a);if(!existsSync(b))return[];const c=readdirSync(b)['filter'](d=>d['endsWith']('.json')&&d!=='latest.json')['sort']();return c['map'](d=>{try{const e=readFileSync(join(b,d),'utf8');return JSON['parse'](e);}catch{return null;}})['filter'](d=>d!==null);}export function listTasks(){if(!existsSync(CHECKPOINT_ROOT))return[];return readdirSync(CHECKPOINT_ROOT,{'withFileTypes':!![]})['filter'](a=>a['isDirectory']())['map'](a=>a['name']);}export function deleteCheckpoint(a,b){const c=getCheckpointPath(a,b);if(existsSync(c)){if(!acquireLock(c))throw new Error('Cannot\x20acquire\x20lock\x20for\x20deletion\x20of\x20'+b);try{unlinkSync(c);}finally{releaseLock(c);}}}export function createCheckpoint(a,b,c,d,e,f,g,h){const i=new Date()['toISOString']()['replace'](/[:.]/g,'-');return{'checkpoint_id':'CP-'+b['replace'](/\s+/g,'')+'-'+c+'-'+i,'task_id':a,'timestamp':new Date()['toISOString'](),'phase':b,'phase_status':c,'odg_snapshot':d,'user_decisions':e,'operation_log':f,'next_phase':g,'semantic_summary':h};}
@@ -1,78 +1 @@
1
- export * from "./types.js";
2
- export * from "./plan.js";
3
- export * from "./verify.js";
4
- export * from "./recover.js";
5
- export * from "./checkpoint.js";
6
- import { classifyIntent, generateODG, identifyDecisionPoints, detectCycles, SCENARIO_REGISTRY, identifyMigrationDecisions } from "./plan.js";
7
- import { verify, generateExpected } from "./verify.js";
8
- import { recover, resetAttempts, getBackoffDelay, RECOVERY_RULES } from "./recover.js";
9
- import { saveCheckpoint, loadLatestCheckpoint, listCheckpoints, listTasks, createCheckpoint } from "./checkpoint.js";
10
- export class Harness {
11
- context = new Map();
12
- plan(userInput, taskId) {
13
- return generateODG(userInput, taskId);
14
- }
15
- classifyIntent(userInput) {
16
- return classifyIntent(userInput);
17
- }
18
- getDecisions(odg) {
19
- return identifyDecisionPoints(odg);
20
- }
21
- getMigrationDecisions(options) {
22
- return identifyMigrationDecisions(options);
23
- }
24
- detectCycles(odg) {
25
- return detectCycles(odg);
26
- }
27
- getScenarioRegistry() {
28
- return SCENARIO_REGISTRY;
29
- }
30
- expect(operation, intent, operationType, data) {
31
- return generateExpected(operation, intent, operationType, data);
32
- }
33
- verify(input) {
34
- return verify(input);
35
- }
36
- recover(errorCode, operationId, context) {
37
- return recover(errorCode, operationId, context);
38
- }
39
- resetRecovery(operationId) {
40
- resetAttempts(operationId);
41
- }
42
- getBackoffDelay(attempt) {
43
- return getBackoffDelay(attempt);
44
- }
45
- getRecoveryRules() {
46
- return RECOVERY_RULES;
47
- }
48
- checkpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary) {
49
- const cp = createCheckpoint(taskId, phase, phaseStatus, odgSnapshot, userDecisions, operationLog, nextPhase, semanticSummary);
50
- saveCheckpoint(cp);
51
- return cp;
52
- }
53
- loadCheckpoint(taskId) {
54
- return loadLatestCheckpoint(taskId);
55
- }
56
- listCheckpoints(taskId) {
57
- return listCheckpoints(taskId);
58
- }
59
- listTasks() {
60
- return listTasks();
61
- }
62
- setContext(key, value) {
63
- this.context.set(key, value);
64
- }
65
- getContext(key) {
66
- return this.context.get(key);
67
- }
68
- }
69
- let singleton = null;
70
- export function getHarness() {
71
- if (!singleton) {
72
- singleton = new Harness();
73
- }
74
- return singleton;
75
- }
76
- export function setHarness(h) {
77
- singleton = h;
78
- }
1
+ export*from'./types.js';export*from'./plan.js';export*from'./verify.js';export*from'./recover.js';export*from'./checkpoint.js';import{classifyIntent,generateODG,identifyDecisionPoints,detectCycles,SCENARIO_REGISTRY,identifyMigrationDecisions}from'./plan.js';import{verify,generateExpected}from'./verify.js';import{recover,resetAttempts,getBackoffDelay,RECOVERY_RULES}from'./recover.js';import{saveCheckpoint,loadLatestCheckpoint,listCheckpoints,listTasks,createCheckpoint}from'./checkpoint.js';export class Harness{['context']=new Map();['plan'](a,b){return generateODG(a,b);}['classifyIntent'](a){return classifyIntent(a);}['getDecisions'](a){return identifyDecisionPoints(a);}['getMigrationDecisions'](a){return identifyMigrationDecisions(a);}['detectCycles'](a){return detectCycles(a);}['getScenarioRegistry'](){return SCENARIO_REGISTRY;}['expect'](a,b,c,d){return generateExpected(a,b,c,d);}['verify'](a){return verify(a);}['recover'](a,b,c){return recover(a,b,c);}['resetRecovery'](a){resetAttempts(a);}['getBackoffDelay'](a){return getBackoffDelay(a);}['getRecoveryRules'](){return RECOVERY_RULES;}['checkpoint'](a,b,c,d,e,f,g,h){const i=createCheckpoint(a,b,c,d,e,f,g,h);return saveCheckpoint(i),i;}['loadCheckpoint'](a){return loadLatestCheckpoint(a);}['listCheckpoints'](a){return listCheckpoints(a);}['listTasks'](){return listTasks();}['setContext'](a,b){this['context']['set'](a,b);}['getContext'](a){return this['context']['get'](a);}}let singleton=null;export function getHarness(){return!singleton&&(singleton=new Harness()),singleton;}export function setHarness(a){singleton=a;}
@@ -1,315 +1 @@
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: "retail",
46
- keywords: ["retail", "shop", "store", "ecommerce", "buy", "sell", "product", "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",
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: "education",
84
- keywords: ["education", "course", "training", "tutor", "teach", "learn", "school", "coach", "class", "lesson"],
85
- description: "Long-cycle education with milestones: publish → enroll → teach → complete → certificate",
86
- default_permissions: { provider: 1000, customer: "namedOperator", arbiter: 1500 },
87
- objects: [
88
- { type: "Permission", reversible: true, dependencies: [], user_decisions: ["reuse existing or create new?"], estimated_time: "2min" },
89
- { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "course details", "token_type"], estimated_time: "3min" },
90
- { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["enrollment states", "milestone flow", "completion"], estimated_time: "15min" },
91
- { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["enrollment guard", "completion guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
92
- { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["refund guard"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
93
- { type: "Allocation", reversible: true, dependencies: ["Service", "Guard"], user_decisions: ["milestone payments", "refund policy"], estimated_time: "5min" },
94
- ],
95
- phases: [
96
- { name: "Foundation", object_types: ["Permission", "Service"] },
97
- { name: "Business Logic", object_types: ["Machine"] },
98
- { name: "Trust Layer", object_types: ["Guard"] },
99
- { name: "Revenue", object_types: ["Allocation"] },
100
- { name: "Publish", object_types: ["Service"] },
101
- ],
102
- },
103
- {
104
- name: "subscription",
105
- keywords: ["subscription", "subscribe", "membership", "recurring", "monthly", "newsletter", "patreon", "tier"],
106
- description: "Recurring subscription with renewal: publish → subscribe → renew → cancel",
107
- default_permissions: { provider: 1000, customer: "namedOperator" },
108
- objects: [
109
- { type: "Permission", reversible: true, dependencies: [], estimated_time: "2min" },
110
- { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "subscription tiers", "token_type"], estimated_time: "3min" },
111
- { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["subscribe states", "renewal flow", "cancellation"], estimated_time: "10min" },
112
- { type: "Allocation", reversible: true, dependencies: ["Service"], user_decisions: ["revenue split"], estimated_time: "3min" },
113
- ],
114
- phases: [
115
- { name: "Foundation", object_types: ["Permission", "Service"] },
116
- { name: "Business Logic", object_types: ["Machine"] },
117
- { name: "Revenue", object_types: ["Allocation"] },
118
- { name: "Publish", object_types: ["Service"] },
119
- ],
120
- },
121
- {
122
- name: "general",
123
- keywords: [],
124
- description: "Fallback for unmatched scenarios — generic service template",
125
- default_permissions: { provider: 1000, customer: "namedOperator" },
126
- objects: [
127
- { type: "Permission", reversible: true, dependencies: [], estimated_time: "2min" },
128
- { type: "Service", reversible: true, dependencies: ["Permission"], user_decisions: ["name", "description", "token_type"], estimated_time: "3min" },
129
- { type: "Machine", reversible: true, dependencies: ["Service"], user_decisions: ["state graph"], estimated_time: "10min" },
130
- { type: "Guard", reversible: false, dependencies: ["Machine"], user_decisions: ["guard requirements"], risk_flags: ["immutable_after_creation"], estimated_time: "5min" },
131
- { type: "Allocation", reversible: true, dependencies: ["Service"], user_decisions: ["sharing"], estimated_time: "5min" },
132
- ],
133
- phases: [
134
- { name: "Foundation", object_types: ["Permission", "Service"] },
135
- { name: "Business Logic", object_types: ["Machine"] },
136
- { name: "Trust Layer", object_types: ["Guard"] },
137
- { name: "Revenue", object_types: ["Allocation"] },
138
- { name: "Publish", object_types: ["Service"] },
139
- ],
140
- },
141
- ];
142
- export function classifyIntent(userInput) {
143
- const lower = userInput.toLowerCase();
144
- let bestMatch = null;
145
- let bestScore = 0;
146
- let matchedKeywords = [];
147
- for (const scenario of SCENARIO_REGISTRY) {
148
- if (scenario.keywords.length === 0)
149
- continue;
150
- const hits = scenario.keywords.filter((kw) => lower.includes(kw));
151
- if (hits.length > bestScore) {
152
- bestScore = hits.length;
153
- bestMatch = scenario;
154
- matchedKeywords = hits;
155
- }
156
- }
157
- if (bestMatch && bestScore > 0) {
158
- const confidence = Math.min(bestScore / 3, 1.0);
159
- return {
160
- scenario: bestMatch.name,
161
- matched_keywords: matchedKeywords,
162
- confidence,
163
- fallback: false,
164
- };
165
- }
166
- return {
167
- scenario: "general",
168
- matched_keywords: [],
169
- confidence: 0.3,
170
- fallback: true,
171
- };
172
- }
173
- let nodeIdCounter = 0;
174
- function nextNodeId(type) {
175
- nodeIdCounter++;
176
- return `${type.toLowerCase()}_${nodeIdCounter}`;
177
- }
178
- export function generateODG(userInput, taskId) {
179
- const classification = classifyIntent(userInput);
180
- const template = SCENARIO_REGISTRY.find((s) => s.name === classification.scenario) ?? SCENARIO_REGISTRY[SCENARIO_REGISTRY.length - 1];
181
- const objects = template.objects.map((obj) => ({
182
- id: nextNodeId(obj.type),
183
- type: obj.type,
184
- status: "not_created",
185
- reversible: obj.reversible,
186
- dependencies: [],
187
- user_decisions: obj.user_decisions,
188
- risk_flags: obj.risk_flags,
189
- estimated_time: obj.estimated_time,
190
- }));
191
- const typeToLatestId = new Map();
192
- for (const obj of objects) {
193
- const depTypes = template.objects.find((t) => t.type === obj.type)?.dependencies ?? [];
194
- obj.dependencies = depTypes
195
- .map((depType) => typeToLatestId.get(depType))
196
- .filter((id) => id !== undefined);
197
- typeToLatestId.set(obj.type, obj.id);
198
- }
199
- const phases = template.phases.map((phase) => {
200
- const phaseObjectIds = objects
201
- .filter((obj) => phase.object_types.includes(obj.type))
202
- .map((obj) => obj.id);
203
- return { name: phase.name, objects: phaseObjectIds };
204
- });
205
- return {
206
- task_id: taskId ?? `task_${Date.now()}`,
207
- scenario: classification.scenario,
208
- objects,
209
- phases,
210
- };
211
- }
212
- export function identifyDecisionPoints(odg) {
213
- const decisions = [];
214
- const scenario = SCENARIO_REGISTRY.find((s) => s.name === odg.scenario);
215
- decisions.push({
216
- round: "R1",
217
- question: `I've classified your intent as "${odg.scenario}". Is this correct?`,
218
- options: ["Yes, correct", "No, let me clarify"],
219
- });
220
- decisions.push({
221
- round: "R2",
222
- question: "Do you have existing Permission objects to reuse, or should I create a new one?",
223
- options: ["Create new", "Reuse existing", "Show me what I have"],
224
- });
225
- decisions.push({
226
- round: "R3",
227
- question: "What is the service name, description, and pricing token?",
228
- options: ["WOW (default)", "USDT", "USDC", "Custom token"],
229
- default: "WOW (default)",
230
- });
231
- if (scenario?.default_permissions.arbiter) {
232
- decisions.push({
233
- round: "R4",
234
- question: "Permission model: provider=1000, customer uses namedOperator, arbiter=1500. Adjust?",
235
- options: ["Use defaults", "Customize"],
236
- default: "Use defaults",
237
- });
238
- }
239
- decisions.push({
240
- round: "R5",
241
- question: "What are the service states and transitions? (entry → states → terminals)",
242
- options: ["Use scenario template", "Custom design"],
243
- });
244
- const guardNodes = odg.objects.filter((o) => o.type === "Guard");
245
- if (guardNodes.length > 0) {
246
- decisions.push({
247
- round: "R6",
248
- question: `${guardNodes.length} Guard(s) needed. What should each Guard verify?`,
249
- options: ["Withdrawal guard", "Refund guard", "Delivery guard", "Custom"],
250
- });
251
- }
252
- decisions.push({
253
- round: "R7",
254
- question: "How should revenue be split? (e.g., merchant 80%, platform 20%)",
255
- options: ["100% to merchant", "80/20 split", "Custom split"],
256
- default: "100% to merchant",
257
- });
258
- return decisions;
259
- }
260
- export function detectCycles(odg) {
261
- const visited = new Set();
262
- const stack = new Set();
263
- const cycleNodes = [];
264
- function dfs(nodeId, path) {
265
- if (stack.has(nodeId)) {
266
- const cycleStart = path.indexOf(nodeId);
267
- cycleNodes.push(...path.slice(cycleStart), nodeId);
268
- return true;
269
- }
270
- if (visited.has(nodeId))
271
- return false;
272
- visited.add(nodeId);
273
- stack.add(nodeId);
274
- const node = odg.objects.find((o) => o.id === nodeId);
275
- if (node) {
276
- for (const dep of node.dependencies) {
277
- if (dfs(dep, [...path, nodeId]))
278
- return true;
279
- }
280
- }
281
- stack.delete(nodeId);
282
- return false;
283
- }
284
- for (const obj of odg.objects) {
285
- if (!visited.has(obj.id)) {
286
- if (dfs(obj.id, []))
287
- return cycleNodes;
288
- }
289
- }
290
- return null;
291
- }
292
- export function identifyMigrationDecisions(options) {
293
- const current = options?.current_payment_token ?? "WOW";
294
- const from = options?.from_network ?? "testnet";
295
- const to = options?.to_network ?? "mainnet";
296
- return [
297
- {
298
- round: "M1",
299
- question: `Your project currently uses "${current}" as the payment token on ${from}. ` +
300
- `When migrating to ${to}, do you want to keep "${current}" or switch to a stablecoin ` +
301
- `(e.g. USDT, available via the ETH mainnet cross-chain bridge)?`,
302
- options: [
303
- `Keep ${current}`,
304
- "Switch to USDT",
305
- "Switch to USDC",
306
- "Other stablecoin",
307
- ],
308
- default: `Keep ${current}`,
309
- note: `Testnet recommendation: WOW for all merchant and order testing. ` +
310
- `Mainnet: USDT and other stablecoins are available via the ETH mainnet cross-chain bridge ` +
311
- `and are often preferred to avoid price volatility. If switching, the Service / Treasury / ` +
312
- `Allocation type_parameter must be updated to the stablecoin's WOW type tag before publishing on mainnet.`,
313
- },
314
- ];
315
- }
1
+ export const SCENARIO_REGISTRY=[{'name':'freelance','keywords':['freelance','service','deliverable','client','gig','consult','design','develop'],'description':'Service\x20delivery\x20with\x20escrow:\x20publish\x20→\x20order\x20→\x20deliver\x20→\x20accept\x20→\x20withdraw','default_permissions':{'provider':0x3e8,'customer':'namedOperator','arbiter':0x5dc},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'user_decisions':['reuse\x20existing\x20or\x20create\x20new?'],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','description','token_type'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['state\x20graph','operators'],'estimated_time':'10min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['guard\x20table','submission\x20fields'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['refund\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service','Guard'],'user_decisions':['sharing\x20ratios','allocators'],'estimated_time':'5min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Trust\x20Layer','object_types':['Guard']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'rental','keywords':['rent','rental','lease','property','item','deposit','tenant','landlord'],'description':'Item\x20rental\x20with\x20deposit:\x20publish\x20→\x20rent\x20→\x20inspect\x20→\x20return/refund','default_permissions':{'provider':0x3e8,'customer':'namedOperator','arbiter':0x5dc},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'user_decisions':['reuse\x20existing\x20or\x20create\x20new?'],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','deposit\x20amount','rental\x20terms'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['rental\x20states','return/inspect\x20flow'],'estimated_time':'10min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['return\x20guard','damage\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['refund\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service','Guard'],'user_decisions':['deposit/refund\x20allocation','damage\x20compensation'],'estimated_time':'5min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Trust\x20Layer','object_types':['Guard']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'retail','keywords':['retail','shop','store','ecommerce','buy','sell','product','digital','download','ebook','software','license','instant','content'],'description':'Instant\x20digital\x20delivery:\x20publish\x20→\x20buy\x20→\x20instant\x20delivery','default_permissions':{'provider':0x3e8,'customer':'namedOperator'},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','price','delivery\x20method'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['instant\x20delivery\x20states'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service'],'user_decisions':['revenue\x20split'],'estimated_time':'3min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'travel','keywords':['travel','tour','trip','package','booking','itinerary','vacation','hotel'],'description':'Multi-stage\x20service\x20with\x20milestones:\x20publish\x20→\x20book\x20→\x20itinerary\x20→\x20complete','default_permissions':{'provider':0x3e8,'customer':'namedOperator','arbiter':0x5dc},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','package\x20details','pricing\x20tiers'],'estimated_time':'5min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['booking\x20states','milestone\x20flow','cancellation'],'estimated_time':'15min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['booking\x20guard','cancellation\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service','Guard'],'user_decisions':['milestone\x20payments','refund\x20policy'],'estimated_time':'5min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Trust\x20Layer','object_types':['Guard']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'education','keywords':['education','course','training','tutor','teach','learn','school','coach','class','lesson'],'description':'Long-cycle\x20education\x20with\x20milestones:\x20publish\x20→\x20enroll\x20→\x20teach\x20→\x20complete\x20→\x20certificate','default_permissions':{'provider':0x3e8,'customer':'namedOperator','arbiter':0x5dc},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'user_decisions':['reuse\x20existing\x20or\x20create\x20new?'],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','course\x20details','token_type'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['enrollment\x20states','milestone\x20flow','completion'],'estimated_time':'15min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['enrollment\x20guard','completion\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['refund\x20guard'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service','Guard'],'user_decisions':['milestone\x20payments','refund\x20policy'],'estimated_time':'5min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Trust\x20Layer','object_types':['Guard']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'subscription','keywords':['subscription','subscribe','membership','recurring','monthly','newsletter','patreon','tier'],'description':'Recurring\x20subscription\x20with\x20renewal:\x20publish\x20→\x20subscribe\x20→\x20renew\x20→\x20cancel','default_permissions':{'provider':0x3e8,'customer':'namedOperator'},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','subscription\x20tiers','token_type'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['subscribe\x20states','renewal\x20flow','cancellation'],'estimated_time':'10min'},{'type':'Allocation','reversible':!![],'dependencies':['Service'],'user_decisions':['revenue\x20split'],'estimated_time':'3min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]},{'name':'general','keywords':[],'description':'Fallback\x20for\x20unmatched\x20scenarios\x20—\x20generic\x20service\x20template','default_permissions':{'provider':0x3e8,'customer':'namedOperator'},'objects':[{'type':'Permission','reversible':!![],'dependencies':[],'estimated_time':'2min'},{'type':'Service','reversible':!![],'dependencies':['Permission'],'user_decisions':['name','description','token_type'],'estimated_time':'3min'},{'type':'Machine','reversible':!![],'dependencies':['Service'],'user_decisions':['state\x20graph'],'estimated_time':'10min'},{'type':'Guard','reversible':![],'dependencies':['Machine'],'user_decisions':['guard\x20requirements'],'risk_flags':['immutable_after_creation'],'estimated_time':'5min'},{'type':'Allocation','reversible':!![],'dependencies':['Service'],'user_decisions':['sharing'],'estimated_time':'5min'}],'phases':[{'name':'Foundation','object_types':['Permission','Service']},{'name':'Business\x20Logic','object_types':['Machine']},{'name':'Trust\x20Layer','object_types':['Guard']},{'name':'Revenue','object_types':['Allocation']},{'name':'Publish','object_types':['Service']}]}];export function classifyIntent(a){const b=a['toLowerCase']();let c=null,d=0x0,e=[];for(const f of SCENARIO_REGISTRY){if(f['keywords']['length']===0x0)continue;const g=f['keywords']['filter'](h=>b['includes'](h));g['length']>d&&(d=g['length'],c=f,e=g);}if(c&&d>0x0){const h=Math['min'](d/0x3,0x1);return{'scenario':c['name'],'matched_keywords':e,'confidence':h,'fallback':![]};}return{'scenario':'general','matched_keywords':[],'confidence':0.3,'fallback':!![]};}let nodeIdCounter=0x0;function nextNodeId(a){return nodeIdCounter++,a['toLowerCase']()+'_'+nodeIdCounter;}export function generateODG(a,b){const c=classifyIntent(a),d=SCENARIO_REGISTRY['find'](h=>h['name']===c['scenario'])??SCENARIO_REGISTRY[SCENARIO_REGISTRY['length']-0x1],e=d['objects']['map'](h=>({'id':nextNodeId(h['type']),'type':h['type'],'status':'not_created','reversible':h['reversible'],'dependencies':[],'user_decisions':h['user_decisions'],'risk_flags':h['risk_flags'],'estimated_time':h['estimated_time']})),f=new Map();for(const h of e){const i=d['objects']['find'](j=>j['type']===h['type'])?.['dependencies']??[];h['dependencies']=i['map'](j=>f['get'](j))['filter'](j=>j!==undefined),f['set'](h['type'],h['id']);}const g=d['phases']['map'](j=>{const k=e['filter'](l=>j['object_types']['includes'](l['type']))['map'](l=>l['id']);return{'name':j['name'],'objects':k};});return{'task_id':b??'task_'+Date['now'](),'scenario':c['scenario'],'objects':e,'phases':g};}export function identifyDecisionPoints(a){const b=[],c=SCENARIO_REGISTRY['find'](e=>e['name']===a['scenario']);b['push']({'round':'R1','question':'I\x27ve\x20classified\x20your\x20intent\x20as\x20\x22'+a['scenario']+'\x22.\x20Is\x20this\x20correct?','options':['Yes,\x20correct','No,\x20let\x20me\x20clarify']}),b['push']({'round':'R2','question':'Do\x20you\x20have\x20existing\x20Permission\x20objects\x20to\x20reuse,\x20or\x20should\x20I\x20create\x20a\x20new\x20one?','options':['Create\x20new','Reuse\x20existing','Show\x20me\x20what\x20I\x20have']}),b['push']({'round':'R3','question':'What\x20is\x20the\x20service\x20name,\x20description,\x20and\x20pricing\x20token?','options':['WOW\x20(default)','USDT','USDC','Custom\x20token'],'default':'WOW\x20(default)'});c?.['default_permissions']['arbiter']&&b['push']({'round':'R4','question':'Permission\x20model:\x20provider=1000,\x20customer\x20uses\x20namedOperator,\x20arbiter=1500.\x20Adjust?','options':['Use\x20defaults','Customize'],'default':'Use\x20defaults'});b['push']({'round':'R5','question':'What\x20are\x20the\x20service\x20states\x20and\x20transitions?\x20(entry\x20→\x20states\x20→\x20terminals)','options':['Use\x20scenario\x20template','Custom\x20design']});const d=a['objects']['filter'](e=>e['type']==='Guard');return d['length']>0x0&&b['push']({'round':'R6','question':d['length']+'\x20Guard(s)\x20needed.\x20What\x20should\x20each\x20Guard\x20verify?','options':['Withdrawal\x20guard','Refund\x20guard','Delivery\x20guard','Custom']}),b['push']({'round':'R7','question':'How\x20should\x20revenue\x20be\x20split?\x20(e.g.,\x20merchant\x2080%,\x20platform\x2020%)','options':['100%\x20to\x20merchant','80/20\x20split','Custom\x20split'],'default':'100%\x20to\x20merchant'}),b;}export function detectCycles(a){const b=new Set(),c=new Set(),d=[];function e(f,g){if(c['has'](f)){const i=g['indexOf'](f);return d['push'](...g['slice'](i),f),!![];}if(b['has'](f))return![];b['add'](f),c['add'](f);const h=a['objects']['find'](j=>j['id']===f);if(h)for(const j of h['dependencies']){if(e(j,[...g,f]))return!![];}return c['delete'](f),![];}for(const f of a['objects']){if(!b['has'](f['id'])){if(e(f['id'],[]))return d;}}return null;}export function identifyMigrationDecisions(a){const b=a?.['current_payment_token']??'WOW',c=a?.['from_network']??'testnet',d=a?.['to_network']??'mainnet';return[{'round':'M1','question':'Your\x20project\x20currently\x20uses\x20\x22'+b+'\x22\x20as\x20the\x20payment\x20token\x20on\x20'+c+'.\x20'+('When\x20migrating\x20to\x20'+d+',\x20do\x20you\x20want\x20to\x20keep\x20\x22'+b+'\x22\x20or\x20switch\x20to\x20a\x20stablecoin\x20')+'(e.g.\x20USDT,\x20available\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge)?','options':['Keep\x20'+b,'Switch\x20to\x20USDT','Switch\x20to\x20USDC','Other\x20stablecoin'],'default':'Keep\x20'+b,'note':'Testnet\x20recommendation:\x20WOW\x20for\x20all\x20merchant\x20and\x20order\x20testing.\x20'+'Mainnet:\x20USDT\x20and\x20other\x20stablecoins\x20are\x20available\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge\x20'+'and\x20are\x20often\x20preferred\x20to\x20avoid\x20price\x20volatility.\x20If\x20switching,\x20the\x20Service\x20/\x20Treasury\x20/\x20'+'Allocation\x20type_parameter\x20must\x20be\x20updated\x20to\x20the\x20stablecoin\x27s\x20WOW\x20type\x20tag\x20before\x20publishing\x20on\x20mainnet.'}];}