pi-mega-compact 0.20.48 → 0.20.49

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 (26) hide show
  1. package/dist/config/vector-cortex-enc0g.js +37 -0
  2. package/dist/config/vector-cortex.js +1 -0
  3. package/dist/config.js +1 -1
  4. package/dist/extensions/dashboard-server/qualification-record.js +71 -0
  5. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
  6. package/dist/extensions/dashboard-server/routes-setup-cortex-actions.js +49 -3
  7. package/dist/extensions/dashboard-server/routes-setup-cortex.js +65 -16
  8. package/dist/extensions/dashboard-server/setup-cortex-actions.js +21 -4
  9. package/dist/extensions/dashboard-server/setup-cortex-blockers.js +3 -69
  10. package/dist/src/config/vector-cortex-enc0g.js +37 -0
  11. package/dist/src/config/vector-cortex.js +1 -0
  12. package/dist/src/config.js +1 -1
  13. package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  14. package/dist/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  15. package/extensions/dashboard-server/api-contracts/setup-cortex.ts +6 -2
  16. package/extensions/dashboard-server/qualification-record.ts +70 -0
  17. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  18. package/extensions/dashboard-server/routes-setup-cortex-actions.ts +50 -3
  19. package/extensions/dashboard-server/routes-setup-cortex.ts +92 -16
  20. package/extensions/dashboard-server/setup-cortex-actions.ts +23 -4
  21. package/extensions/dashboard-server/setup-cortex-blockers.ts +3 -97
  22. package/package.json +1 -1
  23. package/src/config/vector-cortex-enc0g.ts +39 -0
  24. package/src/config/vector-cortex.ts +1 -0
  25. package/src/config.ts +1 -0
  26. package/src/vector-cortex/setup-cortex-blockers-compute.ts +216 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * config/vector-cortex-enc0g.ts — ENC-0g Setup Cortex status route honest state.
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-enc0a.ts .. enc0f.ts and
6
+ * the VC8C/VC9A-D/ML5A-E/DEDUP_ATTR siblings were. vector-cortex.ts re-exports
7
+ * the flag below and root src/config.ts re-exports it, so no consumer import
8
+ * path changes.
9
+ *
10
+ * ENC-0g makes the Setup Cortex status route honest: the status route reads the
11
+ * latest ENC-0f `QualificationV1` record (when ENC_0F is ON and a record
12
+ * exists) and lets its verdict override the structural verifyEncoderAsset
13
+ * result for the `qualification` field; the blocker list becomes a pure
14
+ * computed function over (platform, qualification record, manifest head-count)
15
+ * with corrected HG statuses/wording; and VC9B action gating is re-derived from
16
+ * the live computed blockers instead of the stale static manifest.
17
+ *
18
+ * `MEGACOMPACT_ENC_0G=0` disables: the status route derives its `qualification`
19
+ * verdict from `verifyEncoderAsset(...).ok` alone, the blocker list is the
20
+ * static `SETUP_CORTEX_BLOCKERS` array exactly as ENC-0f-era, and action gating
21
+ * reads the static table as today — byte-identical to the predecessor. The flag
22
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
23
+ * EXCLUDED_SETTINGS).
24
+ *
25
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+ import { sprintFlag } from "./vector-cortex-flag.js";
28
+ /**
29
+ * ENC-0g — Setup Cortex status route honest state (verdict override + live
30
+ * blockers + re-derived gating). Default ON. `MEGACOMPACT_ENC_0G=0` disables
31
+ * and is byte-identical to the predecessor (ENC-0f): verdict from
32
+ * `verifyEncoderAsset` alone, static `SETUP_CORTEX_BLOCKERS`, static
33
+ * `setupCortexActionBlockers`. This flag MUST also be a dashboard SETTINGS
34
+ * toggle (visible in config UI, never in EXCLUDED_SETTINGS), mirroring
35
+ * ENC_0A/ENC_0B/ENC_0C/ENC_0D/ENC_0E/ENC_0F.
36
+ */
37
+ export const ENC_0G_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0G");
@@ -31,5 +31,6 @@ export { ENC_0C_ENABLED } from "./vector-cortex-enc0c.js";
31
31
  export { ENC_0D_ENABLED } from "./vector-cortex-enc0d.js";
