pi-mega-compact 0.20.74 → 0.20.75

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.
@@ -9,12 +9,15 @@
9
9
  *
10
10
  * ENC-2c turns ENC-2a's operator run-script assist into a dashboard action: the
11
11
  * Setup Cortex sub-tab gains an "Install Native ORT" button that, when confirmed
12
- * by the operator, runs the committed `scripts/encoder/install-native-ort.mjs`
13
- * subprocess locally (npm-delegated, sha256-verified) and then re-qualifies the
14
- * binding via the ENC-2b retest path. This is a PREVENT-PI-004 opt-in exemption:
15
- * it is confirm-gated (never automatic), delegated to a local subprocess of a
16
- * committed repo script, and carries NO URL literals in src/ or extensions/
17
- * (the registry URL + sha256 live only in the artifacts-module constants).
12
+ * by the operator, performs the pinned-tarball fetch + sha256 verify + npm
13
+ * install in-process (a TypeScript port of
14
+ * `scripts/encoder/install-native-ort.mjs` the npm package ships
15
+ * src/dist/extensions but NOT scripts/, so an installed device has no checkout
16
+ * script to spawn), then re-qualifies the binding via the ENC-2b retest path.
17
+ * This is a PREVENT-PI-004 opt-in exemption: it is confirm-gated (never
18
+ * automatic), delegated to the operator's npm as a local subprocess, and carries
19
+ * NO URL literals in src/ or extensions/ (the registry URL + sha256 live only
20
+ * in the artifacts-module constants).
18
21
  *
19
22
  * `MEGACOMPACT_ENC_2C=0` disables: no install action branch, no UI button, no
20
23
  * install-related result fields — byte-identical to the ENC-2b predecessor. The
@@ -3,9 +3,11 @@
3
3
  * lazy-download INSTALL action contract types.
4
4
  *
5
5
  * Sibling additive types for the VC9B action driver: POST /api/setup-cortex-action
6
- * gains the `install-native-ort` action that, when confirmed, runs the committed
7
- * scripts/encoder/install-native-ort.mjs subprocess locally (npm-delegated,
8
- * sha256-verified) and then re-qualifies the binding via the ENC-2b retest path.
6
+ * gains the `install-native-ort` action that, when confirmed, performs the
7
+ * pinned-tarball fetch + sha256 verify + npm install in-process (a TypeScript
8
+ * port of scripts/encoder/install-native-ort.mjs the npm package ships
9
+ * src/dist/extensions but NOT scripts/, so an installed device has no checkout
10
+ * script to spawn), then re-qualifies the binding via the ENC-2b retest path.
9
11
  *
10
12
  * The retest result shape mirrors `RetestResult` from
