@vorionsys/atsf-core 0.2.0 → 0.2.2
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/CHANGELOG.md +67 -0
- package/LICENSE +190 -0
- package/README.md +305 -181
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +86 -4
- package/dist/api/server.js.map +1 -1
- package/dist/basis/parser.d.ts +210 -210
- package/dist/basis/parser.js.map +1 -1
- package/dist/chain/index.d.ts +147 -0
- package/dist/chain/index.d.ts.map +1 -0
- package/dist/chain/index.js +219 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/common/adapters.d.ts +9 -9
- package/dist/common/adapters.d.ts.map +1 -1
- package/dist/common/adapters.js +6 -6
- package/dist/common/config.d.ts +152 -152
- package/dist/common/types.d.ts +35 -15
- package/dist/common/types.d.ts.map +1 -1
- package/dist/common/types.js.map +1 -1
- package/dist/enforce/index.d.ts +226 -16
- package/dist/enforce/index.d.ts.map +1 -1
- package/dist/enforce/index.js +196 -49
- package/dist/enforce/index.js.map +1 -1
- package/dist/governance/index.d.ts +2 -0
- package/dist/governance/index.d.ts.map +1 -1
- package/dist/governance/index.js +1 -0
- package/dist/governance/index.js.map +1 -1
- package/dist/governance/proof-bridge.d.ts +86 -0
- package/dist/governance/proof-bridge.d.ts.map +1 -0
- package/dist/governance/proof-bridge.js +139 -0
- package/dist/governance/proof-bridge.js.map +1 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +1 -1
- package/dist/intent/index.d.ts +127 -10
- package/dist/intent/index.d.ts.map +1 -1
- package/dist/intent/index.js +121 -16
- package/dist/intent/index.js.map +1 -1
- package/dist/langchain/executor.d.ts +19 -5
- package/dist/langchain/executor.d.ts.map +1 -1
- package/dist/langchain/executor.js +287 -36
- package/dist/langchain/executor.js.map +1 -1
- package/dist/langchain/index.d.ts +2 -1
- package/dist/langchain/index.d.ts.map +1 -1
- package/dist/langchain/index.js +3 -1
- package/dist/langchain/index.js.map +1 -1
- package/dist/langchain/tools.d.ts.map +1 -1
- package/dist/langchain/tools.js +2 -1
- package/dist/langchain/tools.js.map +1 -1
- package/dist/langchain/types.d.ts +41 -0
- package/dist/langchain/types.d.ts.map +1 -1
- package/dist/layers/index.d.ts +1 -1
- package/dist/layers/index.d.ts.map +1 -1
- package/dist/persistence/file.d.ts +35 -3
- package/dist/persistence/file.d.ts.map +1 -1
- package/dist/persistence/file.js +138 -11
- package/dist/persistence/file.js.map +1 -1
- package/dist/persistence/index.d.ts +10 -1
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +15 -1
- package/dist/persistence/index.js.map +1 -1
- package/dist/persistence/sqlite.d.ts +135 -0
- package/dist/persistence/sqlite.d.ts.map +1 -0
- package/dist/persistence/sqlite.js +372 -0
- package/dist/persistence/sqlite.js.map +1 -0
- package/dist/phase6/ceiling.d.ts +177 -0
- package/dist/phase6/ceiling.d.ts.map +1 -0
- package/dist/phase6/ceiling.js +463 -0
- package/dist/phase6/ceiling.js.map +1 -0
- package/dist/phase6/context.d.ts +207 -0
- package/dist/phase6/context.d.ts.map +1 -0
- package/dist/phase6/context.js +603 -0
- package/dist/phase6/context.js.map +1 -0
- package/dist/phase6/index.d.ts +79 -0
- package/dist/phase6/index.d.ts.map +1 -0
- package/dist/phase6/index.js +152 -0
- package/dist/phase6/index.js.map +1 -0
- package/dist/phase6/presets.d.ts +148 -0
- package/dist/phase6/presets.d.ts.map +1 -0
- package/dist/phase6/presets.js +467 -0
- package/dist/phase6/presets.js.map +1 -0
- package/dist/phase6/provenance.d.ts +148 -0
- package/dist/phase6/provenance.d.ts.map +1 -0
- package/dist/phase6/provenance.js +545 -0
- package/dist/phase6/provenance.js.map +1 -0
- package/dist/phase6/role-gates/index.d.ts +7 -0
- package/dist/phase6/role-gates/index.d.ts.map +1 -0
- package/dist/phase6/role-gates/index.js +7 -0
- package/dist/phase6/role-gates/index.js.map +1 -0
- package/dist/phase6/role-gates/kernel.d.ts +84 -0
- package/dist/phase6/role-gates/kernel.d.ts.map +1 -0
- package/dist/phase6/role-gates/kernel.js +258 -0
- package/dist/phase6/role-gates/kernel.js.map +1 -0
- package/dist/phase6/role-gates/policy.d.ts +110 -0
- package/dist/phase6/role-gates/policy.d.ts.map +1 -0
- package/dist/phase6/role-gates/policy.js +157 -0
- package/dist/phase6/role-gates/policy.js.map +1 -0
- package/dist/phase6/role-gates.d.ts +164 -0
- package/dist/phase6/role-gates.d.ts.map +1 -0
- package/dist/phase6/role-gates.js +536 -0
- package/dist/phase6/role-gates.js.map +1 -0
- package/dist/phase6/types.d.ts +1829 -0
- package/dist/phase6/types.d.ts.map +1 -0
- package/dist/phase6/types.js +452 -0
- package/dist/phase6/types.js.map +1 -0
- package/dist/phase6/weight-presets/canonical.d.ts +93 -0
- package/dist/phase6/weight-presets/canonical.d.ts.map +1 -0
- package/dist/phase6/weight-presets/canonical.js +122 -0
- package/dist/phase6/weight-presets/canonical.js.map +1 -0
- package/dist/phase6/weight-presets/deltas.d.ts +144 -0
- package/dist/phase6/weight-presets/deltas.d.ts.map +1 -0
- package/dist/phase6/weight-presets/deltas.js +184 -0
- package/dist/phase6/weight-presets/deltas.js.map +1 -0
- package/dist/phase6/weight-presets/index.d.ts +8 -0
- package/dist/phase6/weight-presets/index.d.ts.map +1 -0
- package/dist/phase6/weight-presets/index.js +8 -0
- package/dist/phase6/weight-presets/index.js.map +1 -0
- package/dist/phase6/weight-presets/merger.d.ts +79 -0
- package/dist/phase6/weight-presets/merger.d.ts.map +1 -0
- package/dist/phase6/weight-presets/merger.js +161 -0
- package/dist/phase6/weight-presets/merger.js.map +1 -0
- package/dist/proof/index.d.ts +6 -0
- package/dist/proof/index.d.ts.map +1 -1
- package/dist/proof/index.js +56 -6
- package/dist/proof/index.js.map +1 -1
- package/dist/proof/merkle.d.ts +195 -0
- package/dist/proof/merkle.d.ts.map +1 -0
- package/dist/proof/merkle.js +412 -0
- package/dist/proof/merkle.js.map +1 -0
- package/dist/proof/zk-proofs.d.ts +218 -0
- package/dist/proof/zk-proofs.d.ts.map +1 -0
- package/dist/proof/zk-proofs.js +531 -0
- package/dist/proof/zk-proofs.js.map +1 -0
- package/dist/sandbox-training/challenges.d.ts +16 -0
- package/dist/sandbox-training/challenges.d.ts.map +1 -0
- package/dist/sandbox-training/challenges.js +561 -0
- package/dist/sandbox-training/challenges.js.map +1 -0
- package/dist/sandbox-training/graduation.d.ts +25 -0
- package/dist/sandbox-training/graduation.d.ts.map +1 -0
- package/dist/sandbox-training/graduation.js +143 -0
- package/dist/sandbox-training/graduation.js.map +1 -0
- package/dist/sandbox-training/index.d.ts +19 -0
- package/dist/sandbox-training/index.d.ts.map +1 -0
- package/dist/sandbox-training/index.js +22 -0
- package/dist/sandbox-training/index.js.map +1 -0
- package/dist/sandbox-training/promotion-service.d.ts +76 -0
- package/dist/sandbox-training/promotion-service.d.ts.map +1 -0
- package/dist/sandbox-training/promotion-service.js +117 -0
- package/dist/sandbox-training/promotion-service.js.map +1 -0
- package/dist/sandbox-training/runner.d.ts +58 -0
- package/dist/sandbox-training/runner.d.ts.map +1 -0
- package/dist/sandbox-training/runner.js +388 -0
- package/dist/sandbox-training/runner.js.map +1 -0
- package/dist/sandbox-training/scorer.d.ts +40 -0
- package/dist/sandbox-training/scorer.d.ts.map +1 -0
- package/dist/sandbox-training/scorer.js +79 -0
- package/dist/sandbox-training/scorer.js.map +1 -0
- package/dist/sandbox-training/types.d.ts +162 -0
- package/dist/sandbox-training/types.d.ts.map +1 -0
- package/dist/sandbox-training/types.js +32 -0
- package/dist/sandbox-training/types.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/audit.d.ts +98 -0
- package/dist/trust-engine/ceiling-enforcement/audit.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/audit.js +160 -0
- package/dist/trust-engine/ceiling-enforcement/audit.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/index.d.ts +6 -0
- package/dist/trust-engine/ceiling-enforcement/index.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/index.js +6 -0
- package/dist/trust-engine/ceiling-enforcement/index.js.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.d.ts +112 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.d.ts.map +1 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.js +158 -0
- package/dist/trust-engine/ceiling-enforcement/kernel.js.map +1 -0
- package/dist/trust-engine/context-policy/enforcement.d.ts +62 -0
- package/dist/trust-engine/context-policy/enforcement.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/enforcement.js +104 -0
- package/dist/trust-engine/context-policy/enforcement.js.map +1 -0
- package/dist/trust-engine/context-policy/factory.d.ts +75 -0
- package/dist/trust-engine/context-policy/factory.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/factory.js +130 -0
- package/dist/trust-engine/context-policy/factory.js.map +1 -0
- package/dist/trust-engine/context-policy/index.d.ts +6 -0
- package/dist/trust-engine/context-policy/index.d.ts.map +1 -0
- package/dist/trust-engine/context-policy/index.js +6 -0
- package/dist/trust-engine/context-policy/index.js.map +1 -0
- package/dist/trust-engine/creation-modifiers/index.d.ts +5 -0
- package/dist/trust-engine/creation-modifiers/index.d.ts.map +1 -0
- package/dist/trust-engine/creation-modifiers/index.js +5 -0
- package/dist/trust-engine/creation-modifiers/index.js.map +1 -0
- package/dist/trust-engine/creation-modifiers/types.d.ts +112 -0
- package/dist/trust-engine/creation-modifiers/types.d.ts.map +1 -0
- package/dist/trust-engine/creation-modifiers/types.js +166 -0
- package/dist/trust-engine/creation-modifiers/types.js.map +1 -0
- package/dist/trust-engine/index.d.ts +54 -1
- package/dist/trust-engine/index.d.ts.map +1 -1
- package/dist/trust-engine/index.js +118 -1
- package/dist/trust-engine/index.js.map +1 -1
- package/dist/trust-engine/phase6-types.d.ts +123 -0
- package/dist/trust-engine/phase6-types.d.ts.map +1 -0
- package/dist/trust-engine/phase6-types.js +88 -0
- package/dist/trust-engine/phase6-types.js.map +1 -0
- package/package.json +42 -12
- package/dist/audit/key-manager.d.ts +0 -118
- package/dist/audit/key-manager.d.ts.map +0 -1
- package/dist/audit/key-manager.js +0 -565
- package/dist/audit/key-manager.js.map +0 -1
- package/dist/carbon-aware/carbon-metrics.d.ts +0 -151
- package/dist/carbon-aware/carbon-metrics.d.ts.map +0 -1
- package/dist/carbon-aware/carbon-metrics.js +0 -370
- package/dist/carbon-aware/carbon-metrics.js.map +0 -1
- package/dist/carbon-aware/carbon-router.d.ts +0 -101
- package/dist/carbon-aware/carbon-router.d.ts.map +0 -1
- package/dist/carbon-aware/carbon-router.js +0 -400
- package/dist/carbon-aware/carbon-router.js.map +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Adversarial Training Boot Camp — Core Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the T0→T1 training gauntlet that tests
|
|
5
|
+
* Competence (CT-COMP), Reliability (CT-REL), and Observability (CT-OBS).
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/** T1 trust factors that the boot camp tests */
|
|
10
|
+
export type T1Factor = 'CT-COMP' | 'CT-REL' | 'CT-OBS';
|
|
11
|
+
/** Difficulty progression within each factor */
|
|
12
|
+
export type ChallengeDifficulty = 'basic' | 'intermediate' | 'adversarial';
|
|
13
|
+
/** Category of adversarial injection */
|
|
14
|
+
export type AdversarialType = 'malformed_input' | 'timeout_pressure' | 'privilege_escalation' | 'injection' | 'rate_flood' | 'misleading_context' | 'none';
|
|
15
|
+
/** A single boot camp challenge */
|
|
16
|
+
export interface Challenge {
|
|
17
|
+
/** Unique challenge ID (e.g., "comp-basic-001") */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable name */
|
|
20
|
+
name: string;
|
|
21
|
+
/** What the challenge tests */
|
|
22
|
+
description: string;
|
|
23
|
+
/** Which T1 trust factor this targets */
|
|
24
|
+
factor: T1Factor;
|
|
25
|
+
/** Difficulty level */
|
|
26
|
+
difficulty: ChallengeDifficulty;
|
|
27
|
+
/** Type of adversarial injection (or 'none' for clean challenges) */
|
|
28
|
+
adversarialType: AdversarialType;
|
|
29
|
+
/** Maximum time allowed for agent response (ms) */
|
|
30
|
+
timeoutMs: number;
|
|
31
|
+
/** The challenge payload sent to the agent */
|
|
32
|
+
input: ChallengeInput;
|
|
33
|
+
/** How to evaluate the agent's response */
|
|
34
|
+
evaluator: ChallengeEvaluator;
|
|
35
|
+
/** Maximum points awarded on pass (scaled by difficulty) */
|
|
36
|
+
maxPoints: number;
|
|
37
|
+
}
|
|
38
|
+
/** Payload delivered to the agent */
|
|
39
|
+
export interface ChallengeInput {
|
|
40
|
+
/** The task/prompt for the agent */
|
|
41
|
+
prompt: string;
|
|
42
|
+
/** Structured data the agent should process */
|
|
43
|
+
data?: Record<string, unknown>;
|
|
44
|
+
/** Adversarial payload injected into the request */
|
|
45
|
+
adversarialPayload?: Record<string, unknown>;
|
|
46
|
+
/** Constraints the agent must respect */
|
|
47
|
+
constraints?: string[];
|
|
48
|
+
}
|
|
49
|
+
/** Evaluation strategy for a challenge */
|
|
50
|
+
export interface ChallengeEvaluator {
|
|
51
|
+
/** Type of evaluation */
|
|
52
|
+
type: 'exact_match' | 'schema_validation' | 'behavior_check' | 'custom';
|
|
53
|
+
/** Expected output (for exact_match) */
|
|
54
|
+
expected?: unknown;
|
|
55
|
+
/** Schema the response must conform to (for schema_validation) */
|
|
56
|
+
schema?: Record<string, unknown>;
|
|
57
|
+
/** Custom evaluator function name (for custom type) */
|
|
58
|
+
customFn?: string;
|
|
59
|
+
}
|
|
60
|
+
/** What the agent must implement to participate in boot camp */
|
|
61
|
+
export interface BootCampAgent {
|
|
62
|
+
agentId: string;
|
|
63
|
+
tenantId: string;
|
|
64
|
+
/** Handle a challenge and return a response */
|
|
65
|
+
handleChallenge(input: ChallengeInput): Promise<ChallengeResponse>;
|
|
66
|
+
}
|
|
67
|
+
/** Agent's response to a challenge */
|
|
68
|
+
export interface ChallengeResponse {
|
|
69
|
+
/** The agent's output */
|
|
70
|
+
output: unknown;
|
|
71
|
+
/** Agent's confidence level (0-1) */
|
|
72
|
+
confidence?: number;
|
|
73
|
+
/** Whether agent detected adversarial input */
|
|
74
|
+
adversarialDetected?: boolean;
|
|
75
|
+
/** Agent's reasoning (for observability scoring) */
|
|
76
|
+
reasoning?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Result of a single challenge execution */
|
|
79
|
+
export interface ChallengeResult {
|
|
80
|
+
challengeId: string;
|
|
81
|
+
agentId: string;
|
|
82
|
+
factor: T1Factor;
|
|
83
|
+
difficulty: ChallengeDifficulty;
|
|
84
|
+
/** Did the agent pass? */
|
|
85
|
+
passed: boolean;
|
|
86
|
+
/** Score 0.0-1.0 for this challenge */
|
|
87
|
+
score: number;
|
|
88
|
+
/** Time taken to respond (ms) */
|
|
89
|
+
responseTimeMs: number;
|
|
90
|
+
/** Whether agent correctly handled adversarial input */
|
|
91
|
+
adversarialHandled: boolean;
|
|
92
|
+
/** Detailed evaluation notes */
|
|
93
|
+
notes: string[];
|
|
94
|
+
/** ISO 8601 timestamp */
|
|
95
|
+
completedAt: string;
|
|
96
|
+
}
|
|
97
|
+
/** A complete boot camp session */
|
|
98
|
+
export interface BootCampSession {
|
|
99
|
+
sessionId: string;
|
|
100
|
+
agentId: string;
|
|
101
|
+
tenantId: string;
|
|
102
|
+
/** Challenges completed in this session */
|
|
103
|
+
results: ChallengeResult[];
|
|
104
|
+
/** Aggregate scores by factor (0.0-1.0) */
|
|
105
|
+
factorScores: Record<T1Factor, number>;
|
|
106
|
+
/** Overall readiness assessment */
|
|
107
|
+
graduationReady: boolean;
|
|
108
|
+
/** Trust signals emitted during this session */
|
|
109
|
+
signalsEmitted: number;
|
|
110
|
+
/** ISO 8601 timestamp */
|
|
111
|
+
startedAt: string;
|
|
112
|
+
/** ISO 8601 timestamp (set when session completes) */
|
|
113
|
+
completedAt?: string;
|
|
114
|
+
}
|
|
115
|
+
/** Boot camp runner configuration */
|
|
116
|
+
export interface BootCampConfig {
|
|
117
|
+
/** Challenges to run (defaults to full catalog) */
|
|
118
|
+
challenges?: Challenge[];
|
|
119
|
+
/** Minimum factor score to pass (default: 0.50 per T1 spec) */
|
|
120
|
+
minFactorScore?: number;
|
|
121
|
+
/** Whether to stop on first failure (default: false) */
|
|
122
|
+
failFast?: boolean;
|
|
123
|
+
/** Difficulty progression: run basic before intermediate before adversarial */
|
|
124
|
+
progressiveDifficulty?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** Criteria for boot camp graduation */
|
|
127
|
+
export interface GraduationCriteria {
|
|
128
|
+
/** Minimum score per factor (default: 0.50 per BASIS T1 spec) */
|
|
129
|
+
minFactorScore: number;
|
|
130
|
+
/** Minimum challenges passed per difficulty tier */
|
|
131
|
+
minChallengesPassed: Record<ChallengeDifficulty, number>;
|
|
132
|
+
/** Must pass at least 1 adversarial per factor */
|
|
133
|
+
requireAdversarial: boolean;
|
|
134
|
+
}
|
|
135
|
+
/** Per-factor graduation assessment */
|
|
136
|
+
export interface FactorGraduationResult {
|
|
137
|
+
score: number;
|
|
138
|
+
passed: boolean;
|
|
139
|
+
challengesPassed: number;
|
|
140
|
+
challengesFailed: number;
|
|
141
|
+
adversarialPassed: boolean;
|
|
142
|
+
}
|
|
143
|
+
/** Full graduation assessment */
|
|
144
|
+
export interface GraduationResult {
|
|
145
|
+
/** Is the agent ready for T0→T1 promotion? */
|
|
146
|
+
ready: boolean;
|
|
147
|
+
/** Per-factor breakdown */
|
|
148
|
+
factorResults: Record<T1Factor, FactorGraduationResult>;
|
|
149
|
+
/** Human-readable summary for the T0→T1 approval request */
|
|
150
|
+
summary: string;
|
|
151
|
+
/** Recommended trust score based on performance (200-349 range) */
|
|
152
|
+
recommendedScore: number;
|
|
153
|
+
}
|
|
154
|
+
/** All T1 factors */
|
|
155
|
+
export declare const T1_FACTORS: readonly T1Factor[];
|
|
156
|
+
/** Difficulty progression order */
|
|
157
|
+
export declare const DIFFICULTY_ORDER: readonly ChallengeDifficulty[];
|
|
158
|
+
/** Difficulty weights for scoring */
|
|
159
|
+
export declare const DIFFICULTY_WEIGHTS: Record<ChallengeDifficulty, number>;
|
|
160
|
+
/** Factor to trust signal type mapping */
|
|
161
|
+
export declare const FACTOR_TO_SIGNAL: Record<T1Factor, string>;
|
|
162
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sandbox-training/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,gDAAgD;AAChD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEvD,gDAAgD;AAChD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,cAAc,GAAG,aAAa,CAAC;AAE3E,wCAAwC;AACxC,MAAM,MAAM,eAAe,GACvB,iBAAiB,GACjB,kBAAkB,GAClB,sBAAsB,GACtB,WAAW,GACX,YAAY,GACZ,oBAAoB,GACpB,MAAM,CAAC;AAMX,mCAAmC;AACnC,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,MAAM,EAAE,QAAQ,CAAC;IACjB,uBAAuB;IACvB,UAAU,EAAE,mBAAmB,CAAC;IAChC,qEAAqE;IACrE,eAAe,EAAE,eAAe,CAAC;IACjC,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,KAAK,EAAE,cAAc,CAAC;IACtB,2CAA2C;IAC3C,SAAS,EAAE,kBAAkB,CAAC;IAC9B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qCAAqC;AACrC,M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AsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,iCAAiC;AACjC,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,KAAK,EAAE,OAAO,CAAC;IACf,2BAA2B;IAC3B,aAAa,EAAE,MAAM,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IACxD,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAMD,qBAAqB;AACrB,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAA6C,CAAC;AAExF,mCAAmC;AACnC,eAAO,MAAM,gBAAgB,EAAE,SAAS,mBAAmB,EAIjD,CAAC;AAEX,qCAAqC;AACrC,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAIzD,CAAC;AAEX,0CAA0C;AAC1C,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAI5C,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Adversarial Training Boot Camp — Core Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the T0→T1 training gauntlet that tests
|
|
5
|
+
* Competence (CT-COMP), Reliability (CT-REL), and Observability (CT-OBS).
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// CONSTANTS
|
|
11
|
+
// =============================================================================
|
|
12
|
+
/** All T1 factors */
|
|
13
|
+
export const T1_FACTORS = ['CT-COMP', 'CT-REL', 'CT-OBS'];
|
|
14
|
+
/** Difficulty progression order */
|
|
15
|
+
export const DIFFICULTY_ORDER = [
|
|
16
|
+
'basic',
|
|
17
|
+
'intermediate',
|
|
18
|
+
'adversarial',
|
|
19
|
+
];
|
|
20
|
+
/** Difficulty weights for scoring */
|
|
21
|
+
export const DIFFICULTY_WEIGHTS = {
|
|
22
|
+
basic: 1.0,
|
|
23
|
+
intermediate: 1.5,
|
|
24
|
+
adversarial: 2.0,
|
|
25
|
+
};
|
|
26
|
+
/** Factor to trust signal type mapping */
|
|
27
|
+
export const FACTOR_TO_SIGNAL = {
|
|
28
|
+
'CT-COMP': 'behavioral.competence',
|
|
29
|
+
'CT-REL': 'behavioral.reliability',
|
|
30
|
+
'CT-OBS': 'compliance.observability',
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sandbox-training/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgMH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,qBAAqB;AACrB,MAAM,CAAC,MAAM,UAAU,GAAwB,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAExF,mCAAmC;AACnC,MAAM,CAAC,MAAM,gBAAgB,GAAmC;IAC9D,OAAO;IACP,cAAc;IACd,aAAa;CACL,CAAC;AAEX,qCAAqC;AACrC,MAAM,CAAC,MAAM,kBAAkB,GAAwC;IACrE,KAAK,EAAE,GAAG;IACV,YAAY,EAAE,GAAG;IACjB,WAAW,EAAE,GAAG;CACR,CAAC;AAEX,0CAA0C;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAA6B;IACxD,SAAS,EAAE,uBAAuB;IAClC,QAAQ,EAAE,wBAAwB;IAClC,QAAQ,EAAE,0BAA0B;CAC5B,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q1: Ceiling Enforcement - Audit Layer
|
|
3
|
+
*
|
|
4
|
+
* Core responsibility: Log and track all ceiling enforcement decisions
|
|
5
|
+
* - Dual logging: raw_score + clamped_score for every event
|
|
6
|
+
* - Audit trail: timestamp, reason, context
|
|
7
|
+
* - Analytics: ceiling hit frequency, patterns, drift detection
|
|
8
|
+
*/
|
|
9
|
+
import { CeilingEnforcementResult, ContextType } from './kernel';
|
|
10
|
+
/**
|
|
11
|
+
* Audit log entry for a ceiling enforcement operation
|
|
12
|
+
*/
|
|
13
|
+
export interface CeilingAuditEntry {
|
|
14
|
+
/** Unique event ID */
|
|
15
|
+
eventId: string;
|
|
16
|
+
/** Agent being scored */
|
|
17
|
+
agentId: string;
|
|
18
|
+
/** Timestamp of the enforcement */
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
/** Raw score before ceiling */
|
|
21
|
+
rawScore: number;
|
|
22
|
+
/** Clamped score after ceiling */
|
|
23
|
+
clampedScore: number;
|
|
24
|
+
/** Ceiling applied */
|
|
25
|
+
ceiling: number;
|
|
26
|
+
/** Context type */
|
|
27
|
+
contextType: ContextType;
|
|
28
|
+
/** Was ceiling hit (rawScore > ceiling) */
|
|
29
|
+
ceilingHit: boolean;
|
|
30
|
+
/** Reason for this enforcement (e.g., "daily_refresh", "event_triggered", "manual_review") */
|
|
31
|
+
reason: string;
|
|
32
|
+
/** Tags for categorization */
|
|
33
|
+
tags: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Statistical summary of ceiling enforcement activity
|
|
37
|
+
*/
|
|
38
|
+
export interface CeilingStatistics {
|
|
39
|
+
/** Total events processed */
|
|
40
|
+
totalEvents: number;
|
|
41
|
+
/** Events where ceiling was hit */
|
|
42
|
+
ceilingHits: number;
|
|
43
|
+
/** Percentage of events hitting ceiling */
|
|
44
|
+
ceilingHitRate: number;
|
|
45
|
+
/** Average raw score before enforcement */
|
|
46
|
+
avgRawScore: number;
|
|
47
|
+
/** Average clamped score after enforcement */
|
|
48
|
+
avgClampedScore: number;
|
|
49
|
+
/** Max raw score observed */
|
|
50
|
+
maxRawScore: number;
|
|
51
|
+
/** Max clamping delta (rawScore - clampedScore) */
|
|
52
|
+
maxClampingDelta: number;
|
|
53
|
+
/** Breakdown by context type */
|
|
54
|
+
byContext: Record<ContextType, {
|
|
55
|
+
hits: number;
|
|
56
|
+
rate: number;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* In-memory audit log (would be backed by persistent storage in production)
|
|
61
|
+
*/
|
|
62
|
+
export declare class CeilingAuditLog {
|
|
63
|
+
private entries;
|
|
64
|
+
private maxEntries;
|
|
65
|
+
/**
|
|
66
|
+
* Record a ceiling enforcement operation
|
|
67
|
+
*/
|
|
68
|
+
addEntry(eventId: string, agentId: string, result: CeilingEnforcementResult, reason?: string, tags?: string[]): CeilingAuditEntry;
|
|
69
|
+
/**
|
|
70
|
+
* Get all audit entries
|
|
71
|
+
*/
|
|
72
|
+
getEntries(): CeilingAuditEntry[];
|
|
73
|
+
/**
|
|
74
|
+
* Get audit entries for a specific agent
|
|
75
|
+
*/
|
|
76
|
+
getEntriesForAgent(agentId: string): CeilingAuditEntry[];
|
|
77
|
+
/**
|
|
78
|
+
* Get recent entries (last N)
|
|
79
|
+
*/
|
|
80
|
+
getRecentEntries(count: number): CeilingAuditEntry[];
|
|
81
|
+
/**
|
|
82
|
+
* Clear audit log (for testing or reset)
|
|
83
|
+
*/
|
|
84
|
+
clear(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Compute statistics from audit log
|
|
87
|
+
*/
|
|
88
|
+
computeStatistics(): CeilingStatistics;
|
|
89
|
+
/**
|
|
90
|
+
* Check for anomalies (ceiling hits for normally-trusted agents)
|
|
91
|
+
*/
|
|
92
|
+
detectCeilingAnomalies(agentId: string, anomalyThreshold?: number): CeilingAuditEntry[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Global audit log instance
|
|
96
|
+
*/
|
|
97
|
+
export declare const globalCeilingAuditLog: CeilingAuditLog;
|
|
98
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EACL,wBAAwB,EACxB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,SAAS,EAAE,IAAI,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB;IACnB,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,eAAe,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,gBAAgB,EAAE,MAAM,CAAC;IACzB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,UAAU,CAAiB;IAEnC;;OAEG;IACH,QAAQ,CACN,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,wBAAwB,EAChC,MAAM,GAAE,MAAoB,EAC5B,IAAI,GAAE,MAAM,EAAO,GAClB,iBAAiB;IAwBpB;;OAEG;IACH,UAAU,IAAI,iBAAiB,EAAE;IAIjC;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAIxD;;OAEG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAIpD;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,iBAAiB,IAAI,iBAAiB;IAsFtC;;OAEG;IACH,sBAAsB,CACpB,OAAO,EAAE,MAAM,EACf,gBAAgB,GAAE,MAAa,GAC9B,iBAAiB,EAAE;CAiBvB;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,iBAAwB,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q1: Ceiling Enforcement - Audit Layer
|
|
3
|
+
*
|
|
4
|
+
* Core responsibility: Log and track all ceiling enforcement decisions
|
|
5
|
+
* - Dual logging: raw_score + clamped_score for every event
|
|
6
|
+
* - Audit trail: timestamp, reason, context
|
|
7
|
+
* - Analytics: ceiling hit frequency, patterns, drift detection
|
|
8
|
+
*/
|
|
9
|
+
import { ContextType, } from './kernel';
|
|
10
|
+
/**
|
|
11
|
+
* In-memory audit log (would be backed by persistent storage in production)
|
|
12
|
+
*/
|
|
13
|
+
export class CeilingAuditLog {
|
|
14
|
+
entries = [];
|
|
15
|
+
maxEntries = 10000; // Prevent unbounded growth in memory
|
|
16
|
+
/**
|
|
17
|
+
* Record a ceiling enforcement operation
|
|
18
|
+
*/
|
|
19
|
+
addEntry(eventId, agentId, result, reason = 'automatic', tags = []) {
|
|
20
|
+
const entry = {
|
|
21
|
+
eventId,
|
|
22
|
+
agentId,
|
|
23
|
+
timestamp: new Date(),
|
|
24
|
+
rawScore: result.rawScore,
|
|
25
|
+
clampedScore: result.clampedScore,
|
|
26
|
+
ceiling: result.ceiling,
|
|
27
|
+
contextType: result.contextType,
|
|
28
|
+
ceilingHit: result.ceilingApplied,
|
|
29
|
+
reason,
|
|
30
|
+
tags,
|
|
31
|
+
};
|
|
32
|
+
this.entries.push(entry);
|
|
33
|
+
// Rotate oldest entries if we exceed max
|
|
34
|
+
if (this.entries.length > this.maxEntries) {
|
|
35
|
+
this.entries = this.entries.slice(-this.maxEntries);
|
|
36
|
+
}
|
|
37
|
+
return entry;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all audit entries
|
|
41
|
+
*/
|
|
42
|
+
getEntries() {
|
|
43
|
+
return [...this.entries];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get audit entries for a specific agent
|
|
47
|
+
*/
|
|
48
|
+
getEntriesForAgent(agentId) {
|
|
49
|
+
return this.entries.filter((e) => e.agentId === agentId);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get recent entries (last N)
|
|
53
|
+
*/
|
|
54
|
+
getRecentEntries(count) {
|
|
55
|
+
return this.entries.slice(-count);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear audit log (for testing or reset)
|
|
59
|
+
*/
|
|
60
|
+
clear() {
|
|
61
|
+
this.entries = [];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compute statistics from audit log
|
|
65
|
+
*/
|
|
66
|
+
computeStatistics() {
|
|
67
|
+
if (this.entries.length === 0) {
|
|
68
|
+
return {
|
|
69
|
+
totalEvents: 0,
|
|
70
|
+
ceilingHits: 0,
|
|
71
|
+
ceilingHitRate: 0,
|
|
72
|
+
avgRawScore: 0,
|
|
73
|
+
avgClampedScore: 0,
|
|
74
|
+
maxRawScore: 0,
|
|
75
|
+
maxClampingDelta: 0,
|
|
76
|
+
byContext: {
|
|
77
|
+
[ContextType.LOCAL]: { hits: 0, rate: 0 },
|
|
78
|
+
[ContextType.ENTERPRISE]: { hits: 0, rate: 0 },
|
|
79
|
+
[ContextType.SOVEREIGN]: { hits: 0, rate: 0 },
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
let totalRawScore = 0;
|
|
84
|
+
let totalClampedScore = 0;
|
|
85
|
+
let ceilingHits = 0;
|
|
86
|
+
let maxRawScore = -Infinity;
|
|
87
|
+
let maxClampingDelta = 0;
|
|
88
|
+
const byContext = {
|
|
89
|
+
[ContextType.LOCAL]: { hits: 0, total: 0 },
|
|
90
|
+
[ContextType.ENTERPRISE]: { hits: 0, total: 0 },
|
|
91
|
+
[ContextType.SOVEREIGN]: { hits: 0, total: 0 },
|
|
92
|
+
};
|
|
93
|
+
for (const entry of this.entries) {
|
|
94
|
+
totalRawScore += entry.rawScore;
|
|
95
|
+
totalClampedScore += entry.clampedScore;
|
|
96
|
+
maxRawScore = Math.max(maxRawScore, entry.rawScore);
|
|
97
|
+
maxClampingDelta = Math.max(maxClampingDelta, entry.rawScore - entry.clampedScore);
|
|
98
|
+
if (entry.ceilingHit) {
|
|
99
|
+
ceilingHits++;
|
|
100
|
+
}
|
|
101
|
+
byContext[entry.contextType].total++;
|
|
102
|
+
if (entry.ceilingHit) {
|
|
103
|
+
byContext[entry.contextType].hits++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
totalEvents: this.entries.length,
|
|
108
|
+
ceilingHits,
|
|
109
|
+
ceilingHitRate: ceilingHits / this.entries.length,
|
|
110
|
+
avgRawScore: totalRawScore / this.entries.length,
|
|
111
|
+
avgClampedScore: totalClampedScore / this.entries.length,
|
|
112
|
+
maxRawScore,
|
|
113
|
+
maxClampingDelta,
|
|
114
|
+
byContext: {
|
|
115
|
+
[ContextType.LOCAL]: {
|
|
116
|
+
hits: byContext[ContextType.LOCAL].hits,
|
|
117
|
+
rate: byContext[ContextType.LOCAL].total === 0
|
|
118
|
+
? 0
|
|
119
|
+
: byContext[ContextType.LOCAL].hits /
|
|
120
|
+
byContext[ContextType.LOCAL].total,
|
|
121
|
+
},
|
|
122
|
+
[ContextType.ENTERPRISE]: {
|
|
123
|
+
hits: byContext[ContextType.ENTERPRISE].hits,
|
|
124
|
+
rate: byContext[ContextType.ENTERPRISE].total === 0
|
|
125
|
+
? 0
|
|
126
|
+
: byContext[ContextType.ENTERPRISE].hits /
|
|
127
|
+
byContext[ContextType.ENTERPRISE].total,
|
|
128
|
+
},
|
|
129
|
+
[ContextType.SOVEREIGN]: {
|
|
130
|
+
hits: byContext[ContextType.SOVEREIGN].hits,
|
|
131
|
+
rate: byContext[ContextType.SOVEREIGN].total === 0
|
|
132
|
+
? 0
|
|
133
|
+
: byContext[ContextType.SOVEREIGN].hits /
|
|
134
|
+
byContext[ContextType.SOVEREIGN].total,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check for anomalies (ceiling hits for normally-trusted agents)
|
|
141
|
+
*/
|
|
142
|
+
detectCeilingAnomalies(agentId, anomalyThreshold = 0.05) {
|
|
143
|
+
const agentEntries = this.getEntriesForAgent(agentId);
|
|
144
|
+
if (agentEntries.length === 0) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
const hitRate = agentEntries.filter((e) => e.ceilingHit).length /
|
|
148
|
+
agentEntries.length;
|
|
149
|
+
// If hit rate is above threshold (normally 5%), flag as anomaly
|
|
150
|
+
if (hitRate > anomalyThreshold) {
|
|
151
|
+
return agentEntries.filter((e) => e.ceilingHit);
|
|
152
|
+
}
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Global audit log instance
|
|
158
|
+
*/
|
|
159
|
+
export const globalCeilingAuditLog = new CeilingAuditLog();
|
|
160
|
+
//# sourceMappingURL=audit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,EAEL,WAAW,GAEZ,MAAM,UAAU,CAAC;AAkDlB;;GAEG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,GAAwB,EAAE,CAAC;IAClC,UAAU,GAAW,KAAK,CAAC,CAAC,qCAAqC;IAEzE;;OAEG;IACH,QAAQ,CACN,OAAe,EACf,OAAe,EACf,MAAgC,EAChC,SAAiB,WAAW,EAC5B,OAAiB,EAAE;QAEnB,MAAM,KAAK,GAAsB;YAC/B,OAAO;YACP,OAAO;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU,EAAE,MAAM,CAAC,cAAc;YACjC,MAAM;YACN,IAAI;SACL,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEzB,yCAAyC;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,OAAe;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CA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C,CAAC,UAAU,CAAC,CAAC,MAAM;YAC/C,YAAY,CAAC,MAAM,CAAC;QAEtB,gEAAgE;QAChE,IAAI,OAAO,GAAG,gBAAgB,EAAE,CAAC;YAC/B,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Q1: Ceiling Enforcement - Kernel Layer
|
|
3
|
+
*
|
|
4
|
+
* Core responsibility: Apply ceiling enforcement at kernel level (0-1000 scale)
|
|
5
|
+
* - Receives raw trust scores (any numeric value)
|
|
6
|
+
* - Clamps to 0-1000 based on context ceiling
|
|
7
|
+
* - Preserves raw score for audit trail (ceilingApplied flag)
|
|
8
|
+
* - <1ms latency target
|
|
9
|
+
*/
|
|
10
|
+
import { TrustEvent } from '../phase6-types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Context-based ceiling levels (from CONTEXT_CEILINGS)
|
|
13
|
+
*/
|
|
14
|
+
export declare enum ContextType {
|
|
15
|
+
LOCAL = "local",// 0-700: Restricted to test environments
|
|
16
|
+
ENTERPRISE = "enterprise",// 0-900: Approved for business operations
|
|
17
|
+
SOVEREIGN = "sovereign"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Result of ceiling enforcement operation
|
|
21
|
+
*/
|
|
22
|
+
export interface CeilingEnforcementResult {
|
|
23
|
+
/** Original raw score (unclamped) */
|
|
24
|
+
rawScore: number;
|
|
25
|
+
/** Clamped score (post-ceiling) */
|
|
26
|
+
clampedScore: number;
|
|
27
|
+
/** Ceiling that was applied */
|
|
28
|
+
ceiling: number;
|
|
29
|
+
/** Whether clamping occurred (rawScore !== clampedScore) */
|
|
30
|
+
ceilingApplied: boolean;
|
|
31
|
+
/** Context type that determined the ceiling */
|
|
32
|
+
contextType: ContextType;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get ceiling value for a context type
|
|
36
|
+
*
|
|
37
|
+
* @param contextType - The context (local/enterprise/sovereign)
|
|
38
|
+
* @returns The ceiling value (700/900/1000)
|
|
39
|
+
*/
|
|
40
|
+
export declare function getCeilingForContext(contextType: ContextType): number;
|
|
41
|
+
/**
|
|
42
|
+
* Clamp a raw score to the ceiling for a given context
|
|
43
|
+
*
|
|
44
|
+
* This is the core Q1 enforcement: kernel-level ceiling with dual logging
|
|
45
|
+
* - Raw score always preserved (for analytics)
|
|
46
|
+
* - Clamped score enforced at runtime (for authorization decisions)
|
|
47
|
+
* - Flag indicates whether ceiling was applied
|
|
48
|
+
*
|
|
49
|
+
* @param rawScore - The unprocessed trust score (may be >1000 or <0)
|
|
50
|
+
* @param contextType - The context determining the ceiling
|
|
51
|
+
* @returns CeilingEnforcementResult with raw/clamped scores and flags
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const result = clampTrustScore(1050, ContextType.ENTERPRISE);
|
|
55
|
+
* // { rawScore: 1050, clampedScore: 900, ceiling: 900, ceilingApplied: true, contextType: 'enterprise' }
|
|
56
|
+
*/
|
|
57
|
+
export declare function clampTrustScore(rawScore: number, contextType: ContextType): CeilingEnforcementResult;
|
|
58
|
+
/**
|
|
59
|
+
* Apply ceiling enforcement to a TrustEvent
|
|
60
|
+
*
|
|
61
|
+
* This wraps clampTrustScore and populates the event's score and ceilingApplied fields
|
|
62
|
+
*
|
|
63
|
+
* @param event - The trust event to enforce ceiling on
|
|
64
|
+
* @param contextType - The context determining the ceiling
|
|
65
|
+
* @returns The modified TrustEvent with score clamped and ceilingApplied set
|
|
66
|
+
*/
|
|
67
|
+
export declare function applyCeilingEnforcement(event: TrustEvent, contextType: ContextType): TrustEvent;
|
|
68
|
+
/**
|
|
69
|
+
* Validate that a score complies with its context ceiling
|
|
70
|
+
*
|
|
71
|
+
* This is used for assertions/validation - checking that a score
|
|
72
|
+
* was properly clamped before being used in authorization decisions
|
|
73
|
+
*
|
|
74
|
+
* @param score - The score to validate
|
|
75
|
+
* @param contextType - The context that should be limiting the score
|
|
76
|
+
* @returns true if score ≤ ceiling for this context
|
|
77
|
+
*/
|
|
78
|
+
export declare function validateScoreForContext(score: number, contextType: ContextType): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Get the effective autonomy tier based on clamped score
|
|
81
|
+
*
|
|
82
|
+
* Maps the clamped score (after ceiling enforcement) to a tier level.
|
|
83
|
+
* This is used downstream (in role-gates, context-policy) to determine
|
|
84
|
+
* what operations are allowed.
|
|
85
|
+
*
|
|
86
|
+
* Tier mapping:
|
|
87
|
+
* - T0: 0-100 (Sandbox)
|
|
88
|
+
* - T1: 100-300 (Monitored)
|
|
89
|
+
* - T2: 300-500 (Supervised)
|
|
90
|
+
* - T3: 500-700 (Autonomous)
|
|
91
|
+
* - T4: 700-900 (Sovereign)
|
|
92
|
+
* - T5: 900-1000 (Verified)
|
|
93
|
+
*
|
|
94
|
+
* @param clampedScore - Score after ceiling enforcement
|
|
95
|
+
* @returns Tier number 0-5
|
|
96
|
+
*/
|
|
97
|
+
export declare function getTierFromScore(clampedScore: number): number;
|
|
98
|
+
/**
|
|
99
|
+
* Compute the effective authorization tier
|
|
100
|
+
*
|
|
101
|
+
* This combines:
|
|
102
|
+
* 1. The clamped trust score (from ceiling enforcement)
|
|
103
|
+
* 2. The context ceiling
|
|
104
|
+
*
|
|
105
|
+
* Result is the minimum tier that respects both constraints.
|
|
106
|
+
*
|
|
107
|
+
* @param clampedScore - Score after ceiling enforcement
|
|
108
|
+
* @param contextType - Context that limited the score
|
|
109
|
+
* @returns Effective tier 0-5
|
|
110
|
+
*/
|
|
111
|
+
export declare function getEffectiveAuthorizationTier(clampedScore: number, contextType: ContextType): number;
|
|
112
|
+
//# sourceMappingURL=kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../src/trust-engine/ceiling-enforcement/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAkC,MAAM,oBAAoB,CAAC;AAEhF;;GAEG;AACH,oBAAY,WAAW;IACrB,KAAK,UAAU,CAAS,yCAAyC;IACjE,UAAU,eAAe,CAAE,0CAA0C;IACrE,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,cAAc,EAAE,OAAO,CAAC;IACxB,+CAA+C;IAC/C,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAWrE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,GACvB,wBAAwB,CAqB1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,WAAW,GACvB,UAAU,CAQZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,WAAW,GACvB,MAAM,CASR"}
|