@wowok/agent-mcp 3.2.7 → 3.3.0
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/README.md +2 -2
- package/dist/chain-semantics/field-capability.js +1 -1
- package/dist/chain-semantics/freeze-map.js +1 -1
- package/dist/chain-semantics/fund-flow.js +1 -1
- package/dist/chain-semantics/guard-verbs.js +1 -1
- package/dist/chain-semantics/object-graph.js +1 -1
- package/dist/composition/audit.js +1 -1
- package/dist/composition/compile.d.ts +10 -1
- package/dist/composition/compile.js +1 -1
- package/dist/composition/inflight.d.ts +10 -0
- package/dist/composition/inflight.js +1 -1
- package/dist/extensions/business-modules.d.ts +1 -1
- package/dist/extensions/business-modules.js +1 -1
- package/dist/extensions/capability-manifest.js +1 -1
- package/dist/extensions/industry-audit.spec.js +1 -1
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/graph/onchain/edge-schema.js +1 -1
- package/dist/graph/onchain/facts.spec.js +1 -1
- package/dist/graph/onchain/field-manifest.js +1 -1
- package/dist/harness/index.d.ts +1 -0
- package/dist/harness/index.js +1 -1
- package/dist/harness/operation-id.d.ts +1 -0
- package/dist/harness/operation-id.js +1 -0
- package/dist/harness/recover.js +1 -1
- package/dist/index.js +1 -1
- package/dist/intent/types.d.ts +1 -1
- package/dist/intent/types.js +1 -1
- package/dist/keeper/KeeperScan.d.ts +2 -1
- package/dist/keeper/KeeperScan.js +1 -1
- package/dist/keeper/keeper.spec.js +1 -1
- package/dist/keeper/types.d.ts +3 -0
- package/dist/keeper/types.js +1 -1
- package/dist/knowledge/allocator-rail-verifier.d.ts +34 -0
- package/dist/knowledge/allocator-rail-verifier.js +1 -0
- package/dist/knowledge/arbitration-ledger.js +1 -1
- package/dist/knowledge/arbitration-templates.js +1 -1
- package/dist/knowledge/arbitration-venue-order.js +1 -1
- package/dist/knowledge/audit-rules.d.ts +19 -1
- package/dist/knowledge/audit-rules.js +1 -1
- package/dist/knowledge/baselines/rules/alloc_audit.json +1 -1
- package/dist/knowledge/baselines/rules/arb.json +1 -1
- package/dist/knowledge/baselines/rules/guard.json +106 -1
- package/dist/knowledge/baselines/rules/machine.json +9 -6
- package/dist/knowledge/baselines/rules/plan.json +40 -17
- package/dist/knowledge/baselines/semantic-facts.js +1 -1
- package/dist/knowledge/builtin-templates.d.ts +1 -1
- package/dist/knowledge/builtin-templates.js +1 -1
- package/dist/knowledge/contract-invariants.js +1 -1
- package/dist/knowledge/discount-threshold.d.ts +11 -0
- package/dist/knowledge/discount-threshold.js +1 -1
- package/dist/knowledge/event-semantics.js +1 -1
- package/dist/knowledge/fund-layer.js +1 -1
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-anchor-reach.d.ts +1 -1
- package/dist/knowledge/guard-anchor-reach.js +1 -1
- package/dist/knowledge/guard-bindings.js +1 -1
- package/dist/knowledge/guard-design-patterns.d.ts +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/guard-field-cognition.js +1 -1
- package/dist/knowledge/guard-ledger.js +1 -1
- package/dist/knowledge/guard-lint.js +1 -1
- package/dist/knowledge/guard-render.js +1 -1
- package/dist/knowledge/guard-risk.d.ts +1 -0
- package/dist/knowledge/guard-risk.js +1 -1
- package/dist/knowledge/guard-submission-brief.d.ts +6 -0
- package/dist/knowledge/guard-submission-brief.js +1 -1
- package/dist/knowledge/guard-templates.d.ts +2 -2
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/industry-strategy.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-ledger.js +1 -1
- package/dist/knowledge/machine-puzzle.d.ts +1 -1
- package/dist/knowledge/machine-puzzle.js +1 -1
- package/dist/knowledge/machine-risk.js +1 -1
- package/dist/knowledge/machine-templates.js +1 -1
- package/dist/knowledge/machine-topology.d.ts +8 -0
- package/dist/knowledge/machine-topology.js +1 -1
- package/dist/knowledge/machine-translation.js +1 -1
- package/dist/knowledge/order-ledger.js +1 -1
- package/dist/knowledge/permission-ledger.js +1 -1
- package/dist/knowledge/protocol-facts.d.ts +16 -0
- package/dist/knowledge/protocol-facts.js +1 -0
- package/dist/knowledge/recipient-constraint.js +1 -1
- package/dist/knowledge/reward-ledger.d.ts +2 -1
- package/dist/knowledge/reward-ledger.js +1 -1
- package/dist/knowledge/reward-templates.js +1 -1
- package/dist/knowledge/safety-rules.d.ts +0 -2
- package/dist/knowledge/safety-rules.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +7 -0
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/strategy-manuals.js +1 -1
- package/dist/knowledge/template-loader.d.ts +13 -1
- package/dist/knowledge/template-loader.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.d.ts +2 -0
- package/dist/knowledge/template-scanner.js +1 -1
- package/dist/knowledge/tool-constraints.js +1 -1
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +7 -3
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/monitor/normalize.d.ts +1 -1
- package/dist/monitor/normalize.js +1 -1
- package/dist/monitor/types.d.ts +1 -1
- package/dist/monitor/types.js +1 -1
- package/dist/participation/radar-core.d.ts +1 -1
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/game-theory.d.ts +1 -0
- package/dist/playbooks/service-build/game-theory.js +1 -1
- package/dist/playbooks/service-build/intent-analyzer.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/merchant-guide.d.ts +8 -0
- package/dist/playbooks/service-build/merchant-guide.js +1 -1
- package/dist/playbooks/service-build/object-panorama.d.ts +28 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.d.ts +2 -0
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.js +1 -1
- package/dist/playbooks/service-build/reverse-mapping-nk4.spec.js +1 -1
- package/dist/playbooks/service-build/reverse-mapping.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/service-quote.js +1 -1
- package/dist/playbooks/service-build/service-quote.spec.js +1 -1
- package/dist/relationship/registry.js +1 -1
- package/dist/review/index.js +1 -1
- package/dist/role/profiles.js +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/safety/preview.d.ts +1 -0
- package/dist/safety/preview.js +1 -1
- package/dist/schema/benchmark-migration/index.d.ts +19 -1
- package/dist/schema/benchmark-migration/index.js +1 -1
- package/dist/schema/call/allocation.d.ts +1 -1
- package/dist/schema/call/arbitration.d.ts +8 -8
- package/dist/schema/call/arbitration.js +1 -1
- package/dist/schema/call/base.d.ts +52 -5
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/bridge.d.ts +3 -0
- package/dist/schema/call/contact.d.ts +5 -5
- package/dist/schema/call/demand.d.ts +5 -5
- package/dist/schema/call/error-codes.d.ts +1 -1
- package/dist/schema/call/error-codes.js +1 -1
- package/dist/schema/call/guard.d.ts +3 -3
- package/dist/schema/call/guard.js +1 -1
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +13 -5
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/order.d.ts +5 -5
- package/dist/schema/call/order.js +1 -1
- package/dist/schema/call/permission.d.ts +5 -5
- package/dist/schema/call/personal.d.ts +4 -4
- package/dist/schema/call/progress.d.ts +5 -5
- package/dist/schema/call/progress.js +1 -1
- package/dist/schema/call/proof.js +1 -1
- package/dist/schema/call/receipt.d.ts +8 -0
- package/dist/schema/call/receipt.js +1 -1
- package/dist/schema/call/repository.d.ts +9 -9
- package/dist/schema/call/repository.js +1 -1
- package/dist/schema/call/reward.d.ts +25 -5
- package/dist/schema/call/reward.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +10 -5
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/call/treasury.d.ts +5 -5
- package/dist/schema/common/index.d.ts +6 -6
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/goal/index.d.ts +17 -1
- package/dist/schema/goal/planning.d.ts +28 -2
- package/dist/schema/goal/planning.js +1 -1
- package/dist/schema/industry-pack/index.d.ts +3 -0
- package/dist/schema/industry-pack/index.js +1 -1
- package/dist/schema/intent-radar/index.d.ts +9 -0
- package/dist/schema/intent-radar/index.js +1 -1
- package/dist/schema/local/index.d.ts +31 -0
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/messenger/index.js +1 -1
- package/dist/schema/operations.d.ts +57 -43
- package/dist/schema/operations.js +1 -1
- package/dist/schema/query/bi.d.ts +22 -6
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/query/index.d.ts +164 -102
- package/dist/schema/query/index.js +1 -1
- package/dist/schema/schema-query/index.d.ts +2 -0
- package/dist/schema/schema-query/index.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/utils/permission-machine-check.d.ts +2 -0
- package/dist/schema/utils/permission-machine-check.js +1 -1
- package/dist/schema/workflow/index.d.ts +1 -1
- package/dist/schema-query-impl/index.d.ts +1 -1
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +3 -0
- package/dist/schemas/account_operation.schema.json +4 -4
- package/dist/schemas/benchmark_migration_operation.output.json +42 -0
- package/dist/schemas/benchmark_migration_operation.schema.json +40 -3
- package/dist/schemas/bridge_operation.output.json +3 -0
- package/dist/schemas/goal_operation.schema.json +52 -2
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/industry_pack_operation.output.json +8 -0
- package/dist/schemas/industry_pack_operation.schema.json +9 -0
- package/dist/schemas/intent_radar.output.json +8 -2
- package/dist/schemas/intent_radar.schema.json +4 -1
- package/dist/schemas/local_cache_operation.output.json +3 -0
- package/dist/schemas/local_history_operation.output.json +3 -0
- package/dist/schemas/local_info_operation.output.json +3 -0
- package/dist/schemas/local_mark_operation.output.json +3 -0
- package/dist/schemas/messenger_operation.schema.json +4 -4
- package/dist/schemas/monitor_events.schema.json +3 -1
- package/dist/schemas/onchain_events.output.json +275 -11
- package/dist/schemas/onchain_events.schema.json +25 -1
- package/dist/schemas/onchain_operations.output.json +47 -5
- package/dist/schemas/onchain_operations.schema.json +664 -179
- package/dist/schemas/onchain_operations_allocation.schema.json +7 -7
- package/dist/schemas/onchain_operations_arbitration.schema.json +21 -15
- package/dist/schemas/onchain_operations_contact.schema.json +15 -10
- package/dist/schemas/onchain_operations_demand.schema.json +15 -10
- package/dist/schemas/onchain_operations_gen_passport.schema.json +5 -5
- package/dist/schemas/onchain_operations_gen_proof.schema.json +1 -1
- package/dist/schemas/onchain_operations_guard.schema.json +346 -8
- package/dist/schemas/onchain_operations_machine.schema.json +24 -11
- package/dist/schemas/onchain_operations_order.schema.json +17 -12
- package/dist/schemas/onchain_operations_permission.schema.json +10 -5
- package/dist/schemas/onchain_operations_personal.schema.json +2 -2
- package/dist/schemas/onchain_operations_progress.schema.json +17 -12
- package/dist/schemas/onchain_operations_proof.schema.json +6 -6
- package/dist/schemas/onchain_operations_repository.schema.json +19 -14
- package/dist/schemas/onchain_operations_reward.schema.json +96 -15
- package/dist/schemas/onchain_operations_service.schema.json +33 -21
- package/dist/schemas/onchain_operations_treasury.schema.json +15 -10
- package/dist/schemas/onchain_table_data.output.json +7 -7
- package/dist/schemas/query_toolkit.output.json +268 -44
- package/dist/schemas/query_toolkit.schema.json +1 -1
- package/dist/schemas/schema_query.schema.json +7 -2
- package/dist/schemas/workflow_operation.schema.json +5 -5
- package/dist/schemas/wowok_buildin_info.output.json +140 -3
- package/dist/schemas/wowok_buildin_info.schema.json +2 -2
- package/dist/tools/handlers/benchmark-migration.d.ts +66 -1
- package/dist/tools/handlers/benchmark-migration.js +1 -1
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/dispatch-expectations.d.ts +0 -1
- package/dist/tools/handlers/dispatch-expectations.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/intent-radar.js +1 -1
- package/dist/tools/handlers/keeper.d.ts +1 -1
- package/dist/tools/handlers/local.js +1 -1
- package/dist/tools/handlers/onchain.d.ts +12 -0
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/query.d.ts +1 -0
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/handlers/review-chain.js +1 -1
- package/dist/tools/handlers/schema-query.js +1 -1
- package/dist/tools/handlers/workflow.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/move-fn-index.gen.js +1 -1
- package/dist/tools/registry/agent.js +1 -1
- package/dist/tools/registry/business.js +1 -1
- package/dist/tools/registry/files.js +1 -1
- package/dist/tools/registry/query.js +1 -1
- package/dist/tools/rules-hook.js +1 -1
- package/dist/tools/upgrade-check.d.ts +23 -0
- package/dist/tools/upgrade-check.js +1 -1
- package/dist/tools/wip-deploy-assist.d.ts +6 -0
- package/dist/tools/wip-deploy-assist.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
"get_guard_design_patterns",
|
|
20
20
|
"get_safety_rules",
|
|
21
21
|
"get_templates",
|
|
22
|
-
"analyze_guard_semantics"
|
|
22
|
+
"analyze_guard_semantics",
|
|
23
|
+
"get_guard_queries"
|
|
23
24
|
],
|
|
24
|
-
"description": "Action to perform: 'list' (all schemas), 'get' (specific input schema), 'get_output' (tool output schema), 'get_field' (field-path query e.g. field_path='data.node'), 'search' (by keyword), 'list_operations' (on-chain operations), 'get_guard_templates' (Guard creation templates + best practices), 'get_tool_reference' (MCP tool usage reference: summaries, actions, prerequisites, notes — sunk from wowok-tools skill), 'get_guard_design_patterns' (curated Guard design pattern catalog: business requirement → logic tree template — sunk from wowok-guard skill), 'get_safety_rules' (object reuse/immutability/operation-classification/naming rules — sunk from wowok-safety skill), 'get_templates' (unified template registry: ~90 parameterized templates across 11 object types — guard/machine/service/order/progress/arbitration/treasury/permission/passport/allocation/reward; omit 'template' to list metadata, provide 'template' for full detail, provide 'template' + 'params' to instantiate into executable JSON), 'analyze_guard_semantics' (parse + evaluate any Guard JSON: rendered logic tree, lint diagnostics, risk assessment, and a party-perspective reading — who can trigger, under what conditions, with what evidence. Both transacting parties should run this BEFORE relying on a Guard)."
|
|
25
|
+
"description": "Action to perform: 'list' (all schemas), 'get' (specific input schema), 'get_output' (tool output schema), 'get_field' (field-path query e.g. field_path='data.node'), 'search' (by keyword), 'list_operations' (on-chain operations), 'get_guard_templates' (Guard creation templates + best practices), 'get_tool_reference' (MCP tool usage reference: summaries, actions, prerequisites, notes — sunk from wowok-tools skill), 'get_guard_design_patterns' (curated Guard design pattern catalog: business requirement → logic tree template — sunk from wowok-guard skill), 'get_safety_rules' (object reuse/immutability/operation-classification/naming rules — sunk from wowok-safety skill), 'get_templates' (unified template registry: ~90 parameterized templates across 11 object types — guard/machine/service/order/progress/arbitration/treasury/permission/passport/allocation/reward; omit 'template' to list metadata, provide 'template' for full detail, provide 'template' + 'params' to instantiate into executable JSON), 'analyze_guard_semantics' (parse + evaluate any Guard JSON: rendered logic tree, lint diagnostics, risk assessment, and a party-perspective reading — who can trigger, under what conditions, with what evidence. Both transacting parties should run this BEFORE relying on a Guard), 'get_guard_queries' (the GUARDQUERY catalog — every Guard query instruction as data: {id, name, objectType, returnType}; optional query='<keyword>' for full entries with descriptions, output_file to dump all details. Use this to build the field→query→semantics map BEFORE writing Guard trees — and prefer NAME references: a numeric id is resolved verbatim, so a wrong-but-existing id silently checks a different field)."
|
|
25
26
|
},
|
|
26
27
|
"name": {
|
|
27
28
|
"description": "Schema/tool name for 'get'/'get_output'/'get_field'/'get_tool_reference' action (e.g., 'onchain_operations', 'onchain_operations_machine'), or pattern id for 'get_guard_design_patterns' (e.g., 'pattern.identity_check_allowlist').",
|
|
@@ -102,6 +103,10 @@
|
|
|
102
103
|
"mainnet",
|
|
103
104
|
"testnet"
|
|
104
105
|
]
|
|
106
|
+
},
|
|
107
|
+
"compare_with": {
|
|
108
|
+
"description": "ROUND-TRIP VERIFICATION (ZR-32/BKN-P5): an on-chain Guard ADDRESS or LocalMark name to diff the local JSON against. When set (with guard given as JSON forms 1/2), the live chain Guard is loaded and structurally diffed (tree node census, table row count, per-slot b_submission/value_type, rely) — any divergence is reported as an ERROR diagnostic and ready=false. Guards are create-frozen, so this is the only way to prove a local spec still matches what the chain actually stored.",
|
|
109
|
+
"type": "string"
|
|
105
110
|
}
|
|
106
111
|
},
|
|
107
112
|
"required": [
|
|
@@ -150,6 +150,7 @@
|
|
|
150
150
|
"description": "Whether this table item's value is submitted dynamically at Guard trigger time (alloc_by_guard call). \n\ntrue = value is submitted by the caller when triggering the Guard. Use for runtime-context-dependent values like order address, user address. The 'value' field is ignored when b_submission=true; the caller must provide it via submissions[]. \n\nfalse = value is static, set at Guard creation time. Use for values known when the Guard is created: expected node names, expected merchant address, expected service address. The 'value' field must be populated and will be stored on-chain permanently. \n\nRule of thumb: if the value is the SAME for all future Guard triggers, use false. If the value DIFFERS per trigger (e.g., which order to release funds for), use true."
|
|
151
151
|
},
|
|
152
152
|
"value_type": {
|
|
153
|
+
"description": "Type of the value stored in `value`. One of: Bool(0), Address(1), String(2), U8(3), U16(4), U32(5), U64(6), U128(7), U256(8), VecBool(9), VecAddress(10), VecString(11), VecU8(12), VecU16(13), VecU32(14), VecU64(15), VecU128(16), VecU256(17), VecVecU8(18). When value_type=Address (1), the `value` field accepts a hex address string, a LocalMark name, or an AccountOrMark_Address object — see `value` field description for details.",
|
|
153
154
|
"anyOf": [
|
|
154
155
|
{
|
|
155
156
|
"type": "number",
|
|
@@ -436,11 +437,10 @@
|
|
|
436
437
|
"const": "vecvecu8",
|
|
437
438
|
"description": "vecvecu8"
|
|
438
439
|
}
|
|
439
|
-
]
|
|
440
|
-
"description": "Type of the value stored in `value`. One of: Bool(0), Address(1), String(2), U8(3), U16(4), U32(5), U64(6), U128(7), U256(8), VecBool(9), VecAddress(10), VecString(11), VecU8(12), VecU16(13), VecU32(14), VecU64(15), VecU128(16), VecU256(17), VecVecU8(18). When value_type=Address (1), the `value` field accepts a hex address string, a LocalMark name, or an AccountOrMark_Address object — see `value` field description for details."
|
|
440
|
+
]
|
|
441
441
|
},
|
|
442
442
|
"value": {
|
|
443
|
-
"description": "The actual value data. Format depends on `value_type`:\n• Bool: true/false (boolean)\n• Address (CRITICAL — string 'Address' is NOT a placeholder): a hex address (e.g. '0x1234...'), a LocalMark name (e.g. 'my-service' — resolved to address at evaluation time), an AccountOrMark_Address object (e.g. {name_or_address:'my-service'}), or system shorthand ('0xaaa' = EntityLinker, '0xaab' = EntityRegistrar). The literal string 'Address' itself is INVALID — it would be treated as a non-existent LocalMark name and fail. Example: value='0x2::wow::WOW<address>' or value='my-permission'.\n• String: any string\n• U8/U16/U32/U64/U128/U256: number or numeric string (e.g. 42 or '42')\n• Vec* types: arrays of the corresponding element type\nREQUIRED when b_submission=false. OPTIONAL when b_submission=true (value is supplied at evaluation time by user submission).",
|
|
443
|
+
"description": "The actual value data. Format depends on `value_type`:\nTYPE-CLASS SPLIT (F03): scalar value_types (Bool/Address/String/U8..U256) take ONE scalar value (boolean/address string/name/string/number); Vec* value_types (VecBool/VecAddress/VecString/VecU8..VecU256) take a REAL JSON ARRAY of elements — a string (even a Python-repr-looking \"[a, b]\") fails serialization with 'value_type=10 (array) requires a array value'. The historical 'static values must be strings' rule applied to SCALARS only.\n• Bool: true/false (boolean)\n• Address (CRITICAL — string 'Address' is NOT a placeholder): a hex address (e.g. '0x1234...'), a LocalMark name (e.g. 'my-service' — resolved to address at evaluation time), an AccountOrMark_Address object (e.g. {name_or_address:'my-service'}), or system shorthand ('0xaaa' = EntityLinker, '0xaab' = EntityRegistrar). The literal string 'Address' itself is INVALID — it would be treated as a non-existent LocalMark name and fail. Example: value='0x2::wow::WOW<address>' or value='my-permission'.\n• String: any string\n• U8/U16/U32/U64/U128/U256: number or numeric string (e.g. 42 or '42')\n• Vec* types: arrays of the corresponding element type\nPROTOCOL SLOT 254 (once, b_submission Address): the submitted value MUST be the ORDER address bound to the operation (payment_info.for_object) — NEVER the Progress/Machine/Arb object the call is advancing. The chain asserts submission(254) == the order address; a Progress address fails the task binding and the forward aborts.\nREQUIRED when b_submission=false. OPTIONAL when b_submission=true (value is supplied at evaluation time by user submission).",
|
|
444
444
|
"anyOf": [
|
|
445
445
|
{
|
|
446
446
|
"type": "boolean"
|
|
@@ -599,7 +599,7 @@
|
|
|
599
599
|
"additionalProperties": false,
|
|
600
600
|
"description": "Guard table item (QUERY/OUTPUT form — includes auto-derived object_type field)"
|
|
601
601
|
},
|
|
602
|
-
"description": "User-submitted data matching the Guard's required fields. Relation: structure must match the Guard table's column definitions. Example: [{field:'delivery_proof', value:'Qm...'}]"
|
|
602
|
+
"description": "User-submitted data matching the Guard's required fields. Relation: structure must match the Guard table's column definitions. Example: [{field:'delivery_proof', value:'Qm...'}] PROTOCOL SLOT 254: when the Guard table has identifier 254, submit the ORDER address bound to the operation (payment_info.for_object) — never the Progress/Machine object being advanced."
|
|
603
603
|
}
|
|
604
604
|
},
|
|
605
605
|
"required": [
|
|
@@ -609,7 +609,7 @@
|
|
|
609
609
|
"additionalProperties": false,
|
|
610
610
|
"description": "One Guard's submission data: the Guard to verify plus the user-provided data that satisfies its requirements."
|
|
611
611
|
},
|
|
612
|
-
"description": "User-submitted data for each Guard. Relation: one entry per Guard in the guard array; fill submission fields and resubmit via call_with_submission. PLACEMENT: this `submission` field is at the SAME level as `data` and `env` in the operation input — NOT inside `data.data`. Example structure: {tool:'onchain_operations', data:{operation_type:'order', data:{object:'my_order', progress:{...}}}, submission:{type:'submission', guard:[...], submission:[...]}}"
|
|
612
|
+
"description": "User-submitted data for each Guard. Relation: one entry per Guard in the guard array; fill submission fields and resubmit via call_with_submission. SLOT COMPLETENESS (T8 az3-mn-261013): the submission array must cover EVERY b_submission slot in the Guard's table, not just one — a Guard whose table has multiple b_submission entries (e.g. slot 0 + slot 254) aborts on-chain with 'Submission ID not found' (abort 11) when any b_submission slot has no matching entry. Check the Guard's table (each entry with b_submission needs its identifier filled) and include ALL of them. PLACEMENT: this `submission` field is at the SAME level as `data` and `env` in the operation input — NOT inside `data.data`. Example structure: {tool:'onchain_operations', data:{operation_type:'order', data:{object:'my_order', progress:{...}}}, submission:{type:'submission', guard:[...], submission:[...]}}"
|
|
613
613
|
}
|
|
614
614
|
},
|
|
615
615
|
"required": [
|
|
@@ -517,7 +517,7 @@
|
|
|
517
517
|
"description": "vecvecu8"
|
|
518
518
|
}
|
|
519
519
|
],
|
|
520
|
-
"description": "User available value type (number
|
|
520
|
+
"description": "User available value type (number, numeric string, or name — e.g., 6, '6', 'U64', 'u64')"
|
|
521
521
|
},
|
|
522
522
|
{
|
|
523
523
|
"type": "number",
|
|
@@ -866,7 +866,7 @@
|
|
|
866
866
|
"description": "vecvecu8"
|
|
867
867
|
}
|
|
868
868
|
],
|
|
869
|
-
"description": "User available value type (number
|
|
869
|
+
"description": "User available value type (number, numeric string, or name — e.g., 6, '6', 'U64', 'u64')"
|
|
870
870
|
},
|
|
871
871
|
{
|
|
872
872
|
"type": "number",
|
|
@@ -1177,7 +1177,7 @@
|
|
|
1177
1177
|
"description": "vecvecu8"
|
|
1178
1178
|
}
|
|
1179
1179
|
],
|
|
1180
|
-
"description": "User available value type (number
|
|
1180
|
+
"description": "User available value type (number, numeric string, or name — e.g., 6, '6', 'U64', 'u64')"
|
|
1181
1181
|
},
|
|
1182
1182
|
{
|
|
1183
1183
|
"type": "number",
|
|
@@ -1677,6 +1677,143 @@
|
|
|
1677
1677
|
"additionalProperties": false,
|
|
1678
1678
|
"description": "SDK runtime module health"
|
|
1679
1679
|
},
|
|
1680
|
+
"build_stamp": {
|
|
1681
|
+
"description": "Build identity stamp (M-K5 / CTR-B1/B5 + DEPLOY-K1 chain stamp): the per-round version surface a test harness must record; findings from a round whose stamp is missing or stale are not attributable to current code or a known chain state",
|
|
1682
|
+
"type": "object",
|
|
1683
|
+
"properties": {
|
|
1684
|
+
"builtin_templates_version": {
|
|
1685
|
+
"type": "number",
|
|
1686
|
+
"description": "Builtin industry template catalog version — the disk build-source contract (listTemplates hot-loads the disk tree); a test report must record this to claim it describes the current build"
|
|
1687
|
+
},
|
|
1688
|
+
"mcp_dist_stale": {
|
|
1689
|
+
"anyOf": [
|
|
1690
|
+
{
|
|
1691
|
+
"type": "object",
|
|
1692
|
+
"properties": {
|
|
1693
|
+
"stale": {
|
|
1694
|
+
"type": "boolean"
|
|
1695
|
+
},
|
|
1696
|
+
"lag_minutes": {
|
|
1697
|
+
"type": "number"
|
|
1698
|
+
}
|
|
1699
|
+
},
|
|
1700
|
+
"required": [
|
|
1701
|
+
"stale",
|
|
1702
|
+
"lag_minutes"
|
|
1703
|
+
],
|
|
1704
|
+
"additionalProperties": false
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
"type": "null"
|
|
1708
|
+
}
|
|
1709
|
+
],
|
|
1710
|
+
"description": "MCP workspace src newer than its dist (null = no workspace src tree, installed build); stale=true means the process may run code older than its sources — rebuild before drawing conclusions"
|
|
1711
|
+
},
|
|
1712
|
+
"sdk_dist_stale": {
|
|
1713
|
+
"anyOf": [
|
|
1714
|
+
{
|
|
1715
|
+
"type": "object",
|
|
1716
|
+
"properties": {
|
|
1717
|
+
"stale": {
|
|
1718
|
+
"type": "boolean"
|
|
1719
|
+
},
|
|
1720
|
+
"lag_minutes": {
|
|
1721
|
+
"type": "number"
|
|
1722
|
+
}
|
|
1723
|
+
},
|
|
1724
|
+
"required": [
|
|
1725
|
+
"stale",
|
|
1726
|
+
"lag_minutes"
|
|
1727
|
+
],
|
|
1728
|
+
"additionalProperties": false
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
"type": "null"
|
|
1732
|
+
}
|
|
1733
|
+
],
|
|
1734
|
+
"description": "SDK workspace src newer than its dist, same semantics (null = no workspace src tree)"
|
|
1735
|
+
},
|
|
1736
|
+
"chain_stamp": {
|
|
1737
|
+
"type": "object",
|
|
1738
|
+
"properties": {
|
|
1739
|
+
"network": {
|
|
1740
|
+
"anyOf": [
|
|
1741
|
+
{
|
|
1742
|
+
"type": "string"
|
|
1743
|
+
},
|
|
1744
|
+
{
|
|
1745
|
+
"type": "null"
|
|
1746
|
+
}
|
|
1747
|
+
]
|
|
1748
|
+
},
|
|
1749
|
+
"protocol_version": {
|
|
1750
|
+
"anyOf": [
|
|
1751
|
+
{
|
|
1752
|
+
"type": "string"
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
"type": "null"
|
|
1756
|
+
}
|
|
1757
|
+
],
|
|
1758
|
+
"description": "Chain protocol version observed on the current network (null when the chain was unreachable)"
|
|
1759
|
+
},
|
|
1760
|
+
"system_state_version": {
|
|
1761
|
+
"anyOf": [
|
|
1762
|
+
{
|
|
1763
|
+
"type": "string"
|
|
1764
|
+
},
|
|
1765
|
+
{
|
|
1766
|
+
"type": "null"
|
|
1767
|
+
}
|
|
1768
|
+
],
|
|
1769
|
+
"description": "System state data-structure version observed (null when unreachable)"
|
|
1770
|
+
},
|
|
1771
|
+
"epoch": {
|
|
1772
|
+
"anyOf": [
|
|
1773
|
+
{
|
|
1774
|
+
"type": "string"
|
|
1775
|
+
},
|
|
1776
|
+
{
|
|
1777
|
+
"type": "null"
|
|
1778
|
+
}
|
|
1779
|
+
],
|
|
1780
|
+
"description": "Current epoch observed (null when unreachable)"
|
|
1781
|
+
},
|
|
1782
|
+
"fetched": {
|
|
1783
|
+
"type": "boolean",
|
|
1784
|
+
"description": "false when the chain was unreachable — the null fields then carry no meaning and must not be quoted"
|
|
1785
|
+
},
|
|
1786
|
+
"fetched_at": {
|
|
1787
|
+
"anyOf": [
|
|
1788
|
+
{
|
|
1789
|
+
"type": "string"
|
|
1790
|
+
},
|
|
1791
|
+
{
|
|
1792
|
+
"type": "null"
|
|
1793
|
+
}
|
|
1794
|
+
]
|
|
1795
|
+
}
|
|
1796
|
+
},
|
|
1797
|
+
"required": [
|
|
1798
|
+
"network",
|
|
1799
|
+
"protocol_version",
|
|
1800
|
+
"system_state_version",
|
|
1801
|
+
"epoch",
|
|
1802
|
+
"fetched",
|
|
1803
|
+
"fetched_at"
|
|
1804
|
+
],
|
|
1805
|
+
"additionalProperties": false,
|
|
1806
|
+
"description": "Chain-side attribution stamp (DEPLOY-K1): the chain generation this round actually exercised. Deployment-skew class (repo source ahead of the deployed chain — e.g. chain-side replay enforcement measured absent on mainnet) is detectable by recording this per test round; a report without it cannot claim to describe a specific chain state"
|
|
1807
|
+
}
|
|
1808
|
+
},
|
|
1809
|
+
"required": [
|
|
1810
|
+
"builtin_templates_version",
|
|
1811
|
+
"mcp_dist_stale",
|
|
1812
|
+
"sdk_dist_stale",
|
|
1813
|
+
"chain_stamp"
|
|
1814
|
+
],
|
|
1815
|
+
"additionalProperties": false
|
|
1816
|
+
},
|
|
1680
1817
|
"reminder": {
|
|
1681
1818
|
"type": "object",
|
|
1682
1819
|
"properties": {
|
|
@@ -452,7 +452,7 @@
|
|
|
452
452
|
"description": "vecvecu8"
|
|
453
453
|
}
|
|
454
454
|
],
|
|
455
|
-
"description": "User available value type (number
|
|
455
|
+
"description": "User available value type (number, numeric string, or name — e.g., 6, '6', 'U64', 'u64')"
|
|
456
456
|
},
|
|
457
457
|
{
|
|
458
458
|
"type": "number",
|
|
@@ -603,7 +603,7 @@
|
|
|
603
603
|
"info"
|
|
604
604
|
],
|
|
605
605
|
"additionalProperties": false,
|
|
606
|
-
"description": "Upgrade check - returns current vs latest npm versions of the WoWok MCP server and SDK, whether the WoWok desktop client is installed, SDK runtime module health (detects the stale-chunk failure class that version comparison cannot see), and whether an upgrade/install/restart reminder is due. Call at the start of a conversation to decide whether to remind the user to upgrade, install the client, or restart the MCP server."
|
|
606
|
+
"description": "Upgrade check - returns current vs latest npm versions of the WoWok MCP server and SDK, whether the WoWok desktop client is installed, SDK runtime module health (detects the stale-chunk failure class that version comparison cannot see), a build_stamp (template catalog version, src-vs-dist staleness, and a chain-side attribution stamp for the current network), and whether an upgrade/install/restart reminder is due. Call at the start of a conversation to decide whether to remind the user to upgrade, install the client, or restart the MCP server, and record build_stamp in any test round so findings are attributable."
|
|
607
607
|
},
|
|
608
608
|
{
|
|
609
609
|
"type": "object",
|
|
@@ -1,8 +1,73 @@
|
|
|
1
1
|
import { validateAllocatorRows, type IndustryTemplate } from "../../knowledge/template-loader.js";
|
|
2
|
+
import { type TemplateScanResult } from "../../knowledge/template-scanner.js";
|
|
2
3
|
import type { DeliverableDefinition } from "../../playbooks/service-build/intent-analyzer.js";
|
|
3
4
|
import type { IndustryMode } from "../../extensions/index.js";
|
|
4
5
|
import type { ToolDispatchResult } from "../types.js";
|
|
5
|
-
|
|
6
|
+
declare function driftFace(templateId: string): {
|
|
7
|
+
template: string;
|
|
8
|
+
state: "current";
|
|
9
|
+
catalog_version: number;
|
|
10
|
+
blocked: boolean;
|
|
11
|
+
repairable: boolean;
|
|
12
|
+
detail: string;
|
|
13
|
+
} | {
|
|
14
|
+
template: string;
|
|
15
|
+
state: "untracked";
|
|
16
|
+
catalog_version: number;
|
|
17
|
+
blocked: boolean;
|
|
18
|
+
repairable: boolean;
|
|
19
|
+
detail: string;
|
|
20
|
+
} | {
|
|
21
|
+
template: string;
|
|
22
|
+
state: "modified" | "missing";
|
|
23
|
+
catalog_version: number;
|
|
24
|
+
blocked: boolean;
|
|
25
|
+
repairable: boolean;
|
|
26
|
+
detail: string;
|
|
27
|
+
};
|
|
28
|
+
declare function scanSummary(scan: TemplateScanResult, drift?: ReturnType<typeof driftFace>): {
|
|
29
|
+
risk_level: import("../../knowledge/template-scanner.js").TemplateRiskLevel;
|
|
30
|
+
passed: boolean;
|
|
31
|
+
finding_count: number;
|
|
32
|
+
findings_by_severity: Record<string, number>;
|
|
33
|
+
red_flags: string[];
|
|
34
|
+
findings: import("../../knowledge/template-scanner.js").TemplateScanFinding[];
|
|
35
|
+
drift: {
|
|
36
|
+
template: string;
|
|
37
|
+
state: "current";
|
|
38
|
+
catalog_version: number;
|
|
39
|
+
blocked: boolean;
|
|
40
|
+
repairable: boolean;
|
|
41
|
+
detail: string;
|
|
42
|
+
} | {
|
|
43
|
+
template: string;
|
|
44
|
+
state: "untracked";
|
|
45
|
+
catalog_version: number;
|
|
46
|
+
blocked: boolean;
|
|
47
|
+
repairable: boolean;
|
|
48
|
+
detail: string;
|
|
49
|
+
} | {
|
|
50
|
+
template: string;
|
|
51
|
+
state: "modified" | "missing";
|
|
52
|
+
catalog_version: number;
|
|
53
|
+
blocked: boolean;
|
|
54
|
+
repairable: boolean;
|
|
55
|
+
detail: string;
|
|
56
|
+
} | undefined;
|
|
57
|
+
};
|
|
58
|
+
export declare function buildVerdict(summary: ReturnType<typeof scanSummary>, plan: Record<string, unknown>): {
|
|
59
|
+
buildable: boolean;
|
|
60
|
+
blockers: string[];
|
|
61
|
+
};
|
|
62
|
+
export declare function planNextAction(plan: Record<string, unknown>, retryAction: string, verdict?: {
|
|
63
|
+
buildable: boolean;
|
|
64
|
+
blockers: string[];
|
|
65
|
+
}): string;
|
|
66
|
+
export interface RewardPoolPrefill {
|
|
67
|
+
fee_key: "review_reward_pool";
|
|
68
|
+
value: number;
|
|
69
|
+
}
|
|
70
|
+
export declare function extractRewardPoolCandidate(description: string | undefined): number | undefined;
|
|
6
71
|
export { validateAllocatorRows };
|
|
7
72
|
export declare function variantPaymentModel(t: IndustryTemplate): "milestone" | "subscription" | "escrow";
|
|
8
73
|
export declare function variantDeliverables(t: IndustryTemplate, traits: IndustryMode["traits"] | undefined): DeliverableDefinition[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{strictParse}from'../../schema/index.js';import{BenchmarkMigrationSchema}from'../../schema/benchmark-migration/index.js';import{getTemplate,listTemplates,validateAllocatorRows,platformShareBps}from'../../knowledge/template-loader.js';import{scanTemplate,buildFeeParamLandingTable}from'../../knowledge/template-scanner.js';import{planMigration}from'../../playbooks/service-build/migration-planner.js';import{handleMerchantGuide}from'../../playbooks/service-build/merchant-guide.js';import{inferArbitration}from'../../playbooks/service-build/intent-analyzer.js';import{getIndustryModeRegistry}from'../../extensions/index.js';import{resolveIndustryName}from'../../knowledge/industry-registry.js';function templateSummary(a){return{'id':a['id'],'industry':a['industry'],'variant':a['variant'],'product_ref':a['product_ref'],'archetype':a['archetype'],'key_risk':a['key_risk'],'node_count':a['machine_shape']['length'],'guard_count':a['guards']['length'],'recommended_role':a['recommended_role']};}function requireTemplate(a,b){if(!a)throw new Error('\x27template_id\x27\x20is\x20required\x20for\x20action=\x27'+b+'\x27');const c=getTemplate(a);if(!c)throw new Error('Unknown\x20template\x20id:\x20'+a+'\x20(use\x20action=\x27template_list\x27\x20to\x20see\x20valid\x20ids)');return c;}function scanSummary(a){const b={};for(const c of a['findings'])b[c['severity']]=(b[c['severity']]??0x0)+0x1;return{'risk_level':a['risk_level'],'passed':a['passed'],'finding_count':a['findings']['length'],'findings_by_severity':b,'red_flags':a['red_flags'],'findings':a['findings']};}function assertScanPassed(a,b){if(a['passed'])return;throw new Error('action=\x27'+b+'\x27\x20blocked:\x20pre-deploy\x20scan\x20of\x20template\x20\x27'+a['template_id']+'\x27\x20found\x20CRITICAL\x20risk\x20—\x20'+a['red_flags']['join'](';\x20')+'.\x20Fix\x20the\x20template\x20(frontmatter\x20or\x20body)\x20and\x20re-run\x20action=\x27template_scan\x27.');}export function planNextAction(a,b){const c=a['next_action'];if(typeof c==='string'&&c['startsWith']('Plan\x20ready.'))return c;const d=Array['isArray'](a['pending_guard_designs'])?a['pending_guard_designs']['length']:0x0;return'Plan\x20BLOCKED\x20by\x20the\x20guide\x20audit\x20(see\x20plan.audit\x20/\x20plan.next_action).\x20Do\x20NOT\x20materialize,\x20'+'and\x20do\x20NOT\x20hand-build\x20the\x20objects\x20instead:\x20this\x20plan\x20is\x20the\x20wiring\x20authority\x20(Arbitration\x20+\x20'+'compensation-fund,\x20Contact/um,\x20allocator\x20rows)\x20and\x20hand-built\x20replicas\x20silently\x20drop\x20those\x20wirings.\x20'+(d>0x0?'Resolve\x20the\x20'+d+'\x20pending\x20guard\x20design(s)\x20in\x20plan.pending_guard_designs\x20via\x20guard_resolutions\x20(kind\x20\x27inline\x27\x20with\x20the\x20Guard\x20table+root,\x20or\x20kind\x20\x27template\x27\x20with\x20a\x20tpl_*\x20id),\x20':'Adjust\x20fee_overrides,\x20pick\x20another\x20template\x20variant,\x20or\x20fix\x20the\x20template,\x20')+('then\x20re-run\x20action=\x27'+b+'\x27.');}function templateIntent(a,b){if(b&&b['trim']())return b['trim']();return'Adopt\x20the\x20'+a['id']+'\x20industry\x20archetype\x20template\x20('+a['archetype']+')\x20for\x20the\x20'+a['industry']+'\x20industry.\x20'+('Primary\x20risk\x20to\x20mitigate:\x20'+a['key_risk']+'.');}function effectiveFeeParams(a,b){return{...a['fee_params'],...b??{}};}function validateFeeParams(a,b){const c=[];let d=0x0;for(const [e,f]of Object['entries'](a)){if(typeof f!=='number'||!Number['isFinite'](f))continue;if(e['endsWith']('_bps')){(!Number['isInteger'](f)||f<0x0||f>0x2710)&&c['push'](e+'='+f+'\x20is\x20not\x20an\x20integer\x20rate\x20in\x20[0,\x2010000]\x20bps');if(e['endsWith']('_share_bps'))d+=Math['max'](0x0,f);}else{if(e['endsWith']('_days')){if(f<=0x0||f>0xe42)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x203650]\x20days');}else{if(e['endsWith']('_hours')){if(f<=0x0||f>0x2238)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x208760]\x20hours');}}}}if(d>0x2710)c['push']('*_share_bps\x20sum\x20'+d+'\x20exceeds\x2010000\x20(a\x20pool\x20splits\x20into\x20at\x20most\x20100%)');if(c['length']>0x0)throw new Error('invalid\x20fee\x20parameters\x20for\x20template\x20\x27'+b+'\x27:\x20'+c['join'](';\x20')+'.\x20'+'Correct\x20the\x20template\x27s\x20fee_params\x20or\x20pass\x20valid\x20\x27fee_overrides\x27.');}export{validateAllocatorRows};export function variantPaymentModel(a){if(a['payment_model'])return a['payment_model'];const b=a['allocator']['rows']??[];if(b['some'](d=>d['track']==='refund'))return'escrow';const c=a['machine_shape']['map'](d=>d['name'])['join']('\x20')['toLowerCase']();if(/\b(milestone|revision|revis|draft|deliverable)\b/['test'](c))return'milestone';if(/\b(charge|renew|subscription|cycle|billing|monthly)\b/['test'](c))return'subscription';return'escrow';}function variantRefundPolicy(a){const b=a['allocator']['description']['toLowerCase']();if(/full[ -]?refund|100% refund|refund .*100/['test'](b))return'full';if(/pro-?rata|prorated/['test'](b))return'milestone_prorated';if(/partial/['test'](b))return'partial';return undefined;}export function variantDeliverables(a,b){const c=a['machine_shape']['filter'](g=>g['semantic_role']==='final'),d=c[c['length']-0x1]??[...a['machine_shape']]['reverse']()['find'](g=>!/refund|cancel|dispute|terminat/i['test'](g['name']+'\x20'+g['role']))??a['machine_shape'][a['machine_shape']['length']-0x1],e=b?.['has_logistics']?'physical':b?.['pure_digital']?'digital':'service_session',f=(a['guards']??[])['filter'](h=>/repository_data_check|required_info_evidence_gate|allocator_order_anchor/['test'](h['template_id']));return[{'name':a['variant']+'\x20fulfillment','type':e,'acceptanceCriteria':'Order\x20reaches\x20the\x20terminal\x20workflow\x20node\x20\x27'+d['name']+'\x27\x20('+d['role']+')','proofOfDelivery':f['length']>0x0?'wip_hash':'manual_confirm'}];}function validateConditionalParams(a,b){for(const d of a['conditional_guards']??[]){const e=b[d['param']];if(e===undefined)continue;if(typeof e!=='string'||!d['values']['includes'](e))throw new Error('invalid\x20\x27'+d['param']+'='+String(e)+'\x27\x20for\x20template\x20\x27'+a['id']+'\x27:\x20must\x20be\x20one\x20of\x20'+d['values']['map'](f=>'\x27'+f+'\x27')['join']('\x20|\x20')+('\x20(the\x20guard\x20variant\x20mounts\x20at\x20\x27'+d['emit_value']+'\x27)'));}}async function runGuide(a,b,c,d){const e=effectiveFeeParams(a,c);validateFeeParams(e,a['id']),validateConditionalParams(a,e);const f=getIndustryModeRegistry()['getMode'](a['industry']),g=platformShareBps(e),h={'model':variantPaymentModel(a)},i=[],j=(a['allocator']['rows']?.['length']??0x0)>0x0;if(g!==undefined&&g>0x0&&!j&&a['allocator']['mode']==='rate'){const n=Math['round'](g)/0x64;i['push']({'recipient':'merchant','percentage':Math['round']((0x64-n)*0x64)/0x64}),i['push']({'recipient':'platform','percentage':n}),h['allocation']=i;}const k=variantRefundPolicy(a),l={'escrow':!![]};if(k)l['refundPolicy']=k;l['arbitration']=a['arbitration_mode']??l['arbitration']??inferArbitration(templateIntent(a,b));const m=await handleMerchantGuide({'intent':templateIntent(a,b),'guide_confirm':{'industry':a['industry'],'payment':h,'trust':l,'deliverables':variantDeliverables(a,f?.['traits']),...d&&Object['keys'](d)['length']>0x0?{'guard_resolutions':d}:{}},'template_override':{...a,'fee_params':e},'name_base':a['id']});if(a['allocator']['rows']?.['length'])m['template_allocator_rows']=a['allocator']['rows']['map'](o=>({...o}));m['template']={'id':a['id'],'archetype':a['archetype'],'recommended_role':a['recommended_role'],'fee_params':e},m['template_fee_param_landings']=buildFeeParamLandingTable(a,e);if(c&&Object['keys'](c)['length']>0x0)m['template_fee_overrides']=c;return m;}export async function handleBenchmarkMigrationOperation(a){const b=strictParse(BenchmarkMigrationSchema,a,'benchmark_migration_operation\x20input'),c=b['industry']?resolveIndustryName(b['industry'])??b['industry']['toLowerCase']():undefined;let d;switch(b['action']){case'template_list':{const {templates:e,errors:f}=listTemplates(),g=c?e['filter'](h=>h['industry']===c):e;d={'action':'template_list','count':g['length'],'templates':g['map'](templateSummary),'load_errors':f};break;}case'template_get':{const h=requireTemplate(b['template_id'],'template_get');d={'action':'template_get','template':{...h}};break;}case'template_generate':{const i=requireTemplate(b['template_id'],'template_generate'),j=scanTemplate(i);assertScanPassed(j,'template_generate');const k=await runGuide(i,b['description'],b['fee_overrides'],b['guard_resolutions']);d={'action':'template_generate','template_id':i['id'],'scan':scanSummary(j),'plan':k,'next_action':planNextAction(k,'template_generate')};break;}case'template_scan':{const l=requireTemplate(b['template_id'],'template_scan');d={'action':'template_scan','scan':scanTemplate(l)};break;}case'migration_import':{if(!b['description']||!b['description']['trim']())throw new Error('\x27description\x27\x20is\x20required\x20for\x20action=\x27migration_import\x27');const m=planMigration({'url':b['url'],'description':b['description'],'industry':c,'network':b['network']});if(!m)throw new Error('No\x20industry\x20template\x20matched\x20the\x20description.\x20Refine\x20the\x20description\x20or\x20pass\x20an\x20explicit\x20\x27industry\x27\x20hint.');d={'action':'migration_import','log':m,'next_action':'MigrationLog\x20ready.\x20Next:\x20call\x20action=\x27migration_review\x27\x20with\x20this\x20log\x20to\x20surface\x20the\x20mapped/unmapped/manual_review\x20items\x20for\x20user\x20confirmation.'};break;}case'migration_review':{if(!b['log'])throw new Error('\x27log\x27\x20is\x20required\x20for\x20action=\x27migration_review\x27');const n=b['log'],o=Array['isArray'](n['mapped'])?n['mapped']:[],p=Array['isArray'](n['unmapped'])?n['unmapped']:[],q=Array['isArray'](n['manual_review'])?n['manual_review']:[],r=n['risk_check']??{},s=n['source']?.['matched_template']??'',t=p['length']===0x0&&q['length']===0x0&&r['passed']===!![];d={'action':'migration_review','log':n,'review_summary':{'mapped_count':o['length'],'unmapped_count':p['length'],'manual_review_count':q['length'],'risk_passed':r['passed']===!![]},'next_action':t?'Review\x20clean.\x20Proceed:\x20call\x20action=\x27migration_apply\x27\x20with\x20template_id=\x27'+s+'\x27\x20to\x20produce\x20the\x20creation\x20plan\x20(network\x20defaults\x20to\x20testnet;\x20mainnet\x20requires\x20explicit\x20user\x20confirmation).':'Surface\x20the\x20'+p['length']+'\x20unmapped\x20and\x20'+q['length']+'\x20manual_review\x20items'+(r['passed']===!![]?'':'\x20plus\x20the\x20risk_check\x20findings')+'\x20to\x20the\x20user\x20for\x20a\x20decision\x20before\x20action=\x27migration_apply\x27\x20(template_id=\x27'+s+'\x27).'};break;}case'migration_apply':{const u=requireTemplate(b['template_id'],'migration_apply'),v=scanTemplate(u);assertScanPassed(v,'migration_apply');const w=b['network']??'testnet',x=await runGuide(u,b['description'],b['fee_overrides'],b['guard_resolutions']);d={'action':'migration_apply','template_id':u['id'],'network':w,'scan':scanSummary(v),'plan':x,'next_action':planNextAction(x,'migration_apply')};break;}default:throw new Error('Unknown\x20benchmark_migration_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':d})}],'structuredContent':{'result':d}};}
|
|
1
|
+
import{strictParse}from'../../schema/index.js';import{BenchmarkMigrationSchema}from'../../schema/benchmark-migration/index.js';import{getTemplate,listTemplates,validateAllocatorRows,platformShareBps,builtinTemplateDrift}from'../../knowledge/template-loader.js';import{BUILTIN_TEMPLATES,BUILTIN_TEMPLATES_VERSION}from'../../knowledge/builtin-templates.js';import{scanTemplate,buildFeeParamLandingTable}from'../../knowledge/template-scanner.js';import{planMigration}from'../../playbooks/service-build/migration-planner.js';import{handleMerchantGuide}from'../../playbooks/service-build/merchant-guide.js';import{inferArbitration}from'../../playbooks/service-build/intent-analyzer.js';import{getIndustryModeRegistry}from'../../extensions/index.js';import{resolveIndustryName}from'../../knowledge/industry-registry.js';function templateSummary(a){return{'id':a['id'],'industry':a['industry'],'variant':a['variant'],'product_ref':a['product_ref'],'archetype':a['archetype'],'key_risk':a['key_risk'],'node_count':a['machine_shape']['length'],'guard_count':a['guards']['length'],'recommended_role':a['recommended_role']};}function requireTemplate(a,b){if(!a)throw new Error('\x27template_id\x27\x20is\x20required\x20for\x20action=\x27'+b+'\x27');const c=getTemplate(a);if(!c)throw new Error('Unknown\x20template\x20id:\x20'+a+'\x20(use\x20action=\x27template_list\x27\x20to\x20see\x20valid\x20ids)');return c;}function driftFace(a){const b=builtinTemplateDrift()['find'](c=>c['template']===a);if(!b){const c=BUILTIN_TEMPLATES['some'](d=>d['id']===a);return c?{'template':a,'state':'current','catalog_version':BUILTIN_TEMPLATES_VERSION,'blocked':![],'repairable':![],'detail':'disk\x20body\x20matches\x20the\x20shipped\x20catalog\x20(hash-verified\x20sentinel)'}:{'template':a,'state':'untracked','catalog_version':undefined,'blocked':![],'repairable':![],'detail':'user-authored\x20template\x20—\x20no\x20builtin\x20catalog\x20binding\x20to\x20compare\x20against'};}return{'template':b['template'],'state':b['state'],'catalog_version':BUILTIN_TEMPLATES_VERSION,'blocked':!![],'repairable':b['repairable'],'detail':b['detail']};}function scanSummary(a,b){const c={};for(const d of a['findings'])c[d['severity']]=(c[d['severity']]??0x0)+0x1;return{'risk_level':a['risk_level'],'passed':a['passed'],'finding_count':a['findings']['length'],'findings_by_severity':c,'red_flags':a['red_flags'],'findings':a['findings'],'drift':b};}function assertScanPassed(a,b){if(a['passed'])return;throw new Error('action=\x27'+b+'\x27\x20blocked:\x20pre-deploy\x20scan\x20of\x20template\x20\x27'+a['template_id']+'\x27\x20found\x20CRITICAL\x20risk\x20—\x20'+a['red_flags']['join'](';\x20')+'.\x20Fix\x20the\x20template\x20(frontmatter\x20or\x20body)\x20and\x20re-run\x20action=\x27template_scan\x27.');}export function buildVerdict(a,b){const c=[];!a['passed']&&c['push']('scan:\x20'+(a['findings_by_severity']['critical']??0x0)+'\x20CRITICAL\x20finding(s)\x20(scan.passed=false)');const d=b['graph_validation'];if(d&&d['valid']===![]){const f=Array['isArray'](d['hard_violations'])?d['hard_violations']['length']:0x0,g=Array['isArray'](d['hard_violations'])?d['hard_violations']['map'](h=>h['id'])['join'](',\x20'):'';c['push']('graph_validation:\x20'+f+'\x20hard\x20violation(s)'+(g?'\x20('+g+')':''));}const e=b['audit'];return e&&e['blocking']===!![]&&c['push']('audit:\x20guide\x20audit\x20flagged\x20blocking\x20issue(s)\x20(plan.audit)'),{'buildable':c['length']===0x0,'blockers':c};}export function planNextAction(a,b,c){const d=a['next_action'];if(typeof d==='string'&&d['startsWith']('Plan\x20ready.'))return d;if(c?.['buildable']){const f=Array['isArray'](a['pending_guard_designs'])?a['pending_guard_designs']['length']:0x0;return'Plan\x20is\x20buildable\x20(verdict.buildable=true).\x20Materialize\x20the\x20objects\x20in\x20plan.steps\x20order'+(f>0x0?',\x20resolving\x20the\x20'+f+'\x20pending\x20guard\x20design(s)\x20in\x20plan.pending_guard_designs\x20via\x20guard_resolutions\x20before\x20the\x20Machine\x20publish':'')+'.';}const e=Array['isArray'](a['pending_guard_designs'])?a['pending_guard_designs']['length']:0x0;return'Plan\x20BLOCKED\x20by\x20the\x20guide\x20audit\x20(see\x20plan.audit\x20/\x20plan.next_action).\x20Do\x20NOT\x20materialize,\x20'+'and\x20do\x20NOT\x20hand-build\x20the\x20objects\x20instead:\x20this\x20plan\x20is\x20the\x20wiring\x20authority\x20(Arbitration\x20+\x20'+'compensation-fund,\x20Contact/um,\x20allocator\x20rows)\x20and\x20hand-built\x20replicas\x20silently\x20drop\x20those\x20wirings.\x20'+(e>0x0?'Resolve\x20the\x20'+e+'\x20pending\x20guard\x20design(s)\x20in\x20plan.pending_guard_designs\x20via\x20guard_resolutions\x20(kind\x20\x27inline\x27\x20with\x20the\x20Guard\x20table+root,\x20kind\x20\x27template\x27\x20with\x20a\x20tpl_*\x20id,\x20or\x20{kind:\x27omit\x27}\x20for\x20advisory\x20designs\x20that\x20do\x20not\x20apply\x20to\x20this\x20shop),\x20':'Adjust\x20fee_overrides,\x20pick\x20another\x20template\x20variant,\x20or\x20fix\x20the\x20template,\x20')+('then\x20re-run\x20action=\x27'+b+'\x27.');}function templateIntent(a,b){if(b&&b['trim']())return b['trim']();return'Adopt\x20the\x20'+a['id']+'\x20industry\x20archetype\x20template\x20('+a['archetype']+')\x20for\x20the\x20'+a['industry']+'\x20industry.\x20'+('Primary\x20risk\x20to\x20mitigate:\x20'+a['key_risk']+'.');}function effectiveFeeParams(a,b){return{...a['fee_params'],...b??{}};}const REWARD_POOL_PATTERNS=[/(?:reward|review|bonus|tip|prize)[\s-]*pools?\s*(?:of|is|at|:|=)?\s*([0-9][0-9_,]*(?:\.[0-9]+)?)/i,/([0-9][0-9_,]*(?:\.[0-9]+)?)\s*(?:reward|review|bonus|tip|prize)[\s-]*pools?\b/i,/(?:奖(?:金|励)?池|打赏池|好评(?:奖励)?池)\s*(?:为|是|:|:|=)?\s*([0-9][0-9_,]*(?:\.[0-9]+)?)/,/([0-9][0-9_,]*(?:\.[0-9]+)?)\s*的?\s*(?:奖(?:金|励)?池|打赏池|好评(?:奖励)?池)/];export function extractRewardPoolCandidate(a){if(!a)return undefined;for(const b of REWARD_POOL_PATTERNS){const c=b['exec'](a);if(!c)continue;const d=Number(c[0x1]['replaceAll'](/[,_]/g,''));if(Number['isFinite'](d)&&d>=0x0)return d;}return undefined;}function rewardPoolPrefill(a,b,c){if(a['fee_params']['review_reward_pool']===undefined)return undefined;if(c?.['review_reward_pool']!==undefined)return undefined;const d=extractRewardPoolCandidate(b);return d===undefined?undefined:{'fee_key':'review_reward_pool','value':d};}function validateFeeParams(a,b){const c=[];let d=0x0;for(const [e,f]of Object['entries'](a)){if(typeof f!=='number'||!Number['isFinite'](f))continue;if(e['endsWith']('_bps')){(!Number['isInteger'](f)||f<0x0||f>0x2710)&&c['push'](e+'='+f+'\x20is\x20not\x20an\x20integer\x20rate\x20in\x20[0,\x2010000]\x20bps');if(e['endsWith']('_share_bps'))d+=Math['max'](0x0,f);}else{if(e['endsWith']('_days')){if(f<=0x0||f>0xe42)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x203650]\x20days');}else{if(e['endsWith']('_hours')){if(f<=0x0||f>0x2238)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x208760]\x20hours');}}}}if(d>0x2710)c['push']('*_share_bps\x20sum\x20'+d+'\x20exceeds\x2010000\x20(a\x20pool\x20splits\x20into\x20at\x20most\x20100%)');if(c['length']>0x0)throw new Error('invalid\x20fee\x20parameters\x20for\x20template\x20\x27'+b+'\x27:\x20'+c['join'](';\x20')+'.\x20'+'Correct\x20the\x20template\x27s\x20fee_params\x20or\x20pass\x20valid\x20\x27fee_overrides\x27.');}export{validateAllocatorRows};export function variantPaymentModel(a){if(a['payment_model'])return a['payment_model'];const b=a['allocator']['rows']??[];if(b['some'](d=>d['track']==='refund'))return'escrow';const c=a['machine_shape']['map'](d=>d['name'])['join']('\x20')['toLowerCase']();if(/\b(milestone|revision|revis|draft|deliverable)\b/['test'](c))return'milestone';if(/\b(charge|renew|subscription|cycle|billing|monthly)\b/['test'](c))return'subscription';return'escrow';}function variantRefundPolicy(a){const b=a['allocator']['description']['toLowerCase']();if(/full[ -]?refund|100% refund|refund .*100/['test'](b))return'full';if(/pro-?rata|prorated/['test'](b))return'milestone_prorated';if(/partial/['test'](b))return'partial';return undefined;}export function variantDeliverables(a,b){const c=a['machine_shape']['filter'](g=>g['semantic_role']==='final'),d=c[c['length']-0x1]??[...a['machine_shape']]['reverse']()['find'](g=>!/refund|cancel|dispute|terminat/i['test'](g['name']+'\x20'+g['role']))??a['machine_shape'][a['machine_shape']['length']-0x1],e=b?.['has_logistics']?'physical':b?.['pure_digital']?'digital':'service_session',f=(a['guards']??[])['filter'](h=>/repository_data_check|required_info_evidence_gate|allocator_order_anchor/['test'](h['template_id']));return[{'name':a['variant']+'\x20fulfillment','type':e,'acceptanceCriteria':'Order\x20reaches\x20the\x20terminal\x20workflow\x20node\x20\x27'+d['name']+'\x27\x20('+d['role']+')','proofOfDelivery':f['length']>0x0?'wip_hash':'manual_confirm'}];}function validateConditionalParams(a,b){for(const d of a['conditional_guards']??[]){const e=b[d['param']];if(e===undefined)continue;if(typeof e!=='string'||!d['values']['includes'](e))throw new Error('invalid\x20\x27'+d['param']+'='+String(e)+'\x27\x20for\x20template\x20\x27'+a['id']+'\x27:\x20must\x20be\x20one\x20of\x20'+d['values']['map'](f=>'\x27'+f+'\x27')['join']('\x20|\x20')+('\x20(the\x20guard\x20variant\x20mounts\x20at\x20\x27'+d['emit_value']+'\x27)'));}}async function runGuide(a,b,c,d,e){const f=effectiveFeeParams(a,c),g=rewardPoolPrefill(a,b,c);if(g)f[g['fee_key']]=g['value'];validateFeeParams(f,a['id']),validateConditionalParams(a,f);const h=getIndustryModeRegistry()['getMode'](a['industry']),i=platformShareBps(f),j={'model':variantPaymentModel(a)},k=[],l=(a['allocator']['rows']?.['length']??0x0)>0x0;if(i!==undefined&&i>0x0&&!l&&a['allocator']['mode']==='rate'){const p=Math['round'](i)/0x64;k['push']({'recipient':'merchant','percentage':Math['round']((0x64-p)*0x64)/0x64}),k['push']({'recipient':'platform','percentage':p}),j['allocation']=k;}const m=variantRefundPolicy(a),n={'escrow':!![]};if(m)n['refundPolicy']=m;n['arbitration']=a['arbitration_mode']??n['arbitration']??inferArbitration(templateIntent(a,b));const o=await handleMerchantGuide({'intent':templateIntent(a,b),'guide_confirm':{'industry':a['industry'],'payment':j,'trust':n,'deliverables':variantDeliverables(a,h?.['traits']),...d&&Object['keys'](d)['length']>0x0?{'guard_resolutions':d}:{},...e?.['review_mode']?{'review_mode':e['review_mode']}:{},...e?.['reward_funding']!==undefined?{'reward_funding':e['reward_funding']}:{}},'template_override':{...a,'fee_params':f},'name_base':a['id']});if(a['allocator']['rows']?.['length'])o['template_allocator_rows']=a['allocator']['rows']['map'](q=>({...q}));o['template']={'id':a['id'],'archetype':a['archetype'],'recommended_role':a['recommended_role'],'fee_params':f},o['template_fee_param_landings']=buildFeeParamLandingTable(a,f);if(c&&Object['keys'](c)['length']>0x0)o['template_fee_overrides']=c;return g&&(o['fee_overrides_prefill']=g,o['next_action']=o['next_action']+'\x20Reward\x20pool\x20prefilled\x20from\x20your\x20request:\x20'+g['value']+'\x20—\x20adjust\x20via\x20fee_overrides.'),o;}export async function handleBenchmarkMigrationOperation(a){const b=strictParse(BenchmarkMigrationSchema,a,'benchmark_migration_operation\x20input'),c=b['industry']?resolveIndustryName(b['industry'])??b['industry']['toLowerCase']():undefined;let d;switch(b['action']){case'template_list':{const {templates:e,errors:f}=listTemplates(),g=c?e['filter'](i=>i['industry']===c):e,h=new Map(builtinTemplateDrift()['map'](i=>[i['template'],i['state']]));d={'action':'template_list','count':g['length'],'templates':g['map'](i=>({...templateSummary(i),'disk_state':h['get'](i['id'])??(BUILTIN_TEMPLATES['some'](j=>j['id']===i['id'])?'current':'untracked')})),'load_errors':f};break;}case'template_get':{const i=requireTemplate(b['template_id'],'template_get');d={'action':'template_get','template':{...i}};break;}case'template_generate':{const j=requireTemplate(b['template_id'],'template_generate'),k=scanTemplate(j);assertScanPassed(k,'template_generate');const l=await runGuide(j,b['description'],b['fee_overrides'],b['guard_resolutions'],{'review_mode':b['review_mode'],'reward_funding':b['reward_funding']});d=((()=>{const m=scanSummary(k,driftFace(j['id'])),n=buildVerdict(m,l);return{'action':'template_generate','template_id':j['id'],'scan':m,'plan':l,'verdict':n,'next_action':planNextAction(l,'template_generate',n)};})());break;}case'template_scan':{const m=requireTemplate(b['template_id'],'template_scan');d={'action':'template_scan','scan':{...scanTemplate(m),'drift':driftFace(m['id'])}};break;}case'migration_import':{if(!b['description']||!b['description']['trim']())throw new Error('\x27description\x27\x20is\x20required\x20for\x20action=\x27migration_import\x27');const n=planMigration({'url':b['url'],'description':b['description'],'industry':c,'network':b['network']});if(!n)throw new Error('No\x20industry\x20template\x20matched\x20the\x20description.\x20Refine\x20the\x20description\x20or\x20pass\x20an\x20explicit\x20\x27industry\x27\x20hint.');d={'action':'migration_import','log':n,'next_action':'MigrationLog\x20ready.\x20Next:\x20call\x20action=\x27migration_review\x27\x20with\x20this\x20log\x20to\x20surface\x20the\x20mapped/unmapped/manual_review\x20items\x20for\x20user\x20confirmation.'};break;}case'migration_review':{if(!b['log'])throw new Error('\x27log\x27\x20is\x20required\x20for\x20action=\x27migration_review\x27');const o=b['log'],p=Array['isArray'](o['mapped'])?o['mapped']:[],q=Array['isArray'](o['unmapped'])?o['unmapped']:[],r=Array['isArray'](o['manual_review'])?o['manual_review']:[],s=o['risk_check']??{},t=o['source']?.['matched_template']??'',u=q['length']===0x0&&r['length']===0x0&&s['passed']===!![];d={'action':'migration_review','log':o,'review_summary':{'mapped_count':p['length'],'unmapped_count':q['length'],'manual_review_count':r['length'],'risk_passed':s['passed']===!![]},'next_action':u?'Review\x20clean.\x20Proceed:\x20call\x20action=\x27migration_apply\x27\x20with\x20template_id=\x27'+t+'\x27\x20to\x20produce\x20the\x20creation\x20plan\x20(network\x20defaults\x20to\x20testnet;\x20mainnet\x20requires\x20explicit\x20user\x20confirmation).':'Surface\x20the\x20'+q['length']+'\x20unmapped\x20and\x20'+r['length']+'\x20manual_review\x20items'+(s['passed']===!![]?'':'\x20plus\x20the\x20risk_check\x20findings')+'\x20to\x20the\x20user\x20for\x20a\x20decision\x20before\x20action=\x27migration_apply\x27\x20(template_id=\x27'+t+'\x27).'};break;}case'migration_apply':{const v=requireTemplate(b['template_id'],'migration_apply'),w=scanTemplate(v);assertScanPassed(w,'migration_apply');const x=b['network']??'testnet',y=await runGuide(v,b['description'],b['fee_overrides'],b['guard_resolutions'],{'review_mode':b['review_mode'],'reward_funding':b['reward_funding']});d=((()=>{const z=scanSummary(w,driftFace(v['id'])),A=buildVerdict(z,y);return{'action':'migration_apply','template_id':v['id'],'network':x,'scan':z,'plan':y,'verdict':A,'next_action':planNextAction(y,'migration_apply',A)};})());break;}default:throw new Error('Unknown\x20benchmark_migration_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':d})}],'structuredContent':{'result':d}};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{listServices,getServiceInfo,toggle as
|
|
1
|
+
import{listServices,getServiceInfo,toggle as a450a,setEnabled as a450b,reset as a450c}from'../../config/index.js';import{judgmentStatus,setJudgmentOverride,clearJudgmentOverride,clearJudgmentOverrides,patchUserJudgmentDoc,readUserJudgmentDocView}from'../../config/judgment.js';import{strictParse}from'../../schema/index.js';import{ConfigOperationInputSchema}from'../../schema/config/index.js';export async function handleConfigOperation(a){const b=strictParse(ConfigOperationInputSchema,a,'config_operation\x20input'),{action:c,service:d,path:e,value:f}=b;let g;switch(c){case'list':g={'action':'list','services':listServices()};break;case'toggle':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20toggle');const h=d,i=getServiceInfo(h);if(!i)throw new Error('Unknown\x20service:\x20'+h+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(h==='confirm_gate'&&i['enabled'])throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');const j=a450a(h);g={'action':'toggle','service':h,'enabled':j,'reminder':i['reminder']};break;}case'disable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20disable');const k=d,l=getServiceInfo(k);if(!l)throw new Error('Unknown\x20service:\x20'+k+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');if(k==='confirm_gate')throw new Error('confirm_gate\x20cannot\x20be\x20disabled\x20at\x20runtime.\x20'+'Set\x20WOWOK_CONFIRM_GATE=0\x20in\x20the\x20server\x20environment\x20and\x20restart\x20if\x20you\x20really\x20want\x20it\x20off.');a450b(k,![]),g={'action':'disable','service':k,'enabled':![],'reminder':l['reminder']};break;}case'enable':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20enable');const m=d,n=getServiceInfo(m);if(!n)throw new Error('Unknown\x20service:\x20'+m+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a450b(m,!![]),g={'action':'enable','service':m,'enabled':!![],'reminder':n['reminder']};break;}case'reset':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20reset');const o=d,p=getServiceInfo(o);if(!p)throw new Error('Unknown\x20service:\x20'+o+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');a450c(o),g={'action':'reset','service':o,'enabled':getServiceInfo(o)?.['enabled'],'reminder':p['reminder'],'reset':!![]};break;}case'info':{if(!d)throw new Error('\x27service\x27\x20param\x20is\x20required\x20for\x20info');const q=d,r=getServiceInfo(q);if(!r)throw new Error('Unknown\x20service:\x20'+q+'.\x20Use\x20action=\x27list\x27\x20to\x20see\x20all\x20valid\x20services.');g={'action':'info',...r};break;}case'judgment_list':g={'action':'judgment_list',...judgmentStatus()};break;case'judgment_set':{if(!e)throw new Error('\x27path\x27\x20param\x20is\x20required\x20for\x20judgment_set\x20(dotted,\x20e.g.\x20\x27evaluation.weights.trust_reviews\x27)');if(!('value'in b))throw new Error('\x27value\x27\x20param\x20is\x20required\x20for\x20judgment_set');const s=setJudgmentOverride(e,f);if(!s['ok'])throw new Error(s['error']);g={'action':'judgment_set','path':e,'value':f,'applied':!![]};break;}case'judgment_reset':{const t=e?clearJudgmentOverride(e)?0x1:0x0:clearJudgmentOverrides();g={'action':'judgment_reset',...e?{'path':e}:{},'cleared':t};break;}case'judgment_doc_read':{g={'action':'judgment_doc_read',...readUserJudgmentDocView()};break;}case'judgment_doc_patch':{if(!b['patch']||typeof b['patch']!=='object'||Array['isArray'](b['patch']))throw new Error('\x27patch\x27\x20param\x20is\x20required\x20for\x20judgment_doc_patch\x20(a\x20partial\x20judgment\x20document\x20object,\x20e.g.\x20{\x22evaluation\x22:\x20{\x22weights\x22:\x20{…}}})');g={'action':'judgment_doc_patch',...patchUserJudgmentDoc(b['patch'])};break;}default:throw new Error('Unknown\x20config_operation\x20action:\x20'+String(c));}return{'content':[{'type':'text','text':JSON['stringify']({'result':g})}],'structuredContent':{'result':g}};}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { ExpectedResult } from "../../harness/types.js";
|
|
2
2
|
export declare function declareDispatchExpectation(operationType: string, data?: Record<string, unknown>): ExpectedResult | undefined;
|
|
3
|
-
export declare function stableOperationId(operationType: string, data?: unknown): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{referencesExistingObject}from'../../schema/call/semantic.js';export function declareDispatchExpectation(a,b){const c={'result_type':'transaction'};let d=a,e=![];switch(a){case'service':if(b?.['order_new']!==undefined)c['semantic_created']=[{'role':'Order'}],c['semantic_released']=[{'role':'payment'}],c['events']=[{'type':'NewOrderEvent','expect_count':'>=1'}],d='buy\x20service',e=!![];else{if(b?.['publish']===!![]||b?.['bPublished']===!![])c['semantic_modified']=[{'role':'Service','expect_fields':{'bPublished':!![]}}],c['state_transition']={'from':'unpublished','to':'published'},c['events']=[{'type':'ServiceEvent','expect_count':'>=1'}],d='publish\x20service',e=!![];else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Service'}],d='modify\x20service',e=!![]):(c['semantic_created']=[{'role':'Service'}],d='create\x20service',e=!![]);}break;case'machine':referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Machine'}],d='modify\x20machine'):(c['semantic_created']=[{'role':'Machine'}],d='create\x20machine');e=!![];break;case'guard':c['semantic_created']=[{'role':'Guard'}],d='create\x20guard',e=!![];break;case'permission':referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Permission'}],d='modify\x20permission'):(c['semantic_created']=[{'role':'Permission'}],d='create\x20permission');e=!![];break;case'order':if(b?.['progress']!==undefined)c['semantic_modified']=[{'role':'Order'}],c['events']=[{'type':'ProgressEvent','expect_count':'>=1'}],d='advance\x20order';else{if(b?.['arb_confirm']!==undefined)c['state_transition']={'from':'ordered','to':'arbitration'},c['events']=[{'type':'ArbEvent','expect_count':'>=1'}],d='open\x20arbitration';else b?.['arb_objection']!==undefined||b?.['arb_claim_compensation']!==undefined?(c['semantic_modified']=[{'role':'Order'}],d=b?.['arb_objection']!==undefined?'object\x20arbitration\x20result':'claim\x20arbitration\x20compensation'):(c['semantic_modified']=[{'role':'Order'}],d='manage\x20order');}e=!![];break;case'payment':c['semantic_released']=[{'role':'payment'}],c['events']=[{'type':'NewPaymentEvent','expect_count':'>=1'}],d='pay\x20order',e=!![];break;case'treasury':{const f=referencesExistingObject(b);if(b?.['deposit']!==undefined)c['semantic_released']=[{'role':'deposit'}],d=f?'deposit\x20to\x20treasury':'create\x20treasury\x20with\x20deposit';else{if(b?.['withdraw']!==undefined)c['semantic_released']=[{'role':'release'}],d='withdraw\x20from\x20treasury';else f?(c['semantic_modified']=[{'role':'Treasury'}],d='modify\x20treasury'):(c['semantic_created']=[{'role':'Treasury'}],d='create\x20treasury');}c['events']=[{'type':'TreasuryEvent','expect_count':'>=1'},{'type':'NewPaymentEvent','expect_count':'>=1'}],e=!![];break;}case'reward':if(b?.['claim']!==undefined)c['semantic_released']=[{'role':'reward'}],c['events']=[{'type':'RewardClaimEvent','expect_count':'>=1'}],d='claim\x20reward';else{if(b?.['coin_add']!==undefined)c['events']=[{'type':'RewardFundEvent','expect_count':'>=1'}],d='fund\x20reward';else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Reward'}],d='modify\x20reward'):(c['semantic_created']=[{'role':'Reward'}],d='create\x20reward');}e=!![];break;case'allocation':c['semantic_released']=[{'role':'release'}],c['events']=[{'type':'AllocationEvent','expect_count':'>=1'},{'type':'NewPaymentEvent','expect_count':'>=1'}],d='run\x20allocation',e=!![];break;case'demand':if(b?.['present']!==undefined)c['semantic_modified']=[{'role':'Demand'}],c['events']=[{'type':'DemandPresentEvent','expect_count':'>=1'}],d='present\x20demand';else{if(b?.['rewards']!==undefined)c['events']=[{'type':'DemandChangedEvent','expect_count':'>=1'}],d='bind\x20demand\x20reward';else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Demand'}],d='modify\x20demand'):(c['semantic_created']=[{'role':'Demand'}],d='create\x20demand');}e=!![];break;case'progress':c['events']=[{'type':'ProgressEvent','expect_count':'>=1'}],d='progress\x20order',e=!![];break;default:return undefined;}if(!e)return undefined;return{'operation':a,'intent':d,'pre_conditions':[],'expected':c};}
|
|
1
|
+
import{referencesExistingObject}from'../../schema/call/semantic.js';export function declareDispatchExpectation(a,b){const c={'result_type':'transaction'};let d=a,e=![];switch(a){case'service':if(b?.['order_new']!==undefined)c['semantic_created']=[{'role':'Order'}],c['semantic_released']=[{'role':'payment'}],c['events']=[{'type':'NewOrderEvent','expect_count':'>=1'}],d='buy\x20service',e=!![];else{if(b?.['publish']===!![]||b?.['bPublished']===!![])c['semantic_modified']=[{'role':'Service','expect_fields':{'bPublished':!![]}}],c['state_transition']={'from':'unpublished','to':'published'},c['events']=[{'type':'ServiceEvent','expect_count':'>=1'}],d='publish\x20service',e=!![];else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Service'}],d='modify\x20service',e=!![]):(c['semantic_created']=[{'role':'Service'}],d='create\x20service',e=!![]);}break;case'machine':referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Machine'}],d='modify\x20machine'):(c['semantic_created']=[{'role':'Machine'}],d='create\x20machine');e=!![];break;case'guard':c['semantic_created']=[{'role':'Guard'}],d='create\x20guard',e=!![];break;case'permission':referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Permission'}],d='modify\x20permission'):(c['semantic_created']=[{'role':'Permission'}],d='create\x20permission');e=!![];break;case'order':if(b?.['progress']!==undefined)c['semantic_modified']=[{'role':'Order'}],c['events']=[{'type':'ProgressEvent','expect_count':'>=1'}],d='advance\x20order';else{if(b?.['arb_confirm']!==undefined)c['state_transition']={'from':'ordered','to':'arbitration'},c['events']=[{'type':'ArbEvent','expect_count':'>=1'}],d='open\x20arbitration';else b?.['arb_objection']!==undefined||b?.['arb_claim_compensation']!==undefined?(c['semantic_modified']=[{'role':'Order'}],d=b?.['arb_objection']!==undefined?'object\x20arbitration\x20result':'claim\x20arbitration\x20compensation'):(c['semantic_modified']=[{'role':'Order'}],d='manage\x20order');}e=!![];break;case'payment':c['semantic_released']=[{'role':'payment'}],c['events']=[{'type':'NewPaymentEvent','expect_count':'>=1'}],d='pay\x20order',e=!![];break;case'treasury':{const f=referencesExistingObject(b);if(b?.['deposit']!==undefined)c['semantic_released']=[{'role':'deposit'}],d=f?'deposit\x20to\x20treasury':'create\x20treasury\x20with\x20deposit';else{if(b?.['withdraw']!==undefined)c['semantic_released']=[{'role':'release'}],d='withdraw\x20from\x20treasury';else f?(c['semantic_modified']=[{'role':'Treasury'}],d='modify\x20treasury'):(c['semantic_created']=[{'role':'Treasury'}],d='create\x20treasury');}c['events']=[{'type':'TreasuryEvent','expect_count':'>=1'},{'type':'NewPaymentEvent','expect_count':'>=1'}],e=!![];break;}case'reward':if(b?.['claim']!==undefined)c['semantic_released']=[{'role':'reward'}],c['events']=[{'type':'RewardClaimEvent','expect_count':'>=1'}],d='claim\x20reward';else{if(b?.['coin_add']!==undefined)c['events']=[{'type':'RewardFundEvent','expect_count':'>=1'}],d='fund\x20reward';else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Reward'}],d='modify\x20reward'):(c['semantic_created']=[{'role':'Reward'}],d='create\x20reward');}e=!![];break;case'allocation':c['semantic_released']=[{'role':'release'}],c['events']=[{'type':'AllocationEvent','expect_count':'>=1'},{'type':'NewPaymentEvent','expect_count':'>=1'}],d='run\x20allocation',e=!![];break;case'demand':if(b?.['present']!==undefined)c['semantic_modified']=[{'role':'Demand'}],c['events']=[{'type':'DemandPresentEvent','expect_count':'>=1'}],d='present\x20demand';else{if(b?.['rewards']!==undefined)c['events']=[{'type':'DemandChangedEvent','expect_count':'>=1'}],d='bind\x20demand\x20reward';else referencesExistingObject(b)?(c['semantic_modified']=[{'role':'Demand'}],d='modify\x20demand'):(c['semantic_created']=[{'role':'Demand'}],d='create\x20demand');}e=!![];break;case'progress':c['events']=[{'type':'ProgressEvent','expect_count':'>=1'}],d='progress\x20order',e=!![];break;default:return undefined;}if(!e)return undefined;return{'operation':a,'intent':d,'pre_conditions':[],'expected':c};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readdirSync,readFileSync,writeFileSync,existsSync,mkdirSync,statSync,cpSync,renameSync,rmSync}from'node:fs';import{join,relative,resolve,sep,dirname,basename}from'node:path';import{strictParse}from'../../schema/index.js';import{IndustryPackOperationInputSchema}from'../../schema/industry-pack/index.js';import{validateJudgmentFragment}from'../../config/judgment.js';import{scaffoldIndustryPack,listRegisteredPacks,getRegisteredPack,packKind,scanDefaultIndustryPacks,seedBuiltinIndustryTemplates,seedBuiltinStrategyManuals,ensureIndustryReadme,resolveIndustryPackDir,rescanPack,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,diffIndustryPack,resetIndustryPath}from'../../extensions/index.js';import{getIndustryModeRegistry}from'../../extensions/registry.js';import{getBuiltinTemplate,listBuiltinTemplates}from'../../knowledge/builtin-templates.js';import{handleRecommendIndustry,handleListModes,handleDeriveUserMode,handleEvolveUserMode,handleRegisterUserMode,handleUnregisterUserMode,handleRegisterCustomMetric,handleUnregisterCustomMetric,handleRegisterCustomConstraint,handleUnregisterCustomConstraint,handleListMetricsConstraints}from'../../playbooks/service-build/mode-actions.js';import{repairBuiltinTemplates,builtinTemplateDrift,resolveTemplatesDir,parseTemplateFile,TemplateFrontmatterSchema}from'../../knowledge/template-loader.js';const INDUSTRY_ROOT=resolveIndustryPackDir(),resolveTemplatesDirSafe=resolveTemplatesDir;function resolveIndustryPath(a){const b=resolve(INDUSTRY_ROOT,a);if(b!==INDUSTRY_ROOT&&!b['startsWith'](INDUSTRY_ROOT+sep))throw new Error('path\x20\x27'+a+'\x27\x20escapes\x20the\x20industry\x20root');return b;}function isTemplateTreePath(a){const b=a['split'](/[\\/]+/)['filter'](c=>c['length']>0x0);return b['length']>=0x2&&b[0x1]==='templates';}function assertTemplateWriteAuthorized(a,b,c){if(c===!![])return;const d=b['find'](e=>e!==undefined&&isTemplateTreePath(e));if(!d)return;throw new Error('action=\x27'+a+'\x27\x20modifies\x20the\x20user-editable\x20template\x20file\x20\x27'+d+'\x27.\x20'+'Present\x20the\x20intended\x20change\x20to\x20the\x20user\x20first;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20'+'re-call\x20with\x20authorize=true\x20(C5).');}function rescanAffectedPack(a){const b=a['split'](/[\\/]+/)['find'](c=>c['length']>0x0);if(!b)return;rescanPack(b);}const BASELINES_FILENAME='baselines.json',PACK_FILENAME='pack.json';function assertBaselinesContentValid(a,b){const c=a['split'](/[\\/]+/)['pop']()??'';if(c!==BASELINES_FILENAME&&c!==PACK_FILENAME)return;let d;try{d=JSON['parse'](b);}catch{return;}if(!d||typeof d!=='object'||Array['isArray'](d))return;const e=d,f=c===BASELINES_FILENAME?d:e['baselines'];if(f===undefined||f===null)return;const g=validateJudgmentFragment(f,a+'\x20baselines');if(g)throw new Error('write\x20rejected\x20—\x20the\x20baselines\x20fragment\x20in\x20\x27'+a+'\x27\x20is\x20not\x20a\x20valid\x20judgment\x20fragment:\x20'+g);}function assertTemplateContentValid(a,b){if(!isTemplateTreePath(a)||!a['endsWith']('.md'))return;let c;try{({frontmatter:c}=parseTemplateFile(b));}catch(e){throw new Error('write\x20rejected\x20—\x20\x27'+a+'\x27\x20is\x20a\x20template\x20file\x20but\x20the\x20frontmatter\x20block\x20is\x20malformed:\x20'+e['message']);}const d=TemplateFrontmatterSchema['safeParse'](c);if(!d['success']){const f=d['error']['issues']['map'](g=>'\x20\x20'+g['path']['join']('.')+':\x20'+g['message'])['join']('\x0a');throw new Error('write\x20rejected\x20—\x20the\x20template\x20frontmatter\x20in\x20\x27'+a+'\x27\x20violates\x20the\x20schema\x20(the\x20editor\x20whitelist\x20IS\x20the\x20zod\x20schema):\x0a'+f);}}function listRecursive(a,b,c,d=0x0){if(d>0x8)return;let f;try{f=readdirSync(a,{'withFileTypes':!![]});}catch{return;}for(const g of f){const h=join(a,g['name']),i=relative(b,h)['split'](sep)['join']('/');let j=0x0,k=0x0;try{const l=statSync(h);k=l['size'],j=l['mtimeMs'];}catch{}g['isDirectory']()?(c['push']({'path':i,'is_dir':!![],'size':0x0,'mtime':j}),listRecursive(h,b,c,d+0x1)):c['push']({'path':i,'is_dir':![],'size':k,'mtime':j});}}export async function handleIndustryPackOperation(a){const b=strictParse(IndustryPackOperationInputSchema,a,'industry_pack_operation\x20input');mkdirSync(INDUSTRY_ROOT,{'recursive':!![]}),seedBuiltinIndustryTemplates(),seedBuiltinStrategyManuals(),ensureIndustryReadme();let c;switch(b['action']){case'scaffold':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27scaffold\x27');const d=scaffoldIndustryPack(b['name']);c={'action':'scaffold','ok':d['ok'],'dir':d['dir'],'files':d['files'],'errors':d['errors']};if(d['ok'])rescanPack(b['name']);break;}case'list':{c={'action':'list','packs':listRegisteredPacks()};break;}case'scan':{c={'action':'scan','results':scanDefaultIndustryPacks()};break;}case'repair_builtin_templates':{if(b['authorize']!==!![]){const g=repairBuiltinTemplates({'backup':!![],'dryRun':!![]}),h=g['filter'](i=>i['status']==='would_update');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':0x0,'requires_authorization':!![],'results':g,'note':h['length']?'PLAN\x20ONLY\x20(no\x20writes)\x20—\x20'+h['length']+'\x20builtin\x20file(s)\x20differ\x20from\x20the\x20in-code\x20catalog\x20and\x20would\x20be\x20reseeded\x20(each\x20result\x20carries\x20a\x20field-level\x20diff;\x20previous\x20bodies\x20preserved\x20as\x20<file>.bak).\x20Present\x20this\x20plan\x20to\x20the\x20user;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20re-call\x20with\x20authorize=true\x20to\x20execute.':'Nothing\x20to\x20repair\x20—\x20every\x20on-disk\x20builtin\x20template\x20either\x20matches\x20the\x20in-code\x20catalog\x20or\x20carries\x20user\x20edits\x20(which\x20are\x20never\x20overwritten).'};break;}const e=repairBuiltinTemplates({'backup':!![]}),f=e['filter'](i=>i['status']==='updated');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':f['length'],'results':e,'note':f['length']?'Diverging\x20builtin\x20files\x20were\x20reseeded\x20from\x20the\x20in-code\x20catalog.\x20Each\x20previous\x20body\x20is\x20preserved\x20as\x20<file>.bak.':'Nothing\x20repaired\x20—\x20every\x20on-disk\x20builtin\x20template\x20either\x20matches\x20the\x20in-code\x20catalog\x20or\x20carries\x20user\x20edits\x20(which\x20are\x20never\x20overwritten).'};break;}case'template_drift':{const i=builtinTemplateDrift(),j=i['filter'](k=>k['repairable'])['length'];c={'action':'template_drift','dir':resolveTemplatesDirSafe(),'drift_count':i['length'],'repairable_count':j,'drift':i,'note':i['length']?j>0x0?j+'\x20of\x20'+i['length']+'\x20diverging\x20builtin\x20template(s)\x20can\x20be\x20reseeded\x20without\x20losing\x20user\x20work\x20—\x20run\x20action=\x27repair_builtin_templates\x27\x20(plan-only\x20preview\x20first,\x20then\x20authorize=true\x20after\x20the\x20user\x20confirms).\x20The\x20rest\x20carry\x20user\x20edits\x20and\x20are\x20never\x20overwritten.':'All\x20diverging\x20builtin\x20templates\x20carry\x20user\x20edits\x20—\x20never\x20overwritten\x20automatically;\x20resolve\x20by\x20hand\x20or\x20via\x20an\x20authorized\x20write.':'Every\x20builtin\x20template\x20on\x20disk\x20matches\x20the\x20in-code\x20catalog.'};break;}case'resolve':{c={'action':'resolve','dir':INDUSTRY_ROOT};break;}case'list_files':{const k=[];listRecursive(INDUSTRY_ROOT,INDUSTRY_ROOT,k),c={'action':'list_files','dir':INDUSTRY_ROOT,'files':k};break;}case'read_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27read_file\x27');const l=resolveIndustryPath(b['path']);if(!existsSync(l))throw new Error('file\x20not\x20found:\x20'+b['path']);c={'action':'read_file','path':l,'content':readFileSync(l,'utf-8')};break;}case'write_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');if(b['content']===undefined)throw new Error('\x27content\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');assertTemplateWriteAuthorized('write_file',[b['path']],b['authorize']);const m=resolveIndustryPath(b['path']);assertBaselinesContentValid(b['path'],b['content']),assertTemplateContentValid(b['path'],b['content']),mkdirSync(dirname(m),{'recursive':!![]}),writeFileSync(m,b['content'],'utf-8'),c={'action':'write_file','path':m,'ok':!![]},rescanAffectedPack(b['path']);break;}case'get':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27get\x27');const n=b['name'],o=getRegisteredPack(n),p=o?.['layers']??[],q=()=>o?{'kind':packKind(p),'layers':p}:{},u=()=>{const x=getIndustryModeRegistry()['getMode'](n);return x?{'name':x['name'],'display_name':x['display_name'],'key_risk':x['key_risk'],'needs':x['needs']['map'](y=>y['description']),...x['analyze']?.['key_questions']?.['length']?{'analyze_questions':x['analyze']['key_questions']['slice'](0x0,0x2)}:{}}:undefined;};if(b['layer']==='template'){if(b['template']){const x=getBuiltinTemplate(b['template']);if(!x)throw new Error('template\x20\x27'+b['template']+'\x27\x20is\x20not\x20in\x20the\x20builtin\x20catalog\x20'+('(available:\x20'+listBuiltinTemplates()['map'](y=>y['id'])['join'](',\x20')+')'));if(x['industry']!==n)throw new Error('template\x20\x27'+x['id']+'\x27\x20belongs\x20to\x20industry\x20\x27'+x['industry']+'\x27,\x20not\x20\x27'+n+'\x27\x20—\x20'+'set\x20\x27name\x27\x20to\x20the\x20template\x27s\x20industry');c={'action':'get','category':n,'layer':'template','template':JSON['parse'](JSON['stringify'](x))};}else{const y=listBuiltinTemplates()['filter'](z=>z['industry']===n)['map'](z=>({'id':z['id'],'variant':z['variant'],'product_ref':z['product_ref'],'key_risk':z['key_risk']}));if(!y['length'])throw new Error('industry\x20\x27'+n+'\x27\x20has\x20no\x20builtin\x20templates\x20(ids\x20use\x20\x27<industry>/<variant>\x27)');c={'action':'get','category':n,'layer':'template','templates':y,'note':'Re-call\x20with\x20layer=\x27template\x27\x20+\x20template=\x27<id>\x27\x20for\x20the\x20full\x20projection\x20'+'(machine_shape/guards/allocator\x20rows/fee_params/build_notes).'};}break;}if(b['layer']){const z=b['layer'];if(z==='match')throw new Error('layer\x20\x27match\x27\x20is\x20consumed\x20internally\x20by\x20the\x20recommend\x20matching\x20flow\x20—\x20not\x20exposed\x20via\x20get');if(!p['includes'](z))throw new Error('pack\x20\x27'+n+'\x27\x20does\x20not\x20register\x20layer\x20\x27'+z+'\x27'+(o?'\x20(kind='+packKind(p)+',\x20layers=['+p['join'](',\x20')+'])':'\x20(the\x20pack\x20is\x20not\x20registered)')+(z!=='mode'?';\x20layer=\x27template\x27\x20reads\x20the\x20builtin\x20catalog\x20instead\x20if\x20that\x20is\x20what\x20you\x20need':''));const A=z==='mode'?u():z==='dispute'?resolveDisputeRules(n):z==='compliance'?resolveComplianceRules(n):z==='supply'?resolveSupplyRules(n):z==='rules'?resolveIndustryRules(n):resolveIndustryPlaybook(n);if(A===undefined)throw new Error('layer\x20\x27'+z+'\x27\x20is\x20registered\x20for\x20pack\x20\x27'+n+'\x27\x20but\x20resolved\x20to\x20no\x20data');c={'action':'get','category':n,'layer':z,[z]:A,...q()};break;}const v=u(),w=['dispute','compliance','supply','rules','playbook']['filter'](B=>!p['includes'](B));c={'action':'get','category':n,...q(),...v?{'mode':v}:{},...resolveDisputeRules(n)?{'dispute':resolveDisputeRules(n)}:{},...resolveComplianceRules(n)?{'compliance':resolveComplianceRules(n)}:{},...resolveSupplyRules(n)?{'supply':resolveSupplyRules(n)}:{},...resolveIndustryRules(n)?{'rules':resolveIndustryRules(n)}:{},...resolveIndustryPlaybook(n)?{'playbook':resolveIndustryPlaybook(n)}:{},...w['length']?{'missing_layers':w,'note':'pack\x20\x27'+n+'\x27\x20('+(o?packKind(p):'unregistered')+')\x20does\x20not\x20register\x20'+('['+w['join'](',\x20')+']\x20—\x20stub\x20packs\x20(builtin-mode\x20aliases)\x20carry\x20only\x20mode/match\x20')+'data;\x20scaffold\x20a\x20pack\x20or\x20place\x20a\x20pack.json\x20to\x20add\x20business\x20layers.'}:{}};break;}case'diff':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27diff\x27');c={'action':'diff',...diffIndustryPack(b['name'])};break;}case'reset':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27reset\x27');assertTemplateWriteAuthorized('reset',[b['path']],b['authorize']);const B=resetIndustryPath(b['path']);c={'action':'reset','ok':B['ok'],'layout':B['layout'],'target':B['target'],'restored_files':B['restored_files'],'errors':B['errors']},rescanAffectedPack(b['path']);break;}case'delete_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27delete_file\x27');assertTemplateWriteAuthorized('delete_file',[b['path']],b['authorize']);const C=resolveIndustryPath(b['path']);if(!existsSync(C))throw new Error('file\x20not\x20found:\x20'+b['path']);rmSync(C,{'recursive':!![],'force':!![]}),c={'action':'delete_file','path':C,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_file\x27');const D=resolveIndustryPath(b['path']);if(existsSync(D))throw new Error('file\x20already\x20exists:\x20'+b['path']);if(b['content']!==undefined)assertBaselinesContentValid(b['path'],b['content']);mkdirSync(dirname(D),{'recursive':!![]}),writeFileSync(D,b['content']??'','utf-8'),c={'action':'create_file','path':D,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_dir':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_dir\x27');const E=resolveIndustryPath(b['path']);mkdirSync(E,{'recursive':!![]}),c={'action':'create_dir','path':E,'ok':!![]},rescanAffectedPack(b['path']);break;}case'copy':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27copy\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27copy\x27');const F=resolveIndustryPath(b['from']);let G=resolveIndustryPath(b['to']);if(!existsSync(F))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(G)&&statSync(G)['isDirectory']()&&(G=join(G,basename(F)));}catch{}if(G===F)throw new Error('\x27copy\x27\x20cannot\x20copy\x20a\x20file\x20onto\x20itself');existsSync(G)&&isTemplateTreePath(b['to'])&&assertTemplateWriteAuthorized('copy',[b['to']],b['authorize']);mkdirSync(dirname(G),{'recursive':!![]}),cpSync(F,G,{'recursive':!![],'force':!![]}),c={'action':'copy','from':F,'to':G,'ok':!![]},rescanAffectedPack(b['to']);break;}case'move':case'rename':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');assertTemplateWriteAuthorized(b['action'],[b['from'],b['to']],b['authorize']);const H=resolveIndustryPath(b['from']);let I=resolveIndustryPath(b['to']);if(!existsSync(H))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(I)&&statSync(I)['isDirectory']()&&(I=join(I,basename(H)));}catch{}if(I===H)throw new Error('\x27'+b['action']+'\x27\x20cannot\x20move\x20onto\x20itself');mkdirSync(dirname(I),{'recursive':!![]}),renameSync(H,I),c={'action':b['action'],'from':H,'to':I,'ok':!![]},rescanAffectedPack(b['from']),rescanAffectedPack(b['to']);break;}case'recommend_industry':c=await handleRecommendIndustry(b);break;case'list_modes':c=await handleListModes();break;case'derive_user_mode':c=await handleDeriveUserMode(b);break;case'evolve_user_mode':c=await handleEvolveUserMode(b);break;case'register_user_mode':c=await handleRegisterUserMode(b);break;case'unregister_user_mode':c=await handleUnregisterUserMode(b);break;case'register_custom_metric':c=await handleRegisterCustomMetric(b);break;case'unregister_custom_metric':c=await handleUnregisterCustomMetric(b);break;case'register_custom_constraint':c=await handleRegisterCustomConstraint(b);break;case'unregister_custom_constraint':c=await handleUnregisterCustomConstraint(b);break;case'list_metrics_constraints':c=await handleListMetricsConstraints(b);break;default:throw new Error('Unknown\x20industry_pack_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':c})}],'structuredContent':{'result':c}};}
|
|
1
|
+
import{readdirSync,readFileSync,writeFileSync,existsSync,mkdirSync,statSync,cpSync,renameSync,rmSync}from'node:fs';import{join,relative,resolve,sep,dirname,basename}from'node:path';import{strictParse}from'../../schema/index.js';import{IndustryPackOperationInputSchema}from'../../schema/industry-pack/index.js';import{validateJudgmentFragment}from'../../config/judgment.js';import{scaffoldIndustryPack,listRegisteredPacks,getRegisteredPack,packKind,scanDefaultIndustryPacks,seedBuiltinIndustryTemplates,seedBuiltinStrategyManuals,ensureIndustryReadme,resolveIndustryPackDir,rescanPack,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,diffIndustryPack,resetIndustryPath}from'../../extensions/index.js';import{getIndustryModeRegistry}from'../../extensions/registry.js';import{getBuiltinTemplate,listBuiltinTemplates}from'../../knowledge/builtin-templates.js';import{handleRecommendIndustry,handleListModes,handleDeriveUserMode,handleEvolveUserMode,handleRegisterUserMode,handleUnregisterUserMode,handleRegisterCustomMetric,handleUnregisterCustomMetric,handleRegisterCustomConstraint,handleUnregisterCustomConstraint,handleListMetricsConstraints}from'../../playbooks/service-build/mode-actions.js';import{repairBuiltinTemplates,builtinTemplateDrift,resolveTemplatesDir,parseTemplateFile,TemplateFrontmatterSchema,canonicalTemplateContent,renderTemplateFile,matchBuiltinTemplateFile,TEMPLATE_SENTINEL_KIND}from'../../knowledge/template-loader.js';import{stripReleaseSentinel}from'../../knowledge/release-sentinel.js';import{BUILTIN_TEMPLATES_VERSION}from'../../knowledge/builtin-templates.js';const INDUSTRY_ROOT=resolveIndustryPackDir(),resolveTemplatesDirSafe=resolveTemplatesDir;function resolveIndustryPath(a){const b=resolve(INDUSTRY_ROOT,a);if(b!==INDUSTRY_ROOT&&!b['startsWith'](INDUSTRY_ROOT+sep))throw new Error('path\x20\x27'+a+'\x27\x20escapes\x20the\x20industry\x20root');return b;}function isTemplateTreePath(a){const b=a['split'](/[\\/]+/)['filter'](c=>c['length']>0x0);return b['length']>=0x2&&b[0x1]==='templates';}function assertTemplateWriteAuthorized(a,b,c){if(c===!![])return;const d=b['find'](e=>e!==undefined&&isTemplateTreePath(e));if(!d)return;throw new Error('action=\x27'+a+'\x27\x20modifies\x20the\x20user-editable\x20template\x20file\x20\x27'+d+'\x27.\x20'+'Present\x20the\x20intended\x20change\x20to\x20the\x20user\x20first;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20'+'re-call\x20with\x20authorize=true\x20(C5).');}function rescanAffectedPack(a){const b=a['split'](/[\\/]+/)['find'](c=>c['length']>0x0);if(!b)return;rescanPack(b);}const BASELINES_FILENAME='baselines.json',PACK_FILENAME='pack.json';function assertBaselinesContentValid(a,b){const c=a['split'](/[\\/]+/)['pop']()??'';if(c!==BASELINES_FILENAME&&c!==PACK_FILENAME)return;let d;try{d=JSON['parse'](b);}catch{return;}if(!d||typeof d!=='object'||Array['isArray'](d))return;const e=d,f=c===BASELINES_FILENAME?d:e['baselines'];if(f===undefined||f===null)return;const g=validateJudgmentFragment(f,a+'\x20baselines');if(g)throw new Error('write\x20rejected\x20—\x20the\x20baselines\x20fragment\x20in\x20\x27'+a+'\x27\x20is\x20not\x20a\x20valid\x20judgment\x20fragment:\x20'+g);}function assertTemplateContentValid(a,b){if(!isTemplateTreePath(a)||!a['endsWith']('.md'))return;let c;try{({frontmatter:c}=parseTemplateFile(b));}catch(e){throw new Error('write\x20rejected\x20—\x20\x27'+a+'\x27\x20is\x20a\x20template\x20file\x20but\x20the\x20frontmatter\x20block\x20is\x20malformed:\x20'+e['message']);}const d=TemplateFrontmatterSchema['safeParse'](c);if(!d['success']){const f=d['error']['issues']['map'](g=>'\x20\x20'+g['path']['join']('.')+':\x20'+g['message'])['join']('\x0a');throw new Error('write\x20rejected\x20—\x20the\x20template\x20frontmatter\x20in\x20\x27'+a+'\x27\x20violates\x20the\x20schema\x20(the\x20editor\x20whitelist\x20IS\x20the\x20zod\x20schema):\x0a'+f);}}function listRecursive(a,b,c,d=0x0){if(d>0x8)return;let f;try{f=readdirSync(a,{'withFileTypes':!![]});}catch{return;}for(const g of f){const h=join(a,g['name']),i=relative(b,h)['split'](sep)['join']('/');let j=0x0,k=0x0;try{const l=statSync(h);k=l['size'],j=l['mtimeMs'];}catch{}g['isDirectory']()?(c['push']({'path':i,'is_dir':!![],'size':0x0,'mtime':j}),listRecursive(h,b,c,d+0x1)):c['push']({'path':i,'is_dir':![],'size':k,'mtime':j});}}export async function handleIndustryPackOperation(a){const b=strictParse(IndustryPackOperationInputSchema,a,'industry_pack_operation\x20input');mkdirSync(INDUSTRY_ROOT,{'recursive':!![]}),seedBuiltinIndustryTemplates(),seedBuiltinStrategyManuals(),ensureIndustryReadme();let c;switch(b['action']){case'scaffold':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27scaffold\x27');const d=scaffoldIndustryPack(b['name']);c={'action':'scaffold','ok':d['ok'],'dir':d['dir'],'files':d['files'],'errors':d['errors']};if(d['ok'])rescanPack(b['name']);break;}case'list':{c={'action':'list','packs':listRegisteredPacks()};break;}case'scan':{c={'action':'scan','results':scanDefaultIndustryPacks()};break;}case'repair_builtin_templates':{const e=b['include_user_edited'];if(b['authorize']!==!![]){const h=repairBuiltinTemplates({'backup':!![],'dryRun':!![],'includeUserEdited':e}),i=h['filter'](j=>j['status']==='would_update');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':0x0,'requires_authorization':!![],'results':h,'note':i['length']?'PLAN\x20ONLY\x20(no\x20writes)\x20—\x20'+i['length']+'\x20builtin\x20file(s)\x20differ\x20from\x20the\x20in-code\x20catalog\x20and\x20would\x20be\x20reseeded\x20(each\x20result\x20carries\x20a\x20field-level\x20diff;\x20previous\x20bodies\x20preserved\x20as\x20<file>.bak).\x20Present\x20this\x20plan\x20to\x20the\x20user;\x20after\x20the\x20user\x20explicitly\x20confirms,\x20re-call\x20with\x20authorize=true\x20to\x20execute'+(e?.['length']?'\x20(keep\x20include_user_edited\x20on\x20the\x20execute\x20call)':'')+'.':'Nothing\x20to\x20repair\x20—\x20every\x20on-disk\x20builtin\x20template\x20either\x20matches\x20the\x20in-code\x20catalog\x20or\x20carries\x20user\x20edits\x20(which\x20are\x20never\x20overwritten\x20without\x20an\x20explicit\x20include_user_edited\x20authorization).'};break;}const f=repairBuiltinTemplates({'backup':!![],'includeUserEdited':e}),g=f['filter'](j=>j['status']==='updated');c={'action':'repair_builtin_templates','dir':resolveTemplatesDirSafe(),'reseeded_count':g['length'],'results':f,'note':g['length']?'Diverging\x20builtin\x20files\x20were\x20reseeded\x20from\x20the\x20in-code\x20catalog.\x20Each\x20previous\x20body\x20is\x20preserved\x20as\x20<file>.bak.':'Nothing\x20repaired\x20—\x20every\x20on-disk\x20builtin\x20template\x20either\x20matches\x20the\x20in-code\x20catalog\x20or\x20carries\x20user\x20edits\x20(which\x20are\x20never\x20overwritten\x20without\x20an\x20explicit\x20include_user_edited\x20authorization).'};break;}case'template_drift':{const j=builtinTemplateDrift({'includeUserEdited':b['include_user_edited']}),k=j['filter'](l=>l['repairable'])['length'];c={'action':'template_drift','dir':resolveTemplatesDirSafe(),'drift_count':j['length'],'repairable_count':k,'drift':j,'note':j['length']?k>0x0?k+'\x20of\x20'+j['length']+'\x20diverging\x20builtin\x20template(s)\x20can\x20be\x20reseeded\x20without\x20losing\x20user\x20work\x20(including\x20ids\x20listed\x20in\x20include_user_edited)\x20—\x20run\x20action=\x27repair_builtin_templates\x27\x20(plan-only\x20preview\x20first,\x20then\x20authorize=true\x20after\x20the\x20user\x20confirms,\x20keeping\x20include_user_edited\x20on\x20both\x20calls).\x20The\x20rest\x20carry\x20user\x20edits\x20and\x20are\x20never\x20overwritten.':'All\x20diverging\x20builtin\x20templates\x20carry\x20user\x20edits\x20—\x20never\x20overwritten\x20automatically;\x20pass\x20include_user_edited\x20with\x20the\x20explicitly\x20authorized\x20ids\x20to\x20make\x20them\x20reseedable,\x20or\x20resolve\x20by\x20hand.':'Every\x20builtin\x20template\x20on\x20disk\x20matches\x20the\x20in-code\x20catalog.'};break;}case'resolve':{c={'action':'resolve','dir':INDUSTRY_ROOT};break;}case'list_files':{const l=[];listRecursive(INDUSTRY_ROOT,INDUSTRY_ROOT,l),c={'action':'list_files','dir':INDUSTRY_ROOT,'files':l};break;}case'read_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27read_file\x27');const m=resolveIndustryPath(b['path']);if(!existsSync(m))throw new Error('file\x20not\x20found:\x20'+b['path']);c={'action':'read_file','path':m,'content':readFileSync(m,'utf-8')};break;}case'write_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');if(b['content']===undefined)throw new Error('\x27content\x27\x20is\x20required\x20for\x20action=\x27write_file\x27');assertTemplateWriteAuthorized('write_file',[b['path']],b['authorize']);const n=resolveIndustryPath(b['path']);assertBaselinesContentValid(b['path'],b['content']),assertTemplateContentValid(b['path'],b['content']);let o=b['content'],p=![];const q=matchBuiltinTemplateFile(n);if(q){const u=stripReleaseSentinel(o,TEMPLATE_SENTINEL_KIND)['content'];u===canonicalTemplateContent(q)&&(o=renderTemplateFile(q),p=!![]);}mkdirSync(dirname(n),{'recursive':!![]}),writeFileSync(n,o,'utf-8'),c={'action':'write_file','path':n,'ok':!![],...p?{'restamped':!![],'note':'content\x20equals\x20the\x20canonical\x20body\x20of\x20builtin\x20template\x20\x27'+q['id']+'\x27\x20—\x20written\x20with\x20the\x20current\x20release\x20stamp\x20(v'+BUILTIN_TEMPLATES_VERSION+')\x20so\x20the\x20sentinel\x20hash\x20binds\x20again'}:{}},rescanAffectedPack(b['path']);break;}case'get':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27get\x27');const v=b['name'],w=getRegisteredPack(v),x=w?.['layers']??[],y=()=>w?{'kind':packKind(x),'layers':x}:{},z=()=>{const C=getIndustryModeRegistry()['getMode'](v);return C?{'name':C['name'],'display_name':C['display_name'],'key_risk':C['key_risk'],'needs':C['needs']['map'](D=>D['description']),...C['analyze']?.['key_questions']?.['length']?{'analyze_questions':C['analyze']['key_questions']['slice'](0x0,0x2)}:{}}:undefined;};if(b['layer']==='template'){if(b['template']){const C=getBuiltinTemplate(b['template']);if(!C)throw new Error('template\x20\x27'+b['template']+'\x27\x20is\x20not\x20in\x20the\x20builtin\x20catalog\x20'+('(available:\x20'+listBuiltinTemplates()['map'](D=>D['id'])['join'](',\x20')+')'));if(C['industry']!==v)throw new Error('template\x20\x27'+C['id']+'\x27\x20belongs\x20to\x20industry\x20\x27'+C['industry']+'\x27,\x20not\x20\x27'+v+'\x27\x20—\x20'+'set\x20\x27name\x27\x20to\x20the\x20template\x27s\x20industry');c={'action':'get','category':v,'layer':'template','template':JSON['parse'](JSON['stringify'](C))};}else{const D=listBuiltinTemplates()['filter'](E=>E['industry']===v)['map'](E=>({'id':E['id'],'variant':E['variant'],'product_ref':E['product_ref'],'key_risk':E['key_risk']}));if(!D['length'])throw new Error('industry\x20\x27'+v+'\x27\x20has\x20no\x20builtin\x20templates\x20(ids\x20use\x20\x27<industry>/<variant>\x27)');c={'action':'get','category':v,'layer':'template','templates':D,'note':'Re-call\x20with\x20layer=\x27template\x27\x20+\x20template=\x27<id>\x27\x20for\x20the\x20full\x20projection\x20'+'(machine_shape/guards/allocator\x20rows/fee_params/build_notes).'};}break;}if(b['layer']){const E=b['layer'];if(E==='match')throw new Error('layer\x20\x27match\x27\x20is\x20consumed\x20internally\x20by\x20the\x20recommend\x20matching\x20flow\x20—\x20not\x20exposed\x20via\x20get');if(!x['includes'](E))throw new Error('pack\x20\x27'+v+'\x27\x20does\x20not\x20register\x20layer\x20\x27'+E+'\x27'+(w?'\x20(kind='+packKind(x)+',\x20layers=['+x['join'](',\x20')+'])':'\x20(the\x20pack\x20is\x20not\x20registered)')+(E!=='mode'?';\x20layer=\x27template\x27\x20reads\x20the\x20builtin\x20catalog\x20instead\x20if\x20that\x20is\x20what\x20you\x20need':''));const F=E==='mode'?z():E==='dispute'?resolveDisputeRules(v):E==='compliance'?resolveComplianceRules(v):E==='supply'?resolveSupplyRules(v):E==='rules'?resolveIndustryRules(v):resolveIndustryPlaybook(v);if(F===undefined)throw new Error('layer\x20\x27'+E+'\x27\x20is\x20registered\x20for\x20pack\x20\x27'+v+'\x27\x20but\x20resolved\x20to\x20no\x20data');c={'action':'get','category':v,'layer':E,[E]:F,...y()};break;}const A=z(),B=['dispute','compliance','supply','rules','playbook']['filter'](G=>!x['includes'](G));c={'action':'get','category':v,...y(),...A?{'mode':A}:{},...resolveDisputeRules(v)?{'dispute':resolveDisputeRules(v)}:{},...resolveComplianceRules(v)?{'compliance':resolveComplianceRules(v)}:{},...resolveSupplyRules(v)?{'supply':resolveSupplyRules(v)}:{},...resolveIndustryRules(v)?{'rules':resolveIndustryRules(v)}:{},...resolveIndustryPlaybook(v)?{'playbook':resolveIndustryPlaybook(v)}:{},...B['length']?{'missing_layers':B,'note':'pack\x20\x27'+v+'\x27\x20('+(w?packKind(x):'unregistered')+')\x20does\x20not\x20register\x20'+('['+B['join'](',\x20')+']\x20—\x20stub\x20packs\x20(builtin-mode\x20aliases)\x20carry\x20only\x20mode/match\x20')+'data;\x20scaffold\x20a\x20pack\x20or\x20place\x20a\x20pack.json\x20to\x20add\x20business\x20layers.'}:{}};break;}case'diff':{if(!b['name'])throw new Error('\x27name\x27\x20is\x20required\x20for\x20action=\x27diff\x27');c={'action':'diff',...diffIndustryPack(b['name'])};break;}case'reset':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27reset\x27');assertTemplateWriteAuthorized('reset',[b['path']],b['authorize']);const G=resetIndustryPath(b['path']);c={'action':'reset','ok':G['ok'],'layout':G['layout'],'target':G['target'],'restored_files':G['restored_files'],'errors':G['errors']},rescanAffectedPack(b['path']);break;}case'delete_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27delete_file\x27');assertTemplateWriteAuthorized('delete_file',[b['path']],b['authorize']);const H=resolveIndustryPath(b['path']);if(!existsSync(H))throw new Error('file\x20not\x20found:\x20'+b['path']);rmSync(H,{'recursive':!![],'force':!![]}),c={'action':'delete_file','path':H,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_file':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_file\x27');const I=resolveIndustryPath(b['path']);if(existsSync(I))throw new Error('file\x20already\x20exists:\x20'+b['path']);if(b['content']!==undefined)assertBaselinesContentValid(b['path'],b['content']);mkdirSync(dirname(I),{'recursive':!![]}),writeFileSync(I,b['content']??'','utf-8'),c={'action':'create_file','path':I,'ok':!![]},rescanAffectedPack(b['path']);break;}case'create_dir':{if(!b['path'])throw new Error('\x27path\x27\x20is\x20required\x20for\x20action=\x27create_dir\x27');const J=resolveIndustryPath(b['path']);mkdirSync(J,{'recursive':!![]}),c={'action':'create_dir','path':J,'ok':!![]},rescanAffectedPack(b['path']);break;}case'copy':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27copy\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27copy\x27');const K=resolveIndustryPath(b['from']);let L=resolveIndustryPath(b['to']);if(!existsSync(K))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(L)&&statSync(L)['isDirectory']()&&(L=join(L,basename(K)));}catch{}if(L===K)throw new Error('\x27copy\x27\x20cannot\x20copy\x20a\x20file\x20onto\x20itself');existsSync(L)&&isTemplateTreePath(b['to'])&&assertTemplateWriteAuthorized('copy',[b['to']],b['authorize']);mkdirSync(dirname(L),{'recursive':!![]}),cpSync(K,L,{'recursive':!![],'force':!![]}),c={'action':'copy','from':K,'to':L,'ok':!![]},rescanAffectedPack(b['to']);break;}case'move':case'rename':{if(!b['from'])throw new Error('\x27from\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');if(!b['to'])throw new Error('\x27to\x27\x20is\x20required\x20for\x20action=\x27'+b['action']+'\x27');assertTemplateWriteAuthorized(b['action'],[b['from'],b['to']],b['authorize']);const M=resolveIndustryPath(b['from']);let N=resolveIndustryPath(b['to']);if(!existsSync(M))throw new Error('source\x20not\x20found:\x20'+b['from']);try{existsSync(N)&&statSync(N)['isDirectory']()&&(N=join(N,basename(M)));}catch{}if(N===M)throw new Error('\x27'+b['action']+'\x27\x20cannot\x20move\x20onto\x20itself');mkdirSync(dirname(N),{'recursive':!![]}),renameSync(M,N),c={'action':b['action'],'from':M,'to':N,'ok':!![]},rescanAffectedPack(b['from']),rescanAffectedPack(b['to']);break;}case'recommend_industry':c=await handleRecommendIndustry(b);break;case'list_modes':c=await handleListModes();break;case'derive_user_mode':c=await handleDeriveUserMode(b);break;case'evolve_user_mode':c=await handleEvolveUserMode(b);break;case'register_user_mode':c=await handleRegisterUserMode(b);break;case'unregister_user_mode':c=await handleUnregisterUserMode(b);break;case'register_custom_metric':c=await handleRegisterCustomMetric(b);break;case'unregister_custom_metric':c=await handleUnregisterCustomMetric(b);break;case'register_custom_constraint':c=await handleRegisterCustomConstraint(b);break;case'unregister_custom_constraint':c=await handleUnregisterCustomConstraint(b);break;case'list_metrics_constraints':c=await handleListMetricsConstraints(b);break;default:throw new Error('Unknown\x20industry_pack_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':c})}],'structuredContent':{'result':c}};}
|