@wowok/agent-mcp 3.2.2 → 3.2.3

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 (134) hide show
  1. package/dist/chain-semantics/field-capability.d.ts +11 -0
  2. package/dist/chain-semantics/field-capability.js +1 -0
  3. package/dist/chain-semantics/freeze-map.d.ts +11 -0
  4. package/dist/chain-semantics/freeze-map.js +1 -0
  5. package/dist/chain-semantics/fund-flow.d.ts +10 -0
  6. package/dist/chain-semantics/fund-flow.js +1 -0
  7. package/dist/chain-semantics/guard-verbs.d.ts +22 -0
  8. package/dist/chain-semantics/guard-verbs.js +1 -0
  9. package/dist/chain-semantics/index.d.ts +10 -0
  10. package/dist/chain-semantics/index.js +1 -0
  11. package/dist/chain-semantics/object-graph.d.ts +18 -0
  12. package/dist/chain-semantics/object-graph.js +1 -0
  13. package/dist/composition/audit.d.ts +10 -0
  14. package/dist/composition/audit.js +1 -0
  15. package/dist/composition/compile.d.ts +38 -0
  16. package/dist/composition/compile.js +1 -0
  17. package/dist/composition/materialize.d.ts +64 -0
  18. package/dist/composition/materialize.js +1 -0
  19. package/dist/composition/plan.d.ts +92 -0
  20. package/dist/composition/plan.js +1 -0
  21. package/dist/composition/reflux.d.ts +28 -0
  22. package/dist/composition/reflux.js +1 -0
  23. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  24. package/dist/evaluation/engine.js +1 -1
  25. package/dist/experience/realtime-feedback.js +1 -1
  26. package/dist/extensions/business-modules.js +1 -1
  27. package/dist/extensions/industry-pack.js +1 -1
  28. package/dist/extensions/modes.js +1 -1
  29. package/dist/graph/onchain/expand.js +1 -1
  30. package/dist/graph/onchain/exposure.js +1 -1
  31. package/dist/graph/onchain/facts.js +1 -1
  32. package/dist/keeper/detectors.d.ts +7 -0
  33. package/dist/keeper/detectors.js +1 -1
  34. package/dist/keeper/types.d.ts +1 -1
  35. package/dist/keeper/types.js +1 -1
  36. package/dist/knowledge/allocation-ledger.js +1 -1
  37. package/dist/knowledge/allocation-puzzle.js +1 -1
  38. package/dist/knowledge/allocation-risk.js +1 -1
  39. package/dist/knowledge/allocation-templates.js +1 -1
  40. package/dist/knowledge/arb-fund-facts.d.ts +31 -0
  41. package/dist/knowledge/arb-fund-facts.js +1 -0
  42. package/dist/knowledge/baselines/rules/allocation.json +44 -15
  43. package/dist/knowledge/baselines/rules/guard.json +27 -8
  44. package/dist/knowledge/baselines/rules/plan.json +161 -0
  45. package/dist/knowledge/baselines/semantic-facts.d.ts +12 -0
  46. package/dist/knowledge/baselines/semantic-facts.js +1 -0
  47. package/dist/knowledge/builtin-templates.d.ts +1 -1
  48. package/dist/knowledge/builtin-templates.js +1 -1
  49. package/dist/knowledge/getting-started.js +1 -1
  50. package/dist/knowledge/guard-design-patterns.js +1 -1
  51. package/dist/knowledge/guard-ledger.js +1 -1
  52. package/dist/knowledge/guard-risk.js +1 -1
  53. package/dist/knowledge/guard-templates.js +1 -1
  54. package/dist/knowledge/index.js +1 -1
  55. package/dist/knowledge/industry-registry.js +1 -1
  56. package/dist/knowledge/jsonrpc-enum.js +1 -1
  57. package/dist/knowledge/onchain-constants.d.ts +2 -2
  58. package/dist/knowledge/onchain-constants.js +1 -1
  59. package/dist/knowledge/scenario-modes.d.ts +12 -0
  60. package/dist/knowledge/service-allocation-semantics.js +1 -1
  61. package/dist/knowledge/service-ledger.js +1 -1
  62. package/dist/knowledge/service-templates.js +1 -1
  63. package/dist/knowledge/strategy-manuals.js +1 -1
  64. package/dist/knowledge/template-loader.d.ts +16 -1
  65. package/dist/knowledge/template-loader.js +1 -1
  66. package/dist/knowledge/template-registry.js +1 -1
  67. package/dist/knowledge/template-scanner.js +1 -1
  68. package/dist/knowledge/tools-reference.js +1 -1
  69. package/dist/knowledge/workflow-guidance.js +1 -1
  70. package/dist/monitor/MonitorLoop.js +1 -1
  71. package/dist/participation/radar-core.d.ts +6 -0
  72. package/dist/participation/radar-core.js +1 -1
  73. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  74. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  75. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  76. package/dist/playbooks/service-build/migration-planner.js +1 -1
  77. package/dist/playbooks/service-build/object-panorama.js +1 -1
  78. package/dist/playbooks/service-build/participation-radar.js +1 -1
  79. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  80. package/dist/playbooks/service-build/service-panorama.js +1 -1
  81. package/dist/playbooks/service-build/service-quote.js +1 -1
  82. package/dist/review/index.js +1 -1
  83. package/dist/safety/confirm-gate.js +1 -1
  84. package/dist/schema/call/order.d.ts +60 -0
  85. package/dist/schema/call/order.js +1 -1
  86. package/dist/schema/call/semantic.js +1 -1
  87. package/dist/schema/call/service.d.ts +56 -0
  88. package/dist/schema/call/service.js +1 -1
  89. package/dist/schema/common/index.js +1 -1
  90. package/dist/schema/index.d.ts +1 -0
  91. package/dist/schema/index.js +1 -1
  92. package/dist/schema/industry-pack/index.d.ts +2 -0
  93. package/dist/schema/industry-pack/index.js +1 -1
  94. package/dist/schema/local/index.js +1 -1
  95. package/dist/schema/operations.d.ts +48 -0
  96. package/dist/schema/query/index.js +1 -1
  97. package/dist/schema/schema-version.js +1 -1
  98. package/dist/schema/service-clone/index.d.ts +46 -0
  99. package/dist/schema/service-clone/index.js +1 -0
  100. package/dist/schema-query-impl/index.js +1 -1
  101. package/dist/schemas/index.json +7 -1
  102. package/dist/schemas/industry_pack_operation.output.json +4 -0
  103. package/dist/schemas/industry_pack_operation.schema.json +4 -0
  104. package/dist/schemas/onchain_operations.output.json +1 -1
  105. package/dist/schemas/onchain_operations.schema.json +405 -94
  106. package/dist/schemas/onchain_operations_allocation.schema.json +5 -5
  107. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -2
  108. package/dist/schemas/onchain_operations_contact.schema.json +1 -1
  109. package/dist/schemas/onchain_operations_demand.schema.json +3 -3
  110. package/dist/schemas/onchain_operations_gen_passport.schema.json +1 -1
  111. package/dist/schemas/onchain_operations_guard.schema.json +59 -59
  112. package/dist/schemas/onchain_operations_machine.schema.json +1 -1
  113. package/dist/schemas/onchain_operations_order.schema.json +133 -1
  114. package/dist/schemas/onchain_operations_progress.schema.json +1 -1
  115. package/dist/schemas/onchain_operations_proof.schema.json +1 -1
  116. package/dist/schemas/onchain_operations_repository.schema.json +1 -1
  117. package/dist/schemas/onchain_operations_reward.schema.json +4 -4
  118. package/dist/schemas/onchain_operations_service.schema.json +186 -7
  119. package/dist/schemas/onchain_operations_treasury.schema.json +7 -7
  120. package/dist/schemas/query_toolkit.output.json +45 -45
  121. package/dist/schemas/service_clone_operation.output.json +168 -0
  122. package/dist/schemas/service_clone_operation.schema.json +49 -0
  123. package/dist/schemas/workflow_operation.schema.json +1 -1
  124. package/dist/tools/handlers/config.js +1 -1
  125. package/dist/tools/handlers/industry-pack.js +1 -1
  126. package/dist/tools/handlers/onchain.js +1 -1
  127. package/dist/tools/handlers/query.js +1 -1
  128. package/dist/tools/handlers/service-clone.d.ts +2 -0
  129. package/dist/tools/handlers/service-clone.js +1 -0
  130. package/dist/tools/index.js +1 -1
  131. package/dist/tools/registry/business.js +1 -1
  132. package/dist/tools/wrap.d.ts +6 -1
  133. package/dist/tools/wrap.js +1 -1
  134. package/package.json +2 -2
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://wowok.net/schemas/service_clone_operation.json",
4
+ "title": "Service Clone - Rebuild On-chain Services",
5
+ "description": "Clone an existing on-chain Service into a new object. Actions: clone_plan (read the source Service — fields, machine graph, guards, permission, allocators — and emit a reconstruction plan; optional overrides: token_type, network, description, location, sales, compensation_fund, order_allocators), clone_apply (apply overrides to a prior plan, run the pre-publish gate, emit the exact onchain_operations payloads in execution order). Never executes on-chain.",
6
+ "type": "object",
7
+ "properties": {
8
+ "action": {
9
+ "type": "string",
10
+ "enum": [
11
+ "clone_plan",
12
+ "clone_apply"
13
+ ],
14
+ "description": "Action: 'clone_plan' = read the source Service and emit a reconstruction plan (source_service required; never executes on-chain); 'clone_apply' = run a prior clone_plan through the pre-publish gate and emit the exact onchain_operations payloads ready for execution (plan required; never executes on-chain)."
15
+ },
16
+ "source_service": {
17
+ "description": "Source Service object ID or LocalMark name (required for clone_plan).",
18
+ "type": "string"
19
+ },
20
+ "plan": {
21
+ "description": "A prior clone_plan result (required for clone_apply).",
22
+ "type": "object",
23
+ "propertyNames": {
24
+ "type": "string"
25
+ },
26
+ "additionalProperties": {}
27
+ },
28
+ "overrides": {
29
+ "description": "Configuration overrides for the cloned Service. Supported keys: 'token_type' (new payment token, e.g. '0x2::wow::WOW' or '0x2::usdt::USDT'); 'network' (target network — overrides the top-level network field); 'description' (new service description); 'location' (new service location); 'sales' (array of sale overrides, merged by name); 'compensation_fund' (new fund amount in smallest unit); 'order_allocators' (replace allocator plan entirely).",
30
+ "type": "object",
31
+ "propertyNames": {
32
+ "type": "string"
33
+ },
34
+ "additionalProperties": {}
35
+ },
36
+ "network": {
37
+ "description": "Target network (default: the source Service's network).",
38
+ "type": "string",
39
+ "enum": [
40
+ "testnet",
41
+ "mainnet"
42
+ ]
43
+ }
44
+ },
45
+ "required": [
46
+ "action"
47
+ ],
48
+ "additionalProperties": false
49
+ }
@@ -143,7 +143,7 @@
143
143
  "type": "integer",
