pi-mega-compact 0.20.47 → 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 (32) hide show
  1. package/dist/config/vector-cortex-enc0f.js +36 -0
  2. package/dist/config/vector-cortex-enc0g.js +37 -0
  3. package/dist/config/vector-cortex.js +2 -0
  4. package/dist/config.js +1 -1
  5. package/dist/extensions/dashboard-server/qualification-record.js +71 -0
  6. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
  7. package/dist/extensions/dashboard-server/routes-setup-cortex-actions.js +49 -3
  8. package/dist/extensions/dashboard-server/routes-setup-cortex.js +65 -16
  9. package/dist/extensions/dashboard-server/setup-cortex-actions.js +21 -4
  10. package/dist/extensions/dashboard-server/setup-cortex-blockers.js +3 -69
  11. package/dist/src/config/vector-cortex-enc0f.js +36 -0
  12. package/dist/src/config/vector-cortex-enc0g.js +37 -0
  13. package/dist/src/config/vector-cortex.js +2 -0
  14. package/dist/src/config.js +1 -1
  15. package/dist/src/vector-cortex/encoder/qualify.js +50 -0
  16. package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  17. package/dist/vector-cortex/encoder/qualify.js +50 -0
  18. package/dist/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  19. package/extensions/dashboard-server/api-contracts/setup-cortex.ts +6 -2
  20. package/extensions/dashboard-server/qualification-record.ts +70 -0
  21. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
  22. package/extensions/dashboard-server/routes-setup-cortex-actions.ts +50 -3
  23. package/extensions/dashboard-server/routes-setup-cortex.ts +92 -16
  24. package/extensions/dashboard-server/setup-cortex-actions.ts +23 -4
  25. package/extensions/dashboard-server/setup-cortex-blockers.ts +3 -97
  26. package/package.json +1 -1
  27. package/src/config/vector-cortex-enc0f.ts +38 -0
  28. package/src/config/vector-cortex-enc0g.ts +39 -0
  29. package/src/config/vector-cortex.ts +2 -0
  30. package/src/config.ts +2 -0
  31. package/src/vector-cortex/encoder/qualify.ts +83 -0
  32. package/src/vector-cortex/setup-cortex-blockers-compute.ts +216 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * src/vector-cortex/setup-cortex-blockers-compute.ts — canonical blocker
