@warmdrift/kgauto-compiler 2.0.0-alpha.27 → 2.0.0-alpha.29

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.
@@ -1,5 +1,5 @@
1
- import { G as GlassboxEvent } from '../types-o9etg93a.mjs';
2
- import '../ir-B9zqlwjH.mjs';
1
+ import { G as GlassboxEvent } from '../types-BjrIFPGe.mjs';
2
+ import { h as Adapter, u as SectionKind } from '../ir-De2AQtlr.mjs';
3
3
  import '../dialect.mjs';
4
4
 
5
5
  /**
@@ -30,11 +30,122 @@ interface TraceSummary {
30
30
  tokensOut: number;
31
31
  estimatedCostUsd: number;
32
32
  }
33
+
34
+ interface AdvisoryRecord {
35
+ level: 'info' | 'warn' | 'critical';
36
+ /** Stable advisory identifier, e.g. "caching-off-on-claude". */
37
+ code: string;
38
+ /** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
39
+ message: string;
40
+ /** Optional secondary one-liner. Renders below `message` in italics. */
41
+ suggestion?: string;
42
+ /** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
43
+ docsUrl?: string;
44
+ /**
45
+ * alpha.28+ — closed-union adaptation hint surfaced by the advisor when
46
+ * the advisory can be auto-mitigated by a config knob. Renderer surfaces
47
+ * as `→ try toolOrchestration: 'sequential'` on the advisory row.
48
+ *
49
+ * MUST stay byte-identical to Builder C's
50
+ * `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
51
+ * integration; the Adapter type itself is the contract).
52
+ */
53
+ suggestedAdaptation?: Adapter;
54
+ }
55
+ /**
56
+ * Cost-equivalent alternative the chain could have served. Computed at
57
+ * detail-view time by `computeCounterfactuals()` against the served row's
58
+ * observed token counts + archetype + cache state. Up to 2 entries, sorted
59
+ * cheapest first.
60
+ */
61
+ interface TraceCounterfactual {
62
+ modelId: string;
63
+ estimatedCostUsd: number;
64
+ /** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
65
+ savingsUsd: number;
66
+ /** 0-100. */
67
+ savingsPercent: number;
68
+ /** Plain-English rationale tying archetype + perf score. */
69
+ reason: string;
70
+ }
71
+ /**
72
+ * Derived axis-health tri-state for the three Glass-Box dots
73
+ * (input-ratio · cache · fallback). Renderer reads; transformer computes.
74
+ *
75
+ * Thresholds (locked in design contract Phase 0):
76
+ * - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
77
+ * - cache (only when historyCacheableTokens > 1000):
78
+ * green if inputCacheHitRatio ≥ 0.5
79
+ * yellow if 0.1 ≤ inputCacheHitRatio < 0.5
80
+ * red if inputCacheHitRatio < 0.1
81
+ * na if historyCacheableTokens ≤ 1000
82
+ * - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
83
+ */
84
+ interface TraceHealth {
85
+ inputRatioStatus: 'green' | 'yellow' | 'red';
86
+ cacheStatus: 'green' | 'yellow' | 'red' | 'na';
87
+ fallbackStatus: 'green' | 'red';
88
+ }
89
+ /**
90
+ * alpha.29+ — wire-boundary representation of a translator section-rewrite.
91
+ *
92
+ * Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
93
+ * shape drops `originalText` + `transformedText` because those may carry
94
+ * consumer PII. The renderer shows the `rule` + `summary` only. Full text
95
+ * stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
96
+ * by RLS for brain-side cross-app learning.
97
+ */
98
+ interface TraceSectionRewrite {
99
+ /** Stable id of the rewritten section. */
100
+ sectionId: string;
101
+ /** Section-kind discriminator that triggered the rewrite. */
102
+ kind: SectionKind;
103
+ /** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
104
+ rule: string;
105
+ /**
106
+ * Plain-English one-liner describing what fired and why. Renderer surfaces
107
+ * this on the Coaching card; no internal jargon ("L-040", "below floor").
108
+ */
109
+ summary: string;
110
+ }
33
111
  interface TraceDetail extends TraceSummary {
34
- mutationsApplied: unknown[];
35
- advisories: unknown[];
36
- rawRequest?: unknown;
37
- rawResponse?: unknown;
112
+ mutationsApplied: string[];
113
+ advisories: AdvisoryRecord[];
114
+ rawRequest?: string;
115
+ rawResponse?: string;
116
+ /** Set when consumer passed a forceModel / fallback fired. */
117
+ requestedModel?: string;
118
+ /** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
119
+ finishReason?: string;
120
+ /** Time to first token (ms); populated when provider surfaces it. */
121
+ ttftMs?: number;
122
+ /** End-to-end wall-clock (ms); from migration 018. */
123
+ totalMs?: number;
124
+ /** Tools kept after relevance pass. */
125
+ toolsCount?: number;
126
+ /** Number of history messages at compile time. */
127
+ historyDepth?: number;
128
+ /** Rendered system prompt size in characters. */
129
+ systemPromptChars?: number;
130
+ cacheReadInputTokens: number;
131
+ cacheCreationInputTokens: number;
132
+ historyCacheableTokens: number;
133
+ /** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
134
+ inputCacheHitRatio: number;
135
+ fellOverFrom?: string;
136
+ fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
137
+ /** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
138
+ counterfactuals?: TraceCounterfactual[];
139
+ /** Undefined when 7d volume < 5/day (insufficient data). */
140
+ projectedDailyCostUsd?: number;
141
+ /**
142
+ * alpha.29+ — translator activity for this trace. Empty array (not
143
+ * undefined) when no rewrites fired or pre-019 row. Surfaced in the
144
+ * Glass-Box Coaching card as synthetic info-level rows. PII-safe by
145
+ * construction: only sectionId + kind + rule + summary cross the wire.
146
+ */
147
+ sectionRewritesApplied: TraceSectionRewrite[];
148
+ health: TraceHealth;
38
149
  }