32
32
  export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
33
33
  export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
34
+ export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
34
35
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
35
36
  export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
package/dist/config.js CHANGED
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -0,0 +1,71 @@
1
+ /**
2
+ * dashboard-server/qualification-record.ts — ENC-0g QualificationV1 reader.
3
+ *
4
+ * Read-only reader for the ENC-0f qualification record at
5
+ * <stateDir>/encoder-qualification.json. The computed-blocker + action-gating
6
+ * functions live in setup-cortex-blockers.ts (Worker A's canonical module).
7
+ *
8
+ * Reader-only: local filesystem read only (PREVENT-PI-004), no `any`
9
+ * (PREVENT-011), never payloads/prompts/ledger (EVAL-REDACT-002).
10
+ */
11
+ import { homedir } from "node:os";
12
+ import { readFileSync } from "node:fs";
13
+ import { join } from "node:path";
14
+ import { QUALIFICATION_RECORD_UNAVAILABLE } from "../../src/vector-cortex/setup-cortex-blockers-compute.js";
15
+ /** Sentinel appended to thresholdFailures when no valid record is readable (canonical def in setup-cortex-blockers-compute). */
16
+ export { QUALIFICATION_RECORD_UNAVAILABLE };
17
+ /**
18
+ * Resolve the encoder state dir (the record's home) — same precedence as
19
+ * scripts/encoder/gate-qualify.mjs: MEGACOMPACT_STATE_DIR first, else
20
+ * ~/.pi/mega-compact-encoder.
21
+ */
22
+ export function encoderStateDir() {
23
+ const env = process.env.MEGACOMPACT_STATE_DIR;
24
+ return env !== undefined && env.length > 0
25
+ ? env
26
+ : join(homedir(), ".pi", "mega-compact-encoder");
27
+ }
28
+ /**
29
+ * Read + minimally validate the QualificationV1 record. Returns null on a
30
+ * missing/unreadable file, a JSON parse failure, or a shape mismatch (the
31
+ * route degrades to verify-only — never crashes). Read-only (PREVENT-PI-004).
32
+ */
33
+ export function readQualificationRecord(stateDir) {
34
+ let raw;
35
+ try {
36
+ // guardrails-allow PREVENT-PI-004: local qualification-record filesystem read (loopback)
37
+ raw = readFileSync(join(stateDir, "encoder-qualification.json"), "utf8");
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ let parsed;
43
+ try {
44
+ parsed = JSON.parse(raw);
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ const rec = parsed;
50
+ if (rec === null || typeof rec !== "object")
51
+ return null;
52
+ if (rec["schema"] !== "qualification-v1")
53
+ return null;
54
+ if (typeof rec["verdict"] !== "string")
55
+ return null;
56
+ if (!Array.isArray(rec["reasons"]))
57
+ return null;
58
+ if (typeof rec["platform"] !== "string")
59
+ return null;
60
+ const reasons = rec["reasons"].map((r) => String(r));
61
+ return {
62
+ schema: "qualification-v1",
63
+ verdict: rec["verdict"] === "qualified" ? "qualified" : "failed",
64
+ reasons,
65
+ platform: rec["platform"],
66
+ p95Ms: typeof rec["p95Ms"] === "number" ? rec["p95Ms"] : 0,
67
+ rssMib: typeof rec["rssMib"] === "number" ? rec["rssMib"] : 0,
68
+ opset: typeof rec["opset"] === "number" ? rec["opset"] : 0,
69
+ digest: typeof rec["digest"] === "string" ? rec["digest"] : "",
70
+ };
71
+ }
@@ -64,5 +64,6 @@ export const VECTOR_CORTEX_SETTINGS = {
64
64
  boolDirect("MEGACOMPACT_ENC_0D", "ENC-0d Real-Asset Promotion Gate", "ENC-0d promotion gate over real trained assets: accepts a {color} real candidate manifest (the ENC-0c trained head weights + the ENC-0b trunk), digest-verifies every staged byte, and atomically swaps the shipped manifest to a green candidate with rollback-to-previous on qualification failure. OFF = accepts no candidate, swaps nothing, emits nothing, shipped manifest stays at the ENC-0c survivor.", true),
65
65
  boolDirect("MEGACOMPACT_ENC_0E", "ENC-0e darwin-x64 Demotion Reason", "ENC-0e darwin-x64 explicit demotion: on an Intel Mac the runtime demotes to WASM (no native binary upstream); this surfaces a deterministic reason on the runtime-selection event and the Setup Cortex blockers card so an operator sees why mode A is unreachable. OFF = no demotion reason on the event and no Setup card row (the ML5-C WASM demotion itself remains the default, byte-identical predecessor).", true),
66
66
  boolDirect("MEGACOMPACT_ENC_0F", "ENC-0f p95 + marginal-RSS Qualification Gate", "ENC-0f p95 + marginal-RSS qualification gate (real trained asset → mode A): runs the ENC-0d-promoted trained asset through the bench under --expose-gc, asserts p95 ≤ 40 ms @ 512/4 threads, marginal RSS ≤ 150 MiB (baseline-subtracted), determinism, and opset-21; on pass emits QualificationV1 + flips runtime to qualified mode A, on failure asset stays demoted to mode B. OFF = no qualification gate runs, no QualificationV1 written, runtime keeps serving the ENC-0d survivor (byte-identical predecessor).", true),
67
+ boolDirect("MEGACOMPACT_ENC_0G", "ENC-0g Setup Cortex honest state (verdict override + live blockers)", "ENC-0g makes the Setup Cortex status route honest: reads the ENC-0f QualificationV1 record (when ENC_0F is ON and a record exists) and lets its verdict override the structural verify for the qualification field; computes the blocker list from (platform, record, manifest head-count) with corrected HG statuses/wording; re-derives VC9B action gating from live blockers. OFF = verdict from verifyEncoderAsset alone, static SETUP_CORTEX_BLOCKERS, static action gating (byte-identical ENC-0f predecessor).", true),
67
68
  ],
68
69
  };
@@ -17,9 +17,14 @@
17
17
  * readJsonBody), no string literals for scripts/blockers (delegated to
18
18
  * setup-cortex-actions.ts + setup-cortex-blockers.ts).
