@warmdrift/kgauto-compiler 2.0.0-alpha.85 → 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.
@@ -363,6 +363,26 @@ interface CompilePolicy {
363
363
  * advisor; otherwise unspecified.
364
364
  */
365
365
  posture?: 'locked' | 'preferred' | 'open';
366
+ /**
367
+ * alpha.87 — what compile() does with a model id no profile covers
368
+ * (gateway review §6; both cold readers hit this wall).
369
+ *
370
+ * - `'refuse'` (default) — throw, naming `registerProfiles()` and this
371
+ * option. The fleet's safety posture, unchanged: guards can only be
372
+ * honest about models kgauto knows.
373
+ * - `'best-effort'` — synthesize a conservative profile (provider
374
+ * inferred from the id prefix; wire mechanics borrowed from a bundled
375
+ * profile of that provider; NO cliffs, NO measured knowledge, cost
376
+ * UNKNOWN and recorded as 0) and compile anyway, with a loud
377
+ * `cliffWarnings` entry + `best_effort_profile` mutation naming
378
+ * every guard that is skipped. If the provider cannot be inferred,
379
+ * refusal still applies — best-effort cannot lower a wire format it
380
+ * cannot name.
381
+ *
382
+ * The option converts "wait for the maintainer's weekend" into a
383
+ * consumer's informed choice; it does not make the unknown model safe.
384
+ */
385
+ onUnprofiledModel?: 'refuse' | 'best-effort';
366
386
  }
367
387
  /**
368
388
  * alpha.41 — entry in `PromptIR.models[]`. Either a literal model id (the
@@ -899,6 +919,69 @@ interface CompileResult {
899
919
  * number the cost-watcher can weigh against the lift.
900
920
  */
901
921
  disciplineGateTokens: number;
922
+ /**
923
+ * alpha.87 — which world answered THIS compile, per data source (the
924
+ * `per-source-freshness-marker-on-callresult` ask, PB s76). kgauto
925
+ * legitimately ranks on bundled profiles when cold and brain-re-ranked
926
+ * profiles when warm, and before this field the response said nothing
927
+ * about which had answered — PB drew three wrong conclusions across
928
+ * s74–s76 from observations taken at unknown temperature. A FLAT marker
929
+ * was rejected in the s76 consult: the app-scoped gates (measured
930
+ * failure, promotions, exclusions, promote-ready) carry cache state
931
+ * independent of the shared config snapshot, and a config-derived
932
+ * marker would read 'brain' in exactly the window where the
933
+ * measured-failure gate is still cold.
934
+ *
935
+ * Semantics: `config` is `'brain'` iff the shared `/v2/config` snapshot
936
+ * held fetched data at compile time (else `'bundled'`). The per-gate
937
+ * fields are `'warm'` iff a successful app-scoped load had completed in
938
+ * this process — `'cold'` covers never-loaded, load-failed, and
939
+ * feature-disabled alike, because in all three the gate read no data.
940
+ * With alpha.73/.86 prefetch + `gateWarmupMs`, a `call()` after warmup
941
+ * should read all-warm; a cold isolate's first compile may not.
942
+ */
943
+ freshness: {
944
+ config: 'bundled' | 'brain';
945
+ measuredFailure: 'cold' | 'warm';
946
+ promotions: 'cold' | 'warm';
947
+ exclusions: 'cold' | 'warm';
948
+ promoteReady: 'cold' | 'warm';
949
+ };
950
+ /**
951
+ * alpha.87 — per-section cost attribution (cc's
952
+ * `per-section-cost-attribution-in-diagnostics` ask, from Sacha's
953
+ * oracle read). `compile()` already receives sections IDed by the
954
+ * consumer, so this itemization is arithmetic on values the compiler
955
+ * computes anyway: zero model calls, no brain write, counts and IDs
956
+ * only — never section text (G3-compatible by construction). Always-on:
957
+ * an itemization nobody remembers to ask for is absent at the moment
958
+ * it is needed, and the payload is one small object per section.
959
+ *
960
+ * One row per INPUT section, in input order — dropped sections appear
961
+ * with `kept: false` and zero cost so a consumer can see what a pass
962
+ * removed and what it was worth.
963
+ *
964
+ * The cacheable interaction is deliberately two explicit columns
965
+ * rather than one blended number or a compile-time `cacheState` guess:
966
+ * whether a given call pays the first-call or the warm price is decided
967
+ * at the provider AFTER compile, so the honest compile-time statement
968
+ * is both prices. `estCostUsdFirstCall` is the section's tokens at the
969
+ * selected model's uncached input price (provider cache-WRITE
970
+ * surcharges, e.g. Anthropic's 1.25×, are not modeled — this
971
+ * understates first-call cost slightly). `estCostUsdWarm` applies the
972
+ * profile's cache-read discount when the section sits in an ACTIVE
973
+ * cacheable prefix (cacheable, and the prefix met the provider's
974
+ * minimum); otherwise it equals `estCostUsdFirstCall` — for a
975
+ * non-cached section the two worlds cost the same.
976
+ */
977
+ sections: Array<{
978
+ id: string;
979
+ tokens: number;
980
+ kept: boolean;
981
+ cacheable: boolean;
982
+ estCostUsdFirstCall: number;
983
+ estCostUsdWarm: number;
984
+ }>;
902
985
  };
