@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,173 @@
|
|
|
1
|
+
import { USER_DEFINED_PERM_INDEX_START, MAX_ENTITY_COUNT, MAX_PERM_FOR_ENTITY, MAX_ADMIN_COUNT, } from "@wowok/wowok";
|
|
2
|
+
import { isBuiltinPermission, } from "./permission-ledger.js";
|
|
3
|
+
export function initPuzzleFromIntent(intent) {
|
|
4
|
+
const puzzle = {};
|
|
5
|
+
if (intent.action || intent.rule_sentence) {
|
|
6
|
+
puzzle.intent = {
|
|
7
|
+
action: intent.action ?? "create",
|
|
8
|
+
target_object: intent.target_object,
|
|
9
|
+
rule_sentence: intent.rule_sentence ?? "",
|
|
10
|
+
failure_conditions: intent.failure_conditions ?? [],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
puzzle.constraints = {
|
|
14
|
+
F_P_01_custom_index_ge_1000: true,
|
|
15
|
+
F_P_02_entity_count_le_1000: true,
|
|
16
|
+
F_P_03_perm_count_per_entity_le_1000: true,
|
|
17
|
+
F_P_04_admin_count_le_500: true,
|
|
18
|
+
F_P_05_owner_address_valid: true,
|
|
19
|
+
F_P_06_owner_only_for_assert_owner: true,
|
|
20
|
+
F_P_07_admin_only_for_assert_admin: true,
|
|
21
|
+
};
|
|
22
|
+
return puzzle;
|
|
23
|
+
}
|
|
24
|
+
export function checkPuzzleCompleteness(puzzle) {
|
|
25
|
+
const missing = [];
|
|
26
|
+
const missing_details = [];
|
|
27
|
+
if (!puzzle.intent) {
|
|
28
|
+
missing.push("A");
|
|
29
|
+
missing_details.push({ dimension: "A", reason: "Intent not specified (action + rule_sentence)" });
|
|
30
|
+
}
|
|
31
|
+
else if (!puzzle.intent.rule_sentence) {
|
|
32
|
+
missing.push("A");
|
|
33
|
+
missing_details.push({ dimension: "A", reason: "rule_sentence is empty" });
|
|
34
|
+
}
|
|
35
|
+
if (!puzzle.binding) {
|
|
36
|
+
missing.push("B");
|
|
37
|
+
missing_details.push({ dimension: "B", reason: "Binding not specified (owner + admins)" });
|
|
38
|
+
}
|
|
39
|
+
else if (!puzzle.binding.owner) {
|
|
40
|
+
missing.push("B");
|
|
41
|
+
missing_details.push({ dimension: "B", reason: "owner address missing" });
|
|
42
|
+
}
|
|
43
|
+
if (!puzzle.data_source && puzzle.intent?.action === "create") {
|
|
44
|
+
missing.push("C");
|
|
45
|
+
missing_details.push({ dimension: "C", reason: "Data source not specified (entities + permissions)" });
|
|
46
|
+
}
|
|
47
|
+
if (!puzzle.operations) {
|
|
48
|
+
missing.push("D");
|
|
49
|
+
missing_details.push({ dimension: "D", reason: "Operations not enumerated" });
|
|
50
|
+
}
|
|
51
|
+
if (!puzzle.logic) {
|
|
52
|
+
missing.push("E");
|
|
53
|
+
missing_details.push({ dimension: "E", reason: "Logic flow not defined" });
|
|
54
|
+
}
|
|
55
|
+
if (!puzzle.constraints) {
|
|
56
|
+
missing.push("F");
|
|
57
|
+
missing_details.push({ dimension: "F", reason: "Constraints not checked" });
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
dimensions: ["A", "B", "C", "D", "E", "F"],
|
|
61
|
+
missing,
|
|
62
|
+
missing_details,
|
|
63
|
+
complete: missing.length === 0,
|
|
64
|
+
next_step: missing.length === 0
|
|
65
|
+
? "Puzzle complete — ready for confirmation text generation"
|
|
66
|
+
: `Next: complete dimension ${missing[0]} — ${missing_details[0].reason}`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function validateConstraints(puzzle) {
|
|
70
|
+
const violations = [];
|
|
71
|
+
if (!puzzle.data_source)
|
|
72
|
+
return violations;
|
|
73
|
+
for (const entity of puzzle.data_source.entities) {
|
|
74
|
+
for (const idx of entity.permission_indexes) {
|
|
75
|
+
if (idx < USER_DEFINED_PERM_INDEX_START && !isBuiltinPermission(idx)) {
|
|
76
|
+
violations.push({
|
|
77
|
+
constraint_id: "F-P-01",
|
|
78
|
+
severity: "CRITICAL",
|
|
79
|
+
message: `Permission index ${idx} for entity ${entity.address} is < ${USER_DEFINED_PERM_INDEX_START} and not a builtin permission`,
|
|
80
|
+
current_value: idx,
|
|
81
|
+
limit: USER_DEFINED_PERM_INDEX_START,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (puzzle.data_source.entities.length > MAX_ENTITY_COUNT) {
|
|
87
|
+
violations.push({
|
|
88
|
+
constraint_id: "F-P-02",
|
|
89
|
+
severity: "HIGH",
|
|
90
|
+
message: `Entity count ${puzzle.data_source.entities.length} exceeds MAX_ENTITY_COUNT ${MAX_ENTITY_COUNT}`,
|
|
91
|
+
current_value: puzzle.data_source.entities.length,
|
|
92
|
+
limit: MAX_ENTITY_COUNT,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
for (const entity of puzzle.data_source.entities) {
|
|
96
|
+
if (entity.permission_indexes.length > MAX_PERM_FOR_ENTITY) {
|
|
97
|
+
violations.push({
|
|
98
|
+
constraint_id: "F-P-03",
|
|
99
|
+
severity: "HIGH",
|
|
100
|
+
message: `Entity ${entity.address} has ${entity.permission_indexes.length} permissions, exceeds MAX_PERM_FOR_ENTITY ${MAX_PERM_FOR_ENTITY}`,
|
|
101
|
+
current_value: entity.permission_indexes.length,
|
|
102
|
+
limit: MAX_PERM_FOR_ENTITY,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (puzzle.binding && puzzle.binding.admins.length > MAX_ADMIN_COUNT) {
|
|
107
|
+
violations.push({
|
|
108
|
+
constraint_id: "F-P-04",
|
|
109
|
+
severity: "HIGH",
|
|
110
|
+
message: `Admin count ${puzzle.binding.admins.length} exceeds MAX_ADMIN_COUNT ${MAX_ADMIN_COUNT}`,
|
|
111
|
+
current_value: puzzle.binding.admins.length,
|
|
112
|
+
limit: MAX_ADMIN_COUNT,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return violations;
|
|
116
|
+
}
|
|
117
|
+
export function generateConfirmationText(puzzle) {
|
|
118
|
+
const lines = [];
|
|
119
|
+
lines.push("═══ Permission Confirmation ═══");
|
|
120
|
+
lines.push("");
|
|
121
|
+
if (puzzle.intent) {
|
|
122
|
+
lines.push(`Action: ${puzzle.intent.action}`);
|
|
123
|
+
if (puzzle.intent.target_object)
|
|
124
|
+
lines.push(`Target: ${puzzle.intent.target_object}`);
|
|
125
|
+
lines.push(`Rule: ${puzzle.intent.rule_sentence}`);
|
|
126
|
+
if (puzzle.intent.failure_conditions.length > 0) {
|
|
127
|
+
lines.push("Failure conditions:");
|
|
128
|
+
for (const fc of puzzle.intent.failure_conditions)
|
|
129
|
+
lines.push(` - ${fc}`);
|
|
130
|
+
}
|
|
131
|
+
lines.push("");
|
|
132
|
+
}
|
|
133
|
+
if (puzzle.binding) {
|
|
134
|
+
lines.push("─ Binding ──────────────");
|
|
135
|
+
lines.push(`Owner: ${puzzle.binding.owner}`);
|
|
136
|
+
lines.push(`Admins (${puzzle.binding.admins.length}): ${puzzle.binding.admins.join(", ")}`);
|
|
137
|
+
if (puzzle.binding.um !== undefined) {
|
|
138
|
+
lines.push(`UM: ${puzzle.binding.um ?? "(none)"}`);
|
|
139
|
+
}
|
|
140
|
+
if (puzzle.binding.applied_to && puzzle.binding.applied_to.length > 0) {
|
|
141
|
+
lines.push(`Applied to: ${puzzle.binding.applied_to.join(", ")}`);
|
|
142
|
+
}
|
|
143
|
+
lines.push("");
|
|
144
|
+
}
|
|
145
|
+
if (puzzle.data_source) {
|
|
146
|
+
lines.push("─ Data Source ──────────────");
|
|
147
|
+
lines.push(`Entities: ${puzzle.data_source.entities.length}`);
|
|
148
|
+
for (const e of puzzle.data_source.entities) {
|
|
149
|
+
lines.push(` ${e.address} (${e.type}): indexes [${e.permission_indexes.join(", ")}]`);
|
|
150
|
+
}
|
|
151
|
+
if (puzzle.data_source.custom_permissions_defined.length > 0) {
|
|
152
|
+
lines.push("Custom permissions:");
|
|
153
|
+
for (const cp of puzzle.data_source.custom_permissions_defined) {
|
|
154
|
+
lines.push(` [${cp.index}] ${cp.name}: ${cp.description}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
lines.push("");
|
|
158
|
+
}
|
|
159
|
+
if (puzzle.operations && puzzle.operations.operations.length > 0) {
|
|
160
|
+
lines.push("─ Operations ──────────────");
|
|
161
|
+
for (const op of puzzle.operations.operations)
|
|
162
|
+
lines.push(` - ${JSON.stringify(op)}`);
|
|
163
|
+
lines.push("");
|
|
164
|
+
}
|
|
165
|
+
const violations = validateConstraints(puzzle);
|
|
166
|
+
if (violations.length > 0) {
|
|
167
|
+
lines.push("─ Constraint Violations ──────────────");
|
|
168
|
+
for (const v of violations)
|
|
169
|
+
lines.push(` [${v.severity}] ${v.constraint_id}: ${v.message}`);
|
|
170
|
+
lines.push("");
|
|
171
|
+
}
|
|
172
|
+
return lines.join("\n");
|
|
173
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type PermissionScene } from "./permission-ledger.js";
|
|
2
|
+
export type RiskLevel = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
|
|
3
|
+
export type RiskCategory = "structural" | "semantic" | "authority" | "lifecycle" | "cross_object";
|
|
4
|
+
export interface PermissionRisk {
|
|
5
|
+
id: string;
|
|
6
|
+
level: RiskLevel;
|
|
7
|
+
category: RiskCategory;
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
affected_stakeholders: PermissionStakeholder[];
|
|
11
|
+
scenario: string;
|
|
12
|
+
mitigation: string;
|
|
13
|
+
evidence?: string;
|
|
14
|
+
}
|
|
15
|
+
export type PermissionStakeholder = "owner" | "admin" | "entity" | "user" | "system";
|
|
16
|
+
export interface RiskRule {
|
|
17
|
+
id: string;
|
|
18
|
+
category: RiskCategory;
|
|
19
|
+
trigger: string;
|
|
20
|
+
check: (ctx: RiskCheckContext) => PermissionRisk | null;
|
|
21
|
+
}
|
|
22
|
+
export interface RiskCheckContext {
|
|
23
|
+
object?: string | null;
|
|
24
|
+
description?: string;
|
|
25
|
+
admin?: {
|
|
26
|
+
op: "add" | "remove" | "set";
|
|
27
|
+
addresses: string[];
|
|
28
|
+
};
|
|
29
|
+
table?: {
|
|
30
|
+
op: "add perm by index" | "set perm by index" | "remove perm by index";
|
|
31
|
+
index: number;
|
|
32
|
+
entity: string[];
|
|
33
|
+
} | {
|
|
34
|
+
op: "add perm by entity" | "set perm by entity" | "remove perm by entity";
|
|
35
|
+
entity: string;
|
|
36
|
+
index: number[];
|
|
37
|
+
};
|
|
38
|
+
entity?: {
|
|
39
|
+
op: "swap" | "replace" | "copy";
|
|
40
|
+
entity1: string;
|
|
41
|
+
entity2: string;
|
|
42
|
+
} | {
|
|
43
|
+
op: "del";
|
|
44
|
+
entity: string;
|
|
45
|
+
};
|
|
46
|
+
remark?: {
|
|
47
|
+
op: "set";
|
|
48
|
+
index: number;
|
|
49
|
+
remark: string;
|
|
50
|
+
} | {
|
|
51
|
+
op: "remove";
|
|
52
|
+
index: number;
|
|
53
|
+
} | {
|
|
54
|
+
op: "clear";
|
|
55
|
+
};
|
|
56
|
+
apply?: string[];
|
|
57
|
+
builder?: string;
|
|
58
|
+
um?: string | null;
|
|
59
|
+
current_admin_count?: number;
|
|
60
|
+
current_entity_count?: number;
|
|
61
|
+
target_objects_types?: string[];
|
|
62
|
+
}
|
|
63
|
+
export declare const PERMISSION_RISK_VERSION = "1.0.0";
|
|
64
|
+
export declare function getAllRiskRules(): RiskRule[];
|
|
65
|
+
export declare function getRiskRulesCount(): number;
|
|
66
|
+
export declare function getRiskRulesByCategory(category: RiskCategory): RiskRule[];
|
|
67
|
+
export interface PermissionRiskAssessment {
|
|
68
|
+
summary: string;
|
|
69
|
+
scene?: PermissionScene;
|
|
70
|
+
risks: PermissionRisk[];
|
|
71
|
+
overall_risk: RiskLevel;
|
|
72
|
+
risks_by_category: Partial<Record<RiskCategory, number>>;
|
|
73
|
+
stakeholder_advice: Partial<Record<PermissionStakeholder, string[]>>;
|
|
74
|
+
needs_human_review: boolean;
|
|
75
|
+
}
|
|
76
|
+
export declare function assessPermissionRisks(ctx: RiskCheckContext): PermissionRiskAssessment;
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { USER_DEFINED_PERM_INDEX_START, MAX_ENTITY_COUNT, MAX_PERM_FOR_ENTITY, MAX_ADMIN_COUNT, } from "@wowok/wowok";
|
|
2
|
+
import { isBuiltinPermission, findSceneByPermissionIndex, } from "./permission-ledger.js";
|
|
3
|
+
const R_P_01 = {
|
|
4
|
+
id: "R-P-1-01",
|
|
5
|
+
category: "structural",
|
|
6
|
+
trigger: "Custom permission index < USER_DEFINED_PERM_INDEX_START (1000) and not builtin",
|
|
7
|
+
check: (ctx) => {
|
|
8
|
+
if (!ctx.table)
|
|
9
|
+
return null;
|
|
10
|
+
if ("index" in ctx.table && typeof ctx.table.index === "number") {
|
|
11
|
+
const idx = ctx.table.index;
|
|
12
|
+
if (idx < USER_DEFINED_PERM_INDEX_START && !isBuiltinPermission(idx)) {
|
|
13
|
+
return {
|
|
14
|
+
id: "R-P-1-01",
|
|
15
|
+
level: "CRITICAL",
|
|
16
|
+
category: "structural",
|
|
17
|
+
title: "Invalid permission index (< 1000 and not builtin)",
|
|
18
|
+
description: `Permission index ${idx} is below USER_DEFINED_PERM_INDEX_START (${USER_DEFINED_PERM_INDEX_START}) and not a builtin permission. Custom indexes must be >= 1000.`,
|
|
19
|
+
affected_stakeholders: ["owner", "admin", "system"],
|
|
20
|
+
scenario: "User defines a custom permission with index < 1000",
|
|
21
|
+
mitigation: `Use index >= ${USER_DEFINED_PERM_INDEX_START} for custom permissions, or use a builtin index if applicable`,
|
|
22
|
+
evidence: `index=${idx}`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const R_P_02 = {
|
|
30
|
+
id: "R-P-1-02",
|
|
31
|
+
category: "structural",
|
|
32
|
+
trigger: "Entity count exceeds MAX_ENTITY_COUNT (1000)",
|
|
33
|
+
check: (ctx) => {
|
|
34
|
+
const count = ctx.current_entity_count ?? 0;
|
|
35
|
+
if (count > MAX_ENTITY_COUNT) {
|
|
36
|
+
return {
|
|
37
|
+
id: "R-P-1-02",
|
|
38
|
+
level: "HIGH",
|
|
39
|
+
category: "structural",
|
|
40
|
+
title: "Entity count exceeds limit",
|
|
41
|
+
description: `Permission has ${count} entities, exceeds MAX_ENTITY_COUNT ${MAX_ENTITY_COUNT}`,
|
|
42
|
+
affected_stakeholders: ["owner", "admin"],
|
|
43
|
+
scenario: "Adding entities beyond the protocol limit",
|
|
44
|
+
mitigation: "Split into multiple Permission objects or remove inactive entities",
|
|
45
|
+
evidence: `entity_count=${count}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const R_P_03 = {
|
|
52
|
+
id: "R-P-1-03",
|
|
53
|
+
category: "structural",
|
|
54
|
+
trigger: "Per-entity permission count exceeds MAX_PERM_FOR_ENTITY (1000)",
|
|
55
|
+
check: (ctx) => {
|
|
56
|
+
if (ctx.table && "index" in ctx.table && Array.isArray(ctx.table.index)) {
|
|
57
|
+
if (ctx.table.index.length > MAX_PERM_FOR_ENTITY) {
|
|
58
|
+
return {
|
|
59
|
+
id: "R-P-1-03",
|
|
60
|
+
level: "HIGH",
|
|
61
|
+
category: "structural",
|
|
62
|
+
title: "Per-entity permission count exceeds limit",
|
|
63
|
+
description: `Entity ${ctx.table.entity} has ${ctx.table.index.length} permissions, exceeds MAX_PERM_FOR_ENTITY ${MAX_PERM_FOR_ENTITY}`,
|
|
64
|
+
affected_stakeholders: ["entity", "admin"],
|
|
65
|
+
scenario: "Granting too many permissions to one entity",
|
|
66
|
+
mitigation: "Consolidate similar permissions or split entity into multiple roles",
|
|
67
|
+
evidence: `perm_count=${ctx.table.index.length}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const R_P_04 = {
|
|
75
|
+
id: "R-P-1-04",
|
|
76
|
+
category: "structural",
|
|
77
|
+
trigger: "Admin count exceeds MAX_ADMIN_COUNT (500)",
|
|
78
|
+
check: (ctx) => {
|
|
79
|
+
if (ctx.admin) {
|
|
80
|
+
const newCount = ctx.admin.op === "add"
|
|
81
|
+
? (ctx.current_admin_count ?? 0) + ctx.admin.addresses.length
|
|
82
|
+
: ctx.admin.addresses.length;
|
|
83
|
+
if (newCount > MAX_ADMIN_COUNT) {
|
|
84
|
+
return {
|
|
85
|
+
id: "R-P-1-04",
|
|
86
|
+
level: "HIGH",
|
|
87
|
+
category: "structural",
|
|
88
|
+
title: "Admin count exceeds limit",
|
|
89
|
+
description: `Admin count would be ${newCount}, exceeds MAX_ADMIN_COUNT ${MAX_ADMIN_COUNT}`,
|
|
90
|
+
affected_stakeholders: ["owner", "admin"],
|
|
91
|
+
scenario: "Adding too many admins",
|
|
92
|
+
mitigation: "Remove inactive admins before adding new ones",
|
|
93
|
+
evidence: `admin_count=${newCount}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const R_P_2_01 = {
|
|
101
|
+
id: "R-P-2-01",
|
|
102
|
+
category: "semantic",
|
|
103
|
+
trigger: "Builtin permission index used outside its host object scene",
|
|
104
|
+
check: (ctx) => {
|
|
105
|
+
if (!ctx.table || !("index" in ctx.table) || typeof ctx.table.index !== "number")
|
|
106
|
+
return null;
|
|
107
|
+
const idx = ctx.table.index;
|
|
108
|
+
if (!isBuiltinPermission(idx))
|
|
109
|
+
return null;
|
|
110
|
+
const scene = findSceneByPermissionIndex(idx);
|
|
111
|
+
if (!scene)
|
|
112
|
+
return null;
|
|
113
|
+
if (ctx.target_objects_types && ctx.target_objects_types.length > 0) {
|
|
114
|
+
const mismatched = ctx.target_objects_types.filter(t => t !== scene.host_object);
|
|
115
|
+
if (mismatched.length > 0) {
|
|
116
|
+
return {
|
|
117
|
+
id: "R-P-2-01",
|
|
118
|
+
level: "HIGH",
|
|
119
|
+
category: "semantic",
|
|
120
|
+
title: "Permission index host object mismatch",
|
|
121
|
+
description: `Permission ${idx} (${scene.builtin_indexes.find(p => p.index === idx)?.name}) is for ${scene.host_object}, but apply targets: ${mismatched.join(", ")}`,
|
|
122
|
+
affected_stakeholders: ["owner", "admin"],
|
|
123
|
+
scenario: "Using SERVICE_* index on Machine object",
|
|
124
|
+
mitigation: `Use ${scene.host_object}-specific permission indexes for ${mismatched.join(", ")}`,
|
|
125
|
+
evidence: `index=${idx}, targets=${mismatched.join(",")}`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const R_P_2_02 = {
|
|
133
|
+
id: "R-P-2-02",
|
|
134
|
+
category: "semantic",
|
|
135
|
+
trigger: "Custom permission (>= 1000) without remark",
|
|
136
|
+
check: (ctx) => {
|
|
137
|
+
if (!ctx.table || !("index" in ctx.table) || typeof ctx.table.index !== "number")
|
|
138
|
+
return null;
|
|
139
|
+
const idx = ctx.table.index;
|
|
140
|
+
if (idx < USER_DEFINED_PERM_INDEX_START)
|
|
141
|
+
return null;
|
|
142
|
+
if (ctx.remark && ctx.remark.op === "set" && ctx.remark.index === idx)
|
|
143
|
+
return null;
|
|
144
|
+
return {
|
|
145
|
+
id: "R-P-2-02",
|
|
146
|
+
level: "LOW",
|
|
147
|
+
category: "semantic",
|
|
148
|
+
title: "Custom permission without remark",
|
|
149
|
+
description: `Custom permission ${idx} has no remark; future maintainers won't know its purpose`,
|
|
150
|
+
affected_stakeholders: ["admin"],
|
|
151
|
+
scenario: "Adding custom permission without documentation",
|
|
152
|
+
mitigation: `Add remark: { op: "set", index: ${idx}, remark: "<purpose>" }`,
|
|
153
|
+
evidence: `index=${idx}`,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
const R_P_3_01 = {
|
|
158
|
+
id: "R-P-3-01",
|
|
159
|
+
category: "authority",
|
|
160
|
+
trigger: "Permission over-concentration: owner is the only admin",
|
|
161
|
+
check: (ctx) => {
|
|
162
|
+
if (!ctx.admin || ctx.admin.op !== "set")
|
|
163
|
+
return null;
|
|
164
|
+
if (ctx.admin.addresses.length === 1) {
|
|
165
|
+
return {
|
|
166
|
+
id: "R-P-3-01",
|
|
167
|
+
level: "MEDIUM",
|
|
168
|
+
category: "authority",
|
|
169
|
+
title: "Permission over-concentration",
|
|
170
|
+
description: "Only one admin (likely owner); loss of owner key means permanent lockout",
|
|
171
|
+
affected_stakeholders: ["owner"],
|
|
172
|
+
scenario: "Single-admin Permission",
|
|
173
|
+
mitigation: "Add 1-2 backup admins with limited permission indexes",
|
|
174
|
+
evidence: `admin_count=1`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
const R_P_3_02 = {
|
|
181
|
+
id: "R-P-3-02",
|
|
182
|
+
category: "authority",
|
|
183
|
+
trigger: "Permission over-dispersion: admin count > 50",
|
|
184
|
+
check: (ctx) => {
|
|
185
|
+
if (!ctx.admin)
|
|
186
|
+
return null;
|
|
187
|
+
const count = ctx.admin.op === "set" ? ctx.admin.addresses.length : (ctx.current_admin_count ?? 0);
|
|
188
|
+
if (count > 50) {
|
|
189
|
+
return {
|
|
190
|
+
id: "R-P-3-02",
|
|
191
|
+
level: "MEDIUM",
|
|
192
|
+
category: "authority",
|
|
193
|
+
title: "Permission over-dispersion",
|
|
194
|
+
description: `${count} admins increases coordination cost and key-management risk`,
|
|
195
|
+
affected_stakeholders: ["owner", "admin"],
|
|
196
|
+
scenario: "Large admin committee",
|
|
197
|
+
mitigation: "Use multi-sig or hierarchical admin structure",
|
|
198
|
+
evidence: `admin_count=${count}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
const R_P_3_03 = {
|
|
205
|
+
id: "R-P-3-03",
|
|
206
|
+
category: "authority",
|
|
207
|
+
trigger: "UM is owner self-reference",
|
|
208
|
+
check: (ctx) => {
|
|
209
|
+
if (ctx.um === undefined || ctx.um === null)
|
|
210
|
+
return null;
|
|
211
|
+
if (ctx.builder && ctx.um === ctx.builder) {
|
|
212
|
+
return {
|
|
213
|
+
id: "R-P-3-03",
|
|
214
|
+
level: "MEDIUM",
|
|
215
|
+
category: "authority",
|
|
216
|
+
title: "UM is owner self-reference",
|
|
217
|
+
description: "Setting UM to owner address defeats separation of concerns",
|
|
218
|
+
affected_stakeholders: ["owner"],
|
|
219
|
+
scenario: "Owner delegates UM to self",
|
|
220
|
+
mitigation: "Use a separate Contact object address for UM",
|
|
221
|
+
evidence: `um=${ctx.um}`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
const R_P_4_01 = {
|
|
228
|
+
id: "R-P-4-01",
|
|
229
|
+
category: "lifecycle",
|
|
230
|
+
trigger: "Ownership transfer operation (builder field set)",
|
|
231
|
+
check: (ctx) => {
|
|
232
|
+
if (!ctx.builder)
|
|
233
|
+
return null;
|
|
234
|
+
return {
|
|
235
|
+
id: "R-P-4-01",
|
|
236
|
+
level: "HIGH",
|
|
237
|
+
category: "lifecycle",
|
|
238
|
+
title: "Ownership transfer — irreversible",
|
|
239
|
+
description: `Transferring Permission to ${ctx.builder}. Once executed, original owner loses ALL control permanently.`,
|
|
240
|
+
affected_stakeholders: ["owner"],
|
|
241
|
+
scenario: "Owner transfers Permission to new address",
|
|
242
|
+
mitigation: "1) Verify new owner address twice. 2) Export Permission JSON before transfer. 3) Coordinate with new owner to confirm receipt.",
|
|
243
|
+
evidence: `new_owner=${ctx.builder}`,
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
const R_P_4_02 = {
|
|
248
|
+
id: "R-P-4-02",
|
|
249
|
+
category: "lifecycle",
|
|
250
|
+
trigger: "Apply to multiple objects at once",
|
|
251
|
+
check: (ctx) => {
|
|
252
|
+
if (!ctx.apply || ctx.apply.length === 0)
|
|
253
|
+
return null;
|
|
254
|
+
if (ctx.apply.length > 3) {
|
|
255
|
+
return {
|
|
256
|
+
id: "R-P-4-02",
|
|
257
|
+
level: "MEDIUM",
|
|
258
|
+
category: "lifecycle",
|
|
259
|
+
title: "Batch apply to multiple objects",
|
|
260
|
+
description: `Applying Permission to ${ctx.apply.length} objects at once; if any object type mismatches, transaction may fail or silently misalign`,
|
|
261
|
+
affected_stakeholders: ["owner"],
|
|
262
|
+
scenario: "Batch apply across heterogeneous objects",
|
|
263
|
+
mitigation: "Apply to 1-3 objects at a time; verify each object type matches permission indexes",
|
|
264
|
+
evidence: `apply_count=${ctx.apply.length}`,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
const R_P_4_03 = {
|
|
271
|
+
id: "R-P-4-03",
|
|
272
|
+
category: "lifecycle",
|
|
273
|
+
trigger: "Entity replace operation (destructive)",
|
|
274
|
+
check: (ctx) => {
|
|
275
|
+
if (!ctx.entity || ctx.entity.op !== "replace")
|
|
276
|
+
return null;
|
|
277
|
+
return {
|
|
278
|
+
id: "R-P-4-03",
|
|
279
|
+
level: "MEDIUM",
|
|
280
|
+
category: "lifecycle",
|
|
281
|
+
title: "Entity replace — destructive",
|
|
282
|
+
description: `Replacing ${ctx.entity.entity1} with ${ctx.entity.entity2}; entity1 loses ALL permissions permanently`,
|
|
283
|
+
affected_stakeholders: ["entity"],
|
|
284
|
+
scenario: "Replacing a user who left the organization",
|
|
285
|
+
mitigation: "Prefer 'copy' over 'replace' if entity1 should retain permissions",
|
|
286
|
+
evidence: `entity1=${ctx.entity.entity1}, entity2=${ctx.entity.entity2}`,
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
const R_P_5_01 = {
|
|
291
|
+
id: "R-P-5-01",
|
|
292
|
+
category: "cross_object",
|
|
293
|
+
trigger: "Apply to Progress object (Permission becomes immutable on bind)",
|
|
294
|
+
check: (ctx) => {
|
|
295
|
+
if (!ctx.apply)
|
|
296
|
+
return null;
|
|
297
|
+
if (ctx.target_objects_types?.includes("Progress")) {
|
|
298
|
+
return {
|
|
299
|
+
id: "R-P-5-01",
|
|
300
|
+
level: "MEDIUM",
|
|
301
|
+
category: "cross_object",
|
|
302
|
+
title: "Apply to Progress — post-bind mutability limited",
|
|
303
|
+
description: "Once Permission is bound to Progress (which binds Machine), permission table changes may not affect already-published Machine workflow",
|
|
304
|
+
affected_stakeholders: ["owner"],
|
|
305
|
+
scenario: "Permission shared across Machine/Progress",
|
|
306
|
+
mitigation: "Configure all permission indexes before Machine publish",
|
|
307
|
+
evidence: `target=Progress`,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
const R_P_5_02 = {
|
|
314
|
+
id: "R-P-5-02",
|
|
315
|
+
category: "cross_object",
|
|
316
|
+
trigger: "Permission reused across multiple host object types",
|
|
317
|
+
check: (ctx) => {
|
|
318
|
+
if (!ctx.target_objects_types || ctx.target_objects_types.length < 2)
|
|
319
|
+
return null;
|
|
320
|
+
const uniqueTypes = new Set(ctx.target_objects_types);
|
|
321
|
+
if (uniqueTypes.size > 1) {
|
|
322
|
+
return {
|
|
323
|
+
id: "R-P-5-02",
|
|
324
|
+
level: "MEDIUM",
|
|
325
|
+
category: "cross_object",
|
|
326
|
+
title: "Permission shared across heterogeneous objects",
|
|
327
|
+
description: `Single Permission applied to ${[...uniqueTypes].join(", ")}; permission indexes may have different semantics per object`,
|
|
328
|
+
affected_stakeholders: ["owner", "admin"],
|
|
329
|
+
scenario: "One Permission for both Service and Treasury",
|
|
330
|
+
mitigation: "Use separate Permission objects per host object type for clarity",
|
|
331
|
+
evidence: `types=${[...uniqueTypes].join(",")}`,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
const R_P_5_03 = {
|
|
338
|
+
id: "R-P-5-03",
|
|
339
|
+
category: "cross_object",
|
|
340
|
+
trigger: "Treasury external_*_guard management (255/256) granted — verify guard lists are populated",
|
|
341
|
+
check: (ctx) => {
|
|
342
|
+
if (!ctx.table || !("index" in ctx.table) || typeof ctx.table.index !== "number")
|
|
343
|
+
return null;
|
|
344
|
+
const idx = ctx.table.index;
|
|
345
|
+
if (idx === 255 || idx === 256) {
|
|
346
|
+
return {
|
|
347
|
+
id: "R-P-5-03",
|
|
348
|
+
level: "HIGH",
|
|
349
|
+
category: "cross_object",
|
|
350
|
+
title: "Treasury external guard management granted — populate guard lists",
|
|
351
|
+
description: `Permission ${idx} (${idx === 255 ? "TREASURY_EXTERNAL_DEPOSIT_GUARD" : "TREASURY_EXTERNAL_WITHDRAW_GUARD"}) granted; ensure external_${idx === 255 ? "deposit" : "withdraw"}_guard list is populated via external_*_guard_add so external operations are authorized`,
|
|
352
|
+
affected_stakeholders: ["owner", "admin"],
|
|
353
|
+
scenario: "External treasury guard management without populated guard lists",
|
|
354
|
+
mitigation: `Call treasury.external_${idx === 255 ? "deposit" : "withdraw"}_guard_add to register Guard objects; external_deposit/external_withdraw require Guard + Passport (no Permission index)`,
|
|
355
|
+
evidence: `index=${idx}`,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
const ALL_RULES = [
|
|
362
|
+
R_P_01, R_P_02, R_P_03, R_P_04,
|
|
363
|
+
R_P_2_01, R_P_2_02,
|
|
364
|
+
R_P_3_01, R_P_3_02, R_P_3_03,
|
|
365
|
+
R_P_4_01, R_P_4_02, R_P_4_03,
|
|
366
|
+
R_P_5_01, R_P_5_02, R_P_5_03,
|
|
367
|
+
];
|
|
368
|
+
export const PERMISSION_RISK_VERSION = "1.0.0";
|
|
369
|
+
export function getAllRiskRules() {
|
|
370
|
+
return [...ALL_RULES];
|
|
371
|
+
}
|
|
372
|
+
export function getRiskRulesCount() {
|
|
373
|
+
return ALL_RULES.length;
|
|
374
|
+
}
|
|
375
|
+
export function getRiskRulesByCategory(category) {
|
|
376
|
+
return ALL_RULES.filter(r => r.category === category);
|
|
377
|
+
}
|
|
378
|
+
export function assessPermissionRisks(ctx) {
|
|
379
|
+
const risks = [];
|
|
380
|
+
for (const rule of ALL_RULES) {
|
|
381
|
+
const r = rule.check(ctx);
|
|
382
|
+
if (r)
|
|
383
|
+
risks.push(r);
|
|
384
|
+
}
|
|
385
|
+
const overall = risks.length === 0
|
|
386
|
+
? "LOW"
|
|
387
|
+
: risks.some(r => r.level === "CRITICAL") ? "CRITICAL"
|
|
388
|
+
: risks.some(r => r.level === "HIGH") ? "HIGH"
|
|
389
|
+
: risks.some(r => r.level === "MEDIUM") ? "MEDIUM"
|
|
390
|
+
: "LOW";
|
|
391
|
+
const byCategory = {};
|
|
392
|
+
for (const r of risks) {
|
|
393
|
+
byCategory[r.category] = (byCategory[r.category] ?? 0) + 1;
|
|
394
|
+
}
|
|
395
|
+
const advice = {};
|
|
396
|
+
for (const r of risks) {
|
|
397
|
+
for (const s of r.affected_stakeholders) {
|
|
398
|
+
if (!advice[s])
|
|
399
|
+
advice[s] = [];
|
|
400
|
+
advice[s].push(`${r.id}: ${r.mitigation}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
summary: `Assessed ${risks.length} risk(s) across ${Object.keys(byCategory).length} categories`,
|
|
405
|
+
risks,
|
|
406
|
+
overall_risk: overall,
|
|
407
|
+
risks_by_category: byCategory,
|
|
408
|
+
stakeholder_advice: advice,
|
|
409
|
+
needs_human_review: risks.some(r => r.level === "CRITICAL" || r.level === "HIGH"),
|
|
410
|
+
};
|
|
411
|
+
}
|