@wowok/agent-mcp 3.2.4 → 3.2.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 (90) hide show
  1. package/dist/composition/blueprint-view.d.ts +64 -0
  2. package/dist/composition/blueprint-view.js +1 -0
  3. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  4. package/dist/evaluation/engine.js +1 -1
  5. package/dist/experience/realtime-feedback.js +1 -1
  6. package/dist/extensions/industry-pack.d.ts +1 -0
  7. package/dist/extensions/industry-pack.js +1 -1
  8. package/dist/extensions/modes.js +1 -1
  9. package/dist/extensions/registry.d.ts +1 -2
  10. package/dist/extensions/registry.js +1 -1
  11. package/dist/graph/onchain/expand.js +1 -1
  12. package/dist/graph/onchain/exposure.js +1 -1
  13. package/dist/graph/onchain/facts.js +1 -1
  14. package/dist/harness/recover.js +1 -1
  15. package/dist/knowledge/audit-rules.d.ts +2 -0
  16. package/dist/knowledge/audit-rules.js +1 -1
  17. package/dist/knowledge/baselines/rules/allocation.json +5 -5
  18. package/dist/knowledge/baselines/rules/arb.json +1 -1
  19. package/dist/knowledge/baselines/rules/guard.json +9 -9
  20. package/dist/knowledge/baselines/rules/machine.json +5 -5
  21. package/dist/knowledge/baselines/rules/order.json +1 -1
  22. package/dist/knowledge/builtin-templates.d.ts +2 -1
  23. package/dist/knowledge/builtin-templates.js +1 -1
  24. package/dist/knowledge/entity-recipient-guard.js +1 -1
  25. package/dist/knowledge/getting-started.js +1 -1
  26. package/dist/knowledge/guard-design-patterns.js +1 -1
  27. package/dist/knowledge/guard-risk.js +1 -1
  28. package/dist/knowledge/guard-templates.d.ts +1 -1
  29. package/dist/knowledge/guard-templates.js +1 -1
  30. package/dist/knowledge/index.js +1 -1
  31. package/dist/knowledge/industry-generalizer.js +1 -1
  32. package/dist/knowledge/industry-registry.js +1 -1
  33. package/dist/knowledge/jsonrpc-enum.js +1 -1
  34. package/dist/knowledge/order-ledger.js +1 -1
  35. package/dist/knowledge/scenario-modes.d.ts +2 -4
  36. package/dist/knowledge/scenario-modes.js +1 -1
  37. package/dist/knowledge/service-ledger.js +1 -1
  38. package/dist/knowledge/service-templates.js +1 -1
  39. package/dist/knowledge/template-loader.d.ts +7 -2
  40. package/dist/knowledge/template-loader.js +1 -1
  41. package/dist/knowledge/template-registry.js +1 -1
  42. package/dist/knowledge/template-scanner.js +1 -1
  43. package/dist/knowledge/template-validation.d.ts +2 -0
  44. package/dist/knowledge/template-validation.js +1 -0
  45. package/dist/monitor/MonitorLoop.js +1 -1
  46. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  47. package/dist/playbooks/service-build/game-theory.d.ts +2 -2
  48. package/dist/playbooks/service-build/game-theory.js +1 -1
  49. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  50. package/dist/playbooks/service-build/merchant-guide.d.ts +54 -11
  51. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  52. package/dist/playbooks/service-build/mode-actions.js +1 -1
  53. package/dist/playbooks/service-build/object-panorama.js +1 -1
  54. package/dist/playbooks/service-build/participation-radar.js +1 -1
  55. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  56. package/dist/playbooks/service-build/reverse-mapping-nk4.spec.d.ts +1 -0
  57. package/dist/playbooks/service-build/reverse-mapping-nk4.spec.js +1 -0
  58. package/dist/playbooks/service-build/reverse-mapping.d.ts +24 -0
  59. package/dist/playbooks/service-build/reverse-mapping.js +1 -1
  60. package/dist/playbooks/service-build/service-panorama.js +1 -1
  61. package/dist/playbooks/service-build/service-quote.js +1 -1
  62. package/dist/playbooks/service-build/workflow-design-assessment.d.ts +2 -2
  63. package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
  64. package/dist/review/index.js +1 -1
  65. package/dist/safety/confirm-gate.js +1 -1
  66. package/dist/schema/call/handler.js +1 -1
  67. package/dist/schema/call/semantic.js +1 -1
  68. package/dist/schema/call/service.d.ts +14 -0
  69. package/dist/schema/call/service.js +1 -1
  70. package/dist/schema/common/index.js +1 -1
  71. package/dist/schema/goal/planning.js +1 -1
  72. package/dist/schema/local/index.js +1 -1
  73. package/dist/schema/operations.d.ts +7 -0
  74. package/dist/schema/schema-version.js +1 -1
  75. package/dist/schema-query-impl/index.js +1 -1
  76. package/dist/schemas/goal_operation.schema.json +1 -1
  77. package/dist/schemas/index.json +1 -1
  78. package/dist/schemas/onchain_operations.schema.json +37 -2
  79. package/dist/schemas/onchain_operations_service.schema.json +37 -2
  80. package/dist/tools/handlers/benchmark-migration.d.ts +2 -13
  81. package/dist/tools/handlers/benchmark-migration.js +1 -1
  82. package/dist/tools/handlers/config.js +1 -1
  83. package/dist/tools/handlers/industry-pack.js +1 -1
  84. package/dist/tools/handlers/onchain.js +1 -1
  85. package/dist/tools/handlers/query.js +1 -1
  86. package/dist/tools/registry/agent.js +1 -1
  87. package/dist/tools/wip-deploy-assist.js +1 -1
  88. package/package.json +2 -2
  89. package/dist/playbooks/service-build/semantic-graph.d.ts +0 -99
  90. package/dist/playbooks/service-build/semantic-graph.js +0 -1
