pi-mega-compact 0.20.70 → 0.20.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/extensions/dashboard-server/routes-setup-cortex.js +7 -1
  2. package/dist/extensions/dashboard-server/routes-vector-cortex-crystals.js +45 -30
  3. package/dist/extensions/dashboard-server/routes-vector-cortex-diagnostics.js +50 -29
  4. package/dist/extensions/dashboard-server/routes-vector-cortex-economics.js +33 -20
  5. package/dist/extensions/dashboard-server/routes-vector-cortex-helpers.js +54 -0
  6. package/dist/extensions/dashboard-server/routes-vector-cortex-policy.js +33 -16
  7. package/dist/src/vector-cortex/cache/store.js +25 -2
  8. package/dist/src/vector-cortex/encoder/asset.js +34 -2
  9. package/dist/src/vector-cortex/encoder/router.js +31 -3
  10. package/dist/src/vector-cortex/livewire/livewire-live.js +163 -0
  11. package/dist/src/vector-cortex/livewire/livewire-registry.js +73 -0
  12. package/dist/src/vector-cortex/livewire/livewire-runtime.js +107 -0
  13. package/dist/src/vector-cortex/livewire/livewire-snapshot.js +101 -0
  14. package/dist/src/vector-cortex/livewire/livewire-types.js +19 -0
  15. package/dist/src/vector-cortex/provider/registry.js +44 -12
  16. package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +43 -7
  17. package/dist/vector-cortex/cache/store.js +25 -2
  18. package/dist/vector-cortex/encoder/asset.js +34 -2
  19. package/dist/vector-cortex/encoder/router.js +31 -3
  20. package/dist/vector-cortex/provider/registry.js +44 -12
  21. package/dist/vector-cortex/setup-cortex-blockers-compute.js +43 -7
  22. package/extensions/dashboard-server/routes-setup-cortex.ts +8 -1
  23. package/extensions/dashboard-server/routes-vector-cortex-crystals.ts +46 -30
  24. package/extensions/dashboard-server/routes-vector-cortex-diagnostics.ts +52 -29
  25. package/extensions/dashboard-server/routes-vector-cortex-economics.ts +35 -20
  26. package/extensions/dashboard-server/routes-vector-cortex-helpers.ts +84 -0
  27. package/extensions/dashboard-server/routes-vector-cortex-policy.ts +35 -16
  28. package/package.json +1 -1
  29. package/src/vector-cortex/cache/store.ts +26 -2
  30. package/src/vector-cortex/encoder/asset.ts +46 -3
  31. package/src/vector-cortex/encoder/router.ts +56 -2
  32. package/src/vector-cortex/encoder/types.ts +3 -0
  33. package/src/vector-cortex/livewire/livewire-live.ts +223 -0
  34. package/src/vector-cortex/livewire/livewire-registry.ts +91 -0
  35. package/src/vector-cortex/livewire/livewire-runtime.ts +117 -0
  36. package/src/vector-cortex/livewire/livewire-snapshot.ts +108 -0
  37. package/src/vector-cortex/livewire/livewire-types.ts +84 -0
  38. package/src/vector-cortex/provider/economics.ts +9 -31
  39. package/src/vector-cortex/provider/registry.ts +82 -11
  40. package/src/vector-cortex/provider/types.ts +37 -0
  41. package/src/vector-cortex/setup-cortex-blockers-compute.ts +48 -7
@@ -18,6 +18,7 @@
18
18
 
