@warmdrift/kgauto-compiler 2.0.0-alpha.86 → 2.0.0-alpha.87

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/index.js CHANGED
@@ -61,7 +61,9 @@ __export(index_exports, {
61
61
  STRATEGY_AUTHORSHIP_INDEPENDENT: () => STRATEGY_AUTHORSHIP_INDEPENDENT,
62
62
  STRATEGY_AUTHORSHIP_LIMITATION: () => STRATEGY_AUTHORSHIP_LIMITATION,
63
63
  TRANSLATOR_FLOOR: () => TRANSLATOR_FLOOR,
64
+ _testClearConsumerProfiles: () => _testClearConsumerProfiles,
64
65
  _testResetMeasuredFailure: () => _testResetMeasuredFailure,
66
+ _testResetOutcomeSourceWarning: () => _testResetOutcomeSourceWarning,
65
67
  _testResetPromotions: () => _testResetPromotions,
66
68
  _testWaitForMeasuredFailureRefresh: () => _testWaitForMeasuredFailureRefresh,
67
69
  _testWaitForPromotionsRefresh: () => _testWaitForPromotionsRefresh,
@@ -73,6 +75,7 @@ __export(index_exports, {
73
75
  attachCacheControlToStreamTextInput: () => attachCacheControlToStreamTextInput,
74
76
  awaitMeasuredFailureReady: () => awaitMeasuredFailureReady,
75
77
  awaitPromotionsReady: () => awaitPromotionsReady,
78
+ bestEffortProfile: () => bestEffortProfile,
76
79
  brainHealth: () => brainHealth,
77
80
  bucketContext: () => bucketContext,
78
81
  bucketHistory: () => bucketHistory,
@@ -127,6 +130,7 @@ __export(index_exports, {
127
130
  getStarterChainWithGrounding: () => getStarterChainWithGrounding,
128
131
  hasMutation: () => hasMutation,
129
132
  hashShape: () => hashShape,
133
+ inferProviderFromId: () => inferProviderFromId,
130
134
  isAltStrategy: () => isAltStrategy,
131
135
  isArchetype: () => isArchetype,
132
136
  isAutoPromoteEnabledFromEnv: () => isAutoPromoteEnabledFromEnv,
@@ -168,11 +172,13 @@ __export(index_exports, {
168
172
  recordGoldenIr: () => recordGoldenIr,
169
173
  recordOutcome: () => recordOutcome,
170
174
  recordShadowProbe: () => recordShadowProbe,
175
+ registerProfiles: () => registerProfiles,
171
176
  renderIrForJudge: () => renderIrForJudge,
172
177
  resetTokenizer: () => resetTokenizer,
173
178
  resolveConventionsForProfile: () => resolveConventionsForProfile,
174
179
  resolveGoldenCaptureRate: () => resolveGoldenCaptureRate,
175
180
  resolveModelAlias: () => resolveModelAlias,
181
+ resolveOutcomeSource: () => resolveOutcomeSource,
176
182
  resolvePricingAt: () => resolvePricingAt,
177
183
  resolveProviderKey: () => resolveProviderKey,
178
184
  rowToAdvisory: () => rowToAdvisory,
@@ -199,6 +205,9 @@ var FRESH_SNAPSHOT = {
199
205
  };
200
206
  var snapshot = { ...FRESH_SNAPSHOT };
201
207
  var runtime;
208
+ function configFreshness() {
209
+ return runtime && snapshot.data ? "brain" : "bundled";
210
+ }
202
211
  function configureBrainQuery(rt) {
203
212
  runtime = rt;
204
213
  snapshot = { ...FRESH_SNAPSHOT };
@@ -574,7 +583,7 @@ var PROFILES_RAW = [
574
583
  },
575
584
  {
576
585
  id: "claude-opus-4-7",
577
- verifiedAgainstDocs: "2026-05-08",
586
+ verifiedAgainstDocs: "2026-08-14",
578
587
  provider: "anthropic",
579
588
  status: "legacy",
580
589
  // s76 2026-07-25: docs list as LEGACY (Opus 5 is current). Bundle said current while the brain already said legacy — the two disagreed.
@@ -624,7 +633,7 @@ var PROFILES_RAW = [
624
633
  },
625
634
  {
626
635
  id: "claude-opus-4-6",
627
- verifiedAgainstDocs: "2026-05-08",
636
+ verifiedAgainstDocs: "2026-08-14",
628
637
  provider: "anthropic",
629
638
  status: "legacy",
630
639
  maxContextTokens: 1e6,
@@ -669,7 +678,7 @@ var PROFILES_RAW = [
669
678
  },
670
679
  {
671
680
  id: "claude-sonnet-4-6",
672
- verifiedAgainstDocs: "2026-05-08",
681
+ verifiedAgainstDocs: "2026-08-14",
673
682
  provider: "anthropic",
674
683
  status: "legacy",
675
684
  // s76 2026-07-25: docs list as LEGACY (Sonnet 5 is current).
@@ -710,7 +719,7 @@ var PROFILES_RAW = [
710
719
  },
711
720
  {
712
721
  id: "claude-haiku-4-5",
713
- verifiedAgainstDocs: "2026-05-08",
722
+ verifiedAgainstDocs: "2026-08-14",
714
723
  provider: "anthropic",
715
724
  status: "current",
716
725
  maxContextTokens: 2e5,
@@ -773,7 +782,7 @@ var PROFILES_RAW = [
773
782
  // ── Google ──
774
783
  {
775
784
  id: "gemini-2.5-flash",
776
- verifiedAgainstDocs: "2026-05-08",
785
+ verifiedAgainstDocs: "2026-08-14",
777
786
  provider: "google",
778
787
  status: "current",
779
788
  maxContextTokens: 1048576,
@@ -879,7 +888,7 @@ var PROFILES_RAW = [
879
888
  // thresholds. The brain will validate/relax these as evidence accumulates
880
889
  // per (archetype, model) tuple. Currently ZERO brain rows for this model.
881
890
  id: "gemini-2.5-flash-lite",
882
- verifiedAgainstDocs: "2026-05-13",
891
+ verifiedAgainstDocs: "2026-08-14",
883
892
  provider: "google",
884
893
  status: "current",
885
894
  maxContextTokens: 1048576,
@@ -1036,7 +1045,7 @@ var PROFILES_RAW = [
1036
1045
  },
1037
1046
  {
1038
1047
  id: "gemini-3.1-pro-preview",
1039
- verifiedAgainstDocs: "2026-05-08",
1048
+ verifiedAgainstDocs: "2026-08-14",
1040
1049
  provider: "google",
1041
1050
  status: "preview",
1042
1051
  maxContextTokens: 1048576,
@@ -1096,7 +1105,7 @@ var PROFILES_RAW = [
1096
1105
  // deepseek-reasoner registered as aliases (see ALIASES below).
1097
1106
  {
1098
1107
  id: "deepseek-v4-flash",
1099
- verifiedAgainstDocs: "2026-05-08",
1108
+ verifiedAgainstDocs: "2026-08-14",
1100
1109
  provider: "deepseek",
1101
1110
  status: "current",
1102
1111
  maxContextTokens: 1e6,
@@ -1134,7 +1143,7 @@ var PROFILES_RAW = [
1134
1143
  // baseQuality (it carries 'reasoning') with no latency counterweight,
1135
1144
  // leapfrogged gemini-2.5-flash as PB's summarize leader once reachable.
1136
1145
  latencyTier: "slow",
1137
- notes: "Cheap workhorse. 1M context, 384k max output. Cache-hit input $0.0028/M (1/50\xD7 of miss). Aliased as `deepseek-chat` (non-thinking) and `deepseek-reasoner` (thinking) \u2014 see ALIASES.",
1146
+ notes: "Cheap workhorse. 1M context, 384k max output. Cache-hit input $0.0028/M (1/50\xD7 of miss). Aliased as `deepseek-chat` (non-thinking) and `deepseek-reasoner` (thinking) \u2014 see ALIASES. PRICING MODEL CHANGE effective 2026-08-16: DeepSeek moves to peak/off-peak billing, off-peak at HALF the peak rate (docs, fetched 2026-08-14). Encoded prices are peak; cost math for off-peak traffic will overstate by up to 2x until time-of-day pricing is modeled.",
1138
1147
  // Master plan §6.2 anchor. Brain-validated tier 1 cross-provider for
1139
1148
  // classify (169 rows, 0% empty). Tier 0 for summarize-with-no-tools.
1140
1149
  // Falls off on hunt (sequential tools — L-040) and reasoning depth.
@@ -1169,7 +1178,7 @@ var PROFILES_RAW = [
1169
1178
  },
1170
1179
  {
1171
1180
  id: "deepseek-v4-pro",
1172
- verifiedAgainstDocs: "2026-06-22",
1181
+ verifiedAgainstDocs: "2026-08-14",
1173
1182
  provider: "deepseek",
1174
1183
  status: "current",
1175
1184
  maxContextTokens: 1e6,
@@ -1210,7 +1219,7 @@ var PROFILES_RAW = [
1210
1219
  // of the served set. Tag derivation would say 'medium'; the measurement says
1211
1220
  // otherwise.
1212
1221
  latencyTier: "slow",
1213
- notes: "Pro tier. 1M context, 384k max output. $0.435/$0.87 per 1M (cache-hit in $0.003625) \u2014 verified live 2026-06-22; the launch promo became the standing price (no revert). Default mode = thinking.",
1222
+ notes: "Pro tier. 1M context, 384k max output. $0.435/$0.87 per 1M (cache-hit in $0.003625) \u2014 verified live 2026-06-22; the launch promo became the standing price (no revert). Default mode = thinking. PRICING MODEL CHANGE effective 2026-08-16: DeepSeek moves to peak/off-peak billing, off-peak at HALF the peak rate (docs, fetched 2026-08-14). Encoded prices are peak; cost math for off-peak traffic will overstate by up to 2x until time-of-day pricing is modeled.",
1214
1223
  // Master plan §3.3: tier 3 cross-provider for plan chain. Reasoning
1215
1224
  // bumped one notch over V4-Flash; same parallel-tool ceiling.
1216
1225
  archetypePerf: {
@@ -1818,13 +1827,109 @@ var PROFILES_RAW = [
1818
1827
  // +1 vs 2.5-flash — but still below Sonnet/Opus reasoning floor
1819
1828
  }
1820
1829
  },
1830
+ // ─────────────────────────────────────────────────────────────────────────
1831
+ // gemini-3.6-flash — hand-onboarded s86 (2026-08-14), step-zero against
1832
+ // Google docs (models/gemini-3.6-flash page + pricing via catalog-sync's
1833
+ // two-agreeing-extraction the same day). Docs list it as Stable and call
1834
+ // it "previous-generation Flash" (3.5-flash is now "legacy" in Google's
1835
+ // wording) — but kgauto status is 'preview' per the standing entry rule:
1836
+ // a new model enters on capability data verified only at the docs level,
1837
+ // preview is unreachable by starter chains, and promotion to routing
1838
+ // happens through brain evidence, not through Google's marketing tier.
1839
+ // This also means NO family-primary retarget rides this release.
1840
+ // ─────────────────────────────────────────────────────────────────────────
1841
+ {
1842
+ id: "gemini-3.6-flash",
1843
+ verifiedAgainstDocs: "2026-08-14",
1844
+ versionAdded: "2.0.0-alpha.87",
1845
+ provider: "google",
1846
+ status: "preview",
1847
+ maxContextTokens: 1048576,
1848
+ maxOutputTokens: 65536,
1849
+ maxTools: 128,
1850
+ parallelToolCalls: true,
1851
+ structuredOutput: "native",
1852
+ systemPromptMode: "separate",
1853
+ streaming: true,
1854
+ cliffs: [
1855
+ {
1856
+ metric: "input_tokens",
1857
+ threshold: 8e3,
1858
+ action: "downgrade_quality_warning",
1859
+ reason: "Inherited Flash-family guard (2.5\u21923.5 lineage); no 3.6 brain evidence yet"
1860
+ },
1861
+ {
1862
+ metric: "tool_count",
1863
+ threshold: 20,
1864
+ action: "drop_to_top_relevant",
1865
+ reason: "Inherited from Flash family: tool reliability drops above ~20 (despite 128 hard limit). Validate per (archetype, model) after n\u226520."
1866
+ },
1867
+ {
1868
+ metric: "thinking_with_short_output",
1869
+ threshold: 1,
1870
+ action: "force_thinking_budget_zero",
1871
+ reason: "Thinking supported per Google docs; same drain risk as 2.5/3.5-flash \u2014 thinking tokens consume maxOutputTokens"
1872
+ },
1873
+ {
1874
+ metric: "tool_count",
1875
+ threshold: 1,
1876
+ whenIntent: "summarize",
1877
+ action: "strip_tools",
1878
+ reason: "Inherited from 2.5-flash s11 cliff: summarize+tools \u2192 empty response. Preemptive family guard until brain evidence on 3.6-flash specifically."
1879
+ }
1880
+ ],
1881
+ costInputPer1m: 1.5,
1882
+ costOutputPer1m: 7.5,
1883
+ lowering: {
1884
+ ...GOOGLE_LOWERING_BASE,
1885
+ cache: { ...GOOGLE_LOWERING_BASE.cache, discount: 0.1 },
1886
+ thinking: { field: "generationConfig.thinkingConfig.thinkingBudget", default: "auto" }
1887
+ },
1888
+ recovery: [
1889
+ {
1890
+ signal: "empty_response_after_tool",
1891
+ action: "retry_with_params",
1892
+ retryParams: { "generationConfig.thinkingConfig.thinkingBudget": 0 },
1893
+ maxRetries: 1,
1894
+ reason: "Inherited Flash-family pattern: empty after tool result \u2014 retry with thinking off"
1895
+ },
1896
+ {
1897
+ signal: "empty_response",
1898
+ action: "retry_with_params",
1899
+ retryParams: { "generationConfig.thinkingConfig.thinkingBudget": 0 },
1900
+ maxRetries: 1,
1901
+ reason: "Empty response \u2014 try with thinking off"
1902
+ },
1903
+ {
1904
+ signal: "malformed_function_call",
1905
+ action: "escalate",
1906
+ reason: "MALFORMED_FUNCTION_CALL maps to stop \u2014 escalate to next target"
1907
+ }
1908
+ ],
1909
+ strengths: ["agentic_loops", "coding", "1m_context", "parallel_tools", "thinking_mode"],
1910
+ weaknesses: ["no_brain_evidence_yet"],
1911
+ notes: "Hand-onboarded s86 (2026-08-14), step-zero verified: 1,048,576 ctx / 65,536 out (Google model page), $1.50/$7.50 per 1M (catalog-sync two-agreeing-extraction same day \u2014 CHEAPER output than 3.5-flash at $9.00). Docs status Stable; enters kgauto as preview per standing rule (availability != lifecycle, promotion via brain evidence). Function calling + structured outputs + thinking per docs; parallel tools assumed per Flash family (docs silent). First flagged by the release watcher s73; sat in the onboarding queue 18 days \u2014 drained by the s86 catalog-sync run.",
1912
+ archetypePerf: {
1913
+ hunt: 9,
1914
+ // Flash-family parallel-tool tier (L-040); inherited from 3.5-flash
1915
+ classify: 7,
1916
+ summarize: 7,
1917
+ transform: 7,
1918
+ ask: 8,
1919
+ generate: 8,
1920
+ plan: 7,
1921
+ extract: 7,
1922
+ critique: 5
1923
+ }
1924
+ },
1821
1925
  {
1822
1926
  // Auto-onboarded 2026-07-01 from `claude-sonnet-4-6`; VERIFIED 2026-07-02
1823
1927
  // against the claude-api reference (cc-portfolio ratification pass). The
1824
- // clone got context right (1M) and pricing right at sticker ($3/$15
1825
- // NOTE an introductory $2/$10 per MTok runs through 2026-08-31; sticker
1826
- // encoded here per the time-bounded-pricing convention, intro belongs in
1827
- // brain kgauto_pricing if worth capturing). The clone got max output WRONG:
1928
+ // clone got context right (1M). PRICING RE-BASED 2026-08-14 (s86): the
1929
+ // introductory $2/$10 was made PERMANENT Anthropic's pricing page now
1930
+ // states the scheduled Sept-1 increase to $3/$15 "will not occur", so
1931
+ // $2/$10 IS the sticker. (The $3/$15 encoded 07-02 was correct under the
1932
+ // time-bounded-pricing convention at the time; the bound was cancelled.) The clone got max output WRONG:
1828
1933
  // Sonnet 5 is 128k, not 4-6's 64k — corrected. New tokenizer (~30% more
1829
1934
  // tokens for the same text vs 4-6): byte-budget consumers should re-baseline.
1830
1935
  // API quirks (claude-api ref): (a) NON-DEFAULT temperature/top_p/top_k
@@ -1837,7 +1942,7 @@ var PROFILES_RAW = [
1837
1942
  // 'preview' per the Fable precedent — no brain evidence yet; promotion to
1838
1943
  // 'current' is an explicit call. (L-049/L-081.)
1839
1944
  id: "claude-sonnet-5",
1840
- verifiedAgainstDocs: "2026-07-02",
1945
+ verifiedAgainstDocs: "2026-08-14",
1841
1946
  provider: "anthropic",
1842
1947
  status: "current",
1843
1948
  // s76 2026-07-25: GA per docs; was preview.
@@ -1849,8 +1954,9 @@ var PROFILES_RAW = [
1849
1954
  systemPromptMode: "inline",
1850
1955
  streaming: true,
1851
1956
  cliffs: [],
1852
- costInputPer1m: 3,
1853
- costOutputPer1m: 15,
1957
+ costInputPer1m: 2,
1958
+ // 2026-08-14: intro price made PERMANENT (docs: "the previously scheduled increase to $3/$15 on September 1, 2026 will not occur")
1959
+ costOutputPer1m: 10,
1854
1960
  lowering: ANTHROPIC_LOWERING_BASE,
1855
1961
  recovery: [
1856
1962
  { signal: "rate_limit", action: "escalate", reason: "429 \u2014 escalate" },
@@ -2041,6 +2147,55 @@ function _setProfileBrainHook(hook) {
2041
2147
  function canonicalId(id) {
2042
2148
  return brainHook.resolveAlias?.(id) ?? ALIASES[id] ?? id;
2043
2149
  }
2150
+ var CONSUMER_INDEX = /* @__PURE__ */ new Map();
2151
+ function registerProfiles(profiles) {
2152
+ for (const p of profiles) CONSUMER_INDEX.set(p.id, p);
2153
+ }
2154
+ function _testClearConsumerProfiles() {
2155
+ CONSUMER_INDEX.clear();
2156
+ }
2157
+ function inferProviderFromId(id) {
2158
+ const lower2 = id.toLowerCase();
2159
+ if (lower2.startsWith("claude")) return "anthropic";
2160
+ if (lower2.startsWith("gemini") || lower2.startsWith("palm")) return "google";
2161
+ if (lower2.startsWith("gpt") || /^o[0-9]/.test(lower2) || lower2.startsWith("chatgpt")) return "openai";
2162
+ if (lower2.startsWith("deepseek")) return "deepseek";
2163
+ if (lower2.startsWith("glm")) return "zai";
2164
+ if (lower2.startsWith("kimi") || lower2.startsWith("moonshot")) return "moonshot";
2165
+ return void 0;
2166
+ }
2167
+ function bestEffortProfile(id) {
2168
+ const canonical = canonicalId(id);
2169
+ const existing = tryGetProfile(canonical);
2170
+ if (existing) return existing;
2171
+ const provider = inferProviderFromId(canonical);
2172
+ if (!provider) return void 0;
2173
+ const donor = PROFILES_RAW.find((p) => p.provider === provider && p.status === "current") ?? PROFILES_RAW.find((p) => p.provider === provider);
2174
+ if (!donor) return void 0;
2175
+ const synth = {
2176
+ id: canonical,
2177
+ provider,
2178
+ bestEffort: true,
2179
+ status: "preview",
2180
+ maxContextTokens: 128e3,
2181
+ maxOutputTokens: 4096,
2182
+ maxTools: donor.maxTools,
2183
+ parallelToolCalls: false,
2184
+ structuredOutput: "none",
2185
+ systemPromptMode: donor.systemPromptMode,
2186
+ streaming: donor.streaming,
2187
+ cliffs: [],
2188
+ costInputPer1m: 0,
2189
+ costOutputPer1m: 0,
2190
+ lowering: donor.lowering,
2191
+ recovery: [],
2192
+ strengths: [],
2193
+ weaknesses: ["best-effort synthesized profile \u2014 no verified capability data"],
2194
+ notes: `Synthesized by onUnprofiledModel:'best-effort' (provider ${provider} inferred from id; wire mechanics borrowed from ${donor.id}). No cliffs, no measured knowledge, cost UNKNOWN (recorded as 0). Replace via registerProfiles() for real guards.`
2195
+ };
2196
+ CONSUMER_INDEX.set(canonical, synth);
2197
+ return synth;
2198
+ }
2044
2199
  function resolveModelAlias(id) {
2045
2200
  return canonicalId(id);
2046
2201
  }
@@ -2049,18 +2204,22 @@ var PROFILE_INDEX = new Map(
2049
2204
  );
2050
2205
  function getProfile(id) {
2051
2206
  const canonical = canonicalId(id);
2207
+ const fromConsumer = CONSUMER_INDEX.get(canonical);
2208
+ if (fromConsumer) return fromConsumer;
2052
2209
  const fromBrain = brainHook.getProfile?.(canonical);
2053
2210
  if (fromBrain) return fromBrain;
2054
2211
  const p = PROFILE_INDEX.get(canonical);
2055
2212
  if (!p) {
2056
2213
  const known = [...PROFILE_INDEX.keys(), ...Object.keys(ALIASES)].join(", ");
2057
- throw new Error(`Unknown model id: "${id}". Known: ${known}`);
2214
+ throw new Error(
2215
+ `Unknown model id: "${id}". Known: ${known}. For a model kgauto has not onboarded: registerProfiles([...]) supplies a full profile, or policy.onUnprofiledModel:'best-effort' compiles with guards skipped (alpha.87).`
2216
+ );
2058
2217
  }
2059
2218
  return p;
2060
2219
  }
2061
2220
  function tryGetProfile(id) {
2062
2221
  const canonical = canonicalId(id);
2063
- return brainHook.getProfile?.(canonical) ?? PROFILE_INDEX.get(canonical);
2222
+ return CONSUMER_INDEX.get(canonical) ?? brainHook.getProfile?.(canonical) ?? PROFILE_INDEX.get(canonical);
2064
2223
  }
2065
2224
  function allProfiles() {
2066
2225
  return PROFILES_RAW;
@@ -2339,6 +2498,9 @@ function mapRowsToFindings(rows) {
2339
2498
  return out;
2340
2499
  }
2341
2500
  var snapshots = /* @__PURE__ */ new Map();
2501
+ function exclusionFindingsFreshness(appId) {
2502
+ return snapshots.get(appId)?.loaded ? "warm" : "cold";
2503
+ }
2342
2504
  var runtime2;
2343
2505
  var warnedOnce = false;
2344
2506
  var DEFAULT_FINDINGS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/findings/exclusions";
@@ -2399,6 +2561,7 @@ async function doRefresh2(rt, appId) {
2399
2561
  if (runtime2 !== rt) return;
2400
2562
  const rows = Array.isArray(body) ? mapRowsToFindings(body) : [];
2401
2563
  snap.data = rows;
2564
+ snap.loaded = true;
2402
2565
  snap.expiresAt = Date.now() + rt.ttlMs;
2403
2566
  snap.refreshing = false;
2404
2567
  } catch (err) {
@@ -4356,6 +4519,9 @@ function judgeMeasuredFailure(row, cfg = MEASURED_FAILURE_CFG) {
4356
4519
  };
4357
4520
  }
4358
4521
  var snapshots2 = /* @__PURE__ */ new Map();
4522
+ function measuredFailureFreshness(appId) {
4523
+ return snapshots2.get(appId)?.loaded ? "warm" : "cold";
4524
+ }
4359
4525
  var runtime3;
4360
4526
  var warnedOnce2 = false;
4361
4527
  var DEFAULT_MEASURED_FAILURE_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/measured-failure";
@@ -4453,6 +4619,7 @@ async function doRefresh3(rt, appId) {
4453
4619
  const body = await res.json();
4454
4620
  if (runtime3 !== rt) return;
4455
4621
  snap.data = Array.isArray(body) ? mapRows(body) : [];
4622
+ snap.loaded = true;
4456
4623
  snap.expiresAt = Date.now() + rt.ttlMs;
4457
4624
  snap.refreshing = false;
4458
4625
  } catch (err) {
@@ -4524,6 +4691,9 @@ function mapRowsToPromotions(rows) {
4524
4691
  return out;
4525
4692
  }
4526
4693
  var snapshots3 = /* @__PURE__ */ new Map();
4694
+ function promotionsFreshness(appId) {
4695
+ return snapshots3.get(appId)?.loaded ? "warm" : "cold";
4696
+ }
4527
4697
  var runtime4;
4528
4698
  var warnedOnce3 = false;
4529
4699
  var DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
@@ -4608,6 +4778,7 @@ async function doRefresh4(rt, appId) {
4608
4778
  if (runtime4 !== rt) return;
4609
4779
  const rows = Array.isArray(body) ? mapRowsToPromotions(body) : [];
4610
4780
  snap.data = rows;
4781
+ snap.loaded = true;
4611
4782
  snap.expiresAt = Date.now() + rt.ttlMs;
4612
4783
  snap.refreshing = false;
4613
4784
  } catch (err) {
@@ -4708,6 +4879,9 @@ function mapRowsToFindings2(rows) {
4708
4879
  return out;
4709
4880
  }
4710
4881
  var snapshots4 = /* @__PURE__ */ new Map();
4882
+ function promoteReadyFreshness(appId) {
4883
+ return snapshots4.get(appId)?.loaded ? "warm" : "cold";
4884
+ }
4711
4885
  var runtime5;
4712
4886
  var warnedOnce4 = false;
4713
4887
  function isPromoteReadyBrainActive() {
@@ -4766,6 +4940,7 @@ async function doRefresh5(rt, appId) {
4766
4940
  if (runtime5 !== rt) return;
4767
4941
  const rows = Array.isArray(body) ? mapRowsToFindings2(body) : [];
4768
4942
  snap.data = rows;
4943
+ snap.loaded = true;
4769
4944
  snap.expiresAt = Date.now() + rt.ttlMs;
4770
4945
  snap.refreshing = false;
4771
4946
  } catch (err) {
@@ -5715,7 +5890,16 @@ function makeHandle() {
5715
5890
  return `c${Date.now().toString(36)}-${counter.toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
5716
5891
  }
5717
5892
  function compile(ir, opts = {}) {
5718
- const resolver = opts.profileResolver ?? getProfile;
5893
+ const baseResolver = opts.profileResolver ?? getProfile;
5894
+ const resolver = opts.policy?.onUnprofiledModel === "best-effort" ? (id) => {
5895
+ try {
5896
+ return baseResolver(id);
5897
+ } catch (err) {
5898
+ const synth = bestEffortProfile(id);
5899
+ if (!synth) throw err;
5900
+ return synth;
5901
+ }
5902
+ } : baseResolver;
5719
5903
  validateIR(ir);
5720
5904
  ir = resolveModelEntries(ir);
5721
5905
  const sliced = passSlice(ir);
@@ -5775,11 +5959,26 @@ function compile(ir, opts = {}) {
5775
5959
  accumulatedMutations.push(...scores.mutations);
5776
5960
  const target = pickTarget(workingIR, scores.value);
5777
5961
  if (!target) {
5962
+ const unknownIds = scores.value.filter((s) => s.rejectReasons?.includes("unknown_model_id")).map((s) => s.modelId);
5963
+ const uninferable = unknownIds.filter((id) => !inferProviderFromId(id));
5964
+ const unknownHint = unknownIds.length > 0 ? ` Unprofiled model id(s): ${unknownIds.join(", ")}. registerProfiles([...]) supplies a full profile; policy.onUnprofiledModel:'best-effort' compiles with guards skipped.` + (uninferable.length > 0 ? ` Note: provider is not inferable from ${uninferable.join(", ")}, so best-effort cannot lower it \u2014 registerProfiles is the only path for those.` : "") : "";
5778
5965
  throw new Error(
5779
- `compile(): no allowed model fits the request. Scores: ${JSON.stringify(scores.value, null, 2)}`
5966
+ `compile(): no allowed model fits the request.${unknownHint} Scores: ${JSON.stringify(scores.value, null, 2)}`
5780
5967
  );
5781
5968
  }
5782
5969
  const profile = resolver(target.modelId);
5970
+ const bestEffortWarnings = [];
5971
+ if (profile.bestEffort) {
5972
+ bestEffortWarnings.push(
5973
+ `best-effort profile in use for "${profile.id}" (provider ${profile.provider} inferred from the id; wire mechanics borrowed). SKIPPED for this model: cliff guards, recovery rules, measured archetype knowledge, structured-output capability (treated as 'none'), parallel tools (treated as sequential). Cost is UNKNOWN and recorded as $0 \u2014 cost gates and cost attribution are meaningless for this model. registerProfiles() restores real guards.`
5974
+ );
5975
+ accumulatedMutations.push({
5976
+ id: `best_effort_profile_${profile.id}`,
5977
+ source: "best_effort",
5978
+ passName: "resolve-profile",
5979
+ description: `Unprofiled model "${profile.id}" compiled under onUnprofiledModel:'best-effort' \u2014 guards skipped, cost unknown. See diagnostics.cliffWarnings for the full list.`
5980
+ });
5981
+ }
5783
5982
  const fallbackChain = scores.value.filter((s) => s.modelId !== target.modelId && s.fits).sort((a, b) => b.rank - a.rank).map((s) => s.modelId);
5784
5983
  const cliffs = passApplyCliffs(workingIR, profile, inputTokens);
5785
5984
  workingIR = cliffs.value.ir;
@@ -5865,6 +6064,23 @@ function compile(ir, opts = {}) {
5865
6064
  const historyCacheMarkIndex = computeHistoryCacheMarkIndex(workingIR);
5866
6065
  const systemMessages = buildSystemMessages(workingIR, profile.provider);
5867
6066
  const systemCacheMarkIndex = lastCacheableSystemIndex(systemMessages);
6067
+ const keptSectionIds = new Set(workingIR.sections.map((s) => s.id));
6068
+ const cachePrefixActive = lowered.diagnostics.cacheableTokens > 0;
6069
+ const cacheReadFraction = profile.lowering.cache.discount ?? 0.25;
6070
+ const sectionAttribution = ir.sections.map((s) => {
6071
+ const tokens = countTokens(s.text);
6072
+ const kept = keptSectionIds.has(s.id);
6073
+ const estCostUsdFirstCall = kept ? tokens / 1e6 * profile.costInputPer1m : 0;
6074
+ const inActiveCachePrefix = kept && s.cacheable === true && cachePrefixActive;
6075
+ return {
6076
+ id: s.id,
6077
+ tokens,
6078
+ kept,
6079
+ cacheable: s.cacheable === true,
6080
+ estCostUsdFirstCall,
6081
+ estCostUsdWarm: inActiveCachePrefix ? estCostUsdFirstCall * cacheReadFraction : estCostUsdFirstCall
6082
+ };
6083
+ });
5868
6084
  const diagnostics = {
5869
6085
  sectionsKept: workingIR.sections.length,
5870
6086
  sectionsDropped: ir.sections.length - workingIR.sections.length,
@@ -5888,11 +6104,25 @@ function compile(ir, opts = {}) {
5888
6104
  // text the consumer can route on without changing behavior).
5889
6105
  cliffWarnings: [
5890
6106
  ...cliffs.value.loweringHints.qualityWarning ?? [],
5891
- ...conventions.value.cliffWarnings
6107
+ ...conventions.value.cliffWarnings,
6108
+ // alpha.87 — best-effort profile in use (loud on EVERY compile).
6109
+ ...bestEffortWarnings
5892
6110
  ],
5893
6111
  // alpha.68 / Release A — measured discipline gate-token tax (§5.D). 0 when
5894
6112
  // the gate didn't fire.
5895
- disciplineGateTokens
6113
+ disciplineGateTokens,
6114
+ // alpha.87 — per-source freshness stamped at the moment the compile's
6115
+ // reads have all happened, from state each source already tracks (the
6116
+ // "one-line stamp at the point where the source is already known and
6117
+ // discarded" this filing reduced to once alpha.73/.86 warmed the caches).
6118
+ freshness: {
6119
+ config: configFreshness(),
6120
+ measuredFailure: measuredFailureFreshness(ir.appId),
6121
+ promotions: promotionsFreshness(ir.appId),
6122
+ exclusions: exclusionFindingsFreshness(ir.appId),
6123
+ promoteReady: promoteReadyFreshness(ir.appId)
6124
+ },
6125
+ sections: sectionAttribution
5896
6126
  };
5897
6127
  if (ir.intent.archetype === "hunt" && ir.constraints?.toolOrchestration === "sequential") {
5898
6128
  accumulatedMutations.push({
@@ -6057,7 +6287,7 @@ function validateFinalFit(ir, profile, tokens) {
6057
6287
  }
6058
6288
 
6059
6289
  // src/version.ts
6060
- var LIBRARY_VERSION = "2.0.0-alpha.86";
6290
+ var LIBRARY_VERSION = "2.0.0-alpha.87";
6061
6291
 
6062
6292
  // src/pricing-brain.ts
6063
6293
  function isPricingRow(x) {
@@ -6431,6 +6661,26 @@ function maybeWarnDiscardedCompile(reg, handle) {
6431
6661
  `[kgauto] compile-then-discard: compileForAISDKv6() output for handle ${handle} (archetype=${reg.archetype}, model=${reg.model}) was recorded but neither .system, .model, nor .raw was read before record(). The brain row's mutations_applied / estimated_tokens_in / system_prompt_chars describe a compile that did NOT shape the served call. Pass compiled.system + compiled.model into your generateText/streamText (or use call()). Silence via configureBrain({ warnOnDiscardedCompile: false }).`
6432
6662
  );
6433
6663
  }
6664
+ var OUTCOME_SOURCES = ["canary", "smoke", "eval", "probe", "synthetic"];
6665
+ var warnedInvalidEnvSource = false;
6666
+ function resolveOutcomeSource(explicit) {
6667
+ if (explicit) return explicit;
6668
+ const raw = typeof process !== "undefined" ? process.env?.KGAUTO_SOURCE : void 0;
6669
+ if (!raw) return void 0;
6670
+ const trimmed = raw.trim();
6671
+ if (!trimmed) return void 0;
6672
+ if (OUTCOME_SOURCES.includes(trimmed)) return trimmed;
6673
+ if (!warnedInvalidEnvSource) {
6674
+ warnedInvalidEnvSource = true;
6675
+ console.warn(
6676
+ `[kgauto] KGAUTO_SOURCE="${trimmed}" is not one of ${OUTCOME_SOURCES.join("|")} \u2014 recording as 'synthetic' so the row survives the brain's CHECK constraint and stays out of organic-liveness stats.`
6677
+ );
6678
+ }
6679
+ return "synthetic";
6680
+ }
6681
+ function _testResetOutcomeSourceWarning() {
6682
+ warnedInvalidEnvSource = false;
6683
+ }
6434
6684
  async function record(input) {
6435
6685
  const reg = compileRegistry.get(input.handle);
6436
6686
  if (reg) {
@@ -6545,7 +6795,9 @@ function buildPayload(input, reg) {
6545
6795
  latency_ms: input.latencyMs,
6546
6796
  success: input.success,
6547
6797
  empty_response: input.emptyResponse ?? input.tokensOut === 0,
6548
- source: input.source,
6798
+ // alpha.87 — explicit source wins; KGAUTO_SOURCE env fills the gap (the
6799
+ // zero-code synthetic self-mark for harness/smoke processes).
6800
+ source: resolveOutcomeSource(input.source),
6549
6801
  error_type: input.errorType,
6550
6802
  tools_called: input.toolsCalled,
6551
6803
  oracle_score: input.oracleScore?.score,
@@ -10837,7 +11089,9 @@ function compile2(ir, opts) {
10837
11089
  STRATEGY_AUTHORSHIP_INDEPENDENT,
10838
11090
  STRATEGY_AUTHORSHIP_LIMITATION,
10839
11091
  TRANSLATOR_FLOOR,
11092
+ _testClearConsumerProfiles,
10840
11093
  _testResetMeasuredFailure,
11094
+ _testResetOutcomeSourceWarning,
10841
11095
  _testResetPromotions,
10842
11096
  _testWaitForMeasuredFailureRefresh,
10843
11097
  _testWaitForPromotionsRefresh,
@@ -10849,6 +11103,7 @@ function compile2(ir, opts) {
10849
11103
  attachCacheControlToStreamTextInput,
10850
11104
  awaitMeasuredFailureReady,
10851
11105
  awaitPromotionsReady,
11106
+ bestEffortProfile,
10852
11107
  brainHealth,
10853
11108
  bucketContext,
10854
11109
  bucketHistory,
@@ -10903,6 +11158,7 @@ function compile2(ir, opts) {
10903
11158
  getStarterChainWithGrounding,
10904
11159
  hasMutation,
10905
11160
  hashShape,
11161
+ inferProviderFromId,
10906
11162
  isAltStrategy,
10907
11163
  isArchetype,
10908
11164
  isAutoPromoteEnabledFromEnv,
@@ -10944,11 +11200,13 @@ function compile2(ir, opts) {
10944
11200
  recordGoldenIr,
10945
11201
  recordOutcome,
10946
11202
  recordShadowProbe,
11203
+ registerProfiles,
10947
11204
  renderIrForJudge,
10948
11205
  resetTokenizer,
10949
11206
  resolveConventionsForProfile,
10950
11207
  resolveGoldenCaptureRate,
10951
11208
  resolveModelAlias,
11209
+ resolveOutcomeSource,
10952
11210
  resolvePricingAt,
10953
11211
  resolveProviderKey,
10954
11212
  rowToAdvisory,