@wowok/agent-mcp 2.4.1 → 2.5.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/dist/config/runtime.d.ts +4 -0
- package/dist/config/runtime.js +29 -5
- package/dist/harness/auto-escalation.d.ts +27 -0
- package/dist/harness/auto-escalation.js +68 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -1621
- package/dist/knowledge/allocation-confirm.d.ts +115 -0
- package/dist/knowledge/allocation-confirm.js +534 -0
- package/dist/knowledge/allocation-context.d.ts +58 -0
- package/dist/knowledge/allocation-context.js +249 -0
- package/dist/knowledge/allocation-ledger.d.ts +67 -0
- package/dist/knowledge/allocation-ledger.js +463 -0
- package/dist/knowledge/allocation-puzzle.d.ts +135 -0
- package/dist/knowledge/allocation-puzzle.js +298 -0
- package/dist/knowledge/allocation-risk.d.ts +78 -0
- package/dist/knowledge/allocation-risk.js +568 -0
- package/dist/knowledge/allocation-templates.d.ts +38 -0
- package/dist/knowledge/allocation-templates.js +970 -0
- package/dist/knowledge/allocation-translation.d.ts +72 -0
- package/dist/knowledge/allocation-translation.js +585 -0
- package/dist/knowledge/arb-risk.d.ts +37 -0
- package/dist/knowledge/arb-risk.js +210 -0
- package/dist/knowledge/arbitration-confirm.d.ts +135 -0
- package/dist/knowledge/arbitration-confirm.js +559 -0
- package/dist/knowledge/arbitration-context.d.ts +81 -0
- package/dist/knowledge/arbitration-context.js +505 -0
- package/dist/knowledge/arbitration-ledger.d.ts +62 -0
- package/dist/knowledge/arbitration-ledger.js +521 -0
- package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
- package/dist/knowledge/arbitration-puzzle.js +304 -0
- package/dist/knowledge/arbitration-risk.d.ts +112 -0
- package/dist/knowledge/arbitration-risk.js +433 -0
- package/dist/knowledge/arbitration-templates.d.ts +38 -0
- package/dist/knowledge/arbitration-templates.js +276 -0
- package/dist/knowledge/arbitration-translation.d.ts +91 -0
- package/dist/knowledge/arbitration-translation.js +487 -0
- package/dist/knowledge/bridge-risk.d.ts +36 -0
- package/dist/knowledge/bridge-risk.js +263 -0
- package/dist/knowledge/contact-risk.d.ts +32 -0
- package/dist/knowledge/contact-risk.js +200 -0
- package/dist/knowledge/demand-confirm.d.ts +32 -0
- package/dist/knowledge/demand-confirm.js +206 -0
- package/dist/knowledge/demand-risk.d.ts +30 -0
- package/dist/knowledge/demand-risk.js +240 -0
- package/dist/knowledge/demand-translation.d.ts +55 -0
- package/dist/knowledge/demand-translation.js +354 -0
- package/dist/knowledge/deployment-scanner.d.ts +63 -0
- package/dist/knowledge/deployment-scanner.js +762 -0
- package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
- package/dist/knowledge/examples-scanner-cli.js +26 -0
- package/dist/knowledge/examples-scanner.d.ts +121 -0
- package/dist/knowledge/examples-scanner.js +825 -0
- package/dist/knowledge/flywheel-loop.d.ts +3 -0
- package/dist/knowledge/flywheel-loop.js +32 -3
- package/dist/knowledge/glossary.js +3 -1
- package/dist/knowledge/guard-confirm.d.ts +86 -0
- package/dist/knowledge/guard-confirm.js +406 -0
- package/dist/knowledge/guard-context.d.ts +56 -0
- package/dist/knowledge/guard-context.js +287 -0
- package/dist/knowledge/guard-design-patterns.d.ts +37 -0
- package/dist/knowledge/guard-design-patterns.js +257 -0
- package/dist/knowledge/guard-ledger.js +14 -0
- package/dist/knowledge/guard-lint.d.ts +1 -0
- package/dist/knowledge/guard-lint.js +83 -3
- package/dist/knowledge/guard-migration.d.ts +48 -0
- package/dist/knowledge/guard-migration.js +228 -0
- package/dist/knowledge/guard-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +3 -1
- package/dist/knowledge/guard-risk.js +832 -64
- package/dist/knowledge/guard-templates.d.ts +1 -0
- package/dist/knowledge/guard-templates.js +278 -2
- package/dist/knowledge/guard-translation.js +6 -5
- package/dist/knowledge/index.d.ts +342 -0
- package/dist/knowledge/index.js +344 -0
- package/dist/knowledge/machine-confirm.d.ts +102 -0
- package/dist/knowledge/machine-confirm.js +559 -0
- package/dist/knowledge/machine-context.d.ts +160 -0
- package/dist/knowledge/machine-context.js +812 -0
- package/dist/knowledge/machine-ledger.d.ts +41 -0
- package/dist/knowledge/machine-ledger.js +315 -0
- package/dist/knowledge/machine-puzzle.d.ts +206 -0
- package/dist/knowledge/machine-puzzle.js +494 -0
- package/dist/knowledge/machine-risk.d.ts +75 -0
- package/dist/knowledge/machine-risk.js +644 -0
- package/dist/knowledge/machine-templates.d.ts +92 -0
- package/dist/knowledge/machine-templates.js +1592 -0
- package/dist/knowledge/machine-topology.d.ts +57 -0
- package/dist/knowledge/machine-topology.js +234 -0
- package/dist/knowledge/machine-translation.d.ts +96 -0
- package/dist/knowledge/machine-translation.js +513 -0
- package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
- package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
- package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
- package/dist/knowledge/mcp-schema-audit.js +772 -0
- package/dist/knowledge/onchain-constants.d.ts +4 -0
- package/dist/knowledge/onchain-constants.js +35 -0
- package/dist/knowledge/order-confirm.d.ts +115 -0
- package/dist/knowledge/order-confirm.js +573 -0
- package/dist/knowledge/order-context.d.ts +66 -0
- package/dist/knowledge/order-context.js +390 -0
- package/dist/knowledge/order-ledger.d.ts +69 -0
- package/dist/knowledge/order-ledger.js +341 -0
- package/dist/knowledge/order-puzzle.d.ts +159 -0
- package/dist/knowledge/order-puzzle.js +255 -0
- package/dist/knowledge/order-risk.d.ts +66 -0
- package/dist/knowledge/order-risk.js +653 -0
- package/dist/knowledge/order-templates.d.ts +50 -0
- package/dist/knowledge/order-templates.js +368 -0
- package/dist/knowledge/order-translation.d.ts +78 -0
- package/dist/knowledge/order-translation.js +550 -0
- package/dist/knowledge/passport-confirm.d.ts +130 -0
- package/dist/knowledge/passport-confirm.js +531 -0
- package/dist/knowledge/passport-context.d.ts +59 -0
- package/dist/knowledge/passport-context.js +306 -0
- package/dist/knowledge/passport-ledger.d.ts +48 -0
- package/dist/knowledge/passport-ledger.js +282 -0
- package/dist/knowledge/passport-puzzle.d.ts +108 -0
- package/dist/knowledge/passport-puzzle.js +333 -0
- package/dist/knowledge/passport-risk.d.ts +70 -0
- package/dist/knowledge/passport-risk.js +450 -0
- package/dist/knowledge/passport-templates.d.ts +40 -0
- package/dist/knowledge/passport-templates.js +568 -0
- package/dist/knowledge/passport-translation.d.ts +68 -0
- package/dist/knowledge/passport-translation.js +516 -0
- package/dist/knowledge/payment-risk.d.ts +33 -0
- package/dist/knowledge/payment-risk.js +182 -0
- package/dist/knowledge/permission-confirm.d.ts +110 -0
- package/dist/knowledge/permission-confirm.js +426 -0
- package/dist/knowledge/permission-context.d.ts +58 -0
- package/dist/knowledge/permission-context.js +224 -0
- package/dist/knowledge/permission-ledger.d.ts +38 -0
- package/dist/knowledge/permission-ledger.js +403 -0
- package/dist/knowledge/permission-puzzle.d.ts +122 -0
- package/dist/knowledge/permission-puzzle.js +173 -0
- package/dist/knowledge/permission-risk.d.ts +76 -0
- package/dist/knowledge/permission-risk.js +411 -0
- package/dist/knowledge/permission-templates.d.ts +38 -0
- package/dist/knowledge/permission-templates.js +234 -0
- package/dist/knowledge/permission-translation.d.ts +57 -0
- package/dist/knowledge/permission-translation.js +350 -0
- package/dist/knowledge/personal-risk.d.ts +36 -0
- package/dist/knowledge/personal-risk.js +212 -0
- package/dist/knowledge/progress-confirm.d.ts +108 -0
- package/dist/knowledge/progress-confirm.js +456 -0
- package/dist/knowledge/progress-context.d.ts +123 -0
- package/dist/knowledge/progress-context.js +452 -0
- package/dist/knowledge/progress-ledger.d.ts +63 -0
- package/dist/knowledge/progress-ledger.js +327 -0
- package/dist/knowledge/progress-puzzle.d.ts +82 -0
- package/dist/knowledge/progress-puzzle.js +219 -0
- package/dist/knowledge/progress-risk.d.ts +74 -0
- package/dist/knowledge/progress-risk.js +461 -0
- package/dist/knowledge/progress-templates.d.ts +38 -0
- package/dist/knowledge/progress-templates.js +228 -0
- package/dist/knowledge/progress-translation.d.ts +52 -0
- package/dist/knowledge/progress-translation.js +401 -0
- package/dist/knowledge/proof-confirm.d.ts +31 -0
- package/dist/knowledge/proof-confirm.js +187 -0
- package/dist/knowledge/proof-risk.d.ts +33 -0
- package/dist/knowledge/proof-risk.js +207 -0
- package/dist/knowledge/proof-translation.d.ts +52 -0
- package/dist/knowledge/proof-translation.js +283 -0
- package/dist/knowledge/registrar-risk.d.ts +34 -0
- package/dist/knowledge/registrar-risk.js +217 -0
- package/dist/knowledge/repository-confirm.d.ts +36 -0
- package/dist/knowledge/repository-confirm.js +242 -0
- package/dist/knowledge/repository-risk.d.ts +40 -0
- package/dist/knowledge/repository-risk.js +312 -0
- package/dist/knowledge/repository-translation.d.ts +58 -0
- package/dist/knowledge/repository-translation.js +422 -0
- package/dist/knowledge/resource-risk.d.ts +32 -0
- package/dist/knowledge/resource-risk.js +157 -0
- package/dist/knowledge/reward-confirm.d.ts +113 -0
- package/dist/knowledge/reward-confirm.js +496 -0
- package/dist/knowledge/reward-context.d.ts +127 -0
- package/dist/knowledge/reward-context.js +504 -0
- package/dist/knowledge/reward-ledger.d.ts +96 -0
- package/dist/knowledge/reward-ledger.js +502 -0
- package/dist/knowledge/reward-puzzle.d.ts +97 -0
- package/dist/knowledge/reward-puzzle.js +288 -0
- package/dist/knowledge/reward-risk.d.ts +84 -0
- package/dist/knowledge/reward-risk.js +545 -0
- package/dist/knowledge/reward-translation.d.ts +58 -0
- package/dist/knowledge/reward-translation.js +501 -0
- package/dist/knowledge/safety-rules.js +11 -3
- package/dist/knowledge/scenario-modes.d.ts +53 -0
- package/dist/knowledge/scenario-modes.js +302 -0
- package/dist/knowledge/service-confirm.d.ts +152 -0
- package/dist/knowledge/service-confirm.js +699 -0
- package/dist/knowledge/service-context.d.ts +66 -0
- package/dist/knowledge/service-context.js +403 -0
- package/dist/knowledge/service-ledger.d.ts +71 -0
- package/dist/knowledge/service-ledger.js +609 -0
- package/dist/knowledge/service-puzzle.d.ts +158 -0
- package/dist/knowledge/service-puzzle.js +236 -0
- package/dist/knowledge/service-risk.d.ts +108 -0
- package/dist/knowledge/service-risk.js +615 -0
- package/dist/knowledge/service-templates.d.ts +39 -0
- package/dist/knowledge/service-templates.js +418 -0
- package/dist/knowledge/service-translation.d.ts +103 -0
- package/dist/knowledge/service-translation.js +622 -0
- package/dist/knowledge/tools-reference.d.ts +17 -0
- package/dist/knowledge/tools-reference.js +151 -0
- package/dist/knowledge/treasury-confirm.d.ts +133 -0
- package/dist/knowledge/treasury-confirm.js +512 -0
- package/dist/knowledge/treasury-context.d.ts +64 -0
- package/dist/knowledge/treasury-context.js +363 -0
- package/dist/knowledge/treasury-ledger.d.ts +42 -0
- package/dist/knowledge/treasury-ledger.js +300 -0
- package/dist/knowledge/treasury-puzzle.d.ts +163 -0
- package/dist/knowledge/treasury-puzzle.js +216 -0
- package/dist/knowledge/treasury-risk.d.ts +86 -0
- package/dist/knowledge/treasury-risk.js +440 -0
- package/dist/knowledge/treasury-templates.d.ts +38 -0
- package/dist/knowledge/treasury-templates.js +316 -0
- package/dist/knowledge/treasury-translation.d.ts +78 -0
- package/dist/knowledge/treasury-translation.js +498 -0
- package/dist/knowledge/util-risk.d.ts +30 -0
- package/dist/knowledge/util-risk.js +135 -0
- package/dist/project/business-puzzle.d.ts +47 -0
- package/dist/project/business-puzzle.js +372 -0
- package/dist/project/deployment-doc.d.ts +61 -0
- package/dist/project/deployment-doc.js +432 -0
- package/dist/project/graph.d.ts +1 -0
- package/dist/project/graph.js +27 -1
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +39 -2
- package/dist/project/namespace.d.ts +11 -1
- package/dist/project/namespace.js +27 -2
- package/dist/project/query.d.ts +2 -0
- package/dist/project/query.js +56 -15
- package/dist/project/risk-aggregator.d.ts +50 -0
- package/dist/project/risk-aggregator.js +280 -0
- package/dist/project/substep-trace.d.ts +130 -0
- package/dist/project/substep-trace.js +332 -0
- package/dist/rules.d.ts +12 -0
- package/dist/rules.js +9 -0
- package/dist/schema/call/allocation.d.ts +44 -44
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +6 -6
- package/dist/schema/call/bridge-handler.d.ts +5 -2
- package/dist/schema/call/bridge.d.ts +159 -159
- package/dist/schema/call/contact.d.ts +110 -110
- package/dist/schema/call/demand.d.ts +76 -76
- package/dist/schema/call/handler.d.ts +2 -3
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +96 -96
- package/dist/schema/call/order.d.ts +98 -110
- package/dist/schema/call/permission-handler.d.ts +5 -0
- package/dist/schema/call/permission-handler.js +54 -0
- package/dist/schema/call/permission.d.ts +108 -108
- package/dist/schema/call/personal.d.ts +14 -14
- package/dist/schema/call/progress.d.ts +57 -72
- package/dist/schema/call/progress.js +7 -4
- package/dist/schema/call/proof.d.ts +18 -18
- package/dist/schema/call/proof.js +12 -7
- package/dist/schema/call/repository.d.ts +154 -154
- package/dist/schema/call/reward.d.ts +55 -55
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +238 -238
- package/dist/schema/call/treasury.d.ts +93 -93
- package/dist/schema/config/index.d.ts +178 -5
- package/dist/schema/config/index.js +52 -1
- package/dist/schema/local/index.d.ts +3554 -836
- package/dist/schema/local/index.js +2 -1
- package/dist/schema/messenger/index.d.ts +162 -162
- package/dist/schema/operations.d.ts +1102 -1118
- package/dist/schema/operations.js +7 -1
- package/dist/schema/project/index.d.ts +1392 -6
- package/dist/schema/project/index.js +426 -2
- package/dist/schema/query/index.d.ts +818 -818
- package/dist/schema/query/index.js +15 -9
- package/dist/schema/schema-query/index.d.ts +23 -3
- package/dist/schema/schema-query/index.js +13 -2
- package/dist/schema/sync-layer4.d.ts +21 -0
- package/dist/schema/sync-layer4.js +261 -0
- package/dist/schema/trust/index.d.ts +26 -26
- package/dist/schema/utils/guard-query-utils.d.ts +7 -0
- package/dist/schema/utils/guard-query-utils.js +14 -1
- package/dist/schemas/account_operation.output.json +718 -0
- package/dist/schemas/bridge_operation.output.json +1 -1
- package/dist/schemas/config_operation.output.json +173 -0
- package/dist/schemas/index.json +9 -1
- package/dist/schemas/local_info_operation.output.json +718 -0
- package/dist/schemas/local_mark_operation.output.json +718 -0
- package/dist/schemas/messenger_operation.output.json +1 -1
- package/dist/schemas/onchain_events.output.json +1 -1
- package/dist/schemas/onchain_operations.output.json +5 -4
- package/dist/schemas/onchain_operations.schema.json +1813 -333
- package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
- package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
- package/dist/schemas/onchain_operations_contact.schema.json +2 -1
- package/dist/schemas/onchain_operations_demand.schema.json +2 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
- package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
- package/dist/schemas/onchain_operations_guard.schema.json +584 -70
- package/dist/schemas/onchain_operations_machine.schema.json +4 -6
- package/dist/schemas/onchain_operations_order.schema.json +13 -9
- package/dist/schemas/onchain_operations_payment.schema.json +2 -1
- package/dist/schemas/onchain_operations_permission.schema.json +2 -1
- package/dist/schemas/onchain_operations_personal.schema.json +2 -1
- package/dist/schemas/onchain_operations_progress.schema.json +14 -10
- package/dist/schemas/onchain_operations_proof.schema.json +699 -0
- package/dist/schemas/onchain_operations_repository.schema.json +2 -1
- package/dist/schemas/onchain_operations_reward.schema.json +2 -1
- package/dist/schemas/onchain_operations_service.schema.json +4 -6
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- package/dist/schemas/onchain_table_data.output.json +6 -12
- package/dist/schemas/onchain_table_data.schema.json +32 -1
- package/dist/schemas/project_operation.output.json +879 -0
- package/dist/schemas/project_operation.schema.json +473 -2
- package/dist/schemas/query_toolkit.output.json +14906 -6
- package/dist/schemas/schema_query.output.json +38 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/handlers/bridge.d.ts +1 -0
- package/dist/tools/handlers/bridge.js +1 -0
- package/dist/tools/handlers/config.d.ts +2 -0
- package/dist/tools/handlers/config.js +74 -0
- package/dist/tools/handlers/file-export.d.ts +3 -0
- package/dist/tools/handlers/file-export.js +90 -0
- package/dist/tools/handlers/local.d.ts +3 -0
- package/dist/tools/handlers/local.js +38 -0
- package/dist/tools/handlers/messenger.d.ts +16 -0
- package/dist/tools/handlers/messenger.js +188 -0
- package/dist/tools/handlers/onchain.d.ts +2 -0
- package/dist/tools/handlers/onchain.js +248 -0
- package/dist/tools/handlers/project.d.ts +2 -0
- package/dist/tools/handlers/project.js +293 -0
- package/dist/tools/handlers/query.d.ts +5 -0
- package/dist/tools/handlers/query.js +256 -0
- package/dist/tools/handlers/schema-query.d.ts +2 -0
- package/dist/tools/handlers/schema-query.js +93 -0
- package/dist/tools/handlers/trust.d.ts +2 -0
- package/dist/tools/handlers/trust.js +194 -0
- package/dist/tools/handlers/wip.d.ts +2 -0
- package/dist/tools/handlers/wip.js +44 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +526 -0
- package/dist/tools/rules-hook.d.ts +2 -0
- package/dist/tools/rules-hook.js +23 -0
- package/dist/tools/shared.d.ts +20 -0
- package/dist/tools/shared.js +130 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/wrap.d.ts +14 -0
- package/dist/tools/wrap.js +267 -0
- package/package.json +20 -6
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
import { MAX_VOTING_GUARD_COUNT, } from "@wowok/wowok";
|
|
2
|
+
import { isTerminalArbStatus, isValidArbStatusTransition, } from "./arbitration-ledger.js";
|
|
3
|
+
import { assessArbitrationRisks, } from "./arbitration-risk.js";
|
|
4
|
+
export const ARBITRATION_OPERATION_CHECKLIST = [
|
|
5
|
+
{ id: "C-AB-01", description: "object field present (STRING for existing, OBJECT for new)", passed: false, message: "" },
|
|
6
|
+
{ id: "C-AB-02", description: "coin_type valid for new Arbitration (e.g. 0x2::wow::WOW)", passed: false, message: "" },
|
|
7
|
+
{ id: "C-AB-03", description: "permission_address valid (Contact/Permission object)", passed: false, message: "" },
|
|
8
|
+
{ id: "C-AB-04", description: "fee (u64) non-negative; dispute fee >= Arbitration.fee", passed: false, message: "" },
|
|
9
|
+
{ id: "C-AB-05", description: "voting_guard count <= MAX_VOTING_GUARD_COUNT (50)", passed: false, message: "" },
|
|
10
|
+
{ id: "C-AB-06", description: "voting_guard no duplicate addresses", passed: false, message: "" },
|
|
11
|
+
{ id: "C-AB-07", description: "Arb status transition valid (7-state flow)", passed: false, message: "" },
|
|
12
|
+
{ id: "C-AB-08", description: "Operation allowed in current Arb status (not terminal-blocked)", passed: false, message: "" },
|
|
13
|
+
{ id: "C-AB-09", description: "voting_guard / usage_guard dual-Guard coherent with operation", passed: false, message: "" },
|
|
14
|
+
{ id: "C-AB-10", description: "VoteValue weight type valid (GuardIdentifier u8 / FixedValue u32)", passed: false, message: "" },
|
|
15
|
+
{ id: "C-AB-11", description: "Order op permission verified (for dispute)", passed: false, message: "" },
|
|
16
|
+
{ id: "C-AB-12", description: "Ownership transfer (builder) double-confirmed", passed: false, message: "" },
|
|
17
|
+
];
|
|
18
|
+
function runStaticChecklist(input) {
|
|
19
|
+
const items = ARBITRATION_OPERATION_CHECKLIST.map(c => ({ ...c }));
|
|
20
|
+
const data = input.arbitration_json;
|
|
21
|
+
const objValid = data.object !== undefined && data.object !== null;
|
|
22
|
+
const c01 = items.find(i => i.id === "C-AB-01");
|
|
23
|
+
c01.passed = objValid;
|
|
24
|
+
c01.message = objValid ? "" : "object field is required (STRING for existing, OBJECT for new)";
|
|
25
|
+
const c02 = items.find(i => i.id === "C-AB-02");
|
|
26
|
+
if (typeof data.object === "object" && data.object !== null) {
|
|
27
|
+
const obj = data.object;
|
|
28
|
+
const valid = !!obj.type_parameter && obj.type_parameter.includes("::");
|
|
29
|
+
c02.passed = valid;
|
|
30
|
+
c02.message = valid ? "" : "type_parameter must be a valid Coin type (e.g. 0x2::wow::WOW)";
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
c02.passed = true;
|
|
34
|
+
}
|
|
35
|
+
const c03 = items.find(i => i.id === "C-AB-03");
|
|
36
|
+
if (typeof data.object === "object" && data.object !== null) {
|
|
37
|
+
const obj = data.object;
|
|
38
|
+
const valid = !!obj.permission;
|
|
39
|
+
c03.passed = valid;
|
|
40
|
+
c03.message = valid ? "" : "permission is required for new Arbitration";
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
c03.passed = true;
|
|
44
|
+
}
|
|
45
|
+
const c04 = items.find(i => i.id === "C-AB-04");
|
|
46
|
+
if (data.fee !== undefined) {
|
|
47
|
+
const feeNum = typeof data.fee === "string" ? BigInt(data.fee) : BigInt(data.fee);
|
|
48
|
+
const valid = feeNum >= 0;
|
|
49
|
+
c04.passed = valid;
|
|
50
|
+
c04.message = valid ? "" : `fee ${data.fee} must be >= 0`;
|
|
51
|
+
}
|
|
52
|
+
else if (data.dispute && input.current_arbitration_fee !== undefined) {
|
|
53
|
+
const required = typeof input.current_arbitration_fee === "string"
|
|
54
|
+
? BigInt(input.current_arbitration_fee)
|
|
55
|
+
: BigInt(input.current_arbitration_fee);
|
|
56
|
+
const provided = data.dispute.fee && typeof data.dispute.fee === "object" && "balance" in data.dispute.fee
|
|
57
|
+
? BigInt(data.dispute.fee.balance ?? 0)
|
|
58
|
+
: BigInt(0);
|
|
59
|
+
const valid = provided >= required;
|
|
60
|
+
c04.passed = valid;
|
|
61
|
+
c04.message = valid ? "" : `dispute fee ${provided.toString()} < required ${required.toString()}`;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
c04.passed = true;
|
|
65
|
+
}
|
|
66
|
+
const c05 = items.find(i => i.id === "C-AB-05");
|
|
67
|
+
if (data.voting_guard && (data.voting_guard.op === "add" || data.voting_guard.op === "set") && data.voting_guard.guards) {
|
|
68
|
+
const newCount = data.voting_guard.op === "set"
|
|
69
|
+
? data.voting_guard.guards.length
|
|
70
|
+
: (input.current_voting_guard_count ?? 0) + data.voting_guard.guards.length;
|
|
71
|
+
const valid = newCount <= MAX_VOTING_GUARD_COUNT;
|
|
72
|
+
c05.passed = valid;
|
|
73
|
+
c05.message = valid ? "" : `voting_guard count ${newCount} > ${MAX_VOTING_GUARD_COUNT}`;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
c05.passed = true;
|
|
77
|
+
}
|
|
78
|
+
const c06 = items.find(i => i.id === "C-AB-06");
|
|
79
|
+
if (data.voting_guard && (data.voting_guard.op === "add" || data.voting_guard.op === "set") && data.voting_guard.guards) {
|
|
80
|
+
const addrs = data.voting_guard.guards.map(g => g.guard);
|
|
81
|
+
const dupes = addrs.filter((a, i) => addrs.indexOf(a) !== i);
|
|
82
|
+
const valid = dupes.length === 0;
|
|
83
|
+
c06.passed = valid;
|
|
84
|
+
c06.message = valid ? "" : `Duplicate guards: ${dupes.join(", ")}`;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
c06.passed = true;
|
|
88
|
+
}
|
|
89
|
+
const c07 = items.find(i => i.id === "C-AB-07");
|
|
90
|
+
if (input.current_arb_status && input.expected_arb_status) {
|
|
91
|
+
if (input.current_arb_status === input.expected_arb_status) {
|
|
92
|
+
c07.passed = true;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const valid = isValidArbStatusTransition(input.current_arb_status, input.expected_arb_status);
|
|
96
|
+
c07.passed = valid;
|
|
97
|
+
c07.message = valid ? "" : `Invalid transition: ${input.current_arb_status} → ${input.expected_arb_status}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
c07.passed = true;
|
|
102
|
+
}
|
|
103
|
+
const c08 = items.find(i => i.id === "C-AB-08");
|
|
104
|
+
if (input.current_arb_status && isTerminalArbStatus(input.current_arb_status)) {
|
|
105
|
+
const allowedOp = !!data.arb_withdraw;
|
|
106
|
+
const blockedOp = !!(data.vote || data.confirm || data.arbitration || data.reset || data.feedback);
|
|
107
|
+
const valid = allowedOp && !blockedOp;
|
|
108
|
+
c08.passed = valid;
|
|
109
|
+
c08.message = valid ? "" : `Terminal status ${input.current_arb_status} only allows arb_withdraw`;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
c08.passed = true;
|
|
113
|
+
}
|
|
114
|
+
const c09 = items.find(i => i.id === "C-AB-09");
|
|
115
|
+
if (data.vote && data.vote.voting_guard) {
|
|
116
|
+
if (!input.current_voting_guard_addresses || input.current_voting_guard_addresses.length === 0) {
|
|
117
|
+
c09.passed = false;
|
|
118
|
+
c09.message = "vote.voting_guard provided but Arbitration.voting_guard is empty";
|
|
119
|
+
}
|
|
120
|
+
else if (!input.current_voting_guard_addresses.includes(data.vote.voting_guard)) {
|
|
121
|
+
c09.passed = false;
|
|
122
|
+
c09.message = `vote.voting_guard ${data.vote.voting_guard} not in list`;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
c09.passed = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (data.vote && !data.vote.voting_guard && input.current_voting_guard_addresses && input.current_voting_guard_addresses.length > 0) {
|
|
129
|
+
c09.passed = false;
|
|
130
|
+
c09.message = "vote without voting_guard but Arbitration.voting_guard is non-empty (use vote_with_voting_guard)";
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
c09.passed = true;
|
|
134
|
+
}
|
|
135
|
+
const c10 = items.find(i => i.id === "C-AB-10");
|
|
136
|
+
if (data.voting_guard && (data.voting_guard.op === "add" || data.voting_guard.op === "set") && data.voting_guard.guards) {
|
|
137
|
+
let valid = true;
|
|
138
|
+
let msg = "";
|
|
139
|
+
for (const g of data.voting_guard.guards) {
|
|
140
|
+
const vw = g.vote_weight;
|
|
141
|
+
if (!vw) {
|
|
142
|
+
valid = false;
|
|
143
|
+
msg = "Missing vote_weight";
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if ("GuardIdentifier" in vw && vw.GuardIdentifier !== undefined) {
|
|
147
|
+
if (vw.GuardIdentifier > 255) {
|
|
148
|
+
valid = false;
|
|
149
|
+
msg = `GuardIdentifier ${vw.GuardIdentifier} > u8 max (255)`;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ("FixedValue" in vw && vw.FixedValue !== undefined) {
|
|
154
|
+
if (vw.FixedValue > 4294967295) {
|
|
155
|
+
valid = false;
|
|
156
|
+
msg = `FixedValue ${vw.FixedValue} > u32 max`;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
c10.passed = valid;
|
|
162
|
+
c10.message = msg;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
c10.passed = true;
|
|
166
|
+
}
|
|
167
|
+
const c11 = items.find(i => i.id === "C-AB-11");
|
|
168
|
+
if (data.dispute) {
|
|
169
|
+
c11.passed = false;
|
|
170
|
+
c11.message = "Pending environment verification (Layer 4)";
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
c11.passed = true;
|
|
174
|
+
}
|
|
175
|
+
const c12 = items.find(i => i.id === "C-AB-12");
|
|
176
|
+
if (data.builder) {
|
|
177
|
+
c12.passed = false;
|
|
178
|
+
c12.message = "Pending user confirmation in Layer 3";
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
c12.passed = true;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
all_passed: items.filter(i => i.id !== "C-AB-11" && i.id !== "C-AB-12").every(i => i.passed),
|
|
185
|
+
items,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function adaptRiskAssessment(input) {
|
|
189
|
+
const ctx = {
|
|
190
|
+
object: typeof input.arbitration_json.object === "string" ? input.arbitration_json.object : null,
|
|
191
|
+
description: input.arbitration_json.description,
|
|
192
|
+
location: input.arbitration_json.location,
|
|
193
|
+
fee: input.arbitration_json.fee,
|
|
194
|
+
pause: input.arbitration_json.pause,
|
|
195
|
+
dispute: input.arbitration_json.dispute,
|
|
196
|
+
confirm: input.arbitration_json.confirm,
|
|
197
|
+
voting_deadline_change: input.arbitration_json.voting_deadline_change,
|
|
198
|
+
vote: input.arbitration_json.vote,
|
|
199
|
+
feedback: input.arbitration_json.feedback,
|
|
200
|
+
arbitration: input.arbitration_json.arbitration,
|
|
201
|
+
reset: input.arbitration_json.reset,
|
|
202
|
+
arb_withdraw: input.arbitration_json.arb_withdraw,
|
|
203
|
+
fees_transfer: input.arbitration_json.fees_transfer,
|
|
204
|
+
usage_guard: input.arbitration_json.usage_guard,
|
|
205
|
+
voting_guard: input.arbitration_json.voting_guard,
|
|
206
|
+
um: input.arbitration_json.um,
|
|
207
|
+
builder: input.arbitration_json.builder,
|
|
208
|
+
current_arb_status: input.current_arb_status,
|
|
209
|
+
expected_arb_status: input.expected_arb_status,
|
|
210
|
+
current_voting_guard_count: input.current_voting_guard_count,
|
|
211
|
+
current_voting_guard_addresses: input.current_voting_guard_addresses,
|
|
212
|
+
current_arbitration_fee: input.current_arbitration_fee,
|
|
213
|
+
current_bPaused: input.current_bPaused,
|
|
214
|
+
current_timestamp_ms: input.current_timestamp_ms,
|
|
215
|
+
target_objects_types: input.target_objects_types,
|
|
216
|
+
};
|
|
217
|
+
return assessArbitrationRisks(ctx);
|
|
218
|
+
}
|
|
219
|
+
export const ARBITRATION_CONFIRMATION_QUESTIONS = [
|
|
220
|
+
{
|
|
221
|
+
id: "QAB1",
|
|
222
|
+
question: "Are all arbiter/voter addresses correctly granted ARBITRATION_VOTE (358) on the Permission object?",
|
|
223
|
+
requires_explicit_yes: true,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
id: "QAB2",
|
|
227
|
+
question: "Is the voting_guard configuration correct? (Each guard address is a valid Guard object that arbiters can submit Passport for)",
|
|
228
|
+
requires_explicit_yes: true,
|
|
229
|
+
related_risk_ids: ["R-AB-2-01"],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: "QAB3",
|
|
233
|
+
question: "If filing a dispute: have you verified the Order op permission (signer must have Order's dispute permission)?",
|
|
234
|
+
requires_explicit_yes: true,
|
|
235
|
+
related_risk_ids: ["R-AB-5-02"],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
id: "QAB4",
|
|
239
|
+
question: "If making a ruling (arbitration op): is the indemnity amount correct? This will be paid via order::compensate (IRREVERSIBLE).",
|
|
240
|
+
requires_explicit_yes: true,
|
|
241
|
+
related_risk_ids: ["R-AB-3-03"],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: "QAB5",
|
|
245
|
+
question: "⚠️ If transferring ownership (builder field): do you confirm the new owner address is correct? This operation is IRREVERSIBLE.",
|
|
246
|
+
requires_explicit_yes: true,
|
|
247
|
+
related_risk_ids: ["R-AB-3-02"],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: "QAB6",
|
|
251
|
+
question: "If allocating fees (fees_transfer): have you verified the destination Allocation/Treasury has a fair distribution policy for arbiters?",
|
|
252
|
+
requires_explicit_yes: true,
|
|
253
|
+
related_risk_ids: ["R-AB-5-01"],
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
function processUserConfirmation(input, assessment) {
|
|
257
|
+
const questions = [...ARBITRATION_CONFIRMATION_QUESTIONS];
|
|
258
|
+
if (!input.arbitration_json.dispute) {
|
|
259
|
+
const idx = questions.findIndex(q => q.id === "QAB3");
|
|
260
|
+
if (idx >= 0)
|
|
261
|
+
questions.splice(idx, 1);
|
|
262
|
+
}
|
|
263
|
+
if (!input.arbitration_json.arbitration) {
|
|
264
|
+
const idx = questions.findIndex(q => q.id === "QAB4");
|
|
265
|
+
if (idx >= 0)
|
|
266
|
+
questions.splice(idx, 1);
|
|
267
|
+
}
|
|
268
|
+
if (!input.arbitration_json.builder) {
|
|
269
|
+
const idx = questions.findIndex(q => q.id === "QAB5");
|
|
270
|
+
if (idx >= 0)
|
|
271
|
+
questions.splice(idx, 1);
|
|
272
|
+
}
|
|
273
|
+
if (!input.arbitration_json.fees_transfer) {
|
|
274
|
+
const idx = questions.findIndex(q => q.id === "QAB6");
|
|
275
|
+
if (idx >= 0)
|
|
276
|
+
questions.splice(idx, 1);
|
|
277
|
+
}
|
|
278
|
+
if (input.skip_user_confirmation) {
|
|
279
|
+
return {
|
|
280
|
+
questions_asked: questions,
|
|
281
|
+
responses: questions.map(q => ({ question_id: q.id, response: "yes" })),
|
|
282
|
+
all_confirmed: true,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
questions_asked: questions,
|
|
287
|
+
responses: [],
|
|
288
|
+
all_confirmed: false,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function verifyEnvironment(input) {
|
|
292
|
+
const checks = [];
|
|
293
|
+
if (typeof input.arbitration_json.object === "string") {
|
|
294
|
+
checks.push({
|
|
295
|
+
name: "object_exists",
|
|
296
|
+
passed: true,
|
|
297
|
+
message: `Arbitration object ${input.arbitration_json.object} assumed to exist`,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const op = input.arbitration_json;
|
|
301
|
+
const requiresPerm = !!(op.description || op.location || op.fee || op.pause || op.confirm ||
|
|
302
|
+
op.vote || op.feedback || op.arbitration || op.reset || op.arb_withdraw ||
|
|
303
|
+
op.fees_transfer || op.usage_guard !== undefined || op.voting_guard ||
|
|
304
|
+
op.um !== undefined);
|
|
305
|
+
if (requiresPerm) {
|
|
306
|
+
checks.push({
|
|
307
|
+
name: "signer_has_permission",
|
|
308
|
+
passed: true,
|
|
309
|
+
message: "Signer must have the relevant ARBITRATION_* permission index (350-368)",
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const arbOp = op.confirm || op.vote || op.feedback || op.arbitration || op.reset || op.arb_withdraw;
|
|
313
|
+
if (arbOp) {
|
|
314
|
+
checks.push({
|
|
315
|
+
name: "arb_belongs_to_arbitration",
|
|
316
|
+
passed: true,
|
|
317
|
+
message: "Arb.arbitration_address must match this Arbitration (else E_ARBITRATION_ARB_NOT_MATCH)",
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (op.dispute) {
|
|
321
|
+
checks.push({
|
|
322
|
+
name: "order_op_permission",
|
|
323
|
+
passed: false,
|
|
324
|
+
message: `Signer must have Order ${op.dispute.order} dispute operation permission`,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (op.dispute && input.current_bPaused !== undefined) {
|
|
328
|
+
checks.push({
|
|
329
|
+
name: "arbitration_not_paused",
|
|
330
|
+
passed: !input.current_bPaused,
|
|
331
|
+
message: input.current_bPaused ? "Arbitration is paused — dispute will fail (E_PAUSED)" : "OK",
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
if (op.vote && input.current_timestamp_ms !== undefined && input.current_arb_status === "Voting") {
|
|
335
|
+
checks.push({
|
|
336
|
+
name: "voting_deadline_not_expired",
|
|
337
|
+
passed: true,
|
|
338
|
+
message: "Verify Arb.voting_deadline > current time (else vote rejected)",
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
const allPassed = checks.every(c => c.passed);
|
|
342
|
+
return { passed: allPassed, checks };
|
|
343
|
+
}
|
|
344
|
+
export const ARBITRATION_CONFIRM_VERSION = "1.0.0";
|
|
345
|
+
export function runArbitrationConfirmGate(input) {
|
|
346
|
+
const layersPassed = [];
|
|
347
|
+
const layersFailed = [];
|
|
348
|
+
const checklist = runStaticChecklist(input);
|
|
349
|
+
if (!checklist.all_passed) {
|
|
350
|
+
layersFailed.push("L1_checklist");
|
|
351
|
+
return {
|
|
352
|
+
status: "blocked_checklist",
|
|
353
|
+
checklist_result: checklist,
|
|
354
|
+
confirmation_text: generateConfirmationText(input, checklist),
|
|
355
|
+
block_reason: `Checklist failed: ${checklist.items.filter(i => !i.passed && i.id !== "C-AB-11" && i.id !== "C-AB-12").map(i => i.id).join(", ")}`,
|
|
356
|
+
decision_record: {
|
|
357
|
+
timestamp: new Date().toISOString(),
|
|
358
|
+
gate_version: ARBITRATION_CONFIRM_VERSION,
|
|
359
|
+
final_status: "blocked_checklist",
|
|
360
|
+
layers_passed: layersPassed,
|
|
361
|
+
layers_failed: layersFailed,
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
layersPassed.push("L1_checklist");
|
|
366
|
+
const assessment = adaptRiskAssessment(input);
|
|
367
|
+
const hasCritical = assessment.risks.some(r => r.level === "CRITICAL");
|
|
368
|
+
if (hasCritical) {
|
|
369
|
+
layersFailed.push("L2_risk");
|
|
370
|
+
return {
|
|
371
|
+
status: "blocked_risk",
|
|
372
|
+
checklist_result: checklist,
|
|
373
|
+
risk_result: assessment,
|
|
374
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
375
|
+
block_reason: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
|
|
376
|
+
decision_record: {
|
|
377
|
+
timestamp: new Date().toISOString(),
|
|
378
|
+
gate_version: ARBITRATION_CONFIRM_VERSION,
|
|
379
|
+
final_status: "blocked_risk",
|
|
380
|
+
layers_passed: layersPassed,
|
|
381
|
+
layers_failed: layersFailed,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
layersPassed.push("L2_risk");
|
|
386
|
+
const userConf = processUserConfirmation(input, assessment);
|
|
387
|
+
if (!userConf.all_confirmed) {
|
|
388
|
+
if (input.arbitration_json.builder) {
|
|
389
|
+
const cab12 = checklist.items.find(i => i.id === "C-AB-12");
|
|
390
|
+
if (cab12) {
|
|
391
|
+
const qab5 = userConf.responses.find(r => r.question_id === "QAB5");
|
|
392
|
+
cab12.passed = qab5?.response === "yes";
|
|
393
|
+
cab12.message = cab12.passed ? "" : "Transfer not confirmed by user";
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (input.arbitration_json.builder) {
|
|
397
|
+
const cab12 = checklist.items.find(i => i.id === "C-AB-12");
|
|
398
|
+
if (cab12 && !cab12.passed) {
|
|
399
|
+
layersFailed.push("L3_user");
|
|
400
|
+
return {
|
|
401
|
+
status: "blocked_user",
|
|
402
|
+
checklist_result: checklist,
|
|
403
|
+
risk_result: assessment,
|
|
404
|
+
user_confirmation: userConf,
|
|
405
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
406
|
+
block_reason: "User did not confirm ownership transfer",
|
|
407
|
+
decision_record: {
|
|
408
|
+
timestamp: new Date().toISOString(),
|
|
409
|
+
gate_version: ARBITRATION_CONFIRM_VERSION,
|
|
410
|
+
final_status: "blocked_user",
|
|
411
|
+
layers_passed: layersPassed,
|
|
412
|
+
layers_failed: layersFailed,
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
layersPassed.push("L3_user");
|
|
419
|
+
if (input.skip_environment_check) {
|
|
420
|
+
layersPassed.push("L4_environment");
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
const env = verifyEnvironment(input);
|
|
424
|
+
if (!env.passed) {
|
|
425
|
+
layersFailed.push("L4_environment");
|
|
426
|
+
return {
|
|
427
|
+
status: "blocked_environment",
|
|
428
|
+
checklist_result: checklist,
|
|
429
|
+
risk_result: assessment,
|
|
430
|
+
user_confirmation: userConf,
|
|
431
|
+
environment_result: env,
|
|
432
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
433
|
+
block_reason: `Environment check failed: ${env.checks.filter(c => !c.passed).map(c => c.name).join(", ")}`,
|
|
434
|
+
decision_record: {
|
|
435
|
+
timestamp: new Date().toISOString(),
|
|
436
|
+
gate_version: ARBITRATION_CONFIRM_VERSION,
|
|
437
|
+
final_status: "blocked_environment",
|
|
438
|
+
layers_passed: layersPassed,
|
|
439
|
+
layers_failed: layersFailed,
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
layersPassed.push("L4_environment");
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
status: "approved",
|
|
447
|
+
checklist_result: checklist,
|
|
448
|
+
risk_result: assessment,
|
|
449
|
+
user_confirmation: userConf,
|
|
450
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
451
|
+
decision_record: {
|
|
452
|
+
timestamp: new Date().toISOString(),
|
|
453
|
+
gate_version: ARBITRATION_CONFIRM_VERSION,
|
|
454
|
+
final_status: "approved",
|
|
455
|
+
layers_passed: layersPassed,
|
|
456
|
+
layers_failed: layersFailed,
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function generateConfirmationText(input, checklist, assessment) {
|
|
461
|
+
const lines = [];
|
|
462
|
+
const data = input.arbitration_json;
|
|
463
|
+
lines.push("═══ Arbitration Confirmation ═══");
|
|
464
|
+
lines.push("");
|
|
465
|
+
if (typeof data.object === "string") {
|
|
466
|
+
lines.push(`Arbitration: ${data.object}`);
|
|
467
|
+
}
|
|
468
|
+
else if (typeof data.object === "object" && data.object !== null) {
|
|
469
|
+
const obj = data.object;
|
|
470
|
+
lines.push(`Arbitration: NEW '${obj.name ?? "?"}' (T=${obj.type_parameter ?? "?"})`);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
lines.push("Arbitration: (not specified)");
|
|
474
|
+
}
|
|
475
|
+
if (data.description)
|
|
476
|
+
lines.push(`Description: ${data.description}`);
|
|
477
|
+
if (input.current_arb_status)
|
|
478
|
+
lines.push(`Current Arb status: ${input.current_arb_status}`);
|
|
479
|
+
if (input.expected_arb_status)
|
|
480
|
+
lines.push(`Expected Arb status: ${input.expected_arb_status}`);
|
|
481
|
+
lines.push("");
|
|
482
|
+
lines.push("─ Checklist ──────────────────");
|
|
483
|
+
for (const item of checklist.items) {
|
|
484
|
+
const mark = item.passed ? "✓" : "✗";
|
|
485
|
+
lines.push(` ${mark} ${item.id}: ${item.description}${item.message ? " — " + item.message : ""}`);
|
|
486
|
+
}
|
|
487
|
+
lines.push("");
|
|
488
|
+
if (assessment) {
|
|
489
|
+
lines.push("─ Risk Assessment ──────────────────");
|
|
490
|
+
lines.push(`Overall: ${assessment.overall_risk}`);
|
|
491
|
+
lines.push(`Detected: ${assessment.risks.length} risk(s)`);
|
|
492
|
+
for (const r of assessment.risks) {
|
|
493
|
+
lines.push(` [${r.level}] ${r.id}: ${r.title}`);
|
|
494
|
+
}
|
|
495
|
+
lines.push("");
|
|
496
|
+
}
|
|
497
|
+
lines.push("─ Operations ──────────────────");
|
|
498
|
+
if (data.dispute)
|
|
499
|
+
lines.push(`- DISPUTE on Order ${data.dispute.order} (${data.dispute.proposition.length} propositions)`);
|
|
500
|
+
if (data.confirm)
|
|
501
|
+
lines.push(`- CONFIRM Arb ${data.confirm.arb} (deadline=${data.confirm.voting_deadline ?? "none"})`);
|
|
502
|
+
if (data.vote)
|
|
503
|
+
lines.push(`- VOTE on Arb ${data.vote.arb} (${data.vote.voting_guard ? "weighted" : "open"})`);
|
|
504
|
+
if (data.feedback)
|
|
505
|
+
lines.push(`- FEEDBACK on Arb ${data.feedback.arb}`);
|
|
506
|
+
if (data.arbitration)
|
|
507
|
+
lines.push(`- ⚖️ RULING on Arb ${data.arbitration.arb} (indemnity=${data.arbitration.indemnity})`);
|
|
508
|
+
if (data.reset)
|
|
509
|
+
lines.push(`- ↻ RESET Arb ${data.reset.arb}`);
|
|
510
|
+
if (data.arb_withdraw)
|
|
511
|
+
lines.push(`- WITHDRAW from Arb ${data.arb_withdraw.arb}`);
|
|
512
|
+
if (data.fees_transfer) {
|
|
513
|
+
const dest = data.fees_transfer.to.allocation ? `Allocation ${data.fees_transfer.to.allocation}` : `Treasury ${data.fees_transfer.to.treasury}`;
|
|
514
|
+
lines.push(`- 💰 FEES → ${dest}`);
|
|
515
|
+
}
|
|
516
|
+
if (data.voting_guard)
|
|
517
|
+
lines.push(`- voting_guard ${data.voting_guard.op}`);
|
|
518
|
+
if (data.usage_guard !== undefined)
|
|
519
|
+
lines.push(`- usage_guard: ${data.usage_guard ?? "clear"}`);
|
|
520
|
+
if (data.builder)
|
|
521
|
+
lines.push(`- ⚠️ TRANSFER to: ${data.builder}`);
|
|
522
|
+
if (data.um !== undefined)
|
|
523
|
+
lines.push(`- UM: ${data.um ?? "(revoke)"}`);
|
|
524
|
+
lines.push("");
|
|
525
|
+
return lines.join("\n");
|
|
526
|
+
}
|
|
527
|
+
export function progressiveArbitrationCheck(input) {
|
|
528
|
+
const checklist = runStaticChecklist(input);
|
|
529
|
+
if (!checklist.all_passed) {
|
|
530
|
+
return {
|
|
531
|
+
stage: "checklist",
|
|
532
|
+
status: "fail",
|
|
533
|
+
message: `Checklist failed: ${checklist.items.filter(i => !i.passed && i.id !== "C-AB-11" && i.id !== "C-AB-12").map(i => i.id).join(", ")}`,
|
|
534
|
+
next_action: "Fix failing checklist items",
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
const assessment = adaptRiskAssessment(input);
|
|
538
|
+
if (assessment.risks.some(r => r.level === "CRITICAL")) {
|
|
539
|
+
return {
|
|
540
|
+
stage: "risk",
|
|
541
|
+
status: "fail",
|
|
542
|
+
message: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
|
|
543
|
+
next_action: "Resolve CRITICAL risks before proceeding",
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
if (assessment.needs_human_review) {
|
|
547
|
+
return {
|
|
548
|
+
stage: "confirmation",
|
|
549
|
+
status: "pending",
|
|
550
|
+
message: "Human review required for HIGH risks",
|
|
551
|
+
next_action: "Confirm risk acceptance",
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
stage: "complete",
|
|
556
|
+
status: "pass",
|
|
557
|
+
message: "All checks passed",
|
|
558
|
+
};
|
|
559
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type ArbitrationScene, type ArbitrationPermissionEntry, type ArbStatus, type DualGuardMatrix } from "./arbitration-ledger.js";
|
|
2
|
+
import { type ArbitrationTemplate } from "./arbitration-templates.js";
|
|
3
|
+
import { type SemanticToSchemaRule, type ArbitrationConstraintRule } from "./arbitration-translation.js";
|
|
4
|
+
import { type RiskRule, type ArbitrationStakeholder, type ArbitrationRiskAssessment } from "./arbitration-risk.js";
|
|
5
|
+
import { type ArbitrationPuzzle, type PuzzleCompleteness } from "./arbitration-puzzle.js";
|
|
6
|
+
import { type ChecklistItem, type ConfirmationQuestion, type ArbitrationJsonForConfirm } from "./arbitration-confirm.js";
|
|
7
|
+
export declare const ARBITRATION_CONTEXT_VERSION = "1.0.0";
|
|
8
|
+
export type ArbitrationInjectionMode = "initial_design" | "mid_design_review" | "pre_publish" | "post_publish_modify" | "stakeholder_review" | "apply_check";
|
|
9
|
+
export type ArbitrationStakeholderPerspective = ArbitrationStakeholder | "system";
|
|
10
|
+
export interface ArbitrationContextBundle {
|
|
11
|
+
version: string;
|
|
12
|
+
mode: ArbitrationInjectionMode;
|
|
13
|
+
stakeholder_perspective?: ArbitrationStakeholderPerspective;
|
|
14
|
+
matched_scene?: ArbitrationScene;
|
|
15
|
+
matched_template?: ArbitrationTemplate;
|
|
16
|
+
matched_pattern?: SemanticToSchemaRule;
|
|
17
|
+
puzzle_state?: ArbitrationPuzzle;
|
|
18
|
+
puzzle_completeness?: PuzzleCompleteness;
|
|
19
|
+
relevant_risks: RiskRule[];
|
|
20
|
+
risk_assessment?: ArbitrationRiskAssessment;
|
|
21
|
+
relevant_checklist: ChecklistItem[];
|
|
22
|
+
relevant_questions: ConfirmationQuestion[];
|
|
23
|
+
relevant_permissions: ArbitrationPermissionEntry[];
|
|
24
|
+
relevant_constraints: ArbitrationConstraintRule[];
|
|
25
|
+
dual_guard_matrix_entry?: DualGuardMatrix;
|
|
26
|
+
arb_lifecycle_context?: ArbLifecycleContext;
|
|
27
|
+
cross_object_refs: ArbitrationCrossObjectRef[];
|
|
28
|
+
onchain_constraints: ArbitrationOnchainConstraint[];
|
|
29
|
+
rendering_hints: ArbitrationRenderingHints;
|
|
30
|
+
}
|
|
31
|
+
export interface ArbLifecycleContext {
|
|
32
|
+
current_status?: ArbStatus;
|
|
33
|
+
current_status_code?: number;
|
|
34
|
+
is_terminal: boolean;
|
|
35
|
+
valid_next_statuses: ArbStatus[];
|
|
36
|
+
valid_operations_from_here: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface ArbitrationCrossObjectRef {
|
|
39
|
+
object: "Order" | "Service" | "Arb" | "Allocation" | "Treasury" | "Guard" | "Contact" | "Payment";
|
|
40
|
+
field: string;
|
|
41
|
+
scene_id: string;
|
|
42
|
+
description: string;
|
|
43
|
+
direction: "references" | "referenced_by";
|
|
44
|
+
}
|
|
45
|
+
export interface ArbitrationOnchainConstraint {
|
|
46
|
+
name: string;
|
|
47
|
+
value: string | number;
|
|
48
|
+
description: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ArbitrationRenderingHints {
|
|
51
|
+
include_puzzle_template: boolean;
|
|
52
|
+
include_risk_details: boolean;
|
|
53
|
+
include_questions: boolean;
|
|
54
|
+
include_dual_guard_matrix: boolean;
|
|
55
|
+
include_arb_lifecycle: boolean;
|
|
56
|
+
include_immutability_warning: boolean;
|
|
57
|
+
include_indemnity_warning: boolean;
|
|
58
|
+
include_ownership_transfer_warning: boolean;
|
|
59
|
+
max_length: number;
|
|
60
|
+
}
|
|
61
|
+
export interface BuildArbitrationContextInput {
|
|
62
|
+
mode: ArbitrationInjectionMode;
|
|
63
|
+
intent?: string;
|
|
64
|
+
arbitration_json?: ArbitrationJsonForConfirm;
|
|
65
|
+
stakeholder?: ArbitrationStakeholderPerspective;
|
|
66
|
+
target_permission_index?: number;
|
|
67
|
+
target_operation_category?: ArbitrationScene["operation_category"];
|
|
68
|
+
current_arb_status?: ArbStatus;
|
|
69
|
+
voting_guard_empty?: boolean;
|
|
70
|
+
usage_guard_none?: boolean;
|
|
71
|
+
max_length?: number;
|
|
72
|
+
}
|
|
73
|
+
export declare function buildArbitrationContext(input: BuildArbitrationContextInput): ArbitrationContextBundle;
|
|
74
|
+
export declare function buildPromptFromArbitrationContext(bundle: ArbitrationContextBundle): string;
|
|
75
|
+
export declare function getArbitrationContextSummary(bundle: ArbitrationContextBundle): string;
|
|
76
|
+
export { ARBITRATION_LEDGER_VERSION, ARBITRATION_SCENES, ARBITRATION_PERMISSIONS, DUAL_GUARD_MATRIX, ARB_STATUS_CODE, ARB_TERMINAL_STATUSES, findSceneById, findSceneByPermissionIndex, inferSceneFromIntent, getScenesByCategory, getDualGuardMatrixEntry, isValidArbStatusTransition, isTerminalArbStatus, getActiveArbitrationPermissions, getAllArbitrationPermissions, } from "./arbitration-ledger.js";
|
|
77
|
+
export { ARBITRATION_TEMPLATES_VERSION, ARBITRATION_TEMPLATES, suggestTemplateForScene, getTemplatesByScene, getTemplateById, } from "./arbitration-templates.js";
|
|
78
|
+
export { ARBITRATION_TRANSLATION_VERSION, SEMANTIC_TO_SCHEMA_RULES, ARBITRATION_CONSTRAINT_RULES, matchSemanticPattern, explainArbitrationCallData, explainPermissionIndex, explainArbStatus, } from "./arbitration-translation.js";
|
|
79
|
+
export { ARBITRATION_RISK_VERSION, getAllRiskRules, assessArbitrationRisks, } from "./arbitration-risk.js";
|
|
80
|
+
export { ARBITRATION_CONFIRM_VERSION, ARBITRATION_OPERATION_CHECKLIST, ARBITRATION_CONFIRMATION_QUESTIONS, runArbitrationConfirmGate, } from "./arbitration-confirm.js";
|
|
81
|
+
export { initPuzzleFromIntent, checkPuzzleCompleteness, validateConstraints, } from "./arbitration-puzzle.js";
|