@warmdrift/kgauto-compiler 2.0.0-alpha.9 → 2.0.0-alpha.90

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-4LYNDEHJ.mjs +219 -0
  7. package/dist/chunk-65ZMX5OT.mjs +169 -0
  8. package/dist/{chunk-5TI6PNSK.mjs → chunk-BVEXV5KC.mjs} +11 -0
  9. package/dist/chunk-ENELVMJI.mjs +858 -0
  10. package/dist/chunk-NBO4R5PC.mjs +313 -0
  11. package/dist/chunk-OK2TMFRR.mjs +1879 -0
  12. package/dist/chunk-P3TOAEG4.mjs +56 -0
  13. package/dist/chunk-RO22VFIF.mjs +29 -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 +3197 -0
  29. package/dist/glassbox-routes/index.mjs +668 -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 +3782 -99
  35. package/dist/index.d.ts +3782 -99
  36. package/dist/index.js +10835 -2046
  37. package/dist/index.mjs +6270 -276
  38. package/dist/ir-CTx026t0.d.ts +1887 -0
  39. package/dist/ir-DeYMLWge.d.mts +1887 -0
  40. package/dist/key-health.d.mts +166 -0
  41. package/dist/key-health.d.ts +166 -0
  42. package/dist/key-health.js +247 -0
  43. package/dist/key-health.mjs +12 -0
  44. package/dist/profiles.d.mts +352 -2
  45. package/dist/profiles.d.ts +352 -2
  46. package/dist/profiles.js +1282 -51
  47. package/dist/profiles.mjs +19 -1
  48. package/dist/types-BKbRtmUb.d.ts +131 -0
  49. package/dist/types-Cp9ot1HV.d.ts +142 -0
  50. package/dist/types-DD36cCbZ.d.mts +142 -0
  51. package/dist/types-cBzinzUR.d.mts +131 -0
  52. package/package.json +62 -9
  53. package/dist/chunk-3KVKELZN.mjs +0 -657
  54. package/dist/profiles-BYVOc1eW.d.ts +0 -700
  55. package/dist/profiles-NUZOIzGr.d.mts +0 -700
