@warmdrift/kgauto-compiler 2.0.0-alpha.3 → 2.0.0-alpha.30

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 CHANGED
@@ -1,4 +1,4 @@
1
- # @warmdrift/kgauto-compiler — v2.0.0-alpha.3
1
+ # @warmdrift/kgauto-compiler — v2.0.0-alpha.6
2
2
 
3
3
  > Prompt compiler + central learning brain for multi-model AI apps.
4
4
  > **Swap models without rewriting prompts.**
@@ -18,8 +18,8 @@ mutations.
18
18
  - **Package:** alpha — coexists with v1 (`@warmdrift/kgauto@1.2.0`) under
19
19
  the temporary name `@warmdrift/kgauto-compiler`. Renames to v2 final once
20
20
  v1 is fully retired from production.
21
- - **Tests:** 132/132 passing
22
- - **Build:** clean (43KB ESM, 60KB CJS)
21
+ - **Tests:** 201/201 passing
22
+ - **Build:** clean (47KB ESM, 68KB CJS)
23
23
  - **Brain:** schema ready (see `brain/migrations/001_initial_schema.sql`);
24
24
  awaiting dedicated Supabase provisioning.
25
25
  - **Mutation engine:** v2.1 (after enough outcome data accumulates).
@@ -89,6 +89,48 @@ await record({
89
89
  });
90
90
  ```
91
91
 
92
+ ## Structured advisories API (alpha.29+)
93
+
94
+ kgauto's compile-time advisories (`caching-off-on-claude`, `tool-bloat`,
95
+ `archetype-perf-floor-breach`, etc.) used to vanish after the consumer read
96
+ the compile result. alpha.29 ships a structured query + resolution surface
97
+ so Admin UIs can render "what's open right now?" without log-scraping.
98
+
99
+ ```ts
100
+ import {
101
+ getActionableAdvisories,
102
+ markAdvisoryResolved,
103
+ } from '@warmdrift/kgauto-compiler';
104
+
105
+ // Query open advisories for this app
106
+ const open = await getActionableAdvisories({
107
+ appId: 'playbacksam',
108
+ brainEndpoint: process.env.KGAUTO_BRAIN_ENDPOINT!,
109
+ brainJwt: process.env.KGAUTO_BRAIN_JWT!,
110
+ brainAnonKey: process.env.KGAUTO_BRAIN_ANON_KEY!,
111
+ });
112
+
113
+ for (const a of open) {
114
+ console.log(`[${a.severity}] ${a.rule} — ${a.observationCount} firings since ${a.openedAt}`);
115
+ console.log(` ${a.message}`);
116
+ if (a.suggestedFix?.docsLink) console.log(` ↳ ${a.suggestedFix.docsLink}`);
117
+ }
118
+
119
+ // After the operator fixes the issue, mark it resolved:
120
+ const r = await markAdvisoryResolved({
121
+ id: open[0].id,
122
+ resolutionNote: 'wired historyCachePolicy in compile() — PR #99',
123
+ brainEndpoint: process.env.KGAUTO_BRAIN_ENDPOINT!,
124
+ brainJwt: process.env.KGAUTO_BRAIN_JWT!,
125
+ brainAnonKey: process.env.KGAUTO_BRAIN_ANON_KEY!,
126
+ });
127
+ if (!r.ok) console.error(r.reason);
128
+ ```
129
+
130
+ The view enforces server-side auto-resolution: advisories with no firing
131
+ in the last 14 days flip to `status='resolved'` automatically; the next
132
+ firing reopens the rule with a fresh stable `id`.
133
+
92
134
  ## Architecture
93
135
 
94
136
  ```
@@ -154,6 +196,48 @@ The 5 prod empty-responses in tt-intelligence's `gemini-2.5-flash` dashboard
154
196
  calls? v2 catches those automatically — `expectedShortOutput` constraint plus
155
197
  the `force_thinking_budget_zero` cliff guard.
156
198
 
199
+ ## Tools
200
+
201
+ Tools are first-class IR fields. The compiler's tool-relevance pass drops
202
+ tools that don't apply to the current intent before lowering — saves
203
+ context budget on every call.
204
+
205
+ ```ts
206
+ const tools: ToolDefinition[] = [
207
+ {
208
+ name: 'web_search',
209
+ description: 'Search the public web',
210
+ parameters: { type: 'object', properties: { q: { type: 'string' } } },
211
+ relevanceByIntent: {
212
+ ask: 0.9, // primary tool for ask
213
+ hunt: 0.9,
214
+ classify: 0.0, // never useful for classification
215
+ summarize: 0.0,
216
+ extract: 0.1,
217
+ },
218
+ },
219
+ // ...
220
+ ];
221
+ ```
222
+
223
+ Each tool declares per-intent relevance scores 0..1. The pass keeps tools
224
+ where `relevanceByIntent[currentIntent] >= toolRelevanceThreshold` (default
225
+ `0.2`). Missing entries default to neutral (`0.5`) — kept by default. Set
226
+ explicit `0.0` to hard-exclude.
227
+
228
+ Tool definitions eat ~350 tokens of context per tool (L-051), so trimming
229
+ matters: 12 declared tools, only 3 relevant → 9 × 350 = 3150 tokens
230
+ recovered per call.
231
+
232
+ The `tool-bloat` advisory (alpha.6) fires when more than 10 tools survive
233
+ the relevance pass on a short-output archetype (`classify`, `extract`,
234
+ `summarize`, `transform`, `critique`) — those archetypes typically use
235
+ ≤3 tools, so a kept-count >10 indicates either missing `relevanceByIntent`
236
+ or scores set too generously.
237
+
238
+ DeepSeek profiles cap tools to 1 (sequential-only). Other providers
239
+ inherit the count from the IR after the relevance pass.
240
+
157
241
  ## Brain provisioning
158
242
 
159
243
  1. Create a NEW Supabase project (suggested name: `kgauto-brain`)