@orkestrel/study 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,1319 @@
1
+ import type { BudgetInterface } from '@orkestrel/budget';
2
+ import type { estimateRequest } from '@orkestrel/agent';
3
+ import type { Guard } from '@orkestrel/contract';
4
+ import type { isAgentError } from '@orkestrel/agent';
5
+ import type { JSONValue } from '@orkestrel/contract';
6
+ import type { JudgeInterface } from '@orkestrel/agent';
7
+ import type { JudgeRequest } from '@orkestrel/agent';
8
+ import type { JudgeResult } from '@orkestrel/agent';
9
+ import type { LedgerGauge } from '@orkestrel/agent';
10
+ import type { measureRequest } from '@orkestrel/agent';
11
+ import type { Message } from '@orkestrel/agent';
12
+ import type { ProviderDelta } from '@orkestrel/agent';
13
+ import type { ProviderInterface } from '@orkestrel/agent';
14
+ import type { ProviderRequest } from '@orkestrel/agent';
15
+ import type { ProviderResult } from '@orkestrel/agent';
16
+ import type { ProviderStreamOptions } from '@orkestrel/agent';
17
+ import type { RequestMeasure } from '@orkestrel/agent';
18
+ import type { ThinkingReplay } from '@orkestrel/agent';
19
+
20
+ /**
21
+ * Builds the evidence join of a wire request to its canonical dispatch.
22
+ * @param dispatch - The measured dispatch, or undefined when the caller measured none
23
+ * @returns The dispatch id and revision, each null when unknown
24
+ */
25
+ export declare function buildStudyAgentDispatch(dispatch: StudyAgentDispatch | undefined): Readonly<Record<string, JSONValue>>;
26
+
27
+ /**
28
+ * Projects a request's structural components onto plain JSON without storing a total.
29
+ * @param measure - The runtime's disjoint per-message, tools and schema estimates
30
+ * @returns The same components in request order
31
+ */
32
+ export declare function buildStudyAgentParts(measure: RequestMeasure): JSONValue;
33
+
34
+ /**
35
+ * Builds a bounded schedule from explicit repetition rows and declared scenarios.
36
+ * @param definition - The frozen population declaration
37
+ * @param scenarios - The complete scenario declarations
38
+ * @returns Owned trials in repetition, scenario and row-arm order
39
+ * @throws StudyError - Thrown when the population or scenario set is invalid
40
+ * @example
41
+ * ```ts
42
+ * buildStudySchedule(definition, scenarios)
43
+ * ```
44
+ */
45
+ export declare function buildStudySchedule(definition: StudyDefinition, scenarios: readonly StudyScenario[]): readonly StudyTrial[];
46
+
47
+ /**
48
+ * Computes the stop of a request whose actual usage crossed the ceiling it was admitted under.
49
+ * @param charge - The request's admitted ceilings
50
+ * @param usage - The request's measured usage
51
+ * @returns The `scope` stop for the first quantity, tokens then bytes, whose known usage exceeds its admitted ceiling; undefined when none does
52
+ * @example
53
+ * ```ts
54
+ * computeStudyAdmittedStop({ role: 'agent', tokens: 10, bytes: 100 }, usage) // { layer: 'scope', id: 'Admitted tokens', max: 10, consumed: 12 }
55
+ * ```
56
+ */
57
+ export declare function computeStudyAdmittedStop(charge: StudyCharge, usage: StudyUsage): StudyStop | undefined;
58
+
59
+ /**
60
+ * Computes the stop of a product the output allowances cannot hold.
61
+ * @param bytes - The encoded size of the product's value
62
+ * @param limit - The goal's byte allowance
63
+ * @param outputs - The trial and series output budgets, in the order they refuse
64
+ * @returns The `Goal bytes` stop when the goal allowance refuses, else the stop of the first budget whose remaining room is below the product, with its tally including the refused product; undefined when every allowance holds it
65
+ * @example
66
+ * ```ts
67
+ * computeStudyOutputStop(2048, 1024, []) // { layer: 'scope', id: 'Goal bytes', max: 1024, consumed: 2048 }
68
+ * ```
69
+ */
70
+ export declare function computeStudyOutputStop(bytes: number, limit: number, outputs: ReadonlyArray<BudgetInterface<number>>): StudyStop | undefined;
71
+
72
+ /**
73
+ * Computes arm intervals over the complete declared criterion horizon.
74
+ * @param manifest - The sealed population and schedule
75
+ * @param rubric - The criterion declaration
76
+ * @param grading - Judgments bound to the complete scheduled attempt set
77
+ * @returns Whole-horizon scores in declared arm order
78
+ * @throws StudyError - Thrown when schedule, attempts or judgments are incompatible
79
+ * @example
80
+ * ```ts
81
+ * computeStudyScores(manifest, rubric, grading)
82
+ * ```
83
+ */
84
+ export declare function computeStudyScores(manifest: StudyManifest, rubric: StudyRubric, grading: StudyGrading): readonly StudyScore[];
85
+
86
+ /**
87
+ * Records an error that escaped admitted work as the failure of its ticket.
88
+ * @param ticket - The admitted request whose work escaped
89
+ * @param error - The caught value, read through `readStudyFailure`
90
+ * @param role - The responsibility that replaces any role the reading carries; Default: the carried role, else the ticket's admitted role
91
+ * @remarks
92
+ * A ticket that already settled or whose signal aborted is left untouched, because its owner
93
+ * already holds the failure. A remote ticket's aborted signal does not mean it settled locally,
94
+ * so the parent's ownership is respected rather than inferred as local settlement. A refusal
95
+ * thrown by the ticket's own settlement propagates.
96
+ * @throws Thrown when the ticket's settlement refuses the failure.
97
+ * @example Fail an escaped request
98
+ * ```ts
99
+ * import type { StudyTicket } from '@orkestrel/study'
100
+ * import { failStudyTicket } from '@orkestrel/study'
101
+ *
102
+ * declare const ticket: StudyTicket
103
+ *
104
+ * failStudyTicket(ticket, new Error('Provider refused'), 'tool')
105
+ * ```
106
+ */
107
+ export declare function failStudyTicket(ticket: StudyTicket, error: unknown, role?: StudyRole): void;
108
+
109
+ /** Converts an operational reading to its throwable boundary.
110
+ * @param failure - The retained operational reading.
111
+ * @returns An error preserving the reading's cause and responsibility.
112
+ */
113
+ export declare function failureToStudyError(failure: StudyFailure): StudyError;
114
+
115
+ /**
116
+ * Checks whether a namespace exposes the Agent capabilities the instrumentation invokes.
117
+ * @remarks
118
+ * The guard reads only `estimateRequest`, `measureRequest`, and `isAgentError`, so a namespace
119
+ * without Ledger or conversation factories passes. A throwing accessor returns false.
120
+ * @param value - The admitted namespace
121
+ * @returns True if every required capability is a function; false otherwise
122
+ */
123
+ export declare function isStudyAgentRuntime(value: unknown): value is StudyAgentRuntime;
124
+
125
+ /**
126
+ * Checks whether nested scopes admit no larger allowance than their parent.
127
+ * @param value - The candidate bounds
128
+ * @returns True if every nested allowance is ordered; false otherwise
129
+ * @example
130
+ * ```ts
131
+ * isStudyBounds({}) // false
132
+ * ```
133
+ */
134
+ export declare function isStudyBounds(value: unknown): value is StudyBounds;
135
+
136
+ /** Checks whether a value names an operational ending. */
137
+ export declare const isStudyCause: Guard<StudyCause>;
138
+
139
+ /**
140
+ * Checks whether a criterion declares exact grading inputs and references.
141
+ * @param value - The candidate criterion
142
+ * @returns True if its structural grading declaration is valid; false otherwise
143
+ * @example
144
+ * ```ts
145
+ * isStudyCriterion({ id: 'saved', scenario: 'shift', goal: 'write', method: 'state', critical: true, assertion: true }) // true
146
+ * ```
147
+ */
148
+ export declare function isStudyCriterion(value: unknown): value is StudyCriterion;
149
+
150
+ /**
151
+ * Checks whether a study freezes a complete arm order for every repetition.
152
+ * @param value - The candidate definition
153
+ * @returns True if its population and repetition orders are valid; false otherwise
154
+ * @example
155
+ * ```ts
156
+ * isStudyDefinition({ name: 'tools' }) // false
157
+ * ```
158
+ */
159
+ export declare function isStudyDefinition(value: unknown): value is StudyDefinition;
160
+
161
+ /**
162
+ * Checks whether a byte identity is a lowercase SHA-256 digest.
163
+ * @param value - The candidate identity
164
+ * @returns True if it has exactly 64 hexadecimal digits; false otherwise
165
+ * @example
166
+ * ```ts
167
+ * isStudyDigest('a'.repeat(64)) // true
168
+ * ```
169
+ */
170
+ export declare function isStudyDigest(value: unknown): value is string;
171
+
172
+ /**
173
+ * Narrows a caught value to an attributable study error.
174
+ * @remarks
175
+ * Recognition combines the native `Error` base, a subclass prototype, the fixed name, a declared
176
+ * study code, and an own {@link STUDY_ERROR_BRAND} descriptor whose value is the error itself.
177
+ * The global key is recognized across package, ESM, CommonJS and captured module copies; it is
178
+ * not unforgeable provenance. A transparent proxy is refused because its forwarded descriptor
179
+ * stores the target, and an unbranded copy, an inherited brand, or a property-only lookalike
180
+ * stays outside the type. Hostile property access returns false instead of throwing.
181
+ * @param value - The caught value
182
+ * @returns True if the value is a study error; false otherwise
183
+ * @example
184
+ * ```ts
185
+ * isStudyError(new StudyError('CONFIG', 'missing definition')) // true
186
+ * ```
187
+ */
188
+ export declare function isStudyError(value: unknown): value is StudyError;
189
+
190
+ /**
191
+ * Checks whether a value names a supported study error code.
192
+ * @param value - The candidate code
193
+ * @returns True if it is a declared study error code; false otherwise
194
+ * @example
195
+ * ```ts
196
+ * isStudyErrorCode('CONFIG') // true
197
+ * ```
198
+ */
199
+ export declare function isStudyErrorCode(value: unknown): value is StudyErrorCode;
200
+
201
+ /**
202
+ * Checks whether a goal has a bounded identifier and exact JSON input.
203
+ * @param value - The candidate goal
204
+ * @returns True if the goal is valid; false otherwise
205
+ * @example
206
+ * ```ts
207
+ * isStudyGoal({ id: 'write', input: { text: 'hello' } }) // true
208
+ * ```
209
+ */
210
+ export declare function isStudyGoal(value: unknown): value is StudyGoal;
211
+
212
+ /**
213
+ * Checks whether grading binds accountable judgments to unique attempt identities.
214
+ * @param value - The candidate grading
215
+ * @returns True if its identities, attempts and judgments are valid; false otherwise
216
+ * @example
217
+ * ```ts
218
+ * isStudyGrading({}) // false
219
+ * ```
220
+ */
221
+ export declare function isStudyGrading(value: unknown): value is StudyGrading;
222
+
223
+ /**
224
+ * Checks whether a judgment carries a supported verdict and evidence references.
225
+ * @param value - The candidate judgment
226
+ * @returns True if the judgment is attributable and structurally valid; false otherwise
227
+ * @example
228
+ * ```ts
229
+ * isStudyJudgment({ trial: 'r1-s1-a1', criterion: 'saved', verdict: 'unknown', method: 'state', reason: 'No evidence', references: [] }) // true
230
+ * ```
231
+ */
232
+ export declare function isStudyJudgment(value: unknown): value is StudyJudgment;
233
+
234
+ /**
235
+ * Checks whether imported semantic labels have accountable packet provenance.
236
+ * @param value - The candidate labels
237
+ * @returns True if provenance, usage and semantic judgments are valid; false otherwise
238
+ * @example
239
+ * ```ts
240
+ * isStudyLabeling({}) // false
241
+ * ```
242
+ */
243
+ export declare function isStudyLabeling(value: unknown): value is StudyLabeling;
244
+
245
+ /** Checks whether a value names a ceiling a run can stop at. */
246
+ export declare const isStudyLayer: Guard<StudyLayer>;
247
+
248
+ /**
249
+ * Checks whether all allowances are positive safe integers within timer bounds.
250
+ * @param value - The candidate limit
251
+ * @returns True if it defines finite positive allowances; false otherwise
252
+ * @example
253
+ * ```ts
254
+ * isStudyLimit({ duration: 1000, calls: 1, tokens: 100, bytes: 1024 }) // true
255
+ * ```
256
+ */
257
+ export declare function isStudyLimit(value: unknown): value is StudyLimit;
258
+
259
+ /**
260
+ * Checks whether an identifier is portable and bounded.
261
+ * @param value - The candidate identifier
262
+ * @returns True if it is a portable study identifier; false otherwise
263
+ * @example
264
+ * ```ts
265
+ * isStudyName('memory') // true
266
+ * ```
267
+ */
268
+ export declare function isStudyName(value: unknown): value is string;
269
+
270
+ /**
271
+ * Checks a retained public product without awarding task achievement.
272
+ * @param value - The candidate product
273
+ * @returns True if the product carries JSON output and partial status; false otherwise
274
+ * @example
275
+ * ```ts
276
+ * isStudyProduct({ value: { answer: 1 }, partial: true }) // true
277
+ * ```
278
+ */
279
+ export declare function isStudyProduct(value: unknown): value is StudyProduct;
280
+
281
+ /**
282
+ * Checks whether a profile carries finite bounds and an optional explicit provider.
283
+ * @param value - The candidate profile
284
+ * @returns True if the profile is structurally valid; false otherwise
285
+ * @example
286
+ * ```ts
287
+ * isStudyProfile({ name: 'local' }) // false
288
+ * ```
289
+ */
290
+ export declare function isStudyProfile(value: unknown): value is StudyProfile;
291
+
292
+ /**
293
+ * Checks whether a provider declaration names artifacts, an HTTP origin and models.
294
+ * @param value - The candidate provider declaration
295
+ * @returns True if the declaration has a supported origin, nonempty names, and a judge declared with its digest or not at all; false otherwise
296
+ * @example
297
+ * ```ts
298
+ * isStudyProvider({ entry: 'dist/index.js' }) // false
299
+ * ```
300
+ */
301
+ export declare function isStudyProvider(value: unknown): value is StudyProvider;
302
+
303
+ /** Checks whether a value names a measured request role. */
304
+ export declare const isStudyRole: Guard<StudyRole>;
305
+
306
+ /**
307
+ * Checks whether generation room leaves positive context for input.
308
+ * @param value - The candidate room
309
+ * @returns True if input, output and safety allowances fit and any declared recap fits; false otherwise
310
+ * @example
311
+ * ```ts
312
+ * isStudyRoom({ context: 20480, output: 8192, safety: 512, recap: 2048, think: true }) // true
313
+ * isStudyRoom({ context: 20480, output: 8192, safety: 512, think: true }) // true
314
+ * ```
315
+ */
316
+ export declare function isStudyRoom(value: unknown): value is StudyRoom;
317
+
318
+ /**
319
+ * Checks whether a rubric declares nonempty criteria with unique identities.
320
+ * @param value - The candidate rubric
321
+ * @returns True if its version and criteria are valid; false otherwise
322
+ * @example
323
+ * ```ts
324
+ * isStudyRubric({ version: '1', criteria: [] }) // false
325
+ * ```
326
+ */
327
+ export declare function isStudyRubric(value: unknown): value is StudyRubric;
328
+
329
+ /**
330
+ * Checks whether a scenario declares a nonempty horizon with unique goal ids.
331
+ * @param value - The candidate scenario
332
+ * @returns True if the scenario has a valid horizon; false otherwise
333
+ * @example
334
+ * ```ts
335
+ * isStudyScenario({ id: 'shift', goals: [{ id: 'handoff', input: 'Prepare handoff' }] }) // true
336
+ * ```
337
+ */
338
+ export declare function isStudyScenario(value: unknown): value is StudyScenario;
339
+
340
+ /**
341
+ * Checks whether a value is the exact record of a ceiling that stopped a run.
342
+ * @remarks
343
+ * The guard accepts exact own data keys: `layer` and `id` are required and `max` and `consumed` are
344
+ * optional. `max` and `consumed` are each undefined or a finite number. Finite foreign readings,
345
+ * including negative and fractional values, retain the source's measurement unchanged.
346
+ * @param value - The candidate stop
347
+ * @returns True if the layer is known, the id is nonempty, and every reading is absent or finite; false otherwise
348
+ * @example
349
+ * ```ts
350
+ * isStudyStop({ layer: 'scope', id: 'Goal tokens', max: 100, consumed: 120 }) // true
351
+ * ```
352
+ */
353
+ export declare function isStudyStop(value: unknown): value is StudyStop;
354
+
355
+ /**
356
+ * Checks whether a timestamp is a canonical UTC millisecond instant.
357
+ * @param value - The candidate timestamp
358
+ * @returns True if it is a valid canonical timestamp; false otherwise
359
+ * @example
360
+ * ```ts
361
+ * isStudyTimestamp('2026-10-14T12:00:00.000Z') // true
362
+ * ```
363
+ */
364
+ export declare function isStudyTimestamp(value: unknown): value is string;
365
+
366
+ /**
367
+ * Checks whether request usage contains nonnegative safe measurements.
368
+ * @param value - The candidate usage
369
+ * @returns True if the role and every known measurement are valid; false otherwise
370
+ * @example
371
+ * ```ts
372
+ * isStudyUsage({ role: 'tool', calls: 0, bytes: 0, duration: 0 }) // true
373
+ * ```
374
+ */
375
+ export declare function isStudyUsage(value: unknown): value is StudyUsage;
376
+
377
+ /**
378
+ * Matches exact own enumerable data keys without evaluating accessors.
379
+ * @param value - The candidate record
380
+ * @param required - Required keys
381
+ * @param optional - Allowed optional keys
382
+ * @returns True if the record has exactly the allowed data keys; false otherwise
383
+ * @example Check exact keys
384
+ * ```ts
385
+ * import { matchesStudyKeys } from '@orkestrel/study'
386
+ *
387
+ * matchesStudyKeys({ id: 'one' }, ['id']) // true
388
+ * ```
389
+ */
390
+ export declare function matchesStudyKeys(value: unknown, required: readonly string[], optional?: readonly string[]): boolean;
391
+
392
+ /**
393
+ * Omits every undefined optional declaration so the profile has one JSON form.
394
+ * @param profile - The validated profile whose optional leaves may be undefined
395
+ * @returns The profile fields with absent qualification, settings, provider, judge and recap removed
396
+ * @example
397
+ * ```ts
398
+ * normalizeStudyProfile(profile) // no `recap` key when the room declares none
399
+ * ```
400
+ */
401
+ export declare function normalizeStudyProfile(profile: StudyProfile): Readonly<Record<string, unknown>>;
402
+
403
+ /**
404
+ * Copies the own entries of a record that hold a value, in their original order.
405
+ * @param value - The record whose undefined entries are absent declarations
406
+ * @returns A new record without the undefined entries
407
+ * @example
408
+ * ```ts
409
+ * omitStudyAbsent({ context: 512, recap: undefined }) // { context: 512 }
410
+ * ```
411
+ */
412
+ export declare function omitStudyAbsent(value: object): Readonly<Record<string, unknown>>;
413
+
414
+ /**
415
+ * Parses a definition into an independent frozen validated snapshot.
416
+ * @param value - The unknown configuration
417
+ * @returns The owned study definition
418
+ * @throws StudyError - Thrown when configuration is invalid or cannot be owned
419
+ * @example
420
+ * ```ts
421
+ * parseStudyDefinition(configuration)
422
+ * ```
423
+ */
424
+ export declare function parseStudyDefinition(value: unknown): StudyDefinition;
425
+
426
+ /**
427
+ * Parses grading into an independent frozen validated evidence snapshot.
428
+ * @param value - The unknown grading evidence
429
+ * @returns The owned grading identity and judgments
430
+ * @throws StudyError - Thrown when evidence is invalid or cannot be owned
431
+ * @example
432
+ * ```ts
433
+ * parseStudyGrading(evidence)
434
+ * ```
435
+ */
436
+ export declare function parseStudyGrading(value: unknown): StudyGrading;
437
+
438
+ /**
439
+ * Parses semantic labels into an independent frozen validated evidence snapshot.
440
+ * @param value - The unknown imported labels
441
+ * @returns The owned packet provenance, usage and judgments
442
+ * @throws StudyError - Thrown when evidence is invalid or cannot be owned
443
+ * @example
444
+ * ```ts
445
+ * parseStudyLabeling(evidence)
446
+ * ```
447
+ */
448
+ export declare function parseStudyLabeling(value: unknown): StudyLabeling;
449
+
450
+ /**
451
+ * Parses a profile into an independent frozen validated snapshot.
452
+ * @param value - The unknown configuration
453
+ * @returns The owned profile with absent optional settings preserved
454
+ * @throws StudyError - Thrown when configuration is invalid or cannot be owned
455
+ * @example
456
+ * ```ts
457
+ * parseStudyProfile(configuration)
458
+ * ```
459
+ */
460
+ export declare function parseStudyProfile(value: unknown): StudyProfile;
461
+
462
+ /**
463
+ * Parses a foreign reading into a number a stop can retain.
464
+ * @param value - The unknown reading a source reports
465
+ * @returns The value when it is a finite number; undefined otherwise
466
+ * @example
467
+ * ```ts
468
+ * parseStudyReading(2048) // 2048
469
+ * parseStudyReading(Number.NaN) // undefined
470
+ * ```
471
+ */
472
+ export declare function parseStudyReading(value: unknown): number | undefined;
473
+
474
+ /**
475
+ * Parses a rubric into an independent frozen validated snapshot.
476
+ * @param value - The unknown grading declaration
477
+ * @returns The owned rubric and assertion inputs
478
+ * @throws StudyError - Thrown when configuration is invalid or cannot be owned
479
+ * @example
480
+ * ```ts
481
+ * parseStudyRubric(configuration)
482
+ * ```
483
+ */
484
+ export declare function parseStudyRubric(value: unknown): StudyRubric;
485
+
486
+ /**
487
+ * Parses a scenario into an independent frozen validated snapshot.
488
+ * @param value - The unknown configuration
489
+ * @returns The owned scenario and goal inputs
490
+ * @throws StudyError - Thrown when configuration is invalid or cannot be owned
491
+ * @example
492
+ * ```ts
493
+ * parseStudyScenario({ id: 'shift', goals: [{ id: 'write', input: {} }] })
494
+ * ```
495
+ */
496
+ export declare function parseStudyScenario(value: unknown): StudyScenario;
497
+
498
+ /**
499
+ * Prices a runtime estimate through an explicit gauge.
500
+ * @param gauge - The declared scale and overhead
501
+ * @param estimate - The runtime's estimate of one complete request
502
+ * @returns The projected prompt tokens, rounded up
503
+ */
504
+ export declare function projectStudyAgentRequest(gauge: LedgerGauge, estimate: number): number;
505
+
506
+ /** Reads an operational error without inventing a task verdict.
507
+ * @remarks
508
+ * A branded `BudgetError` from any copy of the budget package reads as a `budget` stop, because the
509
+ * error alone does not prove which budget object raised it; the Agent record names a `meter` stop.
510
+ * An unbranded lookalike reads as an infrastructure failure.
511
+ * @param error - The caught error.
512
+ * @returns Existing attribution, the capacity a branded budget error names, the cause a bare
513
+ * capacity or deadline code names, or an infrastructure failure.
514
+ */
515
+ export declare function readStudyFailure(error: unknown): StudyFailure;
516
+
517
+ /** Lists every operational ending in report order. */
518
+ export declare const STUDY_CAUSES: readonly StudyCause[];
519
+
520
+ /**
521
+ * Keys the own self-identity every study error stamps on itself.
522
+ * @remarks
523
+ * The global symbol registry lets every package, ESM, CommonJS and captured copy read the same
524
+ * key. The registry makes the key discoverable; it is a recognition mechanism, not an
525
+ * unforgeable provenance marker.
526
+ */
527
+ export declare const STUDY_ERROR_BRAND: unique symbol;
528
+
529
+ /** Caps a declared scenario horizon before execution. */
530
+ export declare const STUDY_GOALS = 4096;
531
+
532
+ /** Lists every ceiling a run can stop at in report order. */
533
+ export declare const STUDY_LAYERS: readonly StudyLayer[];
534
+
535
+ /** Restricts identifiers to portable path-safe names. */
536
+ export declare const STUDY_NAME: RegExp;
537
+
538
+ /** Lists every measured request role in report order. */
539
+ export declare const STUDY_ROLES: readonly StudyRole[];
540
+
541
+ /** Caps a declared trial population before schedule allocation. */
542
+ export declare const STUDY_TRIALS = 4096;
543
+
544
+ /** Admits requests against enclosing limits before an adapter dispatches them. */
545
+ export declare interface StudyAdmissionInterface {
546
+ readonly signal: AbortSignal;
547
+ readonly usage: readonly StudyUsage[];
548
+ /** Resolves admission before dispatch; local meters may return the ticket synchronously. */
549
+ admit(charge: StudyCharge): StudyTicket | Promise<StudyTicket>;
550
+ }
551
+
552
+ /** Holds the trial-local canonical dispatch identity a wire request joins to. */
553
+ export declare interface StudyAgentDispatch {
554
+ readonly id: number;
555
+ /** Holds the SHA-256 revision of the canonical request, or undefined when it could not be rendered. */
556
+ readonly revision: string | undefined;
557
+ }
558
+
559
+ /** Latches a real judge's failure before an enclosing runtime can treat it as absent. */
560
+ export declare class StudyAgentJudge implements JudgeInterface {
561
+ #private;
562
+ /** Binds a real public judge to the trial's failure owner.
563
+ * @param judge - The admitted judge every question is delegated to.
564
+ * @param latch - The owner that retains the first operational failure.
565
+ */
566
+ constructor(judge: JudgeInterface, latch: StudyLatchInterface);
567
+ /** Reports the delegate's trace label. */
568
+ get id(): string;
569
+ /** Reports the delegate's backend name. */
570
+ get name(): string;
571
+ /** Reports the delegate's model identity. */
572
+ get model(): string;
573
+ /** Refuses dispatch after a retained failure and retains a thrown failure with its identity.
574
+ * @param request - The real classification request.
575
+ * @param signal - The caller's cancellation.
576
+ * @returns The unmodified judge result.
577
+ */
578
+ ask(request: JudgeRequest, signal: AbortSignal): Promise<JudgeResult>;
579
+ }
580
+
581
+ /** Reads each Agent request's size before delegating it unchanged to the real provider. */
582
+ export declare class StudyAgentObserver implements ProviderInterface {
583
+ #private;
584
+ /** Binds the real provider, the measuring runtime, the explicit gauge and usage policy, and the reading recorder.
585
+ * @param options - Delegate, measurement seam, and policies.
586
+ */
587
+ constructor(options: StudyAgentObserverOptions);
588
+ /** Reports the delegate's trace label. */
589
+ get id(): string;
590
+ /** Reports the delegate's backend name. */
591
+ get name(): string;
592
+ /** Reports the delegate's thinking replay policy; an absent policy is the declared `none`. */
593
+ get replay(): ThinkingReplay;
594
+ /** Records one reading, then awaits the real generation.
595
+ * @param messages - The conversation sent.
596
+ * @param signal - Bounds the request.
597
+ * @param tools - The tools advertised this turn.
598
+ * @param options - The per-call options.
599
+ * @returns The real provider's result.
600
+ */
601
+ generate(messages: readonly Message[], signal: AbortSignal, tools?: ProviderRequest['tools'], options?: ProviderStreamOptions): Promise<ProviderResult>;
602
+ /** Records one reading, then relays the real stream.
603
+ * @param messages - The conversation sent.
604
+ * @param signal - Bounds the request.
605
+ * @param tools - The tools advertised this turn.
606
+ * @param options - The per-call options.
607
+ * @returns The real deltas and result.
608
+ */
609
+ stream(messages: readonly Message[], signal: AbortSignal, tools?: ProviderRequest['tools'], options?: ProviderStreamOptions): AsyncGenerator<ProviderDelta, ProviderResult>;
610
+ }
611
+
612
+ /**
613
+ * Holds the observing provider's delegate, measurement seam and explicit policies.
614
+ * @remarks
615
+ * `provider` receives every call unchanged. `runtime` measures each request. `gauge` prices each
616
+ * reading; undefined prices nothing. `enforced` selects the usage policy: if `true`, a successful,
617
+ * unaborted return must report a usable actual prompt count; if `false`, the observer reads usage
618
+ * passively and refuses nothing. `record` receives exactly one reading, synchronously, before
619
+ * each delegated call.
620
+ */
621
+ export declare interface StudyAgentObserverOptions {
622
+ readonly provider: ProviderInterface;
623
+ readonly runtime: Pick<StudyAgentRuntime, 'estimateRequest'>;
624
+ readonly gauge: LedgerGauge | undefined;
625
+ readonly enforced: boolean;
626
+ readonly record: StudyAgentRecordHandler;
627
+ }
628
+
629
+ /** Holds one dispatched request's explicit size reading. */
630
+ export declare interface StudyAgentReading {
631
+ /** Holds the runtime's estimate of the complete pre-encoding request. */
632
+ readonly estimate: number;
633
+ /** Holds the gauge projection of that estimate; undefined when no gauge applies. */
634
+ readonly projected: number | undefined;
635
+ }
636
+
637
+ /** Receives one reading and the exact pre-encoding request it measured. */
638
+ export declare type StudyAgentRecordHandler = (reading: StudyAgentReading, request: ProviderRequest) => void;
639
+
640
+ /**
641
+ * Holds the admitted Agent namespace capabilities the shared instrumentation invokes.
642
+ * @remarks
643
+ * Each member has the exact signature of the export of the same name in the selected Agent
644
+ * runtime. The consumer supplies the admitted namespace; the instrumentation never imports a
645
+ * runtime value from an installed Agent copy. No Ledger capability is required.
646
+ */
647
+ export declare interface StudyAgentRuntime {
648
+ readonly estimateRequest: typeof estimateRequest;
649
+ readonly measureRequest: typeof measureRequest;
650
+ readonly isAgentError: typeof isAgentError;
651
+ }
652
+
653
+ /** Holds a terminal trial record, including goals never dispatched. */
654
+ export declare interface StudyAttempt {
655
+ readonly trial: StudyTrial;
656
+ readonly observations: readonly StudyObservation[];
657
+ readonly failure: StudyFailure | undefined;
658
+ readonly duration: number;
659
+ /** Records whether the trial entered execution without an inherited terminal series failure, including failures before the driver opened; not a claim that the driver was opened. */
660
+ readonly executed: boolean;
661
+ }
662
+
663
+ /** Holds nested execution allowances; each request also has a deadline. */
664
+ export declare interface StudyBounds {
665
+ readonly request: StudyLimit;
666
+ readonly goal: StudyLimit;
667
+ readonly trial: StudyLimit;
668
+ readonly series: StudyLimit;
669
+ }
670
+
671
+ /**
672
+ * Names an operational ending separately from task achievement.
673
+ * @remarks
674
+ * `content` means a request completed but its consumer refused the content as unusable. It
675
+ * claims no model or decoder cause and grades no semantic quality.
676
+ */
677
+ export declare type StudyCause = 'capacity' | 'infrastructure' | 'deadline' | 'interrupted' | 'content';
678
+
679
+ /** Holds a request's pre-dispatch upper bounds. */
680
+ export declare interface StudyCharge {
681
+ readonly role: StudyRole;
682
+ readonly tokens: number;
683
+ readonly bytes: number;
684
+ }
685
+
686
+ /** Holds the resources visible to one running goal. */
687
+ export declare interface StudyContext {
688
+ readonly signal: AbortSignal;
689
+ readonly meter: StudyAdmissionInterface;
690
+ readonly evidence: StudySinkInterface;
691
+ }
692
+
693
+ /** Retains the first operational failure while bounding asynchronous waits. */
694
+ export declare class StudyControl implements StudyControlInterface {
695
+ #private;
696
+ /** Links cancellation to the caller without assigning it a task verdict.
697
+ * @param signal - Optional parent cancellation.
698
+ */
699
+ constructor(signal?: AbortSignal);
700
+ get signal(): AbortSignal;
701
+ get failure(): StudyFailure | undefined;
702
+ /** Latches an operational failure and cancels all linked work.
703
+ * @param failure - The first attribution to preserve.
704
+ */
705
+ fail(failure: StudyFailure): void;
706
+ /** Races work against cancellation and removes its listener after either ending.
707
+ * @param work - Already-started work whose rejection remains observed after cancellation.
708
+ * @returns The work's result if it settles before cancellation.
709
+ * @throws Thrown with the retained operational attribution when cancelled.
710
+ */
711
+ wait<T>(work: PromiseLike<T>): Promise<T>;
712
+ /** Removes the lifecycle listener without changing the retained failure. */
713
+ close(): void;
714
+ }
715
+
716
+ /** Owns the first operational failure and cancellation of enclosing work. */
717
+ export declare interface StudyControlInterface {
718
+ readonly signal: AbortSignal;
719
+ readonly failure: StudyFailure | undefined;
720
+ /** Latches an operational failure and cancels all linked work.
721
+ * @param failure - The first attribution to preserve.
722
+ * @returns Nothing after failure propagation.
723
+ */
724
+ fail(failure: StudyFailure): void;
725
+ /** Races work against cancellation and removes its listener after either ending.
726
+ * @param work - Work whose late rejection remains observed.
727
+ * @returns The result when work settles before cancellation.
728
+ */
729
+ wait<T>(work: PromiseLike<T>): Promise<T>;
730
+ /** Removes the lifecycle listener without changing the retained failure.
731
+ * @returns Nothing after listener release.
732
+ */
733
+ close(): void;
734
+ }
735
+
736
+ /** Holds a grader-owned criterion outside the driver's public input. */
737
+ export declare interface StudyCriterion {
738
+ readonly id: string;
739
+ readonly scenario: string;
740
+ readonly goal: string;
741
+ readonly method: 'state' | 'trace' | 'semantic';
742
+ readonly critical: boolean;
743
+ readonly assertion: JSONValue;
744
+ }
745
+
746
+ /** Bounds each independent operation with a fresh failure owner and deadline. */
747
+ export declare class StudyDeadline implements StudyDeadlineInterface {
748
+ #private;
749
+ /** Retains the deadline without starting a timer.
750
+ * @param options - Finite duration in milliseconds and diagnostic label.
751
+ */
752
+ constructor(options: StudyDeadlineOptions);
753
+ /** Waits for work under a fresh failure owner and releases its timer and listener.
754
+ * @param work - Already-started work whose late rejection remains observed.
755
+ * @returns The work's result when it settles before the deadline.
756
+ * @throws Thrown for an invalid duration, the work's own rejection, or the labelled deadline.
757
+ */
758
+ wait<T>(work: PromiseLike<T>): Promise<T>;
759
+ }
760
+
761
+ /** Bounds one independent asynchronous operation under its own deadline. */
762
+ export declare interface StudyDeadlineInterface {
763
+ /** Waits for work under a fresh failure owner and releases its timer and listener.
764
+ * @param work - Already-started work whose late rejection remains observed.
765
+ * @returns The work's result when it settles before the deadline.
766
+ */
767
+ wait<T>(work: PromiseLike<T>): Promise<T>;
768
+ }
769
+
770
+ /** Supplies one bounded operation's finite deadline and diagnostic label. */
771
+ export declare interface StudyDeadlineOptions {
772
+ readonly duration: number;
773
+ readonly label: string;
774
+ }
775
+
776
+ /** Holds the frozen study question, population and explicit repetition orders. */
777
+ export declare interface StudyDefinition {
778
+ readonly name: string;
779
+ readonly version: string;
780
+ readonly question: string;
781
+ readonly purpose: StudyPurpose;
782
+ readonly driver: string;
783
+ readonly arms: readonly string[];
784
+ readonly scenarios: readonly string[];
785
+ readonly order: ReadonlyArray<readonly string[]>;
786
+ readonly retries: 0;
787
+ readonly rubric: string;
788
+ }
789
+
790
+ /** Creates isolated domain state through a concrete package consumer. */
791
+ export declare interface StudyDriverInterface {
792
+ /** Creates fresh domain state for one scheduled trial.
793
+ * @param trial - The scheduled scenario, arm, and repetition.
794
+ * @param signal - The caller's cancellation.
795
+ * @returns The isolated session for this trial.
796
+ */
797
+ open(trial: StudyTrial, signal: AbortSignal): Promise<StudySessionInterface>;
798
+ }
799
+
800
+ /** Reports a study contract or operational failure with a stable code. */
801
+ export declare class StudyError extends Error {
802
+ readonly code: StudyErrorCode;
803
+ readonly failure: StudyFailure | undefined;
804
+ /**
805
+ * Records the failing boundary and optional operational attribution.
806
+ * @param code - The machine-readable boundary
807
+ * @param message - The specific failure
808
+ * @param failure - The optional operational reading
809
+ */
810
+ constructor(code: StudyErrorCode, message: string, failure?: StudyFailure);
811
+ }
812
+
813
+ /** Names malformed configuration, evidence, custody and operational failures. */
814
+ export declare type StudyErrorCode = 'CONFIG' | 'EVIDENCE' | 'CUSTODY' | 'CAPACITY' | 'FAULT' | 'DEADLINE';
815
+
816
+ /** Holds append-only domain evidence in a JSON-compatible form. */
817
+ export declare interface StudyEvidence {
818
+ readonly event: string;
819
+ readonly goal: string;
820
+ readonly value: JSONValue;
821
+ }
822
+
823
+ /** Holds an attributable operational fault without awarding a task verdict. */
824
+ export declare interface StudyFailure {
825
+ readonly cause: StudyCause;
826
+ readonly message: string;
827
+ readonly role: StudyRole | undefined;
828
+ /** Names the ceiling that stopped the run; undefined for a failure no ceiling caused, and for a record sealed before this member existed. */
829
+ readonly stop: StudyStop | undefined;
830
+ }
831
+
832
+ /** Holds a declared goal's public input without its grading truth. */
833
+ export declare interface StudyGoal {
834
+ readonly id: string;
835
+ readonly input: JSONValue;
836
+ }
837
+
838
+ /** Holds a grading identity that cannot replace or mutate execution bytes. */
839
+ export declare interface StudyGrading {
840
+ readonly result: string;
841
+ readonly rubric: string;
842
+ readonly grader: string;
843
+ readonly instrument: string;
844
+ readonly attempts: readonly string[];
845
+ readonly labels: string | undefined;
846
+ /** Binds the retained public packet and private mapping when semantic criteria exist. */
847
+ readonly packet?: string;
848
+ readonly judgments: readonly StudyJudgment[];
849
+ }
850
+
851
+ /** Holds byte identities that qualification and comparisons must agree on. */
852
+ export declare interface StudyIdentity {
853
+ readonly agent: string;
854
+ readonly subject: string;
855
+ readonly provider: string | undefined;
856
+ readonly instrument: string;
857
+ readonly fixtures: string;
858
+ readonly profile: string;
859
+ }
860
+
861
+ /** Holds an evidence-backed verdict; missing evidence stays unknown. */
862
+ export declare interface StudyJudgment {
863
+ readonly trial: string;
864
+ readonly criterion: string;
865
+ readonly verdict: 'achieved' | 'unsuccessful' | 'unknown';
866
+ readonly method: 'state' | 'trace' | 'human' | 'model';
867
+ readonly reason: string;
868
+ readonly references: readonly string[];
869
+ }
870
+
871
+ /** Holds imported semantic judgments and their accountable origin. */
872
+ export declare interface StudyLabeling {
873
+ readonly packet: string;
874
+ readonly labeler: string;
875
+ readonly version: string;
876
+ readonly created: string;
877
+ readonly usage: readonly StudyUsage[];
878
+ readonly judgments: readonly StudyJudgment[];
879
+ }
880
+
881
+ /** Retains the first operational failure of instrumented work and refuses work after it. */
882
+ export declare interface StudyLatchInterface {
883
+ /** Refuses work after a retained failure or cancellation.
884
+ * @returns Nothing when work may continue.
885
+ */
886
+ check(): void;
887
+ /** Retains an operational failure even when an enclosing runtime catches it.
888
+ * @param error - The observed failure; an earlier retained failure keeps its identity, and a branded `BudgetError` can retain nothing because Agent reports that stop in its own result.
889
+ * @returns Nothing after retention.
890
+ */
891
+ fail(error: unknown): void;
892
+ }
893
+
894
+ /**
895
+ * Names the ceiling that stopped a run.
896
+ * @remarks
897
+ * `scope` is a limit Study declares: the calls, tokens, bytes, or duration of a request, goal,
898
+ * trial, series, or operation, the product output allowance, and a provider's declared byte bound.
899
+ * `window` is a prompt room. `custody` is an evidence allowance. `meter`, `budget`, and `model`
900
+ * mirror the `layer` of the `AgentStop` type from `@orkestrel/agent`: the run's estimate allowance,
901
+ * any other budget, and the model's own token limit, which also names the daemon's context and
902
+ * output caps.
903
+ */
904
+ export declare type StudyLayer = 'scope' | 'window' | 'custody' | 'meter' | 'budget' | 'model';
905
+
906
+ /** Holds finite allowances in milliseconds, calls, tokens and bytes. */
907
+ export declare interface StudyLimit {
908
+ readonly duration: number;
909
+ readonly calls: number;
910
+ readonly tokens: number;
911
+ readonly bytes: number;
912
+ }
913
+
914
+ /** Holds the execution declaration sealed before any trial begins. */
915
+ export declare interface StudyManifest {
916
+ readonly id: string;
917
+ readonly created: string;
918
+ readonly definition: StudyDefinition;
919
+ readonly scenarios: readonly StudyScenario[];
920
+ readonly identity: StudyIdentity;
921
+ readonly schedule: readonly StudyTrial[];
922
+ readonly bounds: StudyBounds;
923
+ readonly qualification: string | undefined;
924
+ readonly host: Readonly<Record<string, string>>;
925
+ }
926
+
927
+ /** Admits request ceilings across every enclosing scope before dispatch. */
928
+ export declare class StudyMeter implements StudyMeterInterface {
929
+ #private;
930
+ /** Holds the goal's shared admission scopes.
931
+ * @param options - Request bound, enclosing scopes, and shared failure owner.
932
+ */
933
+ constructor(options: StudyMeterOptions);
934
+ get signal(): AbortSignal;
935
+ get usage(): readonly StudyUsage[];
936
+ /** Reserves one request atomically across all enclosing allowances.
937
+ * @param charge - Safe integer token and byte ceilings with the request's role.
938
+ * @returns A request ticket that must settle before the goal completes.
939
+ * @throws Thrown before dispatch if the request exceeds available capacity.
940
+ */
941
+ admit(charge: StudyCharge): StudyTicket;
942
+ /** Refuses unfinished requests before closing a goal's admission boundary. */
943
+ close(): void;
944
+ }
945
+
946
+ /** Owns request admission and the goal's terminal lifecycle. */
947
+ export declare interface StudyMeterInterface extends StudyAdmissionInterface {
948
+ /** Refuses unfinished requests before closing a goal's admission boundary.
949
+ * @returns Nothing after admission closes.
950
+ */
951
+ close(): void;
952
+ }
953
+
954
+ /** Supplies the request allowance and all enclosing admission scopes. */
955
+ export declare interface StudyMeterOptions {
956
+ readonly request: StudyLimit;
957
+ readonly scopes: readonly StudyScopeInterface[];
958
+ readonly control: StudyControlInterface;
959
+ }
960
+
961
+ /** Holds the retained outcome of a scheduled goal. */
962
+ export declare interface StudyObservation {
963
+ readonly goal: string;
964
+ readonly product: StudyProduct | undefined;
965
+ readonly failure: StudyFailure | undefined;
966
+ readonly usage: readonly StudyUsage[];
967
+ readonly duration: number;
968
+ /** Records whether the engine dispatched the goal to the session; never inferred from product, usage, duration or failure. */
969
+ readonly executed: boolean;
970
+ }
971
+
972
+ /** Holds observed output and partial completion, never self-awarded success. */
973
+ export declare interface StudyProduct {
974
+ readonly value: JSONValue;
975
+ readonly partial: boolean;
976
+ }
977
+
978
+ /** Holds execution settings independently of scenario and grading declarations. */
979
+ export declare interface StudyProfile {
980
+ readonly name: string;
981
+ /** Selects the Agent runtime entry, independently of the package under study. */
982
+ readonly agent: string;
983
+ /** Selects the entry of the package under study; it can equal the Agent entry. */
984
+ readonly subject: string;
985
+ readonly roots: readonly string[];
986
+ readonly bounds: StudyBounds;
987
+ readonly room: StudyRoom;
988
+ readonly provider: StudyProvider | undefined;
989
+ readonly qualification: string | undefined;
990
+ /** Holds driver-owned JSON; the driver owns its interpretation and Study only validates and owns the object. */
991
+ readonly settings: Readonly<Record<string, JSONValue>> | undefined;
992
+ }
993
+
994
+ /** Holds caller-selected provider artifacts and model identities. */
995
+ export declare interface StudyProvider {
996
+ readonly entry: string;
997
+ readonly url: string;
998
+ readonly model: string;
999
+ /** Names the judge model; declared together with its digest or both absent. */
1000
+ readonly judge: string | undefined;
1001
+ /** Pins the serving inventory independently of mutable model names. */
1002
+ readonly digest: {
1003
+ readonly model: string;
1004
+ /** Pins the judge model; declared together with its name or both absent. */
1005
+ readonly judge: string | undefined;
1006
+ };
1007
+ }
1008
+
1009
+ /** Names the evidence a study can establish. */
1010
+ export declare type StudyPurpose = 'mechanism' | 'quality' | 'capacity';
1011
+
1012
+ /** Settles an admitted request once and propagates operational failure to its owner. */
1013
+ export declare class StudyRequest implements StudyTicket {
1014
+ #private;
1015
+ /** Starts the request deadline after its enclosing scopes reserve capacity.
1016
+ * @param options - Admitted ceilings, request deadline, and settlement callback.
1017
+ */
1018
+ constructor(options: StudyRequestOptions);
1019
+ get signal(): AbortSignal;
1020
+ get settled(): boolean;
1021
+ /** Retains actual measurements and refuses invalid or excessive charges.
1022
+ * @param usage - Measurements attributed to exactly this request.
1023
+ * @throws Thrown when settlement is late, repeated, invalid, or beyond admission.
1024
+ */
1025
+ finish(usage: StudyUsage): void;
1026
+ /** Retains unknown cost conservatively and latches the first operational failure.
1027
+ * @param failure - The operational request failure.
1028
+ * @throws Thrown when this request was already settled.
1029
+ */
1030
+ fail(failure: StudyFailure): void;
1031
+ }
1032
+
1033
+ /** Supplies one admitted request with its shared failure owner and settlement sink. */
1034
+ export declare interface StudyRequestOptions {
1035
+ readonly charge: StudyCharge;
1036
+ readonly duration: number;
1037
+ readonly control: StudyControlInterface;
1038
+ readonly settle: StudySettlementHandler;
1039
+ }
1040
+
1041
+ /** Names a request's measured responsibility. */
1042
+ export declare type StudyRole = 'agent' | 'judge' | 'summary' | 'metadata' | 'tool';
1043
+
1044
+ /** Holds the model context and generation allowance as separate measurements. */
1045
+ export declare interface StudyRoom {
1046
+ readonly context: number;
1047
+ readonly output: number;
1048
+ readonly safety: number;
1049
+ /** Declares the recap allowance; absent when the workflow produces no recap. */
1050
+ readonly recap: number | undefined;
1051
+ readonly think: boolean;
1052
+ }
1053
+
1054
+ /** Holds a versioned grading declaration independently of execution. */
1055
+ export declare interface StudyRubric {
1056
+ readonly version: string;
1057
+ readonly criteria: readonly StudyCriterion[];
1058
+ }
1059
+
1060
+ /** Holds ordered goals sharing state within an isolated trial. */
1061
+ export declare interface StudyScenario {
1062
+ readonly id: string;
1063
+ readonly goals: readonly StudyGoal[];
1064
+ }
1065
+
1066
+ /** Reserves finite request ceilings around cumulative actual budgets and one deadline. */
1067
+ export declare class StudyScope implements StudyScopeInterface {
1068
+ #private;
1069
+ /** Starts a timed scope with independent counters.
1070
+ * @param options - Finite limit, shared failure owner, and diagnostic label.
1071
+ */
1072
+ constructor(options: StudyScopeOptions);
1073
+ /** Checks cumulative consumption and every pending ceiling before admission.
1074
+ * @param charge - One prospective request's ceilings.
1075
+ * @throws Thrown when this scope cannot admit the request.
1076
+ */
1077
+ check(charge?: StudyCharge): void;
1078
+ /** Reserves one request after the enclosing meter checked all scopes.
1079
+ * @param id - The request's unique reservation identity.
1080
+ * @param charge - Its admitted ceilings.
1081
+ */
1082
+ reserve(id: symbol, charge: StudyCharge): void;
1083
+ /** Commits known charges while retaining ceilings for missing measurements.
1084
+ * @param id - The pending reservation identity.
1085
+ * @param usage - The request's retained public measurements.
1086
+ */
1087
+ settle(id: symbol, usage: StudyUsage): void;
1088
+ /** Checks deadline attribution before clearing the timer. */
1089
+ close(): void;
1090
+ }
1091
+
1092
+ /** Holds cumulative admission ceilings for one timed execution scope. */
1093
+ export declare interface StudyScopeInterface {
1094
+ /** Checks cumulative consumption and every pending ceiling before admission.
1095
+ * @param charge - The prospective request's ceilings, when supplied.
1096
+ * @returns Nothing when admission remains possible.
1097
+ */
1098
+ check(charge?: StudyCharge): void;
1099
+ /** Reserves one request after the enclosing meter checked all scopes.
1100
+ * @param id - The reservation identity.
1101
+ * @param charge - The admitted ceilings.
1102
+ * @returns Nothing after reservation.
1103
+ */
1104
+ reserve(id: symbol, charge: StudyCharge): void;
1105
+ /** Commits known charges while retaining ceilings for missing measurements.
1106
+ * @param id - The pending reservation identity.
1107
+ * @param usage - The retained public measurements.
1108
+ * @returns Nothing after settlement.
1109
+ */
1110
+ settle(id: symbol, usage: StudyUsage): void;
1111
+ /** Checks deadline attribution before clearing the timer.
1112
+ * @returns Nothing after resource release.
1113
+ */
1114
+ close(): void;
1115
+ }
1116
+
1117
+ /** Supplies one deadline and its shared failure owner. */
1118
+ export declare interface StudyScopeOptions {
1119
+ readonly limit: StudyLimit;
1120
+ readonly control: StudyControlInterface;
1121
+ readonly label: string;
1122
+ }
1123
+
1124
+ /** Holds an arm's whole-horizon counts without hiding unresolved criteria. */
1125
+ export declare interface StudyScore {
1126
+ readonly arm: string;
1127
+ readonly total: number;
1128
+ readonly achieved: number;
1129
+ readonly unsuccessful: number;
1130
+ readonly unknown: number;
1131
+ readonly critical: number;
1132
+ readonly lower: number;
1133
+ readonly upper: number;
1134
+ readonly coverage: number;
1135
+ }
1136
+
1137
+ /** Executes a frozen serial study schedule with finite admission and sticky failures. */
1138
+ export declare class StudySeries {
1139
+ #private;
1140
+ /** Owns the declared inputs while retaining the concrete driver and custody store.
1141
+ * @param options - Frozen manifest, concrete adapters, and parent cancellation.
1142
+ */
1143
+ constructor(options: StudySeriesOptions);
1144
+ /** Runs every declared trial once and retains explicit unexecuted observations after failure.
1145
+ * Custody rejection leaves the run unsealed; callers must seal only a fulfilled execution.
1146
+ * @returns Ordered terminal attempts without task success labels.
1147
+ * @throws Thrown for invalid configuration or failed or timed out custody operations.
1148
+ */
1149
+ execute(): Promise<readonly StudyAttempt[]>;
1150
+ }
1151
+
1152
+ /** Holds the common engine's fixed execution inputs. */
1153
+ export declare interface StudySeriesOptions {
1154
+ readonly manifest: StudyManifest;
1155
+ readonly driver: StudyDriverInterface;
1156
+ readonly store: StudyStoreInterface;
1157
+ readonly signal: AbortSignal;
1158
+ }
1159
+
1160
+ /** Owns domain state across a trial and releases it before the next trial. */
1161
+ export declare interface StudySessionInterface {
1162
+ /** Executes one public goal against the trial's retained domain state.
1163
+ * @param goal - The declared public input.
1164
+ * @param context - Cancellation, borrowed admission, and evidence custody.
1165
+ * @returns The observed product without a task verdict.
1166
+ */
1167
+ execute(goal: StudyGoal, context: StudyContext): Promise<StudyProduct>;
1168
+ /** Releases the trial's domain resources.
1169
+ * @returns A promise that resolves after release.
1170
+ */
1171
+ close(): Promise<void>;
1172
+ }
1173
+
1174
+ /** Records the settlement of one admitted request. */
1175
+ export declare type StudySettlementHandler = (usage: StudyUsage) => void;
1176
+
1177
+ /** Holds an evidence sink whose implementation owns byte limits and custody. */
1178
+ export declare interface StudySinkInterface {
1179
+ /** Appends bounded domain evidence to the owned execution record.
1180
+ * @param evidence - The public evidence for a declared goal.
1181
+ * @returns A promise that resolves when custody accepts the bytes.
1182
+ */
1183
+ append(evidence: StudyEvidence): Promise<void>;
1184
+ }
1185
+
1186
+ /**
1187
+ * Holds the ceiling that stopped a run and the readings it crossed.
1188
+ * @remarks
1189
+ * `id` names the ceiling: a Study label and quantity such as `Goal tokens`, an Agent budget's trace
1190
+ * id, or the provider option that capped the model such as `num_predict`. `max` is the ceiling and
1191
+ * `consumed` the tally at the crossing, the refused charge included; each is undefined when its
1192
+ * source reports none. On the `model` layer `max` is the cap and `consumed` the completion or prompt.
1193
+ * Finite foreign readings retain their source values, including negative and fractional values.
1194
+ */
1195
+ export declare interface StudyStop {
1196
+ readonly layer: StudyLayer;
1197
+ readonly id: string;
1198
+ readonly max: number | undefined;
1199
+ readonly consumed: number | undefined;
1200
+ }
1201
+
1202
+ /**
1203
+ * Projects a stop onto JSON with every unreported reading as null.
1204
+ * @param stop - The ceiling that stopped a run
1205
+ * @returns The stop's layer, id, and readings, with an undefined `max` or `consumed` as null
1206
+ * @example
1207
+ * ```ts
1208
+ * studyStopToJSON({ layer: 'model', id: 'num_predict', max: 2048, consumed: undefined })
1209
+ * // { layer: 'model', id: 'num_predict', max: 2048, consumed: null }
1210
+ * ```
1211
+ */
1212
+ export declare function studyStopToJSON(stop: StudyStop): JSONValue;
1213
+
1214
+ /** Appends terminal records without overwriting a prior attempt. */
1215
+ export declare interface StudyStoreInterface {
1216
+ /** Opens append-only evidence custody for one scheduled trial.
1217
+ * @param trial - The exact scheduled trial.
1218
+ * @returns The borrowed evidence sink.
1219
+ */
1220
+ start(trial: StudyTrial): Promise<StudySinkInterface>;
1221
+ /** Retains the terminal record for one scheduled trial.
1222
+ * @param attempt - The complete scheduled goal horizon.
1223
+ * @returns A promise that resolves after custody retains the record.
1224
+ */
1225
+ finish(attempt: StudyAttempt): Promise<void>;
1226
+ }
1227
+
1228
+ /** Holds one admitted request until its actual charge is recorded. */
1229
+ export declare interface StudyTicket {
1230
+ readonly signal: AbortSignal;
1231
+ /** Reports whether this ticket already recorded its own settlement; an aborted signal does not establish it. */
1232
+ readonly settled: boolean;
1233
+ /** Records actual measurements for one admitted request.
1234
+ * @param usage - The request's measured charges.
1235
+ * @returns Nothing after settlement.
1236
+ */
1237
+ finish(usage: StudyUsage): void;
1238
+ /** Records an attributable failure for one admitted request.
1239
+ * @param failure - The retained operational attribution.
1240
+ * @returns Nothing after failure propagation.
1241
+ */
1242
+ fail(failure: StudyFailure): void;
1243
+ }
1244
+
1245
+ /** Holds a scheduled trajectory, with a fresh state for each repetition and arm. */
1246
+ export declare interface StudyTrial {
1247
+ readonly id: string;
1248
+ readonly scenario: string;
1249
+ readonly arm: string;
1250
+ readonly repetition: number;
1251
+ }
1252
+
1253
+ /** Holds actual request measurements; absent token usage remains unknown. */
1254
+ export declare interface StudyUsage {
1255
+ readonly role: StudyRole;
1256
+ readonly calls: number;
1257
+ readonly tokens: number | undefined;
1258
+ readonly bytes: number | undefined;
1259
+ readonly duration: number;
1260
+ }
1261
+
1262
+ /**
1263
+ * Translates only a nominal Agent window refusal into the attributable capacity failure.
1264
+ * @remarks
1265
+ * The failure's stop is the `window` layer with the id `Agent window`; its `max` is the window and
1266
+ * its `consumed` the measured request, each read from the error's context when it is a finite
1267
+ * number.
1268
+ * @param error - The caught or reported value
1269
+ * @param runtime - The admitted Agent namespace owning the nominal guard
1270
+ * @returns A capacity StudyError for an Agent `WINDOW` error; every other value with its identity
1271
+ */
1272
+ export declare function translateStudyAgentError(error: unknown, runtime: Pick<StudyAgentRuntime, 'isAgentError'>): unknown;
1273
+
1274
+ /**
1275
+ * Translates an Agent run's stop record into the attributable capacity failure of the layer that stopped it.
1276
+ * @remarks
1277
+ * The record is foreign data from the admitted runtime, so the helper reads it once, each member
1278
+ * once, inside one contained boundary, and validates only the members it dereferences. A `meter`
1279
+ * or `budget` stop always leaves the run partial; a `model` stop is a complete answer, so a
1280
+ * consumer whose role admits a `length` finish keeps it. The consumer throws the returned error
1281
+ * when its policy refuses the stop. A `model` stop reports no cap because the Agent does not see
1282
+ * one; its `consumed` is the completion the stopped call reported, when finite.
1283
+ * @param stop - The `stop` member of an Agent or Ledger result
1284
+ * @returns Undefined when `stop` is undefined; a `CAPACITY` StudyError with role `agent` and the Agent layer for a meter, budget, or model stop; a `FAULT` StudyError with role `agent` for a malformed record
1285
+ * @example
1286
+ * ```ts
1287
+ * translateStudyAgentStop({ layer: 'meter', id: 'meter', max: 2000, consumed: 2001 })
1288
+ * // a CAPACITY StudyError whose failure.stop is { layer: 'meter', id: 'meter', max: 2000, consumed: 2001 }
1289
+ * ```
1290
+ */
1291
+ export declare function translateStudyAgentStop(stop: unknown): StudyError | undefined;
1292
+
1293
+ /**
1294
+ * Checks that a successful provider call reported a usable actual prompt count.
1295
+ * @remarks
1296
+ * The check compares nothing with a forecast; room enforcement stays with the transport.
1297
+ * @param usage - The usage a successful provider call reported
1298
+ * @param role - The responsibility whose request was dispatched; the failure retains it
1299
+ * @returns Nothing when the prompt count is finite and positive
1300
+ * @throws StudyError - Thrown with code `FAULT` when the prompt count is missing, not finite, or not positive
1301
+ */
1302
+ export declare function validateStudyAgentUsage(usage: ProviderResult['usage'], role: StudyRole): void;
1303
+
1304
+ /**
1305
+ * Validates grading coverage and request room against the declared study inputs.
1306
+ * @param definition - The population declaration
1307
+ * @param scenarios - The complete scenario declarations
1308
+ * @param rubric - The independently held grading declaration
1309
+ * @param profile - The execution bounds and model room
1310
+ * @returns Nothing when every cross-input invariant holds
1311
+ * @throws StudyError - Thrown when any input or cross-reference is invalid
1312
+ * @example
1313
+ * ```ts
1314
+ * validateStudyInputs(definition, scenarios, rubric, profile)
1315
+ * ```
1316
+ */
1317
+ export declare function validateStudyInputs(definition: StudyDefinition, scenarios: readonly StudyScenario[], rubric: StudyRubric, profile: StudyProfile): void;
1318
+
1319
+ export { }