@wowok/agent-mcp 2.4.1 → 2.5.0

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 (348) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +29 -1621
  7. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  8. package/dist/knowledge/allocation-confirm.js +534 -0
  9. package/dist/knowledge/allocation-context.d.ts +58 -0
  10. package/dist/knowledge/allocation-context.js +249 -0
  11. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  12. package/dist/knowledge/allocation-ledger.js +463 -0
  13. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  14. package/dist/knowledge/allocation-puzzle.js +298 -0
  15. package/dist/knowledge/allocation-risk.d.ts +78 -0
  16. package/dist/knowledge/allocation-risk.js +568 -0
  17. package/dist/knowledge/allocation-templates.d.ts +38 -0
  18. package/dist/knowledge/allocation-templates.js +970 -0
  19. package/dist/knowledge/allocation-translation.d.ts +72 -0
  20. package/dist/knowledge/allocation-translation.js +585 -0
  21. package/dist/knowledge/arb-risk.d.ts +37 -0
  22. package/dist/knowledge/arb-risk.js +210 -0
  23. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  24. package/dist/knowledge/arbitration-confirm.js +559 -0
  25. package/dist/knowledge/arbitration-context.d.ts +81 -0
  26. package/dist/knowledge/arbitration-context.js +505 -0
  27. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  28. package/dist/knowledge/arbitration-ledger.js +521 -0
  29. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  30. package/dist/knowledge/arbitration-puzzle.js +304 -0
  31. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  32. package/dist/knowledge/arbitration-risk.js +433 -0
  33. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  34. package/dist/knowledge/arbitration-templates.js +276 -0
  35. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  36. package/dist/knowledge/arbitration-translation.js +487 -0
  37. package/dist/knowledge/bridge-risk.d.ts +36 -0
  38. package/dist/knowledge/bridge-risk.js +263 -0
  39. package/dist/knowledge/contact-risk.d.ts +32 -0
  40. package/dist/knowledge/contact-risk.js +200 -0
  41. package/dist/knowledge/demand-confirm.d.ts +32 -0
  42. package/dist/knowledge/demand-confirm.js +206 -0
  43. package/dist/knowledge/demand-risk.d.ts +30 -0
  44. package/dist/knowledge/demand-risk.js +240 -0
  45. package/dist/knowledge/demand-translation.d.ts +55 -0
  46. package/dist/knowledge/demand-translation.js +354 -0
  47. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  48. package/dist/knowledge/deployment-scanner.js +762 -0
  49. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  50. package/dist/knowledge/examples-scanner-cli.js +26 -0
  51. package/dist/knowledge/examples-scanner.d.ts +121 -0
  52. package/dist/knowledge/examples-scanner.js +825 -0
  53. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  54. package/dist/knowledge/flywheel-loop.js +32 -3
  55. package/dist/knowledge/glossary.js +3 -1
  56. package/dist/knowledge/guard-confirm.d.ts +86 -0
  57. package/dist/knowledge/guard-confirm.js +406 -0
  58. package/dist/knowledge/guard-context.d.ts +56 -0
  59. package/dist/knowledge/guard-context.js +287 -0
  60. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  61. package/dist/knowledge/guard-design-patterns.js +257 -0
  62. package/dist/knowledge/guard-ledger.js +14 -0
  63. package/dist/knowledge/guard-lint.d.ts +1 -0
  64. package/dist/knowledge/guard-lint.js +83 -3
  65. package/dist/knowledge/guard-migration.d.ts +48 -0
  66. package/dist/knowledge/guard-migration.js +228 -0
  67. package/dist/knowledge/guard-puzzle.js +3 -2
  68. package/dist/knowledge/guard-risk.d.ts +3 -1
  69. package/dist/knowledge/guard-risk.js +832 -64
  70. package/dist/knowledge/guard-templates.d.ts +1 -0
  71. package/dist/knowledge/guard-templates.js +278 -2
  72. package/dist/knowledge/guard-translation.js +6 -5
  73. package/dist/knowledge/index.d.ts +342 -0
  74. package/dist/knowledge/index.js +344 -0
  75. package/dist/knowledge/machine-confirm.d.ts +102 -0
  76. package/dist/knowledge/machine-confirm.js +559 -0
  77. package/dist/knowledge/machine-context.d.ts +160 -0
  78. package/dist/knowledge/machine-context.js +812 -0
  79. package/dist/knowledge/machine-ledger.d.ts +41 -0
  80. package/dist/knowledge/machine-ledger.js +315 -0
  81. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  82. package/dist/knowledge/machine-puzzle.js +494 -0
  83. package/dist/knowledge/machine-risk.d.ts +75 -0
  84. package/dist/knowledge/machine-risk.js +644 -0
  85. package/dist/knowledge/machine-templates.d.ts +92 -0
  86. package/dist/knowledge/machine-templates.js +1592 -0
  87. package/dist/knowledge/machine-topology.d.ts +57 -0
  88. package/dist/knowledge/machine-topology.js +234 -0
  89. package/dist/knowledge/machine-translation.d.ts +96 -0
  90. package/dist/knowledge/machine-translation.js +513 -0
  91. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  92. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  93. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  94. package/dist/knowledge/mcp-schema-audit.js +772 -0
  95. package/dist/knowledge/onchain-constants.d.ts +4 -0
  96. package/dist/knowledge/onchain-constants.js +35 -0
  97. package/dist/knowledge/order-confirm.d.ts +115 -0
  98. package/dist/knowledge/order-confirm.js +573 -0
  99. package/dist/knowledge/order-context.d.ts +66 -0
  100. package/dist/knowledge/order-context.js +390 -0
  101. package/dist/knowledge/order-ledger.d.ts +69 -0
  102. package/dist/knowledge/order-ledger.js +341 -0
  103. package/dist/knowledge/order-puzzle.d.ts +159 -0
  104. package/dist/knowledge/order-puzzle.js +255 -0
  105. package/dist/knowledge/order-risk.d.ts +66 -0
  106. package/dist/knowledge/order-risk.js +653 -0
  107. package/dist/knowledge/order-templates.d.ts +50 -0
  108. package/dist/knowledge/order-templates.js +368 -0
  109. package/dist/knowledge/order-translation.d.ts +78 -0
  110. package/dist/knowledge/order-translation.js +550 -0
  111. package/dist/knowledge/passport-confirm.d.ts +130 -0
  112. package/dist/knowledge/passport-confirm.js +531 -0
  113. package/dist/knowledge/passport-context.d.ts +59 -0
  114. package/dist/knowledge/passport-context.js +306 -0
  115. package/dist/knowledge/passport-ledger.d.ts +48 -0
  116. package/dist/knowledge/passport-ledger.js +282 -0
  117. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  118. package/dist/knowledge/passport-puzzle.js +333 -0
  119. package/dist/knowledge/passport-risk.d.ts +70 -0
  120. package/dist/knowledge/passport-risk.js +450 -0
  121. package/dist/knowledge/passport-templates.d.ts +40 -0
  122. package/dist/knowledge/passport-templates.js +568 -0
  123. package/dist/knowledge/passport-translation.d.ts +68 -0
  124. package/dist/knowledge/passport-translation.js +516 -0
  125. package/dist/knowledge/payment-risk.d.ts +33 -0
  126. package/dist/knowledge/payment-risk.js +182 -0
  127. package/dist/knowledge/permission-confirm.d.ts +110 -0
  128. package/dist/knowledge/permission-confirm.js +426 -0
  129. package/dist/knowledge/permission-context.d.ts +58 -0
  130. package/dist/knowledge/permission-context.js +224 -0
  131. package/dist/knowledge/permission-ledger.d.ts +38 -0
  132. package/dist/knowledge/permission-ledger.js +403 -0
  133. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  134. package/dist/knowledge/permission-puzzle.js +173 -0
  135. package/dist/knowledge/permission-risk.d.ts +76 -0
  136. package/dist/knowledge/permission-risk.js +411 -0
  137. package/dist/knowledge/permission-templates.d.ts +38 -0
  138. package/dist/knowledge/permission-templates.js +234 -0
  139. package/dist/knowledge/permission-translation.d.ts +57 -0
  140. package/dist/knowledge/permission-translation.js +350 -0
  141. package/dist/knowledge/personal-risk.d.ts +36 -0
  142. package/dist/knowledge/personal-risk.js +212 -0
  143. package/dist/knowledge/progress-confirm.d.ts +108 -0
  144. package/dist/knowledge/progress-confirm.js +456 -0
  145. package/dist/knowledge/progress-context.d.ts +123 -0
  146. package/dist/knowledge/progress-context.js +452 -0
  147. package/dist/knowledge/progress-ledger.d.ts +63 -0
  148. package/dist/knowledge/progress-ledger.js +327 -0
  149. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  150. package/dist/knowledge/progress-puzzle.js +219 -0
  151. package/dist/knowledge/progress-risk.d.ts +74 -0
  152. package/dist/knowledge/progress-risk.js +461 -0
  153. package/dist/knowledge/progress-templates.d.ts +38 -0
  154. package/dist/knowledge/progress-templates.js +228 -0
  155. package/dist/knowledge/progress-translation.d.ts +52 -0
  156. package/dist/knowledge/progress-translation.js +401 -0
  157. package/dist/knowledge/proof-confirm.d.ts +31 -0
  158. package/dist/knowledge/proof-confirm.js +187 -0
  159. package/dist/knowledge/proof-risk.d.ts +33 -0
  160. package/dist/knowledge/proof-risk.js +207 -0
  161. package/dist/knowledge/proof-translation.d.ts +52 -0
  162. package/dist/knowledge/proof-translation.js +283 -0
  163. package/dist/knowledge/registrar-risk.d.ts +34 -0
  164. package/dist/knowledge/registrar-risk.js +217 -0
  165. package/dist/knowledge/repository-confirm.d.ts +36 -0
  166. package/dist/knowledge/repository-confirm.js +242 -0
  167. package/dist/knowledge/repository-risk.d.ts +40 -0
  168. package/dist/knowledge/repository-risk.js +312 -0
  169. package/dist/knowledge/repository-translation.d.ts +58 -0
  170. package/dist/knowledge/repository-translation.js +422 -0
  171. package/dist/knowledge/resource-risk.d.ts +32 -0
  172. package/dist/knowledge/resource-risk.js +157 -0
  173. package/dist/knowledge/reward-confirm.d.ts +113 -0
  174. package/dist/knowledge/reward-confirm.js +496 -0
  175. package/dist/knowledge/reward-context.d.ts +127 -0
  176. package/dist/knowledge/reward-context.js +504 -0
  177. package/dist/knowledge/reward-ledger.d.ts +96 -0
  178. package/dist/knowledge/reward-ledger.js +502 -0
  179. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  180. package/dist/knowledge/reward-puzzle.js +288 -0
  181. package/dist/knowledge/reward-risk.d.ts +84 -0
  182. package/dist/knowledge/reward-risk.js +545 -0
  183. package/dist/knowledge/reward-translation.d.ts +58 -0
  184. package/dist/knowledge/reward-translation.js +501 -0
  185. package/dist/knowledge/safety-rules.js +11 -3
  186. package/dist/knowledge/scenario-modes.d.ts +53 -0
  187. package/dist/knowledge/scenario-modes.js +302 -0
  188. package/dist/knowledge/service-confirm.d.ts +152 -0
  189. package/dist/knowledge/service-confirm.js +699 -0
  190. package/dist/knowledge/service-context.d.ts +66 -0
  191. package/dist/knowledge/service-context.js +403 -0
  192. package/dist/knowledge/service-ledger.d.ts +71 -0
  193. package/dist/knowledge/service-ledger.js +609 -0
  194. package/dist/knowledge/service-puzzle.d.ts +158 -0
  195. package/dist/knowledge/service-puzzle.js +236 -0
  196. package/dist/knowledge/service-risk.d.ts +108 -0
  197. package/dist/knowledge/service-risk.js +615 -0
  198. package/dist/knowledge/service-templates.d.ts +39 -0
  199. package/dist/knowledge/service-templates.js +418 -0
  200. package/dist/knowledge/service-translation.d.ts +103 -0
  201. package/dist/knowledge/service-translation.js +622 -0
  202. package/dist/knowledge/tools-reference.d.ts +17 -0
  203. package/dist/knowledge/tools-reference.js +151 -0
  204. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  205. package/dist/knowledge/treasury-confirm.js +512 -0
  206. package/dist/knowledge/treasury-context.d.ts +64 -0
  207. package/dist/knowledge/treasury-context.js +363 -0
  208. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  209. package/dist/knowledge/treasury-ledger.js +300 -0
  210. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  211. package/dist/knowledge/treasury-puzzle.js +216 -0
  212. package/dist/knowledge/treasury-risk.d.ts +86 -0
  213. package/dist/knowledge/treasury-risk.js +440 -0
  214. package/dist/knowledge/treasury-templates.d.ts +38 -0
  215. package/dist/knowledge/treasury-templates.js +316 -0
  216. package/dist/knowledge/treasury-translation.d.ts +78 -0
  217. package/dist/knowledge/treasury-translation.js +498 -0
  218. package/dist/knowledge/util-risk.d.ts +30 -0
  219. package/dist/knowledge/util-risk.js +135 -0
  220. package/dist/project/business-puzzle.d.ts +47 -0
  221. package/dist/project/business-puzzle.js +372 -0
  222. package/dist/project/deployment-doc.d.ts +61 -0
  223. package/dist/project/deployment-doc.js +432 -0
  224. package/dist/project/graph.d.ts +1 -0
  225. package/dist/project/graph.js +27 -1
  226. package/dist/project/index.d.ts +1 -0
  227. package/dist/project/index.js +39 -2
  228. package/dist/project/namespace.d.ts +11 -1
  229. package/dist/project/namespace.js +27 -2
  230. package/dist/project/query.d.ts +2 -0
  231. package/dist/project/query.js +56 -15
  232. package/dist/project/risk-aggregator.d.ts +50 -0
  233. package/dist/project/risk-aggregator.js +280 -0
  234. package/dist/project/substep-trace.d.ts +130 -0
  235. package/dist/project/substep-trace.js +332 -0
  236. package/dist/rules.d.ts +12 -0
  237. package/dist/rules.js +9 -0
  238. package/dist/schema/call/allocation.d.ts +44 -44
  239. package/dist/schema/call/arbitration.d.ts +141 -141
  240. package/dist/schema/call/base.d.ts +386 -386
  241. package/dist/schema/call/base.js +6 -6
  242. package/dist/schema/call/bridge-handler.d.ts +5 -2
  243. package/dist/schema/call/bridge.d.ts +159 -159
  244. package/dist/schema/call/contact.d.ts +110 -110
  245. package/dist/schema/call/demand.d.ts +76 -76
  246. package/dist/schema/call/handler.d.ts +2 -3
  247. package/dist/schema/call/handler.js +1 -1
  248. package/dist/schema/call/machine.d.ts +96 -96
  249. package/dist/schema/call/order.d.ts +98 -110
  250. package/dist/schema/call/permission-handler.d.ts +5 -0
  251. package/dist/schema/call/permission-handler.js +54 -0
  252. package/dist/schema/call/permission.d.ts +108 -108
  253. package/dist/schema/call/personal.d.ts +14 -14
  254. package/dist/schema/call/progress.d.ts +57 -72
  255. package/dist/schema/call/progress.js +7 -4
  256. package/dist/schema/call/proof.d.ts +18 -18
  257. package/dist/schema/call/proof.js +12 -7
  258. package/dist/schema/call/repository.d.ts +154 -154
  259. package/dist/schema/call/reward.d.ts +55 -55
  260. package/dist/schema/call/semantic.js +1 -1
  261. package/dist/schema/call/service.d.ts +238 -238
  262. package/dist/schema/call/treasury.d.ts +93 -93
  263. package/dist/schema/config/index.d.ts +178 -5
  264. package/dist/schema/config/index.js +52 -1
  265. package/dist/schema/local/index.d.ts +3554 -836
  266. package/dist/schema/local/index.js +2 -1
  267. package/dist/schema/messenger/index.d.ts +162 -162
  268. package/dist/schema/operations.d.ts +1102 -1118
  269. package/dist/schema/operations.js +7 -1
  270. package/dist/schema/project/index.d.ts +1392 -6
  271. package/dist/schema/project/index.js +426 -2
  272. package/dist/schema/query/index.d.ts +818 -818
  273. package/dist/schema/query/index.js +15 -9
  274. package/dist/schema/schema-query/index.d.ts +23 -3
  275. package/dist/schema/schema-query/index.js +13 -2
  276. package/dist/schema/sync-layer4.d.ts +21 -0
  277. package/dist/schema/sync-layer4.js +261 -0
  278. package/dist/schema/trust/index.d.ts +26 -26
  279. package/dist/schema/utils/guard-query-utils.d.ts +7 -0
  280. package/dist/schema/utils/guard-query-utils.js +14 -1
  281. package/dist/schemas/account_operation.output.json +718 -0
  282. package/dist/schemas/bridge_operation.output.json +1 -1
  283. package/dist/schemas/config_operation.output.json +173 -0
  284. package/dist/schemas/index.json +9 -1
  285. package/dist/schemas/local_info_operation.output.json +718 -0
  286. package/dist/schemas/local_mark_operation.output.json +718 -0
  287. package/dist/schemas/messenger_operation.output.json +1 -1
  288. package/dist/schemas/onchain_events.output.json +1 -1
  289. package/dist/schemas/onchain_operations.output.json +5 -4
  290. package/dist/schemas/onchain_operations.schema.json +1813 -333
  291. package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
  292. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  293. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  294. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  295. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  296. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  297. package/dist/schemas/onchain_operations_guard.schema.json +584 -70
  298. package/dist/schemas/onchain_operations_machine.schema.json +4 -6
  299. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  300. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  301. package/dist/schemas/onchain_operations_permission.schema.json +2 -1
  302. package/dist/schemas/onchain_operations_personal.schema.json +2 -1
  303. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  304. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  305. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  306. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  307. package/dist/schemas/onchain_operations_service.schema.json +4 -6
  308. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  309. package/dist/schemas/onchain_table_data.output.json +6 -12
  310. package/dist/schemas/onchain_table_data.schema.json +32 -1
  311. package/dist/schemas/project_operation.output.json +879 -0
  312. package/dist/schemas/project_operation.schema.json +473 -2
  313. package/dist/schemas/query_toolkit.output.json +14906 -6
  314. package/dist/schemas/schema_query.output.json +38 -1
  315. package/dist/telemetry/index.d.ts +1 -1
  316. package/dist/tools/handlers/bridge.d.ts +1 -0
  317. package/dist/tools/handlers/bridge.js +1 -0
  318. package/dist/tools/handlers/config.d.ts +2 -0
  319. package/dist/tools/handlers/config.js +74 -0
  320. package/dist/tools/handlers/file-export.d.ts +3 -0
  321. package/dist/tools/handlers/file-export.js +90 -0
  322. package/dist/tools/handlers/local.d.ts +3 -0
  323. package/dist/tools/handlers/local.js +38 -0
  324. package/dist/tools/handlers/messenger.d.ts +16 -0
  325. package/dist/tools/handlers/messenger.js +188 -0
  326. package/dist/tools/handlers/onchain.d.ts +2 -0
  327. package/dist/tools/handlers/onchain.js +248 -0
  328. package/dist/tools/handlers/project.d.ts +2 -0
  329. package/dist/tools/handlers/project.js +293 -0
  330. package/dist/tools/handlers/query.d.ts +5 -0
  331. package/dist/tools/handlers/query.js +256 -0
  332. package/dist/tools/handlers/schema-query.d.ts +2 -0
  333. package/dist/tools/handlers/schema-query.js +93 -0
  334. package/dist/tools/handlers/trust.d.ts +2 -0
  335. package/dist/tools/handlers/trust.js +194 -0
  336. package/dist/tools/handlers/wip.d.ts +2 -0
  337. package/dist/tools/handlers/wip.js +44 -0
  338. package/dist/tools/index.d.ts +13 -0
  339. package/dist/tools/index.js +526 -0
  340. package/dist/tools/rules-hook.d.ts +2 -0
  341. package/dist/tools/rules-hook.js +23 -0
  342. package/dist/tools/shared.d.ts +20 -0
  343. package/dist/tools/shared.js +130 -0
  344. package/dist/tools/types.d.ts +35 -0
  345. package/dist/tools/types.js +1 -0
  346. package/dist/tools/wrap.d.ts +14 -0
  347. package/dist/tools/wrap.js +267 -0
  348. package/package.json +20 -6
@@ -0,0 +1,699 @@
1
+ import { MAX_SALE_COUNT, MAX_REPOSITORY_COUNT, MAX_ARBITRATION_COUNT, MAX_DISCOUNT_COUNT_ONCE, MAX_DISCOUNT_TOTAL_COUNT, MAX_WIP_LENGTH, MAX_WIP_HASH_LENGTH, } from "@wowok/wowok";
2
+ import { assessServiceRisks, } from "./service-risk.js";
3
+ export const SERVICE_PUBLISH_CHECKLIST = [
4
+ { id: "C-S-01", description: "Sales count <= MAX_SALE_COUNT (50)", passed: false, message: "" },
5
+ { id: "C-S-02", description: "Repositories count <= MAX_REPOSITORY_COUNT (100)", passed: false, message: "" },
6
+ { id: "C-S-03", description: "Arbitrations count <= MAX_ARBITRATION_COUNT (20)", passed: false, message: "" },
7
+ { id: "C-S-04", description: "Rewards count <= MAX_REWARD_COUNT (20)", passed: false, message: "" },
8
+ { id: "C-S-05", description: "WIP URL length <= MAX_WIP_LENGTH (1024) for each sale", passed: false, message: "" },
9
+ { id: "C-S-06", description: "WIP hash length <= MAX_WIP_HASH_LENGTH (64) — sha256 hex", passed: false, message: "" },
10
+ { id: "C-S-07", description: "WIP hash NOT empty when wip URL is set (tamper protection)", passed: false, message: "" },
11
+ { id: "C-S-08", description: "Discount count <= MAX_DISCOUNT_TOTAL_COUNT (20000)", passed: false, message: "" },
12
+ { id: "C-S-09", description: "Discount per-call <= MAX_DISCOUNT_COUNT_ONCE (1000)", passed: false, message: "" },
13
+ { id: "C-S-10", description: "Publish: order_allocators MUST be set (F-S-18, E_NO_ALLOCATOR)", passed: false, message: "" },
14
+ { id: "C-S-11", description: "Publish: if compensation_fund > 0, arbitrations non-empty (F-S-19)", passed: false, message: "" },
15
+ { id: "C-S-12", description: "Post-publish: machine modification BLOCKED (F-S-20)", passed: false, message: "" },
16
+ { id: "C-S-13", description: "Post-publish: arbitrations modification BLOCKED (F-S-21)", passed: false, message: "" },
17
+ { id: "C-S-14", description: "Post-publish: order_allocators modification BLOCKED (F-S-22)", passed: false, message: "" },
18
+ { id: "C-S-15", description: "compensation_fund_withdraw requires bPaused=true + lock_duration expired (F-S-25, F-S-26)", passed: false, message: "" },
19
+ { id: "C-S-16", description: "Address fields valid (0x prefix, length >= 40)", passed: false, message: "" },
20
+ { id: "C-S-17", description: "Publish operation double-confirmed (bPublished irreversible)", passed: false, message: "" },
21
+ { id: "C-S-18", description: "Ownership transfer double-confirmed (IRREVERSIBLE)", passed: false, message: "" },
22
+ ];
23
+ function runStaticChecklist(input) {
24
+ const items = SERVICE_PUBLISH_CHECKLIST.map(c => ({ ...c }));
25
+ const data = input.service_json;
26
+ const isPublished = input.current_bPublished ?? false;
27
+ if (data.sales && (data.sales.op === "add" || data.sales.op === "set")) {
28
+ const currentCount = input.current_sales_count ?? 0;
29
+ const newCount = data.sales.op === "set"
30
+ ? data.sales.sales.length
31
+ : currentCount + data.sales.sales.length;
32
+ const cs01 = items.find(i => i.id === "C-S-01");
33
+ cs01.passed = newCount <= MAX_SALE_COUNT;
34
+ cs01.message = cs01.passed ? "" : `sales count ${newCount} > ${MAX_SALE_COUNT}`;
35
+ }
36
+ else {
37
+ items.find(i => i.id === "C-S-01").passed = true;
38
+ }
39
+ if (data.repositories && (data.repositories.op === "add" || data.repositories.op === "set")) {
40
+ const currentCount = input.current_repositories_count ?? 0;
41
+ const newCount = data.repositories.op === "set"
42
+ ? data.repositories.objects.length
43
+ : currentCount + data.repositories.objects.length;
44
+ const cs02 = items.find(i => i.id === "C-S-02");
45
+ cs02.passed = newCount <= MAX_REPOSITORY_COUNT;
46
+ cs02.message = cs02.passed ? "" : `repositories count ${newCount} > ${MAX_REPOSITORY_COUNT}`;
47
+ }
48
+ else {
49
+ items.find(i => i.id === "C-S-02").passed = true;
50
+ }
51
+ if (data.arbitrations && (data.arbitrations.op === "add" || data.arbitrations.op === "set")) {
52
+ const currentCount = input.current_arbitrations_count ?? 0;
53
+ const newCount = data.arbitrations.op === "set"
54
+ ? data.arbitrations.objects.length
55
+ : currentCount + data.arbitrations.objects.length;
56
+ const cs03 = items.find(i => i.id === "C-S-03");
57
+ cs03.passed = newCount <= MAX_ARBITRATION_COUNT;
58
+ cs03.message = cs03.passed ? "" : `arbitrations count ${newCount} > ${MAX_ARBITRATION_COUNT}`;
59
+ }
60
+ else {
61
+ items.find(i => i.id === "C-S-03").passed = true;
62
+ }
63
+ if (data.rewards && (data.rewards.op === "add" || data.rewards.op === "set")) {
64
+ const currentCount = input.current_rewards_count ?? 0;
65
+ const newCount = data.rewards.op === "set"
66
+ ? data.rewards.objects.length
67
+ : currentCount + data.rewards.objects.length;
68
+ const cs04 = items.find(i => i.id === "C-S-04");
69
+ cs04.passed = newCount <= 20;
70
+ cs04.message = cs04.passed ? "" : `rewards count ${newCount} > 20`;
71
+ }
72
+ else {
73
+ items.find(i => i.id === "C-S-04").passed = true;
74
+ }
75
+ if (data.sales && (data.sales.op === "add" || data.sales.op === "set")) {
76
+ let urlOk = true, hashLenOk = true, hashNotEmptyOk = true;
77
+ let urlMsg = "", hashLenMsg = "", hashEmptyMsg = "";
78
+ for (const s of data.sales.sales) {
79
+ if (s.wip && s.wip.length > MAX_WIP_LENGTH) {
80
+ urlOk = false;
81
+ urlMsg = `sale "${s.name}" wip URL length ${s.wip.length} > ${MAX_WIP_LENGTH}`;
82
+ break;
83
+ }
84
+ if (s.wip_hash && s.wip_hash.length > MAX_WIP_HASH_LENGTH) {
85
+ hashLenOk = false;
86
+ hashLenMsg = `sale "${s.name}" wip_hash length ${s.wip_hash.length} > ${MAX_WIP_HASH_LENGTH}`;
87
+ break;
88
+ }
89
+ if (s.wip && !s.wip_hash) {
90
+ hashNotEmptyOk = false;
91
+ hashEmptyMsg = `sale "${s.name}" has wip URL but no wip_hash (tamper risk)`;
92
+ break;
93
+ }
94
+ }
95
+ const cs05 = items.find(i => i.id === "C-S-05");
96
+ cs05.passed = urlOk;
97
+ cs05.message = urlMsg;
98
+ const cs06 = items.find(i => i.id === "C-S-06");
99
+ cs06.passed = hashLenOk;
100
+ cs06.message = hashLenMsg;
101
+ const cs07 = items.find(i => i.id === "C-S-07");
102
+ cs07.passed = hashNotEmptyOk;
103
+ cs07.message = hashEmptyMsg;
104
+ }
105
+ else {
106
+ items.find(i => i.id === "C-S-05").passed = true;
107
+ items.find(i => i.id === "C-S-06").passed = true;
108
+ items.find(i => i.id === "C-S-07").passed = true;
109
+ }
110
+ if (data.discount) {
111
+ const total = data.discount.count;
112
+ const cs08 = items.find(i => i.id === "C-S-08");
113
+ cs08.passed = total <= MAX_DISCOUNT_TOTAL_COUNT;
114
+ cs08.message = cs08.passed ? "" : `discount total count ${total} > ${MAX_DISCOUNT_TOTAL_COUNT}`;
115
+ const cs09 = items.find(i => i.id === "C-S-09");
116
+ cs09.passed = total <= MAX_DISCOUNT_COUNT_ONCE;
117
+ cs09.message = cs09.passed ? "" : `discount per-call count ${total} > ${MAX_DISCOUNT_COUNT_ONCE}`;
118
+ }
119
+ else {
120
+ items.find(i => i.id === "C-S-08").passed = true;
121
+ items.find(i => i.id === "C-S-09").passed = true;
122
+ }
123
+ if (data.publish) {
124
+ const hasAllocators = input.current_order_allocators_set === true || data.order_allocators !== undefined;
125
+ const cs10 = items.find(i => i.id === "C-S-10");
126
+ cs10.passed = hasAllocators;
127
+ cs10.message = hasAllocators ? "" : "publish requires order_allocators (F-S-18, E_NO_ALLOCATOR)";
128
+ }
129
+ else {
130
+ items.find(i => i.id === "C-S-10").passed = true;
131
+ }
132
+ if (data.publish) {
133
+ const compBalance = input.current_compensation_fund_balance ?? "0";
134
+ const arbCount = input.current_arbitrations_count ?? 0;
135
+ const hasArbFromInput = data.arbitrations && "objects" in data.arbitrations ? data.arbitrations.objects.length : 0;
136
+ const totalArb = arbCount + hasArbFromInput;
137
+ const cs11 = items.find(i => i.id === "C-S-11");
138
+ if (BigInt(compBalance) > 0n && totalArb === 0) {
139
+ cs11.passed = false;
140
+ cs11.message = `compensation_fund ${compBalance} > 0 but no arbitrations (F-S-19)`;
141
+ }
142
+ else {
143
+ cs11.passed = true;
144
+ }
145
+ }
146
+ else {
147
+ items.find(i => i.id === "C-S-11").passed = true;
148
+ }
149
+ if (isPublished && data.machine !== undefined) {
150
+ const cs12 = items.find(i => i.id === "C-S-12");
151
+ cs12.passed = false;
152
+ cs12.message = "machine is IMMUTABLE post-publish (F-S-20)";
153
+ }
154
+ else {
155
+ items.find(i => i.id === "C-S-12").passed = true;
156
+ }
157
+ if (isPublished && data.arbitrations !== undefined) {
158
+ const cs13 = items.find(i => i.id === "C-S-13");
159
+ cs13.passed = false;
160
+ cs13.message = "arbitrations is IMMUTABLE post-publish (F-S-21)";
161
+ }
162
+ else {
163
+ items.find(i => i.id === "C-S-13").passed = true;
164
+ }
165
+ if (isPublished && data.order_allocators !== undefined) {
166
+ const cs14 = items.find(i => i.id === "C-S-14");
167
+ cs14.passed = false;
168
+ cs14.message = "order_allocators is IMMUTABLE post-publish (F-S-22)";
169
+ }
170
+ else {
171
+ items.find(i => i.id === "C-S-14").passed = true;
172
+ }
173
+ if (data.compensation_fund_withdraw) {
174
+ const paused = input.current_bPaused ?? false;
175
+ const cs15 = items.find(i => i.id === "C-S-15");
176
+ if (!paused) {
177
+ cs15.passed = false;
178
+ cs15.message = "compensation_fund_withdraw requires bPaused=true (F-S-26)";
179
+ }
180
+ else {
181
+ cs15.passed = true;
182
+ cs15.message = "Paused OK — verify lock_duration expired on-chain";
183
+ }
184
+ }
185
+ else {
186
+ items.find(i => i.id === "C-S-15").passed = true;
187
+ }
188
+ const addresses = [];
189
+ if (data.object)
190
+ addresses.push(data.object);
191
+ if (data.machine)
192
+ addresses.push(data.machine);
193
+ if (data.buy_guard)
194
+ addresses.push(data.buy_guard);
195
+ if (data.arbitrations && "objects" in data.arbitrations)
196
+ addresses.push(...data.arbitrations.objects);
197
+ if (data.repositories && "objects" in data.repositories)
198
+ addresses.push(...data.repositories.objects);
199
+ if (data.rewards && "objects" in data.rewards)
200
+ addresses.push(...data.rewards.objects);
201
+ if (data.builder)
202
+ addresses.push(data.builder);
203
+ if (data.um)
204
+ addresses.push(data.um);
205
+ const cs16 = items.find(i => i.id === "C-S-16");
206
+ if (addresses.length === 0) {
207
+ cs16.passed = true;
208
+ }
209
+ else {
210
+ const invalid = addresses.filter(a => !a.startsWith("0x") || a.length < 40);
211
+ cs16.passed = invalid.length === 0;
212
+ cs16.message = invalid.length === 0 ? "" : `Invalid addresses: ${invalid.slice(0, 3).join(", ")}${invalid.length > 3 ? "..." : ""}`;
213
+ }
214
+ if (data.publish) {
215
+ const cs17 = items.find(i => i.id === "C-S-17");
216
+ cs17.passed = false;
217
+ cs17.message = "Pending user confirmation in Layer 3 (QS1)";
218
+ }
219
+ else {
220
+ items.find(i => i.id === "C-S-17").passed = true;
221
+ }
222
+ if (data.builder) {
223
+ const cs18 = items.find(i => i.id === "C-S-18");
224
+ cs18.passed = false;
225
+ cs18.message = "Pending user confirmation in Layer 3 (QS2)";
226
+ }
227
+ else {
228
+ items.find(i => i.id === "C-S-18").passed = true;
229
+ }
230
+ const allPassed = items.filter(i => i.id !== "C-S-17" && i.id !== "C-S-18").every(i => i.passed);
231
+ return { all_passed: allPassed, items };
232
+ }
233
+ function adaptRiskAssessment(input) {
234
+ const ctx = {
235
+ object: input.service_json.object,
236
+ description: input.service_json.description,
237
+ location: input.service_json.location,
238
+ sales: input.service_json.sales,
239
+ repositories: input.service_json.repositories,
240
+ rewards: input.service_json.rewards,
241
+ arbitrations: input.service_json.arbitrations,
242
+ machine: input.service_json.machine,
243
+ discount: input.service_json.discount,
244
+ customer_required: input.service_json.customer_required,
245
+ order_allocators: input.service_json.order_allocators,
246
+ buy_guard: input.service_json.buy_guard,
247
+ compensation_fund_add: input.service_json.compensation_fund_add,
248
+ setting_locked_time_add: input.service_json.setting_locked_time_add,
249
+ compensation_fund_receive: input.service_json.compensation_fund_receive,
250
+ owner_receive: input.service_json.owner_receive,
251
+ pause: input.service_json.pause,
252
+ publish: input.service_json.publish,
253
+ um: input.service_json.um,
254
+ order_new: input.service_json.order_new,
255
+ current_bPublished: input.current_bPublished,
256
+ current_bPaused: input.current_bPaused,
257
+ current_compensation_fund_balance: input.current_compensation_fund_balance,
258
+ current_setting_lock_duration: input.current_setting_lock_duration,
259
+ current_arbitrations_count: input.current_arbitrations_count,
260
+ current_rewards_count: input.current_rewards_count,
261
+ current_repositories_count: input.current_repositories_count,
262
+ current_sales_count: input.current_sales_count,
263
+ current_machine_bound: input.current_machine_bound,
264
+ current_order_allocators_set: input.current_order_allocators_set,
265
+ builder: input.service_json.builder,
266
+ target_objects_types: input.target_objects_types,
267
+ };
268
+ return assessServiceRisks(ctx);
269
+ }
270
+ export const SERVICE_CONFIRMATION_QUESTIONS = [
271
+ {
272
+ id: "QS1",
273
+ question: "⚠️ PUBLISH is IRREVERSIBLE — once published, machine/arbitrations/order_allocators become permanently immutable. Do you confirm all configurations are correct and you're ready to publish?",
274
+ requires_explicit_yes: true,
275
+ related_risk_ids: ["R-S-3-01", "R-S-4-01"],
276
+ },
277
+ {
278
+ id: "QS2",
279
+ question: "⚠️ Ownership transfer is IRREVERSIBLE — original owner will lose ALL control over the Service, including compensation_fund and all bindings. Do you confirm the new owner address is correct?",
280
+ requires_explicit_yes: true,
281
+ related_risk_ids: ["R-S-3-04"],
282
+ },
283
+ {
284
+ id: "QS3",
285
+ question: "Are all sales items configured with valid wip_hash (sha256 of the WIP file content)? Missing or incorrect hashes create tampering risks.",
286
+ requires_explicit_yes: true,
287
+ related_risk_ids: ["R-S-2-01"],
288
+ },
289
+ {
290
+ id: "QS4",
291
+ question: "If publishing with compensation_fund > 0, are Arbitration objects configured and their reputations verified? Owners cannot add new Arbitration objects post-publish.",
292
+ requires_explicit_yes: true,
293
+ related_risk_ids: ["R-S-5-02"],
294
+ },
295
+ {
296
+ id: "QS5",
297
+ question: "Is the order_allocators configuration final? It becomes PERMANENTLY immutable after publish — fee splits cannot be adjusted without creating a new Service.",
298
+ requires_explicit_yes: true,
299
+ related_risk_ids: ["R-S-5-03", "R-S-4-03"],
300
+ },
301
+ {
302
+ id: "QS6",
303
+ question: "If binding a Machine, is it published and verified? Machine binding is permanent post-publish — Progress objects will inherit this Machine forever.",
304
+ requires_explicit_yes: true,
305
+ related_risk_ids: ["R-S-5-01"],
306
+ },
307
+ {
308
+ id: "QS7",
309
+ question: "If using buy_guard, is the Guard configuration appropriate for your sale phase (whitelist for pre-sale, null for public sale)? buy_guard remains mutable post-publish.",
310
+ requires_explicit_yes: false,
311
+ related_risk_ids: ["R-S-3-03"],
312
+ },
313
+ {
314
+ id: "QS8",
315
+ question: "For discount operations: are discount counts within limits (<=1000 per call, <=20000 total)? Expired or exhausted discounts cannot be re-issued.",
316
+ requires_explicit_yes: false,
317
+ related_risk_ids: ["R-S-2-04"],
318
+ },
319
+ {
320
+ id: "QS9",
321
+ question: "For order placement: are you aware that stock is deducted at the quote stage and NOT rolled back if later stages fail? Monitor failed transactions and re-add stock manually if needed.",
322
+ requires_explicit_yes: true,
323
+ related_risk_ids: ["R-S-2-03"],
324
+ },
325
+ {
326
+ id: "QS10",
327
+ question: "Have you exported the current Service JSON as a backup before this operation?",
328
+ requires_explicit_yes: false,
329
+ },
330
+ ];
331
+ function processUserConfirmation(input, assessment) {
332
+ const questions = [...SERVICE_CONFIRMATION_QUESTIONS];
333
+ const data = input.service_json;
334
+ const irrelevant = [];
335
+ if (!data.publish)
336
+ irrelevant.push("QS1");
337
+ if (!data.builder)
338
+ irrelevant.push("QS2");
339
+ if (!data.sales || data.sales.op === "clear" || data.sales.op === "remove")
340
+ irrelevant.push("QS3");
341
+ if (!data.publish && !(data.compensation_fund_add && BigInt(String(data.compensation_fund_add.balance)) > 0n))
342
+ irrelevant.push("QS4");
343
+ if (!data.publish && !data.order_allocators)
344
+ irrelevant.push("QS5");
345
+ if (!data.machine)
346
+ irrelevant.push("QS6");
347
+ if (data.buy_guard === undefined)
348
+ irrelevant.push("QS7");
349
+ if (!data.discount)
350
+ irrelevant.push("QS8");
351
+ if (!data.order_new)
352
+ irrelevant.push("QS9");
353
+ const filtered = questions.filter(q => !irrelevant.includes(q.id));
354
+ if (input.skip_user_confirmation) {
355
+ return {
356
+ questions_asked: filtered,
357
+ responses: filtered.map(q => ({ question_id: q.id, response: "yes" })),
358
+ all_confirmed: true,
359
+ };
360
+ }
361
+ return {
362
+ questions_asked: filtered,
363
+ responses: [],
364
+ all_confirmed: false,
365
+ };
366
+ }
367
+ function verifyEnvironment(input) {
368
+ const checks = [];
369
+ const data = input.service_json;
370
+ if (data.object) {
371
+ checks.push({
372
+ name: "object_exists",
373
+ passed: true,
374
+ message: `Service object ${data.object} assumed to exist`,
375
+ });
376
+ }
377
+ if (data.publish) {
378
+ checks.push({
379
+ name: "signer_has_publish_permission",
380
+ passed: true,
381
+ message: "Signer must hold SERVICE_PUBLISH (311) permission",
382
+ });
383
+ }
384
+ if (data.builder) {
385
+ checks.push({
386
+ name: "signer_is_owner",
387
+ passed: true,
388
+ message: "Signer must be Service owner for transfer (builder)",
389
+ });
390
+ }
391
+ if (data.pause !== undefined) {
392
+ checks.push({
393
+ name: "signer_has_pause_permission",
394
+ passed: true,
395
+ message: "Signer must hold SERVICE_PAUSE (310) permission",
396
+ });
397
+ }
398
+ if (data.publish) {
399
+ if (!input.current_order_allocators_set && data.order_allocators === undefined) {
400
+ checks.push({
401
+ name: "order_allocators_set",
402
+ passed: false,
403
+ message: "Publish blocked: order_allocators not set (E_NO_ALLOCATOR)",
404
+ });
405
+ }
406
+ const compBalance = input.current_compensation_fund_balance ?? "0";
407
+ const arbCount = input.current_arbitrations_count ?? 0;
408
+ const arbFromInput = data.arbitrations && "objects" in data.arbitrations ? data.arbitrations.objects.length : 0;
409
+ if (BigInt(compBalance) > 0n && (arbCount + arbFromInput) === 0) {
410
+ checks.push({
411
+ name: "arbitrations_for_compensation_fund",
412
+ passed: false,
413
+ message: "Publish blocked: compensation_fund > 0 but no arbitrations (E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)",
414
+ });
415
+ }
416
+ }
417
+ if (input.current_bPublished) {
418
+ if (data.machine !== undefined) {
419
+ checks.push({
420
+ name: "machine_immutable_post_publish",
421
+ passed: false,
422
+ message: "machine cannot be modified post-publish (F-S-20)",
423
+ });
424
+ }
425
+ if (data.arbitrations !== undefined) {
426
+ checks.push({
427
+ name: "arbitrations_immutable_post_publish",
428
+ passed: false,
429
+ message: "arbitrations cannot be modified post-publish (F-S-21)",
430
+ });
431
+ }
432
+ if (data.order_allocators !== undefined) {
433
+ checks.push({
434
+ name: "order_allocators_immutable_post_publish",
435
+ passed: false,
436
+ message: "order_allocators cannot be modified post-publish (F-S-22)",
437
+ });
438
+ }
439
+ }
440
+ if (data.compensation_fund_withdraw && !input.current_bPaused) {
441
+ checks.push({
442
+ name: "compensation_fund_withdraw_requires_paused",
443
+ passed: false,
444
+ message: "compensation_fund_withdraw requires bPaused=true (F-S-26)",
445
+ });
446
+ }
447
+ const allPassed = checks.every(c => c.passed);
448
+ return { passed: allPassed, checks };
449
+ }
450
+ export const SERVICE_CONFIRM_VERSION = "1.0.0";
451
+ export function runServiceConfirmGate(input) {
452
+ const layersPassed = [];
453
+ const layersFailed = [];
454
+ const checklist = runStaticChecklist(input);
455
+ if (!checklist.all_passed) {
456
+ layersFailed.push("L1_checklist");
457
+ return {
458
+ status: "blocked_checklist",
459
+ checklist_result: checklist,
460
+ confirmation_text: generateConfirmationText(input, checklist),
461
+ block_reason: `Checklist failed: ${checklist.items.filter(i => !i.passed && i.id !== "C-S-17" && i.id !== "C-S-18").map(i => i.id).join(", ")}`,
462
+ decision_record: {
463
+ timestamp: new Date().toISOString(),
464
+ gate_version: SERVICE_CONFIRM_VERSION,
465
+ final_status: "blocked_checklist",
466
+ layers_passed: layersPassed,
467
+ layers_failed: layersFailed,
468
+ },
469
+ };
470
+ }
471
+ layersPassed.push("L1_checklist");
472
+ const assessment = adaptRiskAssessment(input);
473
+ const hasCritical = assessment.risks.some(r => r.level === "CRITICAL");
474
+ if (hasCritical) {
475
+ layersFailed.push("L2_risk");
476
+ return {
477
+ status: "blocked_risk",
478
+ checklist_result: checklist,
479
+ risk_result: assessment,
480
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
481
+ block_reason: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
482
+ decision_record: {
483
+ timestamp: new Date().toISOString(),
484
+ gate_version: SERVICE_CONFIRM_VERSION,
485
+ final_status: "blocked_risk",
486
+ layers_passed: layersPassed,
487
+ layers_failed: layersFailed,
488
+ },
489
+ };
490
+ }
491
+ layersPassed.push("L2_risk");
492
+ const userConf = processUserConfirmation(input, assessment);
493
+ if (!userConf.all_confirmed) {
494
+ if (input.service_json.publish) {
495
+ const cs17 = checklist.items.find(i => i.id === "C-S-17");
496
+ if (cs17) {
497
+ const qs1 = userConf.responses.find(r => r.question_id === "QS1");
498
+ cs17.passed = qs1?.response === "yes";
499
+ cs17.message = cs17.passed ? "" : "Publish not confirmed by user (QS1)";
500
+ }
501
+ }
502
+ if (input.service_json.builder) {
503
+ const cs18 = checklist.items.find(i => i.id === "C-S-18");
504
+ if (cs18) {
505
+ const qs2 = userConf.responses.find(r => r.question_id === "QS2");
506
+ cs18.passed = qs2?.response === "yes";
507
+ cs18.message = cs18.passed ? "" : "Transfer not confirmed by user (QS2)";
508
+ }
509
+ }
510
+ if (input.service_json.publish) {
511
+ const cs17 = checklist.items.find(i => i.id === "C-S-17");
512
+ if (cs17 && !cs17.passed) {
513
+ layersFailed.push("L3_user");
514
+ return {
515
+ status: "blocked_user",
516
+ checklist_result: checklist,
517
+ risk_result: assessment,
518
+ user_confirmation: userConf,
519
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
520
+ block_reason: "User did not confirm publish (QS1)",
521
+ decision_record: {
522
+ timestamp: new Date().toISOString(),
523
+ gate_version: SERVICE_CONFIRM_VERSION,
524
+ final_status: "blocked_user",
525
+ layers_passed: layersPassed,
526
+ layers_failed: layersFailed,
527
+ },
528
+ };
529
+ }
530
+ }
531
+ if (input.service_json.builder) {
532
+ const cs18 = checklist.items.find(i => i.id === "C-S-18");
533
+ if (cs18 && !cs18.passed) {
534
+ layersFailed.push("L3_user");
535
+ return {
536
+ status: "blocked_user",
537
+ checklist_result: checklist,
538
+ risk_result: assessment,
539
+ user_confirmation: userConf,
540
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
541
+ block_reason: "User did not confirm ownership transfer (QS2)",
542
+ decision_record: {
543
+ timestamp: new Date().toISOString(),
544
+ gate_version: SERVICE_CONFIRM_VERSION,
545
+ final_status: "blocked_user",
546
+ layers_passed: layersPassed,
547
+ layers_failed: layersFailed,
548
+ },
549
+ };
550
+ }
551
+ }
552
+ }
553
+ layersPassed.push("L3_user");
554
+ if (input.skip_environment_check) {
555
+ layersPassed.push("L4_environment");
556
+ }
557
+ else {
558
+ const env = verifyEnvironment(input);
559
+ if (!env.passed) {
560
+ layersFailed.push("L4_environment");
561
+ return {
562
+ status: "blocked_environment",
563
+ checklist_result: checklist,
564
+ risk_result: assessment,
565
+ user_confirmation: userConf,
566
+ environment_result: env,
567
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
568
+ block_reason: `Environment check failed: ${env.checks.filter(c => !c.passed).map(c => c.name).join(", ")}`,
569
+ decision_record: {
570
+ timestamp: new Date().toISOString(),
571
+ gate_version: SERVICE_CONFIRM_VERSION,
572
+ final_status: "blocked_environment",
573
+ layers_passed: layersPassed,
574
+ layers_failed: layersFailed,
575
+ },
576
+ };
577
+ }
578
+ layersPassed.push("L4_environment");
579
+ }
580
+ return {
581
+ status: "approved",
582
+ checklist_result: checklist,
583
+ risk_result: assessment,
584
+ user_confirmation: userConf,
585
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
586
+ decision_record: {
587
+ timestamp: new Date().toISOString(),
588
+ gate_version: SERVICE_CONFIRM_VERSION,
589
+ final_status: "approved",
590
+ layers_passed: layersPassed,
591
+ layers_failed: layersFailed,
592
+ },
593
+ };
594
+ }
595
+ function generateConfirmationText(input, checklist, assessment) {
596
+ const lines = [];
597
+ const data = input.service_json;
598
+ lines.push("═══ Service Confirmation ═══");
599
+ lines.push("");
600
+ if (data.object) {
601
+ lines.push(`Service: ${data.object}`);
602
+ }
603
+ else {
604
+ lines.push("Service: NEW (to be created)");
605
+ }
606
+ if (data.description)
607
+ lines.push(`Description: ${data.description}`);
608
+ if (input.current_bPublished !== undefined)
609
+ lines.push(`Currently published: ${input.current_bPublished}`);
610
+ if (input.current_bPaused !== undefined)
611
+ lines.push(`Currently paused: ${input.current_bPaused}`);
612
+ lines.push("");
613
+ lines.push("─ Checklist ──────────────────");
614
+ for (const item of checklist.items) {
615
+ const mark = item.passed ? "✓" : "✗";
616
+ lines.push(` ${mark} ${item.id}: ${item.description}${item.message ? " — " + item.message : ""}`);
617
+ }
618
+ lines.push("");
619
+ if (assessment) {
620
+ lines.push("─ Risk Assessment ──────────────────");
621
+ lines.push(`Overall: ${assessment.overall_risk}`);
622
+ lines.push(`Detected: ${assessment.risks.length} risk(s)`);
623
+ for (const r of assessment.risks.slice(0, 10)) {
624
+ lines.push(` [${r.level}] ${r.id}: ${r.title}`);
625
+ }
626
+ if (assessment.risks.length > 10) {
627
+ lines.push(` ... and ${assessment.risks.length - 10} more`);
628
+ }
629
+ lines.push("");
630
+ }
631
+ lines.push("─ Operations ──────────────────");
632
+ if (data.sales)
633
+ lines.push(`- Sales ${data.sales.op}`);
634
+ if (data.machine !== undefined)
635
+ lines.push(`- Machine: ${data.machine ?? "(unbind)"} ${input.current_bPublished ? "[BLOCKED post-publish]" : ""}`);
636
+ if (data.buy_guard !== undefined)
637
+ lines.push(`- Buy Guard: ${data.buy_guard ?? "(clear)"}`);
638
+ if (data.arbitrations)
639
+ lines.push(`- Arbitrations ${data.arbitrations.op}`);
640
+ if (data.repositories)
641
+ lines.push(`- Repositories ${data.repositories.op}`);
642
+ if (data.rewards)
643
+ lines.push(`- Rewards ${data.rewards.op}`);
644
+ if (data.order_allocators !== undefined)
645
+ lines.push(`- Order Allocators: ${data.order_allocators ? "(set)" : "(clear)"}`);
646
+ if (data.discount)
647
+ lines.push(`- Discount: ${data.discount.name} (${data.discount.count} coupons)`);
648
+ if (data.pause !== undefined)
649
+ lines.push(`- Pause: ${data.pause}`);
650
+ if (data.publish)
651
+ lines.push(`- ⚠️ PUBLISH (IRREVERSIBLE)`);
652
+ if (data.compensation_fund_add)
653
+ lines.push(`- Compensation fund deposit: ${data.compensation_fund_add.balance}`);
654
+ if (data.compensation_fund_withdraw)
655
+ lines.push(`- ⚠️ Compensation fund withdraw (requires paused + lock expired)`);
656
+ if (data.setting_locked_time_add !== undefined)
657
+ lines.push(`- Setting lock +${data.setting_locked_time_add}ms`);
658
+ if (data.order_new)
659
+ lines.push(`- ⚠️ ORDER NEW (8-stage flow, stock deducted at quote)`);
660
+ if (data.builder)
661
+ lines.push(`- ⚠️ TRANSFER to: ${data.builder} (IRREVERSIBLE)`);
662
+ if (data.um !== undefined)
663
+ lines.push(`- UM: ${data.um ?? "(revoke)"}`);
664
+ lines.push("");
665
+ return lines.join("\n");
666
+ }
667
+ export function progressiveServiceCheck(input) {
668
+ const checklist = runStaticChecklist(input);
669
+ if (!checklist.all_passed) {
670
+ return {
671
+ stage: "checklist",
672
+ status: "fail",
673
+ message: `Checklist failed: ${checklist.items.filter(i => !i.passed && i.id !== "C-S-17" && i.id !== "C-S-18").map(i => i.id).join(", ")}`,
674
+ next_action: "Fix failing checklist items",
675
+ };
676
+ }
677
+ const assessment = adaptRiskAssessment(input);
678
+ if (assessment.risks.some(r => r.level === "CRITICAL")) {
679
+ return {
680
+ stage: "risk",
681
+ status: "fail",
682
+ message: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
683
+ next_action: "Resolve CRITICAL risks before proceeding",
684
+ };
685
+ }
686
+ if (assessment.needs_human_review) {
687
+ return {
688
+ stage: "confirmation",
689
+ status: "pending",
690
+ message: "Human review required for HIGH risks",
691
+ next_action: "Confirm risk acceptance via user questions",
692
+ };
693
+ }
694
+ return {
695
+ stage: "complete",
696
+ status: "pass",
697
+ message: "All checks passed",
698
+ };
699
+ }