@wowok/agent-mcp 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/dist/config/exposure.d.ts +8 -8
  2. package/dist/config/judgment.d.ts +20 -20
  3. package/dist/config/rule-engine.d.ts +20 -20
  4. package/dist/extensions/industry-pack.js +1 -1
  5. package/dist/graph/onchain/facts.js +1 -1
  6. package/dist/graph/onchain/sdk-batch.d.ts +1 -0
  7. package/dist/graph/onchain/sdk-batch.js +1 -1
  8. package/dist/graph/onchain/sdk-dataplane.d.ts +1 -0
  9. package/dist/graph/onchain/sdk-dataplane.js +1 -1
  10. package/dist/knowledge/allocation-templates.d.ts +1 -1
  11. package/dist/knowledge/allocation-templates.js +1 -1
  12. package/dist/knowledge/arbitration-ledger.js +1 -1
  13. package/dist/knowledge/audit-rules.d.ts +1 -1
  14. package/dist/knowledge/audit-rules.js +1 -1
  15. package/dist/knowledge/builtin-templates.d.ts +1 -1
  16. package/dist/knowledge/builtin-templates.js +1 -1
  17. package/dist/knowledge/discount-threshold.d.ts +15 -0
  18. package/dist/knowledge/discount-threshold.js +1 -0
  19. package/dist/knowledge/getting-started.js +1 -1
  20. package/dist/knowledge/guard-design-patterns.js +1 -1
  21. package/dist/knowledge/guard-lint.js +1 -1
  22. package/dist/knowledge/guard-translation.js +1 -1
  23. package/dist/knowledge/index.d.ts +2 -2
  24. package/dist/knowledge/index.js +1 -1
  25. package/dist/knowledge/industry-generalizer.d.ts +38 -1
  26. package/dist/knowledge/industry-generalizer.js +1 -1
  27. package/dist/knowledge/industry-registry.js +1 -1
  28. package/dist/knowledge/industry-strategy.js +1 -1
  29. package/dist/knowledge/jsonrpc-enum.js +1 -1
  30. package/dist/knowledge/onchain-constants.d.ts +2 -2
  31. package/dist/knowledge/onchain-constants.js +1 -1
  32. package/dist/knowledge/scenario-modes.d.ts +10 -0
  33. package/dist/knowledge/strategy-manuals.d.ts +1 -1
  34. package/dist/knowledge/strategy-manuals.js +1 -1
  35. package/dist/knowledge/template-loader.d.ts +20 -0
  36. package/dist/knowledge/template-loader.js +1 -1
  37. package/dist/knowledge/template-registry.js +1 -1
  38. package/dist/knowledge/template-scanner.js +1 -1
  39. package/dist/knowledge/tools-reference.js +1 -1
  40. package/dist/monitor/MonitorLoop.js +1 -1
  41. package/dist/participation/arbitrator-interest.js +1 -1
  42. package/dist/participation/customer-interest.js +1 -1
  43. package/dist/participation/merchant-interest.js +1 -1
  44. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  45. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  46. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  47. package/dist/playbooks/service-build/mode-actions.d.ts +12 -1
  48. package/dist/playbooks/service-build/mode-actions.js +1 -1
  49. package/dist/playbooks/service-build/object-panorama.js +1 -1
  50. package/dist/playbooks/service-build/participation-radar.js +1 -1
  51. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  52. package/dist/playbooks/service-build/reverse-mapping-refund-p0-5.spec.d.ts +1 -0
  53. package/dist/playbooks/service-build/reverse-mapping-refund-p0-5.spec.js +1 -0
  54. package/dist/playbooks/service-build/reverse-mapping.js +1 -1
  55. package/dist/playbooks/service-build/semantic-graph.js +1 -1
  56. package/dist/playbooks/service-build/service-panorama.js +1 -1
  57. package/dist/playbooks/service-build/service-quote.js +1 -1
  58. package/dist/review/index.js +1 -1
  59. package/dist/role/profiles.js +1 -1
  60. package/dist/role/types.d.ts +2 -0
  61. package/dist/role/types.js +1 -1
  62. package/dist/safety/confirm-gate.js +1 -1
  63. package/dist/schema/call/allocation.d.ts +7 -7
  64. package/dist/schema/call/arbitration.d.ts +1 -1
  65. package/dist/schema/call/arbitration.js +1 -1
  66. package/dist/schema/call/base.d.ts +5 -5
  67. package/dist/schema/call/base.js +1 -1
  68. package/dist/schema/call/bridge.d.ts +5 -9
  69. package/dist/schema/call/bridge.js +1 -1
  70. package/dist/schema/call/contact.d.ts +1 -1
  71. package/dist/schema/call/demand.d.ts +1 -1
  72. package/dist/schema/call/guard.d.ts +11 -11
  73. package/dist/schema/call/handler.js +1 -1
  74. package/dist/schema/call/machine.d.ts +2 -2
  75. package/dist/schema/call/order.d.ts +1 -1
  76. package/dist/schema/call/payment.d.ts +1 -1
  77. package/dist/schema/call/permission.d.ts +1 -1
  78. package/dist/schema/call/personal.d.ts +1 -1
  79. package/dist/schema/call/progress.d.ts +1 -1
  80. package/dist/schema/call/proof.d.ts +2 -2
  81. package/dist/schema/call/repository.d.ts +1 -1
  82. package/dist/schema/call/reward.d.ts +1 -1
  83. package/dist/schema/call/semantic.js +1 -1
  84. package/dist/schema/call/service.d.ts +5 -5
  85. package/dist/schema/call/service.js +1 -1
  86. package/dist/schema/call/treasury.d.ts +1 -1
  87. package/dist/schema/common/index.js +1 -1
  88. package/dist/schema/evaluation/index.d.ts +6 -2
  89. package/dist/schema/evaluation/index.js +1 -1
  90. package/dist/schema/goal/index.d.ts +8 -8
  91. package/dist/schema/goal/planning.d.ts +15 -15
  92. package/dist/schema/industry-pack/index.d.ts +15 -0
  93. package/dist/schema/industry-pack/modes.d.ts +15 -0
  94. package/dist/schema/industry-pack/modes.js +1 -1
  95. package/dist/schema/intent-radar/index.d.ts +3 -0
  96. package/dist/schema/intent-radar/index.js +1 -1
  97. package/dist/schema/local/index.d.ts +577 -18
  98. package/dist/schema/local/index.js +1 -1
  99. package/dist/schema/messenger/index.d.ts +140 -20
  100. package/dist/schema/messenger/index.js +1 -1
  101. package/dist/schema/operations.d.ts +30 -28
  102. package/dist/schema/operations.js +1 -1
  103. package/dist/schema/persona/index.d.ts +708 -708
  104. package/dist/schema/persona/index.js +1 -1
  105. package/dist/schema/query/bi.d.ts +20 -6
  106. package/dist/schema/query/bi.js +1 -1
  107. package/dist/schema/query/index.d.ts +32 -32
  108. package/dist/schema/query/index.js +1 -1
  109. package/dist/schema/schema-query/index.d.ts +3 -3
  110. package/dist/schema/schema-version.js +1 -1
  111. package/dist/schema/watch/index.d.ts +2 -2
  112. package/dist/schema/workflow/index.d.ts +2 -2
  113. package/dist/schema-query-impl/index.js +1 -1
  114. package/dist/schemas/account_operation.output.json +6 -2
  115. package/dist/schemas/account_operation.schema.json +1 -1
  116. package/dist/schemas/bridge_operation.schema.json +2 -10
  117. package/dist/schemas/evaluation_operation.output.json +2 -0
  118. package/dist/schemas/evaluation_operation.schema.json +2 -0
  119. package/dist/schemas/index.json +7 -1
  120. package/dist/schemas/industry_pack_operation.output.json +87 -4
  121. package/dist/schemas/intent_radar.output.json +2 -0
  122. package/dist/schemas/intent_radar.schema.json +1 -0
  123. package/dist/schemas/local_cache_operation.output.json +1536 -0
  124. package/dist/schemas/local_cache_operation.schema.json +101 -0
  125. package/dist/schemas/local_mark_operation.output.json +51 -36
  126. package/dist/schemas/local_mark_operation.schema.json +1 -0
  127. package/dist/schemas/messenger_operation.schema.json +358 -35
  128. package/dist/schemas/onchain_operations.schema.json +10 -10
  129. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  130. package/dist/schemas/onchain_operations_arbitration.schema.json +3 -3
  131. package/dist/schemas/onchain_operations_payment.schema.json +1 -1
  132. package/dist/schemas/onchain_operations_reward.schema.json +1 -1
  133. package/dist/schemas/onchain_operations_service.schema.json +3 -3
  134. package/dist/schemas/onchain_operations_treasury.schema.json +1 -1
  135. package/dist/schemas/onchain_table_data.output.json +11 -0
  136. package/dist/schemas/query_toolkit.output.json +11 -4
  137. package/dist/schemas/query_toolkit.schema.json +13 -2
  138. package/dist/tools/handlers/benchmark-migration.js +1 -1
  139. package/dist/tools/handlers/bridge.js +1 -1
  140. package/dist/tools/handlers/config.js +1 -1
  141. package/dist/tools/handlers/local.d.ts +1 -0
  142. package/dist/tools/handlers/local.js +1 -1
  143. package/dist/tools/handlers/messenger.d.ts +9 -2
  144. package/dist/tools/handlers/messenger.js +1 -1
  145. package/dist/tools/handlers/name-resolution.d.ts +4 -0
  146. package/dist/tools/handlers/name-resolution.js +1 -0
  147. package/dist/tools/handlers/name-resolution.spec.d.ts +1 -0
  148. package/dist/tools/handlers/name-resolution.spec.js +1 -0
  149. package/dist/tools/handlers/onchain-name-registration.d.ts +37 -0
  150. package/dist/tools/handlers/onchain-name-registration.js +1 -0
  151. package/dist/tools/handlers/onchain-name-registration.spec.d.ts +1 -0
  152. package/dist/tools/handlers/onchain-name-registration.spec.js +1 -0
  153. package/dist/tools/handlers/onchain.d.ts +1 -0
  154. package/dist/tools/handlers/onchain.js +1 -1
  155. package/dist/tools/handlers/query.d.ts +1 -0
  156. package/dist/tools/handlers/query.js +1 -1
  157. package/dist/tools/index.js +1 -1
  158. package/dist/tools/registry/local.js +1 -1
  159. package/dist/tools/sanitize-description-roundtrip.spec.d.ts +1 -0
  160. package/dist/tools/sanitize-description-roundtrip.spec.js +1 -0
  161. package/dist/tools/sanitize-output.d.ts +1 -0
  162. package/dist/tools/sanitize-output.js +1 -1
  163. package/dist/tools/wrap.js +1 -1
  164. package/package.json +2 -2
