@warmdrift/kgauto-compiler 2.0.0-alpha.20 → 2.0.0-alpha.21

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.mjs CHANGED
@@ -1701,101 +1701,119 @@ var loadChainsFromBrain = createBrainQueryCache({
1701
1701
  });
1702
1702
 
1703
1703
  // src/fallback.ts
1704
- var STARTER_CHAINS = {
1704
+ var STARTER_CHAINS_GROUNDED = {
1705
1705
  // Reasoning floor — never degrade. Walk UP on 429 to Opus → cross-provider.
1706
- // alpha.16: gpt-5.5 appended as third-provider critique floor (frontier-tier,
1707
- // archetypePerf=9). Cross-provider-tail invariant has somewhere to land when
1708
- // both Anthropic + Google are unreachable (consumer adds only OpenAI key).
1709
1706
  critique: [
1710
- "claude-opus-4-7",
1711
- "claude-sonnet-4-6",
1712
- "gemini-2.5-pro",
1713
- "gpt-5.5"
1707
+ { id: "claude-opus-4-7", grounding: "judgment", reason: "Highest reasoning bar, no degradation tier \u2014 engineer pick, awaiting measured backing" },
1708
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Same-provider walk-down from Opus on 429" },
1709
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor in similar quality bracket" },
1710
+ { id: "gpt-5.5", grounding: "judgment", reason: "alpha.16: third-provider frontier-tier floor (archetypePerf=9)" }
1714
1711
  ],
1715
- // Reasoning matters — Sonnet primary; walk UP to Opus on 429 (rare exception
1716
- // to "always cheaper"); cross-provider via Pro; DeepSeek Pro as tier 3 floor.
1712
+ // Reasoning matters — Sonnet primary; walk UP to Opus on 429.
1717
1713
  plan: [
1718
- "claude-sonnet-4-6",
1719
- "claude-opus-4-7",
1720
- "gemini-2.5-pro",
1721
- "deepseek-v4-pro"
1714
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Reasoning + cost balance \u2014 engineer pick" },
1715
+ { id: "claude-opus-4-7", grounding: "judgment", reason: 'Same-provider walk-UP on 429 (rare exception to "always cheaper")' },
1716
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
1717
+ { id: "deepseek-v4-pro", grounding: "judgment", reason: "Tier 3 cost floor \u2014 no brain evidence yet" }
1722
1718
  ],
1723
- // Quality + cost match. Walk Sonnet → Haiku same-provider, Pro cross,
1724
- // gpt-5.4-mini as third-provider tail (alpha.16 — closes the mono-Anthropic
1725
- // gap when consumer has only ANTHROPIC + OPENAI keys; archetypePerf=7).
1719
+ // Quality + cost match.
1726
1720
  generate: [
1727
- "claude-sonnet-4-6",
1728
- "claude-haiku-4-5",
1729
- "gemini-2.5-pro",
1730
- "gpt-5.4-mini"
1721
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality + cost match \u2014 engineer pick" },
1722
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
1723
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
1724
+ { id: "gpt-5.4-mini", grounding: "judgment", reason: "alpha.16: third-provider tail (archetypePerf=7) \u2014 closes mono-Anthropic gap" }
1731
1725
  ],
1726
+ // ask::sonnet — STARTER_CHAINS calls this "Quality + cost match" but
1727
+ // tt-intel s78 prod data showed 27% empty rate. Labeled 'judgment' until
1728
+ // evidence either validates or refutes the placement.
1732
1729
  ask: [
1733
- "claude-sonnet-4-6",
1734
- "claude-haiku-4-5",
1735
- "gemini-2.5-pro",
1736
- "gpt-5.4-mini"
1730
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality + cost match \u2014 engineer pick. NOTE: tt-intel s78 prod showed 27% empty rate; placement awaits measurement validation" },
1731
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
1732
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
1733
+ { id: "gpt-5.4-mini", grounding: "judgment", reason: "alpha.16: third-provider tail (archetypePerf=7)" }
1737
1734
  ],
1738
- // Structured-output archetype — Flash skipped (alpha.8 MAX_TOKENS cliff),
1739
- // DeepSeek skipped (no brain evidence). Floor at Haiku. alpha.16: gpt-5.4
1740
- // appended as third-provider extract floor (archetypePerf=8, native
1741
- // structured-output support).
1735
+ // Structured-output archetype — Flash skipped (alpha.8 MAX_TOKENS cliff,
1736
+ // capability-fact); DeepSeek skipped (no brain evidence).
1742
1737
  extract: [
1743
- "claude-sonnet-4-6",
1744
- "claude-haiku-4-5",
1745
- "gemini-2.5-pro",
1746
- "gpt-5.4"
1738
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Reliable structured-output anchor \u2014 engineer pick" },
1739
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down with native structured output" },
1740
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor with structured-output support" },
1741
+ { id: "gpt-5.4", grounding: "capability-fact", reason: "alpha.16: third-provider floor \u2014 native structured-output capability (archetypePerf=8)" }
1747
1742
  ],
1748
1743
  // Forgiving archetype — Sonnet primary but Flash safely floors it.
1749
1744
  transform: [
1750
- "claude-sonnet-4-6",
1751
- "claude-haiku-4-5",
1752
- "gemini-2.5-pro",
1753
- "gemini-2.5-flash"
1745
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality anchor \u2014 engineer pick" },
1746
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
1747
+ { id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
1748
+ { id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost floor \u2014 forgiving archetype tolerates Flash" }
1754
1749
  ],
1755
- // Parallel-tool throughput champion (Flash, L-040). Tier 1 cross-provider
1756
- // Pro; tier 2 Sonnet (quality safety net for blocked-Flash case); tier 3
1757
- // Haiku (reduced tool budget — cliff at 16 fires). This is the
1758
- // `toolOrchestration: 'parallel'` (default) hunt chain. The sequential
1759
- // variant lives in STARTER_CHAINS_BY_MODE.hunt.sequential below — see
1760
- // alpha.20 E3 / interfaces/kgauto.md `sequential-agentic-hunt-mode`.
1750
+ // Parallel-tool throughput champion Flash leads on the L-040 cliff
1751
+ // (capability-fact: Flash 15-75 parallel calls/step vs DeepSeek 7-8).
1761
1752
  hunt: [
1762
- "gemini-2.5-flash",
1763
- "gemini-2.5-pro",
1764
- "claude-sonnet-4-6",
1765
- "claude-haiku-4-5"
1753
+ { id: "gemini-2.5-flash", grounding: "capability-fact", reason: "L-040 parallel-tool throughput champion (15-75 calls/step)" },
1754
+ { id: "gemini-2.5-pro", grounding: "capability-fact", reason: "Cross-provider tier 1 with strong parallel-tool support" },
1755
+ { id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality safety net for blocked-Flash case" },
1756
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Reduced tool budget \u2014 cliff at 16 fires" }
1766
1757
  ],
1767
- // Cost-sensitive + tolerant. DeepSeek brain-evidence tier 1; Haiku tier 2
1768
- // for quality safety; Flash-Lite emergency floor (onboarded s22).
1758
+ // Cost-sensitive + tolerant. DeepSeek brain-evidence tier 1.
1769
1759
  summarize: [
1770
- "gemini-2.5-flash",
1771
- "deepseek-v4-flash",
1772
- "claude-haiku-4-5",
1773
- "gemini-2.5-flash-lite"
1760
+ { id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost-sensitive primary \u2014 engineer pick" },
1761
+ { id: "deepseek-v4-flash", grounding: "measured", reason: "Brain-validated tier 1 for cost-sensitive summarize workloads", n: 169 },
1762
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Quality safety net" },
1763
+ { id: "gemini-2.5-flash-lite", grounding: "judgment", reason: "Emergency floor \u2014 onboarded s22, no brain evidence yet" }
1774
1764
  ],
1775
- // Brain-validated DeepSeek tier 1 (169 rows, 0% empty); Haiku tier 2;
1776
- // Flash-Lite floor for repeat-prompt workloads (cache-discount 10×).
1765
+ // Brain-validated DeepSeek tier 1 (169 rows, 0% empty rate).
1777
1766
  classify: [
1778
- "gemini-2.5-flash",
1779
- "deepseek-v4-flash",
1780
- "claude-haiku-4-5",
1781
- "gemini-2.5-flash-lite"
1767
+ { id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost-sensitive primary \u2014 engineer pick" },
1768
+ { id: "deepseek-v4-flash", grounding: "measured", reason: "Brain-validated tier 1 (169 rows, 0% empty rate)", n: 169 },
1769
+ { id: "claude-haiku-4-5", grounding: "judgment", reason: "Quality safety net" },
1770
+ { id: "gemini-2.5-flash-lite", grounding: "judgment", reason: "Cache-discount 10\xD7 floor for repeat-prompt workloads" }
1782
1771
  ]
1783
1772
  };
1784
- var STARTER_CHAINS_BY_MODE = {
1773
+ var STARTER_CHAINS = (() => {
1774
+ const out = {};
1775
+ for (const [archetype, entries] of Object.entries(STARTER_CHAINS_GROUNDED)) {
1776
+ out[archetype] = entries.map((e) => e.id);
1777
+ }
1778
+ return out;
1779
+ })();
1780
+ var STARTER_CHAINS_BY_MODE_GROUNDED = {
1785
1781
  hunt: {
1786
1782
  sequential: [
1787
- // V4-Pro: cheap + good reasoning at single-step granularity; no
1788
- // L-040 cliff applies when consumer commits to sequential.
1789
- "deepseek-v4-pro",
1790
- // V4-Flash: cheapest viable; sibling-provider fallback.
1791
- "deepseek-v4-flash",
1792
- // Cross-provider safety net — Sonnet handles sequential agentic loops
1793
- // cleanly; Pro as third-provider tail when no DeepSeek key reachable.
1794
- "claude-sonnet-4-6",
1795
- "gemini-2.5-pro"
1783
+ {
1784
+ id: "deepseek-v4-pro",
1785
+ grounding: "judgment",
1786
+ reason: "alpha.20 E3: cheap + good reasoning at single-step granularity; L-040 cliff silenced when sequential \u2014 hypothesis not yet measured"
1787
+ },
1788
+ {
1789
+ id: "deepseek-v4-flash",
1790
+ grounding: "judgment",
1791
+ reason: "Cheapest viable; sibling-provider fallback"
1792
+ },
1793
+ {
1794
+ id: "claude-sonnet-4-6",
1795
+ grounding: "judgment",
1796
+ reason: "Cross-provider safety net \u2014 Sonnet handles sequential agentic loops cleanly"
1797
+ },
1798
+ {
1799
+ id: "gemini-2.5-pro",
1800
+ grounding: "judgment",
1801
+ reason: "Third-provider tail when no DeepSeek key reachable"
1802
+ }
1796
1803
  ]
1797
1804
  }
1798
1805
  };
1806
+ var STARTER_CHAINS_BY_MODE = (() => {
1807
+ const out = {};
1808
+ for (const [archetype, modes] of Object.entries(STARTER_CHAINS_BY_MODE_GROUNDED)) {
1809
+ if (modes?.sequential) {
1810
+ out[archetype] = {
1811
+ sequential: modes.sequential.map((e) => e.id)
1812
+ };
1813
+ }
1814
+ }
1815
+ return out;
1816
+ })();
1799
1817
  function resolveStarterForMode(archetype, toolOrchestration, allChains) {
1800
1818
  if (toolOrchestration === "sequential") {
1801
1819
  const overlay = STARTER_CHAINS_BY_MODE[archetype]?.sequential;
@@ -1857,6 +1875,114 @@ function getAllStarterChains() {
1857
1875
  }
1858
1876
  return out;
1859
1877
  }
1878
+ function getSequentialStarterChain(archetype) {
1879
+ const overlay = STARTER_CHAINS_BY_MODE[archetype]?.sequential;
1880
+ return overlay ? [...overlay] : void 0;
1881
+ }
1882
+ function copyEntry(e) {
1883
+ const out = { id: e.id, grounding: e.grounding };
1884
+ if (e.reason !== void 0) out.reason = e.reason;
1885
+ if (e.n !== void 0) out.n = e.n;
1886
+ return out;
1887
+ }
1888
+ function lookupStaticEntry(id, archetype) {
1889
+ const archetypeEntries = STARTER_CHAINS_GROUNDED[archetype];
1890
+ if (archetypeEntries) {
1891
+ const hit = archetypeEntries.find((e) => e.id === id);
1892
+ if (hit) return hit;
1893
+ }
1894
+ const seqOverlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
1895
+ if (seqOverlay) {
1896
+ const hit = seqOverlay.find((e) => e.id === id);
1897
+ if (hit) return hit;
1898
+ }
1899
+ return void 0;
1900
+ }
1901
+ function resolveGroundedChainForArchetype(archetype, toolOrchestration) {
1902
+ if (toolOrchestration === "sequential") {
1903
+ const overlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
1904
+ if (overlay) return overlay.map(copyEntry);
1905
+ }
1906
+ const allChains = loadChainsFromBrain();
1907
+ const ids = allChains[archetype];
1908
+ if (!ids) return void 0;
1909
+ return ids.map((id) => {
1910
+ const known = lookupStaticEntry(id, archetype);
1911
+ if (known) return copyEntry(known);
1912
+ return { id, grounding: "judgment" };
1913
+ });
1914
+ }
1915
+ function getDefaultFallbackChainWithGrounding(opts) {
1916
+ const {
1917
+ archetype,
1918
+ primary,
1919
+ maxDepth = 3,
1920
+ policy,
1921
+ reachability,
1922
+ toolOrchestration
1923
+ } = opts;
1924
+ if (maxDepth < 1) {
1925
+ throw new Error(
1926
+ `getDefaultFallbackChainWithGrounding: maxDepth must be >= 1, got ${maxDepth}`
1927
+ );
1928
+ }
1929
+ const starter = resolveGroundedChainForArchetype(archetype, toolOrchestration);
1930
+ if (!starter) {
1931
+ throw new Error(
1932
+ `getDefaultFallbackChainWithGrounding: unknown archetype "${archetype}". Known: ${Object.keys(STARTER_CHAINS_GROUNDED).join(", ")}`
1933
+ );
1934
+ }
1935
+ let chain;
1936
+ if (primary) {
1937
+ const primaryEntry = (() => {
1938
+ const inStarter = starter.find((e) => e.id === primary);
1939
+ if (inStarter) return copyEntry(inStarter);
1940
+ const knownAnywhere = lookupStaticEntry(primary, archetype);
1941
+ if (knownAnywhere) return { ...copyEntry(knownAnywhere), id: primary };
1942
+ return { id: primary, grounding: "judgment" };
1943
+ })();
1944
+ chain = [primaryEntry, ...starter.filter((e) => e.id !== primary)];
1945
+ } else {
1946
+ chain = [...starter];
1947
+ }
1948
+ if (policy?.blockedModels && policy.blockedModels.length > 0) {
1949
+ const blocked = new Set(policy.blockedModels);
1950
+ chain = chain.filter((e) => !blocked.has(e.id));
1951
+ }
1952
+ const seen = /* @__PURE__ */ new Set();
1953
+ const deduped = [];
1954
+ for (const e of chain) {
1955
+ if (!seen.has(e.id)) {
1956
+ seen.add(e.id);
1957
+ deduped.push(e);
1958
+ }
1959
+ }
1960
+ let filtered = deduped;
1961
+ if (reachability) {
1962
+ filtered = deduped.filter((e) => isModelReachable(e.id, reachability));
1963
+ }
1964
+ return filtered.slice(0, maxDepth);
1965
+ }
1966
+ function getStarterChainWithGrounding(archetype) {
1967
+ const entries = STARTER_CHAINS_GROUNDED[archetype];
1968
+ if (!entries) {
1969
+ throw new Error(
1970
+ `getStarterChainWithGrounding: unknown archetype "${archetype}"`
1971
+ );
1972
+ }
1973
+ return entries.map(copyEntry);
1974
+ }
1975
+ function getAllStarterChainsWithGrounding() {
1976
+ const out = {};
1977
+ for (const [archetype, entries] of Object.entries(STARTER_CHAINS_GROUNDED)) {
1978
+ out[archetype] = entries.map(copyEntry);
1979
+ }
1980
+ return out;
1981
+ }
1982
+ function getSequentialStarterChainWithGrounding(archetype) {
1983
+ const overlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
1984
+ return overlay ? overlay.map(copyEntry) : void 0;
1985
+ }
1860
1986
  function ensureCrossProviderTail(opts) {
1861
1987
  const { chain, archetype, apiKeys, envSource } = opts;
1862
1988
  if (chain.length < 1) return { chain };
@@ -2321,6 +2447,17 @@ function mapRowsToPerfMap(rows) {
2321
2447
  }
2322
2448
  return out;
2323
2449
  }
2450
+ function mapRowsToNMap(rows) {
2451
+ const out = /* @__PURE__ */ new Map();
2452
+ for (const row of rows) {
2453
+ if (!isPerfRow(row)) continue;
2454
+ if (typeof row.n !== "number") continue;
2455
+ const existing = out.get(row.model_id) ?? {};
2456
+ existing[row.archetype] = row.n;
2457
+ out.set(row.model_id, existing);
2458
+ }
2459
+ return out;
2460
+ }
2324
2461
  function bundledArchetypePerf() {
2325
2462
  const out = /* @__PURE__ */ new Map();
2326
2463
  for (const profile of allProfiles()) {
@@ -2328,13 +2465,27 @@ function bundledArchetypePerf() {
2328
2465
  }
2329
2466
  return out;
2330
2467
  }
2468
+ function bundledArchetypePerfN() {
2469
+ return /* @__PURE__ */ new Map();
2470
+ }
2331
2471
  var loadArchetypePerfFromBrain = createBrainQueryCache({
2332
2472
  table: "kgauto_archetype_perf",
2333
2473
  mapRows: mapRowsToPerfMap,
2334
2474
  bundledFallback: bundledArchetypePerf
2335
2475
  });
2476
+ var loadArchetypePerfNFromBrain = createBrainQueryCache(
2477
+ {
2478
+ table: "kgauto_archetype_perf",
2479
+ mapRows: mapRowsToNMap,
2480
+ bundledFallback: bundledArchetypePerfN
2481
+ }
2482
+ );
2483
+ var MEASURED_GROUNDING_MIN_N = 10;
2336
2484
  function getArchetypePerfScore(modelId, archetype) {
2337
- return loadArchetypePerfFromBrain().get(modelId)?.[archetype] ?? 5;
2485
+ const score = loadArchetypePerfFromBrain().get(modelId)?.[archetype] ?? 5;
2486
+ const n = loadArchetypePerfNFromBrain().get(modelId)?.[archetype] ?? 0;
2487
+ const grounding = n >= MEASURED_GROUNDING_MIN_N ? "measured" : "judgment";
2488
+ return { score, n, grounding };
2338
2489
  }
2339
2490
 
2340
2491
  // src/models-brain.ts
@@ -2468,6 +2619,7 @@ export {
2468
2619
  CallError,
2469
2620
  DIALECT_VERSION,
2470
2621
  INTENT_ARCHETYPES,
2622
+ MEASURED_GROUNDING_MIN_N,
2471
2623
  PROVIDER_ENV_KEYS,
2472
2624
  allProfiles,
2473
2625
  bucketContext,
@@ -2481,11 +2633,16 @@ export {
2481
2633
  countTokens,
2482
2634
  execute,
2483
2635
  getAllStarterChains,
2636
+ getAllStarterChainsWithGrounding,
2484
2637
  getArchetypePerfScore,
2485
2638
  getDefaultFallbackChain,
2639
+ getDefaultFallbackChainWithGrounding,
2486
2640
  getProfile,
2487
2641
  getReachabilityDiagnostic,
2642
+ getSequentialStarterChain,
2643
+ getSequentialStarterChainWithGrounding,
2488
2644
  getStarterChain,
2645
+ getStarterChainWithGrounding,
2489
2646
  hashShape,
2490
2647
  isArchetype,
2491
2648
  isModelReachable,
@@ -2493,6 +2650,7 @@ export {
2493
2650
  learningKey,
2494
2651
  loadAliasesFromBrain,
2495
2652
  loadArchetypePerfFromBrain,
2653
+ loadArchetypePerfNFromBrain,
2496
2654
  loadChainsFromBrain,
2497
2655
  loadModelsFromBrain,
2498
2656
  loadPricingFromBrain,
@@ -741,5 +741,60 @@ interface OutcomeResult {
741
741
  /** Stable reason code when ok=false. One of: 'brain_not_configured' | 'persistence_failed'. */
742
742
  reason?: string;
743
743
  }
744
+ /**
745
+ * alpha.21 (s78 Entry 1): provenance label on a chain entry. Surfaces WHY
746
+ * an entry sits where it sits so consumers can distinguish:
747
+ *
748
+ * - 'measured' brain has N>=10 rows with a measurable quality
749
+ * outcome backing this placement. The number lives on
750
+ * `ChainEntry.n`.
751
+ * - 'capability-fact' inclusion or exclusion driven by a published or
752
+ * measured CAPABILITY (L-040 cliff, ctx window cap,
753
+ * structured-output support). Not an opinion — a
754
+ * fact about what the model can/can't do.
755
+ * - 'judgment' engineer's pick, no measured backing yet. Cold-start
756
+ * prior; entirely valid until evidence accumulates.
757
+ *
758
+ * "Judgment" is HONEST, not a downgrade. Most of `STARTER_CHAINS` lands here
759
+ * in alpha.21 — that's the point: consumers can SEE the grounding gap and
760
+ * prioritize the measurement work that would graduate them to 'measured'.
761
+ */
762
+ type Grounding = 'measured' | 'capability-fact' | 'judgment';
763
+ /**
764
+ * alpha.21 (s78 Entry 1): a single position in a fallback chain, carrying its
765
+ * provenance label and an optional human-readable reason. The shape replaces
766
+ * the old `string[]` representation everywhere chains are surfaced externally.
767
+ *
768
+ * `n` is REQUIRED when `grounding === 'measured'` — the runtime helper
769
+ * `makeMeasuredEntry()` enforces this. For 'capability-fact' and 'judgment'
770
+ * entries, `n` is undefined.
771
+ */
772
+ interface ChainEntry {
773
+ /** Canonical model id (post-alias). */
774
+ id: string;
775
+ /** Why this entry sits in this position. */
776
+ grounding: Grounding;
777
+ /**
778
+ * Optional one-liner explaining the grounding decision. The inline comments
779
+ * that historically lived next to STARTER_CHAINS entries are now expressed
780
+ * here as machine-readable text.
781
+ */
782
+ reason?: string;
783
+ /**
784
+ * When `grounding === 'measured'`, the brain row count that backs this
785
+ * placement. Undefined for 'capability-fact' and 'judgment' entries.
786
+ */
787
+ n?: number;
788
+ }
789
+ /**
790
+ * alpha.21 introspection shape — a per-archetype chain with grounding on
791
+ * every position. Consumers reading this never see naked string ids;
792
+ * everything carries provenance.
793
+ */
794
+ interface ChainWithGrounding {
795
+ archetype: IntentArchetypeName;
796
+ /** Ordered: position 0 = primary, rising index = fallback positions. */
797
+ entries: ChainEntry[];
798
+ }
744
799
 
745
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type CallAttempt as i, CallError as j, type Constraints as k, type MutationApplied as l, type NormalizedTokens as m, type OutcomeKind as n, type PromptSection as o, type ToolDefinition as p };
800
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type ChainEntry as i, type CallAttempt as j, CallError as k, type ChainWithGrounding as l, type Constraints as m, type MutationApplied as n, type NormalizedTokens as o, type OutcomeKind as p, type PromptSection as q, type ToolDefinition as r };
@@ -741,5 +741,60 @@ interface OutcomeResult {
741
741
  /** Stable reason code when ok=false. One of: 'brain_not_configured' | 'persistence_failed'. */
742
742
  reason?: string;
743
743
  }
744
+ /**
745
+ * alpha.21 (s78 Entry 1): provenance label on a chain entry. Surfaces WHY
746
+ * an entry sits where it sits so consumers can distinguish:
747
+ *
748
+ * - 'measured' brain has N>=10 rows with a measurable quality
749
+ * outcome backing this placement. The number lives on
750
+ * `ChainEntry.n`.
751
+ * - 'capability-fact' inclusion or exclusion driven by a published or
752
+ * measured CAPABILITY (L-040 cliff, ctx window cap,
753
+ * structured-output support). Not an opinion — a
754
+ * fact about what the model can/can't do.
755
+ * - 'judgment' engineer's pick, no measured backing yet. Cold-start
756
+ * prior; entirely valid until evidence accumulates.
757
+ *
758
+ * "Judgment" is HONEST, not a downgrade. Most of `STARTER_CHAINS` lands here
759
+ * in alpha.21 — that's the point: consumers can SEE the grounding gap and
760
+ * prioritize the measurement work that would graduate them to 'measured'.
761
+ */
762
+ type Grounding = 'measured' | 'capability-fact' | 'judgment';
763
+ /**
764
+ * alpha.21 (s78 Entry 1): a single position in a fallback chain, carrying its
765
+ * provenance label and an optional human-readable reason. The shape replaces
766
+ * the old `string[]` representation everywhere chains are surfaced externally.
767
+ *
768
+ * `n` is REQUIRED when `grounding === 'measured'` — the runtime helper
769
+ * `makeMeasuredEntry()` enforces this. For 'capability-fact' and 'judgment'
770
+ * entries, `n` is undefined.
771
+ */
772
+ interface ChainEntry {
773
+ /** Canonical model id (post-alias). */
774
+ id: string;
775
+ /** Why this entry sits in this position. */
776
+ grounding: Grounding;
777
+ /**
778
+ * Optional one-liner explaining the grounding decision. The inline comments
779
+ * that historically lived next to STARTER_CHAINS entries are now expressed
780
+ * here as machine-readable text.
781
+ */
782
+ reason?: string;
783
+ /**
784
+ * When `grounding === 'measured'`, the brain row count that backs this
785
+ * placement. Undefined for 'capability-fact' and 'judgment' entries.
786
+ */
787
+ n?: number;
788
+ }
789
+ /**
790
+ * alpha.21 introspection shape — a per-archetype chain with grounding on
791
+ * every position. Consumers reading this never see naked string ids;
792
+ * everything carries provenance.
793
+ */
794
+ interface ChainWithGrounding {
795
+ archetype: IntentArchetypeName;
796
+ /** Ordered: position 0 = primary, rising index = fallback positions. */
797
+ entries: ChainEntry[];
798
+ }
744
799
 
745
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type CallAttempt as i, CallError as j, type Constraints as k, type MutationApplied as l, type NormalizedTokens as m, type OutcomeKind as n, type PromptSection as o, type ToolDefinition as p };
800
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type Provider as h, type ChainEntry as i, type CallAttempt as j, CallError as k, type ChainWithGrounding as l, type Constraints as m, type MutationApplied as n, type NormalizedTokens as o, type OutcomeKind as p, type PromptSection as q, type ToolDefinition as r };
@@ -1,4 +1,4 @@
1
- import { h as Provider } from './ir-DTMbSnyE.mjs';
1
+ import { h as Provider } from './ir-CruZBtpK.mjs';
2
2
  import { IntentArchetypeName } from './dialect.mjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { h as Provider } from './ir-CsTU4cMB.js';
1
+ import { h as Provider } from './ir-Wr5lc8Mi.js';
2
2
  import { IntentArchetypeName } from './dialect.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { l as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, i as CallAttempt } from './ir-CsTU4cMB.js';
1
+ import { n as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, j as CallAttempt } from './ir-Wr5lc8Mi.js';
2
2
 
3
3
  /**
4
4
  * Glass-Box observability types (alpha.17).
@@ -1,4 +1,4 @@
1
- import { l as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, i as CallAttempt } from './ir-DTMbSnyE.mjs';
1
+ import { n as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, j as CallAttempt } from './ir-CruZBtpK.mjs';
2
2
 
3
3
  /**
4
4
  * Glass-Box observability types (alpha.17).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warmdrift/kgauto-compiler",
3
- "version": "2.0.0-alpha.20",
3
+ "version": "2.0.0-alpha.21",
4
4
  "description": "Prompt compiler + central learning brain for multi-model AI apps. Swap models without rewriting prompts.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",