19
19
  import {
20
20
  PRO_PROFILE_UNKNOWN,
21
+ type ProviderEconomicsV1,
21
22
  type ProviderProfileBundle,
22
23
  type ProviderProfileResult,
23
24
  type ProviderProfileV1,
@@ -60,6 +61,7 @@ function profile(
60
61
  id: string,
61
62
  version: string,
62
63
  excludedJsonPointers: ProviderProfileV1["excludedJsonPointers"],
64
+ economics: ProviderProfileV1["economics"],
63
65
  ): ProviderProfileV1 {
64
66
  return {
65
67
  schema: "provider-profile-v1",
@@ -67,42 +69,111 @@ function profile(
67
69
  version,
68
70
  hashMode: "entire-canonical-request",
69
71
  excludedJsonPointers,
72
+ economics,
70
73
  };
71
74
  }
72
75
 
76
+ /**
77
+ * Build integer micro-unit economics for a base profile (VC7B). A cache WRITE
78
+ * costs more than an uncached token, a cache READ costs less — the standard
79
+ * provider-prompt-cache shape. `exclusionFixtureId` mirrors the profile's own
80
+ * exclusion fixture (or null when the profile has none to prove).
81
+ */
82
+ function econ(
83
+ id: string,
84
+ version: string,
85
+ exclusionFixtureId: string | null,
86
+ values: {
87
+ basePrice: number;
88
+ readPrice: number;
89
+ writePrice: number;
90
+ ttlMs: number;
91
+ minPrefix: number;
92
+ },
93
+ ): ProviderEconomicsV1 {
94
+ return {
95
+ schema: "provider-economics-v1",
96
+ profileId: id,
97
+ profileVersion: version,
98
+ basePrice: values.basePrice,
99
+ readPrice: values.readPrice,
100
+ writePrice: values.writePrice,
101
+ ttlMs: values.ttlMs,
102
+ minPrefix: values.minPrefix,
103
+ exclusionFixtureId,
104
+ };
105
+ }
106
+
107
+ /** Representative integer micro-unit economics for the Anthropic opus base tier. */
108
+ const OPUS_ECON: ProviderEconomicsV1 = econ(
109
+ "anthropic-claude-opus",
110
+ "v1",
111
+ null,
112
+ { basePrice: 15, readPrice: 2, writePrice: 19, ttlMs: 300_000, minPrefix: 1024 },
113
+ );
114
+
115
+ /** Representative integer micro-unit economics for the Anthropic sonnet base tier. */
116
+ const SONNET_ECON: ProviderEconomicsV1 = econ(
117
+ "anthropic-claude-sonnet",
118
+ "v1",
119
+ null,
120
+ { basePrice: 3, readPrice: 0, writePrice: 4, ttlMs: 300_000, minPrefix: 1024 },
121
+ );
122
+
123
+ /** Representative integer micro-unit economics for the OpenAI gpt base tier. */
124
+ const GPT_ECON: ProviderEconomicsV1 = econ(
125
+ "openai-gpt",
126
+ "v1",
127
+ null,
128
+ { basePrice: 5, readPrice: 1, writePrice: 6, ttlMs: 300_000, minPrefix: 1024 },
129
+ );
130
+
131
+ /** The gemini profile's versioned, fixture-proven exclusion. */
132
+ const GEMINI_EXCLUSIONS: ProviderProfileV1["excludedJsonPointers"] = [
133
+ {
134
+ pointer: "/requestId",
135
+ fixtureId: "PRO-EXCLUDE-010",
136
+ proofDigest: "sha256:excluded-request-id-proof",
137
+ },
138
+ ];
139
+
140
+ /** Representative integer micro-unit economics for the gemini base tier. */
141
+ const GEMINI_ECON: ProviderEconomicsV1 = econ(
142
+ "google-gemini",
143
+ "v1",
144
+ "PRO-EXCLUDE-010",
145
+ { basePrice: 3, readPrice: 1, writePrice: 4, ttlMs: 300_000, minPrefix: 1024 },
146
+ );
147
+
73
148
  /**
74
149
  * The fixture-backed base profiles. Each entry is the REAL bundle the renderer
75
150
  * resolves; the parallel conformance fixtures prove the cache-identity behavior.
76
151
  */
77
152
  const BASE_PROFILES: readonly ProviderProfileBundle[] = [
78
153
  {
79
- profile: profile("anthropic-claude-opus", "v1", []),
154
+ profile: profile("anthropic-claude-opus", "v1", [], OPUS_ECON),
80
155
  role: BASE_ROLE,
81
156
  tool: BASE_TOOL,
82
157
  cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
83
158
  },
84
159
  {
85
- profile: profile("anthropic-claude-sonnet", "v1", []),
160
+ profile: profile("anthropic-claude-sonnet", "v1", [], SONNET_ECON),
86
161
  role: BASE_ROLE,
87
162
  tool: BASE_TOOL,
88
163
  cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
89
164
  },
90
165
  {
91
- profile: profile("openai-gpt", "v1", []),
166
+ profile: profile("openai-gpt", "v1", [], GPT_ECON),
92
167
  role: BASE_ROLE,
93
168
  tool: BASE_TOOL,
94
169
  cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
95
170
  },
96
171
  {
97
172
  // A profile that proves a fixture-excluded pointer: a provider whose
98
- // request-id header cannot affect cache identity. Excluded + versioned.
99
- profile: profile("google-gemini", "v1", [
100
- {
101
- pointer: "/requestId",
102
- fixtureId: "PRO-EXCLUDE-010",
103
- proofDigest: "sha256:excluded-request-id-proof",
104
- },
105
- ]),
173
+ // request-id header cannot affect cache identity. Excluded + versioned, and
174
+ // the exclusion fixture id is carried into economics so the proof is
175
+ // honored (an unproven exclusion would fail economics validation).
176
+ profile: profile("google-gemini", "v1", GEMINI_EXCLUSIONS, GEMINI_ECON),
106
177
  role: BASE_ROLE,
107
178
  tool: BASE_TOOL,
108
179
  cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
@@ -35,6 +35,37 @@ export interface ProviderProfileExclusion {
35
35
  readonly proofDigest: string;
36
36
  }
37
37
 
38
+ /**
39
+ * Cache economics attached to a provider profile (VC7B).
40
+ *
41
+ * Prices are integer MICRO-UNITS PER TOKEN (1e-6 currency units), so a provider
42
+ * charging $3.00 per million input tokens has `basePrice: 3`. Integers keep the
43
+ * money path exact (see `economics.ts` for why floats are refused).
44
+ */
45
+ export interface ProviderEconomicsV1 {
46
+ readonly schema: "provider-economics-v1";
47
+ /** The `ProviderProfileV1.id` these economics belong to. */
48
+ readonly profileId: string;
49
+ /** Profile version — economics are versioned WITH the profile they price. */
50
+ readonly profileVersion: string;
51
+ /** Uncached price per token, integer micro-units. The savings baseline. */
52
+ readonly basePrice: number;
53
+ /** Cache-READ price per token, integer micro-units. Normally < basePrice. */
54
+ readonly readPrice: number;
55
+ /** Cache-WRITE price per token, integer micro-units. Normally > basePrice. */
56
+ readonly writePrice: number;
57
+ /** Cache entry lifetime in ms. A prefix older than this cannot be read back. */
58
+ readonly ttlMs: number;
59
+ /** Minimum cacheable prefix in tokens; a shorter prefix is never cached. */
60
+ readonly minPrefix: number;
61
+ /**
62
+ * Conformance fixture ID proving this profile's exclusion set is safe, or
63
+ * `null` when the profile declares NO exclusions (nothing to prove). A profile
64
+ * WITH exclusions and a null/blank id is rejected — see `validateEconomics`.
65
+ */
66
+ readonly exclusionFixtureId: string | null;
67
+ }
68
+
38
69
  /**
39
70
  * The provider-profile contract. A renderer consumes a profile to decide how the
40
71
  * rendered prompt is serialized into the canonical outbound request without
@@ -47,6 +78,12 @@ export interface ProviderProfileV1 {
47
78
  readonly hashMode: ProviderHashMode;
48
79
  /** Versioned, fixture-proven exclusions (empty = hash the whole request). */
49
80
  readonly excludedJsonPointers: readonly ProviderProfileExclusion[];
81
+ /**
82
+ * VC7B cache economics pricing this profile's frozen-render reuse. Every base
83
+ * profile carries economics so the cache-economics aggregate is computable
84
+ * without a side table; a profile WITHOUT economics is simply never cached.
85
+ */
86
+ readonly economics: ProviderEconomicsV1 | null;
50
87
  }
51
88
 
52
89
  /**
@@ -14,9 +14,12 @@
14
14
  * all-open, byte-identical to ENC-0f-era for flag-off). `computeSetupCortexBlockers`
15
15
  * is a PURE function over (platform, ENC-0f QualificationV1 record, asset-manifest
16
16
  * head-count) that returns the live blocker list: HG-1 closes on a five-head
17
- * manifest (ENC-0c), HG-5 reflects the measured qualification verdict, HG-4
18
- * notes the ENC-0e visibility close while the binary gap persists, HG-3 stays
19
- * open (genuinely unresolved). `setupCortexActionBlockers` re-derives VC9B
17
+ * manifest (ENC-0c), HG-5 reflects the measured qualification verdict, HG-4 is
18
+ * superseded (upstream arm64-only darwin binary gap, ENC-0e demotion surface),
19
+ * HG-6 is superseded (4-thread mandate = runtime p95 gate), HG-7 closes (frozen
20
+ * model card / dataset manifest / calibration), HG-3 closes when native
21
+ * onnxruntime-node is installed (ENC-2a/2b). `setupCortexActionBlockers`
22
+ * re-derives VC9B
20
23
  * action gating from the live computed blockers (intersects each action's
21
24
  * static candidate gate ids with the currently-open blocker ids).
22
25
  *
@@ -32,6 +35,7 @@ import {
32
35
  ENCODER_LATENCY_P95_MS,
33
36
  ENCODER_RSS_BUDGET_BYTES,
34
37
  } from "./encoder/types.js";
38
+ import { INSTALL_BUDGET_DEFAULT_MIB } from "./encoder/decision.js";
35
39
 
36
40
  const MIB = 1024 * 1024;
37
41
 
@@ -140,19 +144,27 @@ export function setupCortexBlocker(id: string): SetupCortexBlockerV1 | undefined
140
144
  * - HG-1 → `"closed"` when the asset manifest declares all five projection
141
145
  * heads (`headCount === ENCODER_HEAD_ORDER.length`); otherwise stays open.
142
146
  * - HG-3 → unchanged (genuinely open — onnxruntime-node budget unresolved).
143
- * - HG-4 → stays `"open"` (the upstream binary gap is unchanged); resolution
144
- * notes that ENC-0e ships the darwin demotion visibility surface.
147
+ * - HG-4 → `"superseded"` (documented upstream platform gap onnxruntime-node
148
+ * is arm64-only for darwin; ENC-0e ships the demotion surface, no code fix
149
+ * is possible).
145
150
  * - HG-5 → derived from the qualification record: an empty record is
146
151
  * `"superseded"` (no measurement on this device); a `failed` verdict closes
147
152
  * it with the measured p95/RSS wording; a `qualified` verdict closes it with
148
153
  * "measured" wording. Severity stays `"medium"` from the base row.
154
+ * - HG-6 → `"superseded"` (the 4-thread mandate is a runtime p95 gate enforced
155
+ * by the ENC-0f qualification bench — a platform failing the p95 threshold
156
+ * auto-demotes to mode B; no separate code surface needed).
157
+ * - HG-7 → `"closed"` (model card, dataset manifest, and VC2C calibration
158
+ * thresholds are all committed and frozen).
149
159
  * `platform` is carried for contract symmetry with Worker B's route input; the
150
- * HG rules here do not branch on it (HG-4's darwin note applies regardless).
160
+ * HG rules here do not branch on it (the closures are unconditional).
151
161
  */
152
162
  export function computeSetupCortexBlockers(input: {
153
163
  platform: string | null;
154
164
  qualification: QualificationV1 | null;
155
165
  headCount: number | null;
166
+ /** Installed native onnxruntime-node version (null = not installed). */
167
+ nativeOrtInstalledVersion?: string | null;
156
168
  }): readonly SetupCortexBlockerV1[] {
157
169
  const { qualification, headCount } = input;
158
170
  return SETUP_CORTEX_BLOCKERS.map((base): SetupCortexBlockerV1 => {
@@ -161,10 +173,39 @@ export function computeSetupCortexBlockers(input: {
161
173
  return headCount === ENCODER_HEAD_ORDER.length
162
174
  ? { ...base, status: "closed" }
163
175
  : base;
176
+ case "HG-3":
177
+ // HG-3 is the install-budget gate: closes when native onnxruntime-node is
178
+ // installed (the ~101 MiB tarball fits within the 300 MiB default budget).
179
+ // The runtime p95/RSS qualification is HG-5's domain — this gate only asks
180
+ // "is the binding installed and within budget?".
181
+ if (input.nativeOrtInstalledVersion != null) {
182
+ return {
183
+ ...base,
184
+ status: "closed",
185
+ resolution: `Native onnxruntime-node ${input.nativeOrtInstalledVersion} installed (~101 MiB, within the ${INSTALL_BUDGET_DEFAULT_MIB} MiB budget). Runtime qualification is HG-5.`,
186
+ };
187
+ }
188
+ return base;
164
189
  case "HG-4":
165
190
  return {
166
191
  ...base,
167
- resolution: `${base.resolution} ENC-0e shipped the darwin demotion visibility surface.`,
192
+ status: "superseded",
193
+ resolution:
194
+ "Upstream onnxruntime-node ships arm64-only for darwin. ENC-0e ships the demotion surface: darwin-x64 users use the WASM path (mode B) or lexical fallback (mode C). No code fix is possible — the binary does not exist upstream.",
195
+ };
196
+ case "HG-6":
197
+ return {
198
+ ...base,
199
+ status: "superseded",
200
+ resolution:
201
+ "The 4-thread mandate is a runtime p95 gate enforced by the qualification bench (ENC-0f gate-qualify.mjs). A platform that fails the p95 latency threshold (40ms) is automatically demoted to mode B — no separate code surface needed. Low-core platforms are handled by the same qualification gate.",
202
+ };
203
+ case "HG-7":
204
+ return {
205
+ ...base,
206
+ status: "closed",
207
+ resolution:
208
+ "Model card (training/vector-cortex/model-card.json), dataset manifest (training/vector-cortex/dataset-manifest.json), and VC2C calibration thresholds (EVALUATION_THRESHOLDS in types-vc2c.ts) are all committed and frozen.",
168
209
  };
169
210
  case "HG-5":
170
211
  if (qualification === null) {