@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.
- package/README.md +42 -0
- package/dist/chunk-WXCFWUCN.mjs +678 -0
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/index.d.mts +117 -6
- package/dist/glassbox-routes/index.d.ts +117 -6
- package/dist/glassbox-routes/index.js +1859 -8
- package/dist/glassbox-routes/index.mjs +359 -8
- package/dist/index.d.mts +473 -13
- package/dist/index.d.ts +473 -13
- package/dist/index.js +543 -10
- package/dist/index.mjs +484 -585
- package/dist/{ir-B_XX2LAO.d.ts → ir-BIAT9gJk.d.ts} +195 -1
- package/dist/{ir-B9zqlwjH.d.mts → ir-De2AQtlr.d.mts} +195 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-o9etg93a.d.mts → types-BjrIFPGe.d.mts} +1 -1
- package/dist/{types-bt0aVJb8.d.ts → types-D_JAhCv4.d.ts} +1 -1
- package/package.json +1 -1
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as
|
|
2
|
-
export {
|
|
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 SectionRewrite, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as Adapter, i as PerAxisMetrics, j as Provider, k as ChainEntry, G as Grounding } from './ir-De2AQtlr.mjs';
|
|
2
|
+
export { l as CallAttempt, m as CallError, n as ChainWithGrounding, o as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, p as MutationApplied, q as NormalizedTokens, r as OutcomeKind, s as PerAxisMetricsByModel, t as PromptSection, u as SectionKind, T as ToolCall, v as ToolDefinition } from './ir-De2AQtlr.mjs';
|
|
3
3
|
import { ModelProfile } from './profiles.mjs';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.mjs';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.mjs';
|
|
@@ -94,16 +94,6 @@ declare function execute(request: CompiledRequest, opts?: ExecuteOptions): Promi
|
|
|
94
94
|
*/
|
|
95
95
|
declare function call(ir: PromptIR, opts?: CallOptions): Promise<CallResult>;
|
|
96
96
|
|
|
97
|
-
/**
|
|
98
|
-
* Brain client — fire-and-forget telemetry to the central kgauto Supabase.
|
|
99
|
-
*
|
|
100
|
-
* The brain is the centralized learning store. Apps POST outcomes here;
|
|
101
|
-
* mutations flow back through a separate pull (in v2.1).
|
|
102
|
-
*
|
|
103
|
-
* Design: never blocks the caller. Failures are silent (logged via optional
|
|
104
|
-
* onError hook). Uses fetch() — works in Node 18+, Edge runtimes, and browsers.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
97
|
/**
|
|
108
98
|
* alpha.11 — opt-in nested config for brain-query mode (chains / archetype
|
|
109
99
|
* perf / pricing / models registry). Enabled by default when endpoint is
|
|
@@ -205,6 +195,20 @@ interface OutcomePayload {
|
|
|
205
195
|
* cliff lumps DeepSeek sequential perf with parallel without this).
|
|
206
196
|
*/
|
|
207
197
|
tool_orchestration?: 'parallel' | 'sequential' | 'either' | null;
|
|
198
|
+
finish_reason?: string;
|
|
199
|
+
total_ms?: number;
|
|
200
|
+
tools_count?: number;
|
|
201
|
+
history_depth?: number;
|
|
202
|
+
system_prompt_chars?: number;
|
|
203
|
+
fell_over_from?: string;
|
|
204
|
+
fallback_reason?: 'rate_limit' | 'provider_auth_failed' | 'provider_error' | 'cliff' | 'cost_cap' | 'contract_violation';
|
|
205
|
+
/**
|
|
206
|
+
* Per-call SectionRewrite[] captured at compile time. Omitted (sent as
|
|
207
|
+
* undefined → stored NULL) when no rewrites fired. Powers cross-app
|
|
208
|
+
* learning aggregates ("rule X fired N times on (app, model, archetype),
|
|
209
|
+
* downstream outcome quality lifted by M points").
|
|
210
|
+
*/
|
|
211
|
+
section_rewrites_applied?: SectionRewrite[] | null;
|
|
208
212
|
}
|
|
209
213
|
/**
|
|
210
214
|
* alpha.20 Entry 4: record a quality outcome for a previously-compiled call.
|
|
@@ -342,6 +346,17 @@ type AdvisorContext = Pick<CompileResult, 'target' | 'provider' | 'tokensIn' | '
|
|
|
342
346
|
interface RunAdvisorPhase2Context {
|
|
343
347
|
fallbackChain: string[];
|
|
344
348
|
profileResolver?: (id: string) => ModelProfile | undefined;
|
|
349
|
+
/**
|
|
350
|
+
* alpha.29 — translator rewrites that fired this compile. When a rewrite
|
|
351
|
+
* cleared the cliff (e.g. `tool_call_contract` → sequential-tool preamble
|
|
352
|
+
* + `parallelToolCalls: false`), the matching cliff advisor
|
|
353
|
+
* (`archetype-perf-floor-breach`) MUST suppress for the same call. Without
|
|
354
|
+
* suppression both fire — the advisory contradicts the rewrite ("cliff is
|
|
355
|
+
* unaddressed" vs "we just addressed it").
|
|
356
|
+
*
|
|
357
|
+
* Empty array / undefined → no suppression (alpha.28 behavior preserved).
|
|
358
|
+
*/
|
|
359
|
+
sectionRewritesApplied?: SectionRewrite[];
|
|
345
360
|
}
|
|
346
361
|
/**
|
|
347
362
|
* Run all phased rules and return collected advisories. Order is fixed so
|
|
@@ -358,6 +373,451 @@ interface RunAdvisorPhase2Context {
|
|
|
358
373
|
*/
|
|
359
374
|
declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: ModelProfile, policy?: CompilePolicy, phase2?: RunAdvisorPhase2Context): BestPracticeAdvisory[];
|
|
360
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Translator primitive — alpha.29.
|
|
378
|
+
*
|
|
379
|
+
* Pure function. Walks `IR.sections`, matches each section's `kind` against
|
|
380
|
+
* the model + archetype + profile, and applies a model-aware rewrite when
|
|
381
|
+
* a rule fires. Returns the rewritten IR + the list of rewrites for
|
|
382
|
+
* `CompileResult.sectionRewritesApplied` and brain persistence.
|
|
383
|
+
*
|
|
384
|
+
* This is the s37 translator-framing eureka in code: kgauto graduates from
|
|
385
|
+
* "gate" (alpha.28's cliff advisor: "consumer must accept adapter") to
|
|
386
|
+
* "translator" (alpha.29: "consumer declared the section kind, kgauto
|
|
387
|
+
* applies the adapter at compile time without consumer-side branching").
|
|
388
|
+
*
|
|
389
|
+
* alpha.29 ships ONE rule:
|
|
390
|
+
*
|
|
391
|
+
* tool_call_contract + profile.archetypePerf[archetype] < ARCHETYPE_FLOOR_DEFAULT
|
|
392
|
+
* → prepend sequential-tool-pattern guidance
|
|
393
|
+
* → emit wireOverrides: { parallelToolCalls: false }
|
|
394
|
+
*
|
|
395
|
+
* alpha.30+ will extend the rule table to `narration_contract`, `role_intro`,
|
|
396
|
+
* etc. Each new rule lands here as an explicit branch.
|
|
397
|
+
*
|
|
398
|
+
* **Interaction with the cliff advisor (alpha.28):** when this translator
|
|
399
|
+
* fires for a `tool_call_contract` section, the advisor's
|
|
400
|
+
* `archetype-perf-floor-breach` rule MUST suppress for the same call — the
|
|
401
|
+
* cliff was structurally cleared by the rewrite, not unaddressed. The
|
|
402
|
+
* suppression check lives in `advisor.ts` and consults the
|
|
403
|
+
* `CompileResult.sectionRewritesApplied` list.
|
|
404
|
+
*
|
|
405
|
+
* Design contract:
|
|
406
|
+
* command-center/advisory/kgauto/2026-05-21_alpha-29-translator-and-advisories-api.md
|
|
407
|
+
*/
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Re-export of `ARCHETYPE_FLOOR_DEFAULT` as the canonical "translator fires
|
|
411
|
+
* below this score" threshold. Same constant as the cliff advisor — the
|
|
412
|
+
* single threshold is shared (alpha.28's "below this, advisor warns"; alpha.29's
|
|
413
|
+
* "below this, translator AUTO-APPLIES the adapter").
|
|
414
|
+
*/
|
|
415
|
+
declare const TRANSLATOR_FLOOR = 6;
|
|
416
|
+
/**
|
|
417
|
+
* Stable identifier of the alpha.29 sequential-tool rule. Surfaces on
|
|
418
|
+
* `SectionRewrite.rule` and in brain aggregates. Future rules extend this
|
|
419
|
+
* list; the brain learns per-rule effectiveness over time.
|
|
420
|
+
*/
|
|
421
|
+
declare const RULE_SEQUENTIAL_TOOL_CLIFF = "sequential-tool-cliff-below-floor";
|
|
422
|
+
interface ApplySectionRewritesArgs {
|
|
423
|
+
ir: PromptIR;
|
|
424
|
+
profile: ModelProfile;
|
|
425
|
+
archetype: IntentArchetypeName;
|
|
426
|
+
}
|
|
427
|
+
interface ApplySectionRewritesResult {
|
|
428
|
+
/**
|
|
429
|
+
* IR with section.text fields possibly rewritten. When no rewrites fired,
|
|
430
|
+
* this is identical to the input IR (referentially distinct array but
|
|
431
|
+
* same section payloads).
|
|
432
|
+
*/
|
|
433
|
+
rewrittenIR: PromptIR;
|
|
434
|
+
/**
|
|
435
|
+
* One entry per section the translator rewrote. Empty array when no
|
|
436
|
+
* rules fired. Order matches the corresponding section in
|
|
437
|
+
* `rewrittenIR.sections`.
|
|
438
|
+
*/
|
|
439
|
+
rewrites: SectionRewrite[];
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Pure function. Apply model-aware section rewrites to the IR at compile time.
|
|
443
|
+
*
|
|
444
|
+
* Discipline:
|
|
445
|
+
* - Never mutates the input IR; returns a new IR with new sections array.
|
|
446
|
+
* - Sections without a `kind` (or `kind === 'arbitrary'`) pass through
|
|
447
|
+
* unchanged.
|
|
448
|
+
* - Empty `sections` array → returns `{ rewrittenIR: ir, rewrites: [] }`.
|
|
449
|
+
* - Missing `profile.archetypePerf` → no rewrite (defensive — treat the
|
|
450
|
+
* model as un-classified rather than below-floor).
|
|
451
|
+
* - Sections of the same `kind` are processed in array order; the rule
|
|
452
|
+
* fires once per matching section (today every tool_call_contract
|
|
453
|
+
* section gets the same prepend — multiple sections of the same kind
|
|
454
|
+
* ARE supported but is an unusual consumer shape).
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* import { applySectionRewrites } from '@warmdrift/kgauto-compiler';
|
|
459
|
+
* import { getProfile } from '@warmdrift/kgauto-compiler';
|
|
460
|
+
*
|
|
461
|
+
* const { rewrittenIR, rewrites } = applySectionRewrites({
|
|
462
|
+
* ir,
|
|
463
|
+
* profile: getProfile('deepseek-v4-pro'),
|
|
464
|
+
* archetype: 'hunt',
|
|
465
|
+
* });
|
|
466
|
+
* if (rewrites.length > 0) console.log('translator fired:', rewrites);
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
declare function applySectionRewrites(args: ApplySectionRewritesArgs): ApplySectionRewritesResult;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* advisories-api — structured advisories API (alpha.29 Workstream B).
|
|
473
|
+
*
|
|
474
|
+
* Closes the L-117 family bottleneck: kgauto's `result.advisories[]` (the
|
|
475
|
+
* compile-time warnings about caching-off, tool-bloat, archetype-perf-floor
|
|
476
|
+
* breaches, etc.) used to disappear after the consumer read the compile
|
|
477
|
+
* result. The s34 caching-off advisory pattern is the canonical failure: an
|
|
478
|
+
* advisory fired 100+ times in 24h on `generate::sonnet` at 99.4% empty
|
|
479
|
+
* rate, and nobody knew because there was no structured channel to surface
|
|
480
|
+
* "what's open right now?"
|
|
481
|
+
*
|
|
482
|
+
* Migration 020 ships the substrate: `compile_outcome_advisories` gains
|
|
483
|
+
* lifecycle columns (`resolved_at`, `resolution_source`, `resolution_note`)
|
|
484
|
+
* and the `actionable_advisories_v` view rolls per-firing rows into
|
|
485
|
+
* per-(app_id, code) tuples with deterministic stable ids + server-side
|
|
486
|
+
* auto-resolution.
|
|
487
|
+
*
|
|
488
|
+
* Public surface:
|
|
489
|
+
* getActionableAdvisories({ appId, severity?, status?, brainEndpoint, brainJwt, brainAnonKey, fetch? })
|
|
490
|
+
* → Promise<ActionableAdvisory[]>
|
|
491
|
+
*
|
|
492
|
+
* markAdvisoryResolved({ id, resolutionNote?, brainEndpoint, brainJwt, brainAnonKey, fetch? })
|
|
493
|
+
* → Promise<{ ok: true } | { ok: false; reason: string }>
|
|
494
|
+
*
|
|
495
|
+
* Both functions are pure I/O — no module-level state. The fetch wiring
|
|
496
|
+
* mirrors `createProxyHandler` in `glassbox-routes/proxy.ts`: scoped JWT in
|
|
497
|
+
* `Authorization: Bearer`, `apikey` header carries the anon key.
|
|
498
|
+
*
|
|
499
|
+
* The auto-resolution rule is enforced server-side in `actionable_advisories_v`:
|
|
500
|
+
* • Latest firing > 14 days ago → status='resolved' (auto-pruned)
|
|
501
|
+
* • All firings have resolved_at set → status='resolved' (consumer-marked)
|
|
502
|
+
* • Otherwise → status='open'
|
|
503
|
+
*
|
|
504
|
+
* `markAdvisoryResolved` is the consumer override: "I fixed it; the next
|
|
505
|
+
* firing will reopen the rule, but until then it stays resolved."
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Severity of an advisory. Maps to the `level` column on
|
|
510
|
+
* `compile_outcome_advisories` (info | warn | critical).
|
|
511
|
+
*/
|
|
512
|
+
type AdvisorySeverity = 'info' | 'warn' | 'critical';
|
|
513
|
+
/**
|
|
514
|
+
* Status of an advisory rollup.
|
|
515
|
+
*
|
|
516
|
+
* - `open` — at least one unresolved firing in the last 14 days
|
|
517
|
+
* - `resolved` — either auto-pruned (no firings >14d) or consumer-marked
|
|
518
|
+
* - `snoozed` — reserved for alpha.30+ (snooze-until-date); type-accepted
|
|
519
|
+
* today but the view will never emit this value
|
|
520
|
+
*/
|
|
521
|
+
type AdvisoryStatus = 'open' | 'snoozed' | 'resolved';
|
|
522
|
+
/**
|
|
523
|
+
* Source of resolution when status='resolved'.
|
|
524
|
+
*
|
|
525
|
+
* - `auto` — server-side rule auto-pruned (>14d since last firing)
|
|
526
|
+
* - `consumer-marked` — consumer called `markAdvisoryResolved`
|
|
527
|
+
* - `declined` — reserved (alpha.30+: consumer marked the suggestion
|
|
528
|
+
* inapplicable; the advisor will still fire but UIs can hide it)
|
|
529
|
+
*/
|
|
530
|
+
type AdvisoryResolutionSource = 'auto' | 'consumer-marked' | 'declined';
|
|
531
|
+
/**
|
|
532
|
+
* Suggested-fix metadata. `null` when the advisor has no actionable fix
|
|
533
|
+
* (info-level rules can be observational). When set, the consumer's
|
|
534
|
+
* Admin UI can render a one-click apply (alpha.30+) or surface the
|
|
535
|
+
* before/after diff inline.
|
|
536
|
+
*/
|
|
537
|
+
interface AdvisorySuggestedFix {
|
|
538
|
+
type: 'config-change' | 'one-liner' | 'env-var' | 'manual';
|
|
539
|
+
/** File:line hint if kgauto can infer (reserved — alpha.30+). */
|
|
540
|
+
siteHint?: string;
|
|
541
|
+
before?: string;
|
|
542
|
+
after?: string;
|
|
543
|
+
docsLink?: string;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Per-(app_id, code) advisory rollup. The `id` is stable across polls
|
|
547
|
+
* until the rule auto-resolves and re-opens (a new firing after the 14d
|
|
548
|
+
* boundary advances `opened_at` → new id). Treat id-changes as
|
|
549
|
+
* intentional "fresh re-open" signals.
|
|
550
|
+
*
|
|
551
|
+
* Wire-shape from `actionable_advisories_v`. The transformer maps the
|
|
552
|
+
* view's snake_case columns to camelCase. See `feedback_typed_boundary_transformers.md`
|
|
553
|
+
* (L-118) for the rationale.
|
|
554
|
+
*/
|
|
555
|
+
interface ActionableAdvisory {
|
|
556
|
+
id: string;
|
|
557
|
+
rule: string;
|
|
558
|
+
severity: AdvisorySeverity;
|
|
559
|
+
openedAt: string;
|
|
560
|
+
lastObservedAt: string;
|
|
561
|
+
observationCount: number;
|
|
562
|
+
appliesTo: {
|
|
563
|
+
archetype?: IntentArchetypeName;
|
|
564
|
+
model?: string;
|
|
565
|
+
callSiteHint?: string;
|
|
566
|
+
};
|
|
567
|
+
message: string;
|
|
568
|
+
suggestedFix: AdvisorySuggestedFix | null;
|
|
569
|
+
/** Reserved — always `false` in alpha.29. alpha.30+ ships actual auto-apply. */
|
|
570
|
+
autoApplicable: boolean;
|
|
571
|
+
status: AdvisoryStatus;
|
|
572
|
+
resolvedAt?: string;
|
|
573
|
+
resolutionSource?: AdvisoryResolutionSource;
|
|
574
|
+
resolutionNote?: string;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Filter + transport for `getActionableAdvisories`. The brain JWT must
|
|
578
|
+
* carry an `app_id` claim matching `opts.appId` — RLS enforces tenant
|
|
579
|
+
* isolation on the underlying table, so a mismatch silently returns [].
|
|
580
|
+
*/
|
|
581
|
+
interface GetActionableAdvisoriesOptions {
|
|
582
|
+
appId: string;
|
|
583
|
+
/** Severity filter; if omitted, all severities are returned. */
|
|
584
|
+
severity?: AdvisorySeverity;
|
|
585
|
+
/** Status filter; defaults to 'open'. Pass 'all' for the full set. */
|
|
586
|
+
status?: 'open' | 'snoozed' | 'resolved' | 'all';
|
|
587
|
+
brainEndpoint: string;
|
|
588
|
+
brainJwt: string;
|
|
589
|
+
brainAnonKey: string;
|
|
590
|
+
fetch?: typeof fetch;
|
|
591
|
+
}
|
|
592
|
+
interface MarkAdvisoryResolvedOptions {
|
|
593
|
+
/** Stable id from a prior `getActionableAdvisories` call. */
|
|
594
|
+
id: string;
|
|
595
|
+
resolutionNote?: string;
|
|
596
|
+
brainEndpoint: string;
|
|
597
|
+
brainJwt: string;
|
|
598
|
+
brainAnonKey: string;
|
|
599
|
+
fetch?: typeof fetch;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Query the open advisory set for an app. Pulls from
|
|
603
|
+
* `actionable_advisories_v` (per-(app_id, code) rollup with stable ids
|
|
604
|
+
* + server-side auto-resolution).
|
|
605
|
+
*
|
|
606
|
+
* Default behavior (no status filter): returns only `status='open'`.
|
|
607
|
+
* Pass `status: 'all'` to see resolved + open together — useful for
|
|
608
|
+
* Admin UIs that show "recently fixed" badges.
|
|
609
|
+
*
|
|
610
|
+
* Fetch failures bubble out as thrown Errors. (`markAdvisoryResolved`
|
|
611
|
+
* uses the ok/reason envelope; this read path throws to match
|
|
612
|
+
* existing kgauto query semantics where the consumer can decide to
|
|
613
|
+
* retry or render an error state.)
|
|
614
|
+
*/
|
|
615
|
+
declare function getActionableAdvisories(opts: GetActionableAdvisoriesOptions): Promise<ActionableAdvisory[]>;
|
|
616
|
+
/**
|
|
617
|
+
* Mark an advisory as consumer-resolved.
|
|
618
|
+
*
|
|
619
|
+
* Lookup strategy:
|
|
620
|
+
* 1. Query `actionable_advisories_v?id=eq.<id>` to find the (app_id, code)
|
|
621
|
+
* tuple for this advisory.
|
|
622
|
+
* 2. PATCH the latest unresolved firing in `compile_outcome_advisories`
|
|
623
|
+
* matching that tuple via the underlying outcome's app_id.
|
|
624
|
+
*
|
|
625
|
+
* The (app_id, code) lookup is necessary because `compile_outcome_advisories`
|
|
626
|
+
* has no `app_id` column — it inherits scope via the FK to compile_outcomes.
|
|
627
|
+
* PostgREST cannot PATCH with a JOIN predicate, so the markAdvisoryResolved
|
|
628
|
+
* path is a two-step round-trip. The cost is one extra GET per resolve call;
|
|
629
|
+
* acceptable because marks are low-frequency operator actions, not per-call
|
|
630
|
+
* hot path.
|
|
631
|
+
*
|
|
632
|
+
* Idempotent re-marks: if the advisory is already resolved (no unresolved
|
|
633
|
+
* firings match), the PATCH affects zero rows and the call still returns
|
|
634
|
+
* `ok: true`. The function returns `ok: false` only on transport / auth /
|
|
635
|
+
* lookup failures.
|
|
636
|
+
*
|
|
637
|
+
* Returns ok/reason envelope (vs throwing) because consumer Admin UIs
|
|
638
|
+
* typically want to render the failure inline rather than crash.
|
|
639
|
+
*/
|
|
640
|
+
declare function markAdvisoryResolved(opts: MarkAdvisoryResolvedOptions): Promise<{
|
|
641
|
+
ok: true;
|
|
642
|
+
} | {
|
|
643
|
+
ok: false;
|
|
644
|
+
reason: string;
|
|
645
|
+
}>;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Archetype-cliff compatibility — alpha.28 (tt-intel-Cairn ratified).
|
|
649
|
+
*
|
|
650
|
+
* One question, one answer: *given this model and this intent, can it work
|
|
651
|
+
* — and if not, what adapter (if any) would make it work?*
|
|
652
|
+
*
|
|
653
|
+
* Replaces the silent-archetype-cliff failure mode where a consumer picks a
|
|
654
|
+
* model that's structurally wrong for the intent and kgauto compiles cleanly
|
|
655
|
+
* without surfacing the gap. The triggering incident: tt-intel shipped
|
|
656
|
+
* `deepseek-v4-pro` as the hunt default per a local spec; the kgauto coord
|
|
657
|
+
* doc said L-040 — V4 is structurally wrong for hunt (sequential tools).
|
|
658
|
+
* `archetypePerf.hunt = 4` was already in the profile data. The compiler
|
|
659
|
+
* stayed silent. This API + the matching advisor rule surfaces it.
|
|
660
|
+
*
|
|
661
|
+
* Pure function. No network. No brain query. No side effects. ~1ms.
|
|
662
|
+
*
|
|
663
|
+
* Consultation doc:
|
|
664
|
+
* command-center/advisory/kgauto/2026-05-21_archetype-cliff-advisor.md
|
|
665
|
+
*
|
|
666
|
+
* Refinements applied per tt-intel-Cairn ratification (2026-05-21):
|
|
667
|
+
* R1: every variant carries `archetypePerf: number` (raw score) — and
|
|
668
|
+
* `requires-adapter` adds `archetypePerfWithAdapter: number` so
|
|
669
|
+
* consumer policy can be expressed as "accept adapter only when score
|
|
670
|
+
* crosses some threshold WITH the adapter on."
|
|
671
|
+
* R2: every variant carries a plain-English `reason: string`. No internal
|
|
672
|
+
* jargon ("L-040", "archetypePerf=4") — the consumer chooses whether
|
|
673
|
+
* to render it as UI hint or operator-tooling tooltip.
|
|
674
|
+
* R3: `Adapter` is a CLOSED discriminated union, not `| string`. alpha.28
|
|
675
|
+
* ships ONE variant (`toolOrchestration: 'sequential'`). Future
|
|
676
|
+
* adapter parameters extend the union explicitly in named releases.
|
|
677
|
+
* NO escape hatch — the whole point is catching "I added a new
|
|
678
|
+
* adapter and forgot to update consumer policy" at compile time.
|
|
679
|
+
*/
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Minimum `archetypePerf[archetype]` score to count as `compatible` under
|
|
683
|
+
* Option A (default policy). Below this, a documented adapter is needed
|
|
684
|
+
* to lift the model above the floor; if no adapter exists, the model is
|
|
685
|
+
* rejected.
|
|
686
|
+
*
|
|
687
|
+
* Matches `QUALITY_FLOOR_FOR_RECOMMENDATION` in `advisor.ts` — kgauto's
|
|
688
|
+
* library-wide convention for "below this score, swap recommendations stop."
|
|
689
|
+
*/
|
|
690
|
+
declare const ARCHETYPE_FLOOR_DEFAULT = 6;
|
|
691
|
+
/**
|
|
692
|
+
* Absolute floor — below this, the cliff is too steep for ANY adapter to
|
|
693
|
+
* lift cleanly. Reserved under Option A (unused today; every below-floor
|
|
694
|
+
* case is gated by adapter availability). Would gate `reject` vs
|
|
695
|
+
* `requires-adapter` under a future Option B per consultation doc Q1.
|
|
696
|
+
*
|
|
697
|
+
* Exported so consumer-side policy can read it (e.g. "accept adapter only
|
|
698
|
+
* when archetypePerf >= ABSOLUTE_FLOOR + 1"). Not used internally by
|
|
699
|
+
* `getModelCompatibility` today — the gate is "does an adapter exist for
|
|
700
|
+
* this cliff?", not score-based.
|
|
701
|
+
*/
|
|
702
|
+
declare const ABSOLUTE_FLOOR = 4;
|
|
703
|
+
/**
|
|
704
|
+
* The intent the call is expressing — archetype + optional orchestration
|
|
705
|
+
* mode. Same shape as `ir.intent.archetype` + `ir.constraints.toolOrchestration`
|
|
706
|
+
* so a consumer can pass `{ archetype: ir.intent.archetype,
|
|
707
|
+
* toolOrchestration: ir.constraints?.toolOrchestration }` directly.
|
|
708
|
+
*/
|
|
709
|
+
interface CompatibilityIntent {
|
|
710
|
+
archetype: IntentArchetypeName;
|
|
711
|
+
toolOrchestration?: 'parallel' | 'sequential' | 'either';
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* `Adapter` — re-exported above. Canonical definition lives in `ir.ts` to
|
|
715
|
+
* avoid an import cycle (compatibility.ts → profiles.ts → ir.ts).
|
|
716
|
+
*
|
|
717
|
+
* **CLOSED discriminated union per R3.** Future adapter parameters extend
|
|
718
|
+
* the union explicitly in named alpha releases. No `| string` escape hatch
|
|
719
|
+
* — consumer policy code SHOULD write exhaustive `switch (adapter.parameter)`
|
|
720
|
+
* and rely on the compiler to flag "I added a new adapter parameter and
|
|
721
|
+
* forgot to update the consumer's policy."
|
|
722
|
+
*
|
|
723
|
+
* alpha.28 variants:
|
|
724
|
+
* - `{ parameter: 'toolOrchestration'; value: 'sequential'; consequence }`
|
|
725
|
+
* Lifts DeepSeek V4-family on `hunt` from sequential-tool cliff (L-040).
|
|
726
|
+
* The "consequence" plain-English-ifies the trade-off:
|
|
727
|
+
* "Tool calls run one at a time — slower but reliable."
|
|
728
|
+
*
|
|
729
|
+
* alpha.29+ likely additions (per tt-intel-Cairn priority list):
|
|
730
|
+
* - `{ parameter: 'parallelToolCalls'; value: false; consequence }`
|
|
731
|
+
* - `{ parameter: 'maxTools'; value: number; consequence }`
|
|
732
|
+
* - `{ parameter: 'thinkingBudget'; value: 0; consequence }`
|
|
733
|
+
*
|
|
734
|
+
* Each new variant lands in its own named release with the union extended
|
|
735
|
+
* in `ir.ts`. Consumers see the change at compile time.
|
|
736
|
+
*/
|
|
737
|
+
/**
|
|
738
|
+
* The compatibility verdict for a (model, intent) pair. Discriminated union
|
|
739
|
+
* on `status` — `compatible` | `requires-adapter` | `reject`.
|
|
740
|
+
*
|
|
741
|
+
* **Every variant carries `archetypePerf` (R1) + `reason` (R2):**
|
|
742
|
+
* - `archetypePerf` — the raw 0-10 score for (model, archetype). Lets
|
|
743
|
+
* consumers build their own thresholds without re-importing the profile
|
|
744
|
+
* registry.
|
|
745
|
+
* - `reason` — plain-English, consumer-renderable. NOT internal jargon
|
|
746
|
+
* like "L-040 cliff" or "archetypePerf=4". Examples in R2 ratification:
|
|
747
|
+
* - compatible: "Suited for hunt-style parallel discovery."
|
|
748
|
+
* - requires-adapter: "Best with sequential tool calls for hunt — slower but works."
|
|
749
|
+
* - reject: "Not suited for hunt — would underperform significantly."
|
|
750
|
+
*
|
|
751
|
+
* `requires-adapter` additionally carries:
|
|
752
|
+
* - `archetypePerfWithAdapter` — estimated post-adapter score. May be an
|
|
753
|
+
* estimate (we don't measure post-adapter scores yet); kgauto's prior is
|
|
754
|
+
* "adapter lifts to ARCHETYPE_FLOOR_DEFAULT + 1" unless brain-evidenced.
|
|
755
|
+
* - `adapter` — the closed-union variant describing the structural change.
|
|
756
|
+
*
|
|
757
|
+
* Backward-compat: an unknown model returns `reject` with a "model not
|
|
758
|
+
* registered" reason; callers never throw. Unknown archetype is impossible
|
|
759
|
+
* at the type level (`IntentArchetypeName` is a closed union).
|
|
760
|
+
*/
|
|
761
|
+
type ModelCompatibility = {
|
|
762
|
+
status: 'compatible';
|
|
763
|
+
reason: string;
|
|
764
|
+
archetypePerf: number;
|
|
765
|
+
} | {
|
|
766
|
+
status: 'requires-adapter';
|
|
767
|
+
reason: string;
|
|
768
|
+
archetypePerf: number;
|
|
769
|
+
archetypePerfWithAdapter: number;
|
|
770
|
+
adapter: Adapter;
|
|
771
|
+
} | {
|
|
772
|
+
status: 'reject';
|
|
773
|
+
reason: string;
|
|
774
|
+
archetypePerf: number;
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* Compatibility query — *does this model fit this intent, and if not,
|
|
778
|
+
* what would?*
|
|
779
|
+
*
|
|
780
|
+
* **Rules (Option A from consultation doc Q1):**
|
|
781
|
+
* 1. If model is unregistered → `reject` with "model not registered" reason.
|
|
782
|
+
* 2. If intent provides `toolOrchestration: 'sequential'` AND that adapter
|
|
783
|
+
* silences the cliff (because the cliff IS the sequential-tool one)
|
|
784
|
+
* → return `compatible` with raw score (NOT the post-adapter estimate
|
|
785
|
+
* — caller already paid the adapter, score reflects reality).
|
|
786
|
+
* 3. If raw `archetypePerf[archetype] >= ARCHETYPE_FLOOR_DEFAULT`
|
|
787
|
+
* → `compatible`.
|
|
788
|
+
* 4. If below floor BUT a documented adapter exists that lifts to floor
|
|
789
|
+
* → `requires-adapter` with adapter + estimated post-adapter score.
|
|
790
|
+
* 5. If below floor AND no adapter exists → `reject`.
|
|
791
|
+
*
|
|
792
|
+
* **Pure function.** Deterministic for `(modelId, intent)`. No I/O.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* import { getModelCompatibility } from '@warmdrift/kgauto-compiler';
|
|
797
|
+
*
|
|
798
|
+
* const c = getModelCompatibility('deepseek-v4-pro', { archetype: 'hunt' });
|
|
799
|
+
* // → { status: 'requires-adapter',
|
|
800
|
+
* // reason: 'Best with sequential tool calls for hunt — slower but works.',
|
|
801
|
+
* // archetypePerf: 4,
|
|
802
|
+
* // archetypePerfWithAdapter: 7,
|
|
803
|
+
* // adapter: {
|
|
804
|
+
* // parameter: 'toolOrchestration',
|
|
805
|
+
* // value: 'sequential',
|
|
806
|
+
* // consequence: 'Tool calls run one at a time...'
|
|
807
|
+
* // } }
|
|
808
|
+
*
|
|
809
|
+
* // With the adapter already declared:
|
|
810
|
+
* const c2 = getModelCompatibility('deepseek-v4-pro', {
|
|
811
|
+
* archetype: 'hunt',
|
|
812
|
+
* toolOrchestration: 'sequential',
|
|
813
|
+
* });
|
|
814
|
+
* // → { status: 'compatible',
|
|
815
|
+
* // reason: 'Suited for hunt with sequential tool calls.',
|
|
816
|
+
* // archetypePerf: 4 }
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
declare function getModelCompatibility(modelId: string, intent: CompatibilityIntent): ModelCompatibility;
|
|
820
|
+
|
|
361
821
|
/**
|
|
362
822
|
* alpha.22 — sync introspection: is brain-query mode active for a given
|
|
363
823
|
* table? Used by the advisor (`model-stale-evidence` rule) to decide
|
|
@@ -943,4 +1403,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
|
943
1403
|
*/
|
|
944
1404
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
945
1405
|
|
|
946
|
-
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
1406
|
+
export { ABSOLUTE_FLOOR, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type SupportedProvider, TRANSLATOR_FLOOR, applySectionRewrites, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|