pi-mega-compact 0.20.41 → 0.20.43

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.
Files changed (112) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -1
  2. package/dist/config/vector-cortex-dedup-attr.js +14 -0
  3. package/dist/config/vector-cortex-enc0a.js +32 -0
  4. package/dist/config/vector-cortex.js +3 -3
  5. package/dist/config.js +1 -1
  6. package/dist/extensions/dashboard-server/api-contracts/dedup-attribution.js +13 -0
  7. package/dist/extensions/dashboard-server/api-contracts/endpoints/registry-ext.js +7 -0
  8. package/dist/extensions/dashboard-server/route-dispatch.js +3 -1
  9. package/dist/extensions/dashboard-server/routes-dedup-attribution.js +150 -0
  10. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
  11. package/dist/extensions/dashboard-server/routes.js +1 -0
  12. package/dist/src/config/vector-cortex-dedup-attr.js +14 -0
  13. package/dist/src/config/vector-cortex-enc0a.js +32 -0
  14. package/dist/src/config/vector-cortex.js +3 -3
  15. package/dist/src/config.js +1 -1
  16. package/dist/src/vector-cortex/_acceptance-enc0a-contract.js +60 -0
  17. package/dist/src/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
  18. package/dist/src/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
  19. package/dist/src/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
  20. package/dist/src/vector-cortex/_acceptance-vc2b-heads.js +221 -0
  21. package/dist/src/vector-cortex/dedup-attr/rollup.js +97 -0
  22. package/dist/src/vector-cortex/encoder/asset.js +3 -2
  23. package/dist/src/vector-cortex/encoder/decision.js +75 -0
  24. package/dist/src/vector-cortex/encoder/types-vc2c.js +41 -0
  25. package/dist/src/vector-cortex/encoder/types.js +13 -34
  26. package/dist/vector-cortex/_acceptance-enc0a-contract.js +60 -0
  27. package/dist/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
  28. package/dist/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
  29. package/dist/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
  30. package/dist/vector-cortex/_acceptance-vc2b-heads.js +221 -0
  31. package/dist/vector-cortex/dedup-attr/rollup.js +97 -0
  32. package/dist/vector-cortex/encoder/asset.js +3 -2
  33. package/dist/vector-cortex/encoder/decision.js +75 -0
  34. package/dist/vector-cortex/encoder/types-vc2c.js +41 -0
  35. package/dist/vector-cortex/encoder/types.js +13 -34
  36. package/extensions/dashboard-client/dist/assets/{AreaChart-BT7YPcp7.js → AreaChart-Cn6X7epL.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{AreaChart-BT7YPcp7.js.map → AreaChart-Cn6X7epL.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{BarChart-DceGcBUh.js → BarChart-APy1Wc7z.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{BarChart-DceGcBUh.js.map → BarChart-APy1Wc7z.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{CacheTab-B9lCouRl.js → CacheTab-CEv_Ss9O.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{CacheTab-B9lCouRl.js.map → CacheTab-CEv_Ss9O.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{EventsTab-oqJ11jY7.js → EventsTab-8jV1Pr0C.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{EventsTab-oqJ11jY7.js.map → EventsTab-8jV1Pr0C.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{HealthTab-Dbosf2Ik.js → HealthTab-B2VgEz1j.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{HealthTab-Dbosf2Ik.js.map → HealthTab-B2VgEz1j.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-6TiApCVE.js → MaintenanceTab-m37AlTbg.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-6TiApCVE.js.map → MaintenanceTab-m37AlTbg.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-cBsE4mTf.js → MemoryMapTab-Co2jbqdT.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-cBsE4mTf.js.map → MemoryMapTab-Co2jbqdT.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{MetricsTab-CX-X9hhy.js → MetricsTab-D0yV9X6D.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{MetricsTab-CX-X9hhy.js.map → MetricsTab-D0yV9X6D.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{OverviewTab-CpPYaTJF.js → OverviewTab-J5TjXB14.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{OverviewTab-CpPYaTJF.js.map → OverviewTab-J5TjXB14.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{ReposTab-D_Ot4QbU.js → ReposTab-BadNIkWu.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{ReposTab-D_Ot4QbU.js.map → ReposTab-BadNIkWu.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{SessionsTab-BUzO3iGK.js → SessionsTab-CdKShJuR.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{SessionsTab-BUzO3iGK.js.map → SessionsTab-CdKShJuR.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{SetupTab-Be4w9v4j.js → SetupTab-CPemizDx.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{SetupTab-Be4w9v4j.js.map → SetupTab-CPemizDx.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cx-g6CXH.js → TimeSavedCard-TvULibwW.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cx-g6CXH.js.map → TimeSavedCard-TvULibwW.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/{TurnsTab-CC_7T7ad.js → TurnsTab-CglFIcYy.js} +2 -2
  63. package/extensions/dashboard-client/dist/assets/{TurnsTab-CC_7T7ad.js.map → TurnsTab-CglFIcYy.js.map} +1 -1
  64. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-ZTItXSiH.js → VcStatusBadge-H2bBNhrR.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-ZTItXSiH.js.map → VcStatusBadge-H2bBNhrR.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-DgAUZ4Pg.js → VectorCortexTab-CXPv3sYQ.js} +2 -2
  67. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-DgAUZ4Pg.js.map → VectorCortexTab-CXPv3sYQ.js.map} +1 -1
  68. package/extensions/dashboard-client/dist/assets/{WikiTab-DnKupXTv.js → WikiTab-BNfN175_.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{WikiTab-DnKupXTv.js.map → WikiTab-BNfN175_.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/assets/{button-CFt3e0yc.js → button-DjN7aqD2.js} +2 -2
  71. package/extensions/dashboard-client/dist/assets/{button-CFt3e0yc.js.map → button-DjN7aqD2.js.map} +1 -1
  72. package/extensions/dashboard-client/dist/assets/{card-C6ZjsHrl.js → card-DLHA5XP8.js} +2 -2
  73. package/extensions/dashboard-client/dist/assets/{card-C6ZjsHrl.js.map → card-DLHA5XP8.js.map} +1 -1
  74. package/extensions/dashboard-client/dist/assets/{client-extra-DdEdGTIe.js → client-extra-ZT6mIQZS.js} +2 -2
  75. package/extensions/dashboard-client/dist/assets/{client-extra-DdEdGTIe.js.map → client-extra-ZT6mIQZS.js.map} +1 -1
  76. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-C9_fu2hc.js → generateCategoricalChart-DAl4dRVG.js} +2 -2
  77. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-C9_fu2hc.js.map → generateCategoricalChart-DAl4dRVG.js.map} +1 -1
  78. package/extensions/dashboard-client/dist/assets/{index-DY81TY4f.js → index-H-sfROoW.js} +16 -16
  79. package/extensions/dashboard-client/dist/assets/index-H-sfROoW.js.map +1 -0
  80. package/extensions/dashboard-client/dist/assets/{switch-BOqa1d6x.js → switch-BCxvJYon.js} +2 -2
  81. package/extensions/dashboard-client/dist/assets/{switch-BOqa1d6x.js.map → switch-BCxvJYon.js.map} +1 -1
  82. package/extensions/dashboard-client/dist/assets/{toggle-DToFaIEd.js → toggle-DviUMYeg.js} +2 -2
  83. package/extensions/dashboard-client/dist/assets/{toggle-DToFaIEd.js.map → toggle-DviUMYeg.js.map} +1 -1
  84. package/extensions/dashboard-client/dist/assets/{useSSE-CZqkhU18.js → useSSE-DP2O8vHY.js} +2 -2
  85. package/extensions/dashboard-client/dist/assets/{useSSE-CZqkhU18.js.map → useSSE-DP2O8vHY.js.map} +1 -1
  86. package/extensions/dashboard-client/dist/index.html +1 -1
  87. package/extensions/dashboard-server/api-contracts/dedup-attribution.ts +69 -0
  88. package/extensions/dashboard-server/api-contracts/endpoints/registry-ext.ts +15 -0
  89. package/extensions/dashboard-server/api-contracts/index.ts +8 -0
  90. package/extensions/dashboard-server/route-dispatch.ts +2 -0
  91. package/extensions/dashboard-server/routes-dedup-attribution.ts +166 -0
  92. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
  93. package/extensions/dashboard-server/routes.ts +1 -0
  94. package/package.json +1 -1
  95. package/src/config/vector-cortex-dedup-attr.ts +16 -0
  96. package/src/config/vector-cortex-enc0a.ts +34 -0
  97. package/src/config/vector-cortex.ts +3 -3
  98. package/src/config.ts +2 -0
  99. package/src/vector-cortex/_acceptance-enc0a-contract.ts +71 -0
  100. package/src/vector-cortex/_acceptance-vc2a-conformance.ts +119 -0
  101. package/src/vector-cortex/_acceptance-vc2a-runtime.ts +300 -0
  102. package/src/vector-cortex/_acceptance-vc2b-conformance.ts +121 -0
  103. package/src/vector-cortex/_acceptance-vc2b-heads.ts +234 -0
  104. package/src/vector-cortex/dedup-attr/rollup.ts +136 -0
  105. package/src/vector-cortex/encoder/asset.ts +3 -2
  106. package/src/vector-cortex/encoder/bench-export.ts +2 -2
  107. package/src/vector-cortex/encoder/decision.ts +125 -0
  108. package/src/vector-cortex/encoder/runtime-native.ts +1 -1
  109. package/src/vector-cortex/encoder/runtime-wasm.ts +1 -1
  110. package/src/vector-cortex/encoder/types-vc2c.ts +124 -0
  111. package/src/vector-cortex/encoder/types.ts +18 -115
  112. package/extensions/dashboard-client/dist/assets/index-DY81TY4f.js.map +0 -1
@@ -0,0 +1,166 @@
1
+ /**
2
+ * dashboard-server/routes-dedup-attribution.ts — DEDUP-ATTR tier attribution route.
3
+ *
4
+ * GET /api/dedup-tier-attribution?windowMs=<n> — reader-only aggregate answering
5
+ * "L0/L1/L2/new percent of dedup decisions in window W". Reads the repo's local
6
+ * events.log (per-repo stateDir, bounded 8 MiB tail), parses `dedup_audit` lines
7
+ * (PREVENT-001 guarded), and sends the pure rollup with a shared-derived status.
8
+ *
9
+ * Flag-off (MEGACOMPACT_DEDUP_ATTR=0) returns 404 and writes NO durable cache
10
+ * file — byte-identical predecessor. Reader-only: emits tier counts + shares,
11
+ * never matched checkpoint paths/text, never raw user query (EVAL-REDACT-002).
12
+ *
13
+ * Memoization mirrors routes-vector-cortex-health.ts: an in-memory facts cache
14
+ * keyed on {events.log mtime+size, windowMs} is served when ≤5s old, so repeated
15
+ * dashboard polls stay cheap while any on-disk log mutation still invalidates.
16
+ *
17
+ * Guardrails: PREVENT-PI-004 (local filesystem read + loopback response only),
18
+ * PREVENT-001 (JSON.parse guarded), PREVENT-011 (no `any`).
19
+ */
20
+
21
+ import type { IncomingMessage, ServerResponse } from "node:http";
22
+ import { readFileSync, statSync, writeFileSync, mkdirSync } from "node:fs";
23
+ import { join, dirname } from "node:path";
24
+
25
+ import type { RouteContext } from "./routes-core.js";
26
+ import { sendJson } from "./routes-vector-cortex-shared.js";
27
+ import { DEDUP_ATTR_ENABLED } from "../../src/config.js";
28
+ import { computeDedupTierRollup } from "../../src/vector-cortex/dedup-attr/rollup.js";
29
+ import type { DedupTierAttributionResponse } from "./api-contracts/dedup-attribution.js";
30
+ import type { DedupAuditEvent } from "../../src/vectorStore/dedup-audit.js";
31
+ import { deriveVcStatus } from "./vc-status.js";
32
+
33
+ const DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000; // 24h
34
+ const MAX_WINDOW_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
35
+ const MAX_TAIL_BYTES = 8 * 1024 * 1024; // 8 MiB
36
+ const MEMO_TTL_MS = 5000; // ≤5s per stateDir
37
+
38
+ interface MemoEntry {
39
+ key: string;
40
+ at: number;
41
+ body: DedupTierAttributionResponse;
42
+ }
43
+
44
+ let memo: MemoEntry | null = null;
45
+
46
+ /** Parse one events.log line into a DedupAuditEvent, or null (PREVENT-001). */
47
+ function parseAuditLine(line: string): DedupAuditEvent | null {
48
+ if (!line.includes('"dedup_audit"')) return null;
49
+ let parsed: unknown;
50
+ try {
51
+ parsed = JSON.parse(line);
52
+ } catch {
53
+ return null;
54
+ }
55
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
56
+ const obj = parsed as Record<string, unknown>;
57
+ if (obj.type !== "dedup_audit") return null;
58
+ if (typeof obj.ts !== "string") return null;
59
+ const tier = obj.tier;
60
+ const status = obj.status;
61
+ if (tier !== "L0" && tier !== "L1" && tier !== "L2" && tier !== "new") return null;
62
+ if (status !== "deduped" && status !== "passed" && status !== "stored") return null;
63
+ // sessionId is never read by the rollup; a parsed line may omit richer fields.
64
+ return { type: "dedup_audit", ts: obj.ts, tier, status, sessionId: "" };
65
+ }
66
+
67
+ /** Read the bounded tail of events.log into parsed dedup_audit events. */
68
+ function readAuditEvents(eventsPath: string): DedupAuditEvent[] {
69
+ let buf: Buffer;
70
+ try {
71
+ buf = readFileSync(eventsPath); // guardrails-allow PREVENT-PI-004: local events.log read (loopback dashboard)
72
+ } catch {
73
+ return [];
74
+ }
75
+ const tail = buf.length > MAX_TAIL_BYTES ? buf.subarray(buf.length - MAX_TAIL_BYTES) : buf;
76
+ const text = tail.toString("utf-8");
77
+ const lines = text.split("\n");
78
+ // Drop a leading fragment when we truncated mid-line (first line may be partial).
79
+ const start = buf.length > MAX_TAIL_BYTES ? 1 : 0;
80
+ const out: DedupAuditEvent[] = [];
81
+ for (let i = start; i < lines.length; i++) {
82
+ const line = lines[i];
83
+ if (!line) continue;
84
+ const ev = parseAuditLine(line);
85
+ if (ev) out.push(ev);
86
+ }
87
+ return out;
88
+ }
89
+
90
+ /** Resolve windowMs from the ?windowMs= query param (default 24h, capped 30d). */
91
+ function resolveWindowMs(url: string): number {
92
+ if (!url.includes("?")) return DEFAULT_WINDOW_MS;
93
+ const params = new URLSearchParams(url.slice(url.indexOf("?")));
94
+ const raw = params.get("windowMs");
95
+ if (raw == null) return DEFAULT_WINDOW_MS;
96
+ const n = Number(raw);
97
+ if (!Number.isFinite(n) || n <= 0) return DEFAULT_WINDOW_MS;
98
+ return Math.min(n, MAX_WINDOW_MS);
99
+ }
100
+
101
+ /** Best-effort durable snapshot write (never breaks the response). */
102
+ function writeDurableSnapshot(stateDir: string, rollup: DedupTierAttributionResponse): void {
103
+ try {
104
+ mkdirSync(dirname(join(stateDir, "dedup-tier-attribution.json")), { recursive: true });
105
+ writeFileSync(
106
+ join(stateDir, "dedup-tier-attribution.json"),
107
+ `${JSON.stringify(rollup)}\n`,
108
+ "utf-8",
109
+ );
110
+ } catch {
111
+ /* best-effort — instrumentation must never break the read path */
112
+ }
113
+ }
114
+
115
+ export function handleDedupTierAttribution(
116
+ req: IncomingMessage,
117
+ res: ServerResponse,
118
+ ctx: RouteContext,
119
+ ): boolean {
120
+ const url = req.url ?? "";
121
+ const path = url.split("?", 1)[0] ?? url;
122
+ if (path !== "/api/dedup-tier-attribution") return false;
123
+ if (req.method !== "GET") {
124
+ sendJson(res, 405, { error: "method_not_allowed" });
125
+ return true;
126
+ }
127
+ if (!DEDUP_ATTR_ENABLED()) {
128
+ // Flag-off: 404 + no durable cache write — byte-identical predecessor.
129
+ sendJson(res, 404, { error: "not_found" });
130
+ return true;
131
+ }
132
+
133
+ const eventsPath = ctx.eventsPath;
134
+ const windowMs = resolveWindowMs(url);
135
+ const now = new Date();
136
+
137
+ // Memoized-facts pattern (mirrors routes-vector-cortex-health.ts): serve a
138
+ // still-fresh entry keyed on {events.log mtime+size, windowMs}.
139
+ let keyBase: { mtimeMs: number; size: number } | null = null;
140
+ try {
141
+ const s = statSync(eventsPath); // guardrails-allow PREVENT-PI-004: local events.log stat (loopback)
142
+ keyBase = { mtimeMs: s.mtimeMs, size: s.size };
143
+ } catch {
144
+ keyBase = { mtimeMs: 0, size: 0 };
145
+ }
146
+ const key = `${keyBase.mtimeMs}:${keyBase.size}:${windowMs}`;
147
+ if (memo !== null && memo.key === key && now.getTime() - memo.at <= MEMO_TTL_MS) {
148
+ sendJson(res, 200, memo.body);
149
+ return true;
150
+ }
151
+
152
+ const auditEvents = readAuditEvents(eventsPath);
153
+ const rollup = computeDedupTierRollup(auditEvents, windowMs, now);
154
+ const status = deriveVcStatus({
155
+ enabled: true,
156
+ hasData: auditEvents.length > 0,
157
+ structuralOnly: false,
158
+ });
159
+ const body: DedupTierAttributionResponse = { ...rollup, status };
160
+
161
+ memo = { key, at: now.getTime(), body };
162
+ writeDurableSnapshot(ctx.stateDir, body);
163
+
164
+ sendJson(res, 200, body);
165
+ return true;
166
+ }
@@ -246,5 +246,17 @@ export const VECTOR_CORTEX_SETTINGS: SettingGroup = {
246
246
  "ML5-E nightly retraining + feedback loop: the user's own post-redaction conversation turns become fresh training signal, the five heads are re-fit nightly via system cron, calibration is re-validated, and mode-A promotion is re-checked without human intervention. The cron is system-configured (crontab -e); the extension never installs or writes a crontab. Candidates are written to ~/.pi/mega-compact-encoder/candidates/ and promoted via the ML5-D Improve Cortex flow. ON (default) = the scripts may be invoked by the system cron. OFF = scripts are never invoked; byte-identical to ML5-D.",
247
247
  true,
248
248
  ),
249
+ boolDirect(
250
+ "MEGACOMPACT_DEDUP_ATTR",
251
+ "Dedup Tier Attribution Rollup",
252
+ "Dedup tier-attribution rollup: per-tier dedup catch shares (L0/L1/L2/new percent of dedup decisions) read from the local events.log dedup_audit stream (GET /api/dedup-tier-attribution). OFF = 404 + no cache file, byte-identical predecessor.",
253
+ true,
254
+ ),
255
+ boolDirect(
256
+ "MEGACOMPACT_ENC_0A",
257
+ "ENC-0a Encoder Backend Decision",
258
+ "ENC-0a learned-encoder backend-decision lock: records the transformers.js/WASM vs onnxruntime-node choice, per-platform install matrix, opset-21 baseline and pinned digests in docs/vector-cortex/encoder-backend-decision.md. OFF = no decision record written / no resolver runs, mode B trigram byte-identical predecessor.",
259
+ true,
260
+ ),
249
261
  ],
250
262
  };
@@ -66,3 +66,4 @@ export {
66
66
  handleImproveCortex,
67
67
  handleImproveCortexStatus,
68
68
  } from "./routes-cortex-improve.js";
69
+ export { handleDedupTierAttribution } from "./routes-dedup-attribution.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.41",
3
+ "version": "0.20.43",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -0,0 +1,16 @@
1
+ /**
2
+ * config/vector-cortex-dedup-attr.ts — DEDUP-ATTR tier-attribution flag.
3
+ *
4
+ * The single positive sprint flag for the dedup tier-attribution rollup
5
+ * (external-audit item #6). Default ON; `MEGACOMPACT_DEDUP_ATTR=0` / `=false` /
6
+ * `_DISABLED=true` disables and is byte-identical to the predecessor: the
7
+ * `/api/dedup-tier-attribution` endpoint 404s and no rollup cache file is
8
+ * written.
9
+ *
10
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
11
+ */
12
+
13
+ import { sprintFlag } from "./vector-cortex-flag.js";
14
+
15
+ /** Positive sprint flag: `=0` or `_DISABLED=true` disables (default ON). */
16
+ export const DEDUP_ATTR_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_DEDUP_ATTR");
@@ -0,0 +1,34 @@
1
+ /**
2
+ * config/vector-cortex-enc0a.ts — ENC-0a learned-encoder backend-decision flag.
3
+ *
4
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
5
+ * limit (soft-as-hard gate), exactly as vector-cortex-vc9a.ts..vector-cortex-vc9d.ts
6
+ * were. This is the first ENC (real learned encoder) sprint flag. vector-cortex.ts
7
+ * re-exports the ENUM below and root src/config.ts re-exports it, so no consumer
8
+ * import path changes.
9
+ *
10
+ * ENC-0a locks the runtime-backend choice (transformers.js/WASM vs
11
+ * onnxruntime-node native), the per-platform install-size matrix, the opset
12
+ * baseline (re-baselined 17 -> 21) and the license/pinning audit. It writes a
13
+ * durable decision record and bench JSON but touches neither the store schema
14
+ * nor stateDir tables (pure migration).
15
+ *
16
+ * The split is purely mechanical: ENC_0A_ENABLED is byte-identical in name,
17
+ * semantics, and default to the definition it replaces, and vector-cortex.ts
18
+ * re-exports it so every existing `from "./config/vector-cortex.js"` import
19
+ * keeps resolving unchanged.
20
+ *
21
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
22
+ */
23
+
24
+ import { sprintFlag } from "./vector-cortex-flag.js";
25
+
26
+ /**
27
+ * ENC-0a — learned-encoder backend-decision lock. Default ON.
28
+ * `MEGACOMPACT_ENC_0A=0` disables and is byte-identical to the predecessor
29
+ * (placeholder encoder): no decision record is written and no newer
30
+ * backend-resolution script runs — the runtime keeps serving mode B trigram
31
+ * exactly as before. This flag MUST also be a dashboard SETTINGS toggle (visible
32
+ * in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC9D.
33
+ */
34
+ export const ENC_0A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_0A");
@@ -5,8 +5,7 @@
5
5
  * `=0`/`_DISABLED` off. Flag-OFF is byte-identical to the predecessor sprint's
6
6
  * behavior (for VC0A: mode C — observer absent, zero evaluation writes).
7
7
  *
8
- * The breaker/triad constants (TRIAD_RESILIENCE.md) live here so VC0C consumes
9
- * them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
8
+ * Breaker/triad constants (TRIAD_RESILIENCE.md) live here; pi-agnostic, dep-free.
10
9
  */
11
10
 
12
11
  import { sprintFlag } from "./vector-cortex-flag.js";
@@ -270,7 +269,6 @@ export const VC8B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC8B");
270
269
 
271
270
  // VC8C extracted to vector-cortex-vc8c.ts; re-exported so existing imports keep resolving.
272
271
  export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
273
- // Sibling extracts: stay under the 300-line soft limit.
274
272
  export { VC9A_ENABLED } from "./vector-cortex-vc9a.js";
275
273
  export { VC9B_ENABLED } from "./vector-cortex-vc9b.js";
276
274
  export { VC9C_ENABLED } from "./vector-cortex-vc9c.js";
@@ -281,6 +279,8 @@ export { ML5B_ENABLED } from "./vector-cortex-ml5b.js";
281
279
  export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
282
280
  export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
283
281
  export { ML5E_ENABLED } from "./vector-cortex-ml5e.js";
282
+ export { DEDUP_ATTR_ENABLED } from "./vector-cortex-dedup-attr.js";
283
+ export { ENC_0A_ENABLED } from "./vector-cortex-enc0a.js";
284
284
 
285
285
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
286
286
  export {
package/src/config.ts CHANGED
@@ -188,6 +188,8 @@ export {
188
188
  ML5C_ENABLED,
189
189
  ML5D_ENABLED,
190
190
  ML5E_ENABLED,
191
+ DEDUP_ATTR_ENABLED,
192
+ ENC_0A_ENABLED,
191
193
  BREAKER_WINDOW_MS,
192
194
  BREAKER_MIN_ATTEMPTS,
193
195
  BREAKER_PERF_FAILURES,
@@ -0,0 +1,71 @@
1
+ /** ENC-0a buildDecision contract constructor suite — extracted from
2
+ * enc0a-acceptance.test.ts for soft-limit compliance. Receives the contract
3
+ * constructor + constants from the aggregator (no import cycle).
4
+ */
5
+ import { test, describe } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import type { EncoderPlatformRow } from "./encoder/decision.js";
8
+
9
+ export interface Enc0aContractCtx {
10
+ buildDecision: typeof import("./encoder/decision.js").buildDecision;
11
+ PLATFORMS: readonly ["linux-x64", "linux-arm64", "darwin-x64", "darwin-arm64", "win32-x64"];
12
+ }
13
+
14
+ export function registerEnc0aContract(ctx: Enc0aContractCtx): void {
15
+ const { buildDecision, PLATFORMS } = ctx;
16
+
17
+ describe("buildDecision contract constructor", () => {
18
+ test("rejects an incomplete platform matrix", () => {
19
+ const matrix = {
20
+ "linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
21
+ "linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
22
+ "darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
23
+ "darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
24
+ // win32-x64 omitted
25
+ } as Record<(typeof PLATFORMS)[number], EncoderPlatformRow>;
26
+ assert.throws(() =>
27
+ buildDecision({
28
+ backend: "wasm",
29
+ budgetOk: true,
30
+ p95Ms: 18.2,
31
+ platformMatrix: matrix,
32
+ modelPath: "model.onnx",
33
+ modelBytes: 1,
34
+ modelSha256: "a".repeat(64),
35
+ tokenizerPath: "tokenizer.json",
36
+ tokenizerBytes: 1,
37
+ tokenizerSha256: "b".repeat(64),
38
+ blockedBy: [],
39
+ }),
40
+ );
41
+ });
42
+
43
+ test("builds a valid decision with opset 21 + MIT license for a complete matrix", () => {
44
+ const matrix = {
45
+ "linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
46
+ "linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
47
+ "darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
48
+ "darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
49
+ "win32-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
50
+ } as Record<(typeof PLATFORMS)[number], EncoderPlatformRow>;
51
+ const d = buildDecision({
52
+ backend: "wasm",
53
+ budgetOk: true,
54
+ p95Ms: 18.2,
55
+ platformMatrix: matrix,
56
+ modelPath: "model.onnx",
57
+ modelBytes: 24117248,
58
+ modelSha256: "a".repeat(64),
59
+ tokenizerPath: "tokenizer.json",
60
+ tokenizerBytes: 50000,
61
+ tokenizerSha256: "b".repeat(64),
62
+ blockedBy: [],
63
+ });
64
+ assert.equal(d.schema, "encoder-backend-decision-v1");
65
+ assert.equal(d.opset, 21);
66
+ assert.equal(d.backend, "wasm");
67
+ assert.deepEqual(d.license, { spdx: "MIT", redistribution: true });
68
+ assert.equal(d.platformMatrix["darwin-x64"].demotion, "wasm");
69
+ });
70
+ });
71
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * _acceptance-vc2a-conformance.ts — ENC-001..008 conformance rows + the named
3
+ * assertions (ENC-ASSET-001 / ENC-DIGEST-002 / ENC-PLATFORM-003), each driven
4
+ * through the REAL encoder asset/runtime (no mocks). Extracted from
5
+ * vc2a-acceptance.test.ts so the aggregator stays under the tests/ soft limit.
6
+ *
7
+ * The aggregator passes its shared imports/helpers as a context object, so this
8
+ * sibling never imports the aggregator (no import cycle at module load).
9
+ */
10
+ import { test, describe } from "node:test";
11
+ import assert from "node:assert/strict";
12
+ import type { EncoderLoadResult } from "./encoder/types.js";
13
+
14
+ /** Context from the aggregator — only domain-specific helpers, not node:test/assert. */
15
+ export interface Vc2aConformanceCtx {
16
+ ENC_IDS: readonly string[];
17
+ ENC_FAIL: typeof import("./encoder/types.js").ENC_FAIL;
18
+ fixture: (id: string) => {
19
+ id: string;
20
+ input: { scenario: string };
21
+ expected: { ok: boolean; code?: string; mode?: string };
22
+ };
23
+ buildDir: (scenario: string) => Built;
24
+ rmBuilt: (b: Built) => void;
25
+ optionsFor: (scenario: string) => import("./encoder/runtime.js").CreateEncoderRuntimeOptions;
26
+ createEncoderRuntime: typeof import("./encoder/runtime.js").createEncoderRuntime;
27
+ verifyEncoderAsset: typeof import("./encoder/asset.js").verifyEncoderAsset;
28
+ readEncoderManifest: typeof import("./encoder/asset.js").readEncoderManifest;
29
+ }
30
+
31
+ /* Structural stand-in for the aggregator's local `Built` (dir + scenario). */
32
+ interface Built {
33
+ dir: string;
34
+ scenario: string;
35
+ }
36
+
37
+ export function registerVc2aConformance(ctx: Vc2aConformanceCtx): void {
38
+ const {
39
+ ENC_IDS,
40
+ ENC_FAIL,
41
+ fixture,
42
+ buildDir,
43
+ rmBuilt,
44
+ optionsFor,
45
+ createEncoderRuntime,
46
+ verifyEncoderAsset,
47
+ readEncoderManifest,
48
+ } = ctx;
49
+
50
+ // -------------------------------------------------------------------------
51
+ // ENC-001..008 conformance rows through the real runtime
52
+ // -------------------------------------------------------------------------
53
+ describe("ENC-001..008 conformance rows", () => {
54
+ for (const id of ENC_IDS) {
55
+ test(`${id}: resolves through the real runtime to the documented result`, () => {
56
+ const fx = fixture(id);
57
+ const built = buildDir(fx.input.scenario);
58
+ try {
59
+ const rt = createEncoderRuntime(optionsFor(fx.input.scenario));
60
+ const load: EncoderLoadResult = rt.load(built.dir);
61
+ assert.equal(load.ok, fx.expected.ok, `${id} ok`);
62
+ if (!load.ok) {
63
+ assert.equal(load.code, fx.expected.code, `${id} exact failure code`);
64
+ if (fx.expected.mode) assert.equal(load.mode, fx.expected.mode, `${id} mode`);
65
+ } else {
66
+ assert.equal(load.mode, "A", `${id} should be mode A`);
67
+ }
68
+ } finally {
69
+ rmBuilt(built);
70
+ }
71
+ });
72
+ }
73
+ });
74
+
75
+ // -------------------------------------------------------------------------
76
+ // VC2A named assertions
77
+ // -------------------------------------------------------------------------
78
+ describe("VC2A named assertions", () => {
79
+ test("ENC-ASSET-001: opset21 manifest + matching digests load as mode A", () => {
80
+ const fx = fixture("ENC-ASSET-001");
81
+ assert.equal(fx.expected.ok, true);
82
+ const built = buildDir("valid");
83
+ try {
84
+ const load = createEncoderRuntime().load(built.dir);
85
+ assert.equal(load.ok, true);
86
+ if (load.ok) assert.equal(load.mode, "A");
87
+ } finally {
88
+ rmBuilt(built);
89
+ }
90
+ });
91
+ test("ENC-DIGEST-002: one-byte model mutation demotes before load", () => {
92
+ const fx = fixture("ENC-DIGEST-002");
93
+ assert.equal(fx.expected.code, ENC_FAIL.DIGEST_MISMATCH);
94
+ const built = buildDir("mutate-onnx");
95
+ try {
96
+ const res = verifyEncoderAsset(built.dir, readEncoderManifest(built.dir));
97
+ assert.equal(res.ok, false);
98
+ if (!res.ok) assert.equal(res.code, ENC_FAIL.DIGEST_MISMATCH);
99
+ } finally {
100
+ rmBuilt(built);
101
+ }
102
+ });
103
+ test("ENC-PLATFORM-003: unsupported architecture selects trigram B", () => {
104
+ const fx = fixture("ENC-PLATFORM-003");
105
+ assert.equal(fx.expected.mode, "B");
106
+ const built = buildDir("valid");
107
+ try {
108
+ const load = createEncoderRuntime({ platform: () => null }).load(built.dir);
109
+ assert.equal(load.ok, false);
110
+ if (!load.ok) {
111
+ assert.equal(load.mode, "B", "trigram B selected");
112
+ assert.equal(load.code, ENC_FAIL.PLATFORM_UNSUPPORTED);
113
+ }
114
+ } finally {
115
+ rmBuilt(built);
116
+ }
117
+ });
118
+ });
119
+ }