@orkestrel/study 0.0.1 → 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.
@@ -112,6 +112,17 @@ export declare function failStudyTicket(ticket: StudyTicket, error: unknown, rol
112
112
  */
113
113
  export declare function failureToStudyError(failure: StudyFailure): StudyError;
114
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
+
115
126
  /**
116
127
  * Checks whether a namespace exposes the Agent capabilities the instrumentation invokes.
117
128
  * @remarks
@@ -170,10 +181,11 @@ export declare function isStudyDefinition(value: unknown): value is StudyDefinit
170
181
  export declare function isStudyDigest(value: unknown): value is string;
171
182
 
172
183
  /**
173
- * Narrows a caught value to an attributable study error.
184
+ * Narrows a caught value to a branded study error with valid failure attribution.
174
185
  * @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.
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.
177
189
  * The global key is recognized across package, ESM, CommonJS and captured module copies; it is
178
190
  * not unforgeable provenance. A transparent proxy is refused because its forwarded descriptor
179
191
  * stores the target, and an unbranded copy, an inherited brand, or a property-only lookalike
@@ -1308,7 +1320,7 @@ export declare function validateStudyAgentUsage(usage: ProviderResult['usage'],
1308
1320
  * @param rubric - The independently held grading declaration
1309
1321
  * @param profile - The execution bounds and model room
1310
1322
  * @returns Nothing when every cross-input invariant holds
1311
- * @throws StudyError - Thrown when any input or cross-reference is invalid
1323
+ * @throws StudyError - Thrown when any input or cross-reference is invalid, or a quality study has no capacity qualification
1312
1324
  * @example
1313
1325
  * ```ts
1314
1326
  * validateStudyInputs(definition, scenarios, rubric, profile)
@@ -112,6 +112,17 @@ export declare function failStudyTicket(ticket: StudyTicket, error: unknown, rol
112
112
  */
113
113
  export declare function failureToStudyError(failure: StudyFailure): StudyError;
114
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
+
115
126
  /**
116
127
  * Checks whether a namespace exposes the Agent capabilities the instrumentation invokes.
117
128
  * @remarks
@@ -170,10 +181,11 @@ export declare function isStudyDefinition(value: unknown): value is StudyDefinit
170
181
  export declare function isStudyDigest(value: unknown): value is string;
171
182
 
172
183
  /**
173
- * Narrows a caught value to an attributable study error.
184
+ * Narrows a caught value to a branded study error with valid failure attribution.
174
185
  * @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.
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.
177
189
  * The global key is recognized across package, ESM, CommonJS and captured module copies; it is
178
190
  * not unforgeable provenance. A transparent proxy is refused because its forwarded descriptor
179
191
  * stores the target, and an unbranded copy, an inherited brand, or a property-only lookalike
@@ -1308,7 +1320,7 @@ export declare function validateStudyAgentUsage(usage: ProviderResult['usage'],
1308
1320
  * @param rubric - The independently held grading declaration
1309
1321
  * @param profile - The execution bounds and model room
1310
1322
  * @returns Nothing when every cross-input invariant holds
1311
- * @throws StudyError - Thrown when any input or cross-reference is invalid
1323
+ * @throws StudyError - Thrown when any input or cross-reference is invalid, or a quality study has no capacity qualification
1312
1324
  * @example
1313
1325
  * ```ts
1314
1326
  * validateStudyInputs(definition, scenarios, rubric, profile)
@@ -1,4 +1,4 @@
1
- import { attempt, canonicalStringify, cloneJSONValue, holds, isArray, isError, isFiniteNumber, isJSONValue, isNonEmptyString, isObject, isRecord, literalOf } from "@orkestrel/contract";
1
+ import { INTRINSICS, attempt, canonicalStringify, cloneJSONValue, holds, isArray, isError, isFiniteNumber, isJSONValue, isNonEmptyString, isObject, isRecord, literalOf } from "@orkestrel/contract";
2
2
  import { MAX_TIMEOUT_MS, Timeout } from "@orkestrel/timeout";
3
3
  import { Budget, isBudgetError } from "@orkestrel/budget";
4
4
  import { Abort, linkSignal } from "@orkestrel/abort";
@@ -149,7 +149,7 @@ function buildStudySchedule(definition, scenarios) {
149
149
  * @param rubric - The independently held grading declaration
150
150
  * @param profile - The execution bounds and model room
151
151
  * @returns Nothing when every cross-input invariant holds
152
- * @throws StudyError - Thrown when any input or cross-reference is invalid
152
+ * @throws StudyError - Thrown when any input or cross-reference is invalid, or a quality study has no capacity qualification
153
153
  * @example
154
154
  * ```ts
155
155
  * validateStudyInputs(definition, scenarios, rubric, profile)
@@ -166,6 +166,7 @@ function validateStudyInputs(definition, scenarios, rubric, profile) {
166
166
  }
167
167
  const covered = new Set(rubric.criteria.map((criterion) => canonicalStringify([criterion.scenario, criterion.goal]) ?? ""));
168
168
  for (const scenario of scenarios) for (const goal of scenario.goals) if (!covered.has(canonicalStringify([scenario.id, goal.id]) ?? "")) throw new StudyError("CONFIG", "Every declared goal needs a criterion");
169
+ if (definition.purpose === "quality" && profile.qualification === void 0) throw new StudyError("CONFIG", "Quality studies require a capacity qualification");
169
170
  }
170
171
  /**
171
172
  * Computes arm intervals over the complete declared criterion horizon.
@@ -630,8 +631,10 @@ var StudyError = class extends Error {
630
631
  */
631
632
  constructor(code, message, failure) {
632
633
  super(message);
633
- Object.defineProperty(this, STUDY_ERROR_BRAND, {
634
+ INTRINSICS.define(this, STUDY_ERROR_BRAND, {
634
635
  value: this,
636
+ enumerable: false,
637
+ writable: false,
635
638
  configurable: true
636
639
  });
637
640
  this.name = "StudyError";
@@ -640,10 +643,11 @@ var StudyError = class extends Error {
640
643
  }
641
644
  };
642
645
  /**
643
- * Narrows a caught value to an attributable study error.
646
+ * Narrows a caught value to a branded study error with valid failure attribution.
644
647
  * @remarks
645
- * Recognition combines the native `Error` base, a subclass prototype, the fixed name, a declared
646
- * study code, and an own {@link STUDY_ERROR_BRAND} descriptor whose value is the error itself.
648
+ * Recognition combines the native `Error` base, a subclass prototype, a declared study code,
649
+ * valid optional failure members, and an own {@link STUDY_ERROR_BRAND} descriptor whose value is
650
+ * the error itself. Subclasses can replace the name.
647
651
  * The global key is recognized across package, ESM, CommonJS and captured module copies; it is
648
652
  * not unforgeable provenance. A transparent proxy is refused because its forwarded descriptor
649
653
  * stores the target, and an unbranded copy, an inherited brand, or a property-only lookalike
@@ -656,7 +660,27 @@ var StudyError = class extends Error {
656
660
  * ```
657
661
  */
658
662
  function isStudyError(value) {
659
- return isError(value) && holds(() => Object.getPrototypeOf(value) !== Error.prototype && value.name === "StudyError" && Object.getOwnPropertyDescriptor(value, STUDY_ERROR_BRAND)?.value === value && "code" in value && isStudyErrorCode(value.code));
663
+ return holds(() => {
664
+ if (!isError(value) || INTRINSICS.prototype(value) === INTRINSICS.error.prototype) return false;
665
+ const brand = INTRINSICS.describe(value, STUDY_ERROR_BRAND)?.value;
666
+ const code = INTRINSICS.reflect.read(value, "code");
667
+ const failure = INTRINSICS.reflect.read(value, "failure");
668
+ if (brand !== value || !isStudyErrorCode(code) || typeof INTRINSICS.reflect.read(value, "name") !== "string" || typeof INTRINSICS.reflect.read(value, "message") !== "string") return false;
669
+ if (failure === void 0) return true;
670
+ if (!isObject(failure)) return false;
671
+ const cause = INTRINSICS.reflect.read(failure, "cause");
672
+ const message = INTRINSICS.reflect.read(failure, "message");
673
+ const role = INTRINSICS.reflect.read(failure, "role");
674
+ const stop = INTRINSICS.reflect.read(failure, "stop");
675
+ if (!isStudyCause(cause) || typeof message !== "string" || role !== void 0 && !isStudyRole(role)) return false;
676
+ if (stop === void 0) return true;
677
+ if (!isObject(stop)) return false;
678
+ const layer = INTRINSICS.reflect.read(stop, "layer");
679
+ const id = INTRINSICS.reflect.read(stop, "id");
680
+ const max = INTRINSICS.reflect.read(stop, "max");
681
+ const consumed = INTRINSICS.reflect.read(stop, "consumed");
682
+ return isStudyLayer(layer) && typeof id === "string" && (max === void 0 || isFiniteNumber(max)) && (consumed === void 0 || isFiniteNumber(consumed));
683
+ });
660
684
  }
661
685
  //#endregion
662
686
  //#region src/core/parsers.ts
@@ -1876,6 +1900,22 @@ function buildStudyAgentDispatch(dispatch) {
1876
1900
  //#endregion
1877
1901
  //#region src/core/agents/validators.ts
1878
1902
  /**
1903
+ * Checks whether a value is a gauge with a finite positive scale and a finite nonnegative overhead.
1904
+ * @param value - The candidate gauge; additional members are admitted
1905
+ * @returns True if the gauge readings are finite and within their bounds; false otherwise
1906
+ * @example
1907
+ * ```ts
1908
+ * isStudyAgentGauge({ scale: 1, overhead: 0 }) // true
1909
+ * ```
1910
+ */
1911
+ function isStudyAgentGauge(value) {
1912
+ return holds(() => {
1913
+ if (!isObject(value) || !("scale" in value) || !("overhead" in value)) return false;
1914
+ const { scale, overhead } = value;
1915
+ return isFiniteNumber(scale) && scale > 0 && isFiniteNumber(overhead) && overhead >= 0;
1916
+ });
1917
+ }
1918
+ /**
1879
1919
  * Checks whether a namespace exposes the Agent capabilities the instrumentation invokes.
1880
1920
  * @remarks
1881
1921
  * The guard reads only `estimateRequest`, `measureRequest`, and `isAgentError`, so a namespace
@@ -1995,6 +2035,6 @@ var StudyAgentJudge = class {
1995
2035
  }
1996
2036
  };
1997
2037
  //#endregion
1998
- export { STUDY_CAUSES, STUDY_ERROR_BRAND, STUDY_GOALS, STUDY_LAYERS, STUDY_NAME, STUDY_ROLES, STUDY_TRIALS, StudyAgentJudge, StudyAgentObserver, StudyControl, StudyDeadline, StudyError, StudyMeter, StudyRequest, StudyScope, StudySeries, buildStudyAgentDispatch, buildStudyAgentParts, buildStudySchedule, computeStudyAdmittedStop, computeStudyOutputStop, computeStudyScores, failStudyTicket, failureToStudyError, isStudyAgentRuntime, isStudyBounds, isStudyCause, isStudyCriterion, isStudyDefinition, isStudyDigest, isStudyError, isStudyErrorCode, isStudyGoal, isStudyGrading, isStudyJudgment, isStudyLabeling, isStudyLayer, isStudyLimit, isStudyName, isStudyProduct, isStudyProfile, isStudyProvider, isStudyRole, isStudyRoom, isStudyRubric, isStudyScenario, isStudyStop, isStudyTimestamp, isStudyUsage, matchesStudyKeys, normalizeStudyProfile, omitStudyAbsent, parseStudyDefinition, parseStudyGrading, parseStudyLabeling, parseStudyProfile, parseStudyReading, parseStudyRubric, parseStudyScenario, projectStudyAgentRequest, readStudyFailure, studyStopToJSON, translateStudyAgentError, translateStudyAgentStop, validateStudyAgentUsage, validateStudyInputs };
2038
+ export { STUDY_CAUSES, STUDY_ERROR_BRAND, STUDY_GOALS, STUDY_LAYERS, STUDY_NAME, STUDY_ROLES, STUDY_TRIALS, StudyAgentJudge, StudyAgentObserver, StudyControl, StudyDeadline, StudyError, StudyMeter, StudyRequest, StudyScope, StudySeries, buildStudyAgentDispatch, buildStudyAgentParts, buildStudySchedule, computeStudyAdmittedStop, computeStudyOutputStop, computeStudyScores, failStudyTicket, failureToStudyError, isStudyAgentGauge, isStudyAgentRuntime, isStudyBounds, isStudyCause, isStudyCriterion, isStudyDefinition, isStudyDigest, isStudyError, isStudyErrorCode, isStudyGoal, isStudyGrading, isStudyJudgment, isStudyLabeling, isStudyLayer, isStudyLimit, isStudyName, isStudyProduct, isStudyProfile, isStudyProvider, isStudyRole, isStudyRoom, isStudyRubric, isStudyScenario, isStudyStop, isStudyTimestamp, isStudyUsage, matchesStudyKeys, normalizeStudyProfile, omitStudyAbsent, parseStudyDefinition, parseStudyGrading, parseStudyLabeling, parseStudyProfile, parseStudyReading, parseStudyRubric, parseStudyScenario, projectStudyAgentRequest, readStudyFailure, studyStopToJSON, translateStudyAgentError, translateStudyAgentStop, validateStudyAgentUsage, validateStudyInputs };
1999
2039
 
2000
2040
  //# sourceMappingURL=index.js.map