pi-mega-compact 0.20.18 → 0.20.20
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/vector-cortex-vc8c.js +31 -0
- package/dist/config/vector-cortex.js +19 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-platform.js +12 -0
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-policy.js +12 -0
- package/dist/extensions/dashboard-server/route-dispatch.js +12 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-platform.js +42 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-policy.js +45 -0
- package/dist/src/config/vector-cortex-vc8c.js +31 -0
- package/dist/src/config/vector-cortex.js +19 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/cache/_diagnostics-fixture.js +79 -5
- package/dist/src/vector-cortex/cache/diagnostics.js +17 -8
- package/dist/src/vector-cortex/controller/_adaptive-fixture.js +126 -0
- package/dist/src/vector-cortex/controller/policy-emit.js +56 -0
- package/dist/src/vector-cortex/migrations/pressure-v2-ops.js +166 -0
- package/dist/src/vector-cortex/migrations/pressure-v2-types.js +32 -0
- package/dist/src/vector-cortex/migrations/pressure-v2.js +36 -0
- package/dist/src/vector-cortex/migrations/request-hash-v2-ops.js +23 -7
- package/dist/src/vector-cortex/platform/cross-read.js +98 -0
- package/dist/src/vector-cortex/platform/emit.js +54 -0
- package/dist/src/vector-cortex/platform/select.js +104 -0
- package/dist/src/vector-cortex/platform/types.js +57 -0
- package/dist/vector-cortex/cache/_diagnostics-fixture.js +79 -5
- package/dist/vector-cortex/cache/diagnostics.js +17 -8
- package/dist/vector-cortex/controller/_adaptive-fixture.js +126 -0
- package/dist/vector-cortex/controller/policy-emit.js +56 -0
- package/dist/vector-cortex/controller/policy.js +158 -0
- package/dist/vector-cortex/controller/shadow.js +117 -0
- package/dist/vector-cortex/controller/types.js +85 -0
- package/dist/vector-cortex/migrations/pressure-v2-ops.js +166 -0
- package/dist/vector-cortex/migrations/pressure-v2-types.js +32 -0
- package/dist/vector-cortex/migrations/pressure-v2.js +36 -0
- package/dist/vector-cortex/migrations/request-hash-v2-ops.js +23 -7
- package/dist/vector-cortex/platform/cross-read.js +98 -0
- package/dist/vector-cortex/platform/emit.js +54 -0
- package/dist/vector-cortex/platform/select.js +104 -0
- package/dist/vector-cortex/platform/types.js +57 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-BOGp2sag.js → AreaChart-BkfB-LSQ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-BOGp2sag.js.map → AreaChart-BkfB-LSQ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-BHgA-QPL.js → BarChart-Cs1kogko.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-BHgA-QPL.js.map → BarChart-Cs1kogko.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-6E7lwM74.js → CacheTab-BZgaguGr.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-6E7lwM74.js.map → CacheTab-BZgaguGr.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-BEtNmFHz.js → EventsTab-BFbkI_MO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-BEtNmFHz.js.map → EventsTab-BFbkI_MO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-DGxZulRH.js → HealthTab-CvlOENCX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-DGxZulRH.js.map → HealthTab-CvlOENCX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-C86jppQE.js → MaintenanceTab-CtBuz2qL.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-C86jppQE.js.map → MaintenanceTab-CtBuz2qL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-J3VVxooZ.js → MemoryMapTab-K4775S4d.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-J3VVxooZ.js.map → MemoryMapTab-K4775S4d.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-yn9AFumo.js → MetricsTab-DVGcFInz.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-yn9AFumo.js.map → MetricsTab-DVGcFInz.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BMarUiq3.js → OverviewTab-4LmW5ZCl.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BMarUiq3.js.map → OverviewTab-4LmW5ZCl.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-DxnzMive.js → ReposTab-StebchgQ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-DxnzMive.js.map → ReposTab-StebchgQ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DXKpDUuC.js → SessionsTab-C3D_XAkX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DXKpDUuC.js.map → SessionsTab-C3D_XAkX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-BctuV-CJ.js → SetupTab-BTBGyppF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-BctuV-CJ.js.map → SetupTab-BTBGyppF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-D8yOC96S.js → TimeSavedCard-CTPi_AAW.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-D8yOC96S.js.map → TimeSavedCard-CTPi_AAW.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-BBxqGYH-.js → TurnsTab-DSOGcY5Q.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-BBxqGYH-.js.map → TurnsTab-DSOGcY5Q.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-OMW8_RFf.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-OMW8_RFf.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-DdJQSagO.js → WikiTab-Db-qFDdg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-DdJQSagO.js.map → WikiTab-Db-qFDdg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-B4Q9h_8Y.js → button-BF4UgBAD.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-B4Q9h_8Y.js.map → button-BF4UgBAD.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-WyR31hUV.js → card-XmXoYQqB.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-WyR31hUV.js.map → card-XmXoYQqB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-pTio6Bq3.js → generateCategoricalChart-Be8hM1aU.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-pTio6Bq3.js.map → generateCategoricalChart-Be8hM1aU.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/index-Difwoltx.css +1 -0
- package/extensions/dashboard-client/dist/assets/{index-BoLUiNsd.js → index-NXDgILxv.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-BoLUiNsd.js.map → index-NXDgILxv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-5dieXxoo.js → switch-kUZCrbia.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-5dieXxoo.js.map → switch-kUZCrbia.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-BFc-7_LL.js → toggle-DEe5mCwF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-BFc-7_LL.js.map → toggle-DEe5mCwF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-BqmKNBAI.js → useSSE-BlCyLqge.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BqmKNBAI.js.map → useSSE-BlCyLqge.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +2 -2
- package/extensions/dashboard-client/src/api/vector-cortex.ts +18 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexPlatformCard.tsx +42 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexPolicyCard.tsx +43 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +4 -0
- package/extensions/dashboard-client/src/tabs/useVectorCortexPoll.ts +10 -0
- package/extensions/dashboard-client/src/types/vector-cortex-vc8.ts +34 -1
- package/extensions/dashboard-client/src/types/vector-cortex.ts +1 -1
- package/extensions/dashboard-server/api-contracts/vector-cortex-platform.ts +34 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex-policy.ts +36 -0
- package/extensions/dashboard-server/route-dispatch.ts +12 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
- package/extensions/dashboard-server/routes-vector-cortex-platform.ts +52 -0
- package/extensions/dashboard-server/routes-vector-cortex-policy.ts +55 -0
- package/package.json +1 -1
- package/src/config/vector-cortex-vc8c.ts +33 -0
- package/src/config/vector-cortex.ts +21 -0
- package/src/config.ts +2 -0
- package/src/vector-cortex/cache/_diagnostics-fixture.ts +163 -5
- package/src/vector-cortex/cache/diagnostics.ts +18 -9
- package/src/vector-cortex/controller/_adaptive-fixture.ts +230 -0
- package/src/vector-cortex/controller/policy-emit.ts +82 -0
- package/src/vector-cortex/migrations/pressure-v2-ops.ts +204 -0
- package/src/vector-cortex/migrations/pressure-v2-types.ts +83 -0
- package/src/vector-cortex/migrations/pressure-v2.ts +59 -0
- package/src/vector-cortex/migrations/request-hash-v2-ops.ts +21 -6
- package/src/vector-cortex/platform/cross-read.ts +122 -0
- package/src/vector-cortex/platform/emit.ts +77 -0
- package/src/vector-cortex/platform/select.ts +131 -0
- package/src/vector-cortex/platform/types.ts +169 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BTF1AGCJ.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BTF1AGCJ.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-CYpzq9Lm.css +0 -1
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* cache/_diagnostics-fixture.ts — VC7C
|
|
2
|
+
* cache/_diagnostics-fixture.ts — VC7C conformance fixture I/O + host builders.
|
|
3
3
|
*
|
|
4
|
-
* Reads conformance fixtures from the v2 `cache-diagnostics/` domain
|
|
5
|
-
*
|
|
4
|
+
* Reads conformance fixtures from the v2 `cache-diagnostics/` domain, decodes
|
|
5
|
+
* them into the REAL production types (`MissObservation`, `M5Host`) and feeds
|
|
6
|
+
* them verbatim into `classifyMiss` / `migrateRequestHashV2`. Fixtures store
|
|
7
|
+
* bigints as JSON numbers — converted here (lossy conversion would break
|
|
8
|
+
* digests and the acceptance rows would fail loudly).
|
|
9
|
+
*
|
|
10
|
+
* No mocks, no stubs, no parallel "test shape": the decoded objects ARE
|
|
11
|
+
* `MissObservation` / `M5Host` and drive the production functions directly.
|
|
12
|
+
* Mirrors `_economics-fixture.ts`.
|
|
6
13
|
*/
|
|
7
|
-
import { readFileSync } from "node:fs";
|
|
14
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
8
15
|
import { join, dirname } from "node:path";
|
|
9
16
|
import { fileURLToPath } from "node:url";
|
|
10
17
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
|
|
18
|
+
function repoRoot(from) {
|
|
19
|
+
let dir = from;
|
|
20
|
+
for (let i = 0; i < 8; i++) {
|
|
21
|
+
if (existsSync(join(dir, "conformance", "vector-cortex")))
|
|
22
|
+
return dir;
|
|
23
|
+
const next = dirname(dir);
|
|
24
|
+
if (next === dir)
|
|
25
|
+
break;
|
|
26
|
+
dir = next;
|
|
27
|
+
}
|
|
28
|
+
throw new Error("conformance corpus not found above " + from);
|
|
29
|
+
}
|
|
30
|
+
const V2 = join(repoRoot(here), "conformance", "vector-cortex", "v2");
|
|
12
31
|
const DIR = join(V2, "cache-diagnostics");
|
|
13
32
|
/** Read + parse one conformance fixture by ID. */
|
|
14
33
|
export function diagnosticsFixture(id) {
|
|
@@ -29,3 +48,58 @@ export function withVc7cFlag(value, fn) {
|
|
|
29
48
|
process.env.MEGACOMPACT_VC7C = prior;
|
|
30
49
|
}
|
|
31
50
|
}
|
|
51
|
+
/** Read a cache-diagnostic fixture as a typed CacheFx. */
|
|
52
|
+
export function cacheFx(id) {
|
|
53
|
+
return diagnosticsFixture(id);
|
|
54
|
+
}
|
|
55
|
+
/** Decode the fixture's JSON observe into the production MissObservation. */
|
|
56
|
+
export function toObservation(fx) {
|
|
57
|
+
const o = fx.input.observe;
|
|
58
|
+
return {
|
|
59
|
+
requestProfileId: o.requestProfileId,
|
|
60
|
+
requestProfileVersion: o.requestProfileVersion,
|
|
61
|
+
cachedProfileId: o.cachedProfileId,
|
|
62
|
+
cachedProfileVersion: o.cachedProfileVersion,
|
|
63
|
+
requestCoveredDigest: o.requestCoveredDigest,
|
|
64
|
+
cachedCoveredDigest: o.cachedCoveredDigest,
|
|
65
|
+
requestedRangeCount: o.requestedRangeCount,
|
|
66
|
+
cachedRangeCount: o.cachedRangeCount,
|
|
67
|
+
requestDigest: o.requestDigest,
|
|
68
|
+
cachedRequestDigest: o.cachedRequestDigest,
|
|
69
|
+
requestDependencyHighWater: BigInt(o.requestDependencyHighWater),
|
|
70
|
+
cachedDependencyHighWater: o.cachedDependencyHighWater === null
|
|
71
|
+
? null
|
|
72
|
+
: BigInt(o.cachedDependencyHighWater),
|
|
73
|
+
generationInvalidated: o.generationInvalidated,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Read an M5 fixture as a typed M5Fx. */
|
|
77
|
+
export function m5Fx(id) {
|
|
78
|
+
return diagnosticsFixture(id);
|
|
79
|
+
}
|
|
80
|
+
/** Build an in-memory M5Host from the fixture input. */
|
|
81
|
+
export function toM5Host(fx) {
|
|
82
|
+
const v1Rows = fx.input.v1Rows.map((r) => ({
|
|
83
|
+
profileId: r.profileId,
|
|
84
|
+
requestDigest: r.requestDigest,
|
|
85
|
+
hash: r.hash,
|
|
86
|
+
}));
|
|
87
|
+
const v2Rows = [];
|
|
88
|
+
let activeVersion = fx.input.activeVersion;
|
|
89
|
+
const host = {
|
|
90
|
+
v1Rows: () => v1Rows,
|
|
91
|
+
economicsVersionOf: (p) => fx.input.econVersionOf[p] ?? "econ-1",
|
|
92
|
+
sessionOf: (p) => fx.input.sessionOf[p] ?? "s1",
|
|
93
|
+
liveGenerationOf: (s) => BigInt(fx.input.liveGenerationOf[s] ?? 0),
|
|
94
|
+
existingV2: () => v2Rows,
|
|
95
|
+
putV2: (rows) => v2Rows.push(...rows),
|
|
96
|
+
activeVersion: () => activeVersion,
|
|
97
|
+
switchToV2: () => {
|
|
98
|
+
activeVersion = 2;
|
|
99
|
+
},
|
|
100
|
+
get activeVersionAfter() {
|
|
101
|
+
return activeVersion;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
return host;
|
|
105
|
+
}
|
|
@@ -34,21 +34,30 @@ function advanceDelta(request, cached) {
|
|
|
34
34
|
}
|
|
35
35
|
/** Collect the payload-free evidence from one observation. */
|
|
36
36
|
export function collectEvidence(o) {
|
|
37
|
+
// Absence is computed first: "absence is not a mismatch" means a cold key
|
|
38
|
+
// (null cached fields) classifies `unknown`, never `profile`/`range`/etc.
|
|
39
|
+
// The cachedRangeCount on a cold key is 0 by convention (not a real count),
|
|
40
|
+
// so it must not trigger a range mismatch even though isPresent(0) is true.
|
|
41
|
+
const absent = !isPresent(o.cachedProfileId) &&
|
|
42
|
+
!isPresent(o.cachedCoveredDigest) &&
|
|
43
|
+
!isPresent(o.cachedRequestDigest) &&
|
|
44
|
+
!isPresent(o.cachedDependencyHighWater);
|
|
37
45
|
const profileMismatch = isPresent(o.cachedProfileId) &&
|
|
38
46
|
isPresent(o.cachedProfileVersion) &&
|
|
39
47
|
(o.cachedProfileId !== o.requestProfileId ||
|
|
40
48
|
o.cachedProfileVersion !== o.requestProfileVersion);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
// Guard with !absent: a cold key's cachedRangeCount is 0 by convention (not
|
|
50
|
+
// a real count), so it must not fire a range mismatch even though
|
|
51
|
+
// isPresent(0) is true. The covered-digest arm is already null-safe but
|
|
52
|
+
// the rangeCount arm is not — !absent covers both uniformly.
|
|
53
|
+
const rangeMismatch = !absent &&
|
|
54
|
+
((isPresent(o.cachedCoveredDigest) &&
|
|
55
|
+
o.cachedCoveredDigest !== o.requestCoveredDigest) ||
|
|
56
|
+
(isPresent(o.cachedRangeCount) &&
|
|
57
|
+
o.cachedRangeCount !== o.requestedRangeCount));
|
|
45
58
|
const dep = advanceDelta(o.requestDependencyHighWater, o.cachedDependencyHighWater);
|
|
46
59
|
const requestMismatch = isPresent(o.cachedRequestDigest) &&
|
|
47
60
|
o.cachedRequestDigest !== o.requestDigest;
|
|
48
|
-
const absent = !isPresent(o.cachedProfileId) &&
|
|
49
|
-
!isPresent(o.cachedCoveredDigest) &&
|
|
50
|
-
!isPresent(o.cachedRequestDigest) &&
|
|
51
|
-
!isPresent(o.cachedDependencyHighWater);
|
|
52
61
|
return {
|
|
53
62
|
profileMismatch,
|
|
54
63
|
rangeMismatch,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controller/_adaptive-fixture.ts — VC8B conformance fixture I/O + host builders.
|
|
3
|
+
*
|
|
4
|
+
* Reads conformance fixtures from the v2 `adaptive-policy/` domain, decodes
|
|
5
|
+
* them into the REAL production types (`PolicyInput`, `M7Host`) and feeds
|
|
6
|
+
* them verbatim into `evaluatePolicy` / `evaluateShadow` / `migratePressureV2`.
|
|
7
|
+
*
|
|
8
|
+
* No mocks, no stubs, no parallel "test shape": the decoded objects ARE the
|
|
9
|
+
* production types and drive the production functions directly.
|
|
10
|
+
* Mirrors `_diagnostics-fixture.ts` (VC7C) and `_economics-fixture.ts` (VC7B).
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
13
|
+
import { join, dirname } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
function repoRoot(from) {
|
|
17
|
+
let dir = from;
|
|
18
|
+
for (let i = 0; i < 8; i++) {
|
|
19
|
+
if (existsSync(join(dir, "conformance", "vector-cortex")))
|
|
20
|
+
return dir;
|
|
21
|
+
const next = dirname(dir);
|
|
22
|
+
if (next === dir)
|
|
23
|
+
break;
|
|
24
|
+
dir = next;
|
|
25
|
+
}
|
|
26
|
+
throw new Error("conformance corpus not found above " + from);
|
|
27
|
+
}
|
|
28
|
+
const V2 = join(repoRoot(here), "conformance", "vector-cortex", "v2");
|
|
29
|
+
const DIR = join(V2, "adaptive-policy");
|
|
30
|
+
/** Read + parse one conformance fixture by ID from adaptive-policy/. */
|
|
31
|
+
export function adaptiveFixture(id) {
|
|
32
|
+
const raw = readFileSync(join(DIR, `${id}.json`), "utf8");
|
|
33
|
+
return JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
/** Run `fn` with MEGACOMPACT_VC8B set to `value`, restoring the prior value after. */
|
|
36
|
+
export function withVc8bFlag(value, fn) {
|
|
37
|
+
const prior = process.env.MEGACOMPACT_VC8B;
|
|
38
|
+
process.env.MEGACOMPACT_VC8B = value;
|
|
39
|
+
try {
|
|
40
|
+
return fn();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (prior === undefined)
|
|
44
|
+
delete process.env.MEGACOMPACT_VC8B;
|
|
45
|
+
else
|
|
46
|
+
process.env.MEGACOMPACT_VC8B = prior;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Read a policy-decision fixture as a typed PolFx. */
|
|
50
|
+
export function polFx(id) {
|
|
51
|
+
return adaptiveFixture(id);
|
|
52
|
+
}
|
|
53
|
+
/** Decode the fixture's JSON input into the production PolicyInput. */
|
|
54
|
+
export function toPolicyInput(fx) {
|
|
55
|
+
return {
|
|
56
|
+
decisionId: fx.input.decisionId,
|
|
57
|
+
sessionId: fx.input.sessionId,
|
|
58
|
+
pressure: fx.input.pressure,
|
|
59
|
+
requestedBudget: fx.input.requestedBudget,
|
|
60
|
+
bounds: {
|
|
61
|
+
minBudget: fx.input.bounds.minBudget,
|
|
62
|
+
maxBudget: fx.input.bounds.maxBudget,
|
|
63
|
+
},
|
|
64
|
+
ts: fx.input.ts,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Read a policy-shadow fixture as a typed ShadowFx. */
|
|
68
|
+
export function shadowFx(id) {
|
|
69
|
+
return adaptiveFixture(id);
|
|
70
|
+
}
|
|
71
|
+
/** Decode shadow input rows into production PolicyInput[]. */
|
|
72
|
+
export function toShadowInputs(fx) {
|
|
73
|
+
return fx.input.inputs.map((i) => ({
|
|
74
|
+
decisionId: i.decisionId,
|
|
75
|
+
sessionId: i.sessionId,
|
|
76
|
+
pressure: i.pressure,
|
|
77
|
+
requestedBudget: i.requestedBudget,
|
|
78
|
+
bounds: {
|
|
79
|
+
minBudget: i.bounds.minBudget,
|
|
80
|
+
maxBudget: i.bounds.maxBudget,
|
|
81
|
+
},
|
|
82
|
+
ts: i.ts,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/** Read an M7 fixture as a typed M7Fx. */
|
|
86
|
+
export function m7Fx(id) {
|
|
87
|
+
return adaptiveFixture(id);
|
|
88
|
+
}
|
|
89
|
+
/** Build an in-memory M7Host from the fixture input. */
|
|
90
|
+
export function toM7Host(fx) {
|
|
91
|
+
const v1Rows = fx.input.v1Rows.map((r) => ({
|
|
92
|
+
sessionId: r.sessionId,
|
|
93
|
+
label: r.label,
|
|
94
|
+
effectiveSeq: r.effectiveSeq,
|
|
95
|
+
ts: r.ts,
|
|
96
|
+
}));
|
|
97
|
+
// For inject-after-copy, the injected row carries a non-canonical label.
|
|
98
|
+
// migratePressureV2 calls m7Copy first, which throws M7_PRESSURE_UNKNOWN for
|
|
99
|
+
// the bad label — the result is the same: ok:false, pointer on v1.
|
|
100
|
+
if (fx.input.injectedRow) {
|
|
101
|
+
v1Rows.push({
|
|
102
|
+
sessionId: fx.input.injectedRow.sessionId,
|
|
103
|
+
label: fx.input.injectedRow.label,
|
|
104
|
+
effectiveSeq: fx.input.injectedRow.effectiveSeq,
|
|
105
|
+
ts: fx.input.injectedRow.ts,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const v2Rows = [];
|
|
109
|
+
let activeVersion = fx.input.activeVersion ?? 1;
|
|
110
|
+
const host = {
|
|
111
|
+
v1Rows: () => v1Rows,
|
|
112
|
+
existingV2: () => v2Rows,
|
|
113
|
+
putV2: (rows) => v2Rows.push(...rows),
|
|
114
|
+
activeVersion: () => activeVersion,
|
|
115
|
+
switchToV2: () => {
|
|
116
|
+
activeVersion = 2;
|
|
117
|
+
},
|
|
118
|
+
get activeVersionAfter() {
|
|
119
|
+
return activeVersion;
|
|
120
|
+
},
|
|
121
|
+
get v2RowCount() {
|
|
122
|
+
return v2Rows.length;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
return host;
|
|
126
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controller/policy-emit.ts — VC8B reporter seam (FLAG-GATED).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the VC8A outcomes-emit pattern: a thin `safe()` wrapper around an
|
|
5
|
+
* optional injected `emit`, and the two event names the sprint spec requires:
|
|
6
|
+
* - `vector_cortex_shadow_decision_recorded` — a shadow decision was produced.
|
|
7
|
+
* - `vector_cortex_policy_action_rejected` — an input was refused by policy.
|
|
8
|
+
*
|
|
9
|
+
* FLAG SEMANTICS. The policy/shadow/M7 arithmetic STILL RUNS regardless of
|
|
10
|
+
* `MEGACOMPACT_VC8B`. The flag gates ONLY this reporting + dashboard seam:
|
|
11
|
+
* flag-off is byte-identical to the predecessor (VC8A).
|
|
12
|
+
*
|
|
13
|
+
* PAYLOAD DISCIPLINE. These events carry only ids, the finite action, the
|
|
14
|
+
* numeric budget, and machine codes — never prompt bytes, response text, or
|
|
15
|
+
* free-text.
|
|
16
|
+
*
|
|
17
|
+
* PREVENT-PI-004: no network. PREVENT-011: no `any` type.
|
|
18
|
+
*/
|
|
19
|
+
import { VC8B_ENABLED } from "../../config/vector-cortex.js";
|
|
20
|
+
/** Run `fn` only when an emit exists; a reporting failure is never fatal. */
|
|
21
|
+
function safe(emit, fn) {
|
|
22
|
+
if (emit === undefined)
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
fn(emit);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Non-fatal: a reporting failure must never break the agent loop.
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Report a shadow decision that was recorded. Gated by the flag. */
|
|
32
|
+
export function reportShadowDecisionRecorded(emit, decision) {
|
|
33
|
+
if (!VC8B_ENABLED())
|
|
34
|
+
return;
|
|
35
|
+
safe(emit, (e) => e("vector_cortex_shadow_decision_recorded", {
|
|
36
|
+
ts: undefined,
|
|
37
|
+
event: "vector_cortex_shadow_decision_recorded",
|
|
38
|
+
decisionId: decision.decisionId,
|
|
39
|
+
sessionId: decision.sessionId,
|
|
40
|
+
action: decision.action,
|
|
41
|
+
budget: decision.budget,
|
|
42
|
+
pressure: decision.pressure,
|
|
43
|
+
reason: decision.reason,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/** Report a policy action rejected by validation. Gated by the flag. */
|
|
47
|
+
export function reportPolicyActionRejected(emit, rejection) {
|
|
48
|
+
if (!VC8B_ENABLED())
|
|
49
|
+
return;
|
|
50
|
+
safe(emit, (e) => e("vector_cortex_policy_action_rejected", {
|
|
51
|
+
ts: undefined,
|
|
52
|
+
event: "vector_cortex_policy_action_rejected",
|
|
53
|
+
decisionId: rejection.decisionId,
|
|
54
|
+
code: rejection.code,
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controller/policy.ts — VC8B bounded policy engine (PURE).
|
|
3
|
+
*
|
|
4
|
+
* Three guarantees, all structural rather than conventional:
|
|
5
|
+
*
|
|
6
|
+
* 1. FINITE ACTIONS. `evaluatePolicy` can only ever return a member of
|
|
7
|
+
* POLICY_ACTIONS. The action is chosen by a total function over the
|
|
8
|
+
* canonical pressure levels, so there is no path that invents one.
|
|
9
|
+
* 2. BOUNDED BUDGETS. Every returned budget is clamped into
|
|
10
|
+
* `[minBudget, maxBudget]`. Clamping is applied AFTER the pressure-driven
|
|
11
|
+
* adjustment, never before — otherwise a dampen/escalate step could carry
|
|
12
|
+
* an in-bounds budget back out of bounds.
|
|
13
|
+
* 3. UNKNOWN PRESSURE REJECTS. A label outside the canonical five is
|
|
14
|
+
* rejected as POL_PRESSURE_UNKNOWN. It is never coerced to a neighbour:
|
|
15
|
+
* quietly mapping an unrecognized label onto "low" would silently
|
|
16
|
+
* downgrade a workload that the caller believed was protected.
|
|
17
|
+
*
|
|
18
|
+
* Everything here is PURE: no clock, no storage, no network, no flag read. The
|
|
19
|
+
* flag gates only the reporter seam in policy-emit.ts, which is why flag-off is
|
|
20
|
+
* byte-identical to the predecessor.
|
|
21
|
+
*
|
|
22
|
+
* PREVENT-002/011/PI-004 honored.
|
|
23
|
+
*/
|
|
24
|
+
import { POLICY_ACTIONS, POLICY_DECISION_SCHEMA_V1, POL_ACTION_FORBIDDEN, POL_BUDGET_OUT_OF_BOUNDS, POL_PRESSURE_UNKNOWN, PRESSURE_LEVELS, } from "./types.js";
|
|
25
|
+
/** Construct a policy failure. */
|
|
26
|
+
function fail(code) {
|
|
27
|
+
return { code };
|
|
28
|
+
}
|
|
29
|
+
/** Type guard: is this a canonical pressure level? */
|
|
30
|
+
export function isPressureLevel(label) {
|
|
31
|
+
return PRESSURE_LEVELS.includes(label);
|
|
32
|
+
}
|
|
33
|
+
/** Type guard: is this an allowed policy action? */
|
|
34
|
+
export function isPolicyAction(action) {
|
|
35
|
+
return POLICY_ACTIONS.includes(action);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate a pressure label against the canonical five. Throws
|
|
39
|
+
* `{ code: POL_PRESSURE_UNKNOWN }` rather than coercing — see the module note.
|
|
40
|
+
*/
|
|
41
|
+
export function validatePressureLabel(label) {
|
|
42
|
+
if (!isPressureLevel(label))
|
|
43
|
+
throw fail(POL_PRESSURE_UNKNOWN);
|
|
44
|
+
return label;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate an action against the allowed finite set. Throws
|
|
48
|
+
* `{ code: POL_ACTION_FORBIDDEN }` for anything else.
|
|
49
|
+
*/
|
|
50
|
+
export function validateAction(action) {
|
|
51
|
+
if (!isPolicyAction(action))
|
|
52
|
+
throw fail(POL_ACTION_FORBIDDEN);
|
|
53
|
+
return action;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate the bound pair itself. A window with min > max, or a non-finite
|
|
57
|
+
* bound, has no correct clamp result, so it is rejected rather than guessed at.
|
|
58
|
+
*/
|
|
59
|
+
export function validateBounds(bounds) {
|
|
60
|
+
const { minBudget, maxBudget } = bounds;
|
|
61
|
+
if (!Number.isFinite(minBudget) || !Number.isFinite(maxBudget)) {
|
|
62
|
+
throw fail(POL_BUDGET_OUT_OF_BOUNDS);
|
|
63
|
+
}
|
|
64
|
+
if (minBudget > maxBudget)
|
|
65
|
+
throw fail(POL_BUDGET_OUT_OF_BOUNDS);
|
|
66
|
+
if (minBudget < 0)
|
|
67
|
+
throw fail(POL_BUDGET_OUT_OF_BOUNDS);
|
|
68
|
+
return bounds;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clamp a budget into `[minBudget, maxBudget]`.
|
|
72
|
+
*
|
|
73
|
+
* A NaN budget clamps to `minBudget`: NaN comparisons are all false, so a naive
|
|
74
|
+
* Math.min/Math.max chain would propagate NaN straight through the "bounded"
|
|
75
|
+
* guarantee. The safest interpretation of an unusable request is the floor.
|
|
76
|
+
*/
|
|
77
|
+
export function clampBudget(budget, minBudget, maxBudget) {
|
|
78
|
+
validateBounds({ minBudget, maxBudget });
|
|
79
|
+
if (!Number.isFinite(budget))
|
|
80
|
+
return minBudget;
|
|
81
|
+
if (budget < minBudget)
|
|
82
|
+
return minBudget;
|
|
83
|
+
if (budget > maxBudget)
|
|
84
|
+
return maxBudget;
|
|
85
|
+
return budget;
|
|
86
|
+
}
|
|
87
|
+
/** The multiplier applied to the requested budget at each pressure level. */
|
|
88
|
+
const PRESSURE_FACTOR = {
|
|
89
|
+
low: 1,
|
|
90
|
+
medium: 1,
|
|
91
|
+
high: 0.75,
|
|
92
|
+
ultra: 0.5,
|
|
93
|
+
mega: 0.25,
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The action selected at each pressure level. Total over PressureLevel, so the
|
|
97
|
+
* action space cannot grow: `mega` refuses outright, `ultra` defers, `high`
|
|
98
|
+
* dampens, and the quiet levels admit.
|
|
99
|
+
*/
|
|
100
|
+
const PRESSURE_ACTION = {
|
|
101
|
+
low: "admit",
|
|
102
|
+
medium: "admit",
|
|
103
|
+
high: "dampen",
|
|
104
|
+
ultra: "defer",
|
|
105
|
+
mega: "reject",
|
|
106
|
+
};
|
|
107
|
+
/** Select the reason code that explains the decision. */
|
|
108
|
+
function reasonFor(pressure, requested, clamped, bounds) {
|
|
109
|
+
if (clamped === bounds.maxBudget && requested > bounds.maxBudget) {
|
|
110
|
+
return "budget_clamped_high";
|
|
111
|
+
}
|
|
112
|
+
if (clamped === bounds.minBudget && requested < bounds.minBudget) {
|
|
113
|
+
return "budget_clamped_low";
|
|
114
|
+
}
|
|
115
|
+
if (pressure === "mega" || pressure === "ultra")
|
|
116
|
+
return "pressure_critical";
|
|
117
|
+
if (pressure === "high")
|
|
118
|
+
return "pressure_elevated";
|
|
119
|
+
return "within_bounds";
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Evaluate one policy input into a bounded decision.
|
|
123
|
+
*
|
|
124
|
+
* Order matters: validate the label, validate the window, apply the
|
|
125
|
+
* pressure factor, THEN clamp. Clamping last is what makes the bounded-budget
|
|
126
|
+
* guarantee hold for every action including escalate.
|
|
127
|
+
*
|
|
128
|
+
* Throws `{ code }` on an unknown pressure label or an invalid bound pair.
|
|
129
|
+
*/
|
|
130
|
+
export function evaluatePolicy(input) {
|
|
131
|
+
const pressure = validatePressureLabel(input.pressure);
|
|
132
|
+
const bounds = validateBounds(input.bounds);
|
|
133
|
+
const requested = Number.isFinite(input.requestedBudget)
|
|
134
|
+
? input.requestedBudget
|
|
135
|
+
: bounds.minBudget;
|
|
136
|
+
const adjusted = requested * PRESSURE_FACTOR[pressure];
|
|
137
|
+
const budget = clampBudget(adjusted, bounds.minBudget, bounds.maxBudget);
|
|
138
|
+
return {
|
|
139
|
+
schema: POLICY_DECISION_SCHEMA_V1,
|
|
140
|
+
decisionId: input.decisionId,
|
|
141
|
+
sessionId: input.sessionId,
|
|
142
|
+
action: PRESSURE_ACTION[pressure],
|
|
143
|
+
budget,
|
|
144
|
+
pressure,
|
|
145
|
+
reason: reasonFor(pressure, input.requestedBudget, budget, bounds),
|
|
146
|
+
ts: input.ts,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Assert a decision satisfies the sprint invariant: allowed action AND bounded
|
|
151
|
+
* budget. Used by the acceptance aggregator to check every produced row.
|
|
152
|
+
*/
|
|
153
|
+
export function isDecisionWithinBounds(decision, bounds) {
|
|
154
|
+
return (isPolicyAction(decision.action) &&
|
|
155
|
+
Number.isFinite(decision.budget) &&
|
|
156
|
+
decision.budget >= bounds.minBudget &&
|
|
157
|
+
decision.budget <= bounds.maxBudget);
|
|
158
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controller/shadow.ts — VC8B shadow policy evaluator (PURE, READ-ONLY).
|
|
3
|
+
*
|
|
4
|
+
* The shadow engine runs the candidate policy alongside the live path so its
|
|
5
|
+
* decisions can be measured before they are trusted. That is only safe if the
|
|
6
|
+
* shadow is structurally incapable of affecting the live path, so this module
|
|
7
|
+
* takes the capability argument seriously:
|
|
8
|
+
*
|
|
9
|
+
* - NO RENDERER. It imports no renderer and returns no rendered bytes.
|
|
10
|
+
* - NO STORE WRITER. It imports no store and performs no write.
|
|
11
|
+
* - NO PROMPT MUTATION. It receives the canonical prompt as bytes it may only
|
|
12
|
+
* hash, and it re-hashes on exit to PROVE the bytes are unchanged
|
|
13
|
+
* (POL-SHADOW-002). `liveMutations` is reported and is always 0.
|
|
14
|
+
*
|
|
15
|
+
* INPUTS ARE COPIED, NOT BORROWED. Every input is deep-copied on entry, so even
|
|
16
|
+
* a future policy change that mutated its argument could not reach the caller's
|
|
17
|
+
* object. The copy is the enforcement; the `readonly` types are only the
|
|
18
|
+
* documentation of it. This is the difference between "we don't mutate" and
|
|
19
|
+
* "we cannot mutate".
|
|
20
|
+
*
|
|
21
|
+
* A rejected input does NOT abort the run: the shadow's job is measurement, so
|
|
22
|
+
* one unknown pressure label is recorded as a rejection code and the remaining
|
|
23
|
+
* inputs are still evaluated.
|
|
24
|
+
*
|
|
25
|
+
* PREVENT-002/011/PI-004 honored.
|
|
26
|
+
*/
|
|
27
|
+
import { createHash } from "node:crypto";
|
|
28
|
+
import { evaluatePolicy } from "./policy.js";
|
|
29
|
+
/** SHA-256 of the canonical prompt bytes, lowercase hex (VC5B convention). */
|
|
30
|
+
export function promptDigestOf(promptBytes) {
|
|
31
|
+
return createHash("sha256")
|
|
32
|
+
.update(Buffer.from(promptBytes, "utf8"))
|
|
33
|
+
.digest("hex");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Deep-copy one policy input. Explicit field-by-field construction rather than
|
|
37
|
+
* a structured clone: it keeps the copy total over the declared shape and makes
|
|
38
|
+
* an added field a compile error instead of a silently shared reference.
|
|
39
|
+
*/
|
|
40
|
+
export function copyPolicyInput(input) {
|
|
41
|
+
return {
|
|
42
|
+
decisionId: input.decisionId,
|
|
43
|
+
sessionId: input.sessionId,
|
|
44
|
+
pressure: input.pressure,
|
|
45
|
+
requestedBudget: input.requestedBudget,
|
|
46
|
+
bounds: {
|
|
47
|
+
minBudget: input.bounds.minBudget,
|
|
48
|
+
maxBudget: input.bounds.maxBudget,
|
|
49
|
+
},
|
|
50
|
+
ts: input.ts,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Extract the machine code from a thrown policy failure. */
|
|
54
|
+
function codeOf(err) {
|
|
55
|
+
if (typeof err === "object" && err !== null && "code" in err) {
|
|
56
|
+
const code = err.code;
|
|
57
|
+
if (typeof code === "string")
|
|
58
|
+
return code;
|
|
59
|
+
}
|
|
60
|
+
return "POL_UNKNOWN_FAILURE";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Evaluate a batch of policy inputs in shadow mode.
|
|
64
|
+
*
|
|
65
|
+
* Returns decisions + metrics ONLY. The caller receives no capability to apply
|
|
66
|
+
* any of it; promoting a shadow decision is a separate, explicit act.
|
|
67
|
+
*
|
|
68
|
+
* @param inputs the policy inputs to evaluate (copied, never mutated)
|
|
69
|
+
* @param promptBytes the canonical prompt, used ONLY to prove non-mutation
|
|
70
|
+
*/
|
|
71
|
+
export function evaluateShadow(inputs, promptBytes) {
|
|
72
|
+
// Hash the prompt BEFORE any evaluation so the exit comparison is meaningful.
|
|
73
|
+
const digestOnEntry = promptDigestOf(promptBytes);
|
|
74
|
+
// Copy every input up front: nothing downstream ever sees the caller's object.
|
|
75
|
+
const copies = inputs.map(copyPolicyInput);
|
|
76
|
+
const decisions = [];
|
|
77
|
+
const rejections = [];
|
|
78
|
+
let clamped = 0;
|
|
79
|
+
for (const copy of copies) {
|
|
80
|
+
try {
|
|
81
|
+
const decision = evaluatePolicy(copy);
|
|
82
|
+
decisions.push(decision);
|
|
83
|
+
const atBound = decision.reason === "budget_clamped_low" ||
|
|
84
|
+
decision.reason === "budget_clamped_high";
|
|
85
|
+
if (atBound)
|
|
86
|
+
clamped += 1;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
// Measurement continues: one bad row must not blind the whole run.
|
|
90
|
+
rejections.push({ decisionId: copy.decisionId, code: codeOf(err) });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Re-hash on exit. Equality here is the POL-SHADOW-002 proof that the shadow
|
|
94
|
+
// left the canonical prompt untouched.
|
|
95
|
+
const digestOnExit = promptDigestOf(promptBytes);
|
|
96
|
+
const promptUnchanged = digestOnEntry === digestOnExit;
|
|
97
|
+
return {
|
|
98
|
+
decisions,
|
|
99
|
+
rejections,
|
|
100
|
+
metrics: {
|
|
101
|
+
evaluated: decisions.length,
|
|
102
|
+
clamped,
|
|
103
|
+
rejected: rejections.length,
|
|
104
|
+
// Structurally zero: this module holds no writer capability. If the
|
|
105
|
+
// prompt digest ever moved, that is a live mutation and it is counted.
|
|
106
|
+
liveMutations: promptUnchanged ? 0 : 1,
|
|
107
|
+
},
|
|
108
|
+
promptDigest: digestOnExit,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Assert the shadow result carries no live mutation. The sprint's acceptance
|
|
113
|
+
* bar is "shadow live mutation count zero"; this is that check as a function.
|
|
114
|
+
*/
|
|
115
|
+
export function isShadowClean(result) {
|
|
116
|
+
return result.metrics.liveMutations === 0;
|
|
117
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controller/types.ts — VC8B policy decision + pressure type definitions.
|
|
3
|
+
*
|
|
4
|
+
* PolicyDecisionV1 is the FINITE, BOUNDED output of the policy engine: one of a
|
|
5
|
+
* closed action set, a token budget clamped into a configured window, and a
|
|
6
|
+
* machine code reason. There is deliberately no free-text field and no open
|
|
7
|
+
* action string — an adaptive policy whose action space can grow at runtime
|
|
8
|
+
* cannot be reviewed, and a budget with no ceiling is a cost incident waiting
|
|
9
|
+
* to happen.
|
|
10
|
+
*
|
|
11
|
+
* PressureV2 canonicalizes the context-pressure label to EXACTLY five levels
|
|
12
|
+
* (low/medium/high/ultra/mega). Anything else is rejected rather than coerced:
|
|
13
|
+
* silently mapping an unrecognized legacy label onto a neighbouring level is
|
|
14
|
+
* how a "high" workload quietly starts being treated as "low".
|
|
15
|
+
*
|
|
16
|
+
* Conformance IDs POL-001..025 and M7-001..015 are registered here as the
|
|
17
|
+
* single source of truth for the sprint's conformance rows.
|
|
18
|
+
*
|
|
19
|
+
* PREVENT-PI-004: type definitions only, no network code.
|
|
20
|
+
* PREVENT-011: no `any` type.
|
|
21
|
+
*/
|
|
22
|
+
/** Schema version for PolicyDecisionV1. */
|
|
23
|
+
export const POLICY_DECISION_SCHEMA_V1 = "policy-decision-v1";
|
|
24
|
+
/** Schema version for PressureV2. */
|
|
25
|
+
export const PRESSURE_SCHEMA_V2 = "pressure-v2";
|
|
26
|
+
/** Failure code when a pressure label is outside the canonical five levels. */
|
|
27
|
+
export const POL_PRESSURE_UNKNOWN = "POL_PRESSURE_UNKNOWN";
|
|
28
|
+
/** Failure code when a requested action is outside the allowed finite set. */
|
|
29
|
+
export const POL_ACTION_FORBIDDEN = "POL_ACTION_FORBIDDEN";
|
|
30
|
+
/** Failure code when a budget bound pair is itself invalid (min > max, NaN). */
|
|
31
|
+
export const POL_BUDGET_OUT_OF_BOUNDS = "POL_BUDGET_OUT_OF_BOUNDS";
|
|
32
|
+
/** Failure code when the M7 migration meets a non-canonical pressure label. */
|
|
33
|
+
export const M7_PRESSURE_UNKNOWN = "M7_PRESSURE_UNKNOWN";
|
|
34
|
+
/** Failure code when M7 copied rows do not match the legacy row count. */
|
|
35
|
+
export const M7_COUNT_MISMATCH = "M7_COUNT_MISMATCH";
|
|
36
|
+
/** Failure code when an M7 row digest does not re-derive from its own fields. */
|
|
37
|
+
export const M7_DIGEST_MISMATCH = "M7_DIGEST_MISMATCH";
|
|
38
|
+
/** Failure code when the active pressure pointer is not on the legacy version. */
|
|
39
|
+
export const M7_NOT_ON_LEGACY = "M7_NOT_ON_LEGACY";
|
|
40
|
+
/**
|
|
41
|
+
* The canonical five pressure levels. Ordered low -> mega; the order is
|
|
42
|
+
* meaningful (policy escalates monotonically with pressure) so it is exported
|
|
43
|
+
* as an array, not just a union.
|
|
44
|
+
*/
|
|
45
|
+
export const PRESSURE_LEVELS = [
|
|
46
|
+
"low",
|
|
47
|
+
"medium",
|
|
48
|
+
"high",
|
|
49
|
+
"ultra",
|
|
50
|
+
"mega",
|
|
51
|
+
];
|
|
52
|
+
/**
|
|
53
|
+
* The FINITE allowed policy action set. A decision may carry no other action.
|
|
54
|
+
* `admit` — proceed at the requested budget.
|
|
55
|
+
* `dampen` — proceed at a reduced budget (pressure is elevated).
|
|
56
|
+
* `defer` — postpone the work to a later turn.
|
|
57
|
+
* `escalate` — raise the budget within bounds (headroom is available).
|
|
58
|
+
* `reject` — refuse the work outright.
|
|
59
|
+
*/
|
|
60
|
+
export const POLICY_ACTIONS = [
|
|
61
|
+
"admit",
|
|
62
|
+
"dampen",
|
|
63
|
+
"defer",
|
|
64
|
+
"escalate",
|
|
65
|
+
"reject",
|
|
66
|
+
];
|
|
67
|
+
/** Machine reason codes — never free-text. */
|
|
68
|
+
export const POLICY_REASONS = [
|
|
69
|
+
"within_bounds",
|
|
70
|
+
"budget_clamped_low",
|
|
71
|
+
"budget_clamped_high",
|
|
72
|
+
"pressure_elevated",
|
|
73
|
+
"pressure_critical",
|
|
74
|
+
"headroom_available",
|
|
75
|
+
];
|
|
76
|
+
/** Conformance IDs POL-001..POL-025 for the 25 numbered policy rows. */
|
|
77
|
+
export const POLICY_CONFORMANCE_IDS = Array.from({ length: 25 }, (_v, i) => `POL-${String(i + 1).padStart(3, "0")}`);
|
|
78
|
+
/** Conformance IDs M7-001..M7-015 for the 15 numbered migration rows. */
|
|
79
|
+
export const M7_CONFORMANCE_IDS = Array.from({ length: 15 }, (_v, i) => `M7-${String(i + 1).padStart(3, "0")}`);
|
|
80
|
+
/** Named conformance fixtures for the sprint's headline assertions. */
|
|
81
|
+
export const POLICY_NAMED_FIXTURES = [
|
|
82
|
+
"POL-CLAMP-001",
|
|
83
|
+
"POL-SHADOW-002",
|
|
84
|
+
"M7-PRESSURE-003",
|
|
85
|
+
];
|