@wowok/agent-mcp 3.0.4 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evaluation/path-reasoning.d.ts +4 -2
- package/dist/evaluation/path-reasoning.js +1 -1
- package/dist/extensions/constraint-registry.d.ts +2 -2
- package/dist/extensions/constraint-registry.js +1 -1
- package/dist/extensions/custom-registry-file.d.ts +22 -0
- package/dist/extensions/custom-registry-file.js +1 -0
- package/dist/extensions/index.d.ts +2 -1
- package/dist/extensions/index.js +1 -1
- package/dist/extensions/industry-pack.d.ts +7 -0
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/extensions/metric-registry.d.ts +2 -2
- package/dist/extensions/metric-registry.js +1 -1
- package/dist/extensions/modes.js +1 -1
- package/dist/extensions/registry.d.ts +2 -2
- package/dist/extensions/registry.js +1 -1
- package/dist/extensions/types.d.ts +4 -0
- package/dist/goal/GoalEngine.d.ts +13 -1
- package/dist/goal/GoalEngine.js +1 -1
- package/dist/goal/next-steps.d.ts +12 -0
- package/dist/goal/next-steps.js +1 -0
- package/dist/goal/pursue.d.ts +18 -0
- package/dist/goal/pursue.js +1 -0
- package/dist/goal/types.d.ts +72 -0
- package/dist/goal/types.js +1 -1
- package/dist/graph/onchain/analyze.d.ts +44 -0
- package/dist/graph/onchain/analyze.js +1 -0
- package/dist/graph/onchain/analyze.spec.d.ts +1 -0
- package/dist/graph/onchain/analyze.spec.js +1 -0
- package/dist/graph/onchain/anti-cheat.d.ts +39 -0
- package/dist/graph/onchain/anti-cheat.js +1 -0
- package/dist/graph/onchain/anti-cheat.spec.d.ts +1 -0
- package/dist/graph/onchain/anti-cheat.spec.js +1 -0
- package/dist/graph/onchain/dataplane.d.ts +44 -0
- package/dist/graph/onchain/dataplane.js +1 -0
- package/dist/graph/onchain/edge-schema.d.ts +60 -0
- package/dist/graph/onchain/edge-schema.js +1 -0
- package/dist/graph/onchain/expand.d.ts +4 -0
- package/dist/graph/onchain/expand.js +1 -0
- package/dist/graph/onchain/extract.d.ts +21 -0
- package/dist/graph/onchain/extract.js +1 -0
- package/dist/graph/onchain/index.d.ts +17 -0
- package/dist/graph/onchain/index.js +1 -0
- package/dist/graph/onchain/interest.d.ts +10 -0
- package/dist/graph/onchain/interest.js +1 -0
- package/dist/graph/onchain/interest.spec.d.ts +1 -0
- package/dist/graph/onchain/interest.spec.js +1 -0
- package/dist/graph/onchain/onchain.spec.d.ts +1 -0
- package/dist/graph/onchain/onchain.spec.js +1 -0
- package/dist/graph/onchain/order-status.d.ts +53 -0
- package/dist/graph/onchain/order-status.js +1 -0
- package/dist/graph/onchain/project-relationship.d.ts +3 -0
- package/dist/graph/onchain/project-relationship.js +1 -0
- package/dist/graph/onchain/sdk-batch.d.ts +117 -0
- package/dist/graph/onchain/sdk-batch.js +1 -0
- package/dist/graph/onchain/sdk-dataplane.d.ts +40 -0
- package/dist/graph/onchain/sdk-dataplane.js +1 -0
- package/dist/graph/onchain/strategy.d.ts +54 -0
- package/dist/graph/onchain/strategy.js +1 -0
- package/dist/graph/onchain/strategy.spec.d.ts +1 -0
- package/dist/graph/onchain/strategy.spec.js +1 -0
- package/dist/graph/onchain/types.d.ts +238 -0
- package/dist/graph/onchain/types.js +1 -0
- package/dist/graph/onchain/viewport.d.ts +5 -0
- package/dist/graph/onchain/viewport.js +1 -0
- package/dist/harness/recover.js +1 -1
- package/dist/index.js +1 -1
- package/dist/intent/enrich.js +1 -1
- package/dist/keeper/detectors.d.ts +1 -1
- package/dist/keeper/detectors.js +1 -1
- package/dist/knowledge/account-marks.js +1 -1
- package/dist/knowledge/anti-cheat.d.ts +2 -37
- package/dist/knowledge/anti-cheat.js +1 -1
- package/dist/knowledge/contract-invariants.js +1 -1
- package/dist/knowledge/getting-started.d.ts +37 -0
- package/dist/knowledge/getting-started.js +1 -0
- package/dist/knowledge/goal-completion.js +1 -1
- package/dist/knowledge/guard-render.d.ts +1 -0
- package/dist/knowledge/guard-render.js +1 -1
- package/dist/knowledge/guard-submission-brief.d.ts +83 -0
- package/dist/knowledge/guard-submission-brief.js +1 -0
- package/dist/knowledge/guard-submission-prompt.d.ts +13 -0
- package/dist/knowledge/guard-submission-prompt.js +1 -1
- package/dist/knowledge/index.d.ts +6 -4
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/industry-strategy.d.ts +91 -0
- package/dist/knowledge/industry-strategy.js +1 -0
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/market-metrics.d.ts +14 -3
- package/dist/knowledge/market-metrics.js +1 -1
- package/dist/knowledge/migration-preflight.js +1 -1
- package/dist/knowledge/operation-dictionary.d.ts +1 -1
- package/dist/knowledge/safety-rules.js +1 -1
- package/dist/knowledge/scenario-topology.d.ts +6 -1
- package/dist/knowledge/scenario-topology.js +1 -1
- package/dist/knowledge/service-risk-node.d.ts +3 -0
- package/dist/knowledge/service-risk-node.js +1 -0
- package/dist/knowledge/service-risk.d.ts +2 -0
- package/dist/knowledge/service-risk.js +1 -1
- package/dist/knowledge/service-templates.d.ts +2 -0
- package/dist/knowledge/service-templates.js +1 -1
- package/dist/knowledge/strategy-manuals.d.ts +17 -0
- package/dist/knowledge/strategy-manuals.js +1 -0
- package/dist/knowledge/supply-chain.d.ts +3 -1
- package/dist/knowledge/supply-chain.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +3 -118
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/knowledge/workspace-lists.js +1 -1
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/monitor/ScopeResolver.js +1 -1
- package/dist/participation/radar-core.d.ts +15 -15
- package/dist/participation/radar-core.js +1 -1
- package/dist/persona/analyzer.d.ts +2 -1
- package/dist/persona/bridge.d.ts +5 -1
- package/dist/persona/bridge.js +1 -1
- package/dist/persona/defaults.js +1 -1
- package/dist/persona/distill-goal.d.ts +7 -1
- package/dist/persona/distill-goal.js +1 -1
- package/dist/persona/index.d.ts +13 -3
- package/dist/persona/index.js +1 -1
- package/dist/persona/model.d.ts +12 -2
- package/dist/persona/model.js +1 -1
- package/dist/persona/overrides.d.ts +1 -0
- package/dist/persona/overrides.js +1 -1
- package/dist/persona/topology-focus.d.ts +29 -0
- package/dist/persona/topology-focus.js +1 -0
- package/dist/persona/types.d.ts +81 -0
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/context-assembly.js +1 -1
- package/dist/playbooks/service-build/machine-nodes.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.d.ts +1 -0
- package/dist/playbooks/service-build/relationship-profile.js +1 -1
- package/dist/playbooks/service-build/service-panorama.d.ts +4 -0
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/topology-query.d.ts +14 -0
- package/dist/playbooks/service-build/topology-query.js +1 -0
- package/dist/role/index.d.ts +1 -0
- package/dist/role/index.js +1 -1
- package/dist/role/profiles.d.ts +26 -0
- package/dist/role/profiles.js +1 -0
- package/dist/safety/confirm-gate.d.ts +4 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/call/allocation.d.ts +6 -6
- package/dist/schema/call/bridge.d.ts +1 -1
- package/dist/schema/call/guard.d.ts +20 -20
- package/dist/schema/call/repository.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +4 -4
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/employee/index.d.ts +7 -7
- package/dist/schema/evaluation/index.d.ts +22 -9
- package/dist/schema/evaluation/index.js +1 -1
- package/dist/schema/goal/index.d.ts +37 -1
- package/dist/schema/goal/index.js +1 -1
- package/dist/schema/goal/planning.d.ts +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -1
- package/dist/schema/industry-pack/index.d.ts +7 -0
- package/dist/schema/industry-pack/index.js +1 -1
- package/dist/schema/local/index.d.ts +8 -4
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/messenger/index.d.ts +318 -64
- package/dist/schema/messenger/index.js +1 -1
- package/dist/schema/operations.d.ts +146 -11
- package/dist/schema/operations.js +1 -1
- package/dist/schema/persona/index.d.ts +15743 -0
- package/dist/schema/persona/index.js +1 -1
- package/dist/schema/query/bi.d.ts +869 -2
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/query/index.d.ts +163 -41
- package/dist/schema/query/index.js +1 -1
- package/dist/schema/schema-query/index.d.ts +16 -0
- package/dist/schema/schema-query/index.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/strategy-review/index.d.ts +137 -0
- package/dist/schema/strategy-review/index.js +1 -0
- package/dist/schema/trust/index.d.ts +6 -6
- package/dist/schema/workflow/index.d.ts +2 -2
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +8 -4
- package/dist/schemas/account_operation.schema.json +6 -2
- package/dist/schemas/evaluation_operation.output.json +24 -0
- package/dist/schemas/goal_operation.schema.json +124 -0
- package/dist/schemas/index.json +7 -1
- package/dist/schemas/industry_pack_operation.output.json +39 -0
- package/dist/schemas/local_mark_operation.schema.json +2 -2
- package/dist/schemas/messenger_operation.output.json +670 -200
- package/dist/schemas/messenger_operation.schema.json +66 -239
- package/dist/schemas/onchain_operations.schema.json +3 -3
- package/dist/schemas/onchain_operations_repository.schema.json +3 -3
- package/dist/schemas/onchain_table_data.output.json +184 -0
- package/dist/schemas/onchain_table_data.schema.json +43 -43
- package/dist/schemas/persona_operation.output.json +37778 -262
- package/dist/schemas/persona_operation.schema.json +5960 -1
- package/dist/schemas/query_toolkit.output.json +1580 -2
- package/dist/schemas/query_toolkit.schema.json +194 -32
- package/dist/schemas/schema_query.schema.json +25 -1
- package/dist/schemas/strategy_review_operation.output.json +532 -0
- package/dist/schemas/strategy_review_operation.schema.json +66 -0
- package/dist/schemas/wowok_buildin_info.output.json +188 -6
- package/dist/schemas/wowok_buildin_info.schema.json +14 -0
- package/dist/strategy/collectors.d.ts +66 -0
- package/dist/strategy/collectors.js +1 -0
- package/dist/strategy/collectors.spec.d.ts +1 -0
- package/dist/strategy/collectors.spec.js +1 -0
- package/dist/strategy/index.d.ts +5 -0
- package/dist/strategy/index.js +1 -0
- package/dist/strategy/metrics.d.ts +20 -0
- package/dist/strategy/metrics.js +1 -0
- package/dist/strategy/review.d.ts +48 -0
- package/dist/strategy/review.js +1 -0
- package/dist/strategy/scorecard.d.ts +32 -0
- package/dist/strategy/scorecard.js +1 -0
- package/dist/strategy/store.d.ts +26 -0
- package/dist/strategy/store.js +1 -0
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/evaluation.js +1 -1
- package/dist/tools/handlers/goal.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/local.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/permission.js +1 -1
- package/dist/tools/handlers/persona.js +1 -1
- package/dist/tools/handlers/query.d.ts +6 -0
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/handlers/schema-query.js +1 -1
- package/dist/tools/handlers/strategy-review.d.ts +2 -0
- package/dist/tools/handlers/strategy-review.js +1 -0
- package/dist/tools/handlers/watch.js +1 -1
- package/dist/tools/handlers/workflow.js +1 -1
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +1 -1
- package/dist/tools/registry/agent.js +1 -1
- package/dist/tools/registry/business.js +1 -1
- package/dist/tools/registry/local.js +1 -1
- package/dist/tools/registry/messenger.js +1 -1
- package/dist/tools/registry/query.js +1 -1
- package/dist/tools/rules-hook.js +1 -1
- package/dist/tools/shared.d.ts +2 -1
- package/dist/tools/shared.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CommercialRole } from "../role/types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { NodeAnnotations } from "../participation/radar-core.js";
|
|
3
3
|
import { type RiskAppetite } from "./game-strategy.js";
|
|
4
|
+
import { type WorkflowSubgraph, type WfTransitionView } from "../graph/onchain/order-status.js";
|
|
4
5
|
export interface WorkflowPath {
|
|
5
6
|
id: string;
|
|
6
7
|
nodes: string[];
|
|
@@ -17,7 +18,7 @@ export interface WorkflowPath {
|
|
|
17
18
|
export interface PathReasoningInput {
|
|
18
19
|
current_node: string;
|
|
19
20
|
perspective: CommercialRole;
|
|
20
|
-
|
|
21
|
+
workflow: WorkflowSubgraph;
|
|
21
22
|
node_annotations?: NodeAnnotations;
|
|
22
23
|
appetite?: RiskAppetite;
|
|
23
24
|
requirements?: string[];
|
|
@@ -33,3 +34,4 @@ export interface PathReasoningAdvice {
|
|
|
33
34
|
summary: string;
|
|
34
35
|
}
|
|
35
36
|
export declare function evaluatePathReasoning(input: PathReasoningInput): PathReasoningAdvice;
|
|
37
|
+
export type { WorkflowSubgraph, WfTransitionView };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{evaluateOutcome}from'./game-strategy.js';
|
|
1
|
+
import{evaluateOutcome}from'./game-strategy.js';import{annotateNodeName}from'../graph/onchain/order-status.js';function terminalKind(a,b,c){if(!b['terminalNames']['has'](a))return null;const d=a['toLowerCase']();if(c?.['refunded']?.['some'](f=>!!f&&d['includes'](f['toLowerCase']())))return'refunded';if(c?.['completed']?.['some'](f=>!!f&&d['includes'](f['toLowerCase']())))return'completed';const e=annotateNodeName(a);return e==='refund'||e==='exception'?'refunded':'completed';}function buildAdjacency(a){const b=new Map();for(const d of a['transitions']){let e=b['get'](d['prevNode']);!e&&(e=new Map(),b['set'](d['prevNode'],e));let f=e['get'](d['node']);!f&&(f={'to_node':d['node'],'forwards':[],'threshold':d['threshold']},e['set'](d['node'],f)),d['forward']&&f['forwards']['push']({'name':d['forward'],'guard':d['guard'],'weight':d['weight']});}const c=new Map();for(const [g,h]of b)c['set'](g,[...h['values']()]);return c;}function enumeratePaths(a,b,c,d,e){const f=[],g=(i,j)=>{f['push']({'nodes':i['map'](k=>k['node']),'forwards':i['map'](k=>k['forward']),'terminal':j,'guard_gates':i['filter'](k=>k['guard'])['length']});},h=(i,j,k)=>{if(j['length']>0x0){const m=terminalKind(i,b,d);if(m){g(j,m);return;}}if(j['length']>=e){g(j,'open');return;}const l=a['get'](i)??[];if(l['length']===0x0&&j['length']>0x0){g(j,'open');return;}for(const n of l){if(k['has'](n['to_node']))continue;const o=n['forwards']['length']>0x0?n['forwards']:[{'name':'(auto)','guard':null}];for(const p of o){const q=new Set(k);q['add'](n['to_node']),h(n['to_node'],[...j,{'node':n['to_node'],'forward':p['name'],'guard':!!p['guard']}],q);}}};return h(c,[],new Set([c])),f;}function terminalScore(a,b,c){const d=a==='refunded'?'refund':a==='completed'?'completion':'advance',e=evaluateOutcome(d,b,c);return{'net':e['net_score'],'gain':e['gain_score'],'risk':e['risk_score']};}const LENGTH_COST=0x4,GATE_COST=0x5;export function evaluatePathReasoning(a){const {current_node:b,perspective:c,workflow:d,node_annotations:e,appetite:f,requirements:g}=a,h=a['max_depth']??0xc,i=buildAdjacency(d),j=f||g?.['length']?{'risk_appetite':f,'requirements':g}:undefined,k=enumeratePaths(i,d,b,e,h),l=k['map'](r=>{const s=terminalScore(r['terminal'],c,j),u=r['forwards']['length'],v=u*LENGTH_COST,w=r['guard_gates']*GATE_COST,x=Math['max'](0x0,Math['min'](0x64,s['net']-v-w));return{'id':[b,...r['nodes']]['join']('→'),'nodes':r['nodes'],'forwards':r['forwards'],'terminal':r['terminal'],'guard_gates':r['guard_gates'],'length':u,'terminal_value':s['net'],'gain_score':s['gain'],'risk_score':s['risk'],'score':x,'rationale':'terminal='+r['terminal']+'\x20value='+s['net']+'/100;\x20'+u+'\x20step(s),\x20'+r['guard_gates']+'\x20guard\x20gate(s)\x20(−'+(v+w)+')'};});l['sort']((r,s)=>{const t=r['terminal']==='open'?0x1:0x0,u=s['terminal']==='open'?0x1:0x0;if(t!==u)return t-u;return s['score']-r['score'];});const m=l['length']>0x0&&l[0x0]['terminal']!=='open'?l[0x0]:undefined,n=m?.['terminal'],o=new Set(l['filter'](r=>r['terminal']!=='open')['map'](r=>r['terminal']));o['delete'](n);const p=m?Array['from'](o):[];let q;return!m?q='No\x20structural\x20terminal\x20path\x20reachable\x20from\x20\x27'+(b||'(entry)')+'\x27\x20—\x20workflow\x20may\x20be\x20stuck\x20or\x20its\x20nodes\x20were\x20not\x20fetched.':(q='Optimal\x20path\x20for\x20'+c+':\x20'+m['id']+'\x20→\x20'+m['terminal']+'\x20(score\x20'+m['score']+'/100,\x20'+m['length']+'\x20step(s),\x20'+m['guard_gates']+'\x20guard\x20gate(s))',p['length']>0x0&&(q+='\x20—\x20choosing\x20it\x20foregoes\x20'+p['join']('/')+'\x20(opportunity\x20competition:\x20your\x20gain\x20may\x20close\x20another\x20outcome).')),{'current_node':b,'perspective':c,'ranked_paths':l,'optimal_path':m,'foregone_terminals':p,'summary':q};}
|
|
@@ -3,8 +3,8 @@ import type { CapabilityRegistry } from "./capability-manifest.js";
|
|
|
3
3
|
export declare class ConstraintRegistry {
|
|
4
4
|
private static instance;
|
|
5
5
|
private constraints;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
6
|
+
private file;
|
|
7
|
+
private customSyncedMtime;
|
|
8
8
|
static Instance(): ConstraintRegistry;
|
|
9
9
|
private constructor();
|
|
10
10
|
ensureLoaded(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{CustomRegistryFile}from'./custom-registry-file.js';const BUILTIN_CONSTRAINTS=[{'constraint_id':'require_arbitration','display_name':'Require\x20Arbitration','description':'Mode\x20must\x20include\x20arbitration\x20capability\x20(arb.*)\x20for\x20dispute\x20resolution','rule':{'type':'capability_required','capability_id':'arb.vote_weighted'},'severity':'hard','on_violation':'block','scope':'builtin'},{'constraint_id':'require_compensation_fund','display_name':'Require\x20Compensation\x20Fund','description':'Mode\x20must\x20include\x20fund\x20escrow\x20capability\x20(treasury.*)\x20for\x20compensation\x20fund','rule':{'type':'capability_required','capability_id':'treasury.owner_receive'},'severity':'hard','on_violation':'block','scope':'builtin'},{'constraint_id':'require_wip_evidence','display_name':'Require\x20WIP\x20Evidence','description':'Mode\x20must\x20include\x20WIP\x20evidence\x20capability\x20(guard.validate_wip_hash)\x20for\x20digital\x20delivery\x20validation','rule':{'type':'capability_required','capability_id':'guard.validate_wip_hash'},'severity':'soft','on_violation':'warn','scope':'builtin'},{'constraint_id':'max_single_transaction_limit','display_name':'Single\x20Transaction\x20Limit','description':'Single\x20transaction\x20amount\x20must\x20not\x20exceed\x2010000\x20WOW\x20(default\x20value,\x20can\x20be\x20overridden\x20by\x20mode)','rule':{'type':'numeric_limit','field':'max_single_transaction','max':0x2710},'severity':'soft','on_violation':'warn','scope':'builtin'}];export class ConstraintRegistry{static ['instance'];['constraints']=new Map();['file']=CustomRegistryFile['Instance']();['customSyncedMtime']=-0x1;static['Instance'](){return!ConstraintRegistry['instance']&&(ConstraintRegistry['instance']=new ConstraintRegistry()),ConstraintRegistry['instance'];}constructor(){this['registerBuiltinConstraints']();}async['ensureLoaded'](){const {data:a,mtime:b}=await this['file']['read']();if(b<0x0||b===this['customSyncedMtime'])return;this['customSyncedMtime']=b;for(const [c,d]of this['constraints']){if(d['scope']==='custom')this['constraints']['delete'](c);}for(const e of Object['values'](a['constraints'])){const f=e;f?.['constraint_id']&&f['scope']==='custom'?this['constraints']['set'](f['constraint_id'],f):console['warn']('[ConstraintRegistry]\x20Skipping\x20invalid\x20custom_constraints\x20file\x20entry.');}}['registerConstraint'](a){if(!a['constraint_id']||!a['rule'])return![];if(this['constraints']['has'](a['constraint_id']))return![];return this['constraints']['set'](a['constraint_id'],a),!![];}async['registerCustomConstraint'](a,b,c,d,e,f='soft',g='warn'){await this['ensureLoaded']();const h={'constraint_id':a,'display_name':b,'description':c,'rule':d,'severity':f,'on_violation':g,'scope':'custom','owner':e},i=this['registerConstraint'](h);return i&&await this['file']['update'](j=>{j['constraints'][a]=h;}),i;}['getConstraint'](a){return this['constraints']['get'](a);}async['listConstraints'](a){await this['ensureLoaded']();let b=Array['from'](this['constraints']['values']());if(!a)return b;if(a['scope'])b=b['filter'](d=>d['scope']===a['scope']);if(a['owner'])b=b['filter'](d=>d['owner']===a['owner']);if(a['severity'])b=b['filter'](d=>d['severity']===a['severity']);return b;}async['unregisterConstraint'](a,b){await this['ensureLoaded']();const c=this['constraints']['get'](a);if(!c||c['scope']!=='custom'||c['owner']!==b)return![];const d=this['constraints']['delete'](a);return d&&await this['file']['update'](e=>{delete e['constraints'][a];}),d;}['checkConstraints'](a,b,d){const e=new Set(a['disabled_builtin_constraints']??[]),f=[...this['constraints']['values']()]['filter'](h=>!(h['scope']==='builtin'&&e['has'](h['constraint_id'])));if(d)for(const h of d){!f['some'](i=>i['constraint_id']===h['constraint_id'])&&f['push'](h);}const g=[];for(const i of f){const j=this['checkConstraint'](a,i);j&&g['push'](j);}return g;}['checkConstraint'](a,b){const c=b['rule'];switch(c['type']){case'capability_required':{if(!a['capabilities_used']['includes'](c['capability_id']))return{'constraint_id':b['constraint_id'],'display_name':b['display_name'],'violation':'Missing\x20required\x20capability:\x20'+c['capability_id'],'severity':b['severity'],'action':b['on_violation'],'recommendation':'Add\x20\x22'+c['capability_id']+'\x22\x20to\x20capabilities_used'};return null;}case'capability_forbidden':{if(a['capabilities_used']['includes'](c['capability_id']))return{'constraint_id':b['constraint_id'],'display_name':b['display_name'],'violation':'Contains\x20forbidden\x20capability:\x20'+c['capability_id'],'severity':b['severity'],'action':b['on_violation'],'recommendation':'Remove\x20\x22'+c['capability_id']+'\x22\x20from\x20capabilities_used'};return null;}case'numeric_limit':{const d=this['getNumericField'](a,c['field']);if(d===undefined)return null;if(c['max']!==undefined&&d>c['max'])return{'constraint_id':b['constraint_id'],'display_name':b['display_name'],'violation':c['field']+'='+d+'\x20exceeds\x20upper\x20limit\x20'+c['max'],'severity':b['severity'],'action':b['on_violation'],'recommendation':'Reduce\x20'+c['field']+'\x20below\x20'+c['max']};if(c['min']!==undefined&&d<c['min'])return{'constraint_id':b['constraint_id'],'display_name':b['display_name'],'violation':c['field']+'='+d+'\x20below\x20lower\x20limit\x20'+c['min'],'severity':b['severity'],'action':b['on_violation'],'recommendation':'Increase\x20'+c['field']+'\x20above\x20'+c['min']};return null;}case'condition_required':{return{'constraint_id':b['constraint_id'],'display_name':b['display_name'],'violation':'Natural\x20language\x20condition\x20pending\x20AI\x20evaluation:\x20\x22'+c['condition']+'\x22','severity':b['severity'],'action':b['on_violation'],'recommendation':'Please\x20have\x20AI\x20evaluate\x20whether\x20this\x20condition\x20is\x20satisfied,\x20and\x20update\x20the\x20mode\x20configuration'};}default:return null;}}['getNumericField'](a,b){if(b==='max_single_transaction')return a['risk_constraints']['max_single_transaction'];return undefined;}['registerBuiltinConstraints'](){for(const a of BUILTIN_CONSTRAINTS){this['registerConstraint'](a);}}}export function getConstraintRegistry(){return ConstraintRegistry['Instance']();}export const BUILTIN_CONSTRAINTS_COUNT=BUILTIN_CONSTRAINTS['length'];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface CustomRegistryFileData {
|
|
2
|
+
version: number;
|
|
3
|
+
metrics: Record<string, unknown>;
|
|
4
|
+
constraints: Record<string, unknown>;
|
|
5
|
+
user_modes: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface CustomRegistryRead {
|
|
8
|
+
data: CustomRegistryFileData;
|
|
9
|
+
mtime: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class CustomRegistryFile {
|
|
12
|
+
private static instance;
|
|
13
|
+
static Instance(): CustomRegistryFile;
|
|
14
|
+
private cached;
|
|
15
|
+
private cachedMtime;
|
|
16
|
+
private migrationDone;
|
|
17
|
+
private queue;
|
|
18
|
+
private filePath;
|
|
19
|
+
read(): Promise<CustomRegistryRead>;
|
|
20
|
+
update(mutate: (data: CustomRegistryFileData) => void): Promise<void>;
|
|
21
|
+
private migrateLegacySqlite;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync,mkdirSync,readFileSync,renameSync,statSync,writeFileSync}from'node:fs';import{join}from'node:path';import{OwnedRecordStorage}from'@wowok/wowok';import{resolveIndustryPackDir}from'./industry-pack.js';const CUSTOM_REGISTRY_FILENAME='custom-registry.json';function emptyData(){return{'version':0x1,'metrics':{},'constraints':{},'user_modes':{}};}export class CustomRegistryFile{static ['instance'];static['Instance'](){return!CustomRegistryFile['instance']&&(CustomRegistryFile['instance']=new CustomRegistryFile()),CustomRegistryFile['instance'];}['cached'];['cachedMtime']=-0x1;['migrationDone']=![];['queue']=Promise['resolve']();['filePath'](){return join(resolveIndustryPackDir(),CUSTOM_REGISTRY_FILENAME);}async['read'](){try{const a=this['filePath']();if(!existsSync(a)){await this['migrateLegacySqlite'](a);if(!existsSync(a))return{'data':emptyData(),'mtime':-0x1};}const b=statSync(a)['mtimeMs'];if(this['cached']&&b===this['cachedMtime'])return{'data':this['cached'],'mtime':b};const c=JSON['parse'](readFileSync(a,'utf-8')),d={'version':typeof c['version']==='number'?c['version']:0x1,'metrics':c['metrics']&&typeof c['metrics']==='object'?c['metrics']:{},'constraints':c['constraints']&&typeof c['constraints']==='object'?c['constraints']:{},'user_modes':c['user_modes']&&typeof c['user_modes']==='object'?c['user_modes']:{}};return this['cached']=d,this['cachedMtime']=b,{'data':d,'mtime':b};}catch(e){return console['warn']('[CustomRegistryFile]\x20Failed\x20to\x20read\x20\x27'+CUSTOM_REGISTRY_FILENAME+'\x27:',e['message']),{'data':emptyData(),'mtime':-0x1};}}async['update'](a){const b=this['queue']['then'](async()=>{try{const {data:c}=await this['read']();a(c);const d=this['filePath']();mkdirSync(resolveIndustryPackDir(),{'recursive':!![]});const e=d+'.tmp';writeFileSync(e,JSON['stringify'](c,null,0x2)+'\x0a','utf-8'),renameSync(e,d),this['cached']=c,this['cachedMtime']=statSync(d)['mtimeMs'];}catch(f){console['warn']('[CustomRegistryFile]\x20Failed\x20to\x20update\x20\x27'+CUSTOM_REGISTRY_FILENAME+'\x27:',f['message']);}});return this['queue']=b['catch'](()=>{}),b;}async['migrateLegacySqlite'](a){if(this['migrationDone'])return;this['migrationDone']=!![];const b=emptyData(),c=[{'storage':new OwnedRecordStorage('user_modes'),'section':'user_modes','keyedByOwner':!![],'label':'user\x20modes'},{'storage':new OwnedRecordStorage('custom_metrics'),'section':'metrics','keyedByOwner':![],'label':'custom\x20metrics'},{'storage':new OwnedRecordStorage('custom_constraints'),'section':'constraints','keyedByOwner':![],'label':'custom\x20constraints'}];for(const e of c){try{for(const f of await e['storage']['list']()){const g=e['keyedByOwner']?f['owner']+':'+f['name']:f['name'];b[e['section']][g]=JSON['parse'](f['data']);}}catch(h){console['warn']('[CustomRegistryFile]\x20Legacy\x20migration\x20skipped\x20'+e['label']+':',h['message']);}}const d=Object['keys'](b['metrics'])['length']+Object['keys'](b['constraints'])['length']+Object['keys'](b['user_modes'])['length'];try{mkdirSync(resolveIndustryPackDir(),{'recursive':!![]}),writeFileSync(a,JSON['stringify'](b,null,0x2)+'\x0a','utf-8'),d>0x0&&console['log']('[CustomRegistryFile]\x20Migrated\x20'+d+'\x20legacy\x20SQLite\x20record(s)\x20to\x20\x27'+CUSTOM_REGISTRY_FILENAME+'\x27.');}catch(i){console['warn']('[CustomRegistryFile]\x20Failed\x20to\x20write\x20migrated\x20\x27'+CUSTOM_REGISTRY_FILENAME+'\x27:',i['message']);}}}
|
|
@@ -5,11 +5,12 @@ export type { ModeConstraint, ConstraintRule, ConstraintSeverity, ConstraintViol
|
|
|
5
5
|
export { CapabilityRegistry, getCapabilityRegistry, CAPABILITY_MANIFEST_VERSION, } from "./capability-manifest.js";
|
|
6
6
|
export type { CapabilityCard, CapabilityModule, CapabilityCategory, IndustryAgnostic, CapabilityRiskProfile, CapabilityBenefitProfile, CapabilityConstraints, } from "./capability-manifest.js";
|
|
7
7
|
export { IndustryModeRegistry, getIndustryModeRegistry, INDUSTRY_MODE_REGISTRY_VERSION, } from "./registry.js";
|
|
8
|
+
export { CustomRegistryFile } from "./custom-registry-file.js";
|
|
8
9
|
export { MetricRegistry, getMetricRegistry, BUILTIN_METRICS_COUNT, } from "./metric-registry.js";
|
|
9
10
|
export { ConstraintRegistry, getConstraintRegistry, BUILTIN_CONSTRAINTS_COUNT, } from "./constraint-registry.js";
|
|
10
11
|
export { ModeEvaluator } from "./mode-evaluator.js";
|
|
11
12
|
export { BUILTIN_MODES } from "./modes.js";
|
|
12
|
-
export { registerIndustryPack, validatePackManifest, listRegisteredPacks, unregisterIndustryPack, scanPacks, rescanPack, resolveIndustryPackDir, scanDefaultIndustryPacks, scaffoldIndustryPack, seedBuiltinIndustryTemplates, diffIndustryPack, resetIndustryPath, readMergedPackIfPresent, buildPristineMergedPack, locatePackAndRemainder, ensureIndustryReadme, industryReadmeContent, } from "./industry-pack.js";
|
|
13
|
+
export { registerIndustryPack, validatePackManifest, listRegisteredPacks, unregisterIndustryPack, scanPacks, rescanPack, resolveIndustryPackDir, scanDefaultIndustryPacks, scaffoldIndustryPack, seedBuiltinIndustryTemplates, seedBuiltinStrategyManuals, type StrategyManualSeedResult, diffIndustryPack, resetIndustryPath, readMergedPackIfPresent, buildPristineMergedPack, locatePackAndRemainder, ensureIndustryReadme, industryReadmeContent, } from "./industry-pack.js";
|
|
13
14
|
export type { IndustryPackManifest, IndustryPack, IndustryPackLayout, MergedIndustryPack, PackValidation, PackRegistrationResult, PackRecord, ScaffoldResult, PackDiffResult, ResetResult, } from "./industry-pack.js";
|
|
14
15
|
export { registerDisputeRules, registerComplianceRules, registerSupplyRules, registerIndustryRules, registerIndustryPlaybook, resolveDisputeRules, resolveComplianceRules, resolveSupplyRules, resolveIndustryRules, resolveIndustryPlaybook, listRegisteredDisputeCategories, listRegisteredComplianceCategories, listRegisteredSupplyCategories, listRegisteredIndustryRuleCategories, listRegisteredPlaybookCategories, compileIndustryRule, compileIndustryRules, registerIndustryRulesToEngine, unregisterIndustryRulesFromEngine, } from "./industry-layers.js";
|
|
15
16
|
export type { DisputeSlaTier, IndustryDisputeRules, ComplianceRules, SupplyRules, IndustryRule, IndustryRuleCondition, IndustryRuleOperator, IndustryRules, IndustryPlaybook, } from "./industry-layers.js";
|
package/dist/extensions/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{CapabilityRegistry,getCapabilityRegistry,CAPABILITY_MANIFEST_VERSION}from'./capability-manifest.js';export{IndustryModeRegistry,getIndustryModeRegistry,INDUSTRY_MODE_REGISTRY_VERSION}from'./registry.js';export{MetricRegistry,getMetricRegistry,BUILTIN_METRICS_COUNT}from'./metric-registry.js';export{ConstraintRegistry,getConstraintRegistry,BUILTIN_CONSTRAINTS_COUNT}from'./constraint-registry.js';export{ModeEvaluator}from'./mode-evaluator.js';export{BUILTIN_MODES}from'./modes.js';export{registerIndustryPack,validatePackManifest,listRegisteredPacks,unregisterIndustryPack,scanPacks,rescanPack,resolveIndustryPackDir,scanDefaultIndustryPacks,scaffoldIndustryPack,seedBuiltinIndustryTemplates,diffIndustryPack,resetIndustryPath,readMergedPackIfPresent,buildPristineMergedPack,locatePackAndRemainder,ensureIndustryReadme,industryReadmeContent}from'./industry-pack.js';export{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,listRegisteredDisputeCategories,listRegisteredComplianceCategories,listRegisteredSupplyCategories,listRegisteredIndustryRuleCategories,listRegisteredPlaybookCategories,compileIndustryRule,compileIndustryRules,registerIndustryRulesToEngine,unregisterIndustryRulesFromEngine}from'./industry-layers.js';export{registerIndustryPersonae,getIndustryPersona,listPersonaeIndustries,unregisterIndustryPersonae}from'../persona/pack-personae.js';
|
|
1
|
+
export{CapabilityRegistry,getCapabilityRegistry,CAPABILITY_MANIFEST_VERSION}from'./capability-manifest.js';export{IndustryModeRegistry,getIndustryModeRegistry,INDUSTRY_MODE_REGISTRY_VERSION}from'./registry.js';export{CustomRegistryFile}from'./custom-registry-file.js';export{MetricRegistry,getMetricRegistry,BUILTIN_METRICS_COUNT}from'./metric-registry.js';export{ConstraintRegistry,getConstraintRegistry,BUILTIN_CONSTRAINTS_COUNT}from'./constraint-registry.js';export{ModeEvaluator}from'./mode-evaluator.js';export{BUILTIN_MODES}from'./modes.js';export{registerIndustryPack,validatePackManifest,listRegisteredPacks,unregisterIndustryPack,scanPacks,rescanPack,resolveIndustryPackDir,scanDefaultIndustryPacks,scaffoldIndustryPack,seedBuiltinIndustryTemplates,seedBuiltinStrategyManuals,diffIndustryPack,resetIndustryPath,readMergedPackIfPresent,buildPristineMergedPack,locatePackAndRemainder,ensureIndustryReadme,industryReadmeContent}from'./industry-pack.js';export{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,listRegisteredDisputeCategories,listRegisteredComplianceCategories,listRegisteredSupplyCategories,listRegisteredIndustryRuleCategories,listRegisteredPlaybookCategories,compileIndustryRule,compileIndustryRules,registerIndustryRulesToEngine,unregisterIndustryRulesFromEngine}from'./industry-layers.js';export{registerIndustryPersonae,getIndustryPersona,listPersonaeIndustries,unregisterIndustryPersonae}from'../persona/pack-personae.js';
|
|
@@ -78,6 +78,13 @@ export declare function rescanPack(name: string): PackRegistrationResult;
|
|
|
78
78
|
export declare function resolveIndustryPackDir(): string;
|
|
79
79
|
export declare function scanDefaultIndustryPacks(): PackRegistrationResult[];
|
|
80
80
|
export declare function seedBuiltinIndustryTemplates(names?: string[]): string[];
|
|
81
|
+
export interface StrategyManualSeedResult {
|
|
82
|
+
industry: string;
|
|
83
|
+
status: "written" | "updated" | "current" | "skipped_user_file" | "skipped_user_modified" | "error";
|
|
84
|
+
path: string;
|
|
85
|
+
detail?: string;
|
|
86
|
+
}
|
|
87
|
+
export declare function seedBuiltinStrategyManuals(names?: string[]): StrategyManualSeedResult[];
|
|
81
88
|
export interface ScaffoldResult {
|
|
82
89
|
ok: boolean;
|
|
83
90
|
dir: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readdirSync,readFileSync,existsSync,mkdirSync,writeFileSync}from'node:fs';import{join}from'node:path';import{getWowokIndustryDir}from'@wowok/wowok';import{getIndustryModeRegistry}from'./registry.js';import{BUILTIN_MODES}from'./modes.js';import{registerCategoryMatchRules}from'../evaluation/category-match-rules.js';import{registerIndustryPersonae,unregisterIndustryPersonae}from'../persona/pack-personae.js';import{PERSONA_ROLES,SUPPORTED_INDUSTRIES}from'../persona/types.js';import{UNIVERSAL_TEMPLATE}from'../knowledge/universal-template.js';import{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,registerIndustryRulesToEngine}from'./industry-layers.js';const FORBIDDEN_PRICING_MODES=new Set(UNIVERSAL_TEMPLATE['pricing_redlines']),packRegistry=new Map();export function validatePackManifest(a){const b=[];return(!a||a['pack']!=='industry-pack')&&b['push']('manifest.pack\x20must\x20be\x20\x27industry-pack\x27'),(!a['name']||typeof a['name']!=='string')&&b['push']('manifest.name\x20is\x20required'),(!a['version']||typeof a['version']!=='string')&&b['push']('manifest.version\x20is\x20required'),(!Array['isArray'](a['layers'])||a['layers']['length']===0x0)&&b['push']('manifest.layers\x20must\x20be\x20a\x20non-empty\x20array'),{'valid':b['length']===0x0,'errors':b};}function isMeaningfulMatch(a){if(!a)return![];return(a['hard_constraints']?.['length']??0x0)>0x0||Object['keys'](a['soft_weights']??{})['length']>0x0||(a['pricing_rules']?.['length']??0x0)>0x0||(a['highlight_fields']?.['length']??0x0)>0x0;}function isMeaningfulPersona(a){const b=a['long_term']??{},c=a['current']??{};return(c['strategy']?.['length']??0x0)>0x0||(c['requirements']?.['length']??0x0)>0x0||(c['rules']?.['length']??0x0)>0x0||(c['spec']?.['length']??0x0)>0x0||Object['keys'](c['preferences']??{})['length']>0x0||Object['keys'](b['preferences']??{})['length']>0x0||(b['identity']?.['region']?.['length']??0x0)>0x0||(b['identity']?.['languages']?.['length']??0x0)>0x0;}function isMeaningfulDispute(a){return(a?.['sla_tiers']?.['length']??0x0)>0x0||(a?.['fault_rules']?.['length']??0x0)>0x0;}function isMeaningfulCompliance(a){return!!a?.['prepay_mode']||(a?.['qualification']?.['length']??0x0)>0x0||(a?.['disclosure']?.['length']??0x0)>0x0||a?.['refund_window']?.['days']!==undefined&&!a?.['refund_window']?.['not_applicable'];}function isMeaningfulSupply(a){return(a?.['supplier_qualification']?.['length']??0x0)>0x0||!!a?.['first_order_policy']||a?.['redundancy_required']===!![];}function isMeaningfulRules(a){return(a?.['rules']?.['length']??0x0)>0x0;}function isMeaningfulPlaybook(a){if(!a)return![];const b=a['content']??'',c=b['replace'](/# .*Industry Playbook/g,'')['replace'](/> .*/g,'')['replace'](/## (Experience|Strategy|Personalization)/g,'')['replace'](/- \(Add .*\)/g,'')['trim']();return c['length']>0x0;}export function registerIndustryPack(a,b=![]){const c=[],d=[],e=a['manifest'],f=validatePackManifest(e);c['push'](...f['errors']);if(!f['valid'])return{'ok':![],'errors':c,'registered':d};const g=packRegistry['get'](e['name']),h=g!==undefined&&g['version']!==e['version'],i=h||b;if(e['layers']['includes']('mode')){if(!a['mode'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27mode\x27\x20but\x20mode.json\x20is\x20missing');else{const j=getIndustryModeRegistry();i&&j['hasMode'](a['mode']['name'])&&j['unregisterMode'](a['mode']['name']),!j['registerMode'](a['mode'])?c['push']('mode\x20\x27'+a['mode']['name']+'\x27\x20failed\x20to\x20register\x20(already\x20registered?).\x20'+'Unregister\x20first\x20or\x20upgrade\x20with\x20a\x20different\x20version.'):d['push']('mode');}}if(e['layers']['includes']('match')){if(!a['match'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27match\x27\x20but\x20match.json\x20is\x20missing');else{if(!isMeaningfulMatch(a['match'])){}else{const k=a['match']['pricing_rules']['filter'](l=>FORBIDDEN_PRICING_MODES['has'](l));if(k['length']>0x0)c['push']('match.pricing_rules\x20contains\x20forbidden\x20modes:\x20'+k['join'](',\x20')+'\x20'+'(violates\x20upper-layer\x20pricing\x20red\x20lines,\x20K3\x2015\x20§4.2)');else!registerCategoryMatchRules(a['match'],i)?c['push']('match\x20rules\x20for\x20\x27'+a['match']['category']+'\x27\x20already\x20registered'):d['push']('match');}}}if(e['layers']['includes']('personae')){if(!a['personae']||a['personae']['length']===0x0)c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27personae\x27\x20but\x20personae\x20are\x20missing');else{const l=a['personae']['filter'](isMeaningfulPersona);if(l['length']===0x0){}else registerIndustryPersonae(e['name'],l),d['push']('personae');}}if(e['layers']['includes']('dispute')){if(!a['dispute'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27dispute\x27\x20but\x20dispute.json\x20is\x20missing');else{if(!isMeaningfulDispute(a['dispute'])){}else!registerDisputeRules(a['dispute'],i)?c['push']('dispute\x20rules\x20for\x20\x27'+a['dispute']['category']+'\x27\x20already\x20registered'):d['push']('dispute');}}if(e['layers']['includes']('compliance')){if(!a['compliance'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27compliance\x27\x20but\x20compliance.json\x20is\x20missing');else{if(!isMeaningfulCompliance(a['compliance'])){}else!registerComplianceRules(a['compliance'],i)?c['push']('compliance\x20rules\x20for\x20\x27'+a['compliance']['category']+'\x27\x20already\x20registered'):d['push']('compliance');}}if(e['layers']['includes']('supply')){if(!a['supply'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27supply\x27\x20but\x20supply.json\x20is\x20missing');else{if(!isMeaningfulSupply(a['supply'])){}else!registerSupplyRules(a['supply'],i)?c['push']('supply\x20rules\x20for\x20\x27'+a['supply']['category']+'\x27\x20already\x20registered'):d['push']('supply');}}if(e['layers']['includes']('rules')){if(!a['rules'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27rules\x27\x20but\x20rules.json\x20is\x20missing');else{if(!isMeaningfulRules(a['rules'])){}else!registerIndustryRules(a['rules'],i)?c['push']('industry\x20rules\x20for\x20\x27'+a['rules']['category']+'\x27\x20already\x20registered'):(d['push']('rules'),registerIndustryRulesToEngine(a['rules']));}}if(e['layers']['includes']('playbook')){if(!a['playbook'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27playbook\x27\x20but\x20playbook.md\x20is\x20missing');else{if(!isMeaningfulPlaybook(a['playbook'])){}else!registerIndustryPlaybook(a['playbook'],i)?c['push']('playbook\x20for\x20\x27'+a['playbook']['category']+'\x27\x20already\x20registered'):d['push']('playbook');}}return c['length']===0x0&&packRegistry['set'](e['name'],{'version':e['version'],'layers':[...e['layers']],'registered_at':Date['now']()}),{'ok':c['length']===0x0,'errors':c,'registered':d};}let builtinModesAsPacksRegistered=![];function ensureBuiltinModesAsPacks(){if(builtinModesAsPacksRegistered)return;builtinModesAsPacksRegistered=!![];for(const a of BUILTIN_MODES){if(packRegistry['has'](a['name']))continue;packRegistry['set'](a['name'],{'version':a['version'],'layers':['mode','match'],'registered_at':Date['now']()});}}export function listRegisteredPacks(){return ensureBuiltinModesAsPacks(),Array['from'](packRegistry['entries']())['map'](([a,b])=>({'name':a,...b}));}export function unregisterIndustryPack(a){const b=new Set(BUILTIN_MODES['map'](c=>c['name']));if(b['has'](a))return![];if(!packRegistry['has'](a))return![];return packRegistry['delete'](a),unregisterIndustryPersonae(a),!![];}export function diffIndustryPack(a){const b=packRegistry['get'](a)??null,c=resolveIndustryPackDir(),d=join(c,a),e=readMergedPackIfPresent(d);let f=null;try{if(e&&e['manifest'])f={'version':e['manifest']['version'],'layers':e['manifest']['layers']??[]};else{const l=join(d,'manifest.json');if(existsSync(l)){const m=JSON['parse'](readFileSync(l,'utf-8'));f={'version':m['version'],'layers':m['layers']??[]};}}}catch{f=null;}const g=b?.['layers']??[],h=f?.['layers']??[],i=h['filter'](n=>!g['includes'](n)),j=g['filter'](n=>!h['includes'](n)),k=!!b&&!!f&&(b['version']!==f['version']||i['length']>0x0||j['length']>0x0);return{'name':a,'registered':b?{...b,'layers':[...b['layers']]}:null,'disk':f,'upgradable':k,'layer_diff':{'added':i,'removed':j}};}export function scanPacks(a){const b=[];if(!existsSync(a))return b;for(const c of readdirSync(a,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(a,c['name']);try{const e=loadPackFromDir(d);if(!e)continue;b['push'](registerIndustryPack(e));}catch(f){b['push']({'ok':![],'errors':['failed\x20to\x20load\x20pack\x20\x27'+c['name']+'\x27:\x20'+f['message']],'registered':[]});}}return b;}function loadPackFromDir(a){const b=readMergedPackIfPresent(a),c=join(a,'manifest.json'),d=existsSync(c);if(!b&&!d)return null;if(b){const p=b['manifest'],q={'layout':'merged','manifest':p};if(b['mode'])q['mode']=b['mode'];if(b['match'])q['match']=b['match'];b['personae']&&Array['isArray'](b['personae'])&&(q['personae']=b['personae']);if(b['dispute'])q['dispute']=b['dispute'];if(b['compliance'])q['compliance']=b['compliance'];if(b['supply'])q['supply']=b['supply'];if(b['rules'])q['rules']=b['rules'];const r=join(a,'playbook.md');return existsSync(r)&&(q['playbook']={'category':p['name'],'content':readFileSync(r,'utf-8')}),q;}const e=JSON['parse'](readFileSync(c,'utf-8')),g={'layout':'legacy','manifest':e},h=join(a,'mode.json'),i=join(a,'match.json');existsSync(h)&&(g['mode']=JSON['parse'](readFileSync(h,'utf-8')));existsSync(i)&&(g['match']=JSON['parse'](readFileSync(i,'utf-8')));const j=join(a,'personae');if(existsSync(j)){const s=[];for(const t of readdirSync(j)){if(!t['endsWith']('.json'))continue;s['push'](JSON['parse'](readFileSync(join(j,t),'utf-8')));}if(s['length']>0x0)g['personae']=s;}const k=join(a,'dispute.json');existsSync(k)&&(g['dispute']=JSON['parse'](readFileSync(k,'utf-8')));const l=join(a,'compliance.json');existsSync(l)&&(g['compliance']=JSON['parse'](readFileSync(l,'utf-8')));const m=join(a,'supply.json');existsSync(m)&&(g['supply']=JSON['parse'](readFileSync(m,'utf-8')));const n=join(a,'rules.json');existsSync(n)&&(g['rules']=JSON['parse'](readFileSync(n,'utf-8')));const o=join(a,'playbook.md');return existsSync(o)&&(g['playbook']={'category':e['name'],'content':readFileSync(o,'utf-8')}),g;}export function rescanPack(a){const b=join(resolveIndustryPackDir(),a);try{const c=loadPackFromDir(b);if(!c)return{'ok':![],'errors':['no\x20pack\x20found\x20for\x20\x27'+a+'\x27'],'registered':[]};return registerIndustryPack(c,!![]);}catch(d){return{'ok':![],'errors':['failed\x20to\x20rescan\x20pack\x20\x27'+a+'\x27:\x20'+d['message']],'registered':[]};}}export function resolveIndustryPackDir(){return process['env']['WOWOK_INDUSTRY_DIR']||getWowokIndustryDir();}export function scanDefaultIndustryPacks(){return seedBuiltinIndustryTemplates(),ensureIndustryReadme(),ensureBuiltinModesAsPacks(),scanPacks(resolveIndustryPackDir());}export function seedBuiltinIndustryTemplates(a=SUPPORTED_INDUSTRIES){const b=[],c=resolveIndustryPackDir();mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();for(const d of a){const e=join(c,d);if(existsSync(join(e,'manifest.json'))||existsSync(join(e,'pack.json')))continue;const f=scaffoldIndustryPack(d,c);if(f['ok'])b['push'](d);}return b;}export const LAYER_FILE_SECTION={'match.json':'match','dispute.json':'dispute','compliance.json':'compliance','supply.json':'supply','rules.json':'rules','mode.json':'mode'};export const PERSONAE_DIR='personae';function manifestSection(a){return{'pack':'industry-pack','name':a,'display_name':a,'version':'0.1.0','layers':['match','personae','dispute','compliance','supply','rules','playbook']};}function matchSection(a){return{'category':a,'hard_constraints':[],'soft_weights':{},'highlight_fields':[],'calendar_mode':'none','geo_mode':'strict','pricing_rules':[]};}function personaPerRole(a,b){return{'role':a,'industry':b,'long_term':{'identity':{'self_description':b+'\x20'+a},'preferences':{}},'current':{'strategy':[],'requirements':[],'rules':[],'spec':'','preferences':{}}};}function disputeSection(a){return{'category':a,'sla_tiers':[],'fault_rules':[]};}function complianceSection(a){return{'category':a,'prepay_mode':'','qualification':[],'disclosure':[],'refund_window':{'days':0x7,'not_applicable':![]}};}function supplySection(a){return{'category':a,'supplier_qualification':[],'first_order_policy':'','redundancy_required':![]};}function rulesSection(a){return{'category':a,'rules':[]};}export function buildPristineMergedPack(a){const b=PERSONA_ROLES['map'](c=>personaPerRole(c,a));return{'manifest':manifestSection(a),'match':matchSection(a),'personae':b,'dispute':disputeSection(a),'compliance':complianceSection(a),'supply':supplySection(a),'rules':rulesSection(a),'mode':null};}export function industryReadmeContent(){return['#\x20WoWok\x20Industry\x20Packs','','>\x20This\x20folder\x20is\x20the\x20WoWok\x20industry\x20knowledge\x20root.\x20Each\x20sub-folder\x20is\x20one','>\x20industry\x20pack.\x20The\x20AI\x20reads\x20pack\x20data\x20as\x20context\x20on\x20every\x20chat\x20turn.','','##\x20Pack\x20structure\x20(unified\x20layout)','','Every\x20pack\x20is\x20exactly\x20two\x20files:','','-\x20**`<pack>/pack.json`**\x20—\x20machine-checkable\x20**settings\x20only**.\x20No\x20comments,','\x20\x20no\x20documentation.\x20One\x20section\x20per\x20layer\x20(see\x20below).','-\x20**`<pack>/playbook.md`**\x20—\x20human\x20strategy,\x20tone\x20and\x20field-tested\x20experience.','\x20\x20The\x20AI\x20reads\x20it\x20as\x20context\x20and\x20it\x20OVERRIDES\x20built-in\x20industry\x20data\x20for','\x20\x20this\x20account.','','All\x20field\x20explanations\x20live\x20in\x20THIS\x20file,\x20so\x20pack.json\x20stays\x20small\x20and\x20you','can\x20focus\x20on\x20configuration.\x20The\x20editor\x20also\x20validates\x20JSON\x20on\x20save\x20—\x20a\x20file','that\x20fails\x20to\x20parse\x20(or\x20a\x20pack.json\x20missing\x20its\x20manifest)\x20is\x20blocked.','','##\x20How\x20changes\x20take\x20effect','','1.\x20**Save**\x20in\x20the\x20Editor\x20writes\x20bytes\x20to\x20disk.','2.\x20**Scan**\x20(Industry\x20drawer)\x20re-registers\x20each\x20pack\x20into\x20the\x20runtime\x20AI','\x20\x20\x20registry\x20(and\x20SQLite\x20cache).\x20A\x20save\x20of\x20an\x20industry\x20file\x20already\x20runs','\x20\x20\x20Scan\x20automatically.','3.\x20**Next\x20AI\x20chat\x20turn**\x20the\x20L1\x20prompt\x20builder\x20reads\x20the\x20registered\x20layers,','\x20\x20\x20so\x20the\x20AI\x20reasons\x20against\x20your\x20edited\x20rules\x20from\x20that\x20point\x20onward.','','##\x20manifest\x20—\x20pack\x20metadata\x20+\x20layer\x20ENABLE\x20flags','','-\x20`name`:\x20snake_case\x20identifier,\x20must\x20match\x20the\x20folder\x20name.','-\x20`version`:\x20bump\x20after\x20editing\x20content\x20so\x20the\x20registry\x20treats\x20it\x20as\x20an\x20upgrade.','-\x20`display_name`:\x20user-visible\x20label.','-\x20`layers`:\x20which\x20sections\x20are\x20validated\x20and\x20registered\x20on\x20scan.\x20Remove\x20a','\x20\x20layer\x20name\x20to\x20DISABLE\x20it\x20(the\x20section\x20stays\x20in\x20pack.json\x20but\x20is\x20ignored).','','##\x20match\x20—\x20category-match\x20rules','','Decides\x20whether\x20an\x20order/service/account\x20belongs\x20to\x20this\x20industry\x20pack:','-\x20`hard_constraints`:\x20array\x20of\x20REQUIRED\x20predicates;\x20ALL\x20must\x20match\x20before\x20the','\x20\x20pack\x20is\x20considered.\x20Example:','\x20\x20`[{\x20key:\x20\x27order.metadata.service_kind\x27,\x20equals:\x20\x27food_onsite\x27\x20}]`','-\x20`soft_weights`:\x20dict\x20`<heuristic_key:\x20number\x200..1>`;\x20higher\x20=\x20stronger\x20signal.','-\x20`pricing_rules`:\x20pricing\x20modes\x20this\x20industry\x20requires.','-\x20`highlight_fields`:\x20dot-paths\x20surfaced\x20in\x20the\x20UI\x20as\x20important\x20info.','-\x20`geo_mode`:\x20`\x27strict\x27`\x20(region\x20must\x20match)\x20|\x20`\x27none\x27`\x20(ignore\x20region).','-\x20`calendar_mode`:\x20`\x27seasonal\x27`\x20|\x20`\x27weekday\x27`\x20|\x20`\x27none\x27`.','','##\x20personae\x20—\x20per-role\x20AI\x20personas','','One\x20persona\x20per\x20role\x20(`merchant`,\x20`customer`,\x20`supplier`,\x20`collaborator`,','`arbitrator`,\x20`prospect`).\x20The\x20AI\x20uses\x20them\x20to\x20role-play\x20negotiation\x20posture:','-\x20`long_term`:\x20stable\x20properties\x20—\x20`identity.self_description`\x20(free-text\x20bio),','\x20\x20`identity.region/languages`,\x20`preferences`\x20(`<key:\x20string[]>`).','-\x20`current`:\x20per-negotiation\x20posture\x20—\x20`strategy`\x20(moves\x20to\x20make),','\x20\x20`requirements`\x20(non-negotiable\x20demands),\x20`rules`\x20(constraints/axioms),','\x20\x20`spec`\x20(free-form\x20text),\x20`preferences`\x20(per-turn\x20overrides).','','##\x20dispute\x20—\x20SLA\x20tiers\x20+\x20fault\x20assignment','','-\x20`sla_tiers[]`:\x20response/remedy\x20windows\x20per\x20severity\x20level.','\x20\x20Example:\x20`{\x20level:\x20\x27L1\x27,\x20response_hours:\x2024,\x20remedy:\x20\x27reply\x27\x20}`','-\x20`fault_rules[]`:\x20automatic\x20fault\x20attribution\x20—\x20a\x20condition\x20plus\x20the\x20side','\x20\x20that\x20bears\x20fault\x20(`merchant`/`customer`/`supplier`/`operator`/`shared`).','\x20\x20Example:\x20`{\x20when:\x20{\x20evidence_has:\x20[\x27late\x20delivery\x20photo\x27]\x20},\x20assign_to:\x20\x27merchant\x27,\x20weight:\x201.0\x20}`','','##\x20compliance\x20—\x20hard\x20requirements\x20before\x20checkout','','-\x20`prepay_mode`:\x20`\x27\x27`\x20|\x20`\x27full\x27`\x20|\x20`\x27partial\x27`\x20|\x20`\x27deposit\x27`.','-\x20`qualification[]`:\x20licenses/certifications\x20a\x20merchant\x20must\x20hold.','\x20\x20Example:\x20`{\x20label:\x20\x27Food\x20Service\x20License\x27,\x20required:\x20true,\x20region:\x20\x27CN\x27\x20}`','-\x20`disclosure[]`:\x20text\x20the\x20merchant\x20MUST\x20show\x20buyers\x20up-front.','-\x20`refund_window`:\x20`{\x20days:\x20number,\x20not_applicable:\x20boolean,\x20exceptions:\x20[...]\x20}`','','##\x20supply\x20—\x20supply-chain\x20/\x20supplier\x20qualification','','-\x20`supplier_qualification[]`:\x20same\x20shape\x20as\x20compliance\x20qualifications,\x20but','\x20\x20evaluated\x20on\x20the\x20SUPPLIER\x20side\x20(multi-party\x20orders).','-\x20`first_order_policy`:\x20policy\x20string\x20on\x20the\x20first\x20order\x20from\x20a\x20new\x20supplier','\x20\x20(e.g.\x20`\x27sample-only\x27`,\x20`\x27reduced-quantity\x27`).','-\x20`redundancy_required`:\x20true\x20=\x20require\x20≥2\x20eligible\x20suppliers\x20before\x20accepting','\x20\x20an\x20order\x20(mitigates\x20single-sourcing).','','##\x20rules\x20—\x20declarative\x20machine-checked\x20rules','','Each\x20rule\x20is\x20an\x20AST\x20node\x20compiled\x20into\x20the\x20evaluation\x20engine:','`{\x20id:\x20\x27rule_...\x27,\x20when:\x20<bool-condition>,\x20then:\x20\x27reject\x27\x20|\x20\x27warn\x27\x20|\x20\x27flag\x27,\x20message:\x20\x27Text\x27\x20}`','Use\x20`rules`\x20for\x20rules\x20that\x20must\x20be\x20machine-checked;\x20put\x20human\x20strategy\x20in','`playbook.md`.','','##\x20mode\x20—\x20IndustryMode\x20(deep\x20shape)','','Not\x20scaffolded\x20by\x20default.\x20Add\x20it\x20when\x20you\x20need\x20a\x20full\x20driving\x20mode\x20for\x20the','industry,\x20or\x20ask\x20the\x20AI:\x20\x22help\x20me\x20fill\x20mode\x20for\x20<industry>\x22.','','Registered\x20into\x20`IndustryModeRegistry`\x20on\x20scan\x20(manifest\x20must\x20list\x20the','`mode`\x20layer).\x20A\x20pack\x20mode\x20with\x20the\x20same\x20name\x20as\x20a\x20builtin\x20replaces\x20it\x20when','the\x20pack\x20version\x20changes\x20or\x20on\x20a\x20forced\x20rescan.','','###\x20How\x20the\x20mode\x20is\x20consumed','','-\x20**Service\x20build\x20(priors)**:\x20`merchant_guide`\x20resolves\x20the\x20confirmed','\x20\x20industry\x20to\x20a\x20mode\x20(user\x20mode\x20first,\x20then\x20pack\x20mode,\x20then\x20builtin)\x20and','\x20\x20feeds\x20`machine_shape`\x20/\x20`guards`\x20/\x20`allocator`\x20/\x20`key_risk`\x20into\x20the','\x20\x20SemanticObjectGraph\x20build.','-\x20**Evaluation**:\x20the\x20metric\x20+\x20constraint\x20registries\x20score\x20the\x20mode','\x20\x20(risk/benefit\x200-100,\x20hard\x20violations\x20block\x20adoption).\x20Custom\x20metrics\x20and','\x20\x20constraints\x20registered\x20via\x20`industry_pack_operation`\x20participate\x20too.','-\x20**Recommendation**:\x20`recommend_industry`\x20matches\x20trait\x20similarity\x20and,','\x20\x20when\x20a\x20merchant\x20strategy\x20is\x20given,\x20re-ranks\x20by\x20lever\x20alignment\x20(70%','\x20\x20similarity\x20+\x2030%\x20alignment).','','###\x20Field\x20reference','','-\x20**Identity**:\x20`name`\x20(snake_case),\x20`display_name`,\x20`version`\x20(e.g.\x20`v1`),','\x20\x20`source`\x20(`builtin`\x20|\x20`custom`).','-\x20`traits`:\x2010-dimension\x20industry\x20trait\x20vector\x20(logistics,\x20cycle,\x20deposit,','\x20\x20regulatory\x20intensity,\x20...).\x20Drives\x20`recommend_industry`\x20similarity.','-\x20`machine_shape`:\x20Machine\x20node\x20topology\x20—\x20`[{\x20name,\x20role\x20}]`.\x20Node\x20names\x20are','\x20\x20business\x20states.\x20R-M1-11:\x20NEVER\x20model\x20refund/dispute\x20terminals','\x20\x20(`refunded`,\x20`disputed`,\x20`arb_*`)\x20as\x20nodes\x20—\x20disputes\x20flow\x20through','\x20\x20Service.arbitrations\x20independently;\x20route\x20refunds\x20via\x20the\x20Allocator','\x20\x20triggered\x20by\x20business\x20states\x20(`cancelled`,\x20`returned`).','-\x20`guards`:\x20`[{\x20template_id,\x20host,\x20purpose\x20}]`\x20—\x20guard\x20templates\x20to\x20attach.','\x20\x20`host`\x20is\x20one\x20of\x20`service`\x20|\x20`machine`\x20|\x20`reward`\x20|\x20`repository`\x20|','\x20\x20`arbitration`.','-\x20`allocator`:\x20`{\x20recipient,\x20count,\x20mode,\x20description\x20}`\x20—\x20fund\x20split.','\x20\x20`recipient`:\x20`signer`\x20|\x20`entity`;\x20`count`\x20>\x201\x20switches\x20to\x20multi-party','\x20\x20distribution;\x20`mode`:\x20`surplus`\x20|\x20`rate`\x20|\x20`milestone`.','-\x20`risk_checks`\x20/\x20`needs`:\x20buyer-side\x20due-diligence\x20entries\x20surfaced\x20in','\x20\x20prospect\x20evaluation.','-\x20`flywheel`:\x20acquisition\x20flywheel\x20—\x20`rewardStrategy`\x20/\x20`discountStrategy`','\x20\x20/\x20`trustSellingPoints`.\x20A\x20concrete\x20(non-`User-defined`)\x20strategy\x20turns','\x20\x20the\x20`reward`/`discount`\x20levers\x20on\x20for\x20strategy\x20alignment.','-\x20`key_risk`\x20(string)\x20/\x20`build_notes`\x20(string[]):\x20the\x20headline\x20risk\x20and','\x20\x20actionable\x20build\x20guidance\x20shown\x20to\x20the\x20merchant.','-\x20`capabilities_used`:\x20CapabilityCard\x20IDs\x20(e.g.\x20`guard.validate_buy`,','\x20\x20`machine.node_topology`,\x20`allocation.distribute_milestone`).\x20Powers\x20the','\x20\x20`buy_guard`\x20/\x20`machine_design`\x20levers\x20and\x20constraint\x20checks.','-\x20`config_overrides`:\x20per-object\x20field\x20defaults,\x20e.g.','\x20\x20`{\x20service:\x20{\x20engagement_type:\x20\x27milestone\x27\x20},\x20machine:\x20{\x20wip_required:\x20true\x20}\x20}`.','-\x20`config_override_rules`:\x20conditional\x20overrides\x20—','\x20\x20`{\x20object_type,\x20field_path,\x20value\x20|\x20{\x20intent_contains,\x20then_value,\x20else_value\x20}\x20}`.','-\x20`expected_benefits`:\x20`[{\x20metric,\x20expected_value,\x20evidence\x20}]`\x20—\x20what\x20the','\x20\x20mode\x20is\x20supposed\x20to\x20buy\x20you.','-\x20`risk_appetite`:\x20`conservative`\x20|\x20`balanced`\x20|\x20`aggressive`\x20(thresholds','\x20\x20for\x20the\x20risk/benefit\x20verdict).','-\x20`risk_constraints`:\x20`{\x20require_arbitration,\x20require_compensation_fund,','\x20\x20require_wip_evidence,\x20max_single_transaction?,','\x20\x20compensation_fund_coverage_ratio?,\x20other_constraints?\x20}`.\x20Coverage\x20ratio','\x20\x20multiplies\x20max\x20single\x20order\x20to\x20size\x20the\x20compensation\x20fund\x20(retail\x205,','\x20\x20rental\x2010,\x20subscription\x203;\x20default\x205).','-\x20`applicable_conditions`:\x20`{\x20business_scale,\x20min_daily_orders?,','\x20\x20other_conditions?\x20}`\x20—\x20when\x20the\x20mode\x20fits.','-\x20`similar_industries`\x20/\x20`novel_capabilities`:\x20migration\x20hints.','-\x20`disabled_builtin_constraints`:\x20builtin\x20constraint\x20IDs\x20this\x20mode','\x20\x20deliberately\x20opts\x20out\x20of\x20(e.g.\x20retail_d2c\x20skips\x20`require_arbitration`).','\x20\x20Custom\x20constraints\x20are\x20never\x20skipped.','','###\x20Persona\x20integration\x20(strategy\x20→\x20levers)','','The\x20personae\x20section\x27s\x20`current.strategy`\x20statements\x20are\x20bridged\x20into\x20mode','ranking\x20(value\x20intent\x20↔\x20game\x20path\x20unification).\x20Deterministic\x20mapping\x20—','\x22enumerable\x20→\x20MCP,\x20not\x20prompt\x22:','','-\x20`sales_priority`\x20(volume\x20first)\x20→\x20levers\x20`discount`\x20+\x20`reward`','-\x20`profit_priority`\x20(margin\x20first)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','-\x20`buyer_screening`\x20(qualify\x20buyers)\x20→\x20lever\x20`buy_guard`','-\x20`gross_margin_control`\x20(margin\x20band)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','','A\x20mode\x20supports\x20a\x20lever\x20when\x20its\x20data\x20says\x20so:\x20`guard.validate_buy`','capability\x20or\x20a\x20buy-guard\x20template\x20enables\x20`buy_guard`;\x20a\x20concrete','flywheel\x20reward/discount\x20strategy\x20enables\x20`reward`/`discount`;\x20a','non-empty\x20`machine_shape`\x20with\x20`machine.node_topology`\x20enables','`machine_design`.\x20Pass\x20strategy\x20text\x20to\x20`recommend_industry`\x20and\x20each','recommendation\x20reports\x20`strategy_alignment`\x20(matched/missing\x20levers).','','##\x20Reset','','Right-click\x20any\x20file/pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20and\x20choose\x20*Reset*','to\x20restore\x20the\x20pristine\x20template\x20at\x20any\x20time.','']['join']('\x0a');}export function ensureIndustryReadme(){const a=resolveIndustryPackDir();mkdirSync(a,{'recursive':!![]});const b=join(a,'README.md');return writeFileSync(b,industryReadmeContent(),'utf-8'),b;}export function scaffoldIndustryPack(a,b){const c=join(b??resolveIndustryPackDir(),a),d=[],e=[];if(!/^[a-z][a-z0-9_]*$/['test'](a))return{'ok':![],'dir':c,'files':d,'errors':['industry\x20name\x20\x27'+a+'\x27\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)']};try{mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();const f=buildPristineMergedPack(a);return writeFileSync(join(c,'pack.json'),JSON['stringify'](f,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(c,'playbook.md'),playbookTemplate(a)),d['push']('playbook.md'),{'ok':!![],'dir':c,'files':d,'errors':e};}catch(g){return{'ok':![],'dir':c,'files':d,'errors':['scaffold\x20failed:\x20'+g['message']]};}}export function readMergedPackIfPresent(a){const b=join(a,'pack.json');if(!existsSync(b))return null;try{const c=readFileSync(b,'utf-8');return JSON['parse'](c);}catch{return null;}}function playbookTemplate(a){return['#\x20'+a+'\x20—\x20Industry\x20Playbook','','>\x20📘\x20This\x20file\x20captures\x20human\x20business\x20intelligence\x20for\x20the\x20`'+a+'`','>\x20industry.\x20Content\x20here\x20is\x20READ\x20BY\x20THE\x20AI\x20AS\x20CONTEXT\x20on\x20every\x20turn,','>\x20and\x20OVERRIDES\x20WoWok\x27s\x20generic\x20built-in\x20industry\x20data/rules\x20for\x20this','>\x20account.\x20The\x20companion\x20`pack.json`\x20file\x20stores\x20machine-checkable','>\x20rules;\x20THIS\x20file\x20stores\x20human\x20strategy,\x20tone,\x20experience,\x20and\x20ethics.','','>\x20💡\x20Hint\x20for\x20the\x20AI:\x20when\x20the\x20user\x20asks\x20a\x20question\x20about\x20\x22how\x20to','>\x20handle\x20'+a+'\x22\x20or\x20\x22what\x20should\x20I\x20do?\x22,\x20check\x20this\x20file\x20first\x20for\x20the','>\x20merchant/customer\x20voice,\x20then\x20fall\x20back\x20to\x20your\x20built-in\x20data.\x20Cite','>\x20section\x20titles\x20in\x20your\x20reply\x20so\x20the\x20user\x20knows\x20where\x20advice\x20comes\x20from.','','##\x20Experience\x20(Field-Tested\x20Rules\x20of\x20Thumb)','','>\x20Write\x20what\x20actually\x20works\x20in\x20this\x20industry\x20—\x20not\x20what\x20textbooks\x20say.','>\x20Short\x20bullet\x20points\x20preferred;\x20the\x20AI\x20reads\x20them\x20as\x20axioms.\x20Include','>\x20specific\x20numbers\x20when\x20you\x20have\x20them.','','-\x20(Example)\x20\x22Catering:\x20if\x20the\x20event\x20starts\x20before\x2010:00,\x20always\x20assume','\x20\x20the\x20customer\x20wants\x20breakfast\x20service\x20too\x20—\x20upsell\x20it\x20proactively.\x22','-\x20(Example)\x20\x22Common\x20pitfall:\x20last-minute\x20menu\x20swaps\x20on\x20Fridays\x20—\x20require','\x20\x20a\x20written\x20change\x20request\x2048\x20h\x20before\x20the\x20event\x20or\x20charge\x20a\x2015%\x20fee.\x22','-\x20(Add\x20more\x20below\x20—\x20delete\x20the\x20examples\x20above\x20when\x20you\x20have\x20real\x20ones.)','','##\x20Strategy\x20(Competitive\x20/\x20Game-Theory)','','>\x20How\x20should\x20each\x20role\x20act\x20in\x20a\x20negotiation\x20/\x20dispute\x20/\x20supplier','>\x20relationship?\x20Think\x20in\x20\x22always\x20/\x20never\x20/\x20depends-on-X\x22\x20rules,\x20and\x20call','>\x20out\x20the\x20trade-offs.','','-\x20Merchant\x20strategy:\x20(Add\x20how\x20a\x20merchant\x20in\x20this\x20industry\x20should\x20act\x20—','\x20\x20price\x20anchoring,\x20which\x20concessions\x20to\x20give\x20early\x20vs\x20late,\x20what\x20to','\x20\x20never\x20concede\x20on,\x20etc.)','-\x20Customer\x20strategy:\x20(Add\x20what\x20a\x20smart\x20customer\x20should\x20push\x20for.)','-\x20Dispute\x20strategy:\x20(When\x20to\x20settle\x20fast\x20vs\x20when\x20to\x20fight\x20for\x20full','\x20\x20evidence\x20+\x20arbitration.\x20Call\x20out\x20the\x20escalation\x20thresholds.)','','##\x20Personalization\x20(Tone,\x20Brand,\x20Ethics,\x20Red\x20Lines)','','-\x20Tone\x20/\x20voice:\x20(Write\x20one\x20sentence\x20describing\x20the\x20exact\x20conversational','\x20\x20voice\x20this\x20account\x20should\x20use\x20—\x20casual,\x20formal,\x20technical,\x20etc.)','-\x20Brand\x20rules:\x20(Logo,\x20link-out\x20style,\x20forbidden\x20terminology,','\x20\x20always-include\x20phrases,\x20etc.)','-\x20Red\x20lines:\x20(Non-negotiable.\x20Example:\x20\x22Never\x20make\x20a\x20refund\x20promise','\x20\x20larger\x20than\x2030%\x20without\x20arbitration\x20evidence.\x22)','-\x20Ethics:\x20(Example:\x20\x22If\x20customer\x20appears\x20intoxicated,\x20refuse\x20service','\x20\x20and\x20refer\x20to\x20supervisor;\x20never\x20take\x20the\x20order\x20for\x20profit.\x22)','','##\x20Playbook\x20Maintenance','','>\x20You\x20don\x27t\x20need\x20to\x20be\x20perfect\x20on\x20day\x20one.\x20After\x20every\x20real\x20deal,\x20add\x20a','>\x20bullet\x20to\x20the\x20above\x20sections\x20with\x20what\x20worked\x20/\x20what\x20failed.\x20Every','>\x20entry\x20improves\x20the\x20AI\x27s\x20future\x20decisions.','','>\x20Right-click\x20the\x20file\x20or\x20this\x20pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20at','>\x20any\x20time\x20and\x20choose\x20\x22Reset\x22\x20to\x20restore\x20this\x20annotated\x20template.','']['join']('\x0a');}export function locatePackAndRemainder(a){const b=a['replace'](/^[\\/]+/,'')['replace'](/[\\/]+$/,'');if(!b)return null;const [c,...d]=b['split'](/[\\/]+/);if(!c)return null;return{'packName':c,'remainder':d['join']('/')};}export function resetIndustryPath(a,b){const c=[],d=[],f=b??resolveIndustryPackDir(),g=locatePackAndRemainder(a),h=a;if(!g)return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['invalid\x20reset\x20path\x20\x27'+a+'\x27']};const {packName:i,remainder:j}=g,k=join(f,i);if(!existsSync(k))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20directory\x20\x27'+i+'\x27\x20does\x20not\x20exist']};if(!/^[a-z][a-z0-9_]*$/['test'](i))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20name\x20\x27'+i+'\x27\x20is\x20not\x20a\x20valid\x20snake_case\x20identifier']};const l=readMergedPackIfPresent(k),n=l?'merged':'legacy';if(j==='')try{mkdirSync(k,{'recursive':!![]});const s=buildPristineMergedPack(i);return writeFileSync(join(k,'pack.json'),JSON['stringify'](s,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':'merged','target':h,'restored_files':d,'errors':c};}catch(t){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['pack\x20reset\x20failed:\x20'+t['message']]};}const o=j['split']('/')['slice'](-0x1)[0x0],p=j==='playbook.md',q=j['startsWith'](PERSONAE_DIR+'/')&&o['endsWith']('.json');if(n==='merged'){if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(v){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['playbook\x20reset\x20failed:\x20'+v['message']]};}const u=LAYER_FILE_SECTION[j];if(u)try{const w=readMergedPackIfPresent(k)??buildPristineMergedPack(i);switch(u){case'match':w['match']=matchSection(i);break;case'dispute':w['dispute']=disputeSection(i);break;case'compliance':w['compliance']=complianceSection(i);break;case'supply':w['supply']=supplySection(i);break;case'rules':w['rules']=rulesSection(i);break;case'mode':w['mode']=null;break;}return writeFileSync(join(k,'pack.json'),JSON['stringify'](w,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(x){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['section\x20reset\x20failed:\x20'+x['message']]};}if(q){const y=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](y))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20role\x20\x27'+y+'\x27']};try{const z=readMergedPackIfPresent(k)??buildPristineMergedPack(i),A=z['personae']&&Array['isArray'](z['personae'])?[...z['personae']]:[],B=A['findIndex'](D=>D['role']===y),C=personaPerRole(y,i);if(B>=0x0)A[B]=C;else A['push'](C);return z['personae']=A,writeFileSync(join(k,'pack.json'),JSON['stringify'](z,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(D){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['persona\x20reset\x20failed:\x20'+D['message']]};}}if(j==='manifest.json'||j==='manifest')try{const E=readMergedPackIfPresent(k)??buildPristineMergedPack(i);return E['manifest']=manifestSection(i),writeFileSync(join(k,'pack.json'),JSON['stringify'](E,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(F){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['manifest\x20reset\x20failed:\x20'+F['message']]};}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['path\x20\x27'+j+'\x27\x20is\x20not\x20a\x20standard\x20section\x20file\x20of\x20pack\x20\x27'+i+'\x27.\x20Reset\x20is\x20only\x20provided\x20for\x20pack.json\x20standard\x20sections\x20and\x20playbook.md.']};}if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(G){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20playbook\x20reset\x20failed:\x20'+G['message']]};}if(j==='manifest.json')try{const H=manifestSection(i);return writeFileSync(join(k,'manifest.json'),JSON['stringify'](H,null,0x2)+'\x0a'),d['push']('manifest.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(I){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20manifest\x20reset\x20failed:\x20'+I['message']]};}const r=LAYER_FILE_SECTION[j];if(r)try{let J='';switch(r){case'match':J=JSON['stringify'](matchSection(i),null,0x2)+'\x0a';break;case'dispute':J=JSON['stringify'](disputeSection(i),null,0x2)+'\x0a';break;case'compliance':J=JSON['stringify'](complianceSection(i),null,0x2)+'\x0a';break;case'supply':J=JSON['stringify'](supplySection(i),null,0x2)+'\x0a';break;case'rules':J=JSON['stringify'](rulesSection(i),null,0x2)+'\x0a';break;case'mode':J=JSON['stringify']({},null,0x2)+'\x0a';break;}return writeFileSync(join(k,j),J),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(K){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20section\x20reset\x20failed:\x20'+K['message']]};}if(q){const L=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](L))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20\x27'+L+'\x27']};try{return writeFileSync(join(k,j),JSON['stringify'](personaPerRole(L,i),null,0x2)+'\x0a'),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(M){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20persona\x20reset\x20failed:\x20'+M['message']]};}}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['cannot\x20reset\x20non-standard\x20file\x20\x27'+j+'\x27\x20in\x20legacy\x20layout.\x20Only\x20standard\x20layer\x20files,\x20personae/*.json,\x20manifest.json,\x20and\x20playbook.md\x20can\x20be\x20reset.']};}
|
|
1
|
+
import{readdirSync,readFileSync,existsSync,mkdirSync,writeFileSync}from'node:fs';import{join}from'node:path';import{getWowokIndustryDir}from'@wowok/wowok';import{getIndustryModeRegistry}from'./registry.js';import{BUILTIN_MODES}from'./modes.js';import{registerCategoryMatchRules}from'../evaluation/category-match-rules.js';import{registerIndustryPersonae,unregisterIndustryPersonae}from'../persona/pack-personae.js';import{PERSONA_ROLES,SUPPORTED_INDUSTRIES}from'../persona/types.js';import{UNIVERSAL_TEMPLATE}from'../knowledge/universal-template.js';import{STRATEGY_MANUAL_FILENAME,renderStrategyManual,classifyManualFile}from'../knowledge/strategy-manuals.js';import{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,registerIndustryRulesToEngine}from'./industry-layers.js';const FORBIDDEN_PRICING_MODES=new Set(UNIVERSAL_TEMPLATE['pricing_redlines']),packRegistry=new Map();export function validatePackManifest(a){const b=[];return(!a||a['pack']!=='industry-pack')&&b['push']('manifest.pack\x20must\x20be\x20\x27industry-pack\x27'),(!a['name']||typeof a['name']!=='string')&&b['push']('manifest.name\x20is\x20required'),(!a['version']||typeof a['version']!=='string')&&b['push']('manifest.version\x20is\x20required'),(!Array['isArray'](a['layers'])||a['layers']['length']===0x0)&&b['push']('manifest.layers\x20must\x20be\x20a\x20non-empty\x20array'),{'valid':b['length']===0x0,'errors':b};}function isMeaningfulMatch(a){if(!a)return![];return(a['hard_constraints']?.['length']??0x0)>0x0||Object['keys'](a['soft_weights']??{})['length']>0x0||(a['pricing_rules']?.['length']??0x0)>0x0||(a['highlight_fields']?.['length']??0x0)>0x0;}function isMeaningfulPersona(a){const b=a['long_term']??{},c=a['current']??{};return(c['strategy']?.['length']??0x0)>0x0||(c['requirements']?.['length']??0x0)>0x0||(c['rules']?.['length']??0x0)>0x0||(c['spec']?.['length']??0x0)>0x0||Object['keys'](c['preferences']??{})['length']>0x0||Object['keys'](b['preferences']??{})['length']>0x0||(b['identity']?.['region']?.['length']??0x0)>0x0||(b['identity']?.['languages']?.['length']??0x0)>0x0;}function isMeaningfulDispute(a){return(a?.['sla_tiers']?.['length']??0x0)>0x0||(a?.['fault_rules']?.['length']??0x0)>0x0;}function isMeaningfulCompliance(a){return!!a?.['prepay_mode']||(a?.['qualification']?.['length']??0x0)>0x0||(a?.['disclosure']?.['length']??0x0)>0x0||a?.['refund_window']?.['days']!==undefined&&!a?.['refund_window']?.['not_applicable'];}function isMeaningfulSupply(a){return(a?.['supplier_qualification']?.['length']??0x0)>0x0||!!a?.['first_order_policy']||a?.['redundancy_required']===!![];}function isMeaningfulRules(a){return(a?.['rules']?.['length']??0x0)>0x0;}function isMeaningfulPlaybook(a){if(!a)return![];const b=a['content']??'',c=b['replace'](/# .*Industry Playbook/g,'')['replace'](/> .*/g,'')['replace'](/## (Experience|Strategy|Personalization)/g,'')['replace'](/- \(Add .*\)/g,'')['trim']();return c['length']>0x0;}export function registerIndustryPack(a,b=![]){const c=[],d=[],e=a['manifest'],f=validatePackManifest(e);c['push'](...f['errors']);if(!f['valid'])return{'ok':![],'errors':c,'registered':d};const g=packRegistry['get'](e['name']),h=g!==undefined&&g['version']!==e['version'],i=h||b;if(e['layers']['includes']('mode')){if(!a['mode'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27mode\x27\x20but\x20mode.json\x20is\x20missing');else{const j=getIndustryModeRegistry();i&&j['hasMode'](a['mode']['name'])&&j['unregisterMode'](a['mode']['name']),!j['registerMode'](a['mode'])?c['push']('mode\x20\x27'+a['mode']['name']+'\x27\x20failed\x20to\x20register\x20(already\x20registered?).\x20'+'Unregister\x20first\x20or\x20upgrade\x20with\x20a\x20different\x20version.'):d['push']('mode');}}if(e['layers']['includes']('match')){if(!a['match'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27match\x27\x20but\x20match.json\x20is\x20missing');else{if(!isMeaningfulMatch(a['match'])){}else{const k=a['match']['pricing_rules']['filter'](l=>FORBIDDEN_PRICING_MODES['has'](l));if(k['length']>0x0)c['push']('match.pricing_rules\x20contains\x20forbidden\x20modes:\x20'+k['join'](',\x20')+'\x20'+'(violates\x20upper-layer\x20pricing\x20red\x20lines,\x20K3\x2015\x20§4.2)');else!registerCategoryMatchRules(a['match'],i)?c['push']('match\x20rules\x20for\x20\x27'+a['match']['category']+'\x27\x20already\x20registered'):d['push']('match');}}}if(e['layers']['includes']('personae')){if(!a['personae']||a['personae']['length']===0x0)c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27personae\x27\x20but\x20personae\x20are\x20missing');else{const l=a['personae']['filter'](isMeaningfulPersona);if(l['length']===0x0){}else registerIndustryPersonae(e['name'],l),d['push']('personae');}}if(e['layers']['includes']('dispute')){if(!a['dispute'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27dispute\x27\x20but\x20dispute.json\x20is\x20missing');else{if(!isMeaningfulDispute(a['dispute'])){}else!registerDisputeRules(a['dispute'],i)?c['push']('dispute\x20rules\x20for\x20\x27'+a['dispute']['category']+'\x27\x20already\x20registered'):d['push']('dispute');}}if(e['layers']['includes']('compliance')){if(!a['compliance'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27compliance\x27\x20but\x20compliance.json\x20is\x20missing');else{if(!isMeaningfulCompliance(a['compliance'])){}else!registerComplianceRules(a['compliance'],i)?c['push']('compliance\x20rules\x20for\x20\x27'+a['compliance']['category']+'\x27\x20already\x20registered'):d['push']('compliance');}}if(e['layers']['includes']('supply')){if(!a['supply'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27supply\x27\x20but\x20supply.json\x20is\x20missing');else{if(!isMeaningfulSupply(a['supply'])){}else!registerSupplyRules(a['supply'],i)?c['push']('supply\x20rules\x20for\x20\x27'+a['supply']['category']+'\x27\x20already\x20registered'):d['push']('supply');}}if(e['layers']['includes']('rules')){if(!a['rules'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27rules\x27\x20but\x20rules.json\x20is\x20missing');else{if(!isMeaningfulRules(a['rules'])){}else!registerIndustryRules(a['rules'],i)?c['push']('industry\x20rules\x20for\x20\x27'+a['rules']['category']+'\x27\x20already\x20registered'):(d['push']('rules'),registerIndustryRulesToEngine(a['rules']));}}if(e['layers']['includes']('playbook')){if(!a['playbook'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27playbook\x27\x20but\x20playbook.md\x20is\x20missing');else{if(!isMeaningfulPlaybook(a['playbook'])){}else!registerIndustryPlaybook(a['playbook'],i)?c['push']('playbook\x20for\x20\x27'+a['playbook']['category']+'\x27\x20already\x20registered'):d['push']('playbook');}}return c['length']===0x0&&packRegistry['set'](e['name'],{'version':e['version'],'layers':[...e['layers']],'registered_at':Date['now']()}),{'ok':c['length']===0x0,'errors':c,'registered':d};}let builtinModesAsPacksRegistered=![];function ensureBuiltinModesAsPacks(){if(builtinModesAsPacksRegistered)return;builtinModesAsPacksRegistered=!![];for(const a of BUILTIN_MODES){if(packRegistry['has'](a['name']))continue;packRegistry['set'](a['name'],{'version':a['version'],'layers':['mode','match'],'registered_at':Date['now']()});}}export function listRegisteredPacks(){return ensureBuiltinModesAsPacks(),Array['from'](packRegistry['entries']())['map'](([a,b])=>({'name':a,...b}));}export function unregisterIndustryPack(a){const b=new Set(BUILTIN_MODES['map'](c=>c['name']));if(b['has'](a))return![];if(!packRegistry['has'](a))return![];return packRegistry['delete'](a),unregisterIndustryPersonae(a),!![];}export function diffIndustryPack(a){const b=packRegistry['get'](a)??null,c=resolveIndustryPackDir(),d=join(c,a),e=readMergedPackIfPresent(d);let f=null;try{if(e&&e['manifest'])f={'version':e['manifest']['version'],'layers':e['manifest']['layers']??[]};else{const l=join(d,'manifest.json');if(existsSync(l)){const m=JSON['parse'](readFileSync(l,'utf-8'));f={'version':m['version'],'layers':m['layers']??[]};}}}catch{f=null;}const g=b?.['layers']??[],h=f?.['layers']??[],i=h['filter'](n=>!g['includes'](n)),j=g['filter'](n=>!h['includes'](n)),k=!!b&&!!f&&(b['version']!==f['version']||i['length']>0x0||j['length']>0x0);return{'name':a,'registered':b?{...b,'layers':[...b['layers']]}:null,'disk':f,'upgradable':k,'layer_diff':{'added':i,'removed':j}};}export function scanPacks(a){const b=[];if(!existsSync(a))return b;for(const c of readdirSync(a,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(a,c['name']);try{const e=loadPackFromDir(d);if(!e)continue;b['push'](registerIndustryPack(e));}catch(f){b['push']({'ok':![],'errors':['failed\x20to\x20load\x20pack\x20\x27'+c['name']+'\x27:\x20'+f['message']],'registered':[]});}}return b;}function loadPackFromDir(a){const b=readMergedPackIfPresent(a),c=join(a,'manifest.json'),d=existsSync(c);if(!b&&!d)return null;if(b){const p=b['manifest'],q={'layout':'merged','manifest':p};if(b['mode'])q['mode']=b['mode'];if(b['match'])q['match']=b['match'];b['personae']&&Array['isArray'](b['personae'])&&(q['personae']=b['personae']);if(b['dispute'])q['dispute']=b['dispute'];if(b['compliance'])q['compliance']=b['compliance'];if(b['supply'])q['supply']=b['supply'];if(b['rules'])q['rules']=b['rules'];const r=join(a,'playbook.md');return existsSync(r)&&(q['playbook']={'category':p['name'],'content':readFileSync(r,'utf-8')}),q;}const e=JSON['parse'](readFileSync(c,'utf-8')),g={'layout':'legacy','manifest':e},h=join(a,'mode.json'),i=join(a,'match.json');existsSync(h)&&(g['mode']=JSON['parse'](readFileSync(h,'utf-8')));existsSync(i)&&(g['match']=JSON['parse'](readFileSync(i,'utf-8')));const j=join(a,'personae');if(existsSync(j)){const s=[];for(const t of readdirSync(j)){if(!t['endsWith']('.json'))continue;s['push'](JSON['parse'](readFileSync(join(j,t),'utf-8')));}if(s['length']>0x0)g['personae']=s;}const k=join(a,'dispute.json');existsSync(k)&&(g['dispute']=JSON['parse'](readFileSync(k,'utf-8')));const l=join(a,'compliance.json');existsSync(l)&&(g['compliance']=JSON['parse'](readFileSync(l,'utf-8')));const m=join(a,'supply.json');existsSync(m)&&(g['supply']=JSON['parse'](readFileSync(m,'utf-8')));const n=join(a,'rules.json');existsSync(n)&&(g['rules']=JSON['parse'](readFileSync(n,'utf-8')));const o=join(a,'playbook.md');return existsSync(o)&&(g['playbook']={'category':e['name'],'content':readFileSync(o,'utf-8')}),g;}export function rescanPack(a){const b=join(resolveIndustryPackDir(),a);try{const c=loadPackFromDir(b);if(!c)return{'ok':![],'errors':['no\x20pack\x20found\x20for\x20\x27'+a+'\x27'],'registered':[]};return registerIndustryPack(c,!![]);}catch(d){return{'ok':![],'errors':['failed\x20to\x20rescan\x20pack\x20\x27'+a+'\x27:\x20'+d['message']],'registered':[]};}}export function resolveIndustryPackDir(){return process['env']['WOWOK_INDUSTRY_DIR']||getWowokIndustryDir();}export function scanDefaultIndustryPacks(){return seedBuiltinIndustryTemplates(),seedBuiltinStrategyManuals(),ensureIndustryReadme(),ensureBuiltinModesAsPacks(),scanPacks(resolveIndustryPackDir());}export function seedBuiltinIndustryTemplates(a=SUPPORTED_INDUSTRIES){const b=[],c=resolveIndustryPackDir();mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();for(const d of a){const e=join(c,d);if(existsSync(join(e,'manifest.json'))||existsSync(join(e,'pack.json')))continue;const f=scaffoldIndustryPack(d,c);if(f['ok'])b['push'](d);}return b;}export function seedBuiltinStrategyManuals(a=SUPPORTED_INDUSTRIES){const b=[],c=resolveIndustryPackDir();for(const d of a){const e=renderStrategyManual(d);if(!e)continue;const f=join(c,d,STRATEGY_MANUAL_FILENAME);try{const g=join(c,d);if(!existsSync(join(g,'manifest.json'))&&!existsSync(join(g,'pack.json'))){const j=scaffoldIndustryPack(d,c);if(!j['ok']){b['push']({'industry':d,'status':'error','path':f,'detail':j['errors']['join'](';\x20')});continue;}}if(!existsSync(f)){writeFileSync(f,e,'utf-8'),b['push']({'industry':d,'status':'written','path':f});continue;}const h=readFileSync(f,'utf-8'),i=classifyManualFile(d,h);if(i==='outdated')writeFileSync(f,e,'utf-8'),b['push']({'industry':d,'status':'updated','path':f});else{if(i==='current')b['push']({'industry':d,'status':'current','path':f});else i==='user_modified'?b['push']({'industry':d,'status':'skipped_user_modified','path':f,'detail':'strategy-manual.md\x20was\x20edited\x20locally;\x20keeping\x20user\x20content\x20and\x20not\x20upgrading'}):b['push']({'industry':d,'status':'skipped_user_file','path':f,'detail':'strategy-manual.md\x20exists\x20without\x20builtin\x20sentinel;\x20leaving\x20user\x20file\x20untouched'});}}catch(k){b['push']({'industry':d,'status':'error','path':f,'detail':k['message']});}}return b;}export const LAYER_FILE_SECTION={'match.json':'match','dispute.json':'dispute','compliance.json':'compliance','supply.json':'supply','rules.json':'rules','mode.json':'mode'};export const PERSONAE_DIR='personae';function manifestSection(a){return{'pack':'industry-pack','name':a,'display_name':a,'version':'0.1.0','layers':['match','personae','dispute','compliance','supply','rules','playbook']};}function matchSection(a){return{'category':a,'hard_constraints':[],'soft_weights':{},'highlight_fields':[],'calendar_mode':'none','geo_mode':'strict','pricing_rules':[]};}function personaPerRole(a,b){return{'role':a,'industry':b,'long_term':{'identity':{'self_description':b+'\x20'+a},'preferences':{}},'current':{'strategy':[],'requirements':[],'rules':[],'spec':'','preferences':{}}};}function disputeSection(a){return{'category':a,'sla_tiers':[],'fault_rules':[]};}function complianceSection(a){return{'category':a,'prepay_mode':'','qualification':[],'disclosure':[],'refund_window':{'days':0x7,'not_applicable':![]}};}function supplySection(a){return{'category':a,'supplier_qualification':[],'first_order_policy':'','redundancy_required':![]};}function rulesSection(a){return{'category':a,'rules':[]};}export function buildPristineMergedPack(a){const b=PERSONA_ROLES['map'](c=>personaPerRole(c,a));return{'manifest':manifestSection(a),'match':matchSection(a),'personae':b,'dispute':disputeSection(a),'compliance':complianceSection(a),'supply':supplySection(a),'rules':rulesSection(a),'mode':null};}export function industryReadmeContent(){return['#\x20WoWok\x20Industry\x20Packs','','>\x20This\x20folder\x20is\x20the\x20WoWok\x20industry\x20knowledge\x20root.\x20Each\x20sub-folder\x20is\x20one','>\x20industry\x20pack.\x20Pack\x20layers\x20are\x20registered\x20into\x20the\x20runtime\x20registry\x20and','>\x20consumed\x20on\x20demand\x20by\x20the\x20build/recommendation\x20tools\x20(merchant_guide,','>\x20recommend_industry,\x20…);\x20a\x20compact\x20strategy\x20summary\x20for\x20the\x20active','>\x20merchant/supplier\x20lens\x20is\x20injected\x20into\x20every\x20chat\x20turn.','','##\x20Pack\x20structure\x20(unified\x20layout)','','Every\x20pack\x20is\x20exactly\x20two\x20files:','','-\x20**`<pack>/pack.json`**\x20—\x20machine-checkable\x20**settings\x20only**.\x20No\x20comments,','\x20\x20no\x20documentation.\x20One\x20section\x20per\x20layer\x20(see\x20below).','-\x20**`<pack>/playbook.md`**\x20—\x20human\x20strategy,\x20tone\x20and\x20field-tested\x20experience.','\x20\x20Registered\x20on\x20scan\x20and\x20read\x20ON\x20DEMAND\x20via\x20industry_pack_operation','\x20\x20(action=\x27get\x27);\x20it\x20OVERRIDES\x20built-in\x20industry\x20data\x20for\x20this\x20account.','','All\x20field\x20explanations\x20live\x20in\x20THIS\x20file,\x20so\x20pack.json\x20stays\x20small\x20and\x20you','can\x20focus\x20on\x20configuration.\x20The\x20editor\x20also\x20validates\x20JSON\x20on\x20save\x20—\x20a\x20file','that\x20fails\x20to\x20parse\x20(or\x20a\x20pack.json\x20missing\x20its\x20manifest)\x20is\x20blocked.','','##\x20How\x20changes\x20take\x20effect','','1.\x20**Save**\x20in\x20the\x20Editor\x20writes\x20bytes\x20to\x20disk.','2.\x20**Scan**\x20(Industry\x20drawer)\x20re-registers\x20each\x20pack\x20into\x20the\x20runtime\x20AI','\x20\x20\x20registry\x20(and\x20SQLite\x20cache).\x20A\x20save\x20of\x20an\x20industry\x20file\x20already\x20runs','\x20\x20\x20Scan\x20automatically.','3.\x20**Next\x20AI\x20chat\x20turn**\x20the\x20registered\x20layers\x20are\x20available\x20to\x20the','\x20\x20\x20on-demand\x20tools\x20(and\x20the\x20merchant/supplier\x20strategy\x20summary\x20is\x20fresh','\x20\x20\x20in\x20the\x20persona\x20context),\x20so\x20the\x20AI\x20reasons\x20against\x20your\x20edited\x20rules','\x20\x20\x20from\x20that\x20point\x20onward.','','##\x20manifest\x20—\x20pack\x20metadata\x20+\x20layer\x20ENABLE\x20flags','','-\x20`name`:\x20snake_case\x20identifier,\x20must\x20match\x20the\x20folder\x20name.','-\x20`version`:\x20bump\x20after\x20editing\x20content\x20so\x20the\x20registry\x20treats\x20it\x20as\x20an\x20upgrade.','-\x20`display_name`:\x20user-visible\x20label.','-\x20`layers`:\x20which\x20sections\x20are\x20validated\x20and\x20registered\x20on\x20scan.\x20Remove\x20a','\x20\x20layer\x20name\x20to\x20DISABLE\x20it\x20(the\x20section\x20stays\x20in\x20pack.json\x20but\x20is\x20ignored).','','##\x20match\x20—\x20category-match\x20rules','','Decides\x20whether\x20an\x20order/service/account\x20belongs\x20to\x20this\x20industry\x20pack:','-\x20`hard_constraints`:\x20array\x20of\x20REQUIRED\x20predicates;\x20ALL\x20must\x20match\x20before\x20the','\x20\x20pack\x20is\x20considered.\x20Example:','\x20\x20`[{\x20key:\x20\x27order.metadata.service_kind\x27,\x20equals:\x20\x27food_onsite\x27\x20}]`','-\x20`soft_weights`:\x20dict\x20`<heuristic_key:\x20number\x200..1>`;\x20higher\x20=\x20stronger\x20signal.','-\x20`pricing_rules`:\x20pricing\x20modes\x20this\x20industry\x20requires.','-\x20`highlight_fields`:\x20dot-paths\x20surfaced\x20in\x20the\x20UI\x20as\x20important\x20info.','-\x20`geo_mode`:\x20`\x27strict\x27`\x20(region\x20must\x20match)\x20|\x20`\x27none\x27`\x20(ignore\x20region).','-\x20`calendar_mode`:\x20`\x27seasonal\x27`\x20|\x20`\x27weekday\x27`\x20|\x20`\x27none\x27`.','','##\x20personae\x20—\x20per-role\x20AI\x20personas','','One\x20persona\x20per\x20role\x20(`merchant`,\x20`customer`,\x20`supplier`,\x20`collaborator`,','`arbitrator`,\x20`prospect`).\x20The\x20AI\x20uses\x20them\x20to\x20role-play\x20negotiation\x20posture:','-\x20`long_term`:\x20stable\x20properties\x20—\x20`identity.self_description`\x20(free-text\x20bio),','\x20\x20`identity.region/languages`,\x20`preferences`\x20(`<key:\x20string[]>`).','-\x20`current`:\x20per-negotiation\x20posture\x20—\x20`strategy`\x20(moves\x20to\x20make),','\x20\x20`requirements`\x20(non-negotiable\x20demands),\x20`rules`\x20(constraints/axioms),','\x20\x20`spec`\x20(free-form\x20text),\x20`preferences`\x20(per-turn\x20overrides).','','##\x20dispute\x20—\x20SLA\x20tiers\x20+\x20fault\x20assignment','','-\x20`sla_tiers[]`:\x20response/remedy\x20windows\x20per\x20severity\x20level.','\x20\x20Example:\x20`{\x20level:\x20\x27L1\x27,\x20response_hours:\x2024,\x20remedy:\x20\x27reply\x27\x20}`','-\x20`fault_rules[]`:\x20automatic\x20fault\x20attribution\x20—\x20a\x20condition\x20plus\x20the\x20side','\x20\x20that\x20bears\x20fault\x20(`merchant`/`customer`/`supplier`/`operator`/`shared`).','\x20\x20Example:\x20`{\x20when:\x20{\x20evidence_has:\x20[\x27late\x20delivery\x20photo\x27]\x20},\x20assign_to:\x20\x27merchant\x27,\x20weight:\x201.0\x20}`','','##\x20compliance\x20—\x20hard\x20requirements\x20before\x20checkout','','-\x20`prepay_mode`:\x20`\x27\x27`\x20|\x20`\x27full\x27`\x20|\x20`\x27partial\x27`\x20|\x20`\x27deposit\x27`.','-\x20`qualification[]`:\x20licenses/certifications\x20a\x20merchant\x20must\x20hold.','\x20\x20Example:\x20`{\x20label:\x20\x27Food\x20Service\x20License\x27,\x20required:\x20true,\x20region:\x20\x27CN\x27\x20}`','-\x20`disclosure[]`:\x20text\x20the\x20merchant\x20MUST\x20show\x20buyers\x20up-front.','-\x20`refund_window`:\x20`{\x20days:\x20number,\x20not_applicable:\x20boolean,\x20exceptions:\x20[...]\x20}`','','##\x20supply\x20—\x20supply-chain\x20/\x20supplier\x20qualification','','-\x20`supplier_qualification[]`:\x20same\x20shape\x20as\x20compliance\x20qualifications,\x20but','\x20\x20evaluated\x20on\x20the\x20SUPPLIER\x20side\x20(multi-party\x20orders).','-\x20`first_order_policy`:\x20policy\x20string\x20on\x20the\x20first\x20order\x20from\x20a\x20new\x20supplier','\x20\x20(e.g.\x20`\x27sample-only\x27`,\x20`\x27reduced-quantity\x27`).','-\x20`redundancy_required`:\x20true\x20=\x20require\x20≥2\x20eligible\x20suppliers\x20before\x20accepting','\x20\x20an\x20order\x20(mitigates\x20single-sourcing).','','##\x20rules\x20—\x20declarative\x20machine-checked\x20rules','','Each\x20rule\x20is\x20an\x20AST\x20node\x20compiled\x20into\x20the\x20evaluation\x20engine:','`{\x20id:\x20\x27rule_...\x27,\x20when:\x20<bool-condition>,\x20then:\x20\x27reject\x27\x20|\x20\x27warn\x27\x20|\x20\x27flag\x27,\x20message:\x20\x27Text\x27\x20}`','Use\x20`rules`\x20for\x20rules\x20that\x20must\x20be\x20machine-checked;\x20put\x20human\x20strategy\x20in','`playbook.md`.','','##\x20mode\x20—\x20IndustryMode\x20(deep\x20shape)','','Not\x20scaffolded\x20by\x20default.\x20Add\x20it\x20when\x20you\x20need\x20a\x20full\x20driving\x20mode\x20for\x20the','industry,\x20or\x20ask\x20the\x20AI:\x20\x22help\x20me\x20fill\x20mode\x20for\x20<industry>\x22.','','Registered\x20into\x20`IndustryModeRegistry`\x20on\x20scan\x20(manifest\x20must\x20list\x20the','`mode`\x20layer).\x20A\x20pack\x20mode\x20with\x20the\x20same\x20name\x20as\x20a\x20builtin\x20replaces\x20it\x20when','the\x20pack\x20version\x20changes\x20or\x20on\x20a\x20forced\x20rescan.','','###\x20How\x20the\x20mode\x20is\x20consumed','','-\x20**Service\x20build\x20(priors)**:\x20`merchant_guide`\x20resolves\x20the\x20confirmed','\x20\x20industry\x20to\x20a\x20mode\x20(user\x20mode\x20first,\x20then\x20pack\x20mode,\x20then\x20builtin)\x20and','\x20\x20feeds\x20`machine_shape`\x20/\x20`guards`\x20/\x20`allocator`\x20/\x20`key_risk`\x20into\x20the','\x20\x20SemanticObjectGraph\x20build.','-\x20**Evaluation**:\x20the\x20metric\x20+\x20constraint\x20registries\x20score\x20the\x20mode','\x20\x20(risk/benefit\x200-100,\x20hard\x20violations\x20block\x20adoption).\x20Custom\x20metrics\x20and','\x20\x20constraints\x20registered\x20via\x20`industry_pack_operation`\x20participate\x20too.','-\x20**Recommendation**:\x20`recommend_industry`\x20matches\x20trait\x20similarity\x20and,','\x20\x20when\x20a\x20merchant\x20strategy\x20is\x20given,\x20re-ranks\x20by\x20lever\x20alignment\x20(70%','\x20\x20similarity\x20+\x2030%\x20alignment).','','###\x20Field\x20reference','','-\x20**Identity**:\x20`name`\x20(snake_case),\x20`display_name`,\x20`version`\x20(e.g.\x20`v1`),','\x20\x20`source`\x20(`builtin`\x20|\x20`custom`).','-\x20`traits`:\x2010-dimension\x20industry\x20trait\x20vector\x20(logistics,\x20cycle,\x20deposit,','\x20\x20regulatory\x20intensity,\x20...).\x20Drives\x20`recommend_industry`\x20similarity.','-\x20`machine_shape`:\x20Machine\x20node\x20topology\x20—\x20`[{\x20name,\x20role\x20}]`.\x20Node\x20names\x20are','\x20\x20business\x20states.\x20R-M1-11:\x20NEVER\x20model\x20refund/dispute\x20terminals','\x20\x20(`refunded`,\x20`disputed`,\x20`arb_*`)\x20as\x20nodes\x20—\x20disputes\x20flow\x20through','\x20\x20Service.arbitrations\x20independently;\x20route\x20refunds\x20via\x20the\x20Allocator','\x20\x20triggered\x20by\x20business\x20states\x20(`cancelled`,\x20`returned`).','-\x20`guards`:\x20`[{\x20template_id,\x20host,\x20purpose\x20}]`\x20—\x20guard\x20templates\x20to\x20attach.','\x20\x20`host`\x20is\x20one\x20of\x20`service`\x20|\x20`machine`\x20|\x20`reward`\x20|\x20`repository`\x20|','\x20\x20`arbitration`.','-\x20`allocator`:\x20`{\x20recipient,\x20count,\x20mode,\x20description\x20}`\x20—\x20fund\x20split.','\x20\x20`recipient`:\x20`signer`\x20|\x20`entity`;\x20`count`\x20>\x201\x20switches\x20to\x20multi-party','\x20\x20distribution;\x20`mode`:\x20`surplus`\x20|\x20`rate`\x20|\x20`milestone`.','-\x20`risk_checks`\x20/\x20`needs`:\x20buyer-side\x20due-diligence\x20entries\x20surfaced\x20in','\x20\x20prospect\x20evaluation.','-\x20`flywheel`:\x20acquisition\x20flywheel\x20—\x20`rewardStrategy`\x20/\x20`discountStrategy`','\x20\x20/\x20`trustSellingPoints`.\x20A\x20concrete\x20(non-`User-defined`)\x20strategy\x20turns','\x20\x20the\x20`reward`/`discount`\x20levers\x20on\x20for\x20strategy\x20alignment.','-\x20`key_risk`\x20(string)\x20/\x20`build_notes`\x20(string[]):\x20the\x20headline\x20risk\x20and','\x20\x20actionable\x20build\x20guidance\x20shown\x20to\x20the\x20merchant.','-\x20`capabilities_used`:\x20CapabilityCard\x20IDs\x20(e.g.\x20`guard.validate_buy`,','\x20\x20`machine.node_topology`,\x20`allocation.distribute_milestone`).\x20Powers\x20the','\x20\x20`buy_guard`\x20/\x20`machine_design`\x20levers\x20and\x20constraint\x20checks.','-\x20`config_overrides`:\x20per-object\x20field\x20defaults,\x20e.g.','\x20\x20`{\x20service:\x20{\x20engagement_type:\x20\x27milestone\x27\x20},\x20machine:\x20{\x20wip_required:\x20true\x20}\x20}`.','-\x20`config_override_rules`:\x20conditional\x20overrides\x20—','\x20\x20`{\x20object_type,\x20field_path,\x20value\x20|\x20{\x20intent_contains,\x20then_value,\x20else_value\x20}\x20}`.','-\x20`expected_benefits`:\x20`[{\x20metric,\x20expected_value,\x20evidence\x20}]`\x20—\x20what\x20the','\x20\x20mode\x20is\x20supposed\x20to\x20buy\x20you.','-\x20`risk_appetite`:\x20`conservative`\x20|\x20`balanced`\x20|\x20`aggressive`\x20(thresholds','\x20\x20for\x20the\x20risk/benefit\x20verdict).','-\x20`risk_constraints`:\x20`{\x20require_arbitration,\x20require_compensation_fund,','\x20\x20require_wip_evidence,\x20max_single_transaction?,','\x20\x20compensation_fund_coverage_ratio?,\x20other_constraints?\x20}`.\x20Coverage\x20ratio','\x20\x20multiplies\x20max\x20single\x20order\x20to\x20size\x20the\x20compensation\x20fund\x20(retail\x205,','\x20\x20rental\x2010,\x20subscription\x203;\x20default\x205).','-\x20`applicable_conditions`:\x20`{\x20business_scale,\x20min_daily_orders?,','\x20\x20other_conditions?\x20}`\x20—\x20when\x20the\x20mode\x20fits.','-\x20`similar_industries`\x20/\x20`novel_capabilities`:\x20migration\x20hints.','-\x20`disabled_builtin_constraints`:\x20builtin\x20constraint\x20IDs\x20this\x20mode','\x20\x20deliberately\x20opts\x20out\x20of\x20(e.g.\x20retail_d2c\x20skips\x20`require_arbitration`).','\x20\x20Custom\x20constraints\x20are\x20never\x20skipped.','','###\x20Persona\x20integration\x20(strategy\x20→\x20levers)','','The\x20personae\x20section\x27s\x20`current.strategy`\x20statements\x20are\x20bridged\x20into\x20mode','ranking\x20(value\x20intent\x20↔\x20game\x20path\x20unification).\x20Deterministic\x20mapping\x20—','\x22enumerable\x20→\x20MCP,\x20not\x20prompt\x22:','','-\x20`sales_priority`\x20(volume\x20first)\x20→\x20levers\x20`discount`\x20+\x20`reward`','-\x20`profit_priority`\x20(margin\x20first)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','-\x20`buyer_screening`\x20(qualify\x20buyers)\x20→\x20lever\x20`buy_guard`','-\x20`gross_margin_control`\x20(margin\x20band)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','','A\x20mode\x20supports\x20a\x20lever\x20when\x20its\x20data\x20says\x20so:\x20`guard.validate_buy`','capability\x20or\x20a\x20buy-guard\x20template\x20enables\x20`buy_guard`;\x20a\x20concrete','flywheel\x20reward/discount\x20strategy\x20enables\x20`reward`/`discount`;\x20a','non-empty\x20`machine_shape`\x20with\x20`machine.node_topology`\x20enables','`machine_design`.\x20Pass\x20strategy\x20text\x20to\x20`recommend_industry`\x20and\x20each','recommendation\x20reports\x20`strategy_alignment`\x20(matched/missing\x20levers).','','##\x20custom-registry.json\x20—\x20global\x20custom\x20metrics\x20/\x20constraints\x20/\x20modes','','Custom\x20metrics,\x20constraints\x20and\x20user\x20modes\x20registered\x20via','`industry_pack_operation`\x20(register_custom_metric\x20/','register_custom_constraint\x20/\x20derive_user_mode\x20/\x20register_user_mode)','persist\x20to\x20THIS\x20root-level\x20file\x20—\x20it\x20is\x20global\x20and\x20applies\x20to\x20every','industry\x20pack.\x20Layout:\x20`metrics`\x20keyed\x20by\x20metric\x20id,\x20`constraints`','keyed\x20by\x20constraint\x20id,\x20`user_modes`\x20keyed\x20by\x20`<owner>:<name>`.\x20The','file\x20is\x20created\x20on\x20first\x20use\x20(seeded\x20from\x20the\x20legacy\x20SQLite\x20cache\x20when','present);\x20hand\x20edits\x20take\x20effect\x20on\x20the\x20next\x20registry\x20call,\x20and','deleting\x20an\x20entry\x20removes\x20it.','','##\x20Reset','','Right-click\x20any\x20file/pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20and\x20choose\x20*Reset*','to\x20restore\x20the\x20pristine\x20template\x20at\x20any\x20time.','']['join']('\x0a');}export function ensureIndustryReadme(){const a=resolveIndustryPackDir();mkdirSync(a,{'recursive':!![]});const b=join(a,'README.md');return writeFileSync(b,industryReadmeContent(),'utf-8'),b;}export function scaffoldIndustryPack(a,b){const c=join(b??resolveIndustryPackDir(),a),d=[],e=[];if(!/^[a-z][a-z0-9_]*$/['test'](a))return{'ok':![],'dir':c,'files':d,'errors':['industry\x20name\x20\x27'+a+'\x27\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)']};try{mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();const f=buildPristineMergedPack(a);return writeFileSync(join(c,'pack.json'),JSON['stringify'](f,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(c,'playbook.md'),playbookTemplate(a)),d['push']('playbook.md'),{'ok':!![],'dir':c,'files':d,'errors':e};}catch(g){return{'ok':![],'dir':c,'files':d,'errors':['scaffold\x20failed:\x20'+g['message']]};}}export function readMergedPackIfPresent(a){const b=join(a,'pack.json');if(!existsSync(b))return null;try{const c=readFileSync(b,'utf-8');return JSON['parse'](c);}catch{return null;}}function playbookTemplate(a){return['#\x20'+a+'\x20—\x20Industry\x20Playbook','','>\x20📘\x20This\x20file\x20captures\x20human\x20business\x20intelligence\x20for\x20the\x20`'+a+'`','>\x20industry.\x20Content\x20here\x20is\x20READ\x20BY\x20THE\x20AI\x20AS\x20CONTEXT\x20on\x20every\x20turn,','>\x20and\x20OVERRIDES\x20WoWok\x27s\x20generic\x20built-in\x20industry\x20data/rules\x20for\x20this','>\x20account.\x20The\x20companion\x20`pack.json`\x20file\x20stores\x20machine-checkable','>\x20rules;\x20THIS\x20file\x20stores\x20human\x20strategy,\x20tone,\x20experience,\x20and\x20ethics.','','>\x20💡\x20Hint\x20for\x20the\x20AI:\x20when\x20the\x20user\x20asks\x20a\x20question\x20about\x20\x22how\x20to','>\x20handle\x20'+a+'\x22\x20or\x20\x22what\x20should\x20I\x20do?\x22,\x20check\x20this\x20file\x20first\x20for\x20the','>\x20merchant/customer\x20voice,\x20then\x20fall\x20back\x20to\x20your\x20built-in\x20data.\x20Cite','>\x20section\x20titles\x20in\x20your\x20reply\x20so\x20the\x20user\x20knows\x20where\x20advice\x20comes\x20from.','','##\x20Experience\x20(Field-Tested\x20Rules\x20of\x20Thumb)','','>\x20Write\x20what\x20actually\x20works\x20in\x20this\x20industry\x20—\x20not\x20what\x20textbooks\x20say.','>\x20Short\x20bullet\x20points\x20preferred;\x20the\x20AI\x20reads\x20them\x20as\x20axioms.\x20Include','>\x20specific\x20numbers\x20when\x20you\x20have\x20them.','','-\x20(Example)\x20\x22Catering:\x20if\x20the\x20event\x20starts\x20before\x2010:00,\x20always\x20assume','\x20\x20the\x20customer\x20wants\x20breakfast\x20service\x20too\x20—\x20upsell\x20it\x20proactively.\x22','-\x20(Example)\x20\x22Common\x20pitfall:\x20last-minute\x20menu\x20swaps\x20on\x20Fridays\x20—\x20require','\x20\x20a\x20written\x20change\x20request\x2048\x20h\x20before\x20the\x20event\x20or\x20charge\x20a\x2015%\x20fee.\x22','-\x20(Add\x20more\x20below\x20—\x20delete\x20the\x20examples\x20above\x20when\x20you\x20have\x20real\x20ones.)','','##\x20Strategy\x20(Competitive\x20/\x20Game-Theory)','','>\x20How\x20should\x20each\x20role\x20act\x20in\x20a\x20negotiation\x20/\x20dispute\x20/\x20supplier','>\x20relationship?\x20Think\x20in\x20\x22always\x20/\x20never\x20/\x20depends-on-X\x22\x20rules,\x20and\x20call','>\x20out\x20the\x20trade-offs.','','-\x20Merchant\x20strategy:\x20(Add\x20how\x20a\x20merchant\x20in\x20this\x20industry\x20should\x20act\x20—','\x20\x20price\x20anchoring,\x20which\x20concessions\x20to\x20give\x20early\x20vs\x20late,\x20what\x20to','\x20\x20never\x20concede\x20on,\x20etc.)','-\x20Customer\x20strategy:\x20(Add\x20what\x20a\x20smart\x20customer\x20should\x20push\x20for.)','-\x20Dispute\x20strategy:\x20(When\x20to\x20settle\x20fast\x20vs\x20when\x20to\x20fight\x20for\x20full','\x20\x20evidence\x20+\x20arbitration.\x20Call\x20out\x20the\x20escalation\x20thresholds.)','','##\x20Personalization\x20(Tone,\x20Brand,\x20Ethics,\x20Red\x20Lines)','','-\x20Tone\x20/\x20voice:\x20(Write\x20one\x20sentence\x20describing\x20the\x20exact\x20conversational','\x20\x20voice\x20this\x20account\x20should\x20use\x20—\x20casual,\x20formal,\x20technical,\x20etc.)','-\x20Brand\x20rules:\x20(Logo,\x20link-out\x20style,\x20forbidden\x20terminology,','\x20\x20always-include\x20phrases,\x20etc.)','-\x20Red\x20lines:\x20(Non-negotiable.\x20Example:\x20\x22Never\x20make\x20a\x20refund\x20promise','\x20\x20larger\x20than\x2030%\x20without\x20arbitration\x20evidence.\x22)','-\x20Ethics:\x20(Example:\x20\x22If\x20customer\x20appears\x20intoxicated,\x20refuse\x20service','\x20\x20and\x20refer\x20to\x20supervisor;\x20never\x20take\x20the\x20order\x20for\x20profit.\x22)','','##\x20Playbook\x20Maintenance','','>\x20You\x20don\x27t\x20need\x20to\x20be\x20perfect\x20on\x20day\x20one.\x20After\x20every\x20real\x20deal,\x20add\x20a','>\x20bullet\x20to\x20the\x20above\x20sections\x20with\x20what\x20worked\x20/\x20what\x20failed.\x20Every','>\x20entry\x20improves\x20the\x20AI\x27s\x20future\x20decisions.','','>\x20Right-click\x20the\x20file\x20or\x20this\x20pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20at','>\x20any\x20time\x20and\x20choose\x20\x22Reset\x22\x20to\x20restore\x20this\x20annotated\x20template.','']['join']('\x0a');}export function locatePackAndRemainder(a){const b=a['replace'](/^[\\/]+/,'')['replace'](/[\\/]+$/,'');if(!b)return null;const [c,...d]=b['split'](/[\\/]+/);if(!c)return null;return{'packName':c,'remainder':d['join']('/')};}export function resetIndustryPath(a,b){const c=[],d=[],f=b??resolveIndustryPackDir(),g=locatePackAndRemainder(a),h=a;if(!g)return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['invalid\x20reset\x20path\x20\x27'+a+'\x27']};const {packName:i,remainder:j}=g,k=join(f,i);if(!existsSync(k))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20directory\x20\x27'+i+'\x27\x20does\x20not\x20exist']};if(!/^[a-z][a-z0-9_]*$/['test'](i))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20name\x20\x27'+i+'\x27\x20is\x20not\x20a\x20valid\x20snake_case\x20identifier']};const l=readMergedPackIfPresent(k),n=l?'merged':'legacy';if(j==='')try{mkdirSync(k,{'recursive':!![]});const s=buildPristineMergedPack(i);return writeFileSync(join(k,'pack.json'),JSON['stringify'](s,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':'merged','target':h,'restored_files':d,'errors':c};}catch(t){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['pack\x20reset\x20failed:\x20'+t['message']]};}const o=j['split']('/')['slice'](-0x1)[0x0],p=j==='playbook.md',q=j['startsWith'](PERSONAE_DIR+'/')&&o['endsWith']('.json');if(n==='merged'){if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(v){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['playbook\x20reset\x20failed:\x20'+v['message']]};}const u=LAYER_FILE_SECTION[j];if(u)try{const w=readMergedPackIfPresent(k)??buildPristineMergedPack(i);switch(u){case'match':w['match']=matchSection(i);break;case'dispute':w['dispute']=disputeSection(i);break;case'compliance':w['compliance']=complianceSection(i);break;case'supply':w['supply']=supplySection(i);break;case'rules':w['rules']=rulesSection(i);break;case'mode':w['mode']=null;break;}return writeFileSync(join(k,'pack.json'),JSON['stringify'](w,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(x){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['section\x20reset\x20failed:\x20'+x['message']]};}if(q){const y=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](y))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20role\x20\x27'+y+'\x27']};try{const z=readMergedPackIfPresent(k)??buildPristineMergedPack(i),A=z['personae']&&Array['isArray'](z['personae'])?[...z['personae']]:[],B=A['findIndex'](D=>D['role']===y),C=personaPerRole(y,i);if(B>=0x0)A[B]=C;else A['push'](C);return z['personae']=A,writeFileSync(join(k,'pack.json'),JSON['stringify'](z,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(D){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['persona\x20reset\x20failed:\x20'+D['message']]};}}if(j==='manifest.json'||j==='manifest')try{const E=readMergedPackIfPresent(k)??buildPristineMergedPack(i);return E['manifest']=manifestSection(i),writeFileSync(join(k,'pack.json'),JSON['stringify'](E,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(F){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['manifest\x20reset\x20failed:\x20'+F['message']]};}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['path\x20\x27'+j+'\x27\x20is\x20not\x20a\x20standard\x20section\x20file\x20of\x20pack\x20\x27'+i+'\x27.\x20Reset\x20is\x20only\x20provided\x20for\x20pack.json\x20standard\x20sections\x20and\x20playbook.md.']};}if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(G){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20playbook\x20reset\x20failed:\x20'+G['message']]};}if(j==='manifest.json')try{const H=manifestSection(i);return writeFileSync(join(k,'manifest.json'),JSON['stringify'](H,null,0x2)+'\x0a'),d['push']('manifest.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(I){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20manifest\x20reset\x20failed:\x20'+I['message']]};}const r=LAYER_FILE_SECTION[j];if(r)try{let J='';switch(r){case'match':J=JSON['stringify'](matchSection(i),null,0x2)+'\x0a';break;case'dispute':J=JSON['stringify'](disputeSection(i),null,0x2)+'\x0a';break;case'compliance':J=JSON['stringify'](complianceSection(i),null,0x2)+'\x0a';break;case'supply':J=JSON['stringify'](supplySection(i),null,0x2)+'\x0a';break;case'rules':J=JSON['stringify'](rulesSection(i),null,0x2)+'\x0a';break;case'mode':J=JSON['stringify']({},null,0x2)+'\x0a';break;}return writeFileSync(join(k,j),J),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(K){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20section\x20reset\x20failed:\x20'+K['message']]};}if(q){const L=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](L))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20\x27'+L+'\x27']};try{return writeFileSync(join(k,j),JSON['stringify'](personaPerRole(L,i),null,0x2)+'\x0a'),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(M){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20persona\x20reset\x20failed:\x20'+M['message']]};}}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['cannot\x20reset\x20non-standard\x20file\x20\x27'+j+'\x27\x20in\x20legacy\x20layout.\x20Only\x20standard\x20layer\x20files,\x20personae/*.json,\x20manifest.json,\x20and\x20playbook.md\x20can\x20be\x20reset.']};}
|
|
@@ -3,8 +3,8 @@ import type { CapabilityRegistry } from "./capability-manifest.js";
|
|
|
3
3
|
export declare class MetricRegistry {
|
|
4
4
|
private static instance;
|
|
5
5
|
private metrics;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
6
|
+
private file;
|
|
7
|
+
private customSyncedMtime;
|
|
8
8
|
static Instance(): MetricRegistry;
|
|
9
9
|
private constructor();
|
|
10
10
|
ensureLoaded(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{CustomRegistryFile}from'./custom-registry-file.js';const BUILTIN_RISK_METRICS=[{'metric_id':'funds_risk','display_name':'Funds\x20Risk','description':'Directly\x20operates\x20funds\x20/\x20affects\x20fund\x20flow\x20/\x20no\x20fund\x20risk','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_risk','display_name':'Trust\x20Risk','description':'Degree\x20of\x20impact\x20on\x20trust\x20mechanism','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'delivery_risk','display_name':'Delivery\x20Risk','description':'Degree\x20of\x20impact\x20on\x20order\x20fulfillment','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'compliance_risk','display_name':'Compliance\x20Risk','description':'Degree\x20of\x20regulatory\x20involvement','type':'risk','scale':'level','weight':0x1,'scope':'builtin'}],BUILTIN_BENEFIT_METRICS=[{'metric_id':'automation_level','display_name':'Automation\x20Level','description':'Fully\x20automated\x20/\x20semi-automated\x20/\x20manual','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_boost','display_name':'Trust\x20Boost','description':'Degree\x20of\x20enhancement\x20to\x20trust\x20mechanism','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'efficiency_gain','display_name':'Efficiency\x20Gain','description':'Degree\x20of\x20efficiency\x20improvement','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'}];export class MetricRegistry{static ['instance'];['metrics']=new Map();['file']=CustomRegistryFile['Instance']();['customSyncedMtime']=-0x1;static['Instance'](){return!MetricRegistry['instance']&&(MetricRegistry['instance']=new MetricRegistry()),MetricRegistry['instance'];}constructor(){this['registerBuiltinMetrics']();}async['ensureLoaded'](){const {data:a,mtime:b}=await this['file']['read']();if(b<0x0||b===this['customSyncedMtime'])return;this['customSyncedMtime']=b;for(const [c,d]of this['metrics']){if(d['scope']==='custom')this['metrics']['delete'](c);}for(const e of Object['values'](a['metrics'])){const f=e;f?.['metric_id']&&f['scope']==='custom'?this['metrics']['set'](f['metric_id'],f):console['warn']('[MetricRegistry]\x20Skipping\x20invalid\x20custom_metrics\x20file\x20entry.');}}['registerMetric'](a){if(!a['metric_id']||!a['type']||!a['scale'])return![];if(this['metrics']['has'](a['metric_id']))return![];return this['metrics']['set'](a['metric_id'],a),!![];}async['registerCustomMetric'](a,b,c,d,e,f,g){await this['ensureLoaded']();const h={'metric_id':a,'display_name':b,'description':c,'type':d,'scale':e,'weight':g??0x1,'scope':'custom','owner':f},i=this['registerMetric'](h);return i&&await this['file']['update'](j=>{j['metrics'][a]=h;}),i;}['getMetric'](a){return this['metrics']['get'](a);}async['listMetrics'](a){await this['ensureLoaded']();let b=Array['from'](this['metrics']['values']());if(!a)return b;if(a['type'])b=b['filter'](c=>c['type']===a['type']);if(a['scope'])b=b['filter'](c=>c['scope']===a['scope']);if(a['owner'])b=b['filter'](c=>c['owner']===a['owner']);return b;}async['unregisterMetric'](a,b){await this['ensureLoaded']();const c=this['metrics']['get'](a);if(!c||c['scope']!=='custom'||c['owner']!==b)return![];const d=this['metrics']['delete'](a);return d&&await this['file']['update'](e=>{delete e['metrics'][a];}),d;}['evaluateMode'](a,b,c){const d=[...this['metrics']['values']()];if(c)for(const l of c){!d['some'](n=>n['metric_id']===l['metric_id'])&&d['push'](l);}const e=d['filter'](n=>n['type']==='risk'),f=d['filter'](n=>n['type']==='benefit'),g=[];for(const n of a['capabilities_used']){const o=b['getCard'](n);if(o)g['push'](o);}const h=this['evaluateMetricGroup'](g,e,'risk'),i=this['evaluateMetricGroup'](g,f,'benefit'),j=this['aggregateScore'](h),k=this['aggregateScore'](i);return{'risk_score':j,'benefit_score':k,'metric_details':[...h,...i]};}['evaluateMetricGroup'](a,b,c){const d=[];for(const e of b){const f=[];for(const h of a){const i=c==='risk'?h['risk_profile']:h['benefit_profile'];if(!i)continue;const j=i[e['metric_id']];j!==undefined&&f['push']({'value':j,'weight':0x1});}if(f['length']===0x0)continue;const g=this['computeAverageScore'](f,e['scale']);d['push']({'metric_id':e['metric_id'],'display_name':e['display_name'],'value':this['aggregateValue'](f,e['scale']),'normalized_score':g,'weight':e['weight']??0x1});}return d;}['computeAverageScore'](a,b){if(a['length']===0x0)return 0x0;if(b==='level'){const c={'high':0x64,'medium':0x3c,'low':0x1e};let d=0x0,e=0x0;for(const f of a){const g=c[String(f['value'])]??0x32;d+=g*f['weight'],e+=f['weight'];}return Math['round'](d/Math['max'](e,0x1));}if(b==='numeric'){let h=0x0,i=0x0;for(const j of a){const k=typeof j['value']==='number'?j['value']:0x32;h+=k*j['weight'],i+=j['weight'];}return Math['round'](h/Math['max'](i,0x1));}if(b==='percentage'){let l=0x0,m=0x0;for(const n of a){const o=typeof n['value']==='number'?n['value']:0x32;l+=o*n['weight'],m+=n['weight'];}return Math['round'](l/Math['max'](m,0x1));}return 0x0;}['aggregateValue'](a,b){if(b==='level'){const d={'high':0x0,'medium':0x0,'low':0x0};for(const f of a){const g=String(f['value']);if(d[g]!==undefined)d[g]++;}const e=Object['entries'](d)['sort']((h,i)=>i[0x1]-h[0x1])[0x0]?.[0x0];return e??'medium';}const c=a['reduce']((h,i)=>h+(typeof i['value']==='number'?i['value']:0x0),0x0);return Math['round'](c/a['length']);}['aggregateScore'](a){if(a['length']===0x0)return 0x0;let b=0x0,c=0x0;for(const e of a){b+=e['normalized_score']*e['weight'],c+=e['weight'];}return Math['round'](b/Math['max'](c,0x1));}['registerBuiltinMetrics'](){for(const a of BUILTIN_RISK_METRICS){this['registerMetric'](a);}for(const b of BUILTIN_BENEFIT_METRICS){this['registerMetric'](b);}}}export function getMetricRegistry(){return MetricRegistry['Instance']();}export const BUILTIN_METRICS_COUNT=BUILTIN_RISK_METRICS['length']+BUILTIN_BENEFIT_METRICS['length'];
|