@wowok/agent-mcp 2.4.3 → 2.5.1
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 +1412 -6
- package/dist/schema/project/index.js +441 -3
- 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 +1809 -336
- 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 +578 -579
- 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 +0 -514
- package/dist/schemas/onchain_operations_permission.schema.json +0 -514
- package/dist/schemas/onchain_operations_personal.schema.json +0 -514
- 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 +918 -0
- package/dist/schemas/project_operation.schema.json +474 -3
- 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 +262 -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 +96 -25
- 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,280 @@
|
|
|
1
|
+
import { assessServiceRisks, assessMachineRisks, assessAllocationRisks, assessTreasuryRisks, assessArbitrationRisks, assessRewardRisks, assessProgressRisks, assessOrderRisks, assessGuardRisks, checkContactRisks, checkResourceRisks, checkPaymentRisks, checkArbRisks, checkPersonalRisks, checkUtilRisks, checkRegistrarRisks, checkBridgeRisks, checkProofRisks, checkRepositoryRisks, checkDemandRisks, } from "../knowledge/index.js";
|
|
2
|
+
import { assessPermissionRisks } from "../knowledge/permission-risk.js";
|
|
3
|
+
const SEVERITY_ORDER = {
|
|
4
|
+
CRITICAL: 0,
|
|
5
|
+
HIGH: 1,
|
|
6
|
+
MEDIUM: 2,
|
|
7
|
+
LOW: 3,
|
|
8
|
+
INFO: 4,
|
|
9
|
+
};
|
|
10
|
+
const ALL_SEVERITIES = ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"];
|
|
11
|
+
function normalizeSeverity(level) {
|
|
12
|
+
if (typeof level !== "string")
|
|
13
|
+
return "INFO";
|
|
14
|
+
const upper = level.toUpperCase();
|
|
15
|
+
return ALL_SEVERITIES.includes(upper) ? upper : "INFO";
|
|
16
|
+
}
|
|
17
|
+
function extractRiskId(risk, fallback) {
|
|
18
|
+
if (!risk || typeof risk !== "object")
|
|
19
|
+
return fallback;
|
|
20
|
+
return String(risk.id ?? risk.risk_rule_id ?? risk.rule_id ?? fallback);
|
|
21
|
+
}
|
|
22
|
+
function extractRiskMessage(risk) {
|
|
23
|
+
if (!risk || typeof risk !== "object")
|
|
24
|
+
return "(no message)";
|
|
25
|
+
return String(risk.title ?? risk.message ?? risk.description ?? risk.trigger ?? "(no message)");
|
|
26
|
+
}
|
|
27
|
+
function extractFixSuggestion(risk) {
|
|
28
|
+
if (!risk || typeof risk !== "object")
|
|
29
|
+
return "";
|
|
30
|
+
return String(risk.mitigation ?? risk.fix_suggestion ?? risk.suggestion ?? "");
|
|
31
|
+
}
|
|
32
|
+
function toAggregatedRisk(risk, objectType, entryId) {
|
|
33
|
+
return {
|
|
34
|
+
risk_rule_id: extractRiskId(risk, `R-${objectType.toUpperCase()}-?`),
|
|
35
|
+
object_type: objectType,
|
|
36
|
+
entry_id: entryId,
|
|
37
|
+
severity: normalizeSeverity(risk?.level ?? risk?.severity),
|
|
38
|
+
message: extractRiskMessage(risk),
|
|
39
|
+
fix_suggestion: extractFixSuggestion(risk),
|
|
40
|
+
details: risk?.evidence
|
|
41
|
+
? { field_path: String(risk.evidence) }
|
|
42
|
+
: undefined,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function isL1L2Object(objType) {
|
|
46
|
+
return [
|
|
47
|
+
"service", "machine", "allocation", "treasury", "arb",
|
|
48
|
+
"reward", "progress", "order", "permission", "guard",
|
|
49
|
+
].includes(objType);
|
|
50
|
+
}
|
|
51
|
+
function buildL1L2Dispatch() {
|
|
52
|
+
const safeAssess = (puzzle, fn) => {
|
|
53
|
+
try {
|
|
54
|
+
const ctx = puzzle ?? {};
|
|
55
|
+
const result = fn(ctx);
|
|
56
|
+
if (Array.isArray(result))
|
|
57
|
+
return result;
|
|
58
|
+
if (result && typeof result === "object") {
|
|
59
|
+
const r = result.risks;
|
|
60
|
+
if (Array.isArray(r))
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
service: { assess: (p) => safeAssess(p, assessServiceRisks) },
|
|
71
|
+
machine: { assess: (p) => safeAssess(p, (ctx) => assessMachineRisks(ctx, {})) },
|
|
72
|
+
allocation: { assess: (p) => safeAssess(p, assessAllocationRisks) },
|
|
73
|
+
treasury: { assess: (p) => safeAssess(p, assessTreasuryRisks) },
|
|
74
|
+
arb: { assess: (p) => safeAssess(p, assessArbitrationRisks) },
|
|
75
|
+
reward: { assess: (p) => safeAssess(p, (ctx) => assessRewardRisks(ctx)) },
|
|
76
|
+
progress: { assess: (p) => safeAssess(p, (ctx) => assessProgressRisks(ctx)) },
|
|
77
|
+
order: { assess: (p) => safeAssess(p, assessOrderRisks) },
|
|
78
|
+
permission: { assess: (p) => safeAssess(p, assessPermissionRisks) },
|
|
79
|
+
guard: {
|
|
80
|
+
assess: (p) => {
|
|
81
|
+
try {
|
|
82
|
+
const result = assessGuardRisks({
|
|
83
|
+
table: [],
|
|
84
|
+
root: undefined,
|
|
85
|
+
});
|
|
86
|
+
if (Array.isArray(result))
|
|
87
|
+
return result;
|
|
88
|
+
if (result && typeof result === "object") {
|
|
89
|
+
const r = result.risks;
|
|
90
|
+
if (Array.isArray(r))
|
|
91
|
+
return r;
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function buildL3Dispatch() {
|
|
103
|
+
const safeCheck = (puzzle, fn) => {
|
|
104
|
+
try {
|
|
105
|
+
const ctx = puzzle ?? {};
|
|
106
|
+
const result = fn(ctx);
|
|
107
|
+
if (Array.isArray(result))
|
|
108
|
+
return result;
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
contact: { check: (p) => safeCheck(p, checkContactRisks) },
|
|
117
|
+
resource: { check: (p) => safeCheck(p, checkResourceRisks) },
|
|
118
|
+
payment: { check: (p) => safeCheck(p, checkPaymentRisks) },
|
|
119
|
+
arb: { check: (p) => safeCheck(p, checkArbRisks) },
|
|
120
|
+
personal: { check: (p) => safeCheck(p, checkPersonalRisks) },
|
|
121
|
+
util: { check: (p) => safeCheck(p, checkUtilRisks) },
|
|
122
|
+
registrar: { check: (p) => safeCheck(p, checkRegistrarRisks) },
|
|
123
|
+
bridge: { check: (p) => safeCheck(p, checkBridgeRisks) },
|
|
124
|
+
proof: { check: (p) => safeCheck(p, checkProofRisks) },
|
|
125
|
+
repository: { check: (p) => safeCheck(p, checkRepositoryRisks) },
|
|
126
|
+
demand: { check: (p) => safeCheck(p, checkDemandRisks) },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export function aggregateProjectRisks(input) {
|
|
130
|
+
const warnings = [];
|
|
131
|
+
if (!input || !input.project_prefix) {
|
|
132
|
+
warnings.push("input.project_prefix is empty");
|
|
133
|
+
}
|
|
134
|
+
const puzzles = input?.puzzles ?? {};
|
|
135
|
+
const findings = [];
|
|
136
|
+
const l1l2 = buildL1L2Dispatch();
|
|
137
|
+
const l3 = buildL3Dispatch();
|
|
138
|
+
for (const [objTypeStr, entry] of Object.entries(puzzles)) {
|
|
139
|
+
const objType = objTypeStr;
|
|
140
|
+
const entryId = `${input.project_prefix ?? "project"}_${objType}`;
|
|
141
|
+
const puzzle = entry?.puzzle;
|
|
142
|
+
if (isL1L2Object(objType)) {
|
|
143
|
+
const d = l1l2[objType];
|
|
144
|
+
if (!d) {
|
|
145
|
+
warnings.push(`No L1/L2 risk dispatcher for '${objType}'`);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const rawRisks = d.assess(puzzle);
|
|
149
|
+
for (const r of rawRisks) {
|
|
150
|
+
findings.push(toAggregatedRisk(r, objType, entryId));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const d = l3[objType];
|
|
155
|
+
if (!d) {
|
|
156
|
+
warnings.push(`No L3 risk dispatcher for '${objType}'`);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const rawRisks = d.check(puzzle);
|
|
160
|
+
for (const r of rawRisks) {
|
|
161
|
+
findings.push(toAggregatedRisk(r, objType, entryId));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
sortFindings(findings);
|
|
166
|
+
const severity_summary = countBySeverity(findings);
|
|
167
|
+
const threshold = input.severity_threshold ?? "HIGH";
|
|
168
|
+
const status = determineStatus(severity_summary, threshold, input.user_confirmed_high_risks ?? [], findings);
|
|
169
|
+
let pending_confirmations;
|
|
170
|
+
if (status === "RISK_PENDING_CONFIRM") {
|
|
171
|
+
pending_confirmations = findings
|
|
172
|
+
.filter((f) => f.severity === "HIGH")
|
|
173
|
+
.filter((f) => !(input.user_confirmed_high_risks ?? []).includes(f.risk_rule_id))
|
|
174
|
+
.map((f) => ({
|
|
175
|
+
risk_rule_id: f.risk_rule_id,
|
|
176
|
+
description: f.message,
|
|
177
|
+
fix_suggestion: f.fix_suggestion,
|
|
178
|
+
object_type: f.object_type,
|
|
179
|
+
entry_id: f.entry_id,
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
namespace: {
|
|
184
|
+
prefix: input.project_prefix ?? "",
|
|
185
|
+
version: input.version ?? "",
|
|
186
|
+
industry: input.industry ?? "general",
|
|
187
|
+
},
|
|
188
|
+
findings,
|
|
189
|
+
severity_summary,
|
|
190
|
+
status,
|
|
191
|
+
pending_confirmations,
|
|
192
|
+
calibrated_at: Date.now(),
|
|
193
|
+
warnings,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export function sortFindings(findings) {
|
|
197
|
+
return findings.sort((a, b) => {
|
|
198
|
+
const sevDiff = SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity];
|
|
199
|
+
if (sevDiff !== 0)
|
|
200
|
+
return sevDiff;
|
|
201
|
+
if (a.object_type !== b.object_type) {
|
|
202
|
+
return a.object_type.localeCompare(b.object_type);
|
|
203
|
+
}
|
|
204
|
+
return a.risk_rule_id.localeCompare(b.risk_rule_id);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
export function countBySeverity(findings) {
|
|
208
|
+
const counts = {
|
|
209
|
+
CRITICAL: 0,
|
|
210
|
+
HIGH: 0,
|
|
211
|
+
MEDIUM: 0,
|
|
212
|
+
LOW: 0,
|
|
213
|
+
INFO: 0,
|
|
214
|
+
};
|
|
215
|
+
for (const f of findings) {
|
|
216
|
+
counts[f.severity]++;
|
|
217
|
+
}
|
|
218
|
+
return counts;
|
|
219
|
+
}
|
|
220
|
+
export function determineStatus(severity_summary, threshold, user_confirmed_high_risks, findings) {
|
|
221
|
+
if (severity_summary.CRITICAL > 0)
|
|
222
|
+
return "RISK_BLOCKED";
|
|
223
|
+
const thresholdLevel = SEVERITY_ORDER[threshold];
|
|
224
|
+
if (severity_summary.HIGH > 0 && thresholdLevel <= SEVERITY_ORDER.HIGH) {
|
|
225
|
+
const unconfirmed = findings.filter((f) => f.severity === "HIGH" && !user_confirmed_high_risks.includes(f.risk_rule_id));
|
|
226
|
+
if (unconfirmed.length > 0)
|
|
227
|
+
return "RISK_PENDING_CONFIRM";
|
|
228
|
+
}
|
|
229
|
+
if (severity_summary.MEDIUM > 0 && thresholdLevel <= SEVERITY_ORDER.MEDIUM) {
|
|
230
|
+
return "RISK_BLOCKED";
|
|
231
|
+
}
|
|
232
|
+
if (severity_summary.LOW > 0 && thresholdLevel <= SEVERITY_ORDER.LOW) {
|
|
233
|
+
return "RISK_BLOCKED";
|
|
234
|
+
}
|
|
235
|
+
return "RISK_PASSED";
|
|
236
|
+
}
|
|
237
|
+
export function getCriticalRisks(result) {
|
|
238
|
+
if (!result?.findings)
|
|
239
|
+
return [];
|
|
240
|
+
return result.findings.filter((f) => f.severity === "CRITICAL");
|
|
241
|
+
}
|
|
242
|
+
export function summarizeRiskReport(result) {
|
|
243
|
+
if (!result)
|
|
244
|
+
return "(no result)";
|
|
245
|
+
const lines = [];
|
|
246
|
+
lines.push(`# Risk Aggregation Report`);
|
|
247
|
+
lines.push("");
|
|
248
|
+
lines.push(`- Project: ${result.namespace.prefix}_${result.namespace.version}`);
|
|
249
|
+
lines.push(`- Status: ${result.status}`);
|
|
250
|
+
lines.push(`- Calibrated at: ${new Date(result.calibrated_at).toISOString()}`);
|
|
251
|
+
lines.push("");
|
|
252
|
+
lines.push("## Severity Summary");
|
|
253
|
+
lines.push("");
|
|
254
|
+
lines.push("| Severity | Count |");
|
|
255
|
+
lines.push("|----------|-------|");
|
|
256
|
+
for (const sev of ALL_SEVERITIES) {
|
|
257
|
+
lines.push(`| ${sev} | ${result.severity_summary[sev] ?? 0} |`);
|
|
258
|
+
}
|
|
259
|
+
lines.push("");
|
|
260
|
+
if (result.findings.length === 0) {
|
|
261
|
+
lines.push("No risks found.");
|
|
262
|
+
return lines.join("\n");
|
|
263
|
+
}
|
|
264
|
+
lines.push("## Findings (sorted by severity)");
|
|
265
|
+
lines.push("");
|
|
266
|
+
for (const f of result.findings) {
|
|
267
|
+
lines.push(`- **[${f.severity}] ${f.risk_rule_id}** (${f.object_type} / ${f.entry_id})`);
|
|
268
|
+
lines.push(` - ${f.message}`);
|
|
269
|
+
if (f.fix_suggestion) {
|
|
270
|
+
lines.push(` - Fix: ${f.fix_suggestion}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (result.warnings.length > 0) {
|
|
274
|
+
lines.push("");
|
|
275
|
+
lines.push("## Warnings");
|
|
276
|
+
for (const w of result.warnings)
|
|
277
|
+
lines.push(`- ${w}`);
|
|
278
|
+
}
|
|
279
|
+
return lines.join("\n");
|
|
280
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { ProjectObjectType } from "./namespace.js";
|
|
2
|
+
export type SubstepNetwork = "testnet" | "mainnet";
|
|
3
|
+
export type SubstepStatus = "PENDING" | "SUCCESS" | "FAILED" | "SKIPPED";
|
|
4
|
+
export interface OutputRef {
|
|
5
|
+
substep_id: string;
|
|
6
|
+
field_path: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SubstepRecord {
|
|
9
|
+
step_id: string;
|
|
10
|
+
parent_step: string;
|
|
11
|
+
object_type: ProjectObjectType;
|
|
12
|
+
entry_id: string;
|
|
13
|
+
operation_type: string;
|
|
14
|
+
network: SubstepNetwork;
|
|
15
|
+
input: {
|
|
16
|
+
data: Record<string, unknown>;
|
|
17
|
+
input_refs: string[];
|
|
18
|
+
};
|
|
19
|
+
output?: {
|
|
20
|
+
object_id?: string;
|
|
21
|
+
tx_digest?: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
timestamp: number;
|
|
25
|
+
status: SubstepStatus;
|
|
26
|
+
failure_reason?: string;
|
|
27
|
+
dependencies: {
|
|
28
|
+
input_refs: string[];
|
|
29
|
+
output_refs: OutputRef[];
|
|
30
|
+
};
|
|
31
|
+
retry_info?: {
|
|
32
|
+
original_step_id: string;
|
|
33
|
+
retry_count: number;
|
|
34
|
+
retry_reason: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface SubstepEdge {
|
|
38
|
+
source: string;
|
|
39
|
+
target: string;
|
|
40
|
+
field_path: string;
|
|
41
|
+
}
|
|
42
|
+
export interface SubstepDAG {
|
|
43
|
+
namespace: {
|
|
44
|
+
prefix: string;
|
|
45
|
+
version: string;
|
|
46
|
+
};
|
|
47
|
+
network: SubstepNetwork;
|
|
48
|
+
substeps: SubstepRecord[];
|
|
49
|
+
edges: SubstepEdge[];
|
|
50
|
+
topological_order: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface DanglingInput {
|
|
53
|
+
substep_id: string;
|
|
54
|
+
missing_ref: string;
|
|
55
|
+
field_path: string;
|
|
56
|
+
}
|
|
57
|
+
export interface CircularRef {
|
|
58
|
+
cycle: string[];
|
|
59
|
+
}
|
|
60
|
+
export interface MissingOutput {
|
|
61
|
+
substep_id: string;
|
|
62
|
+
expected_field: string;
|
|
63
|
+
dependent_substeps: string[];
|
|
64
|
+
}
|
|
65
|
+
export interface CrossStepBreak {
|
|
66
|
+
source_step: string;
|
|
67
|
+
target_step: string;
|
|
68
|
+
missing_field: string;
|
|
69
|
+
}
|
|
70
|
+
export interface StepTraceDetail {
|
|
71
|
+
parent_step: string;
|
|
72
|
+
total_substeps: number;
|
|
73
|
+
successful: number;
|
|
74
|
+
failed: number;
|
|
75
|
+
pending: number;
|
|
76
|
+
skipped: number;
|
|
77
|
+
substep_ids: string[];
|
|
78
|
+
}
|
|
79
|
+
export interface SubstepTraceInput {
|
|
80
|
+
project_prefix: string;
|
|
81
|
+
version: string;
|
|
82
|
+
network: SubstepNetwork;
|
|
83
|
+
substeps: SubstepRecord[];
|
|
84
|
+
edges?: SubstepEdge[];
|
|
85
|
+
}
|
|
86
|
+
export interface SubstepTraceResult {
|
|
87
|
+
namespace: {
|
|
88
|
+
prefix: string;
|
|
89
|
+
version: string;
|
|
90
|
+
};
|
|
91
|
+
network: SubstepNetwork;
|
|
92
|
+
coherent: boolean;
|
|
93
|
+
dangling_inputs: DanglingInput[];
|
|
94
|
+
circular_refs: CircularRef[];
|
|
95
|
+
missing_outputs: MissingOutput[];
|
|
96
|
+
cross_step_breaks: CrossStepBreak[];
|
|
97
|
+
step_details: StepTraceDetail[];
|
|
98
|
+
topological_order: string[];
|
|
99
|
+
d10_check: D10CheckResult;
|
|
100
|
+
}
|
|
101
|
+
export interface D10CheckResult {
|
|
102
|
+
check_id: "D-10";
|
|
103
|
+
description: string;
|
|
104
|
+
status: "PASS" | "FAIL" | "WARN";
|
|
105
|
+
notes: string[];
|
|
106
|
+
}
|
|
107
|
+
export declare function detectDanglingInputs(substeps: SubstepRecord[], edges?: SubstepEdge[]): DanglingInput[];
|
|
108
|
+
export declare function detectCircularRefs(substeps: SubstepRecord[], edges: SubstepEdge[]): CircularRef[];
|
|
109
|
+
export declare function detectMissingOutputs(substeps: SubstepRecord[]): MissingOutput[];
|
|
110
|
+
export declare function detectCrossStepBreaks(substeps: SubstepRecord[], edges: SubstepEdge[]): CrossStepBreak[];
|
|
111
|
+
export declare function traceSubsteps(input: SubstepTraceInput): SubstepTraceResult;
|
|
112
|
+
export declare class SubstepTracer {
|
|
113
|
+
private records;
|
|
114
|
+
private namespace;
|
|
115
|
+
private network;
|
|
116
|
+
constructor(prefix: string, version: string, network: SubstepNetwork);
|
|
117
|
+
record(rec: SubstepRecord): void;
|
|
118
|
+
getTrace(): SubstepRecord[];
|
|
119
|
+
updateStatus(step_id: string, status: SubstepStatus, output?: Record<string, unknown>, failure_reason?: string): void;
|
|
120
|
+
getDAG(): SubstepDAG;
|
|
121
|
+
checkCoherence(): SubstepTraceResult;
|
|
122
|
+
toJSON(): {
|
|
123
|
+
namespace: {
|
|
124
|
+
prefix: string;
|
|
125
|
+
version: string;
|
|
126
|
+
};
|
|
127
|
+
network: SubstepNetwork;
|
|
128
|
+
substeps: SubstepRecord[];
|
|
129
|
+
};
|
|
130
|
+
}
|