pi-mega-compact 0.20.38 → 0.20.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/vector-cortex-ml5c.js +28 -0
- package/dist/config/vector-cortex-ml5d.js +28 -0
- package/dist/config/vector-cortex.js +4 -3
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/cortex-improve.js +14 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints/registry-ext.js +13 -0
- package/dist/extensions/dashboard-server/route-dispatch.js +5 -1
- package/dist/extensions/dashboard-server/routes-cortex-improve.js +220 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
- package/dist/extensions/dashboard-server/routes.js +1 -0
- package/dist/extensions/mega-runtime/dashboard-snapshot.js +2 -2
- package/dist/src/config/vector-cortex-ml5c.js +28 -0
- package/dist/src/config/vector-cortex-ml5d.js +28 -0
- package/dist/src/config/vector-cortex.js +4 -3
- package/dist/src/config.js +1 -1
- package/dist/src/store/backfill.js +0 -9
- package/dist/src/vector-cortex/encoder/runtime-emit.js +42 -0
- package/dist/src/vector-cortex/encoder/runtime-native.js +77 -0
- package/dist/src/vector-cortex/encoder/runtime-select.js +122 -0
- package/dist/src/vector-cortex/encoder/runtime-stub.js +35 -0
- package/dist/src/vector-cortex/encoder/runtime-wasm.js +71 -0
- package/dist/src/vector-cortex/encoder/runtime.js +49 -61
- package/dist/src/vector-cortex/improve.js +24 -0
- package/dist/vector-cortex/encoder/runtime-emit.js +42 -0
- package/dist/vector-cortex/encoder/runtime-native.js +77 -0
- package/dist/vector-cortex/encoder/runtime-select.js +122 -0
- package/dist/vector-cortex/encoder/runtime-stub.js +35 -0
- package/dist/vector-cortex/encoder/runtime-wasm.js +71 -0
- package/dist/vector-cortex/encoder/runtime.js +49 -61
- package/dist/vector-cortex/improve.js +24 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-DjXp8u2Y.js → AreaChart-BT7YPcp7.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-DjXp8u2Y.js.map → AreaChart-BT7YPcp7.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-BZbus-dR.js → BarChart-DceGcBUh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-BZbus-dR.js.map → BarChart-DceGcBUh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-DQ2CjxVW.js → CacheTab-B9lCouRl.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-DQ2CjxVW.js.map → CacheTab-B9lCouRl.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DUpnOV1p.js → EventsTab-oqJ11jY7.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DUpnOV1p.js.map → EventsTab-oqJ11jY7.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-Bul_xjcn.js → HealthTab-Dbosf2Ik.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-Bul_xjcn.js.map → HealthTab-Dbosf2Ik.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLUjdKd3.js → MaintenanceTab-6TiApCVE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLUjdKd3.js.map → MaintenanceTab-6TiApCVE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-cBsE4mTf.js +2 -0
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BFy0hb6F.js.map → MemoryMapTab-cBsE4mTf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-BpYuUkq3.js → MetricsTab-CX-X9hhy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-BpYuUkq3.js.map → MetricsTab-CX-X9hhy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-z7yuT-uq.js → OverviewTab-CpPYaTJF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-z7yuT-uq.js.map → OverviewTab-CpPYaTJF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-ClORoDy_.js → ReposTab-D_Ot4QbU.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-ClORoDy_.js.map → ReposTab-D_Ot4QbU.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-CUpehIt9.js → SessionsTab-BUzO3iGK.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-CUpehIt9.js.map → SessionsTab-BUzO3iGK.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-Cii80Fdz.js → SetupTab-Be4w9v4j.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-Cii80Fdz.js.map → SetupTab-Be4w9v4j.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BV2iCSdV.js → TimeSavedCard-Cx-g6CXH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BV2iCSdV.js.map → TimeSavedCard-Cx-g6CXH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-1T86rHnD.js → TurnsTab-CC_7T7ad.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{TurnsTab-1T86rHnD.js.map → TurnsTab-CC_7T7ad.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-DKPleja8.js → VcStatusBadge-ZTItXSiH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-DKPleja8.js.map → VcStatusBadge-ZTItXSiH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DgAUZ4Pg.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DgAUZ4Pg.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/WikiTab-DnKupXTv.js +2 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-DKTILa1M.js.map → WikiTab-DnKupXTv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/button-CFt3e0yc.js +2 -0
- package/extensions/dashboard-client/dist/assets/{button-5fSU8BZj.js.map → button-CFt3e0yc.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-BFUnpXE_.js → card-C6ZjsHrl.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-BFUnpXE_.js.map → card-C6ZjsHrl.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/client-extra-DdEdGTIe.js +2 -0
- package/extensions/dashboard-client/dist/assets/client-extra-DdEdGTIe.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-xCzi6pWn.js → generateCategoricalChart-C9_fu2hc.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-xCzi6pWn.js.map → generateCategoricalChart-C9_fu2hc.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-DqjmZ88m.js → index-DY81TY4f.js} +11 -11
- package/extensions/dashboard-client/dist/assets/index-DY81TY4f.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{switch-CeZUPf_e.js → switch-BOqa1d6x.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-CeZUPf_e.js.map → switch-BOqa1d6x.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-MQQwdkwD.js → toggle-DToFaIEd.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-MQQwdkwD.js.map → toggle-DToFaIEd.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-BetS7QHN.js → useSSE-CZqkhU18.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BetS7QHN.js.map → useSSE-CZqkhU18.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/api/client-extra.ts +19 -1
- package/extensions/dashboard-client/src/components/ModelImprovementCard.tsx +141 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +6 -0
- package/extensions/dashboard-client/src/types/cortex-improve.ts +42 -0
- package/extensions/dashboard-server/api-contracts/cortex-improve.ts +82 -0
- package/extensions/dashboard-server/api-contracts/endpoints/registry-ext.ts +31 -0
- package/extensions/dashboard-server/api-contracts/index.ts +12 -0
- package/extensions/dashboard-server/route-dispatch.ts +4 -0
- package/extensions/dashboard-server/routes-cortex-improve.ts +256 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
- package/extensions/dashboard-server/routes.ts +4 -0
- package/extensions/mega-runtime/dashboard-snapshot.ts +2 -2
- package/package.json +1 -1
- package/src/config/vector-cortex-ml5c.ts +30 -0
- package/src/config/vector-cortex-ml5d.ts +30 -0
- package/src/config/vector-cortex.ts +4 -4
- package/src/config.ts +2 -0
- package/src/store/backfill.ts +0 -7
- package/src/vector-cortex/encoder/runtime-emit.ts +47 -0
- package/src/vector-cortex/encoder/runtime-native.ts +117 -0
- package/src/vector-cortex/encoder/runtime-select.ts +167 -0
- package/src/vector-cortex/encoder/runtime-stub.ts +38 -0
- package/src/vector-cortex/encoder/runtime-wasm.ts +110 -0
- package/src/vector-cortex/encoder/runtime.ts +59 -66
- package/src/vector-cortex/improve.ts +28 -0
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-BFy0hb6F.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BRzvd_pU.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BRzvd_pU.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/WikiTab-DKTILa1M.js +0 -2
- package/extensions/dashboard-client/dist/assets/button-5fSU8BZj.js +0 -2
- package/extensions/dashboard-client/dist/assets/client-extra-BZbw21wu.js +0 -2
- package/extensions/dashboard-client/dist/assets/client-extra-BZbw21wu.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-DqjmZ88m.js.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-ml5c.ts — ML5-C runtime decision + packaging flag.
|
|
3
|
+
*
|
|
4
|
+
* Sibling extract mirroring vector-cortex-ml5a.ts / vector-cortex-ml5b.ts, so
|
|
5
|
+
* vector-cortex.ts stays under its 300-line soft limit (soft-as-hard gate).
|
|
6
|
+
* This is the ONNX Runtime backend selection + packaging sprint flag.
|
|
7
|
+
* vector-cortex.ts re-exports the ENUM below and root src/config.ts re-exports
|
|
8
|
+
* it, so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ML5-C selects the ONNX runtime backend (WASM vs native) based on the ML5-B
|
|
11
|
+
* bench record and platform support. The flag gates the runtime-selection
|
|
12
|
+
* dispatch only; when OFF the encoder serves mode B trigram exactly as before
|
|
13
|
+
* (byte-identical to the ML5-B survivor — no `vector_cortex_runtime_selected`
|
|
14
|
+
* event is emitted, no session-selection dispatch runs).
|
|
15
|
+
*
|
|
16
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
17
|
+
*/
|
|
18
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
19
|
+
/**
|
|
20
|
+
* ML5-C — runtime decision + packaging (WASM vs native). Default ON.
|
|
21
|
+
* `MEGACOMPACT_ML5_C=0` disables and is byte-identical to the ML5-B survivor:
|
|
22
|
+
* no runtime selection runs — the encoder continues to serve mode B trigram,
|
|
23
|
+
* exactly as before, with no `vector_cortex_runtime_selected` event emitted.
|
|
24
|
+
* The flag gates the runtime-selection dispatch only; it does not gate the
|
|
25
|
+
* underlying WASM/native backends (which are exercised by ML5-B's bench
|
|
26
|
+
* harness and ML5-A's trained asset independently).
|
|
27
|
+
*/
|
|
28
|
+
export const ML5C_ENABLED = () => sprintFlag("MEGACOMPACT_ML5_C");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-ml5d.ts — ML5-D dashboard "Improve Cortex" flag.
|
|
3
|
+
*
|
|
4
|
+
* Sibling extract mirroring vector-cortex-ml5a.ts / vector-cortex-ml5b.ts /
|
|
5
|
+
* vector-cortex-ml5c.ts, so vector-cortex.ts stays under its 300-line soft
|
|
6
|
+
* limit (soft-as-hard gate). This is the dashboard "Improve Cortex" surface +
|
|
7
|
+
* promote workflow sprint flag.
|
|
8
|
+
* vector-cortex.ts re-exports the ENUM below and root src/config.ts re-exports
|
|
9
|
+
* it, so no consumer import path changes.
|
|
10
|
+
*
|
|
11
|
+
* ML5-D adds the dashboard ModelImprovementCard + the POST /api/cortex/improve
|
|
12
|
+
* and GET /api/cortex/improve/status/:jobId endpoints. The flag gates that
|
|
13
|
+
* surface only; when OFF the endpoints return 404/disabled and VectorCortexTab
|
|
14
|
+
* renders exactly as before (byte-identical to the ML5-C-era tab — no
|
|
15
|
+
* ModelImprovementCard, no improve job is ever spawned).
|
|
16
|
+
*
|
|
17
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
18
|
+
*/
|
|
19
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
20
|
+
/**
|
|
21
|
+
* ML5-D — dashboard "Improve Cortex" surface + promote workflow. Default ON.
|
|
22
|
+
* `MEGACOMPACT_ML5_D=0` disables and is byte-identical to the ML5-C survivor:
|
|
23
|
+
* both `/api/cortex/improve*` endpoints return 404 and VectorCortexTab omits the
|
|
24
|
+
* ModelImprovementCard. The flag gates the dashboard surface only; it does not
|
|
25
|
+
* gate the underlying ML5-A training pipeline or the encoder's mode-A/B/C
|
|
26
|
+
* selection (those are governed by ML5-A and the encoder independently).
|
|
27
|
+
*/
|
|
28
|
+
export const ML5D_ENABLED = () => sprintFlag("MEGACOMPACT_ML5_D");
|
|
@@ -239,10 +239,9 @@ export const VC8A_ENABLED = () => sprintFlag("MEGACOMPACT_VC8A");
|
|
|
239
239
|
* mirroring VC4A..VC8A.
|
|
240
240
|
*/
|
|
241
241
|
export const VC8B_ENABLED = () => sprintFlag("MEGACOMPACT_VC8B");
|
|
242
|
-
// VC8C (canary selection + Rust parity) extracted to vector-cortex-vc8c.ts;
|
|
243
|
-
// re-exported so existing `./config/vector-cortex.js` imports keep resolving.
|
|
242
|
+
// VC8C (canary selection + Rust parity) extracted to vector-cortex-vc8c.ts; re-exported so existing imports keep resolving.
|
|
244
243
|
export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
|
|
245
|
-
//
|
|
244
|
+
// Sibling extracts to stay under the 300-line soft limit.
|
|
246
245
|
export { VC9A_ENABLED } from "./vector-cortex-vc9a.js";
|
|
247
246
|
export { VC9B_ENABLED } from "./vector-cortex-vc9b.js";
|
|
248
247
|
export { VC9C_ENABLED } from "./vector-cortex-vc9c.js";
|
|
@@ -250,5 +249,7 @@ export { VC9D_ENABLED } from "./vector-cortex-vc9d.js";
|
|
|
250
249
|
export { PCC_ENABLED } from "./vector-cortex-pcc.js";
|
|
251
250
|
export { ML5A_ENABLED } from "./vector-cortex-ml5a.js";
|
|
252
251
|
export { ML5B_ENABLED } from "./vector-cortex-ml5b.js";
|
|
252
|
+
export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
|
|
253
|
+
export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
|
|
253
254
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
254
255
|
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, 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, 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,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/cortex-improve.ts — ML5-D "Improve Cortex" job API types.
|
|
3
|
+
*
|
|
4
|
+
* Types for POST /api/cortex/improve (launch a local ML5-A training job that
|
|
5
|
+
* re-qualifies the five heads against the latest local corpus) and GET
|
|
6
|
+
* /api/cortex/improve/status/:jobId (poll the in-process job state to a
|
|
7
|
+
* terminal qualified / demoted_to_B verdict). Local-only, aggregate surfaces:
|
|
8
|
+
* mode / verdict / digest / reason / progress — never message content or corpus
|
|
9
|
+
* rows (EVAL-REDACT-002).
|
|
10
|
+
*
|
|
11
|
+
* PREVENT-PI-004: type definitions only, no network code.
|
|
12
|
+
* PREVENT-011: no `any` type — all types are explicit.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
@@ -54,4 +54,17 @@ export const EXTRA_ENDPOINTS = {
|
|
|
54
54
|
path: "/api/prefix-stability",
|
|
55
55
|
description: "Per-turn prompt-cache stable-prefix ratio trend (GET /api/prefix-stability?limit=N) read from prefix_stability rows in the local events log. Flag-off (MEGACOMPACT_PC_C=0) returns 404.",
|
|
56
56
|
},
|
|
57
|
+
// ─── ML5-D Improve Cortex (dashboard Vector Cortex tab) ───────────
|
|
58
|
+
/** POST /api/cortex/improve — launch a local ML5-A training job. */
|
|
59
|
+
improveCortex: {
|
|
60
|
+
method: "POST",
|
|
61
|
+
path: "/api/cortex/improve",
|
|
62
|
+
description: "Launch a local ML5-A training job that re-qualifies the five heads against the latest local corpus and returns an opaque jobId. Requires confirm:true; flag-off returns 404. Local-only — never fetches anything.",
|
|
63
|
+
},
|
|
64
|
+
/** GET /api/cortex/improve/status/:jobId — poll an improve job. */
|
|
65
|
+
improveCortexStatus: {
|
|
66
|
+
method: "GET",
|
|
67
|
+
path: "/api/cortex/improve/status/:jobId",
|
|
68
|
+
description: "Poll an in-process Cortex improve job to terminal qualified / demoted_to_B. Unknown jobId or flag-off returns 404. Read-only, in-memory job state.",
|
|
69
|
+
},
|
|
57
70
|
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* PREVENT-PI-004: local filesystem read only, no network.
|
|
9
9
|
* PREVENT-011: no `any` type.
|
|
10
10
|
*/
|
|
11
|
-
import { handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerfSamples, handlePerf, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleMemoryStatus, handleCacheStripes, handlePrefixStability, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, handleSetupCortexStatus, handleSetupCortexAction, handleSetupCortexActionLog, } from "./routes.js";
|
|
11
|
+
import { handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerfSamples, handlePerf, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleMemoryStatus, handleCacheStripes, handlePrefixStability, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, handleSetupCortexStatus, handleSetupCortexAction, handleSetupCortexActionLog, handleImproveCortex, handleImproveCortexStatus, } from "./routes.js";
|
|
12
12
|
// VC6C repair lives in its own module (routes-vector-cortex-repair.ts) so the
|
|
13
13
|
// heal route file stays well under the 400-line extension soft limit.
|
|
14
14
|
import { handleVectorCortexRepair } from "./routes-vector-cortex-repair.js";
|
|
@@ -149,5 +149,9 @@ export function dispatchRoutes(req, res, ctx) {
|
|
|
149
149
|
return true;
|
|
150
150
|
if (handleSetupCortexActionLog(req, res, ctx))
|
|
151
151
|
return true;
|
|
152
|
+
if (handleImproveCortex(req, res, ctx))
|
|
153
|
+
return true;
|
|
154
|
+
if (handleImproveCortexStatus(req, res, ctx))
|
|
155
|
+
return true;
|
|
152
156
|
return false;
|
|
153
157
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-cortex-improve.ts — ML5-D "Improve Cortex" job routes.
|
|
3
|
+
*
|
|
4
|
+
* POST /api/cortex/improve — confirmation-gated local ML5-A training
|
|
5
|
+
* GET /api/cortex/improve/status/:jobId — poll an in-process job to terminal
|
|
6
|
+
*
|
|
7
|
+
* The Improve action launches the committed ML5-A training pipeline
|
|
8
|
+
* (training/vector-cortex/train.py) as a background child_process against the
|
|
9
|
+
* latest local corpus, then re-qualifies the five heads. Job state is kept
|
|
10
|
+
* in-process in a Map<jobId, JobState> on this module; nothing is persisted
|
|
11
|
+
* across restarts (the status endpoint is read-only, in-memory).
|
|
12
|
+
*
|
|
13
|
+
* LOCAL ONLY (PREVENT-PI-004): the job spawns a local python process and reads
|
|
14
|
+
* local files — never a fetch. The `onnxruntime-node` native path is attempted
|
|
15
|
+
* only when MEGACOMPACT_ENCODER_NATIVE=1 (default OFF); otherwise the harness
|
|
16
|
+
* uses the WASM/trigram fallback. The status payload surfaces mode/verdict/
|
|
17
|
+
* digest/reason/progress only — never message or corpus content (EVAL-REDACT-002).
|
|
18
|
+
*
|
|
19
|
+
* Guardrails: PREVENT-011 (no `any`), PREVENT-001 (guarded JSON.parse via
|
|
20
|
+
* readJsonBody), flag-off byte-identical (no card + endpoints 404).
|
|
21
|
+
*/
|
|
22
|
+
import { spawn } from "node:child_process";
|
|
23
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
24
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
25
|
+
import { join, dirname } from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
import { sendJson, readJsonBody } from "./routes-vector-cortex-shared.js";
|
|
28
|
+
import { ML5D_ENABLED } from "../../src/config.js";
|
|
29
|
+
import { qualifyDecision } from "../../src/vector-cortex/improve.js";
|
|
30
|
+
/** Resolve the committed training entry by walking up to the repo root. */
|
|
31
|
+
function trainingScript() {
|
|
32
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const rel = join("training", "vector-cortex", "train.py");
|
|
34
|
+
for (let i = 0; i < 8; i++) {
|
|
35
|
+
// guardrails-allow PREVENT-PI-004: local script read (loopback)
|
|
36
|
+
const candidate = join(dir, rel);
|
|
37
|
+
if (existsSync(candidate))
|
|
38
|
+
return candidate;
|
|
39
|
+
const next = dirname(dir);
|
|
40
|
+
if (next === dir)
|
|
41
|
+
break;
|
|
42
|
+
dir = next;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/** In-process job registry; nothing survives a server restart. */
|
|
47
|
+
const JOBS = new Map();
|
|
48
|
+
/** Opaque job token: sha256(ts+random) hex-sliced. */
|
|
49
|
+
function newJobId() {
|
|
50
|
+
return createHash("sha256")
|
|
51
|
+
.update(`${Date.now()}:${randomBytes(16).toString("hex")}`)
|
|
52
|
+
.digest("hex")
|
|
53
|
+
.slice(0, 24);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Spawn the ML5-A training pipeline in the background and drive the job state
|
|
57
|
+
* to a terminal qualified / demoted_to_B verdict. Honest: an empty corpus (the
|
|
58
|
+
* host state) makes train.py no-op and the job ends demoted_to_B.
|
|
59
|
+
*/
|
|
60
|
+
function startJob(jobId) {
|
|
61
|
+
const script = trainingScript();
|
|
62
|
+
const boot = Date.now();
|
|
63
|
+
JOBS.set(jobId, { status: "improving", progress: 0, updatedAt: new Date().toISOString() });
|
|
64
|
+
if (script === null) {
|
|
65
|
+
settle(jobId, { status: "demoted_to_B", reason: "ENC_TRAIN_PIPELINE_ABSENT", progress: 1 });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const env = { ...process.env };
|
|
69
|
+
const proc = spawn("python3", [script], {
|
|
70
|
+
env,
|
|
71
|
+
cwd: join(dirname(script), "..", ".."),
|
|
72
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
73
|
+
});
|
|
74
|
+
let output = "";
|
|
75
|
+
const step = () => {
|
|
76
|
+
const pct = Math.min(0.9, 0.1 + ((Date.now() - boot) / 60000) * 0.6);
|
|
77
|
+
const cur = JOBS.get(jobId);
|
|
78
|
+
if (cur && cur.status === "improving" && pct > cur.progress) {
|
|
79
|
+
JOBS.set(jobId, { ...cur, progress: pct, updatedAt: new Date().toISOString() });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const timer = setInterval(step, 2000);
|
|
83
|
+
const stop = () => clearInterval(timer);
|
|
84
|
+
proc.stdout?.on("data", (d) => {
|
|
85
|
+
output += d.toString();
|
|
86
|
+
});
|
|
87
|
+
proc.stderr?.on("data", (d) => {
|
|
88
|
+
output += d.toString();
|
|
89
|
+
});
|
|
90
|
+
proc.on("error", (err) => {
|
|
91
|
+
stop();
|
|
92
|
+
settle(jobId, {
|
|
93
|
+
status: "demoted_to_B",
|
|
94
|
+
reason: `ENC_TRAIN_SPAWN_FAILED:${err.message}`,
|
|
95
|
+
progress: 1,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
proc.on("close", (code) => {
|
|
99
|
+
stop();
|
|
100
|
+
// Read the produced trained-heads artifact digest. The report line includes
|
|
101
|
+
// `trainedHeadsPath`; verify the file exists after a successful run.
|
|
102
|
+
const match = /trainedHeadsPath":\s*"([^"]+)"/.exec(output);
|
|
103
|
+
const assetPath = match?.[1];
|
|
104
|
+
let digest = null;
|
|
105
|
+
if (assetPath) {
|
|
106
|
+
// guardrails-allow PREVENT-PI-004: local artifact read (loopback)
|
|
107
|
+
try {
|
|
108
|
+
digest = createHash("sha256")
|
|
109
|
+
.update(readFileSync(assetPath))
|
|
110
|
+
.digest("hex")
|
|
111
|
+
.slice(0, 12);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
digest = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const decision = qualifyDecision(code ?? -1, digest);
|
|
118
|
+
if (decision === "qualified") {
|
|
119
|
+
settle(jobId, {
|
|
120
|
+
status: "qualified",
|
|
121
|
+
progress: 1,
|
|
122
|
+
assetDigest: digest ?? undefined,
|
|
123
|
+
verdict: { mode: "A", assetDigestPrefix: digest ?? null, verdict: "qualified" },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
settle(jobId, {
|
|
128
|
+
status: "demoted_to_B",
|
|
129
|
+
reason: assetPath
|
|
130
|
+
? "trained asset did not verify — demoted to mode B"
|
|
131
|
+
: "empty corpus (no groups) — no qualified asset emitted",
|
|
132
|
+
progress: 1,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Write a terminal job state (idempotent — only advances from improving). */
|
|
138
|
+
function settle(jobId, terminal) {
|
|
139
|
+
const cur = JOBS.get(jobId);
|
|
140
|
+
if (cur && cur.status !== "improving")
|
|
141
|
+
return;
|
|
142
|
+
JOBS.set(jobId, { ...terminal, updatedAt: new Date().toISOString() });
|
|
143
|
+
}
|
|
144
|
+
/** Flag-off response, byte-identical regardless of request (ML5-D absent). */
|
|
145
|
+
function sendDisabled(res) {
|
|
146
|
+
sendJson(res, 404, { error: "disabled" });
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* POST /api/cortex/improve (ML5-D). Returns true when it claims the request.
|
|
150
|
+
* Requires `confirm:true` server-side (mirrors the client window.confirm).
|
|
151
|
+
*/
|
|
152
|
+
export function handleImproveCortex(req, res, _ctx) {
|
|
153
|
+
const url = req.url ?? "";
|
|
154
|
+
if (url !== "/api/cortex/improve")
|
|
155
|
+
return false;
|
|
156
|
+
if (req.method !== "POST") {
|
|
157
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (!ML5D_ENABLED()) {
|
|
161
|
+
sendDisabled(res);
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
readJsonBody(req, (parsed) => {
|
|
165
|
+
if (!parsed.ok) {
|
|
166
|
+
sendJson(res, 400, { error: "invalid_body" });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (parsed.value.confirm !== true) {
|
|
170
|
+
sendJson(res, 400, { error: "confirmation_required" });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const jobId = newJobId();
|
|
174
|
+
startJob(jobId);
|
|
175
|
+
const body = { status: "improving", jobId };
|
|
176
|
+
sendJson(res, 200, body);
|
|
177
|
+
});
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* GET /api/cortex/improve/status/:jobId (ML5-D). Returns true when it claims the
|
|
182
|
+
* request. Flag-off or unknown jobId → 404. Read-only in-memory.
|
|
183
|
+
*/
|
|
184
|
+
export function handleImproveCortexStatus(req, res, _ctx) {
|
|
185
|
+
const url = req.url ?? "";
|
|
186
|
+
const match = /^\/api\/cortex\/improve\/status\/([A-Za-z0-9]+)$/.exec(url);
|
|
187
|
+
if (!match)
|
|
188
|
+
return false;
|
|
189
|
+
if (req.method !== "GET") {
|
|
190
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (!ML5D_ENABLED()) {
|
|
194
|
+
sendDisabled(res);
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
const job = JOBS.get(match[1]);
|
|
198
|
+
if (!job) {
|
|
199
|
+
sendJson(res, 404, { error: "job_not_found" });
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
// Narrow job.status into the discriminated CortexImproveStatus variant. The
|
|
203
|
+
// terminal shapes require their payload fields, so construct per-state.
|
|
204
|
+
const body = job.status === "improving"
|
|
205
|
+
? { status: "improving", progress: job.progress }
|
|
206
|
+
: job.status === "qualified"
|
|
207
|
+
? {
|
|
208
|
+
status: "qualified",
|
|
209
|
+
progress: job.progress,
|
|
210
|
+
verdict: job.verdict ?? { mode: "A", assetDigestPrefix: null, verdict: "qualified" },
|
|
211
|
+
assetDigest: job.assetDigest ?? "",
|
|
212
|
+
}
|
|
213
|
+
: {
|
|
214
|
+
status: "demoted_to_B",
|
|
215
|
+
progress: job.progress,
|
|
216
|
+
reason: job.reason ?? "UNKNOWN_TERMINAL",
|
|
217
|
+
};
|
|
218
|
+
sendJson(res, 200, body);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
@@ -54,5 +54,7 @@ export const VECTOR_CORTEX_SETTINGS = {
|
|
|
54
54
|
boolDirect("MEGACOMPACT_VC9D", "VC9D Embedder Detect Consolidation", "Embedder-detect consolidation + VC9 workstream roll-up: memoizes /api/setup-detect against the mutable input (resolved binary path + mtime) so consecutive requests reuse the result without re-spawning, and unifies the embedder + cortex sub-tabs' 5s poll contract. OFF = byte-identical predecessor (VC9C-era): detect spawns fresh per request and the embedder poll keeps its previous cadence.", true),
|
|
55
55
|
boolDirect("MEGACOMPACT_PC_C", "PC-C Dashboard Cache Visibility", "Dashboard per-turn prompt-cache visibility: surfaces the per-turn stable-prefix ratio trend (GET /api/prefix-stability) in the CacheTab PrefixStabilityCard. Reads aggregate ratios/counts from the local monitoring events log only — no payload bytes. OFF = byte-identical predecessor (PC-B-era): /api/prefix-stability returns 404 and the CacheTab omits the PrefixStabilityCard.", true),
|
|
56
56
|
boolDirect("MEGACOMPACT_ML5_A", "ML5-A Five-Head Training Load", "ML5-A real trained-head loading: loadHeadProjections (trained-heads-v1) feeds selectQualifiedEncoder (trainedHeadsPath atomic demotion) + loadCalibrationV1. ON (default) = a pinned trained-heads path must load for mode A. OFF = loaders return null and selection ignores trainedHeadsPath — byte-identical to the placeholder-weighted VC2C path.", true),
|
|
57
|
+
boolDirect("MEGACOMPACT_ML5_C", "ML5-C Runtime Decision + Packaging", "ML5-C runtime backend selection (WASM vs native): selects the ONNX runtime backend based on the ML5-B bench record and platform support. ON (default) = the runtime-selection dispatch runs and emits vector_cortex_runtime_selected. OFF = no selection runs — encoder serves mode B trigram, byte-identical to ML5-B.", true),
|
|
58
|
+
boolDirect("MEGACOMPACT_ML5_D", "ML5-D Dashboard Improve Cortex", "ML5-D dashboard 'Improve Cortex' surface: the ModelImprovementCard + POST /api/cortex/improve + GET /api/cortex/improve/status/:jobId. ON (default) = the card renders and Improve launches a local ML5-A training job. OFF = both improve endpoints return 404 and VectorCortexTab omits the card, byte-identical to ML5-C.", true),
|
|
57
59
|
],
|
|
58
60
|
};
|
|
@@ -27,3 +27,4 @@ export { handleWiki } from "./routes-wiki.js";
|
|
|
27
27
|
export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, } from "./routes-vector-cortex.js";
|
|
28
28
|
export { handleSetupCortexStatus } from "./routes-setup-cortex.js";
|
|
29
29
|
export { handleSetupCortexAction, handleSetupCortexActionLog, } from "./routes-setup-cortex-actions.js";
|
|
30
|
+
export { handleImproveCortex, handleImproveCortexStatus, } from "./routes-cortex-improve.js";
|
|
@@ -97,8 +97,8 @@ export function buildDashboardSnapshot(ctx) {
|
|
|
97
97
|
// per-session in rt and there's no cumulative counter yet.
|
|
98
98
|
total: ctx.repo.dedupCollapsed,
|
|
99
99
|
sessionTokensSaved: ctx.rt.cacheHitTokens,
|
|
100
|
-
// Cumulative tokens saved across all sessions in this repo
|
|
101
|
-
//
|
|
100
|
+
// Cumulative tokens saved across all sessions in this repo = the
|
|
101
|
+
// real repo counter (audit Table 1 stub 8 closed — no rolled-up math).
|
|
102
102
|
totalTokensSaved: ctx.repo.tokensSaved,
|
|
103
103
|
},
|
|
104
104
|
compacts: {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-ml5c.ts — ML5-C runtime decision + packaging flag.
|
|
3
|
+
*
|
|
4
|
+
* Sibling extract mirroring vector-cortex-ml5a.ts / vector-cortex-ml5b.ts, so
|
|
5
|
+
* vector-cortex.ts stays under its 300-line soft limit (soft-as-hard gate).
|
|
6
|
+
* This is the ONNX Runtime backend selection + packaging sprint flag.
|
|
7
|
+
* vector-cortex.ts re-exports the ENUM below and root src/config.ts re-exports
|
|
8
|
+
* it, so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ML5-C selects the ONNX runtime backend (WASM vs native) based on the ML5-B
|
|
11
|
+
* bench record and platform support. The flag gates the runtime-selection
|
|
12
|
+
* dispatch only; when OFF the encoder serves mode B trigram exactly as before
|
|
13
|
+
* (byte-identical to the ML5-B survivor — no `vector_cortex_runtime_selected`
|
|
14
|
+
* event is emitted, no session-selection dispatch runs).
|
|
15
|
+
*
|
|
16
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
17
|
+
*/
|
|
18
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
19
|
+
/**
|
|
20
|
+
* ML5-C — runtime decision + packaging (WASM vs native). Default ON.
|
|
21
|
+
* `MEGACOMPACT_ML5_C=0` disables and is byte-identical to the ML5-B survivor:
|
|
22
|
+
* no runtime selection runs — the encoder continues to serve mode B trigram,
|
|
23
|
+
* exactly as before, with no `vector_cortex_runtime_selected` event emitted.
|
|
24
|
+
* The flag gates the runtime-selection dispatch only; it does not gate the
|
|
25
|
+
* underlying WASM/native backends (which are exercised by ML5-B's bench
|
|
26
|
+
* harness and ML5-A's trained asset independently).
|
|
27
|
+
*/
|
|
28
|
+
export const ML5C_ENABLED = () => sprintFlag("MEGACOMPACT_ML5_C");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-ml5d.ts — ML5-D dashboard "Improve Cortex" flag.
|
|
3
|
+
*
|
|
4
|
+
* Sibling extract mirroring vector-cortex-ml5a.ts / vector-cortex-ml5b.ts /
|
|
5
|
+
* vector-cortex-ml5c.ts, so vector-cortex.ts stays under its 300-line soft
|
|
6
|
+
* limit (soft-as-hard gate). This is the dashboard "Improve Cortex" surface +
|
|
7
|
+
* promote workflow sprint flag.
|
|
8
|
+
* vector-cortex.ts re-exports the ENUM below and root src/config.ts re-exports
|
|
9
|
+
* it, so no consumer import path changes.
|
|
10
|
+
*
|
|
11
|
+
* ML5-D adds the dashboard ModelImprovementCard + the POST /api/cortex/improve
|
|
12
|
+
* and GET /api/cortex/improve/status/:jobId endpoints. The flag gates that
|
|
13
|
+
* surface only; when OFF the endpoints return 404/disabled and VectorCortexTab
|
|
14
|
+
* renders exactly as before (byte-identical to the ML5-C-era tab — no
|
|
15
|
+
* ModelImprovementCard, no improve job is ever spawned).
|
|
16
|
+
*
|
|
17
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
18
|
+
*/
|
|
19
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
20
|
+
/**
|
|
21
|
+
* ML5-D — dashboard "Improve Cortex" surface + promote workflow. Default ON.
|
|
22
|
+
* `MEGACOMPACT_ML5_D=0` disables and is byte-identical to the ML5-C survivor:
|
|
23
|
+
* both `/api/cortex/improve*` endpoints return 404 and VectorCortexTab omits the
|
|
24
|
+
* ModelImprovementCard. The flag gates the dashboard surface only; it does not
|
|
25
|
+
* gate the underlying ML5-A training pipeline or the encoder's mode-A/B/C
|
|
26
|
+
* selection (those are governed by ML5-A and the encoder independently).
|
|
27
|
+
*/
|
|
28
|
+
export const ML5D_ENABLED = () => sprintFlag("MEGACOMPACT_ML5_D");
|
|
@@ -239,10 +239,9 @@ export const VC8A_ENABLED = () => sprintFlag("MEGACOMPACT_VC8A");
|
|
|
239
239
|
* mirroring VC4A..VC8A.
|
|
240
240
|
*/
|
|
241
241
|
export const VC8B_ENABLED = () => sprintFlag("MEGACOMPACT_VC8B");
|
|
242
|
-
// VC8C (canary selection + Rust parity) extracted to vector-cortex-vc8c.ts;
|
|
243
|
-
// re-exported so existing `./config/vector-cortex.js` imports keep resolving.
|
|
242
|
+
// VC8C (canary selection + Rust parity) extracted to vector-cortex-vc8c.ts; re-exported so existing imports keep resolving.
|
|
244
243
|
export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
|
|
245
|
-
//
|
|
244
|
+
// Sibling extracts to stay under the 300-line soft limit.
|
|
246
245
|
export { VC9A_ENABLED } from "./vector-cortex-vc9a.js";
|
|
247
246
|
export { VC9B_ENABLED } from "./vector-cortex-vc9b.js";
|
|
248
247
|
export { VC9C_ENABLED } from "./vector-cortex-vc9c.js";
|
|
@@ -250,5 +249,7 @@ export { VC9D_ENABLED } from "./vector-cortex-vc9d.js";
|
|
|
250
249
|
export { PCC_ENABLED } from "./vector-cortex-pcc.js";
|
|
251
250
|
export { ML5A_ENABLED } from "./vector-cortex-ml5a.js";
|
|
252
251
|
export { ML5B_ENABLED } from "./vector-cortex-ml5b.js";
|
|
252
|
+
export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
|
|
253
|
+
export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
|
|
253
254
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
254
255
|
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/src/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, 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, 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";
|
|
@@ -24,7 +24,6 @@ import { buildRaptorTree } from "../dedup/raptor/tree.js";
|
|
|
24
24
|
import { defaultEmbedder } from "../embedder.js";
|
|
25
25
|
import { getStateDir } from "../store.js";
|
|
26
26
|
const BATCH = 1000;
|
|
27
|
-
const THROTTLE_MS = 0; // synchronous backfill; no cross-process yield needed
|
|
28
27
|
function ensureProgressTable(db) {
|
|
29
28
|
db.exec(`
|
|
30
29
|
CREATE TABLE IF NOT EXISTS backfill_progress (
|
|
@@ -92,10 +91,6 @@ export function backfillContentHashes(stateDir = getStateDir()) {
|
|
|
92
91
|
withTx(db, () => applyRows(pending));
|
|
93
92
|
db.prepare("INSERT INTO backfill_progress(name, last_session_id, last_id, updated, duplicates_resolved) VALUES('content_hashes',?,?,?,?) ON CONFLICT(name) DO UPDATE SET last_session_id=excluded.last_session_id, last_id=excluded.last_id, updated=excluded.updated, duplicates_resolved=excluded.duplicates_resolved").run(lastSid, lastId, updated, duplicatesResolved);
|
|
94
93
|
}
|
|
95
|
-
if (THROTTLE_MS > 0) {
|
|
96
|
-
// No-op in this synchronous build; placeholder for future streaming backfill.
|
|
97
|
-
// guardrails-allow PREVENT-STUB-001: ML5-C
|
|
98
|
-
}
|
|
99
94
|
return { processed, updated, duplicatesResolved };
|
|
100
95
|
}
|
|
101
96
|
/** True when no rows remain pending (backfill complete for this state dir). */
|
|
@@ -151,10 +146,6 @@ export function backfillPhase(phase, sessionId, stateDir, opts = {}) {
|
|
|
151
146
|
});
|
|
152
147
|
savePhaseCursor(db, phase, cursor ?? null, processed);
|
|
153
148
|
batches++;
|
|
154
|
-
if (THROTTLE_MS > 0) {
|
|
155
|
-
const end = Date.now() + THROTTLE_MS;
|
|
156
|
-
while (Date.now() < end) { /* throttle */ }
|
|
157
|
-
}
|
|
158
149
|
if (opts.interruptAfterBatches && batches >= opts.interruptAfterBatches) {
|
|
159
150
|
interrupted = true;
|
|
160
151
|
break;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/encoder/runtime-emit.ts — ML5-C seller event emitter.
|
|
3
|
+
*
|
|
4
|
+
* Emits the `vector_cortex_runtime_selected` seller event to the local
|
|
5
|
+
* events.log so the dashboard Setup Cortex blockers card can surface the HG-3
|
|
6
|
+
* (install budget) / HG-4 (darwin-x64 demotion) closure state. Aggregate
|
|
7
|
+
* fields only — never payload bytes (EVAL-REDACT-002).
|
|
8
|
+
*
|
|
9
|
+
* Extracted from runtime.ts so the runtime delegate-shell stays under the
|
|
10
|
+
* 300-line soft limit after the ML5-C dispatch was added. All writes are
|
|
11
|
+
* best-effort / non-fatal; a disk-full or missing state dir never breaks the
|
|
12
|
+
* encoder loop.
|
|
13
|
+
*
|
|
14
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 — local filesystem append only;
|
|
15
|
+
* no network). No `any` (PREVENT-011).
|
|
16
|
+
*/
|
|
17
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
18
|
+
import { dirname } from "node:path";
|
|
19
|
+
import { defaultEventsPath } from "../../monitoring.js";
|
|
20
|
+
/**
|
|
21
|
+
* Emit the ML5-C `vector_cortex_runtime_selected` seller event (best-effort).
|
|
22
|
+
* The event carries ONLY the four aggregate fields the sprint spec pins
|
|
23
|
+
* ({backend, p95Ms, budgetOk, platform}) — never message content.
|
|
24
|
+
*/
|
|
25
|
+
export function emitRuntimeSelected(stateDir, result) {
|
|
26
|
+
try {
|
|
27
|
+
const path = defaultEventsPath(stateDir);
|
|
28
|
+
const payload = {
|
|
29
|
+
ts: Date.now(),
|
|
30
|
+
event: "vector_cortex_runtime_selected",
|
|
31
|
+
backend: result.backend,
|
|
32
|
+
p95Ms: result.p95Ms,
|
|
33
|
+
budgetOk: result.budgetOk,
|
|
34
|
+
platform: result.platform,
|
|
35
|
+
};
|
|
36
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
37
|
+
appendFileSync(path, JSON.stringify(payload) + "\n", "utf8");
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
/* best-effort — never break the encoder loop */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/encoder/runtime-native.ts — ML5-C native backend (Option N).
|
|
3
|
+
*
|
|
4
|
+
* Loads an `InferenceSession` from the `onnxruntime-node` native binding for
|
|
5
|
+
* the committed encoder-v1 ONNX asset. This is the CHOSEN selection when
|
|
6
|
+
* `MEGACOMPACT_ENCODER_NATIVE=1` (the native opt-in marker) is set AND the
|
|
7
|
+
* package is present — it uses the platform-specific prebuilt binary (no
|
|
8
|
+
* postinstall compilation needed; per vc2-model-prep §1 the allowScripts
|
|
9
|
+
* removal is safe because only CUDA/TensorRT downloads use it, and pi blocks
|
|
10
|
+
* all scripts anyway).
|
|
11
|
+
*
|
|
12
|
+
* The package is NOT declared in package.json dependencies — it is a lazily-
|
|
13
|
+
* resolved peer that the runtime loads ONLY when the native opt-in is set AND
|
|
14
|
+
* selected. Loading uses dynamic `import()` so the module graph compiles
|
|
15
|
+
* cleanly on hosts without the package (absent installs return null, never
|
|
16
|
+
* throw), so the ML5-C dispatch demotes to mode B trigram rather than
|
|
17
|
+
* breaking.
|
|
18
|
+
*
|
|
19
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 — the native binary + model are
|
|
20
|
+
* committed local files). No `any` (PREVENT-011).
|
|
21
|
+
*/
|
|
22
|
+
import { ENCODER_OPSET, ENCODER_SEMANTIC_WIDTH, ENCODER_MAX_TOKENS, } from "./types.js";
|
|
23
|
+
/** True when `MEGACOMPACT_ENCODER_NATIVE=1` (the native opt-in operator flag). */
|
|
24
|
+
export function nativeOptIn() {
|
|
25
|
+
return process.env.MEGACOMPACT_ENCODER_NATIVE === "1";
|
|
26
|
+
}
|
|
27
|
+
/** True if `onnxruntime-node` resolves on this host (loading is best-effort).
|
|
28
|
+
* Absent installs return null (never throw) so the ML5-C dispatch can demote
|
|
29
|
+
* to mode B trigram cleanly. */
|
|
30
|
+
async function loadOrtNative() {
|
|
31
|
+
try {
|
|
32
|
+
// @ts-expect-error — optional peer; the shadow type above covers the surface
|
|
33
|
+
const mod = (await import("onnxruntime-node"));
|
|
34
|
+
return mod;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a native-backed `NativeSession` over the committed ONNX asset, gated
|
|
42
|
+
* first on `nativeOptIn()`. Returns null (never throws) on any failure
|
|
43
|
+
* (opt-in off, absent package, unreadable asset, bad session creation) so the
|
|
44
|
+
* caller demotes to mode B trigram.
|
|
45
|
+
*/
|
|
46
|
+
export async function createNativeSession(modelPath, options = {}) {
|
|
47
|
+
if (!nativeOptIn())
|
|
48
|
+
return null;
|
|
49
|
+
const ort = await loadOrtNative();
|
|
50
|
+
if (!ort || !ort.InferenceSession?.create)
|
|
51
|
+
return null;
|
|
52
|
+
const threads = options.threads ?? 4;
|
|
53
|
+
const maxTokens = options.maxTokens ?? ENCODER_MAX_TOKENS;
|
|
54
|
+
try {
|
|
55
|
+
const session = await ort.InferenceSession.create(modelPath, {
|
|
56
|
+
executionProviders: ["cpu"],
|
|
57
|
+
intraOpNumThreads: threads,
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
opset: ENCODER_OPSET,
|
|
61
|
+
semanticWidth: ENCODER_SEMANTIC_WIDTH,
|
|
62
|
+
maxTokens,
|
|
63
|
+
async infer(inputIds) {
|
|
64
|
+
const feeds = { input_ids: inputIds };
|
|
65
|
+
const results = await session.run(feeds, ["embedding"]);
|
|
66
|
+
const out = results["embedding"];
|
|
67
|
+
if (!out || !(out.data instanceof Float32Array)) {
|
|
68
|
+
return new Float32Array(ENCODER_SEMANTIC_WIDTH);
|
|
69
|
+
}
|
|
70
|
+
return out.data;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|