@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,127 @@
|
|
|
1
|
+
import { type RewardScene, type RewardBuiltinPermissionEntry, type RewardGuardConstructor, type RewardGuardConstructorSpec, type RewardPhase, type RewardRecipientType, type RewardAmountType } from "./reward-ledger.js";
|
|
2
|
+
import { type RewardPuzzle, type RewardPuzzleCompleteness } from "./reward-puzzle.js";
|
|
3
|
+
import { type RewardRiskAssessment, type RewardRiskRule, type RewardStakeholder } from "./reward-risk.js";
|
|
4
|
+
import { type RewardSemanticToSchemaRule } from "./reward-translation.js";
|
|
5
|
+
import { type RewardTemplate } from "./reward-templates.js";
|
|
6
|
+
import { REWARD_OPERATION_CHECKLIST, REWARD_CONFIRMATION_QUESTIONS, type RewardJsonForConfirm } from "./reward-confirm.js";
|
|
7
|
+
export declare const REWARD_CONTEXT_VERSION = "1.0.0";
|
|
8
|
+
export type RewardInjectionMode = "initial_design" | "pre_claim" | "post_claim" | "guard_review" | "balance_review" | "stakeholder_review";
|
|
9
|
+
export type RewardStakeholderPerspective = RewardStakeholder | "system";
|
|
10
|
+
export interface RewardContextBundle {
|
|
11
|
+
version: string;
|
|
12
|
+
mode: RewardInjectionMode;
|
|
13
|
+
stakeholder_perspective?: RewardStakeholderPerspective;
|
|
14
|
+
matched_scene?: RewardScene;
|
|
15
|
+
matched_template?: RewardTemplate;
|
|
16
|
+
matched_pattern?: RewardSemanticToSchemaRule;
|
|
17
|
+
puzzle_state?: RewardPuzzle;
|
|
18
|
+
puzzle_completeness?: RewardPuzzleCompleteness;
|
|
19
|
+
relevant_risks: RewardRiskRule[];
|
|
20
|
+
risk_assessment?: RewardRiskAssessment;
|
|
21
|
+
relevant_checklist: typeof REWARD_OPERATION_CHECKLIST;
|
|
22
|
+
relevant_questions: typeof REWARD_CONFIRMATION_QUESTIONS;
|
|
23
|
+
relevant_builtin_permissions: RewardBuiltinPermissionEntry[];
|
|
24
|
+
relevant_guard_constructors: RewardGuardConstructorSpec[];
|
|
25
|
+
cross_object_refs: RewardCrossObjectRef[];
|
|
26
|
+
onchain_constraints: RewardOnchainConstraint[];
|
|
27
|
+
rendering_hints: RewardRenderingHints;
|
|
28
|
+
}
|
|
29
|
+
export interface RewardCrossObjectRef {
|
|
30
|
+
object: "Guard" | "Permission" | "Passport" | "Payment" | "Repository" | "Service" | "Demand" | "Allocation" | "Contact" | "Coin";
|
|
31
|
+
phase: RewardPhase | "universal";
|
|
32
|
+
relationship: string;
|
|
33
|
+
description: string;
|
|
34
|
+
}
|
|
35
|
+
export interface RewardOnchainConstraint {
|
|
36
|
+
name: string;
|
|
37
|
+
value: string | number;
|
|
38
|
+
description: string;
|
|
39
|
+
error_code?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RewardRenderingHints {
|
|
42
|
+
include_puzzle_template: boolean;
|
|
43
|
+
include_risk_details: boolean;
|
|
44
|
+
include_questions: boolean;
|
|
45
|
+
include_claim_warning: boolean;
|
|
46
|
+
include_owner_receive_warning: boolean;
|
|
47
|
+
include_cross_object_refs: boolean;
|
|
48
|
+
include_guard_constructor_matrix: boolean;
|
|
49
|
+
max_length: number;
|
|
50
|
+
}
|
|
51
|
+
export interface BuildRewardContextInput {
|
|
52
|
+
mode: RewardInjectionMode;
|
|
53
|
+
intent?: string;
|
|
54
|
+
reward_json?: RewardJsonForConfirm;
|
|
55
|
+
stakeholder?: RewardStakeholderPerspective;
|
|
56
|
+
target_phase?: RewardPhase;
|
|
57
|
+
target_industry?: string;
|
|
58
|
+
max_length?: number;
|
|
59
|
+
reward_type?: string;
|
|
60
|
+
current_balance?: string;
|
|
61
|
+
current_guard_count?: number;
|
|
62
|
+
current_record_count_for_recipient?: number;
|
|
63
|
+
current_guard_not_added_expiration_time?: number | null;
|
|
64
|
+
current_clock_ms?: number;
|
|
65
|
+
permission_address?: string;
|
|
66
|
+
signer?: string;
|
|
67
|
+
target_guard_addresses?: string[];
|
|
68
|
+
passport_submission_value_types?: Record<number, string>;
|
|
69
|
+
passport_identifier_is_address?: Record<number, boolean>;
|
|
70
|
+
guard_store_from_id_compatible?: Record<string, boolean>;
|
|
71
|
+
}
|
|
72
|
+
export declare function buildRewardContext(input: BuildRewardContextInput): RewardContextBundle;
|
|
73
|
+
export declare function buildPromptFromRewardContext(bundle: RewardContextBundle): string;
|
|
74
|
+
export declare function getRewardContextSummary(bundle: RewardContextBundle): string;
|
|
75
|
+
export declare function buildStakeholderContext(stakeholder: RewardStakeholderPerspective, intent?: string, reward_json?: RewardJsonForConfirm): RewardContextBundle;
|
|
76
|
+
export declare function quickValidateRewardJson(reward_json: RewardJsonForConfirm, current_state?: {
|
|
77
|
+
reward_type?: string;
|
|
78
|
+
current_balance?: string;
|
|
79
|
+
current_guard_count?: number;
|
|
80
|
+
current_record_count_for_recipient?: number;
|
|
81
|
+
current_guard_not_added_expiration_time?: number | null;
|
|
82
|
+
current_clock_ms?: number;
|
|
83
|
+
target_guard_addresses?: string[];
|
|
84
|
+
}): {
|
|
85
|
+
ok: boolean;
|
|
86
|
+
violations: string[];
|
|
87
|
+
};
|
|
88
|
+
export declare function getRewardKnowledgeSnapshot(): {
|
|
89
|
+
version: {
|
|
90
|
+
ledger: string;
|
|
91
|
+
puzzle: string;
|
|
92
|
+
risk: string;
|
|
93
|
+
translation: string;
|
|
94
|
+
templates: number;
|
|
95
|
+
confirm: string;
|
|
96
|
+
context: string;
|
|
97
|
+
};
|
|
98
|
+
scenes_count: number;
|
|
99
|
+
builtin_permissions_count: number;
|
|
100
|
+
builtin_permissions: {
|
|
101
|
+
index: 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157;
|
|
102
|
+
name: string;
|
|
103
|
+
sdk_exposed: boolean;
|
|
104
|
+
}[];
|
|
105
|
+
guard_constructors_count: number;
|
|
106
|
+
guard_constructors: {
|
|
107
|
+
constructor: RewardGuardConstructor;
|
|
108
|
+
recipient_type: RewardRecipientType;
|
|
109
|
+
amount_type: RewardAmountType;
|
|
110
|
+
}[];
|
|
111
|
+
error_codes_count: number;
|
|
112
|
+
templates_count: number;
|
|
113
|
+
templates: RewardTemplate[];
|
|
114
|
+
semantic_patterns_count: number;
|
|
115
|
+
schema_rules_count: number;
|
|
116
|
+
constraint_rules_count: number;
|
|
117
|
+
risk_rules_count: number;
|
|
118
|
+
checklist_count: number;
|
|
119
|
+
confirmation_questions_count: number;
|
|
120
|
+
cross_object_refs_count: number;
|
|
121
|
+
onchain_limits: {
|
|
122
|
+
max_guard_count_reward: 200;
|
|
123
|
+
max_record_count_reward: 5200;
|
|
124
|
+
};
|
|
125
|
+
injection_modes: RewardInjectionMode[];
|
|
126
|
+
stakeholders: RewardStakeholderPerspective[];
|
|
127
|
+
};
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { MAX_GUARD_COUNT_REWARD, MAX_RECORD_COUNT_REWARD, } from "./onchain-constants.js";
|
|
2
|
+
import { REWARD_PERMISSIONS, REWARD_GUARD_CONSTRUCTORS, REWARD_ERROR_CODES, REWARD_CROSS_OBJECT_REFS, REWARD_LEDGER_VERSION, inferSceneFromIntent, getScenesByIndustry, getScenesByPhase, getAllBuiltinPermissions, getRewardScenesCount, validateGuardCount, validateRecordCount, } from "./reward-ledger.js";
|
|
3
|
+
import { initPuzzleFromIntent, checkPuzzleCompleteness, } from "./reward-puzzle.js";
|
|
4
|
+
import { REWARD_RISK_VERSION, assessRewardRisks, getAllRewardRiskRules, getRewardRiskRulesCount, getRewardRiskRulesByStakeholder, REWARD_STAKEHOLDERS, } from "./reward-risk.js";
|
|
5
|
+
import { REWARD_TRANSLATION_VERSION, REWARD_SEMANTIC_TO_SCHEMA_RULES, REWARD_SCHEMA_TO_SEMANTIC_RULES, REWARD_CONSTRAINT_RULES, matchSemanticPattern, } from "./reward-translation.js";
|
|
6
|
+
import { REWARD_TEMPLATES, REWARD_TEMPLATES_VERSION, getRewardTemplate, listRewardTemplates, suggestRewardTemplate, } from "./reward-templates.js";
|
|
7
|
+
import { REWARD_CONFIRM_VERSION, REWARD_OPERATION_CHECKLIST, REWARD_CONFIRMATION_QUESTIONS, } from "./reward-confirm.js";
|
|
8
|
+
export const REWARD_CONTEXT_VERSION = "1.0.0";
|
|
9
|
+
export function buildRewardContext(input) {
|
|
10
|
+
const max_length = input.max_length ?? 4000;
|
|
11
|
+
let matched_scene;
|
|
12
|
+
if (input.intent) {
|
|
13
|
+
matched_scene = inferSceneFromIntent(input.intent);
|
|
14
|
+
}
|
|
15
|
+
if (!matched_scene && input.target_phase) {
|
|
16
|
+
const phaseScenes = getScenesByPhase(input.target_phase);
|
|
17
|
+
if (phaseScenes.length > 0)
|
|
18
|
+
matched_scene = phaseScenes[0];
|
|
19
|
+
}
|
|
20
|
+
if (!matched_scene && input.target_industry) {
|
|
21
|
+
const industryScenes = getScenesByIndustry(input.target_industry);
|
|
22
|
+
if (industryScenes.length > 0)
|
|
23
|
+
matched_scene = industryScenes[0];
|
|
24
|
+
}
|
|
25
|
+
let matched_template;
|
|
26
|
+
if (input.intent) {
|
|
27
|
+
matched_template = suggestRewardTemplate(input.intent);
|
|
28
|
+
}
|
|
29
|
+
if (!matched_template && matched_scene && matched_scene.recommended_templates.length > 0) {
|
|
30
|
+
const tplType = matched_scene.recommended_templates[0];
|
|
31
|
+
matched_template = getRewardTemplate(tplType);
|
|
32
|
+
}
|
|
33
|
+
let matched_pattern;
|
|
34
|
+
if (input.intent) {
|
|
35
|
+
const patterns = matchSemanticPattern(input.intent);
|
|
36
|
+
if (patterns.length > 0)
|
|
37
|
+
matched_pattern = patterns[0];
|
|
38
|
+
}
|
|
39
|
+
let puzzle_state;
|
|
40
|
+
let puzzle_completeness;
|
|
41
|
+
if (input.mode === "initial_design" && input.intent) {
|
|
42
|
+
puzzle_state = initPuzzleFromIntent({ rule_sentence: input.intent });
|
|
43
|
+
puzzle_completeness = checkPuzzleCompleteness(puzzle_state);
|
|
44
|
+
}
|
|
45
|
+
const relevant_risks = filterRiskRules(input.mode, input.stakeholder, matched_scene);
|
|
46
|
+
let risk_assessment;
|
|
47
|
+
if (input.mode === "pre_claim" && input.reward_json) {
|
|
48
|
+
const ctx = {
|
|
49
|
+
object: input.reward_json.object,
|
|
50
|
+
claim: input.reward_json.claim,
|
|
51
|
+
description: input.reward_json.description,
|
|
52
|
+
coin_add: input.reward_json.coin_add,
|
|
53
|
+
receive: input.reward_json.receive,
|
|
54
|
+
guard_add: input.reward_json.guard_add,
|
|
55
|
+
guard_remove_expired: input.reward_json.guard_remove_expired,
|
|
56
|
+
guard_expiration_time: input.reward_json.guard_expiration_time,
|
|
57
|
+
owner_receive: input.reward_json.owner_receive,
|
|
58
|
+
um: input.reward_json.um,
|
|
59
|
+
reward_type: input.reward_type,
|
|
60
|
+
current_balance: input.current_balance,
|
|
61
|
+
current_guard_count: input.current_guard_count,
|
|
62
|
+
current_record_count_for_recipient: input.current_record_count_for_recipient,
|
|
63
|
+
current_guard_not_added_expiration_time: input.current_guard_not_added_expiration_time,
|
|
64
|
+
current_clock_ms: input.current_clock_ms,
|
|
65
|
+
permission_address: input.permission_address,
|
|
66
|
+
signer: input.signer,
|
|
67
|
+
target_guard_addresses: input.target_guard_addresses,
|
|
68
|
+
passport_submission_value_types: input.passport_submission_value_types,
|
|
69
|
+
passport_identifier_is_address: input.passport_identifier_is_address,
|
|
70
|
+
guard_store_from_id_compatible: input.guard_store_from_id_compatible,
|
|
71
|
+
};
|
|
72
|
+
risk_assessment = assessRewardRisks(ctx);
|
|
73
|
+
}
|
|
74
|
+
const relevant_checklist = filterChecklist(input.mode);
|
|
75
|
+
const relevant_questions = filterQuestions(input.mode);
|
|
76
|
+
const relevant_builtin_permissions = matched_scene
|
|
77
|
+
? matched_scene.builtin_indexes_consumed
|
|
78
|
+
: getAllBuiltinPermissions();
|
|
79
|
+
const relevant_guard_constructors = filterGuardConstructors(matched_scene);
|
|
80
|
+
const cross_object_refs = buildCrossObjectRefs(input.target_phase, matched_scene);
|
|
81
|
+
const onchain_constraints = buildOnchainConstraints();
|
|
82
|
+
const rendering_hints = buildRenderingHints(input.mode, max_length, !!input.reward_json?.claim, input.reward_json?.owner_receive != null, input.mode === "initial_design");
|
|
83
|
+
return {
|
|
84
|
+
version: REWARD_CONTEXT_VERSION,
|
|
85
|
+
mode: input.mode,
|
|
86
|
+
stakeholder_perspective: input.stakeholder,
|
|
87
|
+
matched_scene,
|
|
88
|
+
matched_template,
|
|
89
|
+
matched_pattern,
|
|
90
|
+
puzzle_state,
|
|
91
|
+
puzzle_completeness,
|
|
92
|
+
relevant_risks,
|
|
93
|
+
risk_assessment,
|
|
94
|
+
relevant_checklist,
|
|
95
|
+
relevant_questions,
|
|
96
|
+
relevant_builtin_permissions,
|
|
97
|
+
relevant_guard_constructors,
|
|
98
|
+
cross_object_refs,
|
|
99
|
+
onchain_constraints,
|
|
100
|
+
rendering_hints,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function filterRiskRules(mode, stakeholder, scene) {
|
|
104
|
+
const allRules = getAllRewardRiskRules();
|
|
105
|
+
if (mode === "initial_design") {
|
|
106
|
+
return allRules.filter(r => r.category === "structural" || r.category === "semantic");
|
|
107
|
+
}
|
|
108
|
+
if (mode === "pre_claim") {
|
|
109
|
+
return allRules;
|
|
110
|
+
}
|
|
111
|
+
if (mode === "post_claim") {
|
|
112
|
+
return allRules.filter(r => r.id === "R-R-1-02" || r.id === "R-R-4-02" || r.id === "R-R-4-01");
|
|
113
|
+
}
|
|
114
|
+
if (mode === "guard_review") {
|
|
115
|
+
return allRules.filter(r => r.category === "structural" || r.category === "lifecycle" || r.category === "semantic");
|
|
116
|
+
}
|
|
117
|
+
if (mode === "balance_review") {
|
|
118
|
+
return allRules.filter(r => r.category === "cross_object" || r.id === "R-R-4-02" || r.id === "R-R-3-02");
|
|
119
|
+
}
|
|
120
|
+
if (mode === "stakeholder_review" && stakeholder) {
|
|
121
|
+
const stakeholderNorm = stakeholder === "system" ? "system" : stakeholder;
|
|
122
|
+
return getRewardRiskRulesByStakeholder(stakeholderNorm);
|
|
123
|
+
}
|
|
124
|
+
return allRules;
|
|
125
|
+
}
|
|
126
|
+
function filterChecklist(mode) {
|
|
127
|
+
if (mode === "initial_design") {
|
|
128
|
+
return REWARD_OPERATION_CHECKLIST.filter(i => ["C-R-01", "C-R-06"].includes(i.id));
|
|
129
|
+
}
|
|
130
|
+
if (mode === "pre_claim") {
|
|
131
|
+
return REWARD_OPERATION_CHECKLIST.filter(i => ["C-R-02", "C-R-03", "C-R-05", "C-R-08"].includes(i.id));
|
|
132
|
+
}
|
|
133
|
+
if (mode === "guard_review") {
|
|
134
|
+
return REWARD_OPERATION_CHECKLIST.filter(i => ["C-R-01", "C-R-04", "C-R-05", "C-R-06", "C-R-10"].includes(i.id));
|
|
135
|
+
}
|
|
136
|
+
if (mode === "balance_review") {
|
|
137
|
+
return REWARD_OPERATION_CHECKLIST.filter(i => ["C-R-03", "C-R-07", "C-R-09"].includes(i.id));
|
|
138
|
+
}
|
|
139
|
+
if (mode === "stakeholder_review") {
|
|
140
|
+
return REWARD_OPERATION_CHECKLIST;
|
|
141
|
+
}
|
|
142
|
+
return REWARD_OPERATION_CHECKLIST;
|
|
143
|
+
}
|
|
144
|
+
function filterQuestions(mode) {
|
|
145
|
+
if (mode === "pre_claim") {
|
|
146
|
+
return REWARD_CONFIRMATION_QUESTIONS.filter(q => ["QRW1", "QRW2", "QRW5"].includes(q.id));
|
|
147
|
+
}
|
|
148
|
+
if (mode === "guard_review") {
|
|
149
|
+
return REWARD_CONFIRMATION_QUESTIONS.filter(q => ["QRW2", "QRW4"].includes(q.id));
|
|
150
|
+
}
|
|
151
|
+
if (mode === "balance_review") {
|
|
152
|
+
return REWARD_CONFIRMATION_QUESTIONS.filter(q => ["QRW3", "QRW6"].includes(q.id));
|
|
153
|
+
}
|
|
154
|
+
if (mode === "initial_design") {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
function filterGuardConstructors(scene) {
|
|
160
|
+
if (!scene)
|
|
161
|
+
return [...REWARD_GUARD_CONSTRUCTORS];
|
|
162
|
+
const recipientTypes = new Set(scene.recipient_types_used);
|
|
163
|
+
const amountTypes = new Set(scene.amount_types_used);
|
|
164
|
+
return REWARD_GUARD_CONSTRUCTORS.filter(c => recipientTypes.has(c.recipient_type) && amountTypes.has(c.amount_type));
|
|
165
|
+
}
|
|
166
|
+
function buildCrossObjectRefs(targetPhase, scene) {
|
|
167
|
+
const refs = REWARD_CROSS_OBJECT_REFS.map(r => ({
|
|
168
|
+
object: r.object,
|
|
169
|
+
phase: r.phase,
|
|
170
|
+
relationship: r.relationship,
|
|
171
|
+
description: r.relationship,
|
|
172
|
+
}));
|
|
173
|
+
if (targetPhase) {
|
|
174
|
+
return refs.filter(r => r.phase === targetPhase || r.phase === "universal");
|
|
175
|
+
}
|
|
176
|
+
if (scene) {
|
|
177
|
+
const scenePhases = scene.phases;
|
|
178
|
+
return refs.filter(r => r.phase === "universal" || scenePhases.includes(r.phase));
|
|
179
|
+
}
|
|
180
|
+
return refs;
|
|
181
|
+
}
|
|
182
|
+
function buildOnchainConstraints() {
|
|
183
|
+
return [
|
|
184
|
+
{
|
|
185
|
+
name: "MAX_GUARD_COUNT_REWARD",
|
|
186
|
+
value: MAX_GUARD_COUNT_REWARD,
|
|
187
|
+
description: "Maximum guards per Reward",
|
|
188
|
+
error_code: "E_GUARD_COUNT_EXCEEDED",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "MAX_RECORD_COUNT_REWARD",
|
|
192
|
+
value: MAX_RECORD_COUNT_REWARD,
|
|
193
|
+
description: "Maximum records per recipient (per-recipient claim history cap)",
|
|
194
|
+
error_code: "E_RECORD_COUNT_EXCEEDED",
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "REWARD_NEW (150)",
|
|
198
|
+
value: 150,
|
|
199
|
+
description: "Builtin: create new Reward (new / new_with_passport)",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "REWARD_DESCRIPTION (151)",
|
|
203
|
+
value: 151,
|
|
204
|
+
description: "Builtin: update description (description_set)",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "REWARD_GUARD (152)",
|
|
208
|
+
value: 152,
|
|
209
|
+
description: "Builtin: add / remove expired guards (guard_add, guard_remove_expired)",
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "REWARD_COIN_ADD (153)",
|
|
213
|
+
value: 153,
|
|
214
|
+
description: "Builtin: deposit Coin<T> into balance (coin_add)",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: "REWARD_RECEIVE (154)",
|
|
218
|
+
value: 154,
|
|
219
|
+
description: "Builtin: receive CoinWrapper<T> via Payment (receive)",
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "REWARD_GUARD_EXPIRATION_TIME_ADD (155)",
|
|
223
|
+
value: 155,
|
|
224
|
+
description: "Builtin: set/cancel guard_not_added_expiration_time (time-lock on guard additions)",
|
|
225
|
+
error_code: "E_GUARD_LOCKED_TIME",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "REWARD_OWNER_RECEIVE (156)",
|
|
229
|
+
value: 156,
|
|
230
|
+
description: "Builtin: owner unwrap Receiving<K>/CoinWrapper<K> (owner_receive, owner_receive_object)",
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "REWARD_UM (157)",
|
|
234
|
+
value: 157,
|
|
235
|
+
description: "Builtin: bind/unbind Contact (UM) (um_set, um_none)",
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: "E_INSUFFICIENT_BALANCE",
|
|
239
|
+
value: 6,
|
|
240
|
+
description: "Move error: claim with balance < amount (balance::split aborts)",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "E_GUARD_NOT_FOUND",
|
|
244
|
+
value: 7,
|
|
245
|
+
description: "Move error: claim with guard not in self.guards",
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "E_GUARD_EXPIRED",
|
|
249
|
+
value: 2,
|
|
250
|
+
description: "Move error: guard_add / claim with expiration_time < now",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: "E_GUARD_LOCKED_TIME",
|
|
254
|
+
value: 10,
|
|
255
|
+
description: "Move error: guard_add while guard_not_added_expiration_time is Some and clock ≤ expiration",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "E_AMOUNT_NOT_U64",
|
|
259
|
+
value: 5,
|
|
260
|
+
description: "Move error: RewardGuard constructor with GuardU64Identifier amount where identifier type ≠ u64",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "E_RECIPIENT_IDENTIFIER_NOT_ADDRESS",
|
|
264
|
+
value: 4,
|
|
265
|
+
description: "Move error: RewardGuard constructor with GuardIdentifier recipient where identifier type ≠ address",
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "E_STORE_FROM_ID_NOT_COMPATIBLE",
|
|
269
|
+
value: 12,
|
|
270
|
+
description: "Move error: RewardGuard constructor with store_from_id where identifier is not number/address compatible",
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
function buildRenderingHints(mode, max_length, hasClaim, hasOwnerReceive, isInitialDesign) {
|
|
275
|
+
return {
|
|
276
|
+
include_puzzle_template: isInitialDesign,
|
|
277
|
+
include_risk_details: mode === "pre_claim" || mode === "stakeholder_review",
|
|
278
|
+
include_questions: mode === "pre_claim" || mode === "guard_review" || mode === "balance_review",
|
|
279
|
+
include_claim_warning: hasClaim,
|
|
280
|
+
include_owner_receive_warning: hasOwnerReceive,
|
|
281
|
+
include_cross_object_refs: mode === "initial_design" || mode === "stakeholder_review",
|
|
282
|
+
include_guard_constructor_matrix: isInitialDesign || mode === "guard_review",
|
|
283
|
+
max_length,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
export function buildPromptFromRewardContext(bundle) {
|
|
287
|
+
const lines = [];
|
|
288
|
+
const h = bundle.rendering_hints;
|
|
289
|
+
lines.push(`═══ Reward Context (mode: ${bundle.mode}) ═══`);
|
|
290
|
+
lines.push("");
|
|
291
|
+
if (bundle.stakeholder_perspective) {
|
|
292
|
+
lines.push(`Stakeholder perspective: ${bundle.stakeholder_perspective}`);
|
|
293
|
+
lines.push("");
|
|
294
|
+
}
|
|
295
|
+
if (bundle.matched_scene) {
|
|
296
|
+
lines.push(`Scene: ${bundle.matched_scene.name}`);
|
|
297
|
+
lines.push(`Phases: ${bundle.matched_scene.phases.join(", ")}`);
|
|
298
|
+
lines.push(`Typical guard count: ${bundle.matched_scene.typical_guard_count}/${MAX_GUARD_COUNT_REWARD}`);
|
|
299
|
+
lines.push(`Recipient types: ${bundle.matched_scene.recipient_types_used.join(", ")}`);
|
|
300
|
+
lines.push(`Amount types: ${bundle.matched_scene.amount_types_used.join(", ")}`);
|
|
301
|
+
lines.push(`Uses expiration_time: ${bundle.matched_scene.uses_expiration_time ? "YES" : "NO"}`);
|
|
302
|
+
lines.push("");
|
|
303
|
+
}
|
|
304
|
+
if (bundle.matched_template) {
|
|
305
|
+
lines.push(`Suggested template: ${bundle.matched_template.type} — ${bundle.matched_template.name}`);
|
|
306
|
+
lines.push("");
|
|
307
|
+
}
|
|
308
|
+
if (bundle.matched_pattern) {
|
|
309
|
+
lines.push(`Matched pattern: ${bundle.matched_pattern.id} — ${bundle.matched_pattern.pattern_name}`);
|
|
310
|
+
lines.push(`Intent: ${bundle.matched_pattern.semantic_intent}`);
|
|
311
|
+
lines.push("");
|
|
312
|
+
}
|
|
313
|
+
if (h.include_puzzle_template && bundle.puzzle_completeness) {
|
|
314
|
+
const c = bundle.puzzle_completeness;
|
|
315
|
+
lines.push("─ Puzzle Completeness ──────────────");
|
|
316
|
+
lines.push(`Complete: ${c.complete ? "YES" : "NO"}`);
|
|
317
|
+
if (c.missing.length > 0) {
|
|
318
|
+
lines.push(`Missing dimensions: ${c.missing.join(", ")}`);
|
|
319
|
+
for (const md of c.missing_details) {
|
|
320
|
+
lines.push(` - ${md.dimension}: ${md.reason}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
lines.push(`Next: ${c.next_step}`);
|
|
324
|
+
lines.push("");
|
|
325
|
+
}
|
|
326
|
+
if (h.include_guard_constructor_matrix && bundle.relevant_guard_constructors.length > 0) {
|
|
327
|
+
lines.push(`─ Guard Constructors (${bundle.relevant_guard_constructors.length}) ──────────────`);
|
|
328
|
+
for (const c of bundle.relevant_guard_constructors) {
|
|
329
|
+
lines.push(` ${c.constructor}: ${c.recipient_type} × ${c.amount_type}`);
|
|
330
|
+
lines.push(` use: ${c.typical_use}`);
|
|
331
|
+
}
|
|
332
|
+
lines.push("");
|
|
333
|
+
}
|
|
334
|
+
if (h.include_risk_details && bundle.relevant_risks.length > 0) {
|
|
335
|
+
lines.push(`─ Relevant Risk Rules (${bundle.relevant_risks.length}) ──────────────`);
|
|
336
|
+
for (const r of bundle.relevant_risks.slice(0, 6)) {
|
|
337
|
+
lines.push(` ${r.id} [${r.category}] — ${r.trigger}`);
|
|
338
|
+
}
|
|
339
|
+
if (bundle.relevant_risks.length > 6) {
|
|
340
|
+
lines.push(` ... and ${bundle.relevant_risks.length - 6} more`);
|
|
341
|
+
}
|
|
342
|
+
lines.push("");
|
|
343
|
+
}
|
|
344
|
+
if (bundle.risk_assessment) {
|
|
345
|
+
lines.push("─ Risk Assessment ──────────────");
|
|
346
|
+
lines.push(`Overall: ${bundle.risk_assessment.overall_risk}`);
|
|
347
|
+
lines.push(`Detected: ${bundle.risk_assessment.risks.length} risk(s)`);
|
|
348
|
+
if (bundle.risk_assessment.needs_human_review) {
|
|
349
|
+
lines.push("⚠️ Needs human review (HIGH/CRITICAL risks present)");
|
|
350
|
+
}
|
|
351
|
+
lines.push("");
|
|
352
|
+
}
|
|
353
|
+
if (bundle.relevant_builtin_permissions.length > 0) {
|
|
354
|
+
lines.push(`─ Builtin Permissions (${bundle.relevant_builtin_permissions.length}) ──────────────`);
|
|
355
|
+
for (const p of bundle.relevant_builtin_permissions) {
|
|
356
|
+
lines.push(` [${p.index}] ${p.name}: ${p.description}`);
|
|
357
|
+
}
|
|
358
|
+
lines.push("");
|
|
359
|
+
}
|
|
360
|
+
if (h.include_claim_warning) {
|
|
361
|
+
lines.push("⚠️ CLAIM IS PERMISSION-FREE: anyone with a valid Passport + Guard can claim.");
|
|
362
|
+
lines.push(" Ensure the Guard binds to specific Service/Order context to prevent unauthorized claims.");
|
|
363
|
+
lines.push("");
|
|
364
|
+
}
|
|
365
|
+
if (h.include_owner_receive_warning) {
|
|
366
|
+
lines.push("⚠️ OWNER_RECEIVE (156): unwrap forwards to Permission owner (NOT Reward creator).");
|
|
367
|
+
lines.push(" Grant 156 only to dedicated addresses; log every invocation for audit.");
|
|
368
|
+
lines.push("");
|
|
369
|
+
}
|
|
370
|
+
if (h.include_cross_object_refs && bundle.cross_object_refs.length > 0) {
|
|
371
|
+
lines.push(`─ Cross-Object References (${bundle.cross_object_refs.length}) ──────────────`);
|
|
372
|
+
for (const ref of bundle.cross_object_refs.slice(0, 8)) {
|
|
373
|
+
lines.push(` ${ref.object} [${ref.phase}]: ${ref.relationship}`);
|
|
374
|
+
}
|
|
375
|
+
if (bundle.cross_object_refs.length > 8) {
|
|
376
|
+
lines.push(` ... and ${bundle.cross_object_refs.length - 8} more`);
|
|
377
|
+
}
|
|
378
|
+
lines.push("");
|
|
379
|
+
}
|
|
380
|
+
if (bundle.onchain_constraints.length > 0) {
|
|
381
|
+
lines.push("─ On-chain Constraints ──────────────");
|
|
382
|
+
for (const c of bundle.onchain_constraints) {
|
|
383
|
+
const errPart = c.error_code ? ` (abort: ${c.error_code})` : "";
|
|
384
|
+
lines.push(` ${c.name} = ${c.value} — ${c.description}${errPart}`);
|
|
385
|
+
}
|
|
386
|
+
lines.push("");
|
|
387
|
+
}
|
|
388
|
+
return lines.join("\n");
|
|
389
|
+
}
|
|
390
|
+
export function getRewardContextSummary(bundle) {
|
|
391
|
+
const parts = [
|
|
392
|
+
`mode=${bundle.mode}`,
|
|
393
|
+
`scene=${bundle.matched_scene?.id ?? "none"}`,
|
|
394
|
+
`risks=${bundle.relevant_risks.length}`,
|
|
395
|
+
`permissions=${bundle.relevant_builtin_permissions.length}`,
|
|
396
|
+
`constructors=${bundle.relevant_guard_constructors.length}`,
|
|
397
|
+
`cross_refs=${bundle.cross_object_refs.length}`,
|
|
398
|
+
];
|
|
399
|
+
if (bundle.stakeholder_perspective)
|
|
400
|
+
parts.push(`stakeholder=${bundle.stakeholder_perspective}`);
|
|
401
|
+
if (bundle.risk_assessment)
|
|
402
|
+
parts.push(`overall_risk=${bundle.risk_assessment.overall_risk}`);
|
|
403
|
+
if (bundle.matched_template)
|
|
404
|
+
parts.push(`template=${bundle.matched_template.type}`);
|
|
405
|
+
if (bundle.matched_pattern)
|
|
406
|
+
parts.push(`pattern=${bundle.matched_pattern.id}`);
|
|
407
|
+
return parts.join(", ");
|
|
408
|
+
}
|
|
409
|
+
export function buildStakeholderContext(stakeholder, intent, reward_json) {
|
|
410
|
+
return buildRewardContext({
|
|
411
|
+
mode: "stakeholder_review",
|
|
412
|
+
intent,
|
|
413
|
+
reward_json,
|
|
414
|
+
stakeholder,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
export function quickValidateRewardJson(reward_json, current_state = {}) {
|
|
418
|
+
const violations = [];
|
|
419
|
+
if (reward_json.guard_add && reward_json.guard_add.length > 0) {
|
|
420
|
+
const current = current_state.current_guard_count ?? 0;
|
|
421
|
+
const check = validateGuardCount(current);
|
|
422
|
+
if (!check.ok)
|
|
423
|
+
violations.push(check.violation);
|
|
424
|
+
}
|
|
425
|
+
if (reward_json.claim) {
|
|
426
|
+
const records = current_state.current_record_count_for_recipient ?? 0;
|
|
427
|
+
const check = validateRecordCount(records);
|
|
428
|
+
if (!check.ok)
|
|
429
|
+
violations.push(check.violation);
|
|
430
|
+
}
|
|
431
|
+
if (reward_json.coin_add && current_state.reward_type) {
|
|
432
|
+
if (reward_json.coin_add.coin_type !== current_state.reward_type) {
|
|
433
|
+
violations.push(`coin_add type ${reward_json.coin_add.coin_type} ≠ Reward<${current_state.reward_type}>`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (reward_json.claim && current_state.target_guard_addresses) {
|
|
437
|
+
if (!current_state.target_guard_addresses.includes(reward_json.claim)) {
|
|
438
|
+
violations.push(`claim guard ${reward_json.claim} not in Reward.guards — E_GUARD_NOT_FOUND`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (reward_json.claim && current_state.current_balance !== undefined) {
|
|
442
|
+
const balance = BigInt(current_state.current_balance);
|
|
443
|
+
if (balance === 0n) {
|
|
444
|
+
violations.push("balance=0 — E_INSUFFICIENT_BALANCE will abort claim");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (reward_json.guard_expiration_time !== undefined &&
|
|
448
|
+
reward_json.guard_expiration_time !== null &&
|
|
449
|
+
current_state.current_clock_ms !== undefined) {
|
|
450
|
+
if (reward_json.guard_expiration_time <= current_state.current_clock_ms) {
|
|
451
|
+
violations.push(`guard_expiration_time ${reward_json.guard_expiration_time} ≤ clock ${current_state.current_clock_ms} — E_GUARD_LOCKED_TIME_INVALID`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return { ok: violations.length === 0, violations };
|
|
455
|
+
}
|
|
456
|
+
export function getRewardKnowledgeSnapshot() {
|
|
457
|
+
return {
|
|
458
|
+
version: {
|
|
459
|
+
ledger: REWARD_LEDGER_VERSION,
|
|
460
|
+
puzzle: "1.0.0",
|
|
461
|
+
risk: REWARD_RISK_VERSION,
|
|
462
|
+
translation: REWARD_TRANSLATION_VERSION,
|
|
463
|
+
templates: REWARD_TEMPLATES_VERSION,
|
|
464
|
+
confirm: REWARD_CONFIRM_VERSION,
|
|
465
|
+
context: REWARD_CONTEXT_VERSION,
|
|
466
|
+
},
|
|
467
|
+
scenes_count: getRewardScenesCount(),
|
|
468
|
+
builtin_permissions_count: REWARD_PERMISSIONS.length,
|
|
469
|
+
builtin_permissions: REWARD_PERMISSIONS.map(p => ({
|
|
470
|
+
index: p.index,
|
|
471
|
+
name: p.name,
|
|
472
|
+
sdk_exposed: p.sdk_exposed,
|
|
473
|
+
})),
|
|
474
|
+
guard_constructors_count: REWARD_GUARD_CONSTRUCTORS.length,
|
|
475
|
+
guard_constructors: REWARD_GUARD_CONSTRUCTORS.map(c => ({
|
|
476
|
+
constructor: c.constructor,
|
|
477
|
+
recipient_type: c.recipient_type,
|
|
478
|
+
amount_type: c.amount_type,
|
|
479
|
+
})),
|
|
480
|
+
error_codes_count: REWARD_ERROR_CODES.length,
|
|
481
|
+
templates_count: REWARD_TEMPLATES.length,
|
|
482
|
+
templates: listRewardTemplates(),
|
|
483
|
+
semantic_patterns_count: REWARD_SEMANTIC_TO_SCHEMA_RULES.length,
|
|
484
|
+
schema_rules_count: REWARD_SCHEMA_TO_SEMANTIC_RULES.length,
|
|
485
|
+
constraint_rules_count: REWARD_CONSTRAINT_RULES.length,
|
|
486
|
+
risk_rules_count: getRewardRiskRulesCount(),
|
|
487
|
+
checklist_count: REWARD_OPERATION_CHECKLIST.length,
|
|
488
|
+
confirmation_questions_count: REWARD_CONFIRMATION_QUESTIONS.length,
|
|
489
|
+
cross_object_refs_count: REWARD_CROSS_OBJECT_REFS.length,
|
|
490
|
+
onchain_limits: {
|
|
491
|
+
max_guard_count_reward: MAX_GUARD_COUNT_REWARD,
|
|
492
|
+
max_record_count_reward: MAX_RECORD_COUNT_REWARD,
|
|
493
|
+
},
|
|
494
|
+
injection_modes: [
|
|
495
|
+
"initial_design",
|
|
496
|
+
"pre_claim",
|
|
497
|
+
"post_claim",
|
|
498
|
+
"guard_review",
|
|
499
|
+
"balance_review",
|
|
500
|
+
"stakeholder_review",
|
|
501
|
+
],
|
|
502
|
+
stakeholders: REWARD_STAKEHOLDERS,
|
|
503
|
+
};
|
|
504
|
+
}
|