@vorionsys/atsf-core 0.4.1 → 0.4.3
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/basis/parser.d.ts +74 -74
- package/dist/basis/parser.js +3 -3
- package/dist/basis/parser.js.map +1 -1
- package/dist/common/config.d.ts +16 -16
- package/dist/enforce/fast-path.d.ts +134 -0
- package/dist/enforce/fast-path.d.ts.map +1 -0
- package/dist/enforce/fast-path.js +257 -0
- package/dist/enforce/fast-path.js.map +1 -0
- package/dist/enforce/pipeline-optimizer.d.ts +111 -0
- package/dist/enforce/pipeline-optimizer.d.ts.map +1 -0
- package/dist/enforce/pipeline-optimizer.js +370 -0
- package/dist/enforce/pipeline-optimizer.js.map +1 -0
- package/dist/enforce/policy-cache.d.ts +92 -0
- package/dist/enforce/policy-cache.d.ts.map +1 -0
- package/dist/enforce/policy-cache.js +186 -0
- package/dist/enforce/policy-cache.js.map +1 -0
- package/dist/enforce/trust-cache.d.ts +118 -0
- package/dist/enforce/trust-cache.d.ts.map +1 -0
- package/dist/enforce/trust-cache.js +218 -0
- package/dist/enforce/trust-cache.js.map +1 -0
- package/dist/paramesphere/gpu-svd.d.ts +102 -0
- package/dist/paramesphere/gpu-svd.d.ts.map +1 -0
- package/dist/paramesphere/gpu-svd.js +668 -0
- package/dist/paramesphere/gpu-svd.js.map +1 -0
- package/dist/paramesphere/index.d.ts +2 -0
- package/dist/paramesphere/index.d.ts.map +1 -1
- package/dist/paramesphere/index.js +1 -0
- package/dist/paramesphere/index.js.map +1 -1
- package/dist/paramesphere/paramesphere-engine.d.ts +40 -3
- package/dist/paramesphere/paramesphere-engine.d.ts.map +1 -1
- package/dist/paramesphere/paramesphere-engine.js +133 -6
- package/dist/paramesphere/paramesphere-engine.js.map +1 -1
- package/dist/paramesphere/scheduled-verifier.d.ts +136 -0
- package/dist/paramesphere/scheduled-verifier.d.ts.map +1 -0
- package/dist/paramesphere/scheduled-verifier.js +338 -0
- package/dist/paramesphere/scheduled-verifier.js.map +1 -0
- package/dist/paramesphere/svd-worker-pool.d.ts +37 -0
- package/dist/paramesphere/svd-worker-pool.d.ts.map +1 -0
- package/dist/paramesphere/svd-worker-pool.js +144 -0
- package/dist/paramesphere/svd-worker-pool.js.map +1 -0
- package/dist/paramesphere/svd-worker.d.ts +2 -0
- package/dist/paramesphere/svd-worker.d.ts.map +1 -0
- package/dist/paramesphere/svd-worker.js +103 -0
- package/dist/paramesphere/svd-worker.js.map +1 -0
- package/dist/paramesphere/types.d.ts +14 -0
- package/dist/paramesphere/types.d.ts.map +1 -1
- package/dist/paramesphere/types.js.map +1 -1
- package/dist/phase6/types.d.ts +257 -257
- package/dist/phase6/types.js +1 -1
- package/dist/phase6/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2024-2026 Vorion LLC
|
|
3
|
+
/**
|
|
4
|
+
* Fast-Path Enforcement
|
|
5
|
+
*
|
|
6
|
+
* Pre-computed decision matrix that skips full policy evaluation for the
|
|
7
|
+
* ~70-80% of enforcement requests that have deterministic outcomes.
|
|
8
|
+
*
|
|
9
|
+
* At 10K concurrent agents the policy engine evaluation (~2ms per call)
|
|
10
|
+
* dominates the enforcement pipeline p99 latency. This fast path reduces
|
|
11
|
+
* the common case to an O(1) Map lookup (<0.01ms).
|
|
12
|
+
*
|
|
13
|
+
* How it works:
|
|
14
|
+
* 1. A decision matrix is pre-computed for every (trustTier x actionType x riskLevel) tuple.
|
|
15
|
+
* 2. Each tuple maps to ALLOW, DENY, or CONDITIONAL (needs full evaluation).
|
|
16
|
+
* 3. On enforcement request the fast path is checked first:
|
|
17
|
+
* - ALLOW / DENY → return immediately, skip policy engine entirely
|
|
18
|
+
* - CONDITIONAL → fall through to full evaluation pipeline
|
|
19
|
+
* 4. The matrix is rebuilt when policies change (event-driven invalidation).
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
import { createLogger } from '../common/logger.js';
|
|
24
|
+
const logger = createLogger({ component: 'fast-path-enforcer' });
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// DEFAULTS
|
|
27
|
+
// =============================================================================
|
|
28
|
+
const ALL_TRUST_TIERS = [0, 1, 2, 3, 4, 5, 6, 7];
|
|
29
|
+
const ALL_ACTION_TYPES = ['read', 'write', 'delete', 'execute', 'transfer'];
|
|
30
|
+
const ALL_RISK_LEVELS = ['read', 'low', 'medium', 'high', 'critical'];
|
|
31
|
+
const DEFAULT_THRESHOLDS = {
|
|
32
|
+
autoApproveTier: 4,
|
|
33
|
+
requireRefinementTier: 2,
|
|
34
|
+
autoDenyTier: 0,
|
|
35
|
+
};
|
|
36
|
+
// =============================================================================
|
|
37
|
+
// FAST PATH ENFORCER
|
|
38
|
+
// =============================================================================
|
|
39
|
+
export class FastPathEnforcer {
|
|
40
|
+
matrix = new Map();
|
|
41
|
+
thresholds;
|
|
42
|
+
trustTiers;
|
|
43
|
+
actionTypes;
|
|
44
|
+
riskLevels;
|
|
45
|
+
// Metrics
|
|
46
|
+
_hits = 0;
|
|
47
|
+
_misses = 0;
|
|
48
|
+
_totalFastPathLatencyMs = 0;
|
|
49
|
+
_totalFullEvalLatencyMs = 0;
|
|
50
|
+
_fullEvalCount = 0;
|
|
51
|
+
constructor(config) {
|
|
52
|
+
this.thresholds = config?.thresholds ?? DEFAULT_THRESHOLDS;
|
|
53
|
+
this.trustTiers = config?.trustTiers ?? ALL_TRUST_TIERS;
|
|
54
|
+
this.actionTypes = config?.actionTypes ?? ALL_ACTION_TYPES;
|
|
55
|
+
this.riskLevels = config?.riskLevels ?? ALL_RISK_LEVELS;
|
|
56
|
+
this.rebuildMatrix();
|
|
57
|
+
}
|
|
58
|
+
// ===========================================================================
|
|
59
|
+
// Core API
|
|
60
|
+
// ===========================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Check the fast-path decision matrix for an enforcement request.
|
|
63
|
+
*
|
|
64
|
+
* Returns `hit: true` with a definitive ALLOW or DENY when the matrix
|
|
65
|
+
* can resolve the request without full policy evaluation.
|
|
66
|
+
*
|
|
67
|
+
* Returns `hit: false` with verdict CONDITIONAL when the request must
|
|
68
|
+
* fall through to the full pipeline.
|
|
69
|
+
*/
|
|
70
|
+
check(request) {
|
|
71
|
+
const t0 = performance.now();
|
|
72
|
+
// If the caller signals conditional rules, force fallthrough
|
|
73
|
+
if (request.hasConditionalRules) {
|
|
74
|
+
this._misses++;
|
|
75
|
+
return {
|
|
76
|
+
hit: false,
|
|
77
|
+
verdict: 'CONDITIONAL',
|
|
78
|
+
reasoning: 'Request has conditional policy rules — requires full evaluation',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const key = this.buildKey(request.trustTier, request.actionType, request.riskLevel);
|
|
82
|
+
const cell = this.matrix.get(key);
|
|
83
|
+
const elapsedMs = performance.now() - t0;
|
|
84
|
+
if (!cell || cell.verdict === 'CONDITIONAL') {
|
|
85
|
+
this._misses++;
|
|
86
|
+
return {
|
|
87
|
+
hit: false,
|
|
88
|
+
verdict: 'CONDITIONAL',
|
|
89
|
+
reasoning: cell?.reasoning ?? 'No matrix entry — requires full evaluation',
|
|
90
|
+
lookupTimeNs: Math.round(elapsedMs * 1_000_000),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
this._hits++;
|
|
94
|
+
this._totalFastPathLatencyMs += elapsedMs;
|
|
95
|
+
return {
|
|
96
|
+
hit: true,
|
|
97
|
+
verdict: cell.verdict,
|
|
98
|
+
reasoning: cell.reasoning,
|
|
99
|
+
lookupTimeNs: Math.round(elapsedMs * 1_000_000),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// ===========================================================================
|
|
103
|
+
// Matrix management
|
|
104
|
+
// ===========================================================================
|
|
105
|
+
/**
|
|
106
|
+
* Rebuild the decision matrix from current thresholds.
|
|
107
|
+
* Call this when policies change.
|
|
108
|
+
*/
|
|
109
|
+
rebuildMatrix(thresholds) {
|
|
110
|
+
if (thresholds) {
|
|
111
|
+
this.thresholds = thresholds;
|
|
112
|
+
}
|
|
113
|
+
this.matrix.clear();
|
|
114
|
+
for (const tier of this.trustTiers) {
|
|
115
|
+
for (const action of this.actionTypes) {
|
|
116
|
+
for (const risk of this.riskLevels) {
|
|
117
|
+
const cell = this.computeCell(tier, action, risk);
|
|
118
|
+
this.matrix.set(this.buildKey(tier, action, risk), cell);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
logger.info({ matrixSize: this.matrix.size, thresholds: this.thresholds }, 'Fast-path decision matrix rebuilt');
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the raw matrix size (number of pre-computed cells).
|
|
126
|
+
*/
|
|
127
|
+
get matrixSize() {
|
|
128
|
+
return this.matrix.size;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get a specific matrix cell for inspection/debugging.
|
|
132
|
+
*/
|
|
133
|
+
getCell(trustTier, actionType, riskLevel) {
|
|
134
|
+
return this.matrix.get(this.buildKey(trustTier, actionType, riskLevel));
|
|
135
|
+
}
|
|
136
|
+
// ===========================================================================
|
|
137
|
+
// Full eval latency tracking (called externally)
|
|
138
|
+
// ===========================================================================
|
|
139
|
+
/**
|
|
140
|
+
* Record a full evaluation latency (for metrics comparison).
|
|
141
|
+
* Call this from the pipeline optimizer when a full eval is performed.
|
|
142
|
+
*/
|
|
143
|
+
recordFullEvalLatency(latencyMs) {
|
|
144
|
+
this._totalFullEvalLatencyMs += latencyMs;
|
|
145
|
+
this._fullEvalCount++;
|
|
146
|
+
}
|
|
147
|
+
// ===========================================================================
|
|
148
|
+
// Metrics
|
|
149
|
+
// ===========================================================================
|
|
150
|
+
getMetrics() {
|
|
151
|
+
const total = this._hits + this._misses;
|
|
152
|
+
return {
|
|
153
|
+
fastPathHits: this._hits,
|
|
154
|
+
fastPathMisses: this._misses,
|
|
155
|
+
fastPathHitRate: total > 0 ? this._hits / total : 0,
|
|
156
|
+
fastPathMissRate: total > 0 ? this._misses / total : 0,
|
|
157
|
+
avgFastPathLatencyMs: this._hits > 0 ? this._totalFastPathLatencyMs / this._hits : 0,
|
|
158
|
+
avgFullEvalLatencyMs: this._fullEvalCount > 0 ? this._totalFullEvalLatencyMs / this._fullEvalCount : 0,
|
|
159
|
+
matrixSize: this.matrix.size,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
resetMetrics() {
|
|
163
|
+
this._hits = 0;
|
|
164
|
+
this._misses = 0;
|
|
165
|
+
this._totalFastPathLatencyMs = 0;
|
|
166
|
+
this._totalFullEvalLatencyMs = 0;
|
|
167
|
+
this._fullEvalCount = 0;
|
|
168
|
+
}
|
|
169
|
+
// ===========================================================================
|
|
170
|
+
// Private helpers
|
|
171
|
+
// ===========================================================================
|
|
172
|
+
buildKey(tier, action, risk) {
|
|
173
|
+
return `${tier}:${action}:${risk}`;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Compute a single matrix cell.
|
|
177
|
+
*
|
|
178
|
+
* The logic mirrors TrustAwareEnforcementService.determineTier() but
|
|
179
|
+
* without evaluation context (no specific violated rules). This means
|
|
180
|
+
* we can only produce definitive answers for cases that DON'T depend on
|
|
181
|
+
* per-request policy evaluation results.
|
|
182
|
+
*/
|
|
183
|
+
computeCell(tier, action, risk) {
|
|
184
|
+
// ----- DEFINITIVE DENY cases -----
|
|
185
|
+
// Trust below auto-deny → always RED
|
|
186
|
+
if (tier < this.thresholds.autoDenyTier) {
|
|
187
|
+
return {
|
|
188
|
+
verdict: 'DENY',
|
|
189
|
+
reasoning: `Trust T${tier} below auto-deny threshold T${this.thresholds.autoDenyTier}`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// Critical risk below T6 → never auto-approved (needs refinement or denial)
|
|
193
|
+
if (risk === 'critical' && tier < 6) {
|
|
194
|
+
if (tier < this.thresholds.requireRefinementTier) {
|
|
195
|
+
return {
|
|
196
|
+
verdict: 'DENY',
|
|
197
|
+
reasoning: `Critical risk at T${tier} — below refinement threshold`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// YELLOW zone for critical risk — cannot fast-path ALLOW
|
|
201
|
+
return {
|
|
202
|
+
verdict: 'CONDITIONAL',
|
|
203
|
+
reasoning: `Critical risk at T${tier} — requires refinement evaluation`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
// High risk requires elevated approval (autoApprove + 1)
|
|
207
|
+
if (risk === 'high') {
|
|
208
|
+
const elevatedApproveTier = Math.min(7, this.thresholds.autoApproveTier + 1);
|
|
209
|
+
if (tier >= elevatedApproveTier) {
|
|
210
|
+
return {
|
|
211
|
+
verdict: 'ALLOW',
|
|
212
|
+
reasoning: `T${tier} meets elevated threshold T${elevatedApproveTier} for high-risk ${action}`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (tier < this.thresholds.requireRefinementTier) {
|
|
216
|
+
return {
|
|
217
|
+
verdict: 'DENY',
|
|
218
|
+
reasoning: `T${tier} below refinement threshold for high-risk ${action}`,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
verdict: 'CONDITIONAL',
|
|
223
|
+
reasoning: `High risk at T${tier} — requires policy evaluation`,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// ----- DEFINITIVE ALLOW cases -----
|
|
227
|
+
// Reads at T3+ with low/read risk → always ALLOW
|
|
228
|
+
if (action === 'read' && (risk === 'read' || risk === 'low') && tier >= 3) {
|
|
229
|
+
return {
|
|
230
|
+
verdict: 'ALLOW',
|
|
231
|
+
reasoning: `Read-only at T${tier} with ${risk} risk — auto-approved`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
// Trust at or above auto-approve → ALLOW (assuming evaluation passes)
|
|
235
|
+
// We mark this ALLOW because the fast path only fires when there are
|
|
236
|
+
// no pre-existing violated rules in the evaluation.
|
|
237
|
+
if (tier >= this.thresholds.autoApproveTier) {
|
|
238
|
+
return {
|
|
239
|
+
verdict: 'ALLOW',
|
|
240
|
+
reasoning: `T${tier} meets auto-approve threshold T${this.thresholds.autoApproveTier} for ${action}/${risk}`,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
// Trust below refinement threshold → CONDITIONAL (could be YELLOW or RED depending on eval)
|
|
244
|
+
if (tier < this.thresholds.requireRefinementTier) {
|
|
245
|
+
return {
|
|
246
|
+
verdict: 'CONDITIONAL',
|
|
247
|
+
reasoning: `T${tier} below refinement threshold — decision depends on evaluation`,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// Everything else is in the YELLOW zone — requires evaluation
|
|
251
|
+
return {
|
|
252
|
+
verdict: 'CONDITIONAL',
|
|
253
|
+
reasoning: `T${tier} with ${action}/${risk} — requires policy evaluation for refinement`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=fast-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-path.js","sourceRoot":"","sources":["../../src/enforce/fast-path.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAAC;AA+FjE,gFAAgF;AAChF,WAAW;AACX,gFAAgF;AAEhF,MAAM,eAAe,GAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/D,MAAM,gBAAgB,GAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC1F,MAAM,eAAe,GAAgB,CAAC,MAAM,EAA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;QACpD,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC;YAC5C,OAAO;gBACL,OAAO,EAAE,OAAO;gBAChB,SAAS,EAAE,IAAI,IAAI,kCAAkC,IAAI,CAAC,UAAU,CAAC,eAAe,QAAQ,MAAM,IAAI,IAAI,EAAE;aAC7G,CAAC;QACJ,CAAC;QAED,4FAA4F;QAC5F,IAAI,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,qBAAqB,EAAE,CAAC;YACjD,OAAO;gBACL,OAAO,EAAE,aAAa;gBACtB,SAAS,EAAE,IAAI,IAAI,8DAA8D;aAClF,CAAC;QACJ,CAAC;QAED,8DAA8D;QAC9D,OAAO;YACL,OAAO,EAAE,aAAa;YACtB,SAAS,EAAE,IAAI,IAAI,SAAS,MAAM,IAAI,IAAI,8CAA8C;SACzF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { ID } from '../common/types.js';
|
|
2
|
+
import type { EnforcementContext, FluidDecisionResult } from './index.js';
|
|
3
|
+
import type { TrustAwareEnforcementService } from './trust-aware-enforcement-service.js';
|
|
4
|
+
import { FastPathEnforcer } from './fast-path.js';
|
|
5
|
+
import { TrustLookupCache } from './trust-cache.js';
|
|
6
|
+
import type { TrustScoreProvider, TrustSignalBus } from './trust-cache.js';
|
|
7
|
+
/**
|
|
8
|
+
* Optimizer configuration.
|
|
9
|
+
*/
|
|
10
|
+
export interface PipelineOptimizerConfig {
|
|
11
|
+
/** Enable the fast-path matrix (default: true) */
|
|
12
|
+
enableFastPath: boolean;
|
|
13
|
+
/** Enable the trust lookup cache (default: true) */
|
|
14
|
+
enableTrustCache: boolean;
|
|
15
|
+
/** Enable parallel evaluation of independent checks (default: true) */
|
|
16
|
+
enableParallelEval: boolean;
|
|
17
|
+
/** Enable early termination on capability denial (default: true) */
|
|
18
|
+
enableEarlyTermination: boolean;
|
|
19
|
+
/** Trust cache TTL in ms (default: 5000) */
|
|
20
|
+
trustCacheTtlMs: number;
|
|
21
|
+
/** Maximum trust cache entries (default: 50000) */
|
|
22
|
+
trustCacheMaxEntries: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Batch enforcement request — multiple contexts for the same or different agents.
|
|
26
|
+
*/
|
|
27
|
+
export interface BatchEnforcementRequest {
|
|
28
|
+
contexts: EnforcementContext[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Batch enforcement result.
|
|
32
|
+
*/
|
|
33
|
+
export interface BatchEnforcementResult {
|
|
34
|
+
results: FluidDecisionResult[];
|
|
35
|
+
totalLatencyMs: number;
|
|
36
|
+
avgLatencyMs: number;
|
|
37
|
+
fastPathHits: number;
|
|
38
|
+
fullEvals: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pipeline optimizer metrics.
|
|
42
|
+
*/
|
|
43
|
+
export interface PipelineOptimizerMetrics {
|
|
44
|
+
totalRequests: number;
|
|
45
|
+
fastPathHits: number;
|
|
46
|
+
fastPathMisses: number;
|
|
47
|
+
earlyTerminations: number;
|
|
48
|
+
parallelEvals: number;
|
|
49
|
+
batchRequests: number;
|
|
50
|
+
batchItemsProcessed: number;
|
|
51
|
+
avgLatencyMs: number;
|
|
52
|
+
p99LatencyMs: number;
|
|
53
|
+
}
|
|
54
|
+
export declare class PipelineOptimizer {
|
|
55
|
+
private readonly config;
|
|
56
|
+
private readonly enforcementService;
|
|
57
|
+
private readonly fastPath;
|
|
58
|
+
private readonly trustCache;
|
|
59
|
+
private _totalRequests;
|
|
60
|
+
private _fastPathHits;
|
|
61
|
+
private _fastPathMisses;
|
|
62
|
+
private _earlyTerminations;
|
|
63
|
+
private _parallelEvals;
|
|
64
|
+
private _batchRequests;
|
|
65
|
+
private _batchItemsProcessed;
|
|
66
|
+
private _latencies;
|
|
67
|
+
private readonly _maxLatencyBuffer;
|
|
68
|
+
constructor(enforcementService: TrustAwareEnforcementService, config?: Partial<PipelineOptimizerConfig>);
|
|
69
|
+
getFastPath(): FastPathEnforcer;
|
|
70
|
+
getTrustCache(): TrustLookupCache;
|
|
71
|
+
/**
|
|
72
|
+
* Enforce a single request with optimizations:
|
|
73
|
+
* 1. Fast-path check
|
|
74
|
+
* 2. Trust cache lookup
|
|
75
|
+
* 3. Parallel evaluation of independent checks
|
|
76
|
+
* 4. Early termination on fast-path DENY
|
|
77
|
+
*/
|
|
78
|
+
enforce(context: EnforcementContext): Promise<FluidDecisionResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Enforce multiple requests in a batch.
|
|
81
|
+
*
|
|
82
|
+
* Optimizations:
|
|
83
|
+
* - Shared trust lookups for requests from the same agent
|
|
84
|
+
* - Fast-path filtering to separate definitive from conditional requests
|
|
85
|
+
* - Parallel execution of remaining full evaluations
|
|
86
|
+
*/
|
|
87
|
+
enforceBatch(batch: BatchEnforcementRequest): Promise<BatchEnforcementResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Pre-load trust profiles for known active agents.
|
|
90
|
+
* Call during application startup to avoid cold-cache latency on first request.
|
|
91
|
+
*/
|
|
92
|
+
warmUp(agentIds: ID[], trustProvider: TrustScoreProvider): Promise<number>;
|
|
93
|
+
/**
|
|
94
|
+
* Subscribe to trust signal bus for cache invalidation.
|
|
95
|
+
*/
|
|
96
|
+
subscribeToSignals(bus: TrustSignalBus): void;
|
|
97
|
+
/**
|
|
98
|
+
* Notify the optimizer that policies have changed.
|
|
99
|
+
* Rebuilds the fast-path matrix from the enforcement service's current config.
|
|
100
|
+
*/
|
|
101
|
+
onPolicyChange(): void;
|
|
102
|
+
getMetrics(): PipelineOptimizerMetrics;
|
|
103
|
+
resetMetrics(): void;
|
|
104
|
+
dispose(): void;
|
|
105
|
+
private recordLatency;
|
|
106
|
+
/**
|
|
107
|
+
* Cache trust data extracted from a decision result.
|
|
108
|
+
*/
|
|
109
|
+
private cacheResultTrust;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=pipeline-optimizer.d.ts.map
|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