@@ -1,2 +1,352 @@
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-BYVOc1eW.js';
2
- import './dialect.js';
1
+ import { l as Provider } from './ir-CTx026t0.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
+ * alpha.78 — apply the band-dominating QUALITY_GATE_PENALTY (same lever
28
+ * as the alpha.49 schema-weak gate) when the IR declares
29
+ * structuredOutput and the metric crosses threshold. For models whose
30
+ * declared structured-output support is MEASURED not to hold above an
31
+ * input size on an archetype — evidence-shaped, unlike the archetype-
32
+ * wide `structuredOutputHint: 'avoid'`. Only meaningful with
33
+ * `metric: 'input_tokens'` (+ usually `whenIntent`).
34
+ */
35
+ | 'quality_gate_structured';
36
+ /**
37
+ * Optional: only fire this cliff when the IR's intent.archetype matches.
38
+ * Used for archetype-specific failure modes (e.g. Gemini Flash returns
39
+ * empty when summarize is offered tools).
40
+ */
41
+ whenIntent?: IntentArchetypeName;
42
+ /** Human-readable reason for digest reporting. */
43
+ reason: string;
44
+ }
45
+ /**
46
+ * alpha.43 — per-family-per-archetype prompt-shape convention.
47
+ *
48
+ * Cliffs are runtime warnings about model failure modes; conventions are
49
+ * compile-time prompt rewrites that head off those failure modes BEFORE the
50
+ * call leaves kgauto. The split: "this model hedges on classify" is a fact
51
+ * about the model (a convention); "this prompt is 80k tokens on a Flash
52
+ * profile" is a fact about the call (a cliff).
53
+ *
54
+ * Conventions live as data on profiles (NOT hardcoded in passes). The
55
+ * `passApplyConventions` pass walks each matching convention and applies
56
+ * its prefix/suffix/structured-output hint at compile time. Idempotent: if
57
+ * the prefix/suffix is already at the head/tail, the pass no-ops.
58
+ *
59
+ * Defaulting rule: set conventions on the FAMILY REPRESENTATIVE profile
60
+ * (e.g. deepseek-v4-pro is the family rep for the `deepseek-reasoner`
61
+ * family). Other family members inherit at compile time via the
62
+ * `family-resolution.deriveFamilyFromModelId` lookup. Model-specific
63
+ * overrides are rare; use them only when one model in a family genuinely
64
+ * diverges from the family default.
65
+ *
66
+ * Trigger that justified the substrate (2026-05-28): V4-Pro probe on
67
+ * tt-intel/classify (exclusion-finding ID 20) showed 8/10 judge rationales
68
+ * citing "candidate hedges and fails to commit to a single classification."
69
+ * Without a forcing-function suffix, every reasoner probe on a decisive
70
+ * archetype verdicts stay-excluded for reasoner-behavior reasons, not
71
+ * quality reasons. The convention substrate is the kgauto-side fix.
72
+ */
73
+ interface ArchetypeConvention {
74
+ /** Intent archetype this convention applies to. */
75
+ archetype: IntentArchetypeName;
76
+ /**
77
+ * String prepended to the system prompt (after any existing system
78
+ * content). Use for forcing-functions, output-shape directives,
79
+ * anti-hedge framing. Omit if no prefix needed.
80
+ */
81
+ promptPrefix?: string;
82
+ /**
83
+ * String appended to the LAST user message in history (or to
84
+ * `currentTurn` when history is empty). Use for tail-anchored
85
+ * forcing-functions ("Output exactly one of: [...]"). Omit if no suffix
86
+ * needed.
87
+ */
88
+ promptSuffix?: string;
89
+ /**
90
+ * If 'enforce', kgauto warns (but does not block) when structuredOutput
91
+ * is NOT set and the model wants it. If 'avoid', kgauto warns when
92
+ * structuredOutput IS set and the model struggles with schema
93
+ * compliance. If omitted, no structured-output guidance.
94
+ */
95
+ structuredOutputHint?: 'enforce' | 'avoid';
96
+ /**
97
+ * Free-form cliff-style warning surfaced in
98
+ * `CompileResult.diagnostics.cliffWarnings` when the convention's
99
+ * preconditions are met but the consumer opted out of the convention
100
+ * (e.g. provided their own conflicting prompt-shape) — or when the
101
+ * convention can't be applied automatically (cliffWarning-only entries
102
+ * are pure diagnostics).
103
+ */
104
+ cliffWarning?: string;
105
+ /**
106
+ * Optional: only fire this convention's cliffWarning when the tool count
107
+ * is at least this threshold. Used for parallel-tool advisories on
108
+ * archetypes that don't otherwise carry a hard tool cap.
109
+ */
110
+ whenToolCountAtLeast?: number;
111
+ /**
112
+ * Brain-evidence-linked justification. Appears in mutations_applied
113
+ * trail + advisor rule messages. Same format as existing cliff.reason
114
+ * strings.
115
+ */
116
+ reason: string;
117
+ }
118
+ interface RecoveryRule {
119
+ /** What signal triggers recovery. */
120
+ signal: 'empty_response_after_tool' | 'empty_response' | 'malformed_function_call' | 'rate_limit' | 'model_not_found' | 'context_overflow';
121
+ /** Action: retry with adjusted params, or escalate to next fallback. */
122
+ action: 'retry_with_params' | 'escalate' | 'log_only';
123
+ /** When action=retry_with_params, the param adjustments to apply. */
124
+ retryParams?: Record<string, unknown>;
125
+ /** Max retries with this rule. */
126
+ maxRetries?: number;
127
+ /** Human-readable reason for digest reporting. */
128
+ reason: string;
129
+ }
130
+ interface LoweringSpec {
131
+ /** Where the system prompt goes. */
132
+ system: {
133
+ mode: SystemPromptMode;
134
+ field?: string;
135
+ };
136
+ /** Cache strategy + parameters. */
137
+ cache: {
138
+ strategy: CacheStrategy;
139
+ /** Min tokens before caching is worth it (provider rules). */
140
+ minTokens?: number;
141
+ /** Discount factor on cached input (0.1 = 10% of normal price). */
142
+ discount?: number;
143
+ /** TTL hint in seconds. */
144
+ ttlSeconds?: number;
145
+ };
146
+ /** Tool format identifier — see lower.ts for supported formats. */
147
+ tools?: {
148
+ format: 'anthropic' | 'google' | 'openai' | 'deepseek';
149
+ };
150
+ /** Thinking config — present iff this model has a thinking knob. */
151
+ thinking?: {
152
+ /** Field path on the request. */
153
+ field: string;
154
+ /** Default value when caller hasn't specified. */
155
+ default?: number | 'auto' | 'off';
156
+ };
157
+ }
158
+ /**
159
+ * Coarse latency bucket for a model. alpha.47 — the third swap axis
160
+ * (cost / quality / SPEED). We bucket rather than store per-model ms because
161
+ * served latency varies with token count; honest precision is the tier, not a
162
+ * false-precise number. See {@link LATENCY_TIER_MS} for the representative ms
163
+ * each tier maps to when compared against `constraints.maxLatencyMs`.
164
+ */
165
+ type LatencyTier = 'fast' | 'medium' | 'slow';
166
+ interface ModelProfile {
167
+ id: string;
168
+ provider: Provider;
169
+ status: 'current' | 'preview' | 'legacy';
170
+ maxContextTokens: number;
171
+ maxOutputTokens: number;
172
+ maxTools: number;
173
+ parallelToolCalls: boolean;
174
+ structuredOutput: StructuredOutputCapability;
175
+ systemPromptMode: SystemPromptMode;
176
+ streaming: boolean;
177
+ cliffs: CliffRule[];
178
+ costInputPer1m: number;
179
+ costOutputPer1m: number;
180
+ lowering: LoweringSpec;
181
+ recovery: RecoveryRule[];
182
+ strengths: string[];
183
+ weaknesses: string[];
184
+ /**
185
+ * alpha.47 — explicit latency bucket. OPTIONAL: when unset, `latencyTierOf`
186
+ * derives it from the tags above (`weaknesses` includes `'latency'` → slow,
187
+ * `strengths` includes `'speed'` → fast, else medium). Set this explicitly
188
+ * ONLY when measured evidence contradicts the tag derivation — e.g.
189
+ * `deepseek-v4-flash` carries no `'latency'` weakness yet measures ~20s
190
+ * (alpha.46 shadow-probe). Carry provenance in an inline comment when you
191
+ * override, same discipline as capability data (step zero / L-081).
192
+ */
193
+ latencyTier?: LatencyTier;
194
+ notes?: string;
195
+ verifiedAgainstDocs?: string;
196
+ /**
197
+ * Hand-curated per-archetype performance score on a 0-10 scale.
198
+ *
199
+ * 10 = frontier on this archetype (e.g. Opus 4.7 on critique)
200
+ * 8 = strong second tier (Sonnet on plan, Pro on extract)
201
+ * 7 = competent (Haiku on classify, Flash on hunt)
202
+ * 5 = acceptable for tolerant archetypes (Flash-Lite on classify)
203
+ * 3 = degraded (Flash on critique, DeepSeek on hunt)
204
+ *
205
+ * Missing archetypes default to `5` (no data, neutral). Each non-default
206
+ * value should carry a one-line rationale in the profile's note or inline
207
+ * comment citing brain evidence, family prior, or "starter hypothesis —
208
+ * verify with telemetry."
209
+ *
210
+ * Source today: hand-curated from master plan §3.3 + §6.2 starter tables.
211
+ * Source tomorrow (alpha.10+): brain `archetype_model_evidence` view.
212
+ *
213
+ * Anti-hallucination guardrail (master plan §2.5): when the watcher's
214
+ * `--audit-fields` flag flags a profile stale (>90 days since
215
+ * verifiedAgainstDocs), the archetypePerf values get re-audited
216
+ * alongside capability fields. AI-trained intuition is NOT a valid
217
+ * source — only docs or brain evidence.
218
+ *
219
+ * alpha.9.
220
+ */
221
+ archetypePerf?: Partial<Record<IntentArchetypeName, number>>;
222
+ /**
223
+ * alpha.41 — model-family identifier (e.g. `'claude-opus'`,
224
+ * `'gemini-flash'`). Reads through from `kgauto_models.family` (migration
225
+ * 024). When unset on a brain row, runtime falls back to
226
+ * `deriveFamilyFromModelId(model.id)` (see `family-resolution.ts`).
227
+ *
228
+ * Used by `getRecommendedPrimary({ family, ... })` and the IR-level
229
+ * `{ family: string }` chain entry resolution at compile time.
230
+ */
231
+ family?: string;
232
+ /**
233
+ * alpha.41 — version string of the kgauto release that first introduced
234
+ * this profile (e.g. `'2.0.0-alpha.36'`). Threaded through from the brain
235
+ * row's `version_added` column. Family-resolution sorts candidates by
236
+ * `version_added DESC` (lexicographic) as the secondary tiebreaker after
237
+ * `archetypePerf[archetype]`. Undefined on bundled profiles (no brain
238
+ * row).
239
+ */
240
+ versionAdded?: string;
241
+ /**
242
+ * alpha.41 — whether the brain row is `active = TRUE`. False or undefined
243
+ * means the model is retired / not actively served (kgauto_models row
244
+ * exists but won't be selected by family resolution). Bundled profiles
245
+ * default to `true` when not threaded through (every PROFILES_RAW entry
246
+ * is by definition the active source of truth at bundle time).
247
+ */
248
+ active?: boolean;
249
+ /**
250
+ * alpha.43 — per-archetype prompt-shape conventions. Applied at compile
251
+ * time by `passApplyConventions` (after model selection, before lower).
252
+ * When a convention's archetype matches the request's intent_archetype,
253
+ * the prefix + suffix are applied (idempotent if already present) and
254
+ * the structured-output / cliff-warning diagnostics surface.
255
+ *
256
+ * Conventions are FAMILY-LEVEL by default — set them on the family
257
+ * representative profile (e.g. `deepseek-v4-pro` for the
258
+ * `deepseek-reasoner` family) and other members inherit at compile time
259
+ * via the `family-resolution.deriveFamilyFromModelId` lookup. Model-
260
+ * specific overrides on a member profile take precedence over the
261
+ * family default for the same archetype.
262
+ *
263
+ * See `ArchetypeConvention` for field semantics.
264
+ */
265
+ archetypeConventions?: ArchetypeConvention[];
266
+ /**
267
+ * alpha.87 — true ONLY on profiles synthesized by
268
+ * `onUnprofiledModel: 'best-effort'`. Lets compile() (and any consumer)
269
+ * distinguish "kgauto knows this model" from "kgauto is winging it with
270
+ * borrowed wire mechanics" on every call, not just the one that
271
+ * triggered synthesis. Never set on bundled, brain, or
272
+ * `registerProfiles()` entries.
273
+ */
274
+ bestEffort?: true;
275
+ }
276
+ /**
277
+ * Representative p50 latency (ms) per tier. Coarse on purpose — used only to
278
+ * compare a model against `constraints.maxLatencyMs`, never reported as a
279
+ * per-model number. Grounded: alpha.46 shadow-probe measured
280
+ * `deepseek-v4-flash` at 20485ms and `deepseek-v4-pro` at 47722ms (2026-06-03),
281
+ * both bucket `slow`; gemini-2.5-flash / haiku-4-5 serve in single-digit
282
+ * seconds → `fast`; mid-tier (sonnet, gemini-pro) → `medium`. Phase 2 can swap
283
+ * these buckets for measured per-(archetype,model) p50 from
284
+ * `compile_outcomes.latency_ms` once enough served rows accumulate.
285
+ */
286
+ declare const LATENCY_TIER_MS: Record<LatencyTier, number>;
287
+ /**
288
+ * Resolve a model's latency tier. Explicit `profile.latencyTier` wins;
289
+ * otherwise derive from the tags already on the profile so we don't maintain a
290
+ * second source of truth that can silently disagree (L-073 family):
291
+ * - `weaknesses` includes `'latency'` → `'slow'`
292
+ * - `strengths` includes `'speed'` → `'fast'`
293
+ * - else → `'medium'`
294
+ */
295
+ declare function latencyTierOf(profile: ModelProfile): LatencyTier;
296
+ declare const ALIASES: Record<string, string>;
297
+ interface ProfileBrainHook {
298
+ getProfile?: (canonicalId: string) => ModelProfile | undefined;
299
+ resolveAlias?: (id: string) => string | undefined;
300
+ }
301
+ /** @internal — called by models-brain.ts at module load. */
302
+ declare function _setProfileBrainHook(hook: ProfileBrainHook): void;
303
+ /**
304
+ * Register consumer-supplied profiles. They take precedence over both
305
+ * brain-curated and bundled profiles for the same id (explicit > learned >
306
+ * shipped — see block comment above for the tradeoff). Re-registering an
307
+ * id overwrites the previous consumer entry, including any best-effort
308
+ * synthesized profile.
309
+ */
310
+ declare function registerProfiles(profiles: readonly ModelProfile[]): void;
311
+ /** @internal — test hook. */
312
+ declare function _testClearConsumerProfiles(): void;
313
+ /** Provider inference for best-effort mode — id prefix conventions only. */
314
+ declare function inferProviderFromId(id: string): Provider | undefined;
315
+ /**
316
+ * alpha.87 — best-effort profile synthesis for unprofiled ids (opt-in via
317
+ * `CompilePolicy.onUnprofiledModel: 'best-effort'`; the default posture
318
+ * stays refuse). Returns undefined when the provider cannot be inferred
319
+ * from the id or kgauto ships no donor profile for that provider — in
320
+ * both cases the caller falls back to the standard refusal, which names
321
+ * `registerProfiles()` as the informed path.
322
+ *
323
+ * What a synthesized profile is: the inferred provider's wire mechanics
324
+ * (LoweringSpec / systemPromptMode / streaming are provider-wide, borrowed
325
+ * from a current bundled profile of that provider) around deliberately
326
+ * conservative capability claims — no cliffs, no recovery, no measured
327
+ * knowledge, `structuredOutput: 'none'`, sequential tools, modest output
328
+ * budget, and **cost 0 because cost is UNKNOWN** (cost gates and cost
329
+ * attribution are meaningless for this model; the compile carries a loud
330
+ * warning saying exactly that). It is registered into the consumer index
331
+ * on first synthesis so every later lookup in the process (fallback walk,
332
+ * passes, telemetry) sees one consistent object.
333
+ */
334
+ declare function bestEffortProfile(id: string): ModelProfile | undefined;
335
+ /**
336
+ * Resolve a model id to its canonical form (alias → canonical, unknown ids
337
+ * returned unchanged). This is the same resolution `getProfile` applies, so
338
+ * any code comparing model ids against a policy list (blockedModels,
339
+ * preferredModels) must compare canonical forms on BOTH sides — an alias and
340
+ * its canonical are the same model, and a raw-string comparison lets one
341
+ * evade a policy naming the other (alpha.85, tt-intel s119 spend-gate leak).
342
+ */
343
+ declare function resolveModelAlias(id: string): string;
344
+ declare function getProfile(id: string): ModelProfile;
345
+ declare function tryGetProfile(id: string): ModelProfile | undefined;
346
+ declare function allProfiles(): readonly ModelProfile[];
347
+ /** @internal — bundled-only access for adapters that need a non-brain
348
+ * fallback baseline (avoids a brain → profiles → brain re-entry). */
349
+ declare function allProfilesRaw(): readonly ModelProfile[];
350
+ declare function profilesByProvider(provider: Provider): readonly ModelProfile[];
351
+
352
+ export { ALIASES, type ArchetypeConvention, type CacheStrategy, type CliffRule, LATENCY_TIER_MS, type LatencyTier, type LoweringSpec, type ModelProfile, type RecoveryRule, type StructuredOutputCapability, type SystemPromptMode, _setProfileBrainHook, _testClearConsumerProfiles, allProfiles, allProfilesRaw, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile };