@wowok/agent-mcp 3.3.5 → 3.3.7

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 (243) hide show
  1. package/dist/chain-semantics/eval-order.d.ts +17 -0
  2. package/dist/chain-semantics/eval-order.js +1 -0
  3. package/dist/chain-semantics/field-capability.js +1 -1
  4. package/dist/chain-semantics/freeze-map.js +1 -1
  5. package/dist/chain-semantics/fund-flow.js +1 -1
  6. package/dist/chain-semantics/guard-verbs.js +1 -1
  7. package/dist/chain-semantics/index.d.ts +1 -0
  8. package/dist/chain-semantics/index.js +1 -1
  9. package/dist/chain-semantics/object-graph.js +1 -1
  10. package/dist/composition/audit.js +1 -1
  11. package/dist/composition/compile.d.ts +2 -1
  12. package/dist/composition/compile.js +1 -1
  13. package/dist/composition/materialize.js +1 -1
  14. package/dist/data/api/api.spec.d.ts +1 -0
  15. package/dist/data/api/api.spec.js +1 -0
  16. package/dist/data/api/cli.d.ts +1 -0
  17. package/dist/data/api/cli.js +1 -0
  18. package/dist/data/api/head.d.ts +16 -0
  19. package/dist/data/api/head.js +1 -0
  20. package/dist/data/api/head.spec.d.ts +1 -0
  21. package/dist/data/api/head.spec.js +1 -0
  22. package/dist/data/api/index.d.ts +2 -0
  23. package/dist/data/api/index.js +1 -0
  24. package/dist/data/api/match.d.ts +69 -0
  25. package/dist/data/api/match.js +1 -0
  26. package/dist/data/api/match.spec.d.ts +1 -0
  27. package/dist/data/api/match.spec.js +1 -0
  28. package/dist/data/api/server.d.ts +12 -0
  29. package/dist/data/api/server.js +1 -0
  30. package/dist/data/projection/cli.d.ts +1 -0
  31. package/dist/data/projection/cli.js +1 -0
  32. package/dist/data/projection/edges.d.ts +8 -0
  33. package/dist/data/projection/edges.js +1 -0
  34. package/dist/data/projection/edges.spec.d.ts +1 -0
  35. package/dist/data/projection/edges.spec.js +1 -0
  36. package/dist/data/projection/facets.d.ts +18 -0
  37. package/dist/data/projection/facets.js +1 -0
  38. package/dist/data/projection/facets.spec.d.ts +1 -0
  39. package/dist/data/projection/facets.spec.js +1 -0
  40. package/dist/data/projection/facts.d.ts +40 -0
  41. package/dist/data/projection/facts.js +1 -0
  42. package/dist/data/projection/index.d.ts +6 -0
  43. package/dist/data/projection/index.js +1 -0
  44. package/dist/data/projection/project.d.ts +10 -0
  45. package/dist/data/projection/project.js +1 -0
  46. package/dist/data/projection/projection.spec.d.ts +1 -0
  47. package/dist/data/projection/projection.spec.js +1 -0
  48. package/dist/data/projection/schema.d.ts +1 -0
  49. package/dist/data/projection/schema.js +1 -0
  50. package/dist/data/projection/store.d.ts +49 -0
  51. package/dist/data/projection/store.js +1 -0
  52. package/dist/data/projection/types.d.ts +137 -0
  53. package/dist/data/projection/types.js +1 -0
  54. package/dist/data/sync/cdc.d.ts +34 -0
  55. package/dist/data/sync/cdc.js +1 -0
  56. package/dist/data/sync/cdc.spec.d.ts +1 -0
  57. package/dist/data/sync/cdc.spec.js +1 -0
  58. package/dist/data/sync/graphql-source.d.ts +16 -0
  59. package/dist/data/sync/graphql-source.js +1 -0
  60. package/dist/data/sync/index.d.ts +5 -0
  61. package/dist/data/sync/index.js +1 -0
  62. package/dist/data/sync/reconciler.d.ts +14 -0
  63. package/dist/data/sync/reconciler.js +1 -0
  64. package/dist/data/sync/reconciler.spec.d.ts +1 -0
  65. package/dist/data/sync/reconciler.spec.js +1 -0
  66. package/dist/data/sync/schema.d.ts +1 -0
  67. package/dist/data/sync/schema.js +1 -0
  68. package/dist/data/sync/store.d.ts +19 -0
  69. package/dist/data/sync/store.js +1 -0
  70. package/dist/data/sync/sync.spec.d.ts +1 -0
  71. package/dist/data/sync/sync.spec.js +1 -0
  72. package/dist/data/sync/synchronizer.d.ts +10 -0
  73. package/dist/data/sync/synchronizer.js +1 -0
  74. package/dist/data/sync/types.d.ts +162 -0
  75. package/dist/data/sync/types.js +1 -0
  76. package/dist/evaluation/builtins/demand-match.js +1 -1
  77. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  78. package/dist/evaluation/capability.d.ts +1 -0
  79. package/dist/evaluation/engine.js +1 -1
  80. package/dist/evaluation/extract.d.ts +7 -1
  81. package/dist/evaluation/extract.js +1 -1
  82. package/dist/evaluation/match-policy.d.ts +142 -0
  83. package/dist/evaluation/match-policy.js +1 -0
  84. package/dist/evaluation/match-policy.spec.d.ts +1 -0
  85. package/dist/evaluation/match-policy.spec.js +1 -0
  86. package/dist/experience/realtime-feedback.js +1 -1
  87. package/dist/extensions/business-modules.js +1 -1
  88. package/dist/graph/onchain/expand.js +1 -1
  89. package/dist/graph/onchain/exposure.js +1 -1
  90. package/dist/harness/recover.js +1 -1
  91. package/dist/intent/types.d.ts +1 -1
  92. package/dist/intent/types.js +1 -1
  93. package/dist/keeper/detectors.d.ts +3 -0
  94. package/dist/keeper/detectors.js +1 -1
  95. package/dist/keeper/keeper.spec.js +1 -1
  96. package/dist/knowledge/allocator-rail-verifier.js +1 -1
  97. package/dist/knowledge/arbitration-ledger.js +1 -1
  98. package/dist/knowledge/audit-rules.js +1 -1
  99. package/dist/knowledge/baselines/rules/plan.json +113 -3
  100. package/dist/knowledge/builtin-templates.d.ts +6 -1
  101. package/dist/knowledge/builtin-templates.js +1 -1
  102. package/dist/knowledge/event-semantics.js +1 -1
  103. package/dist/knowledge/getting-started.js +1 -1
  104. package/dist/knowledge/guard-design-patterns.d.ts +1 -1
  105. package/dist/knowledge/guard-design-patterns.js +1 -1
  106. package/dist/knowledge/guard-ledger.js +1 -1
  107. package/dist/knowledge/guard-puzzle.js +1 -1
  108. package/dist/knowledge/guard-render.js +1 -1
  109. package/dist/knowledge/guard-risk.js +1 -1
  110. package/dist/knowledge/guard-templates.d.ts +1 -1
  111. package/dist/knowledge/guard-templates.js +1 -1
  112. package/dist/knowledge/guard-translation.js +1 -1
  113. package/dist/knowledge/index.js +1 -1
  114. package/dist/knowledge/industry-generalizer.d.ts +4 -0
  115. package/dist/knowledge/industry-generalizer.js +1 -1
  116. package/dist/knowledge/industry-registry.js +1 -1
  117. package/dist/knowledge/jsonrpc-enum.d.ts +26 -10
  118. package/dist/knowledge/jsonrpc-enum.js +1 -1
  119. package/dist/knowledge/projection.d.ts +54 -0
  120. package/dist/knowledge/projection.js +1 -0
  121. package/dist/knowledge/projection.spec.d.ts +1 -0
  122. package/dist/knowledge/projection.spec.js +1 -0
  123. package/dist/knowledge/recipient-constraint.d.ts +1 -1
  124. package/dist/knowledge/recipient-constraint.js +1 -1
  125. package/dist/knowledge/semantic-ir.d.ts +113 -0
  126. package/dist/knowledge/semantic-ir.js +1 -0
  127. package/dist/knowledge/service-ledger.d.ts +1 -1
  128. package/dist/knowledge/service-ledger.js +1 -1
  129. package/dist/knowledge/strategy-manuals.js +1 -1
  130. package/dist/knowledge/template-loader.d.ts +34 -0
  131. package/dist/knowledge/template-loader.js +1 -1
  132. package/dist/knowledge/template-prose.d.ts +50 -0
  133. package/dist/knowledge/template-prose.js +1 -0
  134. package/dist/knowledge/template-registry.js +1 -1
  135. package/dist/knowledge/template-scanner.d.ts +1 -1
  136. package/dist/knowledge/template-scanner.js +1 -1
  137. package/dist/knowledge/tools-reference.js +1 -1
  138. package/dist/monitor/MonitorLoop.js +1 -1
  139. package/dist/monitor/normalize.d.ts +1 -1
  140. package/dist/monitor/normalize.js +1 -1
  141. package/dist/monitor/types.js +1 -1
  142. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  143. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  144. package/dist/playbooks/service-build/merchant-guide.d.ts +4 -0
  145. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  146. package/dist/playbooks/service-build/migration-planner.d.ts +2 -1
  147. package/dist/playbooks/service-build/migration-planner.js +1 -1
  148. package/dist/playbooks/service-build/mode-actions.d.ts +7 -0
  149. package/dist/playbooks/service-build/mode-actions.js +1 -1
  150. package/dist/playbooks/service-build/object-panorama.d.ts +22 -1
  151. package/dist/playbooks/service-build/object-panorama.js +1 -1
  152. package/dist/playbooks/service-build/participation-radar.js +1 -1
  153. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  154. package/dist/playbooks/service-build/reverse-mapping-nk4.spec.js +1 -1
  155. package/dist/playbooks/service-build/reverse-mapping.d.ts +1 -0
  156. package/dist/playbooks/service-build/reverse-mapping.js +1 -1
  157. package/dist/playbooks/service-build/service-panorama.js +1 -1
  158. package/dist/playbooks/service-build/service-quote.js +1 -1
  159. package/dist/playbooks/service-build/service-quote.spec.js +1 -1
  160. package/dist/review/index.js +1 -1
  161. package/dist/role/profiles.js +1 -1
  162. package/dist/safety/confirm-gate.js +1 -1
  163. package/dist/schema/benchmark-migration/index.d.ts +64 -10
  164. package/dist/schema/benchmark-migration/index.js +1 -1
  165. package/dist/schema/call/allocation.js +1 -1
  166. package/dist/schema/call/arbitration.js +1 -1
  167. package/dist/schema/call/base.d.ts +8 -0
  168. package/dist/schema/call/bridge.d.ts +2 -0
  169. package/dist/schema/call/error-codes.d.ts +1 -1
  170. package/dist/schema/call/error-codes.js +1 -1
  171. package/dist/schema/call/proof.js +1 -1
  172. package/dist/schema/call/reward.d.ts +10 -0
  173. package/dist/schema/call/reward.js +1 -1
  174. package/dist/schema/call/semantic.js +1 -1
  175. package/dist/schema/call/service.js +1 -1
  176. package/dist/schema/common/index.js +1 -1
  177. package/dist/schema/evaluation/index.d.ts +341 -0
  178. package/dist/schema/evaluation/index.js +1 -1
  179. package/dist/schema/goal/index.d.ts +2 -0
  180. package/dist/schema/goal/planning.d.ts +3 -0
  181. package/dist/schema/goal/planning.js +1 -1
  182. package/dist/schema/industry-pack/index.d.ts +62 -0
  183. package/dist/schema/industry-pack/modes.d.ts +62 -0
  184. package/dist/schema/industry-pack/modes.js +1 -1
  185. package/dist/schema/intent-radar/index.d.ts +3 -0
  186. package/dist/schema/intent-radar/index.js +1 -1
  187. package/dist/schema/local/index.d.ts +20 -0
  188. package/dist/schema/local/index.js +1 -1
  189. package/dist/schema/operations.d.ts +5 -0
  190. package/dist/schema/query/bi.d.ts +4 -0
  191. package/dist/schema/query/bi.js +1 -1
  192. package/dist/schema/query/index.d.ts +145 -47
  193. package/dist/schema/query/index.js +1 -1
  194. package/dist/schema/schema-version.js +1 -1
  195. package/dist/schema-query-impl/index.js +1 -1
  196. package/dist/schemas/account_operation.output.json +2 -0
  197. package/dist/schemas/benchmark_migration_operation.output.json +42 -0
  198. package/dist/schemas/benchmark_migration_operation.schema.json +208 -5
  199. package/dist/schemas/bridge_operation.output.json +2 -0
  200. package/dist/schemas/evaluation_operation.output.json +624 -2
  201. package/dist/schemas/evaluation_operation.schema.json +598 -4
  202. package/dist/schemas/goal_operation.schema.json +18 -10
  203. package/dist/schemas/index.json +1 -1
  204. package/dist/schemas/industry_pack_operation.output.json +86 -2
  205. package/dist/schemas/industry_pack_operation.schema.json +199 -0
  206. package/dist/schemas/intent_radar.output.json +2 -0
  207. package/dist/schemas/intent_radar.schema.json +1 -0
  208. package/dist/schemas/local_cache_operation.output.json +2 -0
  209. package/dist/schemas/local_history_operation.output.json +2 -0
  210. package/dist/schemas/local_info_operation.output.json +2 -0
  211. package/dist/schemas/local_mark_operation.output.json +2 -0
  212. package/dist/schemas/onchain_events.output.json +281 -11
  213. package/dist/schemas/onchain_events.schema.json +5 -1
  214. package/dist/schemas/onchain_operations.output.json +2 -0
  215. package/dist/schemas/onchain_operations.schema.json +914 -314
  216. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  217. package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
  218. package/dist/schemas/onchain_operations_gen_proof.schema.json +1 -1
  219. package/dist/schemas/onchain_operations_guard.schema.json +660 -94
  220. package/dist/schemas/onchain_operations_reward.schema.json +35 -1
  221. package/dist/schemas/onchain_operations_service.schema.json +4 -4
  222. package/dist/schemas/query_toolkit.output.json +333 -0
  223. package/dist/tools/handlers/benchmark-migration.d.ts +5 -2
  224. package/dist/tools/handlers/benchmark-migration.js +1 -1
  225. package/dist/tools/handlers/config.js +1 -1
  226. package/dist/tools/handlers/evaluation.js +1 -1
  227. package/dist/tools/handlers/evaluation.spec.js +1 -1
  228. package/dist/tools/handlers/intent-radar.js +1 -1
  229. package/dist/tools/handlers/messenger.d.ts +1 -0
  230. package/dist/tools/handlers/messenger.js +1 -1
  231. package/dist/tools/handlers/onchain.d.ts +2 -0
  232. package/dist/tools/handlers/onchain.js +1 -1
  233. package/dist/tools/handlers/query.js +1 -1
  234. package/dist/tools/handlers/wip.js +1 -1
  235. package/dist/tools/index.js +1 -1
  236. package/dist/tools/registry/agent.js +1 -1
  237. package/dist/tools/registry/business.js +1 -1
  238. package/dist/tools/registry/query.js +1 -1
  239. package/dist/tools/wip-verify-ledger.d.ts +14 -0
  240. package/dist/tools/wip-verify-ledger.js +1 -0
  241. package/dist/tools/wrap.d.ts +4 -0
  242. package/dist/tools/wrap.js +1 -1
  243. package/package.json +7 -2
