@titan-design/session-analytics 0.4.1 → 0.6.0
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 +130 -3
- package/dist/index.d.ts +1316 -4
- package/dist/index.js +1527 -52
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -110,8 +110,295 @@ interface ReportWindow {
|
|
|
110
110
|
since: string | null;
|
|
111
111
|
until: string | null;
|
|
112
112
|
}
|
|
113
|
+
/** An arrival that opens a wake episode: a turn-start record or a mid-loop `queued_command` delivery. */
|
|
114
|
+
interface WakeEventRow {
|
|
115
|
+
key: string;
|
|
116
|
+
sessionId: string;
|
|
117
|
+
cause: string;
|
|
118
|
+
delivery: string;
|
|
119
|
+
fromName: string | null;
|
|
120
|
+
/** The same `msg_id` reached more than one session. */
|
|
121
|
+
broadcast: boolean;
|
|
122
|
+
}
|
|
123
|
+
/** One agent-chat identity: the name a session carries and how it came to carry it. */
|
|
124
|
+
interface AgentNameRow {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
agentName: string;
|
|
127
|
+
originKind: string | null;
|
|
128
|
+
profile: string | null;
|
|
129
|
+
}
|
|
113
130
|
|
|
114
|
-
declare const
|
|
131
|
+
declare const ACTION_CLASSES: readonly ["journal-write", "pr-ci-check", "merge", "dispatch", "retire", "task-state", "budget-status", "scorer", "message", "read-investigate", "text-only", "other"];
|
|
132
|
+
type ActionClass = (typeof ACTION_CLASSES)[number];
|
|
133
|
+
/** One tool call of a request, with the signals session-read extracted for it. */
|
|
134
|
+
interface ActionCall {
|
|
135
|
+
tool: string;
|
|
136
|
+
/** Command heads of a Bash call, such as `gh pr checks`. */
|
|
137
|
+
heads?: readonly string[];
|
|
138
|
+
readPaths?: readonly string[];
|
|
139
|
+
writePaths?: readonly string[];
|
|
140
|
+
}
|
|
141
|
+
/** A rule matches a call when every field it sets matches; list order is the precedence. */
|
|
142
|
+
interface ActionRule {
|
|
143
|
+
cls: ActionClass;
|
|
144
|
+
tool?: RegExp;
|
|
145
|
+
head?: RegExp;
|
|
146
|
+
readPath?: RegExp;
|
|
147
|
+
writePath?: RegExp;
|
|
148
|
+
}
|
|
149
|
+
declare const DEFAULT_ACTION_RULES: readonly ActionRule[];
|
|
150
|
+
/** Dispatch is judgment about what to hand out, so it stays out of the mechanical list. */
|
|
151
|
+
declare const DEFAULT_MECHANICAL_CLASSES: readonly ActionClass[];
|
|
152
|
+
declare function classifyRequest(calls: readonly ActionCall[], rules?: readonly ActionRule[]): ActionClass;
|
|
153
|
+
|
|
154
|
+
/** A dispatch or a send; with any file write, the first such request ends a session's boot. */
|
|
155
|
+
declare const BOOT_TOOL: RegExp;
|
|
156
|
+
/** The charter's `teleport_k` and `retire_k` at the time of the TP-499 plan; callers pass their own. */
|
|
157
|
+
declare const DEFAULT_CONFIGURED_K: readonly number[];
|
|
158
|
+
declare const DEFAULT_K_SWEEP: {
|
|
159
|
+
readonly fromK: 20000;
|
|
160
|
+
readonly toK: 1000000;
|
|
161
|
+
readonly stepK: 5000;
|
|
162
|
+
};
|
|
163
|
+
declare const DEFAULT_REVIEWER_ROLE = "worker:reviewer";
|
|
164
|
+
declare const DEFAULT_STANDING_ROLE = "worker:standing_peer";
|
|
165
|
+
declare const DEFAULT_REVIEWER_PRS = 10;
|
|
166
|
+
/** The broker logs this when a seat starts handing over; `from` is the outgoing agent id. */
|
|
167
|
+
declare const TELEPORT_EVENT = "teleport_started";
|
|
168
|
+
declare const sweepResultSchema: z.ZodObject<{
|
|
169
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
170
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
171
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
172
|
+
k: z.ZodNumber;
|
|
173
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
174
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
175
|
+
}, z.core.$strip>>;
|
|
176
|
+
}, z.core.$strip>;
|
|
177
|
+
declare const paramsSchema: z.ZodObject<{
|
|
178
|
+
bootCostUsd: z.ZodNumber;
|
|
179
|
+
bootFill: z.ZodNumber;
|
|
180
|
+
growthPerRequest: z.ZodNumber;
|
|
181
|
+
readPricePerMTok: z.ZodNumber;
|
|
182
|
+
}, z.core.$strip>;
|
|
183
|
+
declare const sessionSchema: z.ZodObject<{
|
|
184
|
+
bootCostUsd: z.ZodNumber;
|
|
185
|
+
bootFill: z.ZodNumber;
|
|
186
|
+
growthPerRequest: z.ZodNumber;
|
|
187
|
+
readPricePerMTok: z.ZodNumber;
|
|
188
|
+
sessionId: z.ZodString;
|
|
189
|
+
role: z.ZodString;
|
|
190
|
+
model: z.ZodString;
|
|
191
|
+
requests: z.ZodNumber;
|
|
192
|
+
bootRequests: z.ZodNumber;
|
|
193
|
+
exitFill: z.ZodNumber;
|
|
194
|
+
lastTs: z.ZodString;
|
|
195
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
196
|
+
}, z.core.$strip>;
|
|
197
|
+
declare const cohortSchema: z.ZodObject<{
|
|
198
|
+
bootCostUsd: z.ZodNumber;
|
|
199
|
+
bootFill: z.ZodNumber;
|
|
200
|
+
growthPerRequest: z.ZodNumber;
|
|
201
|
+
readPricePerMTok: z.ZodNumber;
|
|
202
|
+
halfBoot: z.ZodObject<{
|
|
203
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
204
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
205
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
206
|
+
k: z.ZodNumber;
|
|
207
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
208
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
209
|
+
}, z.core.$strip>>;
|
|
210
|
+
}, z.core.$strip>;
|
|
211
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
212
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
213
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
214
|
+
k: z.ZodNumber;
|
|
215
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
216
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
217
|
+
}, z.core.$strip>>;
|
|
218
|
+
role: z.ZodString;
|
|
219
|
+
model: z.ZodString;
|
|
220
|
+
sessions: z.ZodNumber;
|
|
221
|
+
}, z.core.$strip>;
|
|
222
|
+
declare const teleportSchema: z.ZodObject<{
|
|
223
|
+
ts: z.ZodString;
|
|
224
|
+
name: z.ZodNullable<z.ZodString>;
|
|
225
|
+
sessionId: z.ZodString;
|
|
226
|
+
role: z.ZodString;
|
|
227
|
+
model: z.ZodString;
|
|
228
|
+
exitFill: z.ZodNumber;
|
|
229
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
230
|
+
overConfigured: z.ZodArray<z.ZodObject<{
|
|
231
|
+
k: z.ZodNumber;
|
|
232
|
+
over: z.ZodNumber;
|
|
233
|
+
}, z.core.$strip>>;
|
|
234
|
+
}, z.core.$strip>;
|
|
235
|
+
/** `requestsFrom` when the report has no reviewer session at all, so requests per PR is 0. */
|
|
236
|
+
declare const POOLED_REVIEWERS = "pooled";
|
|
237
|
+
declare const reviewerSchema: z.ZodObject<{
|
|
238
|
+
prs: z.ZodNumber;
|
|
239
|
+
fresh: z.ZodArray<z.ZodObject<{
|
|
240
|
+
role: z.ZodString;
|
|
241
|
+
model: z.ZodString;
|
|
242
|
+
sessions: z.ZodNumber;
|
|
243
|
+
requestsPerPr: z.ZodNumber;
|
|
244
|
+
requestsFrom: z.ZodString;
|
|
245
|
+
requestsFromSessions: z.ZodNumber;
|
|
246
|
+
costUsd: z.ZodNumber;
|
|
247
|
+
}, z.core.$strip>>;
|
|
248
|
+
standing: z.ZodArray<z.ZodObject<{
|
|
249
|
+
role: z.ZodString;
|
|
250
|
+
model: z.ZodString;
|
|
251
|
+
sessions: z.ZodNumber;
|
|
252
|
+
requestsPerPr: z.ZodNumber;
|
|
253
|
+
requestsFrom: z.ZodString;
|
|
254
|
+
requestsFromSessions: z.ZodNumber;
|
|
255
|
+
costUsd: z.ZodNumber;
|
|
256
|
+
}, z.core.$strip>>;
|
|
257
|
+
}, z.core.$strip>;
|
|
258
|
+
declare const handoffThresholdSchema: z.ZodObject<{
|
|
259
|
+
configuredK: z.ZodArray<z.ZodNumber>;
|
|
260
|
+
sweep: z.ZodObject<{
|
|
261
|
+
fromK: z.ZodNumber;
|
|
262
|
+
toK: z.ZodNumber;
|
|
263
|
+
stepK: z.ZodNumber;
|
|
264
|
+
}, z.core.$strip>;
|
|
265
|
+
cohorts: z.ZodArray<z.ZodObject<{
|
|
266
|
+
bootCostUsd: z.ZodNumber;
|
|
267
|
+
bootFill: z.ZodNumber;
|
|
268
|
+
growthPerRequest: z.ZodNumber;
|
|
269
|
+
readPricePerMTok: z.ZodNumber;
|
|
270
|
+
halfBoot: z.ZodObject<{
|
|
271
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
272
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
273
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
274
|
+
k: z.ZodNumber;
|
|
275
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
276
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
277
|
+
}, z.core.$strip>>;
|
|
278
|
+
}, z.core.$strip>;
|
|
279
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
280
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
281
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
282
|
+
k: z.ZodNumber;
|
|
283
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
284
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
285
|
+
}, z.core.$strip>>;
|
|
286
|
+
role: z.ZodString;
|
|
287
|
+
model: z.ZodString;
|
|
288
|
+
sessions: z.ZodNumber;
|
|
289
|
+
}, z.core.$strip>>;
|
|
290
|
+
sessions: z.ZodArray<z.ZodObject<{
|
|
291
|
+
bootCostUsd: z.ZodNumber;
|
|
292
|
+
bootFill: z.ZodNumber;
|
|
293
|
+
growthPerRequest: z.ZodNumber;
|
|
294
|
+
readPricePerMTok: z.ZodNumber;
|
|
295
|
+
sessionId: z.ZodString;
|
|
296
|
+
role: z.ZodString;
|
|
297
|
+
model: z.ZodString;
|
|
298
|
+
requests: z.ZodNumber;
|
|
299
|
+
bootRequests: z.ZodNumber;
|
|
300
|
+
exitFill: z.ZodNumber;
|
|
301
|
+
lastTs: z.ZodString;
|
|
302
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
303
|
+
}, z.core.$strip>>;
|
|
304
|
+
unbootedSessions: z.ZodNumber;
|
|
305
|
+
teleports: z.ZodArray<z.ZodObject<{
|
|
306
|
+
ts: z.ZodString;
|
|
307
|
+
name: z.ZodNullable<z.ZodString>;
|
|
308
|
+
sessionId: z.ZodString;
|
|
309
|
+
role: z.ZodString;
|
|
310
|
+
model: z.ZodString;
|
|
311
|
+
exitFill: z.ZodNumber;
|
|
312
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
313
|
+
overConfigured: z.ZodArray<z.ZodObject<{
|
|
314
|
+
k: z.ZodNumber;
|
|
315
|
+
over: z.ZodNumber;
|
|
316
|
+
}, z.core.$strip>>;
|
|
317
|
+
}, z.core.$strip>>;
|
|
318
|
+
unmatchedTeleports: z.ZodNumber;
|
|
319
|
+
reviewers: z.ZodObject<{
|
|
320
|
+
prs: z.ZodNumber;
|
|
321
|
+
fresh: z.ZodArray<z.ZodObject<{
|
|
322
|
+
role: z.ZodString;
|
|
323
|
+
model: z.ZodString;
|
|
324
|
+
sessions: z.ZodNumber;
|
|
325
|
+
requestsPerPr: z.ZodNumber;
|
|
326
|
+
requestsFrom: z.ZodString;
|
|
327
|
+
requestsFromSessions: z.ZodNumber;
|
|
328
|
+
costUsd: z.ZodNumber;
|
|
329
|
+
}, z.core.$strip>>;
|
|
330
|
+
standing: z.ZodArray<z.ZodObject<{
|
|
331
|
+
role: z.ZodString;
|
|
332
|
+
model: z.ZodString;
|
|
333
|
+
sessions: z.ZodNumber;
|
|
334
|
+
requestsPerPr: z.ZodNumber;
|
|
335
|
+
requestsFrom: z.ZodString;
|
|
336
|
+
requestsFromSessions: z.ZodNumber;
|
|
337
|
+
costUsd: z.ZodNumber;
|
|
338
|
+
}, z.core.$strip>>;
|
|
339
|
+
}, z.core.$strip>;
|
|
340
|
+
}, z.core.$strip>;
|
|
341
|
+
type HandoffThreshold = z.infer<typeof handoffThresholdSchema>;
|
|
342
|
+
type HandoffCohort = z.infer<typeof cohortSchema>;
|
|
343
|
+
type HandoffSession = z.infer<typeof sessionSchema>;
|
|
344
|
+
type HandoffTeleport = z.infer<typeof teleportSchema>;
|
|
345
|
+
type ReviewerComparison = z.infer<typeof reviewerSchema>;
|
|
346
|
+
type CycleParams = z.infer<typeof paramsSchema>;
|
|
347
|
+
type KSweep = HandoffThreshold["sweep"];
|
|
348
|
+
/** One main-thread request as the handoff model needs it. */
|
|
349
|
+
interface HandoffRequestRow {
|
|
350
|
+
sessionId: string;
|
|
351
|
+
role: string;
|
|
352
|
+
model: string;
|
|
353
|
+
ts: string;
|
|
354
|
+
/** Tokens in context: input, cache reads and cache writes. */
|
|
355
|
+
fill: number;
|
|
356
|
+
tokens: RequestTokens;
|
|
357
|
+
bootAction: boolean;
|
|
358
|
+
}
|
|
359
|
+
interface TeleportEvent {
|
|
360
|
+
ts: string;
|
|
361
|
+
name: string | null;
|
|
362
|
+
fromAgentId: string;
|
|
363
|
+
}
|
|
364
|
+
interface HandoffOptions {
|
|
365
|
+
configuredK?: readonly number[];
|
|
366
|
+
sweep?: KSweep;
|
|
367
|
+
reviewerRole?: string;
|
|
368
|
+
/** The role whose boot, fill and growth price a reviewer that stays up across PRs. */
|
|
369
|
+
standingRole?: string;
|
|
370
|
+
reviewerPrs?: number;
|
|
371
|
+
/** Prices every request and the read rate; the package table, not the graph's stored one. */
|
|
372
|
+
prices?: readonly PriceRow[];
|
|
373
|
+
}
|
|
374
|
+
declare function isBootAction(calls: readonly ActionCall[]): boolean;
|
|
375
|
+
/** Broker log lines to teleport starts; any other line, or one that is not JSON, is skipped. */
|
|
376
|
+
declare function parseTeleportEvents(lines: Iterable<string>): TeleportEvent[];
|
|
377
|
+
/** One cycle boots to f0 and grows g per request up to K: boot/n + read price x mean fill, with n = (K - f0) / g. */
|
|
378
|
+
declare function costPerRequest(params: CycleParams, k: number): number | null;
|
|
379
|
+
/** The cheapest K on the sweep grid, then each configured K against it. */
|
|
380
|
+
declare function sweepK(params: CycleParams, sweep: KSweep, configuredK: readonly number[]): z.infer<typeof sweepResultSchema>;
|
|
381
|
+
/** Per role and model: boot cost and fill, fill growth and read price from the requests, then the K sweep. */
|
|
382
|
+
declare function handoffThreshold(rows: readonly HandoffRequestRow[], teleports: readonly TeleportEvent[], agentSessions: ReadonlyMap<string, readonly string[]>, options?: HandoffOptions): HandoffThreshold;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Narrows a report to some sessions. Every field left out matches all, and fields combine with AND.
|
|
386
|
+
* Compactions and coverage stay window-wide: the graph does not key them to a request.
|
|
387
|
+
*/
|
|
388
|
+
interface ReportScope {
|
|
389
|
+
sessionIds?: readonly string[];
|
|
390
|
+
/** Keeps sessions whose agent-chat agent name starts with it. */
|
|
391
|
+
agentPrefix?: string;
|
|
392
|
+
/** Report roles, as `byRole` names them. */
|
|
393
|
+
roles?: readonly string[];
|
|
394
|
+
}
|
|
395
|
+
/** A predicate over a request's session and role; with no scope every request passes. */
|
|
396
|
+
declare function scopeFilter(db: Db, scope?: ReportScope): (row: {
|
|
397
|
+
sessionId: string;
|
|
398
|
+
role: string;
|
|
399
|
+
}) => boolean;
|
|
400
|
+
|
|
401
|
+
declare const bucketSchema$1: z.ZodObject<{
|
|
115
402
|
key: z.ZodString;
|
|
116
403
|
requests: z.ZodNumber;
|
|
117
404
|
sessions: z.ZodNumber;
|
|
@@ -139,11 +426,11 @@ declare const costReportSchema: z.ZodObject<{
|
|
|
139
426
|
}, z.core.$strip>;
|
|
140
427
|
byTokenClass: z.ZodArray<z.ZodObject<{
|
|
141
428
|
tokenClass: z.ZodEnum<{
|
|
429
|
+
output: "output";
|
|
142
430
|
input: "input";
|
|
143
431
|
cache_read: "cache_read";
|
|
144
432
|
cache_write_5m: "cache_write_5m";
|
|
145
433
|
cache_write_1h: "cache_write_1h";
|
|
146
|
-
output: "output";
|
|
147
434
|
}>;
|
|
148
435
|
tokens: z.ZodNumber;
|
|
149
436
|
costUsd: z.ZodNumber;
|
|
@@ -172,6 +459,38 @@ declare const costReportSchema: z.ZodObject<{
|
|
|
172
459
|
sessions: z.ZodNumber;
|
|
173
460
|
costUsd: z.ZodNumber;
|
|
174
461
|
}, z.core.$strip>>;
|
|
462
|
+
byAction: z.ZodArray<z.ZodObject<{
|
|
463
|
+
role: z.ZodString;
|
|
464
|
+
buckets: z.ZodArray<z.ZodObject<{
|
|
465
|
+
key: z.ZodString;
|
|
466
|
+
requests: z.ZodNumber;
|
|
467
|
+
sessions: z.ZodNumber;
|
|
468
|
+
costUsd: z.ZodNumber;
|
|
469
|
+
}, z.core.$strip>>;
|
|
470
|
+
}, z.core.$strip>>;
|
|
471
|
+
mechanicalShare: z.ZodObject<{
|
|
472
|
+
classes: z.ZodArray<z.ZodEnum<{
|
|
473
|
+
"journal-write": "journal-write";
|
|
474
|
+
"pr-ci-check": "pr-ci-check";
|
|
475
|
+
merge: "merge";
|
|
476
|
+
dispatch: "dispatch";
|
|
477
|
+
retire: "retire";
|
|
478
|
+
"task-state": "task-state";
|
|
479
|
+
"budget-status": "budget-status";
|
|
480
|
+
scorer: "scorer";
|
|
481
|
+
message: "message";
|
|
482
|
+
"read-investigate": "read-investigate";
|
|
483
|
+
"text-only": "text-only";
|
|
484
|
+
other: "other";
|
|
485
|
+
}>>;
|
|
486
|
+
costUsd: z.ZodNumber;
|
|
487
|
+
share: z.ZodNumber;
|
|
488
|
+
byRole: z.ZodArray<z.ZodObject<{
|
|
489
|
+
role: z.ZodString;
|
|
490
|
+
costUsd: z.ZodNumber;
|
|
491
|
+
share: z.ZodNumber;
|
|
492
|
+
}, z.core.$strip>>;
|
|
493
|
+
}, z.core.$strip>;
|
|
175
494
|
byEpisodeCount: z.ZodArray<z.ZodObject<{
|
|
176
495
|
key: z.ZodString;
|
|
177
496
|
requests: z.ZodNumber;
|
|
@@ -206,6 +525,156 @@ declare const costReportSchema: z.ZodObject<{
|
|
|
206
525
|
midLoopCostUsd: z.ZodNumber;
|
|
207
526
|
}, z.core.$strip>>;
|
|
208
527
|
}, z.core.$strip>>;
|
|
528
|
+
wakeEpisodes: z.ZodObject<{
|
|
529
|
+
unattributed: z.ZodObject<{
|
|
530
|
+
requests: z.ZodNumber;
|
|
531
|
+
costUsd: z.ZodNumber;
|
|
532
|
+
}, z.core.$strip>;
|
|
533
|
+
byCause: z.ZodArray<z.ZodObject<{
|
|
534
|
+
midLoopEpisodes: z.ZodNumber;
|
|
535
|
+
requestsPerEpisode: z.ZodNumber;
|
|
536
|
+
costPerEpisode: z.ZodNumber;
|
|
537
|
+
byFrom: z.ZodArray<z.ZodObject<{
|
|
538
|
+
episodes: z.ZodNumber;
|
|
539
|
+
requests: z.ZodNumber;
|
|
540
|
+
costUsd: z.ZodNumber;
|
|
541
|
+
noActionEpisodes: z.ZodNumber;
|
|
542
|
+
noActionCostUsd: z.ZodNumber;
|
|
543
|
+
key: z.ZodEnum<{
|
|
544
|
+
broadcast: "broadcast";
|
|
545
|
+
seat: "seat";
|
|
546
|
+
agent: "agent";
|
|
547
|
+
broker: "broker";
|
|
548
|
+
none: "none";
|
|
549
|
+
}>;
|
|
550
|
+
}, z.core.$strip>>;
|
|
551
|
+
episodes: z.ZodNumber;
|
|
552
|
+
requests: z.ZodNumber;
|
|
553
|
+
costUsd: z.ZodNumber;
|
|
554
|
+
noActionEpisodes: z.ZodNumber;
|
|
555
|
+
noActionCostUsd: z.ZodNumber;
|
|
556
|
+
key: z.ZodString;
|
|
557
|
+
}, z.core.$strip>>;
|
|
558
|
+
pairs: z.ZodArray<z.ZodObject<{
|
|
559
|
+
episodes: z.ZodNumber;
|
|
560
|
+
requests: z.ZodNumber;
|
|
561
|
+
costUsd: z.ZodNumber;
|
|
562
|
+
noActionEpisodes: z.ZodNumber;
|
|
563
|
+
noActionCostUsd: z.ZodNumber;
|
|
564
|
+
from: z.ZodString;
|
|
565
|
+
fromKind: z.ZodEnum<{
|
|
566
|
+
broadcast: "broadcast";
|
|
567
|
+
seat: "seat";
|
|
568
|
+
agent: "agent";
|
|
569
|
+
broker: "broker";
|
|
570
|
+
none: "none";
|
|
571
|
+
}>;
|
|
572
|
+
to: z.ZodString;
|
|
573
|
+
}, z.core.$strip>>;
|
|
574
|
+
episodes: z.ZodNumber;
|
|
575
|
+
requests: z.ZodNumber;
|
|
576
|
+
costUsd: z.ZodNumber;
|
|
577
|
+
noActionEpisodes: z.ZodNumber;
|
|
578
|
+
noActionCostUsd: z.ZodNumber;
|
|
579
|
+
roles: z.ZodArray<z.ZodString>;
|
|
580
|
+
noActionClasses: z.ZodArray<z.ZodEnum<{
|
|
581
|
+
"journal-write": "journal-write";
|
|
582
|
+
"pr-ci-check": "pr-ci-check";
|
|
583
|
+
merge: "merge";
|
|
584
|
+
dispatch: "dispatch";
|
|
585
|
+
retire: "retire";
|
|
586
|
+
"task-state": "task-state";
|
|
587
|
+
"budget-status": "budget-status";
|
|
588
|
+
scorer: "scorer";
|
|
589
|
+
message: "message";
|
|
590
|
+
"read-investigate": "read-investigate";
|
|
591
|
+
"text-only": "text-only";
|
|
592
|
+
other: "other";
|
|
593
|
+
}>>;
|
|
594
|
+
}, z.core.$strip>;
|
|
595
|
+
handoffThreshold: z.ZodObject<{
|
|
596
|
+
configuredK: z.ZodArray<z.ZodNumber>;
|
|
597
|
+
sweep: z.ZodObject<{
|
|
598
|
+
fromK: z.ZodNumber;
|
|
599
|
+
toK: z.ZodNumber;
|
|
600
|
+
stepK: z.ZodNumber;
|
|
601
|
+
}, z.core.$strip>;
|
|
602
|
+
cohorts: z.ZodArray<z.ZodObject<{
|
|
603
|
+
bootCostUsd: z.ZodNumber;
|
|
604
|
+
bootFill: z.ZodNumber;
|
|
605
|
+
growthPerRequest: z.ZodNumber;
|
|
606
|
+
readPricePerMTok: z.ZodNumber;
|
|
607
|
+
halfBoot: z.ZodObject<{
|
|
608
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
609
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
610
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
611
|
+
k: z.ZodNumber;
|
|
612
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
613
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
614
|
+
}, z.core.$strip>>;
|
|
615
|
+
}, z.core.$strip>;
|
|
616
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
617
|
+
bestCostPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
618
|
+
atConfigured: z.ZodArray<z.ZodObject<{
|
|
619
|
+
k: z.ZodNumber;
|
|
620
|
+
costPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
621
|
+
deltaPerRequest: z.ZodNullable<z.ZodNumber>;
|
|
622
|
+
}, z.core.$strip>>;
|
|
623
|
+
role: z.ZodString;
|
|
624
|
+
model: z.ZodString;
|
|
625
|
+
sessions: z.ZodNumber;
|
|
626
|
+
}, z.core.$strip>>;
|
|
627
|
+
sessions: z.ZodArray<z.ZodObject<{
|
|
628
|
+
bootCostUsd: z.ZodNumber;
|
|
629
|
+
bootFill: z.ZodNumber;
|
|
630
|
+
growthPerRequest: z.ZodNumber;
|
|
631
|
+
readPricePerMTok: z.ZodNumber;
|
|
632
|
+
sessionId: z.ZodString;
|
|
633
|
+
role: z.ZodString;
|
|
634
|
+
model: z.ZodString;
|
|
635
|
+
requests: z.ZodNumber;
|
|
636
|
+
bootRequests: z.ZodNumber;
|
|
637
|
+
exitFill: z.ZodNumber;
|
|
638
|
+
lastTs: z.ZodString;
|
|
639
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
640
|
+
}, z.core.$strip>>;
|
|
641
|
+
unbootedSessions: z.ZodNumber;
|
|
642
|
+
teleports: z.ZodArray<z.ZodObject<{
|
|
643
|
+
ts: z.ZodString;
|
|
644
|
+
name: z.ZodNullable<z.ZodString>;
|
|
645
|
+
sessionId: z.ZodString;
|
|
646
|
+
role: z.ZodString;
|
|
647
|
+
model: z.ZodString;
|
|
648
|
+
exitFill: z.ZodNumber;
|
|
649
|
+
bestK: z.ZodNullable<z.ZodNumber>;
|
|
650
|
+
overConfigured: z.ZodArray<z.ZodObject<{
|
|
651
|
+
k: z.ZodNumber;
|
|
652
|
+
over: z.ZodNumber;
|
|
653
|
+
}, z.core.$strip>>;
|
|
654
|
+
}, z.core.$strip>>;
|
|
655
|
+
unmatchedTeleports: z.ZodNumber;
|
|
656
|
+
reviewers: z.ZodObject<{
|
|
657
|
+
prs: z.ZodNumber;
|
|
658
|
+
fresh: z.ZodArray<z.ZodObject<{
|
|
659
|
+
role: z.ZodString;
|
|
660
|
+
model: z.ZodString;
|
|
661
|
+
sessions: z.ZodNumber;
|
|
662
|
+
requestsPerPr: z.ZodNumber;
|
|
663
|
+
requestsFrom: z.ZodString;
|
|
664
|
+
requestsFromSessions: z.ZodNumber;
|
|
665
|
+
costUsd: z.ZodNumber;
|
|
666
|
+
}, z.core.$strip>>;
|
|
667
|
+
standing: z.ZodArray<z.ZodObject<{
|
|
668
|
+
role: z.ZodString;
|
|
669
|
+
model: z.ZodString;
|
|
670
|
+
sessions: z.ZodNumber;
|
|
671
|
+
requestsPerPr: z.ZodNumber;
|
|
672
|
+
requestsFrom: z.ZodString;
|
|
673
|
+
requestsFromSessions: z.ZodNumber;
|
|
674
|
+
costUsd: z.ZodNumber;
|
|
675
|
+
}, z.core.$strip>>;
|
|
676
|
+
}, z.core.$strip>;
|
|
677
|
+
}, z.core.$strip>;
|
|
209
678
|
wakeCauseByGapBand: z.ZodArray<z.ZodObject<{
|
|
210
679
|
wakeCause: z.ZodString;
|
|
211
680
|
gapBand: z.ZodString;
|
|
@@ -250,9 +719,11 @@ declare const costReportSchema: z.ZodObject<{
|
|
|
250
719
|
}, z.core.$strip>;
|
|
251
720
|
}, z.core.$strip>;
|
|
252
721
|
type CostReport = z.infer<typeof costReportSchema>;
|
|
253
|
-
type CostBucket = z.infer<typeof bucketSchema>;
|
|
722
|
+
type CostBucket = z.infer<typeof bucketSchema$1>;
|
|
254
723
|
type WakeCauseBucket = CostReport["byWakeCause"][number];
|
|
255
724
|
type WakeGapCell = z.infer<typeof cellSchema>;
|
|
725
|
+
type RoleActions = CostReport["byAction"][number];
|
|
726
|
+
type MechanicalShare = CostReport["mechanicalShare"];
|
|
256
727
|
interface CostReportOptions {
|
|
257
728
|
/** ISO timestamp or date, inclusive. Overrides `days`. */
|
|
258
729
|
since?: string;
|
|
@@ -267,10 +738,172 @@ interface CostReportOptions {
|
|
|
267
738
|
transcriptsDiscovered?: number;
|
|
268
739
|
/** The extraction version an audit facet must reach to count as current. */
|
|
269
740
|
facetVersion?: number;
|
|
741
|
+
/** Action rules in precedence order; seat-specific rules belong in the caller's config. */
|
|
742
|
+
actionRules?: readonly ActionRule[];
|
|
743
|
+
/** Action classes counted as mechanical in `mechanicalShare`. */
|
|
744
|
+
mechanicalClasses?: readonly ActionClass[];
|
|
745
|
+
/** Report roles whose wakes `wakeEpisodes` cuts into episodes. */
|
|
746
|
+
episodeRoles?: readonly string[];
|
|
747
|
+
/** A wake is no-action when every one of its requests falls in these action classes. */
|
|
748
|
+
noActionClasses?: readonly ActionClass[];
|
|
749
|
+
/** The broker log's lines, read by the caller; its teleport starts give each handoff's exit fill. */
|
|
750
|
+
brokerLogLines?: () => Iterable<string>;
|
|
751
|
+
handoff?: HandoffOptions;
|
|
752
|
+
/** Narrows every request-keyed field to some sessions; absent means all. */
|
|
753
|
+
scope?: ReportScope;
|
|
270
754
|
}
|
|
271
755
|
/** Reads the graph and never writes it, so a read-only connection is enough. */
|
|
272
756
|
declare function costReport(db: Db, options?: CostReportOptions): CostReport;
|
|
273
757
|
|
|
758
|
+
/** The tool calls each request in the window issued, keyed by `request_id`; a request with none is absent. */
|
|
759
|
+
declare function readRequestToolCalls(db: Db, window: ReportWindow): Map<string, ActionCall[]>;
|
|
760
|
+
|
|
761
|
+
declare const WAKE_FROM_KINDS: readonly ["seat", "agent", "broadcast", "broker", "none"];
|
|
762
|
+
type WakeFromKind = (typeof WAKE_FROM_KINDS)[number];
|
|
763
|
+
/** Report roles whose wakes are cut into episodes: a human coordinator and a spawned coordinator seat. */
|
|
764
|
+
declare const DEFAULT_EPISODE_ROLES: readonly string[];
|
|
765
|
+
/** A wake whose requests only read, answer in text, or call tools no rule names changed nothing outside the session. */
|
|
766
|
+
declare const DEFAULT_NO_ACTION_CLASSES: readonly ActionClass[];
|
|
767
|
+
declare const AGENT_LIFECYCLE = "agent_lifecycle";
|
|
768
|
+
declare const causeSchema: z.ZodObject<{
|
|
769
|
+
midLoopEpisodes: z.ZodNumber;
|
|
770
|
+
requestsPerEpisode: z.ZodNumber;
|
|
771
|
+
costPerEpisode: z.ZodNumber;
|
|
772
|
+
byFrom: z.ZodArray<z.ZodObject<{
|
|
773
|
+
episodes: z.ZodNumber;
|
|
774
|
+
requests: z.ZodNumber;
|
|
775
|
+
costUsd: z.ZodNumber;
|
|
776
|
+
noActionEpisodes: z.ZodNumber;
|
|
777
|
+
noActionCostUsd: z.ZodNumber;
|
|
778
|
+
key: z.ZodEnum<{
|
|
779
|
+
broadcast: "broadcast";
|
|
780
|
+
seat: "seat";
|
|
781
|
+
agent: "agent";
|
|
782
|
+
broker: "broker";
|
|
783
|
+
none: "none";
|
|
784
|
+
}>;
|
|
785
|
+
}, z.core.$strip>>;
|
|
786
|
+
episodes: z.ZodNumber;
|
|
787
|
+
requests: z.ZodNumber;
|
|
788
|
+
costUsd: z.ZodNumber;
|
|
789
|
+
noActionEpisodes: z.ZodNumber;
|
|
790
|
+
noActionCostUsd: z.ZodNumber;
|
|
791
|
+
key: z.ZodString;
|
|
792
|
+
}, z.core.$strip>;
|
|
793
|
+
declare const pairSchema: z.ZodObject<{
|
|
794
|
+
episodes: z.ZodNumber;
|
|
795
|
+
requests: z.ZodNumber;
|
|
796
|
+
costUsd: z.ZodNumber;
|
|
797
|
+
noActionEpisodes: z.ZodNumber;
|
|
798
|
+
noActionCostUsd: z.ZodNumber;
|
|
799
|
+
from: z.ZodString;
|
|
800
|
+
fromKind: z.ZodEnum<{
|
|
801
|
+
broadcast: "broadcast";
|
|
802
|
+
seat: "seat";
|
|
803
|
+
agent: "agent";
|
|
804
|
+
broker: "broker";
|
|
805
|
+
none: "none";
|
|
806
|
+
}>;
|
|
807
|
+
to: z.ZodString;
|
|
808
|
+
}, z.core.$strip>;
|
|
809
|
+
declare const wakeEpisodesSchema: z.ZodObject<{
|
|
810
|
+
unattributed: z.ZodObject<{
|
|
811
|
+
requests: z.ZodNumber;
|
|
812
|
+
costUsd: z.ZodNumber;
|
|
813
|
+
}, z.core.$strip>;
|
|
814
|
+
byCause: z.ZodArray<z.ZodObject<{
|
|
815
|
+
midLoopEpisodes: z.ZodNumber;
|
|
816
|
+
requestsPerEpisode: z.ZodNumber;
|
|
817
|
+
costPerEpisode: z.ZodNumber;
|
|
818
|
+
byFrom: z.ZodArray<z.ZodObject<{
|
|
819
|
+
episodes: z.ZodNumber;
|
|
820
|
+
requests: z.ZodNumber;
|
|
821
|
+
costUsd: z.ZodNumber;
|
|
822
|
+
noActionEpisodes: z.ZodNumber;
|
|
823
|
+
noActionCostUsd: z.ZodNumber;
|
|
824
|
+
key: z.ZodEnum<{
|
|
825
|
+
broadcast: "broadcast";
|
|
826
|
+
seat: "seat";
|
|
827
|
+
agent: "agent";
|
|
828
|
+
broker: "broker";
|
|
829
|
+
none: "none";
|
|
830
|
+
}>;
|
|
831
|
+
}, z.core.$strip>>;
|
|
832
|
+
episodes: z.ZodNumber;
|
|
833
|
+
requests: z.ZodNumber;
|
|
834
|
+
costUsd: z.ZodNumber;
|
|
835
|
+
noActionEpisodes: z.ZodNumber;
|
|
836
|
+
noActionCostUsd: z.ZodNumber;
|
|
837
|
+
key: z.ZodString;
|
|
838
|
+
}, z.core.$strip>>;
|
|
839
|
+
pairs: z.ZodArray<z.ZodObject<{
|
|
840
|
+
episodes: z.ZodNumber;
|
|
841
|
+
requests: z.ZodNumber;
|
|
842
|
+
costUsd: z.ZodNumber;
|
|
843
|
+
noActionEpisodes: z.ZodNumber;
|
|
844
|
+
noActionCostUsd: z.ZodNumber;
|
|
845
|
+
from: z.ZodString;
|
|
846
|
+
fromKind: z.ZodEnum<{
|
|
847
|
+
broadcast: "broadcast";
|
|
848
|
+
seat: "seat";
|
|
849
|
+
agent: "agent";
|
|
850
|
+
broker: "broker";
|
|
851
|
+
none: "none";
|
|
852
|
+
}>;
|
|
853
|
+
to: z.ZodString;
|
|
854
|
+
}, z.core.$strip>>;
|
|
855
|
+
episodes: z.ZodNumber;
|
|
856
|
+
requests: z.ZodNumber;
|
|
857
|
+
costUsd: z.ZodNumber;
|
|
858
|
+
noActionEpisodes: z.ZodNumber;
|
|
859
|
+
noActionCostUsd: z.ZodNumber;
|
|
860
|
+
roles: z.ZodArray<z.ZodString>;
|
|
861
|
+
noActionClasses: z.ZodArray<z.ZodEnum<{
|
|
862
|
+
"journal-write": "journal-write";
|
|
863
|
+
"pr-ci-check": "pr-ci-check";
|
|
864
|
+
merge: "merge";
|
|
865
|
+
dispatch: "dispatch";
|
|
866
|
+
retire: "retire";
|
|
867
|
+
"task-state": "task-state";
|
|
868
|
+
"budget-status": "budget-status";
|
|
869
|
+
scorer: "scorer";
|
|
870
|
+
message: "message";
|
|
871
|
+
"read-investigate": "read-investigate";
|
|
872
|
+
"text-only": "text-only";
|
|
873
|
+
other: "other";
|
|
874
|
+
}>>;
|
|
875
|
+
}, z.core.$strip>;
|
|
876
|
+
type WakeEpisodes = z.infer<typeof wakeEpisodesSchema>;
|
|
877
|
+
type WakeCauseEpisodes = z.infer<typeof causeSchema>;
|
|
878
|
+
type WakePair = z.infer<typeof pairSchema>;
|
|
879
|
+
/** One request as the episode view needs it. */
|
|
880
|
+
interface EpisodeRequestRow {
|
|
881
|
+
costUsd: number;
|
|
882
|
+
action: ActionClass;
|
|
883
|
+
eventKey: string | null;
|
|
884
|
+
}
|
|
885
|
+
interface WakeEpisode {
|
|
886
|
+
key: string;
|
|
887
|
+
cause: string;
|
|
888
|
+
midLoop: boolean;
|
|
889
|
+
fromKind: WakeFromKind;
|
|
890
|
+
from: string;
|
|
891
|
+
to: string;
|
|
892
|
+
requests: number;
|
|
893
|
+
costUsd: number;
|
|
894
|
+
noAction: boolean;
|
|
895
|
+
}
|
|
896
|
+
interface EpisodeNames {
|
|
897
|
+
seats: ReadonlySet<string>;
|
|
898
|
+
/** Each receiving session's agent-chat name. */
|
|
899
|
+
receivers: ReadonlyMap<string, string>;
|
|
900
|
+
}
|
|
901
|
+
/** A seat is a name some top-level session carries, or one a coordinator profile was spawned under. */
|
|
902
|
+
declare function episodeNames(rows: readonly AgentNameRow[]): EpisodeNames;
|
|
903
|
+
/** Each event with the requests that followed it, flagged no-action when every request's class is listed. */
|
|
904
|
+
declare function buildWakeEpisodes(events: readonly WakeEventRow[], requests: readonly EpisodeRequestRow[], names: EpisodeNames, noActionClasses: readonly ActionClass[]): WakeEpisode[];
|
|
905
|
+
declare function summarizeWakeEpisodes(episodes: readonly WakeEpisode[], requests: readonly EpisodeRequestRow[], roles: readonly string[], noActionClasses: readonly ActionClass[]): WakeEpisodes;
|
|
906
|
+
|
|
274
907
|
/** Two rule sets on purpose (design section 18): workers segment by assignment, coordinators by work phase. */
|
|
275
908
|
type Heuristic = "worker-v1" | "coordinator-v1";
|
|
276
909
|
declare const HEURISTIC_VERSIONS: Readonly<Record<Heuristic, number>>;
|
|
@@ -343,5 +976,684 @@ declare function sessionRole(classification: SessionClassification, worker: Work
|
|
|
343
976
|
declare const LIST_PRICE_CAVEAT = "List prices, not a bill: the accounts behind these sessions may run on subscription plans. Rankings hold; the absolute figure is not what you paid.";
|
|
344
977
|
/** The same report as plain-text tables, one section per report field, caveat and footer last. */
|
|
345
978
|
declare function renderCostReportText(report: CostReport): string;
|
|
979
|
+
/** The report's sections a caller may render alone, keyed by the field each one shows. */
|
|
980
|
+
declare const COST_REPORT_SECTIONS: {
|
|
981
|
+
readonly byRole: (report: CostReport) => string;
|
|
982
|
+
readonly byAction: (report: CostReport) => string;
|
|
983
|
+
readonly mechanicalShare: (report: CostReport) => string;
|
|
984
|
+
readonly byWakeCause: (report: CostReport) => string;
|
|
985
|
+
readonly wakeEpisodes: (report: CostReport) => string;
|
|
986
|
+
readonly wakePairs: (report: CostReport) => string;
|
|
987
|
+
readonly handoff: (report: CostReport) => string;
|
|
988
|
+
readonly teleports: (report: CostReport) => string;
|
|
989
|
+
readonly reviewers: (report: CostReport) => string;
|
|
990
|
+
};
|
|
991
|
+
type CostReportSection = keyof typeof COST_REPORT_SECTIONS;
|
|
992
|
+
/** Some sections of the report under its header, with the caveat and footer last as in the full text. */
|
|
993
|
+
declare function renderCostReportSections(report: CostReport, sections: readonly CostReportSection[]): string;
|
|
994
|
+
|
|
995
|
+
/** Gap bands past a 5-minute TTL: the next request finds the cache gone. */
|
|
996
|
+
declare const REBUILD_GAP_BANDS: readonly string[];
|
|
997
|
+
/** One request as the TTL what-if needs it. */
|
|
998
|
+
interface TtlRequestRow {
|
|
999
|
+
sessionId: string;
|
|
1000
|
+
role: string;
|
|
1001
|
+
profile: string;
|
|
1002
|
+
model: string;
|
|
1003
|
+
ts: string;
|
|
1004
|
+
cacheReadTokens: number;
|
|
1005
|
+
cacheWrite1hTokens: number;
|
|
1006
|
+
/** Milliseconds since the session's previous request; null for its first. */
|
|
1007
|
+
gapMs: number | null;
|
|
1008
|
+
}
|
|
1009
|
+
declare const bucketSchema: z.ZodObject<{
|
|
1010
|
+
fiveMinuteLoses: z.ZodBoolean;
|
|
1011
|
+
sessions: z.ZodNumber;
|
|
1012
|
+
requests: z.ZodNumber;
|
|
1013
|
+
write1hTokens: z.ZodNumber;
|
|
1014
|
+
repriceSavingUsd: z.ZodNumber;
|
|
1015
|
+
rebuilds: z.ZodNumber;
|
|
1016
|
+
rebuildTokens: z.ZodNumber;
|
|
1017
|
+
rebuildCostUsd: z.ZodNumber;
|
|
1018
|
+
netSavingUsd: z.ZodNumber;
|
|
1019
|
+
netPerSessionUsd: z.ZodNumber;
|
|
1020
|
+
key: z.ZodString;
|
|
1021
|
+
}, z.core.$strip>;
|
|
1022
|
+
declare const cacheTtlWhatIfSchema: z.ZodObject<{
|
|
1023
|
+
window: z.ZodOptional<z.ZodObject<{
|
|
1024
|
+
since: z.ZodNullable<z.ZodString>;
|
|
1025
|
+
until: z.ZodNullable<z.ZodString>;
|
|
1026
|
+
}, z.core.$strip>>;
|
|
1027
|
+
priceTableVersion: z.ZodNumber;
|
|
1028
|
+
rebuildGapBands: z.ZodArray<z.ZodString>;
|
|
1029
|
+
totals: z.ZodObject<{
|
|
1030
|
+
sessions: z.ZodNumber;
|
|
1031
|
+
requests: z.ZodNumber;
|
|
1032
|
+
write1hTokens: z.ZodNumber;
|
|
1033
|
+
repriceSavingUsd: z.ZodNumber;
|
|
1034
|
+
rebuilds: z.ZodNumber;
|
|
1035
|
+
rebuildTokens: z.ZodNumber;
|
|
1036
|
+
rebuildCostUsd: z.ZodNumber;
|
|
1037
|
+
netSavingUsd: z.ZodNumber;
|
|
1038
|
+
netPerSessionUsd: z.ZodNumber;
|
|
1039
|
+
}, z.core.$strip>;
|
|
1040
|
+
unpricedRequests: z.ZodNumber;
|
|
1041
|
+
byRole: z.ZodArray<z.ZodObject<{
|
|
1042
|
+
fiveMinuteLoses: z.ZodBoolean;
|
|
1043
|
+
sessions: z.ZodNumber;
|
|
1044
|
+
requests: z.ZodNumber;
|
|
1045
|
+
write1hTokens: z.ZodNumber;
|
|
1046
|
+
repriceSavingUsd: z.ZodNumber;
|
|
1047
|
+
rebuilds: z.ZodNumber;
|
|
1048
|
+
rebuildTokens: z.ZodNumber;
|
|
1049
|
+
rebuildCostUsd: z.ZodNumber;
|
|
1050
|
+
netSavingUsd: z.ZodNumber;
|
|
1051
|
+
netPerSessionUsd: z.ZodNumber;
|
|
1052
|
+
key: z.ZodString;
|
|
1053
|
+
}, z.core.$strip>>;
|
|
1054
|
+
byProfile: z.ZodArray<z.ZodObject<{
|
|
1055
|
+
fiveMinuteLoses: z.ZodBoolean;
|
|
1056
|
+
sessions: z.ZodNumber;
|
|
1057
|
+
requests: z.ZodNumber;
|
|
1058
|
+
write1hTokens: z.ZodNumber;
|
|
1059
|
+
repriceSavingUsd: z.ZodNumber;
|
|
1060
|
+
rebuilds: z.ZodNumber;
|
|
1061
|
+
rebuildTokens: z.ZodNumber;
|
|
1062
|
+
rebuildCostUsd: z.ZodNumber;
|
|
1063
|
+
netSavingUsd: z.ZodNumber;
|
|
1064
|
+
netPerSessionUsd: z.ZodNumber;
|
|
1065
|
+
key: z.ZodString;
|
|
1066
|
+
}, z.core.$strip>>;
|
|
1067
|
+
lossRoles: z.ZodArray<z.ZodString>;
|
|
1068
|
+
}, z.core.$strip>;
|
|
1069
|
+
type CacheTtlWhatIf = z.infer<typeof cacheTtlWhatIfSchema>;
|
|
1070
|
+
type CacheTtlBucket = z.infer<typeof bucketSchema>;
|
|
1071
|
+
/** Q3: what each role and profile would have paid with `CLAUDE_CODE_PROMPT_CACHE_TTL=5m` instead of 1h. */
|
|
1072
|
+
declare function cacheTtlWhatIf(rows: readonly TtlRequestRow[], prices?: readonly PriceRow[]): CacheTtlWhatIf;
|
|
1073
|
+
/** Reads the graph and never writes it; roles are the cost report's. */
|
|
1074
|
+
declare function cacheTtlReport(db: Db, options?: CostReportOptions, prices?: readonly PriceRow[]): CacheTtlWhatIf;
|
|
1075
|
+
declare function readTtlRows(db: Db, window: ReportWindow): TtlRequestRow[];
|
|
1076
|
+
/** One table per dimension; a role or profile 5m would cost money is marked `loss`. */
|
|
1077
|
+
declare function renderCacheTtlText(whatIf: CacheTtlWhatIf): string;
|
|
1078
|
+
|
|
1079
|
+
/** One reviewer verdict message, as agent-chat's events table records it. */
|
|
1080
|
+
interface VerdictRecord {
|
|
1081
|
+
eventId: number;
|
|
1082
|
+
at: string;
|
|
1083
|
+
/** The seat the verdict was sent to. */
|
|
1084
|
+
seat: string;
|
|
1085
|
+
reviewer: string;
|
|
1086
|
+
verdict: string;
|
|
1087
|
+
repo: string;
|
|
1088
|
+
pr: number;
|
|
1089
|
+
head: string;
|
|
1090
|
+
}
|
|
1091
|
+
/** A PR as GitHub REST reports it at the time of the run. */
|
|
1092
|
+
interface PullState {
|
|
1093
|
+
repo: string;
|
|
1094
|
+
pr: number;
|
|
1095
|
+
state: "open" | "closed";
|
|
1096
|
+
mergedAt: string | null;
|
|
1097
|
+
headSha: string;
|
|
1098
|
+
}
|
|
1099
|
+
type ParsedVerdict = Pick<VerdictRecord, "verdict" | "repo" | "pr" | "head">;
|
|
1100
|
+
/** Reads a `Verdict:` message's first three lines; null when any of them is missing. */
|
|
1101
|
+
declare function parseVerdict(body: string): ParsedVerdict | null;
|
|
1102
|
+
type MergeStatus = "merged" | "open" | "stale-head" | "closed" | "unknown";
|
|
1103
|
+
/** A PR holding at least one MERGE verdict, resolved against its GitHub state at `asOf`. */
|
|
1104
|
+
interface MergeOutcome {
|
|
1105
|
+
repo: string;
|
|
1106
|
+
pr: number;
|
|
1107
|
+
status: MergeStatus;
|
|
1108
|
+
/** The first MERGE verdict at the PR's final head; null when no verdict names that head. */
|
|
1109
|
+
verdict: VerdictRecord | null;
|
|
1110
|
+
/** Verdict to merge for merged PRs; verdict to `asOf` (a censored age) for open ones. */
|
|
1111
|
+
minutes: number | null;
|
|
1112
|
+
}
|
|
1113
|
+
declare function mergeOutcomes(verdicts: readonly VerdictRecord[], pulls: readonly PullState[], asOf: string): MergeOutcome[];
|
|
1114
|
+
declare function prKey(row: {
|
|
1115
|
+
repo: string;
|
|
1116
|
+
pr: number;
|
|
1117
|
+
}): string;
|
|
1118
|
+
declare const latencyStatsSchema: z.ZodObject<{
|
|
1119
|
+
merged: z.ZodNumber;
|
|
1120
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1121
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1122
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1123
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1124
|
+
censored: z.ZodNumber;
|
|
1125
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1126
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1127
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1128
|
+
}, z.core.$strip>;
|
|
1129
|
+
type LatencyStats = z.infer<typeof latencyStatsSchema>;
|
|
1130
|
+
declare function latencyStats(outcomes: readonly MergeOutcome[]): LatencyStats;
|
|
1131
|
+
|
|
1132
|
+
/** One action the auto-mode classifier refused, read from a seat's transcript. */
|
|
1133
|
+
interface DenialRecord {
|
|
1134
|
+
seat: string;
|
|
1135
|
+
at: string;
|
|
1136
|
+
/** The classifier's bracketed reason, such as "Merge Without Review". */
|
|
1137
|
+
reason: string;
|
|
1138
|
+
/** What the refused call was doing, from its tool input; the reason label alone is loose. */
|
|
1139
|
+
action: string;
|
|
1140
|
+
tool: string;
|
|
1141
|
+
/** The refused call's id; a forked or resumed transcript repeats it, so it is counted once. */
|
|
1142
|
+
toolUseId?: string;
|
|
1143
|
+
}
|
|
1144
|
+
/** Classifies a refused call by what it did; MCP tools keep their own short name. */
|
|
1145
|
+
declare function classifyDeniedAction(tool: string, input: unknown): string;
|
|
1146
|
+
/** Scans transcript JSONL for classifier refusals and joins each to the tool call it refused. */
|
|
1147
|
+
declare function parseDenials(lines: Iterable<string>, seat: string): DenialRecord[];
|
|
1148
|
+
/** One denial per refused call; a record without a tool_use_id cannot be matched and is kept. */
|
|
1149
|
+
declare function dedupeDenials(denials: readonly DenialRecord[]): DenialRecord[];
|
|
1150
|
+
|
|
1151
|
+
/** A seat journal line that states its implementer slot count, and why it did not fill a free slot. */
|
|
1152
|
+
interface SlotTick {
|
|
1153
|
+
seat: string;
|
|
1154
|
+
at: string;
|
|
1155
|
+
used: number;
|
|
1156
|
+
cap: number;
|
|
1157
|
+
reason: string;
|
|
1158
|
+
/** The journal line number, so a row can be checked against its source. */
|
|
1159
|
+
line: number;
|
|
1160
|
+
}
|
|
1161
|
+
interface SeatJournal {
|
|
1162
|
+
ticks: SlotTick[];
|
|
1163
|
+
/** The journal's last timestamped line; the final tick holds until then. */
|
|
1164
|
+
lastAt: string | null;
|
|
1165
|
+
}
|
|
1166
|
+
declare const UNSTATED_REASON = "unstated";
|
|
1167
|
+
/** A tick's count holds at most this long, so a dark seat is not read as an hour of idle slots. */
|
|
1168
|
+
declare const TICK_HOLD_MAX_MIN = 60;
|
|
1169
|
+
/**
|
|
1170
|
+
* Reads `HH:MM[:SS] ...` journal lines for the date the journal covers.
|
|
1171
|
+
* `utcOffsetMin` is the journal clock's offset east of UTC, such as -360 for UTC-6.
|
|
1172
|
+
*/
|
|
1173
|
+
declare function parseSeatJournal(text: string, seat: string, date: string, utcOffsetMin: number): SeatJournal;
|
|
1174
|
+
interface IdleSlotRow {
|
|
1175
|
+
seat: string;
|
|
1176
|
+
reason: string;
|
|
1177
|
+
slotMinutes: number;
|
|
1178
|
+
ticks: number;
|
|
1179
|
+
/** Journal line numbers of the ticks counted here. */
|
|
1180
|
+
lines: number[];
|
|
1181
|
+
}
|
|
1182
|
+
/** Free implementer slots times the minutes each tick's count held, clipped to the window. */
|
|
1183
|
+
declare function idleSlotMinutes(journals: readonly SeatJournal[], window: {
|
|
1184
|
+
since?: string;
|
|
1185
|
+
until?: string;
|
|
1186
|
+
}): IdleSlotRow[];
|
|
1187
|
+
|
|
1188
|
+
/** Where each section's numbers come from: the command that re-reads them and the field it reads. */
|
|
1189
|
+
declare const BLOCKED_FLOW_SOURCES: {
|
|
1190
|
+
readonly verdicts: {
|
|
1191
|
+
readonly command: "sqlite3 -readonly <events.db> \"SELECT id, ts, target, body FROM events WHERE kind='message' AND body LIKE 'Verdict:%'\"";
|
|
1192
|
+
readonly field: "events.ts, events.target, events.body lines Verdict:, PR:, Head:";
|
|
1193
|
+
};
|
|
1194
|
+
readonly pulls: {
|
|
1195
|
+
readonly command: "gh api repos/<owner>/<repo>/pulls/<n>";
|
|
1196
|
+
readonly field: ".state, .merged_at, .head.sha";
|
|
1197
|
+
};
|
|
1198
|
+
readonly denials: {
|
|
1199
|
+
readonly command: "grep 'auto mode classifier. Reason: \\[' <seat transcript>.jsonl";
|
|
1200
|
+
readonly field: "tool_result.content Reason: [<class>], joined to tool_use.input by tool_use_id";
|
|
1201
|
+
};
|
|
1202
|
+
readonly journals: {
|
|
1203
|
+
readonly command: "grep -nE 'impl [0-9]+/[0-9]+' <seat journal>.md";
|
|
1204
|
+
readonly field: "impl <used>/<cap>, No dispatch: <reason>";
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
type BlockedFlowSource = keyof typeof BLOCKED_FLOW_SOURCES;
|
|
1208
|
+
interface BlockedFlowInput {
|
|
1209
|
+
verdicts: readonly VerdictRecord[];
|
|
1210
|
+
pulls: readonly PullState[];
|
|
1211
|
+
denials: readonly DenialRecord[];
|
|
1212
|
+
journals: readonly SeatJournal[];
|
|
1213
|
+
/** Waits are measured to here; a PR merged later counts as open. */
|
|
1214
|
+
asOf: string;
|
|
1215
|
+
window?: {
|
|
1216
|
+
since?: string;
|
|
1217
|
+
until?: string;
|
|
1218
|
+
};
|
|
1219
|
+
/** Splits verdict-to-merge by verdict time, such as the moment a seat was granted merge authority. */
|
|
1220
|
+
splitAt?: string;
|
|
1221
|
+
/** Keeps only verdicts sent to, and denials and journals of, these seats. */
|
|
1222
|
+
seats?: readonly string[];
|
|
1223
|
+
}
|
|
1224
|
+
declare const latencyRowSchema: z.ZodObject<{
|
|
1225
|
+
repo: z.ZodString;
|
|
1226
|
+
prs: z.ZodNumber;
|
|
1227
|
+
staleHead: z.ZodNumber;
|
|
1228
|
+
closed: z.ZodNumber;
|
|
1229
|
+
unknown: z.ZodNumber;
|
|
1230
|
+
all: z.ZodObject<{
|
|
1231
|
+
merged: z.ZodNumber;
|
|
1232
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1233
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1234
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1235
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1236
|
+
censored: z.ZodNumber;
|
|
1237
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1238
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1239
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1240
|
+
}, z.core.$strip>;
|
|
1241
|
+
before: z.ZodOptional<z.ZodObject<{
|
|
1242
|
+
merged: z.ZodNumber;
|
|
1243
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1244
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1245
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1246
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1247
|
+
censored: z.ZodNumber;
|
|
1248
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1249
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1250
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1251
|
+
}, z.core.$strip>>;
|
|
1252
|
+
after: z.ZodOptional<z.ZodObject<{
|
|
1253
|
+
merged: z.ZodNumber;
|
|
1254
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1255
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1256
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1257
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1258
|
+
censored: z.ZodNumber;
|
|
1259
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1260
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1261
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1262
|
+
}, z.core.$strip>>;
|
|
1263
|
+
}, z.core.$strip>;
|
|
1264
|
+
declare const blockedFlowSchema: z.ZodObject<{
|
|
1265
|
+
asOf: z.ZodString;
|
|
1266
|
+
window: z.ZodObject<{
|
|
1267
|
+
since: z.ZodOptional<z.ZodString>;
|
|
1268
|
+
until: z.ZodOptional<z.ZodString>;
|
|
1269
|
+
}, z.core.$strip>;
|
|
1270
|
+
splitAt: z.ZodOptional<z.ZodString>;
|
|
1271
|
+
sources: z.ZodRecord<z.ZodEnum<{
|
|
1272
|
+
verdicts: "verdicts";
|
|
1273
|
+
pulls: "pulls";
|
|
1274
|
+
denials: "denials";
|
|
1275
|
+
journals: "journals";
|
|
1276
|
+
}>, z.ZodObject<{
|
|
1277
|
+
command: z.ZodString;
|
|
1278
|
+
field: z.ZodString;
|
|
1279
|
+
}, z.core.$strip>>;
|
|
1280
|
+
verdictToMerge: z.ZodObject<{
|
|
1281
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1282
|
+
verdicts: "verdicts";
|
|
1283
|
+
pulls: "pulls";
|
|
1284
|
+
denials: "denials";
|
|
1285
|
+
journals: "journals";
|
|
1286
|
+
}>>;
|
|
1287
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1288
|
+
repo: z.ZodString;
|
|
1289
|
+
prs: z.ZodNumber;
|
|
1290
|
+
staleHead: z.ZodNumber;
|
|
1291
|
+
closed: z.ZodNumber;
|
|
1292
|
+
unknown: z.ZodNumber;
|
|
1293
|
+
all: z.ZodObject<{
|
|
1294
|
+
merged: z.ZodNumber;
|
|
1295
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1296
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1297
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1298
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1299
|
+
censored: z.ZodNumber;
|
|
1300
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1301
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1302
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1303
|
+
}, z.core.$strip>;
|
|
1304
|
+
before: z.ZodOptional<z.ZodObject<{
|
|
1305
|
+
merged: z.ZodNumber;
|
|
1306
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1307
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1308
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1309
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1310
|
+
censored: z.ZodNumber;
|
|
1311
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1312
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1313
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1314
|
+
}, z.core.$strip>>;
|
|
1315
|
+
after: z.ZodOptional<z.ZodObject<{
|
|
1316
|
+
merged: z.ZodNumber;
|
|
1317
|
+
medianMin: z.ZodNullable<z.ZodNumber>;
|
|
1318
|
+
meanMin: z.ZodNullable<z.ZodNumber>;
|
|
1319
|
+
p90Min: z.ZodNullable<z.ZodNumber>;
|
|
1320
|
+
maxMin: z.ZodNullable<z.ZodNumber>;
|
|
1321
|
+
censored: z.ZodNumber;
|
|
1322
|
+
oldestCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1323
|
+
censoredPrMinutes: z.ZodNumber;
|
|
1324
|
+
medianWithCensoredMin: z.ZodNullable<z.ZodNumber>;
|
|
1325
|
+
}, z.core.$strip>>;
|
|
1326
|
+
}, z.core.$strip>>;
|
|
1327
|
+
}, z.core.$strip>;
|
|
1328
|
+
openHoldingMerge: z.ZodObject<{
|
|
1329
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1330
|
+
verdicts: "verdicts";
|
|
1331
|
+
pulls: "pulls";
|
|
1332
|
+
denials: "denials";
|
|
1333
|
+
journals: "journals";
|
|
1334
|
+
}>>;
|
|
1335
|
+
prMinutes: z.ZodNumber;
|
|
1336
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1337
|
+
repo: z.ZodString;
|
|
1338
|
+
pr: z.ZodNumber;
|
|
1339
|
+
head: z.ZodString;
|
|
1340
|
+
seat: z.ZodString;
|
|
1341
|
+
verdictAt: z.ZodString;
|
|
1342
|
+
ageMin: z.ZodNumber;
|
|
1343
|
+
eventId: z.ZodNumber;
|
|
1344
|
+
}, z.core.$strip>>;
|
|
1345
|
+
}, z.core.$strip>;
|
|
1346
|
+
denials: z.ZodObject<{
|
|
1347
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1348
|
+
verdicts: "verdicts";
|
|
1349
|
+
pulls: "pulls";
|
|
1350
|
+
denials: "denials";
|
|
1351
|
+
journals: "journals";
|
|
1352
|
+
}>>;
|
|
1353
|
+
total: z.ZodNumber;
|
|
1354
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1355
|
+
reason: z.ZodString;
|
|
1356
|
+
action: z.ZodString;
|
|
1357
|
+
seat: z.ZodString;
|
|
1358
|
+
count: z.ZodNumber;
|
|
1359
|
+
}, z.core.$strip>>;
|
|
1360
|
+
}, z.core.$strip>;
|
|
1361
|
+
idleSlots: z.ZodObject<{
|
|
1362
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1363
|
+
verdicts: "verdicts";
|
|
1364
|
+
pulls: "pulls";
|
|
1365
|
+
denials: "denials";
|
|
1366
|
+
journals: "journals";
|
|
1367
|
+
}>>;
|
|
1368
|
+
holdMaxMin: z.ZodNumber;
|
|
1369
|
+
total: z.ZodNumber;
|
|
1370
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1371
|
+
seat: z.ZodString;
|
|
1372
|
+
reason: z.ZodString;
|
|
1373
|
+
slotMinutes: z.ZodNumber;
|
|
1374
|
+
ticks: z.ZodNumber;
|
|
1375
|
+
lines: z.ZodArray<z.ZodNumber>;
|
|
1376
|
+
}, z.core.$strip>>;
|
|
1377
|
+
}, z.core.$strip>;
|
|
1378
|
+
}, z.core.$strip>;
|
|
1379
|
+
type BlockedFlowReport = z.infer<typeof blockedFlowSchema>;
|
|
1380
|
+
type LatencyRow = z.infer<typeof latencyRowSchema>;
|
|
1381
|
+
declare const ALL_REPOS = "all";
|
|
1382
|
+
/** Per repo: verdict-to-merge waits, PRs still holding MERGE, classifier denials and idle implementer slots. */
|
|
1383
|
+
declare function blockedFlowReport(input: BlockedFlowInput): BlockedFlowReport;
|
|
1384
|
+
/** Each table's title names the JSON field its numbers come from; the sources close the report. */
|
|
1385
|
+
declare function renderBlockedFlowText(report: BlockedFlowReport): string;
|
|
1386
|
+
|
|
1387
|
+
/** One agent-chat broker.log entry and the 1-based line it came from, so each finding can cite it. */
|
|
1388
|
+
interface BrokerEntry {
|
|
1389
|
+
line: number;
|
|
1390
|
+
ts: string;
|
|
1391
|
+
event: string;
|
|
1392
|
+
fields: Record<string, unknown>;
|
|
1393
|
+
}
|
|
1394
|
+
/** Broker log lines to entries; a line that is not a JSON object with `ts` and `event` is skipped but still counted. */
|
|
1395
|
+
declare function parseBrokerLog(lines: Iterable<string>): BrokerEntry[];
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* How a route missed a recipient: `failed` is a `delivered:false` the broker dropped, `partial` reached
|
|
1399
|
+
* others but not this name, and `queued` is a `delivered:false` the broker kept for later delivery.
|
|
1400
|
+
*/
|
|
1401
|
+
type RouteMissKind = "failed" | "partial" | "queued";
|
|
1402
|
+
/** One recipient a routed message did not reach when it was sent. */
|
|
1403
|
+
interface RouteMiss {
|
|
1404
|
+
line: number;
|
|
1405
|
+
at: string;
|
|
1406
|
+
recipient: string;
|
|
1407
|
+
from: string;
|
|
1408
|
+
kind: string;
|
|
1409
|
+
miss: RouteMissKind;
|
|
1410
|
+
}
|
|
1411
|
+
interface RouteFailureRow {
|
|
1412
|
+
recipient: string;
|
|
1413
|
+
failed: number;
|
|
1414
|
+
partial: number;
|
|
1415
|
+
queued: number;
|
|
1416
|
+
first: string;
|
|
1417
|
+
last: string;
|
|
1418
|
+
lines: number[];
|
|
1419
|
+
}
|
|
1420
|
+
/** Each recipient named in `to` that a route did not reach. */
|
|
1421
|
+
declare function routeMisses(entries: readonly BrokerEntry[]): RouteMiss[];
|
|
1422
|
+
/** Misses grouped by recipient, most first. */
|
|
1423
|
+
declare function routeFailureRows(misses: readonly RouteMiss[]): RouteFailureRow[];
|
|
1424
|
+
declare function countMisses(misses: readonly RouteMiss[]): Record<RouteMissKind, number>;
|
|
1425
|
+
|
|
1426
|
+
/** A seat off the broker for longer than this is dark; a teleport hand-off takes seconds. */
|
|
1427
|
+
declare const DARK_MIN = 5;
|
|
1428
|
+
/** A name deregistered from the broker until it registered again, or until asOf if it never did, without exiting in between. */
|
|
1429
|
+
interface DarkGap {
|
|
1430
|
+
seat: string;
|
|
1431
|
+
from: string;
|
|
1432
|
+
to: string | null;
|
|
1433
|
+
minutes: number;
|
|
1434
|
+
/** A teleport of this name started after its last registration and before the gap closed. */
|
|
1435
|
+
teleport: boolean;
|
|
1436
|
+
/** Routes to the seat during the gap logged `delivered:false` and dropped. */
|
|
1437
|
+
failedRoutes: number;
|
|
1438
|
+
/** Routes during the gap that reached other recipients but not the seat. */
|
|
1439
|
+
partialRoutes: number;
|
|
1440
|
+
/** Routes the broker held or queued in the seat's inbox for delivery when it returned. */
|
|
1441
|
+
queuedRoutes: number;
|
|
1442
|
+
/** The deregistered and registered lines, then any teleport lines. */
|
|
1443
|
+
lines: number[];
|
|
1444
|
+
routeLines: number[];
|
|
1445
|
+
}
|
|
1446
|
+
/** Gaps longer than DARK_MIN, skipping a clean exit and later resume; one still open at asOf counts only if a route missed the seat in it. */
|
|
1447
|
+
declare function darkGaps(entries: readonly BrokerEntry[], misses: readonly RouteMiss[], asOf: string): DarkGap[];
|
|
1448
|
+
|
|
1449
|
+
/** An `agent_spawned` row of agent-chat's events table: the agent id and the profile it ran under. */
|
|
1450
|
+
interface SpawnRecord {
|
|
1451
|
+
eventId: number;
|
|
1452
|
+
agentId: string;
|
|
1453
|
+
name: string;
|
|
1454
|
+
profile: string | null;
|
|
1455
|
+
}
|
|
1456
|
+
/** An agent the broker saw exit without reporting to its spawner. */
|
|
1457
|
+
interface UnreportedExit {
|
|
1458
|
+
at: string;
|
|
1459
|
+
line: number;
|
|
1460
|
+
agentId: string;
|
|
1461
|
+
name: string;
|
|
1462
|
+
spawner: string;
|
|
1463
|
+
lastAction: string;
|
|
1464
|
+
/** The `agent_spawned` row the profile came from, or null when none matched the agent id. */
|
|
1465
|
+
spawnEventId: number | null;
|
|
1466
|
+
}
|
|
1467
|
+
interface UnreportedExitRow {
|
|
1468
|
+
profile: string;
|
|
1469
|
+
count: number;
|
|
1470
|
+
exits: UnreportedExit[];
|
|
1471
|
+
}
|
|
1472
|
+
declare const UNKNOWN_PROFILE = "unknown";
|
|
1473
|
+
/** Broker `unreported-exit` lines grouped by the profile the agent was spawned with, most first. */
|
|
1474
|
+
declare function unreportedExitRows(entries: readonly BrokerEntry[], spawns: readonly SpawnRecord[]): UnreportedExitRow[];
|
|
1475
|
+
|
|
1476
|
+
/** A prompt this old with nothing after it from the agent is a hang, not a pause for the owner. */
|
|
1477
|
+
declare const PROMPT_STALE_MIN = 10;
|
|
1478
|
+
/** The newest events-table row an actor wrote before asOf. */
|
|
1479
|
+
interface LastEventRecord {
|
|
1480
|
+
eventId: number;
|
|
1481
|
+
at: string;
|
|
1482
|
+
actor: string;
|
|
1483
|
+
kind: string;
|
|
1484
|
+
/** `meta.tool_name` of an approval request. */
|
|
1485
|
+
tool: string | null;
|
|
1486
|
+
/** A `resolution` row whose `ref` is this request's msg_id, written before asOf. */
|
|
1487
|
+
resolutionEventId: number | null;
|
|
1488
|
+
/** An `agent_exited` or `agent_retired` row for this actor after the request and before asOf. */
|
|
1489
|
+
endEventId: number | null;
|
|
1490
|
+
}
|
|
1491
|
+
interface StalePromptRow {
|
|
1492
|
+
agent: string;
|
|
1493
|
+
at: string;
|
|
1494
|
+
ageMin: number;
|
|
1495
|
+
tool: string | null;
|
|
1496
|
+
eventId: number;
|
|
1497
|
+
resolutionEventId: number | null;
|
|
1498
|
+
}
|
|
1499
|
+
/** Live agents whose last event is an approval request older than PROMPT_STALE_MIN, oldest first; resolved ones included. */
|
|
1500
|
+
declare function stalePromptRows(lastEvents: readonly LastEventRecord[], broker: readonly BrokerEntry[], asOf: string): StalePromptRow[];
|
|
1501
|
+
|
|
1502
|
+
/** Where each section's findings come from: the command that re-reads them and the field it reads. */
|
|
1503
|
+
declare const LIVENESS_SOURCES: {
|
|
1504
|
+
readonly registrations: {
|
|
1505
|
+
readonly command: "grep -nE '\"event\":\"(registered|deregistered|agent_exited|teleport_started|teleport_completed|teleport_failed|teleport_aborted)\"' <broker.log>";
|
|
1506
|
+
readonly field: "ts, event, name; cited as broker.log line numbers; a gap with a clean agent_exited (code 0, not inferred) and no teleport is a resume";
|
|
1507
|
+
};
|
|
1508
|
+
readonly routes: {
|
|
1509
|
+
readonly command: "grep -n '\"event\":\"route\"' <broker.log>";
|
|
1510
|
+
readonly field: "to, delivered, recipients";
|
|
1511
|
+
};
|
|
1512
|
+
readonly exits: {
|
|
1513
|
+
readonly command: "grep -n '\"event\":\"unreported-exit\"' <broker.log>";
|
|
1514
|
+
readonly field: "agentId, name, spawner, lastAction";
|
|
1515
|
+
};
|
|
1516
|
+
readonly spawns: {
|
|
1517
|
+
readonly command: "sqlite3 -readonly <events.db> \"SELECT id, msg_id, target, json_extract(meta,'$.profile') FROM events WHERE kind='agent_spawned'\"";
|
|
1518
|
+
readonly field: "events.msg_id (agent id), events.meta.profile";
|
|
1519
|
+
};
|
|
1520
|
+
readonly prompts: {
|
|
1521
|
+
readonly command: "sqlite3 -readonly <events.db> \"SELECT e.* FROM events e JOIN (SELECT actor, max(id) id FROM events WHERE ts < <asOf> AND kind != 'resolution' GROUP BY actor) l ON e.id = l.id WHERE e.kind='approval_request'\"";
|
|
1522
|
+
readonly field: "events.ts, events.actor, events.meta.tool_name; a resolution row's events.ref; skipped after the actor's agent_exited or agent_retired, or a broker_started it never re-registered after";
|
|
1523
|
+
};
|
|
1524
|
+
};
|
|
1525
|
+
type LivenessSource = keyof typeof LIVENESS_SOURCES;
|
|
1526
|
+
interface LivenessInput {
|
|
1527
|
+
broker: readonly BrokerEntry[];
|
|
1528
|
+
spawns: readonly SpawnRecord[];
|
|
1529
|
+
lastEvents: readonly LastEventRecord[];
|
|
1530
|
+
/** Gaps still open and prompt ages are measured to here; later entries are ignored. */
|
|
1531
|
+
asOf: string;
|
|
1532
|
+
/** A finding is kept when it starts inside the window; a prompt from a live agent still unanswered at asOf is kept however old. */
|
|
1533
|
+
window?: {
|
|
1534
|
+
since?: string;
|
|
1535
|
+
until?: string;
|
|
1536
|
+
};
|
|
1537
|
+
/** Keeps only findings about these names: the dark seat, route recipient, exiting agent or its spawner, prompting agent. */
|
|
1538
|
+
seats?: readonly string[];
|
|
1539
|
+
}
|
|
1540
|
+
declare const livenessSchema: z.ZodObject<{
|
|
1541
|
+
asOf: z.ZodString;
|
|
1542
|
+
window: z.ZodObject<{
|
|
1543
|
+
since: z.ZodOptional<z.ZodString>;
|
|
1544
|
+
until: z.ZodOptional<z.ZodString>;
|
|
1545
|
+
}, z.core.$strip>;
|
|
1546
|
+
thresholds: z.ZodObject<{
|
|
1547
|
+
darkMin: z.ZodNumber;
|
|
1548
|
+
promptStaleMin: z.ZodNumber;
|
|
1549
|
+
}, z.core.$strip>;
|
|
1550
|
+
sources: z.ZodRecord<z.ZodEnum<{
|
|
1551
|
+
exits: "exits";
|
|
1552
|
+
registrations: "registrations";
|
|
1553
|
+
routes: "routes";
|
|
1554
|
+
spawns: "spawns";
|
|
1555
|
+
prompts: "prompts";
|
|
1556
|
+
}>, z.ZodObject<{
|
|
1557
|
+
command: z.ZodString;
|
|
1558
|
+
field: z.ZodString;
|
|
1559
|
+
}, z.core.$strip>>;
|
|
1560
|
+
darkSeats: z.ZodObject<{
|
|
1561
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1562
|
+
exits: "exits";
|
|
1563
|
+
registrations: "registrations";
|
|
1564
|
+
routes: "routes";
|
|
1565
|
+
spawns: "spawns";
|
|
1566
|
+
prompts: "prompts";
|
|
1567
|
+
}>>;
|
|
1568
|
+
withTeleport: z.ZodNumber;
|
|
1569
|
+
withoutTeleport: z.ZodNumber;
|
|
1570
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1571
|
+
seat: z.ZodString;
|
|
1572
|
+
from: z.ZodString;
|
|
1573
|
+
to: z.ZodNullable<z.ZodString>;
|
|
1574
|
+
minutes: z.ZodNumber;
|
|
1575
|
+
teleport: z.ZodBoolean;
|
|
1576
|
+
failedRoutes: z.ZodNumber;
|
|
1577
|
+
partialRoutes: z.ZodNumber;
|
|
1578
|
+
queuedRoutes: z.ZodNumber;
|
|
1579
|
+
lines: z.ZodArray<z.ZodNumber>;
|
|
1580
|
+
routeLines: z.ZodArray<z.ZodNumber>;
|
|
1581
|
+
}, z.core.$strip>>;
|
|
1582
|
+
}, z.core.$strip>;
|
|
1583
|
+
routeFailures: z.ZodObject<{
|
|
1584
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1585
|
+
exits: "exits";
|
|
1586
|
+
registrations: "registrations";
|
|
1587
|
+
routes: "routes";
|
|
1588
|
+
spawns: "spawns";
|
|
1589
|
+
prompts: "prompts";
|
|
1590
|
+
}>>;
|
|
1591
|
+
failed: z.ZodNumber;
|
|
1592
|
+
partial: z.ZodNumber;
|
|
1593
|
+
queued: z.ZodNumber;
|
|
1594
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1595
|
+
recipient: z.ZodString;
|
|
1596
|
+
failed: z.ZodNumber;
|
|
1597
|
+
partial: z.ZodNumber;
|
|
1598
|
+
queued: z.ZodNumber;
|
|
1599
|
+
first: z.ZodString;
|
|
1600
|
+
last: z.ZodString;
|
|
1601
|
+
lines: z.ZodArray<z.ZodNumber>;
|
|
1602
|
+
}, z.core.$strip>>;
|
|
1603
|
+
}, z.core.$strip>;
|
|
1604
|
+
unreportedExits: z.ZodObject<{
|
|
1605
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1606
|
+
exits: "exits";
|
|
1607
|
+
registrations: "registrations";
|
|
1608
|
+
routes: "routes";
|
|
1609
|
+
spawns: "spawns";
|
|
1610
|
+
prompts: "prompts";
|
|
1611
|
+
}>>;
|
|
1612
|
+
total: z.ZodNumber;
|
|
1613
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1614
|
+
profile: z.ZodString;
|
|
1615
|
+
count: z.ZodNumber;
|
|
1616
|
+
exits: z.ZodArray<z.ZodObject<{
|
|
1617
|
+
at: z.ZodString;
|
|
1618
|
+
line: z.ZodNumber;
|
|
1619
|
+
agentId: z.ZodString;
|
|
1620
|
+
name: z.ZodString;
|
|
1621
|
+
spawner: z.ZodString;
|
|
1622
|
+
lastAction: z.ZodString;
|
|
1623
|
+
spawnEventId: z.ZodNullable<z.ZodNumber>;
|
|
1624
|
+
}, z.core.$strip>>;
|
|
1625
|
+
}, z.core.$strip>>;
|
|
1626
|
+
}, z.core.$strip>;
|
|
1627
|
+
stalePrompts: z.ZodObject<{
|
|
1628
|
+
cites: z.ZodArray<z.ZodEnum<{
|
|
1629
|
+
exits: "exits";
|
|
1630
|
+
registrations: "registrations";
|
|
1631
|
+
routes: "routes";
|
|
1632
|
+
spawns: "spawns";
|
|
1633
|
+
prompts: "prompts";
|
|
1634
|
+
}>>;
|
|
1635
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
1636
|
+
agent: z.ZodString;
|
|
1637
|
+
at: z.ZodString;
|
|
1638
|
+
ageMin: z.ZodNumber;
|
|
1639
|
+
tool: z.ZodNullable<z.ZodString>;
|
|
1640
|
+
eventId: z.ZodNumber;
|
|
1641
|
+
resolutionEventId: z.ZodNullable<z.ZodNumber>;
|
|
1642
|
+
}, z.core.$strip>>;
|
|
1643
|
+
resolvedRows: z.ZodArray<z.ZodObject<{
|
|
1644
|
+
agent: z.ZodString;
|
|
1645
|
+
at: z.ZodString;
|
|
1646
|
+
ageMin: z.ZodNumber;
|
|
1647
|
+
tool: z.ZodNullable<z.ZodString>;
|
|
1648
|
+
eventId: z.ZodNumber;
|
|
1649
|
+
resolutionEventId: z.ZodNullable<z.ZodNumber>;
|
|
1650
|
+
}, z.core.$strip>>;
|
|
1651
|
+
}, z.core.$strip>;
|
|
1652
|
+
}, z.core.$strip>;
|
|
1653
|
+
type LivenessReport = z.infer<typeof livenessSchema>;
|
|
1654
|
+
/** Seats dark past DARK_MIN, routes that missed their recipient, unreported exits and agents stuck on a prompt. */
|
|
1655
|
+
declare function livenessReport(input: LivenessInput): LivenessReport;
|
|
1656
|
+
/** Each table's title names the JSON field its rows come from; the sources and the shared caveat close the report. */
|
|
1657
|
+
declare function renderLivenessText(report: LivenessReport): string;
|
|
346
1658
|
|
|
347
|
-
export { type Band, CHANNEL_CLUSTER_MS, CONTEXT_BANDS, CONTEXT_RESET_TOKENS, COORDINATOR_MERGE_DEDUPE_REQUESTS, COORDINATOR_MIN_EPISODE_REQUESTS, COORDINATOR_WAVE_QUIET_REQUESTS, type CostBucket, type CostReport, type CostReportOptions, type EpisodeInbound, type EpisodeInput, type EpisodeRequest, type EpisodeSignal, GAP_BANDS, HEURISTIC_VERSIONS, type Heuristic, type HumanRole, IDLE_GAP_MS, LIST_PRICE_CAVEAT, PRICE_TABLE, PRICE_TABLE_VERSION, PROFILE_ROLES, type PriceRow, type PricedRequest, type ReportWindow, type RequestTokens, STANDING_PEER_MIN_ASSIGNMENTS, STANDING_PEER_MIN_HOURS, type SessionClass, type SessionClassification, type SessionFacts, type SessionOrigin, TOKEN_CLASSES, type TaskInitiative, type TokenClass, type WakeCauseBucket, type WakeGapCell, type WorkerFacts, type WorkerRole, type WrittenEpisodes, assignmentCount, bandOf, buildEpisodes, classifySession, contextBand, costReport, costReportSchema, findPrice, gapBand, heuristicFor, initiativeFromCwd, priceRequest, readEpisodeInput, renderCostReportText, roleFromProfile, sessionInitiative, sessionRole, workerRole, writeEpisodes };
|
|
1659
|
+
export { ACTION_CLASSES, AGENT_LIFECYCLE, ALL_REPOS, type ActionCall, type ActionClass, type ActionRule, type AgentNameRow, BLOCKED_FLOW_SOURCES, BOOT_TOOL, type Band, type BlockedFlowInput, type BlockedFlowReport, type BlockedFlowSource, type BrokerEntry, CHANNEL_CLUSTER_MS, CONTEXT_BANDS, CONTEXT_RESET_TOKENS, COORDINATOR_MERGE_DEDUPE_REQUESTS, COORDINATOR_MIN_EPISODE_REQUESTS, COORDINATOR_WAVE_QUIET_REQUESTS, COST_REPORT_SECTIONS, type CacheTtlBucket, type CacheTtlWhatIf, type CostBucket, type CostReport, type CostReportOptions, type CostReportSection, type CycleParams, DARK_MIN, DEFAULT_ACTION_RULES, DEFAULT_CONFIGURED_K, DEFAULT_EPISODE_ROLES, DEFAULT_K_SWEEP, DEFAULT_MECHANICAL_CLASSES, DEFAULT_NO_ACTION_CLASSES, DEFAULT_REVIEWER_PRS, DEFAULT_REVIEWER_ROLE, DEFAULT_STANDING_ROLE, type DarkGap, type DenialRecord, type EpisodeInbound, type EpisodeInput, type EpisodeNames, type EpisodeRequest, type EpisodeRequestRow, type EpisodeSignal, GAP_BANDS, HEURISTIC_VERSIONS, type HandoffCohort, type HandoffOptions, type HandoffRequestRow, type HandoffSession, type HandoffTeleport, type HandoffThreshold, type Heuristic, type HumanRole, IDLE_GAP_MS, type IdleSlotRow, type KSweep, LIST_PRICE_CAVEAT, LIVENESS_SOURCES, type LastEventRecord, type LatencyRow, type LatencyStats, type LivenessInput, type LivenessReport, type LivenessSource, type MechanicalShare, type MergeOutcome, type MergeStatus, POOLED_REVIEWERS, PRICE_TABLE, PRICE_TABLE_VERSION, PROFILE_ROLES, PROMPT_STALE_MIN, type ParsedVerdict, type PriceRow, type PricedRequest, type PullState, REBUILD_GAP_BANDS, type ReportScope, type ReportWindow, type RequestTokens, type ReviewerComparison, type RoleActions, type RouteFailureRow, type RouteMiss, type RouteMissKind, STANDING_PEER_MIN_ASSIGNMENTS, STANDING_PEER_MIN_HOURS, type SeatJournal, type SessionClass, type SessionClassification, type SessionFacts, type SessionOrigin, type SlotTick, type SpawnRecord, type StalePromptRow, TELEPORT_EVENT, TICK_HOLD_MAX_MIN, TOKEN_CLASSES, type TaskInitiative, type TeleportEvent, type TokenClass, type TtlRequestRow, UNKNOWN_PROFILE, UNSTATED_REASON, type UnreportedExit, type UnreportedExitRow, type VerdictRecord, WAKE_FROM_KINDS, type WakeCauseBucket, type WakeCauseEpisodes, type WakeEpisode, type WakeEpisodes, type WakeEventRow, type WakeFromKind, type WakeGapCell, type WakePair, type WorkerFacts, type WorkerRole, type WrittenEpisodes, assignmentCount, bandOf, blockedFlowReport, blockedFlowSchema, buildEpisodes, buildWakeEpisodes, cacheTtlReport, cacheTtlWhatIf, cacheTtlWhatIfSchema, classifyDeniedAction, classifyRequest, classifySession, contextBand, costPerRequest, costReport, costReportSchema, countMisses, darkGaps, dedupeDenials, episodeNames, findPrice, gapBand, handoffThreshold, handoffThresholdSchema, heuristicFor, idleSlotMinutes, initiativeFromCwd, isBootAction, latencyStats, latencyStatsSchema, livenessReport, livenessSchema, mergeOutcomes, parseBrokerLog, parseDenials, parseSeatJournal, parseTeleportEvents, parseVerdict, prKey, priceRequest, readEpisodeInput, readRequestToolCalls, readTtlRows, renderBlockedFlowText, renderCacheTtlText, renderCostReportSections, renderCostReportText, renderLivenessText, roleFromProfile, routeFailureRows, routeMisses, scopeFilter, sessionInitiative, sessionRole, stalePromptRows, summarizeWakeEpisodes, sweepK, unreportedExitRows, wakeEpisodesSchema, workerRole, writeEpisodes };
|