@wowok/agent-mcp 3.2.3 → 3.2.4
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.
- package/dist/chain-semantics/field-capability.js +1 -1
- package/dist/chain-semantics/freeze-map.js +1 -1
- package/dist/chain-semantics/fund-flow.js +1 -1
- package/dist/chain-semantics/guard-verbs.js +1 -1
- package/dist/communication/proof-reuse.d.ts +9 -0
- package/dist/communication/proof-reuse.js +1 -0
- package/dist/evaluation/builtins/graph-service.spec.js +1 -1
- package/dist/evaluation/engine.js +1 -1
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/graph/onchain/expand.js +1 -1
- package/dist/graph/onchain/exposure.js +1 -1
- package/dist/harness/recover.js +1 -1
- package/dist/knowledge/allocation-ledger.js +1 -1
- package/dist/knowledge/builtin-templates.d.ts +1 -1
- package/dist/knowledge/builtin-templates.js +1 -1
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-bindings.js +1 -1
- package/dist/knowledge/guard-design-patterns.d.ts +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/guard-ledger.js +1 -1
- package/dist/knowledge/guard-risk.js +1 -1
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-ledger.js +1 -1
- package/dist/knowledge/machine-templates.js +1 -1
- package/dist/knowledge/progress-ledger.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +1 -0
- package/dist/knowledge/template-loader.d.ts +1 -0
- package/dist/knowledge/template-loader.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.js +1 -1
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/participation/radar-core.js +1 -1
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/service-quote.js +1 -1
- package/dist/playbooks/service-build/service-quote.spec.d.ts +1 -0
- package/dist/playbooks/service-build/service-quote.spec.js +1 -0
- package/dist/review/index.js +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/call/arbitration.js +1 -1
- package/dist/schema/call/base.d.ts +4 -0
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/bridge.d.ts +1 -0
- package/dist/schema/call/error-codes.d.ts +1 -1
- package/dist/schema/call/error-codes.js +1 -1
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/interaction/index.d.ts +1 -1
- package/dist/schema/local/index.d.ts +10 -0
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/query/bi.d.ts +26 -0
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +1 -0
- package/dist/schemas/bridge_operation.output.json +1 -0
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/local_cache_operation.output.json +1 -0
- package/dist/schemas/local_history_operation.output.json +1 -0
- package/dist/schemas/local_info_operation.output.json +1 -0
- package/dist/schemas/local_mark_operation.output.json +1 -0
- package/dist/schemas/onchain_operations.output.json +1 -0
- package/dist/schemas/onchain_operations.schema.json +3 -3
- package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +1 -1
- package/dist/schemas/onchain_operations_service.schema.json +1 -1
- package/dist/schemas/query_toolkit.output.json +91 -7
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/move-fn-index.gen.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as
|
|
1
|
+
import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as a260a}from'./machine-templates.js';import{SERVICE_TEMPLATES,fillServiceTemplate}from'./service-templates.js';import{ORDER_TEMPLATES,fillTemplate as a260b}from'./order-templates.js';import{PROGRESS_TEMPLATES,fillProgressTemplate}from'./progress-templates.js';import{ARBITRATION_TEMPLATES,fillTemplate as a260c}from'./arbitration-templates.js';import{TREASURY_TEMPLATES,fillTemplate as a260d}from'./treasury-templates.js';import{PERMISSION_TEMPLATES,fillTemplate as a260e}from'./permission-templates.js';import{PASSPORT_TEMPLATES,fillTemplate as a260f}from'./passport-templates.js';import{ALLOCATION_TEMPLATES,fillTemplate as a260g}from'./allocation-templates.js';import{CONTACT_TEMPLATES,fillTemplate as a260h}from'./contact-templates.js';import{REWARD_TEMPLATES}from'./reward-templates.js';export const TEMPLATE_REGISTRY_VERSION=0x1;export const TEMPLATE_OBJECT_TYPES=['guard','machine','service','order','progress','arbitration','treasury','permission','passport','allocation','reward','contact'];function normalizeParam(a){return{'name':a['name'],'type':a['type'],'description':a['description']??'','required':a['required'],...a['default']!==undefined?{'default':a['default']}:{},...a['constraint']!==undefined?{'constraint':a['constraint']}:{}};}function guardMeta(a){return{'id':a['id'],'object_type':'guard','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function machineMeta(a){return{'id':a['id'],'object_type':'machine','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function bodyMeta(a,b,c,d){return{'id':a['id'],'object_type':b,'name':a['name'],'description':a['description'],'scenes':c,'industries':d,'instantiable':!![],'parameters':a['params']['map'](e=>normalizeParam(e))};}function rewardMeta(a){return{'id':a['type'],'object_type':'reward','name':a['name'],'description':a['description'],'scenes':[],'industries':[],'instantiable':![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}let REGISTRY=null,ID_COLLISIONS=[];function buildRegistry(){const a=new Map(),b=[],c=d=>{if(a['has'](d['meta']['id'])){b['push'](d['meta']['id']);return;}a['set'](d['meta']['id'],d);};for(const d of GUARD_TEMPLATES){c({'meta':guardMeta(d),'raw':d,'notes':d['creation_notes']});}for(const e of MACHINE_TEMPLATES){c({'meta':machineMeta(e),'raw':e,'notes':e['creation_notes']});}for(const f of SERVICE_TEMPLATES){c({'meta':bodyMeta(f,'service',f['applicable_scenes'],f['industry_tags']),'raw':f,'notes':f['notes']});}for(const g of ORDER_TEMPLATES){c({'meta':bodyMeta(g,'order',g['applicable_scenes'],g['industry_tags']),'raw':g,'notes':g['notes']});}for(const h of PROGRESS_TEMPLATES){c({'meta':bodyMeta(h,'progress',h['applicable_scenes'],h['industry_tags']),'raw':h,'notes':h['notes']});}for(const i of ARBITRATION_TEMPLATES){c({'meta':bodyMeta(i,'arbitration',i['applicable_scenes'],i['industry_tags']),'raw':i,'notes':i['notes']});}for(const j of TREASURY_TEMPLATES){c({'meta':bodyMeta(j,'treasury',j['applicable_scenes'],j['industry_tags']),'raw':j,'notes':j['notes']});}for(const k of PERMISSION_TEMPLATES){c({'meta':bodyMeta(k,'permission',k['applicable_scenes'],k['industry_tags']),'raw':k,'notes':k['notes']});}for(const l of PASSPORT_TEMPLATES){c({'meta':bodyMeta(l,'passport',l['applicable_scenarios'],l['industry_tags']),'raw':l,'notes':l['notes']});}for(const m of ALLOCATION_TEMPLATES){c({'meta':bodyMeta(m,'allocation',m['applicable_scenes'],m['industry_tags']),'raw':m,'notes':m['notes']});}for(const n of REWARD_TEMPLATES){c({'meta':rewardMeta(n),'raw':n,'guidance':{'guardCondition':n['guardCondition'],'amountRange':n['amountRange'],'allocationStrategy':n['allocationStrategy'],'example':n['example'],'relevantGuardOps':n['relevantGuardOps']}});}for(const o of CONTACT_TEMPLATES){c({'meta':bodyMeta(o,'contact',o['applicable_scenes'],o['industry_tags']),'raw':o,'notes':o['notes']});}return ID_COLLISIONS=b,a;}function registry(){return!REGISTRY&&(REGISTRY=buildRegistry()),REGISTRY;}export function getTemplateIdCollisions(){return registry(),ID_COLLISIONS;}export function getTemplateCounts(){const a=Object['fromEntries'](TEMPLATE_OBJECT_TYPES['map'](b=>[b,0x0]));for(const b of registry()['values']()){a[b['meta']['object_type']]+=0x1;}return a;}export function listTemplates(a){const b=[...registry()['values']()]['map'](c=>c['meta']);return a?b['filter'](c=>c['object_type']===a):b;}export function getTemplateDetail(a){const b=registry()['get'](a);if(!b)return null;return{...b['meta'],'raw':b['raw'],...b['notes']?{'notes':b['notes']}:{},...b['guidance']?{'guidance':b['guidance']}:{}};}export function findTemplateObjectType(a){return registry()['get'](a)?.['meta']['object_type']??null;}export function instantiateTemplate(a,b){const c=registry()['get'](a);if(!c)return{'ok':![],'object_type':null,'template_id':a,'error':'Template\x20not\x20found:\x20'+a+'.\x20Use\x20get_templates\x20without\x20\x27template\x27\x20to\x20list\x20all\x20template\x20ids.'};const d=c['meta']['object_type'];if(!c['meta']['instantiable'])return{'ok':![],'object_type':d,'template_id':a,'error':'Reward\x20templates\x20are\x20guidance-only\x20(prose\x20guard\x20conditions)\x20and\x20cannot\x20be\x20'+'instantiated\x20into\x20executable\x20JSON.\x20Use\x20the\x20guidance\x20payload\x20to\x20design\x20the\x20'+'Reward\x20+\x20Guard\x20manually.','guidance':c['guidance']};switch(d){case'guard':{const e=fillGuardTemplate(a,b);if(!e['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':e['error'],...e['missing']?{'missing_params':e['missing']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'table':e['table'],'root':e['root']},...c['notes']?{'notes':c['notes']}:{}};}case'machine':{const f=a260a(a,b);if(!f['success'])return{'ok':![],'object_type':d,'template_id':a,'error':f['validation_errors']?.['join'](';\x20')??'Machine\x20template\x20fill\x20failed',...f['missing_params']?{'missing_params':f['missing_params']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'nodes':f['filled_nodes'],'pairs':f['filled_pairs']},...c['notes']?{'notes':c['notes']}:{}};}case'service':{const g=fillServiceTemplate(a,b);if(!g['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':g['error']??'Service\x20template\x20fill\x20failed',...g['missing_required']?{'missing_params':g['missing_required']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':g['body'],...c['notes']?{'notes':c['notes']}:{}};}case'order':case'arbitration':case'treasury':case'permission':case'passport':case'allocation':case'progress':case'contact':{const h=fillBodyTemplate(d,a,b);if(!h['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':h['error']};return{'ok':!![],'object_type':d,'template_id':a,'body':h['body'],...c['notes']?{'notes':c['notes']}:{}};}default:return{'ok':![],'object_type':d,'template_id':a,'error':'Instantiation\x20not\x20supported\x20for\x20object_type\x20\x27'+d+'\x27'};}}function fillBodyTemplate(a,b,c){switch(a){case'order':return a260b(b,c);case'arbitration':return a260c(b,c);case'treasury':return a260d(b,c);case'permission':return a260e(b,c);case'passport':return a260f(b,c);case'allocation':return a260g(b,c);case'progress':return fillProgressTemplate(b,c);case'contact':return a260h(b,c);default:return{'ok':![],'error':'No\x20body-template\x20fill\x20for\x20\x27'+a+'\x27'};}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ENTRYPOINT}from'@wowok/wowok';import{buildViewport,runNodeAnalyzers}from'../graph/onchain/index.js';import{makeProposalNode}from'../graph/onchain/proposal-graph.js';import{machineRuleNodeAnalyzer,allocationRuleNodeAnalyzer}from'./rule-node-analyzers.js';import{GUARD_TEMPLATES}from'./guard-templates.js';import{GUARD_DESIGN_PATTERNS}from'./guard-design-patterns.js';import{unannotatedBuyerActionNodes}from'./scenario-modes.js';import{DIRECT_SALES_INVARIANT,ENTITY_RECIPIENT_RULE_ID}from'./entity-recipient-guard.js';const PLATFORM_TAKE_KEY=/^(?:platform_(?:share|commission|take)_bps|platform_fee_rate_bps|commission_rate_bps|(?:base_)?commission_rate_bps|offsite_ads_rate_bps|service_fee_rate_bps|payment_fee_bps)$/,MERCHANT_OWN_PRICE_KEY=/^(?:merchant_service_fee_bps|contract_fee_(?:small|large)_usd|contract_fee_tier_boundary_usd|digital_product_fee_(?:bps|min_usd|max_usd)|arbitration_fee.*|escrow_.*|min_.*|max_.*)$/,MERCHANT_SHARE_KEY=/^(?:host|property|partner|institution|landlord|freelancer|creator|seller|instructor)_rate_bps$/;function directSalesEconomyChecks(a){const b=[],c=a['fee_params'],d=Object['keys'](c)['filter'](x=>PLATFORM_TAKE_KEY['test'](x)&&typeof c[x]==='number'&&c[x]!==0x0);d['length']>0x0&&b['push']({'rule_id':'R-ECON-01','severity':'critical','title':'Template\x20mandates\x20a\x20platform\x20commission\x20('+d['map'](x=>x+'='+c[x])['join'](',\x20')+')','detail':'WoWok\x20is\x20DIRECT\x20SALES:\x20the\x20protocol\x20never\x20extracts\x20and\x20a\x20merchant\x20pays\x20only\x20gas,\x20so\x20the\x20merchant-side\x20share\x20must\x20default\x20to\x20the\x20whole\x20sale.\x20A\x20non-zero\x20platform\x20take\x20is\x20(a)\x20an\x20extraction\x20the\x20platform\x20has\x20no\x20right\x20to,\x20and\x20(b)\x20an\x20UNALLOCATED\x20liability\x20—\x20no\x20template\x20declares\x20a\x20platform\x20address,\x20so\x20at\x20build\x20time\x20it\x20resolves\x20to\x20the\x20deploying\x20merchant\x20itself\x20(blank\x20→\x20Account.Instance(),\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20to\x20the\x20keeper\x20(Recipient::Signer\x20→\x20tx_context::sender,\x20allocation.move:531-533),\x20or\x20back\x20to\x20the\x20buyer\x20(Recipient::GuardIdentifier,\x20allocation.move:501-527).\x20None\x20of\x20those\x20is\x20revenue.','suggestion':'Set\x20'+d['join'](',\x20')+'\x20to\x200\x20and\x20give\x20the\x20merchant\x20the\x20whole\x20sale\x20(single\x20Rate\x2010000\x20leg).\x20If\x20the\x20merchant\x20IS\x20the\x20aggregator\x20and\x20genuinely\x20charges\x20a\x20fee,\x20declare\x20it\x20via\x20merchant_service_fee_bps\x20with\x20an\x20EXPLICIT\x20non-empty\x20recipient\x20Entity.'});const e=a['allocator']['description'],f=/(?:commission|take|platform|remainder|share)\s*(?:=|:)\s*order\s*total\s*-\s*(?:segment|sum)/i['test'](e),g=(a['allocator']['rows']??[])['some'](x=>x['mode']==='surplus')||a['allocator']['mode']==='surplus',h=g&&/(?:platform|commission|fee|take)[^.;]{0,120}\bsurplus\b|\bsurplus\b[^.;]{0,120}(?:platform|commission|fee|take)/i['test'](e);f&&b['push']({'rule_id':'R-ECON-02','severity':'critical','title':'Take\x20is\x20an\x20implicit\x20remainder\x20(not\x20computable\x20before\x20ordering)','detail':'The\x20allocator\x20describes\x20the\x20platform\x20share\x20as\x20\x22order\x20total\x20-\x20segment\x20sums\x22,\x20so\x20the\x20amount\x20taken\x20depends\x20on\x20the\x20segment\x20configuration\x20rather\x20than\x20a\x20declared\x20rate.\x20A\x20buyer\x20(or\x20their\x20AI)\x20cannot\x20compute\x20the\x20take\x20BEFORE\x20ordering,\x20which\x20defeats\x20pre-order\x20evaluation\x20—\x20and\x20an\x20unbounded\x20remainder\x20off\x20a\x20transit\x20pool\x20is\x20unbounded\x20extraction.','suggestion':'Pin\x20every\x20share\x20to\x20an\x20EXPLICIT\x20Rate\x20(or\x20an\x20Amount\x20derived\x20from\x20a\x20declared\x20rate).\x20A\x20supplier\x20fee\x20belongs\x20in\x20its\x20own\x20explicitly-priced\x20segment\x20order,\x20never\x20as\x20a\x20residual\x20share.'});h&&b['push']({'rule_id':'R-ECON-02','severity':'high','title':'Fee\x20appears\x20to\x20be\x20taken\x20by\x20a\x20Surplus\x20leg','detail':'A\x20Surplus\x20sharing\x20entry\x20allocates\x20the\x20WHOLE\x20remaining\x20balance\x20(allocation.move:427\x20withdraw_all\x20semantics),\x20so\x20it\x20cannot\x20express\x20\x22take\x2015%\x22:\x20it\x20doubles\x20as\x20draining\x20the\x20pool.','suggestion':'Use\x20Rate\x20(or\x20RateGross)\x20for\x20any\x20proportional\x20share.\x20Reserve\x20Surplus\x20for\x20an\x20explicitly-bounded\x20residual\x20whose\x20recipient\x20and\x20cap\x20are\x20stated.'});const j=/\{\s*(?:who|Entity|Signer|GuardIdentifier)\s*:/['test'](e)||/recipient\s*[:=]/i['test'](e),k=/^(?:merchant_service_fee_bps|digital_product_fee_bps|logistics_rate_bps|service_fee_rate_bps)$/,l=Object['keys'](c)['some'](x=>k['test'](x)&&typeof c[x]==='number'&&c[x]!==0x0);l&&!j&&d['length']===0x0&&b['push']({'rule_id':'R-ECON-03','severity':'high','title':'Fee-bearing\x20template\x20names\x20no\x20recipient\x20slot\x20for\x20the\x20non-merchant\x20share','detail':'fee_params\x20carry\x20fee-shaped\x20keys\x20but\x20the\x20allocator\x20names\x20no\x20recipient\x20for\x20them.\x20On-chain\x20each\x20Rate\x20lands\x20in\x20ITS\x20OWN\x20recipient\x20slot;\x20an\x20unnamed\x20one\x20resolves\x20to\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20to\x20the\x20keeper\x20(allocation.move:531-533),\x20or\x20back\x20to\x20the\x20buyer.\x20The\x20share\x20is\x20then\x20an\x20unallocated\x20liability\x20rather\x20than\x20revenue.','suggestion':'State\x20the\x20recipient\x20per\x20share\x20in\x20the\x20allocator\x20description\x20and\x20bind\x20it\x20to\x20an\x20explicit\x20NON-EMPTY\x20Entity\x20the\x20buyer\x20can\x20see\x20before\x20ordering.\x20Never\x20leave\x20it\x20blank.'});const m=/(?:layer-?1|service-?level|pool)[^.]*settles? the full amount|full amount to the (?:platform|organizer) pool/i['test'](e);m&&b['push']({'rule_id':'R-ECON-04','severity':'medium','title':'Escrow\x20transits\x20an\x20organizer\x20pool\x20before\x20reaching\x20the\x20merchant','detail':'The\x20full\x20order\x20amount\x20settles\x20into\x20a\x20platform/organizer\x20pool\x20first\x20and\x20is\x20then\x20redistributed.\x20That\x20contradicts\x20the\x20direct-sales\x20promise\x20(\x22money\x20moves\x20only\x20between\x20the\x20two\x20parties\x22)\x20and\x20makes\x20the\x20organizer\x20a\x20waypoint\x20on\x20every\x20payout,\x20including\x20every\x20refund.','suggestion':'Release\x20supplier\x20segments\x20directly\x20from\x20the\x20order\x27s\x20own\x20Allocation,\x20and\x20make\x20the\x20organizer\x20a\x20named\x20party\x20rather\x20than\x20a\x20transit\x20node.'});const n=Object['keys'](c)['find'](x=>/^attributed_.*_bps$/['test'](x)&&typeof c[x]==='number'),o=Object['keys'](c)['find'](x=>/^(?:base_)?commission_rate_bps$/['test'](x)&&typeof c[x]==='number');n&&o&&c[n]>c[o]&&b['push']({'rule_id':'R-ECON-05','severity':'medium','title':'Attribution-priced\x20take:\x20a\x20cheaper\x20acquisition\x20channel\x20is\x20charged\x20MORE','detail':n+'='+c[n]+'\x20exceeds\x20'+o+'='+c[o]+'.\x20Charging\x20more\x20for\x20attributed\x20orders\x20means\x20the\x20merchant\x27s\x20cheap\x20channels\x20(KOC,\x20social,\x20repeat\x20buyers)\x20are\x20penalised\x20—\x20the\x20opposite\x20of\x20what\x20direct\x20sales\x20should\x20reward.','suggestion':'Price\x20every\x20channel\x20identically.\x20Attribution\x20may\x20change\x20RANKING,\x20never\x20the\x20take.'});if(a['allocator']['mode']==='rate'){const x=Object['keys'](c)['filter'](A=>MERCHANT_SHARE_KEY['test'](A)&&typeof c[A]==='number'),y=Object['keys'](c)['filter'](A=>PLATFORM_TAKE_KEY['test'](A)&&typeof c[A]==='number'),z=[...x,...y];if(x['length']>0x0&&y['length']>0x0){const A=z['map'](D=>c[D])['filter'](D=>typeof D==='number'),B=A['reduce']((D,E)=>D+E,0x0),C=/surplus/i['test'](e);B!==0x2710&&!C&&b['push']({'rule_id':'R-ECON-06','severity':'critical','title':'Rate\x20shares\x20sum\x20to\x20'+B+',\x20not\x2010000','detail':'Declared\x20rate\x20shares\x20('+z['map']((D,E)=>D+'='+A[E])['join']('\x20+\x20')+')\x20total\x20'+B+'.\x20With\x20no\x20Surplus\x20recipient\x20the\x20remainder\x20is\x20not\x20protected:\x20the\x20chain\x20records\x20no\x20\x22already\x20triggered\x22\x20flag,\x20so\x20a\x20balance\x20left\x20behind\x20after\x20a\x20partial\x20split\x20can\x20be\x20claimed\x20REPEATEDLY\x20by\x20anyone\x20passing\x20the\x20same\x20Guard.\x20This\x20is\x20exactly\x20what\x20happens\x20when\x20a\x20platform\x20leg\x20is\x20zeroed\x20without\x20recomputing\x20the\x20merchant\x20leg.','suggestion':'Make\x20the\x20shares\x20sum\x20to\x20exactly\x2010000,\x20or\x20declare\x20an\x20explicit\x20Surplus\x20recipient\x20for\x20the\x20residual.'});}}const p=(a['allocator']['rows']??[])['map']((D,E)=>({'r':D,'i':E})),q=p['filter'](({r:D})=>D['recipient']==='entity'&&!(D['recipient_key']??'')['trim']());q['length']>0x0&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'critical','title':'Allocator\x20row(s)\x20'+q['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20name\x20no\x20Entity\x20recipient\x20—\x20the\x20share\x20silently\x20pays\x20the\x20deploying\x20merchant','detail':q['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20declare\x20recipient=\x27entity\x27\x20with\x20no\x20recipient_key,\x20which\x20builds\x20as\x20'+'{\x20who:\x20{\x20Entity:\x20{\x20name_or_address:\x20\x22\x22\x20}\x20}\x20}.\x20That\x20is\x20NOT\x20a\x20no-op:\x20the\x20SDK\x20resolver\x20substitutes\x20the\x20DEFAULT\x20LOCAL\x20ACCOUNT\x20before\x20the\x20'+'address\x20reaches\x20Move,\x20so\x20the\x20order\x20escrow\x20pays\x20whoever\x20ran\x20the\x20deploy\x20—\x20the\x20\x27platform\x27\x20share\x20the\x20template\x20left\x20unnamed\x20becomes\x20the\x20merchant\x27s\x20'+('own\x20take.\x20'+DIRECT_SALES_INVARIANT),'suggestion':'Give\x20the\x20row\x20an\x20explicit\x20`recipient_key`\x20naming\x20the\x20party\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address\x20the\x20buyer\x20can\x20see\x20BEFORE\x20ordering).\x20If\x20the\x20whole\x20sale\x20goes\x20'+'to\x20the\x20merchant,\x20do\x20not\x20declare\x20an\x20entity\x20row\x20at\x20all:\x20use\x20ONE\x20{\x20who:\x20{\x20GuardIdentifier:\x200\x20},\x20sharing:\x2010000,\x20mode:\x20\x22Rate\x22\x20}\x20leg.\x20The\x20scalar\x20'+'`allocator.recipient:\x20\x22entity\x22`\x20form\x20is\x20auditable\x20too:\x20it\x20must\x20carry\x20a\x20`recipient_key`\x20(or\x20a\x20`rows[]`\x20array)\x20when\x20no\x20rows\x20narrow\x20it.'});!a['allocator']['rows']&&a['allocator']['recipient']==='entity'&&!(a['allocator']['recipient_key']??'')['trim']()&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'critical','title':'Allocator\x20names\x20no\x20Entity\x20recipient\x20(scalar\x20form,\x20no\x20rows)\x20—\x20the\x20share\x20silently\x20pays\x20the\x20deploying\x20merchant','detail':'The\x20allocator\x20declares\x20scalar\x20recipient=\x27entity\x27\x20with\x20no\x20recipient_key\x20and\x20no\x20rows[],\x20which\x20builds\x20as\x20'+'{\x20who:\x20{\x20Entity:\x20{\x20name_or_address:\x20\x22\x22\x20}\x20}\x20}.\x20That\x20is\x20NOT\x20a\x20no-op:\x20the\x20SDK\x20resolver\x20substitutes\x20the\x20DEFAULT\x20LOCAL\x20ACCOUNT\x20before\x20the\x20'+'address\x20reaches\x20Move,\x20so\x20the\x20order\x20escrow\x20pays\x20whoever\x20ran\x20the\x20deploy\x20—\x20the\x20share\x20the\x20template\x20left\x20unnamed\x20becomes\x20the\x20merchant\x27s\x20'+('own\x20take.\x20'+DIRECT_SALES_INVARIANT),'suggestion':'Declare\x20the\x20destination\x20machine-checkably:\x20set\x20`recipient_key`\x20on\x20the\x20allocator\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address\x20the\x20buyer\x20can\x20see\x20BEFORE\x20ordering),\x20'+'or\x20add\x20a\x20`rows[]`\x20array\x20carrying\x20the\x20on-chain\x20`who`\x20shape.\x20If\x20the\x20whole\x20sale\x20goes\x20to\x20the\x20merchant,\x20use\x20ONE\x20'+'{\x20recipient:\x20\x27guard_identifier\x27,\x20recipient_key:\x20\x270\x27\x20}\x20row\x20instead\x20of\x20an\x20entity\x20scalar.'});const s=p['filter'](({r:D})=>D['recipient']==='entity'&&/^0x0*$/i['test']((D['recipient_key']??'')['trim']()));s['length']>0x0&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'high','title':'Allocator\x20row(s)\x20'+s['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20name\x20the\x20zero\x20address\x20as\x20Entity\x20recipient','detail':s['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20carry\x20recipient_key=\x270x0\x27\x20(or\x20an\x20all-zero\x20literal).\x20The\x20chain\x20does\x20NOT\x20reject\x20it:\x20'+'allocation.move:250-255\x20swallows\x20Recipient::Entity\x20in\x20a\x20(_)\x20catch-all\x20at\x20declaration\x20time,\x20and\x20allocation.move:451-453\x20/\x20:514\x20forward\x20the\x20raw\x20'+'address\x20straight\x20to\x20the\x20payout\x20constructor.\x20The\x20allocation\x20is\x20accepted\x20and\x20the\x20share\x20is\x20silently\x20transferred\x20to\x200x0\x20and\x20permanently\x20burned\x20—\x20'+'this\x20scan\x20is\x20the\x20only\x20defence.','suggestion':'Replace\x20the\x20zero\x20literal\x20with\x20the\x20real\x20recipient\x20address\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address),\x20or\x20drop\x20the\x20row\x20if\x20the\x20share\x20is\x20not\x20owed.'});const u=D=>D['recipient']+':'+(D['recipient_key']??'')['trim']()['toLowerCase'](),v=new Set((a['allocator']['rows']??[])['filter'](D=>D['mode']==='rate')['map'](u)),w=p['filter'](({r:D})=>D['mode']==='surplus'&&v['has'](u(D)));return w['length']>0x0&&b['push']({'rule_id':'R-RECIPIENT-04','severity':'critical','title':'Surplus\x20row(s)\x20'+w['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20pay\x20a\x20recipient\x20a\x20Rate\x20leg\x20already\x20pays\x20—\x20the\x20remainder\x20swallows\x20an\x20undeclared\x20share','detail':w['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20duplicate\x20a\x20Rate\x20leg\x27s\x20recipient.\x20The\x20chain\x20pays\x20every\x20Rate\x20leg\x20its\x20declared\x20basis\x20points\x20'+'and\x20then\x20pays\x20the\x20ENTIRE\x20remainder\x20to\x20the\x20Surplus\x20recipient,\x20so\x20this\x20party\x20quietly\x20receives\x20rate%\x20+\x20100%\x20of\x20the\x20residual\x20and\x20any\x20leg\x20the\x20'+'author\x20intended\x20but\x20omitted\x20(commission,\x20payment\x20fee,\x20platform\x20take)\x20is\x20never\x20created.\x20The\x20Rate-sum\x20rule\x20passes\x20because\x20the\x20sum\x20is\x20legal\x20—\x20'+'the\x20misroute\x20is\x20invisible\x20there,\x20and\x20order_allocators\x20freezes\x20permanently\x20at\x20publish.\x20Mainnet\x20precedent\x20(Booking\x20replica,\x202026-10-06):\x20the\x20'+'property\x20took\x20100%\x20(Rate\x208350\x20+\x20Surplus),\x20the\x2015%\x20commission\x20and\x201.5%\x20payment-fee\x20legs\x20never\x20existed,\x20and\x20the\x20published\x20Service\x20had\x20to\x20be\x20abandoned.','suggestion':'Point\x20the\x20Surplus\x20row\x20at\x20the\x20party\x20meant\x20to\x20absorb\x20the\x20remainder\x20(usually\x20the\x20merchant),\x20distinct\x20from\x20every\x20Rate\x20leg\x20—\x20or,\x20if\x20the\x20duplicated\x20'+'recipient\x20is\x20truly\x20intended\x20to\x20take\x20rate%\x20+\x20remainder,\x20collapse\x20the\x20two\x20rows\x20into\x20ONE\x20rate\x20row\x20so\x20the\x20declared\x20split\x20equals\x20the\x20actual\x20split.\x20'+'Every\x20intended\x20payee\x20must\x20be\x20its\x20own\x20explicit\x20row.'}),b;}const DISPUTE_NODE_REGEX=/(^|_)(disputed?|arbitration|arb)(_|$)|^(refund|refunded|deposit_refunded|deposit_deducted|cancel|cancelled)$/i,KNOWN_GUARD_REF_IDS=new Set([...GUARD_DESIGN_PATTERNS['map'](a=>a['id']),...GUARD_TEMPLATES['map'](a=>a['id'])]);function guardRefChecks(a){const b=[];for(const c of a['guards']){if(!/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/['test'](c['template_id'])){b['push']({'rule_id':'R-REF-01','severity':'high','title':'Guard\x20reference\x20\x27'+c['template_id']+'\x27\x20is\x20not\x20a\x20resolvable\x20id','detail':'Guard\x20references\x20must\x20name\x20a\x20guard\x20design\x20pattern\x20(\x27pattern.*\x27,\x20'+GUARD_DESIGN_PATTERNS['length']+'\x20available)\x20or\x20a\x20guard\x20template\x20(\x27tpl_*\x27,\x20'+GUARD_TEMPLATES['length']+'\x20available).\x20Bare\x20prose\x20ids\x20dangle:\x20no\x20builder\x20can\x20resolve\x20them,\x20so\x20the\x20AI\x20invents\x20guard\x20logic\x20at\x20build\x20time.','suggestion':'Replace\x20with\x20the\x20semantically\x20nearest\x20pattern.*/tpl_*\x20id\x20(compose\x20multi-condition\x20logic\x20in\x20the\x20purpose\x20text).'});continue;}!KNOWN_GUARD_REF_IDS['has'](c['template_id'])&&b['push']({'rule_id':'R-REF-02','severity':'high','title':'Guard\x20reference\x20\x27'+c['template_id']+'\x27\x20does\x20not\x20exist\x20in\x20any\x20guard\x20catalog','detail':'The\x20id\x20is\x20namespaced\x20correctly\x20but\x20matches\x20no\x20guard\x20design\x20pattern\x20nor\x20guard\x20template\x20—\x20a\x20dangling\x20reference\x20the\x20AI\x20cannot\x20resolve.','suggestion':'Fix\x20the\x20id\x20(typo)\x20or\x20point\x20it\x20at\x20the\x20nearest\x20existing\x20pattern.*/tpl_*\x20entry.'});}return b;}function staticChecks(a){const b=[];for(const h of a['machine_shape']){DISPUTE_NODE_REGEX['test'](h['name'])&&b['push']({'rule_id':'R-M1-11','severity':'critical','title':'Machine\x20node\x20\x27'+h['name']+'\x27\x20models\x20dispute/refund\x20flow','detail':'Disputes\x20are\x20independent\x20of\x20the\x20Machine\x20workflow;\x20refunds\x20route\x20via\x20Allocators\x20triggered\x20by\x20business\x20states.','suggestion':'Remove\x20the\x20node;\x20route\x20refunds\x20via\x20Allocator\x20states\x20(closed_cancel/returned)\x20and\x20disputes\x20via\x20the\x20Arbitration\x20object.'});}const c=new Map();for(const j of a['guards']){if(/time_lock|order_holder|progress_state/['test'](j['template_id'])&&!/order\.service|project bind|service binding/i['test'](j['purpose'])){const k=c['get'](j['template_id'])??[];k['push'](j['key']??'(no\x20key)'),c['set'](j['template_id'],k);}}for(const [l,m]of c){b['push']({'rule_id':'R-C3-05','severity':'medium','title':'Guard\x20\x27'+l+'\x27\x20consumes\x20a\x20submitted\x20Order\x20without\x20project\x20binding\x20('+m['length']+'x:\x20'+m['join'](',\x20')+')','detail':'Passport\x20submissions\x20are\x20caller-built;\x20without\x20logic_equal[order.service,\x20<service>]\x20a\x20stale\x20order\x20from\x20another\x20project\x20can\x20satisfy\x20the\x20guard\x20for\x20a\x20fresh\x20order.','suggestion':'State\x20the\x20project\x20binding\x20in\x20the\x20guard\x20purpose\x20AND\x20include\x20it\x20in\x20the\x20guard\x20root\x20at\x20build\x20time.'});}a['machine_shape']['length']===0x0&&b['push']({'rule_id':'R-M1-01','severity':'critical','title':'machine_shape\x20is\x20empty','detail':'No\x20entry\x20node\x20—\x20the\x20Machine\x20cannot\x20start.','suggestion':'Add\x20at\x20least\x20one\x20entry\x20node\x20representing\x20the\x20escrowed\x20state.'});const d=a['guards']['some'](n=>/refund|cancel/i['test'](n['template_id'])||/refund|cancel/i['test'](n['purpose']))||/refund/i['test'](a['allocator']['description']);!d&&b['push']({'rule_id':'R1','severity':'high','title':'No\x20refund\x20path\x20detected','detail':'No\x20refund/cancel\x20guard\x20and\x20no\x20refund\x20route\x20in\x20the\x20allocator\x20description.','suggestion':'Add\x20a\x20refund/cancel\x20guard\x20or\x20an\x20allocator\x20refund\x20route\x20before\x20publishing.'});const e=a['guards']['some'](n=>n['host']==='arbitration')||a['trust_mechanisms']['some'](n=>n['startsWith']('R2'));!e&&b['push']({'rule_id':'R2','severity':'high','title':'No\x20independent\x20Arbitration\x20reference\x20detected','detail':'The\x20template\x20carries\x20no\x20arbitration-hosted\x20guard\x20and\x20no\x20R2\x20trust\x20mechanism.','suggestion':'Mount\x20an\x20independent\x20Arbitration\x20object\x20with\x20its\x20own\x20Permission.'});a['keeper_dependencies']['length']===0x0&&b['push']({'rule_id':'R9','severity':'medium','title':'No\x20keeper\x20dependencies\x20declared','detail':'Time-driven\x20transitions\x20only\x20ALLOW\x20advancement\x20—\x20someone\x20must\x20run\x20the\x20keepers.','suggestion':'Declare\x20the\x20keeper\x20operations\x20(timeouts,\x20window\x20expiries,\x20settlement\x20triggers).'});b['push'](...directSalesEconomyChecks(a));const f=unannotatedBuyerActionNodes(a['machine_shape']);return f['length']>0x0&&b['push']({'rule_id':'R-OPER-01','severity':'medium','title':'Buyer-side\x20node(s)\x20without\x20an\x20operator\x20annotation','detail':'Node(s)\x20'+f['map'](o=>'\x27'+o+'\x27')['join'](',\x20')+'\x20look\x20like\x20order-payer\x20actions\x20but\x20carry\x20no\x20operator\x20field.\x20At\x20build\x20time\x20they\x20default\x20to\x20a\x20merchant\x20permission\x20slot,\x20and\x20the\x20order\x20payer\x20cannot\x20advance\x20them\x20(E_PERMISSION_DENIED).','suggestion':'Annotate\x20true\x20buyer\x20actions\x20with\x20operator:\x20\x22order_payer\x22\x20(an\x20EMPTY\x20namedOperator\x20—\x20the\x20on-chain\x20check\x20resolves\x20it\x20to\x20the\x20order\x20payer);\x20rename\x20merchant-side\x20states\x20(e.g.\x20\x27cancelled\x27\x20->\x20\x27merchant_cancelled\x27)\x20when\x20the\x20actor\x20is\x20NOT\x20the\x20buyer.'}),b;}const PERIOD_COUNT_KEY_REGEX=/^(monthly_allocators|term_count|session_count|segment_count|periods|cycles|installments)$/;function poolPeriodCount(a){for(const [b,c]of Object['entries'](a['fee_params'])){if(PERIOD_COUNT_KEY_REGEX['test'](b)&&typeof c==='number'&&c>=0x2)return c;}return undefined;}function periodicReleaseChecks(a){const b=poolPeriodCount(a);if(b===undefined)return[];const c=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](f=>f['purpose'])]['join']('\x20\x0a\x20'),d=[];/surplus/i['test'](c)&&!/no surplus|surplus[^.\n]*(disabled|forbidden|disallowed)|amount mode only|single surplus/i['test'](c)&&d['push']({'rule_id':'R-PER-01','severity':'high','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20declares\x20Surplus\x20without\x20a\x20terminal-only\x20qualifier','detail':'A\x20Surplus\x20allocator\x20entry\x20runs\x20balance::withdraw_all\x20(allocation.move:288-298).\x20In\x20a\x20pool\x20pre-funded\x20for\x20'+b+'\x20periods\x20it\x20drains\x20every\x20future\x20release,\x20not\x20just\x20the\x20remainder.','suggestion':'Release\x20each\x20period\x20with\x20Amount;\x20if\x20the\x20pool\x20remainder\x20settles\x20in\x20one\x20entry,\x20declare\x20it\x20explicitly\x20as\x20the\x20SINGLE\x20terminal\x20Surplus\x20at\x20the\x20settlement\x20node,\x20or\x20disable\x20Surplus\x20outright.'});const e=/per[- ](month|period|term|session|cycle|segment)|one per (rent )?period|release-sequence lock/i['test'](c);return!e&&d['push']({'rule_id':'R-PER-02','severity':'high','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20declares\x20no\x20per-period\x20release\x20Guard','detail':'alloc()\x20has\x20no\x20consumed/nonce\x20flag\x20(allocation.move:204-321):\x20two\x20releases\x20bound\x20to\x20the\x20SAME\x20Guard\x20can\x20both\x20fire\x20the\x20same\x20day\x20and\x20drain\x20the\x20pool.\x20The\x20cadence\x20gate\x20must\x20be\x20one\x20Guard\x20per\x20period.','suggestion':'Declare\x20one\x20release\x20Guard\x20per\x20period\x20(per-month/per-term\x20time-lock\x20Guards,\x20each\x20keyed\x20to\x20its\x20own\x20period\x20window)\x20in\x20the\x20guard\x20set.'}),!/threshold[^.\n]*(one|single|per[- ]|month|period|term|session|=\s*0\b|\b0\b|must be 0)/i['test'](c)&&d['push']({'rule_id':'R-PER-03','severity':'medium','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20does\x20not\x20pin\x20threshold\x20to\x20one\x20period','detail':'alloc()\x20asserts\x20balance\x20>=\x20threshold\x20before\x20EVERY\x20release\x20(allocation.move:206).\x20A\x20threshold\x20sized\x20to\x20the\x20total\x20pool\x20passes\x20the\x20first\x20release\x20and\x20then\x20locks\x20all\x20remaining\x20periods.','suggestion':'State\x20in\x20the\x20allocator\x20description\x20or\x20build\x20notes\x20that\x20threshold\x20=\x20one\x20period\x27s\x20release\x20amount\x20(never\x20the\x20pre-funded\x20total).'}),d;}const MIN_PRICE_KEY_REGEX=/^(?:min_[a-z0-9_]*?(?:price|amount|usd|value)|price_floor)$/,FLOOR_TEXT_REGEX=/fixed (?:fee|charge)[^.\n]*(?:<|less than|below) [^.\n]*(?:lowest|minimum|min)|minimum (?:sku|order|item|unit) (?:price|amount)|(?:below|under|<=)\s*the\s+smallest[^.\n]*(?:order|escrow|booking|price)/i,FIXED_FEE_TEXT_REGEX=/\bamount mode\b|fixed (?:fee|fulfillment|fulfilment|per[- ]order) (?:fee|charge)|\bAmount\b[^.\n]*(?:fee|charge)/i;function fundAnchorChecks(a){const b=[],c=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](h=>h['template_id']+'\x20'+h['purpose'])]['join']('\x20\x0a\x20'),d=a['allocator']['refund_track']==='order_anchored'||/allocator_order_anchor/['test'](c)||/guardidentifier\(0\)|order[- ]anchored|for_object/i['test'](c);!d&&b['push']({'rule_id':'R-ANCHOR-01','severity':'critical','title':'Allocator\x20has\x20no\x20order\x20anchor\x20—\x20its\x20Guard\x20cannot\x20bind\x20the\x20paying\x20Order','detail':'Every\x20recipient\x20of\x20this\x20allocator\x20is\x20a\x20fixed\x20party\x20(recipient=\x27'+a['allocator']['recipient']+'\x27,\x20no\x20GuardIdentifier\x20row),\x20so\x20nothing\x20in\x20the\x20Guard\x27s\x20verification\x20context\x20names\x20the\x20Order\x20being\x20settled:\x20Recipient::Entity/Signer\x20are\x20resolved\x20without\x20any\x20submission\x20check\x20(allocation.move:451-456)\x20and\x20the\x20Allocation\x20itself\x20never\x20enters\x20the\x20Guard\x20context.\x20Testnet\x20proved\x20the\x20consequence:\x20a\x20passport\x20built\x20from\x20an\x20ALREADY-SETTLED\x20order\x20of\x20the\x20same\x20Service\x20drained\x20a\x20different\x20order\x27s\x20escrow\x20(CR-01).\x20The\x20identifier-255\x20once-slot\x20does\x20not\x20help\x20—\x20it\x20is\x20stored\x20per\x20Allocation,\x20so\x20a\x20fresh\x20pool\x20has\x20no\x20record.','suggestion':'Adopt\x20pattern.allocator_order_anchor:\x20add\x20one\x20{GuardIdentifier:\x200}\x20row\x20with\x20Rate\x200\x20(pays\x20nothing,\x20makes\x20the\x20submitted\x20Order\x20the\x20Guard\x27s\x20binding\x20target),\x20declare\x20refund_track:\x20\x22order_anchored\x22,\x20and\x20pin\x20the\x20Guard\x20expression\x20to\x20that\x20identifier\x20plus\x20logic_equal[order.service,\x20<this\x20service>].'});const e=a['allocator']['mode']==='amount',f=e||FIXED_FEE_TEXT_REGEX['test'](c),g=Object['keys'](a['fee_params'])['some'](h=>MIN_PRICE_KEY_REGEX['test'](h))||FLOOR_TEXT_REGEX['test'](c);return f&&!g&&b['push']({'rule_id':'R-FIXFEE-01','severity':e?'critical':'high','title':'Fixed\x20Amount\x20fee\x20with\x20no\x20minimum\x20order\x20value\x20—\x20sub-fee\x20orders\x20deadlock\x20permanently','detail':'alloc()\x20asserts\x20balance\x20>=\x20fix\x20before\x20distributing\x20(allocation.move:390):\x20an\x20order\x20escrowed\x20BELOW\x20the\x20fixed\x20fee\x20can\x20never\x20settle,\x20and\x20the\x20terminal\x20nodes\x20(completed/closed_cancel)\x20leave\x20no\x20refund\x20path\x20for\x20it,\x20so\x20buyer\x20funds\x20and\x20the\x20order\x20strand\x20forever\x20(testnet\x20CR-02,\x20reproduced\x20on\x20a\x200.001\x20WOW\x20SKU\x20against\x20a\x200.15\x20WOW\x20fee).','suggestion':'Declare\x20a\x20minimum\x20listing/order\x20value\x20above\x20every\x20fixed\x20leg\x20in\x20fee_params\x20(e.g.\x20min_sku_price)\x20and\x20state\x20it\x20in\x20the\x20allocator\x20description,\x20or\x20model\x20the\x20per-order\x20fee\x20as\x20Rate/RateGross\x20instead\x20of\x20a\x20fixed\x20Amount.'}),a['allocator']['once_per_order']===!![]&&!/per[- ]allocation|per[- ]pool|not cross[- ]order|within (a|the) (pool|allocation)/i['test'](c)&&b['push']({'rule_id':'R-ONCE-SCOPE-01','severity':'medium','title':'once_per_order\x20claim\x20does\x20not\x20state\x20its\x20per-Allocation\x20scope','detail':'The\x20identifier-255\x20once-slot\x20is\x20keyed\x20(guard,\x20allocator,\x20submission)\x20ON\x20ONE\x20Allocation,\x20so\x20replay\x20immunity\x20holds\x20within\x20a\x20single\x20pool\x20only;\x20a\x20second\x20Allocation\x20of\x20the\x20same\x20Service\x20starts\x20with\x20no\x20record.\x20Presenting\x20ONCE\x20as\x20general\x20idempotency\x20is\x20what\x20let\x20testnet\x20CR-01\x20read\x20as\x20\x27already\x20protected\x27.','suggestion':'Say\x20explicitly\x20that\x20255\x20protects\x20one\x20pool,\x20and\x20pair\x20it\x20with\x20the\x20order\x20anchor\x20(R-ANCHOR-01)\x20for\x20cross-order\x20safety.'}),b;}function templateText(a,b=[]){return[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](c=>c['template_id']+'\x20'+c['purpose']),...a['machine_shape']['map'](c=>c['name']+'\x20'+c['role']),...Object['entries'](a['time_anchors']??{})['map'](([c,d])=>c+'\x20'+d),...b]['join']('\x20\x0a\x20');}const STAY_DATE_REGEX=/check[\s-]?in|check[\s-]?out|departure\s+date|arrival\s+date|booking\s+date|checkin|checkout|stay\s+date|stay_nights|\bstay\s+nights?\b|\bper\s+night\b|入住|退房|离店|到店日/i,CHAIN_CLOCK_REGEX=/order\.time|progress\.current_time|\border\s+time\b|witness/i,REPOSITORY_DATE_SOURCE_REGEX=/(?:write|writes|written|storing|store|stores|persist|persisted|record|records|read|reads)\b[^.\n]{0,90}repositor|repositor\w*\b[^.\n]{0,90}(?:stay|check[\s-]?in|check[\s-]?out|departure|arrival|date)/i;function timeWindowAnchorChecks(a){const b=templateText(a);if(!STAY_DATE_REGEX['test'](b))return[];if(CHAIN_CLOCK_REGEX['test'](b)||REPOSITORY_DATE_SOURCE_REGEX['test'](b))return[];const c=b['match'](new RegExp(STAY_DATE_REGEX['source'],'gi'))??[],d=/\d+\s*[-–]\s*\d+\s*h(?:ours?|rs?)?\s*(?:adjustable|tunable|configurable)|\badjustable\b|\btunable\b/i['test'](b);return[{'rule_id':'R-WIN-ANCHOR-01','severity':'high','title':'Per-order\x20time\x20window(s)\x20anchored\x20to\x20a\x20stay\x20date\x20that\x20does\x20not\x20exist\x20on\x20chain\x20('+Array['from'](new Set(c))['slice'](0x0,0x5)['join'](',\x20')+')','detail':'The\x20template\x27s\x20windows\x20are\x20relative\x20to\x20a\x20check-in\x20/\x20check-out\x20/\x20departure\x20/\x20night\x20date.\x20No\x20such\x20field\x20exists\x20on\x20chain:\x20'+'`Order.items`\x20is\x20`vector<SaleItem>`\x20with\x20`SaleItem\x20{\x20item,\x20price,\x20quantity,\x20wip_hash\x20}`\x20(order.move:28-33)\x20and\x20the\x20purchasable\x20'+'`Sale\x20{\x20name,\x20price,\x20stock,\x20suspension,\x20wip,\x20wip_hash\x20}`\x20(service.move:100-107)\x20carries\x20no\x20schedule;\x20the\x20only\x20per-order\x20clock\x20is\x20'+'`Order.time`\x20(order.move:74),\x20the\x20CREATION\x20timestamp.\x20`Progress.current_time`\x20(progress.move:85)\x20is\x20overwritten\x20on\x20every\x20forward\x20'+'(progress.move:458)\x20and\x20`Progress.history`\x20records\x20node\x20visits,\x20so\x20neither\x20is\x20a\x20business\x20date.\x20A\x20window\x20declared\x20relative\x20to\x20the\x20'+'stay\x20calendar\x20is\x20therefore\x20UNREACHABLE\x20—\x20every\x20published\x20Guard\x20silently\x20measures\x20from\x20booking\x20time\x20instead,\x20and\x20for\x20a\x20lead\x20time\x20of\x20'+'days-to-weeks\x20that\x20is\x20a\x20material\x20semantic\x20loss,\x20not\x20a\x20rounding\x20error.'+(d?'\x20The\x20window\x20is\x20also\x20advertised\x20as\x20adjustable,\x20which\x20is\x20doubly\x20unreachable:\x20a\x20Guard\x20is\x20frozen\x20at\x20creation\x20'+'(transfer::freeze_object,\x20guard.move:262)\x20and\x20Machine\x20forwards\x20are\x20immutable\x20after\x20publish\x20(the\x20not-published\x20guard,\x20'+'machine.move:316),\x20so\x20an\x20\x27N-Mh\x20adjustable\x27\x20window\x20means\x20one\x20separately\x20published\x20Guard\x20per\x20window\x20value,\x20never\x20a\x20tunable\x20one.':''),'suggestion':'Express\x20every\x20window\x20relative\x20to\x20`order.time`\x20(or\x20`order.time\x20+\x20<window>`),\x20and\x20if\x20the\x20business\x20promise\x20is\x20genuinely\x20a\x20stay-date\x20'+'deadline,\x20write\x20the\x20stay\x20dates\x20into\x20a\x20Repository\x20at\x20buy\x20time,\x20pin\x20that\x20Repository\x20address\x20as\x20a\x20table\x20constant,\x20and\x20read\x20them\x20in\x20the\x20'+'Guard\x20(`query\x20repository.data`).\x20State\x20the\x20residual\x20semantic\x20loss\x20in\x20build_notes\x20rather\x20than\x20declaring\x20a\x20calendar-relative\x20window.'}];}function signerRefundChecks(a){const b=[],c=a['allocator']['rows']??[],d=c['find'](j=>j['recipient']==='signer'),e=a['allocator']['recipient']==='signer';if(!d&&!e)return b;const f=templateText(a),g=/refund|chargeback|repay|退款|(?:pay(?:ment|out)?|release|send|transfer|settle)\w*[^.\n]{0,40}to the (?:buyer|order|customer)/i['test'](f);if(!g)return b;const h=d?'allocator\x20row\x20'+d['track']+'/'+(d['recipient_key']??'?'):'allocator.recipient=\x27signer\x27';return b['push']({'rule_id':'R-SIGNER-02','severity':'high','title':'Refund\x20leg\x20pays\x20Recipient::Signer\x20—\x20the\x20keeper,\x20not\x20the\x20buyer\x20('+h+')','detail':'`Recipient::Signer`\x20resolves\x20to\x20`tx_context::sender(ctx)`\x20(allocation.move:531-533),\x20i.e.\x20whoever\x20signed\x20the\x20transaction\x20that\x20triggered\x20'+'`alloc`.\x20Time-driven\x20refunds\x20are\x20keeper-triggered\x20by\x20construction,\x20so\x20this\x20leg\x20pays\x20the\x20KEEPER,\x20and\x20because\x20`alloc()`\x20records\x20no\x20'+'consumed\x20flag\x20for\x20the\x20recipient,\x20first-come-first-served.\x20Only\x20`Recipient::GuardIdentifier`\x20(resolved\x20through\x20the\x20Guard\x20submission,\x20'+'allocation.move:501-527)\x20or\x20an\x20explicit\x20`Entity`\x20is\x20safe\x20for\x20a\x20refund.','suggestion':'Replace\x20the\x20Signer\x20refund\x20row\x20with\x20a\x20`{GuardIdentifier:\x200}`\x20row\x20(the\x20submission\x20for\x20a\x20Service-created\x20Allocation\x20is\x20pinned\x20to\x20the\x20paying\x20'+'Order,\x20so\x20only\x20`order.owner`\x20can\x20receive\x20it)\x20and\x20bind\x20the\x20Guard\x20to\x20`order.owner`\x20+\x20`progress.current\x20==\x20<refund\x20node>`.'}),b;}function orderAnchorDeclarationChecks(a){const b=templateText(a),c=a['allocator']['refund_track']==='order_anchored'||/order[\s-]anchored|order anchor|refund recipient is the order|anchor row|guardidentifier\s*\(\s*0\s*\)|for_object|退款接收方为订单/i['test'](b);if(!c)return[];const d=(a['allocator']['rows']??[])['some'](g=>g['recipient']==='guard_identifier'||g['recipient']==='guard_identifier_to_order'),e=a['guards']['some'](h=>h['template_id']==='pattern.allocator_order_anchor');if(d||e)return[];const f=a['allocator']['recipient']??'?';return[{'rule_id':'R-RECIPIENT-02','severity':'high','title':'Order-anchored\x20refund\x20recipient\x20is\x20asserted\x20in\x20prose\x20but\x20declared\x20nowhere\x20machine-checkable','detail':'The\x20template\x20claims\x20an\x20order-anchored\x20escrow\x20/\x20refund\x20recipient\x20while\x20its\x20machine-readable\x20allocator\x20says\x20recipient=\x27'+f+'\x27\x20'+'with\x20no\x20`guard_identifier`\x20row\x20and\x20no\x20`pattern.allocator_order_anchor`\x20Guard\x20reference.\x20Two\x20on-chain\x20facts\x20make\x20the\x20claim\x20as\x20written\x20'+'unbuildable:\x20(1)\x20`Recipient`\x20has\x20only\x20`GuardIdentifier(u8)`\x20/\x20`Entity(address)`\x20/\x20`Signer`\x20(allocation.move:148-152)\x20—\x20there\x20is\x20NO\x20'+'`Order`\x20variant,\x20so\x20\x27the\x20refund\x20recipient\x20is\x20the\x20order\x20object\x27\x20can\x20only\x20be\x20written\x20as\x20a\x20`GuardIdentifier`\x20row;\x20(2)\x20recipients\x20that\x20are\x20'+'all\x20fixed\x20`Entity`\x20rows\x20resolve\x20without\x20the\x20passport\x20submission\x20(allocation.move:528-530)\x20and\x20the\x20Allocation\x20never\x20enters\x20the\x20Guard\x20'+'context,\x20so\x20the\x20Guard\x20has\x20no\x20order\x20to\x20bind\x20at\x20all\x20—\x20the\x20CR-01\x20drain\x20shape.\x20A\x20build\x20agent\x20reading\x20the\x20prose\x20instead\x20of\x20the\x20schema\x20will\x20'+'emit\x20an\x20Entity\x20refund\x20leg\x20to\x20the\x20merchant,\x20or\x20a\x20Signer\x20leg\x20to\x20the\x20keeper.','suggestion':'Declare\x20the\x20anchor\x20machine-checkably:\x20one\x20`{\x20recipient:\x20\x27guard_identifier\x27,\x20recipient_key:\x20\x270\x27,\x20mode:\x20\x27rate\x27,\x20value:\x200\x20}`\x20row\x20(the\x20'+'pattern.allocator_order_anchor\x20convention)\x20plus\x20`refund_track:\x20\x27order_anchored\x27`,\x20and\x20reference\x20`pattern.allocator_order_anchor`\x20in\x20the\x20'+'guard\x20set\x20with\x20the\x20`logic_equal[order.service,\x20<this\x20service>]`\x20binding\x20stated\x20in\x20its\x20purpose.'}];}const EDGE_DEPENDENCY_REGEX=/\b(?:incoming|outgoing|arb_refund)\s+edge\b|\bstop[\s-]node\b|\bedges?\b|\bpairs?\b|\bforwards?\b|one pair|two pairs/i;function topologyChecks(a){const b=[],c=templateText(a);EDGE_DEPENDENCY_REGEX['test'](c)&&b['push']({'rule_id':'R-TOPO-01','severity':'high','title':'machine_shape\x20ships\x20nodes\x20only\x20—\x20no\x20Pair/forward\x20list,\x20so\x20stop-node\x20fund-exit\x20coverage\x20is\x20unauditable','detail':'This\x20template\x27s\x20correctness\x20depends\x20on\x20Machine\x20edges\x20(its\x20own\x20notes\x20reason\x20about\x20incoming/outgoing\x20edges,\x20pairs\x20and\x20stop-node\x20'+'fund-exit\x20coverage),\x20but\x20`machine_shape`\x20carries\x20NO\x20edges:\x20an\x20edge\x20on\x20chain\x20is\x20`Node[target].pairs\x20=\x20{\x20prev_node,\x20threshold,\x20'+'forwards[]\x20}`,\x20which\x20this\x20schema\x20cannot\x20express.\x20The\x20scanner\x20therefore\x20has\x20to\x20invent\x20a\x20linear\x20chain,\x20and\x20the\x20mandatory\x20'+'stop-node\x20walk\x20(R-M5-03\x20/\x20R-M5-09:\x20every\x20rest\x20state\x20needs\x20a\x20defined\x20withdrawal\x20AND\x20refund\x20rule,\x20satisfiable\x20in\x20both\x20directions)\x20'+'cannot\x20be\x20performed\x20—\x20an\x20uncovered\x20stop\x20node\x20strands\x20escrow\x20permanently\x20once\x20Machine\x20+\x20Allocator\x20are\x20frozen\x20at\x20publish.','suggestion':'Either\x20state\x20the\x20edges\x20explicitly\x20in\x20build_notes\x20as\x20`prev\x20─forward(op,w)→\x20next`\x20with\x20the\x20Pair\x20grouping,\x20or\x20declare\x20a\x20machine-readable\x20'+'edge\x20list\x20so\x20the\x20scanner\x20can\x20audit\x20stop-node\x20coverage\x20and\x20prev_node\x20uniqueness\x20instead\x20of\x20guessing.'});const d=a['machine_shape']['map'](j=>j['name']);if(d['length']===0x0)return b;const e=d['filter'](j=>BRANCH_STATE_REGEX['test'](j));if(e['length']===0x0)return b;const f=d[0x0],g=!BRANCH_STATE_REGEX['test'](d[0x1]),h=(g?0x1:0x0)+e['length'];if(h<=0x1)return b;return b['push']({'rule_id':'R-TOPO-02','severity':'medium','title':'Node\x20\x27'+f+'\x27\x20has\x20'+h+'\x20outgoing\x20rails\x20—\x20declare\x20the\x20Pair\x20grouping\x20(E_DUPLICATE_NODE_PREV\x20is\x20per\x20TARGET\x20node,\x20not\x20per\x20source)','detail':'From\x20\x27'+f+'\x27\x20the\x20declared\x20node\x20set\x20requires\x20'+h+'\x20distinct\x20rails\x20'+('('+(g?'the\x20linear\x20rail\x20to\x20\x27'+d[0x1]+'\x27,\x20':''))+(e['map'](j=>'the\x20branch\x20to\x20\x27'+j+'\x27')['join'](',\x20')+').\x20These\x20are\x20LEGAL\x20and\x20must\x20NOT\x20be\x20merged:\x20an\x20edge\x20A→B\x20is\x20')+'stored\x20in\x20`Node[B].pairs\x20=\x20{\x20prev_node:\x20A,\x20threshold,\x20forwards[]\x20}`,\x20and\x20the\x20chain\x20rejects\x20only\x20the\x20SAME\x20`prev_node`\x20appearing\x20'+'twice\x20inside\x20ONE\x20node\x27s\x20pairs\x20(`assert!(!vector::contains(&res,\x20&pair.prev_node),\x20E_DUPLICATE_NODE_PREV)`,\x20machine.move:171\x20and\x20'+'machine.move:440).\x20Rails\x20into\x20different\x20targets\x20occupy\x20different\x20nodes,\x20so\x20each\x20`prev_node`\x20still\x20appears\x20exactly\x20once\x20per\x20node.\x20'+'THE\x20HAZARD\x20IS\x20THE\x20MIRROR\x20IMAGE:\x20two\x20forwards\x20from\x20the\x20SAME\x20source\x20into\x20the\x20SAME\x20target\x20must\x20be\x20ONE\x20Pair\x20carrying\x20both\x20forwards\x20—\x20'+'a\x20builder\x20that\x20emits\x20one\x20Pair\x20per\x20forward\x20duplicates\x20`prev_node`\x20and\x20ABORTS\x20at\x20publish,\x20after\x20Machine\x20+\x20Guard\x20are\x20frozen.\x20Note\x20'+'also\x20that\x20one\x20forward\x20cannot\x20satisfy\x20two\x20operators:\x20each\x20forward\x20contributes\x20its\x20weight\x20at\x20most\x20once\x20(locked\x20by\x20its\x20first\x20operator,\x20'+'progress.move:425-431),\x20so\x20a\x20dual-confirmation\x20step\x20needs\x20`threshold\x20=\x202`\x20with\x20two\x20DISTINCT\x20forwards.\x20A\x20node\x20list\x20cannot\x20distinguish\x20'+'these\x20cases,\x20which\x20is\x20why\x20this\x20is\x20advisory\x20and\x20not\x20a\x20proven\x20defect.','suggestion':'Do\x20NOT\x20merge\x20the\x20rails.\x20Instead\x20declare\x20the\x20grouping\x20explicitly\x20in\x20build_notes\x20as\x20'+'`prev\x20─forward(op,w)→\x20next`,\x20marking\x20which\x20forwards\x20SHARE\x20one\x20target\x20and\x20therefore\x20belong\x20in\x20ONE\x20Pair,\x20and\x20state\x20each\x20Pair\x27s\x20'+'`threshold`\x20(2\x20with\x20two\x20distinct\x20forwards\x20when\x20two\x20different\x20operators\x20must\x20act).\x20This\x20also\x20lets\x20the\x20scanner\x20audit\x20prev_node\x20'+'uniqueness\x20instead\x20of\x20guessing.\x20Related:\x20R-TOPO-01\x20(high)\x20is\x20the\x20finding\x20that\x20records\x20that\x20edges\x20are\x20unauditable\x20at\x20all.'}),b;}function compoundPayoutChecks(a){const b=templateText(a),c=a['allocator']['rows']??[],d=a['allocator']['refund_track']!==undefined||c['some'](f=>f['track']==='refund')||/refund|退款/i['test'](a['allocator']['description']);if(!d)return[];const e=a['guards']['some'](f=>f['host']==='arbitration')||a['trust_mechanisms']['some'](f=>/^R2\b/['test'](f))||/compensation[_ ]fund/i['test'](b);if(!e)return[];return[{'rule_id':'R-COMPOUND-01','severity':'low','title':'Dual\x20buyer-remedy\x20rails\x20(escrow\x20refund\x20+\x20compensation\x20fund)\x20—\x20the\x20arbitrator\x20nets\x20the\x20award','detail':'This\x20template\x20carries\x20BOTH\x20buyer-remedy\x20channels\x20by\x20design:\x20a\x20refund\x20Allocator\x20paying\x20out\x20of\x20the\x20order\x20escrow\x20AND\x20a\x20bound\x20'+'Arbitration\x20paying\x20out\x20of\x20the\x20Service\x27s\x20compensation\x20fund.\x20The\x20two\x20channels\x20are\x20independent\x20on-chain\x20and\x20the\x20platform\x20does\x20not\x20'+'hard-block\x20a\x20double\x20payout\x20at\x20the\x20protocol\x20level\x20—\x20that\x20is\x20an\x20intentional\x20commercial\x20game,\x20not\x20a\x20defect:\x20the\x20merchant\x20chose\x20the\x20'+'arbitrator,\x20and\x20the\x20arbitrator\x20rules\x20on\x20the\x20full\x20fund\x20picture.\x20Every\x20query\x20of\x20an\x20Arb\x20case\x20auto-attaches\x20the\x20order-side\x20fund\x20facts\x20'+'(_order_fund_facts:\x20amount,\x20escrow\x20balance,\x20withdraw\x20history,\x20claimed_by,\x20workflow\x20node),\x20and\x20every\x20case\x20operation\x20result\x20carries\x20'+'order_fund_facts,\x20so\x20a\x20refund-then-claim\x20ordering\x20is\x20visible\x20at\x20ruling\x20time\x20and\x20the\x20award\x20is\x20expected\x20to\x20net\x20out\x20the\x20already-refunded\x20principal.','suggestion':'No\x20structural\x20change\x20required.\x20Keep\x20the\x20operational\x20rule:\x20arbitrators\x20read\x20order_fund_facts\x20before\x20finalizing\x20the\x20indemnity\x20and\x20net\x20'+'any\x20positive\x20escrow_deficit\x20/\x20withdraw_history\x20payouts\x20against\x20the\x20award.\x20If\x20a\x20template\x20intends\x20a\x20non-monetary\x20remedy\x20instead,\x20say\x20so\x20'+'explicitly\x20in\x20the\x20arbitration\x20proposition\x20wording.'}];}function surplusTrackChecks(a){const b=a['allocator']['rows']??[],c=[],d=b['filter'](h=>h['track']==='refund'&&h['mode']==='surplus'),e=b['filter'](h=>h['track']==='settlement'&&h['mode']==='amount');d['length']>0x0&&e['length']>0x0&&c['push']({'rule_id':'R-SURPLUS-01','severity':'critical','title':'Refund-track\x20Surplus\x20sweeps\x20UNPAID\x20settlement\x20Amounts\x20out\x20of\x20the\x20shared\x20pool','detail':'An\x20order\x20funds\x20ONE\x20pool\x20—\x20`track`\x20is\x20a\x20build-time\x20grouping\x20the\x20chain\x20never\x20sees.\x20The\x20refund\x20row\x20'+'runs\x20Surplus\x20mode,\x20which\x20pays\x20the\x20ENTIRE\x20remaining\x20balance\x20(allocation.move:494-505;\x20template\x20rows\x20cannot\x20set\x20'+'`Allocator.max`,\x20so\x20the\x20sweep\x20is\x20uncapped),\x20while\x20the\x20settlement\x20track\x20still\x20carries\x20fixed\x20Amount\x20obligations\x20'+('('+e['map'](h=>h['recipient_key']??h['recipient'])['join'](',\x20')+').\x20Track\x20guards\x20are\x20independent\x20—\x20a\x20')+'time-locked\x20deposit\x20release\x20does\x20not\x20wait\x20for\x20month-gated\x20rent\x20—\x20so\x20when\x20the\x20refund\x20fires\x20first,\x20the\x20sweep\x20hands\x20'+'the\x20unpaid\x20Amounts\x20to\x20the\x20refund\x20recipient.\x20VERIFIED\x20LIVE\x20on\x20ziroom\x20mainnet\x20T-05:\x20the\x20deposit_back\x20Surplus\x20paid\x20'+'the\x20tenant\x20the\x20deposit\x20PLUS\x20the\x20unreleased\x20rent\x20(585/525\x20in\x20full);\x20the\x20landlord\x20received\x200.','suggestion':'Size\x20the\x20refund\x20leg\x20explicitly:\x20an\x20Amount\x20row\x20pinned\x20to\x20the\x20deposit\x20value\x20(value/value_from),\x20so\x20the\x20payout\x20can\x20'+'never\x20exceed\x20its\x20own\x20scope\x20—\x20or\x20split\x20the\x20two\x20fund\x20scopes\x20into\x20separate\x20Allocation\x20objects\x20so\x20a\x20sweep\x20can\x20only\x20'+'reach\x20its\x20own\x20pool.\x20If\x20an\x20uncapped\x20sweep\x20is\x20truly\x20intended,\x20gate\x20it\x20on\x20a\x20node\x20that\x20provably\x20follows\x20the\x20FINAL\x20'+'settlement\x20release,\x20and\x20state\x20in\x20the\x20template\x20that\x20any\x20obligation\x20unpaid\x20by\x20then\x20is\x20forfeit.'});const f=b['filter'](h=>h['track']==='settlement'&&h['mode']==='surplus'),g=b['filter'](h=>h['track']==='refund'&&h['mode']==='amount');return f['length']>0x0&&g['length']>0x0&&c['push']({'rule_id':'R-SURPLUS-02','severity':'high','title':'Settlement-track\x20Surplus\x20can\x20drain\x20the\x20pool\x20ahead\x20of\x20a\x20fixed-Amount\x20refund','detail':'The\x20settlement\x20sweep\x20(Surplus,\x20uncapped\x20—\x20allocation.move:494-505)\x20pays\x20the\x20merchant\x20the\x20entire\x20remainder\x20while\x20'+('the\x20refund\x20track\x20still\x20owes\x20fixed\x20Amounts\x20('+g['map'](h=>h['recipient_key']??h['recipient'])['join'](',\x20')+').\x20')+'If\x20the\x20settlement\x20guard\x20fires\x20while\x20a\x20refund\x20obligation\x20is\x20still\x20open\x20(the\x20tracks\x20are\x20gated\x20independently),\x20the\x20'+'pool\x20is\x20empty\x20when\x20the\x20refund\x20fires\x20and\x20alloc()\x20aborts\x20on\x20insufficient\x20balance\x20(allocation.move:390)\x20—\x20the\x20buyer\x20'+'remedy\x20is\x20bricked\x20and\x20the\x20merchant\x20keeps\x20money\x20the\x20template\x20declared\x20refundable.','suggestion':'Make\x20the\x20two\x20tracks\x20mutually\x20exclusive\x20by\x20construction\x20(refund\x20fires\x20only\x20from\x20cancel\x20nodes\x20the\x20settlement\x20'+'guard\x20can\x20never\x20reach,\x20and\x20vice\x20versa),\x20or\x20size\x20the\x20refund\x20as\x20a\x20Rate\x20so\x20it\x20degrades\x20to\x20a\x20share\x20instead\x20of\x20'+'aborting.\x20NOTE:\x20there\x20is\x20no\x20on-chain\x20holdback\x20(FACT-ALLOC-03)\x20—\x20do\x20NOT\x20try\x20to\x20\x27reserve\x27\x20the\x20refund\x20Amount\x20'+'via\x20a\x20fix\x20value;\x20split\x20the\x20two\x20fund\x20scopes\x20into\x20separate\x20Allocation\x20objects\x20if\x20isolation\x20is\x20required.'}),c;}const BRANCH_STATE_REGEX=/(cancel|return|withdraw|exit|expired)/i;function amountDeadlockChecks(a){const b=a['allocator']['rows']??[],c=b['filter'](f=>f['track']==='settlement');if(c['length']===0x0||!c['every'](f=>f['mode']==='amount'))return[];const d=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](f=>f['template_id']+'\x20'+f['purpose'])]['join']('\x20\x0a\x20'),e=Object['keys'](a['fee_params'])['some'](f=>MIN_PRICE_KEY_REGEX['test'](f))||FLOOR_TEXT_REGEX['test'](d);if(e)return[];return[{'rule_id':'R-DEADLOCK-01','severity':'medium','title':'Settlement\x20track\x20is\x20ALL\x20fixed\x20Amount\x20—\x20an\x20under-funded\x20pool\x20deadlocks\x20permanently','detail':'Every\x20settlement\x20row\x20is\x20mode\x20\x27amount\x27\x20('+c['length']+'\x20row(s));\x20each\x20asserts\x20balance\x20>=\x20fix\x20at\x20release\x20'+'(allocation.move:390).\x20When\x20the\x20pool\x20is\x20smaller\x20than\x20the\x20pinned\x20leg\x20—\x20a\x20discount\x20code,\x20a\x20low-price\x20SKU,\x20a\x20'+'partially-funded\x20order\x20—\x20the\x20call\x20aborts\x20and\x20NO\x20later\x20call\x20can\x20settle\x20a\x20smaller\x20amount:\x20the\x20merchant\x27s\x20payout\x20'+'path\x20is\x20bricked\x20for\x20that\x20order\x20(ziroom\x20CR-02:\x20fixed\x20Amount\x20legs\x20+\x20a\x20cheap\x20SKU\x20=\x20permanent\x20settlement\x20abort).\x20'+'Rate\x20and\x20Surplus\x20legs\x20degrade\x20to\x20whatever\x20the\x20pool\x20actually\x20holds;\x20Amount\x20legs\x20cannot.','suggestion':'Carry\x20at\x20least\x20one\x20Rate/Surplus\x20leg\x20as\x20the\x20degradation\x20path\x20(e.g.\x20the\x20merchant\x20remainder\x20as\x20Rate),\x20or\x20enforce\x20a\x20'+'build-time\x20price\x20floor\x20proving\x20order_total\x20>=\x20the\x20largest\x20fixed\x20leg\x20—\x20and\x20state\x20that\x20floor\x20in\x20fee_params\x20so\x20the\x20'+'builder\x20cannot\x20silently\x20undercut\x20it.'}];}function cancelCoverageChecks(a){const b=a['allocator']['rows']??[];if(b['some'](d=>d['track']==='refund'))return[];if(a['allocator']['refund_track']!==undefined)return[];const c=a['machine_shape']['find'](d=>BRANCH_STATE_REGEX['test'](d['name']));if(!c)return[];return[{'rule_id':'R-CANCEL-01','severity':'high','title':'Machine\x20models\x20\x27'+c['name']+'\x27\x20but\x20the\x20allocator\x20has\x20NO\x20refund-track\x20rows\x20—\x20money\x20locks\x20on\x20that\x20path','detail':'The\x20machine\x20shape\x20carries\x20a\x20cancel/return/exit\x20state,\x20yet\x20no\x20allocator\x20row\x20pays\x20on\x20the\x20refund\x20track.\x20Text-level\x20'+'claims\x20(guard\x20purposes,\x20allocator\x20description)\x20may\x20still\x20say\x20\x27refund\x27,\x20but\x20on\x20chain\x20only\x20rows\x20move\x20money:\x20an\x20'+'order\x20that\x20reaches\x20this\x20state\x20keeps\x20its\x20escrow\x20with\x20no\x20rail\x20out\x20(ofn\x20#P-02:\x20the\x20subscription\x20template\x27s\x20refund\x20'+'rails\x20missed\x20closed_cancel\x20and\x200.5\x20WOW\x20locked\x20permanently;\x20verified\x20live).','suggestion':'Add\x20refund-track\x20rows\x20covering\x20EVERY\x20cancel-ish\x20terminal\x20(order-anchored\x20GuardIdentifier(0)\x20recipient,\x20'+'Rate-sized\x20with\x20the\x20group\x20summing\x2010000),\x20or\x20remove\x20the\x20state\x20from\x20the\x20machine\x20so\x20orders\x20can\x20never\x20enter\x20it.'}];}function redundGuardObjectMismatchChecks(a){const b=a['allocator']['rows']??[],c=b['filter'](g=>g['track']==='refund'&&g['recipient']==='guard_identifier');if(c['length']===0x0)return[];const d=a['guards']['some'](h=>/arb|ruling|arbitration/i['test'](h['template_id'])||/arb|ruling|arbitration/i['test'](h['purpose']));if(!d)return[];const e=templateText(a),f=/two[- ]slot|slot\s*0.*order|slot\s*1.*arb|arb\.order.*==|for_object.*binding/i['test'](e);if(f)return[{'rule_id':'REDUND-GUARD-OBJECT-MISMATCH','severity':'low','title':'Arb-refund\x20guard\x20uses\x20two-slot\x20design\x20(Order\x20+\x20Arb)\x20—\x20self-certifying\x20pair','detail':'The\x20template\x20carries\x20a\x20refund\x20allocator\x20row\x20with\x20a\x20GuardIdentifier\x20recipient\x20AND\x20an\x20arbitration-ruling\x20guard.\x20'+'The\x20two-slot\x20design\x20(slot\x200\x20=\x20Order\x20for\x20the\x20allocator\x20recipient,\x20slot\x201\x20=\x20Arb\x20for\x20the\x20ruling\x20state)\x20is\x20the\x20'+'correct\x20resolution\x20of\x20the\x20F-02\x20slot\x20conflict:\x20the\x20allocator\x20reads\x20slot\x200\x20(payment_info.for_object\x20binding),\x20'+'the\x20forward\x20reads\x20slot\x201\x20(arb.indemnity\x20state),\x20and\x20the\x20binding\x20assertion\x20query(\x22arb.order\x22,\x20slot1)\x20==\x20slot0\x20'+'makes\x20the\x20pair\x20self-certifying\x20against\x20redirect\x20attacks.','suggestion':'Verify\x20the\x20guard\x20is\x20tpl_forward_arb_ruling_won\x20(two-slot\x20form)\x20or\x20an\x20equivalent\x20custom\x20guard\x20with\x20the\x20same\x20'+'slot\x20layout\x20and\x20binding\x20assertion.\x20Single-slot\x20arb-refund\x20guards\x20are\x20unreachable\x20(F-02).'}];return[{'rule_id':'REDUND-GUARD-OBJECT-MISMATCH','severity':'high','title':'Arb-refund\x20guard\x20may\x20use\x20a\x20SINGLE\x20slot\x20—\x20unreachable\x20rail\x20(F-02)','detail':'The\x20template\x20carries\x20a\x20refund\x20allocator\x20row\x20with\x20a\x20GuardIdentifier\x20recipient\x20AND\x20an\x20arbitration-ruling\x20guard,\x20'+'but\x20the\x20template\x20text\x20does\x20not\x20mention\x20the\x20two-slot\x20design.\x20A\x20single-slot\x20guard\x20cannot\x20satisfy\x20both\x20consumers:\x20'+'the\x20forward\x20needs\x20the\x20Arb\x20object\x20(to\x20read\x20arb.indemnity),\x20while\x20the\x20allocator\x20recipient\x20GuardIdentifier(0)\x20needs\x20'+'the\x20Order\x20object\x20(payment_info.for_object\x20binding).\x20F-02\x20verified\x20live:\x20Order\x20address\x20→\x20forward\x20aborts;\x20Arb\x20address\x20'+'→\x20allocation\x20aborts\x2015\x20(ERECIPIENT_NOT_FOR_OBJECT).\x20The\x20escrow\x20strands\x20permanently\x20with\x20no\x20on-chain\x20exit.','suggestion':'Use\x20tpl_forward_arb_ruling_won\x20(two-slot\x20form:\x20slot\x200\x20=\x20Order,\x20slot\x201\x20=\x20Arb,\x20with\x20arb.order\x20==\x20order\x20binding),\x20'+'or\x20document\x20the\x20two-slot\x20design\x20explicitly\x20in\x20the\x20template\x20build_notes.\x20A\x20single-slot\x20arb-refund\x20guard\x20is\x20'+'unreachable\x20by\x20construction\x20(F-02).'}];}function zeroAmountGuardChecks(a){const b=templateText(a),c=/zero[- ]amount|0[ -]?amount|free[^a-z]|price\s*=\s*0|amount\s*>\s*0|min_booking_amount/i['test'](b)||/no[- ]charge|gratis|complimentary/i['test'](b);if(c)return[];const d=a['guards']['some'](e=>e['host']==='machine'&&(/claimed_by|allocation|payment\s|alloc\b/i['test'](e['template_id'])||/claimed_by|allocation|payment\s|alloc\b/i['test'](e['purpose'])));if(!d)return[];return[{'rule_id':'D7-ZERO-AMOUNT-GUARD','severity':'medium','title':'Machine\x20progress\x20guards\x20may\x20depend\x20on\x20allocator\x20events\x20—\x20zero-amount\x20orders\x20deadlock','detail':'The\x20protocol\x20does\x20NOT\x20create\x20an\x20Allocation\x20for\x20a\x20zero-amount\x20order\x20(amount\x20>\x200\x20is\x20required).\x20'+'A\x20zero-amount\x20order\x20therefore\x20has\x20NO\x20claimed_by,\x20NO\x20payment\x20history,\x20and\x20NO\x20allocation\x20balance.\x20'+'This\x20template\x20carries\x20machine\x20guards\x20that\x20reference\x20allocator-dependent\x20state\x20(claimed_by\x20/\x20allocation\x20/\x20payment),\x20'+'but\x20the\x20template\x20does\x20NOT\x20explicitly\x20exclude\x20zero-amount\x20items.\x20A\x20zero-amount\x20order\x20can\x20never\x20satisfy\x20such\x20a\x20guard\x20'+'and\x20deadlocks\x20at\x20the\x20node\x20with\x20no\x20exit.','suggestion':'Either\x20(a)\x20exclude\x20zero-amount\x20items\x20explicitly\x20(e.g.\x20min_booking_amount,\x20amount\x20>\x200\x20in\x20build_notes),\x20or\x20'+'(b)\x20redesign\x20progress\x20guards\x20to\x20use\x20order-native\x20signals\x20(order.time,\x20signer,\x20progress.current,\x20Repository\x20data)\x20'+'instead\x20of\x20allocator-derived\x20state,\x20so\x20zero-amount\x20orders\x20can\x20still\x20advance.'}];}function serialClaimWindowChecks(a){const b=a['machine_shape']['some'](h=>/claim/i['test'](h['name']))||a['guards']['some'](h=>/claim/i['test'](h['purpose']));if(!b)return[];const c=a['allocator']['rows']??[],d=c['some'](h=>h['track']==='settlement'&&(h['mode']==='surplus'||h['mode']==='rate'&&h['value']===0x2710));if(!d)return[];const e=templateText(a),f=a['machine_shape']['some'](h=>/claim_window/i['test'](h['name'])),g=/serial claim[- ]window|claim_window.*serial|serial[- ]claim|claims? (is|are|always) adjudicated while the pool is intact|between checkout and payout|before (any )?release/i['test'](e);if(f&&g)return[{'rule_id':'D2-SERIAL-CLAIM-WINDOW','severity':'low','title':'Serial\x20claim\x20window\x20gates\x20the\x20full-drain\x20release\x20(ABNB2-validated\x20design)','detail':'The\x20template\x20carries\x20claim\x20machinery\x20AND\x20a\x20full-drain\x20settlement\x20group\x20(Rate\x2010000\x20/\x20Surplus),\x20'+'and\x20resolves\x20the\x20race\x20with\x20a\x20serial\x20claim_window\x20node\x20between\x20delivery\x20confirmation\x20and\x20payout:\x20'+'the\x20release\x20can\x20only\x20fire\x20after\x20the\x20window\x20closed\x20with\x20no\x20upheld\x20claim,\x20so\x20the\x20pool\x20is\x20intact\x20'+'whenever\x20money\x20moves.','suggestion':'Verify\x20the\x20release\x20guard\x20anchors\x20on\x20progress.current_time\x20of\x20the\x20claim_window\x20entry\x20'+'(witness-derived),\x20not\x20on\x20order.time\x20—\x20a\x20booking-time\x20delay\x20has\x20always\x20expired\x20before\x20'+'checkout\x20and\x20gives\x20no\x20post-delivery\x20protection.'}];return[{'rule_id':'D2-SERIAL-CLAIM-WINDOW','severity':'high','title':'Full-drain\x20release\x20can\x20fire\x20while\x20a\x20claim\x20is\x20still\x20openable\x20—\x20FCFS\x20race\x20on\x20one\x20pool\x20(FACT-ALLOC-03)','detail':'The\x20template\x20carries\x20claim\x20machinery\x20AND\x20a\x20full-drain\x20settlement\x20group\x20(Rate\x2010000\x20or\x20Surplus),\x20'+'but\x20no\x20serial\x20claim_window\x20node\x20orders\x20them:\x20the\x20payout\x20and\x20a\x20later\x20claim\x20race\x20first-come-first-served\x20'+'on\x20the\x20SAME\x20pool,\x20and\x20the\x20chain\x20has\x20no\x20holdback\x20primitive\x20(fix\x20is\x20the\x20PAID\x20sum\x20of\x20Amount\x20legs,\x20'+'allocation.move:399,540).\x20Once\x20the\x20release\x20fires,\x20a\x20claim\x20can\x20pay\x20nothing\x20from\x20the\x20pool.\x20'+'Airbnb\x20mainnet\x20audit\x202026-10-07:\x20the\x20parallel\x20payout/claim\x20design\x20paid\x20the\x20host\x20in\x20full\x20and\x20left\x20'+'the\x20claim\x20window\x20with\x20an\x20empty\x20pool.','suggestion':'Insert\x20a\x20SERIAL\x20claim_window\x20node\x20between\x20delivery\x20confirmation\x20and\x20payout\x20(ABNB2-validated):\x20'+'checkout\x20→\x20claim_window\x20→\x20payout,\x20with\x20exactly\x20two\x20exits\x20—\x20FileClaim\x20(inside\x20the\x20window,\x20'+'Clock\x20<=\x20current_time(claim_window)\x20+\x20claim_window_days)\x20and\x20ReleaseNoClaim\x20(window\x20elapsed).\x20'+'Gate\x20the\x20release\x20allocator\x20on\x20the\x20post-window\x20node,\x20and\x20give\x20a\x20denied\x20claim\x20its\x20own\x20release\x20'+'forward\x20so\x20no\x20stop\x20node\x20holds\x20funds.'}];}function syntheticMachine(a){const b=a['machine_shape']['map'](e=>({'name':e['name'],'description':e['role'],'operator':e['operator']})),c=[],d=(e,f)=>[{'name':e,'weight':0x1,'named_operator':f==='order_payer'?'':'order_holder'}];b['length']>0x0&&c['push']({'prev_node':'','next_node':b[0x0]['name'],'threshold':0x1,'forwards':d('enter_'+b[0x0]['name'],b[0x0]['operator'])});for(let e=0x0;e<b['length']-0x1;e++){const f=b[e]['name'],g=b[e+0x1];if(BRANCH_STATE_REGEX['test'](g['name']))continue;c['push']({'prev_node':f,'next_node':g['name'],'threshold':0x1,'forwards':d(f+'_to_'+g['name'],g['operator'])});}if(b['length']>0x0)for(const h of b){BRANCH_STATE_REGEX['test'](h['name'])&&c['push']({'prev_node':b[0x0]['name'],'next_node':h['name'],'threshold':0x1,'forwards':d('to_'+h['name'],h['operator'])});}return{'nodes':b,'pairs':c};}function singleNodeGraph(a){return{'network':ENTRYPOINT['Testnet'],'seed':a['id'],'builtAt':Date['now'](),'nodes':new Map([[a['id'],a]]),'edges':[],'out':new Map(),'inc':new Map(),'gaps':[],'truncations':[],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}function analyzerFindings(a){const b=makeProposalNode('machine',syntheticMachine(a)),c=singleNodeGraph(b),d=buildViewport(c,c['seed'],'neutral');return runNodeAnalyzers(d,[machineRuleNodeAnalyzer,allocationRuleNodeAnalyzer]);}const SEVERITY_ORDER={'low':0x0,'medium':0x1,'high':0x2,'critical':0x3};export function scanTemplate(a){const b=[...staticChecks(a),...guardRefChecks(a),...fundAnchorChecks(a),...periodicReleaseChecks(a),...timeWindowAnchorChecks(a),...signerRefundChecks(a),...orderAnchorDeclarationChecks(a),...topologyChecks(a),...compoundPayoutChecks(a),...surplusTrackChecks(a),...amountDeadlockChecks(a),...cancelCoverageChecks(a),...redundGuardObjectMismatchChecks(a),...zeroAmountGuardChecks(a),...serialClaimWindowChecks(a)];for(const e of analyzerFindings(a)){const g=e['severity']==='info'?'low':e['severity'];b['push']({'rule_id':e['ruleId'],'severity':g,'title':e['title'],'detail':e['detail'],'suggestion':e['suggestion']});}b['sort']((h,j)=>SEVERITY_ORDER[j['severity']]-SEVERITY_ORDER[h['severity']]);const c=b['length']>0x0?b[0x0]['severity']:'low',d=b['filter'](h=>h['severity']==='critical')['map'](h=>''+(h['rule_id']?h['rule_id']+':\x20':'')+h['title']);return{'template_id':a['id'],'risk_level':c,'passed':d['length']===0x0,'findings':b,'red_flags':d};}
|
|
1
|
+
import{ENTRYPOINT}from'@wowok/wowok';import{buildViewport,runNodeAnalyzers}from'../graph/onchain/index.js';import{makeProposalNode}from'../graph/onchain/proposal-graph.js';import{machineRuleNodeAnalyzer,allocationRuleNodeAnalyzer}from'./rule-node-analyzers.js';import{GUARD_TEMPLATES}from'./guard-templates.js';import{GUARD_DESIGN_PATTERNS}from'./guard-design-patterns.js';import{unannotatedBuyerActionNodes}from'./scenario-modes.js';import{DIRECT_SALES_INVARIANT,ENTITY_RECIPIENT_RULE_ID}from'./entity-recipient-guard.js';const PLATFORM_TAKE_KEY=/^(?:platform_(?:share|commission|take)_bps|platform_fee_rate_bps|commission_rate_bps|(?:base_)?commission_rate_bps|offsite_ads_rate_bps|service_fee_rate_bps|payment_fee_bps)$/,MERCHANT_OWN_PRICE_KEY=/^(?:merchant_service_fee_bps|contract_fee_(?:small|large)_usd|contract_fee_tier_boundary_usd|digital_product_fee_(?:bps|min_usd|max_usd)|arbitration_fee.*|escrow_.*|min_.*|max_.*)$/,MERCHANT_SHARE_KEY=/^(?:host|property|partner|institution|landlord|freelancer|creator|seller|instructor)_rate_bps$/;function directSalesEconomyChecks(a){const b=[],c=a['fee_params'],d=Object['keys'](c)['filter'](x=>PLATFORM_TAKE_KEY['test'](x)&&typeof c[x]==='number'&&c[x]!==0x0);d['length']>0x0&&b['push']({'rule_id':'R-ECON-01','severity':'critical','title':'Template\x20mandates\x20a\x20platform\x20commission\x20('+d['map'](x=>x+'='+c[x])['join'](',\x20')+')','detail':'WoWok\x20is\x20DIRECT\x20SALES:\x20the\x20protocol\x20never\x20extracts\x20and\x20a\x20merchant\x20pays\x20only\x20gas,\x20so\x20the\x20merchant-side\x20share\x20must\x20default\x20to\x20the\x20whole\x20sale.\x20A\x20non-zero\x20platform\x20take\x20is\x20(a)\x20an\x20extraction\x20the\x20platform\x20has\x20no\x20right\x20to,\x20and\x20(b)\x20an\x20UNALLOCATED\x20liability\x20—\x20no\x20template\x20declares\x20a\x20platform\x20address,\x20so\x20at\x20build\x20time\x20it\x20resolves\x20to\x20the\x20deploying\x20merchant\x20itself\x20(blank\x20→\x20Account.Instance(),\x20ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20to\x20the\x20keeper\x20(Recipient::Signer\x20→\x20tx_context::sender,\x20allocation.move:531-533),\x20or\x20back\x20to\x20the\x20buyer\x20(Recipient::GuardIdentifier,\x20allocation.move:501-527).\x20None\x20of\x20those\x20is\x20revenue.','suggestion':'Set\x20'+d['join'](',\x20')+'\x20to\x200\x20and\x20give\x20the\x20merchant\x20the\x20whole\x20sale\x20(single\x20Rate\x2010000\x20leg).\x20If\x20the\x20merchant\x20IS\x20the\x20aggregator\x20and\x20genuinely\x20charges\x20a\x20fee,\x20declare\x20it\x20via\x20merchant_service_fee_bps\x20with\x20an\x20EXPLICIT\x20non-empty\x20recipient\x20Entity.'});const e=a['allocator']['description'],f=/(?:commission|take|platform|remainder|share)\s*(?:=|:)\s*order\s*total\s*-\s*(?:segment|sum)/i['test'](e),g=(a['allocator']['rows']??[])['some'](x=>x['mode']==='surplus')||a['allocator']['mode']==='surplus',h=g&&/(?:platform|commission|fee|take)[^.;]{0,120}\bsurplus\b|\bsurplus\b[^.;]{0,120}(?:platform|commission|fee|take)/i['test'](e);f&&b['push']({'rule_id':'R-ECON-02','severity':'critical','title':'Take\x20is\x20an\x20implicit\x20remainder\x20(not\x20computable\x20before\x20ordering)','detail':'The\x20allocator\x20describes\x20the\x20platform\x20share\x20as\x20\x22order\x20total\x20-\x20segment\x20sums\x22,\x20so\x20the\x20amount\x20taken\x20depends\x20on\x20the\x20segment\x20configuration\x20rather\x20than\x20a\x20declared\x20rate.\x20A\x20buyer\x20(or\x20their\x20AI)\x20cannot\x20compute\x20the\x20take\x20BEFORE\x20ordering,\x20which\x20defeats\x20pre-order\x20evaluation\x20—\x20and\x20an\x20unbounded\x20remainder\x20off\x20a\x20transit\x20pool\x20is\x20unbounded\x20extraction.','suggestion':'Pin\x20every\x20share\x20to\x20an\x20EXPLICIT\x20Rate\x20(or\x20an\x20Amount\x20derived\x20from\x20a\x20declared\x20rate).\x20A\x20supplier\x20fee\x20belongs\x20in\x20its\x20own\x20explicitly-priced\x20segment\x20order,\x20never\x20as\x20a\x20residual\x20share.'});h&&b['push']({'rule_id':'R-ECON-02','severity':'high','title':'Fee\x20appears\x20to\x20be\x20taken\x20by\x20a\x20Surplus\x20leg','detail':'A\x20Surplus\x20sharing\x20entry\x20allocates\x20the\x20WHOLE\x20remaining\x20balance\x20(allocation.move:427\x20withdraw_all\x20semantics),\x20so\x20it\x20cannot\x20express\x20\x22take\x2015%\x22:\x20it\x20doubles\x20as\x20draining\x20the\x20pool.','suggestion':'Use\x20Rate\x20(or\x20RateGross)\x20for\x20any\x20proportional\x20share.\x20Reserve\x20Surplus\x20for\x20an\x20explicitly-bounded\x20residual\x20whose\x20recipient\x20and\x20cap\x20are\x20stated.'});const j=/\{\s*(?:who|Entity|Signer|GuardIdentifier)\s*:/['test'](e)||/recipient\s*[:=]/i['test'](e),k=/^(?:merchant_service_fee_bps|digital_product_fee_bps|logistics_rate_bps|service_fee_rate_bps)$/,l=Object['keys'](c)['some'](x=>k['test'](x)&&typeof c[x]==='number'&&c[x]!==0x0);l&&!j&&d['length']===0x0&&b['push']({'rule_id':'R-ECON-03','severity':'high','title':'Fee-bearing\x20template\x20names\x20no\x20recipient\x20slot\x20for\x20the\x20non-merchant\x20share','detail':'fee_params\x20carry\x20fee-shaped\x20keys\x20but\x20the\x20allocator\x20names\x20no\x20recipient\x20for\x20them.\x20On-chain\x20each\x20Rate\x20lands\x20in\x20ITS\x20OWN\x20recipient\x20slot;\x20an\x20unnamed\x20one\x20resolves\x20to\x20the\x20deploying\x20account\x20(ts-sdk/packages/wowok/src/w/local/index.ts:89-91),\x20to\x20the\x20keeper\x20(allocation.move:531-533),\x20or\x20back\x20to\x20the\x20buyer.\x20The\x20share\x20is\x20then\x20an\x20unallocated\x20liability\x20rather\x20than\x20revenue.','suggestion':'State\x20the\x20recipient\x20per\x20share\x20in\x20the\x20allocator\x20description\x20and\x20bind\x20it\x20to\x20an\x20explicit\x20NON-EMPTY\x20Entity\x20the\x20buyer\x20can\x20see\x20before\x20ordering.\x20Never\x20leave\x20it\x20blank.'});const m=/(?:layer-?1|service-?level|pool)[^.]*settles? the full amount|full amount to the (?:platform|organizer) pool/i['test'](e);m&&b['push']({'rule_id':'R-ECON-04','severity':'medium','title':'Escrow\x20transits\x20an\x20organizer\x20pool\x20before\x20reaching\x20the\x20merchant','detail':'The\x20full\x20order\x20amount\x20settles\x20into\x20a\x20platform/organizer\x20pool\x20first\x20and\x20is\x20then\x20redistributed.\x20That\x20contradicts\x20the\x20direct-sales\x20promise\x20(\x22money\x20moves\x20only\x20between\x20the\x20two\x20parties\x22)\x20and\x20makes\x20the\x20organizer\x20a\x20waypoint\x20on\x20every\x20payout,\x20including\x20every\x20refund.','suggestion':'Release\x20supplier\x20segments\x20directly\x20from\x20the\x20order\x27s\x20own\x20Allocation,\x20and\x20make\x20the\x20organizer\x20a\x20named\x20party\x20rather\x20than\x20a\x20transit\x20node.'});const n=Object['keys'](c)['find'](x=>/^attributed_.*_bps$/['test'](x)&&typeof c[x]==='number'),o=Object['keys'](c)['find'](x=>/^(?:base_)?commission_rate_bps$/['test'](x)&&typeof c[x]==='number');n&&o&&c[n]>c[o]&&b['push']({'rule_id':'R-ECON-05','severity':'medium','title':'Attribution-priced\x20take:\x20a\x20cheaper\x20acquisition\x20channel\x20is\x20charged\x20MORE','detail':n+'='+c[n]+'\x20exceeds\x20'+o+'='+c[o]+'.\x20Charging\x20more\x20for\x20attributed\x20orders\x20means\x20the\x20merchant\x27s\x20cheap\x20channels\x20(KOC,\x20social,\x20repeat\x20buyers)\x20are\x20penalised\x20—\x20the\x20opposite\x20of\x20what\x20direct\x20sales\x20should\x20reward.','suggestion':'Price\x20every\x20channel\x20identically.\x20Attribution\x20may\x20change\x20RANKING,\x20never\x20the\x20take.'});if(a['allocator']['mode']==='rate'){const x=Object['keys'](c)['filter'](A=>MERCHANT_SHARE_KEY['test'](A)&&typeof c[A]==='number'),y=Object['keys'](c)['filter'](A=>PLATFORM_TAKE_KEY['test'](A)&&typeof c[A]==='number'),z=[...x,...y];if(x['length']>0x0&&y['length']>0x0){const A=z['map'](D=>c[D])['filter'](D=>typeof D==='number'),B=A['reduce']((D,E)=>D+E,0x0),C=/surplus/i['test'](e);B!==0x2710&&!C&&b['push']({'rule_id':'R-ECON-06','severity':'critical','title':'Rate\x20shares\x20sum\x20to\x20'+B+',\x20not\x2010000','detail':'Declared\x20rate\x20shares\x20('+z['map']((D,E)=>D+'='+A[E])['join']('\x20+\x20')+')\x20total\x20'+B+'.\x20With\x20no\x20Surplus\x20recipient\x20the\x20remainder\x20is\x20not\x20protected:\x20the\x20chain\x20records\x20no\x20\x22already\x20triggered\x22\x20flag,\x20so\x20a\x20balance\x20left\x20behind\x20after\x20a\x20partial\x20split\x20can\x20be\x20claimed\x20REPEATEDLY\x20by\x20anyone\x20passing\x20the\x20same\x20Guard.\x20This\x20is\x20exactly\x20what\x20happens\x20when\x20a\x20platform\x20leg\x20is\x20zeroed\x20without\x20recomputing\x20the\x20merchant\x20leg.','suggestion':'Make\x20the\x20shares\x20sum\x20to\x20exactly\x2010000,\x20or\x20declare\x20an\x20explicit\x20Surplus\x20recipient\x20for\x20the\x20residual.'});}}const p=(a['allocator']['rows']??[])['map']((D,E)=>({'r':D,'i':E})),q=p['filter'](({r:D})=>D['recipient']==='entity'&&!(D['recipient_key']??'')['trim']());q['length']>0x0&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'critical','title':'Allocator\x20row(s)\x20'+q['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20name\x20no\x20Entity\x20recipient\x20—\x20the\x20share\x20silently\x20pays\x20the\x20deploying\x20merchant','detail':q['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20declare\x20recipient=\x27entity\x27\x20with\x20no\x20recipient_key,\x20which\x20builds\x20as\x20'+'{\x20who:\x20{\x20Entity:\x20{\x20name_or_address:\x20\x22\x22\x20}\x20}\x20}.\x20That\x20is\x20NOT\x20a\x20no-op:\x20the\x20SDK\x20resolver\x20substitutes\x20the\x20DEFAULT\x20LOCAL\x20ACCOUNT\x20before\x20the\x20'+'address\x20reaches\x20Move,\x20so\x20the\x20order\x20escrow\x20pays\x20whoever\x20ran\x20the\x20deploy\x20—\x20the\x20\x27platform\x27\x20share\x20the\x20template\x20left\x20unnamed\x20becomes\x20the\x20merchant\x27s\x20'+('own\x20take.\x20'+DIRECT_SALES_INVARIANT),'suggestion':'Give\x20the\x20row\x20an\x20explicit\x20`recipient_key`\x20naming\x20the\x20party\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address\x20the\x20buyer\x20can\x20see\x20BEFORE\x20ordering).\x20If\x20the\x20whole\x20sale\x20goes\x20'+'to\x20the\x20merchant,\x20do\x20not\x20declare\x20an\x20entity\x20row\x20at\x20all:\x20use\x20ONE\x20{\x20who:\x20{\x20GuardIdentifier:\x200\x20},\x20sharing:\x2010000,\x20mode:\x20\x22Rate\x22\x20}\x20leg.\x20The\x20scalar\x20'+'`allocator.recipient:\x20\x22entity\x22`\x20form\x20is\x20auditable\x20too:\x20it\x20must\x20carry\x20a\x20`recipient_key`\x20(or\x20a\x20`rows[]`\x20array)\x20when\x20no\x20rows\x20narrow\x20it.'});!a['allocator']['rows']&&a['allocator']['recipient']==='entity'&&!(a['allocator']['recipient_key']??'')['trim']()&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'critical','title':'Allocator\x20names\x20no\x20Entity\x20recipient\x20(scalar\x20form,\x20no\x20rows)\x20—\x20the\x20share\x20silently\x20pays\x20the\x20deploying\x20merchant','detail':'The\x20allocator\x20declares\x20scalar\x20recipient=\x27entity\x27\x20with\x20no\x20recipient_key\x20and\x20no\x20rows[],\x20which\x20builds\x20as\x20'+'{\x20who:\x20{\x20Entity:\x20{\x20name_or_address:\x20\x22\x22\x20}\x20}\x20}.\x20That\x20is\x20NOT\x20a\x20no-op:\x20the\x20SDK\x20resolver\x20substitutes\x20the\x20DEFAULT\x20LOCAL\x20ACCOUNT\x20before\x20the\x20'+'address\x20reaches\x20Move,\x20so\x20the\x20order\x20escrow\x20pays\x20whoever\x20ran\x20the\x20deploy\x20—\x20the\x20share\x20the\x20template\x20left\x20unnamed\x20becomes\x20the\x20merchant\x27s\x20'+('own\x20take.\x20'+DIRECT_SALES_INVARIANT),'suggestion':'Declare\x20the\x20destination\x20machine-checkably:\x20set\x20`recipient_key`\x20on\x20the\x20allocator\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address\x20the\x20buyer\x20can\x20see\x20BEFORE\x20ordering),\x20'+'or\x20add\x20a\x20`rows[]`\x20array\x20carrying\x20the\x20on-chain\x20`who`\x20shape.\x20If\x20the\x20whole\x20sale\x20goes\x20to\x20the\x20merchant,\x20use\x20ONE\x20'+'{\x20recipient:\x20\x27guard_identifier\x27,\x20recipient_key:\x20\x270\x27\x20}\x20row\x20instead\x20of\x20an\x20entity\x20scalar.'});const s=p['filter'](({r:D})=>D['recipient']==='entity'&&/^0x0*$/i['test']((D['recipient_key']??'')['trim']()));s['length']>0x0&&b['push']({'rule_id':ENTITY_RECIPIENT_RULE_ID,'severity':'high','title':'Allocator\x20row(s)\x20'+s['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20name\x20the\x20zero\x20address\x20as\x20Entity\x20recipient','detail':s['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20carry\x20recipient_key=\x270x0\x27\x20(or\x20an\x20all-zero\x20literal).\x20The\x20chain\x20does\x20NOT\x20reject\x20it:\x20'+'allocation.move:250-255\x20swallows\x20Recipient::Entity\x20in\x20a\x20(_)\x20catch-all\x20at\x20declaration\x20time,\x20and\x20allocation.move:451-453\x20/\x20:514\x20forward\x20the\x20raw\x20'+'address\x20straight\x20to\x20the\x20payout\x20constructor.\x20The\x20allocation\x20is\x20accepted\x20and\x20the\x20share\x20is\x20silently\x20transferred\x20to\x200x0\x20and\x20permanently\x20burned\x20—\x20'+'this\x20scan\x20is\x20the\x20only\x20defence.','suggestion':'Replace\x20the\x20zero\x20literal\x20with\x20the\x20real\x20recipient\x20address\x20(a\x20mark\x20name\x20or\x20a\x200x\x20address),\x20or\x20drop\x20the\x20row\x20if\x20the\x20share\x20is\x20not\x20owed.'});const u=D=>D['recipient']+':'+(D['recipient_key']??'')['trim']()['toLowerCase'](),v=new Set((a['allocator']['rows']??[])['filter'](D=>D['mode']==='rate')['map'](u)),w=p['filter'](({r:D})=>D['mode']==='surplus'&&v['has'](u(D)));return w['length']>0x0&&b['push']({'rule_id':'R-RECIPIENT-04','severity':'critical','title':'Surplus\x20row(s)\x20'+w['map'](({i:D})=>'#'+D)['join'](',\x20')+'\x20pay\x20a\x20recipient\x20a\x20Rate\x20leg\x20already\x20pays\x20—\x20the\x20remainder\x20swallows\x20an\x20undeclared\x20share','detail':w['map'](({i:D})=>'rows['+D+']')['join'](',\x20')+'\x20duplicate\x20a\x20Rate\x20leg\x27s\x20recipient.\x20The\x20chain\x20pays\x20every\x20Rate\x20leg\x20its\x20declared\x20basis\x20points\x20'+'and\x20then\x20pays\x20the\x20ENTIRE\x20remainder\x20to\x20the\x20Surplus\x20recipient,\x20so\x20this\x20party\x20quietly\x20receives\x20rate%\x20+\x20100%\x20of\x20the\x20residual\x20and\x20any\x20leg\x20the\x20'+'author\x20intended\x20but\x20omitted\x20(commission,\x20payment\x20fee,\x20platform\x20take)\x20is\x20never\x20created.\x20The\x20Rate-sum\x20rule\x20passes\x20because\x20the\x20sum\x20is\x20legal\x20—\x20'+'the\x20misroute\x20is\x20invisible\x20there,\x20and\x20order_allocators\x20freezes\x20permanently\x20at\x20publish.\x20Mainnet\x20precedent\x20(Booking\x20replica,\x202026-10-06):\x20the\x20'+'property\x20took\x20100%\x20(Rate\x208350\x20+\x20Surplus),\x20the\x2015%\x20commission\x20and\x201.5%\x20payment-fee\x20legs\x20never\x20existed,\x20and\x20the\x20published\x20Service\x20had\x20to\x20be\x20abandoned.','suggestion':'Point\x20the\x20Surplus\x20row\x20at\x20the\x20party\x20meant\x20to\x20absorb\x20the\x20remainder\x20(usually\x20the\x20merchant),\x20distinct\x20from\x20every\x20Rate\x20leg\x20—\x20or,\x20if\x20the\x20duplicated\x20'+'recipient\x20is\x20truly\x20intended\x20to\x20take\x20rate%\x20+\x20remainder,\x20collapse\x20the\x20two\x20rows\x20into\x20ONE\x20rate\x20row\x20so\x20the\x20declared\x20split\x20equals\x20the\x20actual\x20split.\x20'+'Every\x20intended\x20payee\x20must\x20be\x20its\x20own\x20explicit\x20row.'}),b;}const DISPUTE_NODE_REGEX=/(^|_)(disputed?|arbitration|arb)(_|$)|^(refund|refunded|deposit_refunded|deposit_deducted|cancel|cancelled)$/i,KNOWN_GUARD_REF_IDS=new Set([...GUARD_DESIGN_PATTERNS['map'](a=>a['id']),...GUARD_TEMPLATES['map'](a=>a['id'])]);function guardRefChecks(a){const b=[];for(const c of a['guards']){if(!/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/['test'](c['template_id'])){b['push']({'rule_id':'R-REF-01','severity':'high','title':'Guard\x20reference\x20\x27'+c['template_id']+'\x27\x20is\x20not\x20a\x20resolvable\x20id','detail':'Guard\x20references\x20must\x20name\x20a\x20guard\x20design\x20pattern\x20(\x27pattern.*\x27,\x20'+GUARD_DESIGN_PATTERNS['length']+'\x20available)\x20or\x20a\x20guard\x20template\x20(\x27tpl_*\x27,\x20'+GUARD_TEMPLATES['length']+'\x20available).\x20Bare\x20prose\x20ids\x20dangle:\x20no\x20builder\x20can\x20resolve\x20them,\x20so\x20the\x20AI\x20invents\x20guard\x20logic\x20at\x20build\x20time.','suggestion':'Replace\x20with\x20the\x20semantically\x20nearest\x20pattern.*/tpl_*\x20id\x20(compose\x20multi-condition\x20logic\x20in\x20the\x20purpose\x20text).'});continue;}!KNOWN_GUARD_REF_IDS['has'](c['template_id'])&&b['push']({'rule_id':'R-REF-02','severity':'high','title':'Guard\x20reference\x20\x27'+c['template_id']+'\x27\x20does\x20not\x20exist\x20in\x20any\x20guard\x20catalog','detail':'The\x20id\x20is\x20namespaced\x20correctly\x20but\x20matches\x20no\x20guard\x20design\x20pattern\x20nor\x20guard\x20template\x20—\x20a\x20dangling\x20reference\x20the\x20AI\x20cannot\x20resolve.','suggestion':'Fix\x20the\x20id\x20(typo)\x20or\x20point\x20it\x20at\x20the\x20nearest\x20existing\x20pattern.*/tpl_*\x20entry.'});}return b;}function staticChecks(a){const b=[];for(const h of a['machine_shape']){DISPUTE_NODE_REGEX['test'](h['name'])&&b['push']({'rule_id':'R-M1-11','severity':'critical','title':'Machine\x20node\x20\x27'+h['name']+'\x27\x20models\x20dispute/refund\x20flow','detail':'Disputes\x20are\x20independent\x20of\x20the\x20Machine\x20workflow;\x20refunds\x20route\x20via\x20Allocators\x20triggered\x20by\x20business\x20states.','suggestion':'Remove\x20the\x20node;\x20route\x20refunds\x20via\x20Allocator\x20states\x20(closed_cancel/returned)\x20and\x20disputes\x20via\x20the\x20Arbitration\x20object.'});}const c=new Map();for(const j of a['guards']){if(/time_lock|order_holder|progress_state/['test'](j['template_id'])&&!/order\.service|project bind|service binding/i['test'](j['purpose'])){const k=c['get'](j['template_id'])??[];k['push'](j['key']??'(no\x20key)'),c['set'](j['template_id'],k);}}for(const [l,m]of c){b['push']({'rule_id':'R-C3-05','severity':'medium','title':'Guard\x20\x27'+l+'\x27\x20consumes\x20a\x20submitted\x20Order\x20without\x20project\x20binding\x20('+m['length']+'x:\x20'+m['join'](',\x20')+')','detail':'Passport\x20submissions\x20are\x20caller-built;\x20without\x20logic_equal[order.service,\x20<service>]\x20a\x20stale\x20order\x20from\x20another\x20project\x20can\x20satisfy\x20the\x20guard\x20for\x20a\x20fresh\x20order.','suggestion':'State\x20the\x20project\x20binding\x20in\x20the\x20guard\x20purpose\x20AND\x20include\x20it\x20in\x20the\x20guard\x20root\x20at\x20build\x20time.'});}a['machine_shape']['length']===0x0&&b['push']({'rule_id':'R-M1-01','severity':'critical','title':'machine_shape\x20is\x20empty','detail':'No\x20entry\x20node\x20—\x20the\x20Machine\x20cannot\x20start.','suggestion':'Add\x20at\x20least\x20one\x20entry\x20node\x20representing\x20the\x20escrowed\x20state.'});const d=a['guards']['some'](n=>/refund|cancel/i['test'](n['template_id'])||/refund|cancel/i['test'](n['purpose']))||/refund/i['test'](a['allocator']['description']);!d&&b['push']({'rule_id':'R1','severity':'high','title':'No\x20refund\x20path\x20detected','detail':'No\x20refund/cancel\x20guard\x20and\x20no\x20refund\x20route\x20in\x20the\x20allocator\x20description.','suggestion':'Add\x20a\x20refund/cancel\x20guard\x20or\x20an\x20allocator\x20refund\x20route\x20before\x20publishing.'});const e=a['guards']['some'](n=>n['host']==='arbitration')||a['trust_mechanisms']['some'](n=>n['startsWith']('R2'));!e&&b['push']({'rule_id':'R2','severity':'high','title':'No\x20independent\x20Arbitration\x20reference\x20detected','detail':'The\x20template\x20carries\x20no\x20arbitration-hosted\x20guard\x20and\x20no\x20R2\x20trust\x20mechanism.','suggestion':'Mount\x20an\x20independent\x20Arbitration\x20object\x20with\x20its\x20own\x20Permission.'});a['keeper_dependencies']['length']===0x0&&b['push']({'rule_id':'R9','severity':'medium','title':'No\x20keeper\x20dependencies\x20declared','detail':'Time-driven\x20transitions\x20only\x20ALLOW\x20advancement\x20—\x20someone\x20must\x20run\x20the\x20keepers.','suggestion':'Declare\x20the\x20keeper\x20operations\x20(timeouts,\x20window\x20expiries,\x20settlement\x20triggers).'});b['push'](...directSalesEconomyChecks(a));const f=unannotatedBuyerActionNodes(a['machine_shape']);return f['length']>0x0&&b['push']({'rule_id':'R-OPER-01','severity':'medium','title':'Buyer-side\x20node(s)\x20without\x20an\x20operator\x20annotation','detail':'Node(s)\x20'+f['map'](o=>'\x27'+o+'\x27')['join'](',\x20')+'\x20look\x20like\x20order-payer\x20actions\x20but\x20carry\x20no\x20operator\x20field.\x20At\x20build\x20time\x20they\x20default\x20to\x20a\x20merchant\x20permission\x20slot,\x20and\x20the\x20order\x20payer\x20cannot\x20advance\x20them\x20(E_PERMISSION_DENIED).','suggestion':'Annotate\x20true\x20buyer\x20actions\x20with\x20operator:\x20\x22order_payer\x22\x20(an\x20EMPTY\x20namedOperator\x20—\x20the\x20on-chain\x20check\x20resolves\x20it\x20to\x20the\x20order\x20payer);\x20rename\x20merchant-side\x20states\x20(e.g.\x20\x27cancelled\x27\x20->\x20\x27merchant_cancelled\x27)\x20when\x20the\x20actor\x20is\x20NOT\x20the\x20buyer.'}),b;}const PERIOD_COUNT_KEY_REGEX=/^(monthly_allocators|term_count|session_count|segment_count|periods|cycles|installments)$/;function poolPeriodCount(a){for(const [b,c]of Object['entries'](a['fee_params'])){if(PERIOD_COUNT_KEY_REGEX['test'](b)&&typeof c==='number'&&c>=0x2)return c;}return undefined;}function periodicReleaseChecks(a){const b=poolPeriodCount(a);if(b===undefined)return[];const c=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](f=>f['purpose'])]['join']('\x20\x0a\x20'),d=[];/surplus/i['test'](c)&&!/no surplus|surplus[^.\n]*(disabled|forbidden|disallowed)|amount mode only|single surplus/i['test'](c)&&d['push']({'rule_id':'R-PER-01','severity':'high','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20declares\x20Surplus\x20without\x20a\x20terminal-only\x20qualifier','detail':'A\x20Surplus\x20allocator\x20entry\x20runs\x20balance::withdraw_all\x20(allocation.move:288-298).\x20In\x20a\x20pool\x20pre-funded\x20for\x20'+b+'\x20periods\x20it\x20drains\x20every\x20future\x20release,\x20not\x20just\x20the\x20remainder.','suggestion':'Release\x20each\x20period\x20with\x20Amount;\x20if\x20the\x20pool\x20remainder\x20settles\x20in\x20one\x20entry,\x20declare\x20it\x20explicitly\x20as\x20the\x20SINGLE\x20terminal\x20Surplus\x20at\x20the\x20settlement\x20node,\x20or\x20disable\x20Surplus\x20outright.'});const e=/per[- ](month|period|term|session|cycle|segment)|one per (rent )?period|release-sequence lock/i['test'](c);return!e&&d['push']({'rule_id':'R-PER-02','severity':'high','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20declares\x20no\x20per-period\x20release\x20Guard','detail':'alloc()\x20has\x20no\x20consumed/nonce\x20flag\x20(allocation.move:204-321):\x20two\x20releases\x20bound\x20to\x20the\x20SAME\x20Guard\x20can\x20both\x20fire\x20the\x20same\x20day\x20and\x20drain\x20the\x20pool.\x20The\x20cadence\x20gate\x20must\x20be\x20one\x20Guard\x20per\x20period.','suggestion':'Declare\x20one\x20release\x20Guard\x20per\x20period\x20(per-month/per-term\x20time-lock\x20Guards,\x20each\x20keyed\x20to\x20its\x20own\x20period\x20window)\x20in\x20the\x20guard\x20set.'}),!/threshold[^.\n]*(one|single|per[- ]|month|period|term|session|=\s*0\b|\b0\b|must be 0)/i['test'](c)&&d['push']({'rule_id':'R-PER-03','severity':'medium','title':'Multi-period\x20pool\x20('+b+'\x20periods)\x20does\x20not\x20pin\x20threshold\x20to\x20one\x20period','detail':'alloc()\x20asserts\x20balance\x20>=\x20threshold\x20before\x20EVERY\x20release\x20(allocation.move:206).\x20A\x20threshold\x20sized\x20to\x20the\x20total\x20pool\x20passes\x20the\x20first\x20release\x20and\x20then\x20locks\x20all\x20remaining\x20periods.','suggestion':'State\x20in\x20the\x20allocator\x20description\x20or\x20build\x20notes\x20that\x20threshold\x20=\x20one\x20period\x27s\x20release\x20amount\x20(never\x20the\x20pre-funded\x20total).'}),d;}const MIN_PRICE_KEY_REGEX=/^(?:min_[a-z0-9_]*?(?:price|amount|usd|value)|price_floor)$/,FLOOR_TEXT_REGEX=/fixed (?:fee|charge)[^.\n]*(?:<|less than|below) [^.\n]*(?:lowest|minimum|min)|minimum (?:sku|order|item|unit) (?:price|amount)|(?:below|under|<=)\s*the\s+smallest[^.\n]*(?:order|escrow|booking|price)/i,FIXED_FEE_TEXT_REGEX=/\bamount mode\b|fixed (?:fee|fulfillment|fulfilment|per[- ]order) (?:fee|charge)|\bAmount\b[^.\n]*(?:fee|charge)/i;function fundAnchorChecks(a){const b=[],c=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](h=>h['template_id']+'\x20'+h['purpose'])]['join']('\x20\x0a\x20'),d=a['allocator']['refund_track']==='order_anchored'||/allocator_order_anchor/['test'](c)||/guardidentifier\(0\)|order[- ]anchored|for_object/i['test'](c);!d&&b['push']({'rule_id':'R-ANCHOR-01','severity':'critical','title':'Allocator\x20has\x20no\x20order\x20anchor\x20—\x20its\x20Guard\x20cannot\x20bind\x20the\x20paying\x20Order','detail':'Every\x20recipient\x20of\x20this\x20allocator\x20is\x20a\x20fixed\x20party\x20(recipient=\x27'+a['allocator']['recipient']+'\x27,\x20no\x20GuardIdentifier\x20row),\x20so\x20nothing\x20in\x20the\x20Guard\x27s\x20verification\x20context\x20names\x20the\x20Order\x20being\x20settled:\x20Recipient::Entity/Signer\x20are\x20resolved\x20without\x20any\x20submission\x20check\x20(allocation.move:451-456)\x20and\x20the\x20Allocation\x20itself\x20never\x20enters\x20the\x20Guard\x20context.\x20Testnet\x20proved\x20the\x20consequence:\x20a\x20passport\x20built\x20from\x20an\x20ALREADY-SETTLED\x20order\x20of\x20the\x20same\x20Service\x20drained\x20a\x20different\x20order\x27s\x20escrow\x20(CR-01).\x20The\x20identifier-255\x20once-slot\x20does\x20not\x20help\x20—\x20it\x20is\x20stored\x20per\x20Allocation,\x20so\x20a\x20fresh\x20pool\x20has\x20no\x20record.','suggestion':'Adopt\x20pattern.allocator_order_anchor:\x20add\x20one\x20{GuardIdentifier:\x200}\x20row\x20with\x20Rate\x200\x20(pays\x20nothing,\x20makes\x20the\x20submitted\x20Order\x20the\x20Guard\x27s\x20binding\x20target),\x20declare\x20refund_track:\x20\x22order_anchored\x22,\x20and\x20pin\x20the\x20Guard\x20expression\x20to\x20that\x20identifier\x20plus\x20logic_equal[order.service,\x20<this\x20service>].'});const e=a['allocator']['mode']==='amount',f=e||FIXED_FEE_TEXT_REGEX['test'](c),g=Object['keys'](a['fee_params'])['some'](h=>MIN_PRICE_KEY_REGEX['test'](h))||FLOOR_TEXT_REGEX['test'](c);return f&&!g&&b['push']({'rule_id':'R-FIXFEE-01','severity':e?'critical':'high','title':'Fixed\x20Amount\x20fee\x20with\x20no\x20minimum\x20order\x20value\x20—\x20sub-fee\x20orders\x20deadlock\x20permanently','detail':'alloc()\x20asserts\x20balance\x20>=\x20fix\x20before\x20distributing\x20(allocation.move:390):\x20an\x20order\x20escrowed\x20BELOW\x20the\x20fixed\x20fee\x20can\x20never\x20settle,\x20and\x20the\x20terminal\x20nodes\x20(completed/closed_cancel)\x20leave\x20no\x20refund\x20path\x20for\x20it,\x20so\x20buyer\x20funds\x20and\x20the\x20order\x20strand\x20forever\x20(testnet\x20CR-02,\x20reproduced\x20on\x20a\x200.001\x20WOW\x20SKU\x20against\x20a\x200.15\x20WOW\x20fee).','suggestion':'Declare\x20a\x20minimum\x20listing/order\x20value\x20above\x20every\x20fixed\x20leg\x20in\x20fee_params\x20(e.g.\x20min_sku_price)\x20and\x20state\x20it\x20in\x20the\x20allocator\x20description,\x20or\x20model\x20the\x20per-order\x20fee\x20as\x20Rate/RateGross\x20instead\x20of\x20a\x20fixed\x20Amount.'}),a['allocator']['once_per_order']===!![]&&!/per[- ]allocation|per[- ]pool|not cross[- ]order|within (a|the) (pool|allocation)/i['test'](c)&&b['push']({'rule_id':'R-ONCE-SCOPE-01','severity':'medium','title':'once_per_order\x20claim\x20does\x20not\x20state\x20its\x20per-Allocation\x20scope','detail':'The\x20identifier-255\x20once-slot\x20is\x20keyed\x20(guard,\x20allocator,\x20submission)\x20ON\x20ONE\x20Allocation,\x20so\x20replay\x20immunity\x20holds\x20within\x20a\x20single\x20pool\x20only;\x20a\x20second\x20Allocation\x20of\x20the\x20same\x20Service\x20starts\x20with\x20no\x20record.\x20Presenting\x20ONCE\x20as\x20general\x20idempotency\x20is\x20what\x20let\x20testnet\x20CR-01\x20read\x20as\x20\x27already\x20protected\x27.','suggestion':'Say\x20explicitly\x20that\x20255\x20protects\x20one\x20pool,\x20and\x20pair\x20it\x20with\x20the\x20order\x20anchor\x20(R-ANCHOR-01)\x20for\x20cross-order\x20safety.'}),b;}function templateText(a,b=[]){return[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](c=>c['template_id']+'\x20'+c['purpose']),...a['machine_shape']['map'](c=>c['name']+'\x20'+c['role']),...Object['entries'](a['time_anchors']??{})['map'](([c,d])=>c+'\x20'+d),...b]['join']('\x20\x0a\x20');}const STAY_DATE_REGEX=/check[\s-]?in|check[\s-]?out|departure\s+date|arrival\s+date|booking\s+date|checkin|checkout|stay\s+date|stay_nights|\bstay\s+nights?\b|\bper\s+night\b|入住|退房|离店|到店日/i,CHAIN_CLOCK_REGEX=/order\.time|progress\.current_time|\border\s+time\b|witness/i,REPOSITORY_DATE_SOURCE_REGEX=/(?:write|writes|written|storing|store|stores|persist|persisted|record|records|read|reads)\b[^.\n]{0,90}repositor|repositor\w*\b[^.\n]{0,90}(?:stay|check[\s-]?in|check[\s-]?out|departure|arrival|date)/i;function timeWindowAnchorChecks(a){const b=templateText(a);if(!STAY_DATE_REGEX['test'](b))return[];if(CHAIN_CLOCK_REGEX['test'](b)||REPOSITORY_DATE_SOURCE_REGEX['test'](b))return[];const c=b['match'](new RegExp(STAY_DATE_REGEX['source'],'gi'))??[],d=/\d+\s*[-–]\s*\d+\s*h(?:ours?|rs?)?\s*(?:adjustable|tunable|configurable)|\badjustable\b|\btunable\b/i['test'](b);return[{'rule_id':'R-WIN-ANCHOR-01','severity':'high','title':'Per-order\x20time\x20window(s)\x20anchored\x20to\x20a\x20stay\x20date\x20that\x20does\x20not\x20exist\x20on\x20chain\x20('+Array['from'](new Set(c))['slice'](0x0,0x5)['join'](',\x20')+')','detail':'The\x20template\x27s\x20windows\x20are\x20relative\x20to\x20a\x20check-in\x20/\x20check-out\x20/\x20departure\x20/\x20night\x20date.\x20No\x20such\x20field\x20exists\x20on\x20chain:\x20'+'`Order.items`\x20is\x20`vector<SaleItem>`\x20with\x20`SaleItem\x20{\x20item,\x20price,\x20quantity,\x20wip_hash\x20}`\x20(order.move:28-33)\x20and\x20the\x20purchasable\x20'+'`Sale\x20{\x20name,\x20price,\x20stock,\x20suspension,\x20wip,\x20wip_hash\x20}`\x20(service.move:100-107)\x20carries\x20no\x20schedule;\x20the\x20only\x20per-order\x20clock\x20is\x20'+'`Order.time`\x20(order.move:74),\x20the\x20CREATION\x20timestamp.\x20`Progress.current_time`\x20(progress.move:85)\x20is\x20overwritten\x20on\x20every\x20forward\x20'+'(progress.move:458)\x20and\x20`Progress.history`\x20records\x20node\x20visits,\x20so\x20neither\x20is\x20a\x20business\x20date.\x20A\x20window\x20declared\x20relative\x20to\x20the\x20'+'stay\x20calendar\x20is\x20therefore\x20UNREACHABLE\x20—\x20every\x20published\x20Guard\x20silently\x20measures\x20from\x20booking\x20time\x20instead,\x20and\x20for\x20a\x20lead\x20time\x20of\x20'+'days-to-weeks\x20that\x20is\x20a\x20material\x20semantic\x20loss,\x20not\x20a\x20rounding\x20error.'+(d?'\x20The\x20window\x20is\x20also\x20advertised\x20as\x20adjustable,\x20which\x20is\x20doubly\x20unreachable:\x20a\x20Guard\x20is\x20frozen\x20at\x20creation\x20'+'(transfer::freeze_object,\x20guard.move:262)\x20and\x20Machine\x20forwards\x20are\x20immutable\x20after\x20publish\x20(the\x20not-published\x20guard,\x20'+'machine.move:316),\x20so\x20an\x20\x27N-Mh\x20adjustable\x27\x20window\x20means\x20one\x20separately\x20published\x20Guard\x20per\x20window\x20value,\x20never\x20a\x20tunable\x20one.':''),'suggestion':'Express\x20every\x20window\x20relative\x20to\x20`order.time`\x20(or\x20`order.time\x20+\x20<window>`),\x20and\x20if\x20the\x20business\x20promise\x20is\x20genuinely\x20a\x20stay-date\x20'+'deadline,\x20write\x20the\x20stay\x20dates\x20into\x20a\x20Repository\x20at\x20buy\x20time,\x20pin\x20that\x20Repository\x20address\x20as\x20a\x20table\x20constant,\x20and\x20read\x20them\x20in\x20the\x20'+'Guard\x20(`query\x20repository.data`).\x20State\x20the\x20residual\x20semantic\x20loss\x20in\x20build_notes\x20rather\x20than\x20declaring\x20a\x20calendar-relative\x20window.'}];}function signerRefundChecks(a){const b=[],c=a['allocator']['rows']??[],d=c['find'](j=>j['recipient']==='signer'),e=a['allocator']['recipient']==='signer';if(!d&&!e)return b;const f=templateText(a),g=/refund|chargeback|repay|退款|(?:pay(?:ment|out)?|release|send|transfer|settle)\w*[^.\n]{0,40}to the (?:buyer|order|customer)/i['test'](f);if(!g)return b;const h=d?'allocator\x20row\x20'+d['track']+'/'+(d['recipient_key']??'?'):'allocator.recipient=\x27signer\x27';return b['push']({'rule_id':'R-SIGNER-02','severity':'high','title':'Refund\x20leg\x20pays\x20Recipient::Signer\x20—\x20the\x20keeper,\x20not\x20the\x20buyer\x20('+h+')','detail':'`Recipient::Signer`\x20resolves\x20to\x20`tx_context::sender(ctx)`\x20(allocation.move:531-533),\x20i.e.\x20whoever\x20signed\x20the\x20transaction\x20that\x20triggered\x20'+'`alloc`.\x20Time-driven\x20refunds\x20are\x20keeper-triggered\x20by\x20construction,\x20so\x20this\x20leg\x20pays\x20the\x20KEEPER,\x20and\x20because\x20`alloc()`\x20records\x20no\x20'+'consumed\x20flag\x20for\x20the\x20recipient,\x20first-come-first-served.\x20Only\x20`Recipient::GuardIdentifier`\x20(resolved\x20through\x20the\x20Guard\x20submission,\x20'+'allocation.move:501-527)\x20or\x20an\x20explicit\x20`Entity`\x20is\x20safe\x20for\x20a\x20refund.','suggestion':'Replace\x20the\x20Signer\x20refund\x20row\x20with\x20a\x20`{GuardIdentifier:\x200}`\x20row\x20(the\x20submission\x20for\x20a\x20Service-created\x20Allocation\x20is\x20pinned\x20to\x20the\x20paying\x20'+'Order,\x20so\x20only\x20`order.owner`\x20can\x20receive\x20it)\x20and\x20bind\x20the\x20Guard\x20to\x20`order.owner`\x20+\x20`progress.current\x20==\x20<refund\x20node>`.'}),b;}function orderAnchorDeclarationChecks(a){const b=templateText(a),c=a['allocator']['refund_track']==='order_anchored'||/order[\s-]anchored|order anchor|refund recipient is the order|anchor row|guardidentifier\s*\(\s*0\s*\)|for_object|退款接收方为订单/i['test'](b);if(!c)return[];const d=(a['allocator']['rows']??[])['some'](g=>g['recipient']==='guard_identifier'||g['recipient']==='guard_identifier_to_order'),e=a['guards']['some'](h=>h['template_id']==='pattern.allocator_order_anchor');if(d||e)return[];const f=a['allocator']['recipient']??'?';return[{'rule_id':'R-RECIPIENT-02','severity':'high','title':'Order-anchored\x20refund\x20recipient\x20is\x20asserted\x20in\x20prose\x20but\x20declared\x20nowhere\x20machine-checkable','detail':'The\x20template\x20claims\x20an\x20order-anchored\x20escrow\x20/\x20refund\x20recipient\x20while\x20its\x20machine-readable\x20allocator\x20says\x20recipient=\x27'+f+'\x27\x20'+'with\x20no\x20`guard_identifier`\x20row\x20and\x20no\x20`pattern.allocator_order_anchor`\x20Guard\x20reference.\x20Two\x20on-chain\x20facts\x20make\x20the\x20claim\x20as\x20written\x20'+'unbuildable:\x20(1)\x20`Recipient`\x20has\x20only\x20`GuardIdentifier(u8)`\x20/\x20`Entity(address)`\x20/\x20`Signer`\x20(allocation.move:148-152)\x20—\x20there\x20is\x20NO\x20'+'`Order`\x20variant,\x20so\x20\x27the\x20refund\x20recipient\x20is\x20the\x20order\x20object\x27\x20can\x20only\x20be\x20written\x20as\x20a\x20`GuardIdentifier`\x20row;\x20(2)\x20recipients\x20that\x20are\x20'+'all\x20fixed\x20`Entity`\x20rows\x20resolve\x20without\x20the\x20passport\x20submission\x20(allocation.move:528-530)\x20and\x20the\x20Allocation\x20never\x20enters\x20the\x20Guard\x20'+'context,\x20so\x20the\x20Guard\x20has\x20no\x20order\x20to\x20bind\x20at\x20all\x20—\x20the\x20CR-01\x20drain\x20shape.\x20A\x20build\x20agent\x20reading\x20the\x20prose\x20instead\x20of\x20the\x20schema\x20will\x20'+'emit\x20an\x20Entity\x20refund\x20leg\x20to\x20the\x20merchant,\x20or\x20a\x20Signer\x20leg\x20to\x20the\x20keeper.','suggestion':'Declare\x20the\x20anchor\x20machine-checkably:\x20one\x20`{\x20recipient:\x20\x27guard_identifier\x27,\x20recipient_key:\x20\x270\x27,\x20mode:\x20\x27rate\x27,\x20value:\x200\x20}`\x20row\x20(the\x20'+'pattern.allocator_order_anchor\x20convention)\x20plus\x20`refund_track:\x20\x27order_anchored\x27`,\x20and\x20reference\x20`pattern.allocator_order_anchor`\x20in\x20the\x20'+'guard\x20set\x20with\x20the\x20`logic_equal[order.service,\x20<this\x20service>]`\x20binding\x20stated\x20in\x20its\x20purpose.'}];}const EDGE_DEPENDENCY_REGEX=/\b(?:incoming|outgoing|arb_refund)\s+edge\b|\bstop[\s-]node\b|\bedges?\b|\bpairs?\b|\bforwards?\b|one pair|two pairs/i;function topologyChecks(a){const b=[],c=templateText(a);if(a['machine_shape']['some'](j=>(j['from']??[])['length']>0x0))return b;EDGE_DEPENDENCY_REGEX['test'](c)&&b['push']({'rule_id':'R-TOPO-01','severity':'high','title':'machine_shape\x20ships\x20nodes\x20only\x20—\x20no\x20Pair/forward\x20list,\x20so\x20stop-node\x20fund-exit\x20coverage\x20is\x20unauditable','detail':'This\x20template\x27s\x20correctness\x20depends\x20on\x20Machine\x20edges\x20(its\x20own\x20notes\x20reason\x20about\x20incoming/outgoing\x20edges,\x20pairs\x20and\x20stop-node\x20'+'fund-exit\x20coverage),\x20but\x20`machine_shape`\x20carries\x20NO\x20edges:\x20an\x20edge\x20on\x20chain\x20is\x20`Node[target].pairs\x20=\x20{\x20prev_node,\x20threshold,\x20'+'forwards[]\x20}`,\x20which\x20this\x20schema\x20cannot\x20express.\x20The\x20scanner\x20therefore\x20has\x20to\x20invent\x20a\x20linear\x20chain,\x20and\x20the\x20mandatory\x20'+'stop-node\x20walk\x20(R-M5-03\x20/\x20R-M5-09:\x20every\x20rest\x20state\x20needs\x20a\x20defined\x20withdrawal\x20AND\x20refund\x20rule,\x20satisfiable\x20in\x20both\x20directions)\x20'+'cannot\x20be\x20performed\x20—\x20an\x20uncovered\x20stop\x20node\x20strands\x20escrow\x20permanently\x20once\x20Machine\x20+\x20Allocator\x20are\x20frozen\x20at\x20publish.','suggestion':'Either\x20state\x20the\x20edges\x20explicitly\x20in\x20build_notes\x20as\x20`prev\x20─forward(op,w)→\x20next`\x20with\x20the\x20Pair\x20grouping,\x20or\x20declare\x20a\x20machine-readable\x20'+'edge\x20list\x20so\x20the\x20scanner\x20can\x20audit\x20stop-node\x20coverage\x20and\x20prev_node\x20uniqueness\x20instead\x20of\x20guessing.'});const d=a['machine_shape']['map'](j=>j['name']);if(d['length']===0x0)return b;const e=d['filter'](j=>BRANCH_STATE_REGEX['test'](j));if(e['length']===0x0)return b;const f=d[0x0],g=!BRANCH_STATE_REGEX['test'](d[0x1]),h=(g?0x1:0x0)+e['length'];if(h<=0x1)return b;return b['push']({'rule_id':'R-TOPO-02','severity':'medium','title':'Node\x20\x27'+f+'\x27\x20has\x20'+h+'\x20outgoing\x20rails\x20—\x20declare\x20the\x20Pair\x20grouping\x20(E_DUPLICATE_NODE_PREV\x20is\x20per\x20TARGET\x20node,\x20not\x20per\x20source)','detail':'From\x20\x27'+f+'\x27\x20the\x20declared\x20node\x20set\x20requires\x20'+h+'\x20distinct\x20rails\x20'+('('+(g?'the\x20linear\x20rail\x20to\x20\x27'+d[0x1]+'\x27,\x20':''))+(e['map'](j=>'the\x20branch\x20to\x20\x27'+j+'\x27')['join'](',\x20')+').\x20These\x20are\x20LEGAL\x20and\x20must\x20NOT\x20be\x20merged:\x20an\x20edge\x20A→B\x20is\x20')+'stored\x20in\x20`Node[B].pairs\x20=\x20{\x20prev_node:\x20A,\x20threshold,\x20forwards[]\x20}`,\x20and\x20the\x20chain\x20rejects\x20only\x20the\x20SAME\x20`prev_node`\x20appearing\x20'+'twice\x20inside\x20ONE\x20node\x27s\x20pairs\x20(`assert!(!vector::contains(&res,\x20&pair.prev_node),\x20E_DUPLICATE_NODE_PREV)`,\x20machine.move:171\x20and\x20'+'machine.move:440).\x20Rails\x20into\x20different\x20targets\x20occupy\x20different\x20nodes,\x20so\x20each\x20`prev_node`\x20still\x20appears\x20exactly\x20once\x20per\x20node.\x20'+'THE\x20HAZARD\x20IS\x20THE\x20MIRROR\x20IMAGE:\x20two\x20forwards\x20from\x20the\x20SAME\x20source\x20into\x20the\x20SAME\x20target\x20must\x20be\x20ONE\x20Pair\x20carrying\x20both\x20forwards\x20—\x20'+'a\x20builder\x20that\x20emits\x20one\x20Pair\x20per\x20forward\x20duplicates\x20`prev_node`\x20and\x20ABORTS\x20at\x20publish,\x20after\x20Machine\x20+\x20Guard\x20are\x20frozen.\x20Note\x20'+'also\x20that\x20one\x20forward\x20cannot\x20satisfy\x20two\x20operators:\x20each\x20forward\x20contributes\x20its\x20weight\x20at\x20most\x20once\x20(locked\x20by\x20its\x20first\x20operator,\x20'+'progress.move:425-431),\x20so\x20a\x20dual-confirmation\x20step\x20needs\x20`threshold\x20=\x202`\x20with\x20two\x20DISTINCT\x20forwards.\x20A\x20node\x20list\x20cannot\x20distinguish\x20'+'these\x20cases,\x20which\x20is\x20why\x20this\x20is\x20advisory\x20and\x20not\x20a\x20proven\x20defect.','suggestion':'Do\x20NOT\x20merge\x20the\x20rails.\x20Instead\x20declare\x20the\x20grouping\x20explicitly\x20in\x20build_notes\x20as\x20'+'`prev\x20─forward(op,w)→\x20next`,\x20marking\x20which\x20forwards\x20SHARE\x20one\x20target\x20and\x20therefore\x20belong\x20in\x20ONE\x20Pair,\x20and\x20state\x20each\x20Pair\x27s\x20'+'`threshold`\x20(2\x20with\x20two\x20distinct\x20forwards\x20when\x20two\x20different\x20operators\x20must\x20act).\x20This\x20also\x20lets\x20the\x20scanner\x20audit\x20prev_node\x20'+'uniqueness\x20instead\x20of\x20guessing.\x20Related:\x20R-TOPO-01\x20(high)\x20is\x20the\x20finding\x20that\x20records\x20that\x20edges\x20are\x20unauditable\x20at\x20all.'}),b;}function reachabilityChecks(a){const b=a['machine_shape']??[];if(b['length']===0x0)return[];if(!b['some'](s=>(s['from']??[])['length']>0x0))return[];const c=new Map(b['map'](s=>[s['name'],s])),d=new Map(),f=[];for(const s of b){for(const u of s['from']??[]){const v=typeof u==='string'?u:u?.['prev'];if(v==='')f['push'](s['name']);else{if(!d['has'](v))d['set'](v,[]);d['get'](v)['push'](s['name']);}}}const g=[];if(f['length']===0x0)g['push']('no\x20entry\x20edge\x20(prev:\x20\x22\x22)\x20—\x20the\x20Machine\x20has\x20no\x20starting\x20Pair\x20and\x20orders\x20can\x20never\x20begin');else f['length']>0x1&&g['push'](f['length']+'\x20entry\x20edges\x20(prev:\x20\x22\x22)\x20into\x20'+f['map'](w=>'\x27'+w+'\x27')['join'](',\x20')+'\x20—\x20'+'exactly\x20one\x20starting\x20Pair\x20is\x20expressible\x20on\x20chain\x20(the\x20first\x20pair\x20with\x20prev_node\x20\x22\x22)');const h=new Set(f),j=[...f];while(j['length']>0x0){const w=j['pop']();for(const x of d['get'](w)??[]){!h['has'](x)&&(h['add'](x),j['push'](x));}}const k=b['filter'](y=>!h['has'](y['name']))['map'](y=>'\x27'+y['name']+'\x27');k['length']>0x0&&g['push']('unreachable\x20from\x20the\x20entry\x20(declared\x20but\x20dead):\x20'+k['join'](',\x20'));const l=y=>y['semantic_role']==='final'||y['semantic_role']==='cancelled',n=new Map();for(const [y,z]of d){for(const A of z){if(!n['has'](A))n['set'](A,[]);n['get'](A)['push'](y);}}const o=new Set(),p=b['filter'](l)['map'](B=>B['name']);p['forEach'](B=>o['add'](B));while(p['length']>0x0){const B=p['pop']();for(const C of n['get'](B)??[]){!o['has'](C)&&(o['add'](C),p['push'](C));}}const q=b['filter'](D=>!l(D)&&!o['has'](D['name']))['filter'](D=>!(D['optional']===!![]&&(d['get'](D['name'])??[])['length']===0x0))['map'](D=>{const E=(d['get'](D['name'])??[])['length'],F=E===0x0?D['optional']===!![]?'an\x20optional\x20leaf\x20must\x20not\x20hold\x20the\x20only\x20world\x20state\x20—\x20mark\x20it\x20plain\x20and\x20wire\x20an\x20exit,\x20or\x20keep\x20it\x20optional\x20only\x20when\x20settlement\x20truly\x20never\x20routes\x20through\x20it':'leaf\x20with\x20NO\x20exit\x20—\x20an\x20order\x20standing\x20here\x20can\x20never\x20settle\x20or\x20refund':'exits\x20lead\x20only\x20to\x20'+[...new Set(d['get'](D['name'])??[])]['map'](G=>'\x27'+G+'\x27')['join'](',\x20')+',\x20none\x20of\x20which\x20reaches\x20a\x20settlement\x20or\x20refund\x20endpoint';return'\x27'+D['name']+'\x27\x20('+(D['semantic_role']??'no\x20semantic_role')+')\x20—\x20'+F;});q['length']>0x0&&g['push']('no\x20path\x20to\x20a\x20terminal\x20(final/cancelled):\x20'+q['join'](';\x20'));if(g['length']===0x0)return[];return[{'rule_id':'R-TOPO-03','severity':'high','title':'Machine\x20edge\x20graph\x20breaks\x20reachability\x20—\x20declared\x20semantics\x20can\x20never\x20execute\x20or\x20never\x20end','detail':'Auditing\x20the\x20structured\x20from-edges:\x20'+g['join'](';\x20')+'.\x20Every\x20declared\x20node\x20must\x20be\x20'+'reachable\x20from\x20the\x20single\x20entry\x20Pair,\x20and\x20every\x20non-terminal\x20node\x20must\x20reach\x20a\x20final/cancelled\x20'+'endpoint\x20—\x20buy\x20escrows\x20ATOMICALLY,\x20so\x20a\x20node\x20from\x20which\x20the\x20world\x20cannot\x20end\x20strands\x20the\x20pool.\x20'+'Machine\x20topology\x20is\x20frozen\x20at\x20publish\x20(IMMUT-001),\x20so\x20these\x20defects\x20are\x20unfixable\x20after\x20the\x20fact;\x20'+'the\x20only\x20remedy\x20is\x20correcting\x20the\x20template\x20BEFORE\x20the\x20Machine\x20is\x20built.\x20Pure\x20side\x20actions\x20(a\x20review\x20'+'node,\x20order\x20completes\x20without\x20it)\x20are\x20exempt\x20only\x20when\x20marked\x20`optional:\x20true`\x20AND\x20holding\x20no\x20exit\x20—\x20'+'an\x20explicit\x20declaration,\x20never\x20a\x20scanner\x20guess.','suggestion':'Fix\x20the\x20edge\x20data:\x20give\x20every\x20non-entry\x20node\x20a\x20from-edge\x20chain\x20back\x20to\x20the\x20entry,\x20give\x20every\x20mandatory\x20'+'state\x20at\x20least\x20one\x20forward\x20path\x20into\x20a\x20final/cancelled\x20endpoint,\x20and\x20mark\x20genuinely\x20skippable\x20side\x20'+'actions\x20`optional:\x20true`.\x20One\x20entry\x20edge\x20(prev:\x20\x22\x22)\x20only\x20—\x20the\x20on-chain\x20Machine\x20has\x20exactly\x20one\x20'+'starting\x20Pair.'}];}function compoundPayoutChecks(a){const b=templateText(a),c=a['allocator']['rows']??[],d=a['allocator']['refund_track']!==undefined||c['some'](f=>f['track']==='refund')||/refund|退款/i['test'](a['allocator']['description']);if(!d)return[];const e=a['guards']['some'](f=>f['host']==='arbitration')||a['trust_mechanisms']['some'](f=>/^R2\b/['test'](f))||/compensation[_ ]fund/i['test'](b);if(!e)return[];return[{'rule_id':'R-COMPOUND-01','severity':'low','title':'Dual\x20buyer-remedy\x20rails\x20(escrow\x20refund\x20+\x20compensation\x20fund)\x20—\x20the\x20arbitrator\x20nets\x20the\x20award','detail':'This\x20template\x20carries\x20BOTH\x20buyer-remedy\x20channels\x20by\x20design:\x20a\x20refund\x20Allocator\x20paying\x20out\x20of\x20the\x20order\x20escrow\x20AND\x20a\x20bound\x20'+'Arbitration\x20paying\x20out\x20of\x20the\x20Service\x27s\x20compensation\x20fund.\x20The\x20two\x20channels\x20are\x20independent\x20on-chain\x20and\x20the\x20platform\x20does\x20not\x20'+'hard-block\x20a\x20double\x20payout\x20at\x20the\x20protocol\x20level\x20—\x20that\x20is\x20an\x20intentional\x20commercial\x20game,\x20not\x20a\x20defect:\x20the\x20merchant\x20chose\x20the\x20'+'arbitrator,\x20and\x20the\x20arbitrator\x20rules\x20on\x20the\x20full\x20fund\x20picture.\x20Every\x20query\x20of\x20an\x20Arb\x20case\x20auto-attaches\x20the\x20order-side\x20fund\x20facts\x20'+'(_order_fund_facts:\x20amount,\x20escrow\x20balance,\x20withdraw\x20history,\x20claimed_by,\x20workflow\x20node),\x20and\x20every\x20case\x20operation\x20result\x20carries\x20'+'order_fund_facts,\x20so\x20a\x20refund-then-claim\x20ordering\x20is\x20visible\x20at\x20ruling\x20time\x20and\x20the\x20award\x20is\x20expected\x20to\x20net\x20out\x20the\x20already-refunded\x20principal.','suggestion':'No\x20structural\x20change\x20required.\x20Keep\x20the\x20operational\x20rule:\x20arbitrators\x20read\x20order_fund_facts\x20before\x20finalizing\x20the\x20indemnity\x20and\x20net\x20'+'any\x20positive\x20escrow_deficit\x20/\x20withdraw_history\x20payouts\x20against\x20the\x20award.\x20If\x20a\x20template\x20intends\x20a\x20non-monetary\x20remedy\x20instead,\x20say\x20so\x20'+'explicitly\x20in\x20the\x20arbitration\x20proposition\x20wording.'}];}function surplusTrackChecks(a){const b=a['allocator']['rows']??[],c=[],d=b['filter'](h=>h['track']==='refund'&&h['mode']==='surplus'),e=b['filter'](h=>h['track']==='settlement'&&h['mode']==='amount');d['length']>0x0&&e['length']>0x0&&c['push']({'rule_id':'R-SURPLUS-01','severity':'critical','title':'Refund-track\x20Surplus\x20sweeps\x20UNPAID\x20settlement\x20Amounts\x20out\x20of\x20the\x20shared\x20pool','detail':'An\x20order\x20funds\x20ONE\x20pool\x20—\x20`track`\x20is\x20a\x20build-time\x20grouping\x20the\x20chain\x20never\x20sees.\x20The\x20refund\x20row\x20'+'runs\x20Surplus\x20mode,\x20which\x20pays\x20the\x20ENTIRE\x20remaining\x20balance\x20(allocation.move:494-505;\x20template\x20rows\x20cannot\x20set\x20'+'`Allocator.max`,\x20so\x20the\x20sweep\x20is\x20uncapped),\x20while\x20the\x20settlement\x20track\x20still\x20carries\x20fixed\x20Amount\x20obligations\x20'+('('+e['map'](h=>h['recipient_key']??h['recipient'])['join'](',\x20')+').\x20Track\x20guards\x20are\x20independent\x20—\x20a\x20')+'time-locked\x20deposit\x20release\x20does\x20not\x20wait\x20for\x20month-gated\x20rent\x20—\x20so\x20when\x20the\x20refund\x20fires\x20first,\x20the\x20sweep\x20hands\x20'+'the\x20unpaid\x20Amounts\x20to\x20the\x20refund\x20recipient.\x20VERIFIED\x20LIVE\x20on\x20ziroom\x20mainnet\x20T-05:\x20the\x20deposit_back\x20Surplus\x20paid\x20'+'the\x20tenant\x20the\x20deposit\x20PLUS\x20the\x20unreleased\x20rent\x20(585/525\x20in\x20full);\x20the\x20landlord\x20received\x200.','suggestion':'Size\x20the\x20refund\x20leg\x20explicitly:\x20an\x20Amount\x20row\x20pinned\x20to\x20the\x20deposit\x20value\x20(value/value_from),\x20so\x20the\x20payout\x20can\x20'+'never\x20exceed\x20its\x20own\x20scope\x20—\x20or\x20split\x20the\x20two\x20fund\x20scopes\x20into\x20separate\x20Allocation\x20objects\x20so\x20a\x20sweep\x20can\x20only\x20'+'reach\x20its\x20own\x20pool.\x20If\x20an\x20uncapped\x20sweep\x20is\x20truly\x20intended,\x20gate\x20it\x20on\x20a\x20node\x20that\x20provably\x20follows\x20the\x20FINAL\x20'+'settlement\x20release,\x20and\x20state\x20in\x20the\x20template\x20that\x20any\x20obligation\x20unpaid\x20by\x20then\x20is\x20forfeit.'});const f=b['filter'](h=>h['track']==='settlement'&&h['mode']==='surplus'),g=b['filter'](h=>h['track']==='refund'&&h['mode']==='amount');return f['length']>0x0&&g['length']>0x0&&c['push']({'rule_id':'R-SURPLUS-02','severity':'high','title':'Settlement-track\x20Surplus\x20can\x20drain\x20the\x20pool\x20ahead\x20of\x20a\x20fixed-Amount\x20refund','detail':'The\x20settlement\x20sweep\x20(Surplus,\x20uncapped\x20—\x20allocation.move:494-505)\x20pays\x20the\x20merchant\x20the\x20entire\x20remainder\x20while\x20'+('the\x20refund\x20track\x20still\x20owes\x20fixed\x20Amounts\x20('+g['map'](h=>h['recipient_key']??h['recipient'])['join'](',\x20')+').\x20')+'If\x20the\x20settlement\x20guard\x20fires\x20while\x20a\x20refund\x20obligation\x20is\x20still\x20open\x20(the\x20tracks\x20are\x20gated\x20independently),\x20the\x20'+'pool\x20is\x20empty\x20when\x20the\x20refund\x20fires\x20and\x20alloc()\x20aborts\x20on\x20insufficient\x20balance\x20(allocation.move:390)\x20—\x20the\x20buyer\x20'+'remedy\x20is\x20bricked\x20and\x20the\x20merchant\x20keeps\x20money\x20the\x20template\x20declared\x20refundable.','suggestion':'Make\x20the\x20two\x20tracks\x20mutually\x20exclusive\x20by\x20construction\x20(refund\x20fires\x20only\x20from\x20cancel\x20nodes\x20the\x20settlement\x20'+'guard\x20can\x20never\x20reach,\x20and\x20vice\x20versa),\x20or\x20size\x20the\x20refund\x20as\x20a\x20Rate\x20so\x20it\x20degrades\x20to\x20a\x20share\x20instead\x20of\x20'+'aborting.\x20NOTE:\x20there\x20is\x20no\x20on-chain\x20holdback\x20(FACT-ALLOC-03)\x20—\x20do\x20NOT\x20try\x20to\x20\x27reserve\x27\x20the\x20refund\x20Amount\x20'+'via\x20a\x20fix\x20value;\x20split\x20the\x20two\x20fund\x20scopes\x20into\x20separate\x20Allocation\x20objects\x20if\x20isolation\x20is\x20required.'}),c;}const BRANCH_STATE_REGEX=/(cancel|return|withdraw|exit|expired)/i;function amountDeadlockChecks(a){const b=a['allocator']['rows']??[],c=b['filter'](f=>f['track']==='settlement');if(c['length']===0x0||!c['every'](f=>f['mode']==='amount'))return[];const d=[a['allocator']['description'],...a['build_notes'],...a['trust_mechanisms'],...a['guards']['map'](f=>f['template_id']+'\x20'+f['purpose'])]['join']('\x20\x0a\x20'),e=Object['keys'](a['fee_params'])['some'](f=>MIN_PRICE_KEY_REGEX['test'](f))||FLOOR_TEXT_REGEX['test'](d);if(e)return[];return[{'rule_id':'R-DEADLOCK-01','severity':'medium','title':'Settlement\x20track\x20is\x20ALL\x20fixed\x20Amount\x20—\x20an\x20under-funded\x20pool\x20deadlocks\x20permanently','detail':'Every\x20settlement\x20row\x20is\x20mode\x20\x27amount\x27\x20('+c['length']+'\x20row(s));\x20each\x20asserts\x20balance\x20>=\x20fix\x20at\x20release\x20'+'(allocation.move:390).\x20When\x20the\x20pool\x20is\x20smaller\x20than\x20the\x20pinned\x20leg\x20—\x20a\x20discount\x20code,\x20a\x20low-price\x20SKU,\x20a\x20'+'partially-funded\x20order\x20—\x20the\x20call\x20aborts\x20and\x20NO\x20later\x20call\x20can\x20settle\x20a\x20smaller\x20amount:\x20the\x20merchant\x27s\x20payout\x20'+'path\x20is\x20bricked\x20for\x20that\x20order\x20(ziroom\x20CR-02:\x20fixed\x20Amount\x20legs\x20+\x20a\x20cheap\x20SKU\x20=\x20permanent\x20settlement\x20abort).\x20'+'Rate\x20and\x20Surplus\x20legs\x20degrade\x20to\x20whatever\x20the\x20pool\x20actually\x20holds;\x20Amount\x20legs\x20cannot.','suggestion':'Carry\x20at\x20least\x20one\x20Rate/Surplus\x20leg\x20as\x20the\x20degradation\x20path\x20(e.g.\x20the\x20merchant\x20remainder\x20as\x20Rate),\x20or\x20enforce\x20a\x20'+'build-time\x20price\x20floor\x20proving\x20order_total\x20>=\x20the\x20largest\x20fixed\x20leg\x20—\x20and\x20state\x20that\x20floor\x20in\x20fee_params\x20so\x20the\x20'+'builder\x20cannot\x20silently\x20undercut\x20it.'}];}function cancelCoverageChecks(a){const b=a['allocator']['rows']??[];if(b['some'](d=>d['track']==='refund'))return[];if(a['allocator']['refund_track']!==undefined)return[];const c=a['machine_shape']['find'](d=>BRANCH_STATE_REGEX['test'](d['name']));if(!c)return[];return[{'rule_id':'R-CANCEL-01','severity':'high','title':'Machine\x20models\x20\x27'+c['name']+'\x27\x20but\x20the\x20allocator\x20has\x20NO\x20refund-track\x20rows\x20—\x20money\x20locks\x20on\x20that\x20path','detail':'The\x20machine\x20shape\x20carries\x20a\x20cancel/return/exit\x20state,\x20yet\x20no\x20allocator\x20row\x20pays\x20on\x20the\x20refund\x20track.\x20Text-level\x20'+'claims\x20(guard\x20purposes,\x20allocator\x20description)\x20may\x20still\x20say\x20\x27refund\x27,\x20but\x20on\x20chain\x20only\x20rows\x20move\x20money:\x20an\x20'+'order\x20that\x20reaches\x20this\x20state\x20keeps\x20its\x20escrow\x20with\x20no\x20rail\x20out\x20(ofn\x20#P-02:\x20the\x20subscription\x20template\x27s\x20refund\x20'+'rails\x20missed\x20closed_cancel\x20and\x200.5\x20WOW\x20locked\x20permanently;\x20verified\x20live).','suggestion':'Add\x20refund-track\x20rows\x20covering\x20EVERY\x20cancel-ish\x20terminal\x20(order-anchored\x20GuardIdentifier(0)\x20recipient,\x20'+'Rate-sized\x20with\x20the\x20group\x20summing\x2010000),\x20or\x20remove\x20the\x20state\x20from\x20the\x20machine\x20so\x20orders\x20can\x20never\x20enter\x20it.'}];}function redundGuardObjectMismatchChecks(a){const b=a['allocator']['rows']??[],c=b['filter'](g=>g['track']==='refund'&&g['recipient']==='guard_identifier');if(c['length']===0x0)return[];const d=a['guards']['some'](h=>/arb|ruling|arbitration/i['test'](h['template_id'])||/arb|ruling|arbitration/i['test'](h['purpose']));if(!d)return[];const e=templateText(a),f=/two[- ]slot|slot\s*0.*order|slot\s*1.*arb|arb\.order.*==|for_object.*binding/i['test'](e);if(f)return[{'rule_id':'REDUND-GUARD-OBJECT-MISMATCH','severity':'low','title':'Arb-refund\x20guard\x20uses\x20two-slot\x20design\x20(Order\x20+\x20Arb)\x20—\x20self-certifying\x20pair','detail':'The\x20template\x20carries\x20a\x20refund\x20allocator\x20row\x20with\x20a\x20GuardIdentifier\x20recipient\x20AND\x20an\x20arbitration-ruling\x20guard.\x20'+'The\x20two-slot\x20design\x20(slot\x200\x20=\x20Order\x20for\x20the\x20allocator\x20recipient,\x20slot\x201\x20=\x20Arb\x20for\x20the\x20ruling\x20state)\x20is\x20the\x20'+'correct\x20resolution\x20of\x20the\x20F-02\x20slot\x20conflict:\x20the\x20allocator\x20reads\x20slot\x200\x20(payment_info.for_object\x20binding),\x20'+'the\x20forward\x20reads\x20slot\x201\x20(arb.indemnity\x20state),\x20and\x20the\x20binding\x20assertion\x20query(\x22arb.order\x22,\x20slot1)\x20==\x20slot0\x20'+'makes\x20the\x20pair\x20self-certifying\x20against\x20redirect\x20attacks.','suggestion':'Verify\x20the\x20guard\x20is\x20tpl_forward_arb_ruling_won\x20(two-slot\x20form)\x20or\x20an\x20equivalent\x20custom\x20guard\x20with\x20the\x20same\x20'+'slot\x20layout\x20and\x20binding\x20assertion.\x20Single-slot\x20arb-refund\x20guards\x20are\x20unreachable\x20(F-02).'}];return[{'rule_id':'REDUND-GUARD-OBJECT-MISMATCH','severity':'high','title':'Arb-refund\x20guard\x20may\x20use\x20a\x20SINGLE\x20slot\x20—\x20unreachable\x20rail\x20(F-02)','detail':'The\x20template\x20carries\x20a\x20refund\x20allocator\x20row\x20with\x20a\x20GuardIdentifier\x20recipient\x20AND\x20an\x20arbitration-ruling\x20guard,\x20'+'but\x20the\x20template\x20text\x20does\x20not\x20mention\x20the\x20two-slot\x20design.\x20A\x20single-slot\x20guard\x20cannot\x20satisfy\x20both\x20consumers:\x20'+'the\x20forward\x20needs\x20the\x20Arb\x20object\x20(to\x20read\x20arb.indemnity),\x20while\x20the\x20allocator\x20recipient\x20GuardIdentifier(0)\x20needs\x20'+'the\x20Order\x20object\x20(payment_info.for_object\x20binding).\x20F-02\x20verified\x20live:\x20Order\x20address\x20→\x20forward\x20aborts;\x20Arb\x20address\x20'+'→\x20allocation\x20aborts\x2015\x20(ERECIPIENT_NOT_FOR_OBJECT).\x20The\x20escrow\x20strands\x20permanently\x20with\x20no\x20on-chain\x20exit.','suggestion':'Use\x20tpl_forward_arb_ruling_won\x20(two-slot\x20form:\x20slot\x200\x20=\x20Order,\x20slot\x201\x20=\x20Arb,\x20with\x20arb.order\x20==\x20order\x20binding),\x20'+'or\x20document\x20the\x20two-slot\x20design\x20explicitly\x20in\x20the\x20template\x20build_notes.\x20A\x20single-slot\x20arb-refund\x20guard\x20is\x20'+'unreachable\x20by\x20construction\x20(F-02).'}];}function zeroAmountGuardChecks(a){const b=templateText(a),c=/zero[- ]amount|0[ -]?amount|free[^a-z]|price\s*=\s*0|amount\s*>\s*0|min_booking_amount/i['test'](b)||/no[- ]charge|gratis|complimentary/i['test'](b);if(c)return[];const d=a['guards']['some'](e=>e['host']==='machine'&&(/claimed_by|allocation|payment\s|alloc\b/i['test'](e['template_id'])||/claimed_by|allocation|payment\s|alloc\b/i['test'](e['purpose'])));if(!d)return[];return[{'rule_id':'D7-ZERO-AMOUNT-GUARD','severity':'medium','title':'Machine\x20progress\x20guards\x20may\x20depend\x20on\x20allocator\x20events\x20—\x20zero-amount\x20orders\x20deadlock','detail':'The\x20protocol\x20does\x20NOT\x20create\x20an\x20Allocation\x20for\x20a\x20zero-amount\x20order\x20(amount\x20>\x200\x20is\x20required).\x20'+'A\x20zero-amount\x20order\x20therefore\x20has\x20NO\x20claimed_by,\x20NO\x20payment\x20history,\x20and\x20NO\x20allocation\x20balance.\x20'+'This\x20template\x20carries\x20machine\x20guards\x20that\x20reference\x20allocator-dependent\x20state\x20(claimed_by\x20/\x20allocation\x20/\x20payment),\x20'+'but\x20the\x20template\x20does\x20NOT\x20explicitly\x20exclude\x20zero-amount\x20items.\x20A\x20zero-amount\x20order\x20can\x20never\x20satisfy\x20such\x20a\x20guard\x20'+'and\x20deadlocks\x20at\x20the\x20node\x20with\x20no\x20exit.','suggestion':'Either\x20(a)\x20exclude\x20zero-amount\x20items\x20explicitly\x20(e.g.\x20min_booking_amount,\x20amount\x20>\x200\x20in\x20build_notes),\x20or\x20'+'(b)\x20redesign\x20progress\x20guards\x20to\x20use\x20order-native\x20signals\x20(order.time,\x20signer,\x20progress.current,\x20Repository\x20data)\x20'+'instead\x20of\x20allocator-derived\x20state,\x20so\x20zero-amount\x20orders\x20can\x20still\x20advance.'}];}function serialClaimWindowChecks(a){const b=a['machine_shape']['some'](h=>/claim/i['test'](h['name']))||a['guards']['some'](h=>/claim/i['test'](h['purpose']));if(!b)return[];const c=a['allocator']['rows']??[],d=c['some'](h=>h['track']==='settlement'&&(h['mode']==='surplus'||h['mode']==='rate'&&h['value']===0x2710));if(!d)return[];const e=templateText(a),f=a['machine_shape']['some'](h=>/claim_window/i['test'](h['name'])),g=/serial claim[- ]window|claim_window.*serial|serial[- ]claim|claims? (is|are|always) adjudicated while the pool is intact|between checkout and payout|before (any )?release/i['test'](e);if(f&&g)return[{'rule_id':'D2-SERIAL-CLAIM-WINDOW','severity':'low','title':'Serial\x20claim\x20window\x20gates\x20the\x20full-drain\x20release\x20(ABNB2-validated\x20design)','detail':'The\x20template\x20carries\x20claim\x20machinery\x20AND\x20a\x20full-drain\x20settlement\x20group\x20(Rate\x2010000\x20/\x20Surplus),\x20'+'and\x20resolves\x20the\x20race\x20with\x20a\x20serial\x20claim_window\x20node\x20between\x20delivery\x20confirmation\x20and\x20payout:\x20'+'the\x20release\x20can\x20only\x20fire\x20after\x20the\x20window\x20closed\x20with\x20no\x20upheld\x20claim,\x20so\x20the\x20pool\x20is\x20intact\x20'+'whenever\x20money\x20moves.','suggestion':'Verify\x20the\x20release\x20guard\x20anchors\x20on\x20progress.current_time\x20of\x20the\x20claim_window\x20entry\x20'+'(witness-derived),\x20not\x20on\x20order.time\x20—\x20a\x20booking-time\x20delay\x20has\x20always\x20expired\x20before\x20'+'checkout\x20and\x20gives\x20no\x20post-delivery\x20protection.'}];return[{'rule_id':'D2-SERIAL-CLAIM-WINDOW','severity':'high','title':'Full-drain\x20release\x20can\x20fire\x20while\x20a\x20claim\x20is\x20still\x20openable\x20—\x20FCFS\x20race\x20on\x20one\x20pool\x20(FACT-ALLOC-03)','detail':'The\x20template\x20carries\x20claim\x20machinery\x20AND\x20a\x20full-drain\x20settlement\x20group\x20(Rate\x2010000\x20or\x20Surplus),\x20'+'but\x20no\x20serial\x20claim_window\x20node\x20orders\x20them:\x20the\x20payout\x20and\x20a\x20later\x20claim\x20race\x20first-come-first-served\x20'+'on\x20the\x20SAME\x20pool,\x20and\x20the\x20chain\x20has\x20no\x20holdback\x20primitive\x20(fix\x20is\x20the\x20PAID\x20sum\x20of\x20Amount\x20legs,\x20'+'allocation.move:399,540).\x20Once\x20the\x20release\x20fires,\x20a\x20claim\x20can\x20pay\x20nothing\x20from\x20the\x20pool.\x20'+'Airbnb\x20mainnet\x20audit\x202026-10-07:\x20the\x20parallel\x20payout/claim\x20design\x20paid\x20the\x20host\x20in\x20full\x20and\x20left\x20'+'the\x20claim\x20window\x20with\x20an\x20empty\x20pool.','suggestion':'Insert\x20a\x20SERIAL\x20claim_window\x20node\x20between\x20delivery\x20confirmation\x20and\x20payout\x20(ABNB2-validated):\x20'+'checkout\x20→\x20claim_window\x20→\x20payout,\x20with\x20exactly\x20two\x20exits\x20—\x20FileClaim\x20(inside\x20the\x20window,\x20'+'Clock\x20<=\x20current_time(claim_window)\x20+\x20claim_window_days)\x20and\x20ReleaseNoClaim\x20(window\x20elapsed).\x20'+'Gate\x20the\x20release\x20allocator\x20on\x20the\x20post-window\x20node,\x20and\x20give\x20a\x20denied\x20claim\x20its\x20own\x20release\x20'+'forward\x20so\x20no\x20stop\x20node\x20holds\x20funds.'}];}function syntheticMachine(a){const b=a['machine_shape']['map'](e=>({'name':e['name'],'description':e['role'],'operator':e['operator']})),c=[],d=(e,f)=>[{'name':e,'weight':0x1,'named_operator':f==='order_payer'?'':'order_holder'}];b['length']>0x0&&c['push']({'prev_node':'','next_node':b[0x0]['name'],'threshold':0x1,'forwards':d('enter_'+b[0x0]['name'],b[0x0]['operator'])});for(let e=0x0;e<b['length']-0x1;e++){const f=b[e]['name'],g=b[e+0x1];if(BRANCH_STATE_REGEX['test'](g['name']))continue;c['push']({'prev_node':f,'next_node':g['name'],'threshold':0x1,'forwards':d(f+'_to_'+g['name'],g['operator'])});}if(b['length']>0x0)for(const h of b){BRANCH_STATE_REGEX['test'](h['name'])&&c['push']({'prev_node':b[0x0]['name'],'next_node':h['name'],'threshold':0x1,'forwards':d('to_'+h['name'],h['operator'])});}return{'nodes':b,'pairs':c};}function singleNodeGraph(a){return{'network':ENTRYPOINT['Testnet'],'seed':a['id'],'builtAt':Date['now'](),'nodes':new Map([[a['id'],a]]),'edges':[],'out':new Map(),'inc':new Map(),'gaps':[],'truncations':[],'rpcReport':{'batches':0x0,'byChannel':{'objects':0x0,'keyedFields':0x0,'tables':0x0,'events':0x0},'dedupHits':0x0},'budgetExhausted':{}};}function analyzerFindings(a){const b=makeProposalNode('machine',syntheticMachine(a)),c=singleNodeGraph(b),d=buildViewport(c,c['seed'],'neutral');return runNodeAnalyzers(d,[machineRuleNodeAnalyzer,allocationRuleNodeAnalyzer]);}const SEVERITY_ORDER={'low':0x0,'medium':0x1,'high':0x2,'critical':0x3},ONEWAY_GATE_REGEX=/dispute[a-z]*\s*(?:count|len(?:gth)?)?[^.;:\n]{0,24}===?\s*0\b/gi,ONEWAY_NEGATION_REGEX=/\b(?:never|do\s+not|don'?t|not|avoid|instead|substitute|one-way\s+door|welds?|append-only|rather\s+than)\b/i;function onewayDisputeChecks(a){const b=[...a['guards']['map'](d=>['guard\x20'+d['template_id'],d['purpose']]),...(a['allocator']['rows']??[])['map']((d,e)=>['allocator\x20row\x20'+e,d['note']??'']),['allocator\x20description',a['allocator']['description']],...a['build_notes']['map']((d,e)=>['build\x20note\x20'+e,d]),...a['trust_mechanisms']['map']((d,e)=>['trust\x20mechanism\x20'+e,d])],c=[];for(const [d,e]of b){if(!e)continue;ONEWAY_GATE_REGEX['lastIndex']=0x0;for(let f=ONEWAY_GATE_REGEX['exec'](e);f!==null;f=ONEWAY_GATE_REGEX['exec'](e)){const g=e['slice'](Math['max'](0x0,f['index']-0x5a),f['index']+f[0x0]['length']+0x5a);if(ONEWAY_NEGATION_REGEX['test'](g))continue;c['push'](d+':\x20\x22'+f[0x0]['trim']()+'\x22');}}if(c['length']===0x0)return[];return[{'rule_id':'R-ONEWAY-DISPUTE','severity':'critical','title':'Dispute-count\x20gate\x20on\x20an\x20append-only\x20vector\x20—\x20the\x20first\x20filing\x20welds\x20the\x20rail\x20shut','detail':'Order.dispute\x20only\x20grows\x20(the\x20filing\x20entry\x20appends;\x20nothing\x20ever\x20removes).\x20A\x20guard\x20gated\x20on\x20'+'\x22dispute\x20count\x20==\x200\x22\x20is\x20monotone-false\x20after\x20the\x20first\x20case,\x20so\x20one\x20filing\x20permanently\x20closes\x20the\x20'+'gated\x20rail\x20and\x20strands\x20the\x20escrow\x20—\x20verified\x20on\x20mainnet\x20(az-mn-261007\x20T5:\x20the\x20reviewed\x20order\x20walked\x20'+'case\x20->\x20ruling\x20->\x20payout\x20and\x20its\x202.38\x20principal\x20froze\x20with\x20no\x20exit).\x20Offending\x20surfaces:\x20'+c['join'](';\x20')+'.','suggestion':'Gate\x20on\x20the\x20PAYOUT\x20state\x20instead:\x20order.claimed_by\x20via\x20query\x201570\x20—\x20some\x20==\x20false\x20blocks\x20the\x20refund\x20'+'rail\x20only\x20after\x20an\x20award\x20ACTUALLY\x20paid,\x20and\x20the\x20paired\x20merchant-recovery\x20allocator\x20(some\x20==\x20true)\x20'+'keeps\x20the\x20awarded\x20order\x27s\x20escrow\x20exit.\x20Never\x20substitute\x20dispute\x20count\x20==\x200\x20(append-only\x20one-way\x20door).'}];}const ARB_REFERENCE_REGEX=/\barbitration\b|\barbitrator\b|compensation[ -]fund|\barb\.|\bruling\b/i;function noEscrowExitChecks(a){const b=a['allocator']['rows']??[];if(!b['some'](d=>d['track']==='refund'&&d['recipient']==='guard_identifier'))return[];const c=templateText(a,b['map'](d=>d['note']??''));if(!ARB_REFERENCE_REGEX['test'](c))return[];if(/claimed_by/i['test'](c))return[];return[{'rule_id':'R-NO-ESCROW-EXIT','severity':'high','title':'Refund\x20rail\x20never\x20reads\x20the\x20arbitration\x20payout\x20state\x20—\x20double-pay\x20and\x20stranded-escrow\x20hazards','detail':'The\x20template\x20declares\x20an\x20order-anchored\x20refund\x20rail\x20and\x20references\x20arbitration,\x20but\x20no\x20guard\x20design,\x20'+'row\x20note,\x20or\x20build\x20note\x20reads\x20order.claimed_by\x20(query\x201570)\x20—\x20the\x20payout\x20state.\x20After\x20a\x20compensation\x20'+'award\x20pays:\x20the\x20refund\x20rail\x20cannot\x20block\x20(the\x20compensated\x20order\x20still\x20drains\x20the\x20escrow\x20—\x20D-BUG-2\x20'+'double-pay),\x20and\x20no\x20merchant-recovery\x20allocator\x20is\x20declared,\x20so\x20the\x20awarded\x20order\x27s\x20escrow\x20principal\x20'+'has\x20no\x20exit\x20(mainnet\x20az-mn-261007\x20T5:\x202.38\x20stranded).','suggestion':'Gate\x20the\x20refund\x20guard\x20on\x20order.claimed_by\x20some\x20==\x20false\x20(query\x201570)\x20and\x20PAIR\x20a\x20merchant-recovery\x20'+'allocator\x20whose\x20guard\x20asserts\x20order.claimed_by\x20some\x20==\x20true\x20plus\x20order.service\x20binding\x20and\x20the\x20'+'qualifying\x20node\x20—\x20exactly\x20one\x20of\x20the\x20two\x20legs\x20can\x20ever\x20pass\x20(ESCROW\x20EXIT\x20INVARIANT).'}];}function allocReplayChecks(a){const b=a['allocator']['rows']??[];if(b['length']===0x0)return[];if(a['allocator']['once_per_order']===!![])return[];if(poolPeriodCount(a)!==undefined)return[];const c=new Map();for(const e of b){const f=e['guard_key']??'';c['set'](f,[...c['get'](f)??[],e]);}const d=[];for(const [h,j]of c){if(j['some'](n=>n['mode']==='surplus'))continue;const k=j['filter'](n=>n['mode']==='amount');let l=0x0;for(const n of j)if(n['mode']==='rate')l+=Number(n['value'])||0x0;if(k['length']===0x0&&l>=0x2710)continue;const m=h?'guard\x20\x27'+h+'\x27':'ungrouped\x20rows';k['length']>0x0&&d['push']('fixed-Amount\x20row(s)\x20under\x20'+m+':\x20'+k['map'](o=>o['track']+'/'+(o['recipient_key']??o['recipient']))['join'](',\x20')),l>0x0&&l<0x2710&&d['push']('Rate\x20leg\x20under\x20'+m+'\x20summing\x20'+l+'\x20<\x2010000');}if(d['length']===0x0)return[];return[{'rule_id':'R-ALLOC-REPLAY','severity':'high','title':'Residual-capable\x20rails\x20without\x20a\x20once-slot\x20—\x20replay\x20protection\x20is\x20only\x20the\x20drained-balance\x20side\x20effect','detail':'The\x20allocator\x20declares\x20'+d['join']('\x20and\x20')+'\x20but\x20sets\x20no\x20once_per_order\x20replay\x20slot.\x20The\x20trigger\x20'+'guard\x20can\x20be\x20satisfied\x20repeatedly,\x20and\x20each\x20run\x20pays\x20from\x20any\x20remaining\x20balance:\x20a\x20replayed\x20alloc\x20on\x20a\x20'+'drained\x20pool\x20aborts\x20\x27Insufficient\x20balance\x27\x20—\x20the\x20guard\x20clauses\x20themselves\x20PASS\x20(the\x20once-protection\x20is\x20'+'the\x20zero\x20balance,\x20not\x20a\x20consumed-once\x20flag).\x20Any\x20surplus\x20leg\x20that\x20leaves\x20balance,\x20or\x20a\x20later\x20re-deposit\x20'+'into\x20the\x20Allocation,\x20re-enables\x20payout\x20(mainnet\x20az-mn-261007\x20N5).','suggestion':'Declare\x20allocator.once_per_order=true\x20so\x20generation\x20registers\x20the\x20ONCE-FOR-OBJECT\x20submission\x20slot\x20'+'(identifier\x20254\x20—\x20the\x20chain\x20derives\x20the\x20slot\x20key\x20from\x20payment_info.for_object\x20and\x20a\x20replay\x20aborts\x20with\x20'+'code\x2016\x20regardless\x20of\x20submitted\x20bytes;\x20use\x20identifier\x20255\x20with\x20a\x20\x27period-<N>\x27\x20key\x20only\x20for\x20rails\x20that\x20'+'legitimately\x20run\x20once\x20per\x20period).\x20Alternatively\x20make\x20every\x20leg\x20exhaust\x20its\x20pool\x20(pure\x20Rate\x2010000\x20or\x20a\x20'+'Surplus\x20sweep)\x20so\x20no\x20residual\x20can\x20be\x20replayed.'}];}function draftVoidChecks(a){const b=a['machine_shape']??[];if(b['length']===0x0)return[];if(!b['some'](e=>(e['from']??[])['length']>0x0))return[];const c=f=>{const g=[];for(const h of b){for(const j of h['from']??[]){const k=typeof j==='string'?j:j?.['prev'];if(k!==f)continue;const l=typeof j==='object'&&j?.['operator']?j['operator']:h['operator']??'merchant';g['push']({'target':h,'op':l});}}return g;},d=[];for(const e of b){if(!/escrow/i['test'](e['role']??''))continue;if(/award|pays the (host|seller|creator|merchant|provider)/i['test'](e['role']??''))continue;const f=c(e['name']),g=f['some'](({target:h,op:j})=>j==='order_payer'&&h['semantic_role']==='cancelled');if(g)continue;d['push'](f['length']===0x0?'\x27'+e['name']+'\x27\x20has\x20NO\x20outgoing\x20forward\x20at\x20all\x20(entry\x20dead-end)':'\x27'+e['name']+'\x27\x20exits\x20only\x20via\x20'+f['map'](({target:h,op:j})=>h['name']+'['+j+']')['join'](',\x20'));}if(d['length']===0x0)return[];return[{'rule_id':'R-DRAFT-VOID','severity':'high','title':'Escrowed\x20node\x20without\x20a\x20buyer-side\x20void\x20hop\x20—\x20abandoned\x20orders\x20strand\x20the\x20escrow','detail':'Buy\x20escrows\x20atomically,\x20so\x20the\x20money\x20is\x20pooled\x20from\x20the\x20moment\x20the\x20order\x20exists.\x20'+d['join'](';\x20')+'\x20—\x20none\x20of\x20these\x20routes\x20is\x20an\x20order-payer\x20hop\x20into\x20a\x20cancelled\x20'+'endpoint,\x20so\x20a\x20buyer\x20who\x20abandons\x20or\x20fails\x20mid-order\x20(transport\x20error,\x20second\x20thoughts,\x20'+'a\x20ghost\x20order)\x20has\x20funds\x20locked\x20with\x20no\x20single-hop\x20exit\x20(mainnet\x20az-mn-261007\x20G2:\x20the\x20'+'deployed\x20machine\x27s\x20draft\x20node\x20had\x20only\x20the\x20entry\x20forward;\x20voiding\x20required\x20Enter\x20->\x20'+'CancelBeforePayment).','suggestion':'Add\x20an\x20order-payer\x20forward\x20from\x20every\x20escrowed\x20node\x20to\x20the\x20template\x27s\x20cancelled\x20endpoint\x20'+'(e.g.\x20\x27paid\x20->\x20closed_cancel\x27,\x20operator\x20\x27order_payer\x27)\x20gated\x20by\x20the\x20cancel\x20guard;\x20the\x20refund\x20'+'rail\x20must\x20stay\x20mounted\x20—\x20escrow\x20is\x20funded\x20at\x20order_new,\x20not\x20at\x20first\x20forward.'}];}const DELIVERY_SURFACE_REGEX=/\b(ship(?:s|ping|ped|ment)?|tracking|courier|parcel|pickup|check[- ]?in|hand[- ]?over|redeem(?:s|ed|ption)?)\b/i,REQINFO_SURFACE_REGEX=/required[_ ]?info|customer_required|\b1572\b|required_info_evidence_gate/i;function requiredInfoGateChecks(a){const b=a['machine_shape']['filter'](c=>DELIVERY_SURFACE_REGEX['test'](c['name']+'\x20'+c['role']))['map'](c=>'\x27'+c['name']+'\x27\x20('+c['role']+')');if(b['length']===0x0)return[];if(REQINFO_SURFACE_REGEX['test'](templateText(a)))return[];return[{'rule_id':'R-REQINFO-GATE','severity':'high','title':'Fulfilment\x20flow\x20never\x20enforces\x20buyer\x20required\x20info\x20—\x20Service.customer_required\x20is\x20declarative-only','detail':'The\x20on-chain\x20purchase\x20entry\x20never\x20reads\x20Service.customer_required,\x20so\x20an\x20order\x20that\x20skips\x20every\x20'+'required\x20field\x20still\x20creates.\x20Fulfilment\x20surfaces\x20that\x20physically\x20hand\x20over\x20goods\x20or\x20need\x20to\x20reach\x20'+'the\x20buyer\x20—\x20'+b['join'](';\x20')+'\x20—\x20are\x20the\x20only\x20points\x20where\x20that\x20obligation\x20can\x20be\x20'+'enforced\x20on\x20chain,\x20yet\x20the\x20template\x20declares\x20no\x20required_info\x20surface\x20anywhere\x20(no\x20'+'pattern.required_info_evidence_gate,\x20no\x20order.required_info\x201572\x20reference\x20in\x20any\x20guard\x20purpose\x20'+'or\x20build\x20note).','suggestion':'Mount\x20pattern.required_info_evidence_gate\x20on\x20the\x20fulfilment\x20forward:\x20gate\x20order.required_info\x20some\x20'+'(1572)\x20presence\x20FIRST\x20—\x20a\x20bare\x201573\x20value\x20read\x20aborts\x20while\x20the\x20Option\x20is\x20empty.\x20Presence-only\x20is\x20'+'the\x20right\x20default:\x20the\x20recorded\x20value\x20is\x20unvalidated\x20buyer\x20input\x20and\x20carries\x20no\x20on-chain\x20meaning,\x20'+'so\x20treat\x20the\x20merchant\x27s\x20confirming\x20forward\x20(not\x20the\x20recorded\x20address)\x20as\x20the\x20acceptance\x20basis.'}];}export function scanTemplate(a){const b=[...staticChecks(a),...guardRefChecks(a),...fundAnchorChecks(a),...periodicReleaseChecks(a),...timeWindowAnchorChecks(a),...signerRefundChecks(a),...orderAnchorDeclarationChecks(a),...topologyChecks(a),...reachabilityChecks(a),...compoundPayoutChecks(a),...surplusTrackChecks(a),...amountDeadlockChecks(a),...cancelCoverageChecks(a),...redundGuardObjectMismatchChecks(a),...zeroAmountGuardChecks(a),...serialClaimWindowChecks(a),...onewayDisputeChecks(a),...noEscrowExitChecks(a),...allocReplayChecks(a),...draftVoidChecks(a),...requiredInfoGateChecks(a)];for(const e of analyzerFindings(a)){const g=e['severity']==='info'?'low':e['severity'];b['push']({'rule_id':e['ruleId'],'severity':g,'title':e['title'],'detail':e['detail'],'suggestion':e['suggestion']});}b['sort']((h,j)=>SEVERITY_ORDER[j['severity']]-SEVERITY_ORDER[h['severity']]);const c=b['length']>0x0?b[0x0]['severity']:'low',d=b['filter'](h=>h['severity']==='critical')['map'](h=>''+(h['rule_id']?h['rule_id']+':\x20':'')+h['title']);return{'template_id':a['id'],'risk_level':c,'passed':d['length']===0x0,'findings':b,'red_flags':d};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID}from'node:crypto';import{Config,SQLiteStorage}from'@wowok/wowok/w/local';import{query_events}from'@wowok/wowok';import{monitorEventStore}from'./EventStore.js';import{subscriptionStore}from'./SubscriptionStore.js';import{loadScopeSnapshot,resolveScope}from'./ScopeResolver.js';import{annotateBatch,backfillAnnotations}from'./EventRouter.js';import{bridgeMonitorProblems}from'./ProblemBridge.js';import{bridgeMonitorSuggestions}from'./SuggestionBridge.js';import{EVENT_MODULE_OF,MONITOR_CAPTURE_TYPES,PAYMENT_EVENT_TYPE,normalizeMonitorEvent}from'./normalize.js';import{LOOP_DEFAULTS}from'./types.js';import{goalStore}from'../goal/GoalStore.js';import{runKeeperScan as a273a,realKeeperScanDeps}from'../keeper/KeeperScan.js';import{addProblem,addSuggestion,listProblems,listSuggestions}from'../task/ProcessStore.js';const LEASE_PREFIX='mon_lease:v4:',SEED_PAGE=0x64,SEED_MAX=0x7d0,POLL_BATCH=0x32,MAX_BACKOFF_MS=0x493e0;function netKey(a){return(a||'default')['replace'](/[^a-zA-Z0-9_-]/g,'_');}function leaseKey(a){return''+LEASE_PREFIX+netKey(a);}function realDeps(){return{'store':monitorEventStore,'configStore':subscriptionStore,'storage':new SQLiteStorage(),'resolveScope':(a,b)=>resolveScope(a,b),'loadScope':a=>loadScopeSnapshot(a),'router':{'annotateBatch':annotateBatch,'backfillAnnotations':backfillAnnotations},'queryEvents':a=>query_events({'type':a['type'],'cursor':a['cursor'],'limit':a['limit'],'order':a['order'],'network':a['network']}),'defaultNetwork':()=>Config['Instance']()['network_get'](),'now':()=>Date['now'](),'pid':process['pid'],'bootId':randomUUID(),'logger':a=>console['error']('[monitor]\x20'+a),'openProblems':a=>bridgeMonitorProblems(a,{'getGoal':(b,c)=>goalStore['get'](b,c),'addProblem':addProblem,'listProblems':listProblems,'logger':b=>console['error']('[monitor]\x20'+b)}),'openSuggestions':a=>bridgeMonitorSuggestions(a,{'getGoal':(b,c)=>goalStore['get'](b,c),'addSuggestion':addSuggestion,'listSuggestions':listSuggestions,'logger':b=>console['error']('[monitor]\x20'+b)}),'runKeeperScan':(a,b)=>a273a(a,b,realKeeperScanDeps()),'setTimer':(a,b)=>setTimeout(a,b),'clearTimer':a=>clearTimeout(a)};}function newRuntime(a){return{'network':a,'started':![],'holdsLease':![],'leaseHolder':null,'timer':undefined,'ticking':![],'scope':undefined,'lastScopeRefreshAt':0x0,'pollIntervalMs':LOOP_DEFAULTS['poll_interval_ms'],'lastTickAt':0x0,'lastNewCount':0x0,'lastSummary':undefined,'consecutiveErrors':0x0,'backoffMs':0x0};}export class MonitorLoop{['deps'];['runtimes']=new Map();constructor(a){this['deps']={...realDeps(),...a??{}};}async['start'](a){let b=a&&a['length']>0x0?a:undefined;if(!b)b=[await this['deps']['defaultNetwork']()];for(const c of b){const d=netKey(c);if(this['runtimes']['has'](d)){const f=this['runtimes']['get'](d);if(f['started'])continue;f['started']=!![],this['schedule'](f,0x0);continue;}const e=newRuntime(c);e['started']=!![],this['runtimes']['set'](d,e);try{const g=await this['deps']['loadScope'](c);g&&(e['scope']=g,e['lastScopeRefreshAt']=Number(g['resolved_at'])||0x0);}catch{}this['schedule'](e,0x0);}return b;}async['stop'](a){const b=a?[netKey(a)]:[...this['runtimes']['keys']()];for(const c of b){const d=this['runtimes']['get'](c);if(!d)continue;d['started']=![];d['timer']!==undefined&&(this['deps']['clearTimer'](d['timer']),d['timer']=undefined);if(d['holdsLease']){d['holdsLease']=![];try{await this['deps']['storage']['del'](leaseKey(d['network']));}catch{}}this['runtimes']['delete'](c);}}['status'](a){const b=a?this['runtimes']['get'](netKey(a)):[...this['runtimes']['values']()][0x0];if(!b)return{'running':![],'lease_holder':null,'last_tick_at':0x0,'last_new_count':0x0,'scope_version':0x0,'backoff_ms':0x0};return{'running':b['started']&&b['holdsLease'],'lease_holder':b['leaseHolder']?b['leaseHolder']['pid']+':'+b['leaseHolder']['boot_id']:null,'last_tick_at':b['lastTickAt'],'last_new_count':b['lastNewCount'],'scope_version':b['scope']?.['version']??0x0,'backoff_ms':b['backoffMs'],...b['lastSummary']?{'last_tick':b['lastSummary']}:{}};}['kick'](a){const b=this['runtimes']['get'](netKey(a));if(!b||!b['started']||!b['holdsLease']||b['ticking'])return;if(this['deps']['now']()-b['lastTickAt']<b['pollIntervalMs'])return;void this['tick'](b['network']);}['invalidateScope'](a){const b=this['runtimes']['get'](netKey(a));if(!b)return;b['scope']=undefined,b['lastScopeRefreshAt']=0x0;}async['tick'](a){const b=netKey(a);let c=this['runtimes']['get'](b);!c&&(c=newRuntime(a),this['runtimes']['set'](b,c));if(c['ticking'])return undefined;c['ticking']=!![];const d=this['deps']['now']();try{const f=await this['deps']['configStore']['getConfig'](a),g=Number(f['loop']?.['poll_interval_ms'])||LOOP_DEFAULTS['poll_interval_ms'];c['pollIntervalMs']=g;const h=await this['acquireLease'](c,g);if(!h)return undefined;const {newCount:i,events:j}=await this['capture'](c,f),k=await this['getScope'](c,f);let l=0x0,m=[];if(i>0x0&&j['length']>0x0){const p=this['deps']['router']['annotateBatch'](j,k,f)['filter'](q=>q['rules']['length']>0x0||q['focus_hit']||q['matched_filters']['length']>0x0);p['length']>0x0&&(await this['deps']['store']['saveAnnotations'](a,p),l=p['length'],m=p);}if(m['length']>0x0&&this['deps']['openProblems'])try{await this['deps']['openProblems']({'network':a,'events':j,'annotations':m,'scope':k});}catch(q){this['deps']['logger']('monitor\x20loop:\x20problem\x20bridge\x20error\x20on\x20'+a+':\x20'+String(q?.['message']??q));}if(m['length']>0x0&&this['deps']['openSuggestions'])try{await this['deps']['openSuggestions']({'network':a,'events':j,'annotations':m,'scope':k});}catch(s){this['deps']['logger']('monitor\x20loop:\x20suggestion\x20bridge\x20error\x20on\x20'+a+':\x20'+String(s?.['message']??s));}if(this['deps']['runKeeperScan'])try{await this['deps']['runKeeperScan'](a,k);}catch(t){this['deps']['logger']('monitor\x20loop:\x20keeper\x20scan\x20error\x20on\x20'+a+':\x20'+String(t?.['message']??t));}const n=Number(f['loop']?.['scope_refresh_ms'])||LOOP_DEFAULTS['scope_refresh_ms'];if(this['deps']['now']()-c['lastScopeRefreshAt']>=n){c['lastScopeRefreshAt']=this['deps']['now']();const {snapshot:u,changed:v}=await this['deps']['resolveScope'](a,f);c['scope']=u;if(v){const w=Number(f['loop']?.['backfill_days']??LOOP_DEFAULTS['backfill_days']),x=await this['deps']['router']['backfillAnnotations'](a,this['deps']['store'],u,w,f);this['deps']['logger']('monitor\x20loop:\x20scope\x20v'+u['version']+'\x20on\x20'+a+'\x20changed\x20—\x20backfill\x20rescanned\x20'+x['rescanned']+',\x20updated\x20'+x['updated']);}}c['lastTickAt']=this['deps']['now'](),c['lastNewCount']=i,c['consecutiveErrors']=0x0,c['backoffMs']=0x0;const o={'captured':j['length'],'annotated':l,'duration_ms':this['deps']['now']()-d};return c['lastSummary']=o,o;}catch(y){const z=String(y?.['message']??y);return this['deps']['logger']('monitor\x20loop:\x20tick\x20error\x20on\x20'+a+':\x20'+z),c['consecutiveErrors']+=0x1,c['backoffMs']=Math['min'](c['pollIntervalMs']*0x2**c['consecutiveErrors'],MAX_BACKOFF_MS),undefined;}finally{c['ticking']=![],c['started']&&this['schedule'](c,c['backoffMs']>0x0?c['backoffMs']:c['pollIntervalMs']);}}['schedule'](a,b){if(a['timer']!==undefined)this['deps']['clearTimer'](a['timer']);const c=this['deps']['setTimer'](()=>{a['timer']=undefined,void this['tick'](a['network']);},Math['max'](0x0,b));c?.['unref']?.(),a['timer']=c;}async['acquireLease'](a,b){const c=leaseKey(a['network']),d=this['deps']['now']();let e;try{const i=await this['deps']['storage']['get'](c);e=i?JSON['parse'](i):undefined;}catch{e=undefined;}const f={'pid':this['deps']['pid'],'boot_id':this['deps']['bootId']},g=!!e&&e['boot_id']===f['boot_id']&&e['pid']===f['pid'],h=!e||d-Number(e['heartbeat_at']??0x0)>0x2*b;if(g||h)return await this['deps']['storage']['put'](c,JSON['stringify']({...f,'heartbeat_at':d})),a['holdsLease']=!![],a['leaseHolder']=f,!![];return a['holdsLease']=![],a['leaseHolder']={'pid':e['pid'],'boot_id':e['boot_id']},![];}async['getScope'](a,b){if(!a['scope'])try{const c=await this['deps']['loadScope'](a['network']);c&&(a['scope']=c,a['lastScopeRefreshAt']=Number(c['resolved_at'])||0x0);}catch{}if(!a['scope']){a['lastScopeRefreshAt']=this['deps']['now']();const {snapshot:d,changed:e}=await this['deps']['resolveScope'](a['network'],b);a['scope']=d;if(e){const f=Number(b['loop']?.['backfill_days']??LOOP_DEFAULTS['backfill_days']);await this['deps']['router']['backfillAnnotations'](a['network'],this['deps']['store'],d,f,b);}}return a['scope'];}async['capture'](a,b){const c=a['network'],d=await this['deps']['store']['getCursors'](c);let f=0x0;const g=[],h=[...MONITOR_CAPTURE_TYPES];if(b['events']?.[PAYMENT_EVENT_TYPE]===!![])h['push'](PAYMENT_EVENT_TYPE);for(const i of h){const j=EVENT_MODULE_OF[i];if(!j)continue;try{const k=d['cursors'][i];let l=null;if(!k){let m=null,n=0x0;while(n<SEED_MAX){const o=await this['deps']['queryEvents']({'type':i,'cursor':m,'limit':Math['min'](SEED_PAGE,SEED_MAX-n),'order':'descending','network':c}),p=(o?.['data']??[])['map'](q=>normalizeMonitorEvent(q));if(p['length']===0x0)break;if(l===null)l=p[0x0];n+=p['length'],f+=await this['deps']['store']['insert'](c,j,p),g['push'](...p);if(!o?.['hasNextPage']||!o?.['nextCursor'])break;m=o['nextCursor'];}}else{const q=await this['deps']['queryEvents']({'type':i,'cursor':k,'limit':POLL_BATCH,'order':'ascending','network':c}),r=(q?.['data']??[])['map'](s=>normalizeMonitorEvent(s));f+=await this['deps']['store']['insert'](c,j,r),g['push'](...r);if(r['length']>0x0)l=r[r['length']-0x1];}if(l?.['id']){const s=d['cursors'][i];(!s||BigInt(l['id']['eventSeq'])>BigInt(s['eventSeq']||'0'))&&(d['cursors'][i]={'eventSeq':String(l['id']['eventSeq']),'txDigest':String(l['id']['txDigest'])});}}catch(t){const u=String(t?.['message']??t);this['deps']['logger']('monitor\x20loop:\x20type\x20'+i+'\x20poll\x20error:\x20'+u),/referenced transaction/i['test'](u)&&(delete d['cursors'][i],this['deps']['logger']('monitor\x20loop:\x20type\x20'+i+'\x20cursor\x20invalid\x20—\x20dropped,\x20will\x20re-seed\x20next\x20cycle'));}}return await this['deps']['store']['saveCursors'](c,d['cursors'],this['deps']['now']()),{'newCount':f,'events':g};}}export const monitorLoop=new MonitorLoop();
|
|
1
|
+
import{randomUUID}from'node:crypto';import{Config,SQLiteStorage}from'@wowok/wowok/w/local';import{query_events}from'@wowok/wowok';import{monitorEventStore}from'./EventStore.js';import{subscriptionStore}from'./SubscriptionStore.js';import{loadScopeSnapshot,resolveScope}from'./ScopeResolver.js';import{annotateBatch,backfillAnnotations}from'./EventRouter.js';import{bridgeMonitorProblems}from'./ProblemBridge.js';import{bridgeMonitorSuggestions}from'./SuggestionBridge.js';import{EVENT_MODULE_OF,MONITOR_CAPTURE_TYPES,PAYMENT_EVENT_TYPE,normalizeMonitorEvent}from'./normalize.js';import{LOOP_DEFAULTS}from'./types.js';import{goalStore}from'../goal/GoalStore.js';import{runKeeperScan as a274a,realKeeperScanDeps}from'../keeper/KeeperScan.js';import{addProblem,addSuggestion,listProblems,listSuggestions}from'../task/ProcessStore.js';const LEASE_PREFIX='mon_lease:v4:',SEED_PAGE=0x64,SEED_MAX=0x7d0,POLL_BATCH=0x32,MAX_BACKOFF_MS=0x493e0;function netKey(a){return(a||'default')['replace'](/[^a-zA-Z0-9_-]/g,'_');}function leaseKey(a){return''+LEASE_PREFIX+netKey(a);}function realDeps(){return{'store':monitorEventStore,'configStore':subscriptionStore,'storage':new SQLiteStorage(),'resolveScope':(a,b)=>resolveScope(a,b),'loadScope':a=>loadScopeSnapshot(a),'router':{'annotateBatch':annotateBatch,'backfillAnnotations':backfillAnnotations},'queryEvents':a=>query_events({'type':a['type'],'cursor':a['cursor'],'limit':a['limit'],'order':a['order'],'network':a['network']}),'defaultNetwork':()=>Config['Instance']()['network_get'](),'now':()=>Date['now'](),'pid':process['pid'],'bootId':randomUUID(),'logger':a=>console['error']('[monitor]\x20'+a),'openProblems':a=>bridgeMonitorProblems(a,{'getGoal':(b,c)=>goalStore['get'](b,c),'addProblem':addProblem,'listProblems':listProblems,'logger':b=>console['error']('[monitor]\x20'+b)}),'openSuggestions':a=>bridgeMonitorSuggestions(a,{'getGoal':(b,c)=>goalStore['get'](b,c),'addSuggestion':addSuggestion,'listSuggestions':listSuggestions,'logger':b=>console['error']('[monitor]\x20'+b)}),'runKeeperScan':(a,b)=>a274a(a,b,realKeeperScanDeps()),'setTimer':(a,b)=>setTimeout(a,b),'clearTimer':a=>clearTimeout(a)};}function newRuntime(a){return{'network':a,'started':![],'holdsLease':![],'leaseHolder':null,'timer':undefined,'ticking':![],'scope':undefined,'lastScopeRefreshAt':0x0,'pollIntervalMs':LOOP_DEFAULTS['poll_interval_ms'],'lastTickAt':0x0,'lastNewCount':0x0,'lastSummary':undefined,'consecutiveErrors':0x0,'backoffMs':0x0};}export class MonitorLoop{['deps'];['runtimes']=new Map();constructor(a){this['deps']={...realDeps(),...a??{}};}async['start'](a){let b=a&&a['length']>0x0?a:undefined;if(!b)b=[await this['deps']['defaultNetwork']()];for(const c of b){const d=netKey(c);if(this['runtimes']['has'](d)){const f=this['runtimes']['get'](d);if(f['started'])continue;f['started']=!![],this['schedule'](f,0x0);continue;}const e=newRuntime(c);e['started']=!![],this['runtimes']['set'](d,e);try{const g=await this['deps']['loadScope'](c);g&&(e['scope']=g,e['lastScopeRefreshAt']=Number(g['resolved_at'])||0x0);}catch{}this['schedule'](e,0x0);}return b;}async['stop'](a){const b=a?[netKey(a)]:[...this['runtimes']['keys']()];for(const c of b){const d=this['runtimes']['get'](c);if(!d)continue;d['started']=![];d['timer']!==undefined&&(this['deps']['clearTimer'](d['timer']),d['timer']=undefined);if(d['holdsLease']){d['holdsLease']=![];try{await this['deps']['storage']['del'](leaseKey(d['network']));}catch{}}this['runtimes']['delete'](c);}}['status'](a){const b=a?this['runtimes']['get'](netKey(a)):[...this['runtimes']['values']()][0x0];if(!b)return{'running':![],'lease_holder':null,'last_tick_at':0x0,'last_new_count':0x0,'scope_version':0x0,'backoff_ms':0x0};return{'running':b['started']&&b['holdsLease'],'lease_holder':b['leaseHolder']?b['leaseHolder']['pid']+':'+b['leaseHolder']['boot_id']:null,'last_tick_at':b['lastTickAt'],'last_new_count':b['lastNewCount'],'scope_version':b['scope']?.['version']??0x0,'backoff_ms':b['backoffMs'],...b['lastSummary']?{'last_tick':b['lastSummary']}:{}};}['kick'](a){const b=this['runtimes']['get'](netKey(a));if(!b||!b['started']||!b['holdsLease']||b['ticking'])return;if(this['deps']['now']()-b['lastTickAt']<b['pollIntervalMs'])return;void this['tick'](b['network']);}['invalidateScope'](a){const b=this['runtimes']['get'](netKey(a));if(!b)return;b['scope']=undefined,b['lastScopeRefreshAt']=0x0;}async['tick'](a){const b=netKey(a);let c=this['runtimes']['get'](b);!c&&(c=newRuntime(a),this['runtimes']['set'](b,c));if(c['ticking'])return undefined;c['ticking']=!![];const d=this['deps']['now']();try{const f=await this['deps']['configStore']['getConfig'](a),g=Number(f['loop']?.['poll_interval_ms'])||LOOP_DEFAULTS['poll_interval_ms'];c['pollIntervalMs']=g;const h=await this['acquireLease'](c,g);if(!h)return undefined;const {newCount:i,events:j}=await this['capture'](c,f),k=await this['getScope'](c,f);let l=0x0,m=[];if(i>0x0&&j['length']>0x0){const p=this['deps']['router']['annotateBatch'](j,k,f)['filter'](q=>q['rules']['length']>0x0||q['focus_hit']||q['matched_filters']['length']>0x0);p['length']>0x0&&(await this['deps']['store']['saveAnnotations'](a,p),l=p['length'],m=p);}if(m['length']>0x0&&this['deps']['openProblems'])try{await this['deps']['openProblems']({'network':a,'events':j,'annotations':m,'scope':k});}catch(q){this['deps']['logger']('monitor\x20loop:\x20problem\x20bridge\x20error\x20on\x20'+a+':\x20'+String(q?.['message']??q));}if(m['length']>0x0&&this['deps']['openSuggestions'])try{await this['deps']['openSuggestions']({'network':a,'events':j,'annotations':m,'scope':k});}catch(s){this['deps']['logger']('monitor\x20loop:\x20suggestion\x20bridge\x20error\x20on\x20'+a+':\x20'+String(s?.['message']??s));}if(this['deps']['runKeeperScan'])try{await this['deps']['runKeeperScan'](a,k);}catch(t){this['deps']['logger']('monitor\x20loop:\x20keeper\x20scan\x20error\x20on\x20'+a+':\x20'+String(t?.['message']??t));}const n=Number(f['loop']?.['scope_refresh_ms'])||LOOP_DEFAULTS['scope_refresh_ms'];if(this['deps']['now']()-c['lastScopeRefreshAt']>=n){c['lastScopeRefreshAt']=this['deps']['now']();const {snapshot:u,changed:v}=await this['deps']['resolveScope'](a,f);c['scope']=u;if(v){const w=Number(f['loop']?.['backfill_days']??LOOP_DEFAULTS['backfill_days']),x=await this['deps']['router']['backfillAnnotations'](a,this['deps']['store'],u,w,f);this['deps']['logger']('monitor\x20loop:\x20scope\x20v'+u['version']+'\x20on\x20'+a+'\x20changed\x20—\x20backfill\x20rescanned\x20'+x['rescanned']+',\x20updated\x20'+x['updated']);}}c['lastTickAt']=this['deps']['now'](),c['lastNewCount']=i,c['consecutiveErrors']=0x0,c['backoffMs']=0x0;const o={'captured':j['length'],'annotated':l,'duration_ms':this['deps']['now']()-d};return c['lastSummary']=o,o;}catch(y){const z=String(y?.['message']??y);return this['deps']['logger']('monitor\x20loop:\x20tick\x20error\x20on\x20'+a+':\x20'+z),c['consecutiveErrors']+=0x1,c['backoffMs']=Math['min'](c['pollIntervalMs']*0x2**c['consecutiveErrors'],MAX_BACKOFF_MS),undefined;}finally{c['ticking']=![],c['started']&&this['schedule'](c,c['backoffMs']>0x0?c['backoffMs']:c['pollIntervalMs']);}}['schedule'](a,b){if(a['timer']!==undefined)this['deps']['clearTimer'](a['timer']);const c=this['deps']['setTimer'](()=>{a['timer']=undefined,void this['tick'](a['network']);},Math['max'](0x0,b));c?.['unref']?.(),a['timer']=c;}async['acquireLease'](a,b){const c=leaseKey(a['network']),d=this['deps']['now']();let e;try{const i=await this['deps']['storage']['get'](c);e=i?JSON['parse'](i):undefined;}catch{e=undefined;}const f={'pid':this['deps']['pid'],'boot_id':this['deps']['bootId']},g=!!e&&e['boot_id']===f['boot_id']&&e['pid']===f['pid'],h=!e||d-Number(e['heartbeat_at']??0x0)>0x2*b;if(g||h)return await this['deps']['storage']['put'](c,JSON['stringify']({...f,'heartbeat_at':d})),a['holdsLease']=!![],a['leaseHolder']=f,!![];return a['holdsLease']=![],a['leaseHolder']={'pid':e['pid'],'boot_id':e['boot_id']},![];}async['getScope'](a,b){if(!a['scope'])try{const c=await this['deps']['loadScope'](a['network']);c&&(a['scope']=c,a['lastScopeRefreshAt']=Number(c['resolved_at'])||0x0);}catch{}if(!a['scope']){a['lastScopeRefreshAt']=this['deps']['now']();const {snapshot:d,changed:e}=await this['deps']['resolveScope'](a['network'],b);a['scope']=d;if(e){const f=Number(b['loop']?.['backfill_days']??LOOP_DEFAULTS['backfill_days']);await this['deps']['router']['backfillAnnotations'](a['network'],this['deps']['store'],d,f,b);}}return a['scope'];}async['capture'](a,b){const c=a['network'],d=await this['deps']['store']['getCursors'](c);let f=0x0;const g=[],h=[...MONITOR_CAPTURE_TYPES];if(b['events']?.[PAYMENT_EVENT_TYPE]===!![])h['push'](PAYMENT_EVENT_TYPE);for(const i of h){const j=EVENT_MODULE_OF[i];if(!j)continue;try{const k=d['cursors'][i];let l=null;if(!k){let m=null,n=0x0;while(n<SEED_MAX){const o=await this['deps']['queryEvents']({'type':i,'cursor':m,'limit':Math['min'](SEED_PAGE,SEED_MAX-n),'order':'descending','network':c}),p=(o?.['data']??[])['map'](q=>normalizeMonitorEvent(q));if(p['length']===0x0)break;if(l===null)l=p[0x0];n+=p['length'],f+=await this['deps']['store']['insert'](c,j,p),g['push'](...p);if(!o?.['hasNextPage']||!o?.['nextCursor'])break;m=o['nextCursor'];}}else{const q=await this['deps']['queryEvents']({'type':i,'cursor':k,'limit':POLL_BATCH,'order':'ascending','network':c}),r=(q?.['data']??[])['map'](s=>normalizeMonitorEvent(s));f+=await this['deps']['store']['insert'](c,j,r),g['push'](...r);if(r['length']>0x0)l=r[r['length']-0x1];}if(l?.['id']){const s=d['cursors'][i];(!s||BigInt(l['id']['eventSeq'])>BigInt(s['eventSeq']||'0'))&&(d['cursors'][i]={'eventSeq':String(l['id']['eventSeq']),'txDigest':String(l['id']['txDigest'])});}}catch(t){const u=String(t?.['message']??t);this['deps']['logger']('monitor\x20loop:\x20type\x20'+i+'\x20poll\x20error:\x20'+u),/referenced transaction/i['test'](u)&&(delete d['cursors'][i],this['deps']['logger']('monitor\x20loop:\x20type\x20'+i+'\x20cursor\x20invalid\x20—\x20dropped,\x20will\x20re-seed\x20next\x20cycle'));}}return await this['deps']['store']['saveCursors'](c,d['cursors'],this['deps']['now']()),{'newCount':f,'events':g};}}export const monitorLoop=new MonitorLoop();
|