@orkestrel/study 0.0.0-stage → 0.0.2

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