@@ -1 +1 @@
1
- import{GUARDQUERY}from'@wowok/wowok';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{factoryRulePack,getJudgmentDoc}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';function rootRaw(a){try{return JSON['stringify'](a)??'';}catch{return'';}}function hasSignerCheck(a){return a['includes']('\x22Signer\x22');}function hasClockCheck(a){return a['includes']('\x22Clock\x22');}function hasGuardSelfRef(a){return a['includes']('\x22Guard\x22');}function hasWitness(a){return a['includes']('\x22convert_witness\x22');}function extractWitnessCodes(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"convert_witness"\s*:\s*(\d+)/g);for(const e of d){const f=parseInt(e[0x1],0xa);if(f>=0x64&&f<=0x6c)b['push'](f);}return b;}const WITNESS_CHAIN={0x64:['Order','Progress'],0x65:['Order','Machine'],0x66:['Order','Service'],0x67:['Progress','Machine'],0x68:['Arb','Order'],0x69:['Arb','Arbitration'],0x6a:['Arb','Order','Progress'],0x6b:['Arb','Order','Service'],0x6c:['Arb','Order','Machine']};function extractWitnessIdentifierPairs(a){const b=[],c=new WeakSet();function d(e){if(e===null||typeof e!=='object')return;if(c['has'](e))return;c['add'](e);typeof e['convert_witness']==='number'&&typeof e['identifier']==='number'&&b['push']({'code':e['convert_witness'],'identifier':e['identifier']});for(const f of Object['keys'](e)){const g=e[f];if(Array['isArray'](g)){for(const h of g)d(h);}else g!==null&&typeof g==='object'&&d(g);}}return d(a),b;}function getChildNodes(a){if(!a||typeof a!=='object')return[];const b=[];if(Array['isArray'](a['nodes']))b['push'](...a['nodes']);if(a['left'])b['push'](a['left']);if(a['right'])b['push'](a['right']);if(a['vec'])b['push'](a['vec']);if(a['target'])b['push'](a['target']);if(a['object']&&typeof a['object']==='object')b['push'](a['object']);if(Array['isArray'](a['parameters']))b['push'](...a['parameters']);return b['filter'](d=>d&&typeof d==='object');}function findSignerLogicEqualNodes(a){const b=[];function c(d,e){if(!d||typeof d!=='object')return;if(d['type']==='logic_equal'){const f=Array['isArray'](d['nodes'])?d['nodes']:d['left']&&d['right']?[d['left'],d['right']]:[];if(f['length']===0x2){const g=f['findIndex'](h=>h?.['type']==='context'&&h?.['context']==='Signer');g>=0x0&&b['push']({'node':d,'parentType':e,'otherOperand':f[0x1-g]});}}for(const h of getChildNodes(d)){c(h,d['type']);}}return c(a,null),b;}function detectLevel1StrictBinding(a,b){const c=findSignerLogicEqualNodes(a);for(const d of c){const e=d['otherOperand'];if(e?.['type']==='identifier'){const f=b['find'](g=>g['identifier']===e['identifier']);if(f&&!f['b_submission']&&f['value_type']==='Address'&&typeof f['value']==='string'&&f['value']['length']>0x0)return{'detected':!![],'entry':{'identifier':f['identifier'],'value':f['value'],'name':f['name']}};}}return{'detected':![]};}function isSignerCheckInLogicOr(a){const b=findSignerLogicEqualNodes(a);return b['some'](c=>c['parentType']==='logic_or');}const QUERY_INVARIANT_MAP=((()=>{const a=new Map();for(const b of GUARDQUERY){b['invariant']!==undefined&&a['set'](b['id'],b['invariant']);}return a;})());function extractQueryIds(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"query"\s*:\s*(\d+)/g);for(const f of d){const g=parseInt(f[0x1],0xa);if(!b['includes'](g))b['push'](g);}const e=c['matchAll'](/"query"\s*:\s*"([^"]+)"/g);for(const h of e){const i=h[0x1],j=GUARDQUERY['find'](k=>k['name']===i);if(j&&!b['includes'](j['id']))b['push'](j['id']);}return b;}function bareBoolQueryClauses(a){const b=[],c=(d,e)=>{if(e>0x40||!d||typeof d!=='object'||typeof d['type']!=='string')return;if((d['type']==='logic_and'||d['type']==='logic_or')&&Array['isArray'](d['nodes']))for(const f of d['nodes']){if(f&&typeof f==='object'&&f['type']==='query'){const g=f['query'],h=typeof g==='number'?'#'+g:typeof g==='string'?g:'(unknown\x20query)';if(!b['includes'](h))b['push'](h);}}if(Array['isArray'](d['nodes'])){for(const i of d['nodes'])c(i,e+0x1);}if(d['node'])c(d['node'],e+0x1);};return c(a,0x0),b;}function rootAllQueriesNonZero(a){const b=extractQueryIds(a);if(b['length']===0x0)return![];return b['every'](c=>QUERY_INVARIANT_MAP['has'](c));}const REENTRANCY_SPECS=[{'sceneId':'reward_claim','level':'critical','existsPrimitives':[0x64d],'countPrimitives':[0x64c],'addressPrimitives':[0x65a],'rationale':'Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20'+'Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20'+'This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene\x20—\x20direct\x20fund\x20loss.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and\x20with\x20existing\x20conditions):\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record\x20has\x27,\x20object=reward,\x20parameters=[claimant_address]))\x20—\x20RECOMMENDED\x20(per-user\x20Bool\x20check)\x0a'+'\x20\x20-\x20logic_equal([query(\x27reward.record\x20count\x27,\x20object=reward),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20total-claim\x20count\x20is\x200\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record.find_first\x27,\x20object=reward,\x20where={...}))\x20—\x20no\x20matching\x20record\x20found\x0a'+'Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20(logic_not(query_reward_record_exists(where.storeFromId=order_id)))'},{'sceneId':'arbitration_voting_guard','level':'critical','existsPrimitives':[0x57c,0x57e],'countPrimitives':[0x57d],'addressPrimitives':[],'rationale':'Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20'+'multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20—\x20which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation.\x20'+'The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20'+'Note:\x20arb.voted_count\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20an\x20individual\x20voter.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted\x20has\x27,\x20object=arb,\x20parameters=[voter_address]))\x20—\x20RECOMMENDED\x20(per-voter\x20Bool)\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted.agree\x20has\x27,\x20object=arb,\x20parameters=[voter_address,\x20proposition_index]))\x20—\x20per-voter-per-proposition\x0a'+'\x20\x20-\x20logic_equal([query(\x27arb.voted.agree\x20count\x27,\x20object=arb,\x20parameters=[voter_address]),\x20identifier(N)])\x20where\x20table[N].value=0'},{'sceneId':'arbitration_usage_guard','level':'high','existsPrimitives':[0x61d],'countPrimitives':[0x61c],'addressPrimitives':[],'rationale':'Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20'+'(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20'+'Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Filing\x20a\x20dispute\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27order.dispute\x20has\x27,\x20object=order,\x20parameters=[existing_arb_address]))\x20—\x20per-Arb\x20check\x0a'+'\x20\x20-\x20logic_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20STRICT:\x20block\x20any\x20prior\x20dispute\x0a'+'\x20\x20-\x20logic_as_u256_lesser_or_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=K\x20—\x20LENIENT:\x20allow\x20up\x20to\x20K\x20disputes'},{'sceneId':'service_order_allocators_guard','level':'low','existsPrimitives':[0x620],'countPrimitives':[],'addressPrimitives':[0x621],'rationale':'Protocol-level\x20protection:\x20attaching\x20an\x20Allocation\x20to\x20an\x20Order\x20asserts\x20ONE\x20Allocation\x20per\x20Order\x20(E_ALLOCATION_ALREADY_SPECIFIED).\x20'+'After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20Surplus-mode\x20allocators\x20drain\x20balance\x20to\x200,\x20making\x20reentrancy\x20unprofitable.\x20'+'EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/RateGross/Surplus\x20modes.\x20'+'External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).','mitigation':'Default:\x20no\x20action\x20needed\x20(protocol-level\x20guard).\x20IF\x20using\x20Amount-mode-only\x20allocators\x20without\x20Surplus:\x20'+'consider\x20adding\x20logic_not(query(\x27order.allocation\x20some\x27,\x20object=order))\x20OR\x20switch\x20to\x20Rate/Surplus\x20mode\x20to\x20drain\x20balance\x20completely.'},{'sceneId':'service_buy_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20'+'IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20'+'but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history.','mitigation':'IF\x20limit-purchase\x20intent:\x20record\x20purchases\x20in\x20a\x20Repository\x20and\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20...))\x20to\x20root;\x20'+'OR\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy;\x20OR\x20use\x20an\x20off-chain\x20allowlist\x20with\x20on-chain\x20Merkle\x20proof.'},{'sceneId':'repository_write_guard','level':'low','existsPrimitives':[0x48e],'countPrimitives':[],'addressPrimitives':[],'rationale':'Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.','mitigation':'IF\x20one-write-per-ID\x20intent:\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20object=repository,\x20parameters=[policy_name,\x20user_or_object_id]))\x20to\x20root.'},{'sceneId':'gen_passport_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20'+'Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists.','mitigation':'IF\x20one-passport-per-user\x20intent:\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs.'}],QUERY_TYPE_ALIASES=new Map([['query_reward_record_exists',0x64d],['query_reward_record_count',0x64c],['query_reward_record_find',0x65a],['query_progress_history_find',0x4fa],['query_progress_history_session_find',0x4fb],['query_progress_history_session_forward_find',0x4fc],['query_progress_history_session_count',0x4f9],['query_progress_history_session_forward_count',0x4ee],['query_repository_data_count_where',0x495],['query_repository_data_sum_where',0x496],['query_repository_policies_keys',0x497],['query_repository_data_find_where',0x498],['query_repository_data_keys_where',0x499]]);function detectReentrancyProtection(a,b,c){const d=new Set([...c['existsPrimitives'],...c['countPrimitives'],...c['addressPrimitives']]);if(d['size']===0x0)return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20available\x20in\x20GUARDQUERY\x20for\x20this\x20scene'};const e=new Map(),f=new Map();for(const p of d){const q=GUARDQUERY['find'](r=>r['id']===p);q&&(e['set'](p,q['name']),f['set'](q['name'],p));}const g=Array['from'](f['keys']());function h(r){if(!r||typeof r!=='object')return-0x1;if(typeof r['query']==='number'&&d['has'](r['query']))return r['query'];if(typeof r['query']==='string'&&f['has'](r['query']))return f['get'](r['query']);if(typeof r['type']==='string'&&QUERY_TYPE_ALIASES['has'](r['type'])){const s=QUERY_TYPE_ALIASES['get'](r['type']);if(d['has'](s))return s;}if(typeof r['type']==='string'&&f['has'](r['type']))return f['get'](r['type']);return-0x1;}function i(r){if(!r||typeof r!=='object')return![];if(typeof r['type']==='string'&&['number','u8','u16','u32','u64','u128','u256']['includes'](r['type']))return r['value']===0x0||r['value']==='0'||r['value']===0x0n;if(r['type']==='identifier'&&typeof r['identifier']==='number'){const s=b['find'](t=>t['identifier']===r['identifier']);if(s&&!s['b_submission'])return s['value']===0x0||s['value']==='0'||s['value']===0x0n;}return![];}function j(r,s){if(!r||typeof r!=='object')return[];const t=[];if(Array['isArray'](r['nodes']))for(const u of r['nodes']){if(u!==s)t['push'](u);}if(r['left']&&r['left']!==s)t['push'](r['left']);if(r['right']&&r['right']!==s)t['push'](r['right']);return t['filter'](v=>v&&typeof v==='object');}let k=![],l=![],m='',n='';function o(r,s){if(!r||typeof r!=='object')return;const t=h(r);if(t>=0x0){k=!![];const v=e['get'](t)??'query_'+t;n=v;const w=s?.['type']??null;let x=![];const y=c['existsPrimitives']['includes'](t),z=c['addressPrimitives']['includes'](t),A=c['countPrimitives']['includes'](t);(y||z)&&w==='logic_not'&&(x=!![]);if(A&&w==='logic_equal'){const B=j(s,r);B['some'](C=>i(C))&&(x=!![]);}if(x)l=!![];else{if(!m){const C=A?'logic_equal\x20with\x20a\x20zero\x20operand':'logic_not';m='Primitive\x20\x22'+v+'\x22\x20found\x20but\x20its\x20immediate\x20parent\x20is\x20'+(w??'root')+'\x20(expected\x20'+C+').\x20The\x20primitive\x20is\x20present\x20but\x20does\x20NOT\x20actually\x20prevent\x20reentrancy\x20—\x20this\x20is\x20a\x20false\x20sense\x20of\x20security.';}}}const u=[];if(Array['isArray'](r['nodes']))u['push'](...r['nodes']);if(r['left'])u['push'](r['left']);if(r['right'])u['push'](r['right']);if(r['node'])u['push'](r['node']);if(r['vec'])u['push'](r['vec']);if(r['target'])u['push'](r['target']);if(r['object']&&typeof r['object']==='object')u['push'](r['object']);if(Array['isArray'](r['parameters']))u['push'](...r['parameters']);for(const D of u){D&&typeof D==='object'&&o(D,r);}}o(a,null);if(l)return{'state':'protected','evidence':'Anti-reentrancy\x20primitive\x20\x22'+n+'\x22\x20is\x20properly\x20wrapped','foundPrimitiveName':n};if(k)return{'state':'pseudo','evidence':m,'foundPrimitiveName':n};return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20found\x20in\x20root.\x20Expected\x20one\x20of:\x20'+g['join'](',\x20')};}function stableKey(a){if(a===null||typeof a!=='object')return JSON['stringify'](a)??'null';if(Array['isArray'](a))return'['+a['map'](stableKey)['join'](',')+']';const b=a;return'{'+Object['keys'](b)['sort']()['map'](c=>JSON['stringify'](c)+':'+stableKey(b[c]))['join'](',')+'}';}function readsContext(a){return rootRaw(a)['includes']('\x22context\x22');}const NUMERIC_VALUE_TYPE=/^u(?:8|16|32|64|128|256)$/i,NUMERIC_NODE_TYPES=new Set(['calc_number_add','calc_number_multiply','calc_number_subtract','calc_number_divide','calc_number_mod','convert_address_number','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','vec_length','calc_string_length']),REFLEXIVE_TRUE_OPS=new Set(['logic_equal','logic_as_u256_equal','logic_string_nocase_equal','calc_string_nocase_equal','logic_string_contains','calc_string_contains','logic_string_nocase_contains','calc_string_nocase_contains']),REFLEXIVE_FALSE_OPS=new Set(['logic_not_equal','logic_as_u256_greater','logic_as_u256_lesser']);function tableEntryOf(a,b){if(!a||a['type']!=='identifier')return undefined;return b['find'](c=>c['identifier']===a['identifier']);}function staticValueType(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return undefined;if(a['type']==='identifier')return tableEntryOf(a,b)?.['value_type'];const c=QUERY_TYPE_ALIASES['get'](a['type']),d=a['type']==='query'?a['query']:c;if(d!==undefined){const e=GUARDQUERY['find'](f=>f['id']===d||typeof d==='string'&&f['name']===d);if(e)return String(e['return']);}return NUMERIC_NODE_TYPES['has'](a['type'])?'U64':undefined;}function constantNumber(a,b){const c=tableEntryOf(a,b);if(!c||c['b_submission'])return undefined;if(!NUMERIC_VALUE_TYPE['test'](String(c['value_type'])))return undefined;const d=String(c['value']??'')['trim']();if(!/^\d+$/['test'](d))return undefined;try{return BigInt(d);}catch{return undefined;}}function foldCertainOutcome(c,d,e=0x0){if(e>0x40||!c||typeof c!=='object'||typeof c['type']!=='string')return undefined;const f=Array['isArray'](c['nodes'])?c['nodes']:[],g=i=>foldCertainOutcome(i,d,e+0x1),h=()=>f['length']>0x0?f['map'](g):undefined;switch(c['type']){case'identifier':{const i=tableEntryOf(c,d);if(!i||i['b_submission'])return undefined;if(/^bool$/i['test'](String(i['value_type']))){const j=String(i['value']??'')['trim']()['toLowerCase']();if(j==='true'||j==='false')return{'outcome':j,'reason':'table\x20entry\x20#'+i['identifier']+'\x20is\x20the\x20constant\x20Bool\x20'+j};}return undefined;}case'logic_and':{const k=h();if(!k)return undefined;const l=k['find'](m=>m?.['outcome']==='false');if(l)return{'outcome':'false','reason':'a\x20logic_and\x20branch\x20is\x20always\x20false:\x20'+l['reason']};if(k['every'](m=>m?.['outcome']==='true'))return{'outcome':'true','reason':'every\x20logic_and\x20branch\x20is\x20always\x20true:\x20'+(k[0x0]?.['reason']??'')};return undefined;}case'logic_or':{const m=h();if(!m)return undefined;const n=m['find'](o=>o?.['outcome']==='true');if(n)return{'outcome':'true','reason':'a\x20logic_or\x20branch\x20is\x20always\x20true:\x20'+n['reason']};if(m['every'](o=>o?.['outcome']==='false'))return{'outcome':'false','reason':'every\x20logic_or\x20branch\x20is\x20always\x20false'};return undefined;}case'logic_not':{const o=g(c['node']);if(!o)return undefined;return{'outcome':o['outcome']==='true'?'false':'true','reason':'logic_not\x20of\x20'+(o['outcome']==='true'?'an\x20always-true':'an\x20always-false')+'\x20expression:\x20'+o['reason']};}default:{if(f['length']<0x2)return undefined;const p=new Set(f['map'](stableKey));if(p['size']===0x1&&!readsContext(f[0x0])&&!rootRaw(f[0x0])['includes']('\x22query\x22')){if(REFLEXIVE_TRUE_OPS['has'](c['type']))return{'outcome':'true','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20(identifier/constant\x20subtree\x20'+stableKey(f[0x0])['slice'](0x0,0x50)+')\x20—\x20it\x20can\x20never\x20reject'};if(REFLEXIVE_FALSE_OPS['has'](c['type']))return{'outcome':'false','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20—\x20it\x20can\x20never\x20pass'};}const q=f['map'](s=>constantNumber(s,d)),r=c['type']==='logic_as_u256_greater_or_equal'?0x1:c['type']==='logic_as_u256_lesser_or_equal'?0x0:-0x1;if(r>=0x0&&f['length']===0x2){const s=0x1-r,t=f[s],u=staticValueType(t,d);if(q[r]===0x0n&&q[s]===undefined&&u!==undefined&&NUMERIC_VALUE_TYPE['test'](String(u))&&!readsContext(t))return{'outcome':'true','reason':c['type']+'\x20against\x20the\x20constant\x200\x20on\x20an\x20unsigned\x20('+u+')\x20operand\x20—\x20every\x20U-value\x20satisfies\x20it'};}if(q['length']===0x2&&q[0x0]!==undefined&&q[0x1]!==undefined){const v=q[0x0],w=q[0x1],x={'logic_equal':v===w,'logic_as_u256_equal':v===w,'logic_not_equal':v!==w,'logic_as_u256_greater':v>w,'logic_as_u256_greater_or_equal':v>=w,'logic_as_u256_lesser':v<w,'logic_as_u256_lesser_or_equal':v<=w};if(c['type']in x)return{'outcome':x[c['type']]?'true':'false','reason':c['type']+'\x20folds\x20on\x20two\x20constant\x20operands\x20('+v['toString']()+'\x20vs\x20'+w['toString']()+')'};}return undefined;}}}export function guardRiskFacts(a){const b={},c=rootRaw(a?.['root']),d=c['toLowerCase'](),f=Array['isArray'](a?.['table'])?a['table']:[],g=a?.['scene'],h=a?.['rely'];b['has_signer_check']=hasSignerCheck(c),b['has_clock_check']=hasClockCheck(c),b['has_guard_self_ref']=hasGuardSelfRef(c),b['has_witness']=hasWitness(c),b['queries_repository']=d['includes']('repository'),b['queries_progress']=d['includes']('progress'),b['root_has_query']=d['includes']('\x22query\x22'),b['root_has_clock_token']=d['includes']('clock'),b['root_has_calc_number_add']=d['includes']('calc_number_add'),b['root_has_logic_string_contains']=d['includes']('logic_string_contains'),b['root_has_logic_string_nocase']=d['includes']('logic_string_nocase'),b['root_has_logic_as_u256_greater_or_equal']=d['includes']('logic_as_u256_greater_or_equal'),b['root_has_logic_as_u256_greater']=d['includes']('logic_as_u256_greater'),b['root_has_logic_equal']=c['includes']('\x22logic_equal\x22'),b['root_has_logic_not_equal']=c['includes']('\x22logic_not_equal\x22'),b['logic_and_count']=(d['match'](/"logic_and"/g)||[])['length'],b['root_is_identifier']=a?.['root']?.['type']==='identifier';const i=b['root_is_identifier']?f['find'](D=>D['identifier']===a['root']['identifier']):undefined;b['root_identifier_is_submission']=i?.['b_submission']??![];const j=extractQueryIds(a?.['root']);b['root_query_ids_csv']=j['join'](',\x20'),b['root_has_progress_current_query']=j['includes'](0x4e5);const k=bareBoolQueryClauses(a?.['root']);k['length']>0x0&&(b['bare_bool_query_count']=k['length'],b['bare_bool_query_csv_sp']=k['join'](',\x20'));b['queries_arb_status']=d['includes']('arb.status'),b['arb_status_transient_gate']=b['queries_arb_status']&&f['some'](D=>!D['b_submission']&&/^u(8|16|32|64|128|256)$/i['test'](String(D['value_type']))&&Number(D['value'])===0x5);const l=f['some'](D=>D['b_submission']);b['has_submission']=l;const m=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&D['value']);m['length']>0x0&&(b['const_addr_count']=m['length'],b['const_addr_list']=m['map'](D=>'#'+D['identifier']+'='+D['value'])['join'](',\x20'));const n=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&typeof D['value']==='string'&&(D['value']['toLowerCase']()==='0xaab'||D['value']['toLowerCase']()==='0xaaa'));if(n['length']>0x0){b['sys_addr_list']=n['map'](E=>'#'+E['identifier']+'='+E['value']+'('+E['name']+')')['join'](',\x20');const D=n['find'](E=>E['value']==='0xaab'&&E['name']&&!E['name']['toLowerCase']()['includes']('registrar')||E['value']==='0xaaa'&&E['name']&&!E['name']['toLowerCase']()['includes']('linker'));b['sys_addr_wrong']=D!==undefined;}const o=extractWitnessCodes(a?.['root']),p=o['filter'](E=>[0x6a,0x6b,0x6c]['includes'](E));if(p['length']>0x0){const E={0x6a:'Arb→Progress\x20(two\x20hops:\x20arb.order\x20→\x20order.progress)',0x6b:'Arb→Machine\x20(two\x20hops:\x20arb.order\x20→\x20order.machine)',0x6c:'Arb→Service\x20(two\x20hops:\x20arb.order\x20→\x20order.service)'};b['witness_multihop_codes']=p,b['witness_multihop_csv']=p['join'](',\x20'),b['witness_multihop_names_block']=p['map'](F=>'\x20\x20-\x20'+F+':\x20'+E[F])['join']('\x0a');}const q=extractWitnessIdentifierPairs(a?.['root']),r=q['filter'](F=>F['code']>=0x64&&F['code']<=0x6c);if(r['length']>0x0){const F=[],G=[];for(const {code:I,identifier:J}of r){const K=WITNESS_CHAIN[I];if(!K)continue;const L=K[0x0],M=f['find'](O=>O['identifier']===J);if(!M)continue;const N=I+'\x20('+K['join']('→')+')';M['object_type']?M['object_type']!==L&&F['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type='+M['object_type']+'\x20(expected\x20'+L+')')):G['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type\x20is\x20not\x20set\x20(expected\x20'+L+')'));if(K['length']===0x3){const O=K[0x1],P=f['some'](Q=>Q['object_type']===O);!P&&G['push']('witness\x20'+N+'\x20multi-hop\x20chain\x20expects\x20intermediate\x20'+(O+'\x20in\x20table,\x20but\x20no\x20entry\x20with\x20object_type='+O+'\x20found'));}}const H=[...F,...G];H['length']>0x0&&(b['rc2_02_issue_count']=H['length'],b['rc2_02_has_hard_mismatch']=F['length']>0x0,b['rc2_02_evidence_lines']=H['map'](Q=>'\x20\x20-\x20'+Q)['join']('\x0a'),b['rc2_02_evidence_csv']=H['join'](';\x20'));}if(b['has_witness']){const Q=d['includes']('repository')&&d['includes']('\x22query\x22'),R=d['includes']('progress_history')&&d['includes']('\x22query\x22');if(Q||R){const S=d['includes']('convert_number_address')||d['includes']('convert_address_number')||d['includes']('convert_u256')||d['includes']('convert_string');b['rc2_04_queries_repo']=Q,b['rc2_04_queries_progress_history']=R,b['rc2_04_has_conversion']=S,b['rc2_04_conversion_note']=S?'\x0aThe\x20current\x20Guard\x20already\x20uses\x20type\x20conversion\x20nodes,\x20but\x20ensure\x20the\x20conversion\x20direction\x20is\x20correct.':'\x0aWarning:\x20no\x20type\x20conversion\x20node\x20detected\x20in\x20the\x20current\x20Guard;\x20parameter\x20type\x20mismatch\x20risk\x20may\x20exist.',b['rc2_04_conversion_evidence']=S?'Type\x20conversion\x20node\x20in\x20use':'No\x20type\x20conversion\x20node\x20detected';}}b['scene_present']=g!==undefined;g&&(b['scene_id']=g['id'],b['scene_host_object']=g['host_object'],b['scene_binding_field']=g['binding_field'],b['scene_mutable_after_publish']=g['mutable_after_publish']);b['rc3_01_sharing_exempt']=g?.['id']==='service_order_allocators_guard'&&Array['isArray'](a?.['sharing_recipients'])&&a['sharing_recipients']['length']>0x0&&!a['sharing_recipients']['includes']('Signer');if(g?.['binding_field']==='voting_guard'){const T=f['filter'](U=>U['b_submission']&&['U8','U16','U32','U64','U128','U256']['includes'](U['value_type']));T['length']>0x0&&(b['rc3_02_numeric_count']=T['length'],b['rc3_02_numeric_list']=T['map'](U=>'#'+U['identifier']+'('+U['value_type']+')')['join'](',\x20'));}const s=f['filter'](U=>U['b_submission']&&U['value_type']==='Address');if(s['length']>0x0){b['rc3_03_submitted_addr_count']=s['length'];const U=s['filter'](V=>!V['object_type']);b['rc3_03_no_type_count']=U['length'],b['rc3_03_evidence']=U['length']>0x0?'Missing\x20object_type:\x20'+U['map'](V=>'#'+V['identifier'])['join'](',\x20'):'Annotated:\x20'+s['map'](V=>'#'+V['identifier']+'='+V['object_type'])['join'](',\x20');}if(s['length']>0x0){const V=o['some'](a2=>[0x64,0x65,0x66]['includes'](a2)),W=o['some'](a2=>[0x67]['includes'](a2)),X=o['some'](a2=>[0x68,0x69,0x6a,0x6b,0x6c]['includes'](a2)),Y=s['filter'](a2=>a2['object_type']==='Order'||V&&!a2['object_type']),Z=s['filter'](a2=>a2['object_type']==='Progress'||W&&!a2['object_type']),a0=s['filter'](a2=>a2['object_type']==='Arb'||X&&!a2['object_type']),a1=Y['length']>0x0||Z['length']>0x0||a0['length']>0x0;if(a1){const a2=['machine_forward_guard','service_order_allocators_guard','arbitration_usage_guard','arbitration_voting_guard','reward_claim','progress_submission_guard'],a3=g?.['id'],a4=!a3||a2['includes'](a3);if(a4){const a5=new Set([0x61b,0x618,0x4e2,0x57a,0x579]),a6=j['some'](a7=>a5['has'](a7));if(!a6){const a7=[];for(const a8 of Y){a7['push']('#'+a8['identifier']+(a8['object_type']?'(Order)':'(inferred\x20Order\x20via\x20witness\x20100-102)'));}for(const a9 of Z){a7['push']('#'+a9['identifier']+(a9['object_type']?'(Progress)':'(inferred\x20Progress\x20via\x20witness\x20103)'));}for(const aa of a0){a7['push']('#'+aa['identifier']+(aa['object_type']?'(Arb)':'(inferred\x20Arb\x20via\x20witness\x20104-108)'));}b['rc3_05_applies']=!![],b['rc3_05_critical']=a3!==undefined&&(a3==='machine_forward_guard'||a3==='service_order_allocators_guard'),b['rc3_05_unbound_csv']=a7['join'](',\x20'),b['rc3_05_scene_label']=a3??'unknown\x20scene\x20(conservative\x20flag)';}}}}if(g?.['id']==='service_order_allocators_guard'&&!b['has_signer_check']){const ab=a?.['sharing_recipients'],ac=ab!==undefined&&ab['length']>0x0,ad=ac&&ab['includes']('Signer');if(!(ac&&!ad)){const ae=isUnboundSignerTheft({'recipient_is_signer':ad,'caller_identity_constrained':![]});b['rc3_06_applies']=!![],b['rc3_06_signer_sharing']=ae,b['rc3_06_recipients_label']=ac?'['+ab['join'](',\x20')+']':'(not\x20provided\x20—\x20conservative\x20flag)',b['rc3_06_title_suffix']=ad?'sharing.who=Signer\x20confirmed\x20—\x20anyone\x20can\x20steal\x20100%\x20of\x20funds':'if\x20sharing.who=Signer,\x20anyone\x20can\x20steal\x20100%\x20of\x20funds',b['rc3_06_level_rationale']=ae?'Signer\x20sharing\x20confirmed\x20→\x20critical':'sharing\x20hint\x20absent\x20→\x20conservative\x20medium';}}if(b['has_signer_check']){const af=c['includes']('\x22logic_equal\x22'),ag=c['includes']('\x22logic_not_equal\x22');b['rc4_01_comparison_detail']=(af?'logic_equal(==)':'')+'\x20'+(ag?'logic_not_equal(!=)':''),b['rc4_01_comparison_ops']=(af?'==':'')+'\x20'+(ag?'!=':'');}if(b['has_clock_check']){const ah=d['includes']('logic_as_u256_greater_or_equal'),ai=d['includes']('logic_as_u256_greater');(ah||ai)&&(b['rc4_02_has_greater_or_equal']=ah,b['rc4_02_has_greater']=ai,b['rc4_02_comparison_ops']=(ah?'>=':'')+'\x20'+(ai?'>':''));}if(b['has_signer_check']&&!isSignerCheckInLogicOr(a?.['root'])){const aj=detectLevel1StrictBinding(a?.['root'],f);if(aj['detected']&&aj['entry']){const ak=aj['entry'];b['rc4_04_detected']=!![],b['rc4_04_entry_identifier']=ak['identifier'],b['rc4_04_entry_value']=ak['value'],b['rc4_04_entry_detail']='b_submission=false,\x20value=\x22'+ak['value']+'\x22'+(ak['name']?',\x20name=\x22'+ak['name']+'\x22':'');}}const t=rootAllQueriesNonZero(a?.['root']),u=()=>{const al=j['filter'](am=>!QUERY_INVARIANT_MAP['has'](am));if(al['length']===0x0)return'';return'Queries\x20without\x20non-zero\x20invariant:\x20'+al['map'](am=>{const an=GUARDQUERY['find'](ao=>ao['id']===am);return an?an['id']+'\x20('+an['name']+')':''+am;})['join'](',\x20');};b['root_has_logic_as_u256_greater_or_equal']&&d['includes']('\x22clock\x22')&&b['root_has_calc_number_add']&&b['root_has_query']&&!t&&(b['rx1_01_trigger']=!![],b['rx1_01_evidence']=u()||'Baseline\x20query\x20may\x20return\x200');b['root_has_logic_as_u256_greater']&&b['root_has_query']&&!t&&(b['rx1_02_trigger']=!![],b['rx1_02_evidence']=u()||'Query\x20may\x20return\x200');const v=Array['isArray'](h?.['guards'])?h['guards']:[];b['rely_guards_count']=v['length'],b['rely_is_or']=h?.['logic_or']===!![],b['rely_logic']=h?.['logic_or']?'OR':'AND';const w=d['includes']('repository')&&d['includes']('\x22query\x22'),x=f['some'](al=>al['b_submission']&&al['value_type']==='Address'&&al['object_type']==='Repository'),y=w&&x;b['rx1_11_self_rep_false']=y,b['rx1_11_warning_tail']=y?'\x0aWarning:\x20the\x20current\x20Guard\x20itself\x20queries\x20repository.data\x20and\x20the\x20Repository\x20address\x20comes\x20from\x20submission,\x20'+'so\x20its\x20own\x20rep=false\x20and\x20cannot\x20be\x20depended\x20on\x20by\x20other\x20Guards.':'',b['rx1_11_evidence']=y?'Self\x20rep=false\x20(repository.data\x20query\x20depends\x20on\x20submission)':'Self\x20rep\x20status\x20to\x20be\x20confirmed';if(l){const al=f['filter'](an=>an['b_submission']),am=al['filter'](an=>(an['name']??'')==='');am['length']>0x0&&(b['rx1_12_vague_count']=am['length'],b['rx1_12_vague_csv']=am['map'](an=>'identifier='+an['identifier']+',\x20name=\x22'+(an['name']??'')+'\x22')['join'](';\x20'));}if(g){const an=f['find'](ao=>!ao['b_submission']&&ao['value_type']==='Address'&&ao['object_type']===g['host_object']);an&&(b['rx1_13_detected']=!![],b['rx1_13_identifier']=an['identifier']);}const z=REENTRANCY_SPECS['find'](ao=>ao['sceneId']===g?.['id']);if(z){const ao=detectReentrancyProtection(a?.['root'],f,z);ao['state']!=='protected'&&(b['reentry_applicable']=!![],b['reentry_state']=ao['state'],b['reentry_scene_id']=z['sceneId'],b['reentry_rationale']=z['rationale'],b['reentry_mitigation']=z['mitigation'],ao['state']==='pseudo'&&(b['reentry_found_primitive']=ao['foundPrimitiveName']??''),b['reentry_evidence']=ao['evidence']);}const A=foldCertainOutcome(a?.['root'],f),B=A?.['outcome']==='true';b['tree_folds_always_true']=B;A&&A['outcome']==='false'&&(b['tree_folds_always_false']=!![],b['tree_folds_always_false_reason']=A['reason']);if(B)b['tree_folds_always_true_reason']=A['reason'];const C=g?.['binding_field']==='write_guard'||g?.['id']==='repository_write_guard';return b['write_guard_scene']=C,C&&(b['write_guard_no_identity_check']=!b['has_signer_check'],b['write_guard_open']=B||!b['has_signer_check']),b;}function guardRuleBook(){const a=getJudgmentDoc()['rules']['domains']['guard'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27guard\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function dataSourceClassFor(a){if(a['startsWith']('R-C1-'))return'type1_onchain_constant';if(a['startsWith']('R-C2-'))return'type2_witness_derived';if(a['startsWith']('R-C3-'))return'type3_submitted_object';if(a['startsWith']('R-C4-'))return'type4_system_context';return'cross_type';}function findingToGuardRisk(a){return{'id':a['rule_id'],'data_source_class':dataSourceClassFor(a['rule_id']),'level':a['level'],'category':a['dimension']??'data_source_trust','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'',...a['evidence']!==undefined?{'evidence':a['evidence']}:{},...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export function runGuardRulePack(a){const b=guardRuleBook();let c;try{c=guardRiskFacts(a);}catch{return[];}return evaluateRuleBook(b,c)['findings']['map'](findingToGuardRisk);}export function assembleGuardAssessment(a,b){const c=getOverallRiskLevel(b),d={};for(const h of b){d[h['data_source_class']]=(d[h['data_source_class']]??0x0)+0x1;}const e=generateStakeholderAdvice(b,a['scene']),f=b['some'](i=>i['level']==='critical')||b['filter'](i=>i['level']==='high')['length']>=0x2,g=generateGuardSummary(a);return{'guard_summary':g,'scene':a['scene'],'risks':b,'overall_risk':c,'risks_by_data_source':d,'stakeholder_advice':e,'needs_human_review':f};}function getOverallRiskLevel(a){if(a['some'](b=>b['level']==='critical'))return'critical';if(a['some'](b=>b['level']==='high'))return'high';if(a['some'](b=>b['level']==='medium'))return'medium';return'low';}function generateStakeholderAdvice(a,b){const c={};for(const d of a){for(const e of d['affected_stakeholders']){if(!c[e])c[e]=[];c[e]['push']('['+d['level']['toUpperCase']()+']\x20'+d['title']+':\x20'+d['mitigation']);}}if(b)switch(b['binding_field']){case'buy_guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Before\x20purchase,\x20verify\x20the\x20buy_guard\x20logic\x20to\x20ensure\x20your\x20identity/credentials\x20can\x20pass\x20validation');break;case'order_allocators':if(!c['provider'])c['provider']=[];c['provider']['push']('Verify\x20the\x20order_allocators\x20ordering\x20to\x20ensure\x20your\x20Allocator\x20will\x20not\x20be\x20skipped\x20by\x20preceding\x20conditions');break;case'voting_guard':if(!c['arbitrator'])c['arbitrator']=[];c['arbitrator']['push']('Confirm\x20the\x20voting\x20weight\x20source\x20is\x20trustworthy;\x20prefer\x20querying\x20EntityRegistrar\x20rather\x20than\x20user-submitted\x20data');break;case'Forward.guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Verify\x20the\x20Forward.guard\x20conditions\x20to\x20ensure\x20you\x20can\x20satisfy\x20the\x20advancement\x20criteria\x20and\x20avoid\x20locked\x20funds');break;}return c;}function generateGuardSummary(a){const b=[];b['push']('table\x20entries:\x20'+a['table']['length']);const c=a['table']['filter'](d=>d['b_submission'])['length'];return b['push']('submitted\x20data:\x20'+c+'\x20entries'),b['push']('root\x20type:\x20'+(a['root']?.['type']??'unknown')),a['rely']&&b['push']('rely:\x20'+a['rely']['guards']['length']+'\x20dependencies\x20('+(a['rely']['logic_or']?'OR':'AND')+')'),b['join'](',\x20');}export function getRiskSummary(a){return{'risk_count':a['risks']['length'],'critical_count':a['risks']['filter'](b=>b['level']==='critical')['length'],'high_count':a['risks']['filter'](b=>b['level']==='high')['length'],'needs_human_review':a['needs_human_review'],'top_risks':a['risks']['filter'](b=>b['level']==='critical'||b['level']==='high')['slice'](0x0,0x3)['map'](b=>b['title'])};}export function getRiskRulesCount(){return factoryRulePack('guard')?.['rules']['length']??0x0;}export const RISK_RULES=((()=>{const a=factoryRulePack('guard');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'data_source_class':dataSourceClassFor(b['rule_id']),'trigger':b['trigger']??'','check':c=>{const d=guardRuleBook()['find'](f=>f['rule_id']===b['rule_id']);if(!d)return null;const {findings:e}=evaluateRuleBook([d],guardRiskFacts(c));return e['length']>0x0?findingToGuardRisk(e[0x0]):null;}}));})());
1
+ import{GUARDQUERY}from'@wowok/wowok';import{isUnboundSignerTheft}from'./recipient-constraint.js';import{factoryRulePack,getJudgmentDoc}from'../config/judgment.js';import{evaluateRuleBook}from'../config/rule-engine.js';function rootRaw(a){try{return JSON['stringify'](a)??'';}catch{return'';}}function hasSignerCheck(a){return a['includes']('\x22Signer\x22');}function hasClockCheck(a){return a['includes']('\x22Clock\x22');}function hasGuardSelfRef(a){return a['includes']('\x22Guard\x22');}function hasWitness(a){return a['includes']('\x22convert_witness\x22');}function extractWitnessCodes(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"convert_witness"\s*:\s*(\d+)/g);for(const e of d){const f=parseInt(e[0x1],0xa);if(f>=0x64&&f<=0x6c)b['push'](f);}return b;}const WITNESS_CHAIN={0x64:['Order','Progress'],0x65:['Order','Machine'],0x66:['Order','Service'],0x67:['Progress','Machine'],0x68:['Arb','Order'],0x69:['Arb','Arbitration'],0x6a:['Arb','Order','Progress'],0x6b:['Arb','Order','Service'],0x6c:['Arb','Order','Machine']};function extractWitnessIdentifierPairs(a){const b=[],c=new WeakSet();function d(e){if(e===null||typeof e!=='object')return;if(c['has'](e))return;c['add'](e);typeof e['convert_witness']==='number'&&typeof e['identifier']==='number'&&b['push']({'code':e['convert_witness'],'identifier':e['identifier']});for(const f of Object['keys'](e)){const g=e[f];if(Array['isArray'](g)){for(const h of g)d(h);}else g!==null&&typeof g==='object'&&d(g);}}return d(a),b;}function getChildNodes(a){if(!a||typeof a!=='object')return[];const b=[];if(Array['isArray'](a['nodes']))b['push'](...a['nodes']);if(a['left'])b['push'](a['left']);if(a['right'])b['push'](a['right']);if(a['vec'])b['push'](a['vec']);if(a['target'])b['push'](a['target']);if(a['object']&&typeof a['object']==='object')b['push'](a['object']);if(Array['isArray'](a['parameters']))b['push'](...a['parameters']);return b['filter'](d=>d&&typeof d==='object');}function findSignerLogicEqualNodes(a){const b=[];function c(d,e){if(!d||typeof d!=='object')return;if(d['type']==='logic_equal'){const f=Array['isArray'](d['nodes'])?d['nodes']:d['left']&&d['right']?[d['left'],d['right']]:[];if(f['length']===0x2){const g=f['findIndex'](h=>h?.['type']==='context'&&h?.['context']==='Signer');g>=0x0&&b['push']({'node':d,'parentType':e,'otherOperand':f[0x1-g]});}}for(const h of getChildNodes(d)){c(h,d['type']);}}return c(a,null),b;}function detectLevel1StrictBinding(a,b){const c=findSignerLogicEqualNodes(a);for(const d of c){const e=d['otherOperand'];if(e?.['type']==='identifier'){const f=b['find'](g=>g['identifier']===e['identifier']);if(f&&!f['b_submission']&&f['value_type']==='Address'&&typeof f['value']==='string'&&f['value']['length']>0x0)return{'detected':!![],'entry':{'identifier':f['identifier'],'value':f['value'],'name':f['name']}};}}return{'detected':![]};}function isSignerCheckInLogicOr(a){const b=findSignerLogicEqualNodes(a);return b['some'](c=>c['parentType']==='logic_or');}const QUERY_INVARIANT_MAP=((()=>{const a=new Map();for(const b of GUARDQUERY){b['invariant']!==undefined&&a['set'](b['id'],b['invariant']);}return a;})());function extractQueryIds(a){const b=[],c=rootRaw(a),d=c['matchAll'](/"query"\s*:\s*(\d+)/g);for(const f of d){const g=parseInt(f[0x1],0xa);if(!b['includes'](g))b['push'](g);}const e=c['matchAll'](/"query"\s*:\s*"([^"]+)"/g);for(const h of e){const i=h[0x1],j=GUARDQUERY['find'](k=>k['name']===i);if(j&&!b['includes'](j['id']))b['push'](j['id']);}return b;}function bareBoolQueryClauses(a){const b=[],c=(d,e)=>{if(e>0x40||!d||typeof d!=='object'||typeof d['type']!=='string')return;if((d['type']==='logic_and'||d['type']==='logic_or')&&Array['isArray'](d['nodes']))for(const f of d['nodes']){if(f&&typeof f==='object'&&f['type']==='query'){const g=f['query'],h=typeof g==='number'?'#'+g:typeof g==='string'?g:'(unknown\x20query)';if(!b['includes'](h))b['push'](h);}}if(Array['isArray'](d['nodes'])){for(const i of d['nodes'])c(i,e+0x1);}if(d['node'])c(d['node'],e+0x1);};return c(a,0x0),b;}function rootAllQueriesNonZero(a){const b=extractQueryIds(a);if(b['length']===0x0)return![];return b['every'](c=>QUERY_INVARIANT_MAP['has'](c));}const REENTRANCY_SPECS=[{'sceneId':'reward_claim','level':'critical','existsPrimitives':[0x64d],'countPrimitives':[0x64c],'addressPrimitives':[0x65a],'rationale':'Guard\x20pass\x20distributes\x20reward\x20funds\x20to\x20the\x20Claimant\x20AND\x20creates\x20a\x20reward_record,\x20but\x20the\x20Guard\x20conditions\x20(identity,\x20time,\x20node\x20state)\x20do\x20NOT\x20naturally\x20invalidate\x20after\x20a\x20claim.\x20'+'Without\x20an\x20explicit\x20anti-reentrancy\x20primitive,\x20the\x20same\x20Claimant\x20can\x20repeatedly\x20pass\x20the\x20Guard\x20and\x20DRAIN\x20THE\x20ENTIRE\x20POOL.\x20'+'This\x20is\x20the\x20most\x20severe\x20reentrancy\x20scene\x20—\x20direct\x20fund\x20loss.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and\x20with\x20existing\x20conditions):\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record\x20has\x27,\x20object=reward,\x20parameters=[claimant_address]))\x20—\x20RECOMMENDED\x20(per-user\x20Bool\x20check)\x0a'+'\x20\x20-\x20logic_equal([query(\x27reward.record\x20count\x27,\x20object=reward),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20total-claim\x20count\x20is\x200\x0a'+'\x20\x20-\x20logic_not(query(\x27reward.record.find_first\x27,\x20object=reward,\x20where={...}))\x20—\x20no\x20matching\x20record\x20found\x0a'+'Reference\x20template:\x20MyShop_Advanced\x20Guard\x207\x20condition\x204\x20(logic_not(query_reward_record_exists(where.storeFromId=order_id)))'},{'sceneId':'arbitration_voting_guard','level':'critical','existsPrimitives':[0x57c,0x57e],'countPrimitives':[0x57d],'addressPrimitives':[],'rationale':'Guard\x20pass\x20counts\x20the\x20vote\x20with\x20the\x20extracted\x20weight.\x20Without\x20anti-reentrancy,\x20the\x20same\x20voter\x20can\x20vote\x20MULTIPLE\x20times,\x20'+'multiplying\x20their\x20weight\x20and\x20skewing\x20the\x20arbitration\x20result\x20—\x20which\x20directly\x20determines\x20fund\x20ownership\x20via\x20compensation.\x20'+'The\x20voter\x27s\x20eligibility\x20(identity,\x20reputation)\x20does\x20NOT\x20naturally\x20invalidate\x20after\x20voting.\x20'+'Note:\x20arb.voted_count\x20(1403)\x20is\x20total\x20voter\x20count\x20(NOT\x20per-voter)\x20and\x20does\x20NOT\x20serve\x20as\x20an\x20anti-reentrancy\x20primitive\x20for\x20an\x20individual\x20voter.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted\x20has\x27,\x20object=arb,\x20parameters=[voter_address]))\x20—\x20RECOMMENDED\x20(per-voter\x20Bool)\x0a'+'\x20\x20-\x20logic_not(query(\x27arb.voted.agree\x20has\x27,\x20object=arb,\x20parameters=[voter_address,\x20proposition_index]))\x20—\x20per-voter-per-proposition\x0a'+'\x20\x20-\x20logic_equal([query(\x27arb.voted.agree\x20count\x27,\x20object=arb,\x20parameters=[voter_address]),\x20identifier(N)])\x20where\x20table[N].value=0'},{'sceneId':'arbitration_usage_guard','level':'high','existsPrimitives':[0x61d],'countPrimitives':[0x61c],'addressPrimitives':[],'rationale':'Guard\x20pass\x20creates\x20a\x20new\x20Arb\x20case.\x20Without\x20anti-reentrancy,\x20a\x20customer\x20can\x20create\x20multiple\x20Arb\x20cases\x20for\x20the\x20SAME\x20Order\x20'+'(up\x20to\x20MAX_DISPUTE_COUNT=10),\x20harassing\x20the\x20counterparty\x20and\x20inflating\x20arbitration\x20system\x20load.\x20'+'Not\x20direct\x20fund\x20loss,\x20but\x20severe\x20system\x20abuse.\x20Filing\x20a\x20dispute\x20deduplicates\x20by\x20Arb\x20address\x20but\x20does\x20NOT\x20prevent\x20multiple\x20distinct\x20Arbs.','mitigation':'Add\x20ONE\x20of\x20the\x20following\x20to\x20the\x20root\x20(wrapped\x20in\x20logic_and):\x0a'+'\x20\x20-\x20logic_not(query(\x27order.dispute\x20has\x27,\x20object=order,\x20parameters=[existing_arb_address]))\x20—\x20per-Arb\x20check\x0a'+'\x20\x20-\x20logic_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=0\x20—\x20STRICT:\x20block\x20any\x20prior\x20dispute\x0a'+'\x20\x20-\x20logic_as_u256_lesser_or_equal([query(\x27order.dispute\x20count\x27,\x20object=order),\x20identifier(N)])\x20where\x20table[N].value=K\x20—\x20LENIENT:\x20allow\x20up\x20to\x20K\x20disputes'},{'sceneId':'service_order_allocators_guard','level':'low','existsPrimitives':[0x620],'countPrimitives':[],'addressPrimitives':[0x621],'rationale':'Protocol-level\x20protection:\x20attaching\x20an\x20Allocation\x20to\x20an\x20Order\x20asserts\x20ONE\x20Allocation\x20per\x20Order\x20(E_ALLOCATION_ALREADY_SPECIFIED).\x20'+'After\x20alloc()\x20executes,\x20typical\x20Rate-mode\x20allocators\x20(sum=10000)\x20and\x20Surplus-mode\x20allocators\x20drain\x20balance\x20to\x200,\x20making\x20reentrancy\x20unprofitable.\x20'+'EDGE\x20CASE:\x20Amount-mode-only\x20allocators\x20(no\x20Surplus,\x20total\x20<\x20full\x20balance)\x20leave\x20remainder;\x20a\x20second\x20alloc()\x20could\x20extract\x20more\x20—\x20mitigated\x20by\x20preferring\x20Rate/RateGross/Surplus\x20modes.\x20'+'External\x20deposit\x20via\x20receive()\x20is\x20possible\x20but\x20irrational\x20(attacker\x20funds\x20the\x20Allocation\x20they\x20attack).','mitigation':'Default:\x20no\x20action\x20needed\x20(protocol-level\x20guard).\x20IF\x20using\x20Amount-mode-only\x20allocators\x20without\x20Surplus:\x20'+'consider\x20adding\x20logic_not(query(\x27order.allocation\x20some\x27,\x20object=order))\x20OR\x20switch\x20to\x20Rate/Surplus\x20mode\x20to\x20drain\x20balance\x20completely.'},{'sceneId':'service_buy_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20purchase\x20creates\x20a\x20fresh\x20Order;\x20no\x20existing\x20Order\x20state\x20is\x20modified.\x20Default:\x20no\x20reentrancy\x20risk.\x20'+'IF\x20business\x20intent\x20is\x20\x27limit\x20one\x20purchase\x20per\x20user\x27\x20(limited-edition\x20goods,\x20whitelist\x20single-buy),\x20an\x20anti-reentrancy\x20check\x20is\x20REQUIRED\x20'+'but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists\x20for\x20per-user\x20purchase\x20history.','mitigation':'IF\x20limit-purchase\x20intent:\x20record\x20purchases\x20in\x20a\x20Repository\x20and\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20...))\x20to\x20root;\x20'+'OR\x20revoke\x20EntityRegistrar\x20membership\x20after\x20first\x20buy;\x20OR\x20use\x20an\x20off-chain\x20allowlist\x20with\x20on-chain\x20Merkle\x20proof.'},{'sceneId':'repository_write_guard','level':'low','existsPrimitives':[0x48e],'countPrimitives':[],'addressPrimitives':[],'rationale':'Default\x20writes\x20are\x20idempotent\x20(same\x20ID\x20overwrites,\x20different\x20ID\x20appends);\x20no\x20fund\x20flow.\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20write\x20per\x20ID\x27\x20(voting,\x20immutable\x20credential,\x20single-attestation),\x20an\x20anti-reentrancy\x20check\x20is\x20needed.','mitigation':'IF\x20one-write-per-ID\x20intent:\x20add\x20logic_not(query(\x27repository.data\x20has\x27,\x20object=repository,\x20parameters=[policy_name,\x20user_or_object_id]))\x20to\x20root.'},{'sceneId':'gen_passport_guard','level':'low','existsPrimitives':[],'countPrimitives':[],'addressPrimitives':[],'rationale':'Each\x20gen_passport\x20call\x20generates\x20an\x20independent\x20Passport\x20(one\x20Passport\x20per\x20operation).\x20'+'Multiple\x20Passports\x20for\x20the\x20same\x20user\x20are\x20usually\x20valid\x20(each\x20serves\x20a\x20different\x20subsequent\x20operation).\x20'+'IF\x20business\x20intent\x20is\x20\x27one\x20active\x20Passport\x20per\x20user\x27,\x20an\x20anti-reentrancy\x20check\x20is\x20needed\x20but\x20no\x20direct\x20GUARDQUERY\x20primitive\x20exists.','mitigation':'IF\x20one-passport-per-user\x20intent:\x20use\x20off-chain\x20tracking\x20or\x20a\x20Repository\x20to\x20record\x20issued\x20Passport\x20IDs.'}],QUERY_TYPE_ALIASES=new Map([['query_reward_record_exists',0x64d],['query_reward_record_count',0x64c],['query_reward_record_find',0x65a],['query_progress_history_find',0x4fa],['query_progress_history_session_find',0x4fb],['query_progress_history_session_forward_find',0x4fc],['query_progress_history_session_count',0x4f9],['query_progress_history_session_forward_count',0x4ee],['query_repository_data_count_where',0x495],['query_repository_data_sum_where',0x496],['query_repository_policies_keys',0x497],['query_repository_data_find_where',0x498],['query_repository_data_keys_where',0x499]]);function detectReentrancyProtection(a,b,c){const d=new Set([...c['existsPrimitives'],...c['countPrimitives'],...c['addressPrimitives']]);if(d['size']===0x0)return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20available\x20in\x20GUARDQUERY\x20for\x20this\x20scene'};const e=new Map(),f=new Map();for(const p of d){const q=GUARDQUERY['find'](r=>r['id']===p);q&&(e['set'](p,q['name']),f['set'](q['name'],p));}const g=Array['from'](f['keys']());function h(r){if(!r||typeof r!=='object')return-0x1;if(typeof r['query']==='number'&&d['has'](r['query']))return r['query'];if(typeof r['query']==='string'&&f['has'](r['query']))return f['get'](r['query']);if(typeof r['type']==='string'&&QUERY_TYPE_ALIASES['has'](r['type'])){const s=QUERY_TYPE_ALIASES['get'](r['type']);if(d['has'](s))return s;}if(typeof r['type']==='string'&&f['has'](r['type']))return f['get'](r['type']);return-0x1;}function i(r){if(!r||typeof r!=='object')return![];if(typeof r['type']==='string'&&['number','u8','u16','u32','u64','u128','u256']['includes'](r['type']))return r['value']===0x0||r['value']==='0'||r['value']===0x0n;if(r['type']==='identifier'&&typeof r['identifier']==='number'){const s=b['find'](t=>t['identifier']===r['identifier']);if(s&&!s['b_submission'])return s['value']===0x0||s['value']==='0'||s['value']===0x0n;}return![];}function j(r,s){if(!r||typeof r!=='object')return[];const t=[];if(Array['isArray'](r['nodes']))for(const u of r['nodes']){if(u!==s)t['push'](u);}if(r['left']&&r['left']!==s)t['push'](r['left']);if(r['right']&&r['right']!==s)t['push'](r['right']);return t['filter'](v=>v&&typeof v==='object');}let k=![],l=![],m='',n='';function o(r,s){if(!r||typeof r!=='object')return;const t=h(r);if(t>=0x0){k=!![];const v=e['get'](t)??'query_'+t;n=v;const w=s?.['type']??null;let x=![];const y=c['existsPrimitives']['includes'](t),z=c['addressPrimitives']['includes'](t),A=c['countPrimitives']['includes'](t);(y||z)&&w==='logic_not'&&(x=!![]);if(A&&w==='logic_equal'){const B=j(s,r);B['some'](C=>i(C))&&(x=!![]);}if(x)l=!![];else{if(!m){const C=A?'logic_equal\x20with\x20a\x20zero\x20operand':'logic_not';m='Primitive\x20\x22'+v+'\x22\x20found\x20but\x20its\x20immediate\x20parent\x20is\x20'+(w??'root')+'\x20(expected\x20'+C+').\x20The\x20primitive\x20is\x20present\x20but\x20does\x20NOT\x20actually\x20prevent\x20reentrancy\x20—\x20this\x20is\x20a\x20false\x20sense\x20of\x20security.';}}}const u=[];if(Array['isArray'](r['nodes']))u['push'](...r['nodes']);if(r['left'])u['push'](r['left']);if(r['right'])u['push'](r['right']);if(r['node'])u['push'](r['node']);if(r['vec'])u['push'](r['vec']);if(r['target'])u['push'](r['target']);if(r['object']&&typeof r['object']==='object')u['push'](r['object']);if(Array['isArray'](r['parameters']))u['push'](...r['parameters']);for(const D of u){D&&typeof D==='object'&&o(D,r);}}o(a,null);if(l)return{'state':'protected','evidence':'Anti-reentrancy\x20primitive\x20\x22'+n+'\x22\x20is\x20properly\x20wrapped','foundPrimitiveName':n};if(k)return{'state':'pseudo','evidence':m,'foundPrimitiveName':n};return{'state':'absent','evidence':'No\x20anti-reentrancy\x20primitive\x20found\x20in\x20root.\x20Expected\x20one\x20of:\x20'+g['join'](',\x20')};}function stableKey(a){if(a===null||typeof a!=='object')return JSON['stringify'](a)??'null';if(Array['isArray'](a))return'['+a['map'](stableKey)['join'](',')+']';const b=a;return'{'+Object['keys'](b)['sort']()['map'](c=>JSON['stringify'](c)+':'+stableKey(b[c]))['join'](',')+'}';}function readsContext(a){return rootRaw(a)['includes']('\x22context\x22');}const NUMERIC_VALUE_TYPE=/^u(?:8|16|32|64|128|256)$/i,NUMERIC_NODE_TYPES=new Set(['calc_number_add','calc_number_multiply','calc_number_subtract','calc_number_divide','calc_number_mod','convert_address_number','convert_string_number','convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256','vec_length','calc_string_length']),REFLEXIVE_TRUE_OPS=new Set(['logic_equal','logic_as_u256_equal','logic_string_nocase_equal','calc_string_nocase_equal','logic_string_contains','calc_string_contains','logic_string_nocase_contains','calc_string_nocase_contains']),REFLEXIVE_FALSE_OPS=new Set(['logic_not_equal','logic_as_u256_greater','logic_as_u256_lesser']);function tableEntryOf(a,b){if(!a||a['type']!=='identifier')return undefined;return b['find'](c=>c['identifier']===a['identifier']);}function staticValueType(a,b){if(!a||typeof a!=='object'||typeof a['type']!=='string')return undefined;if(a['type']==='identifier')return tableEntryOf(a,b)?.['value_type'];const c=QUERY_TYPE_ALIASES['get'](a['type']),d=a['type']==='query'?a['query']:c;if(d!==undefined){const e=GUARDQUERY['find'](f=>f['id']===d||typeof d==='string'&&f['name']===d);if(e)return String(e['return']);}return NUMERIC_NODE_TYPES['has'](a['type'])?'U64':undefined;}function constantNumber(a,b){const c=tableEntryOf(a,b);if(!c||c['b_submission'])return undefined;if(!NUMERIC_VALUE_TYPE['test'](String(c['value_type'])))return undefined;const d=String(c['value']??'')['trim']();if(!/^\d+$/['test'](d))return undefined;try{return BigInt(d);}catch{return undefined;}}function foldCertainOutcome(c,d,e=0x0){if(e>0x40||!c||typeof c!=='object'||typeof c['type']!=='string')return undefined;const f=Array['isArray'](c['nodes'])?c['nodes']:[],g=i=>foldCertainOutcome(i,d,e+0x1),h=()=>f['length']>0x0?f['map'](g):undefined;switch(c['type']){case'identifier':{const i=tableEntryOf(c,d);if(!i||i['b_submission'])return undefined;if(/^bool$/i['test'](String(i['value_type']))){const j=String(i['value']??'')['trim']()['toLowerCase']();if(j==='true'||j==='false')return{'outcome':j,'reason':'table\x20entry\x20#'+i['identifier']+'\x20is\x20the\x20constant\x20Bool\x20'+j};}return undefined;}case'logic_and':{const k=h();if(!k)return undefined;const l=k['find'](m=>m?.['outcome']==='false');if(l)return{'outcome':'false','reason':'a\x20logic_and\x20branch\x20is\x20always\x20false:\x20'+l['reason']};if(k['every'](m=>m?.['outcome']==='true'))return{'outcome':'true','reason':'every\x20logic_and\x20branch\x20is\x20always\x20true:\x20'+(k[0x0]?.['reason']??'')};return undefined;}case'logic_or':{const m=h();if(!m)return undefined;const n=m['find'](o=>o?.['outcome']==='true');if(n)return{'outcome':'true','reason':'a\x20logic_or\x20branch\x20is\x20always\x20true:\x20'+n['reason']};if(m['every'](o=>o?.['outcome']==='false'))return{'outcome':'false','reason':'every\x20logic_or\x20branch\x20is\x20always\x20false'};return undefined;}case'logic_not':{const o=g(c['node']);if(!o)return undefined;return{'outcome':o['outcome']==='true'?'false':'true','reason':'logic_not\x20of\x20'+(o['outcome']==='true'?'an\x20always-true':'an\x20always-false')+'\x20expression:\x20'+o['reason']};}default:{if(f['length']<0x2)return undefined;const p=new Set(f['map'](stableKey));if(p['size']===0x1&&!readsContext(f[0x0])&&!rootRaw(f[0x0])['includes']('\x22query\x22')){if(REFLEXIVE_TRUE_OPS['has'](c['type']))return{'outcome':'true','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20(identifier/constant\x20subtree\x20'+stableKey(f[0x0])['slice'](0x0,0x50)+')\x20—\x20it\x20can\x20never\x20reject'};if(REFLEXIVE_FALSE_OPS['has'](c['type']))return{'outcome':'false','reason':c['type']+'\x20compares\x20the\x20same\x20operand\x20to\x20itself\x20—\x20it\x20can\x20never\x20pass'};}const q=f['map'](s=>constantNumber(s,d)),r=c['type']==='logic_as_u256_greater_or_equal'?0x1:c['type']==='logic_as_u256_lesser_or_equal'?0x0:-0x1;if(r>=0x0&&f['length']===0x2){const s=0x1-r,t=f[s],u=staticValueType(t,d);if(q[r]===0x0n&&q[s]===undefined&&u!==undefined&&NUMERIC_VALUE_TYPE['test'](String(u))&&!readsContext(t))return{'outcome':'true','reason':c['type']+'\x20against\x20the\x20constant\x200\x20on\x20an\x20unsigned\x20('+u+')\x20operand\x20—\x20every\x20U-value\x20satisfies\x20it'};}if(q['length']===0x2&&q[0x0]!==undefined&&q[0x1]!==undefined){const v=q[0x0],w=q[0x1],x={'logic_equal':v===w,'logic_as_u256_equal':v===w,'logic_not_equal':v!==w,'logic_as_u256_greater':v>w,'logic_as_u256_greater_or_equal':v>=w,'logic_as_u256_lesser':v<w,'logic_as_u256_lesser_or_equal':v<=w};if(c['type']in x)return{'outcome':x[c['type']]?'true':'false','reason':c['type']+'\x20folds\x20on\x20two\x20constant\x20operands\x20('+v['toString']()+'\x20vs\x20'+w['toString']()+')'};}return undefined;}}}export function guardRiskFacts(a){const b={},c=rootRaw(a?.['root']),d=c['toLowerCase'](),f=Array['isArray'](a?.['table'])?a['table']:[],g=a?.['scene'],h=a?.['rely'];b['has_signer_check']=hasSignerCheck(c),b['has_clock_check']=hasClockCheck(c),b['has_guard_self_ref']=hasGuardSelfRef(c),b['has_witness']=hasWitness(c),b['queries_repository']=d['includes']('repository'),b['queries_progress']=d['includes']('progress'),b['root_has_query']=d['includes']('\x22query\x22'),b['root_has_clock_token']=d['includes']('clock'),b['root_has_calc_number_add']=d['includes']('calc_number_add'),b['root_has_logic_string_contains']=d['includes']('logic_string_contains'),b['root_has_logic_string_nocase']=d['includes']('logic_string_nocase'),b['root_has_logic_as_u256_greater_or_equal']=d['includes']('logic_as_u256_greater_or_equal'),b['root_has_logic_as_u256_greater']=d['includes']('logic_as_u256_greater'),b['root_has_logic_equal']=c['includes']('\x22logic_equal\x22'),b['root_has_logic_not_equal']=c['includes']('\x22logic_not_equal\x22'),b['logic_and_count']=(d['match'](/"logic_and"/g)||[])['length'],b['root_is_identifier']=a?.['root']?.['type']==='identifier';const i=b['root_is_identifier']?f['find'](D=>D['identifier']===a['root']['identifier']):undefined;b['root_identifier_is_submission']=i?.['b_submission']??![];const j=extractQueryIds(a?.['root']);b['root_query_ids_csv']=j['join'](',\x20'),b['root_has_progress_current_query']=j['includes'](0x4e5);const k=bareBoolQueryClauses(a?.['root']);k['length']>0x0&&(b['bare_bool_query_count']=k['length'],b['bare_bool_query_csv_sp']=k['join'](',\x20'));b['queries_arb_status']=d['includes']('arb.status'),b['arb_status_transient_gate']=b['queries_arb_status']&&f['some'](D=>!D['b_submission']&&/^u(8|16|32|64|128|256)$/i['test'](String(D['value_type']))&&Number(D['value'])===0x5);const l=f['some'](D=>D['b_submission']);b['has_submission']=l;const m=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&D['value']);m['length']>0x0&&(b['const_addr_count']=m['length'],b['const_addr_list']=m['map'](D=>'#'+D['identifier']+'='+D['value'])['join'](',\x20'));const n=f['filter'](D=>!D['b_submission']&&D['value_type']==='Address'&&typeof D['value']==='string'&&(D['value']['toLowerCase']()==='0xaab'||D['value']['toLowerCase']()==='0xaaa'));if(n['length']>0x0){b['sys_addr_list']=n['map'](E=>'#'+E['identifier']+'='+E['value']+'('+E['name']+')')['join'](',\x20');const D=n['find'](E=>E['value']==='0xaab'&&E['name']&&!E['name']['toLowerCase']()['includes']('registrar')||E['value']==='0xaaa'&&E['name']&&!E['name']['toLowerCase']()['includes']('linker'));b['sys_addr_wrong']=D!==undefined;}const o=extractWitnessCodes(a?.['root']),p=o['filter'](E=>[0x6a,0x6b,0x6c]['includes'](E));if(p['length']>0x0){const E={0x6a:'Arb→Progress\x20(two\x20hops:\x20arb.order\x20→\x20order.progress)',0x6b:'Arb→Machine\x20(two\x20hops:\x20arb.order\x20→\x20order.machine)',0x6c:'Arb→Service\x20(two\x20hops:\x20arb.order\x20→\x20order.service)'};b['witness_multihop_codes']=p,b['witness_multihop_csv']=p['join'](',\x20'),b['witness_multihop_names_block']=p['map'](F=>'\x20\x20-\x20'+F+':\x20'+E[F])['join']('\x0a');}const q=extractWitnessIdentifierPairs(a?.['root']),r=q['filter'](F=>F['code']>=0x64&&F['code']<=0x6c);if(r['length']>0x0){const F=[],G=[];for(const {code:I,identifier:J}of r){const K=WITNESS_CHAIN[I];if(!K)continue;const L=K[0x0],M=f['find'](O=>O['identifier']===J);if(!M)continue;const N=I+'\x20('+K['join']('→')+')';M['object_type']?M['object_type']!==L&&F['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type='+M['object_type']+'\x20(expected\x20'+L+')')):G['push']('witness\x20'+N+'\x20references\x20#'+J+'\x20'+('but\x20object_type\x20is\x20not\x20set\x20(expected\x20'+L+')'));if(K['length']===0x3){const O=K[0x1],P=f['some'](Q=>Q['object_type']===O);!P&&G['push']('witness\x20'+N+'\x20multi-hop\x20chain\x20expects\x20intermediate\x20'+(O+'\x20in\x20table,\x20but\x20no\x20entry\x20with\x20object_type='+O+'\x20found'));}}const H=[...F,...G];H['length']>0x0&&(b['rc2_02_issue_count']=H['length'],b['rc2_02_has_hard_mismatch']=F['length']>0x0,b['rc2_02_evidence_lines']=H['map'](Q=>'\x20\x20-\x20'+Q)['join']('\x0a'),b['rc2_02_evidence_csv']=H['join'](';\x20'));}if(b['has_witness']){const Q=d['includes']('repository')&&d['includes']('\x22query\x22'),R=d['includes']('progress_history')&&d['includes']('\x22query\x22');if(Q||R){const S=d['includes']('convert_number_address')||d['includes']('convert_address_number')||d['includes']('convert_u256')||d['includes']('convert_string');b['rc2_04_queries_repo']=Q,b['rc2_04_queries_progress_history']=R,b['rc2_04_has_conversion']=S,b['rc2_04_conversion_note']=S?'\x0aThe\x20current\x20Guard\x20already\x20uses\x20type\x20conversion\x20nodes,\x20but\x20ensure\x20the\x20conversion\x20direction\x20is\x20correct.':'\x0aWarning:\x20no\x20type\x20conversion\x20node\x20detected\x20in\x20the\x20current\x20Guard;\x20parameter\x20type\x20mismatch\x20risk\x20may\x20exist.',b['rc2_04_conversion_evidence']=S?'Type\x20conversion\x20node\x20in\x20use':'No\x20type\x20conversion\x20node\x20detected';}}b['scene_present']=g!==undefined;g&&(b['scene_id']=g['id'],b['scene_host_object']=g['host_object'],b['scene_binding_field']=g['binding_field'],b['scene_mutable_after_publish']=g['mutable_after_publish']);b['rc3_01_sharing_exempt']=g?.['id']==='service_order_allocators_guard'&&Array['isArray'](a?.['sharing_recipients'])&&a['sharing_recipients']['length']>0x0&&!a['sharing_recipients']['includes']('Signer');if(g?.['binding_field']==='voting_guard'){const T=f['filter'](U=>U['b_submission']&&['U8','U16','U32','U64','U128','U256']['includes'](U['value_type']));T['length']>0x0&&(b['rc3_02_numeric_count']=T['length'],b['rc3_02_numeric_list']=T['map'](U=>'#'+U['identifier']+'('+U['value_type']+')')['join'](',\x20'));}const s=f['filter'](U=>U['b_submission']&&U['value_type']==='Address');if(s['length']>0x0){b['rc3_03_submitted_addr_count']=s['length'];const U=s['filter'](V=>!V['object_type']);b['rc3_03_no_type_count']=U['length'],b['rc3_03_evidence']=U['length']>0x0?'Missing\x20object_type:\x20'+U['map'](V=>'#'+V['identifier'])['join'](',\x20'):'Annotated:\x20'+s['map'](V=>'#'+V['identifier']+'='+V['object_type'])['join'](',\x20');}if(s['length']>0x0){const V=o['some'](a2=>[0x64,0x65,0x66]['includes'](a2)),W=o['some'](a2=>[0x67]['includes'](a2)),X=o['some'](a2=>[0x68,0x69,0x6a,0x6b,0x6c]['includes'](a2)),Y=s['filter'](a2=>a2['object_type']==='Order'||V&&!a2['object_type']),Z=s['filter'](a2=>a2['object_type']==='Progress'||W&&!a2['object_type']),a0=s['filter'](a2=>a2['object_type']==='Arb'||X&&!a2['object_type']),a1=Y['length']>0x0||Z['length']>0x0||a0['length']>0x0;if(a1){const a2=['machine_forward_guard','service_order_allocators_guard','arbitration_usage_guard','arbitration_voting_guard','reward_claim','progress_submission_guard'],a3=g?.['id'],a4=!a3||a2['includes'](a3);if(a4){const a5=new Set([0x61b,0x618,0x4e2,0x57a,0x579]),a6=j['some'](a7=>a5['has'](a7));if(!a6){const a7=[];for(const a8 of Y){a7['push']('#'+a8['identifier']+(a8['object_type']?'(Order)':'(inferred\x20Order\x20via\x20witness\x20100-102)'));}for(const a9 of Z){a7['push']('#'+a9['identifier']+(a9['object_type']?'(Progress)':'(inferred\x20Progress\x20via\x20witness\x20103)'));}for(const aa of a0){a7['push']('#'+aa['identifier']+(aa['object_type']?'(Arb)':'(inferred\x20Arb\x20via\x20witness\x20104-108)'));}b['rc3_05_applies']=!![],b['rc3_05_critical']=a3!==undefined&&a3==='machine_forward_guard',b['rc3_05_unbound_csv']=a7['join'](',\x20'),b['rc3_05_scene_label']=a3??'unknown\x20scene\x20(conservative\x20flag)';}}}}if(g?.['id']==='service_order_allocators_guard'&&!b['has_signer_check']){const ab=a?.['sharing_recipients'],ac=ab!==undefined&&ab['length']>0x0,ad=ac&&ab['includes']('Signer');if(!(ac&&!ad)){const ae=isUnboundSignerTheft({'recipient_is_signer':ad,'caller_identity_constrained':![]});b['rc3_06_applies']=!![],b['rc3_06_signer_sharing']=ae,b['rc3_06_recipients_label']=ac?'['+ab['join'](',\x20')+']':'(not\x20provided\x20—\x20conservative\x20flag)',b['rc3_06_title_suffix']=ad?'sharing.who=Signer\x20confirmed\x20—\x20anyone\x20can\x20steal\x20100%\x20of\x20funds':'if\x20sharing.who=Signer,\x20anyone\x20can\x20steal\x20100%\x20of\x20funds',b['rc3_06_level_rationale']=ae?'Signer\x20sharing\x20confirmed\x20→\x20critical':'sharing\x20hint\x20absent\x20→\x20conservative\x20medium';}}if(b['has_signer_check']){const af=c['includes']('\x22logic_equal\x22'),ag=c['includes']('\x22logic_not_equal\x22');b['rc4_01_comparison_detail']=(af?'logic_equal(==)':'')+'\x20'+(ag?'logic_not_equal(!=)':''),b['rc4_01_comparison_ops']=(af?'==':'')+'\x20'+(ag?'!=':'');}if(b['has_clock_check']){const ah=d['includes']('logic_as_u256_greater_or_equal'),ai=d['includes']('logic_as_u256_greater');(ah||ai)&&(b['rc4_02_has_greater_or_equal']=ah,b['rc4_02_has_greater']=ai,b['rc4_02_comparison_ops']=(ah?'>=':'')+'\x20'+(ai?'>':''));}if(b['has_signer_check']&&!isSignerCheckInLogicOr(a?.['root'])){const aj=detectLevel1StrictBinding(a?.['root'],f);if(aj['detected']&&aj['entry']){const ak=aj['entry'];b['rc4_04_detected']=!![],b['rc4_04_entry_identifier']=ak['identifier'],b['rc4_04_entry_value']=ak['value'],b['rc4_04_entry_detail']='b_submission=false,\x20value=\x22'+ak['value']+'\x22'+(ak['name']?',\x20name=\x22'+ak['name']+'\x22':'');}}const t=rootAllQueriesNonZero(a?.['root']),u=()=>{const al=j['filter'](am=>!QUERY_INVARIANT_MAP['has'](am));if(al['length']===0x0)return'';return'Queries\x20without\x20non-zero\x20invariant:\x20'+al['map'](am=>{const an=GUARDQUERY['find'](ao=>ao['id']===am);return an?an['id']+'\x20('+an['name']+')':''+am;})['join'](',\x20');};b['root_has_logic_as_u256_greater_or_equal']&&d['includes']('\x22clock\x22')&&b['root_has_calc_number_add']&&b['root_has_query']&&!t&&(b['rx1_01_trigger']=!![],b['rx1_01_evidence']=u()||'Baseline\x20query\x20may\x20return\x200');b['root_has_logic_as_u256_greater']&&b['root_has_query']&&!t&&(b['rx1_02_trigger']=!![],b['rx1_02_evidence']=u()||'Query\x20may\x20return\x200');const v=Array['isArray'](h?.['guards'])?h['guards']:[];b['rely_guards_count']=v['length'],b['rely_is_or']=h?.['logic_or']===!![],b['rely_logic']=h?.['logic_or']?'OR':'AND';const w=d['includes']('repository')&&d['includes']('\x22query\x22'),x=f['some'](al=>al['b_submission']&&al['value_type']==='Address'&&al['object_type']==='Repository'),y=w&&x;b['rx1_11_self_rep_false']=y,b['rx1_11_warning_tail']=y?'\x0aWarning:\x20the\x20current\x20Guard\x20itself\x20queries\x20repository.data\x20and\x20the\x20Repository\x20address\x20comes\x20from\x20submission,\x20'+'so\x20its\x20own\x20rep=false\x20and\x20cannot\x20be\x20depended\x20on\x20by\x20other\x20Guards.':'',b['rx1_11_evidence']=y?'Self\x20rep=false\x20(repository.data\x20query\x20depends\x20on\x20submission)':'Self\x20rep\x20status\x20to\x20be\x20confirmed';if(l){const al=f['filter'](an=>an['b_submission']),am=al['filter'](an=>(an['name']??'')==='');am['length']>0x0&&(b['rx1_12_vague_count']=am['length'],b['rx1_12_vague_csv']=am['map'](an=>'identifier='+an['identifier']+',\x20name=\x22'+(an['name']??'')+'\x22')['join'](';\x20'));}if(g){const an=f['find'](ao=>!ao['b_submission']&&ao['value_type']==='Address'&&ao['object_type']===g['host_object']);an&&(b['rx1_13_detected']=!![],b['rx1_13_identifier']=an['identifier']);}const z=REENTRANCY_SPECS['find'](ao=>ao['sceneId']===g?.['id']);if(z){const ao=detectReentrancyProtection(a?.['root'],f,z);ao['state']!=='protected'&&(b['reentry_applicable']=!![],b['reentry_state']=ao['state'],b['reentry_scene_id']=z['sceneId'],b['reentry_rationale']=z['rationale'],b['reentry_mitigation']=z['mitigation'],ao['state']==='pseudo'&&(b['reentry_found_primitive']=ao['foundPrimitiveName']??''),b['reentry_evidence']=ao['evidence']);}const A=foldCertainOutcome(a?.['root'],f),B=A?.['outcome']==='true';b['tree_folds_always_true']=B;A&&A['outcome']==='false'&&(b['tree_folds_always_false']=!![],b['tree_folds_always_false_reason']=A['reason']);if(B)b['tree_folds_always_true_reason']=A['reason'];const C=g?.['binding_field']==='write_guard'||g?.['id']==='repository_write_guard';return b['write_guard_scene']=C,C&&(b['write_guard_no_identity_check']=!b['has_signer_check'],b['write_guard_open']=B||!b['has_signer_check']),b;}function guardRuleBook(){const a=getJudgmentDoc()['rules']['domains']['guard'];if(!a)throw new Error('factory\x20rule\x20pack\x20\x27guard\x27\x20missing\x20—\x20broken\x20installation');return a['rules'];}function dataSourceClassFor(a){if(a['startsWith']('R-C1-'))return'type1_onchain_constant';if(a['startsWith']('R-C2-'))return'type2_witness_derived';if(a['startsWith']('R-C3-'))return'type3_submitted_object';if(a['startsWith']('R-C4-'))return'type4_system_context';return'cross_type';}function findingToGuardRisk(a){return{'id':a['rule_id'],'data_source_class':dataSourceClassFor(a['rule_id']),'level':a['level'],'category':a['dimension']??'data_source_trust','title':a['title'],'description':a['description'],'affected_stakeholders':a['stakeholders']??[],'scenario':a['scenario']??'','mitigation':a['mitigation']??'',...a['evidence']!==undefined?{'evidence':a['evidence']}:{},...a['exposure']!=null?{'exposure':a['exposure']}:{}};}export function runGuardRulePack(a){const b=guardRuleBook();let c;try{c=guardRiskFacts(a);}catch{return[];}return evaluateRuleBook(b,c)['findings']['map'](findingToGuardRisk);}export function assembleGuardAssessment(a,b){const c=getOverallRiskLevel(b),d={};for(const h of b){d[h['data_source_class']]=(d[h['data_source_class']]??0x0)+0x1;}const e=generateStakeholderAdvice(b,a['scene']),f=b['some'](i=>i['level']==='critical')||b['filter'](i=>i['level']==='high')['length']>=0x2,g=generateGuardSummary(a);return{'guard_summary':g,'scene':a['scene'],'risks':b,'overall_risk':c,'risks_by_data_source':d,'stakeholder_advice':e,'needs_human_review':f};}function getOverallRiskLevel(a){if(a['some'](b=>b['level']==='critical'))return'critical';if(a['some'](b=>b['level']==='high'))return'high';if(a['some'](b=>b['level']==='medium'))return'medium';return'low';}function generateStakeholderAdvice(a,b){const c={};for(const d of a){for(const e of d['affected_stakeholders']){if(!c[e])c[e]=[];c[e]['push']('['+d['level']['toUpperCase']()+']\x20'+d['title']+':\x20'+d['mitigation']);}}if(b)switch(b['binding_field']){case'buy_guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Before\x20purchase,\x20verify\x20the\x20buy_guard\x20logic\x20to\x20ensure\x20your\x20identity/credentials\x20can\x20pass\x20validation');break;case'order_allocators':if(!c['provider'])c['provider']=[];c['provider']['push']('Verify\x20the\x20order_allocators\x20ordering\x20to\x20ensure\x20your\x20Allocator\x20will\x20not\x20be\x20skipped\x20by\x20preceding\x20conditions');break;case'voting_guard':if(!c['arbitrator'])c['arbitrator']=[];c['arbitrator']['push']('Confirm\x20the\x20voting\x20weight\x20source\x20is\x20trustworthy;\x20prefer\x20querying\x20EntityRegistrar\x20rather\x20than\x20user-submitted\x20data');break;case'Forward.guard':if(!c['customer'])c['customer']=[];c['customer']['push']('Verify\x20the\x20Forward.guard\x20conditions\x20to\x20ensure\x20you\x20can\x20satisfy\x20the\x20advancement\x20criteria\x20and\x20avoid\x20locked\x20funds');break;}return c;}function generateGuardSummary(a){const b=[];b['push']('table\x20entries:\x20'+a['table']['length']);const c=a['table']['filter'](d=>d['b_submission'])['length'];return b['push']('submitted\x20data:\x20'+c+'\x20entries'),b['push']('root\x20type:\x20'+(a['root']?.['type']??'unknown')),a['rely']&&b['push']('rely:\x20'+a['rely']['guards']['length']+'\x20dependencies\x20('+(a['rely']['logic_or']?'OR':'AND')+')'),b['join'](',\x20');}export function getRiskSummary(a){return{'risk_count':a['risks']['length'],'critical_count':a['risks']['filter'](b=>b['level']==='critical')['length'],'high_count':a['risks']['filter'](b=>b['level']==='high')['length'],'needs_human_review':a['needs_human_review'],'top_risks':a['risks']['filter'](b=>b['level']==='critical'||b['level']==='high')['slice'](0x0,0x3)['map'](b=>b['title'])};}export function getRiskRulesCount(){return factoryRulePack('guard')?.['rules']['length']??0x0;}export const RISK_RULES=((()=>{const a=factoryRulePack('guard');if(!a)return[];return a['rules']['map'](b=>({'id':b['rule_id'],'data_source_class':dataSourceClassFor(b['rule_id']),'trigger':b['trigger']??'','check':c=>{const d=guardRuleBook()['find'](f=>f['rule_id']===b['rule_id']);if(!d)return null;const {findings:e}=evaluateRuleBook([d],guardRiskFacts(c));return e['length']>0x0?findingToGuardRisk(e[0x0]):null;}}));})());
@@ -44,5 +44,5 @@ export type FillGuardTemplateResult = {
44
44
  missing?: string[];
45
45
  };
46
46
  export declare function fillGuardTemplate(templateId: string, params: Record<string, unknown>): FillGuardTemplateResult;
47
- export declare const GUARD_TEMPLATES_VERSION = "1.0.0";
47
+ export declare const GUARD_TEMPLATES_VERSION = "1.1.0";
48
48
  export declare const GUARD_TEMPLATES_COUNT: number;