@wowok/agent-mcp 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/runtime.d.ts +4 -0
- package/dist/config/runtime.js +29 -5
- package/dist/harness/auto-escalation.d.ts +27 -0
- package/dist/harness/auto-escalation.js +68 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -1621
- package/dist/knowledge/allocation-confirm.d.ts +115 -0
- package/dist/knowledge/allocation-confirm.js +534 -0
- package/dist/knowledge/allocation-context.d.ts +58 -0
- package/dist/knowledge/allocation-context.js +249 -0
- package/dist/knowledge/allocation-ledger.d.ts +67 -0
- package/dist/knowledge/allocation-ledger.js +463 -0
- package/dist/knowledge/allocation-puzzle.d.ts +135 -0
- package/dist/knowledge/allocation-puzzle.js +298 -0
- package/dist/knowledge/allocation-risk.d.ts +78 -0
- package/dist/knowledge/allocation-risk.js +568 -0
- package/dist/knowledge/allocation-templates.d.ts +38 -0
- package/dist/knowledge/allocation-templates.js +970 -0
- package/dist/knowledge/allocation-translation.d.ts +72 -0
- package/dist/knowledge/allocation-translation.js +585 -0
- package/dist/knowledge/arb-risk.d.ts +37 -0
- package/dist/knowledge/arb-risk.js +210 -0
- package/dist/knowledge/arbitration-confirm.d.ts +135 -0
- package/dist/knowledge/arbitration-confirm.js +559 -0
- package/dist/knowledge/arbitration-context.d.ts +81 -0
- package/dist/knowledge/arbitration-context.js +505 -0
- package/dist/knowledge/arbitration-ledger.d.ts +62 -0
- package/dist/knowledge/arbitration-ledger.js +521 -0
- package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
- package/dist/knowledge/arbitration-puzzle.js +304 -0
- package/dist/knowledge/arbitration-risk.d.ts +112 -0
- package/dist/knowledge/arbitration-risk.js +433 -0
- package/dist/knowledge/arbitration-templates.d.ts +38 -0
- package/dist/knowledge/arbitration-templates.js +276 -0
- package/dist/knowledge/arbitration-translation.d.ts +91 -0
- package/dist/knowledge/arbitration-translation.js +487 -0
- package/dist/knowledge/bridge-risk.d.ts +36 -0
- package/dist/knowledge/bridge-risk.js +263 -0
- package/dist/knowledge/contact-risk.d.ts +32 -0
- package/dist/knowledge/contact-risk.js +200 -0
- package/dist/knowledge/demand-confirm.d.ts +32 -0
- package/dist/knowledge/demand-confirm.js +206 -0
- package/dist/knowledge/demand-risk.d.ts +30 -0
- package/dist/knowledge/demand-risk.js +240 -0
- package/dist/knowledge/demand-translation.d.ts +55 -0
- package/dist/knowledge/demand-translation.js +354 -0
- package/dist/knowledge/deployment-scanner.d.ts +63 -0
- package/dist/knowledge/deployment-scanner.js +762 -0
- package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
- package/dist/knowledge/examples-scanner-cli.js +26 -0
- package/dist/knowledge/examples-scanner.d.ts +121 -0
- package/dist/knowledge/examples-scanner.js +825 -0
- package/dist/knowledge/flywheel-loop.d.ts +3 -0
- package/dist/knowledge/flywheel-loop.js +32 -3
- package/dist/knowledge/glossary.js +3 -1
- package/dist/knowledge/guard-confirm.d.ts +86 -0
- package/dist/knowledge/guard-confirm.js +406 -0
- package/dist/knowledge/guard-context.d.ts +56 -0
- package/dist/knowledge/guard-context.js +287 -0
- package/dist/knowledge/guard-design-patterns.d.ts +37 -0
- package/dist/knowledge/guard-design-patterns.js +257 -0
- package/dist/knowledge/guard-ledger.js +14 -0
- package/dist/knowledge/guard-lint.d.ts +1 -0
- package/dist/knowledge/guard-lint.js +83 -3
- package/dist/knowledge/guard-migration.d.ts +48 -0
- package/dist/knowledge/guard-migration.js +228 -0
- package/dist/knowledge/guard-puzzle.js +3 -2
- package/dist/knowledge/guard-risk.d.ts +3 -1
- package/dist/knowledge/guard-risk.js +832 -64
- package/dist/knowledge/guard-templates.d.ts +1 -0
- package/dist/knowledge/guard-templates.js +278 -2
- package/dist/knowledge/guard-translation.js +6 -5
- package/dist/knowledge/index.d.ts +342 -0
- package/dist/knowledge/index.js +344 -0
- package/dist/knowledge/machine-confirm.d.ts +102 -0
- package/dist/knowledge/machine-confirm.js +559 -0
- package/dist/knowledge/machine-context.d.ts +160 -0
- package/dist/knowledge/machine-context.js +812 -0
- package/dist/knowledge/machine-ledger.d.ts +41 -0
- package/dist/knowledge/machine-ledger.js +315 -0
- package/dist/knowledge/machine-puzzle.d.ts +206 -0
- package/dist/knowledge/machine-puzzle.js +494 -0
- package/dist/knowledge/machine-risk.d.ts +75 -0
- package/dist/knowledge/machine-risk.js +644 -0
- package/dist/knowledge/machine-templates.d.ts +92 -0
- package/dist/knowledge/machine-templates.js +1592 -0
- package/dist/knowledge/machine-topology.d.ts +57 -0
- package/dist/knowledge/machine-topology.js +234 -0
- package/dist/knowledge/machine-translation.d.ts +96 -0
- package/dist/knowledge/machine-translation.js +513 -0
- package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
- package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
- package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
- package/dist/knowledge/mcp-schema-audit.js +772 -0
- package/dist/knowledge/onchain-constants.d.ts +4 -0
- package/dist/knowledge/onchain-constants.js +35 -0
- package/dist/knowledge/order-confirm.d.ts +115 -0
- package/dist/knowledge/order-confirm.js +573 -0
- package/dist/knowledge/order-context.d.ts +66 -0
- package/dist/knowledge/order-context.js +390 -0
- package/dist/knowledge/order-ledger.d.ts +69 -0
- package/dist/knowledge/order-ledger.js +341 -0
- package/dist/knowledge/order-puzzle.d.ts +159 -0
- package/dist/knowledge/order-puzzle.js +255 -0
- package/dist/knowledge/order-risk.d.ts +66 -0
- package/dist/knowledge/order-risk.js +653 -0
- package/dist/knowledge/order-templates.d.ts +50 -0
- package/dist/knowledge/order-templates.js +368 -0
- package/dist/knowledge/order-translation.d.ts +78 -0
- package/dist/knowledge/order-translation.js +550 -0
- package/dist/knowledge/passport-confirm.d.ts +130 -0
- package/dist/knowledge/passport-confirm.js +531 -0
- package/dist/knowledge/passport-context.d.ts +59 -0
- package/dist/knowledge/passport-context.js +306 -0
- package/dist/knowledge/passport-ledger.d.ts +48 -0
- package/dist/knowledge/passport-ledger.js +282 -0
- package/dist/knowledge/passport-puzzle.d.ts +108 -0
- package/dist/knowledge/passport-puzzle.js +333 -0
- package/dist/knowledge/passport-risk.d.ts +70 -0
- package/dist/knowledge/passport-risk.js +450 -0
- package/dist/knowledge/passport-templates.d.ts +40 -0
- package/dist/knowledge/passport-templates.js +568 -0
- package/dist/knowledge/passport-translation.d.ts +68 -0
- package/dist/knowledge/passport-translation.js +516 -0
- package/dist/knowledge/payment-risk.d.ts +33 -0
- package/dist/knowledge/payment-risk.js +182 -0
- package/dist/knowledge/permission-confirm.d.ts +110 -0
- package/dist/knowledge/permission-confirm.js +426 -0
- package/dist/knowledge/permission-context.d.ts +58 -0
- package/dist/knowledge/permission-context.js +224 -0
- package/dist/knowledge/permission-ledger.d.ts +38 -0
- package/dist/knowledge/permission-ledger.js +403 -0
- package/dist/knowledge/permission-puzzle.d.ts +122 -0
- package/dist/knowledge/permission-puzzle.js +173 -0
- package/dist/knowledge/permission-risk.d.ts +76 -0
- package/dist/knowledge/permission-risk.js +411 -0
- package/dist/knowledge/permission-templates.d.ts +38 -0
- package/dist/knowledge/permission-templates.js +234 -0
- package/dist/knowledge/permission-translation.d.ts +57 -0
- package/dist/knowledge/permission-translation.js +350 -0
- package/dist/knowledge/personal-risk.d.ts +36 -0
- package/dist/knowledge/personal-risk.js +212 -0
- package/dist/knowledge/progress-confirm.d.ts +108 -0
- package/dist/knowledge/progress-confirm.js +456 -0
- package/dist/knowledge/progress-context.d.ts +123 -0
- package/dist/knowledge/progress-context.js +452 -0
- package/dist/knowledge/progress-ledger.d.ts +63 -0
- package/dist/knowledge/progress-ledger.js +327 -0
- package/dist/knowledge/progress-puzzle.d.ts +82 -0
- package/dist/knowledge/progress-puzzle.js +219 -0
- package/dist/knowledge/progress-risk.d.ts +74 -0
- package/dist/knowledge/progress-risk.js +461 -0
- package/dist/knowledge/progress-templates.d.ts +38 -0
- package/dist/knowledge/progress-templates.js +228 -0
- package/dist/knowledge/progress-translation.d.ts +52 -0
- package/dist/knowledge/progress-translation.js +401 -0
- package/dist/knowledge/proof-confirm.d.ts +31 -0
- package/dist/knowledge/proof-confirm.js +187 -0
- package/dist/knowledge/proof-risk.d.ts +33 -0
- package/dist/knowledge/proof-risk.js +207 -0
- package/dist/knowledge/proof-translation.d.ts +52 -0
- package/dist/knowledge/proof-translation.js +283 -0
- package/dist/knowledge/registrar-risk.d.ts +34 -0
- package/dist/knowledge/registrar-risk.js +217 -0
- package/dist/knowledge/repository-confirm.d.ts +36 -0
- package/dist/knowledge/repository-confirm.js +242 -0
- package/dist/knowledge/repository-risk.d.ts +40 -0
- package/dist/knowledge/repository-risk.js +312 -0
- package/dist/knowledge/repository-translation.d.ts +58 -0
- package/dist/knowledge/repository-translation.js +422 -0
- package/dist/knowledge/resource-risk.d.ts +32 -0
- package/dist/knowledge/resource-risk.js +157 -0
- package/dist/knowledge/reward-confirm.d.ts +113 -0
- package/dist/knowledge/reward-confirm.js +496 -0
- package/dist/knowledge/reward-context.d.ts +127 -0
- package/dist/knowledge/reward-context.js +504 -0
- package/dist/knowledge/reward-ledger.d.ts +96 -0
- package/dist/knowledge/reward-ledger.js +502 -0
- package/dist/knowledge/reward-puzzle.d.ts +97 -0
- package/dist/knowledge/reward-puzzle.js +288 -0
- package/dist/knowledge/reward-risk.d.ts +84 -0
- package/dist/knowledge/reward-risk.js +545 -0
- package/dist/knowledge/reward-translation.d.ts +58 -0
- package/dist/knowledge/reward-translation.js +501 -0
- package/dist/knowledge/safety-rules.js +11 -3
- package/dist/knowledge/scenario-modes.d.ts +53 -0
- package/dist/knowledge/scenario-modes.js +302 -0
- package/dist/knowledge/service-confirm.d.ts +152 -0
- package/dist/knowledge/service-confirm.js +699 -0
- package/dist/knowledge/service-context.d.ts +66 -0
- package/dist/knowledge/service-context.js +403 -0
- package/dist/knowledge/service-ledger.d.ts +71 -0
- package/dist/knowledge/service-ledger.js +609 -0
- package/dist/knowledge/service-puzzle.d.ts +158 -0
- package/dist/knowledge/service-puzzle.js +236 -0
- package/dist/knowledge/service-risk.d.ts +108 -0
- package/dist/knowledge/service-risk.js +615 -0
- package/dist/knowledge/service-templates.d.ts +39 -0
- package/dist/knowledge/service-templates.js +418 -0
- package/dist/knowledge/service-translation.d.ts +103 -0
- package/dist/knowledge/service-translation.js +622 -0
- package/dist/knowledge/tools-reference.d.ts +17 -0
- package/dist/knowledge/tools-reference.js +151 -0
- package/dist/knowledge/treasury-confirm.d.ts +133 -0
- package/dist/knowledge/treasury-confirm.js +512 -0
- package/dist/knowledge/treasury-context.d.ts +64 -0
- package/dist/knowledge/treasury-context.js +363 -0
- package/dist/knowledge/treasury-ledger.d.ts +42 -0
- package/dist/knowledge/treasury-ledger.js +300 -0
- package/dist/knowledge/treasury-puzzle.d.ts +163 -0
- package/dist/knowledge/treasury-puzzle.js +216 -0
- package/dist/knowledge/treasury-risk.d.ts +86 -0
- package/dist/knowledge/treasury-risk.js +440 -0
- package/dist/knowledge/treasury-templates.d.ts +38 -0
- package/dist/knowledge/treasury-templates.js +316 -0
- package/dist/knowledge/treasury-translation.d.ts +78 -0
- package/dist/knowledge/treasury-translation.js +498 -0
- package/dist/knowledge/util-risk.d.ts +30 -0
- package/dist/knowledge/util-risk.js +135 -0
- package/dist/project/business-puzzle.d.ts +47 -0
- package/dist/project/business-puzzle.js +372 -0
- package/dist/project/deployment-doc.d.ts +61 -0
- package/dist/project/deployment-doc.js +432 -0
- package/dist/project/graph.d.ts +1 -0
- package/dist/project/graph.js +27 -1
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +39 -2
- package/dist/project/namespace.d.ts +11 -1
- package/dist/project/namespace.js +27 -2
- package/dist/project/query.d.ts +2 -0
- package/dist/project/query.js +56 -15
- package/dist/project/risk-aggregator.d.ts +50 -0
- package/dist/project/risk-aggregator.js +280 -0
- package/dist/project/substep-trace.d.ts +130 -0
- package/dist/project/substep-trace.js +332 -0
- package/dist/rules.d.ts +12 -0
- package/dist/rules.js +9 -0
- package/dist/schema/call/allocation.d.ts +44 -44
- package/dist/schema/call/arbitration.d.ts +141 -141
- package/dist/schema/call/base.d.ts +386 -386
- package/dist/schema/call/base.js +6 -6
- package/dist/schema/call/bridge-handler.d.ts +5 -2
- package/dist/schema/call/bridge.d.ts +159 -159
- package/dist/schema/call/contact.d.ts +110 -110
- package/dist/schema/call/demand.d.ts +76 -76
- package/dist/schema/call/handler.d.ts +2 -3
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.d.ts +96 -96
- package/dist/schema/call/order.d.ts +98 -110
- package/dist/schema/call/permission-handler.d.ts +5 -0
- package/dist/schema/call/permission-handler.js +54 -0
- package/dist/schema/call/permission.d.ts +108 -108
- package/dist/schema/call/personal.d.ts +14 -14
- package/dist/schema/call/progress.d.ts +57 -72
- package/dist/schema/call/progress.js +7 -4
- package/dist/schema/call/proof.d.ts +18 -18
- package/dist/schema/call/proof.js +12 -7
- package/dist/schema/call/repository.d.ts +154 -154
- package/dist/schema/call/reward.d.ts +55 -55
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +238 -238
- package/dist/schema/call/treasury.d.ts +93 -93
- package/dist/schema/config/index.d.ts +178 -5
- package/dist/schema/config/index.js +52 -1
- package/dist/schema/local/index.d.ts +3554 -836
- package/dist/schema/local/index.js +2 -1
- package/dist/schema/messenger/index.d.ts +162 -162
- package/dist/schema/operations.d.ts +1102 -1118
- package/dist/schema/operations.js +7 -1
- package/dist/schema/project/index.d.ts +1392 -6
- package/dist/schema/project/index.js +426 -2
- package/dist/schema/query/index.d.ts +818 -818
- package/dist/schema/query/index.js +15 -9
- package/dist/schema/schema-query/index.d.ts +23 -3
- package/dist/schema/schema-query/index.js +13 -2
- package/dist/schema/sync-layer4.d.ts +21 -0
- package/dist/schema/sync-layer4.js +261 -0
- package/dist/schema/trust/index.d.ts +26 -26
- package/dist/schema/utils/guard-query-utils.d.ts +7 -0
- package/dist/schema/utils/guard-query-utils.js +14 -1
- package/dist/schemas/account_operation.output.json +718 -0
- package/dist/schemas/bridge_operation.output.json +1 -1
- package/dist/schemas/config_operation.output.json +173 -0
- package/dist/schemas/index.json +9 -1
- package/dist/schemas/local_info_operation.output.json +718 -0
- package/dist/schemas/local_mark_operation.output.json +718 -0
- package/dist/schemas/messenger_operation.output.json +1 -1
- package/dist/schemas/onchain_events.output.json +1 -1
- package/dist/schemas/onchain_operations.output.json +5 -4
- package/dist/schemas/onchain_operations.schema.json +1813 -333
- package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
- package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
- package/dist/schemas/onchain_operations_contact.schema.json +2 -1
- package/dist/schemas/onchain_operations_demand.schema.json +2 -1
- package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
- package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
- package/dist/schemas/onchain_operations_guard.schema.json +584 -70
- package/dist/schemas/onchain_operations_machine.schema.json +4 -6
- package/dist/schemas/onchain_operations_order.schema.json +13 -9
- package/dist/schemas/onchain_operations_payment.schema.json +2 -1
- package/dist/schemas/onchain_operations_permission.schema.json +2 -1
- package/dist/schemas/onchain_operations_personal.schema.json +2 -1
- package/dist/schemas/onchain_operations_progress.schema.json +14 -10
- package/dist/schemas/onchain_operations_proof.schema.json +699 -0
- package/dist/schemas/onchain_operations_repository.schema.json +2 -1
- package/dist/schemas/onchain_operations_reward.schema.json +2 -1
- package/dist/schemas/onchain_operations_service.schema.json +4 -6
- package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
- package/dist/schemas/onchain_table_data.output.json +6 -12
- package/dist/schemas/onchain_table_data.schema.json +32 -1
- package/dist/schemas/project_operation.output.json +879 -0
- package/dist/schemas/project_operation.schema.json +473 -2
- package/dist/schemas/query_toolkit.output.json +14906 -6
- package/dist/schemas/schema_query.output.json +38 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/handlers/bridge.d.ts +1 -0
- package/dist/tools/handlers/bridge.js +1 -0
- package/dist/tools/handlers/config.d.ts +2 -0
- package/dist/tools/handlers/config.js +74 -0
- package/dist/tools/handlers/file-export.d.ts +3 -0
- package/dist/tools/handlers/file-export.js +90 -0
- package/dist/tools/handlers/local.d.ts +3 -0
- package/dist/tools/handlers/local.js +38 -0
- package/dist/tools/handlers/messenger.d.ts +16 -0
- package/dist/tools/handlers/messenger.js +188 -0
- package/dist/tools/handlers/onchain.d.ts +2 -0
- package/dist/tools/handlers/onchain.js +248 -0
- package/dist/tools/handlers/project.d.ts +2 -0
- package/dist/tools/handlers/project.js +293 -0
- package/dist/tools/handlers/query.d.ts +5 -0
- package/dist/tools/handlers/query.js +256 -0
- package/dist/tools/handlers/schema-query.d.ts +2 -0
- package/dist/tools/handlers/schema-query.js +93 -0
- package/dist/tools/handlers/trust.d.ts +2 -0
- package/dist/tools/handlers/trust.js +194 -0
- package/dist/tools/handlers/wip.d.ts +2 -0
- package/dist/tools/handlers/wip.js +44 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +526 -0
- package/dist/tools/rules-hook.d.ts +2 -0
- package/dist/tools/rules-hook.js +23 -0
- package/dist/tools/shared.d.ts +20 -0
- package/dist/tools/shared.js +130 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/wrap.d.ts +14 -0
- package/dist/tools/wrap.js +267 -0
- package/package.json +20 -6
|
@@ -82,6 +82,9 @@ export declare const EVOLUTION_STATE_VERSION = 1;
|
|
|
82
82
|
export declare function saveEvolutionState(): string;
|
|
83
83
|
export declare function loadEvolutionState(): boolean;
|
|
84
84
|
export declare function hasPersistedEvolutionState(): boolean;
|
|
85
|
+
export declare function sanitizeSignal(signal: IndustrySignal): IndustrySignal;
|
|
86
|
+
export declare function sanitizeDecisionContext(ctx: DecisionContext): DecisionContext;
|
|
87
|
+
export declare function checkAndTriggerCognitionUpdate(industry: string): CognitionUpdateResult;
|
|
85
88
|
export declare function _resetFlywheelLoopForTest(): void;
|
|
86
89
|
export declare function _snapshotSignalBuffer(): Record<string, IndustrySignal[]>;
|
|
87
90
|
export { MIN_SIGNALS_FOR_EVOLUTION as FLYWHEEL_LOOP_MIN_SIGNALS };
|
|
@@ -7,7 +7,10 @@ import { homedir } from "os";
|
|
|
7
7
|
export const FLYWHEEL_LOOP_VERSION = 2;
|
|
8
8
|
const MIN_SIGNALS_FOR_EVOLUTION = 10;
|
|
9
9
|
const DEFAULT_SCHEDULE = {
|
|
10
|
-
mode: "
|
|
10
|
+
mode: "semi_realtime",
|
|
11
|
+
signal_threshold: 20,
|
|
12
|
+
time_interval_ms: 5 * 60 * 1000,
|
|
13
|
+
auto_apply: false,
|
|
11
14
|
};
|
|
12
15
|
const industrySchedules = new Map();
|
|
13
16
|
const industryLastUpdate = new Map();
|
|
@@ -21,13 +24,14 @@ export function recordIndustrySignal(industry, operation, outcome) {
|
|
|
21
24
|
if (!industry)
|
|
22
25
|
return;
|
|
23
26
|
const resolved = resolveIndustryName(industry) ?? industry;
|
|
24
|
-
const
|
|
27
|
+
const rawSignal = {
|
|
25
28
|
industry: resolved,
|
|
26
29
|
operation_type: operation.type,
|
|
27
30
|
success: outcome.success,
|
|
28
31
|
error_code: outcome.error_code,
|
|
29
32
|
timestamp: Date.now(),
|
|
30
33
|
};
|
|
34
|
+
const signal = sanitizeSignal(rawSignal);
|
|
31
35
|
const list = signalBuffer.get(resolved) ?? [];
|
|
32
36
|
list.push(signal);
|
|
33
37
|
signalBuffer.set(resolved, list);
|
|
@@ -112,7 +116,8 @@ export function getPendingSuggestions(industry) {
|
|
|
112
116
|
export function recordDecisionContext(ctx, graph) {
|
|
113
117
|
if (!ctx.id || !ctx.node_id)
|
|
114
118
|
return;
|
|
115
|
-
|
|
119
|
+
const sanitized = sanitizeDecisionContext(ctx);
|
|
120
|
+
decisionContexts.set(ctx.id, sanitized);
|
|
116
121
|
if (graph) {
|
|
117
122
|
try {
|
|
118
123
|
graph.attachDecisionContext(ctx.node_id, {
|
|
@@ -362,6 +367,30 @@ export function loadEvolutionState() {
|
|
|
362
367
|
export function hasPersistedEvolutionState() {
|
|
363
368
|
return existsSync(evolutionStateFilePath());
|
|
364
369
|
}
|
|
370
|
+
export function sanitizeSignal(signal) {
|
|
371
|
+
return {
|
|
372
|
+
industry: signal.industry,
|
|
373
|
+
operation_type: signal.operation_type,
|
|
374
|
+
success: signal.success,
|
|
375
|
+
error_code: signal.error_code,
|
|
376
|
+
timestamp: signal.timestamp,
|
|
377
|
+
decision_context_id: signal.decision_context_id,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
export function sanitizeDecisionContext(ctx) {
|
|
381
|
+
return {
|
|
382
|
+
id: ctx.id,
|
|
383
|
+
node_id: ctx.node_id,
|
|
384
|
+
decided_at: ctx.decided_at,
|
|
385
|
+
decider: ctx.decider,
|
|
386
|
+
industry: ctx.industry,
|
|
387
|
+
intent: ctx.intent,
|
|
388
|
+
outcome: ctx.outcome,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
export function checkAndTriggerCognitionUpdate(industry) {
|
|
392
|
+
return updateIndustryCognition(industry);
|
|
393
|
+
}
|
|
365
394
|
export function _resetFlywheelLoopForTest() {
|
|
366
395
|
signalBuffer.clear();
|
|
367
396
|
decisionContexts.clear();
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { USER_DEFINED_PERM_INDEX_START } from "./onchain-constants.js";
|
|
1
2
|
export const CONCEPT_GLOSSARY = [
|
|
2
3
|
{
|
|
3
4
|
term: "Permission",
|
|
4
|
-
definition:
|
|
5
|
+
definition: `Organization-wide permission object. indices 0-${USER_DEFINED_PERM_INDEX_START - 1} builtin, ` +
|
|
6
|
+
`${USER_DEFINED_PERM_INDEX_START}-65535 custom. ` +
|
|
5
7
|
"Shared across all Progress instances of a Service. Use for internal staff roles.",
|
|
6
8
|
aliases: ["permission object"],
|
|
7
9
|
category: "permission",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type GuardRiskAssessment, type RiskLevel } from "./guard-risk.js";
|
|
2
|
+
import { type GuardValidationIssue } from "@wowok/wowok";
|
|
3
|
+
export type GuardConfirmGateStatus = "approved" | "blocked_checklist" | "blocked_risk" | "blocked_user" | "blocked_environment";
|
|
4
|
+
export interface GuardConfirmGateResult {
|
|
5
|
+
status: GuardConfirmGateStatus;
|
|
6
|
+
checklist_result: GuardChecklistResult;
|
|
7
|
+
risk_result?: GuardRiskAssessmentResult;
|
|
8
|
+
user_confirmation?: GuardUserConfirmation;
|
|
9
|
+
environment_result?: GuardEnvironmentResult;
|
|
10
|
+
confirmation_text?: string;
|
|
11
|
+
block_reason?: string;
|
|
12
|
+
decision_record: GuardDecisionRecord;
|
|
13
|
+
}
|
|
14
|
+
export interface GuardChecklistResult {
|
|
15
|
+
passed: boolean;
|
|
16
|
+
checked_items: GuardChecklistItem[];
|
|
17
|
+
failed_items: GuardChecklistItem[];
|
|
18
|
+
warnings: GuardChecklistItem[];
|
|
19
|
+
}
|
|
20
|
+
export interface GuardChecklistItem {
|
|
21
|
+
id: string;
|
|
22
|
+
description: string;
|
|
23
|
+
status: "pass" | "fail" | "warning" | "skip";
|
|
24
|
+
detail?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface GuardRiskAssessmentResult {
|
|
27
|
+
overall_risk_level: RiskLevel;
|
|
28
|
+
blocking_risks: string[];
|
|
29
|
+
warning_risks: string[];
|
|
30
|
+
recommendation: "publish" | "fix_first" | "do_not_publish";
|
|
31
|
+
}
|
|
32
|
+
export interface GuardUserConfirmation {
|
|
33
|
+
questions_asked: GuardConfirmationQuestion[];
|
|
34
|
+
user_responses: GuardConfirmationResponse[];
|
|
35
|
+
approved: boolean;
|
|
36
|
+
declined_reason?: string;
|
|
37
|
+
timestamp: string;
|
|
38
|
+
}
|
|
39
|
+
export interface GuardConfirmationQuestion {
|
|
40
|
+
id: string;
|
|
41
|
+
question: string;
|
|
42
|
+
expected_response: "yes" | "no" | "either";
|
|
43
|
+
blocking: boolean;
|
|
44
|
+
explanation?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface GuardConfirmationResponse {
|
|
47
|
+
question_id: string;
|
|
48
|
+
response: "yes" | "no";
|
|
49
|
+
reason?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface GuardEnvironmentResult {
|
|
52
|
+
testnet_tested: boolean;
|
|
53
|
+
binding_target_exists: boolean;
|
|
54
|
+
rely_chain_resolvable: boolean;
|
|
55
|
+
passport_generated_successfully: boolean;
|
|
56
|
+
warnings: string[];
|
|
57
|
+
}
|
|
58
|
+
export interface GuardDecisionRecord {
|
|
59
|
+
final_decision: "approved" | "blocked";
|
|
60
|
+
final_reason?: string;
|
|
61
|
+
timestamp: string;
|
|
62
|
+
layers_passed: ("checklist" | "risk" | "user" | "environment")[];
|
|
63
|
+
}
|
|
64
|
+
export interface GuardJsonForConfirm {
|
|
65
|
+
name?: string;
|
|
66
|
+
root: unknown;
|
|
67
|
+
description?: string;
|
|
68
|
+
binding_target?: string;
|
|
69
|
+
binding_scene_id?: string;
|
|
70
|
+
}
|
|
71
|
+
export declare const GUARD_PUBLISH_CHECKLIST: GuardChecklistItem[];
|
|
72
|
+
export declare const GUARD_CONFIRMATION_QUESTIONS: GuardConfirmationQuestion[];
|
|
73
|
+
export declare const GUARD_CONFIRM_VERSION = "1.0.0";
|
|
74
|
+
export interface GuardConfirmGateInput {
|
|
75
|
+
guard_json: GuardJsonForConfirm;
|
|
76
|
+
skip_user_confirmation?: boolean;
|
|
77
|
+
skip_environment?: boolean;
|
|
78
|
+
existing_lint_issues?: GuardValidationIssue[];
|
|
79
|
+
existing_risk_assessment?: GuardRiskAssessment;
|
|
80
|
+
user_responses?: GuardConfirmationResponse[];
|
|
81
|
+
}
|
|
82
|
+
export declare function runGuardConfirmGate(input: GuardConfirmGateInput): GuardConfirmGateResult;
|
|
83
|
+
export declare function progressiveGuardCheck(guard_json: GuardJsonForConfirm): {
|
|
84
|
+
layer: "checklist" | "risk" | "none";
|
|
85
|
+
result: GuardChecklistResult | GuardRiskAssessmentResult | null;
|
|
86
|
+
};
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { assessGuardRisks, } from "./guard-risk.js";
|
|
2
|
+
import { GUARD_SCENES, } from "./guard-ledger.js";
|
|
3
|
+
export const GUARD_PUBLISH_CHECKLIST = [
|
|
4
|
+
{
|
|
5
|
+
id: "GC-01",
|
|
6
|
+
description: "Root node exists and is a valid GuardNode type",
|
|
7
|
+
status: "skip",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "GC-02",
|
|
11
|
+
description: "All table entries have valid value_type (0-18)",
|
|
12
|
+
status: "skip",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "GC-03",
|
|
16
|
+
description: "Table size within MAX_TABLE_SIZE limit",
|
|
17
|
+
status: "skip",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "GC-04",
|
|
21
|
+
description: "Description length within MAX_DESCRIPTION_LENGTH",
|
|
22
|
+
status: "skip",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "GC-05",
|
|
26
|
+
description: "Binding scene identified (one of 8 scenes) or Standalone",
|
|
27
|
+
status: "skip",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "GC-06",
|
|
31
|
+
description: "All query nodes reference valid GUARDQUERY instructions",
|
|
32
|
+
status: "skip",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "GC-07",
|
|
36
|
+
description: "All witness nodes use valid WitnessType (100-108)",
|
|
37
|
+
status: "skip",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "GC-08",
|
|
41
|
+
description: "No circular rely chain in root tree",
|
|
42
|
+
status: "skip",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "GC-09",
|
|
46
|
+
description: "Type compatibility verified for all equal/compare nodes",
|
|
47
|
+
status: "skip",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "GC-10",
|
|
51
|
+
description: "Context nodes (Signer/Clock/Guard) used with correct semantics",
|
|
52
|
+
status: "skip",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "GC-11",
|
|
56
|
+
description: "Submission data (b_submission=true) marked as Type3 with forgery risk evaluated",
|
|
57
|
+
status: "skip",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "GC-12",
|
|
61
|
+
description: "Immutability acknowledged — Guard CANNOT be modified after creation",
|
|
62
|
+
status: "skip",
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
export const GUARD_CONFIRMATION_QUESTIONS = [
|
|
66
|
+
{
|
|
67
|
+
id: "QG1",
|
|
68
|
+
question: "Have you verified that the Guard's validation rule matches your business intent (e.g., 'customer must have paid' rather than 'customer must NOT have paid')?",
|
|
69
|
+
expected_response: "yes",
|
|
70
|
+
blocking: true,
|
|
71
|
+
explanation: "Inverted logic is the #1 cause of Guard failures. The rule_sentence in your puzzle should match the on-chain enforcement direction.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "QG2",
|
|
75
|
+
question: "Have you confirmed that all Type3 (b_submission=true) data sources are forgery-resistant (submitted by trusted callers, not user-supplied)?",
|
|
76
|
+
expected_response: "yes",
|
|
77
|
+
blocking: true,
|
|
78
|
+
explanation: "Type3 data is the most common attack vector. If users can submit arbitrary values, the Guard is bypassable.",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "QG3",
|
|
82
|
+
question: "Have you tested the Guard on testnet with gen_passport to verify it returns the expected pass/fail result for both valid and invalid inputs?",
|
|
83
|
+
expected_response: "yes",
|
|
84
|
+
blocking: true,
|
|
85
|
+
explanation: "gen_passport is the only way to test Guard evaluation without binding it. Skipping this risks publishing a broken Guard.",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "QG4",
|
|
89
|
+
question: "Is the binding target (Service/Machine/Reward/etc.) already published or planned in the same deployment batch?",
|
|
90
|
+
expected_response: "yes",
|
|
91
|
+
blocking: false,
|
|
92
|
+
explanation: "Guard can be created standalone, but its binding field expects an existing object. Plan creation order accordingly.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "QG5",
|
|
96
|
+
question: "Are you aware that this Guard is IMMUTABLE after creation and cannot be modified (only a new version can be created)?",
|
|
97
|
+
expected_response: "yes",
|
|
98
|
+
blocking: true,
|
|
99
|
+
explanation: "Unlike Machine (which allows permission changes), Guard has NO update entry point. Review the rule twice before confirming.",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "QG6",
|
|
103
|
+
question: "Have you reviewed the game-theory implications — does this Guard favor one stakeholder (customer/provider/arbitrator) unfairly?",
|
|
104
|
+
expected_response: "no",
|
|
105
|
+
blocking: false,
|
|
106
|
+
explanation: "Answer 'no' = no unfair advantage. If 'yes', review the game_theory risk rules in guard-risk.ts and adjust.",
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
export const GUARD_CONFIRM_VERSION = "1.0.0";
|
|
110
|
+
export function runGuardConfirmGate(input) {
|
|
111
|
+
const decision_record = {
|
|
112
|
+
final_decision: "blocked",
|
|
113
|
+
timestamp: new Date().toISOString(),
|
|
114
|
+
layers_passed: [],
|
|
115
|
+
};
|
|
116
|
+
const checklist_result = runStaticChecklist(input.guard_json, input.existing_lint_issues);
|
|
117
|
+
if (!checklist_result.passed) {
|
|
118
|
+
return {
|
|
119
|
+
status: "blocked_checklist",
|
|
120
|
+
checklist_result,
|
|
121
|
+
decision_record: {
|
|
122
|
+
...decision_record,
|
|
123
|
+
final_reason: `Layer 1 failed: ${checklist_result.failed_items.map(i => i.id).join(", ")}`,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
decision_record.layers_passed.push("checklist");
|
|
128
|
+
let risk_result;
|
|
129
|
+
if (input.existing_risk_assessment) {
|
|
130
|
+
risk_result = adaptRiskAssessment(input.existing_risk_assessment);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const guard_data = input.guard_json.root;
|
|
134
|
+
const assessment = assessGuardRisks({
|
|
135
|
+
table: guard_data?.table ?? [],
|
|
136
|
+
root: input.guard_json.root,
|
|
137
|
+
rely: guard_data?.rely,
|
|
138
|
+
});
|
|
139
|
+
risk_result = adaptRiskAssessment(assessment);
|
|
140
|
+
}
|
|
141
|
+
if (risk_result.recommendation === "do_not_publish") {
|
|
142
|
+
return {
|
|
143
|
+
status: "blocked_risk",
|
|
144
|
+
checklist_result,
|
|
145
|
+
risk_result,
|
|
146
|
+
decision_record: {
|
|
147
|
+
...decision_record,
|
|
148
|
+
final_reason: `Layer 2 blocked: ${risk_result.blocking_risks.length} CRITICAL risks`,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
decision_record.layers_passed.push("risk");
|
|
153
|
+
if (!input.skip_user_confirmation) {
|
|
154
|
+
const confirmation_text = generateGuardConfirmationText(input.guard_json, checklist_result, risk_result);
|
|
155
|
+
const user_confirmation = processUserConfirmation(input.user_responses);
|
|
156
|
+
if (!user_confirmation.approved) {
|
|
157
|
+
return {
|
|
158
|
+
status: "blocked_user",
|
|
159
|
+
checklist_result,
|
|
160
|
+
risk_result,
|
|
161
|
+
confirmation_text,
|
|
162
|
+
user_confirmation,
|
|
163
|
+
decision_record: {
|
|
164
|
+
...decision_record,
|
|
165
|
+
final_reason: `Layer 3 declined: ${user_confirmation.declined_reason ?? "no reason given"}`,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
decision_record.layers_passed.push("user");
|
|
170
|
+
if (!input.skip_environment) {
|
|
171
|
+
const environment_result = verifyGuardEnvironment(input.guard_json);
|
|
172
|
+
if (!environment_result.testnet_tested || !environment_result.rely_chain_resolvable) {
|
|
173
|
+
return {
|
|
174
|
+
status: "blocked_environment",
|
|
175
|
+
checklist_result,
|
|
176
|
+
risk_result,
|
|
177
|
+
user_confirmation,
|
|
178
|
+
environment_result,
|
|
179
|
+
decision_record: {
|
|
180
|
+
...decision_record,
|
|
181
|
+
final_reason: `Layer 4 failed: environment issues`,
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
decision_record.layers_passed.push("environment");
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
status: "approved",
|
|
189
|
+
checklist_result,
|
|
190
|
+
risk_result,
|
|
191
|
+
user_confirmation,
|
|
192
|
+
confirmation_text: generateGuardConfirmationText(input.guard_json, checklist_result, risk_result),
|
|
193
|
+
decision_record: {
|
|
194
|
+
...decision_record,
|
|
195
|
+
final_decision: "approved",
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
decision_record.layers_passed.push("user");
|
|
200
|
+
return {
|
|
201
|
+
status: "approved",
|
|
202
|
+
checklist_result,
|
|
203
|
+
risk_result,
|
|
204
|
+
decision_record: {
|
|
205
|
+
...decision_record,
|
|
206
|
+
final_decision: "approved",
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function runStaticChecklist(guard_json, existing_issues) {
|
|
211
|
+
const checked_items = [];
|
|
212
|
+
const failed_items = [];
|
|
213
|
+
const warnings = [];
|
|
214
|
+
for (const template of GUARD_PUBLISH_CHECKLIST) {
|
|
215
|
+
const item = { ...template, status: "skip" };
|
|
216
|
+
try {
|
|
217
|
+
const result = evaluateChecklistItem(item.id, guard_json, existing_issues);
|
|
218
|
+
item.status = result.status;
|
|
219
|
+
item.detail = result.detail;
|
|
220
|
+
if (result.status === "fail")
|
|
221
|
+
failed_items.push(item);
|
|
222
|
+
else if (result.status === "warning")
|
|
223
|
+
warnings.push(item);
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
item.status = "warning";
|
|
227
|
+
item.detail = `Check error: ${err.message}`;
|
|
228
|
+
warnings.push(item);
|
|
229
|
+
}
|
|
230
|
+
checked_items.push(item);
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
passed: failed_items.length === 0,
|
|
234
|
+
checked_items,
|
|
235
|
+
failed_items,
|
|
236
|
+
warnings,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function evaluateChecklistItem(id, guard_json, existing_issues) {
|
|
240
|
+
const root = guard_json.root;
|
|
241
|
+
switch (id) {
|
|
242
|
+
case "GC-01":
|
|
243
|
+
if (!root || !root.type)
|
|
244
|
+
return { status: "fail", detail: "Root node missing or has no type" };
|
|
245
|
+
return { status: "pass" };
|
|
246
|
+
case "GC-02":
|
|
247
|
+
case "GC-03":
|
|
248
|
+
case "GC-04": {
|
|
249
|
+
if (existing_issues && existing_issues.length > 0) {
|
|
250
|
+
const related = existing_issues.find(i => i.path?.includes("table") || i.path?.includes("description"));
|
|
251
|
+
if (related)
|
|
252
|
+
return { status: "fail", detail: related.message };
|
|
253
|
+
}
|
|
254
|
+
return { status: "pass", detail: "Validated by SDK validateGuardData" };
|
|
255
|
+
}
|
|
256
|
+
case "GC-05": {
|
|
257
|
+
if (guard_json.binding_scene_id) {
|
|
258
|
+
const scene = GUARD_SCENES.find(s => s.id === guard_json.binding_scene_id);
|
|
259
|
+
if (scene)
|
|
260
|
+
return { status: "pass", detail: `Scene: ${scene.id}` };
|
|
261
|
+
return { status: "warning", detail: `Scene ID "${guard_json.binding_scene_id}" not found in ledger` };
|
|
262
|
+
}
|
|
263
|
+
return { status: "warning", detail: "No binding scene identified — verify Standalone intent" };
|
|
264
|
+
}
|
|
265
|
+
case "GC-06":
|
|
266
|
+
case "GC-07":
|
|
267
|
+
case "GC-08":
|
|
268
|
+
case "GC-09":
|
|
269
|
+
case "GC-10":
|
|
270
|
+
case "GC-11":
|
|
271
|
+
if (existing_issues && existing_issues.some(i => i.path?.includes("query") || i.path?.includes("witness"))) {
|
|
272
|
+
return { status: "fail", detail: "SDK validation flagged query/witness issues" };
|
|
273
|
+
}
|
|
274
|
+
return { status: "pass", detail: "Delegated to guard-lint.ts" };
|
|
275
|
+
case "GC-12":
|
|
276
|
+
return { status: "pass", detail: "Immutability noted — Guard cannot be modified after creation" };
|
|
277
|
+
default:
|
|
278
|
+
return { status: "skip" };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function adaptRiskAssessment(assessment) {
|
|
282
|
+
const blocking_risks = [];
|
|
283
|
+
const warning_risks = [];
|
|
284
|
+
for (const risk of assessment.risks ?? []) {
|
|
285
|
+
if (risk.level === "critical")
|
|
286
|
+
blocking_risks.push(risk.id);
|
|
287
|
+
else if (risk.level === "high")
|
|
288
|
+
warning_risks.push(risk.id);
|
|
289
|
+
}
|
|
290
|
+
let recommendation = "publish";
|
|
291
|
+
if (blocking_risks.length > 0)
|
|
292
|
+
recommendation = "do_not_publish";
|
|
293
|
+
else if (warning_risks.length > 2)
|
|
294
|
+
recommendation = "fix_first";
|
|
295
|
+
return {
|
|
296
|
+
overall_risk_level: assessment.overall_risk,
|
|
297
|
+
blocking_risks,
|
|
298
|
+
warning_risks,
|
|
299
|
+
recommendation,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function processUserConfirmation(responses) {
|
|
303
|
+
const questions_asked = GUARD_CONFIRMATION_QUESTIONS;
|
|
304
|
+
if (!responses || responses.length === 0) {
|
|
305
|
+
return {
|
|
306
|
+
questions_asked,
|
|
307
|
+
user_responses: [],
|
|
308
|
+
approved: false,
|
|
309
|
+
declined_reason: "No user responses provided",
|
|
310
|
+
timestamp: new Date().toISOString(),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const blocking_questions = questions_asked.filter(q => q.blocking);
|
|
314
|
+
for (const q of blocking_questions) {
|
|
315
|
+
const response = responses.find(r => r.question_id === q.id);
|
|
316
|
+
if (!response) {
|
|
317
|
+
return {
|
|
318
|
+
questions_asked,
|
|
319
|
+
user_responses: responses,
|
|
320
|
+
approved: false,
|
|
321
|
+
declined_reason: `Blocking question ${q.id} not answered`,
|
|
322
|
+
timestamp: new Date().toISOString(),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
if (q.expected_response === "yes" && response.response !== "yes") {
|
|
326
|
+
return {
|
|
327
|
+
questions_asked,
|
|
328
|
+
user_responses: responses,
|
|
329
|
+
approved: false,
|
|
330
|
+
declined_reason: `${q.id} expected 'yes', got '${response.response}'`,
|
|
331
|
+
timestamp: new Date().toISOString(),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
if (q.expected_response === "no" && response.response !== "no") {
|
|
335
|
+
return {
|
|
336
|
+
questions_asked,
|
|
337
|
+
user_responses: responses,
|
|
338
|
+
approved: false,
|
|
339
|
+
declined_reason: `${q.id} expected 'no', got '${response.response}'`,
|
|
340
|
+
timestamp: new Date().toISOString(),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
questions_asked,
|
|
346
|
+
user_responses: responses,
|
|
347
|
+
approved: true,
|
|
348
|
+
timestamp: new Date().toISOString(),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function generateGuardConfirmationText(guard_json, checklist, risk) {
|
|
352
|
+
const lines = [];
|
|
353
|
+
lines.push("═══════════════════════════════════════════════════════════");
|
|
354
|
+
lines.push(" GUARD PUBLISH CONFIRMATION");
|
|
355
|
+
lines.push("═══════════════════════════════════════════════════════════");
|
|
356
|
+
lines.push(`Name: ${guard_json.name ?? "(unnamed)"}`);
|
|
357
|
+
lines.push(`Description: ${guard_json.description ?? "(none)"}`);
|
|
358
|
+
lines.push(`Binding Scene: ${guard_json.binding_scene_id ?? "Standalone"}`);
|
|
359
|
+
lines.push("");
|
|
360
|
+
lines.push("─ Layer 1: Static Checklist ─────────────────────────────");
|
|
361
|
+
lines.push(`Result: ${checklist.passed ? "✅ PASS" : "❌ FAIL"}`);
|
|
362
|
+
lines.push(`Items: ${checklist.checked_items.length} checked, ${checklist.failed_items.length} failed, ${checklist.warnings.length} warnings`);
|
|
363
|
+
lines.push("");
|
|
364
|
+
lines.push("─ Layer 2: Risk Assessment ──────────────────────────────");
|
|
365
|
+
lines.push(`Overall: ${risk.overall_risk_level.toUpperCase()}`);
|
|
366
|
+
lines.push(`Blocking: ${risk.blocking_risks.length} | Warning: ${risk.warning_risks.length}`);
|
|
367
|
+
lines.push(`Recommendation: ${risk.recommendation}`);
|
|
368
|
+
lines.push("");
|
|
369
|
+
lines.push("⚠️ CRITICAL REMINDER: Guard is IMMUTABLE after creation.");
|
|
370
|
+
lines.push(" There is NO update path. If the rule is wrong, you must");
|
|
371
|
+
lines.push(" create a NEW Guard and rebind the host object.");
|
|
372
|
+
lines.push("");
|
|
373
|
+
lines.push("Please review the above and confirm publication.");
|
|
374
|
+
lines.push("═══════════════════════════════════════════════════════════");
|
|
375
|
+
return lines.join("\n");
|
|
376
|
+
}
|
|
377
|
+
function verifyGuardEnvironment(guard_json) {
|
|
378
|
+
const warnings = [];
|
|
379
|
+
if (!guard_json.binding_target) {
|
|
380
|
+
warnings.push("No binding target specified — Guard will be Standalone (verify intent)");
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
testnet_tested: false,
|
|
384
|
+
binding_target_exists: !!guard_json.binding_target,
|
|
385
|
+
rely_chain_resolvable: true,
|
|
386
|
+
passport_generated_successfully: false,
|
|
387
|
+
warnings,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
export function progressiveGuardCheck(guard_json) {
|
|
391
|
+
const checklist = runStaticChecklist(guard_json);
|
|
392
|
+
if (!checklist.passed) {
|
|
393
|
+
return { layer: "checklist", result: checklist };
|
|
394
|
+
}
|
|
395
|
+
const guard_data = guard_json.root;
|
|
396
|
+
const assessment = assessGuardRisks({
|
|
397
|
+
table: guard_data?.table ?? [],
|
|
398
|
+
root: guard_json.root,
|
|
399
|
+
rely: guard_data?.rely,
|
|
400
|
+
});
|
|
401
|
+
const risk = adaptRiskAssessment(assessment);
|
|
402
|
+
if (risk.recommendation === "do_not_publish") {
|
|
403
|
+
return { layer: "risk", result: risk };
|
|
404
|
+
}
|
|
405
|
+
return { layer: "none", result: null };
|
|
406
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type GuardScene } from "./guard-ledger.js";
|
|
2
|
+
import { type GuardTemplate } from "./guard-templates.js";
|
|
3
|
+
import { type SemanticToSchemaRule } from "./guard-translation.js";
|
|
4
|
+
import { type RiskRule, type GuardRiskAssessment, type GuardStakeholder } from "./guard-risk.js";
|
|
5
|
+
import { type GuardPuzzle, type PuzzleCompleteness } from "./guard-puzzle.js";
|
|
6
|
+
import { GUARD_PUBLISH_CHECKLIST, GUARD_CONFIRMATION_QUESTIONS, type GuardJsonForConfirm } from "./guard-confirm.js";
|
|
7
|
+
export declare const GUARD_CONTEXT_VERSION = "1.0.0";
|
|
8
|
+
export type GuardInjectionMode = "initial_design" | "mid_design_review" | "pre_publish" | "post_publish_binding" | "stakeholder_review" | "binding_check";
|
|
9
|
+
export type GuardStakeholderPerspective = GuardStakeholder | "system";
|
|
10
|
+
export interface GuardContextBundle {
|
|
11
|
+
version: string;
|
|
12
|
+
mode: GuardInjectionMode;
|
|
13
|
+
stakeholder_perspective?: GuardStakeholderPerspective;
|
|
14
|
+
matched_scene?: GuardScene;
|
|
15
|
+
matched_template?: GuardTemplate;
|
|
16
|
+
matched_pattern?: SemanticToSchemaRule;
|
|
17
|
+
puzzle_state?: GuardPuzzle;
|
|
18
|
+
puzzle_completeness?: PuzzleCompleteness;
|
|
19
|
+
relevant_risks: RiskRule[];
|
|
20
|
+
risk_assessment?: GuardRiskAssessment;
|
|
21
|
+
relevant_checklist: typeof GUARD_PUBLISH_CHECKLIST;
|
|
22
|
+
relevant_questions: typeof GUARD_CONFIRMATION_QUESTIONS;
|
|
23
|
+
cross_object_refs: GuardCrossObjectRef[];
|
|
24
|
+
onchain_constraints: GuardOnchainConstraint[];
|
|
25
|
+
rendering_hints: GuardRenderingHints;
|
|
26
|
+
}
|
|
27
|
+
export interface GuardCrossObjectRef {
|
|
28
|
+
object: "Machine" | "Service" | "Reward" | "Arbitration" | "Repository" | "Progress" | "Demand";
|
|
29
|
+
field: string;
|
|
30
|
+
scene_id: string;
|
|
31
|
+
description: string;
|
|
32
|
+
}
|
|
33
|
+
export interface GuardOnchainConstraint {
|
|
34
|
+
name: string;
|
|
35
|
+
value: string | number | bigint;
|
|
36
|
+
description: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GuardRenderingHints {
|
|
39
|
+
include_puzzle_template: boolean;
|
|
40
|
+
include_risk_details: boolean;
|
|
41
|
+
include_questions: boolean;
|
|
42
|
+
include_immutability_warning: boolean;
|
|
43
|
+
max_length: number;
|
|
44
|
+
}
|
|
45
|
+
export interface BuildGuardContextInput {
|
|
46
|
+
mode: GuardInjectionMode;
|
|
47
|
+
intent?: string;
|
|
48
|
+
guard_json?: GuardJsonForConfirm;
|
|
49
|
+
stakeholder?: GuardStakeholderPerspective;
|
|
50
|
+
target_host_object?: GuardScene["host_object"];
|
|
51
|
+
target_binding_field?: string;
|
|
52
|
+
max_length?: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function buildGuardContext(input: BuildGuardContextInput): GuardContextBundle;
|
|
55
|
+
export declare function buildPromptFromGuardContext(bundle: GuardContextBundle): string;
|
|
56
|
+
export declare function getGuardContextSummary(bundle: GuardContextBundle): string;
|