19
19
  */
20
+ import { existsSync } from "node:fs";
21
+ import { join, dirname } from "node:path";
22
+ import { fileURLToPath } from "node:url";
20
23
  import { sendJson, readJsonBody } from "./routes-vector-cortex-shared.js";
21
- import { VC9B_ENABLED } from "../../src/config.js";
22
- import { setupCortexActionBlockers } from "./setup-cortex-blockers.js";
24
+ import { VC9B_ENABLED, ENC_0G_ENABLED, ENC_0F_ENABLED } from "../../src/config.js";
25
+ import { setupCortexActionBlockers, computeSetupCortexBlockers } from "./setup-cortex-blockers.js";
26
+ import { readEncoderManifest, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
27
+ import { readQualificationRecord, encoderStateDir, } from "./qualification-record.js";
23
28
  import { runSetupCortexAction, readActionLogTail, } from "./setup-cortex-actions.js";
24
29
  const ACTION_KINDS = new Set([
25
30
  "fetch-model",
@@ -29,6 +34,44 @@ const ACTION_KINDS = new Set([
29
34
  function isActionKind(v) {
30
35
  return typeof v === "string" && ACTION_KINDS.has(v);
31
36
  }
37
+ /** The encoder asset dir used by the action gate (mirrors routes-setup-cortex.ts). */
38
+ function encoderAssetDir() {
39
+ let dir = dirname(fileURLToPath(import.meta.url));
40
+ const rel = join("assets", "vector-cortex", "encoder-v1");
41
+ for (let i = 0; i < 8; i++) {
42
+ const candidate = join(dir, rel);
43
+ if (existsSync(join(candidate, "manifest.json")))
44
+ return candidate;
45
+ const next = dirname(dir);
46
+ if (next === dir)
47
+ break;
48
+ dir = next;
49
+ }
50
+ return null;
51
+ }
52
+ /**
53
+ * ENC-0g: the live computed blockers for the action gate. When both gates are
54
+ * ON, read the QualificationV1 record + verified manifest head-count and derive
55
+ * the live list (so a closed HG-1 no longer gates fetch-model/bench). Otherwise
56
+ * return null and let setupCortexActionBlockers fall back to the static base.
57
+ */
58
+ function liveActionBlockers() {
59
+ if (!ENC_0G_ENABLED() || !ENC_0F_ENABLED())
60
+ return null;
61
+ const record = readQualificationRecord(encoderStateDir());
62
+ let headCount = null;
63
+ const dir = encoderAssetDir();
64
+ if (dir !== null) {
65
+ const manifest = readEncoderManifest(dir);
66
+ if (manifest !== null)
67
+ headCount = Object.keys(manifest.heads).length;
68
+ }
69
+ return computeSetupCortexBlockers({
70
+ platform: detectPlatform(),
71
+ qualification: record,
72
+ headCount,
73
+ });
74
+ }
32
75
  /** Flag-off response, byte-identical regardless of request (VC9B absent). */
33
76
  function sendDisabled(res) {
34
77
  sendJson(res, 404, { error: "disabled" });
@@ -65,7 +108,10 @@ export function handleSetupCortexAction(req, res, ctx) {
65
108
  }
66
109
  // Hard-gate check: when an OPEN hard-gate item gates this action, do NOT
67
110
  // spawn — surface the blocker ids so the client highlights the matching rows.
68
- const blockers = setupCortexActionBlockers(action);
111
+ // ENC-0g: re-derive against the LIVE computed blockers (a closed HG-1 no
112
+ // longer blocks), falling back to the static base when the gates are off.
113
+ const live = liveActionBlockers();
114
+ const blockers = live !== null ? setupCortexActionBlockers(action, live) : setupCortexActionBlockers(action);
69
115
  if (blockers.length > 0) {
70
116
  sendJson(res, 423, {
71
117
  error: "action_blocked_by_open_item",
@@ -22,12 +22,13 @@ import { createHash } from "node:crypto";
22
22
  import { readFileSync, statSync } from "node:fs";
23
23
  import { join, dirname } from "node:path";
24
24
  import { fileURLToPath } from "node:url";
25
- import { VC9A_ENABLED, ENC_0E_ENABLED } from "../../src/config.js";
25
+ import { VC9A_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED } from "../../src/config.js";
26
26
  import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
27
27
  import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
28
28
  import { sendJson } from "./routes-vector-cortex-shared.js";
29
29
  import { deriveVcStatus } from "./vc-status.js";
30
- import { SETUP_CORTEX_BLOCKERS } from "./setup-cortex-blockers.js";
30
+ import { SETUP_CORTEX_BLOCKERS, computeSetupCortexBlockers } from "./setup-cortex-blockers.js";
31
+ import { readQualificationRecord, encoderStateDir, QUALIFICATION_RECORD_UNAVAILABLE, } from "./qualification-record.js";
31
32
  /** Resolve the committed encoder-v1 asset dir by walking up to the repo root. */
32
33
  function encoderAssetDir() {
33
34
  let dir = dirname(fileURLToPath(import.meta.url));
@@ -51,7 +52,7 @@ function encoderAssetDir() {
51
52
  }
52
53
  let factCache = null;
53
54
  /** Stable cache key: manifest bytes + (size,mtime) of the asset files + platform. */
54
- function factCacheKey(dir, manifestPath) {
55
+ function factCacheKey(dir, manifestPath, stateDir, record, recordGate) {
55
56
  const platform = detectPlatform();
56
57
  if (!platform)
57
58
  return null;
@@ -67,15 +68,47 @@ function factCacheKey(dir, manifestPath) {
67
68
  catch {
68
69
  return null;
69
70
  }
71
+ // ENC-0g: fold the qualification-record gate + (mtime, content sha) into the
72
+ // key so a re-run gate invalidates memoized facts (no stale verdict served).
73
+ try {
74
+ const s = statSync(join(stateDir, "encoder-qualification.json"));
75
+ parts.push(`g:${recordGate ? "on" : "off"}`, `q:${s.size}:${s.mtimeMs}`);
76
+ parts.push(createHash("sha256").update(JSON.stringify(record)).digest("hex"));
77
+ }
78
+ catch {
79
+ parts.push(`g:${recordGate ? "on" : "off"}`, "q:absent");
80
+ }
70
81
  return parts.join("|");
71
82
  }
72
- function computeSetupCortexFacts(dir) {
83
+ function applyQualificationOverride(base, record, recordGate) {
84
+ // Flag-off (recordGate false): byte-identical verify-derived facts.
85
+ if (!recordGate)
86
+ return base;
87
+ if (record !== null) {
88
+ // The ENC-0f QualificationV1 failure maps onto the contract "demoted": a
89
+ // structurally-valid asset whose real-asset gate measured failure is honest
90
+ // as demoted, NOT qualified. mode stays verify-derived (A).
91
+ return {
92
+ ...base,
93
+ verdict: record.verdict === "qualified" ? "qualified" : "demoted",
94
+ thresholdFailures: [...record.reasons],
95
+ };
96
+ }
97
+ // No record + gate on: keep the verify verdict but surface the missing-record
98
+ // sentinel (never a fabricated pass, never a bare silent fallback).
99
+ return {
100
+ ...base,
101
+ thresholdFailures: [...base.thresholdFailures, QUALIFICATION_RECORD_UNAVAILABLE],
102
+ };
103
+ }
104
+ function computeSetupCortexFacts(dir, stateDir, record, recordGate) {
73
105
  const manifest = readEncoderManifest(dir);
74
106
  if (manifest === null) {
75
- return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
107
+ return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
76
108
  }
109
+ const headCount = Object.keys(manifest.heads).length;
77
110
  const manifestPath = join(dir, "manifest.json");
78
- const key = factCacheKey(dir, manifestPath);
111
+ const key = factCacheKey(dir, manifestPath, stateDir, record, recordGate);
79
112
  if (key === null)
80
113
  return null;
81
114
  if (factCache !== null && factCache.key === key)
@@ -86,25 +119,27 @@ function computeSetupCortexFacts(dir) {
86
119
  digest = createHash("sha256").update(readFileSync(manifestPath)).digest("hex");
87
120
  }
88
121
  catch {
89
- const facts = { mode: "B", assetDigestPrefix: null, verdict: "demoted", thresholdFailures: ["ENC_ASSET_UNREADABLE"] };
122
+ const base = { mode: "B", assetDigestPrefix: null, verdict: "demoted", thresholdFailures: ["ENC_ASSET_UNREADABLE"], headCount };
123
+ const facts = applyQualificationOverride(base, record, recordGate);
90
124
  factCache = { key, facts };
91
125
  return facts;
92
126
  }
93
127
  const verify = verifyEncoderAsset(dir, manifest, detectPlatform());
94
128
  const prefix = digest.slice(0, 12);
95
- const facts = verify.ok
96
- ? { mode: "A", assetDigestPrefix: prefix, verdict: "qualified", thresholdFailures: [] }
97
- : { mode: "B", assetDigestPrefix: prefix, verdict: "demoted", thresholdFailures: [verify.code] };
129
+ const base = verify.ok
130
+ ? { mode: "A", assetDigestPrefix: prefix, verdict: "qualified", thresholdFailures: [], headCount }
131
+ : { mode: "B", assetDigestPrefix: prefix, verdict: "demoted", thresholdFailures: [verify.code], headCount };
132
+ const facts = applyQualificationOverride(base, record, recordGate);
98
133
  factCache = { key, facts };
99
134
  return facts;
100
135
  }
101
- function setupCortexFacts() {
136
+ function setupCortexFacts(record, recordGate) {
102
137
  const dir = encoderAssetDir();
103
138
  if (dir === null) {
104
- return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
139
+ return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
105
140
  }
106
- const facts = computeSetupCortexFacts(dir);
107
- return facts ?? { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
141
+ const facts = computeSetupCortexFacts(dir, encoderStateDir(), record, recordGate);
142
+ return facts ?? { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
108
143
  }
109
144
  /**
110
145
  * Reader-only GET /api/setup-cortex-status (VC9A).
@@ -122,8 +157,22 @@ export function handleSetupCortexStatus(req, res, _ctx) {
122
157
  return true;
123
158
  }
124
159
  const enabled = VC9A_ENABLED();
125
- const facts = enabled ? setupCortexFacts() : null;
126
- const blocks = enabled ? [...SETUP_CORTEX_BLOCKERS] : [];
160
+ // ENC-0g: when both gates are ON, read the QualificationV1 record and let its
161
+ // verdict override the structural verify for the `qualification` field. When
162
+ // ENC_0G is OFF, nothing below reads the record (byte-identical to ENC-0f-era).
163
+ const enc0g = enabled && ENC_0G_ENABLED();
164
+ const recordGate = enc0g && ENC_0F_ENABLED();
165
+ const record = recordGate ? readQualificationRecord(encoderStateDir()) : null;
166
+ const facts = enabled ? setupCortexFacts(record, recordGate) : null;
167
+ const blocks = enabled
168
+ ? enc0g
169
+ ? [...computeSetupCortexBlockers({
170
+ platform: detectPlatform(),
171
+ qualification: record,
172
+ headCount: facts ? facts.headCount : null,
173
+ })]
174
+ : [...SETUP_CORTEX_BLOCKERS]
175
+ : [];
127
176
  // ENC-0e: surface the darwin-x64 demotion reason additively (reader-only GET,
128
177
  // no new route). The platform is read locally; the selection is pure. On a
129
178
  // non-darwin-x64 host or flag-off this is null and the field is omitted —
@@ -21,6 +21,8 @@ import { mkdirSync, readFileSync, writeFileSync, existsSync, readdirSync, } from
21
21
  import { join, dirname, basename } from "node:path";
22
22
  import { fileURLToPath } from "node:url";
23
23
  import { readEncoderManifest, verifyEncoderAsset, detectPlatform, } from "../../src/vector-cortex/encoder/asset.js";
24
+ import { ENC_0G_ENABLED, ENC_0F_ENABLED } from "../../src/config.js";
25
+ import { readQualificationRecord, encoderStateDir, } from "./qualification-record.js";
24
26
  /** Cap applied to every log tail served by the action-log route. */
25
27
  export const ACTION_LOG_TAIL_BYTES = 8192;
26
28
  /** Locate the commit's vc2-model-prep directory by walking up to the repo root. */
@@ -153,23 +155,38 @@ function runVerifyAsset(stateDir) {
153
155
  spawned: false,
154
156
  };
155
157
  }
158
+ /**
159
+ * The ENC-0g honesty suffix for the verify-asset summary line: when both gates
160
+ * are ON, surface the QualificationV1 record verdict so the action log is honest
161
+ * alongside the (possibly demoted) status card. Returns "" byte-identical when
162
+ * ENC_0G is off. Bounded + redacted (verdict + reasons only).
163
+ */
164
+ function qualificationRecordSuffix() {
165
+ if (!ENC_0G_ENABLED() || !ENC_0F_ENABLED())
166
+ return "";
167
+ const record = readQualificationRecord(encoderStateDir());
168
+ if (record === null)
169
+ return " record_verdict=unavailable";
170
+ return ` record_verdict=${record.verdict} record_reasons=${record.reasons.join(",")}`;
171
+ }
156
172
  /** Compute the redacted verify-asset summary lines (digests + codes only). */
157
173
  function buildVerifySummary() {
174
+ const suffix = qualificationRecordSuffix();
158
175
  const dir = encoderAssetDir();
159
176
  if (dir === null) {
160
- return "mode=C verdict=unavailable reason=asset_missing\n";
177
+ return `mode=C verdict=unavailable reason=asset_missing${suffix}\n`;
161
178
  }
162
179
  const manifest = readEncoderManifest(dir);
163
180
  if (manifest === null) {
164
- return "mode=B verdict=demoted reason=ENC_MANIFEST_INVALID\n";
181
+ return `mode=B verdict=demoted reason=ENC_MANIFEST_INVALID${suffix}\n`;
165
182
  }
166
183
  const platform = detectPlatform();
167
184
  const verify = verifyEncoderAsset(dir, manifest, platform);
168
185
  if (verify.ok) {
169
186
  const prefix = verify.onnxDigest.slice(0, 12);
170
- return `mode=A verdict=qualified onnx_digest_prefix=${prefix} embedded_bytes=${verify.embeddedBytes}\n`;
187
+ return `mode=A verdict=qualified onnx_digest_prefix=${prefix} embedded_bytes=${verify.embeddedBytes}${suffix}\n`;
171
188
  }
172
- return `mode=B verdict=demoted reason=${verify.code}\n`;
189
+ return `mode=B verdict=demoted reason=${verify.code}${suffix}\n`;
173
190
  }
174
191
  /** Walk up to the committed encoder-v1 asset dir (mirrors routes-setup-cortex.ts). */
175
192
  function encoderAssetDir() {
@@ -1,71 +1,5 @@
1
1
  /**
2
- * dashboard-server/setup-cortex-blockers.ts — canonical blocker manifest for the
3
- * dashboard Setup Cortex status read path (VC9A).
4
- *
5
- * The hard-gate items enumerated in docs/vector-cortex/vc2-model-prep.md §6
6
- * (per the 2026-08-05 research update: the opset-14→17 re-export blocker is
7
- * REMOVED because onnx-community exports are now opset 21). This module is the
8
- * SINGLE canonical source of those blockers — the route file
9
- * (routes-setup-cortex.ts) carries NO string literals for them; it reads this
10
- * static manifest so the UI rows and the spec stay in one place.
11
- *
12
- * Reader-only, static: zero network, no writes (PREVENT-PI-004), no `any`
13
- * (PREVENT-011).
2
+ * dashboard-server/setup-cortex-blockers.ts — thin shell re-exporting the
3
+ * canonical Setup Cortex blocker compute from src (single source of truth).
14
4
  */
15
- /**
16
- * The four blockers VC9A reports. Enumerates the vc2-model-prep §6 items that
17
- * remain per the 2026-08-05 research. The opset re-export blocker (formerly
18
- * §6 #2) is NOT listed: onnx-community exports are opset 21, so it is removed.
19
- */
20
- export const SETUP_CORTEX_BLOCKERS = [
21
- {
22
- id: "HG-1",
23
- title: "Five projection heads do not exist",
24
- severity: "blocker",
25
- status: "open",
26
- resolution: "Supervision transfer onto a frozen bge-small-en-v1.5 trunk (contradiction distilled from cross-encoder/nli-deberta-v3-small; dependency NLI-assisted; cache-stability deterministic; payload-routing small MLP) — VC2B training + export.",
27
- },
28
- {
29
- id: "HG-3",
30
- title: "onnxruntime-node install exceeds the 80 MiB asset budget",
31
- severity: "blocker",
32
- status: "open",
33
- resolution: "onnxruntime-node bundles ~258 MiB across all platforms. Candidate: transformers.js v4.2.0 (9.5 MiB shell, pure-Node via onnxruntime-web WASM) measured against budget + p95 gate before committing.",
34
- },
35
- {
36
- id: "HG-4",
37
- title: "No darwin-x64 binary in onnxruntime-node",
38
- severity: "high",
39
- status: "open",
40
- resolution: "Intel-Mac mode-A users demote to the WASM path (if HG-3 resolves that way) or mode B. " +
41
- "darwin-x64: no native binary upstream (arm64-only); mode-B WASM per HG-4.",
42
- },
43
- {
44
- id: "HG-5",
45
- title: "RSS margin at 512 tokens is ~0.5%",
46
- severity: "medium",
47
- status: "open",
48
- resolution: "149.2 MiB vs 150 MiB cap with run-to-run variance 119-149 MiB; considers capping mode A at 384 tokens or using the marginal-footprint accounting runtime.ts already implements.",
49
- },
50
- ];
51
- /** Look up one blocker by id; undefined when unknown (defensive). */
52
- export function setupCortexBlocker(id) {
53
- return SETUP_CORTEX_BLOCKERS.find((b) => b.id === id);
54
- }
55
- /**
56
- * The open hard-gate ids that BLOCK a given action. fetch-model and bench are
57
- * gated by HG-1 (five-head training open) and HG-3 (install budget open) per the
58
- * VC9 workstream plan; verify-asset is a pure re-read of committed assets and is
59
- * NOT gated. When a gated action is requested, the route returns
60
- * action_blocked_by_open_item with these ids and does NOT spawn. The ids are
61
- * always drawn from SETUP_CORTEX_BLOCKERS (each exists — verified by test).
62
- */
63
- export function setupCortexActionBlockers(action) {
64
- switch (action) {
65
- case "fetch-model":
66
- case "bench":
67
- return ["HG-1", "HG-3"];
68
- case "verify-asset":
69
- return [];
70
- }
71
- }
5
+ export * from "../../src/vector-cortex/setup-cortex-blockers-compute.js";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * config/vector-cortex-enc0g.ts — ENC-0g Setup Cortex status route honest state.
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-enc0a.ts .. enc0f.ts and
6
+ * the VC8C/VC9A-D/ML5A-E/DEDUP_ATTR siblings were. vector-cortex.ts re-exports
7
+ * the flag below and root src/config.ts re-exports it, so no consumer import
8
+ * path changes.
9
+ *
10
+ * ENC-0g makes the Setup Cortex status route honest: the status route reads the
11
+ * latest ENC-0f `QualificationV1` record (when ENC_0F is ON and a record
12
+ * exists) and lets its verdict override the structural verifyEncoderAsset
13
+ * result for the `qualification` field; the blocker list becomes a pure
14
+ * computed function over (platform, qualification record, manifest head-count)
15
+ * with corrected HG statuses/wording; and VC9B action gating is re-derived from
16
+ * the live computed blockers instead of the stale static manifest.
17
+ *
18
+ * `MEGACOMPACT_ENC_0G=0` disables: the status route derives its `qualification`
19
+ * verdict from `verifyEncoderAsset(...).ok` alone, the blocker list is the
20
+ * static `SETUP_CORTEX_BLOCKERS` array exactly as ENC-0f-era, and action gating
21
+ * reads the static table as today — byte-identical to the predecessor. The flag
22
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
23
+ * EXCLUDED_SETTINGS).
24
+ *
25
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+ import { sprintFlag } from "./vector-cortex-flag.js";
28
+ /**
29
+ * ENC-0g — Setup Cortex status route honest state (verdict override + live
30
+ * blockers + re-derived gating). Default ON. `MEGACOMPACT_ENC_0G=0` disables
31
+ * and is byte-identical to the predecessor (ENC-0f): verdict from
32
+ * `verifyEncoderAsset` alone, static `SETUP_CORTEX_BLOCKERS`, static
33
+ * `setupCortexActionBlockers`. This flag MUST also be a dashboard SETTINGS
34
+ * toggle (visible in config UI, never in EXCLUDED_SETTINGS), mirroring
35
+ * ENC_0A/ENC_0B/ENC_0C/ENC_0D/ENC_0E/ENC_0F.
36
+ */
37
+ export const ENC_0G_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0G");
@@ -31,5 +31,6 @@ export { ENC_0C_ENABLED } from "./vector-cortex-enc0c.js";
31
31
  export { ENC_0D_ENABLED } from "./vector-cortex-enc0d.js";
32
32
  export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
33
33
  export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
34
+ export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
34
35
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
35
36
  export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";