11
13
  * extensions/dashboard-server/api-contracts/setup.ts (and
@@ -72,7 +72,7 @@ export const VECTOR_CORTEX_SETTINGS = {
72
72
  boolDirect("MEGACOMPACT_ENC_2BUDGET", "ENC-2a operator-configurable native install-budget knob", "ENC-2a exposes the runtime operator knob MEGACOMPACT_NATIVE_ORT_BUDGET_MIB (default 300 MiB, clamp 8192) as a dashboard Settings field. The knob gates budgetOk in the encoder runtime decision (decision.ts installBudgetMib + runtime-select.ts selectRuntimeBackend). Persisted to the per-repo .mega-compact.env via the setup-configure writer branch; the GET status route surfaces the persisted value AND the effective integer installBudgetMib() resolves to (so the dashboard shows the runtime's actual operand). OFF = no new GET fields, no writer branch, no new Settings rows (byte-identical ENC-1b predecessor).", true),
73
73
  boolDirect("MEGACOMPACT_ENC_2A", "ENC-2a native onnxruntime install GUIDE (detect + copy-paste)", "ENC-2a surfaces the platform-matched native onnxruntime install-guide (three copy-paste steps + script path) on the Setup Cortex sub-tab when the operator opted into the native backend but the effective runtime is still wasm (onnxruntime-node absent). Pure guidance — the extension NEVER executes or fetches (PREVENT-PI-004 unchanged); the committed operator script scripts/encoder/install-native-ort.mjs runs in the USER's shell. OFF = no guide GET fields, no guide-request POST branch, no install card (byte-identical ENC-1b predecessor).", true),
74
74
  boolDirect("MEGACOMPACT_ENC_2B", "ENC-2b native ONNX runtime qualification retest (detect + re-qualify)", "ENC-2b re-probes and re-qualifies the installed native onnxruntime binding (onnxruntime-node in ~/.pi/mega-compact/native-ort/, operator-installed via the ENC-2a guide): loads the LOCAL on-disk binding, runs a bounded warmup + p95 probe, measures RSS, and computes a fresh qualification verdict against the ENC-0f p95 budget + the operator install-budget. Never downloads or trains (PREVENT-PI-004 / HG-1 unchanged); surfaces nativeOrtRetestResult + nativeOrtBackendEffective on the GET /api/setup-status. OFF = no retest GET fields, no retest POST branch, no retest card (byte-identical ENC-2a predecessor).", true),
75
- boolDirect("MEGACOMPACT_ENC_2C", "ENC-2c native ONNX runtime lazy-download INSTALL action (dashboard-triggered)", "ENC-2c turns ENC-2a's operator run-script assist into a confirm-gated dashboard action: the Setup Cortex sub-tab gains an Install Native ORT button that, when the operator confirms, runs the committed scripts/encoder/install-native-ort.mjs subprocess locally (npm-delegated, sha256-verified) and then re-qualifies the binding via the ENC-2b retest path, exposing nativeOrtRetestResult / nativeOrtBackendEffective on the completion. PREVENT-PI-004 opt-in exemption: confirm-gated, npm-delegated, no URL literals (registry URL + sha256 live only in native-install-artifacts.ts). OFF = no install action POST branch, no UI button, no install result fields (byte-identical ENC-2b predecessor).", true),
75
+ boolDirect("MEGACOMPACT_ENC_2C", "ENC-2c native ONNX runtime lazy-download INSTALL action (dashboard-triggered)", "ENC-2c turns ENC-2a's operator run-script assist into a confirm-gated dashboard action: the Setup Cortex sub-tab gains an Install Native ORT button that, when the operator confirms, performs the pinned-tarball fetch + sha256 verify + npm install in-process (TypeScript port of scripts/encoder/install-native-ort.mjs the npm package doesn't ship scripts/, so installed devices have no checkout script to spawn) and then re-qualifies the binding via the ENC-2b retest path, exposing nativeOrtRetestResult / nativeOrtBackendEffective on the completion. PREVENT-PI-004 opt-in exemption: confirm-gated, npm-delegated, no URL literals (registry URL + sha256 live only in native-install-artifacts.ts). OFF = no install action POST branch, no UI button, no install result fields (byte-identical ENC-2b predecessor).", true),
76
76
  boolDirect("MEGACOMPACT_COSINE_FP_BENCH", "COS-FP-A Synthetic FP Bench", "Synthetic FP harness + L2 cosine threshold calibration (COS-FP-A): drives the deterministic synthetic-corpus grid sweep (scripts/cosine-fp/bench.mjs) that measures L2 cosine false-positive rates and emits a recommended default, and serves the reader-only GET /api/cosine-fp-report. Synthetic-corpus-only — never reads real session/ledger bytes. OFF = bench inert, endpoint 404s, no report write, L2_COSINE plain MEGACOMPACT_L2_THRESHOLD (byte-identical predecessor).", true),
77
77
  boolDirect("MEGACOMPACT_COSINE_FP_REAL", "COS-FP-R Real-Corpus Validation", "Real-corpus L2 cosine FP validation (COS-FP-R): runs the real-corpus grid sweep (scripts/cosine-fp/real-bench.mjs) against donated, consent-approved sessions only (SECURITY_PRIVACY Lifecycle/Consent), scoring FP/FN with Wilson intervals + session-grouped bootstrap, and appends CI-backed per-content-type recommendations to the cosine-threshold report. Runs only when a valid consented corpus exists; absent corpus = no_corpus (normative pre-donation state, nothing written). OFF = script inert, nothing executes, no writes (byte-identical predecessor).", true),
78
78
  boolDirect("MEGACOMPACT_REPO_CORPUS", "Cross-Repo Corpus (REPO-A)", "Cross-repo corpus preparation (REPO-A): the governed, consent-gated reader-only path that builds a pseudonymous corpus manifest from per-repo events.log slices and serves GET /api/repo-corpus answering which pseudonymous repos/sessions are in the corpus, what cross-repo overlap exists, and whether consent is active for each — counts + IDs + status only, never payload content. Consent is append-only (consent.mjs, CLI/ops-only); revocation freezes the builder + route. OFF = builder refuses to run, reader route 404s, single-repo recall untouched (byte-identical predecessor).", true),
@@ -5,30 +5,99 @@
5
5
  * Sibling of setup-cortex-actions.ts (which stays under the 300-line source soft
6
6
  * cap). Implements the mechanics behind the VC9B `install-native-ort` action:
7
7
  *
8
- * 1. locate the committed scripts/encoder/install-native-ort.mjs by walking up
9
- * to the repo root (mirroring setup-cortex-actions.ts vc2ScriptDir);
10
- * 2. spawn `node <script>` locally with a 60s timeout (npm-delegated,
11
- * sha256-verified install the registry URL + sha256 live ONLY in
12
- * src/vector-cortex/encoder/native-install-artifacts.ts, never here);
13
- * 3. capture output to <stateDir>/logs/vc9b/install-native-ort-<ts>.log;
14
- * 4. REGARDLESS of the install exit code, re-qualify the binding via the ENC-2b
15
- * retest path (`runNativeRetest`) and surface the fresh result +
16
- * effective backend.
8
+ * 1. compute the install root (`MEGACOMPACT_NATIVE_ORT_ROOT` override, else
9
+ * default ~/.pi/mega-compact/native-ort);
10
+ * 2. detect the host platform and reject non-installable hosts (ENC-0e);
11
+ * 3. fetch the pinned onnxruntime-node tarball via the operator's npm and
12
+ * verify its sha256 BEFORE install (the tarball never lands in the final
13
+ * prefix until the pinned sha matches);
14
+ * 4. `npm install --prefix <root> <tarball>` from the VERIFIED local tarball;
15
+ * 5. write a small `.enc2a-marker.json` marker ({platform, version, sha256})
16
+ * the ENC-2a version probe reads;
17
+ * 6. REGARDLESS of install exit code, re-qualify the binding via the ENC-2b
18
+ * retest path (`runNativeRetest`) and surface the fresh result + effective
19
+ * backend.
17
20
  *
18
21
  * PREVENT-PI-004 banner: this is an OPT-IN, confirm-gated, npm-delegated local
19
22
  * subprocess of a committed repo script. It performs no network I/O in this
20
23
  * module and carries NO URL literals (the codebase-wide no-URL-literal scan
21
24
  * covers src/ + extensions/).
22
25
  *
23
- * Guardrails: PREVENT-011 (no `any`); the subprocess is a committed local script,
24
- * never fetched (PREVENT-PI-004, guardrails-allow below).
26
+ * In-process port of scripts/encoder/install-native-ort.mjs: the npm package
27
+ * ships src/ + dist/ + extensions/ but NOT scripts/, so the dashboard button on
28
+ * an installed device has no checkout script to spawn — porting the install
29
+ * logic here keeps the action working independent of the checkout layout.
30
+ *
31
+ * Guardrails: PREVENT-011 (no `any`); PREVENT-PI-004 (npm-delegated local
32
+ * subprocess; guardrails-allow below).
25
33
  */
26
- import { spawnSync } from "node:child_process"; // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install subprocess (local spawn of committed repo script; no URL literals)
27
- import { mkdirSync, writeFileSync, existsSync } from "node:fs";
34
+ import { spawnSync } from "node:child_process"; // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install subprocess (local spawn of committed npm tooling; no URL literals)
35
+ import { createHash } from "node:crypto";
36
+ import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync } from "node:fs";
28
37
  import { join, dirname } from "node:path";
29
38
  import { fileURLToPath } from "node:url";
30
39
  import { runNativeRetest } from "../../src/vector-cortex/encoder/native-qualify-retest.js";
31
- /** Locate scripts/encoder/install-native-ort.mjs by walking up to the repo root. */
40
+ import { NATIVE_ORT_PACKAGE, NATIVE_ORT_TARBALL_SHA256, NATIVE_ORT_VERSION, NATIVE_ORT_INSTALLABLE_PLATFORMS, } from "../../src/vector-cortex/encoder/native-install-artifacts.js";
41
+ /** Candidate install roots: `MEGACOMPACT_NATIVE_ORT_ROOT` override first
42
+ * (ENC-2a parity + test isolation), else the default `~/.pi/mega-compact/
43
+ * native-ort/`. */
44
+ function nativeOrtDir() {
45
+ const override = process.env.MEGACOMPACT_NATIVE_ORT_ROOT;
46
+ if (override !== undefined && override.length > 0)
47
+ return override;
48
+ return join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
49
+ }
50
+ /** Resolve the host to an installable EncoderPlatform string. darwin-x64 is
51
+ * UNSUPPORTED (no native binding upstream — arm64-only since 1.17) and
52
+ * unknown platforms also fail → the caller surfaces a clear failure. */
53
+ function hostPlatform() {
54
+ const plat = process.platform === "win32"
55
+ ? "win32"
56
+ : process.platform === "darwin"
57
+ ? "darwin"
58
+ : process.platform === "linux"
59
+ ? "linux"
60
+ : "";
61
+ const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : "";
62
+ const candidate = `${plat}-${arch}`;
63
+ if (candidate === "darwin-x64")
64
+ return null; // no native binding upstream
65
+ if (!NATIVE_ORT_INSTALLABLE_PLATFORMS.includes(candidate))
66
+ return null;
67
+ return candidate;
68
+ }
69
+ /** sha256 digest of a file on disk. Local FS read (loopback). */
70
+ function sha256File(path) {
71
+ // guardrails-allow PREVENT-PI-004: local file hash (loopback)
72
+ return createHash("sha256").update(readFileSync(path)).digest("hex");
73
+ }
74
+ /** Write the small `.enc2a-marker.json` marker the ENC-2a version probe reads. */
75
+ function writeMarker(root, platform) {
76
+ const marker = {
77
+ platform,
78
+ version: NATIVE_ORT_VERSION,
79
+ installedAt: new Date().toISOString(),
80
+ sha256: NATIVE_ORT_TARBALL_SHA256,
81
+ };
82
+ // guardrails-allow PREVENT-PI-004: local marker write (loopback)
83
+ writeFileSync(join(root, ".enc2a-marker.json"), JSON.stringify(marker, null, 2) + "\n", "utf8");
84
+ }
85
+ /** Ensure the vc9b log dir exists (mirrors setup-cortex-actions.ts). */
86
+ function ensureLogDir(stateDir) {
87
+ const dir = join(stateDir, "logs", "vc9b");
88
+ // guardrails-allow PREVENT-PI-004: local state-dir filesystem write (loopback)
89
+ mkdirSync(dir, { recursive: true });
90
+ return dir;
91
+ }
92
+ function writeLog(logPath, body) {
93
+ // guardrails-allow PREVENT-PI-004: local state-dir filesystem write (loopback)
94
+ writeFileSync(logPath, body, "utf8");
95
+ }
96
+ /** The original committed-install-script path lookup, kept for the unit test
97
+ * that proves the committed scripts/encoder/install-native-ort.mjs lives on
98
+ * disk in a checkout. The install action itself no longer spawns that script
99
+ * (in-process port), but the suite would otherwise need to lose that
100
+ * verification. */
32
101
  export function installScriptPath() {
33
102
  let dir = dirname(fileURLToPath(import.meta.url));
34
103
  const rel = join("scripts", "encoder", "install-native-ort.mjs");
@@ -44,60 +113,118 @@ export function installScriptPath() {
44
113
  }
45
114
  return null;
46
115
  }
47
- /** Ensure the vc9b log dir exists (mirrors setup-cortex-actions.ts). */
48
- function ensureLogDir(stateDir) {
49
- const dir = join(stateDir, "logs", "vc9b");
50
- // guardrails-allow PREVENT-PI-004: local state-dir filesystem write (loopback)
51
- mkdirSync(dir, { recursive: true });
52
- return dir;
53
- }
54
- function writeLog(logPath, body) {
55
- // guardrails-allow PREVENT-PI-004: local state-dir filesystem write (loopback)
56
- writeFileSync(logPath, body, "utf8");
57
- }
58
116
  /**
59
- * Run the ENC-2c lazy-download native onnxruntime INSTALL action. Locates and
60
- * spawns the committed install script (npm-delegated, sha256-verified), logs the
61
- * captured output, then ALWAYS runs the ENC-2b retest to re-qualify the binding
62
- * (regardless of install exit code) and surfaces the fresh result.
117
+ * Run the ENC-2c lazy-download native onnxruntime INSTALL action. Fetches the
118
+ * pinned tarball via the operator's npm, verifies its sha256, installs into
119
+ * `nativeOrtDir()`, then ALWAYS runs the ENC-2b retest to re-qualify the
120
+ * binding and surfacing the fresh result.
63
121
  *
64
- * Never throws: a missing script or non-zero exit is surfaced as ok=false on the
65
- * result; the retest runs even on install failure so the operator sees the
66
- * post-install qualification state. Returns a combined SetupCortexActionResult
67
- * with the ENC-2c additive fields (present only for pendant actions).
122
+ * Never throws: every failure (host platform, npm failure, hash mismatch)
123
+ * surfaces as ok=false on the result; the retest runs even on install failure
124
+ * so the operator sees the post-install qualification state. Returns a
125
+ * combined SetupCortexActionResult with the ENC-2c additive fields (present
126
+ * only for pendant actions).
68
127
  */
69
- // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install action (subprocess of committed repo script; no URL literals)
128
+ // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install action (subprocess of committed npm tooling; no URL literals)
70
129
  export async function runInstallNativeOrt(stateDir) {
71
130
  const ts = Date.now();
72
131
  const logName = `install-native-ort-${ts}.log`;
73
132
  const logPath = join(ensureLogDir(stateDir), logName);
74
- const scriptPath = installScriptPath();
75
- if (scriptPath === null) {
76
- writeLog(logPath, "install-native-ort.mjs not found in this checkout\n");
133
+ const root = nativeOrtDir();
134
+ const platform = hostPlatform();
135
+ if (platform === null) {
136
+ writeLog(logPath, "install-native-ort: host platform has no native binding\n");
77
137
  return {
78
138
  action: "install-native-ort",
79
139
  ok: false,
80
140
  exitCode: null,
81
141
  logPath,
82
142
  logName,
143
+ spawned: false,
144
+ };
145
+ }
146
+ // Step 1: derive the tarball URL + fetch the tarball via the operator's npm.
147
+ // (The tarball never lands in the final prefix until the pinned sha matches.)
148
+ mkdirSync(root, { recursive: true });
149
+ const packedName = `${NATIVE_ORT_PACKAGE}-${NATIVE_ORT_VERSION}.tgz`;
150
+ const packedPath = join(root, packedName);
151
+ let out = "";
152
+ const run = (argv) => {
153
+ const res = spawnSync("npm", argv, { encoding: "utf8", timeout: 60_000 });
154
+ out += [res.stdout, res.stderr].filter(Boolean).join("\n") + "\n";
155
+ return { code: res.status ?? 1, stdio: out };
156
+ };
157
+ // npm pack <pkg>@<ver> --pack-destination <root>
158
+ // guardrails-allow PREVENT-PI-004: npm-delegated tarball fetch (opt-in
159
+ // confirm-gated install action; package@version come from the committed
160
+ // artifacts module, never a literal URL).
161
+ const pack = run([
162
+ "pack",
163
+ `${NATIVE_ORT_PACKAGE}@${NATIVE_ORT_VERSION}`,
164
+ "--pack-destination",
165
+ root,
166
+ ]);
167
+ if (pack.code !== 0 || !existsSync(packedPath)) {
168
+ writeLog(logPath, `${out}npm pack failed — could not download tarball\n`);
169
+ const retest = await runNativeRetest(stateDir);
170
+ return {
171
+ action: "install-native-ort",
172
+ ok: false,
173
+ exitCode: pack.code,
174
+ logPath,
175
+ logName,
176
+ spawned: true,
177
+ nativeOrtRetestResult: retest,
178
+ nativeOrtBackendEffective: retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
179
+ };
180
+ }
181
+ // Step 2: verify sha256 BEFORE install.
182
+ const actual = sha256File(packedPath);
183
+ if (actual !== NATIVE_ORT_TARBALL_SHA256) {
184
+ writeLog(logPath, `${out}sha256 mismatch — expected ${NATIVE_ORT_TARBALL_SHA256}, got ${actual}\n`);
185
+ // guardrails-allow PREVENT-PI-004: removing a tarball we just wrote (local FS)
186
+ rmSync(packedPath, { force: true });
187
+ const retest = await runNativeRetest(stateDir);
188
+ return {
189
+ action: "install-native-ort",
190
+ ok: false,
191
+ exitCode: 1,
192
+ logPath,
193
+ logName,
194
+ spawned: true,
195
+ nativeOrtRetestResult: retest,
196
+ nativeOrtBackendEffective: retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
197
+ };
198
+ }
199
+ // Step 3: install from the VERIFIED local tarball (npm install --prefix).
200
+ // guardrails-allow PREVENT-PI-004: npm-delegated install from a local tarball
201
+ // (opt-in confirm-gated install action).
202
+ const install = run(["install", "--prefix", root, packedPath]);
203
+ // guardrails-allow PREVENT-PI-004: removing the local tarball after install
204
+ rmSync(packedPath, { force: true });
205
+ const installedPkg = join(root, "node_modules", NATIVE_ORT_PACKAGE, "package.json");
206
+ if (install.code !== 0 || !existsSync(installedPkg)) {
207
+ writeLog(logPath, `${out}npm install from verified tarball failed\n`);
208
+ const retest = await runNativeRetest(stateDir);
209
+ return {
210
+ action: "install-native-ort",
211
+ ok: false,
212
+ exitCode: install.code,
213
+ logPath,
214
+ logName,
83
215
  spawned: true,
216
+ nativeOrtRetestResult: retest,
217
+ nativeOrtBackendEffective: retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
84
218
  };
85
219
  }
86
- // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated
87
- // install subprocess (local spawn of committed repo script; no URL literals)
88
- const result = spawnSync(process.execPath, [scriptPath], {
89
- encoding: "utf8",
90
- timeout: 60_000,
91
- });
92
- const out = `${result.stdout ?? ""}${result.stderr ?? ""}`;
93
- writeLog(logPath, out || "(no output)\n");
94
- // Re-qualify AFTER install regardless of exit code (the retest is the source of
95
- // truth for whether the binding is actually usable).
220
+ // Step 4: success — write the marker, log, then retest.
221
+ writeMarker(root, platform);
222
+ writeLog(logPath, `${out}installed ${NATIVE_ORT_PACKAGE}@${NATIVE_ORT_VERSION} (${platform}); sha256 verified + marker written.\n`);
96
223
  const retest = await runNativeRetest(stateDir);
97
224
  return {
98
225
  action: "install-native-ort",
99
- ok: result.status === 0,
100
- exitCode: result.status === null ? null : result.status,
226
+ ok: true,
227
+ exitCode: install.code,
101
228
  logPath,
102
229
  logName,
103
230
  spawned: true,
@@ -9,12 +9,15 @@
9
9
  *
10
10
  * ENC-2c turns ENC-2a's operator run-script assist into a dashboard action: the
11
11
  * Setup Cortex sub-tab gains an "Install Native ORT" button that, when confirmed
12
- * by the operator, runs the committed `scripts/encoder/install-native-ort.mjs`
13
- * subprocess locally (npm-delegated, sha256-verified) and then re-qualifies the
14
- * binding via the ENC-2b retest path. This is a PREVENT-PI-004 opt-in exemption:
15
- * it is confirm-gated (never automatic), delegated to a local subprocess of a
16
- * committed repo script, and carries NO URL literals in src/ or extensions/
17
- * (the registry URL + sha256 live only in the artifacts-module constants).
12
+ * by the operator, performs the pinned-tarball fetch + sha256 verify + npm
13
+ * install in-process (a TypeScript port of
14
+ * `scripts/encoder/install-native-ort.mjs` the npm package ships
15
+ * src/dist/extensions but NOT scripts/, so an installed device has no checkout
16
+ * script to spawn), then re-qualifies the binding via the ENC-2b retest path.
17
+ * This is a PREVENT-PI-004 opt-in exemption: it is confirm-gated (never
18
+ * automatic), delegated to the operator's npm as a local subprocess, and carries
19
+ * NO URL literals in src/ or extensions/ (the registry URL + sha256 live only
20
+ * in the artifacts-module constants).
18
21
  *
19
22
  * `MEGACOMPACT_ENC_2C=0` disables: no install action branch, no UI button, no
20
23
  * install-related result fields — byte-identical to the ENC-2b predecessor. The
@@ -37,12 +37,16 @@ import { detectPlatform } from "./asset.js";
37
37
  import { NATIVE_ORT_PACKAGE } from "./native-install-artifacts.js";
38
38
  /** Candidate ONNX runtime native-ort prefixes. The ENC-2a guide installs to
39
39
  * the global `~/.pi/mega-compact/native-ort/`; `stateDir` (per-repo) is a
40
- * secondary probe root so the retest resolves either install location. */
40
+ * secondary probe root so the retest resolves either install location.
41
+ * `MEGACOMPACT_NATIVE_ORT_ROOT` overrides the global root (ENC-2a parity +
42
+ * test isolation — honors the same override the enc2a probe and the ENC-2c
43
+ * in-process installer honor). */
41
44
  function nativeOrtRootCandidates(stateDir) {
42
- return [
43
- join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort"),
44
- join(stateDir, "native-ort"),
45
- ];
45
+ const override = process.env.MEGACOMPACT_NATIVE_ORT_ROOT;
46
+ const global = override !== undefined && override.length > 0
47
+ ? override
48
+ : join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
49
+ return [global, join(stateDir, "native-ort")];
46
50
  }
47
51
  /** A single bounded inference pass on the fixed 512-token synthetic input;
48
52
  * returns latency ms, or null when the session cannot run (caller reports
@@ -200,9 +200,11 @@ const ACTION_GATE_CANDIDATES = {
200
200
  // behavior change. HG-7 is training work (no action in this set).
201
201
  bench: ["HG-1", "HG-3", "HG-6"],
202
202
  "verify-asset": [],
203
- // ENC-2c: installing the lazy-download native binding is gated by HG-3 (the
204
- // open install-budget hard gate) a closed HG-3 no longer blocks the install.
205
- "install-native-ort": ["HG-3"],
203
+ // install-native-ort is NEVER gated by HG-3: the action's entire purpose is
204
+ // to install the binding that closes HG-3. Gating it would deadlock — you
205
+ // can't install the binding that closes the gate because the gate blocks the
206
+ // install. HG-3 closes when the install succeeds (the probe detects it).
207
+ "install-native-ort": [],
206
208
  };
207
209
  /**
208
210
  * Re-derived VC9B action gating from the LIVE computed blockers. An action is
@@ -37,12 +37,16 @@ import { detectPlatform } from "./asset.js";
37
37
  import { NATIVE_ORT_PACKAGE } from "./native-install-artifacts.js";
38
38
  /** Candidate ONNX runtime native-ort prefixes. The ENC-2a guide installs to
39
39
  * the global `~/.pi/mega-compact/native-ort/`; `stateDir` (per-repo) is a
40
- * secondary probe root so the retest resolves either install location. */
40
+ * secondary probe root so the retest resolves either install location.
41
+ * `MEGACOMPACT_NATIVE_ORT_ROOT` overrides the global root (ENC-2a parity +
42
+ * test isolation — honors the same override the enc2a probe and the ENC-2c
43
+ * in-process installer honor). */
41
44
  function nativeOrtRootCandidates(stateDir) {
42
- return [
43
- join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort"),
44
- join(stateDir, "native-ort"),
45
- ];
45
+ const override = process.env.MEGACOMPACT_NATIVE_ORT_ROOT;
46
+ const global = override !== undefined && override.length > 0
47
+ ? override
48
+ : join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
49
+ return [global, join(stateDir, "native-ort")];
46
50
  }
47
51
  /** A single bounded inference pass on the fixed 512-token synthetic input;
48
52
  * returns latency ms, or null when the session cannot run (caller reports
@@ -200,9 +200,11 @@ const ACTION_GATE_CANDIDATES = {
200
200
  // behavior change. HG-7 is training work (no action in this set).
201
201
  bench: ["HG-1", "HG-3", "HG-6"],
202
202
  "verify-asset": [],
203
- // ENC-2c: installing the lazy-download native binding is gated by HG-3 (the
204
- // open install-budget hard gate) a closed HG-3 no longer blocks the install.
205
- "install-native-ort": ["HG-3"],
203
+ // install-native-ort is NEVER gated by HG-3: the action's entire purpose is
204
+ // to install the binding that closes HG-3. Gating it would deadlock — you
205
+ // can't install the binding that closes the gate because the gate blocks the
206
+ // install. HG-3 closes when the install succeeds (the probe detects it).
207
+ "install-native-ort": [],
206
208
  };
207
209
  /**
208
210
  * Re-derived VC9B action gating from the LIVE computed blockers. An action is
@@ -3,9 +3,11 @@
3
3
  * lazy-download INSTALL action contract types.
4
4
  *
5
5
  * Sibling additive types for the VC9B action driver: POST /api/setup-cortex-action
6
- * gains the `install-native-ort` action that, when confirmed, runs the committed
7
- * scripts/encoder/install-native-ort.mjs subprocess locally (npm-delegated,
8
- * sha256-verified) and then re-qualifies the binding via the ENC-2b retest path.
6
+ * gains the `install-native-ort` action that, when confirmed, performs the
7
+ * pinned-tarball fetch + sha256 verify + npm install in-process (a TypeScript
8
+ * port of scripts/encoder/install-native-ort.mjs the npm package ships
9
+ * src/dist/extensions but NOT scripts/, so an installed device has no checkout
10
+ * script to spawn), then re-qualifies the binding via the ENC-2b retest path.
9
11
  *
10
12
  * The retest result shape mirrors `RetestResult` from
11
13
  * extensions/dashboard-server/api-contracts/setup.ts (and
@@ -329,7 +329,7 @@ export const VECTOR_CORTEX_SETTINGS: SettingGroup = {
329
329
  boolDirect(
330
330
  "MEGACOMPACT_ENC_2C",
331
331
  "ENC-2c native ONNX runtime lazy-download INSTALL action (dashboard-triggered)",
332
- "ENC-2c turns ENC-2a's operator run-script assist into a confirm-gated dashboard action: the Setup Cortex sub-tab gains an Install Native ORT button that, when the operator confirms, runs the committed scripts/encoder/install-native-ort.mjs subprocess locally (npm-delegated, sha256-verified) and then re-qualifies the binding via the ENC-2b retest path, exposing nativeOrtRetestResult / nativeOrtBackendEffective on the completion. PREVENT-PI-004 opt-in exemption: confirm-gated, npm-delegated, no URL literals (registry URL + sha256 live only in native-install-artifacts.ts). OFF = no install action POST branch, no UI button, no install result fields (byte-identical ENC-2b predecessor).",
332
+ "ENC-2c turns ENC-2a's operator run-script assist into a confirm-gated dashboard action: the Setup Cortex sub-tab gains an Install Native ORT button that, when the operator confirms, performs the pinned-tarball fetch + sha256 verify + npm install in-process (TypeScript port of scripts/encoder/install-native-ort.mjs the npm package doesn't ship scripts/, so installed devices have no checkout script to spawn) and then re-qualifies the binding via the ENC-2b retest path, exposing nativeOrtRetestResult / nativeOrtBackendEffective on the completion. PREVENT-PI-004 opt-in exemption: confirm-gated, npm-delegated, no URL literals (registry URL + sha256 live only in native-install-artifacts.ts). OFF = no install action POST branch, no UI button, no install result fields (byte-identical ENC-2b predecessor).",
333
333
  true,
334
334
  ),
335
335
  boolDirect(
@@ -5,48 +5,99 @@
5
5
  * Sibling of setup-cortex-actions.ts (which stays under the 300-line source soft
6
6
  * cap). Implements the mechanics behind the VC9B `install-native-ort` action:
7
7
  *
8
- * 1. locate the committed scripts/encoder/install-native-ort.mjs by walking up
9
- * to the repo root (mirroring setup-cortex-actions.ts vc2ScriptDir);
10
- * 2. spawn `node <script>` locally with a 60s timeout (npm-delegated,
11
- * sha256-verified install the registry URL + sha256 live ONLY in
12
- * src/vector-cortex/encoder/native-install-artifacts.ts, never here);
13
- * 3. capture output to <stateDir>/logs/vc9b/install-native-ort-<ts>.log;
14
- * 4. REGARDLESS of the install exit code, re-qualify the binding via the ENC-2b
15
- * retest path (`runNativeRetest`) and surface the fresh result +
16
- * effective backend.
8
+ * 1. compute the install root (`MEGACOMPACT_NATIVE_ORT_ROOT` override, else
9
+ * default ~/.pi/mega-compact/native-ort);
10
+ * 2. detect the host platform and reject non-installable hosts (ENC-0e);
11
+ * 3. fetch the pinned onnxruntime-node tarball via the operator's npm and
12
+ * verify its sha256 BEFORE install (the tarball never lands in the final
13
+ * prefix until the pinned sha matches);
14
+ * 4. `npm install --prefix <root> <tarball>` from the VERIFIED local tarball;
15
+ * 5. write a small `.enc2a-marker.json` marker ({platform, version, sha256})
16
+ * the ENC-2a version probe reads;
17
+ * 6. REGARDLESS of install exit code, re-qualify the binding via the ENC-2b
18
+ * retest path (`runNativeRetest`) and surface the fresh result + effective
19
+ * backend.
17
20
  *
18
21
  * PREVENT-PI-004 banner: this is an OPT-IN, confirm-gated, npm-delegated local
19
22
  * subprocess of a committed repo script. It performs no network I/O in this
20
23
  * module and carries NO URL literals (the codebase-wide no-URL-literal scan
21
24
  * covers src/ + extensions/).
22
25
  *
23
- * Guardrails: PREVENT-011 (no `any`); the subprocess is a committed local script,
24
- * never fetched (PREVENT-PI-004, guardrails-allow below).
26
+ * In-process port of scripts/encoder/install-native-ort.mjs: the npm package
27
+ * ships src/ + dist/ + extensions/ but NOT scripts/, so the dashboard button on
28
+ * an installed device has no checkout script to spawn — porting the install
29
+ * logic here keeps the action working independent of the checkout layout.
30
+ *
31
+ * Guardrails: PREVENT-011 (no `any`); PREVENT-PI-004 (npm-delegated local
32
+ * subprocess; guardrails-allow below).
25
33
  */
26
34
 
27
- import { spawnSync } from "node:child_process"; // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install subprocess (local spawn of committed repo script; no URL literals)
28
- import { mkdirSync, writeFileSync, existsSync } from "node:fs";
35
+ import { spawnSync } from "node:child_process"; // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install subprocess (local spawn of committed npm tooling; no URL literals)
36
+ import { createHash } from "node:crypto";
37
+ import { mkdirSync, writeFileSync, existsSync, rmSync, readFileSync } from "node:fs";
29
38
  import { join, dirname } from "node:path";
30
39
  import { fileURLToPath } from "node:url";
31
40
  import { runNativeRetest } from "../../src/vector-cortex/encoder/native-qualify-retest.js";
41
+ import {
42
+ NATIVE_ORT_PACKAGE,
43
+ NATIVE_ORT_TARBALL_SHA256,
44
+ NATIVE_ORT_VERSION,
45
+ NATIVE_ORT_INSTALLABLE_PLATFORMS,
46
+ type EncoderPlatform,
47
+ } from "../../src/vector-cortex/encoder/native-install-artifacts.js";
32
48
  import type {
33
49
  SetupCortexActionResultWithNativeOrt,
34
50
  NativeOrtRetestResult,
35
51
  } from "./api-contracts/setup-cortex-native-ort.js";
36
52
 
37
- /** Locate scripts/encoder/install-native-ort.mjs by walking up to the repo root. */
38
- export function installScriptPath(): string | null {
39
- let dir = dirname(fileURLToPath(import.meta.url));
40
- const rel = join("scripts", "encoder", "install-native-ort.mjs");
41
- for (let i = 0; i < 8; i++) {
42
- const candidate = join(dir, rel);
43
- // guardrails-allow PREVENT-PI-004: local repo filesystem read (loopback)
44
- if (existsSync(candidate)) return candidate;
45
- const next = dirname(dir);
46
- if (next === dir) break;
47
- dir = next;
48
- }
49
- return null;
53
+ /** Candidate install roots: `MEGACOMPACT_NATIVE_ORT_ROOT` override first
54
+ * (ENC-2a parity + test isolation), else the default `~/.pi/mega-compact/
55
+ * native-ort/`. */
56
+ function nativeOrtDir(): string {
57
+ const override = process.env.MEGACOMPACT_NATIVE_ORT_ROOT;
58
+ if (override !== undefined && override.length > 0) return override;
59
+ return join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
60
+ }
61
+
62
+ /** Resolve the host to an installable EncoderPlatform string. darwin-x64 is
63
+ * UNSUPPORTED (no native binding upstream — arm64-only since 1.17) and
64
+ * unknown platforms also fail → the caller surfaces a clear failure. */
65
+ function hostPlatform(): EncoderPlatform | null {
66
+ const plat =
67
+ process.platform === "win32"
68
+ ? "win32"
69
+ : process.platform === "darwin"
70
+ ? "darwin"
71
+ : process.platform === "linux"
72
+ ? "linux"
73
+ : "";
74
+ const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : "";
75
+ const candidate = `${plat}-${arch}` as EncoderPlatform;
76
+ if (candidate === "darwin-x64") return null; // no native binding upstream
77
+ if (!NATIVE_ORT_INSTALLABLE_PLATFORMS.includes(candidate)) return null;
78
+ return candidate;
79
+ }
80
+
81
+ /** sha256 digest of a file on disk. Local FS read (loopback). */
82
+ function sha256File(path: string): string {
83
+ // guardrails-allow PREVENT-PI-004: local file hash (loopback)
84
+ return createHash("sha256").update(readFileSync(path)).digest("hex");
85
+ }
86
+
87
+ /** Write the small `.enc2a-marker.json` marker the ENC-2a version probe reads. */
88
+ function writeMarker(root: string, platform: EncoderPlatform): void {
89
+ const marker = {
90
+ platform,
91
+ version: NATIVE_ORT_VERSION,
92
+ installedAt: new Date().toISOString(),
93
+ sha256: NATIVE_ORT_TARBALL_SHA256,
94
+ };
95
+ // guardrails-allow PREVENT-PI-004: local marker write (loopback)
96
+ writeFileSync(
97
+ join(root, ".enc2a-marker.json"),
98
+ JSON.stringify(marker, null, 2) + "\n",
99
+ "utf8",
100
+ );
50
101
  }
51
102
 
52
103
  /** Ensure the vc9b log dir exists (mirrors setup-cortex-actions.ts). */
@@ -62,18 +113,38 @@ function writeLog(logPath: string, body: string): void {
62
113
  writeFileSync(logPath, body, "utf8");
63
114
  }
64
115
 
116
+ /** The original committed-install-script path lookup, kept for the unit test
117
+ * that proves the committed scripts/encoder/install-native-ort.mjs lives on
118
+ * disk in a checkout. The install action itself no longer spawns that script
119
+ * (in-process port), but the suite would otherwise need to lose that
120
+ * verification. */
121
+ export function installScriptPath(): string | null {
122
+ let dir = dirname(fileURLToPath(import.meta.url));
123
+ const rel = join("scripts", "encoder", "install-native-ort.mjs");
124
+ for (let i = 0; i < 8; i++) {
125
+ const candidate = join(dir, rel);
126
+ // guardrails-allow PREVENT-PI-004: local repo filesystem read (loopback)
127
+ if (existsSync(candidate)) return candidate;
128
+ const next = dirname(dir);
129
+ if (next === dir) break;
130
+ dir = next;
131
+ }
132
+ return null;
133
+ }
134
+
65
135
  /**
66
- * Run the ENC-2c lazy-download native onnxruntime INSTALL action. Locates and
67
- * spawns the committed install script (npm-delegated, sha256-verified), logs the
68
- * captured output, then ALWAYS runs the ENC-2b retest to re-qualify the binding
69
- * (regardless of install exit code) and surfaces the fresh result.
136
+ * Run the ENC-2c lazy-download native onnxruntime INSTALL action. Fetches the
137
+ * pinned tarball via the operator's npm, verifies its sha256, installs into
138
+ * `nativeOrtDir()`, then ALWAYS runs the ENC-2b retest to re-qualify the
139
+ * binding and surfacing the fresh result.
70
140
  *
71
- * Never throws: a missing script or non-zero exit is surfaced as ok=false on the
72
- * result; the retest runs even on install failure so the operator sees the
73
- * post-install qualification state. Returns a combined SetupCortexActionResult
74
- * with the ENC-2c additive fields (present only for pendant actions).
141
+ * Never throws: every failure (host platform, npm failure, hash mismatch)
142
+ * surfaces as ok=false on the result; the retest runs even on install failure
143
+ * so the operator sees the post-install qualification state. Returns a
144
+ * combined SetupCortexActionResult with the ENC-2c additive fields (present
145
+ * only for pendant actions).
75
146
  */
76
- // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install action (subprocess of committed repo script; no URL literals)
147
+ // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated install action (subprocess of committed npm tooling; no URL literals)
77
148
  export async function runInstallNativeOrt(
78
149
  stateDir: string,
79
150
  ): Promise<SetupCortexActionResultWithNativeOrt> {
@@ -81,41 +152,122 @@ export async function runInstallNativeOrt(
81
152
  const logName = `install-native-ort-${ts}.log`;
82
153
  const logPath = join(ensureLogDir(stateDir), logName);
83
154
 
84
- const scriptPath = installScriptPath();
85
- if (scriptPath === null) {
86
- writeLog(logPath, "install-native-ort.mjs not found in this checkout\n");
155
+ const root = nativeOrtDir();
156
+ const platform = hostPlatform();
157
+ if (platform === null) {
158
+ writeLog(logPath, "install-native-ort: host platform has no native binding\n");
87
159
  return {
88
160
  action: "install-native-ort",
89
161
  ok: false,
90
162
  exitCode: null,
91
163
  logPath,
92
164
  logName,
165
+ spawned: false,
166
+ };
167
+ }
168
+
169
+ // Step 1: derive the tarball URL + fetch the tarball via the operator's npm.
170
+ // (The tarball never lands in the final prefix until the pinned sha matches.)
171
+ mkdirSync(root, { recursive: true });
172
+ const packedName = `${NATIVE_ORT_PACKAGE}-${NATIVE_ORT_VERSION}.tgz`;
173
+ const packedPath = join(root, packedName);
174
+ let out = "";
175
+ const run = (argv: readonly string[]): { code: number; stdio: string } => {
176
+ const res = spawnSync("npm", argv, { encoding: "utf8", timeout: 60_000 });
177
+ out += [res.stdout, res.stderr].filter(Boolean).join("\n") + "\n";
178
+ return { code: res.status ?? 1, stdio: out };
179
+ };
180
+
181
+ // npm pack <pkg>@<ver> --pack-destination <root>
182
+ // guardrails-allow PREVENT-PI-004: npm-delegated tarball fetch (opt-in
183
+ // confirm-gated install action; package@version come from the committed
184
+ // artifacts module, never a literal URL).
185
+ const pack = run([
186
+ "pack",
187
+ `${NATIVE_ORT_PACKAGE}@${NATIVE_ORT_VERSION}`,
188
+ "--pack-destination",
189
+ root,
190
+ ]);
191
+ if (pack.code !== 0 || !existsSync(packedPath)) {
192
+ writeLog(logPath, `${out}npm pack failed — could not download tarball\n`);
193
+ const retest: NativeOrtRetestResult | null = await runNativeRetest(stateDir);
194
+ return {
195
+ action: "install-native-ort",
196
+ ok: false,
197
+ exitCode: pack.code,
198
+ logPath,
199
+ logName,
93
200
  spawned: true,
201
+ nativeOrtRetestResult: retest,
202
+ nativeOrtBackendEffective:
203
+ retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
94
204
  };
95
205
  }
96
206
 
97
- // guardrails-allow PREVENT-PI-004: opt-in, confirm-gated, npm-delegated
98
- // install subprocess (local spawn of committed repo script; no URL literals)
99
- const result = spawnSync(process.execPath, [scriptPath], {
100
- encoding: "utf8",
101
- timeout: 60_000,
102
- });
207
+ // Step 2: verify sha256 BEFORE install.
208
+ const actual = sha256File(packedPath);
209
+ if (actual !== NATIVE_ORT_TARBALL_SHA256) {
210
+ writeLog(
211
+ logPath,
212
+ `${out}sha256 mismatch — expected ${NATIVE_ORT_TARBALL_SHA256}, got ${actual}\n`,
213
+ );
214
+ // guardrails-allow PREVENT-PI-004: removing a tarball we just wrote (local FS)
215
+ rmSync(packedPath, { force: true });
216
+ const retest: NativeOrtRetestResult | null = await runNativeRetest(stateDir);
217
+ return {
218
+ action: "install-native-ort",
219
+ ok: false,
220
+ exitCode: 1,
221
+ logPath,
222
+ logName,
223
+ spawned: true,
224
+ nativeOrtRetestResult: retest,
225
+ nativeOrtBackendEffective:
226
+ retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
227
+ };
228
+ }
103
229
 
104
- const out = `${result.stdout ?? ""}${result.stderr ?? ""}`;
105
- writeLog(logPath, out || "(no output)\n");
230
+ // Step 3: install from the VERIFIED local tarball (npm install --prefix).
231
+ // guardrails-allow PREVENT-PI-004: npm-delegated install from a local tarball
232
+ // (opt-in confirm-gated install action).
233
+ const install = run(["install", "--prefix", root, packedPath]);
234
+ // guardrails-allow PREVENT-PI-004: removing the local tarball after install
235
+ rmSync(packedPath, { force: true });
106
236
 
107
- // Re-qualify AFTER install regardless of exit code (the retest is the source of
108
- // truth for whether the binding is actually usable).
237
+ const installedPkg = join(root, "node_modules", NATIVE_ORT_PACKAGE, "package.json");
238
+ if (install.code !== 0 || !existsSync(installedPkg)) {
239
+ writeLog(logPath, `${out}npm install from verified tarball failed\n`);
240
+ const retest: NativeOrtRetestResult | null = await runNativeRetest(stateDir);
241
+ return {
242
+ action: "install-native-ort",
243
+ ok: false,
244
+ exitCode: install.code,
245
+ logPath,
246
+ logName,
247
+ spawned: true,
248
+ nativeOrtRetestResult: retest,
249
+ nativeOrtBackendEffective:
250
+ retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
251
+ };
252
+ }
253
+
254
+ // Step 4: success — write the marker, log, then retest.
255
+ writeMarker(root, platform);
256
+ writeLog(
257
+ logPath,
258
+ `${out}installed ${NATIVE_ORT_PACKAGE}@${NATIVE_ORT_VERSION} (${platform}); sha256 verified + marker written.\n`,
259
+ );
109
260
  const retest: NativeOrtRetestResult | null = await runNativeRetest(stateDir);
110
261
 
111
262
  return {
112
263
  action: "install-native-ort",
113
- ok: result.status === 0,
114
- exitCode: result.status === null ? null : result.status,
264
+ ok: true,
265
+ exitCode: install.code,
115
266
  logPath,
116
267
  logName,
117
268
  spawned: true,
118
269
  nativeOrtRetestResult: retest,
119
- nativeOrtBackendEffective: retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
270
+ nativeOrtBackendEffective:
271
+ retest !== null && retest.verdict === "qualified" ? "native" : "wasm",
120
272
  };
121
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.74",
3
+ "version": "0.20.75",
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",
@@ -9,12 +9,15 @@
9
9
  *
10
10
  * ENC-2c turns ENC-2a's operator run-script assist into a dashboard action: the
11
11
  * Setup Cortex sub-tab gains an "Install Native ORT" button that, when confirmed
12
- * by the operator, runs the committed `scripts/encoder/install-native-ort.mjs`
13
- * subprocess locally (npm-delegated, sha256-verified) and then re-qualifies the
14
- * binding via the ENC-2b retest path. This is a PREVENT-PI-004 opt-in exemption:
15
- * it is confirm-gated (never automatic), delegated to a local subprocess of a
16
- * committed repo script, and carries NO URL literals in src/ or extensions/
17
- * (the registry URL + sha256 live only in the artifacts-module constants).
12
+ * by the operator, performs the pinned-tarball fetch + sha256 verify + npm
13
+ * install in-process (a TypeScript port of
14
+ * `scripts/encoder/install-native-ort.mjs` the npm package ships
15
+ * src/dist/extensions but NOT scripts/, so an installed device has no checkout
16
+ * script to spawn), then re-qualifies the binding via the ENC-2b retest path.
17
+ * This is a PREVENT-PI-004 opt-in exemption: it is confirm-gated (never
18
+ * automatic), delegated to the operator's npm as a local subprocess, and carries
19
+ * NO URL literals in src/ or extensions/ (the registry URL + sha256 live only
20
+ * in the artifacts-module constants).
18
21
  *
19
22
  * `MEGACOMPACT_ENC_2C=0` disables: no install action branch, no UI button, no
20
23
  * install-related result fields — byte-identical to the ENC-2b predecessor. The
@@ -39,12 +39,16 @@ import { NATIVE_ORT_PACKAGE, type EncoderPlatform } from "./native-install-artif
39
39
 
40
40
  /** Candidate ONNX runtime native-ort prefixes. The ENC-2a guide installs to
41
41
  * the global `~/.pi/mega-compact/native-ort/`; `stateDir` (per-repo) is a
42
- * secondary probe root so the retest resolves either install location. */
42
+ * secondary probe root so the retest resolves either install location.
43
+ * `MEGACOMPACT_NATIVE_ORT_ROOT` overrides the global root (ENC-2a parity +
44
+ * test isolation — honors the same override the enc2a probe and the ENC-2c
45
+ * in-process installer honor). */
43
46
  function nativeOrtRootCandidates(stateDir: string): string[] {
44
- return [
45
- join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort"),
46
- join(stateDir, "native-ort"),
47
- ];
47
+ const override = process.env.MEGACOMPACT_NATIVE_ORT_ROOT;
48
+ const global = override !== undefined && override.length > 0
49
+ ? override
50
+ : join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
51
+ return [global, join(stateDir, "native-ort")];
48
52
  }
49
53
 
50
54
  /** A single bounded inference pass on the fixed 512-token synthetic input;
@@ -261,9 +261,11 @@ const ACTION_GATE_CANDIDATES: Readonly<Record<SetupCortexActionKind, readonly st
261
261
  // behavior change. HG-7 is training work (no action in this set).
262
262
  bench: ["HG-1", "HG-3", "HG-6"],
263
263
  "verify-asset": [],
264
- // ENC-2c: installing the lazy-download native binding is gated by HG-3 (the
265
- // open install-budget hard gate) a closed HG-3 no longer blocks the install.
266
- "install-native-ort": ["HG-3"],
264
+ // install-native-ort is NEVER gated by HG-3: the action's entire purpose is
265
+ // to install the binding that closes HG-3. Gating it would deadlock — you
266
+ // can't install the binding that closes the gate because the gate blocks the
267
+ // install. HG-3 closes when the install succeeds (the probe detects it).
268
+ "install-native-ort": [],
267
269
  };
268
270
 
269
271
  /**