@@ -0,0 +1 @@
1
+ import{getCacheDb}from'@wowok/wowok/w/local/storage.js';const DEFAULT_TTL_MS=0x78*0x3e8;function projectionTtlMs(){const a=process['env']['WOWOK_PROJECTION_TTL_MS'];if(!a)return DEFAULT_TTL_MS;const b=Number(a);return Number['isFinite'](b)&&b>=0x0?b:DEFAULT_TTL_MS;}let initializedDb,envPathDb;function projectionDb(){const a=process['env']['WOWOK_PROJECTION_DB'];let b;return a?envPathDb&&envPathDb['path']===a?b=envPathDb['db']:(b=new(getCacheDb())['constructor'](a),envPathDb={'path':a,'db':b}):b=getCacheDb(),b!==initializedDb&&(b['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20cache\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20key\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20value\x20TEXT\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20projection_object\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20chain\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20kind\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20object_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20owner\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type_raw\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20name\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20location\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20description\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20coin_type\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20published\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20paused\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20price_min_wei\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20price_max_wei\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_arbitration\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_compensation\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_machine\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_messenger\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_buy_guard\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_wip\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20last_seen_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(chain,\x20kind,\x20object_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20idx_projection_scope\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20projection_object\x20(chain,\x20kind,\x20last_seen_at\x20DESC);\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20projection_watermark\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20chain\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20kind\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20refreshed_at\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20has_more\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20max_objects\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(chain,\x20kind)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20'),initializedDb=b),b;}let writeClockOverride;export function __projectionSetWriteClock(a){writeClockOverride=a;}function lastLocalWriteAt(){if(writeClockOverride!==undefined)return writeClockOverride;try{const a=projectionDb()['prepare']('SELECT\x20value\x20FROM\x20cache\x20WHERE\x20key\x20=\x20\x27write_clock\x27')['get'](),b=a?.['value']?Number(a['value']):0x0;return Number['isFinite'](b)?b:0x0;}catch{return 0x0;}}function escapeLike(a){return a['replace'](/[\\%_]/g,b=>'\x5c'+b);}export function projectionUpsert(a,b,c,d){if(!a)return;const e=projectionDb(),f=d['now']??Date['now'](),g=e['prepare']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20projection_object\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20chain,\x20kind,\x20object_id,\x20owner,\x20type_raw,\x20name,\x20location,\x20description,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20coin_type,\x20published,\x20paused,\x20price_min_wei,\x20price_max_wei,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_arbitration,\x20cap_compensation,\x20cap_machine,\x20cap_messenger,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_buy_guard,\x20cap_wip,\x20payload,\x20last_seen_at\x0a\x20\x20\x20\x20\x20\x20\x20\x20)\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(chain,\x20kind,\x20object_id)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20owner\x20=\x20excluded.owner,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type_raw\x20=\x20excluded.type_raw,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20name\x20=\x20excluded.name,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20location\x20=\x20excluded.location,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20description\x20=\x20excluded.description,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20coin_type\x20=\x20excluded.coin_type,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20published\x20=\x20excluded.published,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20paused\x20=\x20excluded.paused,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20price_min_wei\x20=\x20excluded.price_min_wei,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20price_max_wei\x20=\x20excluded.price_max_wei,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_arbitration\x20=\x20excluded.cap_arbitration,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_compensation\x20=\x20excluded.cap_compensation,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_machine\x20=\x20excluded.cap_machine,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_messenger\x20=\x20excluded.cap_messenger,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_buy_guard\x20=\x20excluded.cap_buy_guard,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20cap_wip\x20=\x20excluded.cap_wip,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload\x20=\x20excluded.payload,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20last_seen_at\x20=\x20excluded.last_seen_at\x0a\x20\x20\x20\x20'),h=e['prepare']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20projection_watermark\x20(chain,\x20kind,\x20refreshed_at,\x20has_more,\x20max_objects)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(chain,\x20kind)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20refreshed_at\x20=\x20MAX(projection_watermark.refreshed_at,\x20excluded.refreshed_at),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20has_more\x20=\x20excluded.has_more,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20max_objects\x20=\x20excluded.max_objects\x0a\x20\x20\x20\x20'),i=e['transaction'](()=>{for(const j of c){g['run'](a,b,j['object_id'],j['owner']??null,j['type_raw']??null,j['name']??null,j['location']??null,j['description']??null,j['coin_type']??null,j['published']??null,j['paused']??null,j['price_min_wei']??null,j['price_max_wei']??null,j['cap_arbitration']??null,j['cap_compensation']??null,j['cap_machine']??null,j['cap_messenger']??null,j['cap_buy_guard']??null,j['cap_wip']??null,j['payload'],f);}h['run'](a,b,f,d['hasMore']?0x1:0x0,d['maxObjects']);});i();}function arbPayloadMatches(b,c){const d=b;if(c['arbitration']!==undefined&&d['arbitration']!==c['arbitration'])return![];if(c['order']!==undefined&&d['order']!==c['order'])return![];if(c['status']!==undefined&&c['status']['length']>0x0&&!c['status']['includes'](Number(d['status'])))return![];return!![];}export function projectionServe(a,b,c,d){try{const e=projectionDb(),f=e['prepare']('SELECT\x20refreshed_at,\x20has_more,\x20max_objects\x20FROM\x20projection_watermark\x20WHERE\x20chain\x20=\x20?\x20AND\x20kind\x20=\x20?')['get'](a,b);if(!f)return undefined;const g=Date['now']();if(g-Number(f['refreshed_at'])>projectionTtlMs())return undefined;if(lastLocalWriteAt()>Number(f['refreshed_at']))return undefined;const h=e['prepare']('SELECT\x20COUNT(*)\x20AS\x20n\x20FROM\x20projection_object\x20WHERE\x20chain\x20=\x20?\x20AND\x20kind\x20=\x20?')['get'](a,b),i=Number(h?.['n']??0x0),j=['chain\x20=\x20?','kind\x20=\x20?'],k=[a,b];c['coin_type']&&(j['push']('coin_type\x20=\x20?'),k['push'](c['coin_type']));c['name_contains']&&(j['push']('LOWER(COALESCE(name,\x20\x27\x27))\x20LIKE\x20?\x20ESCAPE\x20\x27\x5c\x27'),k['push']('%'+escapeLike(c['name_contains']['toLowerCase']())+'%'));const l=(c['location_any']??[])['map'](s=>s['toLowerCase']())['filter'](s=>s['length']>0x0);if(l['length']>0x0){j['push']('('+l['map'](()=>'LOWER(COALESCE(location,\x20\x27\x27))\x20LIKE\x20?\x20ESCAPE\x20\x27\x5c\x27')['join']('\x20OR\x20')+')');for(const s of l)k['push']('%'+escapeLike(s)+'%');}const m=b==='Arb'&&(c['arbitration']!==undefined||c['order']!==undefined||c['status']!==undefined&&c['status']['length']>0x0),n=m?-0x1:Math['max'](0x1,d),o=e['prepare']('SELECT\x20payload\x20FROM\x20projection_object\x20WHERE\x20'+j['join']('\x20AND\x20')+'\x20ORDER\x20BY\x20last_seen_at\x20DESC,\x20object_id\x20ASC\x20LIMIT\x20?'),p=o['all'](...k,n),q=[];for(const u of p){try{const v=JSON['parse'](u['payload']);if(m&&!arbPayloadMatches(v,c))continue;q['push'](v);if(!m&&q['length']>=d)break;}catch{}}return{'items':q,'meta':{'watermark':{'refreshed_at':Number(f['refreshed_at']),'has_more':Number(f['has_more']),'max_objects':Number(f['max_objects'])},'total_rows':i}};}catch{return undefined;}}export function projectionStats(a){try{const b=projectionDb(),c=b['prepare']('SELECT\x20kind,\x20COUNT(*)\x20AS\x20n\x20FROM\x20projection_object\x20WHERE\x20chain\x20=\x20?\x20GROUP\x20BY\x20kind')['all'](a),d=b['prepare']('SELECT\x20kind,\x20refreshed_at\x20FROM\x20projection_watermark\x20WHERE\x20chain\x20=\x20?')['all'](a),e=new Map(d['map'](f=>[f['kind'],Number(f['refreshed_at'])]));for(const f of['Service','Demand','Arb']){if(!c['some'](g=>g['kind']===f))c['push']({'kind':f,'n':0x0});}return c['map'](g=>({'kind':g['kind'],'rows':Number(g['n']),'refreshed_at':e['get'](g['kind'])}));}catch{return[];}}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{describe,it,expect,beforeAll,afterAll}from'vitest';import*as a278a from'node:fs';import*as a278b from'node:os';import*as a278c from'node:path';import{projectionUpsert,projectionServe,projectionStats,__projectionSetWriteClock}from'./projection.js';const SCRATCH_DB=a278c['join'](a278b['tmpdir'](),'wowok-projection-spec-'+process['pid']+'-'+Date['now']()+'.db'),PREV_DB=process['env']['WOWOK_PROJECTION_DB'],PREV_TTL=process['env']['WOWOK_PROJECTION_TTL_MS'];beforeAll(()=>{process['env']['WOWOK_PROJECTION_DB']=SCRATCH_DB,process['env']['WOWOK_PROJECTION_TTL_MS']='120000',__projectionSetWriteClock(0x0);}),afterAll(()=>{if(PREV_DB===undefined)delete process['env']['WOWOK_PROJECTION_DB'];else process['env']['WOWOK_PROJECTION_DB']=PREV_DB;if(PREV_TTL===undefined)delete process['env']['WOWOK_PROJECTION_TTL_MS'];else process['env']['WOWOK_PROJECTION_TTL_MS']=PREV_TTL;__projectionSetWriteClock(undefined);try{a278a['rmSync'](SCRATCH_DB,{'force':!![]}),a278a['rmSync'](SCRATCH_DB+'-wal',{'force':!![]}),a278a['rmSync'](SCRATCH_DB+'-shm',{'force':!![]});}catch{}});function svcRow(a,b={}){const {payloadJson:c,...d}=b;return{'object_id':a,'payload':JSON['stringify']({'object':a,...c??{}}),...d};}describe('projection\x20cache\x20(K5\x20doc\x2017\x20B-tier)',()=>{it('returns\x20undefined\x20without\x20a\x20watermark\x20(never\x20fabricates\x20coverage)',()=>{const a=projectionServe('chain-empty-proj','Service',{},0xc8);expect(a)['toBeUndefined'](),expect(projectionStats('chain-empty-proj')['every'](b=>b['rows']===0x0))['toBe'](!![]);}),it('serves\x20a\x20fresh\x20projection\x20with\x20SQL\x20filters\x20and\x20pre-filter\x20totals',()=>{const a='chain-proj-serve',b=[svcRow('0xa1',{'name':'Alpha\x20Music','location':'Shanghai,\x20CN','coin_type':'0x2::wow::WOW','published':0x1,'paused':0x0,'payloadJson':{'object':'0xa1','name':'Alpha\x20Music','location':'Shanghai,\x20CN'}}),svcRow('0xa2',{'name':'Beta\x20Design','location':'Beijing,\x20CN','coin_type':'0x2::wow::WOW','published':0x1,'paused':0x0,'payloadJson':{'object':'0xa2','name':'Beta\x20Design','location':'Beijing,\x20CN'}}),svcRow('0xa3',{'name':'Gamma\x20Food','location':'Shanghai,\x20CN','coin_type':'0x2::sui::SUI','published':0x1,'paused':0x0,'payloadJson':{'object':'0xa3','name':'Gamma\x20Food','location':'Shanghai,\x20CN'}})];projectionUpsert(a,'Service',b,{'hasMore':![],'maxObjects':0xc8});const c=projectionServe(a,'Service',{},0xc8);expect(c)['toBeDefined'](),expect(c['items'])['toHaveLength'](0x3),expect(c['meta']['total_rows'])['toBe'](0x3),expect(c['meta']['watermark']['has_more'])['toBe'](0x0),expect(c['items']['map'](h=>h['object'])['sort']())['toEqual'](['0xa1','0xa2','0xa3']);const d=projectionServe(a,'Service',{'coin_type':'0x2::wow::WOW'},0xc8);expect(d['items']['map'](h=>h['object'])['sort']())['toEqual'](['0xa1','0xa2']),expect(d['meta']['total_rows'])['toBe'](0x3);const e=projectionServe(a,'Service',{'name_contains':'beta'},0xc8);expect(e['items']['map'](h=>h['object']))['toEqual'](['0xa2']);const f=projectionServe(a,'Service',{'location_any':['shanghai']},0xc8);expect(f['items']['map'](h=>h['object'])['sort']())['toEqual'](['0xa1','0xa3']);const g=projectionServe(a,'Service',{'location_any':['paris']},0xc8);expect(g['items'])['toHaveLength'](0x0),expect(g['meta']['total_rows'])['toBe'](0x3),expect(projectionStats(a)['find'](h=>h['kind']==='Service')?.['rows'])['toBe'](0x3),expect(projectionStats(a)['find'](h=>h['kind']==='Service')?.['refreshed_at'])['toBeGreaterThan'](0x0);}),it('upserts\x20cumulatively:\x20rows\x20update\x20in\x20place\x20and\x20accumulate\x20across\x20windows',()=>{const a='chain-proj-cumulative';projectionUpsert(a,'Demand',[{'object_id':'0xd1','payload':JSON['stringify']({'object':'0xd1','description':'v1'})}],{'hasMore':!![],'maxObjects':0xc8}),projectionUpsert(a,'Demand',[{'object_id':'0xd1','payload':JSON['stringify']({'object':'0xd1','description':'v2'})},{'object_id':'0xd2','payload':JSON['stringify']({'object':'0xd2','description':'new'})}],{'hasMore':![],'maxObjects':0xc8});const b=projectionServe(a,'Demand',{},0xc8);expect(b['items'])['toHaveLength'](0x2);const c=b['items']['find'](d=>d['object']==='0xd1');expect(c?.['description'])['toBe']('v2'),expect(b['meta']['watermark']['has_more'])['toBe'](0x0);}),it('declines\x20to\x20serve\x20when\x20stale\x20by\x20TTL',async()=>{const a='chain-proj-stale-ttl',b=process['env']['WOWOK_PROJECTION_TTL_MS'];process['env']['WOWOK_PROJECTION_TTL_MS']='20';try{projectionUpsert(a,'Service',[svcRow('0xs1')],{'hasMore':![],'maxObjects':0xc8}),expect(projectionServe(a,'Service',{},0xc8))['toBeDefined'](),await new Promise(c=>setTimeout(c,0x28)),expect(projectionServe(a,'Service',{},0xc8))['toBeUndefined']();}finally{process['env']['WOWOK_PROJECTION_TTL_MS']=b;}}),it('declines\x20to\x20serve\x20when\x20a\x20local\x20on-chain\x20write\x20postdates\x20the\x20watermark',()=>{const a='chain-proj-stale-write';projectionUpsert(a,'Service',[svcRow('0xs2')],{'hasMore':![],'maxObjects':0xc8}),__projectionSetWriteClock(Date['now']()+0x1);try{expect(projectionServe(a,'Service',{},0xc8))['toBeUndefined']();}finally{__projectionSetWriteClock(0x0);}}),it('filters\x20arb\x20payloads\x20post-SQL\x20for\x20parity\x20with\x20the\x20legacy\x20post-hydration\x20filter',()=>{const a='chain-proj-arb';projectionUpsert(a,'Arb',[{'object_id':'0xb1','payload':JSON['stringify']({'object':'0xb1','arbitration':'0xarb1','order':'0xo1','status':0x2})},{'object_id':'0xb2','payload':JSON['stringify']({'object':'0xb2','arbitration':'0xarb1','order':'0xo2','status':0x5})},{'object_id':'0xb3','payload':JSON['stringify']({'object':'0xb3','arbitration':'0xarb2','order':'0xo1','status':0x2})}],{'hasMore':![],'maxObjects':0xc8});const b=projectionServe(a,'Arb',{'arbitration':'0xarb1'},0xc8);expect(b['items']['map'](f=>f['object'])['sort']())['toEqual'](['0xb1','0xb2']),expect(b['meta']['total_rows'])['toBe'](0x3);const c=projectionServe(a,'Arb',{'order':'0xo1'},0xc8);expect(c['items']['map'](f=>f['object'])['sort']())['toEqual'](['0xb1','0xb3']);const d=projectionServe(a,'Arb',{'status':[0x5]},0xc8);expect(d['items']['map'](f=>f['object']))['toEqual'](['0xb2']);const e=projectionServe(a,'Arb',{'arbitration':'0xarb2','status':[0x5]},0xc8);expect(e['items'])['toHaveLength'](0x0);}),it('respects\x20the\x20limit\x20on\x20the\x20SQL\x20path',()=>{const a='chain-proj-limit';projectionUpsert(a,'Demand',Array['from']({'length':0x5},(c,d)=>({'object_id':'0xL'+d,'payload':JSON['stringify']({'object':'0xL'+d})})),{'hasMore':![],'maxObjects':0xc8});const b=projectionServe(a,'Demand',{},0x3);expect(b['items'])['toHaveLength'](0x3),expect(b['meta']['total_rows'])['toBe'](0x5);});});
@@ -135,7 +135,7 @@ export type DualPayoutTrack = {
135
135
  } | {
136
136
  track: "unknown";
137
137
  };
