@wowok/agent-mcp 2.4.3 → 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.js +21 -0
- 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-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +1 -1
- package/dist/knowledge/guard-risk.js +12 -14
- package/dist/knowledge/guard-templates.js +1 -1
- 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/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/schema/call/allocation.d.ts +34 -34
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +3 -3
- 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 +58 -58
- 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/service.d.ts +231 -231
- 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 +1058 -1074
- 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 +672 -672
- 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/schemas/account_operation.output.json +718 -0
- 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/onchain_operations.output.json +3 -2
- package/dist/schemas/onchain_operations.schema.json +1802 -313
- package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
- 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 +2 -1
- 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 +2 -1
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- 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/config.d.ts +1 -1
- package/dist/tools/handlers/config.js +21 -18
- package/dist/tools/handlers/file-export.d.ts +2 -2
- package/dist/tools/handlers/local.d.ts +3 -30
- package/dist/tools/handlers/local.js +14 -3
- package/dist/tools/handlers/messenger.d.ts +1 -1
- package/dist/tools/handlers/messenger.js +2 -1
- package/dist/tools/handlers/onchain.d.ts +1 -1
- package/dist/tools/handlers/onchain.js +24 -22
- package/dist/tools/handlers/project.d.ts +1 -1
- package/dist/tools/handlers/project.js +258 -18
- package/dist/tools/handlers/query.d.ts +4 -4
- package/dist/tools/handlers/schema-query.d.ts +1 -1
- package/dist/tools/handlers/schema-query.js +21 -20
- package/dist/tools/handlers/trust.d.ts +1 -1
- package/dist/tools/handlers/trust.js +2 -2
- package/dist/tools/handlers/wip.d.ts +1 -1
- package/dist/tools/handlers/wip.js +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +55 -8
- package/dist/tools/rules-hook.d.ts +1 -1
- package/dist/tools/rules-hook.js +3 -2
- package/dist/tools/shared.d.ts +13 -22
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/wrap.d.ts +10 -2
- package/dist/tools/wrap.js +212 -0
- package/package.json +3 -3
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import { MAX_AGENT_COUNT, MAX_DISPUTE_COUNT, } from "@wowok/wowok";
|
|
2
|
+
import { assessOrderRisks, } from "./order-risk.js";
|
|
3
|
+
export const ORDER_PUBLISH_CHECKLIST = [
|
|
4
|
+
{ id: "C-O-01", description: "Order object address is valid (must start with 0x, length >= 40)", passed: false, message: "" },
|
|
5
|
+
{ id: "C-O-02", description: "Operation is NOT direct order::create (Order created via service::buy)", passed: false, message: "" },
|
|
6
|
+
{ id: "C-O-03", description: `agent count <= MAX_AGENT_COUNT (${MAX_AGENT_COUNT}) — ⚠️ actual allows 11 due to <= bug`, passed: false, message: "" },
|
|
7
|
+
{ id: "C-O-04", description: `dispute count < MAX_DISPUTE_COUNT (${MAX_DISPUTE_COUNT}) — cannot file 11th dispute`, passed: false, message: "" },
|
|
8
|
+
{ id: "C-O-05", description: "claimed_by is None (no terminal claim state) — required for arb_confirm/arb_objection/arb_claim_compensation", passed: false, message: "" },
|
|
9
|
+
{ id: "C-O-06", description: "L1 operations (receive/transfer_to/agent_set) called by OWNER only", passed: false, message: "" },
|
|
10
|
+
{ id: "C-O-07", description: "L2 operations (required_info/progress/arb_*) called by owner OR agent", passed: false, message: "" },
|
|
11
|
+
{ id: "C-O-08", description: "agent_set / owner_change called BEFORE Progress binding (frozen after)", passed: false, message: "" },
|
|
12
|
+
{ id: "C-O-09", description: "receive called only when Progress is at terminal node (not delivering)", passed: false, message: "" },
|
|
13
|
+
{ id: "C-O-10", description: "transfer_to / arb_claim_compensation / arb_objection are IRREVERSIBLE — double-confirm", passed: false, message: "" },
|
|
14
|
+
{ id: "C-O-11", description: "required_info is Contact object OR WTS Proof object OR null (clear)", passed: false, message: "" },
|
|
15
|
+
{ id: "C-O-12", description: "Service is published AND not paused (for service::buy flow)", passed: false, message: "" },
|
|
16
|
+
{ id: "C-O-13", description: "Agent CANNOT receive payments — only owner can call receive", passed: false, message: "" },
|
|
17
|
+
{ id: "C-O-14", description: "arb_claim_compensation requires Arb in Arbitrated state", passed: false, message: "" },
|
|
18
|
+
{ id: "C-O-15", description: "Order has 14 fields — SDK uses 'builder' for Move's 'owner' (naming deviation)", passed: false, message: "" },
|
|
19
|
+
];
|
|
20
|
+
function isValidAddress(addr) {
|
|
21
|
+
return typeof addr === "string" && addr.startsWith("0x") && addr.length >= 40;
|
|
22
|
+
}
|
|
23
|
+
function runStaticChecklist(input) {
|
|
24
|
+
const items = ORDER_PUBLISH_CHECKLIST.map(c => ({ ...c }));
|
|
25
|
+
const data = input.order_json;
|
|
26
|
+
const state = input.current_state ?? {};
|
|
27
|
+
const caller = input.caller ?? {};
|
|
28
|
+
const co01 = items.find(i => i.id === "C-O-01");
|
|
29
|
+
if (!data.object) {
|
|
30
|
+
co01.passed = false;
|
|
31
|
+
co01.message = "Order object address is required (creation goes via service::buy, not here)";
|
|
32
|
+
}
|
|
33
|
+
else if (!isValidAddress(data.object)) {
|
|
34
|
+
co01.passed = false;
|
|
35
|
+
co01.message = `Invalid Order address: ${data.object}`;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
co01.passed = true;
|
|
39
|
+
}
|
|
40
|
+
const co02 = items.find(i => i.id === "C-O-02");
|
|
41
|
+
co02.passed = true;
|
|
42
|
+
co02.message = "CallOrder_Data has no create op — Order creation goes via service::buy";
|
|
43
|
+
const co03 = items.find(i => i.id === "C-O-03");
|
|
44
|
+
if (data.agent) {
|
|
45
|
+
const count = data.agent.length;
|
|
46
|
+
const docValid = count <= MAX_AGENT_COUNT;
|
|
47
|
+
co03.passed = docValid;
|
|
48
|
+
co03.message = docValid
|
|
49
|
+
? (count === MAX_AGENT_COUNT ? `${count} agents (at doc limit; actual allows 11 due to bug)` : `${count} agents`)
|
|
50
|
+
: `${count} agents > MAX_AGENT_COUNT (${MAX_AGENT_COUNT}) — will abort E_MAX_AGENT_COUNT (note: actual allows 11 due to <= bug)`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
co03.passed = true;
|
|
54
|
+
}
|
|
55
|
+
const co04 = items.find(i => i.id === "C-O-04");
|
|
56
|
+
const disputeCount = state.dispute_count ?? 0;
|
|
57
|
+
if (data.arb_confirm) {
|
|
58
|
+
const valid = disputeCount < MAX_DISPUTE_COUNT;
|
|
59
|
+
co04.passed = valid;
|
|
60
|
+
co04.message = valid ? `${disputeCount} existing disputes` : `${disputeCount} disputes already at MAX_DISPUTE_COUNT (${MAX_DISPUTE_COUNT}) — next dispute() will abort E_MAX_DISPUTE_COUNT`;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
co04.passed = true;
|
|
64
|
+
}
|
|
65
|
+
const co05 = items.find(i => i.id === "C-O-05");
|
|
66
|
+
if (data.arb_confirm || data.arb_objection || data.arb_claim_compensation) {
|
|
67
|
+
const valid = !state.claimed_by_set;
|
|
68
|
+
co05.passed = valid;
|
|
69
|
+
co05.message = valid ? "claimed_by is None — arb operations allowed" : "claimed_by is SET — arb operations blocked (E_ORDER_ALREADY_CLAIMED, IRREVERSIBLE)";
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
co05.passed = true;
|
|
73
|
+
}
|
|
74
|
+
const co06 = items.find(i => i.id === "C-O-06");
|
|
75
|
+
const isL1Op = !!(data.receive || data.transfer_to || data.agent);
|
|
76
|
+
if (isL1Op) {
|
|
77
|
+
const valid = !!caller.is_owner;
|
|
78
|
+
co06.passed = valid;
|
|
79
|
+
co06.message = valid ? "Caller is owner — L1 allowed" : "Caller is NOT owner — L1 operation blocked (E_OWNER)";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
co06.passed = true;
|
|
83
|
+
}
|
|
84
|
+
const co07 = items.find(i => i.id === "C-O-07");
|
|
85
|
+
const isL2Op = !!(data.required_info !== undefined || data.progress || data.arb_confirm || data.arb_objection || data.arb_claim_compensation);
|
|
86
|
+
if (isL2Op) {
|
|
87
|
+
const valid = !!caller.is_owner || !!caller.is_agent;
|
|
88
|
+
co07.passed = valid;
|
|
89
|
+
co07.message = valid ? "Caller is owner or agent — L2 allowed" : "Caller is NEITHER owner NOR agent — L2 blocked (E_PERMISSION)";
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
co07.passed = true;
|
|
93
|
+
}
|
|
94
|
+
const co08 = items.find(i => i.id === "C-O-08");
|
|
95
|
+
if (data.agent || (data.transfer_to && !state.progress_bound)) {
|
|
96
|
+
if (data.agent) {
|
|
97
|
+
const valid = !state.progress_bound;
|
|
98
|
+
co08.passed = valid;
|
|
99
|
+
co08.message = valid ? "Progress not bound — agent_set allowed" : "Progress BOUND — agent_set aborts E_PROGRESS_NOT_SPECIFIED (frozen)";
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
co08.passed = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
co08.passed = true;
|
|
107
|
+
}
|
|
108
|
+
const co09 = items.find(i => i.id === "C-O-09");
|
|
109
|
+
if (data.receive) {
|
|
110
|
+
const valid = !!state.progress_at_terminal;
|
|
111
|
+
co09.passed = valid;
|
|
112
|
+
co09.message = valid ? "Progress at terminal — receive allowed" : "Progress NOT at terminal — receive aborts E_ORDER_DELIVERING";
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
co09.passed = true;
|
|
116
|
+
}
|
|
117
|
+
const co10 = items.find(i => i.id === "C-O-10");
|
|
118
|
+
const isIrreversible = !!(data.transfer_to || data.arb_claim_compensation || data.arb_objection);
|
|
119
|
+
if (isIrreversible) {
|
|
120
|
+
co10.passed = false;
|
|
121
|
+
co10.message = "Pending user confirmation in Layer 3 (irreversible operation)";
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
co10.passed = true;
|
|
125
|
+
}
|
|
126
|
+
const co11 = items.find(i => i.id === "C-O-11");
|
|
127
|
+
if (data.required_info !== undefined) {
|
|
128
|
+
const valid = data.required_info === null || isValidAddress(data.required_info);
|
|
129
|
+
co11.passed = valid;
|
|
130
|
+
co11.message = valid
|
|
131
|
+
? (data.required_info === null ? "required_info = null (clear)" : "required_info is valid address (Contact or WTS Proof)")
|
|
132
|
+
: `Invalid required_info: ${data.required_info}`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
co11.passed = true;
|
|
136
|
+
}
|
|
137
|
+
const co12 = items.find(i => i.id === "C-O-12");
|
|
138
|
+
co12.passed = true;
|
|
139
|
+
co12.message = "Service check applies only to service::buy flow (not CallOrder_Data)";
|
|
140
|
+
const co13 = items.find(i => i.id === "C-O-13");
|
|
141
|
+
if (data.receive && caller.is_agent && !caller.is_owner) {
|
|
142
|
+
co13.passed = false;
|
|
143
|
+
co13.message = "Agent CANNOT receive payments — only owner can call receive (L1)";
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
co13.passed = true;
|
|
147
|
+
}
|
|
148
|
+
const co14 = items.find(i => i.id === "C-O-14");
|
|
149
|
+
if (data.arb_claim_compensation) {
|
|
150
|
+
co14.passed = true;
|
|
151
|
+
co14.message = "Arb Arbitrated state verified in Layer 4 (Environment)";
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
co14.passed = true;
|
|
155
|
+
}
|
|
156
|
+
const co15 = items.find(i => i.id === "C-O-15");
|
|
157
|
+
co15.passed = true;
|
|
158
|
+
co15.message = "Informational: SDK ObjectOrder.builder ↔ Move Order.owner (only naming deviation in 22 objects)";
|
|
159
|
+
return {
|
|
160
|
+
all_passed: items.filter(i => i.id !== "C-O-10").every(i => i.passed),
|
|
161
|
+
items,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function adaptRiskAssessment(input) {
|
|
165
|
+
const data = input.order_json;
|
|
166
|
+
const state = input.current_state ?? {};
|
|
167
|
+
const caller = input.caller ?? {};
|
|
168
|
+
let operation;
|
|
169
|
+
if (data.agent)
|
|
170
|
+
operation = "agent_set";
|
|
171
|
+
else if (data.required_info !== undefined)
|
|
172
|
+
operation = "required_info_update";
|
|
173
|
+
else if (data.progress)
|
|
174
|
+
operation = "progress_advance";
|
|
175
|
+
else if (data.arb_confirm)
|
|
176
|
+
operation = "arb_confirm";
|
|
177
|
+
else if (data.arb_objection)
|
|
178
|
+
operation = "arb_objection";
|
|
179
|
+
else if (data.arb_claim_compensation)
|
|
180
|
+
operation = "arb_claim_compensation";
|
|
181
|
+
else if (data.receive)
|
|
182
|
+
operation = "receive";
|
|
183
|
+
else if (data.transfer_to)
|
|
184
|
+
operation = "transfer_to";
|
|
185
|
+
const ctx = {
|
|
186
|
+
object: data.object,
|
|
187
|
+
operation,
|
|
188
|
+
is_buy_operation: false,
|
|
189
|
+
agent_set: data.agent ? { agents: data.agent } : undefined,
|
|
190
|
+
current_dispute_count: state.dispute_count,
|
|
191
|
+
claimed_by_set: state.claimed_by_set,
|
|
192
|
+
progress_bound: state.progress_bound,
|
|
193
|
+
progress_at_terminal: state.progress_at_terminal,
|
|
194
|
+
service_published: state.service_published,
|
|
195
|
+
service_paused: state.service_paused,
|
|
196
|
+
current_service_machine: state.current_service_machine,
|
|
197
|
+
order_machine_snapshot: state.order_machine_snapshot,
|
|
198
|
+
transfer_to_new_owner: data.transfer_to,
|
|
199
|
+
caller_is_owner: caller.is_owner,
|
|
200
|
+
caller_is_agent: caller.is_agent,
|
|
201
|
+
};
|
|
202
|
+
return assessOrderRisks(ctx);
|
|
203
|
+
}
|
|
204
|
+
export const ORDER_CONFIRMATION_QUESTIONS = [
|
|
205
|
+
{
|
|
206
|
+
id: "QO1",
|
|
207
|
+
question: "Is the Order object address correct? Verify it matches the intended Order (check on explorer).",
|
|
208
|
+
requires_explicit_yes: true,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "QO2",
|
|
212
|
+
question: "If setting agent list: are all agent addresses trusted parties? Agents can advance Progress and file arbitration but CANNOT receive payments.",
|
|
213
|
+
requires_explicit_yes: true,
|
|
214
|
+
related_risk_ids: ["R-O-3-01"],
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: "QO3",
|
|
218
|
+
question: "If filing arbitration (arb_confirm): have you attached all evidence? This operation is IRREVERSIBLE — once filed, the Arb process cannot be cancelled.",
|
|
219
|
+
requires_explicit_yes: true,
|
|
220
|
+
related_risk_ids: ["R-O-4-04"],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "QO4",
|
|
224
|
+
question: "⚠️⚠️ If claiming compensation (arb_claim_compensation): do you confirm this is the FINAL Arb ruling? After claim, claimed_by is set IRREVERSIBLY — NO new disputes can ever be filed.",
|
|
225
|
+
requires_explicit_yes: true,
|
|
226
|
+
related_risk_ids: ["R-O-3-03", "R-O-4-04"],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: "QO5",
|
|
230
|
+
question: "⚠️⚠️ If transferring ownership (transfer_to): do you confirm the new owner address is correct? This is IRREVERSIBLE — new owner takes over ALL permissions including payment receipt.",
|
|
231
|
+
requires_explicit_yes: true,
|
|
232
|
+
related_risk_ids: ["R-O-4-06"],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: "QO6",
|
|
236
|
+
question: "If advancing Progress: are you sure about the target node? Node transitions are IRREVERSIBLE — no backward movement is possible.",
|
|
237
|
+
requires_explicit_yes: true,
|
|
238
|
+
related_risk_ids: ["R-O-4-03"],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: "QO7",
|
|
242
|
+
question: "If receiving payment: have you verified the receiving object ID and the amount? Funds are forwarded to the owner address immediately.",
|
|
243
|
+
requires_explicit_yes: false,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: "QO8",
|
|
247
|
+
question: "Have you exported the current Order state as a backup before this operation? (Recommended for irreversible ops.)",
|
|
248
|
+
requires_explicit_yes: false,
|
|
249
|
+
},
|
|
250
|
+
];
|
|
251
|
+
function processUserConfirmation(input, assessment) {
|
|
252
|
+
const data = input.order_json;
|
|
253
|
+
let questions = [...ORDER_CONFIRMATION_QUESTIONS];
|
|
254
|
+
if (!data.agent)
|
|
255
|
+
questions = questions.filter(q => q.id !== "QO2");
|
|
256
|
+
if (!data.arb_confirm)
|
|
257
|
+
questions = questions.filter(q => q.id !== "QO3");
|
|
258
|
+
if (!data.arb_claim_compensation)
|
|
259
|
+
questions = questions.filter(q => q.id !== "QO4");
|
|
260
|
+
if (!data.transfer_to)
|
|
261
|
+
questions = questions.filter(q => q.id !== "QO5");
|
|
262
|
+
if (!data.progress)
|
|
263
|
+
questions = questions.filter(q => q.id !== "QO6");
|
|
264
|
+
if (!data.receive)
|
|
265
|
+
questions = questions.filter(q => q.id !== "QO7");
|
|
266
|
+
if (input.skip_user_confirmation) {
|
|
267
|
+
return {
|
|
268
|
+
questions_asked: questions,
|
|
269
|
+
responses: questions.map(q => ({ question_id: q.id, response: "yes" })),
|
|
270
|
+
all_confirmed: true,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
questions_asked: questions,
|
|
275
|
+
responses: [],
|
|
276
|
+
all_confirmed: false,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function verifyEnvironment(input) {
|
|
280
|
+
const checks = [];
|
|
281
|
+
const data = input.order_json;
|
|
282
|
+
const state = input.current_state ?? {};
|
|
283
|
+
const caller = input.caller ?? {};
|
|
284
|
+
if (data.object) {
|
|
285
|
+
checks.push({
|
|
286
|
+
name: "order_exists",
|
|
287
|
+
passed: true,
|
|
288
|
+
message: `Order ${data.object} assumed to exist (verify via explorer)`,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
const isL1Op = !!(data.receive || data.transfer_to || data.agent);
|
|
292
|
+
const isL2Op = !!(data.required_info !== undefined || data.progress || data.arb_confirm || data.arb_objection || data.arb_claim_compensation);
|
|
293
|
+
if (isL1Op) {
|
|
294
|
+
checks.push({
|
|
295
|
+
name: "signer_is_owner",
|
|
296
|
+
passed: !!caller.is_owner,
|
|
297
|
+
message: caller.is_owner
|
|
298
|
+
? "Signer is owner — L1 allowed"
|
|
299
|
+
: "Signer is NOT owner — L1 operation will abort E_OWNER",
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
else if (isL2Op) {
|
|
303
|
+
const hasPerm = !!caller.is_owner || !!caller.is_agent;
|
|
304
|
+
checks.push({
|
|
305
|
+
name: "signer_is_owner_or_agent",
|
|
306
|
+
passed: hasPerm,
|
|
307
|
+
message: hasPerm
|
|
308
|
+
? `Signer is ${caller.is_owner ? "owner" : "agent"} — L2 allowed`
|
|
309
|
+
: "Signer is NEITHER owner NOR agent — L2 will abort E_PERMISSION",
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (data.arb_confirm || data.arb_objection || data.arb_claim_compensation) {
|
|
313
|
+
checks.push({
|
|
314
|
+
name: "claimed_by_is_none",
|
|
315
|
+
passed: !state.claimed_by_set,
|
|
316
|
+
message: state.claimed_by_set
|
|
317
|
+
? "claimed_by is SET — arb operations blocked (E_ORDER_ALREADY_CLAIMED, IRREVERSIBLE)"
|
|
318
|
+
: "claimed_by is None — arb operations allowed",
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
if (data.receive) {
|
|
322
|
+
checks.push({
|
|
323
|
+
name: "progress_at_terminal",
|
|
324
|
+
passed: !!state.progress_at_terminal,
|
|
325
|
+
message: state.progress_at_terminal
|
|
326
|
+
? "Progress at terminal — receive allowed"
|
|
327
|
+
: "Progress NOT at terminal — receive aborts E_ORDER_DELIVERING",
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
if (data.agent) {
|
|
331
|
+
checks.push({
|
|
332
|
+
name: "progress_not_bound",
|
|
333
|
+
passed: !state.progress_bound,
|
|
334
|
+
message: state.progress_bound
|
|
335
|
+
? "Progress BOUND — agent_set aborts E_PROGRESS_NOT_SPECIFIED (frozen)"
|
|
336
|
+
: "Progress not bound — agent_set allowed",
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (data.arb_confirm) {
|
|
340
|
+
const count = state.dispute_count ?? 0;
|
|
341
|
+
const valid = count < MAX_DISPUTE_COUNT;
|
|
342
|
+
checks.push({
|
|
343
|
+
name: "dispute_count_below_max",
|
|
344
|
+
passed: valid,
|
|
345
|
+
message: valid
|
|
346
|
+
? `${count} disputes (< MAX_DISPUTE_COUNT ${MAX_DISPUTE_COUNT})`
|
|
347
|
+
: `${count} disputes at MAX_DISPUTE_COUNT — next dispute() aborts E_MAX_DISPUTE_COUNT`,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
if (state.service_published === false) {
|
|
351
|
+
checks.push({
|
|
352
|
+
name: "service_published",
|
|
353
|
+
passed: false,
|
|
354
|
+
message: "Service is NOT published — service::buy will fail",
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
if (state.service_paused === true) {
|
|
358
|
+
checks.push({
|
|
359
|
+
name: "service_not_paused",
|
|
360
|
+
passed: false,
|
|
361
|
+
message: "Service is PAUSED — service::buy will fail",
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
const allPassed = checks.every(c => c.passed);
|
|
365
|
+
return { passed: allPassed, checks };
|
|
366
|
+
}
|
|
367
|
+
export const ORDER_CONFIRM_VERSION = "1.0.0";
|
|
368
|
+
export function runOrderConfirmGate(input) {
|
|
369
|
+
const layersPassed = [];
|
|
370
|
+
const layersFailed = [];
|
|
371
|
+
const checklist = runStaticChecklist(input);
|
|
372
|
+
if (!checklist.all_passed) {
|
|
373
|
+
layersFailed.push("L1_checklist");
|
|
374
|
+
return {
|
|
375
|
+
status: "blocked_checklist",
|
|
376
|
+
checklist_result: checklist,
|
|
377
|
+
confirmation_text: generateConfirmationText(input, checklist),
|
|
378
|
+
block_reason: `Checklist failed: ${checklist.items.filter(i => !i.passed).map(i => i.id).join(", ")}`,
|
|
379
|
+
decision_record: {
|
|
380
|
+
timestamp: new Date().toISOString(),
|
|
381
|
+
gate_version: ORDER_CONFIRM_VERSION,
|
|
382
|
+
final_status: "blocked_checklist",
|
|
383
|
+
layers_passed: layersPassed,
|
|
384
|
+
layers_failed: layersFailed,
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
layersPassed.push("L1_checklist");
|
|
389
|
+
const assessment = adaptRiskAssessment(input);
|
|
390
|
+
const hasCritical = assessment.risks.some(r => r.level === "CRITICAL");
|
|
391
|
+
if (hasCritical) {
|
|
392
|
+
layersFailed.push("L2_risk");
|
|
393
|
+
return {
|
|
394
|
+
status: "blocked_risk",
|
|
395
|
+
checklist_result: checklist,
|
|
396
|
+
risk_result: assessment,
|
|
397
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
398
|
+
block_reason: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
|
|
399
|
+
decision_record: {
|
|
400
|
+
timestamp: new Date().toISOString(),
|
|
401
|
+
gate_version: ORDER_CONFIRM_VERSION,
|
|
402
|
+
final_status: "blocked_risk",
|
|
403
|
+
layers_passed: layersPassed,
|
|
404
|
+
layers_failed: layersFailed,
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
layersPassed.push("L2_risk");
|
|
409
|
+
const userConf = processUserConfirmation(input, assessment);
|
|
410
|
+
if (!userConf.all_confirmed) {
|
|
411
|
+
const isIrreversible = !!(input.order_json.transfer_to || input.order_json.arb_claim_compensation || input.order_json.arb_objection);
|
|
412
|
+
if (isIrreversible) {
|
|
413
|
+
const co10 = checklist.items.find(i => i.id === "C-O-10");
|
|
414
|
+
if (co10) {
|
|
415
|
+
const relevantQIds = [];
|
|
416
|
+
if (input.order_json.transfer_to)
|
|
417
|
+
relevantQIds.push("QO5");
|
|
418
|
+
if (input.order_json.arb_claim_compensation)
|
|
419
|
+
relevantQIds.push("QO4");
|
|
420
|
+
if (input.order_json.arb_objection)
|
|
421
|
+
relevantQIds.push("QO3");
|
|
422
|
+
const confirmed = relevantQIds.every(qid => {
|
|
423
|
+
const r = userConf.responses.find(r => r.question_id === qid);
|
|
424
|
+
return r?.response === "yes";
|
|
425
|
+
});
|
|
426
|
+
co10.passed = confirmed;
|
|
427
|
+
co10.message = confirmed ? "" : "Irreversible operation not confirmed by user";
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (isIrreversible) {
|
|
431
|
+
const co10 = checklist.items.find(i => i.id === "C-O-10");
|
|
432
|
+
if (co10 && !co10.passed) {
|
|
433
|
+
layersFailed.push("L3_user");
|
|
434
|
+
return {
|
|
435
|
+
status: "blocked_user",
|
|
436
|
+
checklist_result: checklist,
|
|
437
|
+
risk_result: assessment,
|
|
438
|
+
user_confirmation: userConf,
|
|
439
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
440
|
+
block_reason: "User did not confirm irreversible operation",
|
|
441
|
+
decision_record: {
|
|
442
|
+
timestamp: new Date().toISOString(),
|
|
443
|
+
gate_version: ORDER_CONFIRM_VERSION,
|
|
444
|
+
final_status: "blocked_user",
|
|
445
|
+
layers_passed: layersPassed,
|
|
446
|
+
layers_failed: layersFailed,
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
layersPassed.push("L3_user");
|
|
453
|
+
if (input.skip_environment_check) {
|
|
454
|
+
layersPassed.push("L4_environment");
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
const env = verifyEnvironment(input);
|
|
458
|
+
if (!env.passed) {
|
|
459
|
+
layersFailed.push("L4_environment");
|
|
460
|
+
return {
|
|
461
|
+
status: "blocked_environment",
|
|
462
|
+
checklist_result: checklist,
|
|
463
|
+
risk_result: assessment,
|
|
464
|
+
user_confirmation: userConf,
|
|
465
|
+
environment_result: env,
|
|
466
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
467
|
+
block_reason: `Environment check failed: ${env.checks.filter(c => !c.passed).map(c => c.name).join(", ")}`,
|
|
468
|
+
decision_record: {
|
|
469
|
+
timestamp: new Date().toISOString(),
|
|
470
|
+
gate_version: ORDER_CONFIRM_VERSION,
|
|
471
|
+
final_status: "blocked_environment",
|
|
472
|
+
layers_passed: layersPassed,
|
|
473
|
+
layers_failed: layersFailed,
|
|
474
|
+
},
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
layersPassed.push("L4_environment");
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
status: "approved",
|
|
481
|
+
checklist_result: checklist,
|
|
482
|
+
risk_result: assessment,
|
|
483
|
+
user_confirmation: userConf,
|
|
484
|
+
confirmation_text: generateConfirmationText(input, checklist, assessment),
|
|
485
|
+
decision_record: {
|
|
486
|
+
timestamp: new Date().toISOString(),
|
|
487
|
+
gate_version: ORDER_CONFIRM_VERSION,
|
|
488
|
+
final_status: "approved",
|
|
489
|
+
layers_passed: layersPassed,
|
|
490
|
+
layers_failed: layersFailed,
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function generateConfirmationText(input, checklist, assessment) {
|
|
495
|
+
const lines = [];
|
|
496
|
+
const data = input.order_json;
|
|
497
|
+
lines.push("═══ Order Confirmation ═══");
|
|
498
|
+
lines.push("");
|
|
499
|
+
if (data.object) {
|
|
500
|
+
lines.push(`Order: ${data.object}`);
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
lines.push("Order: (no address — invalid for CallOrder_Data)");
|
|
504
|
+
}
|
|
505
|
+
lines.push("");
|
|
506
|
+
lines.push("─ Operations ──────────────────");
|
|
507
|
+
if (data.agent)
|
|
508
|
+
lines.push(`- ⚠️ Set agent list: ${data.agent.length} agent(s) [L1, owner-only, frozen after progress]`);
|
|
509
|
+
if (data.required_info !== undefined)
|
|
510
|
+
lines.push(`- required_info: ${data.required_info === null ? "(clear)" : data.required_info} [L2]`);
|
|
511
|
+
if (data.progress)
|
|
512
|
+
lines.push(`- Advance Progress: ${data.progress.next_node_name ?? "?"} [L2, irreversible]`);
|
|
513
|
+
if (data.arb_confirm)
|
|
514
|
+
lines.push(`- ⚠️ File arbitration: ${data.arb_confirm.arb} [L2, irreversible]`);
|
|
515
|
+
if (data.arb_objection)
|
|
516
|
+
lines.push(`- ⚠️ Object to Arb: ${data.arb_objection.arb} [L2, irreversible]`);
|
|
517
|
+
if (data.arb_claim_compensation)
|
|
518
|
+
lines.push(`- ⚠️⚠️ Claim compensation: ${data.arb_claim_compensation.arb} [L2, ONE-TIME, IRREVERSIBLE]`);
|
|
519
|
+
if (data.receive)
|
|
520
|
+
lines.push(`- Receive: ${data.receive.received} [L1, owner-only]`);
|
|
521
|
+
if (data.transfer_to)
|
|
522
|
+
lines.push(`- ⚠️⚠️ Transfer ownership to: ${data.transfer_to} [L1, IRREVERSIBLE]`);
|
|
523
|
+
lines.push("");
|
|
524
|
+
lines.push("─ Checklist ──────────────────");
|
|
525
|
+
for (const item of checklist.items) {
|
|
526
|
+
const mark = item.passed ? "✓" : "✗";
|
|
527
|
+
lines.push(` ${mark} ${item.id}: ${item.description}${item.message ? " — " + item.message : ""}`);
|
|
528
|
+
}
|
|
529
|
+
lines.push("");
|
|
530
|
+
if (assessment) {
|
|
531
|
+
lines.push("─ Risk Assessment ──────────────────");
|
|
532
|
+
lines.push(`Overall: ${assessment.overall_risk}`);
|
|
533
|
+
lines.push(`Detected: ${assessment.risks.length} risk(s)`);
|
|
534
|
+
for (const r of assessment.risks) {
|
|
535
|
+
lines.push(` [${r.level}] ${r.id}: ${r.title}`);
|
|
536
|
+
}
|
|
537
|
+
lines.push("");
|
|
538
|
+
}
|
|
539
|
+
return lines.join("\n");
|
|
540
|
+
}
|
|
541
|
+
export function progressiveOrderCheck(input) {
|
|
542
|
+
const checklist = runStaticChecklist(input);
|
|
543
|
+
if (!checklist.all_passed) {
|
|
544
|
+
return {
|
|
545
|
+
stage: "checklist",
|
|
546
|
+
status: "fail",
|
|
547
|
+
message: `Checklist failed: ${checklist.items.filter(i => !i.passed).map(i => i.id).join(", ")}`,
|
|
548
|
+
next_action: "Fix failing checklist items",
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const assessment = adaptRiskAssessment(input);
|
|
552
|
+
if (assessment.risks.some(r => r.level === "CRITICAL")) {
|
|
553
|
+
return {
|
|
554
|
+
stage: "risk",
|
|
555
|
+
status: "fail",
|
|
556
|
+
message: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
|
|
557
|
+
next_action: "Resolve CRITICAL risks before proceeding",
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
if (assessment.needs_human_review) {
|
|
561
|
+
return {
|
|
562
|
+
stage: "confirmation",
|
|
563
|
+
status: "pending",
|
|
564
|
+
message: "Human review required for HIGH risks",
|
|
565
|
+
next_action: "Confirm risk acceptance",
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
return {
|
|
569
|
+
stage: "complete",
|
|
570
|
+
status: "pass",
|
|
571
|
+
message: "All checks passed",
|
|
572
|
+
};
|
|
573
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type OrderScene, type OrderPermissionLayer, type OrderLifecycleEvent } from "./order-ledger.js";
|
|
2
|
+
import { type OrderTemplate } from "./order-templates.js";
|
|
3
|
+
import { type SemanticToSchemaRule } from "./order-translation.js";
|
|
4
|
+
import { type OrderRiskRule, type OrderRiskAssessment, type OrderStakeholder, type OrderRiskCheckContext } from "./order-risk.js";
|
|
5
|
+
import { verifySnapshotMechanism, type OrderPuzzle, type OrderPuzzleCompleteness } from "./order-puzzle.js";
|
|
6
|
+
import { ORDER_PUBLISH_CHECKLIST, ORDER_CONFIRMATION_QUESTIONS, type OrderJsonForConfirm } from "./order-confirm.js";
|
|
7
|
+
export declare const ORDER_CONTEXT_VERSION = "1.0.0";
|
|
8
|
+
export type OrderInjectionMode = "initial_design" | "mid_design_review" | "pre_execute" | "post_create_monitor" | "stakeholder_review" | "dispute_resolution";
|
|
9
|
+
export type OrderStakeholderPerspective = OrderStakeholder | "system";
|
|
10
|
+
export interface OrderContextBundle {
|
|
11
|
+
version: string;
|
|
12
|
+
mode: OrderInjectionMode;
|
|
13
|
+
stakeholder_perspective?: OrderStakeholderPerspective;
|
|
14
|
+
matched_scene?: OrderScene;
|
|
15
|
+
matched_template?: OrderTemplate;
|
|
16
|
+
matched_pattern?: SemanticToSchemaRule;
|
|
17
|
+
puzzle_state?: OrderPuzzle;
|
|
18
|
+
puzzle_completeness?: OrderPuzzleCompleteness;
|
|
19
|
+
relevant_risks: OrderRiskRule[];
|
|
20
|
+
risk_assessment?: OrderRiskAssessment;
|
|
21
|
+
relevant_checklist: typeof ORDER_PUBLISH_CHECKLIST;
|
|
22
|
+
relevant_questions: typeof ORDER_CONFIRMATION_QUESTIONS;
|
|
23
|
+
cross_object_refs: OrderCrossObjectRef[];
|
|
24
|
+
onchain_constraints: OrderOnchainConstraint[];
|
|
25
|
+
rendering_hints: OrderRenderingHints;
|
|
26
|
+
snapshot_verification?: ReturnType<typeof verifySnapshotMechanism>;
|
|
27
|
+
event_audit?: {
|
|
28
|
+
emitted: OrderLifecycleEvent[];
|
|
29
|
+
inferred: OrderLifecycleEvent[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface OrderCrossObjectRef {
|
|
33
|
+
object: "Service" | "Machine" | "Progress" | "Allocation" | "Arbitration" | "Repository" | "Demand" | "Discount" | "Contact" | "WTS_Proof";
|
|
34
|
+
field: string;
|
|
35
|
+
scene_id: string;
|
|
36
|
+
description: string;
|
|
37
|
+
}
|
|
38
|
+
export interface OrderOnchainConstraint {
|
|
39
|
+
name: string;
|
|
40
|
+
value: string | number;
|
|
41
|
+
description: string;
|
|
42
|
+
}
|
|
43
|
+
export interface OrderRenderingHints {
|
|
44
|
+
include_puzzle_template: boolean;
|
|
45
|
+
include_risk_details: boolean;
|
|
46
|
+
include_questions: boolean;
|
|
47
|
+
include_immutability_warning: boolean;
|
|
48
|
+
include_irreversible_warning: boolean;
|
|
49
|
+
include_snapshot_warning: boolean;
|
|
50
|
+
include_claimed_by_warning: boolean;
|
|
51
|
+
max_length: number;
|
|
52
|
+
}
|
|
53
|
+
export interface BuildOrderContextInput {
|
|
54
|
+
mode: OrderInjectionMode;
|
|
55
|
+
intent?: string;
|
|
56
|
+
order_json?: OrderJsonForConfirm;
|
|
57
|
+
stakeholder?: OrderStakeholderPerspective;
|
|
58
|
+
target_operation_field?: OrderScene["operation_field"];
|
|
59
|
+
target_permission_layer?: OrderPermissionLayer;
|
|
60
|
+
max_length?: number;
|
|
61
|
+
current_state?: OrderRiskCheckContext;
|
|
62
|
+
}
|
|
63
|
+
export declare function buildOrderContext(input: BuildOrderContextInput): OrderContextBundle;
|
|
64
|
+
export declare function buildPromptFromOrderContext(bundle: OrderContextBundle): string;
|
|
65
|
+
export declare function getOrderContextSummary(bundle: OrderContextBundle): string;
|
|
66
|
+
export declare function getStakeholderAdvice(stakeholder: OrderStakeholderPerspective, scene?: OrderScene): string[];
|