@wowok/agent-mcp 3.1.5 → 3.1.6

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 (145) hide show
  1. package/dist/evaluation/arbitration-game.js +1 -1
  2. package/dist/evaluation/builtins/graph-service.js +1 -1
  3. package/dist/graph/onchain/analyze.js +1 -1
  4. package/dist/graph/onchain/analyze.spec.js +1 -1
  5. package/dist/graph/onchain/extract.js +1 -1
  6. package/dist/graph/onchain/facts.d.ts +1 -0
  7. package/dist/graph/onchain/facts.js +1 -1
  8. package/dist/graph/onchain/fixtures.js +1 -1
  9. package/dist/graph/onchain/onchain.spec.js +1 -1
  10. package/dist/graph/onchain/strategy.js +1 -1
  11. package/dist/graph/onchain/strategy.spec.js +1 -1
  12. package/dist/harness/recover.js +1 -1
  13. package/dist/knowledge/alloc-audit-policy.spec.js +1 -1
  14. package/dist/knowledge/allocation-risk.js +1 -1
  15. package/dist/knowledge/arbitration-ledger.js +1 -1
  16. package/dist/knowledge/audit-rules.d.ts +1 -0
  17. package/dist/knowledge/audit-rules.js +1 -1
  18. package/dist/knowledge/baselines/rules/alloc_audit.json +20 -0
  19. package/dist/knowledge/baselines/rules/allocation.json +1 -19
  20. package/dist/knowledge/baselines/rules/arb.json +1 -1
  21. package/dist/knowledge/baselines/rules/guard.json +8 -8
  22. package/dist/knowledge/fund-layer.js +1 -1
  23. package/dist/knowledge/guard-design-patterns.d.ts +2 -1
  24. package/dist/knowledge/guard-design-patterns.js +1 -1
  25. package/dist/knowledge/guard-design-patterns.spec.d.ts +1 -0
  26. package/dist/knowledge/guard-design-patterns.spec.js +1 -0
  27. package/dist/knowledge/guard-lint.d.ts +1 -1
  28. package/dist/knowledge/guard-lint.js +1 -1
  29. package/dist/knowledge/guard-puzzle.js +1 -1
  30. package/dist/knowledge/guard-render.js +1 -1
  31. package/dist/knowledge/guard-risk.js +1 -1
  32. package/dist/knowledge/guard-translation.js +1 -1
  33. package/dist/knowledge/index.js +1 -1
  34. package/dist/knowledge/industry-registry.js +1 -1
  35. package/dist/knowledge/jsonrpc-enum.js +1 -1
  36. package/dist/knowledge/permission-ledger.js +1 -1
  37. package/dist/knowledge/recipient-constraint.js +1 -1
  38. package/dist/knowledge/safety-rules.extract-amount.spec.d.ts +1 -0
  39. package/dist/knowledge/safety-rules.extract-amount.spec.js +1 -0
  40. package/dist/knowledge/safety-rules.js +1 -1
  41. package/dist/knowledge/service-ledger.js +1 -1
  42. package/dist/knowledge/template-registry.js +1 -1
  43. package/dist/knowledge/template-scanner.js +1 -1
  44. package/dist/knowledge/tool-constraints.js +1 -1
  45. package/dist/knowledge/workflow-guidance.js +1 -1
  46. package/dist/monitor/MonitorLoop.js +1 -1
  47. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  48. package/dist/playbooks/service-build/pipeline-actions.d.ts +1 -1
  49. package/dist/playbooks/service-build/pipeline-actions.js +1 -1
  50. package/dist/playbooks/service-build/risk-aggregator.js +1 -1
  51. package/dist/role/derivation.d.ts +1 -1
  52. package/dist/role/derivation.js +1 -1
  53. package/dist/safety/confirm-gate.js +1 -1
  54. package/dist/schema/call/allocation.d.ts +7 -0
  55. package/dist/schema/call/allocation.js +1 -1
  56. package/dist/schema/call/arbitration.d.ts +4 -0
  57. package/dist/schema/call/arbitration.js +1 -1
  58. package/dist/schema/call/base.d.ts +48 -0
  59. package/dist/schema/call/base.js +1 -1
  60. package/dist/schema/call/bridge.d.ts +26 -0
  61. package/dist/schema/call/contact.d.ts +4 -0
  62. package/dist/schema/call/demand.d.ts +4 -0
  63. package/dist/schema/call/error-codes.d.ts +1 -1
  64. package/dist/schema/call/error-codes.js +1 -1
  65. package/dist/schema/call/guard.d.ts +12 -0
  66. package/dist/schema/call/handler.js +1 -1
  67. package/dist/schema/call/machine.d.ts +8 -0
  68. package/dist/schema/call/order.d.ts +4 -0
  69. package/dist/schema/call/order.js +1 -1
  70. package/dist/schema/call/payment.d.ts +4 -0
  71. package/dist/schema/call/permission.d.ts +4 -0
  72. package/dist/schema/call/personal.d.ts +4 -0
  73. package/dist/schema/call/progress.d.ts +4 -0
  74. package/dist/schema/call/proof.d.ts +8 -0
  75. package/dist/schema/call/repository.d.ts +4 -0
  76. package/dist/schema/call/repository.js +1 -1
  77. package/dist/schema/call/reward.d.ts +4 -0
  78. package/dist/schema/call/semantic-customer-advice.spec.js +1 -1
  79. package/dist/schema/call/semantic.d.ts +11 -0
  80. package/dist/schema/call/semantic.js +1 -1
  81. package/dist/schema/call/service.d.ts +14 -0
  82. package/dist/schema/call/service.js +1 -1
  83. package/dist/schema/call/treasury.d.ts +4 -0
  84. package/dist/schema/common/index.js +1 -1
  85. package/dist/schema/keeper/index.d.ts +5 -0
  86. package/dist/schema/local/index.d.ts +28 -0
  87. package/dist/schema/local/index.js +1 -1
  88. package/dist/schema/messenger/index.d.ts +5 -0
  89. package/dist/schema/messenger/index.js +1 -1
  90. package/dist/schema/operations.d.ts +83 -0
  91. package/dist/schema/query/bi.js +1 -1
  92. package/dist/schema/query/index.d.ts +16 -0
  93. package/dist/schema/query/index.js +1 -1
  94. package/dist/schema/schema-version.js +1 -1
  95. package/dist/schema/workflow/index.d.ts +2 -0
  96. package/dist/schema/workflow/index.js +1 -1
  97. package/dist/schema-query-impl/index.js +1 -1
  98. package/dist/schemas/account_operation.output.json +25 -1
  99. package/dist/schemas/bridge_operation.output.json +25 -1
  100. package/dist/schemas/bridge_operation.schema.json +40 -0
  101. package/dist/schemas/guard2file.schema.json +8 -0
  102. package/dist/schemas/index.json +1 -1
  103. package/dist/schemas/keeper_operation.output.json +24 -1
  104. package/dist/schemas/local_history_operation.output.json +25 -1
  105. package/dist/schemas/local_info_operation.output.json +25 -1
  106. package/dist/schemas/local_mark_operation.output.json +25 -1
  107. package/dist/schemas/machineNode2file.schema.json +8 -0
  108. package/dist/schemas/messenger_operation.output.json +24 -1
  109. package/dist/schemas/messenger_operation.schema.json +2 -2
  110. package/dist/schemas/monitor_events.output.json +24 -1
  111. package/dist/schemas/monitor_subscription.output.json +24 -1
  112. package/dist/schemas/onchain_events.output.json +24 -1
  113. package/dist/schemas/onchain_operations.output.json +73 -3
  114. package/dist/schemas/onchain_operations.schema.json +3286 -821
  115. package/dist/schemas/onchain_operations_allocation.schema.json +12 -0
  116. package/dist/schemas/onchain_operations_arbitration.schema.json +18 -10
  117. package/dist/schemas/onchain_operations_contact.schema.json +8 -0
  118. package/dist/schemas/onchain_operations_demand.schema.json +8 -0
  119. package/dist/schemas/onchain_operations_gen_passport.schema.json +8 -0
  120. package/dist/schemas/onchain_operations_gen_proof.schema.json +8 -0
  121. package/dist/schemas/onchain_operations_guard.schema.json +2896 -596
  122. package/dist/schemas/onchain_operations_machine.schema.json +8 -0
  123. package/dist/schemas/onchain_operations_order.schema.json +10 -2
  124. package/dist/schemas/onchain_operations_payment.schema.json +8 -0
  125. package/dist/schemas/onchain_operations_permission.schema.json +8 -0
  126. package/dist/schemas/onchain_operations_personal.schema.json +8 -0
  127. package/dist/schemas/onchain_operations_progress.schema.json +8 -0
  128. package/dist/schemas/onchain_operations_proof.schema.json +8 -0
  129. package/dist/schemas/onchain_operations_repository.schema.json +14 -6
  130. package/dist/schemas/onchain_operations_reward.schema.json +8 -0
  131. package/dist/schemas/onchain_operations_service.schema.json +43 -10
  132. package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
  133. package/dist/schemas/onchain_table_data.output.json +35 -12
  134. package/dist/schemas/query_toolkit.output.json +1179 -10
  135. package/dist/schemas/query_toolkit.schema.json +11 -11
  136. package/dist/schemas/workflow_operation.schema.json +8 -0
  137. package/dist/tools/handlers/config.js +1 -1
  138. package/dist/tools/handlers/dispatch-expectations.js +1 -1
  139. package/dist/tools/handlers/dispatch-expectations.spec.d.ts +1 -0
  140. package/dist/tools/handlers/dispatch-expectations.spec.js +1 -0
  141. package/dist/tools/handlers/onchain.js +1 -1
  142. package/dist/tools/handlers/workflow.js +1 -1
  143. package/dist/tools/index.js +1 -1
  144. package/dist/tools/move-fn-index.gen.js +1 -1
  145. package/package.json +2 -2