@@ -1 +1 @@
1
- import{validateGuardData,MAX_DESCRIPTION_LENGTH,MAX_GUARD_TABLE_ITEM_LENGTH,MAX_NAME_LENGTH,ValueType}from'@wowok/wowok';import{evaluateGuardDraft}from'./guard-eval.js';import{findScene,inferSceneFromAction}from'./guard-ledger.js';import{suggestTemplateForScene}from'./guard-templates.js';import{validateGuardTreeShape}from'./guard-render.js';const VALUE_TYPE_ID_TO_NAME={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8'};function normalizeValueTypeNames(a){if(!a['table']['some'](b=>typeof b['value_type']==='number'))return a;return{...a,'table':a['table']['map'](b=>typeof b['value_type']==='number'?{...b,'value_type':VALUE_TYPE_ID_TO_NAME[b['value_type']]??String(b['value_type'])}:b)};}function deepClone(a){return JSON['parse'](JSON['stringify'](a));}function rootToString(a){return JSON['stringify'](a);}function hasSignerContext(a){const b=rootToString(a);return b['includes']('\x22Signer\x22')||b['includes']('\x22context\x22:\x22Signer\x22')||b['includes']('\x22context\x22:\x20\x22Signer\x22');}function getSubmissionEntries(a){return a['filter'](b=>b['b_submission']===!![]);}function inferValueType(a){if(typeof a==='string'){if(a['startsWith']('0x')&&a['length']>=0x3)return'Address';return'String';}if(typeof a==='number'){if(Number['isInteger'](a)){if(a>=0x0&&a<=0xff)return'U8';if(a>=0x0&&a<=0xffff)return'U16';return'U64';}return'U256';}if(typeof a==='boolean')return'Bool';if(Array['isArray'](a)){if(a['length']>0x0){const b=inferValueType(a[0x0]);if(b==='Address')return'Vec<Address>';if(b==='String')return'Vec<String>';if(b==='Bool')return'Vec<Bool>';}return'Vec<Address>';}return undefined;}function sdkIssueToDiagnostic(a){return{'code':a['code'],'message':a['message'],'severity':a['severity'],'source':'sdk','location':{'path':a['path']},'fix':{'description':'SDK\x20validation\x20failed\x20('+(a['sdk_error']??'InvalidParam')+');\x20manual\x20fix\x20required','auto_fixable':![]}};}async function checkSdkSyntax(a){const b=validateGuardTreeShape(a['root']);if(b['length']>0x0)return b['map'](f=>({'code':'G-001','message':f['message'],'severity':'error','source':'sdk','location':{'path':f['path']},'fix':{'description':'Unary\x20operators\x20(logic_not,\x20value_type,\x20vec_length,\x20calc_string_length,\x20convert_*)\x20take\x20a\x20single\x20\x27node\x27\x20child;\x20only\x20multi-operand\x20forms\x20(logic_and,\x20logic_or,\x20logic_equal,\x20logic_as_u256_*,\x20calc_number_*,\x20vec_contains_*)\x20take\x20a\x20\x27nodes\x27\x20array.','auto_fixable':![]}}));const c=a['table']['map'](f=>({'identifier':f['identifier'],'b_submission':f['b_submission']??![],'value_type':f['value_type']??'Address','value':f['value'],'name':f['name']??''}));let d;try{d=await validateGuardData({'description':a['description'],'table':c,'root':a['root'],'rely':a['rely']});}catch(f){const g=f?.['message']??String(f),h=/guard tree ([^:]+):/['exec'](g);return[{'code':'G-001','message':g,'severity':'error','source':'sdk','location':{'path':h?toJsonPointer(h[0x1]):'/root'},'fix':{'description':'Repair\x20the\x20tree\x20at\x20the\x20named\x20path:\x20unary\x20operators\x20(logic_not,\x20convert_*,\x20value_type)\x20take\x20a\x20single\x20\x27node\x27\x20child;\x20only\x20multi-operand\x20forms\x20(logic_and,\x20logic_or,\x20logic_equal,\x20calc_*,\x20vec_*)\x20take\x20\x27nodes\x27.','auto_fixable':![]}}];}return d['map'](sdkIssueToDiagnostic);}function toJsonPointer(a){const b=a['replace'](/^\/+/,'');return b['startsWith']('root')?'/'+b:'/root/'+b;}function checkSemanticErrors(a){const b=[],{table:c,root:d,binding_hint:e}=a,f=e?findScene(e['host_object']??'',e['binding_field']??''):undefined,g=getSubmissionEntries(c);if(g['length']>0x0&&d&&!hasSignerContext(d)){const h=g['some'](j=>j['value_type']==='Address'),i=f?.['id']==='service_order_allocators_guard'&&e?.['sharing_recipients']!==undefined&&e['sharing_recipients']['length']>0x0&&!e['sharing_recipients']['includes']('Signer');if(h&&!i){const j=g['filter'](k=>k['value_type']==='Address')['map'](k=>c['indexOf'](k));b['push']({'code':'LE-04','message':'Submitted\x20data\x20has\x20no\x20Signer\x20binding\x20(submission\x20forgery\x20risk)','severity':'error','source':'lint','location':{'path':j['map'](k=>'/table/'+k)['join']('\x20→\x20')},'fix':{'description':'Add\x20logic_equal(context(Signer),\x20identifier[N])\x20in\x20root\x20to\x20bind\x20the\x20submitter\x20identity','auto_fixable':![]}});}}if(f?.['id']==='arbitration_voting_guard'){const k=g['some'](l=>['U8','U16','U32','U64','U128','U256']['includes'](l['value_type']??''));if(k){const l=g['filter'](m=>['U8','U16','U32','U64','U128','U256']['includes'](m['value_type']??''))['map'](m=>c['indexOf'](m));b['push']({'code':'LE-05','message':'voting_guard\x20voting\x20weight\x20comes\x20from\x20submitted\x20data\x20(weight\x20forgery\x20risk)','severity':'error','source':'lint','location':{'path':l['map'](m=>'/table/'+m)['join']('\x20→\x20')},'fix':{'description':'Derive\x20arbitrator\x20weights\x20from\x20the\x20Arb\x20object\x20via\x20witness\x20(e.g.\x20105\x20TypeArbArbitration)\x20rather\x20than\x20submitting\x20them\x20directly','auto_fixable':![]}});}}if(f?.['id']==='gen_passport_guard'||e?.['action']==='gen_passport'){const m=rootToString(d);if(m['includes']('1167')||m['includes']('repository.data')){const n=m['includes']('quote_guard');n&&b['push']({'code':'LE-06','message':'repository.data\x20query\x20with\x20quote_guard:\x20rigid\x20verification\x20requirement\x20—\x20ensure\x20Passport\x20includes\x20quote_guard\x20verification\x20with\x20necessary\x20submissions\x20(e.g.,\x20Payment\x20proof)','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'Ensure\x20the\x20quote_guard\x20is\x20verified:\x20user\x20submits\x20Payment\x20via\x20Passport,\x20quote_guard\x20verifies\x20Payment\x20fields,\x20repository\x20data\x20query\x20passes','auto_fixable':![]}});}}if(e?.['host_object']&&f){const o=e['host_object'],p=c['filter'](q=>!q['b_submission']&&q['value_type']==='Address'&&typeof q['value']==='string'&&q['value']['startsWith']('0x')&&q['object_type']===o);if(p['length']>0x0){const q=p['map'](r=>c['indexOf'](r));b['push']({'code':'LE-07','message':'Circular\x20reference\x20uses\x20an\x20address\x20rather\x20than\x20a\x20name\x20(Host\x20Object\x20may\x20not\x20be\x20published\x20yet\x20when\x20the\x20Guard\x20is\x20created)','severity':'error','source':'lint','location':{'path':q['map'](r=>'/table/'+r+'/value')['join']('\x20→\x20')},'fix':{'description':'Change\x20value\x20from\x20an\x20address\x20to\x20an\x20object\x20name\x20(e.g.\x20\x22service1\x22);\x20the\x20SDK\x20will\x20resolve\x20it\x20to\x20an\x20address\x20after\x20the\x20Host\x20Object\x20is\x20published','auto_fixable':![]}});}}return b;}function checkSyntaxHints(a){const b=[],{table:c}=a;(!a['description']||a['description']['trim']()==='')&&b['push']({'code':'SH-01','message':'description\x20is\x20missing\x20or\x20empty','severity':'info','source':'lint','location':{'path':'/description'},'fix':{'description':'Add\x20a\x20description,\x20e.g.\x20\x27Service\x20buy_guard:\x20whitelist\x20validation\x27','auto_fixable':!![]}});for(let d=0x0;d<c['length'];d++){const e=c[d];(!e['name']||e['name']['trim']()==='')&&b['push']({'code':'SH-03','message':'table['+d+']\x20is\x20missing\x20name','severity':'warning','source':'lint','location':{'path':'/table/'+d+'/name'},'fix':{'description':'Add\x20a\x20name,\x20e.g.\x20\x22data\x20entry\x20'+e['identifier']+'\x22','auto_fixable':!![]}});}for(let f=0x0;f<c['length'];f++){const g=c[f];!g['value_type']&&b['push']({'code':'SH-05','message':'table['+f+']\x20is\x20missing\x20value_type','severity':'warning','source':'lint','location':{'path':'/table/'+f+'/value_type'},'fix':{'description':'Infer\x20value_type\x20from\x20value\x20(e.g.\x20Address/String/U64,\x20etc.)','auto_fixable':!![]}});}c['length']>MAX_GUARD_TABLE_ITEM_LENGTH&&b['push']({'code':'SH-07','message':'table\x20entry\x20count\x20'+c['length']+'\x20exceeds\x20the\x20maximum\x20limit\x20'+MAX_GUARD_TABLE_ITEM_LENGTH,'severity':'error','source':'lint','location':{'path':'/table'},'fix':{'description':'Slim\x20down\x20the\x20table\x20by\x20merging\x20similar\x20entries,\x20or\x20split\x20into\x20multiple\x20Guards\x20+\x20rely','auto_fixable':![]}});for(let h=0x0;h<c['length'];h++){c[h]['b_submission']===undefined&&b['push']({'code':'SH-10','message':'table['+h+']\x20b_submission\x20is\x20missing','severity':'info','source':'lint','location':{'path':'/table/'+h+'/b_submission'},'fix':{'description':'Set\x20to\x20false\x20(constant)\x20or\x20true\x20(submitted\x20data)','auto_fixable':!![]}});}for(let j=0x0;j<c['length'];j++){const k=c[j];k['b_submission']===!![]&&k['value']!==undefined&&k['value']!==null&&b['push']({'code':'SH-11','message':'table['+j+']\x20has\x20a\x20redundant\x20value\x20field\x20on\x20b_submission=true\x20entry\x20(the\x20verifier\x20supplies\x20the\x20value\x20at\x20runtime;\x20this\x20value\x20is\x20ignored\x20by\x20BCS\x20encoding\x20and\x20wastes\x20gas)','severity':'warning','source':'lint','location':{'path':'/table/'+j+'/value'},'fix':{'description':'Remove\x20the\x20value\x20field\x20—\x20it\x20is\x20ignored\x20for\x20b_submission=true\x20entries','auto_fixable':!![]}});}return b;}function checkSuggestions(a){const b=[],{root:c,binding_hint:d,table:e,description:f}=a;if(c){const i=rootToString(c);if(i['includes']('vec_contains_address')&&i['includes']('Signer'))b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P04\x20(whitelist\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Refer\x20to\x20the\x20P04\x20Pattern\x20to\x20ensure\x20best\x20practices','auto_fixable':![]}});else{if(i['includes']('logic_equal')&&i['includes']('Signer')){const j=e['some'](k=>!k['b_submission']&&k['value_type']==='Address'&&typeof k['value']==='string'&&k['value']['length']>0x0);j&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P04\x20(whitelist\x20validation\x20—\x20single-address\x20variant)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'P04\x20single-address\x20form;\x20for\x20multi-address\x20scenarios,\x20consider\x20vec_contains_address','auto_fixable':![]}});}}(i['includes']('logic_as_u256_greater')||i['includes']('logic_as_u256_lesser'))&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P02\x20(numeric\x20threshold\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Suitable\x20for\x20amount/quantity\x20threshold\x20validation\x20scenarios','auto_fixable':![]}}),i['includes']('convert_witness')&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P09\x20(witness-derived\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Suitable\x20for\x20cross-object\x20relationship\x20validation\x20(e.g.\x20Order→Progress)','auto_fixable':![]}});}if(d?.['action']){const k=['buy','forward','allocate','claim_reward','vote','dispute','write_repository','submit_progress','gen_passport'];if(k['includes'](d['action'])){const l=inferSceneFromAction(d['action']);if(l){const m=suggestTemplateForScene(l['id']);m&&b['push']({'code':'SG-02','message':'Recommended\x20scene\x20template:\x20'+m['name'],'severity':'hint','source':'lint','location':{'path':'/'},'fix':{'description':'Refer\x20to\x20template\x20'+m['id']+'\x20('+m['example_use_case']+')','auto_fixable':![]}});}}}const g=n=>new TextEncoder()['encode'](n)['length'],h=getSubmissionEntries(e);for(const [n,o]of e['entries']()){const p=o['name']??'';if(p['length']===0x0)continue;if(g(p)>MAX_NAME_LENGTH)b['push']({'code':'SG-03','message':'table['+n+']\x20name\x20is\x20'+g(p)+'\x20BCS\x20characters,\x20maximum\x20is\x20'+MAX_NAME_LENGTH+'.\x20Use\x20a\x20short\x20identifier\x20(e.g.\x20\x27order_id\x27,\x20\x27delivery_node\x27);\x20the\x20human-readable\x20explanation\x20belongs\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field','severity':'warning','source':'lint','location':{'path':'/table/'+n+'/name'},'fix':{'description':'Shorten\x20the\x20name\x20to\x20'+MAX_NAME_LENGTH+'\x20BCS\x20characters\x20or\x20fewer','auto_fixable':![]}});else p['toLowerCase']()['startsWith']('0x')&&b['push']({'code':'SG-03','message':'table['+n+']\x20name\x20must\x20not\x20start\x20with\x20\x220x\x22\x20(reserved\x20for\x20object\x20IDs)','severity':'warning','source':'lint','location':{'path':'/table/'+n+'/name'},'fix':{'description':'Rename\x20the\x20entry\x20without\x20the\x200x\x20prefix','auto_fixable':![]}});}if(h['length']>0x0){const q=(f??'')['trim']();q['length']<0xa&&b['push']({'code':'SG-03','message':'This\x20Guard\x20accepts\x20submitted\x20data\x20('+h['length']+'\x20table\x20'+(h['length']===0x1?'entry':'entries')+'\x20with\x20b_submission=true)\x20but\x20its\x20description\x20is\x20too\x20short\x20for\x20a\x20verifier\x20to\x20know\x20what\x20to\x20submit.\x20Explain\x20the\x20expected\x20submitted\x20data\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field,\x20e.g.\x20\x27user-submitted\x20operation\x20type\x20(return/damage)\x27','severity':'info','source':'lint','location':{'path':'/'},'fix':{'description':'Explain\x20the\x20expected\x20submitted\x20data\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field','auto_fixable':![]}});}if(c){const r=rootToString(c),s=r['includes']('proof.signer'),t=r['includes']('proof.time'),u=r['includes']('calc_string_length'),v=h['some'](w=>w['value_type']==='String');if(s&&t)b['push']({'code':'SG-04','message':'Strict-mode\x20privacy-delivery\x20guard\x20detected\x20(proof.signer\x20+\x20proof.time).\x20'+'Recommended\x20three\x20conditions:\x20Signer==proof.signer\x20(submitter\x20accountability),\x20'+'proof.time>order.time\x20(freshness),\x20order.service==service\x20(project\x20binding).\x20'+'No\x20content\x20verification\x20—\x20only\x20submission\x20responsibility\x20(\x27whoever\x20benefits\x20bears\x20the\x20burden\x20of\x20proof\x27).','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'Ensure\x20all\x20three\x20conditions\x20are\x20present\x20(logic_and).\x20Refer\x20to\x20template\x20tpl_forward_privacy_delivery_proof.\x20'+'Query\x20IDs:\x20proof.signer=1958,\x20proof.time=1960,\x20order.time=1574,\x20order.service=1563.','auto_fixable':![]}});else u&&v&&b['push']({'code':'SG-04','message':'Broad-mode\x20privacy-delivery\x20guard\x20detected\x20(String\x20submission\x20+\x20length\x20check,\x20e.g.\x20Merkle\x20Root\x20length\x20==\x2066).\x20'+'This\x20trusts\x20the\x20submitter\x27s\x20honesty;\x20the\x20counterparty\x20can\x20dispute\x20by\x20checking\x20their\x20own\x20Messenger\x20conversation.\x20'+'Suitable\x20as\x20an\x20arbitration\x20basis,\x20not\x20a\x20fund-flow\x20gate.','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'For\x20stronger\x20assurance,\x20consider\x20strict\x20mode:\x20submit\x20a\x20Proof\x20object\x20address\x20(from\x20messenger.submitChainProof)\x20+\x20'+'Order\x20address,\x20then\x20verify\x20proof.signer/proof.time/order.service.\x20See\x20template\x20tpl_forward_privacy_delivery_proof.','auto_fixable':![]}});}return b;}export function autoFixGuard(a){const b=deepClone(a),c=[];(!b['description']||b['description']['trim']()==='')&&(b['description']='Guard\x20(table:\x20'+b['table']['length']+'\x20items,\x20root:\x20'+(b['root']?.['type']??'unknown')+')',c['push']({'diagnostic_code':'SH-01','description':'Fill\x20in\x20default\x20description','after':b['description'],'path':'/description'}));if(b['description']&&b['description']['length']>MAX_DESCRIPTION_LENGTH){const f=b['description'];b['description']=b['description']['substring'](0x0,MAX_DESCRIPTION_LENGTH),c['push']({'diagnostic_code':'G-001','description':'Truncate\x20description\x20to\x20'+MAX_DESCRIPTION_LENGTH+'\x20characters','before':f['length']+'\x20characters','after':b['description']['length']+'\x20characters','path':'/description'});}for(let g=0x0;g<b['table']['length'];g++){const h=b['table'][g];(!h['name']||h['name']['trim']()==='')&&(h['name']='data\x20entry\x20'+h['identifier'],c['push']({'diagnostic_code':'SH-03','description':'table['+g+']\x20fill\x20in\x20name','after':h['name'],'path':'/table/'+g+'/name'}));}for(let j=0x0;j<b['table']['length'];j++){const k=b['table'][j];if(!k['value_type']&&k['value']!==undefined&&k['value']!==null){const l=inferValueType(k['value']);l&&(k['value_type']=l,c['push']({'diagnostic_code':'SH-05','description':'table['+j+']\x20infer\x20value_type','after':l,'path':'/table/'+j+'/value_type'}));}}const d=new Map();let e=0x0;for(let m=0x0;m<b['table']['length'];m++){const n=b['table'][m];if(!d['has'](n['identifier']))d['set'](n['identifier'],e),n['identifier']!==e&&c['push']({'diagnostic_code':'G-007','description':'table['+m+']\x20identifier\x20'+n['identifier']+'\x20→\x20'+e,'before':String(n['identifier']),'after':String(e),'path':'/table/'+m+'/identifier'}),n['identifier']=e,e++;else{const o=n['identifier'];n['identifier']=e,d['set'](o,e),c['push']({'diagnostic_code':'G-007','description':'table['+m+']\x20identifier\x20'+o+'\x20duplicate\x20→\x20reallocated\x20to\x20'+e,'before':String(o),'after':String(e),'path':'/table/'+m+'/identifier'}),e++;}}for(let p=0x0;p<b['table']['length'];p++){const q=b['table'][p];q['b_submission']===undefined&&(q['b_submission']=![],c['push']({'diagnostic_code':'SH-10','description':'table['+p+']\x20b_submission\x20default\x20set\x20to\x20false','after':'false','path':'/table/'+p+'/b_submission'}));}if(b['rely']?.['guards']&&b['rely']['guards']['length']>0x0){const r=[...new Set(b['rely']['guards'])];r['length']!==b['rely']['guards']['length']&&(c['push']({'diagnostic_code':'G-009','description':'rely\x20deduplicate:\x20'+b['rely']['guards']['length']+'\x20→\x20'+r['length'],'before':JSON['stringify'](b['rely']['guards']),'after':JSON['stringify'](r),'path':'/rely/guards'}),b['rely']['guards']=r);}for(let s=0x0;s<b['table']['length'];s++){const t=b['table'][s];if(t['b_submission']===!![]&&t['value']!==undefined&&t['value']!==null){const u=JSON['stringify'](t['value']);delete t['value'],c['push']({'diagnostic_code':'SH-11','description':'table['+s+']\x20remove\x20redundant\x20value\x20on\x20b_submission=true\x20entry','before':u,'after':'(removed)','path':'/table/'+s+'/value'});}}return{'fixed':b,'actions':c};}export async function lintGuard(a,b){const c=b?.['auto_fix']??!![],d=normalizeValueTypeNames(a),{table:e,root:f,rely:g,binding_hint:h}=d,i=[];let j;const k=await checkSdkSyntax(d);i['push'](...k);const l=checkSemanticErrors(d);i['push'](...l);const m=checkSyntaxHints(d);i['push'](...m);let n,o=[];if(c){const {fixed:w,actions:x}=autoFixGuard(d);x['length']>0x0&&(n=w,o=x);}if(e['length']>0x0&&f){const y=h?findScene(h['host_object']??'',h['binding_field']??''):undefined,z=e['map'](B=>({'identifier':B['identifier'],'b_submission':B['b_submission']??![],'value_type':B['value_type']??'Address','value':B['value'],'name':B['name'],'object_type':B['object_type']})),A=evaluateGuardDraft({'table':z,'root':f,'rely':g,'scene':y,'sharing_recipients':h?.['sharing_recipients']});j=A['assessment'];for(const B of j['risks']){const C=B['level']==='critical'||B['level']==='high'?'error':B['level']==='medium'?'warning':B['level']==='low'?'info':'hint',D=B['evidence']??'',E=D['startsWith']('/')?D:'/';i['push']({'code':B['id'],'message':'['+B['level']+']\x20'+B['title'],'severity':C,'source':'risk','location':{'path':E},'fix':{'description':B['mitigation'],'auto_fixable':![]}});}}const p=checkSuggestions(d);i['push'](...p);const q=i['filter'](F=>F['severity']==='error')['length'],s=i['filter'](F=>F['severity']==='warning')['length'],t=i['filter'](F=>F['severity']==='info'||F['severity']==='hint')['length'],u=q===0x0;let v;if(q>0x0)v='Fix\x20'+q+'\x20error(s)\x20and\x20re-run\x20lint';else s>0x0?v='Consider\x20addressing\x20'+s+'\x20warning(s),\x20then\x20submit\x20to\x20SDK\x20newGuard()\x20for\x20final\x20syntax\x20validation':v='lint\x20passed\x20(no\x20errors);\x20submit\x20to\x20SDK\x20newGuard()\x20for\x20final\x20syntax\x20validation\x20before\x20going\x20on-chain';return{'json_summary':{'table_count':e['length'],'root_type':f?.['type']??'unknown','has_rely':!!g?.['guards']?.['length'],'rely_count':g?.['guards']?.['length']??0x0,'has_description':!!d['description']},'diagnostics':i,'fixed_json':n,'fix_actions':o,'risk_assessment':j,'summary':{'errors':q,'warnings':s,'infos':t,'auto_fixes_applied':o['length'],'ready':u,'next_step':v}};}export async function isGuardReady(a){const b=await lintGuard(a,{'auto_fix':![]});return b['summary']['ready'];}export async function getGuardErrors(a){const b=await lintGuard(a,{'auto_fix':![]});return b['diagnostics']['filter'](c=>c['severity']==='error');}export function formatLintResult(a){const b=[];b['push']('===\x20Guard\x20JSON\x20Lint\x20Report\x20==='),b['push'](''),b['push']('Summary:'),b['push']('\x20\x20Errors:\x20\x20\x20\x20\x20'+a['summary']['errors']),b['push']('\x20\x20Warnings:\x20\x20\x20'+a['summary']['warnings']),b['push']('\x20\x20Infos:\x20\x20\x20\x20\x20\x20'+a['summary']['infos']),b['push']('\x20\x20Auto-fixes:\x20'+a['summary']['auto_fixes_applied']),b['push']('\x20\x20Ready:\x20\x20\x20\x20\x20\x20'+(a['summary']['ready']?'YES':'NO')),b['push']('\x20\x20Next\x20step:\x20\x20'+a['summary']['next_step']),b['push']('');if(a['fix_actions']['length']>0x0){b['push']('---\x20Auto-fix\x20Actions\x20---');for(const g of a['fix_actions']){b['push']('\x20\x20['+g['diagnostic_code']+']\x20'+g['description']),b['push']('\x20\x20\x20\x20Path:\x20'+g['path']),g['before']&&g['after']&&b['push']('\x20\x20\x20\x20'+g['before']+'\x20->\x20'+g['after']);}b['push']('');}const c=a['diagnostics']['filter'](h=>h['severity']==='error'),e=a['diagnostics']['filter'](h=>h['severity']==='warning'),f=a['diagnostics']['filter'](h=>h['severity']==='info'||h['severity']==='hint');if(c['length']>0x0){b['push']('---\x20Errors\x20(must\x20fix)\x20---');for(const h of c){b['push']('\x20\x20['+h['code']+']\x20('+h['source']+')\x20'+h['message']),b['push']('\x20\x20\x20\x20Path:\x20'+h['location']['path']);if(h['fix'])b['push']('\x20\x20\x20\x20Fix:\x20\x20'+h['fix']['description']);}b['push']('');}if(e['length']>0x0){b['push']('---\x20Warnings\x20(consider\x20fixing)\x20---');for(const i of e){b['push']('\x20\x20['+i['code']+']\x20('+i['source']+')\x20'+i['message']),b['push']('\x20\x20\x20\x20Path:\x20'+i['location']['path']);if(i['fix'])b['push']('\x20\x20\x20\x20Fix:\x20\x20'+i['fix']['description']);}b['push']('');}if(f['length']>0x0){b['push']('---\x20Info\x20&\x20Hints\x20---');for(const j of f){b['push']('\x20\x20['+j['code']+']\x20('+j['source']+')\x20'+j['message']),b['push']('\x20\x20\x20\x20Path:\x20'+j['location']['path']);}}return b['join']('\x0a');}
1
+ import{validateGuardData,MAX_DESCRIPTION_LENGTH,MAX_GUARD_TABLE_ITEM_LENGTH,MAX_NAME_LENGTH,ValueType}from'@wowok/wowok';import{evaluateGuardDraft}from'./guard-eval.js';import{findScene,inferSceneFromAction}from'./guard-ledger.js';import{suggestTemplateForScene}from'./guard-templates.js';import{validateGuardTreeShape}from'./guard-render.js';const VALUE_TYPE_ID_TO_NAME={[ValueType['Bool']]:'Bool',[ValueType['Address']]:'Address',[ValueType['String']]:'String',[ValueType['U8']]:'U8',[ValueType['U16']]:'U16',[ValueType['U32']]:'U32',[ValueType['U64']]:'U64',[ValueType['U128']]:'U128',[ValueType['U256']]:'U256',[ValueType['VecBool']]:'VecBool',[ValueType['VecAddress']]:'VecAddress',[ValueType['VecString']]:'VecString',[ValueType['VecU8']]:'VecU8',[ValueType['VecU16']]:'VecU16',[ValueType['VecU32']]:'VecU32',[ValueType['VecU64']]:'VecU64',[ValueType['VecU128']]:'VecU128',[ValueType['VecU256']]:'VecU256',[ValueType['VecVecU8']]:'VecVecU8'};function normalizeValueTypeNames(a){if(!a['table']['some'](b=>typeof b['value_type']==='number'))return a;return{...a,'table':a['table']['map'](b=>typeof b['value_type']==='number'?{...b,'value_type':VALUE_TYPE_ID_TO_NAME[b['value_type']]??String(b['value_type'])}:b)};}function deepClone(a){return JSON['parse'](JSON['stringify'](a));}function rootToString(a){return JSON['stringify'](a);}function canonicalNode(a){if(a===null||typeof a!=='object')return JSON['stringify'](a)??'null';if(Array['isArray'](a))return'['+a['map'](canonicalNode)['join'](',')+']';const b=Object['keys'](a)['sort']();return'{'+b['map'](c=>JSON['stringify'](c)+':'+canonicalNode(a[c]))['join'](',')+'}';}const GE_NODE='logic_as_u256_greater_or_equal',LE_NODE='logic_as_u256_lesser_or_equal';function findDegenerateTimeWindows(a){const b=[],c=new Set(),d=g=>{const h=g['filter'](j=>j?.['type']===GE_NODE&&Array['isArray'](j['nodes'])&&j['nodes']['length']>=0x2),i=g['filter'](j=>j?.['type']===LE_NODE&&Array['isArray'](j['nodes'])&&j['nodes']['length']>=0x2);for(const j of h){for(const k of i){const l=canonicalNode(j['nodes'][0x0])===canonicalNode(k['nodes'][0x0]),m=canonicalNode(j['nodes'][0x1])===canonicalNode(k['nodes'][0x1]);if(!l||!m)continue;const n=canonicalNode(j)+'|'+canonicalNode(k);if(c['has'](n))continue;c['add'](n),b['push']({'ge':j,'le':k});}}},e=g=>{if(g?.['type']==='logic_and'&&Array['isArray'](g['nodes']))return g['nodes']['flatMap'](e);return[g];},f=g=>{if(!g||typeof g!=='object')return;if(g['type']==='logic_not')return;if(g['type']==='logic_and'&&Array['isArray'](g['nodes'])){const h=e(g);d(h),h['forEach'](f);return;}if(g['type']==='logic_or'&&Array['isArray'](g['nodes'])){for(const i of g['nodes']){i?.['type']==='logic_and'&&Array['isArray'](i['nodes'])?(d(i['nodes']),i['nodes']['forEach'](f)):f(i);}return;}if(g['type']===GE_NODE||g['type']===LE_NODE)d([g]);if(Array['isArray'](g['nodes']))g['nodes']['forEach'](f);};return f(a),b;}function hasSignerContext(a){const b=rootToString(a);return b['includes']('\x22Signer\x22')||b['includes']('\x22context\x22:\x22Signer\x22')||b['includes']('\x22context\x22:\x20\x22Signer\x22');}function getSubmissionEntries(a){return a['filter'](b=>b['b_submission']===!![]);}function inferValueType(a){if(typeof a==='string'){if(a['startsWith']('0x')&&a['length']>=0x3)return'Address';return'String';}if(typeof a==='number'){if(Number['isInteger'](a)){if(a>=0x0&&a<=0xff)return'U8';if(a>=0x0&&a<=0xffff)return'U16';return'U64';}return'U256';}if(typeof a==='boolean')return'Bool';if(Array['isArray'](a)){if(a['length']>0x0){const b=inferValueType(a[0x0]);if(b==='Address')return'Vec<Address>';if(b==='String')return'Vec<String>';if(b==='Bool')return'Vec<Bool>';}return'Vec<Address>';}return undefined;}function sdkIssueToDiagnostic(a){return{'code':a['code'],'message':a['message'],'severity':a['severity'],'source':'sdk','location':{'path':a['path']},'fix':{'description':'SDK\x20validation\x20failed\x20('+(a['sdk_error']??'InvalidParam')+');\x20manual\x20fix\x20required','auto_fixable':![]}};}async function checkSdkSyntax(a){const b=validateGuardTreeShape(a['root']);if(b['length']>0x0)return b['map'](f=>({'code':'G-001','message':f['message'],'severity':'error','source':'sdk','location':{'path':f['path']},'fix':{'description':'Unary\x20operators\x20(logic_not,\x20value_type,\x20vec_length,\x20calc_string_length,\x20convert_*)\x20take\x20a\x20single\x20\x27node\x27\x20child;\x20only\x20multi-operand\x20forms\x20(logic_and,\x20logic_or,\x20logic_equal,\x20logic_as_u256_*,\x20calc_number_*,\x20vec_contains_*)\x20take\x20a\x20\x27nodes\x27\x20array.','auto_fixable':![]}}));const c=a['table']['map'](f=>({'identifier':f['identifier'],'b_submission':f['b_submission']??![],'value_type':f['value_type']??'Address','value':f['value'],'name':f['name']??''}));let d;try{d=await validateGuardData({'description':a['description'],'table':c,'root':a['root'],'rely':a['rely']});}catch(f){const g=f?.['message']??String(f),h=/guard tree ([^:]+):/['exec'](g);return[{'code':'G-001','message':g,'severity':'error','source':'sdk','location':{'path':h?toJsonPointer(h[0x1]):'/root'},'fix':{'description':'Repair\x20the\x20tree\x20at\x20the\x20named\x20path:\x20unary\x20operators\x20(logic_not,\x20convert_*,\x20value_type)\x20take\x20a\x20single\x20\x27node\x27\x20child;\x20only\x20multi-operand\x20forms\x20(logic_and,\x20logic_or,\x20logic_equal,\x20calc_*,\x20vec_*)\x20take\x20\x27nodes\x27.','auto_fixable':![]}}];}return d['map'](sdkIssueToDiagnostic);}function toJsonPointer(a){const b=a['replace'](/^\/+/,'');return b['startsWith']('root')?'/'+b:'/root/'+b;}function checkSemanticErrors(a){const b=[],{table:c,root:d,binding_hint:e}=a,f=e?findScene(e['host_object']??'',e['binding_field']??''):undefined,g=getSubmissionEntries(c);if(g['length']>0x0&&d&&!hasSignerContext(d)){const h=g['some'](j=>j['value_type']==='Address'),i=f?.['id']==='service_order_allocators_guard'&&e?.['sharing_recipients']!==undefined&&e['sharing_recipients']['length']>0x0&&!e['sharing_recipients']['includes']('Signer');if(h&&!i){const j=g['filter'](k=>k['value_type']==='Address')['map'](k=>c['indexOf'](k));b['push']({'code':'LE-04','message':'Submitted\x20data\x20has\x20no\x20Signer\x20binding\x20(submission\x20forgery\x20risk)','severity':'error','source':'lint','location':{'path':j['map'](k=>'/table/'+k)['join']('\x20→\x20')},'fix':{'description':'Add\x20logic_equal(context(Signer),\x20identifier[N])\x20in\x20root\x20to\x20bind\x20the\x20submitter\x20identity','auto_fixable':![]}});}}if(f?.['id']==='arbitration_voting_guard'){const k=g['some'](l=>['U8','U16','U32','U64','U128','U256']['includes'](l['value_type']??''));if(k){const l=g['filter'](m=>['U8','U16','U32','U64','U128','U256']['includes'](m['value_type']??''))['map'](m=>c['indexOf'](m));b['push']({'code':'LE-05','message':'voting_guard\x20voting\x20weight\x20comes\x20from\x20submitted\x20data\x20(weight\x20forgery\x20risk)','severity':'error','source':'lint','location':{'path':l['map'](m=>'/table/'+m)['join']('\x20→\x20')},'fix':{'description':'Derive\x20arbitrator\x20weights\x20from\x20the\x20Arb\x20object\x20via\x20witness\x20(e.g.\x20105\x20TypeArbArbitration)\x20rather\x20than\x20submitting\x20them\x20directly','auto_fixable':![]}});}}if(f?.['id']==='gen_passport_guard'||e?.['action']==='gen_passport'){const m=rootToString(d);if(m['includes']('1167')||m['includes']('repository.data')){const n=m['includes']('quote_guard');n&&b['push']({'code':'LE-06','message':'repository.data\x20query\x20with\x20quote_guard:\x20rigid\x20verification\x20requirement\x20—\x20ensure\x20Passport\x20includes\x20quote_guard\x20verification\x20with\x20necessary\x20submissions\x20(e.g.,\x20Payment\x20proof)','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'Ensure\x20the\x20quote_guard\x20is\x20verified:\x20user\x20submits\x20Payment\x20via\x20Passport,\x20quote_guard\x20verifies\x20Payment\x20fields,\x20repository\x20data\x20query\x20passes','auto_fixable':![]}});}}if(e?.['host_object']&&f){const o=e['host_object'],p=c['filter'](q=>!q['b_submission']&&q['value_type']==='Address'&&typeof q['value']==='string'&&q['value']['startsWith']('0x')&&q['object_type']===o);if(p['length']>0x0){const q=p['map'](r=>c['indexOf'](r));b['push']({'code':'LE-07','message':'Circular\x20reference\x20uses\x20an\x20address\x20rather\x20than\x20a\x20name\x20(Host\x20Object\x20may\x20not\x20be\x20published\x20yet\x20when\x20the\x20Guard\x20is\x20created)','severity':'error','source':'lint','location':{'path':q['map'](r=>'/table/'+r+'/value')['join']('\x20→\x20')},'fix':{'description':'Change\x20value\x20from\x20an\x20address\x20to\x20an\x20object\x20name\x20(e.g.\x20\x22service1\x22);\x20the\x20SDK\x20will\x20resolve\x20it\x20to\x20an\x20address\x20after\x20the\x20Host\x20Object\x20is\x20published','auto_fixable':![]}});}}for(const {ge:r,le:s}of findDegenerateTimeWindows(d)){b['push']({'code':'LE-08','message':'Degenerate\x20time\x20window:\x20the\x20same\x20conjunction\x20asserts\x20`L\x20>=\x20R`\x20and\x20`L\x20<=\x20R`\x20over\x20'+'structurally\x20identical\x20operands.\x20Their\x20conjunction\x20is\x20`L\x20==\x20R`\x20—\x20on\x20a\x20millisecond\x20Clock\x20'+'an\x20~1\x20ms\x20window,\x20i.e.\x20the\x20guarded\x20forward\x20is\x20effectively\x20unreachable.\x20'+'`logic_as_u256_greater_or_equal`\x20is\x20a\x20LOWER\x20bound\x20(deadline\x20passed);\x20an\x20upper\x20bound\x20'+'(`logic_as_u256_lesser_or_equal`)\x20must\x20use\x20a\x20DIFFERENT\x20right-hand\x20side.','severity':'error','source':'lint','location':{'path':'/root'},'fix':{'description':'For\x20\x22the\x20deadline\x20has\x20passed\x22,\x20keep\x20ONLY\x20`L\x20>=\x20R`\x20and\x20delete\x20the\x20`<=`\x20clause.\x20'+'For\x20\x22the\x20window\x20is\x20open\x22,\x20keep\x20both\x20clauses\x20but\x20make\x20the\x20right-hand\x20sides\x20differ,\x20'+'e.g.\x20`L\x20>=\x20t`\x20and\x20`L\x20<=\x20t\x20+\x20K`.\x20Remember\x20`progress.current_time`\x20is\x20refreshed\x20on\x20'+'every\x20forward,\x20so\x20anchoring\x20a\x20release\x20lock\x20on\x20it\x20restarts\x20the\x20clock\x20at\x20each\x20node\x20change.','auto_fixable':![]}});}return b;}function checkSyntaxHints(a){const b=[],{table:c}=a;(!a['description']||a['description']['trim']()==='')&&b['push']({'code':'SH-01','message':'description\x20is\x20missing\x20or\x20empty','severity':'info','source':'lint','location':{'path':'/description'},'fix':{'description':'Add\x20a\x20description,\x20e.g.\x20\x27Service\x20buy_guard:\x20whitelist\x20validation\x27','auto_fixable':!![]}});for(let d=0x0;d<c['length'];d++){const e=c[d];(!e['name']||e['name']['trim']()==='')&&b['push']({'code':'SH-03','message':'table['+d+']\x20is\x20missing\x20name','severity':'warning','source':'lint','location':{'path':'/table/'+d+'/name'},'fix':{'description':'Add\x20a\x20name,\x20e.g.\x20\x22data\x20entry\x20'+e['identifier']+'\x22','auto_fixable':!![]}});}for(let f=0x0;f<c['length'];f++){const g=c[f];!g['value_type']&&b['push']({'code':'SH-05','message':'table['+f+']\x20is\x20missing\x20value_type','severity':'warning','source':'lint','location':{'path':'/table/'+f+'/value_type'},'fix':{'description':'Infer\x20value_type\x20from\x20value\x20(e.g.\x20Address/String/U64,\x20etc.)','auto_fixable':!![]}});}c['length']>MAX_GUARD_TABLE_ITEM_LENGTH&&b['push']({'code':'SH-07','message':'table\x20entry\x20count\x20'+c['length']+'\x20exceeds\x20the\x20maximum\x20limit\x20'+MAX_GUARD_TABLE_ITEM_LENGTH,'severity':'error','source':'lint','location':{'path':'/table'},'fix':{'description':'Slim\x20down\x20the\x20table\x20by\x20merging\x20similar\x20entries,\x20or\x20split\x20into\x20multiple\x20Guards\x20+\x20rely','auto_fixable':![]}});for(let h=0x0;h<c['length'];h++){c[h]['b_submission']===undefined&&b['push']({'code':'SH-10','message':'table['+h+']\x20b_submission\x20is\x20missing','severity':'info','source':'lint','location':{'path':'/table/'+h+'/b_submission'},'fix':{'description':'Set\x20to\x20false\x20(constant)\x20or\x20true\x20(submitted\x20data)','auto_fixable':!![]}});}for(let j=0x0;j<c['length'];j++){const k=c[j];k['b_submission']===!![]&&k['value']!==undefined&&k['value']!==null&&b['push']({'code':'SH-11','message':'table['+j+']\x20has\x20a\x20redundant\x20value\x20field\x20on\x20b_submission=true\x20entry\x20(the\x20verifier\x20supplies\x20the\x20value\x20at\x20runtime;\x20this\x20value\x20is\x20ignored\x20by\x20BCS\x20encoding\x20and\x20wastes\x20gas)','severity':'warning','source':'lint','location':{'path':'/table/'+j+'/value'},'fix':{'description':'Remove\x20the\x20value\x20field\x20—\x20it\x20is\x20ignored\x20for\x20b_submission=true\x20entries','auto_fixable':!![]}});}return b;}function checkSuggestions(a){const b=[],{root:c,binding_hint:d,table:e,description:f}=a;if(c){const i=rootToString(c);if(i['includes']('vec_contains_address')&&i['includes']('Signer'))b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P04\x20(whitelist\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Refer\x20to\x20the\x20P04\x20Pattern\x20to\x20ensure\x20best\x20practices','auto_fixable':![]}});else{if(i['includes']('logic_equal')&&i['includes']('Signer')){const j=e['some'](k=>!k['b_submission']&&k['value_type']==='Address'&&typeof k['value']==='string'&&k['value']['length']>0x0);j&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P04\x20(whitelist\x20validation\x20—\x20single-address\x20variant)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'P04\x20single-address\x20form;\x20for\x20multi-address\x20scenarios,\x20consider\x20vec_contains_address','auto_fixable':![]}});}}(i['includes']('logic_as_u256_greater')||i['includes']('logic_as_u256_lesser'))&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P02\x20(numeric\x20threshold\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Suitable\x20for\x20amount/quantity\x20threshold\x20validation\x20scenarios','auto_fixable':![]}}),i['includes']('convert_witness')&&b['push']({'code':'SG-01','message':'Matches\x20Pattern\x20P09\x20(witness-derived\x20validation)','severity':'hint','source':'lint','location':{'path':'/root'},'fix':{'description':'Suitable\x20for\x20cross-object\x20relationship\x20validation\x20(e.g.\x20Order→Progress)','auto_fixable':![]}});}if(d?.['action']){const k=['buy','forward','allocate','claim_reward','vote','dispute','write_repository','submit_progress','gen_passport'];if(k['includes'](d['action'])){const l=inferSceneFromAction(d['action']);if(l){const m=suggestTemplateForScene(l['id']);m&&b['push']({'code':'SG-02','message':'Recommended\x20scene\x20template:\x20'+m['name'],'severity':'hint','source':'lint','location':{'path':'/'},'fix':{'description':'Refer\x20to\x20template\x20'+m['id']+'\x20('+m['example_use_case']+')','auto_fixable':![]}});}}}const g=n=>new TextEncoder()['encode'](n)['length'],h=getSubmissionEntries(e);for(const [n,o]of e['entries']()){const p=o['name']??'';if(p['length']===0x0)continue;if(g(p)>MAX_NAME_LENGTH)b['push']({'code':'SG-03','message':'table['+n+']\x20name\x20is\x20'+g(p)+'\x20BCS\x20characters,\x20maximum\x20is\x20'+MAX_NAME_LENGTH+'.\x20Use\x20a\x20short\x20identifier\x20(e.g.\x20\x27order_id\x27,\x20\x27delivery_node\x27);\x20the\x20human-readable\x20explanation\x20belongs\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field','severity':'warning','source':'lint','location':{'path':'/table/'+n+'/name'},'fix':{'description':'Shorten\x20the\x20name\x20to\x20'+MAX_NAME_LENGTH+'\x20BCS\x20characters\x20or\x20fewer','auto_fixable':![]}});else p['toLowerCase']()['startsWith']('0x')&&b['push']({'code':'SG-03','message':'table['+n+']\x20name\x20must\x20not\x20start\x20with\x20\x220x\x22\x20(reserved\x20for\x20object\x20IDs)','severity':'warning','source':'lint','location':{'path':'/table/'+n+'/name'},'fix':{'description':'Rename\x20the\x20entry\x20without\x20the\x200x\x20prefix','auto_fixable':![]}});}if(h['length']>0x0){const q=(f??'')['trim']();q['length']<0xa&&b['push']({'code':'SG-03','message':'This\x20Guard\x20accepts\x20submitted\x20data\x20('+h['length']+'\x20table\x20'+(h['length']===0x1?'entry':'entries')+'\x20with\x20b_submission=true)\x20but\x20its\x20description\x20is\x20too\x20short\x20for\x20a\x20verifier\x20to\x20know\x20what\x20to\x20submit.\x20Explain\x20the\x20expected\x20submitted\x20data\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field,\x20e.g.\x20\x27user-submitted\x20operation\x20type\x20(return/damage)\x27','severity':'info','source':'lint','location':{'path':'/'},'fix':{'description':'Explain\x20the\x20expected\x20submitted\x20data\x20in\x20the\x20Guard\x27s\x20\x27description\x27\x20field','auto_fixable':![]}});}if(c){const r=rootToString(c),s=r['includes']('proof.signer'),t=r['includes']('proof.time'),u=r['includes']('calc_string_length'),v=h['some'](w=>w['value_type']==='String');if(s&&t)b['push']({'code':'SG-04','message':'Strict-mode\x20privacy-delivery\x20guard\x20detected\x20(proof.signer\x20+\x20proof.time).\x20'+'Recommended\x20three\x20conditions:\x20Signer==proof.signer\x20(submitter\x20accountability),\x20'+'proof.time>order.time\x20(freshness),\x20order.service==service\x20(project\x20binding).\x20'+'No\x20content\x20verification\x20—\x20only\x20submission\x20responsibility\x20(\x27whoever\x20benefits\x20bears\x20the\x20burden\x20of\x20proof\x27).','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'Ensure\x20all\x20three\x20conditions\x20are\x20present\x20(logic_and).\x20Refer\x20to\x20template\x20tpl_forward_privacy_delivery_proof.\x20'+'Query\x20IDs:\x20proof.signer=1958,\x20proof.time=1960,\x20order.time=1574,\x20order.service=1563.','auto_fixable':![]}});else u&&v&&b['push']({'code':'SG-04','message':'Broad-mode\x20privacy-delivery\x20guard\x20detected\x20(String\x20submission\x20+\x20length\x20check,\x20e.g.\x20Merkle\x20Root\x20length\x20==\x2066).\x20'+'This\x20trusts\x20the\x20submitter\x27s\x20honesty;\x20the\x20counterparty\x20can\x20dispute\x20by\x20checking\x20their\x20own\x20Messenger\x20conversation.\x20'+'Suitable\x20as\x20an\x20arbitration\x20basis,\x20not\x20a\x20fund-flow\x20gate.','severity':'info','source':'lint','location':{'path':'/root'},'fix':{'description':'For\x20stronger\x20assurance,\x20consider\x20strict\x20mode:\x20submit\x20a\x20Proof\x20object\x20address\x20(from\x20messenger.submitChainProof)\x20+\x20'+'Order\x20address,\x20then\x20verify\x20proof.signer/proof.time/order.service.\x20See\x20template\x20tpl_forward_privacy_delivery_proof.','auto_fixable':![]}});}return b;}export function autoFixGuard(a){const b=deepClone(a),c=[];(!b['description']||b['description']['trim']()==='')&&(b['description']='Guard\x20(table:\x20'+b['table']['length']+'\x20items,\x20root:\x20'+(b['root']?.['type']??'unknown')+')',c['push']({'diagnostic_code':'SH-01','description':'Fill\x20in\x20default\x20description','after':b['description'],'path':'/description'}));if(b['description']&&b['description']['length']>MAX_DESCRIPTION_LENGTH){const f=b['description'];b['description']=b['description']['substring'](0x0,MAX_DESCRIPTION_LENGTH),c['push']({'diagnostic_code':'G-001','description':'Truncate\x20description\x20to\x20'+MAX_DESCRIPTION_LENGTH+'\x20characters','before':f['length']+'\x20characters','after':b['description']['length']+'\x20characters','path':'/description'});}for(let g=0x0;g<b['table']['length'];g++){const h=b['table'][g];(!h['name']||h['name']['trim']()==='')&&(h['name']='data\x20entry\x20'+h['identifier'],c['push']({'diagnostic_code':'SH-03','description':'table['+g+']\x20fill\x20in\x20name','after':h['name'],'path':'/table/'+g+'/name'}));}for(let j=0x0;j<b['table']['length'];j++){const k=b['table'][j];if(!k['value_type']&&k['value']!==undefined&&k['value']!==null){const l=inferValueType(k['value']);l&&(k['value_type']=l,c['push']({'diagnostic_code':'SH-05','description':'table['+j+']\x20infer\x20value_type','after':l,'path':'/table/'+j+'/value_type'}));}}const d=new Map();let e=0x0;for(let m=0x0;m<b['table']['length'];m++){const n=b['table'][m];if(!d['has'](n['identifier']))d['set'](n['identifier'],e),n['identifier']!==e&&c['push']({'diagnostic_code':'G-007','description':'table['+m+']\x20identifier\x20'+n['identifier']+'\x20→\x20'+e,'before':String(n['identifier']),'after':String(e),'path':'/table/'+m+'/identifier'}),n['identifier']=e,e++;else{const o=n['identifier'];n['identifier']=e,d['set'](o,e),c['push']({'diagnostic_code':'G-007','description':'table['+m+']\x20identifier\x20'+o+'\x20duplicate\x20→\x20reallocated\x20to\x20'+e,'before':String(o),'after':String(e),'path':'/table/'+m+'/identifier'}),e++;}}for(let p=0x0;p<b['table']['length'];p++){const q=b['table'][p];q['b_submission']===undefined&&(q['b_submission']=![],c['push']({'diagnostic_code':'SH-10','description':'table['+p+']\x20b_submission\x20default\x20set\x20to\x20false','after':'false','path':'/table/'+p+'/b_submission'}));}if(b['rely']?.['guards']&&b['rely']['guards']['length']>0x0){const r=[...new Set(b['rely']['guards'])];r['length']!==b['rely']['guards']['length']&&(c['push']({'diagnostic_code':'G-009','description':'rely\x20deduplicate:\x20'+b['rely']['guards']['length']+'\x20→\x20'+r['length'],'before':JSON['stringify'](b['rely']['guards']),'after':JSON['stringify'](r),'path':'/rely/guards'}),b['rely']['guards']=r);}for(let s=0x0;s<b['table']['length'];s++){const t=b['table'][s];if(t['b_submission']===!![]&&t['value']!==undefined&&t['value']!==null){const u=JSON['stringify'](t['value']);delete t['value'],c['push']({'diagnostic_code':'SH-11','description':'table['+s+']\x20remove\x20redundant\x20value\x20on\x20b_submission=true\x20entry','before':u,'after':'(removed)','path':'/table/'+s+'/value'});}}return{'fixed':b,'actions':c};}export async function lintGuard(a,b){const c=b?.['auto_fix']??!![],d=normalizeValueTypeNames(a),{table:e,root:f,rely:g,binding_hint:h}=d,i=[];let j;const k=await checkSdkSyntax(d);i['push'](...k);const l=checkSemanticErrors(d);i['push'](...l);const m=checkSyntaxHints(d);i['push'](...m);let n,o=[];if(c){const {fixed:w,actions:x}=autoFixGuard(d);x['length']>0x0&&(n=w,o=x);}if(e['length']>0x0&&f){const y=h?findScene(h['host_object']??'',h['binding_field']??''):undefined,z=e['map'](B=>({'identifier':B['identifier'],'b_submission':B['b_submission']??![],'value_type':B['value_type']??'Address','value':B['value'],'name':B['name'],'object_type':B['object_type']})),A=evaluateGuardDraft({'table':z,'root':f,'rely':g,'scene':y,'sharing_recipients':h?.['sharing_recipients']});j=A['assessment'];for(const B of j['risks']){const C=B['level']==='critical'||B['level']==='high'?'error':B['level']==='medium'?'warning':B['level']==='low'?'info':'hint',D=B['evidence']??'',E=D['startsWith']('/')?D:'/';i['push']({'code':B['id'],'message':'['+B['level']+']\x20'+B['title'],'severity':C,'source':'risk','location':{'path':E},'fix':{'description':B['mitigation'],'auto_fixable':![]}});}}const p=checkSuggestions(d);i['push'](...p);const q=i['filter'](F=>F['severity']==='error')['length'],s=i['filter'](F=>F['severity']==='warning')['length'],t=i['filter'](F=>F['severity']==='info'||F['severity']==='hint')['length'],u=q===0x0;let v;if(q>0x0)v='Fix\x20'+q+'\x20error(s)\x20and\x20re-run\x20lint';else s>0x0?v='Consider\x20addressing\x20'+s+'\x20warning(s),\x20then\x20submit\x20to\x20SDK\x20newGuard()\x20for\x20final\x20syntax\x20validation':v='lint\x20passed\x20(no\x20errors);\x20submit\x20to\x20SDK\x20newGuard()\x20for\x20final\x20syntax\x20validation\x20before\x20going\x20on-chain';return{'json_summary':{'table_count':e['length'],'root_type':f?.['type']??'unknown','has_rely':!!g?.['guards']?.['length'],'rely_count':g?.['guards']?.['length']??0x0,'has_description':!!d['description']},'diagnostics':i,'fixed_json':n,'fix_actions':o,'risk_assessment':j,'summary':{'errors':q,'warnings':s,'infos':t,'auto_fixes_applied':o['length'],'ready':u,'next_step':v}};}export async function isGuardReady(a){const b=await lintGuard(a,{'auto_fix':![]});return b['summary']['ready'];}export async function getGuardErrors(a){const b=await lintGuard(a,{'auto_fix':![]});return b['diagnostics']['filter'](c=>c['severity']==='error');}export function formatLintResult(a){const b=[];b['push']('===\x20Guard\x20JSON\x20Lint\x20Report\x20==='),b['push'](''),b['push']('Summary:'),b['push']('\x20\x20Errors:\x20\x20\x20\x20\x20'+a['summary']['errors']),b['push']('\x20\x20Warnings:\x20\x20\x20'+a['summary']['warnings']),b['push']('\x20\x20Infos:\x20\x20\x20\x20\x20\x20'+a['summary']['infos']),b['push']('\x20\x20Auto-fixes:\x20'+a['summary']['auto_fixes_applied']),b['push']('\x20\x20Ready:\x20\x20\x20\x20\x20\x20'+(a['summary']['ready']?'YES':'NO')),b['push']('\x20\x20Next\x20step:\x20\x20'+a['summary']['next_step']),b['push']('');if(a['fix_actions']['length']>0x0){b['push']('---\x20Auto-fix\x20Actions\x20---');for(const g of a['fix_actions']){b['push']('\x20\x20['+g['diagnostic_code']+']\x20'+g['description']),b['push']('\x20\x20\x20\x20Path:\x20'+g['path']),g['before']&&g['after']&&b['push']('\x20\x20\x20\x20'+g['before']+'\x20->\x20'+g['after']);}b['push']('');}const c=a['diagnostics']['filter'](h=>h['severity']==='error'),e=a['diagnostics']['filter'](h=>h['severity']==='warning'),f=a['diagnostics']['filter'](h=>h['severity']==='info'||h['severity']==='hint');if(c['length']>0x0){b['push']('---\x20Errors\x20(must\x20fix)\x20---');for(const h of c){b['push']('\x20\x20['+h['code']+']\x20('+h['source']+')\x20'+h['message']),b['push']('\x20\x20\x20\x20Path:\x20'+h['location']['path']);if(h['fix'])b['push']('\x20\x20\x20\x20Fix:\x20\x20'+h['fix']['description']);}b['push']('');}if(e['length']>0x0){b['push']('---\x20Warnings\x20(consider\x20fixing)\x20---');for(const i of e){b['push']('\x20\x20['+i['code']+']\x20('+i['source']+')\x20'+i['message']),b['push']('\x20\x20\x20\x20Path:\x20'+i['location']['path']);if(i['fix'])b['push']('\x20\x20\x20\x20Fix:\x20\x20'+i['fix']['description']);}b['push']('');}if(f['length']>0x0){b['push']('---\x20Info\x20&\x20Hints\x20---');for(const j of f){b['push']('\x20\x20['+j['code']+']\x20('+j['source']+')\x20'+j['message']),b['push']('\x20\x20\x20\x20Path:\x20'+j['location']['path']);}}return b['join']('\x0a');}