144
144
  "minimum": 0,
145
145
  "maximum": 255,
146
- "description": "Identifier (0-255) for data lookup in Guard table."
146
+ "description": "Identifier (0-255) for data lookup in Guard table. Slot consensus (enforced on-chain at guard table construction): 0-220 = user slots (free for business guards); 221-253 = PROTOCOL-RESERVED (rejected on-chain — reserved so future protocol features get fixed slots without colliding with published guards); 255 = ONCE replay-protection slot on Allocation (byte-keyed, the submitted bytes are the once-key — use for per-period keys like period-<N>); 254 = ONCE-FOR-OBJECT slot on Allocation (chain-derived key = bcs(the Allocation's payment_info.for_object); the submitted bytes are ignored and the submission only arms the slot — use for one-shot per-order rails such as full refunds)."
147
147
  },
148
148
  "b_submission": {
149
149
  "type": "boolean",
@@ -1 +1 @@
1
- import{listServices,getServiceInfo,toggle as a424a,setEnabled as a424b,reset as a424c}from'../../config/index.js';import{judgmentStatus,setJudgmentOverride,clearJudgmentOverride,clearJudgmentOverrides,patchUserJudgmentDoc,readUserJudgmentDocView}from'../../config/judgment.js';import{strictParse}from'../../schema/index.js';import{ConfigOperationInputSchema}from'../../schema/config/index.js';export async function handleConfigOperation(a){const b=strictParse(ConfigOperationInputSchema,a,'config_operation\x20input'),{action:c,service:d,path:e,value:f}=b;let g;switch(c){case'list':g={'action':'list','services':listServices()};break;case'toggle':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20toggle');const h=d,i=getServiceInfo(h);if(!i)throw new Error('Unknown\x20service:\x20'+h+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(h==='confirm_gate'&&i['enabled'])throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');const j=a424a(h);g={'action':'toggle','service':h,'enabled':j,'reminder':i['reminder']};break;}case'disable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20disable');const k=d,l=getServiceInfo(k);if(!l)throw new Error('Unknown\x20service:\x20'+k+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(k==='confirm_gate')throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');a424b(k,![]),g={'action':'disable','service':k,'enabled':![],'reminder':l['reminder']};break;}case'enable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20enable');const m=d,n=getServiceInfo(m);if(!n)throw new Error('Unknown\x20service:\x20'+m+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a424b(m,!![]),g={'action':'enable','service':m,'enabled':!![],'reminder':n['reminder']};break;}case'reset':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20reset');const o=d,p=getServiceInfo(o);if(!p)throw new Error('Unknown\x20service:\x20'+o+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a424c(o),g={'action':'reset','service':o,'enabled':getServiceInfo(o)?.['enabled'],'reminder':p['reminder'],'reset':!![]};break;}case'info':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20info');const q=d,r=getServiceInfo(q);if(!r)throw new Error('Unknown\x20service:\x20'+q+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');g={'action':'info',...r};break;}case'judgment_list':g={'action':'judgment_list',...judgmentStatus()};break;case'judgment_set':{if(!e)throw new Error('\x27path\x27\x20param\x20is\x20required\x20for\x20judgment_set\x20(dotted,\x20e.g.\x20\x27evaluation.weights.trust_reviews\x27)');if(!('value'in b))throw new Error('\x27value\x27\x20param\x20is\x20required\x20for\x20judgment_set');const s=setJudgmentOverride(e,f);if(!s['ok'])throw new Error(s['error']);g={'action':'judgment_set','path':e,'value':f,'applied':!![]};break;}case'judgment_reset':{const t=e?clearJudgmentOverride(e)?0x1:0x0:clearJudgmentOverrides();g={'action':'judgment_reset',...e?{'path':e}:{},'cleared':t};break;}case'judgment_doc_read':{g={'action':'judgment_doc_read',...readUserJudgmentDocView()};break;}case'judgment_doc_patch':{if(!b['patch']||typeof b['patch']!=='object'||Array['isArray'](b['patch']))throw new Error('\x27patch\x27\x20param\x20is\x20required\x20for\x20judgment_doc_patch\x20(a\x20partial\x20judgment\x20document\x20object,\x20e.g.\x20{\x22evaluation\x22:\x20{\x22weights\x22:\x20{…}}})');g={'action':'judgment_doc_patch',...patchUserJudgmentDoc(b['patch'])};break;}default:throw new Error('Unknown\x20config_operation\x20action:\x20'+String(c));}return{'content':[{'type':'text','text':JSON['stringify']({'result':g})}],'structuredContent':{'result':g}};}
1
+ import{listServices,getServiceInfo,toggle as a438a,setEnabled as a438b,reset as a438c}from'../../config/index.js';import{judgmentStatus,setJudgmentOverride,clearJudgmentOverride,clearJudgmentOverrides,patchUserJudgmentDoc,readUserJudgmentDocView}from'../../config/judgment.js';import{strictParse}from'../../schema/index.js';import{ConfigOperationInputSchema}from'../../schema/config/index.js';export async function handleConfigOperation(a){const b=strictParse(ConfigOperationInputSchema,a,'config_operation\x20input'),{action:c,service:d,path:e,value:f}=b;let g;switch(c){case'list':g={'action':'list','services':listServices()};break;case'toggle':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20toggle');const h=d,i=getServiceInfo(h);if(!i)throw new Error('Unknown\x20service:\x20'+h+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(h==='confirm_gate'&&i['enabled'])throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');const j=a438a(h);g={'action':'toggle','service':h,'enabled':j,'reminder':i['reminder']};break;}case'disable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20disable');const k=d,l=getServiceInfo(k);if(!l)throw new Error('Unknown\x20service:\x20'+k+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(k==='confirm_gate')throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');a438b(k,![]),g={'action':'disable','service':k,'enabled':![],'reminder':l['reminder']};break;}case'enable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20enable');const m=d,n=getServiceInfo(m);if(!n)throw new Error('Unknown\x20service:\x20'+m+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a438b(m,!![]),g={'action':'enable','service':m,'enabled':!![],'reminder':n['reminder']};break;}case'reset':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20reset');const o=d,p=getServiceInfo(o);if(!p)throw new Error('Unknown\x20service:\x20'+o+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a438c(o),g={'action':'reset','service':o,'enabled':getServiceInfo(o)?.['enabled'],'reminder':p['reminder'],'reset':!![]};break;}case'info':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20info');const q=d,r=getServiceInfo(q);if(!r)throw new Error('Unknown\x20service:\x20'+q+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');g={'action':'info',...r};break;}case'judgment_list':g={'action':'judgment_list',...judgmentStatus()};break;case'judgment_set':{if(!e)throw new Error('\x27path\x27\x20param\x20is\x20required\x20for\x20judgment_set\x20(dotted,\x20e.g.\x20\x27evaluation.weights.trust_reviews\x27)');if(!('value'in b))throw new Error('\x27value\x27\x20param\x20is\x20required\x20for\x20judgment_set');const s=setJudgmentOverride(e,f);if(!s['ok'])throw new Error(s['error']);g={'action':'judgment_set','path':e,'value':f,'applied':!![]};break;}case'judgment_reset':{const t=e?clearJudgmentOverride(e)?0x1:0x0:clearJudgmentOverrides();g={'action':'judgment_reset',...e?{'path':e}:{},'cleared':t};break;}case'judgment_doc_read':{g={'action':'judgment_doc_read',...readUserJudgmentDocView()};break;}case'judgment_doc_patch':{if(!b['patch']||typeof b['patch']!=='object'||Array['isArray'](b['patch']))throw new Error('\x27patch\x27\x20param\x20is\x20required\x20for\x20judgment_doc_patch\x20(a\x20partial\x20judgment\x20document\x20object,\x20e.g.\x20{\x22evaluation\x22:\x20{\x22weights\x22:\x20{…}}})');g={'action':'judgment_doc_patch',...patchUserJudgmentDoc(b['patch'])};break;}default:throw new Error('Unknown\x20config_operation\x20action:\x20'+String(c));}return{'content':[{'type':'text','text':JSON['stringify']({'result':g})}],'structuredContent':{'result':g}};}
@@ -1 +1 @@
1
- import{readdirSync,readFileSync,writeFileSync,existsSync,mkdirSync,statSync,cpSync,renameSync,rmSync}from'node:fs';import{join,relative,resolve,sep,dirname,basename}from'node:path';import{strictParse}from'../../schema/index.js';import{IndustryPackOperationInputSchema}from'../../schema/industry-pack/index.js';import{validateJudgmentFragment}from'../../config/judgment.js';import{scaffoldIndustryPack,listRegisteredPacks,scanDefaultIndustryPacks,seedBuiltinIndustryTemplates,seedBuiltinStrategyManuals,ensureIndustryReadme,resolveIndustryPackDir,rescanPack,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,diffIndustryPack,resetIndustryPath}from'../../extensions/index.js';import{getIndustryModeRegistry}from'../../extensions/registry.js';import{handleRecommendIndustry,handleListModes,handleDeriveUserMode,handleEvolveUserMode,handleRegisterUserMode,handleUnregisterUserMode,handleRegisterCustomMetric,handleUnregisterCustomMetric,handleRegisterCustomConstraint,handleUnregisterCustomConstraint,handleListMetricsConstraints}from'../../playbooks/service-build/mode-actions.js';import{repairBuiltinTemplates,builtinTemplateDrift,resolveTemplatesDir}from'../../knowledge/template-loader.js';const INDUSTRY_ROOT=resolveIndustryPackDir(),resolveTemplatesDirSafe=resolveTemplatesDir;function resolveIndustryPath(a){const b=resolve(INDUSTRY_ROOT,a);if(b!==INDUSTRY_ROOT&&!b['startsWith'](INDUSTRY_ROOT+sep))throw new Error('path\x20\x27'+a+'\x27\x20escapes\x20the\x20industry\x20root');return b;}function rescanAffectedPack(a){const b=a['split'](/[\\/]+/)['find'](c=>c['length']>0x0);if(!b)return;rescanPack(b);}const BASELINES_FILENAME='baselines.json',PACK_FILENAME='pack.json';function assertBaselinesContentValid(a,b){const c=a['split'](/[\\/]+/)['pop']()??'';if(c!==BASELINES_FILENAME&&c!==PACK_FILENAME)return;let d;try{d=JSON['parse'](b);}catch{return;}if(!d||typeof d!=='object'||Array['isArray'](d))return;const e=d,f=c===BASELINES_FILENAME?d:e['baselines'];if(f===undefined||f===null)return;const g=validateJudgmentFragment(f,a+'\x20baselines');if(g)throw new Error('write\x20rejected\x20—\x20the\x20baselines\x20fragment\x20in\x20\x27'+a+'\x27\x20is\x20not\x20a\x20valid\x20judgment\x20fragment:\x20'+g);}function listRecursive(a,b,c,d=0x0){if(d>0x8)return;let f;try{f=readdirSync(a,{'withFileTypes':!![]});}catch{return;}for(const g of f){const h=join(a,g['name']),i=relative(b,h)['split'](sep)['join']('/');let j=0x0,k=0x0;try{const l=statSync(h);k=l['size'],j=l['mtimeMs'];}catch{}g['isDirectory']()?(c['push']({'path':i,'is_dir':!![],'size':0x0,'mtime':j}),listRecursive(h,b,c,d+0x1)):c['push']({'path':i,'is_dir':![],'size':k,'mtime':j});}}export async function handleIndustryPackOperation(a){const b=strictParse(IndustryPackOperationInputSchema,a,'industry_pack_operation\x20input');mkdirSync(INDUSTRY_ROOT,{'recursive':!![]}),seedBuiltinIndustryTemplates(),seedBuiltinStrategyManuals(),ensureIndustryReadme();let c;switch(b['action']){case'scaffold':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27scaffold\x27');const d=scaffoldIndustryPack(b['name']);c={'action':'scaffold','ok':d['ok'],'dir':d['dir'],'files':d['files'],'errors':d['errors']};if(d['ok'])rescanPack(b['name']);break;}case'list':{c={'action':'list','packs':listRegisteredPacks()};break;}case'scan':{c={'action':'scan','results':scanDefaultIndustryPacks()};break;}case'repair_builtin_templates':{const e=repairBuiltinTemplates({'backup':!![]}),f=e['filter'](g=>g['status']==='updated');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':f['length'],'results':e,'note':f['length']?'Legacy\x20sentinel-less\x20builtin\x20files\x20were\x20reseeded\x20from\x20the\x20in-code\x20catalog.\x20Each\x20previous\x20body\x20is\x20preserved\x20as\x20<file>.bak.':'No\x20legacy\x20sentinel-less\x20builtin\x20files\x20found\x20—\x20every\x20builtin\x20template\x20already\x20carries\x20a\x20release\x20sentinel.'};break;}case'template_drift':{const g=builtinTemplateDrift();c={'action':'template_drift','dir':resolveTemplatesDirSafe(),'drift_count':g['length'],'drift':g,'note':g['length']?'On-disk\x20builtin\x20templates\x20differ\x20from\x20the\x20in-code\x20catalog.\x20Run\x20action=\x27repair_builtin_templates\x27\x20to\x20reseed.':'Every\x20builtin\x20template\x20on\x20disk\x20matches\x20the\x20in-code\x20catalog.'};break;}case'resolve':{c={'action':'resolve','dir':INDUSTRY_ROOT};break;}case'list_files':{const h=[];listRecursive(INDUSTRY_ROOT,INDUSTRY_ROOT,h),c={'action':'list_files','dir':INDUSTRY_ROOT,'files':h};break;}case'read_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27read_file\x27');const i=resolveIndustryPath(b['path']);if(!existsSync(i))throw new Error('file\x20not\x20found:\x20'+b['path']);c={'action':'read_file','path':i,'content':readFileSync(i,'utf-8')};break;}case'write_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');if(b['content']===undefined)throw new Error('\x27content\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');const j=resolveIndustryPath(b['path']);assertBaselinesContentValid(b['path'],b['content']),mkdirSync(dirname(j),{'recursive':!![]}),writeFileSync(j,b['content'],'utf-8'),c={'action':'write_file','path':j,'ok':!![]},rescanAffectedPack(b['path']);break;}case'get':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27get\x27');const k=b['name'],l=getIndustryModeRegistry()['getMode'](k),m=l?{'name':l['name'],'display_name':l['display_name'],'key_risk':l['key_risk'],'needs':l['needs']['map'](o=>o['description']),...l['analyze']?.['key_questions']?.['length']?{'analyze_questions':l['analyze']['key_questions']['slice'](0x0,0x2)}:{}}:undefined;c={'action':'get','category':k,...m?{'mode':m}:{},...resolveDisputeRules(k)?{'dispute':resolveDisputeRules(k)}:{},...resolveComplianceRules(k)?{'compliance':resolveComplianceRules(k)}:{},...resolveSupplyRules(k)?{'supply':resolveSupplyRules(k)}:{},...resolveIndustryRules(k)?{'rules':resolveIndustryRules(k)}:{},...resolveIndustryPlaybook(k)?{'playbook':resolveIndustryPlaybook(k)}:{}};break;}case'diff':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27diff\x27');c={'action':'diff',...diffIndustryPack(b['name'])};break;}case'reset':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27reset\x27');const n=resetIndustryPath(b['path']);c={'action':'reset','ok':n['ok'],'layout':n['layout'],'target':n['target'],'restored_files':n['restored_files'],'errors':n['errors']},rescanAffectedPack(b['path']);break;}case'delete_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27delete_file\x27');const o=resolveIndustryPath(b['path']);if(!existsSync(o))throw new Error('file\x20not\x20found:\x20'+b['path']);rmSync(o,{'recursive':!![],'force':!![]}),c={'action':'delete_file','path':o,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_file\x27');const p=resolveIndustryPath(b['path']);if(existsSync(p))throw new Error('file\x20already\x20exists:\x20'+b['path']);if(b['content']!==undefined)assertBaselinesContentValid(b['path'],b['content']);mkdirSync(dirname(p),{'recursive':!![]}),writeFileSync(p,b['content']??'','utf-8'),c={'action':'create_file','path':p,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_dir':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_dir\x27');const q=resolveIndustryPath(b['path']);mkdirSync(q,{'recursive':!![]}),c={'action':'create_dir','path':q,'ok':!![]},rescanAffectedPack(b['path']);break;}case'copy':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27copy\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27copy\x27');const t=resolveIndustryPath(b['from']);let u=resolveIndustryPath(b['to']);if(!existsSync(t))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(u)&&statSync(u)['isDirectory']()&&(u=join(u,basename(t)));}catch{}if(u===t)throw new Error('\x27copy\x27\x20cannot\x20copy\x20a\x20file\x20onto\x20itself');mkdirSync(dirname(u),{'recursive':!![]}),cpSync(t,u,{'recursive':!![],'force':!![]}),c={'action':'copy','from':t,'to':u,'ok':!![]},rescanAffectedPack(b['to']);break;}case'move':case'rename':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');const v=resolveIndustryPath(b['from']);let w=resolveIndustryPath(b['to']);if(!existsSync(v))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(w)&&statSync(w)['isDirectory']()&&(w=join(w,basename(v)));}catch{}if(w===v)throw new Error('\x27'+b['action']+'\x27\x20cannot\x20move\x20onto\x20itself');mkdirSync(dirname(w),{'recursive':!![]}),renameSync(v,w),c={'action':b['action'],'from':v,'to':w,'ok':!![]},rescanAffectedPack(b['from']),rescanAffectedPack(b['to']);break;}case'recommend_industry':c=await handleRecommendIndustry(b);break;case'list_modes':c=await handleListModes();break;case'derive_user_mode':c=await handleDeriveUserMode(b);break;case'evolve_user_mode':c=await handleEvolveUserMode(b);break;case'register_user_mode':c=await handleRegisterUserMode(b);break;case'unregister_user_mode':c=await handleUnregisterUserMode(b);break;case'register_custom_metric':c=await handleRegisterCustomMetric(b);break;case'unregister_custom_metric':c=await handleUnregisterCustomMetric(b);break;case'register_custom_constraint':c=await handleRegisterCustomConstraint(b);break;case'unregister_custom_constraint':c=await handleUnregisterCustomConstraint(b);break;case'list_metrics_constraints':c=await handleListMetricsConstraints(b);break;default:throw new Error('Unknown\x20industry_pack_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':c})}],'structuredContent':{'result':c}};}
1
+ import{readdirSync,readFileSync,writeFileSync,existsSync,mkdirSync,statSync,cpSync,renameSync,rmSync}from'node:fs';import{join,relative,resolve,sep,dirname,basename}from'node:path';import{strictParse}from'../../schema/index.js';import{IndustryPackOperationInputSchema}from'../../schema/industry-pack/index.js';import{validateJudgmentFragment}from'../../config/judgment.js';import{scaffoldIndustryPack,listRegisteredPacks,scanDefaultIndustryPacks,seedBuiltinIndustryTemplates,seedBuiltinStrategyManuals,ensureIndustryReadme,resolveIndustryPackDir,rescanPack,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,diffIndustryPack,resetIndustryPath}from'../../extensions/index.js';import{getIndustryModeRegistry}from'../../extensions/registry.js';import{handleRecommendIndustry,handleListModes,handleDeriveUserMode,handleEvolveUserMode,handleRegisterUserMode,handleUnregisterUserMode,handleRegisterCustomMetric,handleUnregisterCustomMetric,handleRegisterCustomConstraint,handleUnregisterCustomConstraint,handleListMetricsConstraints}from'../../playbooks/service-build/mode-actions.js';import{repairBuiltinTemplates,builtinTemplateDrift,resolveTemplatesDir}from'../../knowledge/template-loader.js';const INDUSTRY_ROOT=resolveIndustryPackDir(),resolveTemplatesDirSafe=resolveTemplatesDir;function resolveIndustryPath(a){const b=resolve(INDUSTRY_ROOT,a);if(b!==INDUSTRY_ROOT&&!b['startsWith'](INDUSTRY_ROOT+sep))throw new Error('path\x20\x27'+a+'\x27\x20escapes\x20the\x20industry\x20root');return b;}function isTemplateTreePath(a){const b=a['split'](/[\\/]+/)['filter'](c=>c['length']>0x0);return b['length']>=0x2&&b[0x1]==='templates';}function assertTemplateWriteAuthorized(a,b,c){if(c===!![])return;const d=b['find'](e=>e!==undefined&&isTemplateTreePath(e));if(!d)return;throw new Error('action=\x27'+a+'\x27\x20modifies\x20the\x20user-editable\x20template\x20file\x20\x27'+d+'\x27.\x20'+'Present\x20the\x20intended\x20change\x20to\x20the\x20user\x20first;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20'+'re-call\x20with\x20authorize=true\x20(C5).');}function rescanAffectedPack(a){const b=a['split'](/[\\/]+/)['find'](c=>c['length']>0x0);if(!b)return;rescanPack(b);}const BASELINES_FILENAME='baselines.json',PACK_FILENAME='pack.json';function assertBaselinesContentValid(a,b){const c=a['split'](/[\\/]+/)['pop']()??'';if(c!==BASELINES_FILENAME&&c!==PACK_FILENAME)return;let d;try{d=JSON['parse'](b);}catch{return;}if(!d||typeof d!=='object'||Array['isArray'](d))return;const e=d,f=c===BASELINES_FILENAME?d:e['baselines'];if(f===undefined||f===null)return;const g=validateJudgmentFragment(f,a+'\x20baselines');if(g)throw new Error('write\x20rejected\x20—\x20the\x20baselines\x20fragment\x20in\x20\x27'+a+'\x27\x20is\x20not\x20a\x20valid\x20judgment\x20fragment:\x20'+g);}function listRecursive(a,b,c,d=0x0){if(d>0x8)return;let f;try{f=readdirSync(a,{'withFileTypes':!![]});}catch{return;}for(const g of f){const h=join(a,g['name']),i=relative(b,h)['split'](sep)['join']('/');let j=0x0,k=0x0;try{const l=statSync(h);k=l['size'],j=l['mtimeMs'];}catch{}g['isDirectory']()?(c['push']({'path':i,'is_dir':!![],'size':0x0,'mtime':j}),listRecursive(h,b,c,d+0x1)):c['push']({'path':i,'is_dir':![],'size':k,'mtime':j});}}export async function handleIndustryPackOperation(a){const b=strictParse(IndustryPackOperationInputSchema,a,'industry_pack_operation\x20input');mkdirSync(INDUSTRY_ROOT,{'recursive':!![]}),seedBuiltinIndustryTemplates(),seedBuiltinStrategyManuals(),ensureIndustryReadme();let c;switch(b['action']){case'scaffold':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27scaffold\x27');const d=scaffoldIndustryPack(b['name']);c={'action':'scaffold','ok':d['ok'],'dir':d['dir'],'files':d['files'],'errors':d['errors']};if(d['ok'])rescanPack(b['name']);break;}case'list':{c={'action':'list','packs':listRegisteredPacks()};break;}case'scan':{c={'action':'scan','results':scanDefaultIndustryPacks()};break;}case'repair_builtin_templates':{if(b['authorize']!==!![]){const g=repairBuiltinTemplates({'backup':!![],'dryRun':!![]}),h=g['filter'](i=>i['status']==='would_update');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':0x0,'requires_authorization':!![],'results':g,'note':h['length']?'PLAN\x20ONLY\x20(no\x20writes)\x20—\x20'+h['length']+'\x20legacy\x20sentinel-less\x20builtin\x20file(s)\x20would\x20be\x20reseeded\x20from\x20the\x20in-code\x20catalog,\x20each\x20previous\x20body\x20preserved\x20as\x20<file>.bak.\x20Present\x20this\x20plan\x20to\x20the\x20user;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20re-call\x20with\x20authorize=true\x20to\x20execute.':'No\x20legacy\x20sentinel-less\x20builtin\x20files\x20found\x20—\x20every\x20builtin\x20template\x20already\x20carries\x20a\x20release\x20sentinel.'};break;}const e=repairBuiltinTemplates({'backup':!![]}),f=e['filter'](i=>i['status']==='updated');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':f['length'],'results':e,'note':f['length']?'Legacy\x20sentinel-less\x20builtin\x20files\x20were\x20reseeded\x20from\x20the\x20in-code\x20catalog.\x20Each\x20previous\x20body\x20is\x20preserved\x20as\x20<file>.bak.':'No\x20legacy\x20sentinel-less\x20builtin\x20files\x20found\x20—\x20every\x20builtin\x20template\x20already\x20carries\x20a\x20release\x20sentinel.'};break;}case'template_drift':{const i=builtinTemplateDrift();c={'action':'template_drift','dir':resolveTemplatesDirSafe(),'drift_count':i['length'],'drift':i,'note':i['length']?'On-disk\x20builtin\x20templates\x20differ\x20from\x20the\x20in-code\x20catalog.\x20Run\x20action=\x27repair_builtin_templates\x27\x20to\x20reseed.':'Every\x20builtin\x20template\x20on\x20disk\x20matches\x20the\x20in-code\x20catalog.'};break;}case'resolve':{c={'action':'resolve','dir':INDUSTRY_ROOT};break;}case'list_files':{const j=[];listRecursive(INDUSTRY_ROOT,INDUSTRY_ROOT,j),c={'action':'list_files','dir':INDUSTRY_ROOT,'files':j};break;}case'read_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27read_file\x27');const k=resolveIndustryPath(b['path']);if(!existsSync(k))throw new Error('file\x20not\x20found:\x20'+b['path']);c={'action':'read_file','path':k,'content':readFileSync(k,'utf-8')};break;}case'write_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');if(b['content']===undefined)throw new Error('\x27content\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');assertTemplateWriteAuthorized('write_file',[b['path']],b['authorize']);const l=resolveIndustryPath(b['path']);assertBaselinesContentValid(b['path'],b['content']),mkdirSync(dirname(l),{'recursive':!![]}),writeFileSync(l,b['content'],'utf-8'),c={'action':'write_file','path':l,'ok':!![]},rescanAffectedPack(b['path']);break;}case'get':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27get\x27');const m=b['name'],n=getIndustryModeRegistry()['getMode'](m),o=n?{'name':n['name'],'display_name':n['display_name'],'key_risk':n['key_risk'],'needs':n['needs']['map'](p=>p['description']),...n['analyze']?.['key_questions']?.['length']?{'analyze_questions':n['analyze']['key_questions']['slice'](0x0,0x2)}:{}}:undefined;c={'action':'get','category':m,...o?{'mode':o}:{},...resolveDisputeRules(m)?{'dispute':resolveDisputeRules(m)}:{},...resolveComplianceRules(m)?{'compliance':resolveComplianceRules(m)}:{},...resolveSupplyRules(m)?{'supply':resolveSupplyRules(m)}:{},...resolveIndustryRules(m)?{'rules':resolveIndustryRules(m)}:{},...resolveIndustryPlaybook(m)?{'playbook':resolveIndustryPlaybook(m)}:{}};break;}case'diff':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27diff\x27');c={'action':'diff',...diffIndustryPack(b['name'])};break;}case'reset':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27reset\x27');assertTemplateWriteAuthorized('reset',[b['path']],b['authorize']);const p=resetIndustryPath(b['path']);c={'action':'reset','ok':p['ok'],'layout':p['layout'],'target':p['target'],'restored_files':p['restored_files'],'errors':p['errors']},rescanAffectedPack(b['path']);break;}case'delete_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27delete_file\x27');assertTemplateWriteAuthorized('delete_file',[b['path']],b['authorize']);const q=resolveIndustryPath(b['path']);if(!existsSync(q))throw new Error('file\x20not\x20found:\x20'+b['path']);rmSync(q,{'recursive':!![],'force':!![]}),c={'action':'delete_file','path':q,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_file\x27');const t=resolveIndustryPath(b['path']);if(existsSync(t))throw new Error('file\x20already\x20exists:\x20'+b['path']);if(b['content']!==undefined)assertBaselinesContentValid(b['path'],b['content']);mkdirSync(dirname(t),{'recursive':!![]}),writeFileSync(t,b['content']??'','utf-8'),c={'action':'create_file','path':t,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_dir':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_dir\x27');const u=resolveIndustryPath(b['path']);mkdirSync(u,{'recursive':!![]}),c={'action':'create_dir','path':u,'ok':!![]},rescanAffectedPack(b['path']);break;}case'copy':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27copy\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27copy\x27');const v=resolveIndustryPath(b['from']);let w=resolveIndustryPath(b['to']);if(!existsSync(v))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(w)&&statSync(w)['isDirectory']()&&(w=join(w,basename(v)));}catch{}if(w===v)throw new Error('\x27copy\x27\x20cannot\x20copy\x20a\x20file\x20onto\x20itself');existsSync(w)&&isTemplateTreePath(b['to'])&&assertTemplateWriteAuthorized('copy',[b['to']],b['authorize']);mkdirSync(dirname(w),{'recursive':!![]}),cpSync(v,w,{'recursive':!![],'force':!![]}),c={'action':'copy','from':v,'to':w,'ok':!![]},rescanAffectedPack(b['to']);break;}case'move':case'rename':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');assertTemplateWriteAuthorized(b['action'],[b['from'],b['to']],b['authorize']);const x=resolveIndustryPath(b['from']);let y=resolveIndustryPath(b['to']);if(!existsSync(x))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(y)&&statSync(y)['isDirectory']()&&(y=join(y,basename(x)));}catch{}if(y===x)throw new Error('\x27'+b['action']+'\x27\x20cannot\x20move\x20onto\x20itself');mkdirSync(dirname(y),{'recursive':!![]}),renameSync(x,y),c={'action':b['action'],'from':x,'to':y,'ok':!![]},rescanAffectedPack(b['from']),rescanAffectedPack(b['to']);break;}case'recommend_industry':c=await handleRecommendIndustry(b);break;case'list_modes':c=await handleListModes();break;case'derive_user_mode':c=await handleDeriveUserMode(b);break;case'evolve_user_mode':c=await handleEvolveUserMode(b);break;case'register_user_mode':c=await handleRegisterUserMode(b);break;case'unregister_user_mode':c=await handleUnregisterUserMode(b);break;case'register_custom_metric':c=await handleRegisterCustomMetric(b);break;case'unregister_custom_metric':c=await handleUnregisterCustomMetric(b);break;case'register_custom_constraint':c=await handleRegisterCustomConstraint(b);break;case'unregister_custom_constraint':c=await handleUnregisterCustomConstraint(b);break;case'list_metrics_constraints':c=await handleListMetricsConstraints(b);break;default:throw new Error('Unknown\x20industry_pack_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':c})}],'structuredContent':{'result':c}};}