903
986
  /**
904
987
  * alpha.33. Structured `system` for AI-SDK `streamText({ system })`
@@ -1084,6 +1167,13 @@ interface ShadowProbeConfig {
1084
1167
  skipSlowTierInSync?: boolean;
1085
1168
  }
1086
1169
  interface CallOptions {
1170
+ /**
1171
+ * alpha.86 — self-mark for synthetic callers (canaries, smokes, eval
1172
+ * replays, probes). Passed through to every outcome row this call
1173
+ * records, including failure rows. OMIT for real traffic. See
1174
+ * {@link OutcomeSource}.
1175
+ */
1176
+ source?: OutcomeSource;
1087
1177
  /**
1088
1178
  * alpha.84 — fires once per FAILED attempt during the fallback walk, before
1089
1179
  * the walk continues. IC-Cairn's filing, 2026-07-29.
@@ -1458,9 +1548,34 @@ interface OracleScore {
1458
1548
  /** Free-form explanation for debugging. */
1459
1549
  rationale?: string;
1460
1550
  }
1551
+ /**
1552
+ * alpha.86 — who originated an outcome row (migration 056).
1553
+ *
1554
+ * Absent/undefined means ORGANIC: a real consumer call on behalf of a real
1555
+ * user. Consumers change nothing. Synthetic writers — canaries, smoke
1556
+ * gates, eval replays, probe harnesses — self-mark, so liveness and volume
1557
+ * rules can compute over consumer-originated rows only.
1558
+ *
1559
+ * The incident this closes (cost-watch 2026-08-06 → 08-08): playbacksam's
1560
+ * daily canary wrote exactly 8 rows/day for 13 straight days while PB's
1561
+ * organic traffic was near-zero, and the liveness rule scored PB the
1562
+ * healthiest consumer in the portfolio. On 08-08 EVERY row the brain
1563
+ * received in 24h was canary, and no rule could say so — distinguishing a
1564
+ * replay from real traffic took a hand-reconstructed time-window +
1565
+ * token-fingerprint argument, three mornings running. A consumer whose
1566
+ * only rows are written by kgauto's own machinery is dark, not healthy;
1567
+ * this column is what lets a rule print that sentence.
1568
+ */
1569
+ type OutcomeSource = 'canary' | 'smoke' | 'eval' | 'probe' | 'synthetic';
1461
1570
  interface RecordInput {
1462
1571
  /** Handle from CompileResult. */
1463
1572
  handle: string;
1573
+ /**
1574
+ * alpha.86 — self-mark for synthetic writers (migration 056). OMIT for
1575
+ * real traffic; never write an explicit "organic" value. See
1576
+ * {@link OutcomeSource}.
1577
+ */
1578
+ source?: OutcomeSource;
1464
1579
  /** Actual tokens consumed (post-call). */
1465
1580
  tokensIn: number;
1466
1581
  tokensOut: number;
@@ -1753,4 +1868,4 @@ interface PerAxisMetrics {
1753
1868
  /** Per-axis metrics keyed by model — used for chain-comparison views. */
1754
1869
  type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
1755
1870
 
1756
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, captureGoldenIr as D, type EffortLevel as E, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, hasMutation as J, mutationId as K, parseGoldenCaptureRate as L, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, resolveGoldenCaptureRate as Q, type RecordInput as R, type SystemModelMessage as S, type ToolCall as T, shouldCaptureGolden as U, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OracleScore as h, type Adapter as i, type PerAxisMetrics as j, type Provider as k, type ChainEntry as l, type CallAttempt as m, CallError as n, type ChainModelEntry as o, type ChainWithGrounding as p, type Constraints as q, type GoldenCaptureOptions as r, type MutationApplied as s, type NormalizedTokens as t, type OutcomeKind as u, type PerAxisMetricsByModel as v, type PromptSection as w, type SectionKind as x, type ShadowProbeConfig as y, type ToolDefinition as z };
1871
+ export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type ToolDefinition as D, type EffortLevel as E, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, captureGoldenIr as J, hasMutation as K, mutationId as L, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, parseGoldenCaptureRate as Q, type RecordInput as R, type SystemModelMessage as S, type ToolCall as T, resolveGoldenCaptureRate as U, shouldCaptureGolden as V, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OutcomeSource as h, type OracleScore as i, type Adapter as j, type PerAxisMetrics as k, type Provider as l, type ChainEntry as m, type CallAttempt as n, CallError as o, type ChainModelEntry as p, type ChainWithGrounding as q, type Constraints as r, type GoldenCaptureOptions as s, type MutationApplied as t, type NormalizedTokens as u, type OutcomeKind as v, type PerAxisMetricsByModel as w, type PromptSection as x, type SectionKind as y, type ShadowProbeConfig as z };
@@ -28,7 +28,7 @@ __export(key_health_exports, {
28
28
  module.exports = __toCommonJS(key_health_exports);
29
29
 
30
30
  // src/version.ts
31
- var LIBRARY_VERSION = "2.0.0-alpha.85";
31
+ var LIBRARY_VERSION = "2.0.0-alpha.87";
32
32
 
33
33
  // src/key-health.ts
34
34
  var JSON_HEADERS = { "Content-Type": "application/json" };
@@ -3,7 +3,7 @@ import {
3
3
  KEY_FINGERPRINT_LENGTH,
4
4
  createKeyHealthRoute,
5
5
  keyFingerprint
6
- } from "./chunk-WXN7FNXP.mjs";
6
+ } from "./chunk-GMZT4ZXD.mjs";
7
7
  export {
8
8
  KEY_FINGERPRINT_DOMAIN,
9
9
  KEY_FINGERPRINT_LENGTH,
@@ -1,4 +1,4 @@
1
- import { k as Provider } from './ir-JUoybVM-.mjs';
1
+ import { l as Provider } from './ir-P3NEU8z4.mjs';
2
2
  import { IntentArchetypeName } from './dialect.mjs';
3
3
 
4
4
  /**
@@ -263,6 +263,15 @@ interface ModelProfile {
263
263
  * See `ArchetypeConvention` for field semantics.
264
264
  */
265
265
  archetypeConventions?: ArchetypeConvention[];
266
+ /**
267
+ * alpha.87 — true ONLY on profiles synthesized by
268
+ * `onUnprofiledModel: 'best-effort'`. Lets compile() (and any consumer)
269
+ * distinguish "kgauto knows this model" from "kgauto is winging it with
270
+ * borrowed wire mechanics" on every call, not just the one that
271
+ * triggered synthesis. Never set on bundled, brain, or
272
+ * `registerProfiles()` entries.
273
+ */
274
+ bestEffort?: true;
266
275
  }
267
276
  /**
268
277
  * Representative p50 latency (ms) per tier. Coarse on purpose — used only to
@@ -291,6 +300,38 @@ interface ProfileBrainHook {
291
300
  }
292
301
  /** @internal — called by models-brain.ts at module load. */
293
302
  declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
303
+ /**
304
+ * Register consumer-supplied profiles. They take precedence over both
305
+ * brain-curated and bundled profiles for the same id (explicit > learned >
306
+ * shipped — see block comment above for the tradeoff). Re-registering an
307
+ * id overwrites the previous consumer entry, including any best-effort
308
+ * synthesized profile.
309
+ */
310
+ declare function registerProfiles(profiles: readonly ModelProfile[]): void;
311
+ /** @internal — test hook. */
312
+ declare function _testClearConsumerProfiles(): void;
313
+ /** Provider inference for best-effort mode — id prefix conventions only. */
314
+ declare function inferProviderFromId(id: string): Provider | undefined;
315
+ /**
316
+ * alpha.87 — best-effort profile synthesis for unprofiled ids (opt-in via
317
+ * `CompilePolicy.onUnprofiledModel: 'best-effort'`; the default posture
318
+ * stays refuse). Returns undefined when the provider cannot be inferred
319
+ * from the id or kgauto ships no donor profile for that provider — in
320
+ * both cases the caller falls back to the standard refusal, which names
321
+ * `registerProfiles()` as the informed path.
322
+ *
323
+ * What a synthesized profile is: the inferred provider's wire mechanics
324
+ * (LoweringSpec / systemPromptMode / streaming are provider-wide, borrowed
325
+ * from a current bundled profile of that provider) around deliberately
326
+ * conservative capability claims — no cliffs, no recovery, no measured
327
+ * knowledge, `structuredOutput: 'none'`, sequential tools, modest output
328
+ * budget, and **cost 0 because cost is UNKNOWN** (cost gates and cost
329
+ * attribution are meaningless for this model; the compile carries a loud
330
+ * warning saying exactly that). It is registered into the consumer index
331
+ * on first synthesis so every later lookup in the process (fallback walk,
332
+ * passes, telemetry) sees one consistent object.
333
+ */
334
+ declare function bestEffortProfile(id: string): ModelProfile | undefined;
294
335
  /**
295
336
  * Resolve a model id to its canonical form (alias → canonical, unknown ids
296
337
  * returned unchanged). This is the same resolution `getProfile` applies, so
@@ -308,4 +349,4 @@ declare function allProfiles(): readonly ModelProfile[];
308
349
  declare function allProfilesRaw(): readonly ModelProfile[];
309
350
  declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
310
351
 
311
- export { ALIASES, type ArchetypeConvention, type CacheStrategy, type CliffRule, LATENCY_TIER_MS, type LatencyTier, type LoweringSpec, type ModelProfile, type RecoveryRule, type StructuredOutputCapability, type SystemPromptMode, _setProfileBrainHook, allProfiles, allProfilesRaw, getProfile, latencyTierOf, profilesByProvider, resolveModelAlias, tryGetProfile };
352
+ export { ALIASES, type ArchetypeConvention, type CacheStrategy, type CliffRule, LATENCY_TIER_MS, type LatencyTier, type LoweringSpec, type ModelProfile, type RecoveryRule, type StructuredOutputCapability, type SystemPromptMode, _setProfileBrainHook, _testClearConsumerProfiles, allProfiles, allProfilesRaw, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile };
@@ -1,4 +1,4 @@
1
- import { k as Provider } from './ir-DfrM71pA.js';
1
+ import { l as Provider } from './ir-ZgN2KkuF.js';
2
2
  import { IntentArchetypeName } from './dialect.js';
3
3
 
4
4
  /**
@@ -263,6 +263,15 @@ interface ModelProfile {
263
263
  * See `ArchetypeConvention` for field semantics.
264
264
  */
265
265
  archetypeConventions?: ArchetypeConvention[];
266
+ /**
267
+ * alpha.87 — true ONLY on profiles synthesized by
268
+ * `onUnprofiledModel: 'best-effort'`. Lets compile() (and any consumer)
269
+ * distinguish "kgauto knows this model" from "kgauto is winging it with
270
+ * borrowed wire mechanics" on every call, not just the one that
271
+ * triggered synthesis. Never set on bundled, brain, or
272
+ * `registerProfiles()` entries.
273
+ */
274
+ bestEffort?: true;
266
275
  }