39
150
 
40
151
  /**
@@ -1,5 +1,5 @@
1
- import { G as GlassboxEvent } from '../types-bt0aVJb8.js';
2
- import '../ir-B_XX2LAO.js';
1
+ import { G as GlassboxEvent } from '../types-D_JAhCv4.js';
2
+ import { h as Adapter, u as SectionKind } from '../ir-BIAT9gJk.js';
3
3
  import '../dialect.js';
4
4
 
5
5
  /**
@@ -30,11 +30,122 @@ interface TraceSummary {
30
30
  tokensOut: number;
31
31
  estimatedCostUsd: number;
32
32
  }
33
+
34
+ interface AdvisoryRecord {
35
+ level: 'info' | 'warn' | 'critical';
36
+ /** Stable advisory identifier, e.g. "caching-off-on-claude". */
37
+ code: string;
38
+ /** Consumer-renderable message — no internal jargon ("L-040", "R3" etc.). */
39
+ message: string;
40
+ /** Optional secondary one-liner. Renders below `message` in italics. */
41
+ suggestion?: string;
42
+ /** Deep link to the relevant section of `interfaces/kgauto.md` or docs. */
43
+ docsUrl?: string;
44
+ /**
45
+ * alpha.28+ — closed-union adaptation hint surfaced by the advisor when
46
+ * the advisory can be auto-mitigated by a config knob. Renderer surfaces
47
+ * as `→ try toolOrchestration: 'sequential'` on the advisory row.
48
+ *
49
+ * MUST stay byte-identical to Builder C's
50
+ * `BestPracticeAdvisory.suggestedAdaptation` shape (verified at Phase 2
51
+ * integration; the Adapter type itself is the contract).
52
+ */
53
+ suggestedAdaptation?: Adapter;
54
+ }
55
+ /**
56
+ * Cost-equivalent alternative the chain could have served. Computed at
57
+ * detail-view time by `computeCounterfactuals()` against the served row's
58
+ * observed token counts + archetype + cache state. Up to 2 entries, sorted
59
+ * cheapest first.
60
+ */
61
+ interface TraceCounterfactual {
62
+ modelId: string;
63
+ estimatedCostUsd: number;
64
+ /** servedCostUsd - estimatedCostUsd (always > 0; only ≥10% savings kept). */
65
+ savingsUsd: number;
66
+ /** 0-100. */
67
+ savingsPercent: number;
68
+ /** Plain-English rationale tying archetype + perf score. */
69
+ reason: string;
70
+ }
71
+ /**
72
+ * Derived axis-health tri-state for the three Glass-Box dots
73
+ * (input-ratio · cache · fallback). Renderer reads; transformer computes.
74
+ *
75
+ * Thresholds (locked in design contract Phase 0):
76
+ * - inputRatio: green ≤ 0.65 · yellow 0.65–0.85 · red > 0.85
77
+ * - cache (only when historyCacheableTokens > 1000):
78
+ * green if inputCacheHitRatio ≥ 0.5
79
+ * yellow if 0.1 ≤ inputCacheHitRatio < 0.5
80
+ * red if inputCacheHitRatio < 0.1
81
+ * na if historyCacheableTokens ≤ 1000
82
+ * - fallback: red iff fellOverFrom !== undefined && fellOverFrom !== target
83
+ */
84
+ interface TraceHealth {
85
+ inputRatioStatus: 'green' | 'yellow' | 'red';
86
+ cacheStatus: 'green' | 'yellow' | 'red' | 'na';
87
+ fallbackStatus: 'green' | 'red';
88
+ }
89
+ /**
90
+ * alpha.29+ — wire-boundary representation of a translator section-rewrite.
91
+ *
92
+ * Distinct from the package-internal `SectionRewrite` type in `ir.ts`: this
93
+ * shape drops `originalText` + `transformedText` because those may carry
94
+ * consumer PII. The renderer shows the `rule` + `summary` only. Full text
95
+ * stays on `compile_outcomes.section_rewrites_applied` (Supabase row), gated
96
+ * by RLS for brain-side cross-app learning.
97
+ */
98
+ interface TraceSectionRewrite {
99
+ /** Stable id of the rewritten section. */
100
+ sectionId: string;
101
+ /** Section-kind discriminator that triggered the rewrite. */
102
+ kind: SectionKind;
103
+ /** Stable rule identifier (e.g. `'sequential-tool-cliff-below-floor'`). */
104
+ rule: string;
105
+ /**
106
+ * Plain-English one-liner describing what fired and why. Renderer surfaces
107
+ * this on the Coaching card; no internal jargon ("L-040", "below floor").
108
+ */
109
+ summary: string;
110
+ }
33
111
  interface TraceDetail extends TraceSummary {
34
- mutationsApplied: unknown[];
35
- advisories: unknown[];
36
- rawRequest?: unknown;
37
- rawResponse?: unknown;
112
+ mutationsApplied: string[];
113
+ advisories: AdvisoryRecord[];
114
+ rawRequest?: string;
115
+ rawResponse?: string;
116
+ /** Set when consumer passed a forceModel / fallback fired. */
117
+ requestedModel?: string;
118
+ /** Provider finish reason — 'stop' / 'max_tokens' / 'tool_use' / etc. */
119
+ finishReason?: string;
120
+ /** Time to first token (ms); populated when provider surfaces it. */
121
+ ttftMs?: number;
122
+ /** End-to-end wall-clock (ms); from migration 018. */
123
+ totalMs?: number;
124
+ /** Tools kept after relevance pass. */
125
+ toolsCount?: number;
126
+ /** Number of history messages at compile time. */
127
+ historyDepth?: number;
128
+ /** Rendered system prompt size in characters. */
129
+ systemPromptChars?: number;
130
+ cacheReadInputTokens: number;
131
+ cacheCreationInputTokens: number;
132
+ historyCacheableTokens: number;
133
+ /** Derived: cacheReadInputTokens / max(tokensIn, 1). 0-1. */
134
+ inputCacheHitRatio: number;
135
+ fellOverFrom?: string;
136
+ fallbackReason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
137
+ /** Up to 2 alternatives. Empty array (not undefined) when none qualify. */
138
+ counterfactuals?: TraceCounterfactual[];
139
+ /** Undefined when 7d volume < 5/day (insufficient data). */
140
+ projectedDailyCostUsd?: number;
141
+ /**
142
+ * alpha.29+ — translator activity for this trace. Empty array (not
143
+ * undefined) when no rewrites fired or pre-019 row. Surfaced in the
144
+ * Glass-Box Coaching card as synthetic info-level rows. PII-safe by
145
+ * construction: only sectionId + kind + rule + summary cross the wire.
146
+ */
147
+ sectionRewritesApplied: TraceSectionRewrite[];
148
+ health: TraceHealth;
38
149
  }
39
150
 
40
151
  /**