@warmdrift/kgauto-compiler 2.0.0-alpha.61 → 2.0.0-alpha.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +30 -12
  2. package/dist/brain-proxy.js +5 -1
  3. package/dist/brain-proxy.mjs +1 -1
  4. package/dist/{chunk-5TI6PNSK.mjs → chunk-3KQAID63.mjs} +5 -0
  5. package/dist/{chunk-IUWFML6Z.mjs → chunk-65ZMX5OT.mjs} +5 -1
  6. package/dist/{chunk-3RMLZCUK.mjs → chunk-ABFXMO73.mjs} +1 -1
  7. package/dist/{chunk-IIMPJZNH.mjs → chunk-YZRPNSSQ.mjs} +10 -0
  8. package/dist/dialect.d.mts +14 -2
  9. package/dist/dialect.d.ts +14 -2
  10. package/dist/dialect.js +5 -0
  11. package/dist/dialect.mjs +1 -1
  12. package/dist/glassbox/index.d.mts +3 -3
  13. package/dist/glassbox/index.d.ts +3 -3
  14. package/dist/glassbox-routes/format.d.mts +2 -2
  15. package/dist/glassbox-routes/format.d.ts +2 -2
  16. package/dist/glassbox-routes/index.d.mts +4 -4
  17. package/dist/glassbox-routes/index.d.ts +4 -4
  18. package/dist/glassbox-routes/index.js +10 -0
  19. package/dist/glassbox-routes/index.mjs +1 -1
  20. package/dist/glassbox-routes/react/index.d.mts +2 -2
  21. package/dist/glassbox-routes/react/index.d.ts +2 -2
  22. package/dist/index.d.mts +193 -6
  23. package/dist/index.d.ts +193 -6
  24. package/dist/index.js +681 -2
  25. package/dist/index.mjs +651 -4
  26. package/dist/{ir-DAKlQsVb.d.mts → ir-B2dRyJXO.d.mts} +74 -9
  27. package/dist/{ir-DmUuJsWc.d.ts → ir-ClU56aBc.d.ts} +74 -9
  28. package/dist/key-health.js +1 -1
  29. package/dist/key-health.mjs +1 -1
  30. package/dist/profiles.d.mts +1 -1
  31. package/dist/profiles.d.ts +1 -1
  32. package/dist/{types-B8X1Pyhx.d.ts → types-ByN3r0_7.d.ts} +1 -1
  33. package/dist/{types-DR62iPcO.d.ts → types-C-Wp7HpI.d.ts} +1 -1
  34. package/dist/{types-MRMBUqzY.d.mts → types-CSDweZsl.d.mts} +1 -1
  35. package/dist/{types-CssWqd0X.d.mts → types-axAX1Bg0.d.mts} +1 -1
  36. package/package.json +1 -1
@@ -1,17 +1,73 @@
1
1
  import { IntentArchetypeName } from './dialect.mjs';
2
2
 
3
3
  /**
4
- * Intermediate Representation the structured form of a prompt.
4
+ * Golden-set capture (alpha.62, eval spine design brief 2026-07-17).
5
5
  *
6
- * Everything kgauto v2 does, it does on the IR. The IR is constructed by the
7
- * caller (or by `parse()` from a string-style prompt for backwards-compat),
8
- * transformed by the compiler passes, and lowered to a target-specific wire
9
- * request only at the very end.
6
+ * The eval-driven self-improvement contract needs a replay corpus: 20–50 real
7
+ * historical IRs per (app, archetype), stored WITH the incumbent's output.
8
+ * This module is the capture side a sampling gate on call()'s success path
9
+ * that stores the full PromptIR + served response to `kgauto_golden_irs`.
10
10
  *
11
- * The IR carries STRUCTURE, not just text. Sections are first-class. Tools
12
- * carry per-intent relevance. History knows its turn-age. Constraints are
13
- * explicit. This is what lets passes do real work.
11
+ * ## Consent posture (s51 amendment, ratified 2026-07-17)
12
+ *
13
+ * Golden rows carry RAW prompts a deliberate, documented departure from the
14
+ * s51 "brain holds no raw consumer prompts" rule. Capture is therefore
15
+ * strictly opt-in:
16
+ *
17
+ * - `KGAUTO_GOLDEN_CAPTURE=0.1` in the consumer's environment (the env var
18
+ * IS the consent act — the consumer's operator sets it knowingly), or
19
+ * - `CallOptions.goldenCapture.sampleRate` in consumer code.
20
+ *
21
+ * Default is 0 (off): absent flag, empty string, non-finite, or ≤0 all mean
22
+ * "never capture". Every stored row records its consent provenance in the
23
+ * `consent` column. Reads are strictly app-scoped (RLS) — a consumer can only
24
+ * ever see its own raw prompts.
25
+ */
26
+
27
+ /** Consumer-facing capture options (CallOptions.goldenCapture). */
28
+ interface GoldenCaptureOptions {
29
+ /**
30
+ * Probability [0..1] that a successful call's IR + output is stored as a
31
+ * golden row. Overrides the KGAUTO_GOLDEN_CAPTURE env var when set.
32
+ */
33
+ sampleRate?: number;
34
+ /**
35
+ * Optional free-text appended to the stored consent provenance (e.g. a
36
+ * ticket ref or the operator who approved capture for this surface).
37
+ */
38
+ consentNote?: string;
39
+ }
40
+ /**
41
+ * Parse a capture-rate env value. Mirrors the consumer-side
42
+ * `parseShadowProbeRate` semantics playbacksam established: undefined, empty,
43
+ * or non-finite → 0 (default-OFF); result clamped to [0, 1].
44
+ */
45
+ declare function parseGoldenCaptureRate(raw: string | undefined): number;
46
+ /**
47
+ * Resolve the effective capture rate: explicit option wins; otherwise the
48
+ * KGAUTO_GOLDEN_CAPTURE env var (when a process env exists — Edge-safe).
14
49
  */
50
+ declare function resolveGoldenCaptureRate(optRate?: number): number;
51
+ /** Sampling gate. Injectable rng for tests (same shape as shouldSampleProbe). */
52
+ declare function shouldCaptureGolden(rate: number, rng?: () => number): boolean;
53
+ /** Everything call()'s success path has in scope when capture fires. */
54
+ interface GoldenCaptureContext {
55
+ ir: PromptIR;
56
+ servedModel: string;
57
+ response: NormalizedResponse;
58
+ latencyMs: number;
59
+ handle: string;
60
+ /** Compile-time shape key (peeked before record() popped the registry). */
61
+ shapeKey?: string;
62
+ /** How the rate was resolved — recorded as consent provenance. */
63
+ consent: string;
64
+ }
65
+ /**
66
+ * Store one golden row from a live served call. Fire-and-forget discipline is
67
+ * recordGoldenIr()'s (dead-letter, ledger, honors BrainConfig.sync); this
68
+ * wrapper only shapes the row. Never throws.
69
+ */
70
+ declare function captureGoldenIr(ctx: GoldenCaptureContext): Promise<void>;
15
71
 
16
72
  /**
17
73
  * A semantically-named section of the system prompt. Sections enable
@@ -969,6 +1025,15 @@ interface CallOptions {
969
1025
  * without engaging streaming wire format).
970
1026
  */
971
1027
  noStream?: boolean;
1028
+ /**
1029
+ * alpha.62 (eval spine) — golden-set capture. When the resolved sample rate
1030
+ * is > 0, a successful non-empty call's FULL PromptIR + served output is
1031
+ * stored to the brain's `kgauto_golden_irs` replay corpus (raw prompt —
1032
+ * explicit opt-in; see golden.ts consent posture). `sampleRate` here
1033
+ * overrides the `KGAUTO_GOLDEN_CAPTURE` env var; when neither is set,
1034
+ * capture never fires.
1035
+ */
1036
+ goldenCapture?: GoldenCaptureOptions;
972
1037
  }
973
1038
  interface CallAttempt {
974
1039
  model: string;
@@ -1383,4 +1448,4 @@ interface PerAxisMetrics {
1383
1448
  /** Per-axis metrics keyed by model — used for chain-comparison views. */
1384
1449
  type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
1385
1450
 
1386
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type EffortLevel as E, 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 SystemModelMessage as S, type ToolCall as T, 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 MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type ShadowProbeConfig as x, type ToolDefinition as y };
1451
+ 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, parseGoldenCaptureRate as J, resolveGoldenCaptureRate as K, shouldCaptureGolden as L, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type SystemModelMessage as S, type ToolCall as T, 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 };
@@ -1,17 +1,73 @@
1
1
  import { IntentArchetypeName } from './dialect.js';