@@ -1 +1 @@
1
- import{describe,expect,it}from'vitest';import{ENTRYPOINT}from'@wowok/wowok';import{FakeDataPlane}from'./dataplane.js';import{expandTopology}from'./expand.js';import{EDGE_SCHEMA_BY_ID}from'./edge-schema.js';import{INTENT_PRESETS,TOPOLOGY_INTENTS,EVALUATION_SERVICE_INTENTS,EVALUATION_SERVICE_BUDGET,isTopologyIntent,normalizeTopologyFocusPref,normalizeSchemaHops,resolveExpansionStrategy,withEvaluationBundle}from'./strategy.js';import{ROLE_TOPOLOGY_DEFAULTS,INDUSTRY_TOPOLOGY_DEFAULTS}from'../../persona/topology-focus.js';import{PERSONA_ROLES}from'../../persona/types.js';describe('strategy\x20—\x20registries',()=>{it('every\x20intent\x20has\x20a\x20preset\x20and\x20vice\x20versa',()=>{for(const a of TOPOLOGY_INTENTS){expect(INTENT_PRESETS[a])['toBeDefined'](),expect(INTENT_PRESETS[a]['description']['length'])['toBeGreaterThan'](0x0);}expect(Object['keys'](INTENT_PRESETS)['sort']())['toEqual']([...TOPOLOGY_INTENTS]['sort']());}),it('preset\x20schema\x20ids\x20reference\x20real\x20edge\x20schemas',()=>{for(const a of Object['values'](INTENT_PRESETS)){for(const b of a['schemas']??[]){expect(EDGE_SCHEMA_BY_ID['has'](b),'unknown\x20schema\x20id\x20'+b)['toBe'](!![]);}for(const c of a['tableEdges']??[]){const d=EDGE_SCHEMA_BY_ID['get'](c);expect(d,'table\x20edge\x20'+c+'\x20must\x20be\x20a\x20real\x20schema')['toBeDefined'](),expect(d['read']['kind'])['toBe']('table');}}}),it('role\x20defaults\x20cover\x20every\x20persona\x20role\x20with\x20valid\x20intents',()=>{for(const a of PERSONA_ROLES){const b=ROLE_TOPOLOGY_DEFAULTS[a];expect(b,'role\x20'+a)['toBeDefined'](),expect(b['intents']['length'])['toBeGreaterThan'](0x0);for(const c of b['intents'])expect(isTopologyIntent(c))['toBe'](!![]);expect(b['rationale']['length'])['toBeGreaterThan'](0x0);}}),it('industry\x20templates\x20cover\x20the\x20six\x20built-in\x20industries',()=>{for(const a of['freelance','rental','education','travel','subscription','retail']){expect(INDUSTRY_TOPOLOGY_DEFAULTS[a],a)['toBeDefined']();}});}),describe('strategy\x20—\x20resolveExpansionStrategy\x20layering',()=>{it('no\x20inputs\x20→\x20kernel\x20default\x20posture\x20(full_map,\x20machine.node,\x20no\x20narrowing)',()=>{const a=resolveExpansionStrategy({});expect(a['intents'])['toEqual'](['full_map']),expect(a['edges']['tableEdges'])['toEqual'](['machine.node']),expect(a['edges']['families'])['toBeUndefined'](),expect(a['edges']['schemas'])['toBeUndefined'](),expect(a['edges']['familyDepths'])['toBeUndefined'](),expect(a['budget']['maxDepth'])['toBeUndefined'](),expect(a['trace']['some'](b=>b['startsWith']('kernel\x20default')))['toBe'](!![]);}),it('industry\x20template\x20shapes\x20family\x20depths\x20without\x20cutting\x20families',()=>{const a=resolveExpansionStrategy({'industryTemplate':INDUSTRY_TOPOLOGY_DEFAULTS['rental']});expect(a['edges']['familyDepths'])['toEqual']({'M':0x4,'W':0x2}),expect(a['edges']['families'])['toBeUndefined'](),expect(a['intents'])['toEqual'](['full_map']),expect(a['trace']['some'](b=>b['startsWith']('industry\x20template')))['toBe'](!![]);}),it('role\x20default\x20intents\x20select\x20the\x20preset\x20layer',()=>{const a=resolveExpansionStrategy({'roleDefault':ROLE_TOPOLOGY_DEFAULTS['prospect']});expect(a['intents'])['toEqual'](['counterparty','reputation','fund_flow']),expect(a['edges']['schemas'])['toContain']('order.builder'),expect(a['edges']['schemas'])['toContain']('target.vote'),expect(a['edges']['schemas'])['toContain']('payment.recipient'),expect(a['edges']['familyDepths'])['toMatchObject']({'M':0x4,'S':0x3}),expect(a['trace']['some'](b=>b['startsWith']('intent\x20(role\x20default)')))['toBe'](!![]);}),it('explicit\x20intent\x20beats\x20persona\x20intents\x20beats\x20role\x20default\x20intents',()=>{const a=resolveExpansionStrategy({'intents':['workflow'],'personaPref':{'intents':['reputation']},'roleDefault':ROLE_TOPOLOGY_DEFAULTS['customer']});expect(a['intents'])['toEqual'](['workflow']),expect(a['edges']['tableEdges'])['toContain']('machine.node'),expect(a['trace'][0x0])['toBe']('intent\x20(explicit):\x20workflow');}),it('persona\x20preference\x20overrides\x20preset\x20fragments\x20(identity-specific)',()=>{const a=normalizeTopologyFocusPref({'intents':['order_health'],'table_edges':['machine.node','permission.entity'],'family_depths':{'M':0x3},'max_depth':0x6}),b=resolveExpansionStrategy({'roleDefault':ROLE_TOPOLOGY_DEFAULTS['customer'],'personaPref':{'intents':a['intents'],'tableEdges':a['table_edges'],'familyDepths':a['family_depths'],'maxDepth':a['max_depth']}});expect(b['intents'])['toEqual'](['order_health']),expect(b['edges']['tableEdges'])['toEqual'](['machine.node','repository.data_about','permission.entity']),expect(b['edges']['familyDepths'])['toMatchObject']({'M':0x3}),expect(b['budget']['maxDepth'])['toBe'](0x6),expect(b['trace']['some'](c=>c['startsWith']('persona\x20preference')))['toBe'](!![]);}),it('explicit\x20table_edges\x20REPLACES\x20the\x20accumulated\x20union;\x20explicit\x20budget\x20wins',()=>{const a=resolveExpansionStrategy({'intents':['permission'],'personaPref':{'tableEdges':['permission.entity']},'explicitEdges':{'tableEdges':['demand.presenter'],'budget':{'maxDepth':0x2,'maxNodes':0x64,'maxRpcs':0x1e}}});expect(a['edges']['tableEdges'])['toEqual'](['demand.presenter']),expect(a['budget'])['toEqual']({'maxDepth':0x2,'maxNodes':0x64,'maxFanoutPerNode':undefined,'maxRpcs':0x1e});}),it('table\x20edges\x20accumulate\x20(union)\x20across\x20industry\x20+\x20presets\x20+\x20persona',()=>{const a=resolveExpansionStrategy({'industryTemplate':{'label':'t','tableEdges':['permission.entity']},'intents':['demand_match'],'personaPref':{'tableEdges':['machine.node']}});expect(a['edges']['tableEdges'])['toEqual'](['permission.entity','demand.presenter','demand.presenter_service','machine.node']);}),it('event\x20edges:\x20presets\x20opt\x20in,\x20layers\x20union,\x20explicit\x20replaces,\x20no\x20kernel\x20default',()=>{const a=resolveExpansionStrategy({'intents':['order_health']});expect(a['edges']['eventEdges'])['toEqual'](['service.order_history','eoa.order_history']);const b=resolveExpansionStrategy({'intents':['arbitration']});expect(b['edges']['eventEdges'])['toEqual'](['arb.history']);const c=resolveExpansionStrategy({'intents':['order_health','arbitration']});expect(c['edges']['eventEdges'])['toEqual'](['service.order_history','eoa.order_history','arb.history']);const d=resolveExpansionStrategy({'intents':['order_health'],'explicitEdges':{'eventEdges':['arb.history']}});expect(d['edges']['eventEdges'])['toEqual'](['arb.history']),expect(resolveExpansionStrategy({'intents':['fund_flow']})['edges']['eventEdges'])['toBeUndefined']();}),it('deny\x20only\x20ever\x20comes\x20from\x20explicit\x20params',()=>{const a=resolveExpansionStrategy({'personaPref':{'families':['M']},'explicitEdges':{'deny':['target.vote']}});expect(a['edges']['deny'])['toEqual'](['target.vote']);});}),describe('strategy\x20—\x20schemaHops\x20five-layer\x20merge',()=>{it('merges\x20per\x20key\x20with\x20industry\x20<\x20intent\x20<\x20persona\x20<\x20explicit\x20and\x20traces\x20every\x20layer',()=>{const a=resolveExpansionStrategy({'industryTemplate':{'label':'t','schemaHops':{'guard.relies':0x2,'arb.voter':0x4}},'intents':['arbitration'],'personaPref':{'schemaHops':{'guard.relies':0x1,'arb.order':0x3}},'explicitEdges':{'schemaHops':{'guard.relies':0x0}}});expect(a['edges']['schemaHops'])['toEqual']({'guard.relies':0x0,'arb.voter':0x4,'arb.order':0x3});const b=a['trace']['join']('\x0a');expect(b)['toContain']('industry\x20template\x20(t):\x20hops'),expect(b)['toContain']('persona\x20preference:\x20hops'),expect(b)['toContain']('explicit:\x20hops\x20guard.relies≤0'),expect(b)['toContain']('effective\x20schema\x20hops:'),expect(b)['toContain']('intent\x20presets\x20(arbitration):');}),it('kernel-default\x20resolution\x20carries\x20no\x20schemaHops\x20and\x20no\x20effective\x20line',()=>{const a=resolveExpansionStrategy({});expect(a['edges']['schemaHops'])['toBeUndefined'](),expect(a['trace']['some'](b=>b['includes']('schema\x20hops')))['toBe'](![]);}),it('drops\x20out-of-range,\x20non-integer\x20and\x20unknown-schema\x20values\x20(TR-4.2)',()=>{const a={'guard.relies':0x9,'arb.order':2.5,'arb.voter':'2','not.a.schema':0x1};a['arb.order']=0x2;const b=resolveExpansionStrategy({'explicitEdges':{'schemaHops':a}});expect(b['edges']['schemaHops'])['toEqual']({'arb.order':0x2});const c=b['trace']['filter'](d=>d['includes']('dropped\x20invalid\x20hops'));expect(c)['toHaveLength'](0x1),expect(c[0x0])['toContain']('guard.relies'),expect(c[0x0])['toContain']('arb.voter'),expect(c[0x0])['toContain']('not.a.schema');}),it('normalizeSchemaHops\x20and\x20persona\x20schema_hops\x20share\x20the\x20same\x20rules',()=>{expect(normalizeSchemaHops({'guard.relies':0x1,'bogus':0x1,'x':-0x1}))['toEqual']({'guard.relies':0x1}),expect(normalizeSchemaHops(null))['toBeUndefined'](),expect(normalizeSchemaHops({'bogus':0x1}))['toBeUndefined']();const a=normalizeTopologyFocusPref({'schema_hops':{'guard.relies':0x1,'nope':0x2}});expect(a['schema_hops'])['toEqual']({'guard.relies':0x1});});}),describe('strategy\x20—\x20EVALUATION_SERVICE\x20bundle',()=>{it('is\x20the\x20seven-intent\x20union\x20with\x20valid\x20ids\x20and\x20a\x20bounded\x20budget',()=>{expect([...EVALUATION_SERVICE_INTENTS])['toEqual'](['order_health','supply_chain','arbitration','workflow','fund_flow','permission','reputation']);for(const a of EVALUATION_SERVICE_INTENTS)expect(isTopologyIntent(a))['toBe'](!![]);expect(EVALUATION_SERVICE_BUDGET['maxNodes'])['toBeLessThanOrEqual'](0x1f4),expect(EVALUATION_SERVICE_BUDGET['maxRpcs'])['toBeLessThanOrEqual'](0x78);}),it('resolves\x20into\x20a\x20union\x20whitelist\x20carrying\x20the\x20bundle\x27s\x20tables\x20and\x20depths',()=>{const a=resolveExpansionStrategy({'intents':[...EVALUATION_SERVICE_INTENTS]});expect(a['edges']['tableEdges'])['toContain']('machine.node'),expect(a['edges']['schemas'])['toContain']('payment.recipient'),expect(a['edges']['schemas'])['toContain']('arb.voter'),expect(a['edges']['schemas'])['toContain']('arbitration.voting_guard'),expect(a['edges']['schemas'])['toContain']('service.order'),expect(a['edges']['schemas'])['toContain']('eoa.order'),expect(a['edges']['familyDepths'])['toMatchObject']({'W':0x5,'M':0x4,'S':0x3,'R':0x4});}),it('withEvaluationBundle\x20raises\x20the\x20S\x20floor\x20to\x205\x20and\x20stamps\x20the\x20budget',()=>{const a=withEvaluationBundle(resolveExpansionStrategy({'intents':[...EVALUATION_SERVICE_INTENTS]}));expect(a['edges']['familyDepths'])['toEqual']({'W':0x5,'M':0x4,'S':0x5,'R':0x4}),expect(a['budget'])['toEqual'](EVALUATION_SERVICE_BUDGET),expect(a['trace']['some'](b=>b['includes']('S≤5\x20floor')))['toBe'](!![]);});}),describe('strategy\x20—\x20normalizeTopologyFocusPref',()=>{it('keeps\x20valid\x20fields,\x20drops\x20invalid\x20ones',()=>{const a=normalizeTopologyFocusPref({'intents':['fund_flow','bogus_intent'],'families':['M','X'],'table_edges':['machine.node',0x2a],'family_depths':{'M':0x3,'Z':0x9},'max_depth':0x5,'max_nodes':0x270f,'max_fanout':-0x1});expect(a)['toEqual']({'intents':['fund_flow'],'families':['M'],'table_edges':['machine.node'],'family_depths':{'M':0x3},'max_depth':0x5});}),it('returns\x20undefined\x20for\x20empty/invalid\x20input',()=>{expect(normalizeTopologyFocusPref(null))['toBeUndefined'](),expect(normalizeTopologyFocusPref('x'))['toBeUndefined'](),expect(normalizeTopologyFocusPref({}))['toBeUndefined'](),expect(normalizeTopologyFocusPref({'intents':'not-an-array'}))['toBeUndefined']();});});function mk(a,b){return'0x'+a['toString'](0x10)['padStart'](0x2,'0')+b['toString'](0x10)['padStart'](0x3e,'0');}const eoa=a=>mk(0x0,a),obj=(a,b)=>mk(0x10+a,b),T_USDT='0x2::wow::coins::USDT',buyer=eoa(0x1),merchant=eoa(0x3),svc=obj(0x4,0xa),mac=obj(0x5,0xb),o1=obj(0x6,0x15),pr1=obj(0x7,0x1f),pay=obj(0x8,0x29),perm=obj(0x0,0x33);function depthPlane(){const a=new Map([[o1['toLowerCase'](),{'object':o1,'type':'Order','data':{'builder':buyer,'agent':[],'service':svc,'machine':mac,'progress':pr1,'dispute':[]}}],[svc['toLowerCase'](),{'object':svc,'type':'Service','data':{'permission':perm,'machine':mac},'type_raw':'0x2::service::Service<'+T_USDT+'>'}],[mac['toLowerCase'](),{'object':mac,'type':'Machine','data':{'permission':perm}}],[pr1['toLowerCase'](),{'object':pr1,'type':'Progress','data':{'machine':mac,'task':o1,'current':'done'}}],[pay['toLowerCase'](),{'object':pay,'type':'Payment','data':{'record':[{'recipient':merchant,'amount':'100'}],'info':{}},'type_raw':'0x2::payment::Payment<'+T_USDT+'>'}],[perm['toLowerCase'](),{'object':perm,'type':'Permission','data':{'admin':[merchant]}}]]),b=new Map([['0xaa8',new Map([[buyer,{'items':[{'role':0x1,'order':o1,'time':0x1}]}]])]]),c=new Map([]);return new FakeDataPlane({'objects':a,'keyedFields':b,'tables':c});}describe('strategy\x20—\x20Gate\x20familyDepths\x20in\x20expandTopology',()=>{it('F\x20cap\x201\x20from\x20an\x20EOA\x20seed\x20blocks\x20every\x20field\x20edge\x20(orders\x20reached,\x20service\x20not)',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'familyDepths':{'F':0x1}}});expect(a['nodes']['has'](o1['toLowerCase']()))['toBe'](!![]),expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](![]),expect(a['edges']['some'](b=>b['family']==='F'))['toBe'](![]);}),it('F\x20cap\x202\x20allows\x20one\x20hop\x20of\x20field\x20edges\x20then\x20stops',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'familyDepths':{'F':0x2}}});expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](!![]),expect(a['edges']['some'](b=>b['schema']==='service.permission'))['toBe'](![]);}),it('W\x20cap\x200\x20keeps\x20the\x20workflow\x20family\x20closed\x20even\x20with\x20machine.node\x20whitelisted',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'tableEdges':['machine.node'],'familyDepths':{'W':0x0}}});expect(a['edges']['some'](b=>b['family']==='W'))['toBe'](![]);}),it('unset\x20families\x20fall\x20back\x20to\x20the\x20global\x20maxDepth\x20(no\x20regression)',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer});expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](!![]),expect(a['nodes']['has'](perm['toLowerCase']()))['toBe'](!![]);});}),describe('strategy\x20—\x20Gate\x20schemaHops\x20in\x20expandTopology',()=>{const a=obj(0xa,0x83),b=obj(0xa,0x84),c=obj(0xa,0x85);function d(){const e=new Map([[a['toLowerCase'](),{'object':a,'type':'Guard','data':{'relies':[b]}}],[b['toLowerCase'](),{'object':b,'type':'Guard','data':{'relies':[c]}}],[c['toLowerCase'](),{'object':c,'type':'Guard','data':{'relies':[]}}]]);return new FakeDataPlane({'objects':e,'keyedFields':new Map(),'tables':new Map()});}it('strategy\x20cannot\x20raise\x20the\x20contract\x20cap\x20(guard.relies\x20stays\x201\x20with\x20schemaHops=2)',async()=>{const e=await expandTopology(d(),{'network':ENTRYPOINT['Mainnet'],'seed':a,'edges':{'schemaHops':{'guard.relies':0x2}}});expect(e['edges']['some'](f=>f['schema']==='guard.relies'&&f['from']===a&&f['to']===b))['toBe'](!![]),expect(e['edges']['some'](f=>f['schema']==='guard.relies'&&f['from']===b&&f['to']===c))['toBe'](![]),expect(e['truncations']['find'](f=>f['reason']==='schema_hops')?.['limit'])['toBe'](0x1);}),it('strategy\x20narrows\x20below\x20the\x20contract\x20cap\x20(schemaHops=0\x20blocks\x20even\x20the\x20first\x20hop)',async()=>{const e=await expandTopology(d(),{'network':ENTRYPOINT['Mainnet'],'seed':a,'edges':{'schemaHops':{'guard.relies':0x0}}});expect(e['edges']['some'](g=>g['schema']==='guard.relies'))['toBe'](![]),expect(e['nodes']['has'](b['toLowerCase']()))['toBe'](![]);const f=e['truncations']['find'](g=>g['reason']==='schema_hops');expect(f)['toMatchObject']({'nodeId':a,'schema':'guard.relies','limit':0x0,'observed':0x1});});}),describe('strategy\x20—\x20caller\x20default\x20intents\x20(Task\x2016)',()=>{it('resolves\x20when\x20no\x20higher\x20intent\x20layer\x20exists,\x20with\x20its\x20own\x20trace\x20line',()=>{const a=resolveExpansionStrategy({'defaultIntents':['workflow']});expect(a['intents'])['toEqual'](['workflow']),expect(a['trace']['some'](b=>b['startsWith']('intent\x20(default):\x20workflow')))['toBe'](!![]);}),it('explicit\x20>\x20persona\x20>\x20role\x20default\x20>\x20caller\x20default',()=>{expect(resolveExpansionStrategy({'intents':['arbitration'],'defaultIntents':['workflow']})['intents'])['toEqual'](['arbitration']),expect(resolveExpansionStrategy({'personaPref':{'intents':['reputation']},'defaultIntents':['workflow']})['intents'])['toEqual'](['reputation']),expect(resolveExpansionStrategy({'roleDefault':{'intents':['fund_flow']},'defaultIntents':['workflow']})['intents'])['toEqual'](['fund_flow']);});});
1
+ import{describe,expect,it}from'vitest';import{ENTRYPOINT}from'@wowok/wowok';import{FakeDataPlane}from'./dataplane.js';import{expandTopology}from'./expand.js';import{EDGE_SCHEMA_BY_ID}from'./edge-schema.js';import{INTENT_PRESETS,TOPOLOGY_INTENTS,EVALUATION_SERVICE_INTENTS,EVALUATION_SERVICE_BUDGET,isTopologyIntent,normalizeTopologyFocusPref,normalizeSchemaHops,resolveExpansionStrategy,withEvaluationBundle}from'./strategy.js';import{ROLE_TOPOLOGY_DEFAULTS,INDUSTRY_TOPOLOGY_DEFAULTS}from'../../persona/topology-focus.js';import{PERSONA_ROLES}from'../../persona/types.js';describe('strategy\x20—\x20registries',()=>{it('every\x20intent\x20has\x20a\x20preset\x20and\x20vice\x20versa',()=>{for(const a of TOPOLOGY_INTENTS){expect(INTENT_PRESETS[a])['toBeDefined'](),expect(INTENT_PRESETS[a]['description']['length'])['toBeGreaterThan'](0x0);}expect(Object['keys'](INTENT_PRESETS)['sort']())['toEqual']([...TOPOLOGY_INTENTS]['sort']());}),it('preset\x20schema\x20ids\x20reference\x20real\x20edge\x20schemas',()=>{for(const a of Object['values'](INTENT_PRESETS)){for(const b of a['schemas']??[]){expect(EDGE_SCHEMA_BY_ID['has'](b),'unknown\x20schema\x20id\x20'+b)['toBe'](!![]);}for(const c of a['tableEdges']??[]){const d=EDGE_SCHEMA_BY_ID['get'](c);expect(d,'table\x20edge\x20'+c+'\x20must\x20be\x20a\x20real\x20schema')['toBeDefined'](),expect(d['read']['kind'])['toBe']('table');}}}),it('role\x20defaults\x20cover\x20every\x20persona\x20role\x20with\x20valid\x20intents',()=>{for(const a of PERSONA_ROLES){const b=ROLE_TOPOLOGY_DEFAULTS[a];expect(b,'role\x20'+a)['toBeDefined'](),expect(b['intents']['length'])['toBeGreaterThan'](0x0);for(const c of b['intents'])expect(isTopologyIntent(c))['toBe'](!![]);expect(b['rationale']['length'])['toBeGreaterThan'](0x0);}}),it('industry\x20templates\x20cover\x20the\x20six\x20built-in\x20industries',()=>{for(const a of['freelance','rental','education','travel','subscription','retail']){expect(INDUSTRY_TOPOLOGY_DEFAULTS[a],a)['toBeDefined']();}});}),describe('strategy\x20—\x20resolveExpansionStrategy\x20layering',()=>{it('no\x20inputs\x20→\x20kernel\x20default\x20posture\x20(full_map,\x20machine.node,\x20no\x20narrowing)',()=>{const a=resolveExpansionStrategy({});expect(a['intents'])['toEqual'](['full_map']),expect(a['edges']['tableEdges'])['toEqual'](['machine.node']),expect(a['edges']['families'])['toBeUndefined'](),expect(a['edges']['schemas'])['toBeUndefined'](),expect(a['edges']['familyDepths'])['toBeUndefined'](),expect(a['budget']['maxDepth'])['toBeUndefined'](),expect(a['trace']['some'](b=>b['startsWith']('kernel\x20default')))['toBe'](!![]);}),it('industry\x20template\x20shapes\x20family\x20depths\x20without\x20cutting\x20families',()=>{const a=resolveExpansionStrategy({'industryTemplate':INDUSTRY_TOPOLOGY_DEFAULTS['rental']});expect(a['edges']['familyDepths'])['toEqual']({'M':0x4,'W':0x2}),expect(a['edges']['families'])['toBeUndefined'](),expect(a['intents'])['toEqual'](['full_map']),expect(a['trace']['some'](b=>b['startsWith']('industry\x20template')))['toBe'](!![]);}),it('role\x20default\x20intents\x20select\x20the\x20preset\x20layer',()=>{const a=resolveExpansionStrategy({'roleDefault':ROLE_TOPOLOGY_DEFAULTS['prospect']});expect(a['intents'])['toEqual'](['counterparty','reputation','fund_flow']),expect(a['edges']['schemas'])['toContain']('order.builder'),expect(a['edges']['schemas'])['toContain']('target.vote'),expect(a['edges']['schemas'])['toContain']('payment.recipient'),expect(a['edges']['familyDepths'])['toMatchObject']({'M':0x4,'S':0x3}),expect(a['trace']['some'](b=>b['startsWith']('intent\x20(role\x20default)')))['toBe'](!![]);}),it('explicit\x20intent\x20beats\x20persona\x20intents\x20beats\x20role\x20default\x20intents',()=>{const a=resolveExpansionStrategy({'intents':['workflow'],'personaPref':{'intents':['reputation']},'roleDefault':ROLE_TOPOLOGY_DEFAULTS['customer']});expect(a['intents'])['toEqual'](['workflow']),expect(a['edges']['tableEdges'])['toContain']('machine.node'),expect(a['trace'][0x0])['toBe']('intent\x20(explicit):\x20workflow');}),it('persona\x20preference\x20overrides\x20preset\x20fragments\x20(identity-specific)',()=>{const a=normalizeTopologyFocusPref({'intents':['order_health'],'table_edges':['machine.node','permission.entity'],'family_depths':{'M':0x3},'max_depth':0x6}),b=resolveExpansionStrategy({'roleDefault':ROLE_TOPOLOGY_DEFAULTS['customer'],'personaPref':{'intents':a['intents'],'tableEdges':a['table_edges'],'familyDepths':a['family_depths'],'maxDepth':a['max_depth']}});expect(b['intents'])['toEqual'](['order_health']),expect(b['edges']['tableEdges'])['toEqual'](['machine.node','repository.data_about','permission.entity']),expect(b['edges']['familyDepths'])['toMatchObject']({'M':0x3}),expect(b['budget']['maxDepth'])['toBe'](0x6),expect(b['trace']['some'](c=>c['startsWith']('persona\x20preference')))['toBe'](!![]);}),it('explicit\x20table_edges\x20REPLACES\x20the\x20accumulated\x20union;\x20explicit\x20budget\x20wins',()=>{const a=resolveExpansionStrategy({'intents':['permission'],'personaPref':{'tableEdges':['permission.entity']},'explicitEdges':{'tableEdges':['demand.presenter'],'budget':{'maxDepth':0x2,'maxNodes':0x64,'maxRpcs':0x1e}}});expect(a['edges']['tableEdges'])['toEqual'](['demand.presenter']),expect(a['budget'])['toEqual']({'maxDepth':0x2,'maxNodes':0x64,'maxFanoutPerNode':undefined,'maxRpcs':0x1e});}),it('table\x20edges\x20accumulate\x20(union)\x20across\x20industry\x20+\x20presets\x20+\x20persona',()=>{const a=resolveExpansionStrategy({'industryTemplate':{'label':'t','tableEdges':['permission.entity']},'intents':['demand_match'],'personaPref':{'tableEdges':['machine.node']}});expect(a['edges']['tableEdges'])['toEqual'](['permission.entity','demand.presenter','demand.presenter_service','machine.node']);}),it('event\x20edges:\x20presets\x20opt\x20in,\x20layers\x20union,\x20explicit\x20replaces,\x20no\x20kernel\x20default',()=>{const a=resolveExpansionStrategy({'intents':['order_health']});expect(a['edges']['eventEdges'])['toEqual'](['service.order_history','eoa.order_history']);const b=resolveExpansionStrategy({'intents':['arbitration']});expect(b['edges']['eventEdges'])['toEqual'](['arb.history']);const c=resolveExpansionStrategy({'intents':['order_health','arbitration']});expect(c['edges']['eventEdges'])['toEqual'](['service.order_history','eoa.order_history','arb.history']);const d=resolveExpansionStrategy({'intents':['order_health'],'explicitEdges':{'eventEdges':['arb.history']}});expect(d['edges']['eventEdges'])['toEqual'](['arb.history']),expect(resolveExpansionStrategy({'intents':['fund_flow']})['edges']['eventEdges'])['toBeUndefined']();}),it('deny\x20only\x20ever\x20comes\x20from\x20explicit\x20params',()=>{const a=resolveExpansionStrategy({'personaPref':{'families':['M']},'explicitEdges':{'deny':['target.vote']}});expect(a['edges']['deny'])['toEqual'](['target.vote']);});}),describe('strategy\x20—\x20schemaHops\x20five-layer\x20merge',()=>{it('merges\x20per\x20key\x20with\x20industry\x20<\x20intent\x20<\x20persona\x20<\x20explicit\x20and\x20traces\x20every\x20layer',()=>{const a=resolveExpansionStrategy({'industryTemplate':{'label':'t','schemaHops':{'guard.relies':0x2,'arb.voter':0x4}},'intents':['arbitration'],'personaPref':{'schemaHops':{'guard.relies':0x1,'arb.order':0x3}},'explicitEdges':{'schemaHops':{'guard.relies':0x0}}});expect(a['edges']['schemaHops'])['toEqual']({'guard.relies':0x0,'arb.voter':0x4,'arb.order':0x3});const b=a['trace']['join']('\x0a');expect(b)['toContain']('industry\x20template\x20(t):\x20hops'),expect(b)['toContain']('persona\x20preference:\x20hops'),expect(b)['toContain']('explicit:\x20hops\x20guard.relies≤0'),expect(b)['toContain']('effective\x20schema\x20hops:'),expect(b)['toContain']('intent\x20presets\x20(arbitration):');}),it('kernel-default\x20resolution\x20carries\x20no\x20schemaHops\x20and\x20no\x20effective\x20line',()=>{const a=resolveExpansionStrategy({});expect(a['edges']['schemaHops'])['toBeUndefined'](),expect(a['trace']['some'](b=>b['includes']('schema\x20hops')))['toBe'](![]);}),it('drops\x20out-of-range,\x20non-integer\x20and\x20unknown-schema\x20values\x20(TR-4.2)',()=>{const a={'guard.relies':0x9,'arb.order':2.5,'arb.voter':'2','not.a.schema':0x1};a['arb.order']=0x2;const b=resolveExpansionStrategy({'explicitEdges':{'schemaHops':a}});expect(b['edges']['schemaHops'])['toEqual']({'arb.order':0x2});const c=b['trace']['filter'](d=>d['includes']('dropped\x20invalid\x20hops'));expect(c)['toHaveLength'](0x1),expect(c[0x0])['toContain']('guard.relies'),expect(c[0x0])['toContain']('arb.voter'),expect(c[0x0])['toContain']('not.a.schema');}),it('normalizeSchemaHops\x20and\x20persona\x20schema_hops\x20share\x20the\x20same\x20rules',()=>{expect(normalizeSchemaHops({'guard.relies':0x1,'bogus':0x1,'x':-0x1}))['toEqual']({'guard.relies':0x1}),expect(normalizeSchemaHops(null))['toBeUndefined'](),expect(normalizeSchemaHops({'bogus':0x1}))['toBeUndefined']();const a=normalizeTopologyFocusPref({'schema_hops':{'guard.relies':0x1,'nope':0x2}});expect(a['schema_hops'])['toEqual']({'guard.relies':0x1});});}),describe('strategy\x20—\x20EVALUATION_SERVICE\x20bundle',()=>{it('is\x20the\x20seven-intent\x20union\x20with\x20valid\x20ids\x20and\x20a\x20bounded\x20budget',()=>{expect([...EVALUATION_SERVICE_INTENTS])['toEqual'](['order_health','supply_chain','arbitration','workflow','fund_flow','permission','reputation']);for(const a of EVALUATION_SERVICE_INTENTS)expect(isTopologyIntent(a))['toBe'](!![]);expect(EVALUATION_SERVICE_BUDGET['maxNodes'])['toBeLessThanOrEqual'](0x1f4),expect(EVALUATION_SERVICE_BUDGET['maxRpcs'])['toBeLessThanOrEqual'](0x78);}),it('resolves\x20into\x20a\x20union\x20whitelist\x20carrying\x20the\x20bundle\x27s\x20tables\x20and\x20depths',()=>{const a=resolveExpansionStrategy({'intents':[...EVALUATION_SERVICE_INTENTS]});expect(a['edges']['tableEdges'])['toContain']('machine.node'),expect(a['edges']['schemas'])['toContain']('payment.recipient'),expect(a['edges']['schemas'])['toContain']('arb.voter'),expect(a['edges']['schemas'])['toContain']('arbitration.voting_guard'),expect(a['edges']['schemas'])['toContain']('service.order'),expect(a['edges']['schemas'])['toContain']('eoa.order'),expect(a['edges']['schemas'])['toContain']('service.reward'),expect(a['edges']['schemas'])['toContain']('reward.guard'),expect(a['edges']['familyDepths'])['toMatchObject']({'W':0x5,'M':0x4,'S':0x3,'R':0x4});}),it('withEvaluationBundle\x20raises\x20the\x20S\x20floor\x20to\x205\x20and\x20stamps\x20the\x20budget',()=>{const a=withEvaluationBundle(resolveExpansionStrategy({'intents':[...EVALUATION_SERVICE_INTENTS]}));expect(a['edges']['familyDepths'])['toEqual']({'W':0x5,'M':0x4,'S':0x5,'R':0x4}),expect(a['budget'])['toEqual'](EVALUATION_SERVICE_BUDGET),expect(a['trace']['some'](b=>b['includes']('S≤5\x20floor')))['toBe'](!![]);});}),describe('strategy\x20—\x20normalizeTopologyFocusPref',()=>{it('keeps\x20valid\x20fields,\x20drops\x20invalid\x20ones',()=>{const a=normalizeTopologyFocusPref({'intents':['fund_flow','bogus_intent'],'families':['M','X'],'table_edges':['machine.node',0x2a],'family_depths':{'M':0x3,'Z':0x9},'max_depth':0x5,'max_nodes':0x270f,'max_fanout':-0x1});expect(a)['toEqual']({'intents':['fund_flow'],'families':['M'],'table_edges':['machine.node'],'family_depths':{'M':0x3},'max_depth':0x5});}),it('returns\x20undefined\x20for\x20empty/invalid\x20input',()=>{expect(normalizeTopologyFocusPref(null))['toBeUndefined'](),expect(normalizeTopologyFocusPref('x'))['toBeUndefined'](),expect(normalizeTopologyFocusPref({}))['toBeUndefined'](),expect(normalizeTopologyFocusPref({'intents':'not-an-array'}))['toBeUndefined']();});});function mk(a,b){return'0x'+a['toString'](0x10)['padStart'](0x2,'0')+b['toString'](0x10)['padStart'](0x3e,'0');}const eoa=a=>mk(0x0,a),obj=(a,b)=>mk(0x10+a,b),T_USDT='0x2::wow::coins::USDT',buyer=eoa(0x1),merchant=eoa(0x3),svc=obj(0x4,0xa),mac=obj(0x5,0xb),o1=obj(0x6,0x15),pr1=obj(0x7,0x1f),pay=obj(0x8,0x29),perm=obj(0x0,0x33);function depthPlane(){const a=new Map([[o1['toLowerCase'](),{'object':o1,'type':'Order','data':{'builder':buyer,'agent':[],'service':svc,'machine':mac,'progress':pr1,'dispute':[]}}],[svc['toLowerCase'](),{'object':svc,'type':'Service','data':{'permission':perm,'machine':mac},'type_raw':'0x2::service::Service<'+T_USDT+'>'}],[mac['toLowerCase'](),{'object':mac,'type':'Machine','data':{'permission':perm}}],[pr1['toLowerCase'](),{'object':pr1,'type':'Progress','data':{'machine':mac,'task':o1,'current':'done'}}],[pay['toLowerCase'](),{'object':pay,'type':'Payment','data':{'record':[{'recipient':merchant,'amount':'100'}],'info':{}},'type_raw':'0x2::payment::Payment<'+T_USDT+'>'}],[perm['toLowerCase'](),{'object':perm,'type':'Permission','data':{'admin':[merchant]}}]]),b=new Map([['0xaa8',new Map([[buyer,{'items':[{'role':0x1,'order':o1,'time':0x1}]}]])]]),c=new Map([]);return new FakeDataPlane({'objects':a,'keyedFields':b,'tables':c});}describe('strategy\x20—\x20Gate\x20familyDepths\x20in\x20expandTopology',()=>{it('F\x20cap\x201\x20from\x20an\x20EOA\x20seed\x20blocks\x20every\x20field\x20edge\x20(orders\x20reached,\x20service\x20not)',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'familyDepths':{'F':0x1}}});expect(a['nodes']['has'](o1['toLowerCase']()))['toBe'](!![]),expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](![]),expect(a['edges']['some'](b=>b['family']==='F'))['toBe'](![]);}),it('F\x20cap\x202\x20allows\x20one\x20hop\x20of\x20field\x20edges\x20then\x20stops',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'familyDepths':{'F':0x2}}});expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](!![]),expect(a['edges']['some'](b=>b['schema']==='service.permission'))['toBe'](![]);}),it('W\x20cap\x200\x20keeps\x20the\x20workflow\x20family\x20closed\x20even\x20with\x20machine.node\x20whitelisted',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer,'edges':{'tableEdges':['machine.node'],'familyDepths':{'W':0x0}}});expect(a['edges']['some'](b=>b['family']==='W'))['toBe'](![]);}),it('unset\x20families\x20fall\x20back\x20to\x20the\x20global\x20maxDepth\x20(no\x20regression)',async()=>{const a=await expandTopology(depthPlane(),{'network':ENTRYPOINT['Mainnet'],'seed':buyer});expect(a['nodes']['has'](svc['toLowerCase']()))['toBe'](!![]),expect(a['nodes']['has'](perm['toLowerCase']()))['toBe'](!![]);});}),describe('strategy\x20—\x20Gate\x20schemaHops\x20in\x20expandTopology',()=>{const a=obj(0xa,0x83),b=obj(0xa,0x84),c=obj(0xa,0x85);function d(){const e=new Map([[a['toLowerCase'](),{'object':a,'type':'Guard','data':{'relies':[b]}}],[b['toLowerCase'](),{'object':b,'type':'Guard','data':{'relies':[c]}}],[c['toLowerCase'](),{'object':c,'type':'Guard','data':{'relies':[]}}]]);return new FakeDataPlane({'objects':e,'keyedFields':new Map(),'tables':new Map()});}it('strategy\x20cannot\x20raise\x20the\x20contract\x20cap\x20(guard.relies\x20stays\x201\x20with\x20schemaHops=2)',async()=>{const e=await expandTopology(d(),{'network':ENTRYPOINT['Mainnet'],'seed':a,'edges':{'schemaHops':{'guard.relies':0x2}}});expect(e['edges']['some'](f=>f['schema']==='guard.relies'&&f['from']===a&&f['to']===b))['toBe'](!![]),expect(e['edges']['some'](f=>f['schema']==='guard.relies'&&f['from']===b&&f['to']===c))['toBe'](![]),expect(e['truncations']['find'](f=>f['reason']==='schema_hops')?.['limit'])['toBe'](0x1);}),it('strategy\x20narrows\x20below\x20the\x20contract\x20cap\x20(schemaHops=0\x20blocks\x20even\x20the\x20first\x20hop)',async()=>{const e=await expandTopology(d(),{'network':ENTRYPOINT['Mainnet'],'seed':a,'edges':{'schemaHops':{'guard.relies':0x0}}});expect(e['edges']['some'](g=>g['schema']==='guard.relies'))['toBe'](![]),expect(e['nodes']['has'](b['toLowerCase']()))['toBe'](![]);const f=e['truncations']['find'](g=>g['reason']==='schema_hops');expect(f)['toMatchObject']({'nodeId':a,'schema':'guard.relies','limit':0x0,'observed':0x1});});}),describe('strategy\x20—\x20caller\x20default\x20intents\x20(Task\x2016)',()=>{it('resolves\x20when\x20no\x20higher\x20intent\x20layer\x20exists,\x20with\x20its\x20own\x20trace\x20line',()=>{const a=resolveExpansionStrategy({'defaultIntents':['workflow']});expect(a['intents'])['toEqual'](['workflow']),expect(a['trace']['some'](b=>b['startsWith']('intent\x20(default):\x20workflow')))['toBe'](!![]);}),it('explicit\x20>\x20persona\x20>\x20role\x20default\x20>\x20caller\x20default',()=>{expect(resolveExpansionStrategy({'intents':['arbitration'],'defaultIntents':['workflow']})['intents'])['toEqual'](['arbitration']),expect(resolveExpansionStrategy({'personaPref':{'intents':['reputation']},'defaultIntents':['workflow']})['intents'])['toEqual'](['reputation']),expect(resolveExpansionStrategy({'roleDefault':{'intents':['fund_flow']},'defaultIntents':['workflow']})['intents'])['toEqual'](['fund_flow']);});});
@@ -1 +1 @@
1
- export const RECOVERY_RULES={'insufficient_balance':{'error_code':'insufficient_balance','strategy':'claim_faucet','max_attempts':0x3,'automation':'semi','detail':'1.\x20Testnet:\x20claim\x20WOW\x20from\x20the\x20faucet\x202.\x20Mainnet:\x20transfer\x20ETH/USDT/USDC/WBTC\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge\x20(query\x20active\x20EVM\x20account\x20→\x20top\x20up\x20from\x20external\x20wallet\x20→\x20confirm\x20→\x20cross-chain)\x203.\x20Point\x20the\x20user\x20to\x20the\x20live\x20airdrop\x20page\x20(https://wowok.net/airdrop.html)\x20for\x20the\x20current\x20round\x204.\x20Retry\x20original\x20operation','user_prompt':'Insufficient\x20balance\x20for\x20gas\x20or\x20operation.\x20How\x20to\x20obtain\x20WOW\x20tokens:\x20(1)\x20Testnet\x20—\x20claim\x20WOW\x20from\x20the\x20faucet\x20(https://faucet.testnet.wowok.net);\x20all\x20merchant\x20and\x20order\x20testing\x20can\x20use\x20WOW\x20as\x20the\x20payment\x20token.\x20(2)\x20Mainnet\x20—\x20transfer\x20ETH\x20/\x20USDT\x20/\x20USDC\x20/\x20WBTC\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge:\x20first\x20query\x20the\x20active\x20EVM\x20account\x20(bridge_operation\x20query_active_evm_account,\x20auto-generated\x20on\x20first\x20use),\x20then\x20transfer\x20from\x20an\x20external\x20wallet\x20(e.g.\x20MetaMask)\x20to\x20that\x20address,\x20confirm\x20the\x20balance\x20arrived,\x20and\x20cross-chain\x20to\x20WOW\x20mainnet\x20(bridge_operation\x20cross_chain_evm_to_wow).\x20(3)\x20WOW\x20airdrop:\x20current\x20round\x20status,\x20pool\x20and\x20eligibility\x20are\x20published\x20live\x20at\x20https://wowok.net/airdrop.html\x20(referral:\x20https://wowok.net/refer.html)\x20—\x20open\x20that\x20page\x20rather\x20than\x20assuming\x20a\x20round\x20is\x20live\x20or\x20closed.\x20Query\x20wowok_buildin_info\x20with\x20info=\x27funding\x20guidance\x27\x20for\x20the\x20canonical\x20funding\x20guidance.'},'stock_exhausted':{'error_code':'stock_exhausted','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'Merchant-side\x20inventory\x20shortfall\x20(Move\x20service:16\x20E_STOCK_NOT_ENOUGH)\x20—\x20NOT\x20a\x20buyer\x20balance\x20problem,\x20so\x20a\x20faucet\x20claim\x20will\x20NOT\x20help.\x201.\x20Reduce\x20the\x20purchase\x20quantity\x20to\x20the\x20item\x27s\x20remaining\x20stock\x202.\x20Pick\x20another\x20sale\x20item\x203.\x20Ask\x20the\x20merchant\x20to\x20restock,\x20then\x20retry','user_prompt':'The\x20sale\x20item\x27s\x20stock\x20is\x20exhausted\x20for\x20the\x20requested\x20quantity.\x20Reduce\x20the\x20quantity,\x20choose\x20another\x20item,\x20or\x20ask\x20the\x20merchant\x20to\x20restock.'},'sale_suspended':{'error_code':'sale_suspended','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'The\x20merchant\x20suspended\x20this\x20sale\x20item\x20(Move\x20service:34\x20E_SALE_SUSPENDED).\x201.\x20Pick\x20another\x20(non-suspended)\x20item\x202.\x20Contact\x20the\x20merchant\x20to\x20resume\x20the\x20sale,\x20then\x20retry','user_prompt':'The\x20sale\x20item\x20is\x20suspended\x20by\x20the\x20merchant.\x20Please\x20choose\x20another\x20item\x20or\x20contact\x20the\x20merchant.'},'discount_invalid':{'error_code':'discount_invalid','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'The\x20discount\x20is\x20outside\x20its\x20[time_start,\x20time_end]\x20validity\x20window\x20(Move\x20service:35\x20E_DISCOUNT_TIME_INVALID).\x201.\x20Retry\x20without\x20the\x20discount\x202.\x20Ask\x20the\x20merchant\x20for\x20a\x20fresh\x20discount,\x20then\x20retry','user_prompt':'The\x20discount\x20is\x20not\x20valid\x20at\x20the\x20current\x20time\x20(outside\x20its\x20validity\x20window).\x20Buy\x20without\x20the\x20discount\x20or\x20ask\x20the\x20merchant\x20for\x20a\x20new\x20one.'},'rate_limit':{'error_code':'rate_limit','strategy':'retry','max_attempts':0x5,'automation':'full','detail':'Rate\x20limit\x20hit\x20(HTTP\x20429).\x20Exponential\x20backoff\x20retry:\x202s\x20/\x204s\x20/\x208s\x20/\x2016s\x20/\x2032s.\x20Avoid\x20parallel\x20calls\x20while\x20the\x20limit\x20window\x20is\x20active.'},'gas_exceeded':{'error_code':'gas_exceeded','strategy':'adjust_params','max_attempts':0x3,'automation':'semi','detail':'Gas\x20budget\x20exceeded.\x201.\x20Increase\x20the\x20gas_budget\x20parameter\x202.\x20Reduce\x20the\x20operation\x20size\x20(fewer\x20objects\x20per\x20transaction)\x203.\x20Retry\x20the\x20original\x20operation','user_prompt':'Gas\x20budget\x20exceeded.\x20Increase\x20the\x20gas\x20budget\x20or\x20reduce\x20the\x20operation\x20size,\x20then\x20retry.'},'bcs_error':{'error_code':'bcs_error','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'BCS\x20serialization/deserialization\x20error\x20—\x20a\x20parameter\x20does\x20not\x20match\x20the\x20expected\x20type/structure.\x201.\x20Query\x20the\x20operation\x20schema\x20(schema_query)\x202.\x20Fix\x20the\x20offending\x20parameter\x20type\x20(e.g.\x20BigInt\x20vs\x20number,\x20vector\x20element\x20type)\x203.\x20Retry','user_prompt':'A\x20parameter\x20failed\x20serialization.\x20Check\x20the\x20parameter\x20types\x20against\x20the\x20schema\x20and\x20retry.'},'signature_error':{'error_code':'signature_error','strategy':'switch_account','max_attempts':0x2,'automation':'semi','detail':'Signature\x20verification\x20failed.\x201.\x20Verify\x20the\x20account\x20is\x20not\x20suspended\x202.\x20Check\x20the\x20network\x20matches\x20the\x20account\x27s\x203.\x20Switch\x20to\x20a\x20healthy\x20account\x20and\x20retry','user_prompt':'Signature\x20verification\x20failed.\x20The\x20account\x20may\x20be\x20suspended\x20or\x20misconfigured.\x20Switch\x20accounts\x20or\x20check\x20the\x20configuration\x20and\x20retry.'},'config_error':{'error_code':'config_error','strategy':'escalate_human','max_attempts':0x1,'automation':'manual','detail':'Local\x20configuration\x20error\x20(network\x20not\x20specified,\x20persistent\x20storage\x20not\x20set).\x201.\x20Show\x20the\x20user\x20which\x20configuration\x20is\x20missing\x202.\x20Guide\x20the\x20user\x20through\x20the\x20account_operation/config\x20setup\x203.\x20Retry\x20after\x20the\x20user\x20fixes\x20it','user_prompt':'Local\x20configuration\x20is\x20incomplete.\x20Please\x20finish\x20the\x20account/network\x20setup\x20and\x20retry.'},'wip_verification_failed':{'error_code':'wip_verification_failed','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'WIP\x20file\x20not\x20publicly\x20reachable\x20/\x20hash\x20mismatch.\x201.\x20Deploy\x20the\x20.wip\x20file\x20to\x20a\x20public\x20URL\x20(GitHub\x20Pages\x20/\x20IPFS\x20/\x20own\x20site)\x202.\x20Update\x20the\x20sale\x27s\x20wip\x20URL\x203.\x20Re-run\x20the\x20operation','user_prompt':'The\x20WIP\x20file\x20could\x20not\x20be\x20verified\x20from\x20a\x20public\x20URL.\x20Deploy\x20it\x20(GitHub\x20Pages\x20or\x20IPFS),\x20update\x20the\x20sale\x27s\x20WIP\x20URL,\x20and\x20retry.'},'network_error':{'error_code':'network_error','strategy':'retry','max_attempts':0x5,'automation':'full','detail':'Exponential\x20backoff\x20retry:\x201s\x20/\x202s\x20/\x204s\x20/\x208s\x20/\x2016s.\x20Switch\x20RPC\x20node\x20if\x20available.'},'guard_rejected':{'error_code':'guard_rejected','strategy':'fill_submission','max_attempts':0x2,'automation':'semi','detail':'1.\x20Parse\x20Guard\x20table\x20structure\x202.\x20Prompt\x20user\x20to\x20fill\x20submission\x20fields\x203.\x20Resubmit\x20with\x20call_with_submission','user_prompt':'Guard\x20verification\x20rejected.\x20Please\x20fill\x20in\x20the\x20required\x20submission\x20data\x20and\x20resubmit.'},'time_lock_not_elapsed':{'error_code':'time_lock_not_elapsed','strategy':'wait_and_retry','max_attempts':0x1,'automation':'semi','detail':'1.\x20Verify\x20Service\x20is\x20paused\x20(bPaused=true).\x20If\x20not,\x20submit\x20pause=true\x20first.\x202.\x20Wait\x20until\x20paused_time\x20+\x20setting_lock_duration\x20<=\x20current\x20clock.\x203.\x20Retry\x20the\x20original\x20operation.\x20Do\x20NOT\x20recreate\x20the\x20object.','user_prompt':'Service\x20setting_lock_duration\x20has\x20not\x20elapsed\x20since\x20the\x20Service\x20was\x20paused.\x20Please\x20pause\x20the\x20Service\x20if\x20it\x20is\x20not\x20already\x20paused,\x20wait\x20for\x20the\x20lock\x20duration\x20to\x20elapse,\x20then\x20retry.'},'immutable_violation':{'error_code':'immutable_violation','strategy':'recreate','max_attempts':0x1,'automation':'semi','detail':'1.\x20Stop\x20modification\x20attempt\x202.\x20Evaluate\x20creating\x20a\x20new\x20object\x20as\x20replacement\x203.\x20Re-plan\x20affected\x20phases','user_prompt':'Cannot\x20modify\x20an\x20immutable\x20object.\x20A\x20new\x20object\x20must\x20be\x20created\x20as\x20a\x20replacement.\x20Confirm\x20to\x20proceed\x20with\x20recreation.'},'permission_denied':{'error_code':'permission_denied','strategy':'switch_account','max_attempts':0x2,'automation':'semi','detail':'1.\x20Query\x20object\x27s\x20permission_guard\x202.\x20List\x20accounts\x20with\x20permission\x203.\x20Switch\x20account\x20or\x20prompt\x20user\x20to\x20add\x20permission','user_prompt':'Current\x20account\x20lacks\x20permission\x20for\x20this\x20operation.\x20Switch\x20to\x20an\x20authorized\x20account\x20or\x20update\x20the\x20Permission\x20object.'},'object_not_found':{'error_code':'object_not_found','strategy':'query_and_retry','max_attempts':0x3,'automation':'semi','detail':'1.\x20Re-query\x20the\x20object\x20(may\x20be\x20sync\x20delay)\x202.\x20If\x20truly\x20absent,\x20search\x20for\x20similar\x20objects\x203.\x20Prompt\x20user\x20to\x20reselect','user_prompt':'Referenced\x20object\x20not\x20found.\x20It\x20may\x20be\x20a\x20synchronization\x20delay.\x20Retrying...\x20If\x20the\x20issue\x20persists,\x20please\x20select\x20a\x20valid\x20object.'},'state_conflict':{'error_code':'state_conflict','strategy':'adjust_params','max_attempts':0x2,'automation':'full','detail':'1.\x20Query\x20object\x27s\x20current\x20true\x20state\x202.\x20Update\x20ODG\x20status\x20annotations\x203.\x20Adjust\x20subsequent\x20operations\x20(e.g.,\x20skip\x20completed\x20steps)'},'invalid_parameter':{'error_code':'invalid_parameter','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'1.\x20Query\x20the\x20relevant\x20schema\x202.\x20Auto-fix\x20obvious\x20errors\x20(e.g.,\x20BigInt\x20vs\x20string)\x203.\x20If\x20unfixable,\x20prompt\x20user','user_prompt':'Parameter\x20validation\x20failed.\x20Please\x20check\x20the\x20parameter\x20types\x20and\x20values\x20against\x20the\x20schema\x20and\x20retry.'},'unknown':{'error_code':'unknown','strategy':'escalate_human','max_attempts':0x1,'automation':'manual','detail':'1.\x20Report\x20full\x20error\x20context\x20to\x20the\x20user\x202.\x20Escalate\x20to\x20human\x20intervention\x203.\x20Flag\x20for\x20error-classification\x20rule\x20addition','user_prompt':'An\x20unclassified\x20error\x20occurred.\x20Please\x20review\x20the\x20error\x20details\x20and\x20contact\x20support\x20if\x20needed.'}};const operationAttempts=new Map();function getAttemptCount(a,b){const c=operationAttempts['get'](a);if(!c)return 0x0;return c['get'](b)??0x0;}function incrementAttempt(a,b){!operationAttempts['has'](a)&&operationAttempts['set'](a,new Map());const c=operationAttempts['get'](a),d=(c['get'](b)??0x0)+0x1;return c['set'](b,d),d;}function getTotalAttempts(a){const b=operationAttempts['get'](a);if(!b)return 0x0;let c=0x0;for(const d of b['values']())c+=d;return c;}export function resetAttempts(a){operationAttempts['delete'](a);}export function recover(a,b,c){const d=RECOVERY_RULES[a]??RECOVERY_RULES['unknown'],e=0x5,f=getTotalAttempts(b),g=getAttemptCount(b,a);if(f>=e)return{'strategy':'stop','should_retry':![],'max_attempts':e,'current_attempt':f,'detail':'Total\x20retry\x20limit\x20('+e+')\x20reached\x20for\x20operation\x20'+b+'.\x20Escalating\x20to\x20human\x20intervention.','user_prompt':'Maximum\x20retry\x20attempts\x20reached.\x20Manual\x20intervention\x20required.'};if(g>=d['max_attempts'])return{'strategy':'escalate_human','should_retry':![],'max_attempts':d['max_attempts'],'current_attempt':g,'detail':'Per-error-code\x20retry\x20limit\x20('+d['max_attempts']+')\x20reached\x20for\x20'+a+'.\x20Escalating\x20to\x20human.','user_prompt':'Recovery\x20attempts\x20for\x20'+a+'\x20exhausted.\x20Manual\x20intervention\x20required.'};const h=incrementAttempt(b,a);return{'strategy':d['strategy'],'should_retry':d['automation']==='full'||h<d['max_attempts'],'max_attempts':d['max_attempts'],'current_attempt':h,'adjusted_params':d['adjusted_params'],'user_prompt':d['user_prompt'],'detail':d['detail']};}export function getBackoffDelay(a){return Math['pow'](0x2,a-0x1)*0x3e8;}
1
+ export const RECOVERY_RULES={'insufficient_balance':{'error_code':'insufficient_balance','strategy':'claim_faucet','max_attempts':0x3,'automation':'semi','detail':'1.\x20Testnet:\x20claim\x20WOW\x20from\x20the\x20faucet\x202.\x20Mainnet:\x20transfer\x20ETH/USDT/USDC/WBTC\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge\x20(query\x20active\x20EVM\x20account\x20→\x20top\x20up\x20from\x20external\x20wallet\x20→\x20confirm\x20→\x20cross-chain)\x203.\x20Point\x20the\x20user\x20to\x20the\x20live\x20airdrop\x20page\x20(https://wowok.net/airdrop.html)\x20for\x20the\x20current\x20round\x204.\x20Retry\x20original\x20operation','user_prompt':'Insufficient\x20balance\x20for\x20gas\x20or\x20operation.\x20How\x20to\x20obtain\x20WOW\x20tokens:\x20(1)\x20Testnet\x20—\x20claim\x20WOW\x20from\x20the\x20faucet\x20(https://faucet.testnet.wowok.net);\x20all\x20merchant\x20and\x20order\x20testing\x20can\x20use\x20WOW\x20as\x20the\x20payment\x20token.\x20(2)\x20Mainnet\x20—\x20transfer\x20ETH\x20/\x20USDT\x20/\x20USDC\x20/\x20WBTC\x20via\x20the\x20ETH\x20mainnet\x20cross-chain\x20bridge:\x20first\x20query\x20the\x20active\x20EVM\x20account\x20(bridge_operation\x20query_active_evm_account,\x20auto-generated\x20on\x20first\x20use),\x20then\x20transfer\x20from\x20an\x20external\x20wallet\x20(e.g.\x20MetaMask)\x20to\x20that\x20address,\x20confirm\x20the\x20balance\x20arrived,\x20and\x20cross-chain\x20to\x20WOW\x20mainnet\x20(bridge_operation\x20cross_chain_evm_to_wow).\x20(3)\x20WOW\x20airdrop:\x20current\x20round\x20status,\x20pool\x20and\x20eligibility\x20are\x20published\x20live\x20at\x20https://wowok.net/airdrop.html\x20(referral:\x20https://wowok.net/refer.html)\x20—\x20open\x20that\x20page\x20rather\x20than\x20assuming\x20a\x20round\x20is\x20live\x20or\x20closed.\x20Query\x20wowok_buildin_info\x20with\x20info=\x27funding\x20guidance\x27\x20for\x20the\x20canonical\x20funding\x20guidance.'},'stock_exhausted':{'error_code':'stock_exhausted','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'Merchant-side\x20inventory\x20shortfall\x20(Move\x20service:16\x20E_STOCK_NOT_ENOUGH)\x20—\x20NOT\x20a\x20buyer\x20balance\x20problem,\x20so\x20a\x20faucet\x20claim\x20will\x20NOT\x20help.\x201.\x20Reduce\x20the\x20purchase\x20quantity\x20to\x20the\x20item\x27s\x20remaining\x20stock\x202.\x20Pick\x20another\x20sale\x20item\x203.\x20Ask\x20the\x20merchant\x20to\x20restock,\x20then\x20retry','user_prompt':'The\x20sale\x20item\x27s\x20stock\x20is\x20exhausted\x20for\x20the\x20requested\x20quantity.\x20Reduce\x20the\x20quantity,\x20choose\x20another\x20item,\x20or\x20ask\x20the\x20merchant\x20to\x20restock.'},'sale_suspended':{'error_code':'sale_suspended','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'The\x20merchant\x20suspended\x20this\x20sale\x20item\x20(Move\x20service:34\x20E_SALE_SUSPENDED).\x201.\x20Pick\x20another\x20(non-suspended)\x20item\x202.\x20Contact\x20the\x20merchant\x20to\x20resume\x20the\x20sale,\x20then\x20retry','user_prompt':'The\x20sale\x20item\x20is\x20suspended\x20by\x20the\x20merchant.\x20Please\x20choose\x20another\x20item\x20or\x20contact\x20the\x20merchant.'},'discount_invalid':{'error_code':'discount_invalid','strategy':'adjust_params','max_attempts':0x1,'automation':'semi','detail':'The\x20discount\x20is\x20outside\x20its\x20[time_start,\x20time_end]\x20validity\x20window\x20(Move\x20service:35\x20E_DISCOUNT_TIME_INVALID).\x201.\x20Retry\x20without\x20the\x20discount\x202.\x20Ask\x20the\x20merchant\x20for\x20a\x20fresh\x20discount,\x20then\x20retry','user_prompt':'The\x20discount\x20is\x20not\x20valid\x20at\x20the\x20current\x20time\x20(outside\x20its\x20validity\x20window).\x20Buy\x20without\x20the\x20discount\x20or\x20ask\x20the\x20merchant\x20for\x20a\x20new\x20one.'},'rate_limit':{'error_code':'rate_limit','strategy':'retry','max_attempts':0x5,'automation':'full','detail':'Rate\x20limit\x20hit\x20(HTTP\x20429).\x20Exponential\x20backoff\x20retry:\x202s\x20/\x204s\x20/\x208s\x20/\x2016s\x20/\x2032s.\x20Avoid\x20parallel\x20calls\x20while\x20the\x20limit\x20window\x20is\x20active.'},'gas_exceeded':{'error_code':'gas_exceeded','strategy':'adjust_params','max_attempts':0x3,'automation':'semi','detail':'Gas\x20budget\x20exceeded.\x201.\x20Increase\x20the\x20gas_budget\x20parameter\x202.\x20Reduce\x20the\x20operation\x20size\x20(fewer\x20objects\x20per\x20transaction)\x203.\x20Retry\x20the\x20original\x20operation','user_prompt':'Gas\x20budget\x20exceeded.\x20Increase\x20the\x20gas\x20budget\x20or\x20reduce\x20the\x20operation\x20size,\x20then\x20retry.'},'bcs_error':{'error_code':'bcs_error','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'BCS\x20serialization/deserialization\x20error\x20—\x20a\x20parameter\x20does\x20not\x20match\x20the\x20expected\x20type/structure.\x201.\x20Query\x20the\x20operation\x20schema\x20(schema_query)\x202.\x20Fix\x20the\x20offending\x20parameter\x20type\x20(e.g.\x20BigInt\x20vs\x20number,\x20vector\x20element\x20type)\x203.\x20Retry','user_prompt':'A\x20parameter\x20failed\x20serialization.\x20Check\x20the\x20parameter\x20types\x20against\x20the\x20schema\x20and\x20retry.'},'signature_error':{'error_code':'signature_error','strategy':'switch_account','max_attempts':0x2,'automation':'semi','detail':'Signature\x20verification\x20failed.\x201.\x20Verify\x20the\x20account\x20is\x20not\x20suspended\x202.\x20Check\x20the\x20network\x20matches\x20the\x20account\x27s\x203.\x20Switch\x20to\x20a\x20healthy\x20account\x20and\x20retry','user_prompt':'Signature\x20verification\x20failed.\x20The\x20account\x20may\x20be\x20suspended\x20or\x20misconfigured.\x20Switch\x20accounts\x20or\x20check\x20the\x20configuration\x20and\x20retry.'},'config_error':{'error_code':'config_error','strategy':'escalate_human','max_attempts':0x1,'automation':'manual','detail':'Local\x20configuration\x20error\x20(network\x20not\x20specified,\x20persistent\x20storage\x20not\x20set).\x201.\x20Show\x20the\x20user\x20which\x20configuration\x20is\x20missing\x202.\x20Guide\x20the\x20user\x20through\x20the\x20account_operation/config\x20setup\x203.\x20Retry\x20after\x20the\x20user\x20fixes\x20it','user_prompt':'Local\x20configuration\x20is\x20incomplete.\x20Please\x20finish\x20the\x20account/network\x20setup\x20and\x20retry.'},'wip_verification_failed':{'error_code':'wip_verification_failed','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'WIP\x20file\x20not\x20publicly\x20reachable\x20/\x20hash\x20mismatch.\x201.\x20Deploy\x20the\x20.wip\x20file\x20to\x20a\x20public\x20URL\x20(GitHub\x20Pages\x20/\x20IPFS\x20/\x20own\x20site)\x202.\x20Update\x20the\x20sale\x27s\x20wip\x20URL\x203.\x20Re-run\x20the\x20operation','user_prompt':'The\x20WIP\x20file\x20could\x20not\x20be\x20verified\x20from\x20a\x20public\x20URL.\x20Deploy\x20it\x20(GitHub\x20Pages\x20or\x20IPFS),\x20update\x20the\x20sale\x27s\x20WIP\x20URL,\x20and\x20retry.'},'network_error':{'error_code':'network_error','strategy':'retry','max_attempts':0x5,'automation':'full','detail':'Exponential\x20backoff\x20retry:\x201s\x20/\x202s\x20/\x204s\x20/\x208s\x20/\x2016s.\x20Switch\x20RPC\x20node\x20if\x20available.'},'transaction_expired':{'error_code':'transaction_expired','strategy':'retry','max_attempts':0x3,'automation':'full','detail':'The\x20transaction\x20expired\x20before\x20execution\x20(epoch\x20boundary\x20or\x20validator/gateway\x20outage)\x20—\x20it\x20did\x20NOT\x20land\x20and\x20nothing\x20was\x20committed.\x20Bounded\x20backoff\x20retry:\x2010s\x20/\x2030s\x20/\x2060s,\x20resubmit\x20the\x20SAME\x20call\x20unchanged.\x20If\x20a\x20dry_run\x20passes\x20while\x20the\x20real\x20call\x20keeps\x20failing,\x20the\x20fault\x20is\x20chain-side\x20—\x20wait\x20it\x20out.\x20Verify\x20with\x20onchain_events\x20if\x20unsure.'},'guard_rejected':{'error_code':'guard_rejected','strategy':'fill_submission','max_attempts':0x2,'automation':'semi','detail':'1.\x20Parse\x20Guard\x20table\x20structure\x202.\x20If\x20the\x20Guard\x20defines\x20submission\x20items,\x20fill\x20them\x20and\x20resubmit\x20with\x20call_with_submission\x203.\x20If\x20it\x20defines\x20none,\x20the\x20rule\x20evaluated\x20false\x20—\x20adjust\x20the\x20call\x27s\x20parameters\x20(signer/query/state)\x20or\x20change\x20the\x20Guard\x20(docs#40)','user_prompt':'Guard\x20verification\x20rejected.\x20If\x20the\x20Guard\x20defines\x20submission\x20items,\x20fill\x20in\x20the\x20required\x20submission\x20data\x20and\x20resubmit;\x20if\x20it\x20defines\x20none,\x20the\x20Guard\x20rule\x20evaluated\x20false\x20—\x20adjust\x20this\x20call\x27s\x20parameters\x20or\x20change\x20the\x20Guard\x20rule.'},'time_lock_not_elapsed':{'error_code':'time_lock_not_elapsed','strategy':'wait_and_retry','max_attempts':0x1,'automation':'semi','detail':'1.\x20Verify\x20Service\x20is\x20paused\x20(bPaused=true).\x20If\x20not,\x20submit\x20pause=true\x20first.\x202.\x20Wait\x20until\x20paused_time\x20+\x20setting_lock_duration\x20<=\x20current\x20clock.\x203.\x20Retry\x20the\x20original\x20operation.\x20Do\x20NOT\x20recreate\x20the\x20object.','user_prompt':'Service\x20setting_lock_duration\x20has\x20not\x20elapsed\x20since\x20the\x20Service\x20was\x20paused.\x20Please\x20pause\x20the\x20Service\x20if\x20it\x20is\x20not\x20already\x20paused,\x20wait\x20for\x20the\x20lock\x20duration\x20to\x20elapse,\x20then\x20retry.'},'immutable_violation':{'error_code':'immutable_violation','strategy':'recreate','max_attempts':0x1,'automation':'semi','detail':'1.\x20Stop\x20modification\x20attempt\x202.\x20Evaluate\x20creating\x20a\x20new\x20object\x20as\x20replacement\x203.\x20Re-plan\x20affected\x20phases','user_prompt':'Cannot\x20modify\x20an\x20immutable\x20object.\x20A\x20new\x20object\x20must\x20be\x20created\x20as\x20a\x20replacement.\x20Confirm\x20to\x20proceed\x20with\x20recreation.'},'permission_denied':{'error_code':'permission_denied','strategy':'switch_account','max_attempts':0x2,'automation':'semi','detail':'1.\x20Query\x20object\x27s\x20permission_guard\x202.\x20List\x20accounts\x20with\x20permission\x203.\x20Switch\x20account\x20or\x20prompt\x20user\x20to\x20add\x20permission','user_prompt':'Current\x20account\x20lacks\x20permission\x20for\x20this\x20operation.\x20Switch\x20to\x20an\x20authorized\x20account\x20or\x20update\x20the\x20Permission\x20object.'},'object_not_found':{'error_code':'object_not_found','strategy':'query_and_retry','max_attempts':0x3,'automation':'semi','detail':'1.\x20Verify\x20the\x20referenced\x20name/ID\x20spelling\x20(local_mark_list)\x20and\x20that\x20the\x20object\x20exists\x20on\x20the\x20current\x20network\x202.\x20If\x20recently\x20created,\x20re-query\x20the\x20object\x20(may\x20be\x20sync\x20delay)\x203.\x20If\x20truly\x20absent,\x20search\x20for\x20similar\x20objects\x204.\x20Prompt\x20user\x20to\x20reselect','user_prompt':'Referenced\x20object\x20not\x20found.\x20First\x20verify\x20the\x20name/ID\x20spelling\x20and\x20that\x20the\x20object\x20exists\x20on\x20the\x20current\x20network;\x20if\x20it\x20was\x20created\x20recently,\x20this\x20may\x20be\x20a\x20synchronization\x20delay\x20—\x20retry.\x20If\x20the\x20issue\x20persists,\x20please\x20select\x20a\x20valid\x20object.'},'state_conflict':{'error_code':'state_conflict','strategy':'adjust_params','max_attempts':0x2,'automation':'full','detail':'1.\x20Query\x20object\x27s\x20current\x20true\x20state\x202.\x20Update\x20ODG\x20status\x20annotations\x203.\x20Adjust\x20subsequent\x20operations\x20(e.g.,\x20skip\x20completed\x20steps)'},'invalid_parameter':{'error_code':'invalid_parameter','strategy':'adjust_params','max_attempts':0x2,'automation':'semi','detail':'1.\x20Query\x20the\x20relevant\x20schema\x202.\x20Auto-fix\x20obvious\x20errors\x20(e.g.,\x20BigInt\x20vs\x20string)\x203.\x20If\x20unfixable,\x20prompt\x20user','user_prompt':'Parameter\x20validation\x20failed.\x20Please\x20check\x20the\x20parameter\x20types\x20and\x20values\x20against\x20the\x20schema\x20and\x20retry.'},'unknown':{'error_code':'unknown','strategy':'escalate_human','max_attempts':0x1,'automation':'manual','detail':'1.\x20Report\x20full\x20error\x20context\x20to\x20the\x20user\x202.\x20Escalate\x20to\x20human\x20intervention\x203.\x20Flag\x20for\x20error-classification\x20rule\x20addition','user_prompt':'An\x20unclassified\x20error\x20occurred.\x20Please\x20review\x20the\x20error\x20details\x20and\x20contact\x20support\x20if\x20needed.'}};const operationAttempts=new Map();function getAttemptCount(a,b){const c=operationAttempts['get'](a);if(!c)return 0x0;return c['get'](b)??0x0;}function incrementAttempt(a,b){!operationAttempts['has'](a)&&operationAttempts['set'](a,new Map());const c=operationAttempts['get'](a),d=(c['get'](b)??0x0)+0x1;return c['set'](b,d),d;}function getTotalAttempts(a){const b=operationAttempts['get'](a);if(!b)return 0x0;let c=0x0;for(const d of b['values']())c+=d;return c;}export function resetAttempts(a){operationAttempts['delete'](a);}export function recover(a,b,c){const d=RECOVERY_RULES[a]??RECOVERY_RULES['unknown'],e=0x5,f=getTotalAttempts(b),g=getAttemptCount(b,a);if(f>=e)return{'strategy':'stop','should_retry':![],'max_attempts':e,'current_attempt':f,'detail':'Total\x20retry\x20limit\x20('+e+')\x20reached\x20for\x20operation\x20'+b+'.\x20Escalating\x20to\x20human\x20intervention.','user_prompt':'Maximum\x20retry\x20attempts\x20reached.\x20Manual\x20intervention\x20required.'};if(g>=d['max_attempts'])return{'strategy':'escalate_human','should_retry':![],'max_attempts':d['max_attempts'],'current_attempt':g,'detail':'Per-error-code\x20retry\x20limit\x20('+d['max_attempts']+')\x20reached\x20for\x20'+a+'.\x20Escalating\x20to\x20human.','user_prompt':'Recovery\x20attempts\x20for\x20'+a+'\x20exhausted.\x20Manual\x20intervention\x20required.'};const h=incrementAttempt(b,a);return{'strategy':d['strategy'],'should_retry':d['automation']==='full'||h<d['max_attempts'],'max_attempts':d['max_attempts'],'current_attempt':h,'adjusted_params':d['adjusted_params'],'user_prompt':d['user_prompt'],'detail':d['detail']};}export function getBackoffDelay(a){return Math['pow'](0x2,a-0x1)*0x3e8;}
@@ -1 +1 @@
1
- import{mkdtempSync,writeFileSync}from'node:fs';import{tmpdir}from'node:os';import{join}from'node:path';import{afterAll,beforeAll,describe,expect,it}from'vitest';import{beginPolicyRun,endPolicyRun,factoryRulePack,getJudgmentDoc,judgmentStatus}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';import{serviceAllocatorAuditNodeAnalyzer}from'./service-allocator-audit-node.js';const CONFIG_DIR=mkdtempSync(join(tmpdir(),'wowok-alloc-audit-'));process['env']['WOWOK_CONFIG_DIR']=CONFIG_DIR;const PACK_IDS=['RC-FIND-01','RC-FIND-02','RC-FIND-03','RC-FIND-04','RC-FIND-05','RC-FIND-06','RC-FIND-07','RC-FIND-08','RC-GAP','RC-SUMMARY'];function rule(a,b){const c=factoryRulePack('alloc_audit');if(!c)throw new Error('alloc_audit\x20factory\x20pack\x20missing');const d=c['rules']['find'](e=>e['rule_id']===a);if(!d)throw new Error('rule\x20'+a+'\x20missing');return evaluateRuleBook([d],b)['findings'][0x0];}const BASE={'host_service':'0xsvc','code':'RC-FIND-01','base_level':'high','evidence_paths':'(root)','evidence_count':0x0};function resnapshot(){endPolicyRun(),beginPolicyRun();}beforeAll(()=>{beginPolicyRun();}),afterAll(()=>{endPolicyRun();}),describe('alloc_audit\x20factory\x20parity\x20—\x20per-finding\x20rules',()=>{it('the\x20pack\x20carries\x20exactly\x20the\x20canonical\x20emission\x20ids',()=>{const a=factoryRulePack('alloc_audit');expect(a)['not']['toBeNull'](),expect(a['rules']['map'](b=>b['rule_id'])['sort']())['toEqual']([...PACK_IDS]['sort']());}),it('fact:base_level\x20passes\x20the\x20kernel\x20severity\x20through\x20unchanged',()=>{for(const a of['high','medium','low']){expect(rule('RC-FIND-01',{...BASE,'base_level':a})?.['level'])['toBe'](a);}}),it('copy\x20is\x20pack-owned\x20and\x20interpolates\x20the\x20kernel\x20facts',()=>{const a=rule('RC-FIND-01',{...BASE,'evidence_paths':'root.and(0)'});expect(a?.['title'])['toBe']('Fund\x20theft\x20risk:\x20Signer\x20recipient\x20without\x20caller\x20identity\x20constraint'),expect(a?.['description'])['toContain']('service\x200xsvc'),expect(a?.['description'])['toContain']('rule\x20RC-FIND-01,\x20evidence\x20paths\x20root.and(0)'),expect(a?.['mitigation'])['toContain']('do\x20NOT\x20pay\x20this\x20service\x20before\x20the\x20fix');}),it('fixed\x20levels\x20hold\x20where\x20the\x20kernel\x20hardcoded\x20them',()=>{expect(rule('RC-FIND-05',{...BASE,'code':'RC-FIND-05','base_level':'high'})?.['level'])['toBe']('medium'),expect(rule('RC-FIND-06',{...BASE,'code':'RC-FIND-06','base_level':'high'})?.['level'])['toBe']('low'),expect(rule('RC-FIND-07',{...BASE,'code':'RC-FIND-07','base_level':'high'})?.['level'])['toBe']('medium');}),it('shortfall\x20findings\x20(05/07)\x20carry\x20loss\x20parties\x20only\x20and\x20are\x20never\x20downgraded',()=>{for(const a of['RC-FIND-05','RC-FIND-07']){const b=rule(a,{...BASE,'code':a});expect(b?.['exposure']?.['gainPaths'])['toHaveLength'](0x0),expect(b?.['exposure']?.['lossParties']['length'])['toBeGreaterThan'](0x0),expect(b?.['exposure']?.['verdict'])['toBe']('confirmed'),expect(b?.['level'])['not']['toBe']('info');}expect(rule('RC-FIND-05',{...BASE,'code':'RC-FIND-05'})?.['exposure']?.['lossParties']['map'](c=>c['role']))['toEqual'](['supplier','buyer']);}),it('RC-FIND-08\x20keeps\x20its\x20level\x20as\x20pending-disclosure\x20(undecided\x20predicate)',()=>{const a=rule('RC-FIND-08',{...BASE,'code':'RC-FIND-08','base_level':'medium','evidence_count':0x2});expect(a?.['level'])['toBe']('medium'),expect(a?.['description'])['toContain']('composes\x202\x20sub-guard(s)'),expect(a?.['exposure']?.['verdict'])['toBe']('pending-disclosure'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('unverifiable');}),it('an\x20unknown\x20canonical\x20code\x20fires\x20no\x20case\x20(kernel\x20fallback\x20stays\x20in\x20charge)',()=>{const a=factoryRulePack('alloc_audit'),b=a['rules']['find'](d=>d['rule_id']==='RC-FIND-01'),{findings:c}=evaluateRuleBook([b],{...BASE,'code':'RC-FIND-99'});expect(c)['toHaveLength'](0x0);});}),describe('alloc_audit\x20factory\x20parity\x20—\x20gap\x20and\x20verdict',()=>{it('RC-GAP\x20emits\x20info\x20with\x20the\x20unfetched\x20evidence\x20interpolated',()=>{const a=rule('RC-GAP',{'host_service':'0xsvc','unfetched_count':0x2,'unfetched_list':'0xa,\x200xb\x20(guard.relies)'});expect(a?.['level'])['toBe']('info'),expect(a?.['title'])['toContain']('evidence\x20gap'),expect(a?.['description'])['toContain']('references\x202\x20guard(s)'),expect(a?.['description'])['toContain']('0xa,\x200xb\x20(guard.relies)'),expect(a?.['exposure']?.['gainPaths'])['toHaveLength'](0x0),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');}),it('RC-SUMMARY\x20—\x20unsafe\x20wins\x20at\x20high,\x20with\x20and\x20without\x20the\x20residual\x20suffix',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':!![],'resolution_required':![]}));expect(a?.['level'])['toBe']('high'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists'),expect(a?.['description'])['toContain']('WARNING:\x20an\x20unbound\x20Signer\x20direct-pay\x20path\x20exists'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('viable'),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');const b=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':!![],'resolution_required':!![]}));expect(b?.['level'])['toBe']('high'),expect(b?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists\x20(residual\x20requires\x20explicit\x20decision)');}),it('RC-SUMMARY\x20—\x20safe\x20+\x20residual\x20is\x20medium\x20conditional\x20with\x20the\x20destinations\x20interpolated',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':![],'resolution_required':!![]}));expect(a?.['level'])['toBe']('medium'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20destination\x20safe\x20(residual\x20requires\x20explicit\x20decision)'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('conditional'),expect(a?.['exposure']?.['lossParties'][0x0]?.['basis'])['toContain']('0xmerchant'),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');}),it('RC-SUMMARY\x20—\x20fully\x20safe\x20downgrades\x20to\x20info\x20(redirect\x20provably\x20blocked)',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':![],'resolution_required':![]}));expect(a?.['level'])['toBe']('info'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20destination\x20safe'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('blocked'),expect(a?.['exposure']?.['verdict'])['toBe']('downgraded'),expect(a?.['exposure']?.['baseSeverity'])['toBe']('info');});});function summaryFacts(a){return{'host_service':'0xsvc','allocator_count':0x1,'guard_count':0x1,'destinations_text':'0xmerchant','dest_unsafe':a['dest_unsafe'],'resolution_required':a['resolution_required'],'audit_summary':'Analyzed\x201\x20allocator(s):\x201\x20actionable,\x200\x20unavoidable.'};}const GUARD='0xguard0000000000000000000000000000000000000000000000000000000001';function serviceNode(){return{'id':'0xsvc','kind':'object','state':'fetched','origins':[],'depth':0x0,'raw':{'data':{'order_allocators':{'allocators':[{'guard':GUARD,'sharing':[{'who':{'Signer':!![]},'sharing':'10000','mode':'Rate'}]}]}}}};}function guardNode(){return{'id':GUARD,'kind':'object','state':'fetched','origins':[],'depth':0x1,'raw':{'data':{'table':[],'root':{'type':'value','value':!![]}}}};}function viewport(){return{'visibleEdges':[{'id':'service.order_allocator_guard|0xsvc→'+GUARD,'schema':'service.order_allocator_guard','family':'F','from':'0xsvc','to':GUARD,'retention':'complete','observedAt':0x0}],'graph':{'nodes':new Map([[GUARD,guardNode()]])}};}describe('alloc_audit\x20binding\x20—\x20end\x20to\x20end',()=>{it('a\x20signer-recipient\x20service\x20yields\x20the\x20pack-driven\x20theft\x20finding\x20+\x20unsafe\x20verdict',()=>{const a=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(a)['toHaveLength'](0x3);const [b,c,d]=a;expect(b['id'])['toBe']('ALC1:0xsvc#0'),expect(b['title'])['toBe']('Fund\x20theft\x20risk:\x20Signer\x20recipient\x20without\x20caller\x20identity\x20constraint'),expect(b['severity'])['toBe']('high'),expect(b['exposure']?.['verdict'])['toBe']('confirmed'),expect(b['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('viable'),expect(b['detail'])['toContain']('service\x200xsvc'),expect(c['id'])['toBe']('ALC1:0xsvc#1'),expect(c['title'])['toBe']('Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run'),expect(c['severity'])['toBe']('low'),expect(c['exposure']?.['verdict'])['toBe']('confirmed'),expect(d['id'])['toBe']('ALC1:0xsvc#2'),expect(d['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists'),expect(d['severity'])['toBe']('high'),expect(d['detail'])['toContain']('1\x20allocator(s)\x20/\x201\x20resolved\x20guard(s)');}),it('a\x20user\x20disable\x20suppresses\x20the\x20theft\x20finding;\x20the\x20verdict\x20stays',()=>{writeFileSync(join(CONFIG_DIR,'judgment.json'),JSON['stringify']({'version':0x1,'rules':{'domains':{'alloc_audit':{'rules':[{'rule_id':'RC-FIND-01','enabled':![]}]}}}}),'utf-8'),resnapshot();const a=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(a['map'](c=>c['title']))['toEqual'](['Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run','Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists']);const b=judgmentStatus();expect(b['user_doc_loaded'])['toBe'](!![]);}),it('a\x20fact:\x20reference\x20outside\x20the\x20factory\x20vocabulary\x20is\x20rejected\x20loudly;\x20the\x20factory\x20keeps\x20serving',()=>{writeFileSync(join(CONFIG_DIR,'judgment.json'),JSON['stringify']({'version':0x1,'rules':{'domains':{'alloc_audit':{'rules':[{'rule_id':'RC-FIND-01','cases':[{'when':{'field':'code','op':'eq','value':'RC-FIND-01'},'level':'fact:not_a_kernel_fact','title':'t','description':'d'}]}]}}}}),'utf-8'),void getJudgmentDoc(),resnapshot();const a=judgmentStatus();expect(a['last_reload_error'])['toContain']('fact:not_a_kernel_fact'),expect(a['last_reload_error'])['toContain']('RC-FIND-01');const b=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(b['map'](c=>c['title']))['toEqual'](['Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run','Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists']);});});
1
+ import{mkdtempSync,writeFileSync}from'node:fs';import{tmpdir}from'node:os';import{join}from'node:path';import{afterAll,beforeAll,describe,expect,it}from'vitest';import{beginPolicyRun,endPolicyRun,factoryRulePack,getJudgmentDoc,judgmentStatus}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';import{serviceAllocatorAuditNodeAnalyzer}from'./service-allocator-audit-node.js';const CONFIG_DIR=mkdtempSync(join(tmpdir(),'wowok-alloc-audit-'));process['env']['WOWOK_CONFIG_DIR']=CONFIG_DIR;const PACK_IDS=['RC-FIND-01','RC-FIND-02','RC-FIND-03','RC-FIND-04','RC-FIND-05','RC-FIND-06','RC-FIND-07','RC-FIND-08','RC-FIND-09','RC-GAP','RC-SUMMARY'];function rule(a,b){const c=factoryRulePack('alloc_audit');if(!c)throw new Error('alloc_audit\x20factory\x20pack\x20missing');const d=c['rules']['find'](e=>e['rule_id']===a);if(!d)throw new Error('rule\x20'+a+'\x20missing');return evaluateRuleBook([d],b)['findings'][0x0];}const BASE={'host_service':'0xsvc','code':'RC-FIND-01','base_level':'high','evidence_paths':'(root)','evidence_count':0x0};function resnapshot(){endPolicyRun(),beginPolicyRun();}beforeAll(()=>{beginPolicyRun();}),afterAll(()=>{endPolicyRun();}),describe('alloc_audit\x20factory\x20parity\x20—\x20per-finding\x20rules',()=>{it('the\x20pack\x20carries\x20exactly\x20the\x20canonical\x20emission\x20ids',()=>{const a=factoryRulePack('alloc_audit');expect(a)['not']['toBeNull'](),expect(a['rules']['map'](b=>b['rule_id'])['sort']())['toEqual']([...PACK_IDS]['sort']());}),it('fact:base_level\x20passes\x20the\x20kernel\x20severity\x20through\x20unchanged',()=>{for(const a of['high','medium','low']){expect(rule('RC-FIND-01',{...BASE,'base_level':a})?.['level'])['toBe'](a);}}),it('copy\x20is\x20pack-owned\x20and\x20interpolates\x20the\x20kernel\x20facts',()=>{const a=rule('RC-FIND-01',{...BASE,'evidence_paths':'root.and(0)'});expect(a?.['title'])['toBe']('Fund\x20theft\x20risk:\x20Signer\x20recipient\x20without\x20caller\x20identity\x20constraint'),expect(a?.['description'])['toContain']('service\x200xsvc'),expect(a?.['description'])['toContain']('rule\x20RC-FIND-01,\x20evidence\x20paths\x20root.and(0)'),expect(a?.['mitigation'])['toContain']('do\x20NOT\x20pay\x20this\x20service\x20before\x20the\x20fix');}),it('fixed\x20levels\x20hold\x20where\x20the\x20kernel\x20hardcoded\x20them',()=>{expect(rule('RC-FIND-05',{...BASE,'code':'RC-FIND-05','base_level':'high'})?.['level'])['toBe']('medium'),expect(rule('RC-FIND-06',{...BASE,'code':'RC-FIND-06','base_level':'high'})?.['level'])['toBe']('low'),expect(rule('RC-FIND-07',{...BASE,'code':'RC-FIND-07','base_level':'high'})?.['level'])['toBe']('medium');}),it('shortfall\x20findings\x20(05/07)\x20carry\x20loss\x20parties\x20only\x20and\x20are\x20never\x20downgraded',()=>{for(const a of['RC-FIND-05','RC-FIND-07']){const b=rule(a,{...BASE,'code':a});expect(b?.['exposure']?.['gainPaths'])['toHaveLength'](0x0),expect(b?.['exposure']?.['lossParties']['length'])['toBeGreaterThan'](0x0),expect(b?.['exposure']?.['verdict'])['toBe']('confirmed'),expect(b?.['level'])['not']['toBe']('info');}expect(rule('RC-FIND-05',{...BASE,'code':'RC-FIND-05'})?.['exposure']?.['lossParties']['map'](c=>c['role']))['toEqual'](['supplier','buyer']);}),it('RC-FIND-08\x20keeps\x20its\x20level\x20as\x20pending-disclosure\x20(undecided\x20predicate)',()=>{const a=rule('RC-FIND-08',{...BASE,'code':'RC-FIND-08','base_level':'medium','evidence_count':0x2});expect(a?.['level'])['toBe']('medium'),expect(a?.['description'])['toContain']('composes\x202\x20sub-guard(s)'),expect(a?.['exposure']?.['verdict'])['toBe']('pending-disclosure'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('unverifiable');}),it('RC-FIND-09\x20stays\x20low\x20(visibility\x20hint\x20—\x20omission\x20is\x20often\x20intended,\x20not\x20theft)',()=>{const a=rule('RC-FIND-09',{...BASE,'code':'RC-FIND-09','base_level':'low'});expect(a?.['level'])['toBe']('low'),expect(a?.['mitigation'])['toContain']('anchor\x20row'),expect(a?.['description'])['toContain']('confirm\x20it\x20is');}),it('an\x20unknown\x20canonical\x20code\x20fires\x20no\x20case\x20(kernel\x20fallback\x20stays\x20in\x20charge)',()=>{const a=factoryRulePack('alloc_audit'),b=a['rules']['find'](d=>d['rule_id']==='RC-FIND-01'),{findings:c}=evaluateRuleBook([b],{...BASE,'code':'RC-FIND-99'});expect(c)['toHaveLength'](0x0);});}),describe('alloc_audit\x20factory\x20parity\x20—\x20gap\x20and\x20verdict',()=>{it('RC-GAP\x20emits\x20info\x20with\x20the\x20unfetched\x20evidence\x20interpolated',()=>{const a=rule('RC-GAP',{'host_service':'0xsvc','unfetched_count':0x2,'unfetched_list':'0xa,\x200xb\x20(guard.relies)'});expect(a?.['level'])['toBe']('info'),expect(a?.['title'])['toContain']('evidence\x20gap'),expect(a?.['description'])['toContain']('references\x202\x20guard(s)'),expect(a?.['description'])['toContain']('0xa,\x200xb\x20(guard.relies)'),expect(a?.['exposure']?.['gainPaths'])['toHaveLength'](0x0),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');}),it('RC-SUMMARY\x20—\x20unsafe\x20wins\x20at\x20high,\x20with\x20and\x20without\x20the\x20residual\x20suffix',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':!![],'resolution_required':![]}));expect(a?.['level'])['toBe']('high'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists'),expect(a?.['description'])['toContain']('WARNING:\x20an\x20unbound\x20Signer\x20direct-pay\x20path\x20exists'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('viable'),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');const b=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':!![],'resolution_required':!![]}));expect(b?.['level'])['toBe']('high'),expect(b?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists\x20(residual\x20requires\x20explicit\x20decision)');}),it('RC-SUMMARY\x20—\x20safe\x20+\x20residual\x20is\x20medium\x20conditional\x20with\x20the\x20destinations\x20interpolated',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':![],'resolution_required':!![]}));expect(a?.['level'])['toBe']('medium'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20destination\x20safe\x20(residual\x20requires\x20explicit\x20decision)'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('conditional'),expect(a?.['exposure']?.['lossParties'][0x0]?.['basis'])['toContain']('0xmerchant'),expect(a?.['exposure']?.['verdict'])['toBe']('confirmed');}),it('RC-SUMMARY\x20—\x20fully\x20safe\x20downgrades\x20to\x20info\x20(redirect\x20provably\x20blocked)',()=>{const a=rule('RC-SUMMARY',summaryFacts({'dest_unsafe':![],'resolution_required':![]}));expect(a?.['level'])['toBe']('info'),expect(a?.['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20destination\x20safe'),expect(a?.['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('blocked'),expect(a?.['exposure']?.['verdict'])['toBe']('downgraded'),expect(a?.['exposure']?.['baseSeverity'])['toBe']('info');});});function summaryFacts(a){return{'host_service':'0xsvc','allocator_count':0x1,'guard_count':0x1,'destinations_text':'0xmerchant','dest_unsafe':a['dest_unsafe'],'resolution_required':a['resolution_required'],'audit_summary':'Analyzed\x201\x20allocator(s):\x201\x20actionable,\x200\x20unavoidable.'};}const GUARD='0xguard0000000000000000000000000000000000000000000000000000000001';function serviceNode(){return{'id':'0xsvc','kind':'object','state':'fetched','origins':[],'depth':0x0,'raw':{'data':{'order_allocators':{'allocators':[{'guard':GUARD,'sharing':[{'who':{'Signer':!![]},'sharing':'10000','mode':'Rate'}]}]}}}};}function guardNode(){return{'id':GUARD,'kind':'object','state':'fetched','origins':[],'depth':0x1,'raw':{'data':{'table':[],'root':{'type':'value','value':!![]}}}};}function viewport(){return{'visibleEdges':[{'id':'service.order_allocator_guard|0xsvc→'+GUARD,'schema':'service.order_allocator_guard','family':'F','from':'0xsvc','to':GUARD,'retention':'complete','observedAt':0x0}],'graph':{'nodes':new Map([[GUARD,guardNode()]])}};}function scopedGuardNode(a){return{'id':GUARD,'kind':'object','state':'fetched','origins':[],'depth':0x1,'raw':{'data':{'table':[{'identifier':0x0,'b_submission':!![],'value_type':a,'value':undefined,'name':'order_slot'},{'identifier':0x2,'b_submission':![],'value_type':'Address','value':'0xsvc','name':'svc'}],'root':{'type':'logic_and','nodes':[{'type':'logic_equal','nodes':[{'type':'query','query':'order.service','object':{'identifier':0x0}},{'type':'identifier','identifier':0x2}]}]}}}};}function scopedServiceNode(){return{'id':'0xsvc','kind':'object','state':'fetched','origins':[],'depth':0x0,'raw':{'data':{'order_allocators':{'allocators':[{'guard':GUARD,'sharing':[{'who':{'GuardIdentifier':0x0},'sharing':'10000','mode':'Rate'}]}]}}}};}function scopedViewport(a){return{'visibleEdges':[{'id':'service.order_allocator_guard|0xsvc→'+GUARD,'schema':'service.order_allocator_guard','family':'F','from':'0xsvc','to':GUARD,'retention':'complete','observedAt':0x0}],'graph':{'nodes':new Map([[GUARD,scopedGuardNode(a)]])}};}describe('alloc_audit\x20binding\x20—\x20identifier-constant\x20scope\x20binding\x20(docs#44-b)',()=>{it('does\x20NOT\x20fire\x20RC-FIND-02\x20when\x20the\x20table\x20constant\x20is\x20a\x20chain-serialized\x20type\x20name',()=>{const a=serviceAllocatorAuditNodeAnalyzer['run'](scopedServiceNode(),scopedViewport('Address'));expect(a['map'](c=>c['title'])['some'](c=>c['includes']('no\x20scope\x20binding')))['toBe'](![]);const b=a['find'](c=>c['title']['startsWith']('Fund\x20destination\x20and\x20condition\x20integrity'));expect(b?.['title'])['toContain']('destination\x20safe');}),it('does\x20NOT\x20fire\x20RC-FIND-02\x20when\x20the\x20table\x20constant\x20is\x20a\x20numeric\x20value_type\x20enum',()=>{const a=serviceAllocatorAuditNodeAnalyzer['run'](scopedServiceNode(),scopedViewport(0x1));expect(a['map'](c=>c['title'])['some'](c=>c['includes']('no\x20scope\x20binding')))['toBe'](![]);const b=a['find'](c=>c['title']['startsWith']('Fund\x20destination\x20and\x20condition\x20integrity'));expect(b?.['title'])['toContain']('destination\x20safe');});}),describe('alloc_audit\x20binding\x20—\x20end\x20to\x20end',()=>{it('a\x20signer-recipient\x20service\x20yields\x20the\x20pack-driven\x20theft\x20finding\x20+\x20unsafe\x20verdict',()=>{const a=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(a)['toHaveLength'](0x4);const [b,c,d,e]=a;expect(b['id'])['toBe']('ALC1:0xsvc#0'),expect(b['title'])['toBe']('Fund\x20theft\x20risk:\x20Signer\x20recipient\x20without\x20caller\x20identity\x20constraint'),expect(b['severity'])['toBe']('high'),expect(b['exposure']?.['verdict'])['toBe']('confirmed'),expect(b['exposure']?.['gainPaths'][0x0]?.['viability'])['toBe']('viable'),expect(b['detail'])['toContain']('service\x200xsvc'),expect(c['id'])['toBe']('ALC1:0xsvc#1'),expect(c['title'])['toBe']('Allocator\x20Guard\x20has\x20no\x20GuardIdentifier\x20sharing\x20row\x20—\x20bound\x20to\x20no\x20particular\x20order'),expect(c['severity'])['toBe']('low'),expect(d['id'])['toBe']('ALC1:0xsvc#2'),expect(d['title'])['toBe']('Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run'),expect(d['severity'])['toBe']('low'),expect(d['exposure']?.['verdict'])['toBe']('confirmed'),expect(e['id'])['toBe']('ALC1:0xsvc#3'),expect(e['title'])['toBe']('Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists'),expect(e['severity'])['toBe']('high'),expect(e['detail'])['toContain']('1\x20allocator(s)\x20/\x201\x20resolved\x20guard(s)');}),it('a\x20user\x20disable\x20suppresses\x20the\x20theft\x20finding;\x20the\x20verdict\x20stays',()=>{writeFileSync(join(CONFIG_DIR,'judgment.json'),JSON['stringify']({'version':0x1,'rules':{'domains':{'alloc_audit':{'rules':[{'rule_id':'RC-FIND-01','enabled':![]}]}}}}),'utf-8'),resnapshot();const a=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(a['map'](c=>c['title']))['toEqual'](['Allocator\x20Guard\x20has\x20no\x20GuardIdentifier\x20sharing\x20row\x20—\x20bound\x20to\x20no\x20particular\x20order','Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run','Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists']);const b=judgmentStatus();expect(b['user_doc_loaded'])['toBe'](!![]);}),it('a\x20fact:\x20reference\x20outside\x20the\x20factory\x20vocabulary\x20is\x20rejected\x20loudly;\x20the\x20factory\x20keeps\x20serving',()=>{writeFileSync(join(CONFIG_DIR,'judgment.json'),JSON['stringify']({'version':0x1,'rules':{'domains':{'alloc_audit':{'rules':[{'rule_id':'RC-FIND-01','cases':[{'when':{'field':'code','op':'eq','value':'RC-FIND-01'},'level':'fact:not_a_kernel_fact','title':'t','description':'d'}]}]}}}}),'utf-8'),void getJudgmentDoc(),resnapshot();const a=judgmentStatus();expect(a['last_reload_error'])['toContain']('fact:not_a_kernel_fact'),expect(a['last_reload_error'])['toContain']('RC-FIND-01');const b=serviceAllocatorAuditNodeAnalyzer['run'](serviceNode(),viewport());expect(b['map'](c=>c['title']))['toEqual'](['Allocator\x20Guard\x20has\x20no\x20GuardIdentifier\x20sharing\x20row\x20—\x20bound\x20to\x20no\x20particular\x20order','Permissionless\x20alloc\x20—\x20settlement\x20timing\x20can\x20be\x20front-run','Fund\x20destination\x20and\x20condition\x20integrity:\x20stealable\x20destination\x20exists']);});});
@@ -1 +1 @@
1
- import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'ERECIPIENT_NOT_FOR_OBJECT\x20(15,\x20only\x20fires\x20when\x20a\x20binding\x20is\x20declared)','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let P=0x0;P<e['length'];P++){if(e[P]['sharing']['length']===0x0){f=P,g=e[P]['guard'];break;}}let h,j,k,l=![],m=![];if(d)for(let Q=0x0;Q<e['length'];Q++){const R=e[Q],S=R['sharing']['filter'](U=>U['mode']==='Rate')['reduce']((U,V)=>U+Number(V['sharing']),0x0),T=R['sharing']['some'](U=>U['mode']==='Surplus');if(!T&&S>0x0&&S!==RATE_TOTAL_FULL){h=Q,j=R['guard'],k=S,l=!![];break;}if(T&&S>RATE_TOTAL_FULL){h=Q,j=R['guard'],k=S,m=!![];break;}}let n,o,p,q,r,t,u;if(d){const U=Number(c['threshold']);for(let V=0x0;V<e['length'];V++){const W=e[V],X=W['sharing']['filter'](Z=>Z['mode']==='Surplus')['length'];if(X>0x1){n='multiple_surplus',o=V,p=W['guard'],q=X;break;}const Y=W['sharing']['filter'](Z=>Z['mode']==='Amount')['reduce']((Z,a0)=>Z+Number(a0['sharing']),0x0);if(Y>0x0&&Y<U){n='below_threshold',o=V,p=W['guard'],r=Y,t=U;break;}if(W['max']!=null&&Y>Number(W['max'])){n='exceeds_max',o=V,p=W['guard'],r=Y,u=Number(W['max']);break;}}}let v=![],w,x,y;if(d)for(let Z=0x0;Z<e['length'];Z++){const a0=e[Z],a1=a0['sharing']['some'](a3=>'Signer'in a3['who']),a2=b['guard_signer_bindings']?.[a0['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':a1,'caller_identity_constrained':a2})){v=!![],w=Z,x=a0['guard'],y=a2;break;}}let z,A,B;if(d&&b['passport_identifier_types'])for(let a3=0x0;a3<e['length'];a3++){const a4=e[a3],a5=a4['sharing']['find'](a8=>'GuardIdentifier'in a8['who']);if(!a5)continue;const a6=a5['who']['GuardIdentifier'],a7=b['passport_identifier_types'][a6];if(a7!==undefined&&a7!=='address'){z=a6,A=a7,B=a3;break;}}let C=![],D,E,F,G;if(d){const a8=e['map'](aa=>aa['guard']),a9=new Set(a8);if(a9['size']!==a8['length']){const aa=a8['filter']((ab,ad)=>a8['indexOf'](ab)!==ad);C=!![],D=a8['length'],E=a9['size'],F=aa['join'](',\x20'),G=aa['join'](',');}}const H=b['payment_info_for_object']!==undefined,I=d&&e['some'](ab=>ab['sharing']['some'](ad=>'GuardIdentifier'in ad['who'])),J=!!b['payment_info_for_object'];let K=![],L,M;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const ab of e){for(const ad of ab['sharing']){if(!(ad['who']!==null&&typeof ad['who']==='object'&&'Entity'in ad['who']))continue;const ae=ad['who']['Entity'],af=b['referenced_treasuries_permissions'][ae];if(af&&af!==b['host_service_permission']){K=!![],L=ae,M=af;break;}}if(K)break;}let N;if(b['trigger_source']==='standalone'&&d){const ag=[];for(const ah of e){const ai=b['guard_signer_bindings']?.[ah['guard']]===!![],aj=b['guard_has_time_lock']?.[ah['guard']]===!![];if(!ai&&!aj)ag['push'](ah['guard']);}N=ag;}let O;if(d)for(let ak=0x0;ak<e['length'];ak++){const al=e[ak],am=al['sharing']['length']>0x0&&al['sharing']['every'](an=>an['mode']==='Amount');if(am){O=ak;break;}}return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':m,'rate_total_full':RATE_TOTAL_FULL,'amount_rule_branch':n,'amount_rule_index':o,'amount_rule_guard':p,'amount_rule_surplus_count':q,'amount_rule_amount_sum':r,'amount_rule_threshold':t,'amount_rule_max':u,'signer_theft_detected':v,'signer_theft_index':w,'signer_theft_guard':x,'signer_theft_guard_bound':y,'guard_id_bad_identifier':z,'guard_id_bad_type':A,'guard_id_bad_index':B,'duplicate_guards_present':C,'allocators_total':D,'allocators_unique':E,'duplicate_guards_csv_sp':F,'duplicate_guards_csv':G,'for_object_anchor_known':H,'guard_identifier_recipient_present':I,'for_object_anchor_set':J,'for_object_anchor':H&&J?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':K,'treasury_perm_entity':L,'treasury_perm_treasury':M,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':N?.['length'],'standalone_weak_guards_csv_sp':N?.['join'](',\x20'),'standalone_weak_guards_csv':N?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':O,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT,'always_true':!![]};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.1.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
1
+ import{MAX_ALLOCATOR_COUNT,RATE_TOTAL_FULL,ALLOCATION_ERROR_CODES}from'./allocation-ledger.js';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{getJudgmentDoc,factoryRulePack}from'../config/judgment.js';import{evaluateRuleBook,evaluateCondition}from'../config/rule-engine.js';const AUTO_FIXABLE=new Set(['R-A-1-02#0','R-A-1-02#1','R-A-1-03#0','R-A-1-03#2','R-A-2-03#0','R-A-5-03#0']),RELATED_MOVE_ERROR={'R-A-1-01#0':'EALLOCATORS_EMPTY\x20(8)\x20/\x20ENO_ALLOCATOR\x20(3)','R-A-1-01#1':'ENO_ALLOCATOR\x20(3)','R-A-1-02#0':'ERATE_NOT_10000\x20(4)','R-A-1-02#1':'ERATE_EXCEEDS_10000\x20(6)','R-A-1-03#0':'EMULTIPLE_SURPLUS\x20(5)','R-A-1-03#1':'EAMOUNT_BELOW_THRESHOLD\x20(12)','R-A-1-03#2':'EAMOUNT_EXCEEDS_MAX\x20(13)','R-A-2-02#0':'ERECIPIENT_IDENTIFIER_NOT_ADDRESS\x20(1)','R-A-2-04#0':'ERECIPIENT_NOT_FOR_OBJECT\x20(15)','R-A-2-04#1':'ERECIPIENT_NOT_FOR_OBJECT\x20(15,\x20only\x20fires\x20when\x20a\x20binding\x20is\x20declared)','R-A-5-01#0':'E_ALLOCATION_ALREADY_SPECIFIED','R-A-5-02#0':'ENO_PAYMENT_INFO\x20(9)'},RELATED_GUARD_RISK={'R-A-2-01#0':'R-C3-06','R-A-3-04#0':'R-C3-06\x20(Signer\x20binding)\x20/\x20time-lock\x20patterns','R-A-4-01#0':'R-X1-05','R-A-4-03#0':'reentrancy\x20low'};export function allocationRiskFacts(b){const c=b['allocators_config'],d=!!c,e=d?c['allocators']:[];let f,g;if(d&&e['length']>0x0)for(let P=0x0;P<e['length'];P++){if(e[P]['sharing']['length']===0x0){f=P,g=e[P]['guard'];break;}}let h,j,k,l=![],m=![];if(d)for(let Q=0x0;Q<e['length'];Q++){const R=e[Q],S=R['sharing']['filter'](U=>U['mode']==='Rate')['reduce']((U,V)=>U+Number(V['sharing']),0x0),T=R['sharing']['some'](U=>U['mode']==='Surplus');if(!T&&S>0x0&&S!==RATE_TOTAL_FULL){h=Q,j=R['guard'],k=S,l=!![];break;}if(T&&S>RATE_TOTAL_FULL){h=Q,j=R['guard'],k=S,m=!![];break;}}let n,o,p,q,r,t,u;if(d){const U=Number(c['threshold']);for(let V=0x0;V<e['length'];V++){const W=e[V],X=W['sharing']['filter'](Z=>Z['mode']==='Surplus')['length'];if(X>0x1){n='multiple_surplus',o=V,p=W['guard'],q=X;break;}const Y=W['sharing']['filter'](Z=>Z['mode']==='Amount')['reduce']((Z,a0)=>Z+Number(a0['sharing']),0x0);if(Y>0x0&&Y<U){n='below_threshold',o=V,p=W['guard'],r=Y,t=U;break;}if(W['max']!=null&&Y>Number(W['max'])){n='exceeds_max',o=V,p=W['guard'],r=Y,u=Number(W['max']);break;}}}let v=![],w,x,y;if(d)for(let Z=0x0;Z<e['length'];Z++){const a0=e[Z],a1=a0['sharing']['some'](a3=>'Signer'in a3['who']),a2=b['guard_signer_bindings']?.[a0['guard']]===!![];if(isUnboundSignerTheft({'recipient_is_signer':a1,'caller_identity_constrained':a2})){v=!![],w=Z,x=a0['guard'],y=a2;break;}}let z,A,B;if(d&&b['passport_identifier_types'])for(let a3=0x0;a3<e['length'];a3++){const a4=e[a3],a5=a4['sharing']['find'](a8=>'GuardIdentifier'in a8['who']);if(!a5)continue;const a6=a5['who']['GuardIdentifier'],a7=b['passport_identifier_types'][a6];if(a7!==undefined&&a7!=='address'){z=a6,A=a7,B=a3;break;}}let C=![],D,E,F,G;if(d){const a8=e['map'](aa=>aa['guard']),a9=new Set(a8);if(a9['size']!==a8['length']){const aa=a8['filter']((ab,ad)=>a8['indexOf'](ab)!==ad);C=!![],D=a8['length'],E=a9['size'],F=aa['join'](',\x20'),G=aa['join'](',');}}const H=b['payment_info_for_object']!==undefined,I=d&&e['some'](ab=>ab['sharing']['some'](ad=>'GuardIdentifier'in ad['who'])),J=!!b['payment_info_for_object'];let K=![],L,M;if(d&&b['referenced_treasuries_permissions']&&b['host_service_permission'])for(const ab of e){for(const ad of ab['sharing']){if(!(ad['who']!==null&&typeof ad['who']==='object'&&'Entity'in ad['who']))continue;const ae=ad['who']['Entity'],af=b['referenced_treasuries_permissions'][ae];if(af&&af!==b['host_service_permission']){K=!![],L=ae,M=af;break;}}if(K)break;}let N;if(b['trigger_source']==='standalone'&&d){const ag=[];for(const ah of e){const ai=b['guard_signer_bindings']?.[ah['guard']]===!![],aj=b['guard_has_time_lock']?.[ah['guard']]===!![];if(!ai&&!aj)ag['push'](ah['guard']);}N=ag;}let O;if(d)for(let ak=0x0;ak<e['length'];ak++){const al=e[ak],am=al['sharing']['length']>0x0&&al['sharing']['every'](an=>an['mode']==='Amount');if(am){O=ak;break;}}return{'allocators_config_present':d,'allocators_count':d?e['length']:undefined,'allocators_empty':d&&e['length']===0x0,'empty_sharing_allocator_index':f,'empty_sharing_allocator_guard':g,'rate_rule_index':h,'rate_rule_guard':j,'rate_rule_sum':k,'rate_rule_pure':l,'rate_rule_exceed':m,'rate_total_full':RATE_TOTAL_FULL,'amount_rule_branch':n,'amount_rule_index':o,'amount_rule_guard':p,'amount_rule_surplus_count':q,'amount_rule_amount_sum':r,'amount_rule_threshold':t,'amount_rule_max':u,'signer_theft_detected':v,'signer_theft_index':w,'signer_theft_guard':x,'signer_theft_guard_bound':y,'guard_id_bad_identifier':z,'guard_id_bad_type':A,'guard_id_bad_index':B,'duplicate_guards_present':C,'allocators_total':D,'allocators_unique':E,'duplicate_guards_csv_sp':F,'duplicate_guards_csv':G,'for_object_anchor_known':H,'guard_identifier_recipient_present':I,'for_object_anchor_set':J,'for_object_anchor':H&&J?b['payment_info_for_object']??undefined:undefined,'host_service_published':b['host_service_published'],'treasury_perm_mismatch':K,'treasury_perm_entity':L,'treasury_perm_treasury':M,'host_service_permission':b['host_service_permission'],'allocation_create_op':b['operation_type']==='create','allocation_standalone':b['trigger_source']==='standalone','trigger_source_display':b['trigger_source']??'unknown','standalone_weak_guards_count':N?.['length'],'standalone_weak_guards_csv_sp':N?.['join'](',\x20'),'standalone_weak_guards_csv':N?.['join'](','),'has_fallback_allocator':b['has_fallback_allocator'],'guard_conditions_mutually_exclusive':b['guard_conditions_mutually_exclusive'],'has_fallback_allocator_display':String(b['has_fallback_allocator']??![]),'mutually_exclusive_display':String(b['guard_conditions_mutually_exclusive']??![]),'pure_amount_index':O,'order_already_has_allocation':b['order_already_has_allocation'],'bound_order_display':b['bound_order']??'unknown','bound_order_paren_display':b['bound_order']??'(unknown)','has_payment_info':b['has_payment_info'],'operation_type':b['operation_type'],'max_allocator_count':MAX_ALLOCATOR_COUNT};}function allocationRuleBook(){const a=getJudgmentDoc()['rules']['domains']['allocation'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27allocation\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function firedCaseKey(a,b,c){const d=a['find'](e=>e['rule_id']===c);if(d)for(let e=0x0;e<d['cases']['length'];e++){if(evaluateCondition(d['cases'][e]['when'],b))return c+'#'+e;}return c+'#0';}function findingToAllocationRisk(a,b){const c=RELATED_MOVE_ERROR[b],d=RELATED_GUARD_RISK[b];return{'id':a['rule_id'],'level':a['level'],'category':a['dimension']??'structural','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'','evidence':a['evidence'],...c!==undefined?{'related_move_error':c}:{},...d!==undefined?{'related_guard_risk':d}:{},'auto_fixable':AUTO_FIXABLE['has'](b),...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export const ALLOCATION_RISK_VERSION='1.1.0';export function getAllRiskRules(){const a=factoryRulePack('allocation');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'category':b['dimension']??'structural','trigger':b['trigger']??'','check':c=>{const d=allocationRiskFacts(c),{findings:e}=evaluateRuleBook([b],d);return e['length']>0x0?findingToAllocationRisk(e[0x0],firedCaseKey([b],d,b['rule_id'])):null;}}));}export function assessAllocationRisks(a){const b=allocationRuleBook(),c=allocationRiskFacts(a),{findings:d}=evaluateRuleBook(b,c),e=d['map'](j=>findingToAllocationRisk(j,firedCaseKey(b,c,j['rule_id']))),f=e['length']===0x0?'low':e['some'](j=>j['level']==='critical')?'critical':e['some'](j=>j['level']==='high')?'high':e['some'](j=>j['level']==='medium')?'medium':'low',g={},h={};for(const j of e){g[j['category']]=(g[j['category']]??0x0)+0x1,h[j['level']]=(h[j['level']]??0x0)+0x1;}const i={};for(const k of e){for(const l of k['affected_stakeholders']){if(!i[l])i[l]=[];i[l]['push'](k['id']+':\x20'+k['mitigation']);}}return{'summary':'Assessed\x20'+e['length']+'\x20risk(s)\x20across\x20'+Object['keys'](g)['length']+'\x20categories','risks':e,'overall_risk':f,'risks_by_category':g,'risks_by_level':h,'stakeholder_advice':i,'needs_human_review':e['some'](m=>m['level']==='critical'||m['level']==='high'),'blocks_publish':e['some'](m=>m['level']==='critical')};}export{ALLOCATION_ERROR_CODES};
@@ -1 +1 @@
1
- export const ARB_STATUS_CODE={'Principal_confirming':0x0,'Arbitrator_confirming':0x1,'Voting':0x2,'Arbitrated':0x3,'Objectionable':0x4,'Finished':0x5,'Withdrawn':0x6};export const ARB_TERMINAL_STATUSES=['Finished','Withdrawn'];export const ARB_STATUS_ALIASES={'created':'Principal_confirming','voting':'Voting','feedback':'Arbitrator_confirming','confirmed':'Arbitrated','completed':'Finished','reset':'Objectionable','disputed':'Withdrawn'};export const ARBITRATION_PERMISSIONS=[{'index':0x15e,'name':'ARBITRATION_NEW','description':'Create\x20new\x20Arbitration\x20object','governed_operations':['create\x20a\x20new\x20arbitration\x20service']},{'index':0x15f,'name':'ARBITRATION_DESCRIPTION','description':'Modify\x20Arbitration\x20description','governed_operations':['modify\x20the\x20arbitration\x20description']},{'index':0x160,'name':'ARBITRATION_ENDPOINT','description':'Reserved\x20placeholder\x20—\x20not\x20used\x20on-chain\x20(SDK\x20commented\x20out)','governed_operations':[],'is_reserved':!![]},{'index':0x161,'name':'ARBITRATION_LOCATION','description':'Set\x20Arbitration\x20location','governed_operations':['set\x20the\x20arbitration\x20location']},{'index':0x162,'name':'ARBITRATION_VOTING_GUARD','description':'Manage\x20voting_guard\x20list\x20(add\x20/\x20remove\x20/\x20clear)\x20—\x20controls\x20vote\x20weight','governed_operations':['add\x20a\x20passport-identifier\x20voting\x20guard\x20(dynamic\x20weight)','add\x20a\x20fixed-weight\x20voting\x20guard','remove\x20a\x20voting\x20guard','clear\x20the\x20voting\x20guard\x20list']},{'index':0x163,'name':'ARBITRATION_USAGE_GUARD','description':'Set\x20/\x20clear\x20usage_guard\x20—\x20controls\x20who\x20can\x20file\x20disputes','governed_operations':['set\x20the\x20usage\x20guard\x20(restrict\x20who\x20can\x20file\x20disputes)','clear\x20the\x20usage\x20guard']},{'index':0x164,'name':'ARBITRATION_PAUSE','description':'Pause\x20/\x20resume\x20Arbitration\x20(bPaused\x20default\x20true)','governed_operations':['pause/resume\x20the\x20arbitration\x20service']},{'index':0x165,'name':'ARBITRATION_FEE','description':'Set\x20dispute\x20application\x20fee\x20(u64)','governed_operations':['set\x20the\x20dispute\x20application\x20fee']},{'index':0x166,'name':'ARBITRATION_VOTE','description':'Open\x20vote\x20(no\x20voting_guard\x20configured\x20—\x201\x20person\x201\x20vote)','governed_operations':['open\x20a\x20vote\x20(1\x20person\x201\x20vote)']},{'index':0x167,'name':'ARBITRATION_ARBITRATION','description':'Make\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)','governed_operations':['issue\x20the\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)']},{'index':0x168,'name':'ARBITRATION_FEEDBACK','description':'Provide\x20feedback\x20on\x20Arb\x20case','governed_operations':['attach\x20feedback\x20to\x20the\x20Arb\x20case']},{'index':0x169,'name':'ARBITRATION_CONFIRM','description':'Confirm\x20materials\x20submitted\x20by\x20principal\x20(starts\x20voting\x20phase)','governed_operations':['confirm\x20the\x20principal\x27s\x20materials\x20(starts\x20the\x20voting\x20phase)']},{'index':0x16a,'name':'ARBITRATION_VOTING_DEADLINE_CHANGE','description':'Change\x20voting\x20deadline\x20for\x20an\x20Arb\x20case','governed_operations':['change\x20the\x20voting\x20deadline\x20for\x20an\x20Arb\x20case']},{'index':0x16b,'name':'ARBITRATION_RESET','description':'Reset\x20arbitration\x20—\x20principal\x20resubmits\x20materials,\x20restart\x20lifecycle','governed_operations':['reset\x20the\x20arbitration\x20(principal\x20resubmits\x20materials)']},{'index':0x16c,'name':'ARBITRATION_ARB_WITHDRAW','description':'Withdraw\x20arbitration\x20fees\x20from\x20Arb\x20into\x20Arbitration.balance','governed_operations':['withdraw\x20arbitration\x20fees\x20from\x20the\x20Arb\x20into\x20Arbitration.balance']},{'index':0x16d,'name':'ARBITRATION_FEES_ALLOC','description':'Allocate\x20arbitration\x20fees\x20to\x20Allocation\x20object','governed_operations':['allocate\x20arbitration\x20fees\x20to\x20an\x20Allocation\x20object']},{'index':0x16e,'name':'ARBITRATION_FEES_TRANSFER','description':'Transfer\x20arbitration\x20fees\x20to\x20Treasury\x20object','governed_operations':['transfer\x20arbitration\x20fees\x20to\x20a\x20Treasury\x20object']},{'index':0x16f,'name':'ARBITRATION_OWNER_RECEIVE','description':'Owner\x20receive\x20(unwrap\x20received\x20Coin/Object\x20and\x20send\x20to\x20Permission\x20owner)','governed_operations':['owner\x20receipt\x20of\x20payments\x20(unwrapped\x20to\x20the\x20owner)','owner\x20receipt\x20of\x20whole\x20objects']},{'index':0x170,'name':'ARBITRATION_UM','description':'Set\x20/\x20clear\x20User\x20Manager\x20(Contact\x20object)','governed_operations':['bind\x20a\x20Contact\x20as\x20the\x20UM\x20coordinator','unbind\x20the\x20UM\x20Contact']}];export const DUAL_GUARD_MATRIX=[{'voting_guard_empty':!![],'usage_guard_empty':!![],'dispute_method':'dispute','vote_method':'vote','scenario':'Open\x20dispute\x20+\x20open\x20voting\x20(1\x20person\x201\x20vote)'},{'voting_guard_empty':!![],'usage_guard_empty':![],'dispute_method':'dispute_via_passport','vote_method':'vote','scenario':'Restricted\x20dispute\x20+\x20open\x20voting'},{'voting_guard_empty':![],'usage_guard_empty':!![],'dispute_method':'dispute','vote_method':'vote_weighted_by_guard','scenario':'Open\x20dispute\x20+\x20weighted\x20voting'},{'voting_guard_empty':![],'usage_guard_empty':![],'dispute_method':'dispute_via_passport','vote_method':'vote_weighted_by_guard','scenario':'Restricted\x20dispute\x20+\x20weighted\x20voting\x20(most\x20controlled)'}];export const ARBITRATION_SCENES=[{'id':'arbitration_create','name':'Create\x20new\x20Arbitration\x20service','operation_category':'lifecycle','permission_index':0x15e,'permission_name':'ARBITRATION_NEW','requires_voting_guard':'any','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['create\x20a\x20new\x20arbitration\x20service'],'common_patterns':['Pre-publish\x20config:\x20create\x20Arbitration\x20+\x20Permission\x20together','bPaused\x20defaults\x20to\x20true\x20—\x20must\x20call\x20pause(false)\x20to\x20enable','Generic\x20T:\x20choose\x20Coin\x20type\x20(e.g.\x200x2::wow::WOW)\x20at\x20creation','object-linker\x20binding\x20(core):\x20permission\x20+\x20arbitration\x20linked\x20by\x20an\x20affiliation\x20core\x20binding'],'recommended_templates':['T-AB-01','T-AB-02']},{'id':'arbitration_dispute','name':'File\x20dispute\x20against\x20an\x20Order\x20(creates\x20Arb\x20case)','operation_category':'dispute','permission_index':0x0,'permission_name':'(order\x20op\x20permission\x20—\x20no\x20ARBITRATION_*\x20index)','required_arb_status':[],'resulting_arb_status':'Arbitrator_confirming','requires_voting_guard':'any','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['file\x20a\x20dispute\x20against\x20an\x20Order\x20(creates\x20the\x20Arb\x20case)'],'common_patterns':['Fee\x20gate:\x20coin::value(&fee)\x20>=\x20self.fee,\x20else\x20E_FEE_NOT_ENOUGH','Order\x20op\x20permission\x20check\x20required\x20(caller\x20must\x20hold\x20the\x20matching\x20order\x20operation\x20permission)','Creates\x20independent\x20Arb<T>\x20object\x20with\x20its\x20own\x20lifecycle','If\x20usage_guard\x20is\x20Some\x20→\x20the\x20dispute\x20must\x20go\x20through\x20passport\x20verification','Order.dispute\x20list:\x20appends\x20new\x20Arb\x20(max\x2010\x20per\x20Order)'],'recommended_templates':['T-AB-01','T-AB-03','T-AB-04']},{'id':'arbitration_vote','name':'Vote\x20on\x20Arb\x20propositions','operation_category':'voting','permission_index':0x166,'permission_name':'ARBITRATION_VOTE','required_arb_status':['Voting'],'requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['open\x20a\x20vote\x20(1\x20person\x201\x20vote)','cast\x20a\x20weighted\x20vote\x20(weights\x20resolved\x20from\x20the\x20voting\x20guard)'],'common_patterns':['Open\x20vote:\x20voting_guard\x20empty\x20→\x20plain\x20vote\x20(passport\x20variant\x20supported)','Weighted\x20vote:\x20voting_guard\x20non-empty\x20→\x20vote\x20weight\x20resolved\x20per\x20voting\x20guard','votes:\x20u8\x20array\x20—\x20index\x20into\x20proposition\x20list\x20(0..N-1)','Mismatch:\x20vote()\x20with\x20non-empty\x20voting_guard\x20→\x20E_VOTING_GUARD_USED','Guard\x20not\x20in\x20list:\x20E_VOTING_GUARD_NOT_FOUND'],'recommended_templates':['T-AB-02','T-AB-03']},{'id':'arbitration_confirm','name':'Confirm\x20principal\x20materials\x20and\x20start\x20voting\x20phase','operation_category':'ruling','permission_index':0x169,'permission_name':'ARBITRATION_CONFIRM','required_arb_status':['Arbitrator_confirming'],'resulting_arb_status':'Voting','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['confirm\x20the\x20principal\x27s\x20materials\x20(starts\x20the\x20voting\x20phase)'],'common_patterns':['Transitions\x20Arb\x20from\x20Arbitrator_confirming\x20→\x20Voting','voting_deadline:\x20u64\x20timestamp_ms\x20(null\x20=\x20no\x20deadline)','Once\x20in\x20Voting,\x20only\x20vote\x20/\x20voting_deadline_change\x20/\x20reset\x20allowed'],'recommended_templates':['T-AB-01','T-AB-02']},{'id':'arbitration_feedback','name':'Provide\x20feedback\x20on\x20Arb\x20case','operation_category':'ruling','permission_index':0x168,'permission_name':'ARBITRATION_FEEDBACK','required_arb_status':['Principal_confirming','Arbitrator_confirming','Voting','Arbitrated','Objectionable'],'requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['attach\x20feedback\x20to\x20the\x20Arb\x20case'],'common_patterns':['Feedback\x20is\x20informational\x20—\x20does\x20not\x20change\x20Arb\x20status','Used\x20by\x20principal\x20/\x20arbitrator\x20/\x20voters\x20to\x20attach\x20notes','No\x20state\x20transition;\x20supplements\x20the\x20case\x20record'],'recommended_templates':['T-AB-01','T-AB-07']},{'id':'arbitration_ruling','name':'Make\x20definitive\x20arbitration\x20ruling\x20with\x20indemnity','operation_category':'ruling','permission_index':0x167,'permission_name':'ARBITRATION_ARBITRATION','required_arb_status':['Voting'],'resulting_arb_status':'Arbitrated','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['issue\x20the\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)'],'common_patterns':['Ruling\x20produces:\x20feedback\x20(string)\x20+\x20indemnity\x20(u64)','indemnity\x20is\x20compensation\x20amount\x20—\x20paid\x20through\x20the\x20order\x20compensation\x20flow','compensation\x20is\x20package-internal\x20—\x20only\x20the\x20order\x20lifecycle\x20can\x20trigger\x20it','Once\x20Arbitrated,\x20case\x20enters\x20Objectionable\x20window\x20(reset\x20possible)'],'recommended_templates':['T-AB-01','T-AB-05']},{'id':'arbitration_reset','name':'Reset\x20arbitration\x20—\x20principal\x20resubmits\x20materials','operation_category':'ruling','permission_index':0x16b,'permission_name':'ARBITRATION_RESET','required_arb_status':['Objectionable','Arbitrator_confirming'],'resulting_arb_status':'Principal_confirming','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['reset\x20the\x20arbitration\x20(principal\x20resubmits\x20materials)'],'common_patterns':['Resets\x20Arb\x20from\x20Objectionable/Arbitrator_confirming\x20→\x20Principal_confirming','Used\x20when\x20principal\x20objects\x20to\x20ruling\x20and\x20resubmits\x20materials','Feedback\x20required\x20(string\x20explaining\x20reset\x20reason)','Restart\x20full\x20lifecycle:\x20Principal_confirming\x20→\x20...\x20→\x20Finished'],'recommended_templates':['T-AB-07']},{'id':'arbitration_arb_withdraw','name':'Withdraw\x20arbitration\x20fees\x20from\x20Arb\x20into\x20Arbitration.balance','operation_category':'fund','permission_index':0x16c,'permission_name':'ARBITRATION_ARB_WITHDRAW','required_arb_status':['Finished','Arbitrated','Objectionable'],'requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['withdraw\x20arbitration\x20fees\x20from\x20the\x20Arb\x20into\x20Arbitration.balance'],'common_patterns':['Moves\x20fees\x20from\x20the\x20Arb\x20object\x20into\x20Arbitration.balance\x20(clock-checked)','Finished:\x20withdraw\x20immediately','Arbitrated/Objectionable:\x20must\x20wait\x20WITHDRAW_DURATION_TIME\x20(30d)\x20past\x20indemnity.time','Increases\x20Arbitration.balance\x20—\x20funds\x20available\x20for\x20fee\x20allocation/transfer'],'recommended_templates':['T-AB-06']},{'id':'arbitration_fees_alloc','name':'Allocate\x20arbitration\x20fees\x20to\x20Allocation\x20object','operation_category':'fund','permission_index':0x16d,'permission_name':'ARBITRATION_FEES_ALLOC','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['allocate\x20arbitration\x20fees\x20to\x20an\x20Allocation\x20object'],'common_patterns':['Destination:\x20Allocation\x20object\x20(parameterized\x20fund\x20distribution)','payment_remark\x20+\x20payment_index:\x20bookkeeping\x20for\x20Payment\x20object','May\x20create\x20new\x20Payment\x20object\x20if\x20newPayment\x20name\x20provided','Triggers\x20balance::withdraw_all\x20—\x20extracts\x20ALL\x20balance'],'recommended_templates':['T-AB-06']},{'id':'arbitration_fees_transfer','name':'Transfer\x20arbitration\x20fees\x20to\x20Treasury\x20object','operation_category':'fund','permission_index':0x16e,'permission_name':'ARBITRATION_FEES_TRANSFER','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['transfer\x20arbitration\x20fees\x20to\x20a\x20Treasury\x20object'],'common_patterns':['Destination:\x20Treasury\x20object\x20(general\x20fund\x20pool)','Same\x20bookkeeping\x20as\x20fee\x20allocation\x20(remark\x20+\x20index\x20+\x20newPayment)','Triggers\x20balance::withdraw_all\x20—\x20extracts\x20ALL\x20balance','Choose\x20Allocation\x20vs\x20Treasury\x20by\x20distribution\x20need'],'recommended_templates':['T-AB-06']},{'id':'arbitration_voting_guard_config','name':'Configure\x20voting_guard\x20list\x20(add\x20/\x20set\x20/\x20remove\x20/\x20clear)','operation_category':'guard','permission_index':0x162,'permission_name':'ARBITRATION_VOTING_GUARD','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['add\x20a\x20passport-identifier\x20voting\x20guard\x20(dynamic\x20weight)','add\x20a\x20fixed-weight\x20voting\x20guard','remove\x20a\x20voting\x20guard','clear\x20the\x20voting\x20guard\x20list'],'common_patterns':['Max\x2050\x20guards:\x20MAX_VOTING_GUARD_COUNT=50\x20(off-by-one-safe:\x20len<50\x20allows\x20add)','GuardIdentifier(u8):\x20dynamic\x20weight\x20from\x20Passport\x20submission\x20value','FixedValue(u32):\x20static\x20weight\x20(e.g.\x20100\x20votes\x20per\x20holder)','Add\x20same\x20guard\x20twice\x20→\x20updates\x20vote_weight\x20(no\x20duplicate)','op=\x27set\x27\x20=\x20clear\x20then\x20add;\x20op=\x27add\x27\x20=\x20append;\x20op=\x27remove\x27\x20=\x20by\x20address'],'recommended_templates':['T-AB-02','T-AB-03']},{'id':'arbitration_usage_guard_config','name':'Configure\x20usage_guard\x20(set\x20/\x20clear)','operation_category':'guard','permission_index':0x163,'permission_name':'ARBITRATION_USAGE_GUARD','requires_voting_guard':'not_applicable','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['set\x20the\x20usage\x20guard\x20(restrict\x20who\x20can\x20file\x20disputes)','clear\x20the\x20usage\x20guard'],'common_patterns':['Single\x20guard\x20(Option<address>)\x20—\x20not\x20a\x20list','Some(guard):\x20the\x20dispute\x20must\x20go\x20through\x20passport\x20verification','None:\x20dispute\x20can\x20use\x20either\x20variant\x20(no\x20passport\x20needed)','object-linker\x20affiliation\x20change:\x20updates\x20link\x20when\x20guard\x20changes'],'recommended_templates':['T-AB-04']},{'id':'arbitration_pause','name':'Pause\x20/\x20resume\x20Arbitration\x20service','operation_category':'lifecycle','permission_index':0x164,'permission_name':'ARBITRATION_PAUSE','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['pause/resume\x20the\x20arbitration\x20service'],'common_patterns':['bPaused\x20default\x20true\x20—\x20new\x20Arbitration\x20cannot\x20accept\x20disputes','pause(false)\x20to\x20enable,\x20pause(true)\x20to\x20disable','Paused\x20Arbitration\x20rejects\x20dispute\x20(E_PAUSED)','Does\x20not\x20affect\x20already-open\x20Arb\x20cases'],'recommended_templates':['T-AB-01']}];export const ARBITRATION_LEDGER_VERSION='1.0.0';export function getScenesByCategory(a){return ARBITRATION_SCENES['filter'](b=>b['operation_category']===a);}export function findSceneById(a){return ARBITRATION_SCENES['find'](b=>b['id']===a);}export function findSceneByPermissionIndex(a){return ARBITRATION_SCENES['find'](b=>b['permission_index']===a);}export function getPermissionByIndex(a){return ARBITRATION_PERMISSIONS['find'](b=>b['index']===a);}export function getPermissionByName(a){return ARBITRATION_PERMISSIONS['find'](b=>b['name']===a);}export function isReservedIndex(a){const b=getPermissionByIndex(a);return!!b?.['is_reserved'];}export function isUsedPermissionIndex(a){const b=getPermissionByIndex(a);return!!b&&!b['is_reserved'];}export function getActivePermissionCount(){return ARBITRATION_PERMISSIONS['filter'](a=>!a['is_reserved'])['length'];}export function inferSceneFromIntent(a){const b=a['toLowerCase'](),c=[{'keywords':['create','new'],'sceneId':'arbitration_create'},{'keywords':['dispute','file','complaint'],'sceneId':'arbitration_dispute'},{'keywords':['vote','voting','decide'],'sceneId':'arbitration_vote'},{'keywords':['confirm','materials'],'sceneId':'arbitration_confirm'},{'keywords':['feedback','opinion'],'sceneId':'arbitration_feedback'},{'keywords':['ruling','arbitration','verdict'],'sceneId':'arbitration_ruling'},{'keywords':['reset','resubmit'],'sceneId':'arbitration_reset'},{'keywords':['arb_withdraw','withdraw','withdraw\x20fees'],'sceneId':'arbitration_arb_withdraw'},{'keywords':['allocate','allocate\x20fees','fees\x20allocation'],'sceneId':'arbitration_fees_alloc'},{'keywords':['fees_transfer','transfer','transfer\x20in'],'sceneId':'arbitration_fees_transfer'},{'keywords':['voting_guard','voting\x20guard'],'sceneId':'arbitration_voting_guard_config'},{'keywords':['usage_guard','usage\x20guard'],'sceneId':'arbitration_usage_guard_config'},{'keywords':['pause','enable'],'sceneId':'arbitration_pause'}];for(const {keywords:d,sceneId:e}of c){if(d['some'](f=>b['includes'](f['toLowerCase']()))){const f=findSceneById(e);if(f)return f;}}return undefined;}export function getDualGuardMatrixEntry(a,b){return DUAL_GUARD_MATRIX['find'](c=>c['voting_guard_empty']===a&&c['usage_guard_empty']===b);}export function isValidArbStatusTransition(a,b){const c={'Principal_confirming':['Arbitrator_confirming'],'Arbitrator_confirming':['Voting','Principal_confirming'],'Voting':['Arbitrated'],'Arbitrated':['Objectionable','Finished','Withdrawn'],'Objectionable':['Principal_confirming','Withdrawn'],'Finished':['Withdrawn'],'Withdrawn':[]};return c[a]?.['includes'](b)??![];}export function isTerminalArbStatus(a){return ARB_TERMINAL_STATUSES['includes'](a);}export function getScenesProducingStatus(a){return ARBITRATION_SCENES['filter'](b=>b['resulting_arb_status']===a);}export function getScenesRequiringStatus(a){return ARBITRATION_SCENES['filter'](b=>b['required_arb_status']?.['includes'](a));}export function getArbitrationScenesCount(){return ARBITRATION_SCENES['length'];}export function getAllArbitrationPermissions(){return[...ARBITRATION_PERMISSIONS];}export function getActiveArbitrationPermissions(){return ARBITRATION_PERMISSIONS['filter'](a=>!a['is_reserved']);}
1
+ export const ARB_STATUS_CODE={'Principal_confirming':0x0,'Arbitrator_confirming':0x1,'Voting':0x2,'Arbitrated':0x3,'Objectionable':0x4,'Finished':0x5,'Withdrawn':0x6};export const ARB_TERMINAL_STATUSES=['Finished','Withdrawn'];export const ARB_STATUS_ALIASES={'created':'Principal_confirming','voting':'Voting','feedback':'Arbitrator_confirming','confirmed':'Arbitrated','completed':'Finished','reset':'Objectionable','disputed':'Withdrawn'};export const ARBITRATION_PERMISSIONS=[{'index':0x15e,'name':'ARBITRATION_NEW','description':'Create\x20new\x20Arbitration\x20object','governed_operations':['create\x20a\x20new\x20arbitration\x20service']},{'index':0x15f,'name':'ARBITRATION_DESCRIPTION','description':'Modify\x20Arbitration\x20description','governed_operations':['modify\x20the\x20arbitration\x20description']},{'index':0x160,'name':'ARBITRATION_ENDPOINT','description':'Reserved\x20placeholder\x20—\x20not\x20used\x20on-chain\x20(SDK\x20commented\x20out)','governed_operations':[],'is_reserved':!![]},{'index':0x161,'name':'ARBITRATION_LOCATION','description':'Set\x20Arbitration\x20location','governed_operations':['set\x20the\x20arbitration\x20location']},{'index':0x162,'name':'ARBITRATION_VOTING_GUARD','description':'Manage\x20voting_guard\x20list\x20(add\x20/\x20remove\x20/\x20clear)\x20—\x20controls\x20vote\x20weight','governed_operations':['add\x20a\x20passport-identifier\x20voting\x20guard\x20(dynamic\x20weight)','add\x20a\x20fixed-weight\x20voting\x20guard','remove\x20a\x20voting\x20guard','clear\x20the\x20voting\x20guard\x20list']},{'index':0x163,'name':'ARBITRATION_USAGE_GUARD','description':'Set\x20/\x20clear\x20usage_guard\x20—\x20controls\x20who\x20can\x20file\x20disputes','governed_operations':['set\x20the\x20usage\x20guard\x20(restrict\x20who\x20can\x20file\x20disputes)','clear\x20the\x20usage\x20guard']},{'index':0x164,'name':'ARBITRATION_PAUSE','description':'Pause\x20/\x20resume\x20Arbitration\x20(bPaused\x20default\x20true)','governed_operations':['pause/resume\x20the\x20arbitration\x20service']},{'index':0x165,'name':'ARBITRATION_FEE','description':'Set\x20dispute\x20application\x20fee\x20(u64)','governed_operations':['set\x20the\x20dispute\x20application\x20fee']},{'index':0x166,'name':'ARBITRATION_VOTE','description':'Open\x20vote\x20(no\x20voting_guard\x20configured\x20—\x201\x20person\x201\x20vote)','governed_operations':['open\x20a\x20vote\x20(1\x20person\x201\x20vote)']},{'index':0x167,'name':'ARBITRATION_ARBITRATION','description':'Make\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)','governed_operations':['issue\x20the\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)']},{'index':0x168,'name':'ARBITRATION_FEEDBACK','description':'Provide\x20feedback\x20on\x20Arb\x20case','governed_operations':['attach\x20feedback\x20to\x20the\x20Arb\x20case']},{'index':0x169,'name':'ARBITRATION_CONFIRM','description':'Confirm\x20materials\x20submitted\x20by\x20principal\x20(starts\x20voting\x20phase)','governed_operations':['confirm\x20the\x20principal\x27s\x20materials\x20(starts\x20the\x20voting\x20phase)']},{'index':0x16a,'name':'ARBITRATION_VOTING_DEADLINE_CHANGE','description':'Change\x20voting\x20deadline\x20for\x20an\x20Arb\x20case','governed_operations':['change\x20the\x20voting\x20deadline\x20for\x20an\x20Arb\x20case']},{'index':0x16b,'name':'ARBITRATION_RESET','description':'Reset\x20arbitration\x20—\x20principal\x20resubmits\x20materials,\x20restart\x20lifecycle','governed_operations':['reset\x20the\x20arbitration\x20(principal\x20resubmits\x20materials)']},{'index':0x16c,'name':'ARBITRATION_ARB_WITHDRAW','description':'Withdraw\x20arbitration\x20fees\x20from\x20Arb\x20into\x20Arbitration.balance','governed_operations':['withdraw\x20arbitration\x20fees\x20from\x20the\x20Arb\x20into\x20Arbitration.balance']},{'index':0x16d,'name':'ARBITRATION_FEES_ALLOC','description':'Allocate\x20arbitration\x20fees\x20to\x20Allocation\x20object','governed_operations':['allocate\x20arbitration\x20fees\x20to\x20an\x20Allocation\x20object']},{'index':0x16e,'name':'ARBITRATION_FEES_TRANSFER','description':'Transfer\x20arbitration\x20fees\x20to\x20Treasury\x20object','governed_operations':['transfer\x20arbitration\x20fees\x20to\x20a\x20Treasury\x20object']},{'index':0x16f,'name':'ARBITRATION_OWNER_RECEIVE','description':'Owner\x20receive\x20(unwrap\x20received\x20Coin/Object\x20and\x20send\x20to\x20Permission\x20owner)','governed_operations':['owner\x20receipt\x20of\x20payments\x20(unwrapped\x20to\x20the\x20owner)','owner\x20receipt\x20of\x20whole\x20objects']},{'index':0x170,'name':'ARBITRATION_UM','description':'Set\x20/\x20clear\x20User\x20Manager\x20(Contact\x20object)','governed_operations':['bind\x20a\x20Contact\x20as\x20the\x20UM\x20coordinator','unbind\x20the\x20UM\x20Contact']}];export const DUAL_GUARD_MATRIX=[{'voting_guard_empty':!![],'usage_guard_empty':!![],'dispute_method':'dispute','vote_method':'vote','scenario':'Open\x20dispute\x20+\x20open\x20voting\x20(1\x20person\x201\x20vote)'},{'voting_guard_empty':!![],'usage_guard_empty':![],'dispute_method':'dispute_via_passport','vote_method':'vote','scenario':'Restricted\x20dispute\x20+\x20open\x20voting'},{'voting_guard_empty':![],'usage_guard_empty':!![],'dispute_method':'dispute','vote_method':'vote_weighted_by_guard','scenario':'Open\x20dispute\x20+\x20weighted\x20voting'},{'voting_guard_empty':![],'usage_guard_empty':![],'dispute_method':'dispute_via_passport','vote_method':'vote_weighted_by_guard','scenario':'Restricted\x20dispute\x20+\x20weighted\x20voting\x20(most\x20controlled)'}];export const ARBITRATION_SCENES=[{'id':'arbitration_create','name':'Create\x20new\x20Arbitration\x20service','operation_category':'lifecycle','permission_index':0x15e,'permission_name':'ARBITRATION_NEW','requires_voting_guard':'any','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['create\x20a\x20new\x20arbitration\x20service'],'common_patterns':['Pre-publish\x20config:\x20create\x20Arbitration\x20+\x20Permission\x20together','bPaused\x20defaults\x20to\x20true\x20—\x20must\x20call\x20pause(false)\x20to\x20enable','Generic\x20T:\x20choose\x20Coin\x20type\x20(e.g.\x200x2::wow::WOW)\x20at\x20creation','object-linker\x20binding\x20(core):\x20permission\x20+\x20arbitration\x20linked\x20by\x20an\x20affiliation\x20core\x20binding'],'recommended_templates':['T-AB-01','T-AB-02']},{'id':'arbitration_dispute','name':'File\x20dispute\x20against\x20an\x20Order\x20(creates\x20Arb\x20case)','operation_category':'dispute','permission_index':0x0,'permission_name':'(order\x20op\x20permission\x20—\x20no\x20ARBITRATION_*\x20index)','required_arb_status':[],'resulting_arb_status':'Arbitrator_confirming','requires_voting_guard':'any','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['file\x20a\x20dispute\x20against\x20an\x20Order\x20(creates\x20the\x20Arb\x20case)'],'common_patterns':['Fee\x20gate:\x20coin::value(&fee)\x20>=\x20self.fee,\x20else\x20E_FEE_NOT_ENOUGH','Order\x20op\x20permission\x20check\x20required\x20(caller\x20must\x20hold\x20the\x20matching\x20order\x20operation\x20permission)','Creates\x20independent\x20Arb<T>\x20object\x20with\x20its\x20own\x20lifecycle','If\x20usage_guard\x20is\x20Some\x20→\x20the\x20dispute\x20must\x20go\x20through\x20passport\x20verification','Order.dispute\x20list:\x20appends\x20new\x20Arb\x20(max\x2010\x20per\x20Order)'],'recommended_templates':['T-AB-01','T-AB-03','T-AB-04']},{'id':'arbitration_vote','name':'Vote\x20on\x20Arb\x20propositions','operation_category':'voting','permission_index':0x166,'permission_name':'ARBITRATION_VOTE','required_arb_status':['Voting'],'requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['open\x20a\x20vote\x20(1\x20person\x201\x20vote)','cast\x20a\x20weighted\x20vote\x20(weights\x20resolved\x20from\x20the\x20voting\x20guard)'],'common_patterns':['Open\x20vote:\x20voting_guard\x20empty\x20→\x20plain\x20vote\x20(passport\x20variant\x20supported)','Weighted\x20vote:\x20voting_guard\x20non-empty\x20→\x20vote\x20weight\x20resolved\x20per\x20voting\x20guard','votes:\x20u8\x20array\x20—\x20index\x20into\x20proposition\x20list\x20(0..N-1)','Mismatch:\x20vote()\x20with\x20non-empty\x20voting_guard\x20→\x20E_VOTING_GUARD_USED','Guard\x20not\x20in\x20list:\x20E_VOTING_GUARD_NOT_FOUND'],'recommended_templates':['T-AB-02','T-AB-03']},{'id':'arbitration_confirm','name':'Confirm\x20principal\x20materials\x20and\x20start\x20voting\x20phase','operation_category':'ruling','permission_index':0x169,'permission_name':'ARBITRATION_CONFIRM','required_arb_status':['Arbitrator_confirming'],'resulting_arb_status':'Voting','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['confirm\x20the\x20principal\x27s\x20materials\x20(starts\x20the\x20voting\x20phase)'],'common_patterns':['Transitions\x20Arb\x20from\x20Arbitrator_confirming\x20→\x20Voting','voting_deadline:\x20u64\x20timestamp_ms\x20(null\x20=\x20no\x20deadline)','Once\x20in\x20Voting,\x20only\x20vote\x20/\x20voting_deadline_change\x20/\x20reset\x20allowed'],'recommended_templates':['T-AB-01','T-AB-02']},{'id':'arbitration_feedback','name':'Provide\x20feedback\x20on\x20Arb\x20case','operation_category':'ruling','permission_index':0x168,'permission_name':'ARBITRATION_FEEDBACK','required_arb_status':['Principal_confirming','Arbitrator_confirming','Voting','Arbitrated','Objectionable'],'requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['attach\x20feedback\x20to\x20the\x20Arb\x20case'],'common_patterns':['Feedback\x20is\x20informational\x20—\x20does\x20not\x20change\x20Arb\x20status','Used\x20by\x20principal\x20/\x20arbitrator\x20/\x20voters\x20to\x20attach\x20notes','No\x20state\x20transition;\x20supplements\x20the\x20case\x20record'],'recommended_templates':['T-AB-01','T-AB-07']},{'id':'arbitration_ruling','name':'Make\x20definitive\x20arbitration\x20ruling\x20with\x20indemnity','operation_category':'ruling','permission_index':0x167,'permission_name':'ARBITRATION_ARBITRATION','required_arb_status':['Voting'],'resulting_arb_status':'Arbitrated','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['issue\x20the\x20definitive\x20arbitration\x20ruling\x20(with\x20indemnity)'],'common_patterns':['Ruling\x20produces:\x20feedback\x20(string)\x20+\x20indemnity\x20(u64)','indemnity\x20is\x20compensation\x20amount\x20—\x20paid\x20through\x20the\x20order\x20compensation\x20flow','compensation\x20is\x20package-internal\x20—\x20only\x20the\x20order\x20lifecycle\x20can\x20trigger\x20it','Once\x20Arbitrated,\x20case\x20enters\x20Objectionable\x20window\x20(reset\x20possible)'],'recommended_templates':['T-AB-01','T-AB-05']},{'id':'arbitration_reset','name':'Reset\x20arbitration\x20—\x20principal\x20resubmits\x20materials','operation_category':'ruling','permission_index':0x16b,'permission_name':'ARBITRATION_RESET','required_arb_status':['Objectionable','Arbitrator_confirming'],'resulting_arb_status':'Principal_confirming','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['reset\x20the\x20arbitration\x20(principal\x20resubmits\x20materials)'],'common_patterns':['Resets\x20Arb\x20from\x20Objectionable/Arbitrator_confirming\x20→\x20Principal_confirming','Used\x20when\x20principal\x20objects\x20to\x20ruling\x20and\x20resubmits\x20materials','Feedback\x20required\x20(string\x20explaining\x20reset\x20reason)','Restart\x20full\x20lifecycle:\x20Principal_confirming\x20→\x20...\x20→\x20Finished'],'recommended_templates':['T-AB-07']},{'id':'arbitration_arb_withdraw','name':'Withdraw\x20arbitration\x20fees\x20from\x20Arb\x20into\x20Arbitration.balance','operation_category':'fund','permission_index':0x16c,'permission_name':'ARBITRATION_ARB_WITHDRAW','required_arb_status':['Finished','Arbitrated'],'requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['withdraw\x20arbitration\x20fees\x20from\x20the\x20Arb\x20into\x20Arbitration.balance'],'common_patterns':['Moves\x20fees\x20from\x20the\x20Arb\x20object\x20into\x20Arbitration.balance\x20(clock-checked)','Finished:\x20withdraw\x20immediately','Arbitrated:\x20must\x20wait\x20WITHDRAW_DURATION_TIME\x20(30d)\x20past\x20indemnity.time\x20—\x20silence\x20=\x20acceptance','Objectionable:\x20NEVER\x20withdrawable\x20(protocol\x20141)\x20—\x20the\x20fee\x20stays\x20escrowed\x20until\x20the\x20objection\x20cycle\x20is\x20closed\x20by\x20the\x20principal\x20re-confirming','Increases\x20Arbitration.balance\x20—\x20funds\x20available\x20for\x20fee\x20allocation/transfer'],'recommended_templates':['T-AB-06']},{'id':'arbitration_fees_alloc','name':'Allocate\x20arbitration\x20fees\x20to\x20Allocation\x20object','operation_category':'fund','permission_index':0x16d,'permission_name':'ARBITRATION_FEES_ALLOC','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['allocate\x20arbitration\x20fees\x20to\x20an\x20Allocation\x20object'],'common_patterns':['Destination:\x20Allocation\x20object\x20(parameterized\x20fund\x20distribution)','payment_remark\x20+\x20payment_index:\x20bookkeeping\x20for\x20Payment\x20object','May\x20create\x20new\x20Payment\x20object\x20if\x20newPayment\x20name\x20provided','Triggers\x20balance::withdraw_all\x20—\x20extracts\x20ALL\x20balance'],'recommended_templates':['T-AB-06']},{'id':'arbitration_fees_transfer','name':'Transfer\x20arbitration\x20fees\x20to\x20Treasury\x20object','operation_category':'fund','permission_index':0x16e,'permission_name':'ARBITRATION_FEES_TRANSFER','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['transfer\x20arbitration\x20fees\x20to\x20a\x20Treasury\x20object'],'common_patterns':['Destination:\x20Treasury\x20object\x20(general\x20fund\x20pool)','Same\x20bookkeeping\x20as\x20fee\x20allocation\x20(remark\x20+\x20index\x20+\x20newPayment)','Triggers\x20balance::withdraw_all\x20—\x20extracts\x20ALL\x20balance','Choose\x20Allocation\x20vs\x20Treasury\x20by\x20distribution\x20need'],'recommended_templates':['T-AB-06']},{'id':'arbitration_voting_guard_config','name':'Configure\x20voting_guard\x20list\x20(add\x20/\x20set\x20/\x20remove\x20/\x20clear)','operation_category':'guard','permission_index':0x162,'permission_name':'ARBITRATION_VOTING_GUARD','requires_voting_guard':'any','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['add\x20a\x20passport-identifier\x20voting\x20guard\x20(dynamic\x20weight)','add\x20a\x20fixed-weight\x20voting\x20guard','remove\x20a\x20voting\x20guard','clear\x20the\x20voting\x20guard\x20list'],'common_patterns':['Max\x2050\x20guards:\x20MAX_VOTING_GUARD_COUNT=50\x20(off-by-one-safe:\x20len<50\x20allows\x20add)','GuardIdentifier(u8):\x20dynamic\x20weight\x20from\x20Passport\x20submission\x20value','FixedValue(u32):\x20static\x20weight\x20(e.g.\x20100\x20votes\x20per\x20holder)','Add\x20same\x20guard\x20twice\x20→\x20updates\x20vote_weight\x20(no\x20duplicate)','op=\x27set\x27\x20=\x20clear\x20then\x20add;\x20op=\x27add\x27\x20=\x20append;\x20op=\x27remove\x27\x20=\x20by\x20address'],'recommended_templates':['T-AB-02','T-AB-03']},{'id':'arbitration_usage_guard_config','name':'Configure\x20usage_guard\x20(set\x20/\x20clear)','operation_category':'guard','permission_index':0x163,'permission_name':'ARBITRATION_USAGE_GUARD','requires_voting_guard':'not_applicable','requires_usage_guard':'any','has_passport_variant':!![],'governed_operations':['set\x20the\x20usage\x20guard\x20(restrict\x20who\x20can\x20file\x20disputes)','clear\x20the\x20usage\x20guard'],'common_patterns':['Single\x20guard\x20(Option<address>)\x20—\x20not\x20a\x20list','Some(guard):\x20the\x20dispute\x20must\x20go\x20through\x20passport\x20verification','None:\x20dispute\x20can\x20use\x20either\x20variant\x20(no\x20passport\x20needed)','object-linker\x20affiliation\x20change:\x20updates\x20link\x20when\x20guard\x20changes'],'recommended_templates':['T-AB-04']},{'id':'arbitration_pause','name':'Pause\x20/\x20resume\x20Arbitration\x20service','operation_category':'lifecycle','permission_index':0x164,'permission_name':'ARBITRATION_PAUSE','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['pause/resume\x20the\x20arbitration\x20service'],'common_patterns':['bPaused\x20default\x20true\x20—\x20new\x20Arbitration\x20cannot\x20accept\x20disputes','pause(false)\x20to\x20enable,\x20pause(true)\x20to\x20disable','Paused\x20Arbitration\x20rejects\x20dispute\x20(E_PAUSED)','Does\x20not\x20affect\x20already-open\x20Arb\x20cases'],'recommended_templates':['T-AB-01']},{'id':'arbitration_service_statement','name':'Service\x20(defendant)\x20appends\x20a\x20text\x20statement\x20to\x20the\x20case\x20record','operation_category':'dispute','permission_index':0x141,'permission_name':'SERVICE_ARB_STATEMENT','requires_voting_guard':'not_applicable','requires_usage_guard':'not_applicable','has_passport_variant':!![],'governed_operations':['append\x20the\x20seller\x27s\x20text\x20statement\x20to\x20a\x20case\x20against\x20an\x20order\x20of\x20the\x20service\x20(ArbStatementEvent)'],'common_patterns':['Defendant-side\x20voice\x20WITHOUT\x20holding\x20the\x20order\x20—\x20the\x20arb/arbitration\x20function\x20family\x20is\x20order-anchored;\x20this\x20entry\x20is\x20service-anchored','PRIMARY\x20evidence\x20channel\x20is\x20Messenger:\x20submit\x20encrypted\x20WTS\x20records\x20of\x20the\x20exchange\x20with\x20the\x20order\x20customer\x20first','This\x20statement\x20is\x20the\x20SECONDARY\x20channel:\x20declare\x20facts\x20or\x20report\x20customer\x20behavior\x20(absence,\x20non-cooperation)\x20on\x20the\x20case\x20record','Event-only:\x20nothing\x20on\x20the\x20Arb\x20object\x20is\x20mutated;\x20the\x20record\x20cannot\x20be\x20rewritten\x20or\x20deleted\x20by\x20any\x20party','Text\x20length\x20cap\x20identical\x20to\x20description/objection\x20(DESCRIPTION\x20bound,\x204000)'],'recommended_templates':[]}];export const ARBITRATION_LEDGER_VERSION='1.0.0';export function getScenesByCategory(a){return ARBITRATION_SCENES['filter'](b=>b['operation_category']===a);}export function findSceneById(a){return ARBITRATION_SCENES['find'](b=>b['id']===a);}export function findSceneByPermissionIndex(a){return ARBITRATION_SCENES['find'](b=>b['permission_index']===a);}export function getPermissionByIndex(a){return ARBITRATION_PERMISSIONS['find'](b=>b['index']===a);}export function getPermissionByName(a){return ARBITRATION_PERMISSIONS['find'](b=>b['name']===a);}export function isReservedIndex(a){const b=getPermissionByIndex(a);return!!b?.['is_reserved'];}export function isUsedPermissionIndex(a){const b=getPermissionByIndex(a);return!!b&&!b['is_reserved'];}export function getActivePermissionCount(){return ARBITRATION_PERMISSIONS['filter'](a=>!a['is_reserved'])['length'];}export function inferSceneFromIntent(a){const b=a['toLowerCase'](),c=[{'keywords':['create','new'],'sceneId':'arbitration_create'},{'keywords':['dispute','file','complaint'],'sceneId':'arbitration_dispute'},{'keywords':['vote','voting','decide'],'sceneId':'arbitration_vote'},{'keywords':['confirm','materials'],'sceneId':'arbitration_confirm'},{'keywords':['feedback','opinion'],'sceneId':'arbitration_feedback'},{'keywords':['ruling','arbitration','verdict'],'sceneId':'arbitration_ruling'},{'keywords':['reset','resubmit'],'sceneId':'arbitration_reset'},{'keywords':['arb_withdraw','withdraw','withdraw\x20fees'],'sceneId':'arbitration_arb_withdraw'},{'keywords':['allocate','allocate\x20fees','fees\x20allocation'],'sceneId':'arbitration_fees_alloc'},{'keywords':['fees_transfer','transfer','transfer\x20in'],'sceneId':'arbitration_fees_transfer'},{'keywords':['voting_guard','voting\x20guard'],'sceneId':'arbitration_voting_guard_config'},{'keywords':['usage_guard','usage\x20guard'],'sceneId':'arbitration_usage_guard_config'},{'keywords':['pause','enable'],'sceneId':'arbitration_pause'}];for(const {keywords:d,sceneId:e}of c){if(d['some'](f=>b['includes'](f['toLowerCase']()))){const f=findSceneById(e);if(f)return f;}}return undefined;}export function getDualGuardMatrixEntry(a,b){return DUAL_GUARD_MATRIX['find'](c=>c['voting_guard_empty']===a&&c['usage_guard_empty']===b);}export function isValidArbStatusTransition(a,b){const c={'Principal_confirming':['Arbitrator_confirming'],'Arbitrator_confirming':['Voting','Principal_confirming'],'Voting':['Arbitrated'],'Arbitrated':['Objectionable','Finished','Withdrawn'],'Objectionable':['Principal_confirming'],'Finished':['Withdrawn'],'Withdrawn':[]};return c[a]?.['includes'](b)??![];}export function isTerminalArbStatus(a){return ARB_TERMINAL_STATUSES['includes'](a);}export function getScenesProducingStatus(a){return ARBITRATION_SCENES['filter'](b=>b['resulting_arb_status']===a);}export function getScenesRequiringStatus(a){return ARBITRATION_SCENES['filter'](b=>b['required_arb_status']?.['includes'](a));}export function getArbitrationScenesCount(){return ARBITRATION_SCENES['length'];}export function getAllArbitrationPermissions(){return[...ARBITRATION_PERMISSIONS];}export function getActiveArbitrationPermissions(){return ARBITRATION_PERMISSIONS['filter'](a=>!a['is_reserved']);}
@@ -10,6 +10,7 @@ export interface AuditRule {
10
10
  id: string;
11
11
  description: string;
12
12
  severity: AuditSeverity;
13
+ fields?: string[];
13
14
  check: (data: any, context?: AuditContext) => boolean;
14
15
  message: (data: any) => string;
15
16
  recommendation?: string;
@@ -1 +1 @@
1
- export const AUDIT_RULES=[{'id':'audit_machine_bound','description':'Service\x20should\x20have\x20a\x20Machine\x20workflow\x20bound\x20before\x20publish','severity':'warning','check':(a,b)=>{if(!a?.['publish'])return!![];return!!a?.['machine'];},'message':()=>'Publishing\x20a\x20service\x20without\x20a\x20Machine\x20workflow.\x20Customers\x20won\x27t\x20have\x20a\x20structured\x20order\x20process.','recommendation':'Create\x20a\x20Machine\x20(workflow\x20template)\x20and\x20bind\x20it\x20to\x20the\x20service\x20before\x20publishing.\x20The\x20machine\x20field\x20becomes\x20IMMUTABLE\x20after\x20publish.'},{'id':'audit_order_allocators','description':'Service\x20should\x20have\x20order_allocators\x20for\x20fund\x20distribution','severity':'warning','check':a=>{if(!a?.['publish'])return!![];return Array['isArray'](a?.['order_allocators'])&&a['order_allocators']['length']>0x0;},'message':()=>'Publishing\x20a\x20service\x20without\x20order_allocators.\x20Order\x20funds\x20cannot\x20be\x20auto-distributed\x20to\x20suppliers.','recommendation':'Configure\x20order_allocators\x20before\x20publishing\x20—\x20this\x20field\x20becomes\x20IMMUTABLE\x20after\x20publish.'},{'id':'audit_buy_guard','description':'Service\x20should\x20have\x20a\x20buy_guard\x20for\x20customer\x20screening','severity':'info','check':a=>!!a?.['buy_guard'],'message':()=>'No\x20buy_guard\x20configured\x20—\x20anyone\x20can\x20purchase\x20this\x20service\x20without\x20verification.','recommendation':'Consider\x20adding\x20a\x20Guard\x20to\x20verify\x20customer\x20eligibility\x20(e.g.,\x20identity,\x20wallet\x20balance,\x20location).'},{'id':'audit_compensation_fund','description':'Service\x20should\x20have\x20a\x20compensation_fund\x20for\x20trust','severity':'warning','check':a=>!!a?.['compensation_fund'],'message':()=>'No\x20compensation_fund\x20configured.\x20Customers\x20have\x20no\x20financial\x20protection\x20if\x20you\x20fail\x20to\x20deliver.','recommendation':'Lock\x20a\x20compensation_fund\x20(Treasury)\x20to\x20build\x20trust.\x20The\x20fund\x20deters\x20fraud\x20and\x20enables\x20arbitration\x20claims.'},{'id':'audit_arbitrations','description':'Service\x20should\x20have\x20arbitration\x20options\x20for\x20dispute\x20resolution','severity':'info','check':a=>Array['isArray'](a?.['arbitrations'])&&a['arbitrations']['length']>0x0,'message':()=>'No\x20arbitration\x20configured.\x20Disputes\x20cannot\x20be\x20resolved\x20through\x20a\x20third\x20party.','recommendation':'Add\x20at\x20least\x20one\x20Arb\x20object\x20to\x20enable\x20on-chain\x20dispute\x20resolution.'},{'id':'audit_price','description':'Service\x20should\x20have\x20a\x20price\x20set','severity':'error','check':a=>a?.['price']!==undefined&&a?.['price']!==null,'message':()=>'Service\x20has\x20no\x20price.\x20Customers\x20cannot\x20place\x20orders\x20without\x20knowing\x20the\x20cost.','recommendation':'Set\x20the\x20price\x20field\x20before\x20publishing.'},{'id':'audit_description','description':'Service\x20should\x20have\x20a\x20description','severity':'warning','check':a=>typeof a?.['description']==='string'&&a['description']['length']>0x0,'message':()=>'Service\x20has\x20no\x20description.\x20Customers\x20won\x27t\x20understand\x20what\x20you\x27re\x20offering.','recommendation':'Write\x20a\x20clear\x20description\x20of\x20the\x20service,\x20including\x20deliverables,\x20timelines,\x20and\x20terms.'},{'id':'audit_named_new_name','description':'Service\x20being\x20created\x20should\x20have\x20a\x20name','severity':'warning','check':a=>!!a?.['namedNew']?.['name']||typeof a?.['object']==='string','message':()=>'Creating\x20a\x20service\x20without\x20a\x20name\x20makes\x20it\x20hard\x20to\x20reference\x20and\x20organize.','recommendation':'Set\x20namedNew.name\x20following\x20the\x20convention:\x20<projectPrefix>_<service>_<purpose>.'},{'id':'audit_dangling_deps','description':'Service\x20dependencies\x20should\x20be\x20fully\x20created','severity':'error','check':(a,b)=>{if(!a?.['publish'])return!![];if(!b?.['graph'])return!![];const c=b['graph']['findDanglingDependencies']()??[];return c['length']===0x0;},'message':()=>'Service\x20references\x20objects\x20that\x20are\x20not\x20yet\x20created.\x20Publishing\x20will\x20lock\x20these\x20references.','recommendation':'Ensure\x20all\x20referenced\x20objects\x20(machine,\x20allocators,\x20guards)\x20are\x20created\x20and\x20finalized\x20before\x20publishing.'},{'id':'audit_type_parameter','description':'Service\x20should\x20have\x20a\x20token\x20type\x20specified','severity':'info','check':a=>!!a?.['type_parameter']||!!a?.['namedNew']?.['type_parameter'],'message':()=>'No\x20payment\x20token\x20type\x20specified.\x20Defaulting\x20to\x20WOW\x20(0x2::wow::WOW).','recommendation':'Explicitly\x20set\x20type_parameter\x20if\x20you\x20want\x20to\x20accept\x20non-WOW\x20tokens\x20(e.g.,\x20USDT,\x20ETH).'}];const RULE_INDEX=new Map(AUDIT_RULES['map'](a=>[a['id'],a]));export function auditService(a,b){const c=[];for(const d of AUDIT_RULES){try{!d['check'](a,b)&&c['push']({'rule_id':d['id'],'severity':d['severity'],'message':d['message'](a),'recommendation':d['recommendation']});}catch{}}return c;}export function hasBlockingErrors(a){return a['some'](b=>b['severity']==='error');}export function getErrors(a){return a['filter'](b=>b['severity']==='error');}export function getWarnings(a){return a['filter'](b=>b['severity']==='warning');}export function summarizeFindings(a){if(a['length']===0x0)return'All\x20audit\x20checks\x20passed.';const b=getErrors(a),c=getWarnings(a),d=a['filter'](g=>g['severity']==='info'),e=[];if(b['length']>0x0)e['push'](b['length']+'\x20error(s)');if(c['length']>0x0)e['push'](c['length']+'\x20warning(s)');if(d['length']>0x0)e['push'](d['length']+'\x20info');return'Audit:\x20'+e['join'](',\x20')+'.\x20Review\x20before\x20publishing.';}export const AUDIT_RULES_VERSION=0x1;
1
+ export const AUDIT_RULES=[{'id':'audit_machine_bound','description':'Service\x20should\x20have\x20a\x20Machine\x20workflow\x20bound\x20before\x20publish','severity':'warning','fields':['machine'],'check':(a,b)=>{if(!a?.['publish'])return!![];return!!a?.['machine'];},'message':()=>'Publishing\x20a\x20service\x20without\x20a\x20Machine\x20workflow.\x20Customers\x20won\x27t\x20have\x20a\x20structured\x20order\x20process.','recommendation':'Create\x20a\x20Machine\x20(workflow\x20template)\x20and\x20bind\x20it\x20to\x20the\x20service\x20before\x20publishing.\x20The\x20machine\x20field\x20becomes\x20IMMUTABLE\x20after\x20publish.'},{'id':'audit_order_allocators','description':'Service\x20should\x20have\x20order_allocators\x20for\x20fund\x20distribution','severity':'warning','fields':['order_allocators'],'check':a=>{if(!a?.['publish'])return!![];return Array['isArray'](a?.['order_allocators'])&&a['order_allocators']['length']>0x0;},'message':()=>'Publishing\x20a\x20service\x20without\x20order_allocators.\x20Order\x20funds\x20cannot\x20be\x20auto-distributed\x20to\x20suppliers.','recommendation':'Configure\x20order_allocators\x20before\x20publishing\x20—\x20this\x20field\x20becomes\x20IMMUTABLE\x20after\x20publish.'},{'id':'audit_buy_guard','description':'Service\x20should\x20have\x20a\x20buy_guard\x20for\x20customer\x20screening','severity':'info','fields':['buy_guard'],'check':a=>!!a?.['buy_guard'],'message':()=>'No\x20buy_guard\x20configured\x20—\x20anyone\x20can\x20purchase\x20this\x20service\x20without\x20verification.','recommendation':'Consider\x20adding\x20a\x20Guard\x20to\x20verify\x20customer\x20eligibility\x20(e.g.,\x20identity,\x20wallet\x20balance,\x20location).'},{'id':'audit_compensation_fund','description':'Service\x20should\x20have\x20a\x20compensation_fund\x20for\x20trust','severity':'warning','fields':['compensation_fund'],'check':a=>!!a?.['compensation_fund'],'message':()=>'No\x20compensation_fund\x20configured.\x20Customers\x20have\x20no\x20financial\x20protection\x20if\x20you\x20fail\x20to\x20deliver.','recommendation':'Lock\x20a\x20compensation_fund\x20(Treasury)\x20to\x20build\x20trust.\x20The\x20fund\x20deters\x20fraud\x20and\x20enables\x20arbitration\x20claims.'},{'id':'audit_arbitrations','description':'Service\x20should\x20have\x20arbitration\x20options\x20for\x20dispute\x20resolution','severity':'info','fields':['arbitrations'],'check':a=>Array['isArray'](a?.['arbitrations'])&&a['arbitrations']['length']>0x0,'message':()=>'No\x20arbitration\x20configured.\x20Disputes\x20cannot\x20be\x20resolved\x20through\x20a\x20third\x20party.','recommendation':'Add\x20at\x20least\x20one\x20Arb\x20object\x20to\x20enable\x20on-chain\x20dispute\x20resolution.'},{'id':'audit_price','description':'Service\x20should\x20have\x20a\x20price\x20set','severity':'error','fields':['price'],'check':a=>a?.['price']!==undefined&&a?.['price']!==null,'message':()=>'Service\x20has\x20no\x20price.\x20Customers\x20cannot\x20place\x20orders\x20without\x20knowing\x20the\x20cost.','recommendation':'Set\x20the\x20price\x20field\x20before\x20publishing.'},{'id':'audit_description','description':'Service\x20should\x20have\x20a\x20description','severity':'warning','fields':['description'],'check':a=>typeof a?.['description']==='string'&&a['description']['length']>0x0,'message':()=>'Service\x20has\x20no\x20description.\x20Customers\x20won\x27t\x20understand\x20what\x20you\x27re\x20offering.','recommendation':'Write\x20a\x20clear\x20description\x20of\x20the\x20service,\x20including\x20deliverables,\x20timelines,\x20and\x20terms.'},{'id':'audit_named_new_name','description':'Service\x20being\x20created\x20should\x20have\x20a\x20name','severity':'warning','check':a=>!!a?.['namedNew']?.['name']||typeof a?.['object']==='string','message':()=>'Creating\x20a\x20service\x20without\x20a\x20name\x20makes\x20it\x20hard\x20to\x20reference\x20and\x20organize.','recommendation':'Set\x20namedNew.name\x20following\x20the\x20convention:\x20<projectPrefix>_<service>_<purpose>.'},{'id':'audit_dangling_deps','description':'Service\x20dependencies\x20should\x20be\x20fully\x20created','severity':'error','check':(a,b)=>{if(!a?.['publish'])return!![];if(!b?.['graph'])return!![];const c=b['graph']['findDanglingDependencies']()??[];return c['length']===0x0;},'message':()=>'Service\x20references\x20objects\x20that\x20are\x20not\x20yet\x20created.\x20Publishing\x20will\x20lock\x20these\x20references.','recommendation':'Ensure\x20all\x20referenced\x20objects\x20(machine,\x20allocators,\x20guards)\x20are\x20created\x20and\x20finalized\x20before\x20publishing.'},{'id':'audit_type_parameter','description':'Service\x20should\x20have\x20a\x20token\x20type\x20specified','severity':'info','fields':['type_parameter'],'check':a=>!!a?.['type_parameter']||!!a?.['namedNew']?.['type_parameter'],'message':()=>'No\x20payment\x20token\x20type\x20specified.\x20Defaulting\x20to\x20WOW\x20(0x2::wow::WOW).','recommendation':'Explicitly\x20set\x20type_parameter\x20if\x20you\x20want\x20to\x20accept\x20non-WOW\x20tokens\x20(e.g.,\x20USDT,\x20ETH).'}];const RULE_INDEX=new Map(AUDIT_RULES['map'](a=>[a['id'],a]));export function auditService(a,b){const c=[],d=a?.['publish']===!![]&&typeof a?.['object']==='string';for(const e of AUDIT_RULES){try{if(d&&e['fields']&&!e['fields']['some'](g=>a[g]!==undefined))continue;!e['check'](a,b)&&c['push']({'rule_id':e['id'],'severity':e['severity'],'message':e['message'](a),'recommendation':e['recommendation']});}catch{}}return c;}export function hasBlockingErrors(a){return a['some'](b=>b['severity']==='error');}export function getErrors(a){return a['filter'](b=>b['severity']==='error');}export function getWarnings(a){return a['filter'](b=>b['severity']==='warning');}export function summarizeFindings(a){if(a['length']===0x0)return'All\x20audit\x20checks\x20passed.';const b=getErrors(a),c=getWarnings(a),d=a['filter'](g=>g['severity']==='info'),e=[];if(b['length']>0x0)e['push'](b['length']+'\x20error(s)');if(c['length']>0x0)e['push'](c['length']+'\x20warning(s)');if(d['length']>0x0)e['push'](d['length']+'\x20info');return'Audit:\x20'+e['join'](',\x20')+'.\x20Review\x20before\x20publishing.';}export const AUDIT_RULES_VERSION=0x1;
@@ -152,6 +152,26 @@
152
152
  }
153
153
  ]
154
154
  },
155
+ {
156
+ "rule_id": "RC-FIND-09",
157
+ "dimension": "fund_destination",
158
+ "trigger": "Allocator Guard has no GuardIdentifier sharing row — bound to no particular order.",
159
+ "cases": [
160
+ {
161
+ "when": { "field": "code", "op": "eq", "value": "RC-FIND-09" },
162
+ "level": "low",
163
+ "title": "Allocator Guard has no GuardIdentifier sharing row — bound to no particular order",
164
+ "description": "Every sharing row of service ${host_service}'s allocator (rule ${code}) is a fixed recipient (Entity/Signer), which resolves no submission: the Guard cannot read the paying order and the allocation pays the same fixed destinations for EVERY order. Often intended — confirm it is.",
165
+ "mitigation": "If the Guard should distinguish orders, add a zero-share {GuardIdentifier: 0} anchor row (Rate 0) so the Identifier slot resolves to the paying order (design pattern allocator_order_anchor). If fixed-pay is intended, no action.",
166
+ "exposure": {
167
+ "loss_parties": [
168
+ { "role": "buyer", "basis": "Allocator behavior cannot vary per order — any per-order conditions in the Guard never see the order." }
169
+ ],
170
+ "gain_paths": []
171
+ }
172
+ }
173
+ ]
174
+ },
155
175
  {
156
176
  "rule_id": "RC-FIND-07",
157
177
  "dimension": "fund_destination",
@@ -56,8 +56,7 @@
56
56
  "bound_order_paren_display": "Rendered bound_order — '(unknown)' when the context carries none (description form).",
57
57
  "has_payment_info": "Whether payment_info is present for the alloc() call.",
58
58
  "operation_type": "Raw operation type ('create' | 'receive' | 'alloc_by_guard' | 'query').",
59
- "max_allocator_count": "KERNEL CONSTANT — allocators per Allocation cap (MAX_ALLOCATOR_COUNT).",
60
- "always_true": "Extractor sentinel — unconditionally true; marks the always-on constant-sync reminder (R-A-5-03)."
59
+ "max_allocator_count": "KERNEL CONSTANT — allocators per Allocation cap (MAX_ALLOCATOR_COUNT)."
61
60
  },
62
61
  "rules": [
63
62
  {
@@ -470,23 +469,6 @@
470
469
  "stakeholders": ["owner"]
471
470
  }
472
471
  ]
473
- },
474
- {
475
- "rule_id": "R-A-5-03",
476
- "dimension": "cross_object",
477
- "trigger": "MAX_ALLOCATOR_COUNT not synced to onchain-constants.ts",
478
- "cases": [
479
- {
480
- "when": { "field": "always_true", "op": "eq", "value": true },
481
- "level": "low",
482
- "title": "MAX_ALLOCATOR_COUNT not synced to onchain-constants.ts",
483
- "description": "The Move layer defines MAX_ALLOCATOR_COUNT=${max_allocator_count}, but onchain-constants.ts does NOT export this constant. SDK allocation.ts:318 defines it locally, creating a double-definition risk. MCP knowledge imports the local definition.",
484
- "scenario": "Constant sync drift between Move / SDK / MCP",
485
- "mitigation": "1) Add MAX_ALLOCATOR_COUNT=100 to onchain-constants.ts. 2) Update SDK allocation.ts to import from onchain-constants.js. 3) Delete local definition.",
486
- "evidence": "MAX_ALLOCATOR_COUNT=${max_allocator_count} (local), not in onchain-constants.ts",
487
- "stakeholders": ["system"]
488
- }
489
- ]
490
472
  }
491
473
  ]
492
474
  }
@@ -41,7 +41,7 @@
41
41
  "when": { "field": "withdraw_too_early", "op": "eq", "value": true },
42
42
  "level": "medium",
43
43
  "title": "WITHDRAW_DURATION_TIME=${withdraw_duration_time_ms}ms (30 days) — funds locked",
44
- "description": "After arbitration, the fee Balance can only be withdrawn after WITHDRAW_DURATION_TIME=${withdraw_duration_time_ms}ms (30 days) when status is Arbitrated(3) or Objectionable(4). From Finished(5), withdraw is immediate. The 30-day lock is a dispute-window safeguard, but it locks funds for a long time and users may not understand why.",
44
+ "description": "After arbitration, the fee Balance can only be withdrawn after WITHDRAW_DURATION_TIME=${withdraw_duration_time_ms}ms (30 days) when status is Arbitrated(3) with no objection filed (silence = acceptance). From Finished(5), withdraw is immediate. From Objectionable(4), withdraw is NEVER possible (protocol 141): a contested case keeps its fee escrowed until the principal closes the objection cycle — reset → order.arb_confirm → new ruling → unchallenged. States 0/1/2 are also rejected.",
45
45
  "scenario": "Arbitrator finishes a case but must wait 30 days to claim the fee",
46
46
  "mitigation": "Surface the unlock timestamp in the UI. To shorten the lock, drive the case to Finished(5) via finish() rather than leaving it in Arbitrated/Objectionable.",
47
47
  "evidence": "withdraw_too_early=true (limit=${withdraw_duration_time_ms}ms)",