267
276
  /**
268
277
  * Representative p50 latency (ms) per tier. Coarse on purpose — used only to
@@ -291,6 +300,38 @@ interface ProfileBrainHook {
291
300
  }
292
301
  /** @internal — called by models-brain.ts at module load. */
293
302
  declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
303
+ /**
304
+ * Register consumer-supplied profiles. They take precedence over both
305
+ * brain-curated and bundled profiles for the same id (explicit > learned >
306
+ * shipped — see block comment above for the tradeoff). Re-registering an
307
+ * id overwrites the previous consumer entry, including any best-effort
308
+ * synthesized profile.
309
+ */
310
+ declare function registerProfiles(profiles: readonly ModelProfile[]): void;
311
+ /** @internal — test hook. */
312
+ declare function _testClearConsumerProfiles(): void;
313
+ /** Provider inference for best-effort mode — id prefix conventions only. */
314
+ declare function inferProviderFromId(id: string): Provider | undefined;
315
+ /**
316
+ * alpha.87 — best-effort profile synthesis for unprofiled ids (opt-in via
317
+ * `CompilePolicy.onUnprofiledModel: 'best-effort'`; the default posture
318
+ * stays refuse). Returns undefined when the provider cannot be inferred
319
+ * from the id or kgauto ships no donor profile for that provider — in
320
+ * both cases the caller falls back to the standard refusal, which names
321
+ * `registerProfiles()` as the informed path.
322
+ *
323
+ * What a synthesized profile is: the inferred provider's wire mechanics
324
+ * (LoweringSpec / systemPromptMode / streaming are provider-wide, borrowed
325
+ * from a current bundled profile of that provider) around deliberately
326
+ * conservative capability claims — no cliffs, no recovery, no measured
327
+ * knowledge, `structuredOutput: 'none'`, sequential tools, modest output
328
+ * budget, and **cost 0 because cost is UNKNOWN** (cost gates and cost
329
+ * attribution are meaningless for this model; the compile carries a loud
330
+ * warning saying exactly that). It is registered into the consumer index
331
+ * on first synthesis so every later lookup in the process (fallback walk,
332
+ * passes, telemetry) sees one consistent object.
333
+ */
334
+ declare function bestEffortProfile(id: string): ModelProfile | undefined;
294
335
  /**
295
336
  * Resolve a model id to its canonical form (alias → canonical, unknown ids
296
337
  * returned unchanged). This is the same resolution `getProfile` applies, so
@@ -308,4 +349,4 @@ declare function allProfiles(): readonly ModelProfile[];
308
349
  declare function allProfilesRaw(): readonly ModelProfile[];
309
350
  declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
310
351
 
311
- export { ALIASES, type ArchetypeConvention, type CacheStrategy, type CliffRule, LATENCY_TIER_MS, type LatencyTier, type LoweringSpec, type ModelProfile, type RecoveryRule, type StructuredOutputCapability, type SystemPromptMode, _setProfileBrainHook, allProfiles, allProfilesRaw, getProfile, latencyTierOf, profilesByProvider, resolveModelAlias, tryGetProfile };
352
+ export { ALIASES, type ArchetypeConvention, type CacheStrategy, type CliffRule, LATENCY_TIER_MS, type LatencyTier, type LoweringSpec, type ModelProfile, type RecoveryRule, type StructuredOutputCapability, type SystemPromptMode, _setProfileBrainHook, _testClearConsumerProfiles, allProfiles, allProfilesRaw, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile };