@warmdrift/kgauto-compiler 2.0.0-alpha.63 → 2.0.0-alpha.65

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-B2dRyJXO.mjs';
2
- export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, E as EffortLevel, F as FallbackReason, r as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, s as MutationApplied, t as NormalizedTokens, u as OutcomeKind, v as PerAxisMetricsByModel, w as PromptSection, x as SectionKind, y as ShadowProbeConfig, T as ToolCall, z as ToolDefinition, D as captureGoldenIr, J as parseGoldenCaptureRate, K as resolveGoldenCaptureRate, L as shouldCaptureGolden } from './ir-B2dRyJXO.mjs';
1
+ import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-9rrfI3yB.mjs';
2
+ export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, E as EffortLevel, F as FallbackReason, r as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, s as MutationApplied, t as NormalizedTokens, u as OutcomeKind, v as PerAxisMetricsByModel, w as PromptSection, x as SectionKind, y as ShadowProbeConfig, T as ToolCall, z as ToolDefinition, D as captureGoldenIr, J as parseGoldenCaptureRate, K as resolveGoldenCaptureRate, L as shouldCaptureGolden } from './ir-9rrfI3yB.mjs';
3
3
  import { ModelProfile, ArchetypeConvention } from './profiles.mjs';
4
4
  export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, latencyTierOf, profilesByProvider, tryGetProfile } from './profiles.mjs';
5
5
  export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.mjs';
@@ -376,6 +376,14 @@ interface BrainQueryConfig {
376
376
  * advisory).
377
377
  */
378
378
  findingsExclusions?: boolean;
379
+ /**
380
+ * alpha.64 — hard opt-out of the surface-promotions fetch layer (Stage 2).
381
+ * Default true; only matters when consent (`BrainConfig.autoPromote` /
382
+ * `KGAUTO_AUTO_PROMOTE`) is present — without consent the layer is off
383
+ * regardless. Set `false` to disable the fetch even while consented
384
+ * (debug/emergency lever).
385
+ */
386
+ promotions?: boolean;
379
387
  /** SWR window in ms. Default 300_000 (5 min). */
380
388
  cacheTtlMs?: number;
381
389
  /** Override the GET URL when the read endpoint differs from the write one.
@@ -388,6 +396,13 @@ interface BrainQueryConfig {
388
396
  * Defaults to `https://kgauto-dashboard.vercel.app/api/kgauto-v2/findings/exclusions`.
389
397
  */
390
398
  findingsEndpoint?: string;
399
+ /**
400
+ * alpha.64 — override the surface-promotions endpoint (Stage 2). Only
401
+ * consulted when the consumer opted in via `BrainConfig.autoPromote` /
402
+ * `KGAUTO_AUTO_PROMOTE`. Library appends `?app_id=X`. Defaults to
403
+ * `https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions`.
404
+ */
405
+ promotionsEndpoint?: string;
391
406
  }
392
407
  interface BrainConfig {
393
408
  /** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
@@ -437,6 +452,27 @@ interface BrainConfig {
437
452
  * not affected.
438
453
  */
439
454
  timeoutMs?: number;
455
+ /**
456
+ * alpha.64 (Stage 2 of the eval trust ladder) — consent switch for the
457
+ * surface-promotion routing effect. Default OFF.
458
+ *
459
+ * When true (or when the `KGAUTO_AUTO_PROMOTE` env var is '1'/'true' and
460
+ * this field is left undefined — env-as-consent, the KGAUTO_GOLDEN_CAPTURE
461
+ * precedent; an explicit `false` here overrides the env), compile()
462
+ * consults the brain's active `kgauto_promotions` rows for this app and
463
+ * boosts the promoted model at scoring time. Promotions are written only
464
+ * by the automated golden-eval trigger after a promote-ready verdict on a
465
+ * price-dominant (cheaper) candidate, and every promotion sits behind the
466
+ * 7-day rollback guard (daily watcher auto-reverts on regression vs the
467
+ * frozen baseline).
468
+ *
469
+ * Not opted in ⇒ promotions have ZERO routing effect (they remain visible
470
+ * as advisories + dashboard rows). Consumer sovereignty is preserved even
471
+ * when opted in: `forceModel`, `policy.blockedModels`, and cost ceilings
472
+ * always win, and a non-empty `policy.preferredModels` defers the
473
+ * promotion entirely.
474
+ */
475
+ autoPromote?: boolean;
440
476
  }
441
477
  declare function configureBrain(config: BrainConfig): void;
442
478
  declare function clearBrain(): void;
@@ -887,7 +923,7 @@ declare function runGoldenEval(opts: GoldenEvalOptions): Promise<GoldenEvalRunRe
887
923
  * guard in `tests/version.test.ts` fails the suite (and therefore
888
924
  * `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
889
925
  */
890
- declare const LIBRARY_VERSION = "2.0.0-alpha.63";
926
+ declare const LIBRARY_VERSION = "2.0.0-alpha.65";
891
927
 
892
928
  /**
893
929
  * Oracle contract — how an app tells the brain whether a response was good.
@@ -1772,7 +1808,7 @@ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxis
1772
1808
  * no execute() handler, no env-var convention). Narrowing here keeps the
1773
1809
  * reachability check structurally honest.
1774
1810
  */
1775
- type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek';
1811
+ type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot';
1776
1812
  /**
1777
1813
  * Per-provider env var names kgauto recognizes. Order doesn't matter —
1778
1814
  * first-present wins. Multiple names per provider supported because Google
@@ -2630,6 +2666,114 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
2630
2666
  reason: string;
2631
2667
  }>;
2632
2668
 
2669
+ /**
2670
+ * promotions-brain — alpha.64 Stage-2 substrate.
2671
+ *
2672
+ * Per-tenant SWR cache for the `kgauto_promotions` table populated by the
2673
+ * golden-eval trigger's auto-promote actor (Stage 2 of the eval trust
2674
+ * ladder: auto-promote downswaps behind the 7-day rollback guard). Mirrors
2675
+ * `promote-ready-brain.ts` shape where applicable; this is the read-side
2676
+ * substrate for the compile-time promotion boost in `passScoreTargets`.
2677
+ *
2678
+ * Design contract:
2679
+ * command-center/advisory/kgauto/2026-07-18_stage2-auto-promote-design.md
2680
+ *
2681
+ * Consent posture: the routing effect is OPT-IN, default OFF. The cache is
2682
+ * only activated by `configureBrain()` when the consumer opted in via
2683
+ * `BrainConfig.autoPromote: true` or the `KGAUTO_AUTO_PROMOTE` env var
2684
+ * (config field wins when both are present — mirror of the
2685
+ * `KGAUTO_GOLDEN_CAPTURE` env-as-consent precedent). Not opted in ⇒ this
2686
+ * module never fetches and `getApplicablePromotion` returns undefined ⇒
2687
+ * zero behavior change anywhere in compile().
2688
+ *
2689
+ * Architecture (mirror of promote-ready-brain):
2690
+ * - Sync API surface: `getApplicablePromotion({ appId, archetype })`
2691
+ * returns immediately. First call returns undefined (cold) and fires an
2692
+ * async refresh; subsequent calls within TTL return brain data.
2693
+ * - Per-appId snapshot; one fetch per appId per TTL window.
2694
+ * - Tolerant: brain down / misconfigured / unexpected shape → undefined.
2695
+ * Never throws. Warns once per process.
2696
+ *
2697
+ * A rollback (`status='rolled_back'` PATCHed by the promotion-guard
2698
+ * watcher) drops the row from the endpoint's `status=active` filter, so
2699
+ * routing reverts within one TTL window — the mechanism the 7-day guard's
2700
+ * auto-revert rests on.
2701
+ */
2702
+
2703
+ /**
2704
+ * One active surface promotion, camelCase-mapped at the boundary from the
2705
+ * snake_case endpoint row (typed-boundary-transformer convention).
2706
+ */
2707
+ interface PromotionRow {
2708
+ /** Brain row id — cited in the `promotion-applied` mutation for Glass-Box. */
2709
+ id: number;
2710
+ /** Intent archetype the promotion applies to. */
2711
+ archetype: string;
2712
+ /** The model this surface now routes to. */
2713
+ promotedModel: string;
2714
+ /** The model it replaced (the eval's incumbent). */
2715
+ incumbentModel: string;
2716
+ /** The promote-ready kgauto_golden_eval_runs row this rests on. */
2717
+ evalRunId: number | null;
2718
+ /**
2719
+ * Evidence-supersedes-judgment: skip the alpha.49 schema-weak
2720
+ * quality-gate penalty for the promoted model on this surface (the eval
2721
+ * measured the schema floor holding on real workload).
2722
+ */
2723
+ suppressQualityGate: boolean;
2724
+ /** ISO timestamp the promotion went active. */
2725
+ promotedAt: string;
2726
+ }
2727
+ interface PromotionsRuntime {
2728
+ /** Endpoint base URL. The library appends `?app_id=<id>`. */
2729
+ endpoint: string;
2730
+ /** Stale-while-revalidate window in ms. */
2731
+ ttlMs: number;
2732
+ /** Pluggable fetch. */
2733
+ fetchImpl: typeof fetch;
2734
+ /** Optional warn hook. */
2735
+ onError?: (err: unknown) => void;
2736
+ }
2737
+ /**
2738
+ * Default endpoint hosted on the kgauto-dashboard. Serves `status='active'`
2739
+ * kgauto_promotions rows for one app_id. Mirrors the findings convention.
2740
+ */
2741
+ declare const DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
2742
+ /**
2743
+ * True when the KGAUTO_AUTO_PROMOTE env var opts this process in.
2744
+ * Accepted truthy forms: '1', 'true' (case-insensitive). Everything else —
2745
+ * unset, '', '0', 'false' — is OFF. Read at configureBrain() time, not per
2746
+ * call.
2747
+ */
2748
+ declare function isAutoPromoteEnabledFromEnv(envSource?: Record<string, string | undefined>): boolean;
2749
+ /**
2750
+ * Wire (or rewire) the runtime. Pass undefined to disable. Resets all
2751
+ * snapshots. Called from `configureBrain()` ONLY when the consumer opted in.
2752
+ */
2753
+ declare function configurePromotionsBrain(rt: PromotionsRuntime | undefined): void;
2754
+ /** Sync introspection — is the promotions brain active (i.e. opted in)? */
2755
+ declare function isPromotionsBrainActive(): boolean;
2756
+ interface GetApplicablePromotionOpts {
2757
+ /** App id to read promotions for. Required. */
2758
+ appId: string;
2759
+ /** Archetype of the compile in flight. Required. */
2760
+ archetype: IntentArchetypeName | string;
2761
+ }
2762
+ /**
2763
+ * Sync reader. Returns the active promotion for `(appId, archetype)` or
2764
+ * undefined. First call returns undefined and triggers async refresh;
2765
+ * subsequent calls within TTL return brain data. The brain enforces one
2766
+ * active promotion per surface (partial unique index), so at most one row
2767
+ * matches.
2768
+ *
2769
+ * NEVER throws. Not configured / brain down / cold → undefined.
2770
+ */
2771
+ declare function getApplicablePromotion(opts: GetApplicablePromotionOpts): PromotionRow | undefined;
2772
+ /** Reset module state. Tests must call between cases. */
2773
+ declare function _testResetPromotions(): void;
2774
+ /** Wait for any in-flight refresh to settle. */
2775
+ declare function _testWaitForPromotionsRefresh(): Promise<void>;
2776
+
2633
2777
  /**
2634
2778
  * @warmdrift/kgauto v2 — prompt compiler + central learning brain.
2635
2779
  *
@@ -2676,4 +2820,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
2676
2820
  */
2677
2821
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
2678
2822
 
2679
- export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
2823
+ export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetApplicablePromotionOpts, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, type PromotionRow, type PromotionsRuntime, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, _testResetPromotions, _testWaitForPromotionsRefresh, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configurePromotionsBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isAutoPromoteEnabledFromEnv, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isPromotionsBrainActive, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-ClU56aBc.js';
2
- export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, E as EffortLevel, F as FallbackReason, r as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, s as MutationApplied, t as NormalizedTokens, u as OutcomeKind, v as PerAxisMetricsByModel, w as PromptSection, x as SectionKind, y as ShadowProbeConfig, T as ToolCall, z as ToolDefinition, D as captureGoldenIr, J as parseGoldenCaptureRate, K as resolveGoldenCaptureRate, L as shouldCaptureGolden } from './ir-ClU56aBc.js';
1
+ import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-Dx_UXPfP.js';
2
+ export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, E as EffortLevel, F as FallbackReason, r as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, s as MutationApplied, t as NormalizedTokens, u as OutcomeKind, v as PerAxisMetricsByModel, w as PromptSection, x as SectionKind, y as ShadowProbeConfig, T as ToolCall, z as ToolDefinition, D as captureGoldenIr, J as parseGoldenCaptureRate, K as resolveGoldenCaptureRate, L as shouldCaptureGolden } from './ir-Dx_UXPfP.js';
3
3
  import { ModelProfile, ArchetypeConvention } from './profiles.js';
4
4
  export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, latencyTierOf, profilesByProvider, tryGetProfile } from './profiles.js';
5
5
  export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.js';
@@ -376,6 +376,14 @@ interface BrainQueryConfig {
376
376
  * advisory).
377
377
  */
378
378
  findingsExclusions?: boolean;
379
+ /**
380
+ * alpha.64 — hard opt-out of the surface-promotions fetch layer (Stage 2).
381
+ * Default true; only matters when consent (`BrainConfig.autoPromote` /
382
+ * `KGAUTO_AUTO_PROMOTE`) is present — without consent the layer is off
383
+ * regardless. Set `false` to disable the fetch even while consented
384
+ * (debug/emergency lever).
385
+ */
386
+ promotions?: boolean;
379
387
  /** SWR window in ms. Default 300_000 (5 min). */
380
388
  cacheTtlMs?: number;
381
389
  /** Override the GET URL when the read endpoint differs from the write one.
@@ -388,6 +396,13 @@ interface BrainQueryConfig {
388
396
  * Defaults to `https://kgauto-dashboard.vercel.app/api/kgauto-v2/findings/exclusions`.
389
397
  */
390
398
  findingsEndpoint?: string;
399
+ /**
400
+ * alpha.64 — override the surface-promotions endpoint (Stage 2). Only
401
+ * consulted when the consumer opted in via `BrainConfig.autoPromote` /
402
+ * `KGAUTO_AUTO_PROMOTE`. Library appends `?app_id=X`. Defaults to
403
+ * `https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions`.
404
+ */
405
+ promotionsEndpoint?: string;
391
406
  }
392
407
  interface BrainConfig {
393
408
  /** Brain HTTP endpoint base URL (e.g., https://kgauto-brain.vercel.app/api). */
@@ -437,6 +452,27 @@ interface BrainConfig {
437
452
  * not affected.
438
453
  */
439
454
  timeoutMs?: number;
455
+ /**
456
+ * alpha.64 (Stage 2 of the eval trust ladder) — consent switch for the
457
+ * surface-promotion routing effect. Default OFF.
458
+ *
459
+ * When true (or when the `KGAUTO_AUTO_PROMOTE` env var is '1'/'true' and
460
+ * this field is left undefined — env-as-consent, the KGAUTO_GOLDEN_CAPTURE
461
+ * precedent; an explicit `false` here overrides the env), compile()
462
+ * consults the brain's active `kgauto_promotions` rows for this app and
463
+ * boosts the promoted model at scoring time. Promotions are written only
464
+ * by the automated golden-eval trigger after a promote-ready verdict on a
465
+ * price-dominant (cheaper) candidate, and every promotion sits behind the
466
+ * 7-day rollback guard (daily watcher auto-reverts on regression vs the
467
+ * frozen baseline).
468
+ *
469
+ * Not opted in ⇒ promotions have ZERO routing effect (they remain visible
470
+ * as advisories + dashboard rows). Consumer sovereignty is preserved even
471
+ * when opted in: `forceModel`, `policy.blockedModels`, and cost ceilings
472
+ * always win, and a non-empty `policy.preferredModels` defers the
473
+ * promotion entirely.
474
+ */
475
+ autoPromote?: boolean;
440
476
  }
441
477
  declare function configureBrain(config: BrainConfig): void;
442
478
  declare function clearBrain(): void;
@@ -887,7 +923,7 @@ declare function runGoldenEval(opts: GoldenEvalOptions): Promise<GoldenEvalRunRe
887
923
  * guard in `tests/version.test.ts` fails the suite (and therefore
888
924
  * `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
889
925
  */
890
- declare const LIBRARY_VERSION = "2.0.0-alpha.63";
926
+ declare const LIBRARY_VERSION = "2.0.0-alpha.65";
891
927
 
892
928
  /**
893
929
  * Oracle contract — how an app tells the brain whether a response was good.
@@ -1772,7 +1808,7 @@ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxis
1772
1808
  * no execute() handler, no env-var convention). Narrowing here keeps the
1773
1809
  * reachability check structurally honest.
1774
1810
  */
1775
- type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek';
1811
+ type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot';
1776
1812
  /**
1777
1813
  * Per-provider env var names kgauto recognizes. Order doesn't matter —
1778
1814
  * first-present wins. Multiple names per provider supported because Google
@@ -2630,6 +2666,114 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
2630
2666
  reason: string;
2631
2667
  }>;
2632
2668
 
2669
+ /**
2670
+ * promotions-brain — alpha.64 Stage-2 substrate.
2671
+ *
2672
+ * Per-tenant SWR cache for the `kgauto_promotions` table populated by the
2673
+ * golden-eval trigger's auto-promote actor (Stage 2 of the eval trust
2674
+ * ladder: auto-promote downswaps behind the 7-day rollback guard). Mirrors
2675
+ * `promote-ready-brain.ts` shape where applicable; this is the read-side
2676
+ * substrate for the compile-time promotion boost in `passScoreTargets`.
2677
+ *
2678
+ * Design contract:
2679
+ * command-center/advisory/kgauto/2026-07-18_stage2-auto-promote-design.md
2680
+ *
2681
+ * Consent posture: the routing effect is OPT-IN, default OFF. The cache is
2682
+ * only activated by `configureBrain()` when the consumer opted in via
2683
+ * `BrainConfig.autoPromote: true` or the `KGAUTO_AUTO_PROMOTE` env var
2684
+ * (config field wins when both are present — mirror of the
2685
+ * `KGAUTO_GOLDEN_CAPTURE` env-as-consent precedent). Not opted in ⇒ this
2686
+ * module never fetches and `getApplicablePromotion` returns undefined ⇒
2687
+ * zero behavior change anywhere in compile().
2688
+ *
2689
+ * Architecture (mirror of promote-ready-brain):
2690
+ * - Sync API surface: `getApplicablePromotion({ appId, archetype })`
2691
+ * returns immediately. First call returns undefined (cold) and fires an
2692
+ * async refresh; subsequent calls within TTL return brain data.
2693
+ * - Per-appId snapshot; one fetch per appId per TTL window.
2694
+ * - Tolerant: brain down / misconfigured / unexpected shape → undefined.
2695
+ * Never throws. Warns once per process.
2696
+ *
2697
+ * A rollback (`status='rolled_back'` PATCHed by the promotion-guard
2698
+ * watcher) drops the row from the endpoint's `status=active` filter, so
2699
+ * routing reverts within one TTL window — the mechanism the 7-day guard's
2700
+ * auto-revert rests on.
2701
+ */
2702
+
2703
+ /**
2704
+ * One active surface promotion, camelCase-mapped at the boundary from the
2705
+ * snake_case endpoint row (typed-boundary-transformer convention).
2706
+ */
2707
+ interface PromotionRow {
2708
+ /** Brain row id — cited in the `promotion-applied` mutation for Glass-Box. */
2709
+ id: number;
2710
+ /** Intent archetype the promotion applies to. */
2711
+ archetype: string;
2712
+ /** The model this surface now routes to. */
2713
+ promotedModel: string;
2714
+ /** The model it replaced (the eval's incumbent). */
2715
+ incumbentModel: string;
2716
+ /** The promote-ready kgauto_golden_eval_runs row this rests on. */
2717
+ evalRunId: number | null;
2718
+ /**
2719
+ * Evidence-supersedes-judgment: skip the alpha.49 schema-weak
2720
+ * quality-gate penalty for the promoted model on this surface (the eval
2721
+ * measured the schema floor holding on real workload).
2722
+ */
2723
+ suppressQualityGate: boolean;
2724
+ /** ISO timestamp the promotion went active. */
2725
+ promotedAt: string;
2726
+ }
2727
+ interface PromotionsRuntime {
2728
+ /** Endpoint base URL. The library appends `?app_id=<id>`. */
2729
+ endpoint: string;
2730
+ /** Stale-while-revalidate window in ms. */
2731
+ ttlMs: number;
2732
+ /** Pluggable fetch. */
2733
+ fetchImpl: typeof fetch;
2734
+ /** Optional warn hook. */
2735
+ onError?: (err: unknown) => void;
2736
+ }
2737
+ /**
2738
+ * Default endpoint hosted on the kgauto-dashboard. Serves `status='active'`
2739
+ * kgauto_promotions rows for one app_id. Mirrors the findings convention.
2740
+ */
2741
+ declare const DEFAULT_PROMOTIONS_ENDPOINT = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/promotions";
2742
+ /**
2743
+ * True when the KGAUTO_AUTO_PROMOTE env var opts this process in.
2744
+ * Accepted truthy forms: '1', 'true' (case-insensitive). Everything else —
2745
+ * unset, '', '0', 'false' — is OFF. Read at configureBrain() time, not per
2746
+ * call.
2747
+ */
2748
+ declare function isAutoPromoteEnabledFromEnv(envSource?: Record<string, string | undefined>): boolean;
2749
+ /**
2750
+ * Wire (or rewire) the runtime. Pass undefined to disable. Resets all
2751
+ * snapshots. Called from `configureBrain()` ONLY when the consumer opted in.
2752
+ */
2753
+ declare function configurePromotionsBrain(rt: PromotionsRuntime | undefined): void;
2754
+ /** Sync introspection — is the promotions brain active (i.e. opted in)? */
2755
+ declare function isPromotionsBrainActive(): boolean;
2756
+ interface GetApplicablePromotionOpts {
2757
+ /** App id to read promotions for. Required. */
2758
+ appId: string;
2759
+ /** Archetype of the compile in flight. Required. */
2760
+ archetype: IntentArchetypeName | string;
2761
+ }
2762
+ /**
2763
+ * Sync reader. Returns the active promotion for `(appId, archetype)` or
2764
+ * undefined. First call returns undefined and triggers async refresh;
2765
+ * subsequent calls within TTL return brain data. The brain enforces one
2766
+ * active promotion per surface (partial unique index), so at most one row
2767
+ * matches.
2768
+ *
2769
+ * NEVER throws. Not configured / brain down / cold → undefined.
2770
+ */
2771
+ declare function getApplicablePromotion(opts: GetApplicablePromotionOpts): PromotionRow | undefined;
2772
+ /** Reset module state. Tests must call between cases. */
2773
+ declare function _testResetPromotions(): void;
2774
+ /** Wait for any in-flight refresh to settle. */
2775
+ declare function _testWaitForPromotionsRefresh(): Promise<void>;
2776
+
2633
2777
  /**
2634
2778
  * @warmdrift/kgauto v2 — prompt compiler + central learning brain.
2635
2779
  *
@@ -2676,4 +2820,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
2676
2820
  */
2677
2821
  declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
2678
2822
 
2679
- export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };
2823
+ export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainDeadLetterEntry, type BrainHealthSnapshot, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileForAISDKv6Result, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, DEFAULT_PROMOTIONS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetApplicablePromotionOpts, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, type GoldenEvalCase, type GoldenEvalOptions, type GoldenEvalRunResult, type GoldenIrRecordInput, Grounding, IntentArchetypeName, JUDGE_RUBRICS, LIBRARY_VERSION, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProbeShadowOptions, type ProbeShadowServed, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, type PromotionRow, type PromotionsRuntime, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, _testResetPromotions, _testWaitForPromotionsRefresh, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, brainHealth, buildGoldenIrRow, buildLLMJudge, buildPairwiseJudgePrompt, buildShadowProbeRow, call, clearBrain, combineOrderSwappedVerdicts, compile, compileForAISDKv6, configureBrain, configurePromotionsBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, flushBrainDeadLetter, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getApplicablePromotion, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isAutoPromoteEnabledFromEnv, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isPromotionsBrainActive, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, parseJudgeVerdict, peekBrainDeadLetter, probeShadow, profileToRow, readBrainReadEnv, record, recordGoldenIr, recordOutcome, recordShadowProbe, renderIrForJudge, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, rubricFor, runAdvisor, runGoldenEval, setTokenizer };