@warmdrift/kgauto-compiler 2.0.0-alpha.7 → 2.0.0-alpha.70

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 (55) hide show
  1. package/README.md +176 -46
  2. package/dist/brain-proxy.d.mts +113 -0
  3. package/dist/brain-proxy.d.ts +113 -0
  4. package/dist/brain-proxy.js +193 -0
  5. package/dist/brain-proxy.mjs +6 -0
  6. package/dist/chunk-4UO4CCSP.mjs +1620 -0
  7. package/dist/chunk-65ZMX5OT.mjs +169 -0
  8. package/dist/{chunk-5TI6PNSK.mjs → chunk-BVEXV5KC.mjs} +11 -0
  9. package/dist/chunk-FR4DNGLW.mjs +203 -0
  10. package/dist/chunk-NBO4R5PC.mjs +313 -0
  11. package/dist/chunk-P3TOAEG4.mjs +56 -0
  12. package/dist/chunk-RO22VFIF.mjs +29 -0
  13. package/dist/chunk-SBFSYCQG.mjs +719 -0
  14. package/dist/dialect.d.mts +41 -3
  15. package/dist/dialect.d.ts +41 -3
  16. package/dist/dialect.js +14 -2
  17. package/dist/dialect.mjs +5 -3
  18. package/dist/glassbox/index.d.mts +59 -0
  19. package/dist/glassbox/index.d.ts +59 -0
  20. package/dist/glassbox/index.js +312 -0
  21. package/dist/glassbox/index.mjs +12 -0
  22. package/dist/glassbox-routes/format.d.mts +24 -0
  23. package/dist/glassbox-routes/format.d.ts +24 -0
  24. package/dist/glassbox-routes/format.js +86 -0
  25. package/dist/glassbox-routes/format.mjs +18 -0
  26. package/dist/glassbox-routes/index.d.mts +191 -0
  27. package/dist/glassbox-routes/index.d.ts +191 -0
  28. package/dist/glassbox-routes/index.js +2888 -0
  29. package/dist/glassbox-routes/index.mjs +667 -0
  30. package/dist/glassbox-routes/react/index.d.mts +74 -0
  31. package/dist/glassbox-routes/react/index.d.ts +74 -0
  32. package/dist/glassbox-routes/react/index.js +819 -0
  33. package/dist/glassbox-routes/react/index.mjs +754 -0
  34. package/dist/index.d.mts +2739 -17
  35. package/dist/index.d.ts +2739 -17
  36. package/dist/index.js +8989 -1659
  37. package/dist/index.mjs +5078 -367
  38. package/dist/ir-Bqn1RVdV.d.mts +1583 -0
  39. package/dist/ir-Bvlkw5ja.d.ts +1583 -0
  40. package/dist/key-health.d.mts +131 -0
  41. package/dist/key-health.d.ts +131 -0
  42. package/dist/key-health.js +228 -0
  43. package/dist/key-health.mjs +6 -0
  44. package/dist/profiles.d.mts +292 -2
  45. package/dist/profiles.d.ts +292 -2
  46. package/dist/profiles.js +1231 -16
  47. package/dist/profiles.mjs +9 -1
  48. package/dist/types-Bon96eyc.d.ts +131 -0
  49. package/dist/types-CwGhacGT.d.mts +149 -0
  50. package/dist/types-DIxRZ3Dj.d.ts +149 -0
  51. package/dist/types-DsEq35WY.d.mts +131 -0
  52. package/package.json +54 -8
  53. package/dist/chunk-MBEI5UOM.mjs +0 -409
  54. package/dist/profiles-B3eNQ2py.d.ts +0 -619
  55. package/dist/profiles-Py8c7zjJ.d.mts +0 -619
