@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,651 +1 @@
1
- import { MAX_SALE_COUNT, MAX_REPOSITORY_COUNT, MAX_ARBITRATION_COUNT, MAX_DISCOUNT_TOTAL_COUNT, MAX_WIP_LENGTH, MAX_WIP_HASH_LENGTH, } from "@wowok/wowok";
2
- const R_S_1_01 = {
3
- id: "R-S-1-01",
4
- category: "structural",
5
- trigger: "sales count exceeds MAX_SALE_COUNT (50)",
6
- check: (ctx) => {
7
- const count = ctx.current_sales_count ?? 0;
8
- if (ctx.sales && (ctx.sales.op === "add" || ctx.sales.op === "set")) {
9
- const newCount = ctx.sales.op === "set" ? ctx.sales.sales.length : count + ctx.sales.sales.length;
10
- if (newCount > MAX_SALE_COUNT) {
11
- return {
12
- id: "R-S-1-01",
13
- level: "HIGH",
14
- category: "structural",
15
- title: "Sales count exceeds limit",
16
- description: `Service would have ${newCount} sales items, exceeds MAX_SALE_COUNT ${MAX_SALE_COUNT}`,
17
- affected_stakeholders: ["owner", "system"],
18
- scenario: "Adding too many product SKUs",
19
- mitigation: "Split into multiple Service objects or remove discontinued items",
20
- evidence: `sales_count=${newCount}`,
21
- };
22
- }
23
- }
24
- return null;
25
- },
26
- };
27
- const R_S_1_02 = {
28
- id: "R-S-1-02",
29
- category: "structural",
30
- trigger: "repositories count exceeds MAX_REPOSITORY_COUNT (100)",
31
- check: (ctx) => {
32
- const count = ctx.current_repositories_count ?? 0;
33
- if (ctx.repositories && (ctx.repositories.op === "add" || ctx.repositories.op === "set")) {
34
- const newCount = ctx.repositories.op === "set" ? ctx.repositories.objects.length : count + ctx.repositories.objects.length;
35
- if (newCount > MAX_REPOSITORY_COUNT) {
36
- return {
37
- id: "R-S-1-02",
38
- level: "MEDIUM",
39
- category: "structural",
40
- title: "Repositories count exceeds limit",
41
- description: `Service would have ${newCount} repositories, exceeds MAX_REPOSITORY_COUNT ${MAX_REPOSITORY_COUNT}`,
42
- affected_stakeholders: ["owner"],
43
- scenario: "Binding too many data repositories",
44
- mitigation: "Consolidate repositories or remove inactive ones",
45
- evidence: `repositories_count=${newCount}`,
46
- };
47
- }
48
- }
49
- return null;
50
- },
51
- };
52
- const R_S_1_03 = {
53
- id: "R-S-1-03",
54
- category: "structural",
55
- trigger: "arbitrations count exceeds MAX_ARBITRATION_COUNT (20)",
56
- check: (ctx) => {
57
- const count = ctx.current_arbitrations_count ?? 0;
58
- if (ctx.arbitrations && (ctx.arbitrations.op === "add" || ctx.arbitrations.op === "set")) {
59
- const newCount = ctx.arbitrations.op === "set" ? ctx.arbitrations.objects.length : count + ctx.arbitrations.objects.length;
60
- if (newCount > MAX_ARBITRATION_COUNT) {
61
- return {
62
- id: "R-S-1-03",
63
- level: "HIGH",
64
- category: "structural",
65
- title: "Arbitrations count exceeds limit",
66
- description: `Service would have ${newCount} arbitrations, exceeds MAX_ARBITRATION_COUNT ${MAX_ARBITRATION_COUNT}`,
67
- affected_stakeholders: ["owner", "arbitrator"],
68
- scenario: "Binding too many Arbitration objects",
69
- mitigation: "Use 1-3 Arbitration objects covering different dispute scopes",
70
- evidence: `arbitrations_count=${newCount}`,
71
- };
72
- }
73
- }
74
- return null;
75
- },
76
- };
77
- const R_S_1_04 = {
78
- id: "R-S-1-04",
79
- category: "structural",
80
- trigger: "WIP hash length exceeds MAX_WIP_HASH_LENGTH (64) or URL exceeds MAX_WIP_LENGTH (1024)",
81
- check: (ctx) => {
82
- if (ctx.sales && (ctx.sales.op === "add" || ctx.sales.op === "set")) {
83
- for (const s of ctx.sales.sales) {
84
- if (s.wip_hash && s.wip_hash.length > MAX_WIP_HASH_LENGTH) {
85
- return {
86
- id: "R-S-1-04",
87
- level: "HIGH",
88
- category: "structural",
89
- title: "WIP hash length exceeds limit",
90
- description: `Sale "${s.name}" wip_hash length ${s.wip_hash.length} > MAX_WIP_HASH_LENGTH ${MAX_WIP_HASH_LENGTH}`,
91
- affected_stakeholders: ["owner", "customer"],
92
- scenario: "Malformed WIP hash (should be sha256 hex, 64 chars)",
93
- mitigation: "Use sha256 hex hash (64 characters, no prefix)",
94
- evidence: `wip_hash_length=${s.wip_hash.length}`,
95
- };
96
- }
97
- if (s.wip && s.wip.length > MAX_WIP_LENGTH) {
98
- return {
99
- id: "R-S-1-04",
100
- level: "HIGH",
101
- category: "structural",
102
- title: "WIP URL length exceeds limit",
103
- description: `Sale "${s.name}" wip URL length ${s.wip.length} > MAX_WIP_LENGTH ${MAX_WIP_LENGTH}`,
104
- affected_stakeholders: ["owner"],
105
- scenario: "WIP URL too long (use IPFS or short HTTPS URL)",
106
- mitigation: "Use IPFS CID or shorter URL",
107
- evidence: `wip_url_length=${s.wip.length}`,
108
- };
109
- }
110
- }
111
- }
112
- return null;
113
- },
114
- };
115
- const R_S_1_05 = {
116
- id: "R-S-1-05",
117
- category: "structural",
118
- trigger: "sale.wip is a local path / localhost / LAN URL (not network-deployable) — every customer order fails",
119
- check: (ctx) => {
120
- if (ctx.sales && (ctx.sales.op === "add" || ctx.sales.op === "set")) {
121
- for (const s of ctx.sales.sales) {
122
- if (s.wip && s.wip !== "") {
123
- let localType = null;
124
- const w = s.wip;
125
- if (/^[A-Za-z]:[\\/]/.test(w) || w.startsWith("/") || w.startsWith("./") || w.startsWith("../")) {
126
- localType = "local filesystem path";
127
- }
128
- else if (/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)([:/]|$)/i.test(w)) {
129
- localType = "localhost/loopback URL";
130
- }
131
- else if (/^https?:\/\/(10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3})([:/]|$)/i.test(w)) {
132
- localType = "LAN (private IP) URL";
133
- }
134
- else if (!/^https?:\/\//i.test(w) && !w.startsWith("ipfs://") && !w.startsWith("data:")) {
135
- localType = "unrecognized format (not a network URL)";
136
- }
137
- if (localType) {
138
- return {
139
- id: "R-S-1-05",
140
- level: "CRITICAL",
141
- category: "structural",
142
- title: "WIP is not network-deployed — every customer order will fail",
143
- description: `Sale "${s.name}" wip "${s.wip}" is a ${localType}. It passes set-time verification ` +
144
- `on the merchant's own machine but is unreachable by customers on other machines — ` +
145
- `order_new aborts 100% when a customer tries to buy.`,
146
- affected_stakeholders: ["owner", "customer"],
147
- scenario: "Merchant sets wip to a local file path / localhost / LAN URL and publishes the Service; " +
148
- "the on-chain wip points at the merchant's machine; customers cannot fetch it.",
149
- mitigation: "Deploy the .wip file to a public host (GitHub Pages, IPFS, or your own website) and set " +
150
- "sale.wip to the public URL. Or leave sale.wip empty (\"\") to skip WIP verification " +
151
- "(TESTING ONLY — not recommended for production).",
152
- evidence: `sale=${s.name}, wip=${s.wip}`,
153
- };
154
- }
155
- }
156
- }
157
- }
158
- return null;
159
- },
160
- };
161
- const R_S_2_01 = {
162
- id: "R-S-2-01",
163
- category: "semantic",
164
- trigger: "WIP hash tampering risk — owner updates WIP file without updating wip_hash",
165
- check: (ctx) => {
166
- if (ctx.sales && (ctx.sales.op === "add" || ctx.sales.op === "set")) {
167
- for (const s of ctx.sales.sales) {
168
- if (s.wip && !s.wip_hash) {
169
- return {
170
- id: "R-S-2-01",
171
- level: "CRITICAL",
172
- category: "semantic",
173
- title: "WIP hash missing — tampering risk",
174
- description: `Sale "${s.name}" has wip URL but no wip_hash. Owner could replace the WIP file without customers noticing.`,
175
- affected_stakeholders: ["customer", "owner"],
176
- scenario: "Owner sets wip without hash, then changes file content later",
177
- mitigation: "Always compute sha256(wip_file_content) and set as wip_hash. SDK auto-derives if omitted, but explicit hash is safer.",
178
- evidence: `sale=${s.name}`,
179
- };
180
- }
181
- }
182
- }
183
- return null;
184
- },
185
- };
186
- const R_S_2_02 = {
187
- id: "R-S-2-02",
188
- category: "semantic",
189
- trigger: "compensation_fund confused with Service balance (internal Balance<T>)",
190
- check: (ctx) => {
191
- if (ctx.compensation_fund_add) {
192
- return {
193
- id: "R-S-2-02",
194
- level: "HIGH",
195
- category: "semantic",
196
- title: "compensation_fund is internal Balance<T>, NOT Service-owned Treasury",
197
- description: `Depositing ${ctx.compensation_fund_add.balance} to compensation_fund. This balance is internal to Service<T> and is consumed by arbitration::compensation_claim, not by owner withdrawals. Owner can only withdraw via compensation_fund_withdraw (requires bPaused=true + lock_duration expired).`,
198
- affected_stakeholders: ["owner", "arbitrator", "customer"],
199
- scenario: "Owner confuses compensation_fund with general Treasury",
200
- mitigation: "Use external Treasury (referenced via order_allocators.sharing.who=Entity) for general funds. Use compensation_fund only for arbitration payouts.",
201
- evidence: `deposit=${ctx.compensation_fund_add.balance}`,
202
- };
203
- }
204
- return null;
205
- },
206
- };
207
- const R_S_2_03 = {
208
- id: "R-S-2-03",
209
- category: "semantic",
210
- trigger: "quote side effect — stock deduction not rolled back on later failure",
211
- check: (ctx) => {
212
- if (ctx.order_new && ctx.order_new.buy.items.length > 0) {
213
- return {
214
- id: "R-S-2-03",
215
- level: "HIGH",
216
- category: "semantic",
217
- title: "Order flow: stock deducted at quote stage — NOT rolled back on failure",
218
- description: `Order will deduct stock at Stage 3 (quote). If Stages 4-7 fail, stock remains deducted. Customer must manually re-add stock or accept the loss.`,
219
- affected_stakeholders: ["owner", "customer"],
220
- scenario: "Customer's transaction fails after quote but stock is gone",
221
- mitigation: "1) Monitor failed transactions and re-add stock via stock_add. 2) Set sales suspension during high-failure periods. 3) Use small batch orders to limit blast radius.",
222
- evidence: `items=${ctx.order_new.buy.items.length}`,
223
- };
224
- }
225
- return null;
226
- },
227
- };
228
- const R_S_2_04 = {
229
- id: "R-S-2-04",
230
- category: "semantic",
231
- trigger: "Discount issuance — verify type and total count semantics",
232
- check: (ctx) => {
233
- if (ctx.discount) {
234
- const count = ctx.discount.count;
235
- if (count > MAX_DISCOUNT_TOTAL_COUNT) {
236
- return {
237
- id: "R-S-2-04",
238
- level: "MEDIUM",
239
- category: "semantic",
240
- title: "Discount count exceeds total cap",
241
- description: `Issuing ${count} discounts exceeds MAX_DISCOUNT_TOTAL_COUNT ${MAX_DISCOUNT_TOTAL_COUNT}`,
242
- affected_stakeholders: ["owner"],
243
- scenario: "Bulk discount issuance",
244
- mitigation: `Issue in batches of <= 1000 (MAX_DISCOUNT_COUNT_ONCE) and keep total <= ${MAX_DISCOUNT_TOTAL_COUNT}`,
245
- evidence: `count=${count}`,
246
- };
247
- }
248
- }
249
- return null;
250
- },
251
- };
252
- const R_S_2_05 = {
253
- id: "R-S-2-05",
254
- category: "semantic",
255
- trigger: "Order placed without verifying WIP hash — buyer passes empty wip_hash",
256
- check: (ctx) => {
257
- if (ctx.order_new) {
258
- const emptyHashItems = ctx.order_new.buy.items.filter(i => i.wip_hash === "");
259
- if (emptyHashItems.length > 0) {
260
- return {
261
- id: "R-S-2-05",
262
- level: "MEDIUM",
263
- category: "semantic",
264
- title: "Order with empty wip_hash — SDK auto-fills from sale",
265
- description: `${emptyHashItems.length} item(s) have empty wip_hash. SDK will auto-fill from sale.wip_hash at order time. If owner updates the WIP file between viewing and ordering, buyer receives the new (potentially different) content.`,
266
- affected_stakeholders: ["customer"],
267
- scenario: "Time-of-check to time-of-use WIP mismatch",
268
- mitigation: "Buyer should explicitly pass the wip_hash they saw when viewing the product. Empty string is convenience but riskier.",
269
- evidence: `empty_hash_items=${emptyHashItems.length}`,
270
- };
271
- }
272
- }
273
- return null;
274
- },
275
- };
276
- const R_S_3_01 = {
277
- id: "R-S-3-01",
278
- category: "authority",
279
- trigger: "publish operation — requires SERVICE_PUBLISH (311) + prerequisites",
280
- check: (ctx) => {
281
- if (!ctx.publish)
282
- return null;
283
- const blockers = [];
284
- if (!ctx.current_order_allocators_set)
285
- blockers.push("order_allocators not set (F-S-18, E_NO_ALLOCATOR)");
286
- const compBalance = ctx.current_compensation_fund_balance ?? "0";
287
- if (BigInt(compBalance) > 0n && (ctx.current_arbitrations_count ?? 0) === 0) {
288
- blockers.push("compensation_fund > 0 but no arbitrations (F-S-19, E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)");
289
- }
290
- if (blockers.length > 0) {
291
- return {
292
- id: "R-S-3-01",
293
- level: "CRITICAL",
294
- category: "authority",
295
- title: "Publish blocked — prerequisites not met",
296
- description: `Cannot publish: ${blockers.join("; ")}`,
297
- affected_stakeholders: ["owner"],
298
- scenario: "Owner attempts publish without configuring prerequisites",
299
- mitigation: "Configure order_allocators (and arbitrations if compensation_fund > 0) before publish",
300
- evidence: `blockers=${blockers.length}`,
301
- };
302
- }
303
- return null;
304
- },
305
- };
306
- const R_S_3_02 = {
307
- id: "R-S-3-02",
308
- category: "authority",
309
- trigger: "pause operation — affects new orders but not existing Progress",
310
- check: (ctx) => {
311
- if (ctx.pause === undefined)
312
- return null;
313
- return {
314
- id: "R-S-3-02",
315
- level: "MEDIUM",
316
- category: "authority",
317
- title: ctx.pause ? "Pausing Service — new orders blocked, existing Progress continues" : "Resuming Service — new orders accepted",
318
- description: ctx.pause
319
- ? "Service.bPaused = true will reject new orders (E_SERVICE_PAUSED). Existing orders' Progress continues normally."
320
- : "Service.bPaused = false will allow new orders again.",
321
- affected_stakeholders: ["owner", "customer"],
322
- scenario: ctx.pause ? "Owner pauses for maintenance/stockout" : "Owner resumes after maintenance",
323
- mitigation: ctx.pause ? "Communicate pause to customers. Use compensation_fund_withdraw only when paused." : "Verify stock levels before resuming.",
324
- evidence: `pause=${ctx.pause}`,
325
- };
326
- },
327
- };
328
- const R_S_3_03 = {
329
- id: "R-S-3-03",
330
- category: "authority",
331
- trigger: "buy_guard change — post-publish mutable (unusual exception)",
332
- check: (ctx) => {
333
- if (ctx.buy_guard === undefined)
334
- return null;
335
- if (ctx.current_bPublished) {
336
- return {
337
- id: "R-S-3-03",
338
- level: "MEDIUM",
339
- category: "authority",
340
- title: "buy_guard change post-publish — unusual mutability",
341
- description: `buy_guard is the ONLY publish-locked-field exception: it remains mutable post-publish. Other fields (machine/arbitrations/order_allocators) are immutable.`,
342
- affected_stakeholders: ["owner", "customer"],
343
- scenario: "Owner changes buy_guard strategy after publish (e.g. whitelist → public)",
344
- mitigation: "Document buy_guard changes for transparency. Customers should re-verify buy_guard before ordering.",
345
- evidence: `buy_guard=${ctx.buy_guard ?? "(cleared)"}`,
346
- };
347
- }
348
- return null;
349
- },
350
- };
351
- const R_S_3_04 = {
352
- id: "R-S-3-04",
353
- category: "authority",
354
- trigger: "Ownership transfer (builder field) — irreversible",
355
- check: (ctx) => {
356
- if (!ctx.builder)
357
- return null;
358
- return {
359
- id: "R-S-3-04",
360
- level: "HIGH",
361
- category: "authority",
362
- title: "Service ownership transfer — IRREVERSIBLE",
363
- description: `Transferring Service to ${ctx.builder}. Original owner loses ALL control. New owner inherits permission + compensation_fund + all bindings.`,
364
- affected_stakeholders: ["owner"],
365
- scenario: "Owner transfers Service to new address",
366
- mitigation: "1) Verify new owner address twice. 2) Withdraw compensation_fund first (if applicable). 3) Export Service JSON before transfer.",
367
- evidence: `new_owner=${ctx.builder}`,
368
- };
369
- },
370
- };
371
- const R_S_4_01 = {
372
- id: "R-S-4-01",
373
- category: "lifecycle",
374
- trigger: "publish is irreversible — bPublished cannot be reset to false",
375
- check: (ctx) => {
376
- if (!ctx.publish)
377
- return null;
378
- if (ctx.current_bPublished) {
379
- return {
380
- id: "R-S-4-01",
381
- level: "HIGH",
382
- category: "lifecycle",
383
- title: "Service already published — publish is no-op",
384
- description: "Service.bPublished is already true. Subsequent publish calls have no effect (bPublished is one-shot, cannot revert).",
385
- affected_stakeholders: ["owner"],
386
- scenario: "Owner calls publish again on already-published Service",
387
- mitigation: "Skip publish if already published. To 'reset' a Service, create a new one.",
388
- evidence: `bPublished=true`,
389
- };
390
- }
391
- return {
392
- id: "R-S-4-01",
393
- level: "HIGH",
394
- category: "lifecycle",
395
- title: "Publish is IRREVERSIBLE — 3 fields will be locked forever",
396
- description: "Once published: machine (306), arbitrations (308), order_allocators (313) become permanently immutable. bPublished cannot be reset to false. Clone Service to make changes.",
397
- affected_stakeholders: ["owner", "customer"],
398
- scenario: "Owner publishes Service for the first time",
399
- mitigation: "Verify all configurations before publish. Run pre-publish checklist (service-confirm.ts).",
400
- evidence: `bPublished=false→true`,
401
- };
402
- },
403
- };
404
- const R_S_4_02 = {
405
- id: "R-S-4-02",
406
- category: "lifecycle",
407
- trigger: "setting_lock_duration add — only-increase mechanism",
408
- check: (ctx) => {
409
- if (ctx.setting_lock_duration_add === undefined)
410
- return null;
411
- return {
412
- id: "R-S-4-02",
413
- level: "MEDIUM",
414
- category: "lifecycle",
415
- title: "setting_lock_duration can only INCREASE",
416
- description: `Adding ${ctx.setting_lock_duration_add} ms to setting_lock_duration. New value = old + input (safe_add). Cannot be decreased — protects customers from owner reducing lock to withdraw compensation_fund faster.`,
417
- affected_stakeholders: ["owner", "customer"],
418
- scenario: "Owner extends lock period to build trust",
419
- mitigation: "Ensure extension is intentional. Lock affects rewards/compensation_fund_withdraw/compensation_fund_receive.",
420
- evidence: `add_ms=${ctx.setting_lock_duration_add}`,
421
- };
422
- },
423
- };
424
- const R_S_4_03 = {
425
- id: "R-S-4-03",
426
- category: "lifecycle",
427
- trigger: "machine/arbitrations/order_allocators modification after publish — SDK blocks",
428
- check: (ctx) => {
429
- if (!ctx.current_bPublished)
430
- return null;
431
- const blockedFields = [];
432
- if (ctx.machine !== undefined)
433
- blockedFields.push("machine (306)");
434
- if (ctx.arbitrations !== undefined)
435
- blockedFields.push("arbitrations (308)");
436
- if (ctx.order_allocators !== undefined)
437
- blockedFields.push("order_allocators (313)");
438
- if (blockedFields.length > 0) {
439
- return {
440
- id: "R-S-4-03",
441
- level: "HIGH",
442
- category: "lifecycle",
443
- title: "Post-publish modification blocked by SDK",
444
- description: `Service is published. Cannot modify: ${blockedFields.join(", ")}. SDK checkNotPublished() will abort. To change these fields, clone the Service.`,
445
- affected_stakeholders: ["owner"],
446
- scenario: "Owner attempts to change locked field post-publish",
447
- mitigation: "Create a new Service with the desired configuration. Migrate active orders if needed.",
448
- evidence: `blocked=${blockedFields.join(",")}`,
449
- };
450
- }
451
- return null;
452
- },
453
- };
454
- const R_S_4_04 = {
455
- id: "R-S-4-04",
456
- category: "lifecycle",
457
- trigger: "sales modification — stock/price changes affect future orders only",
458
- check: (ctx) => {
459
- if (!ctx.sales)
460
- return null;
461
- return {
462
- id: "R-S-4-04",
463
- level: "LOW",
464
- category: "lifecycle",
465
- title: "Sales modification affects future orders only",
466
- description: "Sales add/set/remove/clear changes do NOT affect already-created Orders. Existing Orders' Progress continues with the original sale parameters.",
467
- affected_stakeholders: ["owner", "customer"],
468
- scenario: "Owner updates prices mid-campaign",
469
- mitigation: "Communicate price/stock changes to customers. Existing orders are unaffected.",
470
- evidence: `sales_op=${ctx.sales.op}`,
471
- };
472
- },
473
- };
474
- const R_S_5_01 = {
475
- id: "R-S-5-01",
476
- category: "cross_object",
477
- trigger: "Machine binding — post-publish immutable, Progress inherits",
478
- check: (ctx) => {
479
- if (ctx.machine === undefined)
480
- return null;
481
- if (ctx.current_bPublished) {
482
- return {
483
- id: "R-S-5-01",
484
- level: "HIGH",
485
- category: "cross_object",
486
- title: "Machine binding immutable post-publish",
487
- description: `Service is published; machine cannot be changed. All future Progress objects will use the bound Machine.`,
488
- affected_stakeholders: ["owner"],
489
- scenario: "Owner wants to upgrade workflow post-publish",
490
- mitigation: "Create new Service with new Machine. Migrate customers via discounts.",
491
- evidence: `machine=${ctx.machine ?? "(cleared)"}`,
492
- };
493
- }
494
- return {
495
- id: "R-S-5-01",
496
- level: "MEDIUM",
497
- category: "cross_object",
498
- title: "Machine binding — verify Machine is published",
499
- description: `Binding Machine ${ctx.machine}. Ensure Machine is published (machine::publish) — Service cannot bind unpublished Machine.`,
500
- affected_stakeholders: ["owner"],
501
- scenario: "Owner binds Machine before publishing Service",
502
- mitigation: "Verify Machine.bPublished = true before binding.",
503
- evidence: `machine=${ctx.machine}`,
504
- };
505
- },
506
- };
507
- const R_S_5_02 = {
508
- id: "R-S-5-02",
509
- category: "cross_object",
510
- trigger: "Arbitration binding — required when compensation_fund > 0",
511
- check: (ctx) => {
512
- if (!ctx.arbitrations)
513
- return null;
514
- const compBalance = ctx.current_compensation_fund_balance ?? "0";
515
- if (BigInt(compBalance) > 0n && (ctx.current_arbitrations_count ?? 0) === 0) {
516
- return {
517
- id: "R-S-5-02",
518
- level: "HIGH",
519
- category: "cross_object",
520
- title: "Arbitration required — compensation_fund has balance",
521
- description: `compensation_fund balance is ${compBalance}. Publish will fail (E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND) until arbitrations is non-empty.`,
522
- affected_stakeholders: ["owner"],
523
- scenario: "Owner deposits compensation_fund without configuring arbitrations",
524
- mitigation: "Add at least 1 Arbitration object before publish.",
525
- evidence: `compensation_fund=${compBalance}`,
526
- };
527
- }
528
- return null;
529
- },
530
- };
531
- const R_S_5_03 = {
532
- id: "R-S-5-03",
533
- category: "cross_object",
534
- trigger: "order_allocators binding — publish prerequisite, post-publish immutable",
535
- check: (ctx) => {
536
- if (ctx.order_allocators === undefined)
537
- return null;
538
- if (ctx.current_bPublished) {
539
- return {
540
- id: "R-S-5-03",
541
- level: "HIGH",
542
- category: "cross_object",
543
- title: "order_allocators immutable post-publish",
544
- description: "Service is published; order_allocators cannot be changed. Fund distribution strategy is permanently locked.",
545
- affected_stakeholders: ["owner"],
546
- scenario: "Owner wants to adjust fee split post-publish",
547
- mitigation: "Create new Service with new allocators. Cannot migrate existing Orders.",
548
- evidence: `order_allocators=${ctx.order_allocators ? "(set)" : "(cleared)"}`,
549
- };
550
- }
551
- if (ctx.publish && !ctx.order_allocators) {
552
- return {
553
- id: "R-S-5-03",
554
- level: "CRITICAL",
555
- category: "cross_object",
556
- title: "Publish without order_allocators — will fail",
557
- description: "Publish will abort with E_NO_ALLOCATOR. order_allocators is a mandatory publish prerequisite.",
558
- affected_stakeholders: ["owner"],
559
- scenario: "Owner attempts publish without configuring allocators",
560
- mitigation: "Set order_allocators before publish.",
561
- evidence: `order_allocators=null`,
562
- };
563
- }
564
- return null;
565
- },
566
- };
567
- const R_S_5_04 = {
568
- id: "R-S-5-04",
569
- category: "cross_object",
570
- trigger: "Repository/Reward binding — verify object types before adding",
571
- check: (ctx) => {
572
- if (ctx.repositories && (ctx.repositories.op === "add" || ctx.repositories.op === "set")) {
573
- return {
574
- id: "R-S-5-04",
575
- level: "LOW",
576
- category: "cross_object",
577
- title: "Repository binding — verify object types",
578
- description: `Adding ${ctx.repositories.objects.length} repositories. SDK uses queryObjectsWithType to validate each is ObjectType.Repository before binding.`,
579
- affected_stakeholders: ["owner"],
580
- scenario: "Owner adds non-Repository object by mistake",
581
- mitigation: "Use LocalMark names or addresses that are confirmed Repository objects.",
582
- evidence: `objects=${ctx.repositories.objects.length}`,
583
- };
584
- }
585
- if (ctx.rewards && (ctx.rewards.op === "add" || ctx.rewards.op === "set")) {
586
- return {
587
- id: "R-S-5-04",
588
- level: "LOW",
589
- category: "cross_object",
590
- title: "Reward binding — verify object types + lock_duration",
591
- description: `Adding ${ctx.rewards.objects.length} rewards. SDK validates ObjectType.Reward. Note: rewards modification is locked by setting_lock_duration.`,
592
- affected_stakeholders: ["owner"],
593
- scenario: "Owner adds Reward objects",
594
- mitigation: "Verify Reward objects exist and are active. Be aware of lock_duration implications.",
595
- evidence: `objects=${ctx.rewards.objects.length}`,
596
- };
597
- }
598
- return null;
599
- },
600
- };
601
- const ALL_RULES = [
602
- R_S_1_01, R_S_1_02, R_S_1_03, R_S_1_04, R_S_1_05,
603
- R_S_2_01, R_S_2_02, R_S_2_03, R_S_2_04, R_S_2_05,
604
- R_S_3_01, R_S_3_02, R_S_3_03, R_S_3_04,
605
- R_S_4_01, R_S_4_02, R_S_4_03, R_S_4_04,
606
- R_S_5_01, R_S_5_02, R_S_5_03, R_S_5_04,
607
- ];
608
- export const SERVICE_RISK_VERSION = "1.0.0";
609
- export function getAllServiceRiskRules() {
610
- return [...ALL_RULES];
611
- }
612
- export function getServiceRiskRulesCount() {
613
- return ALL_RULES.length;
614
- }
615
- export function getServiceRiskRulesByCategory(category) {
616
- return ALL_RULES.filter(r => r.category === category);
617
- }
618
- export function assessServiceRisks(ctx) {
619
- const risks = [];
620
- for (const rule of ALL_RULES) {
621
- const r = rule.check(ctx);
622
- if (r)
623
- risks.push(r);
624
- }
625
- const overall = risks.length === 0
626
- ? "LOW"
627
- : risks.some(r => r.level === "CRITICAL") ? "CRITICAL"
628
- : risks.some(r => r.level === "HIGH") ? "HIGH"
629
- : risks.some(r => r.level === "MEDIUM") ? "MEDIUM"
630
- : "LOW";
631
- const byCategory = {};
632
- for (const r of risks) {
633
- byCategory[r.category] = (byCategory[r.category] ?? 0) + 1;
634
- }
635
- const advice = {};
636
- for (const r of risks) {
637
- for (const s of r.affected_stakeholders) {
638
- if (!advice[s])
639
- advice[s] = [];
640
- advice[s].push(`${r.id}: ${r.mitigation}`);
641
- }
642
- }
643
- return {
644
- summary: `Assessed ${risks.length} risk(s) across ${Object.keys(byCategory).length} categories`,
645
- risks,
646
- overall_risk: overall,
647
- risks_by_category: byCategory,
648
- stakeholder_advice: advice,
649
- needs_human_review: risks.some(r => r.level === "CRITICAL" || r.level === "HIGH"),
650
- };
651
- }
1
+ import{MAX_SALE_COUNT,MAX_REPOSITORY_COUNT,MAX_ARBITRATION_COUNT,MAX_DISCOUNT_TOTAL_COUNT,MAX_WIP_LENGTH,MAX_WIP_HASH_LENGTH}from'@wowok/wowok';const R_S_1_01={'id':'R-S-1-01','category':'structural','trigger':'sales\x20count\x20exceeds\x20MAX_SALE_COUNT\x20(50)','check':a=>{const b=a['current_sales_count']??0x0;if(a['sales']&&(a['sales']['op']==='add'||a['sales']['op']==='set')){const c=a['sales']['op']==='set'?a['sales']['sales']['length']:b+a['sales']['sales']['length'];if(c>MAX_SALE_COUNT)return{'id':'R-S-1-01','level':'HIGH','category':'structural','title':'Sales\x20count\x20exceeds\x20limit','description':'Service\x20would\x20have\x20'+c+'\x20sales\x20items,\x20exceeds\x20MAX_SALE_COUNT\x20'+MAX_SALE_COUNT,'affected_stakeholders':['owner','system'],'scenario':'Adding\x20too\x20many\x20product\x20SKUs','mitigation':'Split\x20into\x20multiple\x20Service\x20objects\x20or\x20remove\x20discontinued\x20items','evidence':'sales_count='+c};}return null;}},R_S_1_02={'id':'R-S-1-02','category':'structural','trigger':'repositories\x20count\x20exceeds\x20MAX_REPOSITORY_COUNT\x20(100)','check':a=>{const b=a['current_repositories_count']??0x0;if(a['repositories']&&(a['repositories']['op']==='add'||a['repositories']['op']==='set')){const c=a['repositories']['op']==='set'?a['repositories']['objects']['length']:b+a['repositories']['objects']['length'];if(c>MAX_REPOSITORY_COUNT)return{'id':'R-S-1-02','level':'MEDIUM','category':'structural','title':'Repositories\x20count\x20exceeds\x20limit','description':'Service\x20would\x20have\x20'+c+'\x20repositories,\x20exceeds\x20MAX_REPOSITORY_COUNT\x20'+MAX_REPOSITORY_COUNT,'affected_stakeholders':['owner'],'scenario':'Binding\x20too\x20many\x20data\x20repositories','mitigation':'Consolidate\x20repositories\x20or\x20remove\x20inactive\x20ones','evidence':'repositories_count='+c};}return null;}},R_S_1_03={'id':'R-S-1-03','category':'structural','trigger':'arbitrations\x20count\x20exceeds\x20MAX_ARBITRATION_COUNT\x20(20)','check':a=>{const b=a['current_arbitrations_count']??0x0;if(a['arbitrations']&&(a['arbitrations']['op']==='add'||a['arbitrations']['op']==='set')){const c=a['arbitrations']['op']==='set'?a['arbitrations']['objects']['length']:b+a['arbitrations']['objects']['length'];if(c>MAX_ARBITRATION_COUNT)return{'id':'R-S-1-03','level':'HIGH','category':'structural','title':'Arbitrations\x20count\x20exceeds\x20limit','description':'Service\x20would\x20have\x20'+c+'\x20arbitrations,\x20exceeds\x20MAX_ARBITRATION_COUNT\x20'+MAX_ARBITRATION_COUNT,'affected_stakeholders':['owner','arbitrator'],'scenario':'Binding\x20too\x20many\x20Arbitration\x20objects','mitigation':'Use\x201-3\x20Arbitration\x20objects\x20covering\x20different\x20dispute\x20scopes','evidence':'arbitrations_count='+c};}return null;}},R_S_1_04={'id':'R-S-1-04','category':'structural','trigger':'WIP\x20hash\x20length\x20exceeds\x20MAX_WIP_HASH_LENGTH\x20(64)\x20or\x20URL\x20exceeds\x20MAX_WIP_LENGTH\x20(1024)','check':a=>{if(a['sales']&&(a['sales']['op']==='add'||a['sales']['op']==='set'))for(const b of a['sales']['sales']){if(b['wip_hash']&&b['wip_hash']['length']>MAX_WIP_HASH_LENGTH)return{'id':'R-S-1-04','level':'HIGH','category':'structural','title':'WIP\x20hash\x20length\x20exceeds\x20limit','description':'Sale\x20\x22'+b['name']+'\x22\x20wip_hash\x20length\x20'+b['wip_hash']['length']+'\x20>\x20MAX_WIP_HASH_LENGTH\x20'+MAX_WIP_HASH_LENGTH,'affected_stakeholders':['owner','customer'],'scenario':'Malformed\x20WIP\x20hash\x20(should\x20be\x20sha256\x20hex,\x2064\x20chars)','mitigation':'Use\x20sha256\x20hex\x20hash\x20(64\x20characters,\x20no\x20prefix)','evidence':'wip_hash_length='+b['wip_hash']['length']};if(b['wip']&&b['wip']['length']>MAX_WIP_LENGTH)return{'id':'R-S-1-04','level':'HIGH','category':'structural','title':'WIP\x20URL\x20length\x20exceeds\x20limit','description':'Sale\x20\x22'+b['name']+'\x22\x20wip\x20URL\x20length\x20'+b['wip']['length']+'\x20>\x20MAX_WIP_LENGTH\x20'+MAX_WIP_LENGTH,'affected_stakeholders':['owner'],'scenario':'WIP\x20URL\x20too\x20long\x20(use\x20IPFS\x20or\x20short\x20HTTPS\x20URL)','mitigation':'Use\x20IPFS\x20CID\x20or\x20shorter\x20URL','evidence':'wip_url_length='+b['wip']['length']};}return null;}},R_S_1_05={'id':'R-S-1-05','category':'structural','trigger':'sale.wip\x20is\x20a\x20local\x20path\x20/\x20localhost\x20/\x20LAN\x20URL\x20(not\x20network-deployable)\x20—\x20every\x20customer\x20order\x20fails','check':a=>{if(a['sales']&&(a['sales']['op']==='add'||a['sales']['op']==='set'))for(const b of a['sales']['sales']){if(b['wip']&&b['wip']!==''){let c=null;const d=b['wip'];if(/^[A-Za-z]:[\\/]/['test'](d)||d['startsWith']('/')||d['startsWith']('./')||d['startsWith']('../'))c='local\x20filesystem\x20path';else{if(/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0)([:/]|$)/i['test'](d))c='localhost/loopback\x20URL';else{if(/^https?:\/\/(10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3})([:/]|$)/i['test'](d))c='LAN\x20(private\x20IP)\x20URL';else!/^https?:\/\//i['test'](d)&&!d['startsWith']('ipfs://')&&!d['startsWith']('data:')&&(c='unrecognized\x20format\x20(not\x20a\x20network\x20URL)');}}if(c)return{'id':'R-S-1-05','level':'CRITICAL','category':'structural','title':'WIP\x20is\x20not\x20network-deployed\x20—\x20every\x20customer\x20order\x20will\x20fail','description':'Sale\x20\x22'+b['name']+'\x22\x20wip\x20\x22'+b['wip']+'\x22\x20is\x20a\x20'+c+'.\x20It\x20passes\x20set-time\x20verification\x20'+'on\x20the\x20merchant\x27s\x20own\x20machine\x20but\x20is\x20unreachable\x20by\x20customers\x20on\x20other\x20machines\x20—\x20'+'order_new\x20aborts\x20100%\x20when\x20a\x20customer\x20tries\x20to\x20buy.','affected_stakeholders':['owner','customer'],'scenario':'Merchant\x20sets\x20wip\x20to\x20a\x20local\x20file\x20path\x20/\x20localhost\x20/\x20LAN\x20URL\x20and\x20publishes\x20the\x20Service;\x20'+'the\x20on-chain\x20wip\x20points\x20at\x20the\x20merchant\x27s\x20machine;\x20customers\x20cannot\x20fetch\x20it.','mitigation':'Deploy\x20the\x20.wip\x20file\x20to\x20a\x20public\x20host\x20(GitHub\x20Pages,\x20IPFS,\x20or\x20your\x20own\x20website)\x20and\x20set\x20'+'sale.wip\x20to\x20the\x20public\x20URL.\x20Or\x20leave\x20sale.wip\x20empty\x20(\x22\x22)\x20to\x20skip\x20WIP\x20verification\x20'+'(TESTING\x20ONLY\x20—\x20not\x20recommended\x20for\x20production).','evidence':'sale='+b['name']+',\x20wip='+b['wip']};}}return null;}},R_S_2_01={'id':'R-S-2-01','category':'semantic','trigger':'WIP\x20hash\x20tampering\x20risk\x20—\x20owner\x20updates\x20WIP\x20file\x20without\x20updating\x20wip_hash','check':a=>{if(a['sales']&&(a['sales']['op']==='add'||a['sales']['op']==='set'))for(const b of a['sales']['sales']){if(b['wip']&&!b['wip_hash'])return{'id':'R-S-2-01','level':'CRITICAL','category':'semantic','title':'WIP\x20hash\x20missing\x20—\x20tampering\x20risk','description':'Sale\x20\x22'+b['name']+'\x22\x20has\x20wip\x20URL\x20but\x20no\x20wip_hash.\x20Owner\x20could\x20replace\x20the\x20WIP\x20file\x20without\x20customers\x20noticing.','affected_stakeholders':['customer','owner'],'scenario':'Owner\x20sets\x20wip\x20without\x20hash,\x20then\x20changes\x20file\x20content\x20later','mitigation':'Always\x20compute\x20sha256(wip_file_content)\x20and\x20set\x20as\x20wip_hash.\x20SDK\x20auto-derives\x20if\x20omitted,\x20but\x20explicit\x20hash\x20is\x20safer.','evidence':'sale='+b['name']};}return null;}},R_S_2_02={'id':'R-S-2-02','category':'semantic','trigger':'compensation_fund\x20confused\x20with\x20Service\x20balance\x20(internal\x20Balance<T>)','check':a=>{if(a['compensation_fund_add'])return{'id':'R-S-2-02','level':'HIGH','category':'semantic','title':'compensation_fund\x20is\x20internal\x20Balance<T>,\x20NOT\x20Service-owned\x20Treasury','description':'Depositing\x20'+a['compensation_fund_add']['balance']+'\x20to\x20compensation_fund.\x20This\x20balance\x20is\x20internal\x20to\x20Service<T>\x20and\x20is\x20consumed\x20by\x20arbitration::compensation_claim,\x20not\x20by\x20owner\x20withdrawals.\x20Owner\x20can\x20only\x20withdraw\x20via\x20compensation_fund_withdraw\x20(requires\x20bPaused=true\x20+\x20lock_duration\x20expired).','affected_stakeholders':['owner','arbitrator','customer'],'scenario':'Owner\x20confuses\x20compensation_fund\x20with\x20general\x20Treasury','mitigation':'Use\x20external\x20Treasury\x20(referenced\x20via\x20order_allocators.sharing.who=Entity)\x20for\x20general\x20funds.\x20Use\x20compensation_fund\x20only\x20for\x20arbitration\x20payouts.','evidence':'deposit='+a['compensation_fund_add']['balance']};return null;}},R_S_2_03={'id':'R-S-2-03','category':'semantic','trigger':'quote\x20side\x20effect\x20—\x20stock\x20deduction\x20not\x20rolled\x20back\x20on\x20later\x20failure','check':a=>{if(a['order_new']&&a['order_new']['buy']['items']['length']>0x0)return{'id':'R-S-2-03','level':'HIGH','category':'semantic','title':'Order\x20flow:\x20stock\x20deducted\x20at\x20quote\x20stage\x20—\x20NOT\x20rolled\x20back\x20on\x20failure','description':'Order\x20will\x20deduct\x20stock\x20at\x20Stage\x203\x20(quote).\x20If\x20Stages\x204-7\x20fail,\x20stock\x20remains\x20deducted.\x20Customer\x20must\x20manually\x20re-add\x20stock\x20or\x20accept\x20the\x20loss.','affected_stakeholders':['owner','customer'],'scenario':'Customer\x27s\x20transaction\x20fails\x20after\x20quote\x20but\x20stock\x20is\x20gone','mitigation':'1)\x20Monitor\x20failed\x20transactions\x20and\x20re-add\x20stock\x20via\x20stock_add.\x202)\x20Set\x20sales\x20suspension\x20during\x20high-failure\x20periods.\x203)\x20Use\x20small\x20batch\x20orders\x20to\x20limit\x20blast\x20radius.','evidence':'items='+a['order_new']['buy']['items']['length']};return null;}},R_S_2_04={'id':'R-S-2-04','category':'semantic','trigger':'Discount\x20issuance\x20—\x20verify\x20type\x20and\x20total\x20count\x20semantics','check':a=>{if(a['discount']){const b=a['discount']['count'];if(b>MAX_DISCOUNT_TOTAL_COUNT)return{'id':'R-S-2-04','level':'MEDIUM','category':'semantic','title':'Discount\x20count\x20exceeds\x20total\x20cap','description':'Issuing\x20'+b+'\x20discounts\x20exceeds\x20MAX_DISCOUNT_TOTAL_COUNT\x20'+MAX_DISCOUNT_TOTAL_COUNT,'affected_stakeholders':['owner'],'scenario':'Bulk\x20discount\x20issuance','mitigation':'Issue\x20in\x20batches\x20of\x20<=\x201000\x20(MAX_DISCOUNT_COUNT_ONCE)\x20and\x20keep\x20total\x20<=\x20'+MAX_DISCOUNT_TOTAL_COUNT,'evidence':'count='+b};}return null;}},R_S_2_05={'id':'R-S-2-05','category':'semantic','trigger':'Order\x20placed\x20without\x20verifying\x20WIP\x20hash\x20—\x20buyer\x20passes\x20empty\x20wip_hash','check':a=>{if(a['order_new']){const b=a['order_new']['buy']['items']['filter'](c=>c['wip_hash']==='');if(b['length']>0x0)return{'id':'R-S-2-05','level':'MEDIUM','category':'semantic','title':'Order\x20with\x20empty\x20wip_hash\x20—\x20SDK\x20auto-fills\x20from\x20sale','description':b['length']+'\x20item(s)\x20have\x20empty\x20wip_hash.\x20SDK\x20will\x20auto-fill\x20from\x20sale.wip_hash\x20at\x20order\x20time.\x20If\x20owner\x20updates\x20the\x20WIP\x20file\x20between\x20viewing\x20and\x20ordering,\x20buyer\x20receives\x20the\x20new\x20(potentially\x20different)\x20content.','affected_stakeholders':['customer'],'scenario':'Time-of-check\x20to\x20time-of-use\x20WIP\x20mismatch','mitigation':'Buyer\x20should\x20explicitly\x20pass\x20the\x20wip_hash\x20they\x20saw\x20when\x20viewing\x20the\x20product.\x20Empty\x20string\x20is\x20convenience\x20but\x20riskier.','evidence':'empty_hash_items='+b['length']};}return null;}},R_S_3_01={'id':'R-S-3-01','category':'authority','trigger':'publish\x20operation\x20—\x20requires\x20SERVICE_PUBLISH\x20(311)\x20+\x20prerequisites','check':a=>{if(!a['publish'])return null;const b=[];if(!a['current_order_allocators_set'])b['push']('order_allocators\x20not\x20set\x20(F-S-18,\x20E_NO_ALLOCATOR)');const c=a['current_compensation_fund_balance']??'0';BigInt(c)>0x0n&&(a['current_arbitrations_count']??0x0)===0x0&&b['push']('compensation_fund\x20>\x200\x20but\x20no\x20arbitrations\x20(F-S-19,\x20E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)');if(b['length']>0x0)return{'id':'R-S-3-01','level':'CRITICAL','category':'authority','title':'Publish\x20blocked\x20—\x20prerequisites\x20not\x20met','description':'Cannot\x20publish:\x20'+b['join'](';\x20'),'affected_stakeholders':['owner'],'scenario':'Owner\x20attempts\x20publish\x20without\x20configuring\x20prerequisites','mitigation':'Configure\x20order_allocators\x20(and\x20arbitrations\x20if\x20compensation_fund\x20>\x200)\x20before\x20publish','evidence':'blockers='+b['length']};return null;}},R_S_3_02={'id':'R-S-3-02','category':'authority','trigger':'pause\x20operation\x20—\x20affects\x20new\x20orders\x20but\x20not\x20existing\x20Progress','check':a=>{if(a['pause']===undefined)return null;return{'id':'R-S-3-02','level':'MEDIUM','category':'authority','title':a['pause']?'Pausing\x20Service\x20—\x20new\x20orders\x20blocked,\x20existing\x20Progress\x20continues':'Resuming\x20Service\x20—\x20new\x20orders\x20accepted','description':a['pause']?'Service.bPaused\x20=\x20true\x20will\x20reject\x20new\x20orders\x20(E_SERVICE_PAUSED).\x20Existing\x20orders\x27\x20Progress\x20continues\x20normally.':'Service.bPaused\x20=\x20false\x20will\x20allow\x20new\x20orders\x20again.','affected_stakeholders':['owner','customer'],'scenario':a['pause']?'Owner\x20pauses\x20for\x20maintenance/stockout':'Owner\x20resumes\x20after\x20maintenance','mitigation':a['pause']?'Communicate\x20pause\x20to\x20customers.\x20Use\x20compensation_fund_withdraw\x20only\x20when\x20paused.':'Verify\x20stock\x20levels\x20before\x20resuming.','evidence':'pause='+a['pause']};}},R_S_3_03={'id':'R-S-3-03','category':'authority','trigger':'buy_guard\x20change\x20—\x20post-publish\x20mutable\x20(unusual\x20exception)','check':a=>{if(a['buy_guard']===undefined)return null;if(a['current_bPublished'])return{'id':'R-S-3-03','level':'MEDIUM','category':'authority','title':'buy_guard\x20change\x20post-publish\x20—\x20unusual\x20mutability','description':'buy_guard\x20is\x20the\x20ONLY\x20publish-locked-field\x20exception:\x20it\x20remains\x20mutable\x20post-publish.\x20Other\x20fields\x20(machine/arbitrations/order_allocators)\x20are\x20immutable.','affected_stakeholders':['owner','customer'],'scenario':'Owner\x20changes\x20buy_guard\x20strategy\x20after\x20publish\x20(e.g.\x20whitelist\x20→\x20public)','mitigation':'Document\x20buy_guard\x20changes\x20for\x20transparency.\x20Customers\x20should\x20re-verify\x20buy_guard\x20before\x20ordering.','evidence':'buy_guard='+(a['buy_guard']??'(cleared)')};return null;}},R_S_3_04={'id':'R-S-3-04','category':'authority','trigger':'Ownership\x20transfer\x20(builder\x20field)\x20—\x20irreversible','check':a=>{if(!a['builder'])return null;return{'id':'R-S-3-04','level':'HIGH','category':'authority','title':'Service\x20ownership\x20transfer\x20—\x20IRREVERSIBLE','description':'Transferring\x20Service\x20to\x20'+a['builder']+'.\x20Original\x20owner\x20loses\x20ALL\x20control.\x20New\x20owner\x20inherits\x20permission\x20+\x20compensation_fund\x20+\x20all\x20bindings.','affected_stakeholders':['owner'],'scenario':'Owner\x20transfers\x20Service\x20to\x20new\x20address','mitigation':'1)\x20Verify\x20new\x20owner\x20address\x20twice.\x202)\x20Withdraw\x20compensation_fund\x20first\x20(if\x20applicable).\x203)\x20Export\x20Service\x20JSON\x20before\x20transfer.','evidence':'new_owner='+a['builder']};}},R_S_4_01={'id':'R-S-4-01','category':'lifecycle','trigger':'publish\x20is\x20irreversible\x20—\x20bPublished\x20cannot\x20be\x20reset\x20to\x20false','check':a=>{if(!a['publish'])return null;if(a['current_bPublished'])return{'id':'R-S-4-01','level':'HIGH','category':'lifecycle','title':'Service\x20already\x20published\x20—\x20publish\x20is\x20no-op','description':'Service.bPublished\x20is\x20already\x20true.\x20Subsequent\x20publish\x20calls\x20have\x20no\x20effect\x20(bPublished\x20is\x20one-shot,\x20cannot\x20revert).','affected_stakeholders':['owner'],'scenario':'Owner\x20calls\x20publish\x20again\x20on\x20already-published\x20Service','mitigation':'Skip\x20publish\x20if\x20already\x20published.\x20To\x20\x27reset\x27\x20a\x20Service,\x20create\x20a\x20new\x20one.','evidence':'bPublished=true'};return{'id':'R-S-4-01','level':'HIGH','category':'lifecycle','title':'Publish\x20is\x20IRREVERSIBLE\x20—\x203\x20fields\x20will\x20be\x20locked\x20forever','description':'Once\x20published:\x20machine\x20(306),\x20arbitrations\x20(308),\x20order_allocators\x20(313)\x20become\x20permanently\x20immutable.\x20bPublished\x20cannot\x20be\x20reset\x20to\x20false.\x20Clone\x20Service\x20to\x20make\x20changes.','affected_stakeholders':['owner','customer'],'scenario':'Owner\x20publishes\x20Service\x20for\x20the\x20first\x20time','mitigation':'Verify\x20all\x20configurations\x20before\x20publish.\x20Run\x20pre-publish\x20checklist\x20(service-confirm.ts).','evidence':'bPublished=false→true'};}},R_S_4_02={'id':'R-S-4-02','category':'lifecycle','trigger':'setting_lock_duration\x20add\x20—\x20only-increase\x20mechanism','check':a=>{if(a['setting_lock_duration_add']===undefined)return null;return{'id':'R-S-4-02','level':'MEDIUM','category':'lifecycle','title':'setting_lock_duration\x20can\x20only\x20INCREASE','description':'Adding\x20'+a['setting_lock_duration_add']+'\x20ms\x20to\x20setting_lock_duration.\x20New\x20value\x20=\x20old\x20+\x20input\x20(safe_add).\x20Cannot\x20be\x20decreased\x20—\x20protects\x20customers\x20from\x20owner\x20reducing\x20lock\x20to\x20withdraw\x20compensation_fund\x20faster.','affected_stakeholders':['owner','customer'],'scenario':'Owner\x20extends\x20lock\x20period\x20to\x20build\x20trust','mitigation':'Ensure\x20extension\x20is\x20intentional.\x20Lock\x20affects\x20rewards/compensation_fund_withdraw/compensation_fund_receive.','evidence':'add_ms='+a['setting_lock_duration_add']};}},R_S_4_03={'id':'R-S-4-03','category':'lifecycle','trigger':'machine/arbitrations/order_allocators\x20modification\x20after\x20publish\x20—\x20SDK\x20blocks','check':a=>{if(!a['current_bPublished'])return null;const b=[];if(a['machine']!==undefined)b['push']('machine\x20(306)');if(a['arbitrations']!==undefined)b['push']('arbitrations\x20(308)');if(a['order_allocators']!==undefined)b['push']('order_allocators\x20(313)');if(b['length']>0x0)return{'id':'R-S-4-03','level':'HIGH','category':'lifecycle','title':'Post-publish\x20modification\x20blocked\x20by\x20SDK','description':'Service\x20is\x20published.\x20Cannot\x20modify:\x20'+b['join'](',\x20')+'.\x20SDK\x20checkNotPublished()\x20will\x20abort.\x20To\x20change\x20these\x20fields,\x20clone\x20the\x20Service.','affected_stakeholders':['owner'],'scenario':'Owner\x20attempts\x20to\x20change\x20locked\x20field\x20post-publish','mitigation':'Create\x20a\x20new\x20Service\x20with\x20the\x20desired\x20configuration.\x20Migrate\x20active\x20orders\x20if\x20needed.','evidence':'blocked='+b['join'](',')};return null;}},R_S_4_04={'id':'R-S-4-04','category':'lifecycle','trigger':'sales\x20modification\x20—\x20stock/price\x20changes\x20affect\x20future\x20orders\x20only','check':a=>{if(!a['sales'])return null;return{'id':'R-S-4-04','level':'LOW','category':'lifecycle','title':'Sales\x20modification\x20affects\x20future\x20orders\x20only','description':'Sales\x20add/set/remove/clear\x20changes\x20do\x20NOT\x20affect\x20already-created\x20Orders.\x20Existing\x20Orders\x27\x20Progress\x20continues\x20with\x20the\x20original\x20sale\x20parameters.','affected_stakeholders':['owner','customer'],'scenario':'Owner\x20updates\x20prices\x20mid-campaign','mitigation':'Communicate\x20price/stock\x20changes\x20to\x20customers.\x20Existing\x20orders\x20are\x20unaffected.','evidence':'sales_op='+a['sales']['op']};}},R_S_5_01={'id':'R-S-5-01','category':'cross_object','trigger':'Machine\x20binding\x20—\x20post-publish\x20immutable,\x20Progress\x20inherits','check':a=>{if(a['machine']===undefined)return null;if(a['current_bPublished'])return{'id':'R-S-5-01','level':'HIGH','category':'cross_object','title':'Machine\x20binding\x20immutable\x20post-publish','description':'Service\x20is\x20published;\x20machine\x20cannot\x20be\x20changed.\x20All\x20future\x20Progress\x20objects\x20will\x20use\x20the\x20bound\x20Machine.','affected_stakeholders':['owner'],'scenario':'Owner\x20wants\x20to\x20upgrade\x20workflow\x20post-publish','mitigation':'Create\x20new\x20Service\x20with\x20new\x20Machine.\x20Migrate\x20customers\x20via\x20discounts.','evidence':'machine='+(a['machine']??'(cleared)')};return{'id':'R-S-5-01','level':'MEDIUM','category':'cross_object','title':'Machine\x20binding\x20—\x20verify\x20Machine\x20is\x20published','description':'Binding\x20Machine\x20'+a['machine']+'.\x20Ensure\x20Machine\x20is\x20published\x20(machine::publish)\x20—\x20Service\x20cannot\x20bind\x20unpublished\x20Machine.','affected_stakeholders':['owner'],'scenario':'Owner\x20binds\x20Machine\x20before\x20publishing\x20Service','mitigation':'Verify\x20Machine.bPublished\x20=\x20true\x20before\x20binding.','evidence':'machine='+a['machine']};}},R_S_5_02={'id':'R-S-5-02','category':'cross_object','trigger':'Arbitration\x20binding\x20—\x20required\x20when\x20compensation_fund\x20>\x200','check':a=>{if(!a['arbitrations'])return null;const b=a['current_compensation_fund_balance']??'0';if(BigInt(b)>0x0n&&(a['current_arbitrations_count']??0x0)===0x0)return{'id':'R-S-5-02','level':'HIGH','category':'cross_object','title':'Arbitration\x20required\x20—\x20compensation_fund\x20has\x20balance','description':'compensation_fund\x20balance\x20is\x20'+b+'.\x20Publish\x20will\x20fail\x20(E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)\x20until\x20arbitrations\x20is\x20non-empty.','affected_stakeholders':['owner'],'scenario':'Owner\x20deposits\x20compensation_fund\x20without\x20configuring\x20arbitrations','mitigation':'Add\x20at\x20least\x201\x20Arbitration\x20object\x20before\x20publish.','evidence':'compensation_fund='+b};return null;}},R_S_5_03={'id':'R-S-5-03','category':'cross_object','trigger':'order_allocators\x20binding\x20—\x20publish\x20prerequisite,\x20post-publish\x20immutable','check':a=>{if(a['order_allocators']===undefined)return null;if(a['current_bPublished'])return{'id':'R-S-5-03','level':'HIGH','category':'cross_object','title':'order_allocators\x20immutable\x20post-publish','description':'Service\x20is\x20published;\x20order_allocators\x20cannot\x20be\x20changed.\x20Fund\x20distribution\x20strategy\x20is\x20permanently\x20locked.','affected_stakeholders':['owner'],'scenario':'Owner\x20wants\x20to\x20adjust\x20fee\x20split\x20post-publish','mitigation':'Create\x20new\x20Service\x20with\x20new\x20allocators.\x20Cannot\x20migrate\x20existing\x20Orders.','evidence':'order_allocators='+(a['order_allocators']?'(set)':'(cleared)')};if(a['publish']&&!a['order_allocators'])return{'id':'R-S-5-03','level':'CRITICAL','category':'cross_object','title':'Publish\x20without\x20order_allocators\x20—\x20will\x20fail','description':'Publish\x20will\x20abort\x20with\x20E_NO_ALLOCATOR.\x20order_allocators\x20is\x20a\x20mandatory\x20publish\x20prerequisite.','affected_stakeholders':['owner'],'scenario':'Owner\x20attempts\x20publish\x20without\x20configuring\x20allocators','mitigation':'Set\x20order_allocators\x20before\x20publish.','evidence':'order_allocators=null'};return null;}},R_S_5_04={'id':'R-S-5-04','category':'cross_object','trigger':'Repository/Reward\x20binding\x20—\x20verify\x20object\x20types\x20before\x20adding','check':a=>{if(a['repositories']&&(a['repositories']['op']==='add'||a['repositories']['op']==='set'))return{'id':'R-S-5-04','level':'LOW','category':'cross_object','title':'Repository\x20binding\x20—\x20verify\x20object\x20types','description':'Adding\x20'+a['repositories']['objects']['length']+'\x20repositories.\x20SDK\x20uses\x20queryObjectsWithType\x20to\x20validate\x20each\x20is\x20ObjectType.Repository\x20before\x20binding.','affected_stakeholders':['owner'],'scenario':'Owner\x20adds\x20non-Repository\x20object\x20by\x20mistake','mitigation':'Use\x20LocalMark\x20names\x20or\x20addresses\x20that\x20are\x20confirmed\x20Repository\x20objects.','evidence':'objects='+a['repositories']['objects']['length']};if(a['rewards']&&(a['rewards']['op']==='add'||a['rewards']['op']==='set'))return{'id':'R-S-5-04','level':'LOW','category':'cross_object','title':'Reward\x20binding\x20—\x20verify\x20object\x20types\x20+\x20lock_duration','description':'Adding\x20'+a['rewards']['objects']['length']+'\x20rewards.\x20SDK\x20validates\x20ObjectType.Reward.\x20Note:\x20rewards\x20modification\x20is\x20locked\x20by\x20setting_lock_duration.','affected_stakeholders':['owner'],'scenario':'Owner\x20adds\x20Reward\x20objects','mitigation':'Verify\x20Reward\x20objects\x20exist\x20and\x20are\x20active.\x20Be\x20aware\x20of\x20lock_duration\x20implications.','evidence':'objects='+a['rewards']['objects']['length']};return null;}},ALL_RULES=[R_S_1_01,R_S_1_02,R_S_1_03,R_S_1_04,R_S_1_05,R_S_2_01,R_S_2_02,R_S_2_03,R_S_2_04,R_S_2_05,R_S_3_01,R_S_3_02,R_S_3_03,R_S_3_04,R_S_4_01,R_S_4_02,R_S_4_03,R_S_4_04,R_S_5_01,R_S_5_02,R_S_5_03,R_S_5_04];export const SERVICE_RISK_VERSION='1.0.0';export function getAllServiceRiskRules(){return[...ALL_RULES];}export function getServiceRiskRulesCount(){return ALL_RULES['length'];}export function getServiceRiskRulesByCategory(a){return ALL_RULES['filter'](b=>b['category']===a);}export function assessServiceRisks(a){const b=[];for(const f of ALL_RULES){const g=f['check'](a);if(g)b['push'](g);}const c=b['length']===0x0?'LOW':b['some'](h=>h['level']==='CRITICAL')?'CRITICAL':b['some'](h=>h['level']==='HIGH')?'HIGH':b['some'](h=>h['level']==='MEDIUM')?'MEDIUM':'LOW',d={};for(const h of b){d[h['category']]=(d[h['category']]??0x0)+0x1;}const e={};for(const i of b){for(const j of i['affected_stakeholders']){if(!e[j])e[j]=[];e[j]['push'](i['id']+':\x20'+i['mitigation']);}}return{'summary':'Assessed\x20'+b['length']+'\x20risk(s)\x20across\x20'+Object['keys'](d)['length']+'\x20categories','risks':b,'overall_risk':c,'risks_by_category':d,'stakeholder_advice':e,'needs_human_review':b['some'](k=>k['level']==='CRITICAL'||k['level']==='HIGH')};}