138
- export declare function classifyDualPayoutTrack(allocators: unknown): DualPayoutTrack;
138
+ export declare function classifyDualPayoutTrack(allocators: unknown, guardAddr?: string): DualPayoutTrack;
139
139
  export declare const RECIPIENT_CONSTRAINT_VERSION = "1.2.0";
140
140
  export declare function analyzeRecipientConstraints(input: RecipientConstraintInput): RecipientConstraintAudit;
141
141
  export declare function derivePayoffFromSharing(sharing: Array<{
@@ -1 +1 @@
1
- import{ValueType}from'@wowok/wowok';import{getGuardQueryByIdOrName}from'../schema/utils/guard-query-utils.js';function asNode(a){if(typeof a!=='object'||a===null)return null;const b=a['type'];return typeof b==='string'?a:null;}function queryMeta(a){if(typeof a!=='number'&&typeof a!=='string')return null;const b=getGuardQueryByIdOrName(a);return b?{'id':b['id'],'name':b['name']}:null;}function childNodes(a){const b=[];if(Array['isArray'](a['nodes']))a['nodes']['forEach'](d=>{const e=asNode(d);if(e)b['push'](e);});if(asNode(a['node']))b['push'](asNode(a['node']));return[a['nodeLeft'],a['nodeRight']]['forEach'](d=>{const e=asNode(d);if(e)b['push'](e);}),b;}export function classifyRecipient(a){if(typeof a!=='object'||a===null)return null;const b=a;if(typeof b['Entity']==='string')return{'kind':'entity','address':b['Entity']};const c=b['Entity'];if(c&&typeof c==='object'&&typeof c['name_or_address']==='string')return{'kind':'entity','address':c['name_or_address']};if(b['Signer']==='signer'||b['Signer']===!![])return{'kind':'signer'};if(typeof b['GuardIdentifier']==='number')return{'kind':'submission','identifier':b['GuardIdentifier']};return null;}export function classifyDualPayoutTrack(a){let b=[];if(Array['isArray'](a))b=a;else{if(a&&typeof a==='object'){const e=a['allocators'];if(Array['isArray'](e))b=e;}}const c=[];for(const f of b){const h=f?.['sharing'];if(Array['isArray'](h))c['push'](...h);}if(c['length']===0x0)return{'track':'unknown'};const d=[];for(const i of c){const j=i?.['who'],k=classifyRecipient(typeof j==='string'?j==='Signer'?{'Signer':!![]}:{'Entity':j}:j);if(!k||k['kind']==='signer')return{'track':'unknown'};if(k['kind']==='submission')return{'track':'order-directed'};d['push'](k['address']);}return{'track':'entity-directed','recipients':d};}function leafInfo(a,b){if(a['type']==='context'&&typeof a['context']==='string'){if(a['context']==='Signer')return{'kind':'signer'};if(a['context']==='Clock')return{'kind':'clock'};}if(a['type']==='query'){const c=queryMeta(a['query']),d=a['object'];if(c&&d&&typeof d['identifier']==='number')return{'kind':'query','query_name':c['name'],'query_id':c['id'],'object_identifier':d['identifier'],'convert_witness':d['convert_witness']};}if(a['type']==='identifier'){const e=typeof a['identifier']==='number'?a['identifier']:-0x1,f=b['find'](g=>g['identifier']===e);if(f){const g=typeof f['value']==='string'?f['value']:undefined,h=normalizeValueType(f['value_type']);if(h===ValueType['Address'])return{'kind':'static_address','value':g};if(h===ValueType['String'])return{'kind':'static_string','value':g};}}return{'kind':'other'};}function comparisonLeaves(a,b){if(a['type']==='logic_equal'){const c=childNodes(a)['map'](d=>flattenLeaf(d,b));return c;}return[];}function flattenLeaf(a,b){if(a['type']==='logic_not'){const d=childNodes(a)[0x0];return d?flattenLeaf(d,b):{'kind':'other'};}return leafInfo(a,b);}function isOrderProgressWitness(a){if(a===0x64)return!![];return typeof a==='string'&&a['toLowerCase']()['includes']('orderprogress');}function describe(a){switch(a){case'service_binding':return'Submitted\x20object\x20must\x20belong\x20to\x20the\x20expected\x20service';case'progress_node_state':return'Submitted\x20order\x20must\x20be\x20at\x20a\x20qualifying\x20workflow\x20node';case'signer_is_submitted_object_owner':return'Caller\x20must\x20be\x20the\x20owner\x20of\x20the\x20submitted\x20object';case'signer_authorized_entity':return'Caller\x20must\x20equal\x20a\x20fixed\x20authorized\x20address';case'signer_permission_member':return'Caller\x20must\x20satisfy\x20a\x20Permission\x20membership\x20rule';case'time_lock':return'Current\x20time\x20must\x20satisfy\x20the\x20time-lock';case'repository_crosscheck':return'Repository\x20data\x20must\x20satisfy\x20the\x20cross-check';default:return'Other\x20guard\x20constraint';}}function extractConstraints(a,b){const c=[],d=new Set(),e=h=>{const i=h['code']+':'+(h['slot']??'-');!d['has'](i)&&(d['add'](i),c['push'](h));},f=(h,i)=>({'path':h,'queries':i}),g=(h,i)=>{const j=comparisonLeaves(h,b);if(j['length']>=0x2){const k=j['find'](r=>r['kind']==='signer'),l=j['find'](r=>r['kind']==='query'&&r['query_name']==='order.owner'),m=j['find'](r=>r['kind']==='query'&&r['query_name']==='order.service'),n=j['find'](r=>r['kind']==='query'&&r['query_name']==='progress.current'),o=j['find'](r=>r['kind']==='static_address'),p=j['find'](r=>r['kind']==='static_string');k&&l&&e({'code':'signer_is_submitted_object_owner','slot':l['object_identifier'],'description':describe('signer_is_submitted_object_owner'),'caller_constraint':!![],'evidence':f(i,['Signer','order.owner'])});k&&o&&e({'code':'signer_authorized_entity','description':describe('signer_authorized_entity'),'caller_constraint':!![],'evidence':f(i,['Signer'])});m&&o&&e({'code':'service_binding','slot':m['object_identifier'],'description':describe('service_binding'),'caller_constraint':![],'evidence':f(i,['order.service'])});if(n&&p){const r=n['object_identifier'];isOrderProgressWitness(n['convert_witness'])&&e({'code':'progress_node_state','slot':r,'description':describe('progress_node_state'),'caller_constraint':![],'evidence':f(i,['progress.current'])});}}if(h['type']['startsWith']('logic_as_u256')||h['type']==='calc_number_add'){const s=[h,...childNodes(h)]['map'](t=>flattenLeaf(t,b));if(s['some'](t=>t['kind']==='clock')&&s['some'](t=>t['kind']==='query'&&(t['query_name']==='progress.current_time'||t['query_name']==='progress.session.forward.time'))){const t=s['find'](u=>u['kind']==='query');e({'code':'time_lock','slot':t['object_identifier'],'description':describe('time_lock'),'caller_constraint':![],'evidence':f(i,['Clock',t['query_name']])});}}if(h['type']==='query'){const u=queryMeta(h['query']);if(u&&u['name']['startsWith']('repository.')){const v=h['object'];e({'code':'repository_crosscheck','slot':v?.['identifier'],'description':describe('repository_crosscheck'),'caller_constraint':![],'evidence':f(i,[u['name']])});}}childNodes(h)['forEach']((w,x)=>g(w,i+'/'+x));};return g(a,'/root'),c;}function findSessionQueries(a){const b=[],c=(d,e)=>{if(d['type']==='query'){const f=queryMeta(d['query']);if(f&&(f['id']===0x4f6||f['id']===0x4f7))b['push'](e);}childNodes(d)['forEach']((g,h)=>c(g,e+'/'+h));};return c(a,'/root'),b;}function collectSlotUsages(a){const b=[],c=(d,e)=>{if(d['type']==='query'){const f=queryMeta(d['query']),g=d['object'];f&&g&&typeof g['identifier']==='number'&&b['push']({'slot':g['identifier'],'path':e,'query_id':f['id'],'query_name':f['name'],...g['convert_witness']!==undefined?{'convert_witness':g['convert_witness']}:{}});}childNodes(d)['forEach']((h,j)=>c(h,e+'/'+j));};return c(a,'/root'),b;}function deriveReceiptRight(a,b){const c=b['find'](e=>e['code']==='progress_node_state'&&e['slot']===a),d=b['find'](e=>e['code']==='signer_is_submitted_object_owner'&&e['slot']===a);if(c||d)return{'object_type':'order','receive_entry':'owner-side\x20extraction\x20on\x20the\x20order','guarantee':'Delivered\x20funds\x20are\x20owned\x20by\x20the\x20submitted\x20Order;\x20only\x20its\x20current\x20owner\x20can\x20'+'extract\x20them\x20(&mut\x20Order\x20input),\x20and\x20coins\x20transfer\x20to\x20that\x20owner.'};return undefined;}function deriveBeneficialOwner(a,b){switch(a['kind']){case'entity':return'Fixed\x20entity\x20'+a['address'];case'signer':return'Transaction\x20caller\x20(Signer)\x20—\x20direct\x20wallet';case'submission':return b?'Owner\x20of\x20the\x20submitted\x20object\x20at\x20table['+a['identifier']+']\x20(object\x20receipt\x20=\x20owner\x20receipt)':'Address\x20submitted\x20at\x20table['+a['identifier']+']\x20(caller-provided)';}}function buildSlotModels(a,b,c,d){const e=[...new Set(c['map'](f=>f['spec'])['filter'](f=>f['kind']==='submission')['map'](f=>f['identifier']))];return e['map'](f=>{const g=a['find'](p=>p['identifier']===f),h=g?normalizeValueType(g['value_type']):undefined,i=h===ValueType['Address'],j=b['filter'](p=>p['slot']===f),k=c['filter'](p=>p['spec']['kind']==='submission'&&p['spec']['identifier']===f)['map'](p=>p['mode']??'Unknown'),l=d['filter'](p=>p['slot']===undefined||p['slot']===f),m=deriveReceiptRight(f,d),n=l['some'](p=>p['code']==='service_binding'||p['code']==='repository_crosscheck'||p['code']==='signer_permission_member'),o=[];if(h!==undefined&&!i)o['push']('RC-FIND-07');if(!n)o['push']('RC-FIND-02');if(m?.['object_type']==='order')o['push']('RC-FIND-03');return{'identifier':f,'externally_submitted':g?.['b_submission']??!![],...h!==undefined?{'declared_value_type':h}:{},'is_address':i,'usages':j,'recipient_modes':k,'constraints':l,...m?{'receipt':m}:{},'beneficial_owner':deriveBeneficialOwner({'kind':'submission','identifier':f},m),'assessment':{'address_typed':i,'scope_bound':n,'object_receipt':m?.['object_type']==='order'},'findings':o};});}function buildSlotFinding(a,b,c){const d=a['identifier'];switch(b){case'RC-FIND-07':return{'code':b,'severity':'medium','title':'Submission\x20slot\x20'+d+'\x20is\x20not\x20address-typed','explanation':'GuardIdentifier\x20recipients\x20require\x20an\x20address-typed\x20table\x20entry\x20'+'(enforced\x20at\x20allocator\x20registration\x20/\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','evidence_paths':c,'mitigation':'Set\x20the\x20slot\x20value_type\x20to\x20Address,\x20or\x20use\x20an\x20Entity\x20recipient.','unavoidable':![]};case'RC-FIND-02':return{'code':b,'severity':'high','title':'Submission\x20slot\x20'+d+'\x20has\x20no\x20scope\x20binding','explanation':'Nothing\x20constrains\x20which\x20submitted\x20objects/addresses\x20qualify:\x20no\x20'+'service\x20binding,\x20repository\x20cross-check\x20or\x20permission\x20membership.\x20A\x20caller\x20'+'can\x20submit\x20arbitrary\x20qualifying-by-other-conditions\x20inputs.','evidence_paths':c,'mitigation':'Add\x20a\x20constraint\x20binding\x20the\x20slot\x20(e.g.\x20order.service\x20==\x20host\x20service).','unavoidable':![]};case'RC-FIND-03':return{'code':b,'severity':'medium','title':'Cross-allocation\x20settlement\x20residual','explanation':'The\x20submitted\x20order\x20is\x20not\x20bound\x20to\x20the\x20Allocation\x20being\x20settled\x20'+'(alloc\x20is\x20permissionless\x20and\x20allocation\x20context\x20is\x20not\x20a\x20Guard\x20input).\x20A\x20'+'caller\x20owning\x20ANY\x20qualifying\x20order\x20can\x20settle\x20OTHER\x20allocations;\x20funds\x20land\x20'+'at\x20the\x20submitted\x20order\x20and\x20are\x20receivable\x20by\x20its\x20owner.\x20Destination\x20is\x20safe\x20'+'(an\x20order\x20owner),\x20allocation\x20choice\x20is\x20the\x20residual.','evidence_paths':c,'mitigation':'Pick\x20ONE\x20resolution\x20and\x20record\x20it\x20in\x20the\x20service\x20description:\x20'+'(1)\x20competition\x20semantics\x20—\x20declare\x20that\x20any\x20qualifying\x20order\x20may\x20settle\x20'+'this\x20allocation\x20and\x20cap\x20the\x20exposure\x20(sharing\x20threshold\x20/\x20max\x20amount);\x20'+'(2)\x20Entity\x20routing\x20—\x20use\x20a\x20fixed\x20Entity\x20(treasury)\x20recipient,\x20the\x20only\x20'+'exclusive\x20choice\x20on\x20the\x20automatic\x20order_allocators\x20route\x20(trust\x20shifts\x20to\x20'+'the\x20entity\x20operator);\x20'+'(3)\x20per-order\x20pinned\x20Guards\x20—\x20abandon\x20automatic\x20order_allocators\x20and\x20attach\x20'+'a\x20per-order\x20Guard\x20pinning\x20the\x20order\x20id\x20(order.owner\x20==\x20constant),\x20the\x20'+'trustless\x20exclusive\x20route.','unavoidable':!![],'resolution_required':!![]};default:return{'code':b,'severity':'low','title':'Slot\x20'+d+'\x20finding\x20'+b,'explanation':'','evidence_paths':c,'mitigation':'','unavoidable':![]};}}function buildFindings(a,b){const c=[];let d=![],e=![];for(const f of b){const g=f['recipients']['flatMap'](h=>h['constraints'])['filter'](h=>h['caller_constraint']);if(g['length']>0x0)d=!![];if(f['slots']['some'](h=>h['assessment']['scope_bound']))e=!![];for(const h of f['recipients']){const i=h['constraints']['map'](j=>j['evidence']['path']);h['spec']['kind']==='signer'&&g['length']===0x0&&c['push']({'code':'RC-FIND-01','severity':'critical','title':'Signer\x20recipient\x20without\x20caller\x20constraint\x20—\x20fund\x20theft','explanation':'Funds\x20are\x20delivered\x20directly\x20to\x20the\x20transaction\x20caller,\x20but\x20the\x20Guard\x20'+'does\x20not\x20bind\x20the\x20Signer\x20to\x20an\x20authorized\x20identity.\x20Anyone\x20who\x20satisfies\x20the\x20'+'other\x20conditions\x20steals\x20the\x20funds.','evidence_paths':i,'mitigation':'Bind\x20the\x20Signer\x20(signer==order.owner\x20or\x20signer==fixed\x20address),\x20or\x20change\x20'+'the\x20recipient\x20to\x20an\x20Entity\x20/\x20submitted\x20object\x20slot.','unavoidable':![]});}for(const j of f['slots']){const k=j['constraints']['map'](l=>l['evidence']['path']);for(const l of j['findings']){c['push'](buildSlotFinding(j,l,k));}}a['trigger_source']==='service_order_allocators'&&f['recipients']['length']>0x0&&!f['recipients']['some'](m=>m['spec']['kind']==='submission')&&c['push']({'code':'RC-FIND-09','severity':'low','title':'Allocator\x20Guard\x20'+f['guard']+'\x20has\x20no\x20GuardIdentifier\x20sharing\x20row\x20—\x20bound\x20to\x20no\x20particular\x20order','explanation':'Every\x20sharing\x20row\x20is\x20a\x20fixed\x20recipient\x20(Entity/Signer),\x20which\x20resolves\x20no\x20'+'submission.\x20The\x20Guard\x20therefore\x20cannot\x20read\x20the\x20paying\x20order\x20(order.*\x20queries\x20have\x20'+'no\x20binding\x20target),\x20and\x20the\x20allocation\x20pays\x20the\x20same\x20fixed\x20destinations\x20for\x20EVERY\x20order.\x20'+'This\x20is\x20often\x20intended\x20—\x20confirm\x20it\x20is.','evidence_paths':[],'mitigation':'If\x20the\x20Guard\x20should\x20distinguish\x20orders,\x20add\x20a\x20zero-share\x20{GuardIdentifier:\x200}\x20'+'anchor\x20row\x20(Rate\x200)\x20so\x20the\x20Identifier\x20slot\x20resolves\x20to\x20the\x20paying\x20order\x20'+'(pattern.allocator_order_anchor).\x20If\x20fixed-pay\x20is\x20intended,\x20no\x20action.','unavoidable':![]});}a['trigger_source']==='standalone'&&!d&&c['push']({'code':'RC-FIND-04','severity':'high','title':'Standalone\x20allocation\x20without\x20issuer\x20identity\x20constraint','explanation':'Standalone\x20allocations\x20have\x20no\x20Service/Arbitration\x20access-control\x20layer.\x20'+'Without\x20a\x20Signer/permission\x20binding\x20in\x20the\x20Guard,\x20anyone\x20can\x20trigger\x20distribution.','evidence_paths':[],'mitigation':'Bind\x20the\x20issuer\x20(Signer==owner/admin)\x20or\x20move\x20the\x20allocation\x20into\x20a\x20Service.','unavoidable':![]});c['push']({'code':'RC-FIND-06','severity':'low','title':'Permissionless\x20alloc\x20—\x20forced\x20settlement\x20timing','explanation':'Once\x20the\x20Guard\x27s\x20conditions\x20are\x20satisfiable,\x20anyone\x20can\x20trigger\x20settlement\x20of\x20an\x20'+'order\x27s\x20allocation.\x20With\x20Entity/object\x20recipients\x20this\x20affects\x20timing\x20only,\x20not\x20destination.','evidence_paths':[],'mitigation':'Monitor\x20settlements;\x20constrain\x20time-sensitivity\x20via\x20Guard\x20conditions.','unavoidable':!![]});for(const [m,n]of Object['entries'](a['guards']??{})){const o=asNode(n['root']);if(!o)continue;for(const q of findSessionQueries(o)){c['push']({'code':'RC-FIND-05','severity':'medium','title':'Guard\x20'+m+'\x20uses\x20session-only\x20query\x20at\x20'+q,'explanation':'Queries\x201270/1271\x20read\x20the\x20active\x20session;\x20after\x20the\x20session\x20migrates\x20to\x20'+'history\x20the\x20query\x20aborts\x20(W_FIELD_NOT_FOUND)\x20and\x20the\x20Guard\x20permanently\x20fails.','evidence_paths':[q],'mitigation':'Use\x20progress.current_time\x20(1272)\x20or\x20history\x20queries\x20(1274-1280).','unavoidable':![]});}}for(const [s,t]of Object['entries'](a['guards']??{})){const u=(t['relies']??[])['filter'](v=>typeof v==='string'&&v);if(u['length']===0x0)continue;c['push']({'code':'RC-FIND-08','severity':'low','title':'Guard\x20'+s+'\x20relies\x20on\x20'+u['length']+'\x20sub-guard(s)\x20—\x20not\x20credited\x20by\x20this\x20audit','explanation':'Guard\x20composition\x20(relies,\x20one\x20level,\x20≤4,\x20'+((t['relies_logic_and']===![]?'OR':'AND')+'-logic)\x20may\x20carry\x20the\x20scope/signer\x20')+'constraints\x20in\x20the\x20relied\x20sub-guards.\x20This\x20audit\x20evaluates\x20only\x20the\x20guard\x27s\x20own\x20root:\x20'+'sub-guard\x20constraints\x20are\x20NOT\x20credited,\x20so\x20scope-binding\x20gaps\x20(RC-FIND-02)\x20may\x20be\x20'+'over-reported\x20and\x20sub-guard-only\x20conditions\x20stay\x20unverified.','evidence_paths':u,'mitigation':'Resolve\x20the\x20relied\x20sub-guards\x20and\x20verify\x20their\x20constraints\x20manually,\x20or\x20re-run\x20'+'with\x20the\x20sub-guard\x20defs\x20included\x20(read-side\x20resolvers\x20attach\x20them\x20automatically).','unavoidable':![]});}if(!e&&a['trigger_source']==='service_order_allocators'){}return c;}function buildPayoff(a,b){const c=a['recipients']['some'](h=>h['constraints']['some'](i=>i['caller_constraint'])),d=c?'Caller\x20must\x20satisfy\x20the\x20Guard\x27s\x20Signer/identity\x20binding':b==='standalone'?'Any\x20caller\x20(no\x20identity\x20binding)':'Any\x20caller\x20who\x20satisfies\x20the\x20Guard\x27s\x20object/state\x20conditions',e=a['recipients']['map'](h=>h['beneficial_owner'])['join'](';\x20')||'(none)',f={},g=a['recipients']['some'](h=>h['spec']['kind']==='signer'&&!c);return f['caller']=g?'gains':c?'conditional':'neutral',f['provider']=a['recipients']['some'](h=>h['spec']['kind']==='entity')?'gains':'conditional',f['customer']=a['recipients']['some'](h=>h['receipt']?.['object_type']==='order')?'conditional':'neutral',f['system']='neutral',{'caller_eligibility':d,'beneficial_recipient':e,'positions':f};}export const RECIPIENT_CONSTRAINT_VERSION='1.2.0';export function analyzeRecipientConstraints(a){const b=a['allocators']['map'](h=>{const i=a['guards']?.[h['guard']],j=asNode(i?.['root']),k=i?.['table']??[],l=j?extractConstraints(j,k):[],m=j?collectSlotUsages(j):[],n=h['sharing']['map'](q=>{const r=classifyRecipient(q['who']);if(!r)return{'spec':{'kind':'entity','address':'(unclassifiable)'},'constraints':l,'beneficial_owner':'Unclassifiable\x20recipient\x20—\x20check\x20allocator\x20config'};const t=r['kind']==='submission'?r['identifier']:undefined,u=t!==undefined?k['find'](w=>w['identifier']===t):undefined,v=t!==undefined?deriveReceiptRight(t,l):undefined;return{'spec':r,'slot_value_type':u?normalizeValueType(u['value_type']):undefined,'constraints':t!==undefined?l['filter'](w=>w['slot']===undefined||w['slot']===t):l,'receipt':v,'beneficial_owner':deriveBeneficialOwner(r,v)};}),o=buildSlotModels(k,m,h['sharing']['map'](q=>({'spec':classifyRecipient(q['who'])??{'kind':'entity','address':'(unclassifiable)'},'mode':q['mode']})),l),p={'guard':h['guard'],'recipients':n,'slots':o,'payoff':{'caller_eligibility':'','beneficial_recipient':'','positions':{}}};return p['payoff']=buildPayoff(p,a['trigger_source']),p;}),c=buildFindings(a,b),d=c['some'](h=>h['severity']==='critical')?'critical':c['some'](h=>h['severity']==='high')?'high':c['some'](h=>h['severity']==='medium')?'medium':'low',e=!c['some'](h=>h['code']==='RC-FIND-01'),f=c['some'](h=>h['resolution_required']),g=[{'code':'RC-FIND-03','title':'Cross-allocation\x20settlement','detail':'Submitted\x20order\x20is\x20not\x20bound\x20to\x20the\x20settled\x20allocation;\x20destination\x20stays\x20at\x20an\x20order\x20owner.'},{'code':'RC-FIND-06','title':'Forced\x20settlement\x20timing','detail':'alloc\x20is\x20permissionless;\x20settlement\x20can\x20be\x20triggered\x20by\x20anyone\x20once\x20conditions\x20hold.'},{'code':'RC-RES-01','title':'Published\x20immutability','detail':'order_allocators,\x20Machine\x20and\x20Guards\x20are\x20immutable\x20after\x20publish.'},{'code':'RC-RES-03','title':'Off-chain\x20arbitration\x20backstop','detail':'No\x20on-chain\x20clawback;\x20post-incident\x20recovery\x20relies\x20on\x20arbitration.'}];return{'version':RECIPIENT_CONSTRAINT_VERSION,'scope':{'trigger_source':a['trigger_source'],'host_service':a['host_service'],'allocation':a['allocation']},'allocators':b,'findings':c,'unavoidable':g,'safe_destination':e,'resolution_required':f,'overall':d,'summary':'Analyzed\x20'+b['length']+'\x20allocator(s):\x20'+c['filter'](h=>!h['unavoidable'])['length']+'\x20actionable,\x20'+(c['filter'](h=>h['unavoidable'])['length']+'\x20structural\x20finding(s).\x20Safe\x20destination:\x20'+e+'.')+(''+(f?'\x20Resolution\x20REQUIRED:\x20at\x20least\x20one\x20residual\x20demands\x20an\x20explicit\x20design\x20decision\x20before\x20publish.':''))};}export function derivePayoffFromSharing(a,b,c){const d=asNode(c?.['root']),e=c?.['table']??[],f=d?extractConstraints(d,e):[],g=a['map'](i=>{const j=classifyRecipient(i['who'])??{'kind':'entity','address':'(unclassifiable)'},k=j['kind']==='submission'?j['identifier']:undefined,l=k!==undefined?e['find'](n=>n['identifier']===k):undefined,m=k!==undefined?deriveReceiptRight(k,f):undefined;return{'spec':j,'slot_value_type':l?normalizeValueType(l['value_type']):undefined,'constraints':k!==undefined?f['filter'](n=>n['slot']===undefined||n['slot']===k):f,'receipt':m,'beneficial_owner':deriveBeneficialOwner(j,m)};}),h={'guard':'','recipients':g,'slots':[],'payoff':{'caller_eligibility':'','beneficial_recipient':'','positions':{}}};return buildPayoff(h,b);}function normalizeValueType(a){if(typeof a==='number')return a;const b={'bool':ValueType['Bool'],'address':ValueType['Address'],'string':ValueType['String'],'u64':ValueType['U64'],'u256':ValueType['U256']};return b[a['toLowerCase']()];}export function isUnboundSignerTheft(a){return a['recipient_is_signer']&&!a['caller_identity_constrained'];}export function canonicalDoctrine(a){switch(a){case'RC-FIND-01':return{'severity':'critical','title':'Signer\x20recipient\x20without\x20caller\x20constraint\x20—\x20fund\x20theft','mitigation':'Bind\x20the\x20Signer\x20(signer==order.owner\x20or\x20signer==fixed\x20address),\x20or\x20change\x20'+'the\x20recipient\x20to\x20an\x20Entity\x20/\x20submitted\x20object\x20slot.'};case'RC-FIND-03':return{'severity':'medium','title':'Cross-allocation\x20settlement\x20residual','mitigation':'Pick\x20ONE\x20resolution\x20and\x20record\x20it\x20in\x20the\x20service\x20description:\x20'+'(1)\x20competition\x20semantics\x20with\x20capped\x20exposure\x20(threshold\x20/\x20max\x20amount);\x20'+'(2)\x20Entity\x20routing\x20(treasury)\x20—\x20the\x20only\x20exclusive\x20choice\x20on\x20the\x20automatic\x20'+'order_allocators\x20route;\x20'+'(3)\x20per-order\x20pinned\x20Guards\x20(order.owner\x20==\x20constant)\x20—\x20the\x20trustless\x20'+'exclusive\x20route.','resolution_required':!![]};case'RC-FIND-06':return{'severity':'low','title':'Permissionless\x20alloc\x20—\x20forced\x20settlement\x20timing','mitigation':'Monitor\x20settlements;\x20constrain\x20time-sensitivity\x20via\x20Guard\x20conditions.'};}}export const RECIPIENT_DESIGN_OPTIONS=[{'id':'entity','move_recipient':'Recipient::Entity(address)','semantics':'Funds\x20flow\x20to\x20a\x20fixed\x20address\x20(a\x20constrained\x20user\x20account\x20/\x20treasury).\x20'+'Destination\x20never\x20depends\x20on\x20the\x20caller.','required_constraints':['The\x20address\x20is\x20chosen\x20at\x20design\x20time\x20and\x20recorded\x20in\x20the\x20allocator\x20table.']},{'id':'submitted_object','move_recipient':'Recipient::GuardIdentifier(u8)','semantics':'Funds\x20flow\x20to\x20the\x20object\x20submitted\x20under\x20protocol\x20context\x20(e.g.\x20the\x20order\x20being\x20settled).\x20'+'Receivable\x20only\x20by\x20that\x20object\x27s\x20owner\x20—\x20object\x20receipt\x20=\x20owner\x20receipt.','required_constraints':['The\x20Guard\x20binds\x20the\x20submission\x27s\x20scope\x20(which\x20query/object\x20type\x20the\x20slot\x20carries).','The\x20slot\x27s\x20table\x20value\x20type\x20is\x20address\x20(enforced\x20at\x20allocator\x20registration).'],'finding_if_unmet':'RC-FIND-02\x20/\x20RC-FIND-07'},{'id':'signer','move_recipient':'Recipient::Signer','semantics':'Funds\x20flow\x20to\x20the\x20caller\x20who\x20executes\x20the\x20permissionless\x20alloc.\x20'+'Safe\x20only\x20when\x20the\x20Guard\x20proves\x20exactly\x20who\x20the\x20caller\x20may\x20be.','required_constraints':['The\x20Guard\x20constrains\x20the\x20Signer\x20identity\x20(signer\x20==\x20a\x20fixed\x20address\x20or\x20a\x20derived\x20legitimate\x20owner).'],'finding_if_unmet':'RC-FIND-01'},{'id':'constrained_submission','move_recipient':'Recipient::GuardIdentifier(u8)','semantics':'Funds\x20flow\x20to\x20an\x20object\x20address\x20supplied\x20by\x20the\x20signer,\x20but\x20the\x20Guard\x20constrains\x20'+'both\x20the\x20submission\x20scope\x20and\x20the\x20signer\x27s\x20relation\x20to\x20it\x20(e.g.\x20the\x20signer\x20owns\x20the\x20submitted\x20order).','required_constraints':['The\x20Guard\x20binds\x20the\x20submission\x27s\x20scope\x20(object/query\x20type).','The\x20Guard\x20binds\x20the\x20signer\x20to\x20the\x20submitted\x20object.','The\x20slot\x27s\x20table\x20value\x20type\x20is\x20address\x20(enforced\x20at\x20allocator\x20registration).'],'finding_if_unmet':'RC-FIND-01\x20/\x20RC-FIND-02\x20/\x20RC-FIND-07'}];export function recipientDesignGuidance(){return RECIPIENT_DESIGN_OPTIONS;}export const OBJECT_DRIVEABILITY=[{'object_type':'order','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20order','owner-side\x20object\x20extraction\x20from\x20the\x20order'],'anyone_drivable':!![],'funds_settle_to':'order.owner','rationale':'Order\x20is\x20a\x20shared\x20object\x20and\x20extraction\x20has\x20no\x20signer\x20gate;\x20'+'Receiving\x20is\x20restricted\x20to\x20objects\x20actually\x20delivered\x20to\x20that\x20order,\x20and\x20coins\x20settle\x20to\x20its\x20owner.'},{'object_type':'permission','receive_entries':['owner-side\x20coin\x20extraction\x20via\x20the\x20permission\x20object','owner-side\x20object\x20extraction\x20via\x20the\x20permission\x20object'],'anyone_drivable':!![],'funds_settle_to':'permission.owner','rationale':'Permission\x20is\x20the\x20final\x20authority;\x20anyone\x20can\x20drive\x20extraction\x20of\x20funds\x20sent\x20to\x20its\x20address,\x20but\x20the\x20destination\x20is\x20its\x20owner.'},{'object_type':'service','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20service','owner-side\x20object\x20extraction\x20from\x20the\x20service'],'anyone_drivable':![],'permission_index':0x13f,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20319);\x20members\x20drive,\x20value\x20settles\x20to\x20the\x20organization\x20owner.'},{'object_type':'treasury','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20treasury','owner-side\x20object\x20extraction\x20from\x20the\x20treasury'],'anyone_drivable':![],'permission_index':0x101,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20257).'},{'object_type':'arbitration','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20arbitration','owner-side\x20object\x20extraction\x20from\x20the\x20arbitration'],'anyone_drivable':![],'permission_index':0x16f,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20367).'},{'object_type':'machine','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20machine','owner-side\x20object\x20extraction\x20from\x20the\x20machine'],'anyone_drivable':![],'permission_index':0xcf,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20207).'},{'object_type':'progress','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20progress','owner-side\x20object\x20extraction\x20from\x20the\x20progress'],'anyone_drivable':![],'permission_index':0xe1,'funds_settle_to':'machine\x27s\x20permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20225),\x20scoped\x20to\x20the\x20Machine\x20permission.'},{'object_type':'demand','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20demand','owner-side\x20object\x20extraction\x20from\x20the\x20demand'],'anyone_drivable':![],'permission_index':0x197,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20407).'},{'object_type':'contact','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20contact','owner-side\x20object\x20extraction\x20from\x20the\x20contact'],'anyone_drivable':![],'permission_index':0x1c6,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20454).'}];export function driveabilityOf(a){return OBJECT_DRIVEABILITY['find'](b=>b['object_type']===a);}function rewardRecipientKind(a){if(typeof a==='string'){const e=a['toLowerCase']();if(e==='signer')return{'kind':'signer'};return{'kind':'entity'};}if(typeof a!=='object'||a===null)return{'kind':'entity'};const b=a,c=f=>typeof b[f]==='number'?b[f]:undefined,d=c('GuardIdentifier')??c('guard_identifier')??c('identifier');if(d!==undefined)return{'kind':'submission','slot':d};if(b['Signer']!==undefined||b['signer']!==undefined)return{'kind':'signer'};return{'kind':'entity'};}const SLOT_BINDING_CODES=new Set(['service_binding','progress_node_state','signer_is_submitted_object_owner','repository_crosscheck','signer_permission_member']);export function analyzeRewardClaimGuard(a){const {kind:b,slot:c}=rewardRecipientKind(a['recipient']),d={'entry_index':a['entry_index'],'guard':a['guard'],'recipient_kind':b,...c!==undefined?{'recipient_slot':c}:{},'guard_resolved':![],'constraint_codes':[],'recipient_slot_usages':0x0,'caller_identity_constrained':![],'viability':'unverifiable','reason':'Guard\x20table/root\x20not\x20fetched\x20with\x20the\x20topology\x20—\x20the\x20deciding\x20predicate\x20is\x20outside\x20the\x20evidence;\x20the\x20owner\x20must\x20disclose\x20the\x20full\x20guard\x20definitions.'},e=asNode(a['guard_def']?.['root']);if(!e)return d;const f=a['guard_def']?.['table']??[],g=extractConstraints(e,f);d['guard_resolved']=!![],d['constraint_codes']=g['map'](k=>k['code']),d['caller_identity_constrained']=g['some'](k=>k['caller_constraint']);if(b==='entity')return d['viability']='blocked',d['reason']='Payout\x20address\x20is\x20fixed\x20at\x20guard\x20registration\x20(Entity\x20recipient);\x20the\x20claim\x20path\x20cannot\x20redirect\x20it.',d;if(b==='signer')return d['caller_identity_constrained']?(d['viability']='blocked',d['reason']='Recipient\x20is\x20the\x20caller\x20(Signer)\x20but\x20the\x20guard\x20binds\x20the\x20caller\x20identity\x20—\x20only\x20the\x20authorized\x20party\x20can\x20claim.'):(d['viability']='viable',d['reason']='Recipient\x20is\x20the\x20caller\x20(Signer)\x20with\x20no\x20identity\x20binding\x20—\x20anyone\x20satisfying\x20the\x20remaining\x20conditions\x20claims\x20to\x20their\x20own\x20address.'),d;const h=c??-0x1,i=collectSlotUsages(e)['filter'](k=>k['slot']===h);d['recipient_slot_usages']=i['length'];const j=g['filter'](k=>k['slot']===h&&SLOT_BINDING_CODES['has'](k['code']));if(j['length']>0x0)d['viability']='blocked',d['reason']='Submitted\x20address\x20is\x20constrained\x20inside\x20the\x20guard\x20('+j['map'](k=>k['code'])['join'](',\x20')+')\x20—\x20a\x20passerby\x20cannot\x20fill\x20the\x20slot\x20with\x20an\x20arbitrary\x20address.';else i['length']>0x0?(d['viability']='conditional',d['reason']='The\x20guard\x20reads\x20the\x20submitted\x20slot\x20('+i['length']+'\x20query\x20usage(s))\x20but\x20no\x20recognized\x20scope/equality\x20constraint\x20was\x20matched\x20—\x20manual\x20predicate\x20review\x20required.'):(d['viability']='viable',d['reason']='No\x20guard\x20query\x20consumes\x20the\x20submitted\x20slot\x20—\x20the\x20predicate\x20cannot\x20constrain\x20the\x20payout\x20address;\x20any\x20passing\x20party\x20claims\x20to\x20their\x20own\x20address.');return d;}
1
+ import{ValueType}from'@wowok/wowok';import{getGuardQueryByIdOrName}from'../schema/utils/guard-query-utils.js';function asNode(a){if(typeof a!=='object'||a===null)return null;const b=a['type'];return typeof b==='string'?a:null;}function queryMeta(a){if(typeof a!=='number'&&typeof a!=='string')return null;const b=getGuardQueryByIdOrName(a);return b?{'id':b['id'],'name':b['name']}:null;}function childNodes(a){const b=[];if(Array['isArray'](a['nodes']))a['nodes']['forEach'](d=>{const e=asNode(d);if(e)b['push'](e);});if(asNode(a['node']))b['push'](asNode(a['node']));return[a['nodeLeft'],a['nodeRight']]['forEach'](d=>{const e=asNode(d);if(e)b['push'](e);}),b;}export function classifyRecipient(a){if(typeof a!=='object'||a===null)return null;const b=a;if(typeof b['Entity']==='string')return{'kind':'entity','address':b['Entity']};const c=b['Entity'];if(c&&typeof c==='object'&&typeof c['name_or_address']==='string')return{'kind':'entity','address':c['name_or_address']};if(b['Signer']==='signer'||b['Signer']===!![])return{'kind':'signer'};if(typeof b['GuardIdentifier']==='number')return{'kind':'submission','identifier':b['GuardIdentifier']};return null;}export function classifyDualPayoutTrack(a,b){let c=[];if(Array['isArray'](a))c=a;else{if(a&&typeof a==='object'){const f=a['allocators'];if(Array['isArray'](f))c=f;}}const d=[];for(const h of c){if(b){const j=h?.['guard'];if(typeof j!=='string'||j['toLowerCase']()!==b['toLowerCase']())continue;}const i=h?.['sharing'];if(Array['isArray'](i))d['push'](...i);}if(d['length']===0x0)return{'track':'unknown'};const e=[];for(const k of d){const l=k?.['who'],m=classifyRecipient(typeof l==='string'?l==='Signer'?{'Signer':!![]}:{'Entity':l}:l);if(!m||m['kind']==='signer')return{'track':'unknown'};if(m['kind']==='submission')return{'track':'order-directed'};e['push'](m['address']);}return{'track':'entity-directed','recipients':e};}function leafInfo(a,b){if(a['type']==='context'&&typeof a['context']==='string'){if(a['context']==='Signer')return{'kind':'signer'};if(a['context']==='Clock')return{'kind':'clock'};}if(a['type']==='query'){const c=queryMeta(a['query']),d=a['object'];if(c&&d&&typeof d['identifier']==='number')return{'kind':'query','query_name':c['name'],'query_id':c['id'],'object_identifier':d['identifier'],'convert_witness':d['convert_witness']};}if(a['type']==='identifier'){const e=typeof a['identifier']==='number'?a['identifier']:-0x1,f=b['find'](g=>g['identifier']===e);if(f){const g=typeof f['value']==='string'?f['value']:undefined,h=normalizeValueType(f['value_type']);if(h===ValueType['Address'])return{'kind':'static_address','value':g};if(h===ValueType['String'])return{'kind':'static_string','value':g};}}return{'kind':'other'};}function comparisonLeaves(a,b){if(a['type']==='logic_equal'){const c=childNodes(a)['map'](d=>flattenLeaf(d,b));return c;}return[];}function flattenLeaf(a,b){if(a['type']==='logic_not'){const d=childNodes(a)[0x0];return d?flattenLeaf(d,b):{'kind':'other'};}return leafInfo(a,b);}function isOrderProgressWitness(a){if(a===0x64)return!![];return typeof a==='string'&&a['toLowerCase']()['includes']('orderprogress');}function describe(a){switch(a){case'service_binding':return'Submitted\x20object\x20must\x20belong\x20to\x20the\x20expected\x20service';case'progress_node_state':return'Submitted\x20order\x20must\x20be\x20at\x20a\x20qualifying\x20workflow\x20node';case'signer_is_submitted_object_owner':return'Caller\x20must\x20be\x20the\x20owner\x20of\x20the\x20submitted\x20object';case'signer_authorized_entity':return'Caller\x20must\x20equal\x20a\x20fixed\x20authorized\x20address';case'signer_permission_member':return'Caller\x20must\x20satisfy\x20a\x20Permission\x20membership\x20rule';case'time_lock':return'Current\x20time\x20must\x20satisfy\x20the\x20time-lock';case'repository_crosscheck':return'Repository\x20data\x20must\x20satisfy\x20the\x20cross-check';default:return'Other\x20guard\x20constraint';}}function extractConstraints(a,b){const c=[],d=new Set(),e=h=>{const i=h['code']+':'+(h['slot']??'-');!d['has'](i)&&(d['add'](i),c['push'](h));},f=(h,i)=>({'path':h,'queries':i}),g=(h,i)=>{const j=comparisonLeaves(h,b);if(j['length']>=0x2){const k=j['find'](r=>r['kind']==='signer'),l=j['find'](r=>r['kind']==='query'&&r['query_name']==='order.owner'),m=j['find'](r=>r['kind']==='query'&&r['query_name']==='order.service'),n=j['find'](r=>r['kind']==='query'&&r['query_name']==='progress.current'),o=j['find'](r=>r['kind']==='static_address'),p=j['find'](r=>r['kind']==='static_string');k&&l&&e({'code':'signer_is_submitted_object_owner','slot':l['object_identifier'],'description':describe('signer_is_submitted_object_owner'),'caller_constraint':!![],'evidence':f(i,['Signer','order.owner'])});k&&o&&e({'code':'signer_authorized_entity','description':describe('signer_authorized_entity'),'caller_constraint':!![],'evidence':f(i,['Signer'])});m&&o&&e({'code':'service_binding','slot':m['object_identifier'],'description':describe('service_binding'),'caller_constraint':![],'evidence':f(i,['order.service'])});if(n&&p){const r=n['object_identifier'];isOrderProgressWitness(n['convert_witness'])&&e({'code':'progress_node_state','slot':r,'description':describe('progress_node_state'),'caller_constraint':![],'evidence':f(i,['progress.current'])});}}if(h['type']['startsWith']('logic_as_u256')||h['type']==='calc_number_add'){const s=[h,...childNodes(h)]['map'](t=>flattenLeaf(t,b));if(s['some'](t=>t['kind']==='clock')&&s['some'](t=>t['kind']==='query'&&(t['query_name']==='progress.current_time'||t['query_name']==='progress.session.forward.time'))){const t=s['find'](u=>u['kind']==='query');e({'code':'time_lock','slot':t['object_identifier'],'description':describe('time_lock'),'caller_constraint':![],'evidence':f(i,['Clock',t['query_name']])});}}if(h['type']==='query'){const u=queryMeta(h['query']);if(u&&u['name']['startsWith']('repository.')){const v=h['object'];e({'code':'repository_crosscheck','slot':v?.['identifier'],'description':describe('repository_crosscheck'),'caller_constraint':![],'evidence':f(i,[u['name']])});}}childNodes(h)['forEach']((w,x)=>g(w,i+'/'+x));};return g(a,'/root'),c;}function findSessionQueries(a){const b=[],c=(d,e)=>{if(d['type']==='query'){const f=queryMeta(d['query']);if(f&&(f['id']===0x4f6||f['id']===0x4f7))b['push'](e);}childNodes(d)['forEach']((g,h)=>c(g,e+'/'+h));};return c(a,'/root'),b;}function collectSlotUsages(a){const b=[],c=(d,e)=>{if(d['type']==='query'){const f=queryMeta(d['query']),g=d['object'];f&&g&&typeof g['identifier']==='number'&&b['push']({'slot':g['identifier'],'path':e,'query_id':f['id'],'query_name':f['name'],...g['convert_witness']!==undefined?{'convert_witness':g['convert_witness']}:{}});}childNodes(d)['forEach']((h,j)=>c(h,e+'/'+j));};return c(a,'/root'),b;}function deriveReceiptRight(a,b){const c=b['find'](e=>e['code']==='progress_node_state'&&e['slot']===a),d=b['find'](e=>e['code']==='signer_is_submitted_object_owner'&&e['slot']===a);if(c||d)return{'object_type':'order','receive_entry':'owner-side\x20extraction\x20on\x20the\x20order','guarantee':'Delivered\x20funds\x20are\x20owned\x20by\x20the\x20submitted\x20Order;\x20only\x20its\x20current\x20owner\x20can\x20'+'extract\x20them\x20(&mut\x20Order\x20input),\x20and\x20coins\x20transfer\x20to\x20that\x20owner.'};return undefined;}function deriveBeneficialOwner(a,b){switch(a['kind']){case'entity':return'Fixed\x20entity\x20'+a['address'];case'signer':return'Transaction\x20caller\x20(Signer)\x20—\x20direct\x20wallet';case'submission':return b?'Owner\x20of\x20the\x20submitted\x20object\x20at\x20table['+a['identifier']+']\x20(object\x20receipt\x20=\x20owner\x20receipt)':'Address\x20submitted\x20at\x20table['+a['identifier']+']\x20(caller-provided)';}}function buildSlotModels(a,b,c,d){const e=[...new Set(c['map'](f=>f['spec'])['filter'](f=>f['kind']==='submission')['map'](f=>f['identifier']))];return e['map'](f=>{const g=a['find'](p=>p['identifier']===f),h=g?normalizeValueType(g['value_type']):undefined,i=h===ValueType['Address'],j=b['filter'](p=>p['slot']===f),k=c['filter'](p=>p['spec']['kind']==='submission'&&p['spec']['identifier']===f)['map'](p=>p['mode']??'Unknown'),l=d['filter'](p=>p['slot']===undefined||p['slot']===f),m=deriveReceiptRight(f,d),n=l['some'](p=>p['code']==='service_binding'||p['code']==='repository_crosscheck'||p['code']==='signer_permission_member'),o=[];if(h!==undefined&&!i)o['push']('RC-FIND-07');if(!n)o['push']('RC-FIND-02');if(m?.['object_type']==='order')o['push']('RC-FIND-03');return{'identifier':f,'externally_submitted':g?.['b_submission']??!![],...h!==undefined?{'declared_value_type':h}:{},'is_address':i,'usages':j,'recipient_modes':k,'constraints':l,...m?{'receipt':m}:{},'beneficial_owner':deriveBeneficialOwner({'kind':'submission','identifier':f},m),'assessment':{'address_typed':i,'scope_bound':n,'object_receipt':m?.['object_type']==='order'},'findings':o};});}function buildSlotFinding(a,b,c){const d=a['identifier'];switch(b){case'RC-FIND-07':return{'code':b,'severity':'medium','title':'Submission\x20slot\x20'+d+'\x20is\x20not\x20address-typed','explanation':'GuardIdentifier\x20recipients\x20require\x20an\x20address-typed\x20table\x20entry\x20'+'(enforced\x20at\x20allocator\x20registration\x20/\x20ERECIPIENT_IDENTIFIER_NOT_ADDRESS).','evidence_paths':c,'mitigation':'Set\x20the\x20slot\x20value_type\x20to\x20Address,\x20or\x20use\x20an\x20Entity\x20recipient.','unavoidable':![]};case'RC-FIND-02':return{'code':b,'severity':'high','title':'Submission\x20slot\x20'+d+'\x20has\x20no\x20scope\x20binding','explanation':'Nothing\x20constrains\x20which\x20submitted\x20objects/addresses\x20qualify:\x20no\x20'+'service\x20binding,\x20repository\x20cross-check\x20or\x20permission\x20membership.\x20A\x20caller\x20'+'can\x20submit\x20arbitrary\x20qualifying-by-other-conditions\x20inputs.','evidence_paths':c,'mitigation':'Add\x20a\x20constraint\x20binding\x20the\x20slot\x20(e.g.\x20order.service\x20==\x20host\x20service).','unavoidable':![]};case'RC-FIND-03':return{'code':b,'severity':'medium','title':'Cross-allocation\x20settlement\x20residual','explanation':'The\x20submitted\x20order\x20is\x20not\x20bound\x20to\x20the\x20Allocation\x20being\x20settled\x20'+'(alloc\x20is\x20permissionless\x20and\x20allocation\x20context\x20is\x20not\x20a\x20Guard\x20input).\x20A\x20'+'caller\x20owning\x20ANY\x20qualifying\x20order\x20can\x20settle\x20OTHER\x20allocations;\x20funds\x20land\x20'+'at\x20the\x20submitted\x20order\x20and\x20are\x20receivable\x20by\x20its\x20owner.\x20Destination\x20is\x20safe\x20'+'(an\x20order\x20owner),\x20allocation\x20choice\x20is\x20the\x20residual.','evidence_paths':c,'mitigation':'Pick\x20ONE\x20resolution\x20and\x20record\x20it\x20in\x20the\x20service\x20description:\x20'+'(1)\x20competition\x20semantics\x20—\x20declare\x20that\x20any\x20qualifying\x20order\x20may\x20settle\x20'+'this\x20allocation\x20and\x20cap\x20the\x20exposure\x20(sharing\x20threshold\x20/\x20max\x20amount);\x20'+'(2)\x20Entity\x20routing\x20—\x20use\x20a\x20fixed\x20Entity\x20(treasury)\x20recipient,\x20the\x20only\x20'+'exclusive\x20choice\x20on\x20the\x20automatic\x20order_allocators\x20route\x20(trust\x20shifts\x20to\x20'+'the\x20entity\x20operator);\x20'+'(3)\x20per-order\x20pinned\x20Guards\x20—\x20abandon\x20automatic\x20order_allocators\x20and\x20attach\x20'+'a\x20per-order\x20Guard\x20pinning\x20the\x20order\x20id\x20(order.owner\x20==\x20constant),\x20the\x20'+'trustless\x20exclusive\x20route.','unavoidable':!![],'resolution_required':!![]};default:return{'code':b,'severity':'low','title':'Slot\x20'+d+'\x20finding\x20'+b,'explanation':'','evidence_paths':c,'mitigation':'','unavoidable':![]};}}function buildFindings(a,b){const c=[];let d=![],e=![];for(const f of b){const g=f['recipients']['flatMap'](h=>h['constraints'])['filter'](h=>h['caller_constraint']);if(g['length']>0x0)d=!![];if(f['slots']['some'](h=>h['assessment']['scope_bound']))e=!![];for(const h of f['recipients']){const i=h['constraints']['map'](j=>j['evidence']['path']);h['spec']['kind']==='signer'&&g['length']===0x0&&c['push']({'code':'RC-FIND-01','severity':'critical','title':'Signer\x20recipient\x20without\x20caller\x20constraint\x20—\x20fund\x20theft','explanation':'Funds\x20are\x20delivered\x20directly\x20to\x20the\x20transaction\x20caller,\x20but\x20the\x20Guard\x20'+'does\x20not\x20bind\x20the\x20Signer\x20to\x20an\x20authorized\x20identity.\x20Anyone\x20who\x20satisfies\x20the\x20'+'other\x20conditions\x20steals\x20the\x20funds.','evidence_paths':i,'mitigation':'Bind\x20the\x20Signer\x20(signer==order.owner\x20or\x20signer==fixed\x20address),\x20or\x20change\x20'+'the\x20recipient\x20to\x20an\x20Entity\x20/\x20submitted\x20object\x20slot.','unavoidable':![]});}for(const j of f['slots']){const k=j['constraints']['map'](l=>l['evidence']['path']);for(const l of j['findings']){c['push'](buildSlotFinding(j,l,k));}}a['trigger_source']==='service_order_allocators'&&f['recipients']['length']>0x0&&!f['recipients']['some'](m=>m['spec']['kind']==='submission')&&c['push']({'code':'RC-FIND-09','severity':'low','title':'Allocator\x20Guard\x20'+f['guard']+'\x20has\x20no\x20GuardIdentifier\x20sharing\x20row\x20—\x20bound\x20to\x20no\x20particular\x20order','explanation':'Every\x20sharing\x20row\x20is\x20a\x20fixed\x20recipient\x20(Entity/Signer),\x20which\x20resolves\x20no\x20'+'submission.\x20The\x20Guard\x20therefore\x20cannot\x20read\x20the\x20paying\x20order\x20(order.*\x20queries\x20have\x20'+'no\x20binding\x20target),\x20and\x20the\x20allocation\x20pays\x20the\x20same\x20fixed\x20destinations\x20for\x20EVERY\x20order.\x20'+'This\x20is\x20often\x20intended\x20—\x20confirm\x20it\x20is.','evidence_paths':[],'mitigation':'If\x20the\x20Guard\x20should\x20distinguish\x20orders,\x20add\x20a\x20zero-share\x20{GuardIdentifier:\x200}\x20'+'anchor\x20row\x20(Rate\x200)\x20so\x20the\x20Identifier\x20slot\x20resolves\x20to\x20the\x20paying\x20order\x20'+'(pattern.allocator_order_anchor).\x20If\x20fixed-pay\x20is\x20intended,\x20no\x20action.','unavoidable':![]});}a['trigger_source']==='standalone'&&!d&&c['push']({'code':'RC-FIND-04','severity':'high','title':'Standalone\x20allocation\x20without\x20issuer\x20identity\x20constraint','explanation':'Standalone\x20allocations\x20have\x20no\x20Service/Arbitration\x20access-control\x20layer.\x20'+'Without\x20a\x20Signer/permission\x20binding\x20in\x20the\x20Guard,\x20anyone\x20can\x20trigger\x20distribution.','evidence_paths':[],'mitigation':'Bind\x20the\x20issuer\x20(Signer==owner/admin)\x20or\x20move\x20the\x20allocation\x20into\x20a\x20Service.','unavoidable':![]});c['push']({'code':'RC-FIND-06','severity':'low','title':'Permissionless\x20alloc\x20—\x20forced\x20settlement\x20timing','explanation':'Once\x20the\x20Guard\x27s\x20conditions\x20are\x20satisfiable,\x20anyone\x20can\x20trigger\x20settlement\x20of\x20an\x20'+'order\x27s\x20allocation.\x20With\x20Entity/object\x20recipients\x20this\x20affects\x20timing\x20only,\x20not\x20destination.','evidence_paths':[],'mitigation':'Monitor\x20settlements;\x20constrain\x20time-sensitivity\x20via\x20Guard\x20conditions.','unavoidable':!![]});for(const [m,n]of Object['entries'](a['guards']??{})){const o=asNode(n['root']);if(!o)continue;for(const q of findSessionQueries(o)){c['push']({'code':'RC-FIND-05','severity':'medium','title':'Guard\x20'+m+'\x20uses\x20session-only\x20query\x20at\x20'+q,'explanation':'Queries\x201270/1271\x20read\x20the\x20active\x20session;\x20after\x20the\x20session\x20migrates\x20to\x20'+'history\x20the\x20query\x20aborts\x20(W_FIELD_NOT_FOUND)\x20and\x20the\x20Guard\x20permanently\x20fails.','evidence_paths':[q],'mitigation':'Use\x20progress.current_time\x20(1272)\x20or\x20history\x20queries\x20(1274-1280).','unavoidable':![]});}}for(const [s,t]of Object['entries'](a['guards']??{})){const u=(t['relies']??[])['filter'](v=>typeof v==='string'&&v);if(u['length']===0x0)continue;c['push']({'code':'RC-FIND-08','severity':'low','title':'Guard\x20'+s+'\x20relies\x20on\x20'+u['length']+'\x20sub-guard(s)\x20—\x20not\x20credited\x20by\x20this\x20audit','explanation':'Guard\x20composition\x20(relies,\x20one\x20level,\x20≤4,\x20'+((t['relies_logic_and']===![]?'OR':'AND')+'-logic)\x20may\x20carry\x20the\x20scope/signer\x20')+'constraints\x20in\x20the\x20relied\x20sub-guards.\x20This\x20audit\x20evaluates\x20only\x20the\x20guard\x27s\x20own\x20root:\x20'+'sub-guard\x20constraints\x20are\x20NOT\x20credited,\x20so\x20scope-binding\x20gaps\x20(RC-FIND-02)\x20may\x20be\x20'+'over-reported\x20and\x20sub-guard-only\x20conditions\x20stay\x20unverified.','evidence_paths':u,'mitigation':'Resolve\x20the\x20relied\x20sub-guards\x20and\x20verify\x20their\x20constraints\x20manually,\x20or\x20re-run\x20'+'with\x20the\x20sub-guard\x20defs\x20included\x20(read-side\x20resolvers\x20attach\x20them\x20automatically).','unavoidable':![]});}if(!e&&a['trigger_source']==='service_order_allocators'){}return c;}function buildPayoff(a,b){const c=a['recipients']['some'](h=>h['constraints']['some'](i=>i['caller_constraint'])),d=c?'Caller\x20must\x20satisfy\x20the\x20Guard\x27s\x20Signer/identity\x20binding':b==='standalone'?'Any\x20caller\x20(no\x20identity\x20binding)':'Any\x20caller\x20who\x20satisfies\x20the\x20Guard\x27s\x20object/state\x20conditions',e=a['recipients']['map'](h=>h['beneficial_owner'])['join'](';\x20')||'(none)',f={},g=a['recipients']['some'](h=>h['spec']['kind']==='signer'&&!c);return f['caller']=g?'gains':c?'conditional':'neutral',f['provider']=a['recipients']['some'](h=>h['spec']['kind']==='entity')?'gains':'conditional',f['customer']=a['recipients']['some'](h=>h['receipt']?.['object_type']==='order')?'conditional':'neutral',f['system']='neutral',{'caller_eligibility':d,'beneficial_recipient':e,'positions':f};}export const RECIPIENT_CONSTRAINT_VERSION='1.2.0';export function analyzeRecipientConstraints(a){const b=a['allocators']['map'](h=>{const i=a['guards']?.[h['guard']],j=asNode(i?.['root']),k=i?.['table']??[],l=j?extractConstraints(j,k):[],m=j?collectSlotUsages(j):[],n=h['sharing']['map'](q=>{const r=classifyRecipient(q['who']);if(!r)return{'spec':{'kind':'entity','address':'(unclassifiable)'},'constraints':l,'beneficial_owner':'Unclassifiable\x20recipient\x20—\x20check\x20allocator\x20config'};const t=r['kind']==='submission'?r['identifier']:undefined,u=t!==undefined?k['find'](w=>w['identifier']===t):undefined,v=t!==undefined?deriveReceiptRight(t,l):undefined;return{'spec':r,'slot_value_type':u?normalizeValueType(u['value_type']):undefined,'constraints':t!==undefined?l['filter'](w=>w['slot']===undefined||w['slot']===t):l,'receipt':v,'beneficial_owner':deriveBeneficialOwner(r,v)};}),o=buildSlotModels(k,m,h['sharing']['map'](q=>({'spec':classifyRecipient(q['who'])??{'kind':'entity','address':'(unclassifiable)'},'mode':q['mode']})),l),p={'guard':h['guard'],'recipients':n,'slots':o,'payoff':{'caller_eligibility':'','beneficial_recipient':'','positions':{}}};return p['payoff']=buildPayoff(p,a['trigger_source']),p;}),c=buildFindings(a,b),d=c['some'](h=>h['severity']==='critical')?'critical':c['some'](h=>h['severity']==='high')?'high':c['some'](h=>h['severity']==='medium')?'medium':'low',e=!c['some'](h=>h['code']==='RC-FIND-01'),f=c['some'](h=>h['resolution_required']),g=[{'code':'RC-FIND-03','title':'Cross-allocation\x20settlement','detail':'Submitted\x20order\x20is\x20not\x20bound\x20to\x20the\x20settled\x20allocation;\x20destination\x20stays\x20at\x20an\x20order\x20owner.'},{'code':'RC-FIND-06','title':'Forced\x20settlement\x20timing','detail':'alloc\x20is\x20permissionless;\x20settlement\x20can\x20be\x20triggered\x20by\x20anyone\x20once\x20conditions\x20hold.'},{'code':'RC-RES-01','title':'Published\x20immutability','detail':'order_allocators,\x20Machine\x20and\x20Guards\x20are\x20immutable\x20after\x20publish.'},{'code':'RC-RES-03','title':'Off-chain\x20arbitration\x20backstop','detail':'No\x20on-chain\x20clawback;\x20post-incident\x20recovery\x20relies\x20on\x20arbitration.'}];return{'version':RECIPIENT_CONSTRAINT_VERSION,'scope':{'trigger_source':a['trigger_source'],'host_service':a['host_service'],'allocation':a['allocation']},'allocators':b,'findings':c,'unavoidable':g,'safe_destination':e,'resolution_required':f,'overall':d,'summary':'Analyzed\x20'+b['length']+'\x20allocator(s):\x20'+c['filter'](h=>!h['unavoidable'])['length']+'\x20actionable,\x20'+(c['filter'](h=>h['unavoidable'])['length']+'\x20structural\x20finding(s).\x20Safe\x20destination:\x20'+e+'.')+(''+(f?'\x20Resolution\x20REQUIRED:\x20at\x20least\x20one\x20residual\x20demands\x20an\x20explicit\x20design\x20decision\x20before\x20publish.':''))};}export function derivePayoffFromSharing(a,b,c){const d=asNode(c?.['root']),e=c?.['table']??[],f=d?extractConstraints(d,e):[],g=a['map'](i=>{const j=classifyRecipient(i['who'])??{'kind':'entity','address':'(unclassifiable)'},k=j['kind']==='submission'?j['identifier']:undefined,l=k!==undefined?e['find'](n=>n['identifier']===k):undefined,m=k!==undefined?deriveReceiptRight(k,f):undefined;return{'spec':j,'slot_value_type':l?normalizeValueType(l['value_type']):undefined,'constraints':k!==undefined?f['filter'](n=>n['slot']===undefined||n['slot']===k):f,'receipt':m,'beneficial_owner':deriveBeneficialOwner(j,m)};}),h={'guard':'','recipients':g,'slots':[],'payoff':{'caller_eligibility':'','beneficial_recipient':'','positions':{}}};return buildPayoff(h,b);}function normalizeValueType(a){if(typeof a==='number')return a;const b={'bool':ValueType['Bool'],'address':ValueType['Address'],'string':ValueType['String'],'u64':ValueType['U64'],'u256':ValueType['U256']};return b[a['toLowerCase']()];}export function isUnboundSignerTheft(a){return a['recipient_is_signer']&&!a['caller_identity_constrained'];}export function canonicalDoctrine(a){switch(a){case'RC-FIND-01':return{'severity':'critical','title':'Signer\x20recipient\x20without\x20caller\x20constraint\x20—\x20fund\x20theft','mitigation':'Bind\x20the\x20Signer\x20(signer==order.owner\x20or\x20signer==fixed\x20address),\x20or\x20change\x20'+'the\x20recipient\x20to\x20an\x20Entity\x20/\x20submitted\x20object\x20slot.'};case'RC-FIND-03':return{'severity':'medium','title':'Cross-allocation\x20settlement\x20residual','mitigation':'Pick\x20ONE\x20resolution\x20and\x20record\x20it\x20in\x20the\x20service\x20description:\x20'+'(1)\x20competition\x20semantics\x20with\x20capped\x20exposure\x20(threshold\x20/\x20max\x20amount);\x20'+'(2)\x20Entity\x20routing\x20(treasury)\x20—\x20the\x20only\x20exclusive\x20choice\x20on\x20the\x20automatic\x20'+'order_allocators\x20route;\x20'+'(3)\x20per-order\x20pinned\x20Guards\x20(order.owner\x20==\x20constant)\x20—\x20the\x20trustless\x20'+'exclusive\x20route.','resolution_required':!![]};case'RC-FIND-06':return{'severity':'low','title':'Permissionless\x20alloc\x20—\x20forced\x20settlement\x20timing','mitigation':'Monitor\x20settlements;\x20constrain\x20time-sensitivity\x20via\x20Guard\x20conditions.'};}}export const RECIPIENT_DESIGN_OPTIONS=[{'id':'entity','move_recipient':'Recipient::Entity(address)','semantics':'Funds\x20flow\x20to\x20a\x20fixed\x20address\x20(a\x20constrained\x20user\x20account\x20/\x20treasury).\x20'+'Destination\x20never\x20depends\x20on\x20the\x20caller.','required_constraints':['The\x20address\x20is\x20chosen\x20at\x20design\x20time\x20and\x20recorded\x20in\x20the\x20allocator\x20table.']},{'id':'submitted_object','move_recipient':'Recipient::GuardIdentifier(u8)','semantics':'Funds\x20flow\x20to\x20the\x20object\x20submitted\x20under\x20protocol\x20context\x20(e.g.\x20the\x20order\x20being\x20settled).\x20'+'Receivable\x20only\x20by\x20that\x20object\x27s\x20owner\x20—\x20object\x20receipt\x20=\x20owner\x20receipt.','required_constraints':['The\x20Guard\x20binds\x20the\x20submission\x27s\x20scope\x20(which\x20query/object\x20type\x20the\x20slot\x20carries).','The\x20slot\x27s\x20table\x20value\x20type\x20is\x20address\x20(enforced\x20at\x20allocator\x20registration).'],'finding_if_unmet':'RC-FIND-02\x20/\x20RC-FIND-07'},{'id':'signer','move_recipient':'Recipient::Signer','semantics':'Funds\x20flow\x20to\x20the\x20caller\x20who\x20executes\x20the\x20permissionless\x20alloc.\x20'+'Safe\x20only\x20when\x20the\x20Guard\x20proves\x20exactly\x20who\x20the\x20caller\x20may\x20be.','required_constraints':['The\x20Guard\x20constrains\x20the\x20Signer\x20identity\x20(signer\x20==\x20a\x20fixed\x20address\x20or\x20a\x20derived\x20legitimate\x20owner).'],'finding_if_unmet':'RC-FIND-01'},{'id':'constrained_submission','move_recipient':'Recipient::GuardIdentifier(u8)','semantics':'Funds\x20flow\x20to\x20an\x20object\x20address\x20supplied\x20by\x20the\x20signer,\x20but\x20the\x20Guard\x20constrains\x20'+'both\x20the\x20submission\x20scope\x20and\x20the\x20signer\x27s\x20relation\x20to\x20it\x20(e.g.\x20the\x20signer\x20owns\x20the\x20submitted\x20order).','required_constraints':['The\x20Guard\x20binds\x20the\x20submission\x27s\x20scope\x20(object/query\x20type).','The\x20Guard\x20binds\x20the\x20signer\x20to\x20the\x20submitted\x20object.','The\x20slot\x27s\x20table\x20value\x20type\x20is\x20address\x20(enforced\x20at\x20allocator\x20registration).'],'finding_if_unmet':'RC-FIND-01\x20/\x20RC-FIND-02\x20/\x20RC-FIND-07'}];export function recipientDesignGuidance(){return RECIPIENT_DESIGN_OPTIONS;}export const OBJECT_DRIVEABILITY=[{'object_type':'order','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20order','owner-side\x20object\x20extraction\x20from\x20the\x20order'],'anyone_drivable':!![],'funds_settle_to':'order.owner','rationale':'Order\x20is\x20a\x20shared\x20object\x20and\x20extraction\x20has\x20no\x20signer\x20gate;\x20'+'Receiving\x20is\x20restricted\x20to\x20objects\x20actually\x20delivered\x20to\x20that\x20order,\x20and\x20coins\x20settle\x20to\x20its\x20owner.'},{'object_type':'permission','receive_entries':['owner-side\x20coin\x20extraction\x20via\x20the\x20permission\x20object','owner-side\x20object\x20extraction\x20via\x20the\x20permission\x20object'],'anyone_drivable':!![],'funds_settle_to':'permission.owner','rationale':'Permission\x20is\x20the\x20final\x20authority;\x20anyone\x20can\x20drive\x20extraction\x20of\x20funds\x20sent\x20to\x20its\x20address,\x20but\x20the\x20destination\x20is\x20its\x20owner.'},{'object_type':'service','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20service','owner-side\x20object\x20extraction\x20from\x20the\x20service'],'anyone_drivable':![],'permission_index':0x13f,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20319);\x20members\x20drive,\x20value\x20settles\x20to\x20the\x20organization\x20owner.'},{'object_type':'treasury','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20treasury','owner-side\x20object\x20extraction\x20from\x20the\x20treasury'],'anyone_drivable':![],'permission_index':0x101,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20257).'},{'object_type':'arbitration','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20arbitration','owner-side\x20object\x20extraction\x20from\x20the\x20arbitration'],'anyone_drivable':![],'permission_index':0x16f,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20367).'},{'object_type':'machine','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20machine','owner-side\x20object\x20extraction\x20from\x20the\x20machine'],'anyone_drivable':![],'permission_index':0xcf,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20207).'},{'object_type':'progress','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20progress','owner-side\x20object\x20extraction\x20from\x20the\x20progress'],'anyone_drivable':![],'permission_index':0xe1,'funds_settle_to':'machine\x27s\x20permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20225),\x20scoped\x20to\x20the\x20Machine\x20permission.'},{'object_type':'demand','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20demand','owner-side\x20object\x20extraction\x20from\x20the\x20demand'],'anyone_drivable':![],'permission_index':0x197,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20407).'},{'object_type':'contact','receive_entries':['owner-side\x20coin\x20extraction\x20from\x20the\x20contact','owner-side\x20object\x20extraction\x20from\x20the\x20contact'],'anyone_drivable':![],'permission_index':0x1c6,'funds_settle_to':'permission.owner','rationale':'Business\x20permission\x20gate\x20(index\x20454).'}];export function driveabilityOf(a){return OBJECT_DRIVEABILITY['find'](b=>b['object_type']===a);}function rewardRecipientKind(a){if(typeof a==='string'){const e=a['toLowerCase']();if(e==='signer')return{'kind':'signer'};return{'kind':'entity'};}if(typeof a!=='object'||a===null)return{'kind':'entity'};const b=a,c=f=>typeof b[f]==='number'?b[f]:undefined,d=c('GuardIdentifier')??c('guard_identifier')??c('identifier');if(d!==undefined)return{'kind':'submission','slot':d};if(b['Signer']!==undefined||b['signer']!==undefined)return{'kind':'signer'};return{'kind':'entity'};}const SLOT_BINDING_CODES=new Set(['service_binding','progress_node_state','signer_is_submitted_object_owner','repository_crosscheck','signer_permission_member']);export function analyzeRewardClaimGuard(a){const {kind:b,slot:c}=rewardRecipientKind(a['recipient']),d={'entry_index':a['entry_index'],'guard':a['guard'],'recipient_kind':b,...c!==undefined?{'recipient_slot':c}:{},'guard_resolved':![],'constraint_codes':[],'recipient_slot_usages':0x0,'caller_identity_constrained':![],'viability':'unverifiable','reason':'Guard\x20table/root\x20not\x20fetched\x20with\x20the\x20topology\x20—\x20the\x20deciding\x20predicate\x20is\x20outside\x20the\x20evidence;\x20the\x20owner\x20must\x20disclose\x20the\x20full\x20guard\x20definitions.'},e=asNode(a['guard_def']?.['root']);if(!e)return d;const f=a['guard_def']?.['table']??[],g=extractConstraints(e,f);d['guard_resolved']=!![],d['constraint_codes']=g['map'](k=>k['code']),d['caller_identity_constrained']=g['some'](k=>k['caller_constraint']);if(b==='entity')return d['viability']='blocked',d['reason']='Payout\x20address\x20is\x20fixed\x20at\x20guard\x20registration\x20(Entity\x20recipient);\x20the\x20claim\x20path\x20cannot\x20redirect\x20it.',d;if(b==='signer')return d['caller_identity_constrained']?(d['viability']='blocked',d['reason']='Recipient\x20is\x20the\x20caller\x20(Signer)\x20but\x20the\x20guard\x20binds\x20the\x20caller\x20identity\x20—\x20only\x20the\x20authorized\x20party\x20can\x20claim.'):(d['viability']='viable',d['reason']='Recipient\x20is\x20the\x20caller\x20(Signer)\x20with\x20no\x20identity\x20binding\x20—\x20anyone\x20satisfying\x20the\x20remaining\x20conditions\x20claims\x20to\x20their\x20own\x20address.'),d;const h=c??-0x1,i=collectSlotUsages(e)['filter'](k=>k['slot']===h);d['recipient_slot_usages']=i['length'];const j=g['filter'](k=>k['slot']===h&&SLOT_BINDING_CODES['has'](k['code']));if(j['length']>0x0)d['viability']='blocked',d['reason']='Submitted\x20address\x20is\x20constrained\x20inside\x20the\x20guard\x20('+j['map'](k=>k['code'])['join'](',\x20')+')\x20—\x20a\x20passerby\x20cannot\x20fill\x20the\x20slot\x20with\x20an\x20arbitrary\x20address.';else i['length']>0x0?(d['viability']='conditional',d['reason']='The\x20guard\x20reads\x20the\x20submitted\x20slot\x20('+i['length']+'\x20query\x20usage(s))\x20but\x20no\x20recognized\x20scope/equality\x20constraint\x20was\x20matched\x20—\x20manual\x20predicate\x20review\x20required.'):(d['viability']='viable',d['reason']='No\x20guard\x20query\x20consumes\x20the\x20submitted\x20slot\x20—\x20the\x20predicate\x20cannot\x20constrain\x20the\x20payout\x20address;\x20any\x20passing\x20party\x20claims\x20to\x20their\x20own\x20address.');return d;}
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ import { type DomainPriorMatch, type TraitInferenceResult } from "./industry-generalizer.js";
3
+ import type { IndustryTraits } from "./industry-registry.js";
4
+ export declare const SEMANTIC_IR_SCHEMA_VERSION: 1;
5
+ export declare const TRAIT_KEYS: Array<keyof IndustryTraits>;
6
+ export declare const SEMANTIC_CLAIM_KEYS: readonly ["reward_pool_amount"];
7
+ export type SemanticClaimKey = (typeof SEMANTIC_CLAIM_KEYS)[number];
8
+ export declare const SemanticIRInputSchema: z.ZodObject<{
9
+ schema_version: z.ZodLiteral<1>;
10
+ locale: z.ZodString;
11
+ traits: z.ZodOptional<z.ZodArray<z.ZodObject<{
12
+ trait: z.ZodString;
13
+ value: z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>;
14
+ confidence: z.ZodNumber;
15
+ span: z.ZodOptional<z.ZodObject<{
16
+ start: z.ZodNumber;
17
+ end: z.ZodNumber;
18
+ }, z.core.$strict>>;
19
+ quote: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strict>>>;
21
+ domains: z.ZodOptional<z.ZodArray<z.ZodObject<{
22
+ domain: z.ZodString;
23
+ confidence: z.ZodOptional<z.ZodNumber>;
24
+ span: z.ZodOptional<z.ZodObject<{
25
+ start: z.ZodNumber;
26
+ end: z.ZodNumber;
27
+ }, z.core.$strict>>;
28
+ quote: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$strict>>>;
30
+ claims: z.ZodOptional<z.ZodArray<z.ZodObject<{
31
+ key: z.ZodString;
32
+ value: z.ZodNumber;
33
+ confidence: z.ZodOptional<z.ZodNumber>;
34
+ span: z.ZodOptional<z.ZodObject<{
35
+ start: z.ZodNumber;
36
+ end: z.ZodNumber;
37
+ }, z.core.$strict>>;
38
+ quote: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$strict>>>;
40
+ provenance: z.ZodObject<{
41
+ source: z.ZodEnum<{
42
+ human: "human";
43
+ caller_llm: "caller_llm";
44
+ }>;
45
+ model: z.ZodOptional<z.ZodString>;
46
+ prompt_version: z.ZodOptional<z.ZodString>;
47
+ generated_at: z.ZodOptional<z.ZodNumber>;
48
+ }, z.core.$strict>;
49
+ }, z.core.$strict>;
50
+ export type SemanticIRInput = z.infer<typeof SemanticIRInputSchema>;
51
+ export interface SemanticIRTraitEvidence {
52
+ trait: keyof IndustryTraits;
53
+ value: boolean | string;
54
+ confidence: number;
55
+ span?: {
56
+ start: number;
57
+ end: number;
58
+ };
59
+ quote?: string;
60
+ }
61
+ export interface SemanticIRDomainEvidence {
62
+ domain: string;
63
+ confidence: number;
64
+ span?: {
65
+ start: number;
66
+ end: number;
67
+ };
68
+ quote?: string;
69
+ }
70
+ export interface SemanticIRClaim {
71
+ key: SemanticClaimKey;
72
+ value: number;
73
+ confidence: number;
74
+ span?: {
75
+ start: number;
76
+ end: number;
77
+ };
78
+ quote?: string;
79
+ }
80
+ export interface CanonicalSemanticIR {
81
+ schema_version: typeof SEMANTIC_IR_SCHEMA_VERSION;
82
+ locale: string;
83
+ traits: SemanticIRTraitEvidence[];
84
+ domains: SemanticIRDomainEvidence[];
85
+ claims: SemanticIRClaim[];
86
+ provenance: {
87
+ source: "caller_llm" | "human";
88
+ model?: string;
89
+ prompt_version?: string;
90
+ generated_at?: number;
91
+ };
92
+ }
93
+ export interface NormalizedSemanticIR {
94
+ ir: CanonicalSemanticIR;
95
+ digest: string;
96
+ issues: string[];
97
+ }
98
+ export declare function semanticIrDigest(ir: CanonicalSemanticIR): string;
99
+ export declare function normalizeSemanticIR(raw: unknown): NormalizedSemanticIR;
100
+ export declare function claimNumber(ir: CanonicalSemanticIR, key: SemanticClaimKey): number | undefined;
101
+ export interface SemanticIRConflict {
102
+ trait: string;
103
+ keyword_value: boolean | string;
104
+ keyword_confidence: number;
105
+ ir_value: boolean | string;
106
+ ir_confidence: number;
107
+ }
108
+ export interface MergedTraitInference extends TraitInferenceResult {
109
+ conflicts: SemanticIRConflict[];
110
+ }
111
+ export declare function mergeSemanticIR(base: TraitInferenceResult, ir: CanonicalSemanticIR): MergedTraitInference;
112
+ export declare function domainPriorsFromIR(ir: CanonicalSemanticIR): DomainPriorMatch[];
113
+ export declare function mergeDomainPriors(keywordPriors: DomainPriorMatch[], irPriors: DomainPriorMatch[]): DomainPriorMatch[];
@@ -0,0 +1 @@
1
+ import{createHash}from'node:crypto';import{z}from'zod';import{BOOLEAN_TRAIT_KEYS,DOMAIN_PRIORS,ENUM_TRAIT_SCALES,EVIDENCE_THRESHOLD}from'./industry-generalizer.js';export const SEMANTIC_IR_SCHEMA_VERSION=0x1;export const TRAIT_KEYS=[...BOOLEAN_TRAIT_KEYS,...Object['keys'](ENUM_TRAIT_SCALES)];export const SEMANTIC_CLAIM_KEYS=['reward_pool_amount'];const SpanSchema=z['object']({'start':z['number']()['int']()['nonnegative'](),'end':z['number']()['int']()['nonnegative']()})['strict'](),TraitEvidenceSchema=z['object']({'trait':z['string']()['max'](0x40),'value':z['union']([z['boolean'](),z['string']()['max'](0x20)]),'confidence':z['number'](),'span':SpanSchema['optional'](),'quote':z['string']()['max'](0x12c)['optional']()})['strict'](),DomainEvidenceSchema=z['object']({'domain':z['string']()['max'](0x40),'confidence':z['number']()['optional'](),'span':SpanSchema['optional'](),'quote':z['string']()['max'](0x12c)['optional']()})['strict'](),ClaimEvidenceSchema=z['object']({'key':z['string']()['max'](0x40),'value':z['number'](),'confidence':z['number']()['optional'](),'span':SpanSchema['optional'](),'quote':z['string']()['max'](0x12c)['optional']()})['strict'](),ProvenanceSchema=z['object']({'source':z['enum'](['caller_llm','human']),'model':z['string']()['max'](0x78)['optional'](),'prompt_version':z['string']()['max'](0x3c)['optional'](),'generated_at':z['number']()['int']()['nonnegative']()['optional']()})['strict']();export const SemanticIRInputSchema=z['object']({'schema_version':z['literal'](SEMANTIC_IR_SCHEMA_VERSION),'locale':z['string']()['min'](0x2)['max'](0x23),'traits':z['array'](TraitEvidenceSchema)['max'](0x14)['optional'](),'domains':z['array'](DomainEvidenceSchema)['max'](0xa)['optional'](),'claims':z['array'](ClaimEvidenceSchema)['max'](0xa)['optional'](),'provenance':ProvenanceSchema})['strict']();export function semanticIrDigest(a){return createHash('sha256')['update'](JSON['stringify'](a))['digest']('hex');}function traitOrder(a){return TRAIT_KEYS['indexOf'](a);}export function normalizeSemanticIR(a){const b=SemanticIRInputSchema['safeParse'](a);if(!b['success']){const q=b['error']['issues']['map'](r=>(r['path']['length']>0x0?r['path']['join']('.'):'(root)')+':\x20'+r['message'])['join'](';\x20');throw new Error('semantic_ir\x20rejected:\x20'+q);}const e=[],f=[];for(const r of b['data']['traits']??[]){if(!TRAIT_KEYS['includes'](r['trait'])){e['push']('unknown\x20trait\x20\x27'+r['trait']+'\x27\x20ignored\x20(vocabulary:\x20'+TRAIT_KEYS['join'](',\x20')+')');continue;}const s=r['trait'],t=BOOLEAN_TRAIT_KEYS['includes'](s);if(t){if(typeof r['value']!=='boolean'){e['push']('trait\x20\x27'+s+'\x27\x20is\x20boolean;\x20value\x20\x27'+String(r['value'])+'\x27\x20ignored');continue;}}else{const x=ENUM_TRAIT_SCALES[s];if(!x||typeof r['value']!=='string'||!x['includes'](r['value'])){e['push']('trait\x20\x27'+s+'\x27\x20expects\x20one\x20of\x20['+(x??[])['join'](',\x20')+'];\x20'+('value\x20\x27'+String(r['value'])+'\x27\x20ignored'));continue;}}if(!Number['isFinite'](r['confidence'])){e['push']('trait\x20\x27'+s+'\x27\x20confidence\x20is\x20not\x20finite;\x20evidence\x20ignored');continue;}const u=Math['max'](0x0,Math['min'](0x1,r['confidence']));u!==r['confidence']&&e['push']('trait\x20\x27'+s+'\x27\x20confidence\x20'+r['confidence']+'\x20clamped\x20to\x20'+u);u<EVIDENCE_THRESHOLD&&e['push']('trait\x20\x27'+s+'\x27\x20confidence\x20'+u+'\x20is\x20below\x20the\x20evidence\x20threshold\x20'+(EVIDENCE_THRESHOLD+';\x20recorded\x20but\x20not\x20applied'));let v;r['span']&&(r['span']['end']<r['span']['start']?e['push']('trait\x20\x27'+s+'\x27\x20span\x20has\x20end\x20<\x20start;\x20span\x20dropped'):v={'start':r['span']['start'],'end':r['span']['end']});const w={'trait':s,'value':r['value'],'confidence':u};if(v)w['span']=v;if(r['quote']!==undefined)w['quote']=r['quote'];f['push'](w);}f['sort']((y,A)=>{const B=traitOrder(y['trait'])-traitOrder(A['trait']);if(B!==0x0)return B;if(A['confidence']!==y['confidence'])return A['confidence']-y['confidence'];return JSON['stringify'](y['value'])['localeCompare'](JSON['stringify'](A['value']));});const g=[],h=new Map();for(const y of f){const A=h['get'](y['trait']);if(!A){h['set'](y['trait'],y),g['push'](y);continue;}A['value']!==y['value']&&e['push']('conflicting\x20evidence\x20for\x20\x27'+y['trait']+'\x27:\x20'+('kept\x20\x27'+String(A['value'])+'\x27\x20(confidence\x20'+A['confidence']+')\x20over\x20')+('\x27'+String(y['value'])+'\x27\x20(confidence\x20'+y['confidence']+')'));}const i=[];for(const B of b['data']['domains']??[]){if(!DOMAIN_PRIORS['some'](F=>F['domain']===B['domain'])){e['push']('unknown\x20domain\x20\x27'+B['domain']+'\x27\x20ignored\x20(vocabulary:\x20'+DOMAIN_PRIORS['map'](F=>F['domain'])['join'](',\x20')+')');continue;}const C=B['confidence']??0x1;if(!Number['isFinite'](C)){e['push']('domain\x20\x27'+B['domain']+'\x27\x20confidence\x20is\x20not\x20finite;\x20evidence\x20ignored');continue;}const D=Math['max'](0x0,Math['min'](0x1,C));D!==C&&e['push']('domain\x20\x27'+B['domain']+'\x27\x20confidence\x20'+C+'\x20clamped\x20to\x20'+D);D<EVIDENCE_THRESHOLD&&e['push']('domain\x20\x27'+B['domain']+'\x27\x20confidence\x20'+D+'\x20is\x20below\x20the\x20evidence\x20threshold\x20'+(EVIDENCE_THRESHOLD+';\x20recorded\x20but\x20not\x20applied'));const E={'domain':B['domain'],'confidence':D};if(B['span']&&B['span']['end']>=B['span']['start'])E['span']={'start':B['span']['start'],'end':B['span']['end']};else{if(B['span'])e['push']('domain\x20\x27'+B['domain']+'\x27\x20span\x20has\x20end\x20<\x20start;\x20span\x20dropped');}if(B['quote']!==undefined)E['quote']=B['quote'];i['push'](E);}i['sort']((F,G)=>{if(G['confidence']!==F['confidence'])return G['confidence']-F['confidence'];return F['domain']['localeCompare'](G['domain']);});const j=[],k=new Set();for(const F of i){if(k['has'](F['domain']))continue;k['add'](F['domain']),j['push'](F);}const l=[];for(const G of b['data']['claims']??[]){if(!SEMANTIC_CLAIM_KEYS['includes'](G['key'])){e['push']('unknown\x20claim\x20\x27'+G['key']+'\x27\x20ignored\x20(vocabulary:\x20'+SEMANTIC_CLAIM_KEYS['join'](',\x20')+')');continue;}const H=G['key'];if(!Number['isFinite'](G['value'])){e['push']('claim\x20\x27'+H+'\x27\x20value\x20is\x20not\x20finite;\x20ignored');continue;}if(G['value']<0x0){e['push']('claim\x20\x27'+H+'\x27\x20value\x20'+G['value']+'\x20is\x20negative;\x20ignored');continue;}const I=G['confidence']??0x1;if(!Number['isFinite'](I)){e['push']('claim\x20\x27'+H+'\x27\x20confidence\x20is\x20not\x20finite;\x20claim\x20ignored');continue;}const J=Math['max'](0x0,Math['min'](0x1,I));J!==I&&e['push']('claim\x20\x27'+H+'\x27\x20confidence\x20'+I+'\x20clamped\x20to\x20'+J);J<EVIDENCE_THRESHOLD&&e['push']('claim\x20\x27'+H+'\x27\x20confidence\x20'+J+'\x20is\x20below\x20the\x20evidence\x20threshold\x20'+(EVIDENCE_THRESHOLD+';\x20recorded\x20but\x20not\x20applied'));const K={'key':H,'value':G['value'],'confidence':J};G['span']&&(G['span']['end']<G['span']['start']?e['push']('claim\x20\x27'+H+'\x27\x20span\x20has\x20end\x20<\x20start;\x20span\x20dropped'):K['span']={'start':G['span']['start'],'end':G['span']['end']});if(G['quote']!==undefined)K['quote']=G['quote'];l['push'](K);}l['sort']((L,M)=>{if(L['key']!==M['key'])return L['key']<M['key']?-0x1:0x1;return M['confidence']-L['confidence'];});const m=[],n=new Map();for(const L of l){const M=n['get'](L['key']);if(!M){n['set'](L['key'],L),m['push'](L);continue;}M['value']!==L['value']&&e['push']('conflicting\x20evidence\x20for\x20claim\x20\x27'+L['key']+'\x27:\x20'+('kept\x20'+M['value']+'\x20(confidence\x20'+M['confidence']+')\x20over\x20')+(L['value']+'\x20(confidence\x20'+L['confidence']+')'));}g['length']===0x0&&j['length']===0x0&&m['length']===0x0&&e['push']('semantic_ir\x20carries\x20no\x20usable\x20evidence;\x20keyword\x20inference\x20is\x20the\x20only\x20signal');const o={'source':b['data']['provenance']['source']};if(b['data']['provenance']['model']!==undefined)o['model']=b['data']['provenance']['model'];b['data']['provenance']['prompt_version']!==undefined&&(o['prompt_version']=b['data']['provenance']['prompt_version']);b['data']['provenance']['generated_at']!==undefined&&(o['generated_at']=b['data']['provenance']['generated_at']);const p={'schema_version':SEMANTIC_IR_SCHEMA_VERSION,'locale':b['data']['locale'],'traits':g,'domains':j,'claims':m,'provenance':o};return{'ir':p,'digest':semanticIrDigest(p),'issues':e};}export function claimNumber(a,b){const c=a['claims']['find'](d=>d['key']===b&&d['confidence']>=EVIDENCE_THRESHOLD);return c?.['value'];}export function mergeSemanticIR(a,b){const c={...a['traits']},d={...a['trait_confidence']},e=[];for(const h of b['traits']){if(h['confidence']<EVIDENCE_THRESHOLD)continue;const i=a['trait_confidence'][h['trait']],j=a['traits'][h['trait']];i!==undefined&&j!==h['value']?(e['push']({'trait':h['trait'],'keyword_value':j,'keyword_confidence':i,'ir_value':h['value'],'ir_confidence':h['confidence']}),d[h['trait']]=h['confidence']):d[h['trait']]=Math['max'](i??0x0,h['confidence']),c[h['trait']]=h['value'];}const f=Object['values'](d)['filter'](k=>(k??0x0)>=EVIDENCE_THRESHOLD)['length'],g=Math['min'](0x1,Math['max'](a['confidence'],f/TRAIT_KEYS['length']));return{'traits':c,'confidence':g,'matched_keywords':[...a['matched_keywords']],'trait_confidence':d,'conflicts':e};}export function domainPriorsFromIR(a){const b=[];for(const c of a['domains']){if(c['confidence']<EVIDENCE_THRESHOLD)continue;const e=DOMAIN_PRIORS['find'](f=>f['domain']===c['domain']);if(!e)continue;b['push']({'domain':e['domain'],'matched_keywords':[],'industries':[...e['industries']],'boost':e['boost'],'source':'semantic_ir'});}return b;}export function mergeDomainPriors(a,b){const c=new Map();for(const d of a){c['set'](d['domain'],{...d,'source':d['source']??'keyword'});}for(const e of b){const f=c['get'](e['domain']);if(!f){c['set'](e['domain'],e);continue;}c['set'](e['domain'],{...f,'matched_keywords':[...new Set([...f['matched_keywords'],...e['matched_keywords']])],'industries':[...new Set([...f['industries'],...e['industries']])],'boost':Math['max'](f['boost'],e['boost']),'source':'both'});}return Array['from'](c['values']());}
@@ -58,7 +58,7 @@ export declare const SERVICE_LISTING_REFUND_GATES: {
58
58
  readonly rationale: "A zero-priced listing plus an allocation-free 0-amount order produced stores whose entire economics live outside the chain. Repricing an EXISTING sale down to zero stays legal and is caught at buy time by the zero-total order gate.";
59
59
  };
60
60
  readonly restock: {
61
- readonly rule: "Refund restocking is opt-in per SKU: the merchant marks an ALIVE sale with the restock flag (305), then a refunded order's purchased units can be put back on shelf (305). Two-pass on-chain (validate every line, then apply) — ALL lines restock or NOTHING mutates. Unflagged or delisted lines abort E_RESTOCK_NOT_FLAGGED = 46 / E_SALE_ITEM_NOT_FOUND. Quantities come from the order's purchase rows.";
61
+ readonly rule: "Refund restocking is opt-in per SKU: the merchant marks an ALIVE sale with the restock flag (305), then a refunded order's purchased units can be put back on shelf (305). Two-pass on-chain (validate every line, then apply) — ALL lines restock or NOTHING mutates. Unflagged or delisted lines abort E_RESTOCK_NOT_FLAGGED = 46 / E_SALE_ITEM_NOT_FOUND. Quantities come from the order's purchase rows. ONCE-PER-ORDER: the restock operation stamps the order with a RestockStamp dynamic field and a second call for the same order aborts E_RESTOCK_ALREADY_APPLIED = 49 (a replay would stack the purchased units again, an unbounded +quantity). OWNERSHIP-BOUND: only an order whose service field is THIS service restocks here — a foreign order aborts E_ORDER_SERVICE_NOT_MATCH = 26. The applied state is readable via the public restock_applied flag.";
62
62
  readonly events: "StockRestockedEvent per line (service, order, item, quantity, time).";
63
63
  };
64
64
  readonly dismissal_conclusion: {