@@ -1,2 +1,292 @@
1
- export { f as ALIASES, g as CacheStrategy, j as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-Py8c7zjJ.mjs';
2
- import './dialect.mjs';
1
+ import { k as Provider } from './ir-Bqn1RVdV.mjs';
2
+ import { IntentArchetypeName } from './dialect.mjs';
3
+
4
+ /**
5
+ * Model profiles — executable knowledge about each provider/model.
6
+ *
7
+ * Unlike v1 which carried `known_failures` as prose strings, v2 makes them
8
+ * executable: cliffs trigger guards, lowering describes the wire format,
9
+ * recovery handlers describe what to do after specific failures.
10
+ *
11
+ * Each profile is the answer to "if I want to call THIS model with THIS
12
+ * shape of work, what does it need from me, and what should I do when it
13
+ * fails?"
14
+ */
15
+
16
+ type StructuredOutputCapability = 'native' | 'grammar' | 'none';
17
+ type SystemPromptMode = 'inline' | 'separate' | 'as_developer' | 'unsupported';
18
+ type CacheStrategy = 'cache_control' | 'cachedContent' | 'unsupported';
19
+ interface CliffRule {
20
+ /** What metric triggers this cliff. */
21
+ metric: 'input_tokens' | 'tool_count' | 'history_turns' | 'thinking_with_short_output';
22
+ /** Threshold — meaning depends on metric. */
23
+ threshold: number;
24
+ /** What action to take when triggered. */
25
+ action: 'downgrade_quality_warning' | 'drop_to_top_relevant' | 'force_thinking_budget_zero' | 'force_terse_output' | 'escalate_target' | 'strip_tools';
26
+ /**
27
+ * Optional: only fire this cliff when the IR's intent.archetype matches.
28
+ * Used for archetype-specific failure modes (e.g. Gemini Flash returns
29
+ * empty when summarize is offered tools).
30
+ */
31
+ whenIntent?: IntentArchetypeName;
32
+ /** Human-readable reason for digest reporting. */
33
+ reason: string;
34
+ }
35
+ /**
36
+ * alpha.43 — per-family-per-archetype prompt-shape convention.
37
+ *
38
+ * Cliffs are runtime warnings about model failure modes; conventions are
39
+ * compile-time prompt rewrites that head off those failure modes BEFORE the
40
+ * call leaves kgauto. The split: "this model hedges on classify" is a fact
41
+ * about the model (a convention); "this prompt is 80k tokens on a Flash
42
+ * profile" is a fact about the call (a cliff).
43
+ *
44
+ * Conventions live as data on profiles (NOT hardcoded in passes). The
45
+ * `passApplyConventions` pass walks each matching convention and applies
46
+ * its prefix/suffix/structured-output hint at compile time. Idempotent: if
47
+ * the prefix/suffix is already at the head/tail, the pass no-ops.
48
+ *
49
+ * Defaulting rule: set conventions on the FAMILY REPRESENTATIVE profile
50
+ * (e.g. deepseek-v4-pro is the family rep for the `deepseek-reasoner`
51
+ * family). Other family members inherit at compile time via the
52
+ * `family-resolution.deriveFamilyFromModelId` lookup. Model-specific
53
+ * overrides are rare; use them only when one model in a family genuinely
54
+ * diverges from the family default.
55
+ *
56
+ * Trigger that justified the substrate (2026-05-28): V4-Pro probe on
57
+ * tt-intel/classify (exclusion-finding ID 20) showed 8/10 judge rationales
58
+ * citing "candidate hedges and fails to commit to a single classification."
59
+ * Without a forcing-function suffix, every reasoner probe on a decisive
60
+ * archetype verdicts stay-excluded for reasoner-behavior reasons, not
61
+ * quality reasons. The convention substrate is the kgauto-side fix.
62
+ */
63
+ interface ArchetypeConvention {
64
+ /** Intent archetype this convention applies to. */
65
+ archetype: IntentArchetypeName;
66
+ /**
67
+ * String prepended to the system prompt (after any existing system
68
+ * content). Use for forcing-functions, output-shape directives,
69
+ * anti-hedge framing. Omit if no prefix needed.
70
+ */
71
+ promptPrefix?: string;
72
+ /**
73
+ * String appended to the LAST user message in history (or to
74
+ * `currentTurn` when history is empty). Use for tail-anchored
75
+ * forcing-functions ("Output exactly one of: [...]"). Omit if no suffix
76
+ * needed.
77
+ */
78
+ promptSuffix?: string;
79
+ /**
80
+ * If 'enforce', kgauto warns (but does not block) when structuredOutput
81
+ * is NOT set and the model wants it. If 'avoid', kgauto warns when
82
+ * structuredOutput IS set and the model struggles with schema
83
+ * compliance. If omitted, no structured-output guidance.
84
+ */
85
+ structuredOutputHint?: 'enforce' | 'avoid';
86
+ /**
87
+ * Free-form cliff-style warning surfaced in
88
+ * `CompileResult.diagnostics.cliffWarnings` when the convention's
89
+ * preconditions are met but the consumer opted out of the convention
90
+ * (e.g. provided their own conflicting prompt-shape) — or when the
91
+ * convention can't be applied automatically (cliffWarning-only entries
92
+ * are pure diagnostics).
93
+ */
94
+ cliffWarning?: string;
95
+ /**
96
+ * Optional: only fire this convention's cliffWarning when the tool count
97
+ * is at least this threshold. Used for parallel-tool advisories on
98
+ * archetypes that don't otherwise carry a hard tool cap.
99
+ */
100
+ whenToolCountAtLeast?: number;
101
+ /**
102
+ * Brain-evidence-linked justification. Appears in mutations_applied
103
+ * trail + advisor rule messages. Same format as existing cliff.reason
104
+ * strings.
105
+ */
106
+ reason: string;
107
+ }
108
+ interface RecoveryRule {
109
+ /** What signal triggers recovery. */
110
+ signal: 'empty_response_after_tool' | 'empty_response' | 'malformed_function_call' | 'rate_limit' | 'model_not_found' | 'context_overflow';
111
+ /** Action: retry with adjusted params, or escalate to next fallback. */
112
+ action: 'retry_with_params' | 'escalate' | 'log_only';
113
+ /** When action=retry_with_params, the param adjustments to apply. */
114
+ retryParams?: Record<string, unknown>;
115
+ /** Max retries with this rule. */
116
+ maxRetries?: number;
117
+ /** Human-readable reason for digest reporting. */
118
+ reason: string;
119
+ }
120
+ interface LoweringSpec {
121
+ /** Where the system prompt goes. */
122
+ system: {
123
+ mode: SystemPromptMode;
124
+ field?: string;
125
+ };
126
+ /** Cache strategy + parameters. */
127
+ cache: {
128
+ strategy: CacheStrategy;
129
+ /** Min tokens before caching is worth it (provider rules). */
130
+ minTokens?: number;
131
+ /** Discount factor on cached input (0.1 = 10% of normal price). */
132
+ discount?: number;
133
+ /** TTL hint in seconds. */
134
+ ttlSeconds?: number;
135
+ };
136
+ /** Tool format identifier — see lower.ts for supported formats. */
137
+ tools?: {
138
+ format: 'anthropic' | 'google' | 'openai' | 'deepseek';
139
+ };
140
+ /** Thinking config — present iff this model has a thinking knob. */
141
+ thinking?: {
142
+ /** Field path on the request. */
143
+ field: string;
144
+ /** Default value when caller hasn't specified. */
145
+ default?: number | 'auto' | 'off';
146
+ };
147
+ }
148
+ /**
149
+ * Coarse latency bucket for a model. alpha.47 — the third swap axis
150
+ * (cost / quality / SPEED). We bucket rather than store per-model ms because
151
+ * served latency varies with token count; honest precision is the tier, not a
152
+ * false-precise number. See {@link LATENCY_TIER_MS} for the representative ms
153
+ * each tier maps to when compared against `constraints.maxLatencyMs`.
154
+ */
155
+ type LatencyTier = 'fast' | 'medium' | 'slow';
156
+ interface ModelProfile {
157
+ id: string;
158
+ provider: Provider;
159
+ status: 'current' | 'preview' | 'legacy';
160
+ maxContextTokens: number;
161
+ maxOutputTokens: number;
162
+ maxTools: number;
163
+ parallelToolCalls: boolean;
164
+ structuredOutput: StructuredOutputCapability;
165
+ systemPromptMode: SystemPromptMode;
166
+ streaming: boolean;
167
+ cliffs: CliffRule[];
168
+ costInputPer1m: number;
169
+ costOutputPer1m: number;
170
+ lowering: LoweringSpec;
171
+ recovery: RecoveryRule[];
172
+ strengths: string[];
173
+ weaknesses: string[];
174
+ /**
175
+ * alpha.47 — explicit latency bucket. OPTIONAL: when unset, `latencyTierOf`
176
+ * derives it from the tags above (`weaknesses` includes `'latency'` → slow,
177
+ * `strengths` includes `'speed'` → fast, else medium). Set this explicitly
178
+ * ONLY when measured evidence contradicts the tag derivation — e.g.
179
+ * `deepseek-v4-flash` carries no `'latency'` weakness yet measures ~20s
180
+ * (alpha.46 shadow-probe). Carry provenance in an inline comment when you
181
+ * override, same discipline as capability data (step zero / L-081).
182
+ */
183
+ latencyTier?: LatencyTier;
184
+ notes?: string;
185
+ verifiedAgainstDocs?: string;
186
+ /**
187
+ * Hand-curated per-archetype performance score on a 0-10 scale.
188
+ *
189
+ * 10 = frontier on this archetype (e.g. Opus 4.7 on critique)
190
+ * 8 = strong second tier (Sonnet on plan, Pro on extract)
191
+ * 7 = competent (Haiku on classify, Flash on hunt)
192
+ * 5 = acceptable for tolerant archetypes (Flash-Lite on classify)
193
+ * 3 = degraded (Flash on critique, DeepSeek on hunt)
194
+ *
195
+ * Missing archetypes default to `5` (no data, neutral). Each non-default
196
+ * value should carry a one-line rationale in the profile's note or inline
197
+ * comment citing brain evidence, family prior, or "starter hypothesis —
198
+ * verify with telemetry."
199
+ *
200
+ * Source today: hand-curated from master plan §3.3 + §6.2 starter tables.
201
+ * Source tomorrow (alpha.10+): brain `archetype_model_evidence` view.
202
+ *
203
+ * Anti-hallucination guardrail (master plan §2.5): when the watcher's
204
+ * `--audit-fields` flag flags a profile stale (>90 days since
205
+ * verifiedAgainstDocs), the archetypePerf values get re-audited
206
+ * alongside capability fields. AI-trained intuition is NOT a valid
207
+ * source — only docs or brain evidence.
208
+ *
209
+ * alpha.9.
210
+ */
211
+ archetypePerf?: Partial<Record<IntentArchetypeName, number>>;
212
+ /**
213
+ * alpha.41 — model-family identifier (e.g. `'claude-opus'`,
214
+ * `'gemini-flash'`). Reads through from `kgauto_models.family` (migration
215
+ * 024). When unset on a brain row, runtime falls back to
216
+ * `deriveFamilyFromModelId(model.id)` (see `family-resolution.ts`).
217
+ *
218
+ * Used by `getRecommendedPrimary({ family, ... })` and the IR-level
219
+ * `{ family: string }` chain entry resolution at compile time.
220
+ */
221
+ family?: string;
222
+ /**
223
+ * alpha.41 — version string of the kgauto release that first introduced
224
+ * this profile (e.g. `'2.0.0-alpha.36'`). Threaded through from the brain
225
+ * row's `version_added` column. Family-resolution sorts candidates by
226
+ * `version_added DESC` (lexicographic) as the secondary tiebreaker after
227
+ * `archetypePerf[archetype]`. Undefined on bundled profiles (no brain
228
+ * row).
229
+ */
230
+ versionAdded?: string;
231
+ /**
232
+ * alpha.41 — whether the brain row is `active = TRUE`. False or undefined
233
+ * means the model is retired / not actively served (kgauto_models row
234
+ * exists but won't be selected by family resolution). Bundled profiles
235
+ * default to `true` when not threaded through (every PROFILES_RAW entry
236
+ * is by definition the active source of truth at bundle time).
237
+ */
238
+ active?: boolean;
239
+ /**
240
+ * alpha.43 — per-archetype prompt-shape conventions. Applied at compile
241
+ * time by `passApplyConventions` (after model selection, before lower).
242
+ * When a convention's archetype matches the request's intent_archetype,
243
+ * the prefix + suffix are applied (idempotent if already present) and
244
+ * the structured-output / cliff-warning diagnostics surface.
245
+ *
246
+ * Conventions are FAMILY-LEVEL by default — set them on the family
247
+ * representative profile (e.g. `deepseek-v4-pro` for the
248
+ * `deepseek-reasoner` family) and other members inherit at compile time
249
+ * via the `family-resolution.deriveFamilyFromModelId` lookup. Model-
250
+ * specific overrides on a member profile take precedence over the
251
+ * family default for the same archetype.
252
+ *
253
+ * See `ArchetypeConvention` for field semantics.
254
+ */
255
+ archetypeConventions?: ArchetypeConvention[];
256
+ }
257
+ /**
258
+ * Representative p50 latency (ms) per tier. Coarse on purpose — used only to
259
+ * compare a model against `constraints.maxLatencyMs`, never reported as a
260
+ * per-model number. Grounded: alpha.46 shadow-probe measured
261
+ * `deepseek-v4-flash` at 20485ms and `deepseek-v4-pro` at 47722ms (2026-06-03),
262
+ * both bucket `slow`; gemini-2.5-flash / haiku-4-5 serve in single-digit
263
+ * seconds → `fast`; mid-tier (sonnet, gemini-pro) → `medium`. Phase 2 can swap
264
+ * these buckets for measured per-(archetype,model) p50 from
265
+ * `compile_outcomes.latency_ms` once enough served rows accumulate.
266
+ */
267
+ declare const LATENCY_TIER_MS: Record<LatencyTier, number>;
268
+ /**
269
+ * Resolve a model's latency tier. Explicit `profile.latencyTier` wins;
270
+ * otherwise derive from the tags already on the profile so we don't maintain a
271
+ * second source of truth that can silently disagree (L-073 family):
272
+ * - `weaknesses` includes `'latency'` → `'slow'`
273
+ * - `strengths` includes `'speed'` → `'fast'`
274
+ * - else → `'medium'`
275
+ */
276
+ declare function latencyTierOf(profile: ModelProfile): LatencyTier;
277
+ declare const ALIASES: Record<string, string>;
278
+ interface ProfileBrainHook {
279
+ getProfile?: (canonicalId: string) => ModelProfile | undefined;
280
+ resolveAlias?: (id: string) => string | undefined;
281
+ }
282
+ /** @internal — called by models-brain.ts at module load. */
283
+ declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
284
+ declare function getProfile(id: string): ModelProfile;
285
+ declare function tryGetProfile(id: string): ModelProfile | undefined;
286
+ declare function allProfiles(): readonly ModelProfile[];
287
+ /** @internal — bundled-only access for adapters that need a non-brain
288
+ * fallback baseline (avoids a brain → profiles → brain re-entry). */
289
+ declare function allProfilesRaw(): readonly ModelProfile[];
290
+ declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
291
+
292
+ 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, tryGetProfile };
@@ -1,2 +1,292 @@
1
- export { f as ALIASES, g as CacheStrategy, j as CliffRule, L as LoweringSpec, M as ModelProfile, q as RecoveryRule, S as StructuredOutputCapability, r as SystemPromptMode, t as allProfiles, u as getProfile, v as profilesByProvider, w as tryGetProfile } from './profiles-B3eNQ2py.js';
2
- import './dialect.js';
1
+ import { k as Provider } from './ir-Bvlkw5ja.js';
2
+ import { IntentArchetypeName } from './dialect.js';
3
+
4
+ /**
5
+ * Model profiles — executable knowledge about each provider/model.
6
+ *
7
+ * Unlike v1 which carried `known_failures` as prose strings, v2 makes them
8
+ * executable: cliffs trigger guards, lowering describes the wire format,
9
+ * recovery handlers describe what to do after specific failures.
10
+ *
11
+ * Each profile is the answer to "if I want to call THIS model with THIS
12
+ * shape of work, what does it need from me, and what should I do when it
13
+ * fails?"
14
+ */
15
+
16
+ type StructuredOutputCapability = 'native' | 'grammar' | 'none';
17
+ type SystemPromptMode = 'inline' | 'separate' | 'as_developer' | 'unsupported';
18
+ type CacheStrategy = 'cache_control' | 'cachedContent' | 'unsupported';
19
+ interface CliffRule {
20
+ /** What metric triggers this cliff. */
21
+ metric: 'input_tokens' | 'tool_count' | 'history_turns' | 'thinking_with_short_output';
22
+ /** Threshold — meaning depends on metric. */
23
+ threshold: number;
24
+ /** What action to take when triggered. */
25
+ action: 'downgrade_quality_warning' | 'drop_to_top_relevant' | 'force_thinking_budget_zero' | 'force_terse_output' | 'escalate_target' | 'strip_tools';
26
+ /**
27
+ * Optional: only fire this cliff when the IR's intent.archetype matches.
28
+ * Used for archetype-specific failure modes (e.g. Gemini Flash returns
29
+ * empty when summarize is offered tools).
30
+ */
31
+ whenIntent?: IntentArchetypeName;
32
+ /** Human-readable reason for digest reporting. */
33
+ reason: string;
34
+ }
35
+ /**
36
+ * alpha.43 — per-family-per-archetype prompt-shape convention.
37
+ *
38
+ * Cliffs are runtime warnings about model failure modes; conventions are
39
+ * compile-time prompt rewrites that head off those failure modes BEFORE the
40
+ * call leaves kgauto. The split: "this model hedges on classify" is a fact
41
+ * about the model (a convention); "this prompt is 80k tokens on a Flash
42
+ * profile" is a fact about the call (a cliff).
43
+ *
44
+ * Conventions live as data on profiles (NOT hardcoded in passes). The
45
+ * `passApplyConventions` pass walks each matching convention and applies
46
+ * its prefix/suffix/structured-output hint at compile time. Idempotent: if
47
+ * the prefix/suffix is already at the head/tail, the pass no-ops.
48
+ *
49
+ * Defaulting rule: set conventions on the FAMILY REPRESENTATIVE profile
50
+ * (e.g. deepseek-v4-pro is the family rep for the `deepseek-reasoner`
51
+ * family). Other family members inherit at compile time via the
52
+ * `family-resolution.deriveFamilyFromModelId` lookup. Model-specific
53
+ * overrides are rare; use them only when one model in a family genuinely
54
+ * diverges from the family default.
55
+ *
56
+ * Trigger that justified the substrate (2026-05-28): V4-Pro probe on
57
+ * tt-intel/classify (exclusion-finding ID 20) showed 8/10 judge rationales
58
+ * citing "candidate hedges and fails to commit to a single classification."
59
+ * Without a forcing-function suffix, every reasoner probe on a decisive
60
+ * archetype verdicts stay-excluded for reasoner-behavior reasons, not
61
+ * quality reasons. The convention substrate is the kgauto-side fix.
62
+ */
63
+ interface ArchetypeConvention {
64
+ /** Intent archetype this convention applies to. */
65
+ archetype: IntentArchetypeName;
66
+ /**
67
+ * String prepended to the system prompt (after any existing system
68
+ * content). Use for forcing-functions, output-shape directives,
69
+ * anti-hedge framing. Omit if no prefix needed.
70
+ */
71
+ promptPrefix?: string;
72
+ /**
73
+ * String appended to the LAST user message in history (or to
74
+ * `currentTurn` when history is empty). Use for tail-anchored
75
+ * forcing-functions ("Output exactly one of: [...]"). Omit if no suffix
76
+ * needed.
77
+ */
78
+ promptSuffix?: string;
79
+ /**
80
+ * If 'enforce', kgauto warns (but does not block) when structuredOutput
81
+ * is NOT set and the model wants it. If 'avoid', kgauto warns when
82
+ * structuredOutput IS set and the model struggles with schema
83
+ * compliance. If omitted, no structured-output guidance.
84
+ */
85
+ structuredOutputHint?: 'enforce' | 'avoid';
86
+ /**
87
+ * Free-form cliff-style warning surfaced in
88
+ * `CompileResult.diagnostics.cliffWarnings` when the convention's
89
+ * preconditions are met but the consumer opted out of the convention
90
+ * (e.g. provided their own conflicting prompt-shape) — or when the
91
+ * convention can't be applied automatically (cliffWarning-only entries
92
+ * are pure diagnostics).
93
+ */
94
+ cliffWarning?: string;
95
+ /**
96
+ * Optional: only fire this convention's cliffWarning when the tool count
97
+ * is at least this threshold. Used for parallel-tool advisories on
98
+ * archetypes that don't otherwise carry a hard tool cap.
99
+ */
100
+ whenToolCountAtLeast?: number;
101
+ /**
102
+ * Brain-evidence-linked justification. Appears in mutations_applied
103
+ * trail + advisor rule messages. Same format as existing cliff.reason
104
+ * strings.
105
+ */
106
+ reason: string;
107
+ }
108
+ interface RecoveryRule {
109
+ /** What signal triggers recovery. */
110
+ signal: 'empty_response_after_tool' | 'empty_response' | 'malformed_function_call' | 'rate_limit' | 'model_not_found' | 'context_overflow';
111
+ /** Action: retry with adjusted params, or escalate to next fallback. */
112
+ action: 'retry_with_params' | 'escalate' | 'log_only';
113
+ /** When action=retry_with_params, the param adjustments to apply. */
114
+ retryParams?: Record<string, unknown>;
115
+ /** Max retries with this rule. */
116
+ maxRetries?: number;
117
+ /** Human-readable reason for digest reporting. */
118
+ reason: string;
119
+ }
120
+ interface LoweringSpec {
121
+ /** Where the system prompt goes. */
122
+ system: {
123
+ mode: SystemPromptMode;
124
+ field?: string;
125
+ };
126
+ /** Cache strategy + parameters. */
127
+ cache: {
128
+ strategy: CacheStrategy;
129
+ /** Min tokens before caching is worth it (provider rules). */
130
+ minTokens?: number;
131
+ /** Discount factor on cached input (0.1 = 10% of normal price). */
132
+ discount?: number;
133
+ /** TTL hint in seconds. */
134
+ ttlSeconds?: number;
135
+ };
136
+ /** Tool format identifier — see lower.ts for supported formats. */
137
+ tools?: {
138
+ format: 'anthropic' | 'google' | 'openai' | 'deepseek';
139
+ };
140
+ /** Thinking config — present iff this model has a thinking knob. */
141
+ thinking?: {
142
+ /** Field path on the request. */
143
+ field: string;
144
+ /** Default value when caller hasn't specified. */
145
+ default?: number | 'auto' | 'off';
146
+ };
147
+ }
148
+ /**
149
+ * Coarse latency bucket for a model. alpha.47 — the third swap axis
150
+ * (cost / quality / SPEED). We bucket rather than store per-model ms because
151
+ * served latency varies with token count; honest precision is the tier, not a
152
+ * false-precise number. See {@link LATENCY_TIER_MS} for the representative ms
153
+ * each tier maps to when compared against `constraints.maxLatencyMs`.
154
+ */
155
+ type LatencyTier = 'fast' | 'medium' | 'slow';
156
+ interface ModelProfile {
157
+ id: string;
158
+ provider: Provider;
159
+ status: 'current' | 'preview' | 'legacy';
160
+ maxContextTokens: number;
161
+ maxOutputTokens: number;
162
+ maxTools: number;
163
+ parallelToolCalls: boolean;
164
+ structuredOutput: StructuredOutputCapability;
165
+ systemPromptMode: SystemPromptMode;
166
+ streaming: boolean;
167
+ cliffs: CliffRule[];
168
+ costInputPer1m: number;
169
+ costOutputPer1m: number;
170
+ lowering: LoweringSpec;
171
+ recovery: RecoveryRule[];
172
+ strengths: string[];
173
+ weaknesses: string[];
174
+ /**
175
+ * alpha.47 — explicit latency bucket. OPTIONAL: when unset, `latencyTierOf`
176
+ * derives it from the tags above (`weaknesses` includes `'latency'` → slow,
177
+ * `strengths` includes `'speed'` → fast, else medium). Set this explicitly
178
+ * ONLY when measured evidence contradicts the tag derivation — e.g.
179
+ * `deepseek-v4-flash` carries no `'latency'` weakness yet measures ~20s
180
+ * (alpha.46 shadow-probe). Carry provenance in an inline comment when you
181
+ * override, same discipline as capability data (step zero / L-081).
182
+ */
183
+ latencyTier?: LatencyTier;
184
+ notes?: string;
185
+ verifiedAgainstDocs?: string;
186
+ /**
187
+ * Hand-curated per-archetype performance score on a 0-10 scale.
188
+ *
189
+ * 10 = frontier on this archetype (e.g. Opus 4.7 on critique)
190
+ * 8 = strong second tier (Sonnet on plan, Pro on extract)
191
+ * 7 = competent (Haiku on classify, Flash on hunt)
192
+ * 5 = acceptable for tolerant archetypes (Flash-Lite on classify)
193
+ * 3 = degraded (Flash on critique, DeepSeek on hunt)
194
+ *
195
+ * Missing archetypes default to `5` (no data, neutral). Each non-default
196
+ * value should carry a one-line rationale in the profile's note or inline
197
+ * comment citing brain evidence, family prior, or "starter hypothesis —
198
+ * verify with telemetry."
199
+ *
200
+ * Source today: hand-curated from master plan §3.3 + §6.2 starter tables.
201
+ * Source tomorrow (alpha.10+): brain `archetype_model_evidence` view.
202
+ *
203
+ * Anti-hallucination guardrail (master plan §2.5): when the watcher's
204
+ * `--audit-fields` flag flags a profile stale (>90 days since
205
+ * verifiedAgainstDocs), the archetypePerf values get re-audited
206
+ * alongside capability fields. AI-trained intuition is NOT a valid
207
+ * source — only docs or brain evidence.
208
+ *
209
+ * alpha.9.
210
+ */
211
+ archetypePerf?: Partial<Record<IntentArchetypeName, number>>;
212
+ /**
213
+ * alpha.41 — model-family identifier (e.g. `'claude-opus'`,
214
+ * `'gemini-flash'`). Reads through from `kgauto_models.family` (migration
215
+ * 024). When unset on a brain row, runtime falls back to
216
+ * `deriveFamilyFromModelId(model.id)` (see `family-resolution.ts`).
217
+ *
218
+ * Used by `getRecommendedPrimary({ family, ... })` and the IR-level
219
+ * `{ family: string }` chain entry resolution at compile time.
220
+ */
221
+ family?: string;
222
+ /**
223
+ * alpha.41 — version string of the kgauto release that first introduced
224
+ * this profile (e.g. `'2.0.0-alpha.36'`). Threaded through from the brain
225
+ * row's `version_added` column. Family-resolution sorts candidates by
226
+ * `version_added DESC` (lexicographic) as the secondary tiebreaker after
227
+ * `archetypePerf[archetype]`. Undefined on bundled profiles (no brain
228
+ * row).
229
+ */
230
+ versionAdded?: string;
231
+ /**
232
+ * alpha.41 — whether the brain row is `active = TRUE`. False or undefined
233
+ * means the model is retired / not actively served (kgauto_models row
234
+ * exists but won't be selected by family resolution). Bundled profiles
235
+ * default to `true` when not threaded through (every PROFILES_RAW entry
236
+ * is by definition the active source of truth at bundle time).
237
+ */
238
+ active?: boolean;
239
+ /**
240
+ * alpha.43 — per-archetype prompt-shape conventions. Applied at compile
241
+ * time by `passApplyConventions` (after model selection, before lower).
242
+ * When a convention's archetype matches the request's intent_archetype,
243
+ * the prefix + suffix are applied (idempotent if already present) and
244
+ * the structured-output / cliff-warning diagnostics surface.
245
+ *
246
+ * Conventions are FAMILY-LEVEL by default — set them on the family
247
+ * representative profile (e.g. `deepseek-v4-pro` for the
248
+ * `deepseek-reasoner` family) and other members inherit at compile time
249
+ * via the `family-resolution.deriveFamilyFromModelId` lookup. Model-
250
+ * specific overrides on a member profile take precedence over the
251
+ * family default for the same archetype.
252
+ *
253
+ * See `ArchetypeConvention` for field semantics.
254
+ */
255
+ archetypeConventions?: ArchetypeConvention[];
256
+ }
257
+ /**
258
+ * Representative p50 latency (ms) per tier. Coarse on purpose — used only to
259
+ * compare a model against `constraints.maxLatencyMs`, never reported as a
260
+ * per-model number. Grounded: alpha.46 shadow-probe measured
261
+ * `deepseek-v4-flash` at 20485ms and `deepseek-v4-pro` at 47722ms (2026-06-03),
262
+ * both bucket `slow`; gemini-2.5-flash / haiku-4-5 serve in single-digit
263
+ * seconds → `fast`; mid-tier (sonnet, gemini-pro) → `medium`. Phase 2 can swap
264
+ * these buckets for measured per-(archetype,model) p50 from
265
+ * `compile_outcomes.latency_ms` once enough served rows accumulate.
266
+ */
267
+ declare const LATENCY_TIER_MS: Record<LatencyTier, number>;
268
+ /**
269
+ * Resolve a model's latency tier. Explicit `profile.latencyTier` wins;
270
+ * otherwise derive from the tags already on the profile so we don't maintain a
271
+ * second source of truth that can silently disagree (L-073 family):
272
+ * - `weaknesses` includes `'latency'` → `'slow'`
273
+ * - `strengths` includes `'speed'` → `'fast'`
274
+ * - else → `'medium'`
275
+ */
276
+ declare function latencyTierOf(profile: ModelProfile): LatencyTier;
277
+ declare const ALIASES: Record<string, string>;
278
+ interface ProfileBrainHook {
279
+ getProfile?: (canonicalId: string) => ModelProfile | undefined;
280
+ resolveAlias?: (id: string) => string | undefined;
281
+ }
282
+ /** @internal — called by models-brain.ts at module load. */
283
+ declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
284
+ declare function getProfile(id: string): ModelProfile;
285
+ declare function tryGetProfile(id: string): ModelProfile | undefined;
286
+ declare function allProfiles(): readonly ModelProfile[];
287
+ /** @internal — bundled-only access for adapters that need a non-brain
288
+ * fallback baseline (avoids a brain → profiles → brain re-entry). */
289
+ declare function allProfilesRaw(): readonly ModelProfile[];
290
+ declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
291
+
292
+ 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, tryGetProfile };