2
2
 
3
3
  /**
4
- * Intermediate Representation the structured form of a prompt.
4
+ * Golden-set capture (alpha.62, eval spine design brief 2026-07-17).
5
5
  *
6
- * Everything kgauto v2 does, it does on the IR. The IR is constructed by the
7
- * caller (or by `parse()` from a string-style prompt for backwards-compat),
8
- * transformed by the compiler passes, and lowered to a target-specific wire
9
- * request only at the very end.
6
+ * The eval-driven self-improvement contract needs a replay corpus: 20–50 real
7
+ * historical IRs per (app, archetype), stored WITH the incumbent's output.
8
+ * This module is the capture side a sampling gate on call()'s success path
9
+ * that stores the full PromptIR + served response to `kgauto_golden_irs`.
10
10
  *
11
- * The IR carries STRUCTURE, not just text. Sections are first-class. Tools
12
- * carry per-intent relevance. History knows its turn-age. Constraints are
13
- * explicit. This is what lets passes do real work.
11
+ * ## Consent posture (s51 amendment, ratified 2026-07-17)
12
+ *
13
+ * Golden rows carry RAW prompts a deliberate, documented departure from the
14
+ * s51 "brain holds no raw consumer prompts" rule. Capture is therefore
15
+ * strictly opt-in:
16
+ *
17
+ * - `KGAUTO_GOLDEN_CAPTURE=0.1` in the consumer's environment (the env var
18
+ * IS the consent act — the consumer's operator sets it knowingly), or
19
+ * - `CallOptions.goldenCapture.sampleRate` in consumer code.
20
+ *
21
+ * Default is 0 (off): absent flag, empty string, non-finite, or ≤0 all mean
22
+ * "never capture". Every stored row records its consent provenance in the
23
+ * `consent` column. Reads are strictly app-scoped (RLS) — a consumer can only
24
+ * ever see its own raw prompts.
25
+ */
26
+
27
+ /** Consumer-facing capture options (CallOptions.goldenCapture). */
28
+ interface GoldenCaptureOptions {
29
+ /**
30
+ * Probability [0..1] that a successful call's IR + output is stored as a
31
+ * golden row. Overrides the KGAUTO_GOLDEN_CAPTURE env var when set.
32
+ */
33
+ sampleRate?: number;
34
+ /**
35
+ * Optional free-text appended to the stored consent provenance (e.g. a
36
+ * ticket ref or the operator who approved capture for this surface).
37
+ */
38
+ consentNote?: string;
39
+ }
40
+ /**
41
+ * Parse a capture-rate env value. Mirrors the consumer-side
42
+ * `parseShadowProbeRate` semantics playbacksam established: undefined, empty,
43
+ * or non-finite → 0 (default-OFF); result clamped to [0, 1].
44
+ */
45
+ declare function parseGoldenCaptureRate(raw: string | undefined): number;
46
+ /**
47
+ * Resolve the effective capture rate: explicit option wins; otherwise the
48
+ * KGAUTO_GOLDEN_CAPTURE env var (when a process env exists — Edge-safe).
14
49
  */
50
+ declare function resolveGoldenCaptureRate(optRate?: number): number;
51
+ /** Sampling gate. Injectable rng for tests (same shape as shouldSampleProbe). */
52
+ declare function shouldCaptureGolden(rate: number, rng?: () => number): boolean;
53
+ /** Everything call()'s success path has in scope when capture fires. */
54
+ interface GoldenCaptureContext {
55
+ ir: PromptIR;
56
+ servedModel: string;
57
+ response: NormalizedResponse;
58
+ latencyMs: number;
59
+ handle: string;
60
+ /** Compile-time shape key (peeked before record() popped the registry). */
61
+ shapeKey?: string;
62
+ /** How the rate was resolved — recorded as consent provenance. */
63
+ consent: string;
64
+ }
65
+ /**
66
+ * Store one golden row from a live served call. Fire-and-forget discipline is
67
+ * recordGoldenIr()'s (dead-letter, ledger, honors BrainConfig.sync); this
68
+ * wrapper only shapes the row. Never throws.
69
+ */
70
+ declare function captureGoldenIr(ctx: GoldenCaptureContext): Promise<void>;
15
71
 
16
72
  /**
17
73
  * A semantically-named section of the system prompt. Sections enable
@@ -969,6 +1025,15 @@ interface CallOptions {
969
1025
  * without engaging streaming wire format).
970
1026
  */
971
1027
  noStream?: boolean;
1028
+ /**
1029
+ * alpha.62 (eval spine) — golden-set capture. When the resolved sample rate
1030
+ * is > 0, a successful non-empty call's FULL PromptIR + served output is
1031
+ * stored to the brain's `kgauto_golden_irs` replay corpus (raw prompt —
1032
+ * explicit opt-in; see golden.ts consent posture). `sampleRate` here
1033
+ * overrides the `KGAUTO_GOLDEN_CAPTURE` env var; when neither is set,
1034
+ * capture never fires.
1035
+ */
1036
+ goldenCapture?: GoldenCaptureOptions;
972
1037
  }
973
1038
  interface CallAttempt {
974
1039
  model: string;
@@ -1383,4 +1448,4 @@ interface PerAxisMetrics {
1383
1448
  /** Per-axis metrics keyed by model — used for chain-comparison views. */
1384
1449
  type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
1385
1450
 
1386
- export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type EffortLevel as E, 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 SystemModelMessage as S, type ToolCall as T, 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 MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type ShadowProbeConfig as x, type ToolDefinition as y };
1451
+ 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, parseGoldenCaptureRate as J, resolveGoldenCaptureRate as K, shouldCaptureGolden as L, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type SystemModelMessage as S, type ToolCall as T, 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 };
@@ -25,7 +25,7 @@ __export(key_health_exports, {
25
25
  module.exports = __toCommonJS(key_health_exports);
26
26
 
27
27
  // src/version.ts
28
- var LIBRARY_VERSION = "2.0.0-alpha.61";
28
+ var LIBRARY_VERSION = "2.0.0-alpha.62";
29
29
 
30
30
  // src/key-health.ts
31
31
  var JSON_HEADERS = { "Content-Type": "application/json" };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createKeyHealthRoute
3
- } from "./chunk-3RMLZCUK.mjs";
3
+ } from "./chunk-ABFXMO73.mjs";
4
4
  export {
5
5
  createKeyHealthRoute
6
6
  };
@@ -1,4 +1,4 @@
1
- import { k as Provider } from './ir-DAKlQsVb.mjs';
1
+ import { k as Provider } from './ir-B2dRyJXO.mjs';
2
2
  import { IntentArchetypeName } from './dialect.mjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { k as Provider } from './ir-DmUuJsWc.js';
1
+ import { k as Provider } from './ir-ClU56aBc.js';
2
2
  import { IntentArchetypeName } from './dialect.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { i as Adapter, w as SectionKind } from './ir-DmUuJsWc.js';
1
+ import { i as Adapter, x as SectionKind } from './ir-ClU56aBc.js';
2
2
 
3
3
  /**
4
4
  * Internal config + hook types for createGlassboxRoutes().
@@ -1,4 +1,4 @@
1
- import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-DmUuJsWc.js';
1
+ import { s as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-ClU56aBc.js';
2
2
 
3
3
  /**
4
4
  * Glass-Box observability types (alpha.17).
@@ -1,4 +1,4 @@
1
- import { i as Adapter, w as SectionKind } from './ir-DAKlQsVb.mjs';
1
+ import { i as Adapter, x as SectionKind } from './ir-B2dRyJXO.mjs';
2
2
 
3
3
  /**
4
4
  * Internal config + hook types for createGlassboxRoutes().
@@ -1,4 +1,4 @@
1
- import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-DAKlQsVb.mjs';
1
+ import { s as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-B2dRyJXO.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.61",
3
+ "version": "2.0.0-alpha.62",
4
4
  "description": "Prompt compiler with executable provider knowledge for multi-model AI apps: normalized multi-provider transport with fallback chains, compile-time cliff guards, a curated model registry, and a telemetry flight recorder. Swap models without rewriting prompts.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",