@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,559 +1 @@
1
- import { analyzeTopology, } from "./machine-topology.js";
2
- import { USER_DEFINED_PERM_INDEX_START, MAX_NODE_COUNT, MAX_NODE_PAIR_COUNT, MAX_FORWARD_COUNT, MAX_FORWARD_ORDER_COUNT, } from "./onchain-constants.js";
3
- import { assessMachineRisks, } from "./machine-risk.js";
4
- import { derivePuzzleFromMachineJson, generateConfirmationText, } from "./machine-puzzle.js";
5
- export const PUBLISH_CHECKLIST = [
6
- {
7
- id: "C-01",
8
- description: "Entry point exists: at least one Pair with prev_node=''",
9
- status: "skip",
10
- detail: "Workflow cannot start without entry Pair. Verify Pair table for empty prev_node.",
11
- },
12
- {
13
- id: "C-02",
14
- description: "Every node has outgoing Forwards (except terminal nodes)",
15
- status: "skip",
16
- detail: "Dead-end nodes trap workflow. Identify terminals and verify they are intended.",
17
- },
18
- {
19
- id: "C-03",
20
- description: "Every node has incoming Pair (except entry point)",
21
- status: "skip",
22
- detail: "Orphaned nodes are unreachable. Verify all non-entry nodes are reachable.",
23
- },
24
- {
25
- id: "C-04",
26
- description: "All thresholds independently achievable (no dead branches)",
27
- status: "skip",
28
- detail: "If a competing Pair always loses, it is dead code. Use topology analysis.",
29
- },
30
- {
31
- id: "C-05",
32
- description: "All Guards exist on-chain and tested (via gen_passport)",
33
- status: "skip",
34
- detail: "Guard addresses referenced in forwards must be valid published Guard objects.",
35
- },
36
- {
37
- id: "C-06",
38
- description: "namedOperator vs permissionIndex correct per Forward",
39
- status: "skip",
40
- detail: "Each Forward must have at least one of namedOperator or permissionIndex.",
41
- },
42
- {
43
- id: "C-07",
44
- description: "Terminal nodes mapped to Allocator entries for fund distribution",
45
- status: "skip",
46
- detail: "Terminal nodes without Allocator risk funds being locked forever.",
47
- },
48
- {
49
- id: "C-08",
50
- description: "Tested end-to-end on testnet via a test Progress",
51
- status: "skip",
52
- detail: "Testnet verification is mandatory before mainnet publish.",
53
- },
54
- {
55
- id: "C-09",
56
- description: "Current state exported via machineNode2file as backup",
57
- status: "skip",
58
- detail: "Backup before publish. If publish fails, you can rebuild from export.",
59
- },
60
- {
61
- id: "C-10",
62
- description: `On-chain constraint limits respected (MAX_NODE_COUNT=${MAX_NODE_COUNT}, MAX_NODE_PAIR_COUNT=${MAX_NODE_PAIR_COUNT}, MAX_FORWARD_COUNT=${MAX_FORWARD_COUNT})`,
63
- status: "skip",
64
- detail: "Exceeding on-chain constants will cause transaction failure.",
65
- },
66
- {
67
- id: "C-11",
68
- description: "All permissionIndex values >= 1000 (USER_DEFINED_PERM_INDEX_START)",
69
- status: "skip",
70
- detail: "On-chain permission.move reserves indexes 0-999 for built-in permissions. " +
71
- "Custom permission_index MUST be >= 1000 (see doc 06 §4.4). " +
72
- "Using index < 1000 causes confusion with built-in permissions.",
73
- },
74
- ];
75
- export function runStaticChecklist(machine) {
76
- const checked = [];
77
- const failed = [];
78
- const warnings = [];
79
- const topology = analyzeTopology(machine.nodes, machine.pairs);
80
- const hasEntry = topology.entry_nodes.length > 0;
81
- checked.push({
82
- id: "C-01",
83
- description: "Entry point exists",
84
- status: hasEntry ? "pass" : "fail",
85
- detail: hasEntry
86
- ? `Found entry nodes: ${topology.entry_nodes.join(", ")}`
87
- : "NO entry Pair with prev_node=''",
88
- });
89
- if (!hasEntry)
90
- failed.push(checked[checked.length - 1]);
91
- const nonTerminalWithoutOutgoing = machine.nodes.filter((n) => !topology.terminal_nodes.includes(n.name) &&
92
- !machine.pairs.some((p) => p.prev_node === n.name));
93
- checked.push({
94
- id: "C-02",
95
- description: "Every node has outgoing Forwards (except terminals)",
96
- status: nonTerminalWithoutOutgoing.length === 0 ? "pass" : "fail",
97
- detail: nonTerminalWithoutOutgoing.length === 0
98
- ? "All non-terminal nodes have outgoing Pairs"
99
- : `Dead-end nodes: ${nonTerminalWithoutOutgoing.map((n) => n.name).join(", ")}`,
100
- });
101
- if (nonTerminalWithoutOutgoing.length > 0)
102
- failed.push(checked[checked.length - 1]);
103
- checked.push({
104
- id: "C-03",
105
- description: "Every node has incoming Pair",
106
- status: topology.orphaned_nodes.length === 0 ? "pass" : "fail",
107
- detail: topology.orphaned_nodes.length === 0
108
- ? "All non-entry nodes are reachable"
109
- : `Orphaned nodes: ${topology.orphaned_nodes.join(", ")}`,
110
- });
111
- if (topology.orphaned_nodes.length > 0)
112
- failed.push(checked[checked.length - 1]);
113
- checked.push({
114
- id: "C-04",
115
- description: "All thresholds achievable",
116
- status: topology.dead_branches.length === 0 ? "pass" : "warning",
117
- detail: topology.dead_branches.length === 0
118
- ? "No dead branches detected"
119
- : `Potential dead branches: ${topology.dead_branches.length}`,
120
- });
121
- if (topology.dead_branches.length > 0)
122
- warnings.push(checked[checked.length - 1]);
123
- checked.push({
124
- id: "C-05",
125
- description: "All Guards exist on-chain",
126
- status: "skip",
127
- detail: "Verify at runtime via onchain_objects query for each Guard address",
128
- });
129
- const invalidForwards = [];
130
- for (const pair of machine.pairs) {
131
- for (const fwd of pair.forwards) {
132
- const hasNamed = fwd.named_operator !== undefined;
133
- const hasPerm = fwd.permission_index !== undefined;
134
- if (!hasNamed && !hasPerm) {
135
- invalidForwards.push(`${pair.prev_node}->${pair.next_node}:${fwd.name}`);
136
- }
137
- }
138
- }
139
- checked.push({
140
- id: "C-06",
141
- description: "Forward permission model correct",
142
- status: invalidForwards.length === 0 ? "pass" : "fail",
143
- detail: invalidForwards.length === 0
144
- ? "All Forwards have valid permission"
145
- : `Invalid Forwards: ${invalidForwards.join(", ")}`,
146
- });
147
- if (invalidForwards.length > 0)
148
- failed.push(checked[checked.length - 1]);
149
- checked.push({
150
- id: "C-07",
151
- description: "Terminal nodes have Allocator",
152
- status: "skip",
153
- detail: "Verify at Service binding stage",
154
- });
155
- checked.push({
156
- id: "C-08",
157
- description: "Testnet test passed",
158
- status: "skip",
159
- detail: "Verify at Layer 4 (environment)",
160
- });
161
- checked.push({
162
- id: "C-09",
163
- description: "machineNode2file backup created",
164
- status: "skip",
165
- detail: "Recommend exporting before publish",
166
- });
167
- const limitViolations = [];
168
- if (!topology.within_limits.max_node_count)
169
- limitViolations.push(`MAX_NODE_COUNT=${MAX_NODE_COUNT}`);
170
- if (!topology.within_limits.max_node_pair_count)
171
- limitViolations.push(`MAX_NODE_PAIR_COUNT=${MAX_NODE_PAIR_COUNT}`);
172
- if (!topology.within_limits.max_forward_count)
173
- limitViolations.push(`MAX_FORWARD_COUNT=${MAX_FORWARD_COUNT}`);
174
- if (!topology.within_limits.max_forward_order_count)
175
- limitViolations.push(`MAX_FORWARD_ORDER_COUNT=${MAX_FORWARD_ORDER_COUNT}`);
176
- checked.push({
177
- id: "C-10",
178
- description: "On-chain limits respected",
179
- status: limitViolations.length === 0 ? "pass" : "fail",
180
- detail: limitViolations.length === 0
181
- ? "All limits within bounds"
182
- : `Violations: ${limitViolations.join(", ")}`,
183
- });
184
- if (limitViolations.length > 0)
185
- failed.push(checked[checked.length - 1]);
186
- const lowPermissionIndexes = [];
187
- for (const pair of machine.pairs) {
188
- for (const fwd of pair.forwards) {
189
- if (fwd.permission_index !== undefined &&
190
- fwd.permission_index !== null &&
191
- fwd.permission_index < USER_DEFINED_PERM_INDEX_START) {
192
- lowPermissionIndexes.push(`${pair.prev_node}->${pair.next_node}:${fwd.name} (idx=${fwd.permission_index})`);
193
- }
194
- }
195
- }
196
- checked.push({
197
- id: "C-11",
198
- description: `permissionIndex >= ${USER_DEFINED_PERM_INDEX_START}`,
199
- status: lowPermissionIndexes.length === 0 ? "pass" : "fail",
200
- detail: lowPermissionIndexes.length === 0
201
- ? `All permission_index values >= ${USER_DEFINED_PERM_INDEX_START}`
202
- : `permission_index < ${USER_DEFINED_PERM_INDEX_START}: ${lowPermissionIndexes.join(", ")}`,
203
- });
204
- if (lowPermissionIndexes.length > 0)
205
- failed.push(checked[checked.length - 1]);
206
- return {
207
- passed: failed.length === 0,
208
- checked_items: checked,
209
- failed_items: failed,
210
- warnings,
211
- };
212
- }
213
- export function integrateRiskAssessment(machine, context) {
214
- const machineForRisk = {
215
- nodes: machine.nodes,
216
- pairs: machine.pairs,
217
- b_published: machine.b_published,
218
- b_paused: machine.b_paused,
219
- scene_id: machine.scene_id,
220
- };
221
- const assessment = assessMachineRisks(machineForRisk, context);
222
- const blocking_risks = [];
223
- const warning_risks = [];
224
- for (const risk of assessment.detected_risks) {
225
- if (risk.severity === "critical" || risk.severity === "high") {
226
- blocking_risks.push(risk.rule_id);
227
- }
228
- else if (risk.severity === "medium") {
229
- warning_risks.push(risk.rule_id);
230
- }
231
- }
232
- let recommendation;
233
- if (blocking_risks.some((id) => {
234
- const risk = assessment.detected_risks.find((r) => r.rule_id === id);
235
- return risk?.severity === "critical";
236
- })) {
237
- recommendation = "do_not_publish";
238
- }
239
- else if (blocking_risks.length > 0) {
240
- recommendation = "fix_first";
241
- }
242
- else if (warning_risks.length > 3) {
243
- recommendation = "fix_first";
244
- }
245
- else {
246
- recommendation = "publish";
247
- }
248
- return {
249
- overall_risk_level: assessment.overall_level,
250
- blocking_risks,
251
- warning_risks,
252
- recommendation,
253
- };
254
- }
255
- export const CONFIRMATION_QUESTIONS = [
256
- { id: "Q1", question: "Reviewed topology and confirmed all nodes/forwards are correct?", expected_response: "yes", blocking: true },
257
- { id: "Q2", question: "Tested this Machine on TESTNET with a successful Progress run?", expected_response: "yes", blocking: true },
258
- { id: "Q3", question: "All Guards created, bound, and verified via gen_passport?", expected_response: "yes", blocking: true },
259
- { id: "Q4", question: "All Allocators configured for terminal nodes?", expected_response: "yes", blocking: true },
260
- { id: "Q5", question: "Acknowledge that publishing is IRREVERSIBLE and gas will be consumed?", expected_response: "yes", blocking: true },
261
- { id: "Q6", question: "Proceed with publishing this Machine NOW?", expected_response: "yes", blocking: true },
262
- ];
263
- export function parseUserConfirmation(userInput) {
264
- const responses = userInput.split(",").map((s) => s.trim().toLowerCase());
265
- const user_responses = [];
266
- for (let i = 0; i < CONFIRMATION_QUESTIONS.length; i++) {
267
- const q = CONFIRMATION_QUESTIONS[i];
268
- const answer = responses[i] || "(no answer)";
269
- const is_yes = answer.startsWith("y") || answer === "yes";
270
- const is_no = answer.startsWith("n") || answer === "no";
271
- user_responses.push({
272
- question_id: q.id,
273
- response: is_yes ? "yes" : is_no ? "no" : "unclear",
274
- raw_input: answer,
275
- });
276
- }
277
- const all_blocking_yes = CONFIRMATION_QUESTIONS
278
- .filter((q) => q.blocking)
279
- .every((q, idx) => user_responses[idx].response === "yes");
280
- return {
281
- questions_asked: CONFIRMATION_QUESTIONS,
282
- user_responses,
283
- approved: all_blocking_yes,
284
- declined_reason: all_blocking_yes
285
- ? undefined
286
- : "One or more blocking questions answered 'no'",
287
- timestamp: new Date().toISOString(),
288
- };
289
- }
290
- export function generateFullConfirmationText(machine, checklistResult, riskResult) {
291
- const puzzle = derivePuzzleFromMachineJson({
292
- nodes: machine.nodes,
293
- pairs: machine.pairs,
294
- scene_id: machine.scene_id,
295
- template_id: machine.template_id,
296
- });
297
- const puzzleText = generateConfirmationText(puzzle);
298
- const lines = [
299
- "╔═══════════════════════════════════════════════════════════════╗",
300
- "║ MACHINE PUBLISH CONFIRMATION REQUIRED ║",
301
- "╚═══════════════════════════════════════════════════════════════╝",
302
- "",
303
- "⚠️ WARNING: Publishing a Machine is IRREVERSIBLE.",
304
- " - Nodes, Pairs, Forwards will be FROZEN permanently.",
305
- " - Gas will be consumed (cannot be refunded).",
306
- " - Any error requires creating a NEW Machine (with new gas cost).",
307
- "",
308
- "═══════════════════════════════════════════════════════════════",
309
- puzzleText,
310
- "═══════════════════════════════════════════════════════════════",
311
- "RISK ASSESSMENT:",
312
- ` Overall Risk Level: ${riskResult.overall_risk_level.toUpperCase()}`,
313
- ` Recommendation: ${riskResult.recommendation}`,
314
- ` Blocking Risks: ${riskResult.blocking_risks.length === 0 ? "None" : riskResult.blocking_risks.join(", ")}`,
315
- ` Warning Risks: ${riskResult.warning_risks.length === 0 ? "None" : riskResult.warning_risks.join(", ")}`,
316
- "",
317
- "═══════════════════════════════════════════════════════════════",
318
- "STATIC CHECKLIST:",
319
- ` Passed: ${checklistResult.checked_items.filter((i) => i.status === "pass").length} / ${checklistResult.checked_items.length}`,
320
- ` Failed: ${checklistResult.failed_items.length}`,
321
- ` Warnings: ${checklistResult.warnings.length}`,
322
- ` Skipped: ${checklistResult.checked_items.filter((i) => i.status === "skip").length}`,
323
- "",
324
- ...checklistResult.failed_items.map((i) => ` ❌ ${i.id}: ${i.description} — ${i.detail || ""}`),
325
- ...checklistResult.warnings.map((i) => ` ⚠️ ${i.id}: ${i.description} — ${i.detail || ""}`),
326
- "",
327
- "═══════════════════════════════════════════════════════════════",
328
- "USER CONFIRMATION QUESTIONS:",
329
- "",
330
- ...CONFIRMATION_QUESTIONS.map((q, idx) => ` Q${idx + 1}. ${q.question} [Yes / No]`),
331
- "",
332
- "If you answer 'No' to ANY of Q1-Q5, publish will be BLOCKED.",
333
- "If you answer 'No' to Q6, publish will be CANCELLED (no gas spent).",
334
- "",
335
- "Type your answers (Q1-Q6) separated by commas:",
336
- ];
337
- return lines.join("\n");
338
- }
339
- export function verifyEnvironment(machine, context, isMainnet) {
340
- const missing_dependencies = [];
341
- for (const pair of machine.pairs) {
342
- for (const forward of pair.forwards) {
343
- if (forward.guard && !context.published_guards.has(forward.guard)) {
344
- missing_dependencies.push(`Guard: ${forward.guard}`);
345
- }
346
- }
347
- }
348
- const has_testnet_test_passed = context.testnet_test_passed;
349
- const effectiveTestPassed = isMainnet ? has_testnet_test_passed : true;
350
- return {
351
- is_testnet: !isMainnet,
352
- has_testnet_test_passed: effectiveTestPassed,
353
- gas_estimation: context.gas_estimation,
354
- dependency_table_complete: missing_dependencies.length === 0,
355
- missing_dependencies,
356
- };
357
- }
358
- function hashMachineJson(machine) {
359
- const json = JSON.stringify({
360
- nodes: machine.nodes.map((n) => n.name),
361
- pairs: machine.pairs.map((p) => ({
362
- prev: p.prev_node,
363
- next: p.next_node,
364
- threshold: p.threshold,
365
- forwards: p.forwards.map((f) => f.name),
366
- })),
367
- });
368
- let hash = 0;
369
- for (let i = 0; i < json.length; i++) {
370
- const char = json.charCodeAt(i);
371
- hash = ((hash << 5) - hash) + char;
372
- hash = hash & hash;
373
- }
374
- return `0x${(hash >>> 0).toString(16).padStart(8, "0")}`;
375
- }
376
- export function confirmPublish(machine, context, isMainnet, userConfirmationInput) {
377
- const decision_record = {
378
- timestamp: new Date().toISOString(),
379
- user_address: context.user_address,
380
- machine_json_hash: hashMachineJson(machine),
381
- template_id: machine.template_id,
382
- scene_id: machine.scene_id,
383
- final_status: "blocked_checklist",
384
- };
385
- const checklist_result = runStaticChecklist(machine);
386
- if (!checklist_result.passed) {
387
- return {
388
- status: "blocked_checklist",
389
- checklist_result,
390
- decision_record: { ...decision_record, final_status: "blocked_checklist" },
391
- block_reason: `Checklist failed: ${checklist_result.failed_items.map((i) => i.id).join(", ")}`,
392
- };
393
- }
394
- const risk_result = integrateRiskAssessment(machine, context);
395
- if (risk_result.recommendation === "do_not_publish") {
396
- return {
397
- status: "blocked_risk",
398
- checklist_result,
399
- risk_result,
400
- decision_record: { ...decision_record, final_status: "blocked_risk" },
401
- block_reason: `Critical risks detected: ${risk_result.blocking_risks.join(", ")}`,
402
- };
403
- }
404
- if (!userConfirmationInput) {
405
- const confirmation_text = generateFullConfirmationText(machine, checklist_result, risk_result);
406
- return {
407
- status: "blocked_user",
408
- checklist_result,
409
- risk_result,
410
- confirmation_text,
411
- decision_record: { ...decision_record, final_status: "blocked_user" },
412
- block_reason: "Awaiting user confirmation",
413
- };
414
- }
415
- const user_confirmation = parseUserConfirmation(userConfirmationInput);
416
- if (!user_confirmation.approved) {
417
- return {
418
- status: "blocked_user",
419
- checklist_result,
420
- risk_result,
421
- user_confirmation,
422
- decision_record: { ...decision_record, final_status: "blocked_user" },
423
- block_reason: user_confirmation.declined_reason || "User declined",
424
- };
425
- }
426
- const environment_result = verifyEnvironment(machine, context, isMainnet);
427
- if (!environment_result.dependency_table_complete || !environment_result.has_testnet_test_passed) {
428
- const issues = [];
429
- if (!environment_result.dependency_table_complete) {
430
- issues.push(`missing dependencies: ${environment_result.missing_dependencies.join(", ")}`);
431
- }
432
- if (!environment_result.has_testnet_test_passed) {
433
- issues.push("testnet test not passed (required for mainnet)");
434
- }
435
- return {
436
- status: "blocked_environment",
437
- checklist_result,
438
- risk_result,
439
- user_confirmation,
440
- environment_result,
441
- decision_record: { ...decision_record, final_status: "blocked_environment" },
442
- block_reason: `Environment issues: ${issues.join("; ")}`,
443
- };
444
- }
445
- return {
446
- status: "approved",
447
- checklist_result,
448
- risk_result,
449
- user_confirmation,
450
- environment_result,
451
- decision_record: { ...decision_record, final_status: "approved" },
452
- };
453
- }
454
- export function overrideBlockWithReason(result, _userReason) {
455
- if (result.status !== "blocked_risk") {
456
- return result;
457
- }
458
- const hasCritical = result.risk_result?.blocking_risks.some((id) => id.includes("CRITICAL") || id.includes("critical"));
459
- if (hasCritical) {
460
- return {
461
- ...result,
462
- block_reason: "Cannot override CRITICAL risks",
463
- };
464
- }
465
- return {
466
- ...result,
467
- status: "approved",
468
- block_reason: undefined,
469
- decision_record: {
470
- ...result.decision_record,
471
- final_status: "approved",
472
- },
473
- };
474
- }
475
- export function progressiveCheck(machine, round) {
476
- const fullResult = runStaticChecklist(machine);
477
- if (round === "R5") {
478
- return filterChecklist(fullResult, ["C-01", "C-02", "C-03", "C-04", "C-06", "C-10"]);
479
- }
480
- if (round === "R6") {
481
- return filterChecklist(fullResult, ["C-01", "C-02", "C-03", "C-04", "C-05", "C-06", "C-10"]);
482
- }
483
- return fullResult;
484
- }
485
- function filterChecklist(result, allowedIds) {
486
- const filtered = result.checked_items.filter((i) => allowedIds.includes(i.id));
487
- return {
488
- passed: filtered.filter((i) => i.status === "fail").length === 0,
489
- checked_items: filtered,
490
- failed_items: filtered.filter((i) => i.status === "fail"),
491
- warnings: filtered.filter((i) => i.status === "warning"),
492
- };
493
- }
494
- export function prePublishHook(machine, context, isMainnet) {
495
- const result = confirmPublish(machine, context, isMainnet);
496
- if (result.status !== "blocked_user" && result.status !== "approved") {
497
- return {
498
- proceed: false,
499
- error: formatBlockError(result),
500
- confirmGateResult: result,
501
- };
502
- }
503
- if (result.status === "blocked_user" && result.confirmation_text) {
504
- return {
505
- proceed: false,
506
- error: result.confirmation_text,
507
- confirmGateResult: result,
508
- };
509
- }
510
- return { proceed: true, confirmGateResult: result };
511
- }
512
- export function postConfirmationHook(machine, context, isMainnet, userConfirmationInput) {
513
- const result = confirmPublish(machine, context, isMainnet, userConfirmationInput);
514
- if (result.status !== "approved") {
515
- return {
516
- proceed: false,
517
- error: formatBlockError(result),
518
- confirmGateResult: result,
519
- };
520
- }
521
- return { proceed: true, confirmGateResult: result };
522
- }
523
- export function formatBlockError(result) {
524
- const lines = [
525
- "❌ MACHINE PUBLISH BLOCKED",
526
- "",
527
- `Status: ${result.status}`,
528
- `Reason: ${result.block_reason || "(no reason provided)"}`,
529
- "",
530
- ];
531
- if (result.status === "blocked_checklist") {
532
- lines.push("Failed checklist items:");
533
- for (const item of result.checklist_result.failed_items) {
534
- lines.push(` - ${item.id}: ${item.description}`);
535
- lines.push(` Detail: ${item.detail || "(no detail)"}`);
536
- }
537
- }
538
- if (result.status === "blocked_risk" && result.risk_result) {
539
- lines.push("Blocking risks:");
540
- for (const riskId of result.risk_result.blocking_risks) {
541
- lines.push(` - ${riskId}`);
542
- }
543
- lines.push("");
544
- lines.push(`Recommendation: ${result.risk_result.recommendation}`);
545
- }
546
- if (result.status === "blocked_environment" && result.environment_result) {
547
- lines.push("Environment issues:");
548
- for (const dep of result.environment_result.missing_dependencies) {
549
- lines.push(` - Missing dependency: ${dep}`);
550
- }
551
- if (!result.environment_result.has_testnet_test_passed) {
552
- lines.push(" - Testnet test NOT passed (required for mainnet)");
553
- }
554
- }
555
- return lines.join("\n");
556
- }
557
- export const MACHINE_CONFIRM_VERSION = "1.0.0";
558
- export const MACHINE_CHECKLIST_ITEMS_COUNT = PUBLISH_CHECKLIST.length;
559
- export const MACHINE_CONFIRMATION_QUESTIONS_COUNT = CONFIRMATION_QUESTIONS.length;
1
+ import{analyzeTopology}from'./machine-topology.js';import{USER_DEFINED_PERM_INDEX_START,MAX_NODE_COUNT,MAX_NODE_PAIR_COUNT,MAX_FORWARD_COUNT,MAX_FORWARD_ORDER_COUNT}from'./onchain-constants.js';import{assessMachineRisks}from'./machine-risk.js';import{derivePuzzleFromMachineJson,generateConfirmationText}from'./machine-puzzle.js';export const PUBLISH_CHECKLIST=[{'id':'C-01','description':'Entry\x20point\x20exists:\x20at\x20least\x20one\x20Pair\x20with\x20prev_node=\x27\x27','status':'skip','detail':'Workflow\x20cannot\x20start\x20without\x20entry\x20Pair.\x20Verify\x20Pair\x20table\x20for\x20empty\x20prev_node.'},{'id':'C-02','description':'Every\x20node\x20has\x20outgoing\x20Forwards\x20(except\x20terminal\x20nodes)','status':'skip','detail':'Dead-end\x20nodes\x20trap\x20workflow.\x20Identify\x20terminals\x20and\x20verify\x20they\x20are\x20intended.'},{'id':'C-03','description':'Every\x20node\x20has\x20incoming\x20Pair\x20(except\x20entry\x20point)','status':'skip','detail':'Orphaned\x20nodes\x20are\x20unreachable.\x20Verify\x20all\x20non-entry\x20nodes\x20are\x20reachable.'},{'id':'C-04','description':'All\x20thresholds\x20independently\x20achievable\x20(no\x20dead\x20branches)','status':'skip','detail':'If\x20a\x20competing\x20Pair\x20always\x20loses,\x20it\x20is\x20dead\x20code.\x20Use\x20topology\x20analysis.'},{'id':'C-05','description':'All\x20Guards\x20exist\x20on-chain\x20and\x20tested\x20(via\x20gen_passport)','status':'skip','detail':'Guard\x20addresses\x20referenced\x20in\x20forwards\x20must\x20be\x20valid\x20published\x20Guard\x20objects.'},{'id':'C-06','description':'namedOperator\x20vs\x20permissionIndex\x20correct\x20per\x20Forward','status':'skip','detail':'Each\x20Forward\x20must\x20have\x20at\x20least\x20one\x20of\x20namedOperator\x20or\x20permissionIndex.'},{'id':'C-07','description':'Terminal\x20nodes\x20mapped\x20to\x20Allocator\x20entries\x20for\x20fund\x20distribution','status':'skip','detail':'Terminal\x20nodes\x20without\x20Allocator\x20risk\x20funds\x20being\x20locked\x20forever.'},{'id':'C-08','description':'Tested\x20end-to-end\x20on\x20testnet\x20via\x20a\x20test\x20Progress','status':'skip','detail':'Testnet\x20verification\x20is\x20mandatory\x20before\x20mainnet\x20publish.'},{'id':'C-09','description':'Current\x20state\x20exported\x20via\x20machineNode2file\x20as\x20backup','status':'skip','detail':'Backup\x20before\x20publish.\x20If\x20publish\x20fails,\x20you\x20can\x20rebuild\x20from\x20export.'},{'id':'C-10','description':'On-chain\x20constraint\x20limits\x20respected\x20(MAX_NODE_COUNT='+MAX_NODE_COUNT+',\x20MAX_NODE_PAIR_COUNT='+MAX_NODE_PAIR_COUNT+',\x20MAX_FORWARD_COUNT='+MAX_FORWARD_COUNT+')','status':'skip','detail':'Exceeding\x20on-chain\x20constants\x20will\x20cause\x20transaction\x20failure.'},{'id':'C-11','description':'All\x20permissionIndex\x20values\x20>=\x201000\x20(USER_DEFINED_PERM_INDEX_START)','status':'skip','detail':'On-chain\x20permission.move\x20reserves\x20indexes\x200-999\x20for\x20built-in\x20permissions.\x20'+'Custom\x20permission_index\x20MUST\x20be\x20>=\x201000\x20(see\x20doc\x2006\x20§4.4).\x20'+'Using\x20index\x20<\x201000\x20causes\x20confusion\x20with\x20built-in\x20permissions.'}];export function runStaticChecklist(a){const b=[],c=[],d=[],e=analyzeTopology(a['nodes'],a['pairs']),f=e['entry_nodes']['length']>0x0;b['push']({'id':'C-01','description':'Entry\x20point\x20exists','status':f?'pass':'fail','detail':f?'Found\x20entry\x20nodes:\x20'+e['entry_nodes']['join'](',\x20'):'NO\x20entry\x20Pair\x20with\x20prev_node=\x27\x27'});if(!f)c['push'](b[b['length']-0x1]);const g=a['nodes']['filter'](k=>!e['terminal_nodes']['includes'](k['name'])&&!a['pairs']['some'](l=>l['prev_node']===k['name']));b['push']({'id':'C-02','description':'Every\x20node\x20has\x20outgoing\x20Forwards\x20(except\x20terminals)','status':g['length']===0x0?'pass':'fail','detail':g['length']===0x0?'All\x20non-terminal\x20nodes\x20have\x20outgoing\x20Pairs':'Dead-end\x20nodes:\x20'+g['map'](k=>k['name'])['join'](',\x20')});if(g['length']>0x0)c['push'](b[b['length']-0x1]);b['push']({'id':'C-03','description':'Every\x20node\x20has\x20incoming\x20Pair','status':e['orphaned_nodes']['length']===0x0?'pass':'fail','detail':e['orphaned_nodes']['length']===0x0?'All\x20non-entry\x20nodes\x20are\x20reachable':'Orphaned\x20nodes:\x20'+e['orphaned_nodes']['join'](',\x20')});if(e['orphaned_nodes']['length']>0x0)c['push'](b[b['length']-0x1]);b['push']({'id':'C-04','description':'All\x20thresholds\x20achievable','status':e['dead_branches']['length']===0x0?'pass':'warning','detail':e['dead_branches']['length']===0x0?'No\x20dead\x20branches\x20detected':'Potential\x20dead\x20branches:\x20'+e['dead_branches']['length']});if(e['dead_branches']['length']>0x0)d['push'](b[b['length']-0x1]);b['push']({'id':'C-05','description':'All\x20Guards\x20exist\x20on-chain','status':'skip','detail':'Verify\x20at\x20runtime\x20via\x20onchain_objects\x20query\x20for\x20each\x20Guard\x20address'});const h=[];for(const k of a['pairs']){for(const l of k['forwards']){const m=l['named_operator']!==undefined,n=l['permission_index']!==undefined;!m&&!n&&h['push'](k['prev_node']+'->'+k['next_node']+':'+l['name']);}}b['push']({'id':'C-06','description':'Forward\x20permission\x20model\x20correct','status':h['length']===0x0?'pass':'fail','detail':h['length']===0x0?'All\x20Forwards\x20have\x20valid\x20permission':'Invalid\x20Forwards:\x20'+h['join'](',\x20')});if(h['length']>0x0)c['push'](b[b['length']-0x1]);b['push']({'id':'C-07','description':'Terminal\x20nodes\x20have\x20Allocator','status':'skip','detail':'Verify\x20at\x20Service\x20binding\x20stage'}),b['push']({'id':'C-08','description':'Testnet\x20test\x20passed','status':'skip','detail':'Verify\x20at\x20Layer\x204\x20(environment)'}),b['push']({'id':'C-09','description':'machineNode2file\x20backup\x20created','status':'skip','detail':'Recommend\x20exporting\x20before\x20publish'});const i=[];if(!e['within_limits']['max_node_count'])i['push']('MAX_NODE_COUNT='+MAX_NODE_COUNT);if(!e['within_limits']['max_node_pair_count'])i['push']('MAX_NODE_PAIR_COUNT='+MAX_NODE_PAIR_COUNT);if(!e['within_limits']['max_forward_count'])i['push']('MAX_FORWARD_COUNT='+MAX_FORWARD_COUNT);if(!e['within_limits']['max_forward_order_count'])i['push']('MAX_FORWARD_ORDER_COUNT='+MAX_FORWARD_ORDER_COUNT);b['push']({'id':'C-10','description':'On-chain\x20limits\x20respected','status':i['length']===0x0?'pass':'fail','detail':i['length']===0x0?'All\x20limits\x20within\x20bounds':'Violations:\x20'+i['join'](',\x20')});if(i['length']>0x0)c['push'](b[b['length']-0x1]);const j=[];for(const o of a['pairs']){for(const p of o['forwards']){p['permission_index']!==undefined&&p['permission_index']!==null&&p['permission_index']<USER_DEFINED_PERM_INDEX_START&&j['push'](o['prev_node']+'->'+o['next_node']+':'+p['name']+'\x20(idx='+p['permission_index']+')');}}b['push']({'id':'C-11','description':'permissionIndex\x20>=\x20'+USER_DEFINED_PERM_INDEX_START,'status':j['length']===0x0?'pass':'fail','detail':j['length']===0x0?'All\x20permission_index\x20values\x20>=\x20'+USER_DEFINED_PERM_INDEX_START:'permission_index\x20<\x20'+USER_DEFINED_PERM_INDEX_START+':\x20'+j['join'](',\x20')});if(j['length']>0x0)c['push'](b[b['length']-0x1]);return{'passed':c['length']===0x0,'checked_items':b,'failed_items':c,'warnings':d};}export function integrateRiskAssessment(a,b){const c={'nodes':a['nodes'],'pairs':a['pairs'],'b_published':a['b_published'],'b_paused':a['b_paused'],'scene_id':a['scene_id']},d=assessMachineRisks(c,b),e=[],f=[];for(const h of d['detected_risks']){if(h['severity']==='critical'||h['severity']==='high')e['push'](h['rule_id']);else h['severity']==='medium'&&f['push'](h['rule_id']);}let g;if(e['some'](i=>{const j=d['detected_risks']['find'](k=>k['rule_id']===i);return j?.['severity']==='critical';}))g='do_not_publish';else{if(e['length']>0x0)g='fix_first';else f['length']>0x3?g='fix_first':g='publish';}return{'overall_risk_level':d['overall_level'],'blocking_risks':e,'warning_risks':f,'recommendation':g};}export const CONFIRMATION_QUESTIONS=[{'id':'Q1','question':'Reviewed\x20topology\x20and\x20confirmed\x20all\x20nodes/forwards\x20are\x20correct?','expected_response':'yes','blocking':!![]},{'id':'Q2','question':'Tested\x20this\x20Machine\x20on\x20TESTNET\x20with\x20a\x20successful\x20Progress\x20run?','expected_response':'yes','blocking':!![]},{'id':'Q3','question':'All\x20Guards\x20created,\x20bound,\x20and\x20verified\x20via\x20gen_passport?','expected_response':'yes','blocking':!![]},{'id':'Q4','question':'All\x20Allocators\x20configured\x20for\x20terminal\x20nodes?','expected_response':'yes','blocking':!![]},{'id':'Q5','question':'Acknowledge\x20that\x20publishing\x20is\x20IRREVERSIBLE\x20and\x20gas\x20will\x20be\x20consumed?','expected_response':'yes','blocking':!![]},{'id':'Q6','question':'Proceed\x20with\x20publishing\x20this\x20Machine\x20NOW?','expected_response':'yes','blocking':!![]}];export function parseUserConfirmation(a){const b=a['split'](',')['map'](e=>e['trim']()['toLowerCase']()),c=[];for(let e=0x0;e<CONFIRMATION_QUESTIONS['length'];e++){const f=CONFIRMATION_QUESTIONS[e],g=b[e]||'(no\x20answer)',h=g['startsWith']('y')||g==='yes',j=g['startsWith']('n')||g==='no';c['push']({'question_id':f['id'],'response':h?'yes':j?'no':'unclear','raw_input':g});}const d=CONFIRMATION_QUESTIONS['filter'](k=>k['blocking'])['every']((k,l)=>c[l]['response']==='yes');return{'questions_asked':CONFIRMATION_QUESTIONS,'user_responses':c,'approved':d,'declined_reason':d?undefined:'One\x20or\x20more\x20blocking\x20questions\x20answered\x20\x27no\x27','timestamp':new Date()['toISOString']()};}export function generateFullConfirmationText(a,b,c){const d=derivePuzzleFromMachineJson({'nodes':a['nodes'],'pairs':a['pairs'],'scene_id':a['scene_id'],'template_id':a['template_id']}),e=generateConfirmationText(d),f=['╔═══════════════════════════════════════════════════════════════╗','║\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20MACHINE\x20PUBLISH\x20CONFIRMATION\x20REQUIRED\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20║','╚═══════════════════════════════════════════════════════════════╝','','⚠️\x20\x20WARNING:\x20Publishing\x20a\x20Machine\x20is\x20IRREVERSIBLE.','\x20\x20\x20-\x20Nodes,\x20Pairs,\x20Forwards\x20will\x20be\x20FROZEN\x20permanently.','\x20\x20\x20-\x20Gas\x20will\x20be\x20consumed\x20(cannot\x20be\x20refunded).','\x20\x20\x20-\x20Any\x20error\x20requires\x20creating\x20a\x20NEW\x20Machine\x20(with\x20new\x20gas\x20cost).','','═══════════════════════════════════════════════════════════════',e,'═══════════════════════════════════════════════════════════════','RISK\x20ASSESSMENT:','\x20\x20Overall\x20Risk\x20Level:\x20'+c['overall_risk_level']['toUpperCase'](),'\x20\x20Recommendation:\x20\x20\x20\x20\x20'+c['recommendation'],'\x20\x20Blocking\x20Risks:\x20\x20\x20\x20\x20'+(c['blocking_risks']['length']===0x0?'None':c['blocking_risks']['join'](',\x20')),'\x20\x20Warning\x20Risks:\x20\x20\x20\x20\x20'+(c['warning_risks']['length']===0x0?'None':c['warning_risks']['join'](',\x20')),'','═══════════════════════════════════════════════════════════════','STATIC\x20CHECKLIST:','\x20\x20Passed:\x20\x20\x20\x20'+b['checked_items']['filter'](g=>g['status']==='pass')['length']+'\x20/\x20'+b['checked_items']['length'],'\x20\x20Failed:\x20\x20\x20\x20'+b['failed_items']['length'],'\x20\x20Warnings:\x20\x20'+b['warnings']['length'],'\x20\x20Skipped:\x20\x20\x20'+b['checked_items']['filter'](g=>g['status']==='skip')['length'],'',...b['failed_items']['map'](g=>'\x20\x20❌\x20'+g['id']+':\x20'+g['description']+'\x20—\x20'+(g['detail']||'')),...b['warnings']['map'](g=>'\x20\x20⚠️\x20\x20'+g['id']+':\x20'+g['description']+'\x20—\x20'+(g['detail']||'')),'','═══════════════════════════════════════════════════════════════','USER\x20CONFIRMATION\x20QUESTIONS:','',...CONFIRMATION_QUESTIONS['map']((g,h)=>'\x20\x20Q'+(h+0x1)+'.\x20'+g['question']+'\x20[Yes\x20/\x20No]'),'','If\x20you\x20answer\x20\x27No\x27\x20to\x20ANY\x20of\x20Q1-Q5,\x20publish\x20will\x20be\x20BLOCKED.','If\x20you\x20answer\x20\x27No\x27\x20to\x20Q6,\x20publish\x20will\x20be\x20CANCELLED\x20(no\x20gas\x20spent).','','Type\x20your\x20answers\x20(Q1-Q6)\x20separated\x20by\x20commas:'];return f['join']('\x0a');}export function verifyEnvironment(a,b,c){const d=[];for(const g of a['pairs']){for(const h of g['forwards']){h['guard']&&!b['published_guards']['has'](h['guard'])&&d['push']('Guard:\x20'+h['guard']);}}const e=b['testnet_test_passed'],f=c?e:!![];return{'is_testnet':!c,'has_testnet_test_passed':f,'gas_estimation':b['gas_estimation'],'dependency_table_complete':d['length']===0x0,'missing_dependencies':d};}function hashMachineJson(a){const b=JSON['stringify']({'nodes':a['nodes']['map'](d=>d['name']),'pairs':a['pairs']['map'](d=>({'prev':d['prev_node'],'next':d['next_node'],'threshold':d['threshold'],'forwards':d['forwards']['map'](e=>e['name'])}))});let c=0x0;for(let d=0x0;d<b['length'];d++){const e=b['charCodeAt'](d);c=(c<<0x5)-c+e,c=c&c;}return'0x'+(c>>>0x0)['toString'](0x10)['padStart'](0x8,'0');}export function confirmPublish(a,b,c,d){const e={'timestamp':new Date()['toISOString'](),'user_address':b['user_address'],'machine_json_hash':hashMachineJson(a),'template_id':a['template_id'],'scene_id':a['scene_id'],'final_status':'blocked_checklist'},f=runStaticChecklist(a);if(!f['passed'])return{'status':'blocked_checklist','checklist_result':f,'decision_record':{...e,'final_status':'blocked_checklist'},'block_reason':'Checklist\x20failed:\x20'+f['failed_items']['map'](j=>j['id'])['join'](',\x20')};const g=integrateRiskAssessment(a,b);if(g['recommendation']==='do_not_publish')return{'status':'blocked_risk','checklist_result':f,'risk_result':g,'decision_record':{...e,'final_status':'blocked_risk'},'block_reason':'Critical\x20risks\x20detected:\x20'+g['blocking_risks']['join'](',\x20')};if(!d){const j=generateFullConfirmationText(a,f,g);return{'status':'blocked_user','checklist_result':f,'risk_result':g,'confirmation_text':j,'decision_record':{...e,'final_status':'blocked_user'},'block_reason':'Awaiting\x20user\x20confirmation'};}const h=parseUserConfirmation(d);if(!h['approved'])return{'status':'blocked_user','checklist_result':f,'risk_result':g,'user_confirmation':h,'decision_record':{...e,'final_status':'blocked_user'},'block_reason':h['declined_reason']||'User\x20declined'};const i=verifyEnvironment(a,b,c);if(!i['dependency_table_complete']||!i['has_testnet_test_passed']){const k=[];return!i['dependency_table_complete']&&k['push']('missing\x20dependencies:\x20'+i['missing_dependencies']['join'](',\x20')),!i['has_testnet_test_passed']&&k['push']('testnet\x20test\x20not\x20passed\x20(required\x20for\x20mainnet)'),{'status':'blocked_environment','checklist_result':f,'risk_result':g,'user_confirmation':h,'environment_result':i,'decision_record':{...e,'final_status':'blocked_environment'},'block_reason':'Environment\x20issues:\x20'+k['join'](';\x20')};}return{'status':'approved','checklist_result':f,'risk_result':g,'user_confirmation':h,'environment_result':i,'decision_record':{...e,'final_status':'approved'}};}export function overrideBlockWithReason(a,b){if(a['status']!=='blocked_risk')return a;const c=a['risk_result']?.['blocking_risks']['some'](d=>d['includes']('CRITICAL')||d['includes']('critical'));if(c)return{...a,'block_reason':'Cannot\x20override\x20CRITICAL\x20risks'};return{...a,'status':'approved','block_reason':undefined,'decision_record':{...a['decision_record'],'final_status':'approved'}};}export function progressiveCheck(a,b){const c=runStaticChecklist(a);if(b==='R5')return filterChecklist(c,['C-01','C-02','C-03','C-04','C-06','C-10']);if(b==='R6')return filterChecklist(c,['C-01','C-02','C-03','C-04','C-05','C-06','C-10']);return c;}function filterChecklist(a,b){const c=a['checked_items']['filter'](d=>b['includes'](d['id']));return{'passed':c['filter'](d=>d['status']==='fail')['length']===0x0,'checked_items':c,'failed_items':c['filter'](d=>d['status']==='fail'),'warnings':c['filter'](d=>d['status']==='warning')};}export function prePublishHook(a,b,c){const d=confirmPublish(a,b,c);if(d['status']!=='blocked_user'&&d['status']!=='approved')return{'proceed':![],'error':formatBlockError(d),'confirmGateResult':d};if(d['status']==='blocked_user'&&d['confirmation_text'])return{'proceed':![],'error':d['confirmation_text'],'confirmGateResult':d};return{'proceed':!![],'confirmGateResult':d};}export function postConfirmationHook(a,b,c,d){const e=confirmPublish(a,b,c,d);if(e['status']!=='approved')return{'proceed':![],'error':formatBlockError(e),'confirmGateResult':e};return{'proceed':!![],'confirmGateResult':e};}export function formatBlockError(a){const b=['❌\x20MACHINE\x20PUBLISH\x20BLOCKED','','Status:\x20'+a['status'],'Reason:\x20'+(a['block_reason']||'(no\x20reason\x20provided)'),''];if(a['status']==='blocked_checklist'){b['push']('Failed\x20checklist\x20items:');for(const c of a['checklist_result']['failed_items']){b['push']('\x20\x20-\x20'+c['id']+':\x20'+c['description']),b['push']('\x20\x20\x20\x20Detail:\x20'+(c['detail']||'(no\x20detail)'));}}if(a['status']==='blocked_risk'&&a['risk_result']){b['push']('Blocking\x20risks:');for(const d of a['risk_result']['blocking_risks']){b['push']('\x20\x20-\x20'+d);}b['push'](''),b['push']('Recommendation:\x20'+a['risk_result']['recommendation']);}if(a['status']==='blocked_environment'&&a['environment_result']){b['push']('Environment\x20issues:');for(const e of a['environment_result']['missing_dependencies']){b['push']('\x20\x20-\x20Missing\x20dependency:\x20'+e);}!a['environment_result']['has_testnet_test_passed']&&b['push']('\x20\x20-\x20Testnet\x20test\x20NOT\x20passed\x20(required\x20for\x20mainnet)');}return b['join']('\x0a');}export const MACHINE_CONFIRM_VERSION='1.0.0';export const MACHINE_CHECKLIST_ITEMS_COUNT=PUBLISH_CHECKLIST['length'];export const MACHINE_CONFIRMATION_QUESTIONS_COUNT=CONFIRMATION_QUESTIONS['length'];