3
+ * manifest + pure computed blocker derivation for the Setup Cortex status
4
+ * read path (VC9A/ENC-0g).
5
+ *
6
+ * The hard-gate items enumerated in docs/vector-cortex/vc2-model-prep.md §6
7
+ * (per the 2026-08-05 research update: the opset-14→17 re-export blocker is
8
+ * REMOVED because onnx-community exports are now opset 21). This module is the
9
+ * SINGLE canonical source of those blockers — the route file
10
+ * (routes-setup-cortex.ts) carries NO string literals for them; it reads this
11
+ * manifest so the UI rows and the spec stay in one place.
12
+ *
13
+ * ENC-0g: `SETUP_CORTEX_BLOCKERS` remains the canonical BASE data (authored
14
+ * all-open, byte-identical to ENC-0f-era for flag-off). `computeSetupCortexBlockers`
15
+ * is a PURE function over (platform, ENC-0f QualificationV1 record, asset-manifest
16
+ * head-count) that returns the live blocker list: HG-1 closes on a five-head
17
+ * manifest (ENC-0c), HG-5 reflects the measured qualification verdict, HG-4
18
+ * notes the ENC-0e visibility close while the binary gap persists, HG-3 stays
19
+ * open (genuinely unresolved). `setupCortexActionBlockers` re-derives VC9B
20
+ * action gating from the live computed blockers (intersects each action's
21
+ * static candidate gate ids with the currently-open blocker ids).
22
+ *
23
+ * Reader-only, pure computation: zero network, no writes (PREVENT-PI-004), no
24
+ * `any` (PREVENT-011). Thresholds come from src/vector-cortex/encoder/types.js
25
+ * (ENCODER_HEAD_ORDER / ENCODER_LATENCY_P95_MS / ENCODER_RSS_BUDGET_BYTES) —
26
+ * never magic numbers in the computed path.
27
+ */
28
+
29
+ import type { QualificationV1 } from "./encoder/qualify.js";
30
+ import {
31
+ ENCODER_HEAD_ORDER,
32
+ ENCODER_LATENCY_P95_MS,
33
+ ENCODER_RSS_BUDGET_BYTES,
34
+ } from "./encoder/types.js";
35
+
36
+ const MIB = 1024 * 1024;
37
+
38
+ /**
39
+ * Marker threshold-failure emitted by the status route when NO QualificationV1
40
+ * record exists on the device (or it is missing / unreadable / corrupt) — the
41
+ * route falls back to the verify-only verdict and includes this marker, never a
42
+ * fabricated pass and never a bare silent fallback. SINGLE source: the status
43
+ * route references this const, never a re-literal (no-scattered-literal scan).
44
+ */
45
+ export const QUALIFICATION_RECORD_UNAVAILABLE = "qualification_record_unavailable";
46
+
47
+ /** Lifecycle of a hard-gate item surfaced on the blockers card. */
48
+ export type SetupCortexBlockerStatusV1 = "open" | "closed" | "superseded";
49
+
50
+ /**
51
+ * A hard-gate item VC9A surfaces. `status` is `"open"` by default (a hard gate
52
+ * is never silently closed); a computed blocker may mark it `"closed"` (a
53
+ * measured/gated close) or `"superseded"` (an open question, but no live
54
+ * measurement exists on this device). The client renders `status` as a row
55
+ * label (no exhaustive switch), so widening is renderer-safe.
56
+ */
57
+ export interface SetupCortexBlockerV1 {
58
+ /** Stable machine id (e.g. HG-1) the client can key rows on. */
59
+ readonly id: string;
60
+ /** Human title shown on the blockers card. */
61
+ readonly title: string;
62
+ /** Severity: blocker | high | medium. */
63
+ readonly severity: "blocker" | "high" | "medium";
64
+ /** Lifecycle state — authored OPEN (ENC-0f-era base), computed from live state. */
65
+ readonly status: SetupCortexBlockerStatusV1;
66
+ /** Optional candidate resolution surfaced for the controller / user. */
67
+ readonly resolution?: string;
68
+ }
69
+
70
+ /**
71
+ * The four blockers VC9A reports. Enumerates the vc2-model-prep §6 items that
72
+ * remain per the 2026-08-05 research. The opset re-export blocker (formerly
73
+ * §6 #2) is NOT listed: onnx-community exports are opset 21, so it is removed.
74
+ * This is the canonical BASE (all `status:"open"`); `computeSetupCortexBlockers`
75
+ * derives the live list from it. Flag-off consumes this array verbatim.
76
+ */
77
+ export const SETUP_CORTEX_BLOCKERS: readonly SetupCortexBlockerV1[] = [
78
+ {
79
+ id: "HG-1",
80
+ title: "Five projection heads do not exist",
81
+ severity: "blocker",
82
+ status: "open",
83
+ resolution:
84
+ "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.",
85
+ },
86
+ {
87
+ id: "HG-3",
88
+ title: "onnxruntime-node install exceeds the 80 MiB asset budget",
89
+ severity: "blocker",
90
+ status: "open",
91
+ resolution:
92
+ "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.",
93
+ },
94
+ {
95
+ id: "HG-4",
96
+ title: "No darwin-x64 binary in onnxruntime-node",
97
+ severity: "high",
98
+ status: "open",
99
+ resolution:
100
+ "Intel-Mac mode-A users demote to the WASM path (if HG-3 resolves that way) or mode B. " +
101
+ "darwin-x64: no native binary upstream (arm64-only); mode-B WASM per HG-4.",
102
+ },
103
+ {
104
+ id: "HG-5",
105
+ title: "RSS margin at 512 tokens is ~0.5%",
106
+ severity: "medium",
107
+ status: "open",
108
+ resolution:
109
+ "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.",
110
+ },
111
+ ];
112
+
113
+ /** Look up one blocker by id; undefined when unknown (defensive). */
114
+ export function setupCortexBlocker(id: string): SetupCortexBlockerV1 | undefined {
115
+ return SETUP_CORTEX_BLOCKERS.find((b) => b.id === id);
116
+ }
117
+
118
+ /**
119
+ * The live blockers computed from (platform, ENC-0f QualificationV1 record,
120
+ * asset-manifest head-count). Pure + deterministic — no IO, no clock, no flag
121
+ * dependence. Rules:
122
+ * - HG-1 → `"closed"` when the asset manifest declares all five projection
123
+ * heads (`headCount === ENCODER_HEAD_ORDER.length`); otherwise stays open.
124
+ * - HG-3 → unchanged (genuinely open — onnxruntime-node budget unresolved).
125
+ * - HG-4 → stays `"open"` (the upstream binary gap is unchanged); resolution
126
+ * notes that ENC-0e ships the darwin demotion visibility surface.
127
+ * - HG-5 → derived from the qualification record: an empty record is
128
+ * `"superseded"` (no measurement on this device); a `failed` verdict closes
129
+ * it with the measured p95/RSS wording; a `qualified` verdict closes it with
130
+ * "measured" wording. Severity stays `"medium"` from the base row.
131
+ * `platform` is carried for contract symmetry with Worker B's route input; the
132
+ * HG rules here do not branch on it (HG-4's darwin note applies regardless).
133
+ */
134
+ export function computeSetupCortexBlockers(input: {
135
+ platform: string | null;
136
+ qualification: QualificationV1 | null;
137
+ headCount: number | null;
138
+ }): readonly SetupCortexBlockerV1[] {
139
+ const { qualification, headCount } = input;
140
+ return SETUP_CORTEX_BLOCKERS.map((base): SetupCortexBlockerV1 => {
141
+ switch (base.id) {
142
+ case "HG-1":
143
+ return headCount === ENCODER_HEAD_ORDER.length
144
+ ? { ...base, status: "closed" }
145
+ : base;
146
+ case "HG-4":
147
+ return {
148
+ ...base,
149
+ resolution: `${base.resolution} ENC-0e shipped the darwin demotion visibility surface.`,
150
+ };
151
+ case "HG-5":
152
+ if (qualification === null) {
153
+ return {
154
+ ...base,
155
+ status: "superseded",
156
+ resolution:
157
+ "No QualificationV1 record on this device — run the gate (scripts/encoder/gate-qualify.mjs) to measure.",
158
+ };
159
+ }
160
+ if (qualification.verdict === "failed") {
161
+ return {
162
+ ...base,
163
+ title: "Real-asset qualification: failed (latency + marginal-RSS over budget)",
164
+ status: "closed",
165
+ resolution:
166
+ `p95 ${qualification.p95Ms} ms vs ${ENCODER_LATENCY_P95_MS} ms gate, marginal RSS ${qualification.rssMib} MiB vs ${ENCODER_RSS_BUDGET_BYTES / MIB} MiB cap — mode A requires the native onnxruntime-node selection`,
167
+ };
168
+ }
169
+ return {
170
+ ...base,
171
+ title: "Real-asset qualification: measured",
172
+ status: "closed",
173
+ };
174
+ default:
175
+ return base;
176
+ }
177
+ });
178
+ }
179
+
180
+ // ─── VC9B action gating ─────────────────────────────────────────────────────
181
+
182
+ /** The VC9B action kinds the drivers know how to run. */
183
+ export type SetupCortexActionKind = "fetch-model" | "bench" | "verify-asset";
184
+
185
+ /**
186
+ * The static PER-ACTION CANDIDATE gate ids — this is POLICY, NOT the derived
187
+ * gating. fetch-model and bench ARE candidates for HG-1 (five-head training)
188
+ * and HG-3 (install budget); verify-asset is a pure re-read of committed assets
189
+ * and is NEVER gated (empty candidate list). The derived gating (below)
190
+ * intersects these candidates with the currently-OPEN blockers from the live
191
+ * computed list, so a candidate only blocks when its blocker is actually open.
192
+ */
193
+ const ACTION_GATE_CANDIDATES: Readonly<Record<SetupCortexActionKind, readonly string[]>> = {
194
+ "fetch-model": ["HG-1", "HG-3"],
195
+ bench: ["HG-1", "HG-3"],
196
+ "verify-asset": [],
197
+ };
198
+
199
+ /**
200
+ * Re-derived VC9B action gating from the LIVE computed blockers. An action is
201
+ * gated by exactly the candidate ids that are `status:"open"` AND
202
+ * `severity:"blocker"` in the supplied blockers. `blockers` defaults to the
203
+ * base `SETUP_CORTEX_BLOCKERS` (authored all-open) for backward compatibility
204
+ * with single-arg callers — with HG-1 closed by a computed list, fetch-model
205
+ * and bench surface `["HG-3"]`; verify-asset always `[]`.
206
+ */
207
+ export function setupCortexActionBlockers(
208
+ action: SetupCortexActionKind,
209
+ blockers?: readonly SetupCortexBlockerV1[],
210
+ ): readonly string[] {
211
+ const live = blockers ?? SETUP_CORTEX_BLOCKERS;
212
+ const openBlockerIds = new Set(
213
+ live.filter((b) => b.status === "open" && b.severity === "blocker").map((b) => b.id),
214
+ );
215
+ return ACTION_GATE_CANDIDATES[action].filter((id) => openBlockerIds.has(id));
216
+ }