@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 @@
1
+ {"version":3,"file":"main.js","names":["delay"],"sources":["../../src/core/constants.ts","../../src/core/helpers.ts","../../src/core/validators.ts","../../src/core/errors.ts","../../src/core/parsers.ts","../../src/core/engines/helpers.ts","../../src/core/engines/StudyControl.ts","../../src/core/engines/StudyScope.ts","../../src/core/engines/StudyDeadline.ts","../../src/core/engines/StudyRequest.ts","../../src/core/engines/StudyMeter.ts","../../src/core/engines/StudyTrialLease.ts","../../src/core/engines/StudySeries.ts","../../src/server/artifacts/constants.ts","../../src/server/helpers.ts","../../src/server/artifacts/errors.ts","../../src/server/artifacts/helpers.ts","../../src/server/artifacts/Resolution.ts","../../src/server/artifacts/ArtifactLoader.ts","../../src/server/stores/constants.ts","../../src/server/stores/validators.ts","../../src/server/adapters/validators.ts","../../src/server/adapters/helpers.ts","../../src/server/stores/helpers.ts","../../src/server/processes/constants.ts","../../src/server/processes/helpers.ts","../../src/server/processes/StudyArtifactLoader.ts","../../src/server/processes/validators.ts","../../src/server/processes/StudyChannel.ts","../../src/server/processes/StudyProcessGoal.ts","../../src/server/processes/StudyProcessSession.ts","../../src/server/processes/StudyProcessDriver.ts","../../src/server/stores/StudyGradingStore.ts","../../src/server/stores/StudyEvidenceSink.ts","../../src/server/stores/StudyResultStore.ts","../../src/server/processes/StudyTaskChild.ts","../../src/server/processes/StudyTask.ts","../../src/server/commands/constants.ts","../../src/server/commands/helpers.ts","../../src/server/commands/parsers.ts","../../src/server/commands/StudyCommand.ts","../../src/server/processes/StudyTaskWorker.ts","../../src/server/processes/StudyRemoteTicket.ts","../../src/server/processes/StudyRemoteMeter.ts","../../src/server/processes/StudyWorker.ts","../../src/server/launchers/constants.ts","../../src/server/launchers/StudyLaunchChild.ts","../../src/server/launchers/StudyLauncher.ts","../../src/server/launchers/StudyCLI.ts","../../src/bin/main.ts"],"sourcesContent":["import type { StudyCause, StudyLayer, StudyRole } from './types.js'\n\n/**\n * Keys the own self-identity every study error stamps on itself.\n * @remarks\n * The global symbol registry lets every package, ESM, CommonJS and captured copy read the same\n * key. The registry makes the key discoverable; it is a recognition mechanism, not an\n * unforgeable provenance marker.\n */\nexport const STUDY_ERROR_BRAND = Symbol.for('@orkestrel/study.error')\n\n/** Caps a declared trial population before schedule allocation. */\nexport const STUDY_TRIALS = 4096\n\n/** Caps a declared scenario horizon before execution. */\nexport const STUDY_GOALS = 4096\n\n/** Restricts identifiers to portable path-safe names. */\nexport const STUDY_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/\n\n/** Lists every measured request role in report order. */\nexport const STUDY_ROLES: readonly StudyRole[] = Object.freeze([\n\t'agent',\n\t'judge',\n\t'summary',\n\t'metadata',\n\t'tool',\n])\n\n/** Lists every ceiling a run can stop at in report order. */\nexport const STUDY_LAYERS: readonly StudyLayer[] = Object.freeze([\n\t'scope',\n\t'window',\n\t'custody',\n\t'meter',\n\t'budget',\n\t'model',\n])\n\n/** Lists every operational ending in report order. */\nexport const STUDY_CAUSES: readonly StudyCause[] = Object.freeze([\n\t'capacity',\n\t'infrastructure',\n\t'deadline',\n\t'interrupted',\n\t'content',\n])\n","import type {\n\tStudyDefinition,\n\tStudyGrading,\n\tStudyManifest,\n\tStudyProfile,\n\tStudyRubric,\n\tStudyScenario,\n\tStudyScore,\n\tStudyStop,\n\tStudyTrial,\n} from './types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport { holds, canonicalStringify, isRecord } from '@orkestrel/contract'\nimport { StudyError } from './errors.js'\nimport {\n\tisStudyDefinition,\n\tisStudyGrading,\n\tisStudyProfile,\n\tisStudyRubric,\n\tisStudyScenario,\n} from './validators.js'\n\n/**\n * Copies the own entries of a record that hold a value, in their original order.\n * @param value - The record whose undefined entries are absent declarations\n * @returns A new record without the undefined entries\n * @example\n * ```ts\n * omitStudyAbsent({ context: 512, recap: undefined }) // { context: 512 }\n * ```\n */\nexport function omitStudyAbsent(value: object): Readonly<Record<string, unknown>> {\n\treturn Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined))\n}\n\n/**\n * Omits every undefined optional declaration so the profile has one JSON form.\n * @param profile - The validated profile whose optional leaves may be undefined\n * @returns The profile fields with absent qualification, settings, provider, judge and recap removed\n * @example\n * ```ts\n * normalizeStudyProfile(profile) // no `recap` key when the room declares none\n * ```\n */\nexport function normalizeStudyProfile(profile: StudyProfile): Readonly<Record<string, unknown>> {\n\tconst { provider, qualification, settings, room, ...required } = profile\n\treturn {\n\t\t...required,\n\t\troom: omitStudyAbsent(room),\n\t\t...(provider === undefined\n\t\t\t? {}\n\t\t\t: { provider: { ...omitStudyAbsent(provider), digest: omitStudyAbsent(provider.digest) } }),\n\t\t...(qualification === undefined ? {} : { qualification }),\n\t\t...(settings === undefined ? {} : { settings }),\n\t}\n}\n\n/**\n * Projects a stop onto JSON with every unreported reading as null.\n * @param stop - The ceiling that stopped a run\n * @returns The stop's layer, id, and readings, with an undefined `max` or `consumed` as null\n * @example\n * ```ts\n * studyStopToJSON({ layer: 'model', id: 'num_predict', max: 2048, consumed: undefined })\n * // { layer: 'model', id: 'num_predict', max: 2048, consumed: null }\n * ```\n */\nexport function studyStopToJSON(stop: StudyStop): JSONValue {\n\treturn {\n\t\tlayer: stop.layer,\n\t\tid: stop.id,\n\t\tmax: stop.max ?? null,\n\t\tconsumed: stop.consumed ?? null,\n\t}\n}\n\n/**\n * Matches exact own enumerable data keys without evaluating accessors.\n * @param value - The candidate record\n * @param required - Required keys\n * @param optional - Allowed optional keys\n * @returns True if the record has exactly the allowed data keys; false otherwise\n * @example Check exact keys\n * ```ts\n * import { matchesStudyKeys } from '@orkestrel/study'\n *\n * matchesStudyKeys({ id: 'one' }, ['id']) // true\n * ```\n */\nexport function matchesStudyKeys(\n\tvalue: unknown,\n\trequired: readonly string[],\n\toptional: readonly string[] = [],\n): boolean {\n\treturn holds(() => {\n\t\tif (!isRecord(value)) return false\n\t\tconst keys = Reflect.ownKeys(value)\n\t\treturn (\n\t\t\trequired.every((key) => Object.hasOwn(value, key)) &&\n\t\t\tkeys.every((key) => {\n\t\t\t\tif (typeof key !== 'string' || (!required.includes(key) && !optional.includes(key)))\n\t\t\t\t\treturn false\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, key)\n\t\t\t\treturn (\n\t\t\t\t\tdescriptor !== undefined &&\n\t\t\t\t\tdescriptor.enumerable === true &&\n\t\t\t\t\tObject.hasOwn(descriptor, 'value')\n\t\t\t\t)\n\t\t\t})\n\t\t)\n\t})\n}\n\n/**\n * Builds a bounded schedule from explicit repetition rows and declared scenarios.\n * @param definition - The frozen population declaration\n * @param scenarios - The complete scenario declarations\n * @returns Owned trials in repetition, scenario and row-arm order\n * @throws StudyError - Thrown when the population or scenario set is invalid\n * @example\n * ```ts\n * buildStudySchedule(definition, scenarios)\n * ```\n */\nexport function buildStudySchedule(\n\tdefinition: StudyDefinition,\n\tscenarios: readonly StudyScenario[],\n): readonly StudyTrial[] {\n\tif (!isStudyDefinition(definition) || !scenarios.every(isStudyScenario))\n\t\tthrow new StudyError('CONFIG', 'Invalid study population')\n\tconst ids = new Set(scenarios.map((scenario) => scenario.id))\n\tif (\n\t\tids.size !== scenarios.length ||\n\t\tids.size !== definition.scenarios.length ||\n\t\t!definition.scenarios.every((id) => ids.has(id))\n\t)\n\t\tthrow new StudyError('CONFIG', 'Scenario declarations must match the population exactly')\n\treturn Object.freeze(\n\t\t[...definition.order.entries()].flatMap(([repetition, row]) =>\n\t\t\t[...definition.scenarios.entries()].flatMap(([scenario, id]) =>\n\t\t\t\trow.map((arm): StudyTrial =>\n\t\t\t\t\tObject.freeze({\n\t\t\t\t\t\tid: `r${repetition + 1}-s${scenario + 1}-a${definition.arms.indexOf(arm) + 1}`,\n\t\t\t\t\t\tscenario: id,\n\t\t\t\t\t\tarm,\n\t\t\t\t\t\trepetition,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t)\n}\n\n/**\n * Validates grading coverage and request room against the declared study inputs.\n * @param definition - The population declaration\n * @param scenarios - The complete scenario declarations\n * @param rubric - The independently held grading declaration\n * @param profile - The execution bounds and model room\n * @returns Nothing when every cross-input invariant holds\n * @throws StudyError - Thrown when any input or cross-reference is invalid\n * @example\n * ```ts\n * validateStudyInputs(definition, scenarios, rubric, profile)\n * ```\n */\nexport function validateStudyInputs(\n\tdefinition: StudyDefinition,\n\tscenarios: readonly StudyScenario[],\n\trubric: StudyRubric,\n\tprofile: StudyProfile,\n): void {\n\tbuildStudySchedule(definition, scenarios)\n\tif (!isStudyRubric(rubric) || !isStudyProfile(profile))\n\t\tthrow new StudyError('CONFIG', 'Invalid rubric or profile')\n\tif (\n\t\tprofile.bounds.request.tokens > profile.room.context - profile.room.safety ||\n\t\tprofile.room.output > profile.bounds.request.tokens\n\t)\n\t\tthrow new StudyError('CONFIG', 'Request allowance does not fit the model room')\n\tfor (const criterion of rubric.criteria) {\n\t\tconst scenario = scenarios.find((entry) => entry.id === criterion.scenario)\n\t\tif (scenario === undefined || !scenario.goals.some((goal) => goal.id === criterion.goal))\n\t\t\tthrow new StudyError('CONFIG', 'Criterion references an undeclared goal')\n\t\tif (definition.purpose === 'mechanism' && criterion.method === 'semantic')\n\t\t\tthrow new StudyError('CONFIG', 'Mechanism studies cannot establish semantic quality')\n\t}\n\tconst covered = new Set(\n\t\trubric.criteria.map(\n\t\t\t(criterion) => canonicalStringify([criterion.scenario, criterion.goal]) ?? '',\n\t\t),\n\t)\n\tfor (const scenario of scenarios) {\n\t\tfor (const goal of scenario.goals) {\n\t\t\tif (!covered.has(canonicalStringify([scenario.id, goal.id]) ?? ''))\n\t\t\t\tthrow new StudyError('CONFIG', 'Every declared goal needs a criterion')\n\t\t}\n\t}\n}\n\n/**\n * Computes arm intervals over the complete declared criterion horizon.\n * @param manifest - The sealed population and schedule\n * @param rubric - The criterion declaration\n * @param grading - Judgments bound to the complete scheduled attempt set\n * @returns Whole-horizon scores in declared arm order\n * @throws StudyError - Thrown when schedule, attempts or judgments are incompatible\n * @example\n * ```ts\n * computeStudyScores(manifest, rubric, grading)\n * ```\n */\nexport function computeStudyScores(\n\tmanifest: StudyManifest,\n\trubric: StudyRubric,\n\tgrading: StudyGrading,\n): readonly StudyScore[] {\n\tif (!isStudyRubric(rubric) || !isStudyGrading(grading))\n\t\tthrow new StudyError('EVIDENCE', 'Invalid rubric or grading')\n\tconst expected = buildStudySchedule(manifest.definition, manifest.scenarios)\n\tif (canonicalStringify(expected) !== canonicalStringify(manifest.schedule))\n\t\tthrow new StudyError('EVIDENCE', 'Manifest schedule differs from the declared population')\n\tconst trials = new Map(expected.map((trial) => [trial.id, trial]))\n\tif (\n\t\tgrading.attempts.length !== expected.length ||\n\t\t!grading.attempts.every((id) => trials.has(id))\n\t)\n\t\tthrow new StudyError('EVIDENCE', 'Grading attempts differ from the declared schedule')\n\tconst criteria = new Map(rubric.criteria.map((criterion) => [criterion.id, criterion]))\n\tfor (const scenario of manifest.scenarios) {\n\t\tfor (const goal of scenario.goals) {\n\t\t\tif (\n\t\t\t\t!rubric.criteria.some(\n\t\t\t\t\t(criterion) => criterion.scenario === scenario.id && criterion.goal === goal.id,\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new StudyError('EVIDENCE', 'Rubric omits a declared goal')\n\t\t}\n\t}\n\tfor (const criterion of rubric.criteria) {\n\t\tif (\n\t\t\t!manifest.scenarios.some(\n\t\t\t\t(scenario) =>\n\t\t\t\t\tscenario.id === criterion.scenario &&\n\t\t\t\t\tscenario.goals.some((goal) => goal.id === criterion.goal),\n\t\t\t) ||\n\t\t\t(manifest.definition.purpose === 'mechanism' && criterion.method === 'semantic')\n\t\t)\n\t\t\tthrow new StudyError('EVIDENCE', 'Criterion is incompatible with the study')\n\t}\n\tconst keyed = grading.judgments.map((judgment) => ({\n\t\tjudgment,\n\t\tkey: canonicalStringify([judgment.trial, judgment.criterion]) ?? '',\n\t}))\n\t// Reversed so the earliest index of each key is the one the lookup retains.\n\tconst firsts = new Map([...keyed.entries()].reverse().map(([index, { key }]) => [key, index]))\n\tfor (const [index, { judgment, key }] of keyed.entries()) {\n\t\tconst trial = trials.get(judgment.trial)\n\t\tconst criterion = criteria.get(judgment.criterion)\n\t\tif (\n\t\t\ttrial === undefined ||\n\t\t\tcriterion === undefined ||\n\t\t\tcriterion.scenario !== trial.scenario ||\n\t\t\tfirsts.get(key) !== index\n\t\t)\n\t\t\tthrow new StudyError('EVIDENCE', 'Duplicate or foreign trial criterion judgment')\n\t\tif (\n\t\t\tcriterion.method === 'semantic'\n\t\t\t\t? judgment.method !== 'human' && judgment.method !== 'model'\n\t\t\t\t: judgment.method !== criterion.method\n\t\t)\n\t\t\tthrow new StudyError('EVIDENCE', 'Judgment method differs from the criterion')\n\t}\n\tconst judgments = new Map(keyed.map(({ key, judgment }) => [key, judgment]))\n\treturn Object.freeze(\n\t\tmanifest.definition.arms.map((arm): StudyScore => {\n\t\t\tconst pairs = expected\n\t\t\t\t.filter((trial) => trial.arm === arm)\n\t\t\t\t.flatMap((trial) =>\n\t\t\t\t\trubric.criteria\n\t\t\t\t\t\t.filter((criterion) => criterion.scenario === trial.scenario)\n\t\t\t\t\t\t.map((criterion) => ({\n\t\t\t\t\t\t\tcriterion,\n\t\t\t\t\t\t\tjudgment: judgments.get(canonicalStringify([trial.id, criterion.id]) ?? ''),\n\t\t\t\t\t\t})),\n\t\t\t\t)\n\t\t\tconst refuted = pairs.filter(({ judgment }) => judgment?.verdict === 'unsuccessful')\n\t\t\tconst total = pairs.length\n\t\t\tconst achieved = pairs.filter(({ judgment }) => judgment?.verdict === 'achieved').length\n\t\t\tconst unsuccessful = refuted.length\n\t\t\tconst critical = refuted.filter(({ criterion }) => criterion.critical).length\n\t\t\tconst unknown = total - achieved - unsuccessful\n\t\t\treturn Object.freeze({\n\t\t\t\tarm,\n\t\t\t\ttotal,\n\t\t\t\tachieved,\n\t\t\t\tunsuccessful,\n\t\t\t\tunknown,\n\t\t\t\tcritical,\n\t\t\t\tlower: achieved / total,\n\t\t\t\tupper: (achieved + unknown) / total,\n\t\t\t\tcoverage: (achieved + unsuccessful) / total,\n\t\t\t})\n\t\t}),\n\t)\n}\n","import type {\n\tStudyBounds,\n\tStudyCause,\n\tStudyDefinition,\n\tStudyCriterion,\n\tStudyErrorCode,\n\tStudyGrading,\n\tStudyJudgment,\n\tStudyLabeling,\n\tStudyGoal,\n\tStudyLimit,\n\tStudyProduct,\n\tStudyProfile,\n\tStudyProvider,\n\tStudyLayer,\n\tStudyRole,\n\tStudyRoom,\n\tStudyScenario,\n\tStudyRubric,\n\tStudyStop,\n\tStudyUsage,\n} from './types.js'\nimport type { Guard } from '@orkestrel/contract'\nimport {\n\tholds,\n\tcanonicalStringify,\n\tisArray,\n\tisFiniteNumber,\n\tisJSONValue,\n\tisNonEmptyString,\n\tisRecord,\n\tliteralOf,\n} from '@orkestrel/contract'\nimport { MAX_TIMEOUT_MS } from '@orkestrel/timeout'\nimport {\n\tSTUDY_CAUSES,\n\tSTUDY_GOALS,\n\tSTUDY_LAYERS,\n\tSTUDY_NAME,\n\tSTUDY_ROLES,\n\tSTUDY_TRIALS,\n} from './constants.js'\nimport { matchesStudyKeys } from './helpers.js'\n\n/** Checks whether a value names a measured request role. */\nexport const isStudyRole: Guard<StudyRole> = literalOf(STUDY_ROLES)\n\n/** Checks whether a value names an operational ending. */\nexport const isStudyCause: Guard<StudyCause> = literalOf(STUDY_CAUSES)\n\n/** Checks whether a value names a ceiling a run can stop at. */\nexport const isStudyLayer: Guard<StudyLayer> = literalOf(STUDY_LAYERS)\n\n/**\n * Checks whether a value is the exact record of a ceiling that stopped a run.\n * @remarks\n * The guard accepts exact own data keys: `layer` and `id` are required and `max` and `consumed` are\n * optional. `max` and `consumed` are each undefined or a finite number. Finite foreign readings,\n * including negative and fractional values, retain the source's measurement unchanged.\n * @param value - The candidate stop\n * @returns True if the layer is known, the id is nonempty, and every reading is absent or finite; false otherwise\n * @example\n * ```ts\n * isStudyStop({ layer: 'scope', id: 'Goal tokens', max: 100, consumed: 120 }) // true\n * ```\n */\nexport function isStudyStop(value: unknown): value is StudyStop {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['layer', 'id'], ['max', 'consumed']) &&\n\t\t\tisStudyLayer(value.layer) &&\n\t\t\tisNonEmptyString(value.id) &&\n\t\t\t['max', 'consumed'].every((key) => value[key] === undefined || isFiniteNumber(value[key])),\n\t)\n}\n\n/**\n * Checks whether an identifier is portable and bounded.\n * @param value - The candidate identifier\n * @returns True if it is a portable study identifier; false otherwise\n * @example\n * ```ts\n * isStudyName('memory') // true\n * ```\n */\nexport function isStudyName(value: unknown): value is string {\n\treturn typeof value === 'string' && value.length <= 128 && STUDY_NAME.test(value)\n}\n\n/**\n * Checks whether all allowances are positive safe integers within timer bounds.\n * @param value - The candidate limit\n * @returns True if it defines finite positive allowances; false otherwise\n * @example\n * ```ts\n * isStudyLimit({ duration: 1000, calls: 1, tokens: 100, bytes: 1024 }) // true\n * ```\n */\nexport function isStudyLimit(value: unknown): value is StudyLimit {\n\treturn holds(() => {\n\t\tif (!isRecord(value) || !matchesStudyKeys(value, ['duration', 'calls', 'tokens', 'bytes']))\n\t\t\treturn false\n\t\treturn (\n\t\t\t['duration', 'calls', 'tokens', 'bytes'].every(\n\t\t\t\t(key) =>\n\t\t\t\t\ttypeof value[key] === 'number' && Number.isSafeInteger(value[key]) && value[key] > 0,\n\t\t\t) &&\n\t\t\ttypeof value.duration === 'number' &&\n\t\t\tvalue.duration <= MAX_TIMEOUT_MS\n\t\t)\n\t})\n}\n\n/**\n * Checks whether nested scopes admit no larger allowance than their parent.\n * @param value - The candidate bounds\n * @returns True if every nested allowance is ordered; false otherwise\n * @example\n * ```ts\n * isStudyBounds({}) // false\n * ```\n */\nexport function isStudyBounds(value: unknown): value is StudyBounds {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['request', 'goal', 'trial', 'series']) ||\n\t\t\t!isStudyLimit(value.request) ||\n\t\t\t!isStudyLimit(value.goal) ||\n\t\t\t!isStudyLimit(value.trial) ||\n\t\t\t!isStudyLimit(value.series)\n\t\t)\n\t\t\treturn false\n\t\tconst limits = [value.request, value.goal, value.trial, value.series]\n\t\tfor (const [index, limit] of limits.entries()) {\n\t\t\tconst next = limits[index + 1]\n\t\t\tif (next === undefined) continue\n\t\t\tif (\n\t\t\t\tlimit.duration > next.duration ||\n\t\t\t\tlimit.calls > next.calls ||\n\t\t\t\tlimit.tokens > next.tokens ||\n\t\t\t\tlimit.bytes > next.bytes\n\t\t\t)\n\t\t\t\treturn false\n\t\t}\n\t\treturn value.request.calls === 1\n\t})\n}\n\n/**\n * Checks whether a goal has a bounded identifier and exact JSON input.\n * @param value - The candidate goal\n * @returns True if the goal is valid; false otherwise\n * @example\n * ```ts\n * isStudyGoal({ id: 'write', input: { text: 'hello' } }) // true\n * ```\n */\nexport function isStudyGoal(value: unknown): value is StudyGoal {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['id', 'input']) &&\n\t\t\tisStudyName(value.id) &&\n\t\t\tisJSONValue(value.input)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a scenario declares a nonempty horizon with unique goal ids.\n * @param value - The candidate scenario\n * @returns True if the scenario has a valid horizon; false otherwise\n * @example\n * ```ts\n * isStudyScenario({ id: 'shift', goals: [{ id: 'handoff', input: 'Prepare handoff' }] }) // true\n * ```\n */\nexport function isStudyScenario(value: unknown): value is StudyScenario {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['id', 'goals']) ||\n\t\t\t!isStudyName(value.id) ||\n\t\t\t!isArray(value.goals)\n\t\t)\n\t\t\treturn false\n\t\treturn (\n\t\t\tvalue.goals.length > 0 &&\n\t\t\tvalue.goals.length <= STUDY_GOALS &&\n\t\t\tvalue.goals.every(isStudyGoal) &&\n\t\t\tnew Set(value.goals.map((goal) => goal.id)).size === value.goals.length &&\n\t\t\tisJSONValue(value.goals)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a study freezes a complete arm order for every repetition.\n * @param value - The candidate definition\n * @returns True if its population and repetition orders are valid; false otherwise\n * @example\n * ```ts\n * isStudyDefinition({ name: 'tools' }) // false\n * ```\n */\nexport function isStudyDefinition(value: unknown): value is StudyDefinition {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!isJSONValue(value) ||\n\t\t\t!matchesStudyKeys(value, [\n\t\t\t\t'name',\n\t\t\t\t'version',\n\t\t\t\t'question',\n\t\t\t\t'purpose',\n\t\t\t\t'driver',\n\t\t\t\t'arms',\n\t\t\t\t'scenarios',\n\t\t\t\t'order',\n\t\t\t\t'retries',\n\t\t\t\t'rubric',\n\t\t\t]) ||\n\t\t\t!isStudyName(value.name) ||\n\t\t\t!isStudyName(value.driver) ||\n\t\t\t!isNonEmptyString(value.version) ||\n\t\t\t!isNonEmptyString(value.question) ||\n\t\t\t(value.purpose !== 'mechanism' &&\n\t\t\t\tvalue.purpose !== 'quality' &&\n\t\t\t\tvalue.purpose !== 'capacity') ||\n\t\t\t!isArray(value.arms) ||\n\t\t\tvalue.arms.length === 0 ||\n\t\t\t!value.arms.every(isStudyName) ||\n\t\t\tnew Set(value.arms).size !== value.arms.length ||\n\t\t\t!isArray(value.scenarios) ||\n\t\t\tvalue.scenarios.length === 0 ||\n\t\t\t!value.scenarios.every(isStudyName) ||\n\t\t\tnew Set(value.scenarios).size !== value.scenarios.length ||\n\t\t\t!isArray(value.order) ||\n\t\t\t!isJSONValue(value.order) ||\n\t\t\tvalue.order.length === 0 ||\n\t\t\tvalue.retries !== 0 ||\n\t\t\t!isNonEmptyString(value.rubric)\n\t\t)\n\t\t\treturn false\n\t\tconst arms = value.arms\n\t\tif (arms.length * value.scenarios.length * value.order.length > STUDY_TRIALS) return false\n\t\treturn value.order.every(\n\t\t\t(order) =>\n\t\t\t\tisArray(order) &&\n\t\t\t\torder.length === arms.length &&\n\t\t\t\tnew Set(order).size === arms.length &&\n\t\t\t\torder.every((arm) => typeof arm === 'string' && arms.includes(arm)),\n\t\t)\n\t})\n}\n\n/**\n * Checks whether generation room leaves positive context for input.\n * @param value - The candidate room\n * @returns True if input, output and safety allowances fit and any declared recap fits; false otherwise\n * @example\n * ```ts\n * isStudyRoom({ context: 20480, output: 8192, safety: 512, recap: 2048, think: true }) // true\n * isStudyRoom({ context: 20480, output: 8192, safety: 512, think: true }) // true\n * ```\n */\nexport function isStudyRoom(value: unknown): value is StudyRoom {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['context', 'output', 'safety', 'think'], ['recap']) ||\n\t\t\ttypeof value.think !== 'boolean'\n\t\t)\n\t\t\treturn false\n\t\tconst declared = value.recap === undefined ? [] : ['recap']\n\t\tif (\n\t\t\t!['context', 'output', 'safety', ...declared].every(\n\t\t\t\t(key) =>\n\t\t\t\t\ttypeof value[key] === 'number' && Number.isSafeInteger(value[key]) && value[key] > 0,\n\t\t\t)\n\t\t)\n\t\t\treturn false\n\t\treturn (\n\t\t\ttypeof value.context === 'number' &&\n\t\t\ttypeof value.output === 'number' &&\n\t\t\ttypeof value.safety === 'number' &&\n\t\t\tvalue.output + value.safety < value.context &&\n\t\t\t(value.recap === undefined ||\n\t\t\t\t(typeof value.recap === 'number' && value.recap + value.safety < value.context))\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a provider declaration names artifacts, an HTTP origin and models.\n * @param value - The candidate provider declaration\n * @returns True if the declaration has a supported origin, nonempty names, and a judge declared with its digest or not at all; false otherwise\n * @example\n * ```ts\n * isStudyProvider({ entry: 'dist/index.js' }) // false\n * ```\n */\nexport function isStudyProvider(value: unknown): value is StudyProvider {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['entry', 'url', 'model', 'digest'], ['judge']) ||\n\t\t\t!['entry', 'url', 'model'].every((key) => isNonEmptyString(value[key])) ||\n\t\t\ttypeof value.url !== 'string' ||\n\t\t\t!isRecord(value.digest) ||\n\t\t\t!matchesStudyKeys(value.digest, ['model'], ['judge']) ||\n\t\t\t!isStudyDigest(value.digest.model) ||\n\t\t\t(value.judge === undefined) !== (value.digest.judge === undefined) ||\n\t\t\t(value.judge !== undefined &&\n\t\t\t\t(!isNonEmptyString(value.judge) || !isStudyDigest(value.digest.judge)))\n\t\t)\n\t\t\treturn false\n\t\tconst url = new URL(value.url)\n\t\treturn (\n\t\t\t['http:', 'https:'].includes(url.protocol) &&\n\t\t\turl.username === '' &&\n\t\t\turl.password === '' &&\n\t\t\turl.search === '' &&\n\t\t\turl.hash === '' &&\n\t\t\turl.pathname === '/'\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a profile carries finite bounds and an optional explicit provider.\n * @param value - The candidate profile\n * @returns True if the profile is structurally valid; false otherwise\n * @example\n * ```ts\n * isStudyProfile({ name: 'local' }) // false\n * ```\n */\nexport function isStudyProfile(value: unknown): value is StudyProfile {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(\n\t\t\t\tvalue,\n\t\t\t\t['name', 'agent', 'subject', 'roots', 'bounds', 'room'],\n\t\t\t\t['provider', 'qualification', 'settings'],\n\t\t\t) &&\n\t\t\tisStudyName(value.name) &&\n\t\t\tisNonEmptyString(value.agent) &&\n\t\t\tisArray(value.roots) &&\n\t\t\tisJSONValue(value.roots) &&\n\t\t\tvalue.roots.length > 0 &&\n\t\t\tvalue.roots.every((root) => typeof root === 'string' && root.trim().length > 0) &&\n\t\t\tnew Set(value.roots).size === value.roots.length &&\n\t\t\tisNonEmptyString(value.subject) &&\n\t\t\tisStudyBounds(value.bounds) &&\n\t\t\tisStudyRoom(value.room) &&\n\t\t\t(value.provider === undefined || isStudyProvider(value.provider)) &&\n\t\t\t(value.qualification === undefined || isNonEmptyString(value.qualification)) &&\n\t\t\t(value.settings === undefined || (isRecord(value.settings) && isJSONValue(value.settings)))\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a byte identity is a lowercase SHA-256 digest.\n * @param value - The candidate identity\n * @returns True if it has exactly 64 hexadecimal digits; false otherwise\n * @example\n * ```ts\n * isStudyDigest('a'.repeat(64)) // true\n * ```\n */\nexport function isStudyDigest(value: unknown): value is string {\n\treturn typeof value === 'string' && /^[a-f0-9]{64}$/.test(value)\n}\n\n/**\n * Checks whether a timestamp is a canonical UTC millisecond instant.\n * @param value - The candidate timestamp\n * @returns True if it is a valid canonical timestamp; false otherwise\n * @example\n * ```ts\n * isStudyTimestamp('2026-10-14T12:00:00.000Z') // true\n * ```\n */\nexport function isStudyTimestamp(value: unknown): value is string {\n\treturn holds(() => {\n\t\treturn (\n\t\t\ttypeof value === 'string' &&\n\t\t\t/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/.test(value) &&\n\t\t\tnew Date(value).toISOString() === value\n\t\t)\n\t})\n}\n\n/**\n * Checks whether request usage contains nonnegative safe measurements.\n * @param value - The candidate usage\n * @returns True if the role and every known measurement are valid; false otherwise\n * @example\n * ```ts\n * isStudyUsage({ role: 'tool', calls: 0, bytes: 0, duration: 0 }) // true\n * ```\n */\nexport function isStudyUsage(value: unknown): value is StudyUsage {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['role', 'calls', 'duration'], ['tokens', 'bytes']) &&\n\t\t\tisStudyRole(value.role) &&\n\t\t\t['calls', 'duration'].every(\n\t\t\t\t(key) =>\n\t\t\t\t\ttypeof value[key] === 'number' && Number.isSafeInteger(value[key]) && value[key] >= 0,\n\t\t\t) &&\n\t\t\t(value.bytes === undefined ||\n\t\t\t\t(typeof value.bytes === 'number' &&\n\t\t\t\t\tNumber.isSafeInteger(value.bytes) &&\n\t\t\t\t\tvalue.bytes >= 0)) &&\n\t\t\t(value.tokens === undefined ||\n\t\t\t\t(typeof value.tokens === 'number' &&\n\t\t\t\t\tNumber.isSafeInteger(value.tokens) &&\n\t\t\t\t\tvalue.tokens >= 0))\n\t\t)\n\t})\n}\n\n/**\n * Checks a retained public product without awarding task achievement.\n * @param value - The candidate product\n * @returns True if the product carries JSON output and partial status; false otherwise\n * @example\n * ```ts\n * isStudyProduct({ value: { answer: 1 }, partial: true }) // true\n * ```\n */\nexport function isStudyProduct(value: unknown): value is StudyProduct {\n\treturn holds(\n\t\t() => isRecord(value) && typeof value.partial === 'boolean' && isJSONValue(value.value),\n\t)\n}\n\n/**\n * Checks whether a criterion declares exact grading inputs and references.\n * @param value - The candidate criterion\n * @returns True if its structural grading declaration is valid; false otherwise\n * @example\n * ```ts\n * isStudyCriterion({ id: 'saved', scenario: 'shift', goal: 'write', method: 'state', critical: true, assertion: true }) // true\n * ```\n */\nexport function isStudyCriterion(value: unknown): value is StudyCriterion {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['id', 'scenario', 'goal', 'method', 'critical', 'assertion']) &&\n\t\t\tisStudyName(value.id) &&\n\t\t\tisStudyName(value.scenario) &&\n\t\t\tisStudyName(value.goal) &&\n\t\t\t(value.method === 'state' || value.method === 'trace' || value.method === 'semantic') &&\n\t\t\ttypeof value.critical === 'boolean' &&\n\t\t\tisJSONValue(value.assertion)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a rubric declares nonempty criteria with unique identities.\n * @param value - The candidate rubric\n * @returns True if its version and criteria are valid; false otherwise\n * @example\n * ```ts\n * isStudyRubric({ version: '1', criteria: [] }) // false\n * ```\n */\nexport function isStudyRubric(value: unknown): value is StudyRubric {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['version', 'criteria']) &&\n\t\t\ttypeof value.version === 'string' &&\n\t\t\tvalue.version.trim().length > 0 &&\n\t\t\tisArray(value.criteria) &&\n\t\t\tvalue.criteria.length > 0 &&\n\t\t\tvalue.criteria.every(isStudyCriterion) &&\n\t\t\tnew Set(value.criteria.map((criterion) => criterion.id)).size === value.criteria.length &&\n\t\t\tisJSONValue(value.criteria)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a judgment carries a supported verdict and evidence references.\n * @param value - The candidate judgment\n * @returns True if the judgment is attributable and structurally valid; false otherwise\n * @example\n * ```ts\n * isStudyJudgment({ trial: 'r1-s1-a1', criterion: 'saved', verdict: 'unknown', method: 'state', reason: 'No evidence', references: [] }) // true\n * ```\n */\nexport function isStudyJudgment(value: unknown): value is StudyJudgment {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, [\n\t\t\t\t'trial',\n\t\t\t\t'criterion',\n\t\t\t\t'verdict',\n\t\t\t\t'method',\n\t\t\t\t'reason',\n\t\t\t\t'references',\n\t\t\t]) &&\n\t\t\tisStudyName(value.trial) &&\n\t\t\tisStudyName(value.criterion) &&\n\t\t\t(value.verdict === 'achieved' ||\n\t\t\t\tvalue.verdict === 'unsuccessful' ||\n\t\t\t\tvalue.verdict === 'unknown') &&\n\t\t\t(value.method === 'state' ||\n\t\t\t\tvalue.method === 'trace' ||\n\t\t\t\tvalue.method === 'human' ||\n\t\t\t\tvalue.method === 'model') &&\n\t\t\ttypeof value.reason === 'string' &&\n\t\t\tvalue.reason.trim().length > 0 &&\n\t\t\tisArray(value.references) &&\n\t\t\tisJSONValue(value.references) &&\n\t\t\tvalue.references.every(\n\t\t\t\t(reference) => typeof reference === 'string' && reference.trim().length > 0,\n\t\t\t) &&\n\t\t\tnew Set(value.references).size === value.references.length &&\n\t\t\t(value.verdict === 'unknown' || value.references.length > 0)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether imported semantic labels have accountable packet provenance.\n * @param value - The candidate labels\n * @returns True if provenance, usage and semantic judgments are valid; false otherwise\n * @example\n * ```ts\n * isStudyLabeling({}) // false\n * ```\n */\nexport function isStudyLabeling(value: unknown): value is StudyLabeling {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['packet', 'labeler', 'version', 'created', 'usage', 'judgments']) &&\n\t\t\tisStudyDigest(value.packet) &&\n\t\t\ttypeof value.labeler === 'string' &&\n\t\t\tvalue.labeler.trim().length > 0 &&\n\t\t\ttypeof value.version === 'string' &&\n\t\t\tvalue.version.trim().length > 0 &&\n\t\t\tisStudyTimestamp(value.created) &&\n\t\t\tisArray(value.usage) &&\n\t\t\tReflect.ownKeys(value.usage).length === value.usage.length + 1 &&\n\t\t\tArray.from(value.usage).every(isStudyUsage) &&\n\t\t\tisArray(value.judgments) &&\n\t\t\tvalue.judgments.every(isStudyJudgment) &&\n\t\t\tvalue.judgments.every(\n\t\t\t\t(judgment) => judgment.method === 'human' || judgment.method === 'model',\n\t\t\t) &&\n\t\t\tnew Set(\n\t\t\t\tvalue.judgments.map((judgment) => canonicalStringify([judgment.trial, judgment.criterion])),\n\t\t\t).size === value.judgments.length &&\n\t\t\tisJSONValue(value.judgments)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a value names a supported study error code.\n * @param value - The candidate code\n * @returns True if it is a declared study error code; false otherwise\n * @example\n * ```ts\n * isStudyErrorCode('CONFIG') // true\n * ```\n */\nexport function isStudyErrorCode(value: unknown): value is StudyErrorCode {\n\treturn (\n\t\tvalue === 'CONFIG' ||\n\t\tvalue === 'EVIDENCE' ||\n\t\tvalue === 'CUSTODY' ||\n\t\tvalue === 'CAPACITY' ||\n\t\tvalue === 'FAULT' ||\n\t\tvalue === 'DEADLINE'\n\t)\n}\n\n/**\n * Checks whether grading binds accountable judgments to unique attempt identities.\n * @param value - The candidate grading\n * @returns True if its identities, attempts and judgments are valid; false otherwise\n * @example\n * ```ts\n * isStudyGrading({}) // false\n * ```\n */\nexport function isStudyGrading(value: unknown): value is StudyGrading {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(\n\t\t\t\tvalue,\n\t\t\t\t['result', 'rubric', 'grader', 'instrument', 'attempts', 'judgments'],\n\t\t\t\t['labels', 'packet'],\n\t\t\t) &&\n\t\t\tisStudyDigest(value.result) &&\n\t\t\tisStudyDigest(value.rubric) &&\n\t\t\tisStudyDigest(value.instrument) &&\n\t\t\ttypeof value.grader === 'string' &&\n\t\t\tvalue.grader.trim().length > 0 &&\n\t\t\t(value.labels === undefined || isStudyDigest(value.labels)) &&\n\t\t\t(value.packet === undefined || isStudyDigest(value.packet)) &&\n\t\t\tisArray(value.attempts) &&\n\t\t\tisJSONValue(value.attempts) &&\n\t\t\tvalue.attempts.every(isStudyName) &&\n\t\t\tnew Set(value.attempts).size === value.attempts.length &&\n\t\t\tisArray(value.judgments) &&\n\t\t\tvalue.judgments.every(isStudyJudgment) &&\n\t\t\tnew Set(\n\t\t\t\tvalue.judgments.map((judgment) => canonicalStringify([judgment.trial, judgment.criterion])),\n\t\t\t).size === value.judgments.length &&\n\t\t\tisJSONValue(value.judgments)\n\t\t)\n\t})\n}\n","import type { StudyErrorCode, StudyFailure } from './types.js'\nimport { holds, isError } from '@orkestrel/contract'\nimport { STUDY_ERROR_BRAND } from './constants.js'\nimport { isStudyErrorCode } from './validators.js'\n\n/** Reports a study contract or operational failure with a stable code. */\nexport class StudyError extends Error {\n\treadonly code: StudyErrorCode\n\treadonly failure: StudyFailure | undefined\n\n\t/**\n\t * Records the failing boundary and optional operational attribution.\n\t * @param code - The machine-readable boundary\n\t * @param message - The specific failure\n\t * @param failure - The optional operational reading\n\t */\n\tconstructor(code: StudyErrorCode, message: string, failure?: StudyFailure) {\n\t\tsuper(message)\n\t\tObject.defineProperty(this, STUDY_ERROR_BRAND, { value: this, configurable: true })\n\t\tthis.name = 'StudyError'\n\t\tthis.code = code\n\t\tthis.failure = failure\n\t}\n}\n\n/**\n * Narrows a caught value to an attributable study error.\n * @remarks\n * Recognition combines the native `Error` base, a subclass prototype, the fixed name, a declared\n * study code, and an own {@link STUDY_ERROR_BRAND} descriptor whose value is the error itself.\n * The global key is recognized across package, ESM, CommonJS and captured module copies; it is\n * not unforgeable provenance. A transparent proxy is refused because its forwarded descriptor\n * stores the target, and an unbranded copy, an inherited brand, or a property-only lookalike\n * stays outside the type. Hostile property access returns false instead of throwing.\n * @param value - The caught value\n * @returns True if the value is a study error; false otherwise\n * @example\n * ```ts\n * isStudyError(new StudyError('CONFIG', 'missing definition')) // true\n * ```\n */\nexport function isStudyError(value: unknown): value is StudyError {\n\treturn (\n\t\tisError(value) &&\n\t\tholds(\n\t\t\t() =>\n\t\t\t\tObject.getPrototypeOf(value) !== Error.prototype &&\n\t\t\t\tvalue.name === 'StudyError' &&\n\t\t\t\tObject.getOwnPropertyDescriptor(value, STUDY_ERROR_BRAND)?.value === value &&\n\t\t\t\t'code' in value &&\n\t\t\t\tisStudyErrorCode(value.code),\n\t\t)\n\t)\n}\n","import type {\n\tStudyDefinition,\n\tStudyGrading,\n\tStudyLabeling,\n\tStudyProfile,\n\tStudyRubric,\n\tStudyScenario,\n} from './types.js'\nimport { cloneJSONValue, isFiniteNumber } from '@orkestrel/contract'\nimport { StudyError } from './errors.js'\nimport { normalizeStudyProfile } from './helpers.js'\nimport {\n\tisStudyDefinition,\n\tisStudyGrading,\n\tisStudyLabeling,\n\tisStudyProfile,\n\tisStudyRubric,\n\tisStudyScenario,\n} from './validators.js'\n\n/**\n * Parses a foreign reading into a number a stop can retain.\n * @param value - The unknown reading a source reports\n * @returns The value when it is a finite number; undefined otherwise\n * @example\n * ```ts\n * parseStudyReading(2048) // 2048\n * parseStudyReading(Number.NaN) // undefined\n * ```\n */\nexport function parseStudyReading(value: unknown): number | undefined {\n\treturn isFiniteNumber(value) ? value : undefined\n}\n\n/**\n * Parses a definition into an independent frozen validated snapshot.\n * @param value - The unknown configuration\n * @returns The owned study definition\n * @throws StudyError - Thrown when configuration is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyDefinition(configuration)\n * ```\n */\nexport function parseStudyDefinition(value: unknown): StudyDefinition {\n\ttry {\n\t\tif (!isStudyDefinition(value)) throw new StudyError('CONFIG', 'Invalid study definition')\n\t\tconst snapshot = cloneJSONValue(value)\n\t\tif (isStudyDefinition(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('CONFIG', 'Invalid or unreadable study definition')\n\t}\n\tthrow new StudyError('CONFIG', 'Invalid study definition snapshot')\n}\n\n/**\n * Parses a scenario into an independent frozen validated snapshot.\n * @param value - The unknown configuration\n * @returns The owned scenario and goal inputs\n * @throws StudyError - Thrown when configuration is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyScenario({ id: 'shift', goals: [{ id: 'write', input: {} }] })\n * ```\n */\nexport function parseStudyScenario(value: unknown): StudyScenario {\n\ttry {\n\t\tif (!isStudyScenario(value)) throw new StudyError('CONFIG', 'Invalid study scenario')\n\t\tconst snapshot = cloneJSONValue(value)\n\t\tif (isStudyScenario(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('CONFIG', 'Invalid or unreadable study scenario')\n\t}\n\tthrow new StudyError('CONFIG', 'Invalid study scenario snapshot')\n}\n\n/**\n * Parses a profile into an independent frozen validated snapshot.\n * @param value - The unknown configuration\n * @returns The owned profile with absent optional settings preserved\n * @throws StudyError - Thrown when configuration is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyProfile(configuration)\n * ```\n */\nexport function parseStudyProfile(value: unknown): StudyProfile {\n\ttry {\n\t\tif (!isStudyProfile(value)) throw new StudyError('CONFIG', 'Invalid study profile')\n\t\tconst snapshot = cloneJSONValue(normalizeStudyProfile(value))\n\t\tif (isStudyProfile(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('CONFIG', 'Invalid or unreadable study profile')\n\t}\n\tthrow new StudyError('CONFIG', 'Invalid study profile snapshot')\n}\n\n/**\n * Parses a rubric into an independent frozen validated snapshot.\n * @param value - The unknown grading declaration\n * @returns The owned rubric and assertion inputs\n * @throws StudyError - Thrown when configuration is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyRubric(configuration)\n * ```\n */\nexport function parseStudyRubric(value: unknown): StudyRubric {\n\ttry {\n\t\tif (!isStudyRubric(value)) throw new StudyError('CONFIG', 'Invalid study rubric')\n\t\tconst snapshot = cloneJSONValue(value)\n\t\tif (isStudyRubric(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('CONFIG', 'Invalid or unreadable study rubric')\n\t}\n\tthrow new StudyError('CONFIG', 'Invalid study rubric snapshot')\n}\n\n/**\n * Parses grading into an independent frozen validated evidence snapshot.\n * @param value - The unknown grading evidence\n * @returns The owned grading identity and judgments\n * @throws StudyError - Thrown when evidence is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyGrading(evidence)\n * ```\n */\nexport function parseStudyGrading(value: unknown): StudyGrading {\n\ttry {\n\t\tif (!isStudyGrading(value)) throw new StudyError('EVIDENCE', 'Invalid study grading')\n\t\tconst { labels, packet, ...required } = value\n\t\tconst snapshot = cloneJSONValue({\n\t\t\t...required,\n\t\t\t...(labels === undefined ? {} : { labels }),\n\t\t\t...(packet === undefined ? {} : { packet }),\n\t\t})\n\t\tif (isStudyGrading(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('EVIDENCE', 'Invalid or unreadable study grading')\n\t}\n\tthrow new StudyError('EVIDENCE', 'Invalid study grading snapshot')\n}\n\n/**\n * Parses semantic labels into an independent frozen validated evidence snapshot.\n * @param value - The unknown imported labels\n * @returns The owned packet provenance, usage and judgments\n * @throws StudyError - Thrown when evidence is invalid or cannot be owned\n * @example\n * ```ts\n * parseStudyLabeling(evidence)\n * ```\n */\nexport function parseStudyLabeling(value: unknown): StudyLabeling {\n\ttry {\n\t\tif (!isStudyLabeling(value)) throw new StudyError('EVIDENCE', 'Invalid study labels')\n\t\tconst snapshot = cloneJSONValue({\n\t\t\t...value,\n\t\t\tusage: value.usage.map(({ tokens, bytes, ...usage }) => ({\n\t\t\t\t...usage,\n\t\t\t\t...(tokens === undefined ? {} : { tokens }),\n\t\t\t\t...(bytes === undefined ? {} : { bytes }),\n\t\t\t})),\n\t\t})\n\t\tif (isStudyLabeling(snapshot)) return snapshot\n\t} catch {\n\t\tthrow new StudyError('EVIDENCE', 'Invalid or unreadable study labels')\n\t}\n\tthrow new StudyError('EVIDENCE', 'Invalid study labels snapshot')\n}\n","import type { BudgetInterface } from '@orkestrel/budget'\nimport type {\n\tStudyCharge,\n\tStudyFailure,\n\tStudyRole,\n\tStudyStop,\n\tStudyTicket,\n\tStudyUsage,\n} from '../types.js'\nimport { isBudgetError } from '@orkestrel/budget'\nimport { attempt, isError, isNonEmptyString } from '@orkestrel/contract'\nimport { isStudyError, StudyError } from '../errors.js'\nimport { parseStudyReading } from '../parsers.js'\n\n/** Converts an operational reading to its throwable boundary.\n * @param failure - The retained operational reading.\n * @returns An error preserving the reading's cause and responsibility.\n */\nexport function failureToStudyError(failure: StudyFailure): StudyError {\n\treturn new StudyError(\n\t\tfailure.cause === 'capacity' ? 'CAPACITY' : failure.cause === 'deadline' ? 'DEADLINE' : 'FAULT',\n\t\tfailure.message,\n\t\tfailure,\n\t)\n}\n\n/** Reads an operational error without inventing a task verdict.\n * @remarks\n * A branded `BudgetError` from any copy of the budget package reads as a `budget` stop, because the\n * error alone does not prove which budget object raised it; the Agent record names a `meter` stop.\n * An unbranded lookalike reads as an infrastructure failure.\n * @param error - The caught error.\n * @returns Existing attribution, the capacity a branded budget error names, the cause a bare\n * capacity or deadline code names, or an infrastructure failure.\n */\nexport function readStudyFailure(error: unknown): StudyFailure {\n\tif (isStudyError(error)) {\n\t\tconst { failure, code, message } = error\n\t\tif (failure !== undefined) return failure\n\t\tif (code === 'CAPACITY') return { cause: 'capacity', message, role: undefined, stop: undefined }\n\t\tif (code === 'DEADLINE') return { cause: 'deadline', message, role: undefined, stop: undefined }\n\t}\n\tif (isBudgetError(error)) {\n\t\tconst reading = attempt(() => {\n\t\t\tconst context = error.context\n\t\t\treturn {\n\t\t\t\tid: context.id,\n\t\t\t\tmax: context.max,\n\t\t\t\tconsumed: context.consumed,\n\t\t\t\tmessage: error.message,\n\t\t\t}\n\t\t})\n\t\tif (reading.success)\n\t\t\treturn {\n\t\t\t\tcause: 'capacity',\n\t\t\t\tmessage: reading.value.message,\n\t\t\t\trole: undefined,\n\t\t\t\tstop: {\n\t\t\t\t\tlayer: 'budget',\n\t\t\t\t\tid: isNonEmptyString(reading.value.id) ? reading.value.id : 'Agent budget',\n\t\t\t\t\tmax: parseStudyReading(reading.value.max),\n\t\t\t\t\tconsumed: parseStudyReading(reading.value.consumed),\n\t\t\t\t},\n\t\t\t}\n\t}\n\treturn {\n\t\tcause: 'infrastructure',\n\t\tmessage: isError(error) ? error.message : 'Study operation rejected without an Error',\n\t\trole: undefined,\n\t\tstop: undefined,\n\t}\n}\n\n/**\n * Computes the stop of a request whose actual usage crossed the ceiling it was admitted under.\n * @param charge - The request's admitted ceilings\n * @param usage - The request's measured usage\n * @returns The `scope` stop for the first quantity, tokens then bytes, whose known usage exceeds its admitted ceiling; undefined when none does\n * @example\n * ```ts\n * computeStudyAdmittedStop({ role: 'agent', tokens: 10, bytes: 100 }, usage) // { layer: 'scope', id: 'Admitted tokens', max: 10, consumed: 12 }\n * ```\n */\nexport function computeStudyAdmittedStop(\n\tcharge: StudyCharge,\n\tusage: StudyUsage,\n): StudyStop | undefined {\n\tif (usage.tokens !== undefined && usage.tokens > charge.tokens)\n\t\treturn { layer: 'scope', id: 'Admitted tokens', max: charge.tokens, consumed: usage.tokens }\n\tif (usage.bytes !== undefined && usage.bytes > charge.bytes)\n\t\treturn { layer: 'scope', id: 'Admitted bytes', max: charge.bytes, consumed: usage.bytes }\n\treturn undefined\n}\n\n/**\n * Computes the stop of a product the output allowances cannot hold.\n * @param bytes - The encoded size of the product's value\n * @param limit - The goal's byte allowance\n * @param outputs - The trial and series output budgets, in the order they refuse\n * @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\n * @example\n * ```ts\n * computeStudyOutputStop(2048, 1024, []) // { layer: 'scope', id: 'Goal bytes', max: 1024, consumed: 2048 }\n * ```\n */\nexport function computeStudyOutputStop(\n\tbytes: number,\n\tlimit: number,\n\toutputs: ReadonlyArray<BudgetInterface<number>>,\n): StudyStop | undefined {\n\tif (bytes > limit) return { layer: 'scope', id: 'Goal bytes', max: limit, consumed: bytes }\n\tconst refusal = outputs.find((budget) => bytes > budget.remaining)\n\treturn refusal === undefined\n\t\t? undefined\n\t\t: { layer: 'scope', id: refusal.id, max: refusal.max, consumed: refusal.consumed + bytes }\n}\n\n/**\n * Records an error that escaped admitted work as the failure of its ticket.\n * @param ticket - The admitted request whose work escaped\n * @param error - The caught value, read through `readStudyFailure`\n * @param role - The responsibility that replaces any role the reading carries; Default: the carried role, else the ticket's admitted role\n * @remarks\n * A ticket that already settled or whose signal aborted is left untouched, because its owner\n * already holds the failure. A remote ticket's aborted signal does not mean it settled locally,\n * so the parent's ownership is respected rather than inferred as local settlement. A refusal\n * thrown by the ticket's own settlement propagates.\n * @throws Thrown when the ticket's settlement refuses the failure.\n * @example Fail an escaped request\n * ```ts\n * import type { StudyTicket } from '@orkestrel/study'\n * import { failStudyTicket } from '@orkestrel/study'\n *\n * declare const ticket: StudyTicket\n *\n * failStudyTicket(ticket, new Error('Provider refused'), 'tool')\n * ```\n */\nexport function failStudyTicket(ticket: StudyTicket, error: unknown, role?: StudyRole): void {\n\tif (ticket.settled || ticket.signal.aborted) return\n\tconst failure = readStudyFailure(error)\n\tticket.fail(role === undefined ? failure : { ...failure, role })\n}\n","import type { StudyFailure } from '../types.js'\nimport type { StudyControlInterface } from './types.js'\nimport { Abort } from '@orkestrel/abort'\nimport { failureToStudyError } from './helpers.js'\n\n/** Retains the first operational failure while bounding asynchronous waits. */\nexport class StudyControl implements StudyControlInterface {\n\t#abort: Abort\n\t#listeners = new Abort()\n\t#failure: StudyFailure | undefined\n\n\t/** Links cancellation to the caller without assigning it a task verdict.\n\t * @param signal - Optional parent cancellation.\n\t */\n\tconstructor(signal?: AbortSignal) {\n\t\tthis.#abort = new Abort(signal === undefined ? undefined : { signal })\n\t\tif (this.#abort.aborted) this.#interrupt()\n\t\telse\n\t\t\tthis.#abort.signal.addEventListener('abort', () => this.#interrupt(), {\n\t\t\t\tonce: true,\n\t\t\t\tsignal: this.#listeners.signal,\n\t\t\t})\n\t}\n\n\tget signal(): AbortSignal {\n\t\treturn this.#abort.signal\n\t}\n\tget failure(): StudyFailure | undefined {\n\t\treturn this.#failure\n\t}\n\n\t/** Latches an operational failure and cancels all linked work.\n\t * @param failure - The first attribution to preserve.\n\t */\n\tfail(failure: StudyFailure): void {\n\t\tif (this.#failure !== undefined) return\n\t\tthis.#failure = Object.freeze({\n\t\t\t...failure,\n\t\t\tstop: failure.stop === undefined ? undefined : Object.freeze({ ...failure.stop }),\n\t\t})\n\t\tthis.#abort.abort(failureToStudyError(this.#failure))\n\t}\n\n\t/** Races work against cancellation and removes its listener after either ending.\n\t * @param work - Already-started work whose rejection remains observed after cancellation.\n\t * @returns The work's result if it settles before cancellation.\n\t * @throws Thrown with the retained operational attribution when cancelled.\n\t */\n\twait<T>(work: PromiseLike<T>): Promise<T> {\n\t\tconst listeners = new Abort()\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tPromise.resolve(work).then(resolve, reject)\n\t\t\tif (this.#abort.aborted) reject(this.#reason())\n\t\t\telse\n\t\t\t\tthis.#abort.signal.addEventListener('abort', () => reject(this.#reason()), {\n\t\t\t\t\tonce: true,\n\t\t\t\t\tsignal: listeners.signal,\n\t\t\t\t})\n\t\t}).finally(() => listeners.abort())\n\t}\n\n\t/** Removes the lifecycle listener without changing the retained failure. */\n\tclose(): void {\n\t\tthis.#listeners.abort()\n\t}\n\n\t#reason(): Error {\n\t\treturn failureToStudyError(\n\t\t\tthis.#failure ?? {\n\t\t\t\tcause: 'interrupted',\n\t\t\t\tmessage: 'Study interrupted',\n\t\t\t\trole: undefined,\n\t\t\t\tstop: undefined,\n\t\t\t},\n\t\t)\n\t}\n\n\t#interrupt(): void {\n\t\tif (this.#failure === undefined)\n\t\t\tthis.fail({\n\t\t\t\tcause: 'interrupted',\n\t\t\t\tmessage: 'Study interrupted by parent cancellation',\n\t\t\t\trole: undefined,\n\t\t\t\tstop: undefined,\n\t\t\t})\n\t}\n}\n","import type { StudyCharge, StudyFailure, StudyUsage } from '../types.js'\nimport type { StudyScopeInterface, StudyScopeOptions } from './types.js'\nimport { Abort } from '@orkestrel/abort'\nimport { Budget } from '@orkestrel/budget'\nimport { Timeout } from '@orkestrel/timeout'\nimport { StudyError } from '../errors.js'\nimport { isStudyLimit } from '../validators.js'\nimport { failureToStudyError } from './helpers.js'\n\n/** Reserves finite request ceilings around cumulative actual budgets and one deadline. */\nexport class StudyScope implements StudyScopeInterface {\n\t#options: StudyScopeOptions\n\t#calls: Budget<number>\n\t#tokens: Budget<number>\n\t#bytes: Budget<number>\n\t#timeout: Timeout\n\t#listeners = new Abort()\n\treadonly #pending = new Map<symbol, StudyCharge>()\n\t#started = performance.now()\n\t#closed = false\n\n\t/** Starts a timed scope with independent counters.\n\t * @param options - Finite limit, shared failure owner, and diagnostic label.\n\t */\n\tconstructor(options: StudyScopeOptions) {\n\t\tif (!isStudyLimit(options.limit)) throw new StudyError('CONFIG', 'Invalid study scope limit')\n\t\tthis.#options = { ...options, limit: { ...options.limit } }\n\t\tthis.#calls = new Budget({ max: options.limit.calls, consumer: (value: number) => value })\n\t\tthis.#tokens = new Budget({ max: options.limit.tokens, consumer: (value: number) => value })\n\t\tthis.#bytes = new Budget({ max: options.limit.bytes, consumer: (value: number) => value })\n\t\tthis.#timeout = new Timeout({ ms: options.limit.duration })\n\t\tthis.#timeout.signal.addEventListener('abort', () => this.#expire(), {\n\t\t\tonce: true,\n\t\t\tsignal: this.#listeners.signal,\n\t\t})\n\t\tthis.#timeout.start()\n\t}\n\n\t/** Checks cumulative consumption and every pending ceiling before admission.\n\t * @param charge - One prospective request's ceilings.\n\t * @throws Thrown when this scope cannot admit the request.\n\t */\n\tcheck(charge?: StudyCharge): void {\n\t\tthis.#checkTime()\n\t\tif (this.#closed) throw new StudyError('FAULT', 'Study scope is closed')\n\t\tconst prior = this.#options.control.failure\n\t\tif (prior !== undefined) throw failureToStudyError(prior)\n\t\tif (charge === undefined) return\n\t\tconst pending = [...this.#pending.values()]\n\t\tconst tokens = pending.reduce((total, entry) => total + entry.tokens, 0)\n\t\tconst bytes = pending.reduce((total, entry) => total + entry.bytes, 0)\n\t\tconst { label, limit } = this.#options\n\t\tconst refusal = [\n\t\t\t{\n\t\t\t\tid: `${label} calls`,\n\t\t\t\trefused: this.#calls.remaining - this.#pending.size < 1,\n\t\t\t\tmax: limit.calls,\n\t\t\t\tconsumed: this.#calls.consumed + this.#pending.size + 1,\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: `${label} tokens`,\n\t\t\t\trefused: this.#tokens.remaining - tokens < charge.tokens,\n\t\t\t\tmax: limit.tokens,\n\t\t\t\tconsumed: this.#tokens.consumed + tokens + charge.tokens,\n\t\t\t},\n\t\t\t{\n\t\t\t\tid: `${label} bytes`,\n\t\t\t\trefused: this.#bytes.remaining - bytes < charge.bytes,\n\t\t\t\tmax: limit.bytes,\n\t\t\t\tconsumed: this.#bytes.consumed + bytes + charge.bytes,\n\t\t\t},\n\t\t].find((entry) => entry.refused)\n\t\tif (refusal !== undefined) {\n\t\t\tconst failure: StudyFailure = {\n\t\t\t\tcause: 'capacity',\n\t\t\t\tmessage: `${label} allowance cannot admit the request`,\n\t\t\t\trole: charge.role,\n\t\t\t\tstop: { layer: 'scope', id: refusal.id, max: refusal.max, consumed: refusal.consumed },\n\t\t\t}\n\t\t\tthis.#options.control.fail(failure)\n\t\t\tthrow failureToStudyError(failure)\n\t\t}\n\t}\n\n\t/** Reserves one request after the enclosing meter checked all scopes.\n\t * @param id - The request's unique reservation identity.\n\t * @param charge - Its admitted ceilings.\n\t */\n\treserve(id: symbol, charge: StudyCharge): void {\n\t\tif (this.#pending.has(id)) throw new StudyError('FAULT', 'Duplicate study reservation')\n\t\tthis.#pending.set(id, { ...charge })\n\t}\n\n\t/** Commits known charges while retaining ceilings for missing measurements.\n\t * @param id - The pending reservation identity.\n\t * @param usage - The request's retained public measurements.\n\t */\n\tsettle(id: symbol, usage: StudyUsage): void {\n\t\tconst charge = this.#pending.get(id)\n\t\tif (charge === undefined) throw new StudyError('FAULT', 'Study reservation is not pending')\n\t\tthis.#pending.delete(id)\n\t\tthis.#calls.consume(1)\n\t\tthis.#tokens.consume(Math.min(charge.tokens, usage.tokens ?? charge.tokens))\n\t\tthis.#bytes.consume(Math.min(charge.bytes, usage.bytes ?? charge.bytes))\n\t}\n\n\t/** Checks deadline attribution before clearing the timer. */\n\tclose(): void {\n\t\tif (this.#closed) return\n\t\tthis.#checkTime()\n\t\tthis.#closed = true\n\t\tthis.#listeners.abort()\n\t\tthis.#timeout.clear()\n\t}\n\n\t#checkTime(): void {\n\t\tif (\n\t\t\t!this.#closed &&\n\t\t\t(this.#timeout.expired || performance.now() - this.#started >= this.#options.limit.duration)\n\t\t)\n\t\t\tthis.#expire()\n\t}\n\n\t#expire(): void {\n\t\tthis.#options.control.fail({\n\t\t\tcause: 'deadline',\n\t\t\tmessage: `${this.#options.label} deadline expired`,\n\t\t\trole: undefined,\n\t\t\tstop: {\n\t\t\t\tlayer: 'scope',\n\t\t\t\tid: `${this.#options.label} duration`,\n\t\t\t\tmax: this.#options.limit.duration,\n\t\t\t\tconsumed: Math.ceil(performance.now() - this.#started),\n\t\t\t},\n\t\t})\n\t}\n}\n","import type { StudyDeadlineInterface, StudyDeadlineOptions } from './types.js'\nimport { StudyControl } from './StudyControl.js'\nimport { StudyScope } from './StudyScope.js'\n\n/** Bounds each independent operation with a fresh failure owner and deadline. */\nexport class StudyDeadline implements StudyDeadlineInterface {\n\t#options: StudyDeadlineOptions\n\n\t/** Retains the deadline without starting a timer.\n\t * @param options - Finite duration in milliseconds and diagnostic label.\n\t */\n\tconstructor(options: StudyDeadlineOptions) {\n\t\tthis.#options = { ...options }\n\t}\n\n\t/** Waits for work under a fresh failure owner and releases its timer and listener.\n\t * @param work - Already-started work whose late rejection remains observed.\n\t * @returns The work's result when it settles before the deadline.\n\t * @throws Thrown for an invalid duration, the work's own rejection, or the labelled deadline.\n\t */\n\tasync wait<T>(work: PromiseLike<T>): Promise<T> {\n\t\tconst control = new StudyControl()\n\t\tconst scope = this.#open(control, work)\n\t\ttry {\n\t\t\tconst result = await control.wait(work)\n\t\t\tscope.check()\n\t\t\treturn result\n\t\t} finally {\n\t\t\tscope.close()\n\t\t\tcontrol.close()\n\t\t}\n\t}\n\n\t// Opens the deadline scope; an invalid duration closes the owner and keeps the work's late rejection observed.\n\t#open(control: StudyControl, work: PromiseLike<unknown>): StudyScope {\n\t\ttry {\n\t\t\treturn new StudyScope({\n\t\t\t\tlimit: { duration: this.#options.duration, calls: 1, tokens: 1, bytes: 1 },\n\t\t\t\tcontrol,\n\t\t\t\tlabel: this.#options.label,\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tPromise.resolve(work).catch(() => undefined)\n\t\t\tcontrol.close()\n\t\t\tthrow error\n\t\t}\n\t}\n}\n","import type { StudyFailure, StudyTicket, StudyUsage } from '../types.js'\nimport type { StudyRequestOptions } from './types.js'\nimport { Abort, linkSignal } from '@orkestrel/abort'\nimport { Timeout } from '@orkestrel/timeout'\nimport { StudyError } from '../errors.js'\nimport { isStudyUsage } from '../validators.js'\nimport { computeStudyAdmittedStop, failureToStudyError } from './helpers.js'\n\n/** Settles an admitted request once and propagates operational failure to its owner. */\nexport class StudyRequest implements StudyTicket {\n\t#options: StudyRequestOptions\n\t#timeout: Timeout\n\t#signal: AbortSignal\n\t#listeners = new Abort()\n\t#started = performance.now()\n\t#settled = false\n\n\t/** Starts the request deadline after its enclosing scopes reserve capacity.\n\t * @param options - Admitted ceilings, request deadline, and settlement callback.\n\t */\n\tconstructor(options: StudyRequestOptions) {\n\t\tthis.#options = { ...options, charge: { ...options.charge } }\n\t\tthis.#timeout = new Timeout({ ms: options.duration })\n\t\tthis.#signal = linkSignal(this.#timeout.signal, options.control.signal)\n\t\tthis.#signal.addEventListener('abort', () => this.#abort(), {\n\t\t\tonce: true,\n\t\t\tsignal: this.#listeners.signal,\n\t\t})\n\t\tthis.#timeout.start()\n\t\tif (this.#signal.aborted) this.#abort()\n\t}\n\n\tget signal(): AbortSignal {\n\t\treturn this.#signal\n\t}\n\tget settled(): boolean {\n\t\treturn this.#settled\n\t}\n\n\t/** Retains actual measurements and refuses invalid or excessive charges.\n\t * @param usage - Measurements attributed to exactly this request.\n\t * @throws Thrown when settlement is late, repeated, invalid, or beyond admission.\n\t */\n\tfinish(usage: StudyUsage): void {\n\t\tthis.#checkPending()\n\t\tif (!isStudyUsage(usage) || usage.role !== this.#options.charge.role || usage.calls !== 1) {\n\t\t\tconst failure: StudyFailure = {\n\t\t\t\tcause: 'infrastructure',\n\t\t\t\tmessage: 'Request usage is invalid or misattributed',\n\t\t\t\trole: this.#options.charge.role,\n\t\t\t\tstop: undefined,\n\t\t\t}\n\t\t\tthis.fail(failure)\n\t\t\tthrow failureToStudyError(failure)\n\t\t}\n\t\tconst elapsed = performance.now() - this.#started\n\t\tconst admitted = computeStudyAdmittedStop(this.#options.charge, usage)\n\t\tconst failure: StudyFailure | undefined =\n\t\t\tthis.#timeout.expired ||\n\t\t\telapsed >= this.#options.duration ||\n\t\t\tusage.duration > this.#options.duration\n\t\t\t\t? {\n\t\t\t\t\t\tcause: 'deadline',\n\t\t\t\t\t\tmessage: 'Request deadline expired',\n\t\t\t\t\t\trole: usage.role,\n\t\t\t\t\t\tstop: {\n\t\t\t\t\t\t\tlayer: 'scope',\n\t\t\t\t\t\t\tid: 'Request duration',\n\t\t\t\t\t\t\tmax: this.#options.duration,\n\t\t\t\t\t\t\tconsumed: Math.ceil(Math.max(elapsed, usage.duration)),\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: admitted !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcause: 'capacity',\n\t\t\t\t\t\t\tmessage: 'Request usage exceeded its admitted ceiling',\n\t\t\t\t\t\t\trole: usage.role,\n\t\t\t\t\t\t\tstop: admitted,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined\n\t\tthis.#complete(usage)\n\t\tif (failure !== undefined) {\n\t\t\tthis.#options.control.fail(failure)\n\t\t\tthrow failureToStudyError(failure)\n\t\t}\n\t}\n\n\t/** Retains unknown cost conservatively and latches the first operational failure.\n\t * @param failure - The operational request failure.\n\t * @throws Thrown when this request was already settled.\n\t */\n\tfail(failure: StudyFailure): void {\n\t\tthis.#checkPending()\n\t\tthis.#complete({\n\t\t\trole: this.#options.charge.role,\n\t\t\tcalls: 1,\n\t\t\ttokens: undefined,\n\t\t\tbytes: undefined,\n\t\t\tduration: Math.ceil(performance.now() - this.#started),\n\t\t})\n\t\tthis.#options.control.fail({ ...failure, role: failure.role ?? this.#options.charge.role })\n\t}\n\n\t#complete(usage: StudyUsage): void {\n\t\tthis.#settled = true\n\t\tthis.#listeners.abort()\n\t\tthis.#timeout.clear()\n\t\tthis.#options.settle(Object.freeze({ ...usage }))\n\t}\n\n\t#checkPending(): void {\n\t\tif (this.#settled) {\n\t\t\tthis.#options.control.fail({\n\t\t\t\tcause: 'infrastructure',\n\t\t\t\tmessage: 'Request settlement is late or repeated',\n\t\t\t\trole: this.#options.charge.role,\n\t\t\t\tstop: undefined,\n\t\t\t})\n\t\t\tthrow new StudyError(\n\t\t\t\t'FAULT',\n\t\t\t\t'Request settlement is late or repeated',\n\t\t\t\tthis.#options.control.failure,\n\t\t\t)\n\t\t}\n\t}\n\n\t#abort(): void {\n\t\tif (this.#settled) return\n\t\tconst expired = this.#timeout.expired\n\t\tthis.fail(\n\t\t\tthis.#options.control.failure ?? {\n\t\t\t\tcause: expired ? 'deadline' : 'interrupted',\n\t\t\t\tmessage: expired ? 'Request deadline expired' : 'Request interrupted',\n\t\t\t\trole: this.#options.charge.role,\n\t\t\t\tstop: expired\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tlayer: 'scope',\n\t\t\t\t\t\t\tid: 'Request duration',\n\t\t\t\t\t\t\tmax: this.#options.duration,\n\t\t\t\t\t\t\tconsumed: Math.ceil(performance.now() - this.#started),\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t)\n\t}\n}\n","import type { StudyCharge, StudyFailure, StudyTicket, StudyUsage } from '../types.js'\nimport type { StudyMeterInterface, StudyMeterOptions } from './types.js'\nimport { StudyError } from '../errors.js'\nimport { isStudyLimit, isStudyRole } from '../validators.js'\nimport { failureToStudyError } from './helpers.js'\nimport { StudyRequest } from './StudyRequest.js'\n\n/** Admits request ceilings across every enclosing scope before dispatch. */\nexport class StudyMeter implements StudyMeterInterface {\n\t#options: StudyMeterOptions\n\treadonly #pending = new Set<symbol>()\n\t#usage: readonly StudyUsage[] = []\n\t#closed = false\n\n\t/** Holds the goal's shared admission scopes.\n\t * @param options - Request bound, enclosing scopes, and shared failure owner.\n\t */\n\tconstructor(options: StudyMeterOptions) {\n\t\tif (\n\t\t\t!isStudyLimit(options.request) ||\n\t\t\toptions.request.calls !== 1 ||\n\t\t\toptions.scopes.length === 0\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Invalid request admission bounds')\n\t\tthis.#options = { ...options, request: { ...options.request }, scopes: [...options.scopes] }\n\t}\n\n\tget signal(): AbortSignal {\n\t\treturn this.#options.control.signal\n\t}\n\tget usage(): readonly StudyUsage[] {\n\t\treturn Object.freeze([...this.#usage])\n\t}\n\n\t/** Reserves one request atomically across all enclosing allowances.\n\t * @param charge - Safe integer token and byte ceilings with the request's role.\n\t * @returns A request ticket that must settle before the goal completes.\n\t * @throws Thrown before dispatch if the request exceeds available capacity.\n\t */\n\tadmit(charge: StudyCharge): StudyTicket {\n\t\tif (this.#closed) throw new StudyError('FAULT', 'Study meter is closed')\n\t\tif (this.#options.control.failure !== undefined)\n\t\t\tthrow failureToStudyError(this.#options.control.failure)\n\t\tif (\n\t\t\t!isStudyRole(charge.role) ||\n\t\t\t!Number.isSafeInteger(charge.tokens) ||\n\t\t\tcharge.tokens < 0 ||\n\t\t\t!Number.isSafeInteger(charge.bytes) ||\n\t\t\tcharge.bytes < 0\n\t\t) {\n\t\t\tconst failure: StudyFailure = {\n\t\t\t\tcause: 'infrastructure',\n\t\t\t\tmessage: 'Request admission requires safe nonnegative ceilings',\n\t\t\t\trole: undefined,\n\t\t\t\tstop: undefined,\n\t\t\t}\n\t\t\tthis.#options.control.fail(failure)\n\t\t\tthrow failureToStudyError(failure)\n\t\t}\n\t\tconst { request } = this.#options\n\t\tif (charge.tokens > request.tokens || charge.bytes > request.bytes) {\n\t\t\tconst tokens = charge.tokens > request.tokens\n\t\t\tconst failure: StudyFailure = {\n\t\t\t\tcause: 'capacity',\n\t\t\t\tmessage: 'Request ceiling exceeds the request allowance',\n\t\t\t\trole: charge.role,\n\t\t\t\tstop: {\n\t\t\t\t\tlayer: 'scope',\n\t\t\t\t\tid: tokens ? 'Request tokens' : 'Request bytes',\n\t\t\t\t\tmax: tokens ? request.tokens : request.bytes,\n\t\t\t\t\tconsumed: tokens ? charge.tokens : charge.bytes,\n\t\t\t\t},\n\t\t\t}\n\t\t\tthis.#options.control.fail(failure)\n\t\t\tthrow failureToStudyError(failure)\n\t\t}\n\t\tfor (const scope of this.#options.scopes) scope.check(charge)\n\t\tconst id = Symbol('request')\n\t\tfor (const scope of this.#options.scopes) scope.reserve(id, charge)\n\t\tthis.#pending.add(id)\n\t\treturn new StudyRequest({\n\t\t\tcharge,\n\t\t\tduration: this.#options.request.duration,\n\t\t\tcontrol: this.#options.control,\n\t\t\tsettle: (usage) => {\n\t\t\t\tfor (const scope of this.#options.scopes) scope.settle(id, usage)\n\t\t\t\tthis.#pending.delete(id)\n\t\t\t\tthis.#usage = [...this.#usage, usage]\n\t\t\t},\n\t\t})\n\t}\n\n\t/** Refuses unfinished requests before closing a goal's admission boundary. */\n\tclose(): void {\n\t\tif (this.#closed) return\n\t\tthis.#closed = true\n\t\tif (this.#pending.size > 0)\n\t\t\tthis.#options.control.fail({\n\t\t\t\tcause: 'infrastructure',\n\t\t\t\tmessage: 'Goal completed with unsettled requests',\n\t\t\t\trole: undefined,\n\t\t\t\tstop: undefined,\n\t\t\t})\n\t}\n}\n","import type {\n\tStudyFailure,\n\tStudySeriesOptions,\n\tStudySessionInterface,\n\tStudySinkInterface,\n\tStudyTrial,\n} from '../types.js'\nimport type { StudyControl } from './StudyControl.js'\nimport type { StudyDeadline } from './StudyDeadline.js'\nimport { StudyError } from '../errors.js'\nimport { failureToStudyError, readStudyFailure } from './helpers.js'\nimport { StudyScope } from './StudyScope.js'\n\n/** Holds one trial's evidence custody, admission scope and driver session from opening to cleanup. */\nexport class StudyTrialLease {\n\treadonly #trial: StudyTrial\n\treadonly #options: StudySeriesOptions\n\treadonly #control: StudyControl\n\treadonly #series: StudyScope\n\treadonly #deadline: StudyDeadline\n\t#scope: StudyScope | undefined\n\t#evidence: StudySinkInterface | undefined\n\t#opening: Promise<StudySessionInterface> | undefined\n\t#session: StudySessionInterface | undefined\n\n\t/** Binds one scheduled trial to the series' owned inputs, failure owner, series scope and cleanup deadline.\n\t * @param trial - The scheduled trial.\n\t * @param options - The series' owned manifest, driver and store.\n\t * @param control - The series failure owner.\n\t * @param series - The series admission scope.\n\t * @param deadline - The custody and cleanup deadline.\n\t */\n\tconstructor(\n\t\ttrial: StudyTrial,\n\t\toptions: StudySeriesOptions,\n\t\tcontrol: StudyControl,\n\t\tseries: StudyScope,\n\t\tdeadline: StudyDeadline,\n\t) {\n\t\tthis.#trial = trial\n\t\tthis.#options = options\n\t\tthis.#control = control\n\t\tthis.#series = series\n\t\tthis.#deadline = deadline\n\t}\n\n\t/** Reports the trial scope once opened; undefined when the trial inherited a failure. */\n\tget scope(): StudyScope | undefined {\n\t\treturn this.#scope\n\t}\n\n\t/** Reports the trial's evidence sink once custody started. */\n\tget evidence(): StudySinkInterface | undefined {\n\t\treturn this.#evidence\n\t}\n\n\t/** Reports the driver session once it opened. */\n\tget session(): StudySessionInterface | undefined {\n\t\treturn this.#session\n\t}\n\n\t/** Starts evidence custody and, unless a failure is latched, opens the trial scope and driver session.\n\t * @returns Nothing after the session opened, or after custody alone started under a latched failure.\n\t * @throws StudyError - Thrown with code `CUSTODY` when custody refuses the trial; thrown for a series or trial limit or an opening failure.\n\t */\n\tasync open(): Promise<void> {\n\t\tconst control = this.#control\n\t\tif (control.failure !== undefined) {\n\t\t\tthis.#evidence = await this.#start()\n\t\t\treturn\n\t\t}\n\t\tthis.#series.check()\n\t\tconst scope = new StudyScope({\n\t\t\tlimit: this.#options.manifest.bounds.trial,\n\t\t\tcontrol,\n\t\t\tlabel: 'Trial',\n\t\t})\n\t\tthis.#scope = scope\n\t\tthis.#evidence = await this.#start()\n\t\tthis.#series.check()\n\t\tscope.check()\n\t\tconst opening = this.#launch()\n\t\tthis.#opening = opening\n\t\tthis.#session = await control.wait(opening)\n\t}\n\n\t/** Closes the opened session, or a session that opened late, then the trial scope.\n\t * @returns The cleanup failure, or undefined when cleanup succeeded or repeated the latched failure.\n\t */\n\tasync close(): Promise<StudyFailure | undefined> {\n\t\tconst cleanup = await this.#release()\n\t\tthis.#scope?.close()\n\t\treturn cleanup\n\t}\n\n\t// Closes the session or awaits and closes a late opening; a session close failure is latched, a late one only reported when it differs.\n\tasync #release(): Promise<StudyFailure | undefined> {\n\t\tconst session = this.#session\n\t\tconst opening = this.#opening\n\t\tif (session !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait this.#deadline.wait(session.close())\n\t\t\t\treturn undefined\n\t\t\t} catch (error) {\n\t\t\t\tconst cleanup = readStudyFailure(error)\n\t\t\t\tthis.#control.fail(cleanup)\n\t\t\t\treturn cleanup\n\t\t\t}\n\t\t}\n\t\tif (opening === undefined) return undefined\n\t\ttry {\n\t\t\tconst late = await this.#deadline.wait(opening)\n\t\t\tawait this.#deadline.wait(late.close())\n\t\t\treturn undefined\n\t\t} catch (error) {\n\t\t\tconst late = readStudyFailure(error)\n\t\t\treturn late.message !== this.#control.failure?.message ? late : undefined\n\t\t}\n\t}\n\n\t// Opens the driver session; a failure latched while it opened closes it and refuses.\n\tasync #launch(): Promise<StudySessionInterface> {\n\t\tconst control = this.#control\n\t\tconst session = await this.#options.driver.open(this.#trial, control.signal)\n\t\tif (control.failure !== undefined) {\n\t\t\tawait this.#deadline.wait(session.close())\n\t\t\tthrow failureToStudyError(control.failure)\n\t\t}\n\t\treturn session\n\t}\n\n\t// Starts evidence custody; a refusal latches the failure and surfaces as a custody error.\n\tasync #start(): Promise<StudySinkInterface> {\n\t\tconst control = this.#control\n\t\ttry {\n\t\t\tconst pending = this.#options.store.start(this.#trial)\n\t\t\treturn control.failure === undefined\n\t\t\t\t? await control.wait(pending)\n\t\t\t\t: await this.#deadline.wait(pending)\n\t\t} catch (error) {\n\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t\tconst failure = control.failure ?? readStudyFailure(error)\n\t\t\tthrow new StudyError('CUSTODY', failure.message, failure)\n\t\t}\n\t}\n}\n","import type {\n\tStudyAttempt,\n\tStudyFailure,\n\tStudyGoal,\n\tStudyObservation,\n\tStudyProduct,\n\tStudyScenario,\n\tStudySeriesOptions,\n\tStudySessionInterface,\n\tStudySinkInterface,\n\tStudyTrial,\n} from '../types.js'\nimport { Budget } from '@orkestrel/budget'\nimport { canonicalStringify, cloneJSONValue } from '@orkestrel/contract'\nimport { isStudyError, StudyError } from '../errors.js'\nimport { buildStudySchedule } from '../helpers.js'\nimport { isStudyBounds, isStudyProduct } from '../validators.js'\nimport { computeStudyOutputStop, readStudyFailure } from './helpers.js'\nimport { StudyControl } from './StudyControl.js'\nimport { StudyDeadline } from './StudyDeadline.js'\nimport { StudyMeter } from './StudyMeter.js'\nimport { StudyScope } from './StudyScope.js'\nimport { StudyTrialLease } from './StudyTrialLease.js'\n\n/** Executes a frozen serial study schedule with finite admission and sticky failures. */\nexport class StudySeries {\n\t#options: StudySeriesOptions\n\t#executed = false\n\n\t/** Owns the declared inputs while retaining the concrete driver and custody store.\n\t * @param options - Frozen manifest, concrete adapters, and parent cancellation.\n\t */\n\tconstructor(options: StudySeriesOptions) {\n\t\tthis.#options = { ...options, manifest: structuredClone(options.manifest) }\n\t}\n\n\t/** Runs every declared trial once and retains explicit unexecuted observations after failure.\n\t * Custody rejection leaves the run unsealed; callers must seal only a fulfilled execution.\n\t * @returns Ordered terminal attempts without task success labels.\n\t * @throws Thrown for invalid configuration or failed or timed out custody operations.\n\t */\n\tasync execute(): Promise<readonly StudyAttempt[]> {\n\t\tif (this.#executed) throw new StudyError('CONFIG', 'Study series can execute only once')\n\t\tthis.#executed = true\n\t\tconst manifest = this.#options.manifest\n\t\tconst expected = buildStudySchedule(manifest.definition, manifest.scenarios)\n\t\tif (\n\t\t\t!isStudyBounds(manifest.bounds) ||\n\t\t\tcanonicalStringify(expected) !== canonicalStringify(manifest.schedule)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Study manifest schedule or bounds are invalid')\n\t\tconst control = new StudyControl(this.#options.signal)\n\t\tconst scope = new StudyScope({ limit: manifest.bounds.series, control, label: 'Series' })\n\t\tconst deadline = new StudyDeadline({\n\t\t\tduration: manifest.bounds.request.duration,\n\t\t\tlabel: 'Custody or cleanup',\n\t\t})\n\t\tconst output = new Budget({\n\t\t\tid: 'Series output',\n\t\t\tmax: manifest.bounds.series.bytes,\n\t\t\tconsumer: (bytes: number) => bytes,\n\t\t})\n\t\tconst attempts: StudyAttempt[] = []\n\t\ttry {\n\t\t\tfor (const trial of manifest.schedule)\n\t\t\t\tattempts.push(await this.#executeTrial(trial, control, scope, output, deadline))\n\t\t} finally {\n\t\t\tscope.close()\n\t\t\tcontrol.close()\n\t\t}\n\t\treturn Object.freeze(attempts)\n\t}\n\n\tasync #executeTrial(\n\t\ttrial: StudyTrial,\n\t\tcontrol: StudyControl,\n\t\tseries: StudyScope,\n\t\toutput: Budget<number>,\n\t\tdeadline: StudyDeadline,\n\t): Promise<StudyAttempt> {\n\t\tconst started = performance.now()\n\t\tconst scenario = this.#options.manifest.scenarios.find((entry) => entry.id === trial.scenario)\n\t\tif (scenario === undefined) throw new StudyError('CONFIG', 'Scheduled scenario is absent')\n\t\tconst prior = control.failure\n\t\tconst lease = new StudyTrialLease(trial, this.#options, control, series, deadline)\n\t\tconst executed = await this.#executeGoals(scenario, lease, control, series, output)\n\t\tconst cleanup = await this.#release(lease, control, series)\n\t\tconst failure = control.failure\n\t\tconst observations: readonly StudyObservation[] = [\n\t\t\t...executed,\n\t\t\t...scenario.goals.slice(executed.length).map((goal): StudyObservation => {\n\t\t\t\tconst unexecuted: StudyFailure =\n\t\t\t\t\tfailure === undefined\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tcause: 'infrastructure',\n\t\t\t\t\t\t\t\tmessage: 'Goal unexecuted because the trial did not open',\n\t\t\t\t\t\t\t\trole: undefined,\n\t\t\t\t\t\t\t\tstop: undefined,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: { ...failure, message: `Goal unexecuted: ${failure.message}` }\n\t\t\t\treturn Object.freeze({\n\t\t\t\t\tgoal: goal.id,\n\t\t\t\t\tproduct: undefined,\n\t\t\t\t\tfailure: unexecuted,\n\t\t\t\t\tusage: Object.freeze([]),\n\t\t\t\t\tduration: 0,\n\t\t\t\t\texecuted: false,\n\t\t\t\t})\n\t\t\t}),\n\t\t]\n\t\tconst attempt: StudyAttempt = Object.freeze({\n\t\t\ttrial,\n\t\t\tobservations: Object.freeze(observations),\n\t\t\tfailure:\n\t\t\t\tcleanup !== undefined &&\n\t\t\t\tfailure !== undefined &&\n\t\t\t\t(prior !== undefined || failure.message !== cleanup.message)\n\t\t\t\t\t? { ...failure, message: `${failure.message}; cleanup: ${cleanup.message}` }\n\t\t\t\t\t: failure,\n\t\t\tduration: Math.ceil(performance.now() - started),\n\t\t\t// The trial entered execution unless it inherited a terminal series failure at its\n\t\t\t// boundary. This does not claim that driver.open ran.\n\t\t\texecuted: prior === undefined,\n\t\t})\n\t\ttry {\n\t\t\tawait deadline.wait(this.#options.store.finish(attempt))\n\t\t\tif (attempt.failure === undefined) series.check()\n\t\t} catch (error) {\n\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t\tconst custody = control.failure ?? readStudyFailure(error)\n\t\t\tthrow new StudyError('CUSTODY', custody.message, custody)\n\t\t}\n\t\treturn attempt\n\t}\n\n\t// Opens the lease and executes each goal while the trial stays open; a custody refusal releases the lease before it propagates.\n\tasync #executeGoals(\n\t\tscenario: StudyScenario,\n\t\tlease: StudyTrialLease,\n\t\tcontrol: StudyControl,\n\t\tseries: StudyScope,\n\t\toutput: Budget<number>,\n\t): Promise<readonly StudyObservation[]> {\n\t\tconst observations: StudyObservation[] = []\n\t\ttry {\n\t\t\tawait lease.open()\n\t\t\tconst trialOutput = new Budget({\n\t\t\t\tid: 'Trial output',\n\t\t\t\tmax: this.#options.manifest.bounds.trial.bytes,\n\t\t\t\tconsumer: (bytes: number) => bytes,\n\t\t\t})\n\t\t\tfor (const goal of scenario.goals) {\n\t\t\t\tconst { session, scope, evidence } = lease\n\t\t\t\tif (\n\t\t\t\t\tcontrol.failure !== undefined ||\n\t\t\t\t\tsession === undefined ||\n\t\t\t\t\tscope === undefined ||\n\t\t\t\t\tevidence === undefined\n\t\t\t\t)\n\t\t\t\t\tbreak\n\t\t\t\tseries.check()\n\t\t\t\tscope.check()\n\t\t\t\tobservations.push(\n\t\t\t\t\tawait this.#executeGoal(\n\t\t\t\t\t\tgoal,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tevidence,\n\t\t\t\t\t\tcontrol,\n\t\t\t\t\t\t[scope, series],\n\t\t\t\t\t\t[trialOutput, output],\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (isStudyError(error) && error.code === 'CUSTODY') {\n\t\t\t\tawait this.#release(lease, control, series)\n\t\t\t\tthrow error\n\t\t\t}\n\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t}\n\t\treturn observations\n\t}\n\n\t// Closes the lease, then rechecks the series ceiling, and returns the lease's cleanup failure.\n\tasync #release(\n\t\tlease: StudyTrialLease,\n\t\tcontrol: StudyControl,\n\t\tseries: StudyScope,\n\t): Promise<StudyFailure | undefined> {\n\t\tconst cleanup = await lease.close()\n\t\ttry {\n\t\t\tseries.check()\n\t\t} catch (error) {\n\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t}\n\t\treturn cleanup\n\t}\n\n\tasync #executeGoal(\n\t\tgoal: StudyGoal,\n\t\tsession: StudySessionInterface,\n\t\tevidence: StudySinkInterface,\n\t\tcontrol: StudyControl,\n\t\tparents: readonly StudyScope[],\n\t\toutputs: ReadonlyArray<Budget<number>>,\n\t): Promise<StudyObservation> {\n\t\tconst started = performance.now()\n\t\tconst bounds = this.#options.manifest.bounds\n\t\tconst scope = new StudyScope({ limit: bounds.goal, control, label: 'Goal' })\n\t\tconst meter = new StudyMeter({ request: bounds.request, scopes: [scope, ...parents], control })\n\t\tconst product = await this.#produce(\n\t\t\tgoal,\n\t\t\tsession,\n\t\t\tevidence,\n\t\t\tcontrol,\n\t\t\tscope,\n\t\t\tmeter,\n\t\t\tparents,\n\t\t\toutputs,\n\t\t)\n\t\treturn Object.freeze({\n\t\t\tgoal: goal.id,\n\t\t\tproduct,\n\t\t\tfailure: control.failure,\n\t\t\tusage: meter.usage,\n\t\t\tduration: Math.ceil(performance.now() - started),\n\t\t\texecuted: true,\n\t\t})\n\t}\n\n\t// Runs one goal and closes its meter and scope; a late check failure leaves the retained product in place.\n\tasync #produce(\n\t\tgoal: StudyGoal,\n\t\tsession: StudySessionInterface,\n\t\tevidence: StudySinkInterface,\n\t\tcontrol: StudyControl,\n\t\tscope: StudyScope,\n\t\tmeter: StudyMeter,\n\t\tparents: readonly StudyScope[],\n\t\toutputs: ReadonlyArray<Budget<number>>,\n\t): Promise<StudyProduct | undefined> {\n\t\tconst bounds = this.#options.manifest.bounds\n\t\ttry {\n\t\t\tconst value: unknown = await control.wait(\n\t\t\t\tsession.execute(goal, { signal: control.signal, meter, evidence }),\n\t\t\t)\n\t\t\tif (!isStudyProduct(value))\n\t\t\t\tthrow new StudyError('FAULT', 'Driver returned no valid study product')\n\t\t\tconst candidate = Object.freeze({\n\t\t\t\tvalue: cloneJSONValue(value.value),\n\t\t\t\tpartial: value.partial,\n\t\t\t})\n\t\t\tconst bytes = new TextEncoder().encode(JSON.stringify(candidate.value)).byteLength\n\t\t\tconst stop = computeStudyOutputStop(bytes, bounds.goal.bytes, outputs)\n\t\t\tconst product = stop === undefined ? candidate : undefined\n\t\t\ttry {\n\t\t\t\tfor (const parent of parents) parent.check()\n\t\t\t\tscope.check()\n\t\t\t\tif (stop !== undefined) {\n\t\t\t\t\tcontrol.fail({\n\t\t\t\t\t\tcause: 'capacity',\n\t\t\t\t\t\tmessage: 'Study product exceeded its output allowance',\n\t\t\t\t\t\trole: undefined,\n\t\t\t\t\t\tstop,\n\t\t\t\t\t})\n\t\t\t\t} else for (const budget of outputs) budget.consume(bytes)\n\t\t\t} catch (error) {\n\t\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t\t}\n\t\t\treturn product\n\t\t} catch (error) {\n\t\t\tcontrol.fail(readStudyFailure(error))\n\t\t\treturn undefined\n\t\t} finally {\n\t\t\tmeter.close()\n\t\t\tscope.close()\n\t\t}\n\t}\n}\n","/** Bounds admitted files before another capture is allocated. */\nexport const ARTIFACT_FILES = 8192\n\n/** Bounds all captured input bytes to 128 MiB. */\nexport const ARTIFACT_BYTES = 128 * 1024 * 1024\n\n/** Bounds one captured input file to 16 MiB. */\nexport const ARTIFACT_FILE_BYTES = 16 * 1024 * 1024\n\n/** Bounds all visited directory entries, including ignored assets. */\nexport const ARTIFACT_VISITS = 32768\n\n/** Bounds directory nesting below each selected root. */\nexport const ARTIFACT_DEPTH = 64\n\n/** Bounds selected package roots before traversal begins. */\nexport const ARTIFACT_ROOTS = 128\n","import { canonicalStringify, parseJSON } from '@orkestrel/contract'\nimport { createHash } from 'node:crypto'\nimport { isAbsolute, relative, sep } from 'node:path'\nimport { StudyError } from '../core/errors.js'\n\n/** Checks strict lexical containment under a selected directory.\n * @param root - The canonical directory.\n * @param path - The candidate absolute file.\n * @returns True if the file is below the directory; false otherwise.\n */\nexport function containsArtifact(root: string, path: string): boolean {\n\tconst location = relative(root, path)\n\treturn (\n\t\tlocation !== '' &&\n\t\tlocation !== '..' &&\n\t\t!location.startsWith(`..${sep}`) &&\n\t\t!isAbsolute(location)\n\t)\n}\n\n/**\n * Computes the lowercase SHA-256 identity of exact bytes or UTF-8 text.\n * @param input - The retained bytes, or text identified by its UTF-8 bytes\n * @returns The lowercase hexadecimal digest\n * @example Identify captured bytes\n * ```ts\n * import { hashStudyBytes } from '@orkestrel/study/server'\n *\n * hashStudyBytes('retained evidence')\n * ```\n */\nexport function hashStudyBytes(input: string | Uint8Array): string {\n\treturn createHash('sha256').update(input).digest('hex')\n}\n\n/**\n * Encodes deterministic JSON bytes without synthesizing execution metadata.\n * @param value - The validated record\n * @returns The exact canonical UTF-8 bytes\n * @throws StudyError - Thrown when the record cannot be serialized\n * @example Encode custody bytes\n * ```ts\n * import { encodeStudyJSON } from '@orkestrel/study/server'\n *\n * encodeStudyJSON({ id: 1 })\n * ```\n */\nexport function encodeStudyJSON(value: unknown): Uint8Array {\n\tconst wire = JSON.stringify(value)\n\tconst text = wire === undefined ? undefined : canonicalStringify(parseJSON(wire))\n\tif (text === undefined) throw new StudyError('EVIDENCE', 'Record cannot be encoded')\n\treturn Buffer.from(`${text}\\n`, 'utf8')\n}\n\n/**\n * Decodes strict UTF-8 custody bytes and parses their JSON text.\n * @param bytes - The exact retained bytes\n * @returns The parsed value, or undefined when the text is not JSON\n * @throws TypeError - Thrown when the bytes are not valid UTF-8\n * @example\n * ```ts\n * decodeStudyJSON(new TextEncoder().encode('{\"id\":1}')) // { id: 1 }\n * ```\n */\nexport function decodeStudyJSON(bytes: Uint8Array): unknown {\n\treturn parseJSON(new TextDecoder('utf-8', { fatal: true }).decode(bytes))\n}\n","import { isInstance } from '@orkestrel/contract'\n\n/** Reports an invalid or drifted artifact inventory. */\nexport class ArtifactError extends Error {\n\treadonly code = 'ARTIFACT' as const\n\n\t/** Records the refused artifact boundary.\n\t * @param message - The specific refusal.\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'ArtifactError'\n\t}\n}\n\n/** Narrows a caught value to an artifact refusal.\n * @param value - The caught value.\n * @returns True if the value is an artifact error; false otherwise.\n */\nexport function isArtifactError(value: unknown): value is ArtifactError {\n\treturn isInstance(value, ArtifactError)\n}\n","import type { Dir, Dirent } from 'node:fs'\nimport type { ArtifactSource } from './types.js'\nimport { closeSync, fstatSync, lstatSync, openSync, readSync, realpathSync } from 'node:fs'\nimport { isAbsolute, resolve } from 'node:path'\nimport { hashStudyBytes } from '../helpers.js'\nimport { ARTIFACT_FILE_BYTES } from './constants.js'\nimport { ArtifactError } from './errors.js'\n\n/** Fills a buffer from an open descriptor, one positioned read at a time.\n * @param descriptor - The open file descriptor to read.\n * @param target - The buffer to fill.\n * @param offset - The position in the file and the buffer to continue from; Default: 0.\n * @returns The bytes read, as the whole buffer when the file filled it or as its leading part when the file ended first.\n */\nexport function readArtifactBytes(descriptor: number, target: Buffer, offset = 0): Buffer {\n\tif (offset >= target.length) return target\n\tconst count = readSync(descriptor, target, offset, target.length - offset, offset)\n\treturn count === 0\n\t\t? target.subarray(0, offset)\n\t\t: readArtifactBytes(descriptor, target, offset + count)\n}\n\n/** Iterates the remaining entries of an open directory handle lazily, in read order.\n * @param handle - The open synchronous directory handle; the caller owns it and closes it.\n * @returns Each remaining entry until the handle reports the end. An entry is read only when the consumer asks for it, so a consumer that stops early leaves the rest unread.\n */\nexport function* iterateArtifactEntries(handle: Dir): Generator<Dirent, void> {\n\tfor (;;) {\n\t\tconst entry = handle.readSync()\n\t\tif (entry === null) return\n\t\tyield entry\n\t}\n}\n\n/** Reads a bounded regular file only through its canonical absolute path.\n * @param path - The absolute path to inspect.\n * @param maximum - The remaining capture budget; Default: 16 MiB.\n * @returns Captured bytes with their identity.\n * @throws Thrown when the path is linked, noncanonical, oversized, or changes while read.\n */\nexport function readArtifact(path: string, maximum = ARTIFACT_FILE_BYTES): ArtifactSource {\n\tif (\n\t\t!Number.isSafeInteger(maximum) ||\n\t\tmaximum < 0 ||\n\t\t!isAbsolute(path) ||\n\t\tresolve(path) !== path ||\n\t\trealpathSync(path) !== path ||\n\t\t!lstatSync(path).isFile()\n\t) {\n\t\tthrow new ArtifactError(`Artifact requires a canonical regular file and byte budget: ${path}`)\n\t}\n\tconst descriptor = openSync(path, 'r')\n\ttry {\n\t\tconst before = fstatSync(descriptor)\n\t\tif (!before.isFile() || before.size > Math.min(maximum, ARTIFACT_FILE_BYTES))\n\t\t\tthrow new ArtifactError(`Artifact byte limit exceeded: ${path}`)\n\t\tconst source = readArtifactBytes(descriptor, Buffer.alloc(before.size))\n\t\tif (source.length !== before.size)\n\t\t\tthrow new ArtifactError(`Artifact file drifted while reading: ${path}`)\n\t\tconst after = fstatSync(descriptor)\n\t\tif (\n\t\t\tbefore.size !== after.size ||\n\t\t\tbefore.mtimeMs !== after.mtimeMs ||\n\t\t\tbefore.ctimeMs !== after.ctimeMs ||\n\t\t\trealpathSync(path) !== path ||\n\t\t\t!lstatSync(path).isFile()\n\t\t)\n\t\t\tthrow new ArtifactError(`Artifact file drifted while reading: ${path}`)\n\t\treturn { path, digest: hashStudyBytes(source), size: source.byteLength, source }\n\t} finally {\n\t\tcloseSync(descriptor)\n\t}\n}\n","import type {\n\tLoadHookContext,\n\tLoadFnOutput,\n\tResolveHookContext,\n\tResolveFnOutput,\n} from 'node:module'\nimport type {\n\tArtifactHookInput,\n\tArtifactLoadHandler,\n\tArtifactResolveHandler,\n\tArtifactSource,\n} from './types.js'\nimport { isBuiltin, stripTypeScriptTypes } from 'node:module'\nimport { basename, extname, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { containsArtifact } from '../helpers.js'\nimport { ArtifactError } from './errors.js'\nimport { readArtifact } from './helpers.js'\n\n/** Enforces captured inventory membership at every synchronous native import edge. */\nexport class Resolution {\n\t#input: ArtifactHookInput\n\t#files: ReadonlyMap<string, ArtifactSource>\n\n\t/** Retains the trusted captured inventory and its private namespace.\n\t * @param input - Captured built bytes and separate source selection.\n\t */\n\tconstructor(input: ArtifactHookInput) {\n\t\tthis.#input = input\n\t\tthis.#files = new Map(input.files.map((file) => [file.path, file]))\n\t}\n\n\t/** Resolves native edges with source-local JavaScript-to-TypeScript substitution.\n\t * @param specifier - The requested native specifier.\n\t * @param context - Node's resolution context.\n\t * @param next - The remaining native resolution chain.\n\t * @returns An admitted URL in the captured namespace.\n\t */\n\tresolve(\n\t\tspecifier: string,\n\t\tcontext: ResolveHookContext,\n\t\tnext: ArtifactResolveHandler,\n\t): ResolveFnOutput {\n\t\tconst parent = context.parentURL === undefined ? undefined : new URL(context.parentURL)\n\t\tconst initial = specifier.startsWith('file:') ? new URL(specifier) : undefined\n\t\tif (\n\t\t\tparent?.searchParams.get('artifact') !== this.#input.token &&\n\t\t\tinitial?.searchParams.get('artifact') !== this.#input.token\n\t\t)\n\t\t\treturn next(specifier, context)\n\t\tif (isBuiltin(specifier)) {\n\t\t\tconst instrument = this.#input.instrument\n\t\t\tconst trusted =\n\t\t\t\tinstrument !== undefined &&\n\t\t\t\tparent?.protocol === 'file:' &&\n\t\t\t\tcontainsArtifact(join(instrument, 'dist'), fileURLToPath(parent)) &&\n\t\t\t\tthis.#files.has(fileURLToPath(parent))\n\t\t\tif (\n\t\t\t\t!trusted &&\n\t\t\t\t['module', 'vm', 'worker_threads', 'child_process', 'cluster'].includes(\n\t\t\t\t\tspecifier.replace(/^node:/, ''),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new ArtifactError(`Artifact alternate loader is unsupported: ${specifier}`)\n\t\t\treturn next(specifier, context)\n\t\t}\n\t\tfor (const file of this.#input.files) {\n\t\t\tif (basename(file.path) === 'package.json' && readArtifact(file.path).digest !== file.digest)\n\t\t\t\tthrow new ArtifactError(`Artifact manifest drifted: ${file.path}`)\n\t\t}\n\t\tconst source = this.#input.source\n\t\tconst target = this.#locate(specifier, parent, initial)\n\t\tif (\n\t\t\tsource !== undefined &&\n\t\t\ttarget?.protocol === 'file:' &&\n\t\t\tcontainsArtifact(source.root, fileURLToPath(target))\n\t\t) {\n\t\t\tif (\n\t\t\t\tparent !== undefined &&\n\t\t\t\t(parent.protocol !== 'file:' || !containsArtifact(source.root, fileURLToPath(parent))) &&\n\t\t\t\tinitial?.searchParams.get('artifact') !== this.#input.token\n\t\t\t)\n\t\t\t\tthrow new ArtifactError('Artifact built modules cannot import consumer sources')\n\t\t\tif (\n\t\t\t\ttarget.hash !== '' ||\n\t\t\t\t(target.search !== '' && target.search !== `?artifact=${this.#input.token}`)\n\t\t\t)\n\t\t\t\tthrow new ArtifactError(`Artifact source URL is unsupported: ${target.href}`)\n\t\t\tconst file = this.#files.get(fileURLToPath(target))\n\t\t\tif (file === undefined || !['.ts', '.mts', '.js', '.mjs'].includes(extname(file.path)))\n\t\t\t\tthrow new ArtifactError(`Artifact source dependency is not admitted: ${target.href}`)\n\t\t\tif (readArtifact(file.path).digest !== file.digest)\n\t\t\t\tthrow new ArtifactError(`Artifact dependency drifted: ${file.path}`)\n\t\t\ttarget.searchParams.set('artifact', this.#input.token)\n\t\t\treturn {\n\t\t\t\turl: target.href,\n\t\t\t\tformat: 'module',\n\t\t\t\tshortCircuit: true,\n\t\t\t}\n\t\t}\n\t\tconst result = next(specifier, context)\n\t\tconst url = new URL(result.url)\n\t\tif (\n\t\t\turl.protocol !== 'file:' ||\n\t\t\turl.hash !== '' ||\n\t\t\t(url.search !== '' && url.search !== `?artifact=${this.#input.token}`)\n\t\t)\n\t\t\tthrow new ArtifactError(`Artifact URL is unsupported: ${result.url}`)\n\t\turl.search = ''\n\t\tconst file = this.#files.get(fileURLToPath(url))\n\t\tif (\n\t\t\tfile === undefined ||\n\t\t\t(source !== undefined && containsArtifact(source.root, file.path)) ||\n\t\t\t!['.js', '.mjs', '.json'].includes(extname(file.path)) ||\n\t\t\t(result.format !== 'module' && result.format !== 'json')\n\t\t)\n\t\t\tthrow new ArtifactError(`Artifact dependency is not admitted ESM: ${result.url}`)\n\t\tif (this.#input.excluded?.includes(file.path) === true)\n\t\t\tthrow new ArtifactError(`Artifact module is excluded: ${file.path}`)\n\t\tif (readArtifact(file.path).digest !== file.digest)\n\t\t\tthrow new ArtifactError(`Artifact dependency drifted: ${file.path}`)\n\t\turl.searchParams.set('artifact', this.#input.token)\n\t\treturn { ...result, url: url.href }\n\t}\n\n\t/** Returns captured bytes after verifying their live disk identity.\n\t * @param href - Node's resolved URL.\n\t * @param context - Node's load context.\n\t * @param next - The remaining native load chain.\n\t * @returns Captured ESM, JSON, or native strip-only TypeScript output.\n\t */\n\tload(href: string, context: LoadHookContext, next: ArtifactLoadHandler): LoadFnOutput {\n\t\tconst url = new URL(href)\n\t\tif (url.searchParams.get('artifact') !== this.#input.token) return next(href, context)\n\t\turl.search = ''\n\t\tconst file = this.#files.get(fileURLToPath(url))\n\t\tif (file === undefined || (context.format !== 'module' && context.format !== 'json'))\n\t\t\tthrow new ArtifactError(`Artifact load is unsupported: ${href}`)\n\t\tif (readArtifact(file.path).digest !== file.digest)\n\t\t\tthrow new ArtifactError(`Artifact dependency drifted: ${file.path}`)\n\t\tconst extension = extname(file.path)\n\t\treturn {\n\t\t\tformat: context.format,\n\t\t\tsource:\n\t\t\t\textension === '.ts' || extension === '.mts'\n\t\t\t\t\t? stripTypeScriptTypes(Buffer.from(file.source).toString('utf8'), { mode: 'strip' })\n\t\t\t\t\t: new Uint8Array(file.source),\n\t\t\tshortCircuit: true,\n\t\t}\n\t}\n\n\t// Locates a source-local relative edge, substituting the captured TypeScript twin of a\n\t// JavaScript specifier; any other edge keeps its initial target.\n\t#locate(specifier: string, parent: URL | undefined, initial: URL | undefined): URL | undefined {\n\t\tconst source = this.#input.source\n\t\tif (\n\t\t\tsource === undefined ||\n\t\t\tparent?.protocol !== 'file:' ||\n\t\t\t!containsArtifact(source.root, fileURLToPath(parent)) ||\n\t\t\t!(specifier.startsWith('./') || specifier.startsWith('../'))\n\t\t)\n\t\t\treturn initial\n\t\tconst target = new URL(specifier, parent)\n\t\tif (target.search !== '' || target.hash !== '')\n\t\t\tthrow new ArtifactError(`Artifact source URL is unsupported: ${specifier}`)\n\t\tconst path = fileURLToPath(target)\n\t\tif (!containsArtifact(source.root, path))\n\t\t\tthrow new ArtifactError(`Artifact source dependency escapes its root: ${specifier}`)\n\t\tconst extension = extname(path)\n\t\tif (extension !== '.js' && extension !== '.mjs') return target\n\t\tconst substitute = `${path.slice(0, -extension.length)}${extension === '.js' ? '.ts' : '.mts'}`\n\t\tif (!this.#files.has(substitute)) return target\n\t\tif (this.#files.has(path))\n\t\t\tthrow new ArtifactError(`Artifact source target is ambiguous: ${path}`)\n\t\treturn pathToFileURL(substitute)\n\t}\n}\n","import type {\n\tArtifactInventory,\n\tArtifactLoaderOptions,\n\tArtifactPackage,\n\tArtifactSource,\n\tArtifactTally,\n} from './types.js'\nimport { isNonEmptyString, isRecord } from '@orkestrel/contract'\nimport { randomUUID } from 'node:crypto'\nimport { lstatSync, opendirSync, realpathSync } from 'node:fs'\nimport { registerHooks, stripTypeScriptTypes } from 'node:module'\nimport { extname, isAbsolute, join, resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport {\n\tARTIFACT_BYTES,\n\tARTIFACT_DEPTH,\n\tARTIFACT_FILES,\n\tARTIFACT_ROOTS,\n\tARTIFACT_VISITS,\n} from './constants.js'\nimport { containsArtifact, hashStudyBytes } from '../helpers.js'\nimport { ArtifactError } from './errors.js'\nimport { iterateArtifactEntries, readArtifact } from './helpers.js'\nimport { Resolution } from './Resolution.js'\n\n/** Captures built ESM and a separate strip-only consumer adapter in a fresh worker.\n * @remarks\n * Loads trusted code, not a hostile-code sandbox. Native process APIs, eval and external\n * services are not replayed. One inventory may load per process; terminate it afterwards.\n */\nexport class ArtifactLoader {\n\tstatic #active = false\n\t#options: ArtifactLoaderOptions\n\t#inventory: ArtifactInventory | undefined\n\t#sources: readonly ArtifactSource[] = []\n\t#token: string | undefined\n\n\t/** Captures selections without reading or executing selected modules.\n\t * @param options - Canonical built selections and optional consumer source selection.\n\t */\n\tconstructor(options: ArtifactLoaderOptions) {\n\t\tif (options.roots.length > ARTIFACT_ROOTS || options.entries.length > ARTIFACT_FILES)\n\t\t\tthrow new ArtifactError('Artifact selection exceeds its limit')\n\t\tthis.#options = {\n\t\t\t...options,\n\t\t\tentries: [...options.entries],\n\t\t\troots: [...options.roots],\n\t\t\t...(options.source === undefined ? {} : { source: { ...options.source } }),\n\t\t\t...(options.excluded === undefined ? {} : { excluded: [...options.excluded] }),\n\t\t}\n\t}\n\n\t/** Reads and identifies admitted files without evaluating selected modules.\n\t * @returns Frozen evidence identifying all captured bytes and the native runtime.\n\t * @throws Thrown for invalid selections, unsupported TypeScript, limits, or drift.\n\t */\n\tinspect(): ArtifactInventory {\n\t\tif (this.#inventory !== undefined) {\n\t\t\tthis.verify()\n\t\t\treturn this.#inventory\n\t\t}\n\t\tif (\n\t\t\t(this.#options.entries.length === 0 && this.#options.source === undefined) ||\n\t\t\tthis.#options.roots.length > ARTIFACT_ROOTS ||\n\t\t\tthis.#options.entries.length > ARTIFACT_FILES\n\t\t)\n\t\t\tthrow new ArtifactError('Artifact selection is empty or exceeds its limit')\n\t\tif (\n\t\t\tthis.#options.instrument !== undefined &&\n\t\t\t!this.#options.roots.includes(this.#options.instrument)\n\t\t)\n\t\t\tthrow new ArtifactError('Artifact instrument must be an admitted package root')\n\t\tconst sources = this.#capture()\n\t\tconst packages = [...this.#options.roots].sort().map((root, index, sorted): ArtifactPackage => {\n\t\t\tconst manifest = sources.find((file) => file.path === join(root, 'package.json'))\n\t\t\tif (manifest === undefined) throw new ArtifactError(`Artifact manifest is missing: ${root}`)\n\t\t\tconst value: unknown = JSON.parse(Buffer.from(manifest.source).toString('utf8'))\n\t\t\tif (\n\t\t\t\t!isRecord(value) ||\n\t\t\t\tvalue.type !== 'module' ||\n\t\t\t\t!isNonEmptyString(value.name) ||\n\t\t\t\t!isNonEmptyString(value.version)\n\t\t\t)\n\t\t\t\tthrow new ArtifactError(`Artifact requires a named, versioned ESM package: ${root}`)\n\t\t\tif (sorted.indexOf(root) !== index)\n\t\t\t\tthrow new ArtifactError(`Artifact package identity is duplicated: ${value.name}`)\n\t\t\treturn Object.freeze({ root, name: value.name, version: value.version })\n\t\t})\n\t\tfor (const entry of this.#options.entries) {\n\t\t\tif (\n\t\t\t\t!['.js', '.mjs'].includes(extname(entry)) ||\n\t\t\t\t!sources.some((file) => file.path === entry) ||\n\t\t\t\t!packages.some((item) => containsArtifact(join(item.root, 'dist'), entry))\n\t\t\t)\n\t\t\t\tthrow new ArtifactError(`Artifact entry must be admitted built ESM: ${entry}`)\n\t\t}\n\t\tconst source = this.#options.source\n\t\tif (source !== undefined) {\n\t\t\tif (\n\t\t\t\t!['.ts', '.mts', '.js', '.mjs'].includes(extname(source.entry)) ||\n\t\t\t\t!containsArtifact(source.root, source.entry) ||\n\t\t\t\t!sources.some((file) => file.path === source.entry)\n\t\t\t)\n\t\t\t\tthrow new ArtifactError('Artifact source entry must be an admitted module')\n\t\t\tfor (const file of sources.filter((candidate) =>\n\t\t\t\tcontainsArtifact(source.root, candidate.path),\n\t\t\t)) {\n\t\t\t\tif (file.path.endsWith('.ts') || file.path.endsWith('.mts')) {\n\t\t\t\t\tconst counterpart = file.path.endsWith('.mts')\n\t\t\t\t\t\t? `${file.path.slice(0, -4)}.mjs`\n\t\t\t\t\t\t: `${file.path.slice(0, -3)}.js`\n\t\t\t\t\tif (sources.some((candidate) => candidate.path === counterpart))\n\t\t\t\t\t\tthrow new ArtifactError(`Artifact source target is ambiguous: ${file.path}`)\n\t\t\t\t\tstripTypeScriptTypes(Buffer.from(file.source).toString('utf8'), { mode: 'strip' })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tsources.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0))\n\t\tconst settings = process.env.NODE_OPTIONS\n\t\tconst evidence = {\n\t\t\tnode: process.version,\n\t\t\truntime: Object.freeze({\n\t\t\t\targuments: Object.freeze([...process.execArgv]),\n\t\t\t\tplatform: process.platform,\n\t\t\t\tarchitecture: process.arch,\n\t\t\t\t...(settings === undefined ? {} : { options: settings }),\n\t\t\t}),\n\t\t\tentries: Object.freeze(\n\t\t\t\t[\n\t\t\t\t\t...new Set([...this.#options.entries, ...(source === undefined ? [] : [source.entry])]),\n\t\t\t\t].sort(),\n\t\t\t),\n\t\t\tpackages: Object.freeze(packages),\n\t\t\t...(source === undefined ? {} : { source: Object.freeze({ ...source }) }),\n\t\t\t...(this.#options.instrument === undefined ? {} : { instrument: this.#options.instrument }),\n\t\t\tfiles: Object.freeze(\n\t\t\t\tsources.map(({ path, digest, size }) => Object.freeze({ path, digest, size })),\n\t\t\t),\n\t\t}\n\t\tthis.#sources = sources\n\t\tthis.#inventory = Object.freeze({\n\t\t\tdigest: hashStudyBytes(JSON.stringify(evidence)),\n\t\t\t...evidence,\n\t\t})\n\t\tthis.verify()\n\t\treturn this.#inventory\n\t}\n\n\t/** Refuses byte and population drift since inspection.\n\t * @throws Thrown when any admitted file or the admitted population changes.\n\t */\n\tverify(): void {\n\t\tif (this.#inventory === undefined) throw new ArtifactError('Artifact inspection is required')\n\t\tconst current = this.#capture()\n\t\tconst captured = new Map(this.#sources.map((file) => [file.path, file.digest]))\n\t\tif (\n\t\t\tcurrent.length !== this.#sources.length ||\n\t\t\tcurrent.some((file) => captured.get(file.path) !== file.digest)\n\t\t)\n\t\t\tthrow new ArtifactError('Artifact inventory drifted')\n\t}\n\n\t/** Imports one selected entry through synchronous captured-byte hooks.\n\t * @param entry - The exact canonical built entry or selected source adapter entry.\n\t * @returns The actual module namespace for the caller to narrow.\n\t * @throws Thrown for drift, unsupported edges, evaluation failures, or a reused worker.\n\t */\n\tasync load(entry: string): Promise<unknown> {\n\t\tconst inventory = this.inspect()\n\t\tif (!inventory.entries.includes(entry))\n\t\t\tthrow new ArtifactError('Artifact entry was not selected')\n\t\tif (this.#token === undefined) {\n\t\t\tif (ArtifactLoader.#active)\n\t\t\t\tthrow new ArtifactError('Artifact loading requires a fresh process')\n\t\t\tconst token = randomUUID()\n\t\t\tconst resolution = new Resolution({\n\t\t\t\ttoken,\n\t\t\t\tfiles: this.#sources,\n\t\t\t\t...(inventory.source === undefined ? {} : { source: inventory.source }),\n\t\t\t\t...(inventory.instrument === undefined ? {} : { instrument: inventory.instrument }),\n\t\t\t\t...(this.#options.excluded === undefined ? {} : { excluded: this.#options.excluded }),\n\t\t\t})\n\t\t\tregisterHooks({\n\t\t\t\tresolve: (specifier, context, next) => resolution.resolve(specifier, context, next),\n\t\t\t\tload: (href, context, next) => resolution.load(href, context, next),\n\t\t\t})\n\t\t\tthis.#token = token\n\t\t\tArtifactLoader.#active = true\n\t\t}\n\t\tconst url = pathToFileURL(entry)\n\t\turl.searchParams.set('artifact', this.#token)\n\t\tconst namespace: unknown = await import(url.href)\n\t\tthis.verify()\n\t\treturn namespace\n\t}\n\n\t// Captures every root's manifest and built files, then the optional source graph, threading the visit and byte tally through each step.\n\t#capture(): ArtifactSource[] {\n\t\tconst sources: ArtifactSource[] = []\n\t\tconst tally = this.#options.roots.reduce<ArtifactTally>(\n\t\t\t(counted, root) => {\n\t\t\t\tif (\n\t\t\t\t\t!isAbsolute(root) ||\n\t\t\t\t\tresolve(root) !== root ||\n\t\t\t\t\trealpathSync(root) !== root ||\n\t\t\t\t\t!lstatSync(root).isDirectory()\n\t\t\t\t)\n\t\t\t\t\tthrow new ArtifactError(`Artifact requires a canonical package root: ${root}`)\n\t\t\t\treturn this.#walk(\n\t\t\t\t\tjoin(root, 'dist'),\n\t\t\t\t\tsources,\n\t\t\t\t\tfalse,\n\t\t\t\t\t0,\n\t\t\t\t\tthis.#append(join(root, 'package.json'), sources, counted),\n\t\t\t\t)\n\t\t\t},\n\t\t\tObject.freeze({ visits: 0, bytes: 0 }),\n\t\t)\n\t\tconst source = this.#options.source\n\t\tif (source !== undefined) {\n\t\t\tif (\n\t\t\t\tthis.#options.roots.some(\n\t\t\t\t\t(root) =>\n\t\t\t\t\t\tjoin(root, 'dist') === source.root ||\n\t\t\t\t\t\tcontainsArtifact(join(root, 'dist'), source.root) ||\n\t\t\t\t\t\tcontainsArtifact(source.root, join(root, 'dist')),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new ArtifactError('Artifact source and built inventories must not overlap')\n\t\t\tthis.#walk(source.root, sources, true, 0, tally)\n\t\t}\n\t\treturn sources\n\t}\n\n\t// Reads one admitted file under the bytes that remain and returns the tally including it.\n\t#append(path: string, sources: ArtifactSource[], tally: ArtifactTally): ArtifactTally {\n\t\tif (sources.length >= ARTIFACT_FILES)\n\t\t\tthrow new ArtifactError('Artifact file count limit exceeded')\n\t\tconst file = readArtifact(path, ARTIFACT_BYTES - tally.bytes)\n\t\tsources.push(file)\n\t\treturn Object.freeze({ visits: tally.visits, bytes: tally.bytes + file.size })\n\t}\n\n\t// Visits a directory's entries lazily, so a limit refusal stops reading it, and returns the tally including its subtree.\n\t#walk(\n\t\tdirectory: string,\n\t\tsources: ArtifactSource[],\n\t\tsource: boolean,\n\t\tdepth: number,\n\t\ttally: ArtifactTally,\n\t): ArtifactTally {\n\t\tif (depth > ARTIFACT_DEPTH) throw new ArtifactError('Artifact directory depth limit exceeded')\n\t\tif (\n\t\t\t!isAbsolute(directory) ||\n\t\t\tresolve(directory) !== directory ||\n\t\t\trealpathSync(directory) !== directory ||\n\t\t\t!lstatSync(directory).isDirectory()\n\t\t)\n\t\t\tthrow new ArtifactError(`Artifact directory must be canonical and not linked: ${directory}`)\n\t\tconst handle = opendirSync(directory)\n\t\ttry {\n\t\t\treturn iterateArtifactEntries(handle).reduce<ArtifactTally>((counted, entry) => {\n\t\t\t\tconst visited = Object.freeze({ visits: counted.visits + 1, bytes: counted.bytes })\n\t\t\t\tif (visited.visits > ARTIFACT_VISITS)\n\t\t\t\t\tthrow new ArtifactError('Artifact traversal limit exceeded')\n\t\t\t\tconst path = join(directory, entry.name)\n\t\t\t\tif (entry.isSymbolicLink())\n\t\t\t\t\tthrow new ArtifactError(`Artifact links are unsupported: ${path}`)\n\t\t\t\tif (entry.isDirectory()) return this.#walk(path, sources, source, depth + 1, visited)\n\t\t\t\treturn (source\n\t\t\t\t\t? ['.ts', '.mts', '.js', '.mjs']\n\t\t\t\t\t: ['.js', '.mjs', '.cjs', '.json']\n\t\t\t\t).includes(extname(path)) &&\n\t\t\t\t\t!path.endsWith('.d.ts') &&\n\t\t\t\t\t!path.endsWith('.d.mts')\n\t\t\t\t\t? this.#append(path, sources, visited)\n\t\t\t\t\t: visited\n\t\t\t}, tally)\n\t\t} finally {\n\t\t\thandle.closeSync()\n\t\t}\n\t}\n}\n","/** Limits untrusted metadata before JSON parsing or file allocation. */\nexport const STUDY_CUSTODY_BYTES = 16 * 1024 * 1024\n\n/** Rejects names that Windows reserves even on other hosts. */\nexport const STUDY_RESERVED_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/i\n\n/** Discloses the limits of neutral identifiers when public text remains visible. */\nexport const STUDY_PACKET_DISCLOSURE =\n\t'Identifiers omit treatment and model names. Input and product text may still reveal design details.'\n","import type {\n\tStudyAttempt,\n\tStudyEvidence,\n\tStudyFailure,\n\tStudyManifest,\n\tStudyObservation,\n\tStudyTrial,\n} from '../../core/types.js'\nimport type { StudyFile, StudySeal } from './types.js'\nimport {\n\tholds,\n\tcanonicalStringify,\n\tisArray,\n\tisJSONValue,\n\tisNonEmptyString,\n\tisRecord,\n} from '@orkestrel/contract'\nimport { buildStudySchedule, matchesStudyKeys } from '../../core/helpers.js'\nimport {\n\tisStudyBounds,\n\tisStudyCause,\n\tisStudyDefinition,\n\tisStudyDigest,\n\tisStudyName,\n\tisStudyRole,\n\tisStudyScenario,\n\tisStudyStop,\n\tisStudyTimestamp,\n\tisStudyUsage,\n} from '../../core/validators.js'\nimport { STUDY_RESERVED_NAME } from './constants.js'\n\n/**\n * Checks whether a trial name is portable on all supported hosts.\n * @param value - The candidate name\n * @returns True if the name is portable; false otherwise\n * @example\n * ```ts\n * isStudyCustodyName('r1-s1-a1') // true\n * ```\n */\nexport function isStudyCustodyName(value: unknown): value is string {\n\treturn isStudyName(value) && !STUDY_RESERVED_NAME.test(value)\n}\n\n/**\n * Checks whether a manifest exactly binds its declared population and identities.\n * @param value - The candidate manifest\n * @returns True if the manifest is valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodyManifest({}) // false\n * ```\n */\nexport function isStudyCustodyManifest(value: unknown): value is StudyManifest {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(\n\t\t\t\tvalue,\n\t\t\t\t['id', 'created', 'definition', 'scenarios', 'identity', 'schedule', 'bounds', 'host'],\n\t\t\t\t['qualification'],\n\t\t\t) ||\n\t\t\t!isStudyCustodyName(value.id) ||\n\t\t\t!isStudyTimestamp(value.created) ||\n\t\t\t!isStudyDefinition(value.definition) ||\n\t\t\t!isArray(value.scenarios) ||\n\t\t\t!value.scenarios.every(isStudyScenario) ||\n\t\t\t!isStudyBounds(value.bounds) ||\n\t\t\t!isRecord(value.identity) ||\n\t\t\t!matchesStudyKeys(\n\t\t\t\tvalue.identity,\n\t\t\t\t['agent', 'subject', 'instrument', 'fixtures', 'profile'],\n\t\t\t\t['provider'],\n\t\t\t) ||\n\t\t\t(value.identity.provider !== undefined && !isStudyDigest(value.identity.provider)) ||\n\t\t\t(value.qualification !== undefined && !isStudyDigest(value.qualification)) ||\n\t\t\t!isRecord(value.host) ||\n\t\t\t!Object.values(value.host).every((entry) => typeof entry === 'string') ||\n\t\t\t!isArray(value.schedule)\n\t\t)\n\t\t\treturn false\n\t\tconst identity = value.identity\n\t\tif (\n\t\t\t!['agent', 'subject', 'instrument', 'fixtures', 'profile'].every((key) =>\n\t\t\t\tisStudyDigest(identity[key]),\n\t\t\t)\n\t\t)\n\t\t\treturn false\n\t\tconst schedule = buildStudySchedule(value.definition, value.scenarios)\n\t\treturn (\n\t\t\tvalue.schedule.every(isStudyCustodyTrial) &&\n\t\t\tcanonicalStringify(schedule) === canonicalStringify(value.schedule)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a scheduled trial has exact valid identity fields.\n * @param value - The candidate trial\n * @returns True if its identity is valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodyTrial({}) // false\n * ```\n */\nexport function isStudyCustodyTrial(value: unknown): value is StudyTrial {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['id', 'scenario', 'arm', 'repetition']) &&\n\t\t\tisStudyCustodyName(value.id) &&\n\t\t\tisStudyName(value.scenario) &&\n\t\t\tisStudyName(value.arm) &&\n\t\t\ttypeof value.repetition === 'number' &&\n\t\t\tNumber.isSafeInteger(value.repetition) &&\n\t\t\tvalue.repetition >= 0\n\t\t)\n\t})\n}\n\n/**\n * Checks whether evidence is exact JSON with a declared event and goal name.\n * @param value - The candidate evidence\n * @returns True if evidence is valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodyEvidence({ event: 'saved', goal: 'write', value: true }) // true\n * ```\n */\nexport function isStudyCustodyEvidence(value: unknown): value is StudyEvidence {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['event', 'goal', 'value']) &&\n\t\t\tisStudyName(value.event) &&\n\t\t\tisStudyName(value.goal) &&\n\t\t\tisJSONValue(value.value)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a failure carries exact attributable operational fields.\n * @remarks\n * `role` and `stop` are optional keys. A `stop` is valid only on a `capacity` or `deadline` failure,\n * and it must satisfy `isStudyStop`; a failure sealed before the `stop` member existed has no key.\n * @param value - The candidate failure\n * @returns True if the failure is valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodyFailure({}) // false\n * ```\n */\nexport function isStudyCustodyFailure(value: unknown): value is StudyFailure {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['cause', 'message'], ['role', 'stop']) &&\n\t\t\tisStudyCause(value.cause) &&\n\t\t\tisNonEmptyString(value.message) &&\n\t\t\t(value.role === undefined || isStudyRole(value.role)) &&\n\t\t\t(value.stop === undefined ||\n\t\t\t\t((value.cause === 'capacity' || value.cause === 'deadline') && isStudyStop(value.stop)))\n\t\t)\n\t})\n}\n\n/**\n * Checks whether an observation preserves output or an explicit unexecuted failure.\n * @param value - The candidate observation\n * @returns True if the observation is valid, with an executed fact or an unexecuted fact that holds a failure and no product, usage or duration; false otherwise\n * @example\n * ```ts\n * isStudyCustodyObservation({}) // false\n * ```\n */\nexport function isStudyCustodyObservation(value: unknown): value is StudyObservation {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['goal', 'usage', 'duration', 'executed'], ['product', 'failure']) ||\n\t\t\t!isStudyName(value.goal) ||\n\t\t\t!isArray(value.usage) ||\n\t\t\t!value.usage.every(isStudyUsage) ||\n\t\t\ttypeof value.duration !== 'number' ||\n\t\t\t!Number.isSafeInteger(value.duration) ||\n\t\t\tvalue.duration < 0 ||\n\t\t\t(value.failure !== undefined && !isStudyCustodyFailure(value.failure)) ||\n\t\t\ttypeof value.executed !== 'boolean' ||\n\t\t\t(value.executed === false &&\n\t\t\t\t(value.product !== undefined ||\n\t\t\t\t\tvalue.failure === undefined ||\n\t\t\t\t\tvalue.usage.length !== 0 ||\n\t\t\t\t\tvalue.duration !== 0))\n\t\t)\n\t\t\treturn false\n\t\tif (value.product === undefined) return value.failure !== undefined\n\t\treturn (\n\t\t\tisRecord(value.product) &&\n\t\t\tmatchesStudyKeys(value.product, ['value', 'partial']) &&\n\t\t\tisJSONValue(value.product.value) &&\n\t\t\ttypeof value.product.partial === 'boolean'\n\t\t)\n\t})\n}\n\n/**\n * Checks whether an attempt terminally accounts for the exact scheduled goal horizon.\n * @param value - The candidate attempt\n * @param manifest - The authoritative declaration\n * @returns True if the terminal record is compatible and its execution facts are consistent; false otherwise\n * @remarks\n * Executed goals form a prefix of the horizon and an executed goal with a failure ends it.\n * An unexecuted attempt holds only unexecuted goals, and an attempt without a failure holds only\n * executed goals that did not fail.\n * @example\n * ```ts\n * isStudyCustodyAttempt({}, manifest) // false\n * ```\n */\nexport function isStudyCustodyAttempt(\n\tvalue: unknown,\n\tmanifest: StudyManifest,\n): value is StudyAttempt {\n\treturn holds(() => {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\t!matchesStudyKeys(value, ['trial', 'observations', 'duration', 'executed'], ['failure']) ||\n\t\t\t!isStudyCustodyTrial(value.trial) ||\n\t\t\t!isArray(value.observations) ||\n\t\t\t!value.observations.every(isStudyCustodyObservation) ||\n\t\t\ttypeof value.duration !== 'number' ||\n\t\t\t!Number.isSafeInteger(value.duration) ||\n\t\t\tvalue.duration < 0 ||\n\t\t\t(value.failure !== undefined && !isStudyCustodyFailure(value.failure))\n\t\t)\n\t\t\treturn false\n\t\tconst identity = value.trial\n\t\tconst trial = manifest.schedule.find((entry) => entry.id === identity.id)\n\t\tconst scenario = manifest.scenarios.find((entry) => entry.id === identity.scenario)\n\t\tif (\n\t\t\ttrial === undefined ||\n\t\t\tscenario === undefined ||\n\t\t\tcanonicalStringify(trial) !== canonicalStringify(value.trial) ||\n\t\t\tvalue.observations.length !== scenario.goals.length ||\n\t\t\t!value.observations.every(\n\t\t\t\t(observation, index) => observation.goal === scenario.goals[index]?.id,\n\t\t\t)\n\t\t)\n\t\t\treturn false\n\t\tconst executed = value.executed\n\t\tif (typeof executed !== 'boolean') return false\n\t\t// A terminal record without a failure holds only executed goals that did not fail.\n\t\tif (\n\t\t\tvalue.failure === undefined &&\n\t\t\t!value.observations.every((entry) => entry.executed && entry.failure === undefined)\n\t\t)\n\t\t\treturn false\n\t\t// An executed goal needs an executed attempt and no earlier goal that was unexecuted or failed,\n\t\t// so it lies at or before the first goal that was unexecuted or failed. A hole reads as an\n\t\t// absent observation, which refuses the record, as visiting every position does.\n\t\tconst observations = Array.from(value.observations)\n\t\tconst stop = observations.findIndex(\n\t\t\t(observation) => !observation.executed || observation.failure !== undefined,\n\t\t)\n\t\treturn observations.every(\n\t\t\t(observation, index) => !observation.executed || (executed && (stop === -1 || index <= stop)),\n\t\t)\n\t})\n}\n\n/**\n * Checks whether an execution file inventory entry is path-safe and bounded.\n * @param value - The candidate entry\n * @returns True if the entry is valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodyFile({}) // false\n * ```\n */\nexport function isStudyCustodyFile(value: unknown): value is StudyFile {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['path', 'bytes', 'digest']) &&\n\t\t\ttypeof value.path === 'string' &&\n\t\t\t(value.path === 'manifest.json' ||\n\t\t\t\t/^trials\\/[a-z0-9]+(?:-[a-z0-9]+)*\\/(?:evidence.jsonl|attempt.json)$/.test(value.path)) &&\n\t\t\tvalue.path.split('/').every((name) => !STUDY_RESERVED_NAME.test(name)) &&\n\t\t\ttypeof value.bytes === 'number' &&\n\t\t\tNumber.isSafeInteger(value.bytes) &&\n\t\t\tvalue.bytes >= 0 &&\n\t\t\tisStudyDigest(value.digest)\n\t\t)\n\t})\n}\n\n/**\n * Checks whether a seal has an exact unique execution inventory.\n * @param value - The candidate seal\n * @returns True if the seal is structurally valid; false otherwise\n * @example\n * ```ts\n * isStudyCustodySeal({}) // false\n * ```\n */\nexport function isStudyCustodySeal(value: unknown): value is StudySeal {\n\treturn holds(() => {\n\t\treturn (\n\t\t\tisRecord(value) &&\n\t\t\tmatchesStudyKeys(value, ['result', 'id', 'files']) &&\n\t\t\tisStudyCustodyName(value.result) &&\n\t\t\tisStudyDigest(value.id) &&\n\t\t\tisArray(value.files) &&\n\t\t\tvalue.files.length > 0 &&\n\t\t\tvalue.files.every(isStudyCustodyFile) &&\n\t\t\tnew Set(value.files.map((entry) => entry.path)).size === value.files.length\n\t\t)\n\t})\n}\n","import type { StudyAdapterInterface } from './types.js'\nimport { holds } from '@orkestrel/contract'\n\n/** Checks whether a factory returned the complete consumer adapter contract.\n * @param value - The unknown factory result.\n * @returns True if validation, construction, and grading are callable; false otherwise.\n * @example Refuse an incomplete adapter\n * ```ts\n * import { isStudyAdapter } from '@orkestrel/study/server'\n *\n * isStudyAdapter({}) // false\n * ```\n */\nexport function isStudyAdapter(value: unknown): value is StudyAdapterInterface {\n\treturn holds(() => {\n\t\treturn (\n\t\t\ttypeof value === 'object' &&\n\t\t\tvalue !== null &&\n\t\t\t'validate' in value &&\n\t\t\ttypeof value.validate === 'function' &&\n\t\t\t'driver' in value &&\n\t\t\ttypeof value.driver === 'function' &&\n\t\t\t'grade' in value &&\n\t\t\ttypeof value.grade === 'function'\n\t\t)\n\t})\n}\n","import type { StudyEvidence, StudyJudgment } from '../../core/types.js'\nimport type {\n\tStudyAdapterInterface,\n\tStudyAdjudication,\n\tStudyGradeFunction,\n\tStudyGradeTarget,\n\tStudyReference,\n} from './types.js'\nimport { isArray, isRecord } from '@orkestrel/contract'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyJudgment, isStudyRubric } from '../../core/validators.js'\nimport {\n\tisStudyCustodyAttempt,\n\tisStudyCustodyEvidence,\n\tisStudyCustodyManifest,\n} from '../stores/validators.js'\nimport { isStudyAdapter } from './validators.js'\n\n/** Reads a complete adapter from an admitted module namespace.\n * @param namespace - The captured consumer module.\n * @returns The validated adapter instance.\n */\nexport function readStudyAdapter(namespace: unknown): StudyAdapterInterface {\n\tif (!isRecord(namespace) || typeof namespace.createStudyAdapter !== 'function')\n\t\tthrow new StudyError('CONFIG', 'Consumer module must export createStudyAdapter')\n\tconst adapter: unknown = namespace.createStudyAdapter()\n\tif (!isStudyAdapter(adapter))\n\t\tthrow new StudyError('CONFIG', 'Consumer factory returned an incomplete study adapter')\n\treturn adapter\n}\n\n/**\n * Renders a citation of one retained trial file or evidence row.\n * @param target - The declared pair whose retained observations the citation must name\n * @param reference - The attempt file, the evidence file, or one zero-based evidence row\n * @returns The retained path, with a one-based row position for an evidence row\n * @throws StudyError - Thrown when the trial was not retained, or the citation names a row that does not exist or a row of the attempt file\n * @example Cite a retained evidence row\n * ```ts\n * import type { StudyGradeTarget } from '@orkestrel/study/server'\n * import { buildStudyReference } from '@orkestrel/study/server'\n *\n * declare const target: StudyGradeTarget\n *\n * buildStudyReference(target, { file: 'evidence', row: 0 }) // 'trials/r1-s1-a1/evidence.jsonl#1'\n * ```\n */\nexport function buildStudyReference(target: StudyGradeTarget, reference: StudyReference): string {\n\tif (!isRecord(reference)) throw new StudyError('EVIDENCE', 'Grading reference must be a record')\n\tif (target.attempt === undefined)\n\t\tthrow new StudyError('EVIDENCE', 'Grading reference names a trial that was not retained')\n\tif (reference.file !== 'attempt' && reference.file !== 'evidence')\n\t\tthrow new StudyError('EVIDENCE', 'Grading reference names an unknown retained file')\n\tconst file = reference.file === 'attempt' ? 'attempt.json' : 'evidence.jsonl'\n\tconst path = `trials/${target.trial.id}/${file}`\n\tif (reference.row === undefined) return path\n\tif (\n\t\treference.file !== 'evidence' ||\n\t\t!Number.isSafeInteger(reference.row) ||\n\t\treference.row < 0 ||\n\t\treference.row >= target.evidence.length ||\n\t\t!isStudyCustodyEvidence(target.evidence[reference.row])\n\t)\n\t\tthrow new StudyError('EVIDENCE', 'Grading reference names a retained row that does not exist')\n\treturn `${path}#${reference.row + 1}`\n}\n\n/**\n * Grades every declared trial and criterion pair through the consumer's predicate.\n * @param input - The sealed declaration, retained attempts, retained evidence, and independent rubric\n * @param grade - The consumer's domain predicate; it supplies each verdict, method, reason, and citation\n * @returns One judgment for each declared pair, in schedule then rubric order, with one-based evidence references\n * @remarks\n * The traversal validates its input at this boundary, so a direct call retains the checks the\n * host also makes. A trial without a retained attempt still receives a judgment: the predicate\n * sees no attempt and no evidence, and missing evidence stays whatever verdict the consumer\n * reads from it. The traversal never decides success, and it cites nothing the retained\n * evidence cannot back.\n * @throws StudyError - Thrown when the rubric, declaration, attempts, or evidence are invalid or foreign, when a criterion names an undeclared goal, or when a reading is not a valid judgment\n * @example Grade retained evidence with a consumer predicate\n * ```ts\n * import type { StudyAdjudication, StudyGradeFunction } from '@orkestrel/study/server'\n * import { gradeStudyEvidence } from '@orkestrel/study/server'\n *\n * declare const input: StudyAdjudication\n * declare const grade: StudyGradeFunction\n *\n * gradeStudyEvidence(input, grade)\n * ```\n */\nexport function gradeStudyEvidence(\n\tinput: StudyAdjudication,\n\tgrade: StudyGradeFunction,\n): readonly StudyJudgment[] {\n\tif (!isRecord(input)) throw new StudyError('CONFIG', 'Invalid grading input')\n\tconst { manifest, rubric, attempts, evidence } = input\n\tif (!isStudyRubric(rubric)) throw new StudyError('CONFIG', 'Invalid grading rubric')\n\tif (!isStudyCustodyManifest(manifest))\n\t\tthrow new StudyError('CONFIG', 'Invalid grading manifest or schedule')\n\tconst schedule = manifest.schedule\n\tif (!isArray(attempts) || !attempts.every((attempt) => isStudyCustodyAttempt(attempt, manifest)))\n\t\tthrow new StudyError('EVIDENCE', 'Invalid or duplicate grading attempts')\n\tconst retained = new Map(attempts.map((attempt) => [attempt.trial.id, attempt]))\n\tif (retained.size !== attempts.length)\n\t\tthrow new StudyError('EVIDENCE', 'Invalid or duplicate grading attempts')\n\tconst known = new Set(schedule.map((trial) => trial.id))\n\tif (\n\t\t!isRecord(evidence) ||\n\t\t!Object.entries(evidence).every(\n\t\t\t([id, rows]) =>\n\t\t\t\tknown.has(id) && isArray(rows) && Array.from(rows).every(isStudyCustodyEvidence),\n\t\t)\n\t)\n\t\tthrow new StudyError('EVIDENCE', 'Invalid or foreign grading evidence')\n\tfor (const criterion of rubric.criteria) {\n\t\tif (\n\t\t\t!manifest.scenarios.some(\n\t\t\t\t(scenario) =>\n\t\t\t\t\tscenario.id === criterion.scenario &&\n\t\t\t\t\tscenario.goals.some((goal) => goal.id === criterion.goal),\n\t\t\t)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Grading criterion references an undeclared goal')\n\t}\n\t// Iterators pull each trial and criterion only after the preceding predicate returned, so a\n\t// predicate that edits the caller's live arrays changes what the next judgment names.\n\treturn Object.freeze(\n\t\tschedule\n\t\t\t.values()\n\t\t\t.flatMap((trial) => {\n\t\t\t\tconst attempt = retained.get(trial.id)\n\t\t\t\tconst rows: readonly StudyEvidence[] =\n\t\t\t\t\tattempt === undefined ? Object.freeze([]) : (evidence[trial.id] ?? Object.freeze([]))\n\t\t\t\treturn rubric.criteria\n\t\t\t\t\t.values()\n\t\t\t\t\t.filter((criterion) => criterion.scenario === trial.scenario)\n\t\t\t\t\t.map((criterion): StudyJudgment => {\n\t\t\t\t\t\tconst target: StudyGradeTarget = Object.freeze({\n\t\t\t\t\t\t\ttrial,\n\t\t\t\t\t\t\tcriterion,\n\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\tevidence: rows,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst reading = grade(target)\n\t\t\t\t\t\tif (!isRecord(reading) || !isArray(reading.references))\n\t\t\t\t\t\t\tthrow new StudyError('EVIDENCE', 'Grading predicate returned an invalid reading')\n\t\t\t\t\t\tconst judgment = {\n\t\t\t\t\t\t\ttrial: trial.id,\n\t\t\t\t\t\t\tcriterion: criterion.id,\n\t\t\t\t\t\t\tverdict: reading.verdict,\n\t\t\t\t\t\t\tmethod: reading.method,\n\t\t\t\t\t\t\treason: reading.reason,\n\t\t\t\t\t\t\treferences: Object.freeze(\n\t\t\t\t\t\t\t\treading.references.map((reference) => buildStudyReference(target, reference)),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!isStudyJudgment(judgment))\n\t\t\t\t\t\t\tthrow new StudyError('EVIDENCE', 'Grading predicate returned an invalid judgment')\n\t\t\t\t\t\treturn Object.freeze(judgment)\n\t\t\t\t\t})\n\t\t\t})\n\t\t\t.toArray(),\n\t)\n}\n","import type {\n\tStudyAttempt,\n\tStudyJudgment,\n\tStudyLabeling,\n\tStudyManifest,\n\tStudyRubric,\n} from '../../core/types.js'\nimport type {\n\tStudyFile,\n\tStudyPacketBundle,\n\tStudyPacketEntry,\n\tStudyPacketLink,\n\tStudyResultReading,\n\tStudySealedResult,\n} from './types.js'\nimport type { FileHandle } from 'node:fs/promises'\nimport { attempt, canonicalStringify, parseJSON } from '@orkestrel/contract'\nimport { constants } from 'node:fs'\nimport { lstat, open, readdir } from 'node:fs/promises'\nimport { dirname, join, parse, relative, resolve, sep } from 'node:path'\nimport { StudyError } from '../../core/errors.js'\nimport { decodeStudyJSON, encodeStudyJSON, hashStudyBytes } from '../helpers.js'\nimport { STUDY_CUSTODY_BYTES, STUDY_PACKET_DISCLOSURE } from './constants.js'\nimport {\n\tisStudyCustodyAttempt,\n\tisStudyCustodyEvidence,\n\tisStudyCustodyManifest,\n\tisStudyCustodySeal,\n} from './validators.js'\n\n/**\n * Builds neutral semantic identities for the complete eligible sealed horizon.\n * @param result - The verified sealed execution\n * @param rubric - The compatible independently held rubric\n * @returns Deterministically sorted neutral mappings\n * @example\n * ```ts\n * buildStudyPacketLinks(result, rubric)\n * ```\n */\nexport function buildStudyPacketLinks(\n\tresult: StudySealedResult,\n\trubric: StudyRubric,\n): readonly StudyPacketLink[] {\n\t// The pairs are produced one at a time, and a hole is a position that reads as absent, so a hole\n\t// refuses after the links before it were counted, as visiting each position in turn does.\n\tconst pairs = result.manifest.schedule.values().flatMap((trial) =>\n\t\trubric.criteria\n\t\t\t.values()\n\t\t\t.filter(\n\t\t\t\t(criterion) => criterion.method === 'semantic' && criterion.scenario === trial.scenario,\n\t\t\t)\n\t\t\t.map((criterion) => ({ trial, criterion })),\n\t)\n\t// Each record carries the encoded bytes of every link up to and including its own.\n\tconst records: Array<{ readonly link: StudyPacketLink; readonly bytes: number }> = []\n\tfor (const { trial, criterion } of pairs) {\n\t\tconst link = {\n\t\t\ttrial: `t-${hashStudyBytes(encodeStudyJSON([result.seal.id, 'trial', trial.id]))}`,\n\t\t\tcriterion: `c-${hashStudyBytes(encodeStudyJSON([result.seal.id, 'criterion', criterion.id]))}`,\n\t\t\tsource: { trial: trial.id, criterion: criterion.id },\n\t\t}\n\t\tconst bytes = (records.at(-1)?.bytes ?? 256) + encodeStudyJSON(link).byteLength\n\t\tif (bytes > STUDY_CUSTODY_BYTES)\n\t\t\tthrow new StudyError('CAPACITY', 'Semantic packet mapping exceeds its custody allowance')\n\t\trecords.push({ link, bytes })\n\t}\n\tconst links = records.map(({ link }) => link)\n\treturn Object.freeze(\n\t\tlinks.sort((left, right) =>\n\t\t\t`${left.trial}/${left.criterion}` < `${right.trial}/${right.criterion}`\n\t\t\t\t? -1\n\t\t\t\t: `${left.trial}/${left.criterion}` > `${right.trial}/${right.criterion}`\n\t\t\t\t\t? 1\n\t\t\t\t\t: 0,\n\t\t),\n\t)\n}\n\n/**\n * Builds deterministic public semantic inputs and a separately retained private map.\n * @param result - The verified sealed execution\n * @param rubric - The compatible semantic criterion declaration\n * @param digest - The exact imported rubric-byte identity\n * @returns The packet bundle, or undefined for a purely mechanical rubric\n * @throws StudyError - Thrown when a semantic pair has no declared input or terminal record\n * @example\n * ```ts\n * buildStudyPacket(result, rubric, rubricDigest)\n * ```\n */\nexport function buildStudyPacket(\n\tresult: StudySealedResult,\n\trubric: StudyRubric,\n\tdigest: string,\n): StudyPacketBundle | undefined {\n\tconst links = buildStudyPacketLinks(result, rubric)\n\tif (links.length === 0) return undefined\n\tconst opening = encodeStudyJSON({ disclosure: STUDY_PACKET_DISCLOSURE, entries: [] }).byteLength\n\t// Each link is looked up, refused or counted before the next one is read; each record carries the\n\t// encoded bytes of every entry up to and including its own.\n\tconst records: Array<{ readonly entry: StudyPacketEntry; readonly length: number }> = []\n\tfor (const link of links) {\n\t\tconst trial = result.manifest.schedule.find((entry) => entry.id === link.source.trial)\n\t\tconst criterion = rubric.criteria.find((entry) => entry.id === link.source.criterion)\n\t\tconst scenario = result.manifest.scenarios.find((entry) => entry.id === trial?.scenario)\n\t\tconst goal = scenario?.goals.find((entry) => entry.id === criterion?.goal)\n\t\tconst observation = result.attempts\n\t\t\t.find((entry) => entry.trial.id === link.source.trial)\n\t\t\t?.observations.find((entry) => entry.goal === criterion?.goal)\n\t\tif (criterion === undefined || goal === undefined || observation === undefined)\n\t\t\tthrow new StudyError('EVIDENCE', 'Semantic packet refers to an absent sealed horizon')\n\t\tconst entry = {\n\t\t\ttrial: link.trial,\n\t\t\tcriterion: link.criterion,\n\t\t\tinput: goal.input,\n\t\t\tproduct: observation.product,\n\t\t\tassertion: criterion.assertion,\n\t\t}\n\t\tconst length = (records.at(-1)?.length ?? opening) + encodeStudyJSON(entry).byteLength\n\t\tif (length > STUDY_CUSTODY_BYTES)\n\t\t\tthrow new StudyError('CAPACITY', 'Semantic packet content exceeds its custody allowance')\n\t\trecords.push({ entry, length })\n\t}\n\tconst entries = records.map(({ entry }) => entry)\n\treturn Object.freeze({\n\t\tcontent: encodeStudyJSON({ disclosure: STUDY_PACKET_DISCLOSURE, entries }),\n\t\tmapping: encodeStudyJSON({\n\t\t\tresult: result.seal.id,\n\t\t\trubric: digest,\n\t\t\tentries: links,\n\t\t}),\n\t})\n}\n\n/**\n * Computes a bundle identity binding exact public packet and private map bytes.\n * @param packet - The immutable grading packet bundle\n * @returns The exact bundle digest\n * @example\n * ```ts\n * computeStudyPacketDigest(packet)\n * ```\n */\nexport function computeStudyPacketDigest(packet: StudyPacketBundle): string {\n\treturn hashStudyBytes(\n\t\tencodeStudyJSON({\n\t\t\tcontent: hashStudyBytes(packet.content),\n\t\t\tmapping: hashStudyBytes(packet.mapping),\n\t\t}),\n\t)\n}\n\n/**\n * Translates bound neutral imported labels through the sealed semantic horizon.\n * @param result - The verified sealed execution\n * @param rubric - The retained rubric\n * @param digest - The exact retained rubric-byte identity\n * @param labels - The original imported neutral labels\n * @returns Judgments translated to scheduled trial and criterion identities\n * @throws StudyError - Thrown when the packet or a label identity is foreign\n * @example\n * ```ts\n * translateStudyPacketLabeling(result, rubric, rubricDigest, labels)\n * ```\n */\nexport function translateStudyPacketLabeling(\n\tresult: StudySealedResult,\n\trubric: StudyRubric,\n\tdigest: string,\n\tlabels: StudyLabeling,\n): readonly StudyJudgment[] {\n\tconst packet = buildStudyPacket(result, rubric, digest)\n\tif (packet === undefined || labels.packet !== hashStudyBytes(packet.content))\n\t\tthrow new StudyError('EVIDENCE', 'Labels bind a different semantic packet')\n\tconst links = buildStudyPacketLinks(result, rubric)\n\treturn Object.freeze(\n\t\tlabels.judgments.map((judgment) => {\n\t\t\tconst link = links.find(\n\t\t\t\t(entry) => entry.trial === judgment.trial && entry.criterion === judgment.criterion,\n\t\t\t)\n\t\t\tif (link === undefined || (judgment.method !== 'human' && judgment.method !== 'model'))\n\t\t\t\tthrow new StudyError('EVIDENCE', 'Label refers to a foreign semantic packet identity')\n\t\t\treturn { ...judgment, trial: link.source.trial, criterion: link.source.criterion }\n\t\t}),\n\t)\n}\n\n/**\n * Refuses symbolic links and non-directory ancestors before custody operations.\n * @param directory - The absolute or relative directory\n * @returns The resolved checked directory\n * @throws StudyError - Thrown when any ancestor is linked or is not a directory\n * @example\n * ```ts\n * await checkStudyDirectory(directory)\n * ```\n */\nexport async function checkStudyDirectory(directory: string): Promise<string> {\n\tconst absolute = resolve(directory)\n\tconst root = parse(absolute).root\n\tconst names = relative(root, absolute).split(sep).filter(Boolean)\n\tfor (const [index] of names.entries()) {\n\t\tconst stat = await lstat(join(root, ...names.slice(0, index + 1)))\n\t\tif (!stat.isDirectory() || stat.isSymbolicLink())\n\t\t\tthrow new StudyError('CUSTODY', 'Linked or invalid custody directory')\n\t}\n\treturn absolute\n}\n\n/**\n * Reads from an open file handle into a buffer until the buffer is full or the file ends.\n * @param handle - The open file handle to read\n * @param target - The buffer to fill from the start of the file\n * @param offset - The position in the file and the buffer to continue from; Default: 0\n * @returns The bytes read, as the whole buffer when the file filled it or as its leading part when the file ended first\n */\nexport async function readStudyHandle(\n\thandle: FileHandle,\n\ttarget: Buffer,\n\toffset = 0,\n): Promise<Buffer> {\n\tif (offset >= target.length) return target\n\tconst reading = await handle.read(target, offset, target.length - offset, offset)\n\treturn reading.bytesRead === 0\n\t\t? target.subarray(0, offset)\n\t\t: readStudyHandle(handle, target, offset + reading.bytesRead)\n}\n\n/**\n * Reads bounded regular-file bytes without following a symbolic link.\n * @param path - The custody file path\n * @param limit - The byte allowance\n * @returns Exact retained bytes\n * @throws StudyError - Thrown when the file is linked, oversized, changed, or not regular\n * @example\n * ```ts\n * await readStudyBytes(path, 1024)\n * ```\n */\nexport async function readStudyBytes(path: string, limit: number): Promise<Uint8Array> {\n\tif (!Number.isSafeInteger(limit) || limit < 0)\n\t\tthrow new StudyError('CONFIG', 'Invalid custody byte allowance')\n\tawait checkStudyDirectory(dirname(path))\n\tconst prior = await lstat(path)\n\tif (prior.isSymbolicLink() || !prior.isFile() || prior.size > limit)\n\t\tthrow new StudyError('CUSTODY', 'Invalid or oversized custody file')\n\tconst handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0))\n\ttry {\n\t\tconst stat = await handle.stat()\n\t\tif (!stat.isFile() || stat.size > limit || stat.dev !== prior.dev || stat.ino !== prior.ino)\n\t\t\tthrow new StudyError('CUSTODY', 'Custody file changed during admission')\n\t\tconst bytes = await readStudyHandle(handle, Buffer.alloc(stat.size + 1))\n\t\tif (bytes.length !== stat.size)\n\t\t\tthrow new StudyError('CUSTODY', 'Custody file changed while reading')\n\t\treturn bytes\n\t} finally {\n\t\tawait handle.close()\n\t}\n}\n\n/**\n * Writes an exclusive regular record and synchronizes it before reporting success.\n * @param path - The new custody path\n * @param bytes - The exact encoded record\n * @returns Nothing after the record is synchronized\n * @example\n * ```ts\n * await writeStudyBytes(path, bytes)\n * ```\n */\nexport async function writeStudyBytes(path: string, bytes: Uint8Array): Promise<void> {\n\tawait checkStudyDirectory(dirname(path))\n\tconst handle = await open(path, 'wx')\n\ttry {\n\t\tawait handle.writeFile(bytes)\n\t\tawait handle.sync()\n\t} finally {\n\t\tawait handle.close()\n\t}\n}\n\n/**\n * Scans regular execution files while refusing unknown directories and linked paths.\n * @param directory - The execution directory\n * @param manifest - The authoritative population\n * @returns Sorted exact inventory entries\n * @throws StudyError - Thrown when inventory escapes its declared tree\n * @example\n * ```ts\n * await scanStudyExecution(directory, manifest)\n * ```\n */\nexport async function scanStudyExecution(\n\tdirectory: string,\n\tmanifest: StudyManifest,\n): Promise<readonly StudyFile[]> {\n\tawait checkStudyDirectory(directory)\n\tconst known = new Set(manifest.schedule.map((trial) => trial.id))\n\tconst files = await scanStudyTree(directory, '', known, manifest.bounds.series.bytes)\n\treturn Object.freeze(\n\t\t[...files].sort((left, right) =>\n\t\t\tleft.path < right.path ? -1 : left.path > right.path ? 1 : 0,\n\t\t),\n\t)\n}\n\n/**\n * Scans one execution directory and the subdirectories it admits, reading each admitted file under the series bytes that remain.\n * @param directory - The execution directory\n * @param prefix - The slash-separated path of the scanned directory; the empty string names the execution root\n * @param known - The scheduled trial identities\n * @param allowance - The series bytes that remain before this directory\n * @returns The admitted files in read order: this directory's files, then each admitted subdirectory's, last listed first\n * @throws StudyError - Thrown when the tree holds a link, an unknown directory or file, or a file beyond the remaining allowance\n */\nexport async function scanStudyTree(\n\tdirectory: string,\n\tprefix: string,\n\tknown: ReadonlySet<string>,\n\tallowance: number,\n): Promise<readonly StudyFile[]> {\n\tconst files: StudyFile[] = []\n\tconst directories: string[] = []\n\tfor (const entry of await readdir(join(directory, ...prefix.split('/').filter(Boolean)), {\n\t\twithFileTypes: true,\n\t})) {\n\t\tconst path = prefix === '' ? entry.name : `${prefix}/${entry.name}`\n\t\tif (entry.isSymbolicLink())\n\t\t\tthrow new StudyError('CUSTODY', 'Execution contains a symbolic link')\n\t\tif (entry.isDirectory()) {\n\t\t\tif (path !== 'trials' && !(prefix === 'trials' && known.has(entry.name)))\n\t\t\t\tthrow new StudyError('CUSTODY', 'Execution contains an unknown directory')\n\t\t\tdirectories.push(path)\n\t\t\tcontinue\n\t\t}\n\t\tconst names = path.split('/')\n\t\tif (\n\t\t\t!entry.isFile() ||\n\t\t\t!(\n\t\t\t\tpath === 'manifest.json' ||\n\t\t\t\t(names.length === 3 &&\n\t\t\t\t\tnames[0] === 'trials' &&\n\t\t\t\t\tknown.has(names[1] ?? '') &&\n\t\t\t\t\t(names[2] === 'attempt.json' || names[2] === 'evidence.jsonl'))\n\t\t\t)\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Execution contains an unknown file')\n\t\t// A directory admits at most two file names, so the sum over its earlier files is constant work.\n\t\tconst bytes = await readStudyBytes(\n\t\t\tjoin(directory, ...names),\n\t\t\tfiles.reduce((left, file) => left - file.bytes, allowance),\n\t\t)\n\t\tfiles.push(Object.freeze({ path, bytes: bytes.byteLength, digest: hashStudyBytes(bytes) }))\n\t}\n\tconst remaining = files.reduce((left, file) => left - file.bytes, allowance)\n\t// Each step carries the allowance its subtree left, computed once from the step before it.\n\tconst steps: Array<{ readonly found: readonly StudyFile[]; readonly left: number }> = []\n\tfor (const child of [...directories].reverse()) {\n\t\tconst before = steps.at(-1)?.left ?? remaining\n\t\tconst found = await scanStudyTree(directory, child, known, before)\n\t\tsteps.push({ found, left: found.reduce((left, file) => left - file.bytes, before) })\n\t}\n\treturn [...files, ...steps.flatMap((step) => step.found)]\n}\n\n/**\n * Validates complete evidence lines and per-goal encoded evidence bounds.\n * @param bytes - The exact JSONL file\n * @param manifest - The bounds and scenario declarations\n * @param trial - The scheduled trial identity\n * @returns Nothing when evidence satisfies its custody contract\n * @throws StudyError - Thrown when evidence is partial, invalid, foreign, or oversized\n * @example\n * ```ts\n * validateStudyEvidenceBytes(bytes, manifest, trial)\n * ```\n */\nexport function validateStudyEvidenceBytes(\n\tbytes: Uint8Array,\n\tmanifest: StudyManifest,\n\ttrial: string,\n): void {\n\tconst scheduled = manifest.schedule.find((entry) => entry.id === trial)\n\tconst scenario = manifest.scenarios.find((entry) => entry.id === scheduled?.scenario)\n\tif (scenario === undefined || bytes.byteLength > manifest.bounds.trial.bytes)\n\t\tthrow new StudyError('CUSTODY', 'Evidence exceeds the declared trial')\n\tconst text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n\tif (text !== '' && !text.endsWith('\\n'))\n\t\tthrow new StudyError('CUSTODY', 'Evidence ends with a partial record')\n\t// A line's goal is undefined where it is not valid evidence for a declared goal.\n\tconst records = text\n\t\t.split(/\\r\\n|\\n/)\n\t\t.slice(0, -1)\n\t\t.map((line) => {\n\t\t\tconst evidence = parseJSON(line)\n\t\t\treturn {\n\t\t\t\tgoal:\n\t\t\t\t\tisStudyCustodyEvidence(evidence) &&\n\t\t\t\t\tscenario.goals.some((goal) => goal.id === evidence.goal)\n\t\t\t\t\t\t? evidence.goal\n\t\t\t\t\t\t: undefined,\n\t\t\t\tsize: Buffer.byteLength(`${line}\\n`, 'utf8'),\n\t\t\t}\n\t\t})\n\t// Only the lines before the first invalid one count: an overflow among them is the earlier refusal.\n\tconst invalid = records.findIndex(({ goal }) => goal === undefined)\n\tconst admitted = invalid === -1 ? records : records.slice(0, invalid)\n\tif (\n\t\t[...Map.groupBy(admitted, ({ goal }) => goal).values()].some(\n\t\t\t(group) => group.reduce((total, { size }) => total + size, 0) > manifest.bounds.goal.bytes,\n\t\t)\n\t)\n\t\tthrow new StudyError('CUSTODY', 'Evidence exceeds a goal allowance')\n\tif (invalid !== -1) throw new StudyError('CUSTODY', 'Evidence refers to an invalid goal')\n}\n\n/**\n * Computes an execution seal identity from its exact sorted inventory.\n * @param result - The manifest result identity\n * @param files - The sorted inventory\n * @returns The deterministic seal digest\n * @example\n * ```ts\n * computeStudySealId('execution', files)\n * ```\n */\nexport function computeStudySealId(result: string, files: readonly StudyFile[]): string {\n\treturn hashStudyBytes(encodeStudyJSON({ result, files }))\n}\n\n/**\n * Inspects custody bytes offline and verifies complete execution before grading.\n * @param directory - The result directory\n * @returns A sealed result or explicitly interrupted safe metadata\n * @throws StudyError - Thrown when existing custody bytes are invalid or tampered\n * @example\n * ```ts\n * await readStudyResult(directory)\n * ```\n */\nexport async function readStudyResult(directory: string): Promise<StudyResultReading> {\n\tconst absolute = await checkStudyDirectory(directory)\n\tconst root = await readdir(absolute, { withFileTypes: true })\n\tfor (const entry of root) {\n\t\tif (entry.isSymbolicLink()) throw new StudyError('CUSTODY', 'Result contains a symbolic link')\n\t\tif (\n\t\t\tentry.name === 'execution' || entry.name === 'grades' || entry.name === 'reports'\n\t\t\t\t? !entry.isDirectory()\n\t\t\t\t: entry.name !== 'seal.json' || !entry.isFile()\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Result contains an unknown path')\n\t}\n\tconst sealed = root.some((entry) => entry.name === 'seal.json')\n\tif (!root.some((entry) => entry.name === 'execution')) {\n\t\tif (sealed) throw new StudyError('CUSTODY', 'Sealed result is missing execution')\n\t\treturn Object.freeze({\n\t\t\tstatus: 'interrupted',\n\t\t\tdirectory: absolute,\n\t\t\tmanifest: undefined,\n\t\t\tattempts: Object.freeze([]),\n\t\t})\n\t}\n\tconst execution = join(absolute, 'execution')\n\tconst entries = await readdir(execution, { withFileTypes: true })\n\tif (!entries.some((entry) => entry.name === 'manifest.json')) {\n\t\tif (entries.length !== 0 || sealed)\n\t\t\tthrow new StudyError('CUSTODY', 'Execution is missing its manifest')\n\t\treturn Object.freeze({\n\t\t\tstatus: 'interrupted',\n\t\t\tdirectory: absolute,\n\t\t\tmanifest: undefined,\n\t\t\tattempts: Object.freeze([]),\n\t\t})\n\t}\n\tconst manifestBytes = await readStudyBytes(join(execution, 'manifest.json'), STUDY_CUSTODY_BYTES)\n\tconst decoded = attempt((): unknown => decodeStudyJSON(manifestBytes))\n\tif (!decoded.success && sealed) throw decoded.error\n\tconst manifest: unknown = decoded.success ? decoded.value : undefined\n\tif (!isStudyCustodyManifest(manifest)) {\n\t\tif (sealed) throw new StudyError('CUSTODY', 'Invalid execution manifest')\n\t\treturn Object.freeze({\n\t\t\tstatus: 'interrupted',\n\t\t\tdirectory: absolute,\n\t\t\tmanifest: undefined,\n\t\t\tattempts: Object.freeze([]),\n\t\t})\n\t}\n\tconst files = await scanStudyExecution(execution, manifest)\n\tif (\n\t\tfiles.find((entry) => entry.path === 'manifest.json')?.digest !== hashStudyBytes(manifestBytes)\n\t)\n\t\tthrow new StudyError('CUSTODY', 'Manifest changed during inventory reading')\n\tconst attempts: StudyAttempt[] = []\n\tfor (const trial of manifest.schedule) {\n\t\tconst evidence = files.find((entry) => entry.path === `trials/${trial.id}/evidence.jsonl`)\n\t\tif (evidence !== undefined && sealed) {\n\t\t\tconst bytes = await readStudyBytes(\n\t\t\t\tjoin(execution, 'trials', trial.id, 'evidence.jsonl'),\n\t\t\t\tmanifest.bounds.trial.bytes,\n\t\t\t)\n\t\t\tif (hashStudyBytes(bytes) !== evidence.digest)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Evidence changed during inventory reading')\n\t\t\tvalidateStudyEvidenceBytes(bytes, manifest, trial.id)\n\t\t}\n\t\tconst terminal = files.find((entry) => entry.path === `trials/${trial.id}/attempt.json`)\n\t\tif (terminal === undefined) continue\n\t\tif (evidence === undefined)\n\t\t\tthrow new StudyError('CUSTODY', 'Terminal attempt is missing its evidence file')\n\t\tconst bytes = await readStudyBytes(\n\t\t\tjoin(execution, 'trials', trial.id, 'attempt.json'),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tif (hashStudyBytes(bytes) !== terminal.digest)\n\t\t\tthrow new StudyError('CUSTODY', 'Attempt changed during inventory reading')\n\t\tconst reading = attempt((): unknown => decodeStudyJSON(bytes))\n\t\tif (!reading.success && sealed) throw reading.error\n\t\tconst record: unknown = reading.success ? reading.value : undefined\n\t\tif (!isStudyCustodyAttempt(record, manifest) || record.trial.id !== trial.id) {\n\t\t\tif (sealed) throw new StudyError('CUSTODY', 'Invalid or foreign terminal attempt')\n\t\t\tcontinue\n\t\t}\n\t\tattempts.push(record)\n\t}\n\tif (!sealed)\n\t\treturn Object.freeze({\n\t\t\tstatus: 'interrupted',\n\t\t\tdirectory: absolute,\n\t\t\tmanifest,\n\t\t\tattempts: Object.freeze(attempts),\n\t\t})\n\tconst sealBytes = await readStudyBytes(join(absolute, 'seal.json'), STUDY_CUSTODY_BYTES)\n\tif (\n\t\tfiles.reduce((total, file) => total + file.bytes, sealBytes.byteLength) >\n\t\tmanifest.bounds.series.bytes\n\t)\n\t\tthrow new StudyError('CUSTODY', 'Seal and execution exceed the series allowance')\n\tconst seal = decodeStudyJSON(sealBytes)\n\tif (\n\t\t!isStudyCustodySeal(seal) ||\n\t\tseal.result !== manifest.id ||\n\t\tseal.id !== computeStudySealId(manifest.id, files) ||\n\t\tcanonicalStringify(seal.files) !== canonicalStringify(files) ||\n\t\tattempts.length !== manifest.schedule.length ||\n\t\tfiles.length !== 1 + manifest.schedule.length * 2\n\t)\n\t\tthrow new StudyError('CUSTODY', 'Execution seal does not match the complete byte inventory')\n\treturn Object.freeze({\n\t\tstatus: 'sealed',\n\t\tdirectory: absolute,\n\t\tmanifest,\n\t\tattempts: Object.freeze(attempts),\n\t\tseal,\n\t})\n}\n","/** Limits each serialized IPC envelope, including its JSON framing. */\nexport const STUDY_FRAME_BYTES = 16 * 1024 * 1024\n\n/** Limits outstanding bidirectional protocol work per process. */\nexport const STUDY_PENDING_LIMIT = 64\n\n/** Limits combined worker stdout and stderr before termination. */\nexport const STUDY_LOG_BYTES = 64 * 1024\n\n/** Bounds how long inherited output handles stay open after native exit, in milliseconds. */\nexport const STUDY_DRAIN_DURATION = 1000\n\n/** Attributes an expired process handshake or cleanup deadline. */\nexport const STUDY_PROCESS_LABEL = 'Process lifecycle'\n\n/** Names the worker operation routed by the built application entry. */\nexport const STUDY_WORKER_OPERATION = 'study-worker'\n\n/** Names the private bounded validation and grading route. */\nexport const STUDY_TASK_OPERATION = 'study-adapter'\n\n/** Names the command route beneath the native supervisor. */\nexport const STUDY_COMMAND_OPERATION = 'study-command'\n\n/** Caps pure domain work independently of its event loop. */\nexport const STUDY_TASK_DURATION = 60000\n","import type { StudyFailure, StudyProfile } from '../../core/types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport type { ChildProcess } from 'node:child_process'\nimport { canonicalStringify, isJSONValue, isRecord } from '@orkestrel/contract'\nimport { execFileSync } from 'node:child_process'\nimport { existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { StudyError } from '../../core/errors.js'\nimport { hashStudyBytes } from '../helpers.js'\nimport { STUDY_DRAIN_DURATION } from './constants.js'\n\n/** Projects optional domain fields into the JSON wire representation.\n * @param value - An owned domain value with optional undefined fields.\n * @returns A JSON-compatible snapshot.\n * @example Project a wire value\n * ```ts\n * import { valueToWire } from '@orkestrel/study/server'\n *\n * valueToWire({ state: 'ready', failure: undefined }) // { state: 'ready' }\n * ```\n */\nexport function valueToWire(value: unknown): JSONValue {\n\tconst parsed: unknown = JSON.parse(JSON.stringify(value))\n\tif (!isJSONValue(parsed)) throw new StudyError('FAULT', 'Invalid study wire value')\n\treturn parsed\n}\n\n/** Creates attributable protocol infrastructure failure.\n * @param message - The refused operation or broken boundary.\n * @returns A domain failure that never awards task credit.\n */\nexport function createStudyProcessFailure(message: string): StudyFailure {\n\treturn { cause: 'infrastructure', message, role: undefined, stop: undefined }\n}\n\n/** Binds the canonical fully resolved execution profile carried over IPC.\n * @param profile - The resolved execution settings, with optional absent leaves.\n * @returns The SHA256 digest of the canonical JSON wire representation.\n */\nexport function computeStudyProfileDigest(profile: StudyProfile): string {\n\tconst encoded = canonicalStringify(valueToWire(profile))\n\tif (encoded === undefined) throw new StudyError('CONFIG', 'Study profile is not JSON-compatible')\n\treturn hashStudyBytes(encoded)\n}\n\n/** Collects the executable entries a profile selects, each canonical path once.\n * @param profile - The resolved execution profile.\n * @returns The agent, subject, and provider entries without repeating a shared entry.\n * @remarks The declared roles stay separate in the profile; only capture and loading deduplicate.\n */\nexport function collectStudyEntries(profile: StudyProfile): readonly string[] {\n\treturn [\n\t\t...new Set([\n\t\t\tprofile.agent,\n\t\t\tprofile.subject,\n\t\t\t...(profile.provider === undefined ? [] : [profile.provider.entry]),\n\t\t]),\n\t]\n}\n\n/** Computes the instrument identity binding trusted runtime bytes to the adapter inventory.\n * @param entry - The SHA-256 identity of the trusted runtime entry bytes.\n * @param inventory - The captured adapter inventory digest.\n * @returns The identity that validation, grading, and trial children must share.\n */\nexport function computeStudyInstrumentDigest(entry: string, inventory: string): string {\n\treturn hashStudyBytes(JSON.stringify([entry, inventory]))\n}\n\n/** Resolves the actual host package from its trusted executable entry.\n * @param entry - The runtime's own executable, never a consumer-supplied module.\n * @returns The canonical study package root.\n */\nexport function resolveStudyInstrument(entry: string): string {\n\tconst root = collectStudyAncestors(dirname(realpathSync(entry))).find((directory) => {\n\t\tconst manifest = join(directory, 'package.json')\n\t\tif (!existsSync(manifest)) return false\n\t\tconst value: unknown = JSON.parse(readFileSync(manifest, 'utf8'))\n\t\treturn isRecord(value) && value.name === '@orkestrel/study'\n\t})\n\tif (root === undefined) throw new StudyError('CONFIG', 'Cannot locate the study runtime package')\n\treturn root\n}\n\n/** Collects a directory and each of its ancestors up to the filesystem root, nearest first.\n * @param directory - The absolute directory to start from.\n * @returns The directory followed by every parent directory, ending at the root.\n */\nexport function collectStudyAncestors(directory: string): readonly string[] {\n\tconst parent = dirname(directory)\n\treturn parent === directory ? [directory] : [directory, ...collectStudyAncestors(parent)]\n}\n\n/** Refuses a profile that omits the actual host runtime's declared dependency bytes.\n * @param instrument - The canonical package owning the trusted runtime entry.\n * @param roots - Explicitly admitted package roots, including the instrument.\n */\nexport function validateStudyRuntime(instrument: string, roots: readonly string[]): void {\n\tconst pending = [instrument]\n\tconst visited = new Set<string>()\n\twhile (pending.length > 0) {\n\t\tconst root = pending.pop()\n\t\tif (root === undefined || visited.has(root)) continue\n\t\tvisited.add(root)\n\t\tif (!roots.includes(root))\n\t\t\tthrow new StudyError('CONFIG', `Profile roots omit a runtime dependency: ${root}`)\n\t\tconst manifest = join(root, 'package.json')\n\t\tconst value: unknown = JSON.parse(readFileSync(manifest, 'utf8'))\n\t\tif (!isRecord(value) || value.dependencies === undefined) continue\n\t\tif (!isRecord(value.dependencies))\n\t\t\tthrow new StudyError('CONFIG', 'Runtime dependency declarations are invalid')\n\t\tconst resolver = createRequire(manifest)\n\t\tfor (const dependency of Object.keys(value.dependencies))\n\t\t\tpending.push(dirname(realpathSync(resolver.resolve(`${dependency}/package.json`))))\n\t}\n}\n\n/** Releases inherited output handles a bounded time after native exit.\n * @param child - A newly spawned child, subscribed before native exit.\n * @remarks A descendant that outlives an exited root is outside discoverable-tree cleanup; this only stops the parent from waiting on its pipes.\n */\nexport function drainStudyChild(child: ChildProcess): void {\n\tconst closed = new AbortController()\n\tchild.once('exit', () => {\n\t\t// A close before the allowance ends aborts the wait, which is the only rejection it can have.\n\t\tvoid delay(STUDY_DRAIN_DURATION, undefined, { signal: closed.signal }).then(\n\t\t\t() => {\n\t\t\t\tchild.stdout?.destroy()\n\t\t\t\tchild.stderr?.destroy()\n\t\t\t},\n\t\t\t() => undefined,\n\t\t)\n\t})\n\tchild.once('close', () => closed.abort())\n}\n\n/** Terminates the recorded native process tree under a finite cleanup allowance.\n * @param child - The exclusively owned child process.\n */\nexport function terminateStudyChild(child: ChildProcess): void {\n\tif (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) return\n\ttry {\n\t\tif (process.platform === 'win32')\n\t\t\texecFileSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], {\n\t\t\t\twindowsHide: true,\n\t\t\t\ttimeout: 2000,\n\t\t\t\tstdio: 'ignore',\n\t\t\t})\n\t\telse {\n\t\t\tconst rows = execFileSync('ps', ['-eo', 'pid=,ppid='], {\n\t\t\t\ttimeout: 2000,\n\t\t\t\tencoding: 'utf8',\n\t\t\t\tmaxBuffer: 1024 * 1024,\n\t\t\t})\n\t\t\t\t.trim()\n\t\t\t\t.split(/\\r\\n|\\n/)\n\t\t\t\t.map((row) => row.trim().split(/\\s+/).map(Number))\n\t\t\tconst descendants = new Set([child.pid])\n\t\t\t// One pass per row bounds the depth of any parent chain the table can hold.\n\t\t\trows.forEach(() => {\n\t\t\t\tfor (const [pid, parent] of rows)\n\t\t\t\t\tif (pid !== undefined && parent !== undefined && descendants.has(parent))\n\t\t\t\t\t\tdescendants.add(pid)\n\t\t\t})\n\t\t\tfor (const pid of [...descendants].reverse()) {\n\t\t\t\ttry {\n\t\t\t\t\tprocess.kill(pid, 'SIGKILL')\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!(error instanceof Error && 'code' in error && error.code === 'ESRCH')) throw error\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\ttry {\n\t\t\tprocess.kill(child.pid, 0)\n\t\t} catch (status) {\n\t\t\tif (status instanceof Error && 'code' in status && status.code === 'ESRCH') return\n\t\t\tthrow status\n\t\t}\n\t\tif (child.exitCode === null && child.signalCode === null) {\n\t\t\tchild.kill('SIGKILL')\n\t\t\tthrow error\n\t\t}\n\t}\n}\n","import type {\n\tStudyArtifactIdentity,\n\tStudyArtifactModule,\n\tStudyArtifactLoaderOptions,\n} from './types.js'\nimport type { StudyAdapterInterface } from '../adapters/types.js'\nimport { dirname, isAbsolute } from 'node:path'\nimport { readFileSync } from 'node:fs'\nimport { StudyError } from '../../core/errors.js'\nimport { ArtifactLoader } from '../artifacts/ArtifactLoader.js'\nimport { readStudyAdapter } from '../adapters/helpers.js'\nimport { hashStudyBytes } from '../helpers.js'\nimport { readStudyBytes } from '../stores/helpers.js'\nimport { STUDY_CUSTODY_BYTES } from '../stores/constants.js'\nimport {\n\tcollectStudyEntries,\n\tcomputeStudyInstrumentDigest,\n\tresolveStudyInstrument,\n\tvalidateStudyRuntime,\n} from './helpers.js'\n\n/** Binds consumer instrumentation separately from selected executable identities. */\nexport class StudyArtifactLoader {\n\t#options: StudyArtifactLoaderOptions\n\t#loader: ArtifactLoader | undefined\n\t#instrument: ArtifactLoader | undefined\n\t#identity: StudyArtifactIdentity | undefined\n\t#entry: string | undefined\n\t/** Owns resolved built and consumer source selections.\n\t * @param options - The trusted host, adapter, and profile.\n\t */\n\tconstructor(options: StudyArtifactLoaderOptions) {\n\t\tthis.#options = structuredClone(options)\n\t\tif (\n\t\t\t![\n\t\t\t\toptions.entry,\n\t\t\t\toptions.root,\n\t\t\t\toptions.adapter,\n\t\t\t\t...collectStudyEntries(options.profile),\n\t\t\t\t...options.profile.roots,\n\t\t\t].every(isAbsolute)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Study artifact paths must be absolute')\n\t}\n\t/** Inventories bytes without importing selected code.\n\t * @returns Bound executable and instrumentation identities.\n\t */\n\tasync inspect(): Promise<StudyArtifactIdentity> {\n\t\tif (this.#identity !== undefined) {\n\t\t\tthis.verify()\n\t\t\treturn this.#identity\n\t\t}\n\t\tconst profile = this.#options.profile\n\t\tconst instrument = resolveStudyInstrument(this.#options.entry)\n\t\tconst roots = [...new Set([...profile.roots, instrument])]\n\t\tvalidateStudyRuntime(instrument, roots)\n\t\tconst source = { root: dirname(this.#options.adapter), entry: this.#options.adapter }\n\t\tthis.#instrument = new ArtifactLoader({ entries: [], roots, source, instrument })\n\t\tconst entry = hashStudyBytes(await readStudyBytes(this.#options.entry, STUDY_CUSTODY_BYTES))\n\t\tthis.#entry = entry\n\t\tthis.#loader = new ArtifactLoader({\n\t\t\tentries: collectStudyEntries(profile),\n\t\t\troots,\n\t\t\tsource,\n\t\t\tinstrument,\n\t\t})\n\t\tconst inventory = this.#loader.inspect()\n\t\tthis.#identity = Object.freeze({\n\t\t\tagent: inventory.digest,\n\t\t\tsubject: inventory.digest,\n\t\t\tprovider: profile.provider === undefined ? undefined : inventory.digest,\n\t\t\tinstrument: computeStudyInstrumentDigest(entry, this.#instrument.inspect().digest),\n\t\t})\n\t\tthis.verify()\n\t\treturn this.#identity\n\t}\n\t/** Loads the adapter from the trial inventory.\n\t * @returns The complete consumer adapter.\n\t */\n\tasync adapter(): Promise<StudyAdapterInterface> {\n\t\tawait this.inspect()\n\t\tif (this.#loader === undefined)\n\t\t\tthrow new StudyError('CONFIG', 'Artifact inspection is required')\n\t\treturn readStudyAdapter(await this.#loader.load(this.#options.adapter))\n\t}\n\t/** Loads admitted built namespaces inside the trial child.\n\t * @returns The agent, subject and optional provider; a shared entry loads once and keeps each role.\n\t */\n\tasync load(): Promise<StudyArtifactModule> {\n\t\tawait this.inspect()\n\t\tif (this.#loader === undefined)\n\t\t\tthrow new StudyError('CONFIG', 'Artifact inspection is required')\n\t\tconst profile = this.#options.profile\n\t\tconst loaded: Array<readonly [string, unknown]> = []\n\t\tfor (const entry of collectStudyEntries(profile))\n\t\t\tloaded.push([entry, await this.#loader.load(entry)])\n\t\tconst namespaces = new Map(loaded)\n\t\tthis.verify()\n\t\tconst provider = profile.provider\n\t\treturn Object.freeze({\n\t\t\tagent: namespaces.get(profile.agent),\n\t\t\tsubject: namespaces.get(profile.subject),\n\t\t\tprovider: provider === undefined ? undefined : namespaces.get(provider.entry),\n\t\t})\n\t}\n\t/** Refuses instrument and inventory drift after inspection. */\n\tverify(): void {\n\t\tif (this.#loader === undefined || this.#instrument === undefined)\n\t\t\tthrow new StudyError('CONFIG', 'Artifact inspection is required')\n\t\tif (hashStudyBytes(readFileSync(this.#options.entry)) !== this.#entry)\n\t\t\tthrow new StudyError('FAULT', 'Study instrument bytes drifted')\n\t\tthis.#loader.verify()\n\t\tthis.#instrument.verify()\n\t}\n}\n","import type { StudyFrame } from './types.js'\nimport type {\n\tStudyCharge,\n\tStudyEvidence,\n\tStudyFailure,\n\tStudyTrial,\n\tStudyIdentity,\n} from '../../core/types.js'\nimport {\n\tisStudyCause,\n\tisStudyDigest,\n\tisStudyName,\n\tisStudyRole,\n\tisStudyStop,\n} from '../../core/validators.js'\nimport { holds, isJSONValue, isRecord } from '@orkestrel/contract'\n\n/** Checks the complete transport envelope before domain handling.\n * @param value - Native IPC decoded value.\n * @returns True if the envelope is bounded in shape and JSON-compatible; false otherwise.\n */\nexport function isStudyFrame(value: unknown): value is StudyFrame {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tObject.keys(value).length === 3 &&\n\t\t\tObject.hasOwn(value, 'id') &&\n\t\t\tObject.hasOwn(value, 'operation') &&\n\t\t\tObject.hasOwn(value, 'value') &&\n\t\t\ttypeof value.id === 'number' &&\n\t\t\tNumber.isSafeInteger(value.id) &&\n\t\t\tvalue.id >= 0 &&\n\t\t\ttypeof value.operation === 'string' &&\n\t\t\t[\n\t\t\t\t'open',\n\t\t\t\t'goal',\n\t\t\t\t'close',\n\t\t\t\t'admit',\n\t\t\t\t'finish',\n\t\t\t\t'fail',\n\t\t\t\t'evidence',\n\t\t\t\t'reply',\n\t\t\t\t'error',\n\t\t\t\t'abort',\n\t\t\t].includes(value.operation) &&\n\t\t\tisJSONValue(value.value),\n\t)\n}\n\n/** Checks operational failure attribution arriving over IPC.\n * @param value - Decoded failure value.\n * @returns True if the failure carries a known cause, an optional role, and an optional stop that satisfies `isStudyStop` on a `capacity` or `deadline` cause; false otherwise.\n */\nexport function isStudyProcessFailure(value: unknown): value is StudyFailure {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\ttypeof value.message === 'string' &&\n\t\t\tisStudyCause(value.cause) &&\n\t\t\t(value.role === undefined || isStudyRole(value.role)) &&\n\t\t\t(value.stop === undefined ||\n\t\t\t\t((value.cause === 'capacity' || value.cause === 'deadline') && isStudyStop(value.stop))),\n\t)\n}\n\n/** Checks a request's declared role and finite cost ceilings.\n * @param value - Decoded charge.\n * @returns True if all charge leaves are valid; false otherwise.\n */\nexport function isStudyCharge(value: unknown): value is StudyCharge {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tisStudyRole(value.role) &&\n\t\t\ttypeof value.tokens === 'number' &&\n\t\t\tNumber.isSafeInteger(value.tokens) &&\n\t\t\tvalue.tokens >= 0 &&\n\t\t\ttypeof value.bytes === 'number' &&\n\t\t\tNumber.isSafeInteger(value.bytes) &&\n\t\t\tvalue.bytes >= 0,\n\t)\n}\n\n/** Checks append-only public evidence.\n * @param value - Decoded evidence.\n * @returns True if event, goal and payload are valid; false otherwise.\n */\nexport function isStudyEvidence(value: unknown): value is StudyEvidence {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tisStudyName(value.event) &&\n\t\t\tisStudyName(value.goal) &&\n\t\t\tisJSONValue(value.value),\n\t)\n}\n\n/** Checks a fresh trial's declared identifiers.\n * @param value - Decoded trial.\n * @returns True if every identifier and repetition is valid; false otherwise.\n */\nexport function isStudyTrial(value: unknown): value is StudyTrial {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tisStudyName(value.id) &&\n\t\t\tisStudyName(value.scenario) &&\n\t\t\tisStudyName(value.arm) &&\n\t\t\ttypeof value.repetition === 'number' &&\n\t\t\tNumber.isSafeInteger(value.repetition) &&\n\t\t\tvalue.repetition >= 0,\n\t)\n}\n\n/** Checks the exact digest fields carried by the execution declaration.\n * @param value - Decoded identity.\n * @returns True if all required identities are digests; false otherwise.\n */\nexport function isStudyIdentity(value: unknown): value is StudyIdentity {\n\treturn holds(\n\t\t() =>\n\t\t\tisRecord(value) &&\n\t\t\tisStudyDigest(value.agent) &&\n\t\t\tisStudyDigest(value.subject) &&\n\t\t\t(value.provider === undefined || isStudyDigest(value.provider)) &&\n\t\t\tisStudyDigest(value.instrument) &&\n\t\t\tisStudyDigest(value.fixtures) &&\n\t\t\tisStudyDigest(value.profile),\n\t)\n}\n","import type { StudyChannelOptions, StudyFrame, StudyOperation, StudyResponse } from './types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport { StudyControl, failureToStudyError, readStudyFailure } from '../../core/engines/index.js'\nimport { STUDY_FRAME_BYTES, STUDY_PENDING_LIMIT } from './constants.js'\nimport { createStudyProcessFailure, valueToWire } from './helpers.js'\nimport { isStudyFrame, isStudyProcessFailure } from './validators.js'\n\n/** Correlates bounded IPC work and rejects every outstanding request on transport failure. */\nexport class StudyChannel {\n\t#options: StudyChannelOptions\n\t#control = new StudyControl()\n\treadonly #pending = new Map<number, StudyResponse>()\n\t#next = 0\n\t#received = 0\n\treadonly #working = new Set<symbol>()\n\t#message: (value: unknown) => void\n\t#disconnect: () => void\n\t#error: (error: Error) => void\n\n\t/** Subscribes to one native IPC endpoint.\n\t * @param options - Native endpoint and owning domain handlers; the bag is snapshotted while selected collaborators keep their identity.\n\t */\n\tconstructor(options: StudyChannelOptions) {\n\t\tthis.#options = { ...options }\n\t\tthis.#message = this.#onMessage.bind(this)\n\t\tthis.#disconnect = this.#onDisconnect.bind(this)\n\t\tthis.#error = this.close.bind(this)\n\t\tthis.#options.endpoint.on('message', this.#message)\n\t\tthis.#options.endpoint.on('disconnect', this.#disconnect)\n\t\tthis.#options.endpoint.on('error', this.#error)\n\t}\n\n\tget signal(): AbortSignal {\n\t\treturn this.#control.signal\n\t}\n\n\t#onMessage(value: unknown): void {\n\t\tvoid this.#receive(value).catch((error: unknown) => this.close(error))\n\t}\n\n\t#onDisconnect(): void {\n\t\tthis.close(failureToStudyError(createStudyProcessFailure('Study process disconnected')))\n\t}\n\n\t/** Sends one correlated domain request.\n\t * @param operation - The domain operation expected by the peer.\n\t * @param value - Public JSON payload.\n\t * @returns The peer's acknowledged result.\n\t */\n\trequest(operation: StudyOperation, value: JSONValue): Promise<JSONValue> {\n\t\tif (this.#control.failure !== undefined)\n\t\t\treturn Promise.reject(failureToStudyError(this.#control.failure))\n\t\tif (this.#pending.size >= STUDY_PENDING_LIMIT)\n\t\t\treturn Promise.reject(\n\t\t\t\tfailureToStudyError(createStudyProcessFailure('Study IPC pending limit exceeded')),\n\t\t\t)\n\t\tconst id = ++this.#next\n\t\treturn new Promise<JSONValue>((resolve, reject) => {\n\t\t\tthis.#pending.set(id, { resolve, reject })\n\t\t\tthis.#send({ id, operation, value }).catch((error: unknown) => this.close(error))\n\t\t})\n\t}\n\n\t/** Forwards cancellation without closing the cleanup transport.\n\t * @param value - Validated goal, trial or ticket cancellation attribution.\n\t */\n\tabort(value: JSONValue): void {\n\t\tvoid this.#send({ id: 0, operation: 'abort', value }).catch((error: unknown) =>\n\t\t\tthis.close(error),\n\t\t)\n\t}\n\n\t/** Removes endpoint handlers and rejects all unresolved calls.\n\t * @param error - The first transport or owning lifecycle failure.\n\t */\n\tclose(\n\t\terror: unknown = failureToStudyError(createStudyProcessFailure('Study channel closed')),\n\t): void {\n\t\tthis.#control.fail(readStudyFailure(error))\n\t\tthis.#options.endpoint.removeListener('message', this.#message)\n\t\tthis.#options.endpoint.removeListener('disconnect', this.#disconnect)\n\t\tthis.#options.endpoint.removeListener('error', this.#error)\n\t\tfor (const pending of this.#pending.values())\n\t\t\tpending.reject(failureToStudyError(this.#control.failure ?? readStudyFailure(error)))\n\t\tthis.#pending.clear()\n\t\tthis.#control.close()\n\t}\n\n\tasync #send(frame: StudyFrame): Promise<void> {\n\t\tif (Buffer.byteLength(JSON.stringify(frame)) > STUDY_FRAME_BYTES)\n\t\t\tthrow failureToStudyError(createStudyProcessFailure('Study IPC frame limit exceeded'))\n\t\tif (!this.#options.endpoint.connected || this.#options.endpoint.send === undefined)\n\t\t\tthrow failureToStudyError(createStudyProcessFailure('Study IPC is unavailable'))\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.#options.endpoint.send?.(frame, undefined, {}, (error: Error | null) =>\n\t\t\t\terror === null ? resolve() : reject(error),\n\t\t\t)\n\t\t})\n\t}\n\n\tasync #receive(value: unknown): Promise<void> {\n\t\tif (!isStudyFrame(value) || Buffer.byteLength(JSON.stringify(value)) > STUDY_FRAME_BYTES)\n\t\t\tthrow failureToStudyError(createStudyProcessFailure('Malformed study IPC frame'))\n\t\tif (value.operation === 'abort') {\n\t\t\tif (value.id !== 0)\n\t\t\t\tthrow failureToStudyError(createStudyProcessFailure('Foreign study cancellation'))\n\t\t\tthis.#options.abort(value.value)\n\t\t\treturn\n\t\t}\n\t\tif (value.operation === 'reply' || value.operation === 'error') {\n\t\t\tconst pending = this.#pending.get(value.id)\n\t\t\tif (pending === undefined)\n\t\t\t\tthrow failureToStudyError(createStudyProcessFailure('Unknown study IPC reply'))\n\t\t\tif (value.operation === 'reply') pending.resolve(value.value)\n\t\t\telse {\n\t\t\t\tif (!isStudyProcessFailure(value.value))\n\t\t\t\t\tthrow failureToStudyError(createStudyProcessFailure('Invalid study IPC failure'))\n\t\t\t\tpending.reject(failureToStudyError(value.value))\n\t\t\t}\n\t\t\tthis.#pending.delete(value.id)\n\t\t\treturn\n\t\t}\n\t\tif (value.id !== this.#received + 1 || this.#working.size >= STUDY_PENDING_LIMIT)\n\t\t\tthrow failureToStudyError(\n\t\t\t\tcreateStudyProcessFailure('Out-of-order or excessive study IPC request'),\n\t\t\t)\n\t\tconst id = value.id\n\t\tthis.#received = id\n\t\t// The request joins the registry before its handler can run, so a request the handler admits\n\t\t// on its synchronous path meets the limit.\n\t\tconst working = Symbol('request')\n\t\tthis.#working.add(working)\n\t\ttry {\n\t\t\tconst result = await this.#options.handle(value.operation, value.value)\n\t\t\t// The admitted id answers both outcomes: another listener on the shared endpoint may edit\n\t\t\t// the borrowed frame while the handler is pending.\n\t\t\tawait this.#send({ id, operation: 'reply', value: result })\n\t\t} catch (error) {\n\t\t\tawait this.#send({\n\t\t\t\tid,\n\t\t\t\toperation: 'error',\n\t\t\t\tvalue: valueToWire(readStudyFailure(error)),\n\t\t\t})\n\t\t} finally {\n\t\t\tthis.#working.delete(working)\n\t\t}\n\t}\n}\n","import type { StudyContext } from '../../core/types.js'\n\n/** Holds one goal's parent context and the worker admission sequence it issues while the goal runs.\n * @example Issue worker admissions in sequence\n * ```ts\n * import type { StudyContext } from '@orkestrel/study'\n * import { StudyProcessGoal } from '@orkestrel/study/server'\n *\n * declare const context: StudyContext\n *\n * const goal = new StudyProcessGoal(context)\n * goal.issue(2) // undefined\n * goal.issue(1) // 1\n * goal.issue(1) // undefined\n * goal.issue(2) // 2\n * ```\n */\nexport class StudyProcessGoal {\n\treadonly #context: StudyContext\n\t#issued = 0\n\n\t/** Binds one goal to the parent meter and evidence sink it runs under.\n\t * @param context - The actual parent meter, evidence sink and cancellation of the goal.\n\t */\n\tconstructor(context: StudyContext) {\n\t\tthis.#context = context\n\t}\n\n\t/** Reports the parent meter and evidence sink the goal runs under. */\n\tget context(): StudyContext {\n\t\treturn this.#context\n\t}\n\n\t/** Issues the identifier of the next worker admission when the worker asked for exactly that one.\n\t * @param requested - The identifier the worker supplied.\n\t * @returns The issued identifier, or undefined when the requested one is not the next in sequence.\n\t */\n\tissue(requested: unknown): number | undefined {\n\t\tif (requested !== this.#issued + 1) return undefined\n\t\tthis.#issued++\n\t\treturn this.#issued\n\t}\n}\n","import type {\n\tStudyContext,\n\tStudyGoal,\n\tStudyProduct,\n\tStudySessionInterface,\n} from '../../core/types.js'\nimport type { StudyOperation, StudyParentTicket, StudyProcessSessionOptions } from './types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport type { ChildProcess } from 'node:child_process'\nimport { isRecord } from '@orkestrel/contract'\nimport { execFile, fork } from 'node:child_process'\nimport { mkdtemp } from 'node:fs/promises'\nimport { isAbsolute, join } from 'node:path'\nimport {\n\tStudyControl,\n\tStudyDeadline,\n\tfailureToStudyError,\n\treadStudyFailure,\n} from '../../core/engines/index.js'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyProduct, isStudyUsage } from '../../core/validators.js'\nimport { STUDY_LOG_BYTES, STUDY_PROCESS_LABEL, STUDY_WORKER_OPERATION } from './constants.js'\nimport { createStudyProcessFailure, drainStudyChild, valueToWire } from './helpers.js'\nimport { StudyChannel } from './StudyChannel.js'\nimport { StudyProcessGoal } from './StudyProcessGoal.js'\nimport { isStudyCharge, isStudyEvidence, isStudyProcessFailure } from './validators.js'\n\n/** Keeps admission and evidence custody in the parent of one fresh trial process. */\nexport class StudyProcessSession implements StudySessionInterface {\n\t#options: StudyProcessSessionOptions\n\t#control: StudyControl\n\t#listeners = new AbortController()\n\t#child: ChildProcess | undefined\n\t#channel: StudyChannel | undefined\n\t#exit: Promise<void> | undefined\n\t#closing: Promise<void> | undefined\n\treadonly #goals = new Set<StudyProcessGoal>()\n\treadonly #tickets = new Map<number, StudyParentTicket>()\n\treadonly #appends = new Set<Promise<void>>()\n\t#logs = 0\n\t#started = false\n\t#deadline: ReturnType<typeof setTimeout> | undefined\n\n\t/** Owns one trial's process lifecycle without starting host work.\n\t * @param options - Public trial and process configuration; the configuration is snapshotted while the borrowed signal keeps its identity.\n\t */\n\tconstructor(options: StudyProcessSessionOptions) {\n\t\tconst { signal, ...configuration } = options\n\t\tthis.#options = { ...structuredClone(configuration), signal }\n\t\tthis.#control = new StudyControl(signal)\n\t}\n\n\t/** Starts the child and verifies its artifact-bound readiness. */\n\tasync start(): Promise<void> {\n\t\tif (this.#started || this.#closing !== undefined)\n\t\t\tthrow new StudyError('FAULT', 'Study process start is single use')\n\t\tthis.#started = true\n\t\tif (this.#control.failure !== undefined) throw failureToStudyError(this.#control.failure)\n\t\tif (![this.#options.entry, this.#options.root, this.#options.directory].every(isAbsolute))\n\t\t\tthrow new StudyError('CONFIG', 'Study process paths must be absolute')\n\t\tconst directory = await mkdtemp(join(this.#options.directory, 'trial-'))\n\t\tif (this.#control.failure !== undefined) throw failureToStudyError(this.#control.failure)\n\t\tconst child = fork(this.#options.entry, [STUDY_WORKER_OPERATION], {\n\t\t\tcwd: this.#options.root,\n\t\t\texecArgv: [...process.execArgv],\n\t\t\tsilent: true,\n\t\t\tserialization: 'json',\n\t\t\twindowsHide: true,\n\t\t\tdetached: process.platform !== 'win32',\n\t\t})\n\t\tdrainStudyChild(child)\n\t\tthis.#child = child\n\t\tthis.#deadline = setTimeout(() => {\n\t\t\tthis.#control.fail({\n\t\t\t\tcause: 'deadline',\n\t\t\t\tmessage: 'Trial native deadline exceeded',\n\t\t\t\trole: undefined,\n\t\t\t\t// The session holds no start time, so the timer firing proves only that the elapsed time reached the limit.\n\t\t\t\tstop: {\n\t\t\t\t\tlayer: 'scope',\n\t\t\t\t\tid: 'Trial duration',\n\t\t\t\t\tmax: this.#options.profile.bounds.trial.duration,\n\t\t\t\t\tconsumed: undefined,\n\t\t\t\t},\n\t\t\t})\n\t\t\tvoid this.#terminate().catch((error: unknown) => this.#control.fail(readStudyFailure(error)))\n\t\t}, this.#options.profile.bounds.trial.duration)\n\t\tthis.#exit = new Promise<void>((resolve) => child.once('close', () => resolve()))\n\t\tthis.#channel = new StudyChannel({\n\t\t\tendpoint: child,\n\t\t\thandle: (operation, value) =>\n\t\t\t\tthis.#handle(operation, value).catch((error: unknown) => {\n\t\t\t\t\tthis.#control.fail(readStudyFailure(error))\n\t\t\t\t\tthrow error\n\t\t\t\t}),\n\t\t\tabort: () => {\n\t\t\t\tthrow new StudyError('FAULT', 'Worker cannot cancel parent authority')\n\t\t\t},\n\t\t})\n\t\tthis.#channel.signal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => this.#control.fail(readStudyFailure(this.#channel?.signal.reason)),\n\t\t\t{ once: true, signal: this.#listeners.signal },\n\t\t)\n\t\tthis.#control.signal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => this.#channel?.abort(valueToWire({ failure: this.#control.failure })),\n\t\t\t{ once: true, signal: this.#listeners.signal },\n\t\t)\n\t\tchild.stdout?.on('data', (value: Buffer) => this.#readLog(value))\n\t\tchild.stderr?.on('data', (value: Buffer) => this.#readLog(value))\n\t\tconst ready = await this.#control.wait(\n\t\t\tnew StudyDeadline({\n\t\t\t\tduration: this.#options.profile.bounds.trial.duration,\n\t\t\t\tlabel: STUDY_PROCESS_LABEL,\n\t\t\t}).wait(\n\t\t\t\tthis.#channel.request(\n\t\t\t\t\t'open',\n\t\t\t\t\tvalueToWire({ ...this.#options, signal: undefined, directory }),\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\tif (\n\t\t\t!isRecord(ready) ||\n\t\t\tready.pid !== child.pid ||\n\t\t\tready.agent !== this.#options.identity.agent ||\n\t\t\tready.subject !== this.#options.identity.subject ||\n\t\t\tready.instrument !== this.#options.identity.instrument\n\t\t)\n\t\t\tthrow new StudyError('FAULT', 'Worker readiness identity differs')\n\t}\n\n\t/** Runs one ordered goal through parent-authorized requests and acknowledged evidence.\n\t * @param goal - Public goal without grading truth.\n\t * @param context - Actual parent meter and evidence sink.\n\t * @returns The retained child product after every admitted operation settles.\n\t */\n\tasync execute(goal: StudyGoal, context: StudyContext): Promise<StudyProduct> {\n\t\tif (this.#goals.size !== 0 || this.#closing !== undefined || this.#channel === undefined)\n\t\t\tthrow new StudyError('FAULT', 'Study process cannot execute in its current state')\n\t\tif (this.#control.failure !== undefined) throw failureToStudyError(this.#control.failure)\n\t\tconst running = new StudyProcessGoal(context)\n\t\tthis.#goals.add(running)\n\t\tconst listeners = new AbortController()\n\t\tconst control = new StudyControl(context.signal)\n\t\tthis.#control.signal.addEventListener(\n\t\t\t'abort',\n\t\t\t() =>\n\t\t\t\tcontrol.fail(this.#control.failure ?? createStudyProcessFailure('Study process failed')),\n\t\t\t{ once: true, signal: listeners.signal },\n\t\t)\n\t\tcontrol.signal.addEventListener(\n\t\t\t'abort',\n\t\t\t() => this.#channel?.abort(valueToWire({ failure: control.failure })),\n\t\t\t{ once: true, signal: listeners.signal },\n\t\t)\n\t\ttry {\n\t\t\tconst product = await control.wait(this.#channel.request('goal', valueToWire(goal)))\n\t\t\tif (this.#tickets.size !== 0 || this.#appends.size !== 0)\n\t\t\t\tthrow new StudyError('FAULT', 'Worker goal ended with unsettled admission or evidence')\n\t\t\tif (!isStudyProduct(product)) throw new StudyError('FAULT', 'Worker product is invalid')\n\t\t\treturn product\n\t\t} catch (error) {\n\t\t\tthis.#control.fail(readStudyFailure(error))\n\t\t\tthrow failureToStudyError(this.#control.failure ?? readStudyFailure(error))\n\t\t} finally {\n\t\t\tlisteners.abort()\n\t\t\tcontrol.close()\n\t\t\tthis.#goals.delete(running)\n\t\t}\n\t}\n\n\t/** Requests verified cleanup, then terminates only this recorded process tree. */\n\tclose(): Promise<void> {\n\t\tthis.#closing ??= this.#close()\n\t\treturn this.#closing\n\t}\n\n\tasync #handle(operation: StudyOperation, value: JSONValue): Promise<JSONValue> {\n\t\tconst [running] = this.#goals\n\t\tif (running === undefined) throw new StudyError('FAULT', 'Worker requested work outside a goal')\n\t\tconst context = running.context\n\t\tif (operation === 'admit') {\n\t\t\tif (!isRecord(value) || !isStudyCharge(value.charge))\n\t\t\t\tthrow new StudyError('FAULT', 'Invalid worker admission')\n\t\t\tconst id = running.issue(value.id)\n\t\t\tif (id === undefined) throw new StudyError('FAULT', 'Invalid worker admission')\n\t\t\tconst ticket = await context.meter.admit(value.charge)\n\t\t\tconst listeners = new AbortController()\n\t\t\tthis.#tickets.set(id, { ticket, listeners })\n\t\t\tticket.signal.addEventListener(\n\t\t\t\t'abort',\n\t\t\t\t() =>\n\t\t\t\t\tthis.#channel?.abort(\n\t\t\t\t\t\tvalueToWire({ id, failure: readStudyFailure(ticket.signal.reason) }),\n\t\t\t\t\t),\n\t\t\t\t{ once: true, signal: listeners.signal },\n\t\t\t)\n\t\t\tif (ticket.signal.aborted) throw ticket.signal.reason\n\t\t\treturn { id }\n\t\t}\n\t\tif (operation === 'finish' || operation === 'fail') {\n\t\t\tif (!isRecord(value) || typeof value.id !== 'number')\n\t\t\t\tthrow new StudyError('FAULT', 'Invalid worker settlement')\n\t\t\tconst entry = this.#tickets.get(value.id)\n\t\t\tif (entry === undefined)\n\t\t\t\tthrow new StudyError('FAULT', 'Foreign or repeated worker settlement')\n\t\t\tif (\n\t\t\t\t(operation === 'finish' && !isStudyUsage(value.usage)) ||\n\t\t\t\t(operation === 'fail' && !isStudyProcessFailure(value.failure))\n\t\t\t)\n\t\t\t\tthrow new StudyError('FAULT', 'Invalid worker settlement payload')\n\t\t\tthis.#tickets.delete(value.id)\n\t\t\tentry.listeners.abort()\n\t\t\tif (operation === 'finish' && isStudyUsage(value.usage)) entry.ticket.finish(value.usage)\n\t\t\telse if (isStudyProcessFailure(value.failure)) entry.ticket.fail(value.failure)\n\t\t\treturn true\n\t\t}\n\t\tif (operation === 'evidence') {\n\t\t\tif (!isStudyEvidence(value)) throw new StudyError('FAULT', 'Invalid worker evidence')\n\t\t\tconst appending = context.evidence.append(value)\n\t\t\tthis.#appends.add(appending)\n\t\t\ttry {\n\t\t\t\tawait appending\n\t\t\t\treturn true\n\t\t\t} finally {\n\t\t\t\tthis.#appends.delete(appending)\n\t\t\t}\n\t\t}\n\t\tthrow new StudyError('FAULT', 'Worker requested a forbidden operation')\n\t}\n\n\t#readLog(value: Buffer): void {\n\t\tthis.#logs += value.byteLength\n\t\tif (this.#logs > STUDY_LOG_BYTES) {\n\t\t\tthis.#control.fail(createStudyProcessFailure('Worker output limit exceeded'))\n\t\t\tvoid this.close().catch(() => undefined)\n\t\t}\n\t}\n\n\tasync #close(): Promise<void> {\n\t\tconst failure = await this.#acknowledge()\n\t\tfor (const entry of this.#tickets.values()) {\n\t\t\tentry.listeners.abort()\n\t\t\tif (!entry.ticket.signal.aborted) {\n\t\t\t\ttry {\n\t\t\t\t\tentry.ticket.fail(\n\t\t\t\t\t\tthis.#control.failure ??\n\t\t\t\t\t\t\tcreateStudyProcessFailure('Worker closed with an unfinished request'),\n\t\t\t\t\t)\n\t\t\t\t} catch {\n\t\t\t\t\t/* First parent failure is already retained. */\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.#tickets.clear()\n\t\tthis.#listeners.abort()\n\t\tthis.#channel?.close(failure)\n\t\tawait this.#terminate()\n\t\tthis.#control.close()\n\t\tif (failure !== undefined) throw failure\n\t}\n\n\t// Asks the worker to clean up and returns the failure that stopped it, or undefined when it acknowledged.\n\tasync #acknowledge(): Promise<unknown> {\n\t\ttry {\n\t\t\tif (this.#channel !== undefined && !this.#channel.signal.aborted) {\n\t\t\t\tconst closed = await new StudyDeadline({\n\t\t\t\t\tduration: this.#options.profile.bounds.request.duration,\n\t\t\t\t\tlabel: STUDY_PROCESS_LABEL,\n\t\t\t\t}).wait(this.#channel.request('close', true))\n\t\t\t\tif (closed !== true)\n\t\t\t\t\tthrow new StudyError('FAULT', 'Worker cleanup acknowledgment is invalid')\n\t\t\t}\n\t\t\treturn undefined\n\t\t} catch (error) {\n\t\t\treturn error\n\t\t}\n\t}\n\n\tasync #terminate(): Promise<void> {\n\t\tclearTimeout(this.#deadline)\n\t\tconst child = this.#child\n\t\tif (child === undefined) return\n\t\tif (child.exitCode === null && child.signalCode === null && child.pid !== undefined) {\n\t\t\tif (process.platform === 'win32') {\n\t\t\t\tawait new Promise<void>((resolve, reject) =>\n\t\t\t\t\texecFile(\n\t\t\t\t\t\t'taskkill',\n\t\t\t\t\t\t['/PID', String(child.pid), '/T', '/F'],\n\t\t\t\t\t\t{ windowsHide: true, timeout: 2000 },\n\t\t\t\t\t\t(error) =>\n\t\t\t\t\t\t\terror === null || child.exitCode !== null || child.signalCode !== null\n\t\t\t\t\t\t\t\t? resolve()\n\t\t\t\t\t\t\t\t: reject(error),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t} else process.kill(-child.pid, 'SIGKILL')\n\t\t}\n\t\tif (this.#exit !== undefined)\n\t\t\tawait new StudyDeadline({ duration: 2000, label: STUDY_PROCESS_LABEL }).wait(this.#exit)\n\t}\n}\n","import type { StudyDriverInterface, StudySessionInterface, StudyTrial } from '../../core/types.js'\nimport type { StudyProcessOptions } from './types.js'\nimport { StudyProcessSession } from './StudyProcessSession.js'\n\n/** Opens one fresh native child for each scheduled trial. */\nexport class StudyProcessDriver implements StudyDriverInterface {\n\t#options: StudyProcessOptions\n\n\t/** Owns immutable resolved launch settings.\n\t * @param options - Built entry, admitted identities and exclusive scratch parent.\n\t */\n\tconstructor(options: StudyProcessOptions) {\n\t\tthis.#options = structuredClone(options)\n\t}\n\n\t/** Opens isolated child state and waits for its verified readiness.\n\t * @param trial - The public scheduled trial.\n\t * @param signal - Authoritative parent cancellation.\n\t * @returns A ready process-backed session.\n\t */\n\tasync open(trial: StudyTrial, signal: AbortSignal): Promise<StudySessionInterface> {\n\t\tconst session = new StudyProcessSession({ ...this.#options, trial, signal })\n\t\ttry {\n\t\t\tawait session.start()\n\t\t\treturn session\n\t\t} catch (error) {\n\t\t\tawait session.close().catch(() => undefined)\n\t\t\tthrow error\n\t\t}\n\t}\n}\n","import type { StudyGrading, StudyLabeling, StudyRubric } from '../../core/types.js'\nimport type { StudyGradingStoreOptions, StudyPacketBundle, StudySealedResult } from './types.js'\nimport { canonicalStringify } from '@orkestrel/contract'\nimport { lstat, mkdir, readdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { StudyError } from '../../core/errors.js'\nimport { computeStudyScores } from '../../core/helpers.js'\nimport { parseStudyGrading, parseStudyLabeling, parseStudyRubric } from '../../core/parsers.js'\nimport { isStudyDigest } from '../../core/validators.js'\nimport { decodeStudyJSON, encodeStudyJSON, hashStudyBytes } from '../helpers.js'\nimport { STUDY_CUSTODY_BYTES } from './constants.js'\nimport {\n\tcheckStudyDirectory,\n\tbuildStudyPacket,\n\tcomputeStudyPacketDigest,\n\treadStudyBytes,\n\treadStudyResult,\n\ttranslateStudyPacketLabeling,\n\twriteStudyBytes,\n} from './helpers.js'\n\n/** Retains immutable deterministic grading versions independently of execution bytes. */\nexport class StudyGradingStore {\n\treadonly #directory: string\n\treadonly #seal: string\n\treadonly #rubric: StudyRubric\n\treadonly #rubricBytes: Uint8Array\n\treadonly #rubricDigest: string\n\treadonly #labels: StudyLabeling | undefined\n\treadonly #labelsBytes: Uint8Array | undefined\n\treadonly #labelsDigest: string | undefined\n\treadonly #packet: StudyPacketBundle | undefined\n\t// The writes not yet settled; a write joins when called and leaves when it settles, and each waits for every earlier one.\n\treadonly #writes = new Set<Promise<string>>()\n\n\t/**\n\t * Owns exact imported grading bytes without writing any custody files.\n\t * @param options - The verified execution and exact rubric and optional labels bytes\n\t * @throws StudyError - Thrown when imported bytes exceed bounds or fail validation\n\t */\n\tconstructor(options: StudyGradingStoreOptions) {\n\t\tif (options.result.status !== 'sealed')\n\t\t\tthrow new StudyError('CUSTODY', 'Grading requires a sealed execution')\n\t\tif (\n\t\t\toptions.rubric.byteLength > STUDY_CUSTODY_BYTES ||\n\t\t\t(options.labels !== undefined && options.labels.byteLength > STUDY_CUSTODY_BYTES)\n\t\t)\n\t\t\tthrow new StudyError('CAPACITY', 'Imported grading bytes exceed the metadata allowance')\n\t\tthis.#directory = options.result.directory\n\t\tthis.#seal = options.result.seal.id\n\t\tthis.#rubricBytes = new Uint8Array(options.rubric)\n\t\tthis.#rubricDigest = hashStudyBytes(this.#rubricBytes)\n\t\tthis.#rubric = parseStudyRubric(decodeStudyJSON(this.#rubricBytes))\n\t\tthis.#labelsBytes = options.labels === undefined ? undefined : new Uint8Array(options.labels)\n\t\tthis.#labelsDigest =\n\t\t\tthis.#labelsBytes === undefined ? undefined : hashStudyBytes(this.#labelsBytes)\n\t\tthis.#labels =\n\t\t\tthis.#labelsBytes === undefined\n\t\t\t\t? undefined\n\t\t\t\t: parseStudyLabeling(decodeStudyJSON(this.#labelsBytes))\n\t\tif (\n\t\t\toptions.packet !== undefined &&\n\t\t\t(options.packet.content.byteLength > STUDY_CUSTODY_BYTES ||\n\t\t\t\toptions.packet.mapping.byteLength > STUDY_CUSTODY_BYTES)\n\t\t)\n\t\t\tthrow new StudyError('CAPACITY', 'Packet exceeds the grading metadata allowance')\n\t\tthis.#packet =\n\t\t\toptions.packet === undefined\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tcontent: new Uint8Array(options.packet.content),\n\t\t\t\t\t\tmapping: new Uint8Array(options.packet.mapping),\n\t\t\t\t\t}\n\t}\n\n\t/**\n\t * Retains a deterministic grading version or verifies identical existing bytes.\n\t * @param grading - The complete evidence-backed judgments and artifact bindings\n\t * @returns The exact grading-byte SHA-256 identity\n\t * @throws StudyError - Thrown when coverage, bindings, or existing bytes are invalid\n\t */\n\twrite(grading: StudyGrading): Promise<string> {\n\t\ttry {\n\t\t\tconst snapshot = parseStudyGrading(grading)\n\t\t\tconst bytes = encodeStudyJSON(snapshot)\n\t\t\tif (bytes.byteLength > STUDY_CUSTODY_BYTES)\n\t\t\t\tthrow new StudyError('CAPACITY', 'Grading exceeds the metadata allowance')\n\t\t\tconst previous = Promise.allSettled([...this.#writes])\n\t\t\tconst operation = previous.then(() => this.#write(snapshot, bytes))\n\t\t\tthis.#writes.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#writes.delete(operation),\n\t\t\t\t() => this.#writes.delete(operation),\n\t\t\t)\n\t\t\treturn operation\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error)\n\t\t}\n\t}\n\n\t/**\n\t * Reads an immutable grading version and verifies every bound artifact byte.\n\t * @param id - The grading-byte SHA-256 identity\n\t * @returns The verified grading, or undefined when the version does not exist\n\t * @throws StudyError - Thrown when an existing version is partial or tampered\n\t */\n\tasync read(id: string): Promise<StudyGrading | undefined> {\n\t\tif (!isStudyDigest(id)) throw new StudyError('EVIDENCE', 'Invalid grading identity')\n\t\tconst result = await this.#verifyResult()\n\t\tconst directory = join(result.directory, 'grades', id)\n\t\ttry {\n\t\t\tawait lstat(directory)\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && 'code' in error && error.code === 'ENOENT') return undefined\n\t\t\tthrow error\n\t\t}\n\t\tawait checkStudyDirectory(directory)\n\t\tconst bytes = await readStudyBytes(join(directory, 'grading.json'), STUDY_CUSTODY_BYTES)\n\t\tif (hashStudyBytes(bytes) !== id)\n\t\t\tthrow new StudyError('CUSTODY', 'Grading identity differs from its exact bytes')\n\t\tconst grading = parseStudyGrading(decodeStudyJSON(bytes))\n\t\tconst expected = [\n\t\t\t'grading.json',\n\t\t\t`${grading.rubric}.rubric.json`,\n\t\t\t...(grading.labels === undefined ? [] : [`${grading.labels}.labels.json`]),\n\t\t\t...(grading.packet === undefined\n\t\t\t\t? []\n\t\t\t\t: [`${grading.packet}.packet.json`, `${grading.packet}.mapping.json`]),\n\t\t]\n\t\tconst entries = await readdir(directory, { withFileTypes: true })\n\t\tif (\n\t\t\tentries.length !== expected.length ||\n\t\t\tentries.some(\n\t\t\t\t(entry) => !entry.isFile() || entry.isSymbolicLink() || !expected.includes(entry.name),\n\t\t\t)\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Grading inventory differs from its bound artifacts')\n\t\tconst rubricBytes = await readStudyBytes(\n\t\t\tjoin(directory, `${grading.rubric}.rubric.json`),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tif (hashStudyBytes(rubricBytes) !== grading.rubric)\n\t\t\tthrow new StudyError('CUSTODY', 'Rubric bytes differ from the grading identity')\n\t\tconst rubric = parseStudyRubric(decodeStudyJSON(rubricBytes))\n\t\tconst labels =\n\t\t\tgrading.labels === undefined ? undefined : await this.#retrieve(directory, grading.labels)\n\t\tconst packet: StudyPacketBundle | undefined =\n\t\t\tgrading.packet === undefined\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tcontent: await readStudyBytes(\n\t\t\t\t\t\t\tjoin(directory, `${grading.packet}.packet.json`),\n\t\t\t\t\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tmapping: await readStudyBytes(\n\t\t\t\t\t\t\tjoin(directory, `${grading.packet}.mapping.json`),\n\t\t\t\t\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\tthis.#validate(grading, result, rubric, labels, packet)\n\t\tawait this.#verifyResult()\n\t\treturn grading\n\t}\n\n\tasync #retrieve(directory: string, digest: string): Promise<StudyLabeling> {\n\t\tconst bytes = await readStudyBytes(\n\t\t\tjoin(directory, `${digest}.labels.json`),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tif (hashStudyBytes(bytes) !== digest)\n\t\t\tthrow new StudyError('CUSTODY', 'Labels bytes differ from the grading identity')\n\t\treturn parseStudyLabeling(decodeStudyJSON(bytes))\n\t}\n\n\tasync #write(grading: StudyGrading, bytes: Uint8Array): Promise<string> {\n\t\tconst result = await this.#verifyResult()\n\t\tif (grading.rubric !== this.#rubricDigest || grading.labels !== this.#labelsDigest)\n\t\t\tthrow new StudyError('EVIDENCE', 'Grading does not bind the imported artifact bytes')\n\t\tthis.#validate(grading, result, this.#rubric, this.#labels, this.#packet)\n\t\tconst id = hashStudyBytes(bytes)\n\t\tconst root = join(result.directory, 'grades')\n\t\ttry {\n\t\t\tawait mkdir(root)\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof Error && 'code' in error && error.code === 'EEXIST')) throw error\n\t\t}\n\t\tawait checkStudyDirectory(root)\n\t\tconst directory = join(root, id)\n\t\ttry {\n\t\t\tawait mkdir(directory)\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof Error && 'code' in error && error.code === 'EEXIST')) throw error\n\t\t\tconst existing = await this.read(id)\n\t\t\tif (\n\t\t\t\texisting === undefined ||\n\t\t\t\tcanonicalStringify(existing) !== canonicalStringify(grading) ||\n\t\t\t\thashStudyBytes(\n\t\t\t\t\tawait readStudyBytes(join(directory, 'grading.json'), STUDY_CUSTODY_BYTES),\n\t\t\t\t) !== id\n\t\t\t)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Existing grading version is incompatible')\n\t\t\treturn id\n\t\t}\n\t\tawait writeStudyBytes(join(directory, `${this.#rubricDigest}.rubric.json`), this.#rubricBytes)\n\t\tif (this.#packet !== undefined && grading.packet !== undefined) {\n\t\t\tawait writeStudyBytes(join(directory, `${grading.packet}.packet.json`), this.#packet.content)\n\t\t\tawait writeStudyBytes(join(directory, `${grading.packet}.mapping.json`), this.#packet.mapping)\n\t\t}\n\t\tif (this.#labelsBytes !== undefined && this.#labelsDigest !== undefined)\n\t\t\tawait writeStudyBytes(join(directory, `${this.#labelsDigest}.labels.json`), this.#labelsBytes)\n\t\tawait writeStudyBytes(join(directory, 'grading.json'), bytes)\n\t\tawait this.read(id)\n\t\treturn id\n\t}\n\n\tasync #verifyResult(): Promise<StudySealedResult> {\n\t\tconst result = await readStudyResult(this.#directory)\n\t\tif (result.status !== 'sealed' || result.seal.id !== this.#seal)\n\t\t\tthrow new StudyError('CUSTODY', 'Execution no longer matches the verified seal')\n\t\treturn result\n\t}\n\n\t#validate(\n\t\tgrading: StudyGrading,\n\t\tresult: StudySealedResult,\n\t\trubric: StudyRubric,\n\t\tlabels: StudyLabeling | undefined,\n\t\tpacket: StudyPacketBundle | undefined,\n\t): void {\n\t\tif (grading.result !== result.seal.id)\n\t\t\tthrow new StudyError('EVIDENCE', 'Grading binds a different execution seal')\n\t\tcomputeStudyScores(result.manifest, rubric, grading)\n\t\tif (grading.packet !== (packet === undefined ? undefined : computeStudyPacketDigest(packet)))\n\t\t\tthrow new StudyError('CUSTODY', 'Grading packet bytes do not match their bundle identity')\n\t\tif (packet !== undefined) {\n\t\t\tconst expected = buildStudyPacket(result, rubric, grading.rubric)\n\t\t\tif (\n\t\t\t\texpected === undefined ||\n\t\t\t\thashStudyBytes(expected.content) !== hashStudyBytes(packet.content) ||\n\t\t\t\thashStudyBytes(expected.mapping) !== hashStudyBytes(packet.mapping)\n\t\t\t)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Grading packet differs from the sealed semantic horizon')\n\t\t}\n\t\tif (labels !== undefined && packet === undefined)\n\t\t\tthrow new StudyError('EVIDENCE', 'Imported labels require a retained semantic packet')\n\t\tconst translated =\n\t\t\tlabels === undefined\n\t\t\t\t? []\n\t\t\t\t: translateStudyPacketLabeling(result, rubric, grading.rubric, labels)\n\t\tfor (const trial of result.manifest.schedule) {\n\t\t\tfor (const criterion of rubric.criteria) {\n\t\t\t\tif (criterion.scenario !== trial.scenario) continue\n\t\t\t\tconst judgment = grading.judgments.find(\n\t\t\t\t\t(entry) => entry.trial === trial.id && entry.criterion === criterion.id,\n\t\t\t\t)\n\t\t\t\tif (judgment === undefined)\n\t\t\t\t\tthrow new StudyError('EVIDENCE', 'Grading must record every scheduled criterion judgment')\n\t\t\t\tif (\n\t\t\t\t\tcriterion.method === 'semantic' &&\n\t\t\t\t\tjudgment.verdict !== 'unknown' &&\n\t\t\t\t\t!translated.some((entry) => canonicalStringify(entry) === canonicalStringify(judgment))\n\t\t\t\t)\n\t\t\t\t\tthrow new StudyError('EVIDENCE', 'Semantic verdict has no bound imported label')\n\t\t\t}\n\t\t}\n\t\tfor (const judgment of translated) {\n\t\t\tif (\n\t\t\t\t!grading.judgments.some(\n\t\t\t\t\t(entry) => canonicalStringify(entry) === canonicalStringify(judgment),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new StudyError(\n\t\t\t\t\t'EVIDENCE',\n\t\t\t\t\t'Imported label is absent or differs from its recorded judgment',\n\t\t\t\t)\n\t\t}\n\t}\n}\n","import type { StudyEvidence } from '../../core/types.js'\nimport type { StudyCustodySinkInterface, StudyEvidenceSinkOptions } from './types.js'\nimport { StudyError } from '../../core/errors.js'\nimport { encodeStudyJSON } from '../helpers.js'\nimport { isStudyCustodyEvidence } from './validators.js'\n\n/** Retains admitted evidence in order and closes admission before terminal records. */\nexport class StudyEvidenceSink implements StudyCustodySinkInterface {\n\treadonly #options: StudyEvidenceSinkOptions\n\treadonly #goals = new Map<string, number>()\n\t// The admitted writes not yet settled; a write joins when admitted and leaves when it settles, and each waits for every earlier one.\n\treadonly #writes = new Set<Promise<void>>()\n\t#bytes = 0\n\t// Wraps the first failed write so every later append and the close refuse with that failure.\n\t#fault: { readonly error: unknown } | undefined\n\t#closing: Promise<void> | undefined\n\n\t/**\n\t * Owns the descriptor selection and constraints while retaining the live file and budget.\n\t * @param options - The owned descriptor, goal names, and byte admission bounds\n\t */\n\tconstructor(options: StudyEvidenceSinkOptions) {\n\t\tthis.#options = { ...options, goals: [...options.goals] }\n\t}\n\n\t/**\n\t * Admits exact encoded bytes before queuing an append in call order.\n\t * @param evidence - The validated domain record\n\t * @returns Nothing after the admitted append completes\n\t * @throws StudyError - Thrown when admission is closed or a byte limit is exceeded\n\t */\n\tappend(evidence: StudyEvidence): Promise<void> {\n\t\ttry {\n\t\t\tif (this.#closing !== undefined)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Evidence admission is closed')\n\t\t\tif (!isStudyCustodyEvidence(evidence) || !this.#options.goals.includes(evidence.goal))\n\t\t\t\tthrow new StudyError('EVIDENCE', 'Evidence refers to an undeclared goal')\n\t\t\tconst bytes = encodeStudyJSON(evidence)\n\t\t\tconst used = (this.#goals.get(evidence.goal) ?? 0) + bytes.byteLength\n\t\t\tconst trial = this.#bytes + bytes.byteLength\n\t\t\tif (used > this.#options.goal || trial > this.#options.trial) {\n\t\t\t\tconst message = 'Encoded evidence exceeds its allowance'\n\t\t\t\tthrow new StudyError('CAPACITY', message, {\n\t\t\t\t\tcause: 'capacity',\n\t\t\t\t\tmessage,\n\t\t\t\t\trole: undefined,\n\t\t\t\t\tstop:\n\t\t\t\t\t\tused > this.#options.goal\n\t\t\t\t\t\t\t? { layer: 'custody', id: 'Goal evidence', max: this.#options.goal, consumed: used }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tlayer: 'custody',\n\t\t\t\t\t\t\t\t\tid: 'Trial evidence',\n\t\t\t\t\t\t\t\t\tmax: this.#options.trial,\n\t\t\t\t\t\t\t\t\tconsumed: trial,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\tthis.#options.budget.reserve(bytes.byteLength)\n\t\t\tthis.#goals.set(evidence.goal, used)\n\t\t\tthis.#bytes += bytes.byteLength\n\t\t\tconst previous = Promise.allSettled([...this.#writes])\n\t\t\tconst write = previous.then(() => this.#write(bytes))\n\t\t\tthis.#writes.add(write)\n\t\t\tvoid write.then(\n\t\t\t\t() => this.#writes.delete(write),\n\t\t\t\t() => this.#writes.delete(write),\n\t\t\t)\n\t\t\treturn write\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error)\n\t\t}\n\t}\n\n\t/**\n\t * Closes admission immediately and synchronizes all previously admitted writes.\n\t * @returns Nothing when the evidence descriptor has closed\n\t */\n\tclose(): Promise<void> {\n\t\tthis.#closing ??= Promise.allSettled([...this.#writes])\n\t\t\t.then(async () => {\n\t\t\t\tif (this.#fault !== undefined) throw this.#fault.error\n\t\t\t\tawait this.#options.file.sync()\n\t\t\t})\n\t\t\t.finally(async () => {\n\t\t\t\tawait this.#options.file.close()\n\t\t\t})\n\t\treturn this.#closing\n\t}\n\n\t// Writes after every earlier write settled, and refuses once any earlier write failed.\n\tasync #write(bytes: Uint8Array): Promise<void> {\n\t\tif (this.#fault !== undefined) throw this.#fault.error\n\t\ttry {\n\t\t\tawait this.#options.file.writeFile(bytes)\n\t\t} catch (error) {\n\t\t\tthis.#fault ??= { error }\n\t\t\tthrow error\n\t\t}\n\t}\n}\n","import type {\n\tStudyAttempt,\n\tStudyManifest,\n\tStudySinkInterface,\n\tStudyTrial,\n} from '../../core/types.js'\nimport type {\n\tStudyCustodyPhase,\n\tStudyResultStoreOptions,\n\tStudyResultStoreInterface,\n\tStudySeal,\n\tStudyTrialCustody,\n} from './types.js'\nimport { canonicalStringify } from '@orkestrel/contract'\nimport { mkdir, open } from 'node:fs/promises'\nimport { dirname, join, resolve } from 'node:path'\nimport { StudyError } from '../../core/errors.js'\nimport { decodeStudyJSON, encodeStudyJSON } from '../helpers.js'\nimport { STUDY_CUSTODY_BYTES } from './constants.js'\nimport {\n\tcheckStudyDirectory,\n\tcomputeStudySealId,\n\treadStudyBytes,\n\treadStudyResult,\n\tscanStudyExecution,\n\tvalidateStudyEvidenceBytes,\n\twriteStudyBytes,\n} from './helpers.js'\nimport { StudyEvidenceSink } from './StudyEvidenceSink.js'\nimport { isStudyCustodyAttempt, isStudyCustodyManifest, isStudyCustodyTrial } from './validators.js'\n\n/** Owns append-only execution bytes and seals only a complete terminal population. */\nexport class StudyResultStore implements StudyResultStoreInterface {\n\treadonly #directory: string\n\treadonly #manifest: StudyManifest\n\treadonly #trials = new Map<string, StudyTrialCustody>()\n\treadonly #starting = new Set<string>()\n\t#phase: StudyCustodyPhase = 'new'\n\t#bytes = 0\n\n\t/**\n\t * Owns a validated manifest snapshot without creating any files.\n\t * @param options - The new result directory and execution declaration\n\t * @throws StudyError - Thrown when the manifest is invalid\n\t */\n\tconstructor(options: StudyResultStoreOptions) {\n\t\tif (!isStudyCustodyManifest(options.manifest))\n\t\t\tthrow new StudyError('CONFIG', 'Invalid execution manifest')\n\t\tconst snapshot = decodeStudyJSON(encodeStudyJSON(options.manifest))\n\t\tif (!isStudyCustodyManifest(snapshot))\n\t\t\tthrow new StudyError('CONFIG', 'Invalid manifest snapshot')\n\t\tthis.#manifest = snapshot\n\t\tthis.#directory = resolve(options.directory)\n\t}\n\n\t/**\n\t * Exclusively creates the result directory and initial manifest bytes.\n\t * @returns Nothing after the manifest is synchronized\n\t * @throws StudyError - Thrown when creation repeats or custody bounds are exceeded\n\t */\n\tasync create(): Promise<void> {\n\t\tif (this.#phase !== 'new') throw new StudyError('CUSTODY', 'Result creation has already begun')\n\t\tthis.#phase = 'creating'\n\t\ttry {\n\t\t\tconst bytes = encodeStudyJSON(this.#manifest)\n\t\t\tif (bytes.byteLength > STUDY_CUSTODY_BYTES)\n\t\t\t\tthrow new StudyError('CAPACITY', 'Manifest exceeds the metadata allowance')\n\t\t\tthis.#reserve(bytes.byteLength)\n\t\t\tawait checkStudyDirectory(dirname(this.#directory))\n\t\t\tawait mkdir(this.#directory)\n\t\t\tawait mkdir(join(this.#directory, 'execution'))\n\t\t\tawait mkdir(join(this.#directory, 'execution', 'trials'))\n\t\t\tawait writeStudyBytes(join(this.#directory, 'execution', 'manifest.json'), bytes)\n\t\t\tthis.#phase = 'ready'\n\t\t} catch (error) {\n\t\t\tthis.#phase = 'failed'\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t/**\n\t * Exclusively creates the evidence sink for an exact scheduled trial.\n\t * @param trial - The scheduled trajectory\n\t * @returns The bounded append-only sink\n\t * @throws StudyError - Thrown when the trial is foreign, repeated, or late\n\t */\n\tasync start(trial: StudyTrial): Promise<StudySinkInterface> {\n\t\tif (\n\t\t\tthis.#phase !== 'ready' ||\n\t\t\t!isStudyCustodyTrial(trial) ||\n\t\t\tthis.#trials.has(trial.id) ||\n\t\t\tthis.#starting.has(trial.id)\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Trial cannot start in the current state')\n\t\tconst scheduled = this.#manifest.schedule.find((entry) => entry.id === trial.id)\n\t\tconst scenario = this.#manifest.scenarios.find((entry) => entry.id === trial.scenario)\n\t\tif (\n\t\t\tscheduled === undefined ||\n\t\t\tscenario === undefined ||\n\t\t\tcanonicalStringify(scheduled) !== canonicalStringify(trial)\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Trial differs from the execution schedule')\n\t\tthis.#starting.add(scheduled.id)\n\t\ttry {\n\t\t\tconst directory = join(this.#directory, 'execution', 'trials', scheduled.id)\n\t\t\tawait checkStudyDirectory(dirname(directory))\n\t\t\tawait mkdir(directory)\n\t\t\tconst file = await open(join(directory, 'evidence.jsonl'), 'wx')\n\t\t\tconst sink = new StudyEvidenceSink({\n\t\t\t\tfile,\n\t\t\t\tgoals: scenario.goals.map((goal) => goal.id),\n\t\t\t\tgoal: this.#manifest.bounds.goal.bytes,\n\t\t\t\ttrial: this.#manifest.bounds.trial.bytes,\n\t\t\t\tbudget: { reserve: (bytes) => this.#reserve(bytes) },\n\t\t\t})\n\t\t\tthis.#trials.set(scheduled.id, { sink, terminal: undefined })\n\t\t\treturn sink\n\t\t} catch (error) {\n\t\t\tthis.#phase = 'failed'\n\t\t\tthrow error\n\t\t} finally {\n\t\t\tthis.#starting.delete(scheduled.id)\n\t\t}\n\t}\n\n\t/**\n\t * Closes evidence admission, drains admitted appends, and writes a terminal record.\n\t * @param attempt - The complete scheduled goal horizon\n\t * @returns Nothing after the terminal record is synchronized\n\t * @throws StudyError - Thrown when the terminal record is invalid, repeated, or late\n\t */\n\tfinish(attempt: StudyAttempt): Promise<void> {\n\t\ttry {\n\t\t\tif (this.#phase !== 'ready' || !isStudyCustodyAttempt(attempt, this.#manifest))\n\t\t\t\tthrow new StudyError('CUSTODY', 'Attempt differs from the declared horizon')\n\t\t\tconst custody = this.#trials.get(attempt.trial.id)\n\t\t\tif (custody === undefined || custody.terminal !== undefined)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Trial is unknown or already terminal')\n\t\t\tconst bytes = encodeStudyJSON(attempt)\n\t\t\tif (bytes.byteLength > STUDY_CUSTODY_BYTES)\n\t\t\t\tthrow new StudyError('CAPACITY', 'Attempt exceeds the metadata allowance')\n\t\t\tconst drained = custody.sink.close()\n\t\t\tconst terminal = this.#finish(attempt.trial.id, bytes, drained)\n\t\t\tthis.#trials.set(attempt.trial.id, { ...custody, terminal })\n\t\t\treturn terminal\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error)\n\t\t}\n\t}\n\n\t/**\n\t * Seals exact execution inventory after every scheduled trial has terminated.\n\t * @returns The immutable deterministic execution seal\n\t * @throws StudyError - Thrown when custody is incomplete, invalid, or already sealed\n\t */\n\tasync seal(): Promise<StudySeal> {\n\t\tif (\n\t\t\tthis.#phase !== 'ready' ||\n\t\t\tthis.#starting.size !== 0 ||\n\t\t\tthis.#trials.size !== this.#manifest.schedule.length ||\n\t\t\t[...this.#trials.values()].some((trial) => trial.terminal === undefined)\n\t\t)\n\t\t\tthrow new StudyError('CUSTODY', 'Execution is not terminally accounted')\n\t\tthis.#phase = 'sealing'\n\t\ttry {\n\t\t\tawait Promise.all([...this.#trials.values()].map((trial) => trial.terminal))\n\t\t\tconst reading = await readStudyResult(this.#directory)\n\t\t\tif (\n\t\t\t\treading.status !== 'interrupted' ||\n\t\t\t\treading.manifest === undefined ||\n\t\t\t\treading.attempts.length !== this.#manifest.schedule.length ||\n\t\t\t\tcanonicalStringify(reading.manifest) !== canonicalStringify(this.#manifest)\n\t\t\t)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Execution changed before sealing')\n\t\t\tconst files = await scanStudyExecution(join(this.#directory, 'execution'), this.#manifest)\n\t\t\tif (files.length !== 1 + this.#manifest.schedule.length * 2)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Execution inventory is incomplete')\n\t\t\tfor (const trial of this.#manifest.schedule) {\n\t\t\t\tvalidateStudyEvidenceBytes(\n\t\t\t\t\tawait readStudyBytes(\n\t\t\t\t\t\tjoin(this.#directory, 'execution', 'trials', trial.id, 'evidence.jsonl'),\n\t\t\t\t\t\tthis.#manifest.bounds.trial.bytes,\n\t\t\t\t\t),\n\t\t\t\t\tthis.#manifest,\n\t\t\t\t\ttrial.id,\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst seal: StudySeal = Object.freeze({\n\t\t\t\tresult: this.#manifest.id,\n\t\t\t\tid: computeStudySealId(this.#manifest.id, files),\n\t\t\t\tfiles,\n\t\t\t})\n\t\t\tconst bytes = encodeStudyJSON(seal)\n\t\t\tif (bytes.byteLength > STUDY_CUSTODY_BYTES)\n\t\t\t\tthrow new StudyError('CAPACITY', 'Seal exceeds the metadata allowance')\n\t\t\tif (\n\t\t\t\tfiles.reduce((total, file) => total + file.bytes, bytes.byteLength) >\n\t\t\t\tthis.#manifest.bounds.series.bytes\n\t\t\t)\n\t\t\t\tthrow new StudyError('CAPACITY', 'Seal and execution exceed the series allowance')\n\t\t\tthis.#reserve(bytes.byteLength)\n\t\t\tawait writeStudyBytes(join(this.#directory, 'seal.json'), bytes)\n\t\t\tconst verified = await readStudyResult(this.#directory)\n\t\t\tif (verified.status !== 'sealed' || verified.seal.id !== seal.id)\n\t\t\t\tthrow new StudyError('CUSTODY', 'Execution changed while sealing')\n\t\t\tthis.#phase = 'sealed'\n\t\t\treturn seal\n\t\t} catch (error) {\n\t\t\tthis.#phase = 'failed'\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t#reserve(bytes: number): void {\n\t\tif (this.#bytes + bytes > this.#manifest.bounds.series.bytes)\n\t\t\tthrow new StudyError('CAPACITY', 'Execution bytes exceed the series allowance')\n\t\tthis.#bytes += bytes\n\t}\n\n\tasync #finish(trial: string, bytes: Uint8Array, drained: Promise<void>): Promise<void> {\n\t\ttry {\n\t\t\tawait drained\n\t\t\tthis.#reserve(bytes.byteLength)\n\t\t\tawait writeStudyBytes(\n\t\t\t\tjoin(this.#directory, 'execution', 'trials', trial, 'attempt.json'),\n\t\t\t\tbytes,\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tthis.#phase = 'failed'\n\t\t\tthrow error\n\t\t}\n\t}\n}\n","import type { ChildProcess } from 'node:child_process'\nimport type { StudyTaskOptions, StudyTaskResult } from './types.js'\nimport { isJSONValue, isRecord } from '@orkestrel/contract'\nimport { fork } from 'node:child_process'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyDigest } from '../../core/validators.js'\nimport { STUDY_FRAME_BYTES, STUDY_LOG_BYTES, STUDY_TASK_OPERATION } from './constants.js'\nimport { drainStudyChild, terminateStudyChild } from './helpers.js'\n\n/** Supervises one forked adapter child until it closes with one verified response. */\nexport class StudyTaskChild {\n\treadonly #options: StudyTaskOptions\n\treadonly #duration: number\n\treadonly #signal: AbortSignal\n\t#failure: unknown\n\t#result: StudyTaskResult | undefined\n\t#logs = 0\n\t#executed = false\n\n\t/** Binds one adapter evaluation to its owned route, validated deadline and caller cancellation.\n\t * @param options - The owning task's snapshotted entry, root and selection.\n\t * @param duration - The validated deadline in milliseconds.\n\t * @param signal - Caller cancellation.\n\t */\n\tconstructor(options: StudyTaskOptions, duration: number, signal: AbortSignal) {\n\t\tthis.#options = options\n\t\tthis.#duration = duration\n\t\tthis.#signal = signal\n\t}\n\n\t/** Forks the adapter child, sends one request frame and settles with its single verified response.\n\t * @param input - The validated request frame.\n\t * @returns The verified adapter output and instrumentation identity.\n\t * @throws StudyError - Thrown with code `CONFIG` when this child is already supervised.\n\t */\n\texecute(input: Readonly<Record<string, unknown>>): Promise<StudyTaskResult> {\n\t\tif (this.#executed) throw new StudyError('CONFIG', 'Study task child can execute only once')\n\t\tthis.#executed = true\n\t\tconst signal = this.#signal\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = fork(this.#options.entry, [STUDY_TASK_OPERATION], {\n\t\t\t\tcwd: this.#options.root,\n\t\t\t\texecArgv: [...process.execArgv],\n\t\t\t\tsilent: true,\n\t\t\t\twindowsHide: true,\n\t\t\t\tdetached: process.platform !== 'win32',\n\t\t\t\tserialization: 'json',\n\t\t\t})\n\t\t\tdrainStudyChild(child)\n\t\t\tconst listeners = new AbortController()\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.#failure = new StudyError('FAULT', 'Adapter deadline exceeded', {\n\t\t\t\t\tcause: 'deadline',\n\t\t\t\t\tmessage: 'Adapter deadline exceeded',\n\t\t\t\t\trole: undefined,\n\t\t\t\t\tstop: {\n\t\t\t\t\t\tlayer: 'scope',\n\t\t\t\t\t\tid: 'Adapter duration',\n\t\t\t\t\t\tmax: this.#duration,\n\t\t\t\t\t\tconsumed: undefined,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tthis.#terminate(child)\n\t\t\t}, this.#duration)\n\t\t\tsignal.addEventListener(\n\t\t\t\t'abort',\n\t\t\t\t() => {\n\t\t\t\t\tthis.#failure = signal.reason\n\t\t\t\t\tthis.#terminate(child)\n\t\t\t\t},\n\t\t\t\t{ once: true, signal: listeners.signal },\n\t\t\t)\n\t\t\tchild.on('message', (value: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#result !== undefined ||\n\t\t\t\t\t\t!isRecord(value) ||\n\t\t\t\t\t\tBuffer.byteLength(JSON.stringify(value)) > STUDY_FRAME_BYTES\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new StudyError('FAULT', 'Adapter response is oversized or repeated')\n\t\t\t\t\tif (typeof value.error === 'string')\n\t\t\t\t\t\tthrow new StudyError(value.code === 'CONFIG' ? 'CONFIG' : 'FAULT', value.error)\n\t\t\t\t\tif (!isStudyDigest(value.instrument) || !isJSONValue(value.value))\n\t\t\t\t\t\tthrow new StudyError('FAULT', 'Adapter response is malformed')\n\t\t\t\t\tthis.#result = { instrument: value.instrument, value: value.value }\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.#failure = error\n\t\t\t\t}\n\t\t\t\tthis.#terminate(child)\n\t\t\t})\n\t\t\tfor (const stream of [child.stdout, child.stderr])\n\t\t\t\tstream?.on('data', (chunk: Buffer) => {\n\t\t\t\t\tthis.#logs += chunk.byteLength\n\t\t\t\t\tif (this.#logs <= STUDY_LOG_BYTES) return\n\t\t\t\t\tthis.#failure = new StudyError('FAULT', 'Adapter output exceeds the log allowance')\n\t\t\t\t\tthis.#terminate(child)\n\t\t\t\t})\n\t\t\tchild.once('error', (error) => {\n\t\t\t\tthis.#failure = error\n\t\t\t})\n\t\t\tchild.once('close', () => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tlisteners.abort()\n\t\t\t\tconst result = this.#result\n\t\t\t\tif (this.#failure !== undefined) reject(this.#failure)\n\t\t\t\telse if (result === undefined)\n\t\t\t\t\treject(new StudyError('FAULT', 'Adapter exited without a complete response'))\n\t\t\t\telse resolve(result)\n\t\t\t})\n\t\t\tchild.send(input, (error: Error | null) => {\n\t\t\t\tif (error === null) return\n\t\t\t\tthis.#failure = error\n\t\t\t\tthis.#terminate(child)\n\t\t\t})\n\t\t\tif (signal.aborted) {\n\t\t\t\tthis.#failure = signal.reason\n\t\t\t\tthis.#terminate(child)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Terminates the child tree; a termination failure replaces the failure that requested it.\n\t#terminate(child: ChildProcess): void {\n\t\ttry {\n\t\t\tterminateStudyChild(child)\n\t\t} catch (error) {\n\t\t\tthis.#failure = error\n\t\t}\n\t}\n}\n","import type { StudyTaskOptions, StudyTaskRequest, StudyTaskResult } from './types.js'\nimport { isRecord } from '@orkestrel/contract'\nimport { StudyError } from '../../core/errors.js'\nimport { STUDY_FRAME_BYTES, STUDY_TASK_DURATION } from './constants.js'\nimport { valueToWire } from './helpers.js'\nimport { StudyTaskChild } from './StudyTaskChild.js'\n\n/** Bounds adapter evaluation by an independent native parent timer. */\nexport class StudyTask {\n\t#options: StudyTaskOptions\n\t/** Owns the built child route and captured source selection.\n\t * @param options - Consumer root, runtime entry, adapter, and admitted dependencies.\n\t */\n\tconstructor(options: StudyTaskOptions) {\n\t\tthis.#options = structuredClone(options)\n\t}\n\t/** Executes one validation or grading operation in a fresh child.\n\t * @param request - Declarations or retained evidence, never a trial payload.\n\t * @param signal - Caller cancellation.\n\t * @returns Verified adapter output and active instrumentation identity.\n\t */\n\texecute(request: StudyTaskRequest, signal: AbortSignal): Promise<StudyTaskResult> {\n\t\tsignal.throwIfAborted()\n\t\tconst duration = this.#options.duration ?? STUDY_TASK_DURATION\n\t\tif (!Number.isSafeInteger(duration) || duration <= 0 || duration > STUDY_TASK_DURATION)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter deadline must be finite and at most 60 seconds')\n\t\tconst input = valueToWire({ ...this.#options, ...request })\n\t\tif (!isRecord(input)) throw new StudyError('CONFIG', 'Adapter input must be an object')\n\t\tif (Buffer.byteLength(JSON.stringify(input)) > STUDY_FRAME_BYTES)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter input exceeds the frame allowance')\n\t\t// Each call supervises its own child, so concurrent calls never share event state.\n\t\treturn new StudyTaskChild(this.#options, duration, signal).execute(input)\n\t}\n}\n","/** Caps declared execution duration at the native supervisor's host ceiling. */\nexport const STUDY_COMMAND_DURATION = 86400000\n\n/** Names the trusted command's independent offline predicate. */\nexport const STUDY_COMMAND_GRADER = 'consumer-adapter'\n\n/** Defines the complete public CLI reference shared by help and grammar diagnostics. */\nexport const STUDY_COMMAND_HELP = `study check <study> [--profile <name>]\nstudy execute <study> [--profile <name>] [--out <path>] [--expected <sha256>]\nstudy grade <result> --rubric <path>\nstudy label <result> --grading <sha256> --labels <path>\nstudy report <result> --grading <sha256>\nstudy --help\n\nProfiles default to local. Flags require values and may appear only once.\nResults default to tmp/studies/<result>; scratch also uses tmp/studies.\nA result is its id under tmp/studies, a root-relative path, or an absolute path.\nRelative paths, including --out, must stay inside the consumer working directory.\nOutput directories must be new; existing results are never overwritten.\n--expected pins the fingerprint returned by check. --grading selects an exact grading.\n--rubric selects independent criteria. --labels imports caller-supplied semantic labels.\nSuccess writes one JSON document; next contains suggested argv, never executed automatically.\ncheck, grade, label and report have a fixed allowance of 60 seconds.\nexecute checks first, then uses the declared series duration plus 15 seconds for cleanup.\nExit codes: 0 success, 64 invalid input, 124 deadline, 130 interruption, 1 operational failure.\n`\n","import type {\n\tStudyAttempt,\n\tStudyBounds,\n\tStudyDefinition,\n\tStudyEvidence,\n\tStudyGrading,\n\tStudyIdentity,\n\tStudyObservation,\n\tStudyProfile,\n\tStudyRubric,\n} from '../../core/types.js'\nimport type { StudyAttributionSource, StudyCommandArtifact } from './types.js'\nimport type { StudySealedResult } from '../stores/types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport { parseJSON } from '@orkestrel/contract'\nimport { isAbsolute, join, resolve } from 'node:path'\nimport { STUDY_CAUSES, STUDY_LAYERS, STUDY_ROLES } from '../../core/constants.js'\nimport { StudyError } from '../../core/errors.js'\nimport { computeStudyScores, studyStopToJSON } from '../../core/helpers.js'\nimport { containsArtifact, encodeStudyJSON, hashStudyBytes } from '../helpers.js'\nimport { readStudyBytes } from '../stores/helpers.js'\nimport { isStudyCustodyEvidence } from '../stores/validators.js'\nimport { STUDY_RESERVED_NAME } from '../stores/constants.js'\n\n/**\n * Resolves a portable relative artifact path strictly inside its selected directory.\n * @param directory - The selected custody or study directory\n * @param path - The slash-separated relative artifact path\n * @returns The contained absolute host path\n * @throws StudyError - Thrown when a path is malformed, reserved, absolute, or escaping\n * @example\n * ```ts\n * resolveStudyPath(directory, 'profiles/local.json')\n * ```\n */\nexport function resolveStudyPath(directory: string, path: string): string {\n\tconst names = path.split('/')\n\tif (\n\t\tpath === '' ||\n\t\tisAbsolute(path) ||\n\t\t/[\\\\<>:\"|?*]/.test(path) ||\n\t\tArray.from(path).some(\n\t\t\t(character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127,\n\t\t) ||\n\t\tnames.some(\n\t\t\t(name) =>\n\t\t\t\tname === '' ||\n\t\t\t\tname === '.' ||\n\t\t\t\tname === '..' ||\n\t\t\t\tname.endsWith('.') ||\n\t\t\t\tname.endsWith(' ') ||\n\t\t\t\tSTUDY_RESERVED_NAME.test(name.split('.')[0] ?? ''),\n\t\t)\n\t)\n\t\tthrow new StudyError('CONFIG', 'Artifact path must be a portable contained relative path')\n\tconst absolute = resolve(directory, ...names)\n\tif (!containsArtifact(resolve(directory), absolute))\n\t\tthrow new StudyError('CONFIG', 'Artifact path escapes its selected directory')\n\treturn absolute\n}\n\n/**\n * Resolves the execution profile's caller-selected built artifact paths.\n * @param root - The repository root\n * @param profile - The validated source profile\n * @returns The reproducible resolved execution profile\n * @example\n * ```ts\n * resolveStudyProfile(root, profile)\n * ```\n */\nexport function resolveStudyProfile(root: string, profile: StudyProfile): StudyProfile {\n\treturn {\n\t\t...profile,\n\t\tqualification:\n\t\t\tprofile.qualification === undefined ? undefined : resolve(root, profile.qualification),\n\t\tagent: resolve(root, profile.agent),\n\t\tsubject: resolve(root, profile.subject),\n\t\troots: profile.roots.map((path) => resolve(root, path)),\n\t\tprovider:\n\t\t\tprofile.provider === undefined\n\t\t\t\t? undefined\n\t\t\t\t: { ...profile.provider, entry: resolve(root, profile.provider.entry) },\n\t}\n}\n\n/**\n * Computes the native supervisor's exact validated execution fingerprint.\n * @param identity - The reproducible executable identities\n * @param bounds - The validated nested execution limits\n * @param definition - The optional full declaration binding supervisor check to execute\n * @returns The fingerprint that execute must compare before any writes or child work\n * @example\n * ```ts\n * computeStudyCommandFingerprint(identity, bounds)\n * ```\n */\nexport function computeStudyCommandFingerprint(\n\tidentity: StudyIdentity,\n\tbounds: StudyBounds,\n\tdefinition?: StudyDefinition,\n): string {\n\treturn hashStudyBytes(\n\t\tencodeStudyJSON({ identity, bounds, ...(definition === undefined ? {} : { definition }) }),\n\t)\n}\n\n/**\n * Computes public fixture identity from execution policy and exact scenario bytes.\n * @param definition - The complete retained study declaration\n * @param scenarios - The exact public scenario artifact identities\n * @returns The digest shared by compatible capacity and memory executions\n * @example\n * ```ts\n * computeStudyFixtureDigest(definition, scenarios)\n * ```\n */\nexport function computeStudyFixtureDigest(\n\tdefinition: StudyDefinition,\n\tscenarios: readonly StudyCommandArtifact[],\n): string {\n\treturn hashStudyBytes(\n\t\tencodeStudyJSON({\n\t\t\tdriver: definition.driver,\n\t\t\tarms: definition.arms,\n\t\t\torder: definition.order,\n\t\t\tretries: definition.retries,\n\t\t\tscenarios,\n\t\t}),\n\t)\n}\n\n/**\n * Reads sealed evidence bytes through custody checks without loading executable code.\n * @param result - The independently verified sealed execution\n * @returns Evidence records keyed by scheduled trial identity\n * @throws StudyError - Thrown when evidence drifts, becomes partial, or fails validation\n * @example\n * ```ts\n * await collectStudyEvidence(result)\n * ```\n */\nexport async function collectStudyEvidence(\n\tresult: StudySealedResult,\n): Promise<Readonly<Record<string, readonly StudyEvidence[]>>> {\n\tconst retained: Array<readonly [string, readonly StudyEvidence[]]> = []\n\tfor (const trial of result.manifest.schedule) {\n\t\tconst path = `trials/${trial.id}/evidence.jsonl`\n\t\tconst file = result.seal.files.find((entry) => entry.path === path)\n\t\tconst bytes = await readStudyBytes(\n\t\t\tjoin(result.directory, 'execution', 'trials', trial.id, 'evidence.jsonl'),\n\t\t\tresult.manifest.bounds.trial.bytes,\n\t\t)\n\t\tif (file === undefined || hashStudyBytes(bytes) !== file.digest)\n\t\t\tthrow new StudyError('CUSTODY', 'Evidence changed after execution verification')\n\t\tconst text = new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n\t\tif (text !== '' && !text.endsWith('\\n'))\n\t\t\tthrow new StudyError('CUSTODY', 'Evidence is incomplete')\n\t\tconst rows = text\n\t\t\t.split(/\\r\\n|\\n/)\n\t\t\t.slice(0, -1)\n\t\t\t.map((line): StudyEvidence => {\n\t\t\t\tconst row = parseJSON(line)\n\t\t\t\tif (!isStudyCustodyEvidence(row)) throw new StudyError('CUSTODY', 'Evidence row is invalid')\n\t\t\t\treturn row\n\t\t\t})\n\t\tretained.push([trial.id, Object.freeze(rows)])\n\t}\n\treturn Object.freeze(Object.fromEntries(retained))\n}\n\n/**\n * Partitions records by their explicit execution fact without inferring any.\n * @param records - The attempts, observations, or attribution sources to partition\n * @returns Counts of executed and unexecuted records, which sum to the record count\n * @example\n * ```ts\n * computeStudyPartition(attempts) // { executed: 2, unexecuted: 1 }\n * ```\n */\nexport function computeStudyPartition(\n\trecords: ReadonlyArray<StudyAttempt | StudyObservation | StudyAttributionSource>,\n): Readonly<Record<'executed' | 'unexecuted', number>> {\n\treturn {\n\t\texecuted: records.filter((record) => record.executed).length,\n\t\tunexecuted: records.filter((record) => !record.executed).length,\n\t}\n}\n\n/**\n * Groups failed records by cause, role, and layer, each group carrying its source readings.\n * @remarks\n * A group exists for each cause, role, and layer that holds at least one record. Groups follow\n * `STUDY_CAUSES`, then `STUDY_ROLES` with an absent role last, then `STUDY_LAYERS` with an absent\n * layer last. `role` and `layer` are null when absent. `executed` and `unexecuted` partition the\n * group by each record's own execution fact. `readings` lists every record of the group that carries\n * a stop, in source order, with `trial`, `goal` at the goal level only, `id`, `max`, and `consumed`\n * (null when the source reported none). A failure sealed before the `stop` member existed groups with\n * a null layer and no reading; the helper infers no layer from a message.\n * @param sources - The failed records, in source order\n * @returns The JSON groups\n * @example\n * ```ts\n * computeStudyAttributions([{ trial: 'r1-s1-a1', goal: undefined, failure, executed: true }])\n * ```\n */\nexport function computeStudyAttributions(sources: readonly StudyAttributionSource[]): JSONValue {\n\treturn STUDY_CAUSES.flatMap((cause) =>\n\t\t[...STUDY_ROLES, undefined].flatMap((role) =>\n\t\t\t[...STUDY_LAYERS, undefined].flatMap((layer) => {\n\t\t\t\tconst group = sources.filter(\n\t\t\t\t\t(source) =>\n\t\t\t\t\t\tsource.failure.cause === cause &&\n\t\t\t\t\t\tsource.failure.role === role &&\n\t\t\t\t\t\tsource.failure.stop?.layer === layer,\n\t\t\t\t)\n\t\t\t\tif (group.length === 0) return []\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tcause,\n\t\t\t\t\t\trole: role ?? null,\n\t\t\t\t\t\tlayer: layer ?? null,\n\t\t\t\t\t\t...computeStudyPartition(group),\n\t\t\t\t\t\treadings: group.flatMap((source) => {\n\t\t\t\t\t\t\tconst stop = source.failure.stop\n\t\t\t\t\t\t\treturn stop === undefined\n\t\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttrial: source.trial,\n\t\t\t\t\t\t\t\t\t\t\t...(source.goal === undefined ? {} : { goal: source.goal }),\n\t\t\t\t\t\t\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\t\tObject.entries(studyStopToJSON(stop) ?? {}).filter(\n\t\t\t\t\t\t\t\t\t\t\t\t\t([key]) => key !== 'layer',\n\t\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}),\n\t\t),\n\t)\n}\n\n/**\n * Computes whole-horizon results with operational costs and repetitions kept distinct.\n * @param result - The verified complete execution\n * @param rubric - The retained compatible rubric\n * @param grading - The independently verified selected grading\n * @returns The JSON report without pooling identities or inventing absent measurements\n * @remarks\n * Operations count affected trial and goal records, not independent failure events, and the\n * trial and goal counts overlap and are never added. Completion is operational: a goal is\n * completed when it holds a non-partial product and no failure, and a trial when it holds no\n * failure and every goal completed. It is neither task success nor a qualification gate.\n * @example\n * ```ts\n * computeStudyReport(result, rubric, grading)\n * ```\n */\nexport function computeStudyReport(\n\tresult: StudySealedResult,\n\trubric: StudyRubric,\n\tgrading: StudyGrading,\n): JSONValue {\n\tconst scores = computeStudyScores(result.manifest, rubric, grading)\n\tconst observations = result.attempts.flatMap((attempt) => attempt.observations)\n\tconst usage = observations.flatMap((observation) => observation.usage)\n\tconst completed = new Set(\n\t\tobservations.filter(\n\t\t\t(observation) =>\n\t\t\t\tobservation.product !== undefined &&\n\t\t\t\t!observation.product.partial &&\n\t\t\t\tobservation.failure === undefined,\n\t\t),\n\t)\n\tconst repetitions = result.manifest.definition.order.map((order, repetition) => ({\n\t\trepetition,\n\t\torder: [...order],\n\t\tarms: result.manifest.definition.arms.map((arm) => {\n\t\t\tconst trials = new Set(\n\t\t\t\tresult.manifest.schedule\n\t\t\t\t\t.filter((trial) => trial.repetition === repetition && trial.arm === arm)\n\t\t\t\t\t.map((trial) => trial.id),\n\t\t\t)\n\t\t\tconst applicable = result.manifest.schedule\n\t\t\t\t.filter((trial) => trials.has(trial.id))\n\t\t\t\t.flatMap((trial) =>\n\t\t\t\t\trubric.criteria\n\t\t\t\t\t\t.filter((criterion) => criterion.scenario === trial.scenario)\n\t\t\t\t\t\t.map((criterion) => ({ trial: trial.id, criterion })),\n\t\t\t\t)\n\t\t\tconst judgments = applicable.map((pair) => ({\n\t\t\t\tcriterion: pair.criterion,\n\t\t\t\tjudgment: grading.judgments.find(\n\t\t\t\t\t(entry) => entry.trial === pair.trial && entry.criterion === pair.criterion.id,\n\t\t\t\t),\n\t\t\t}))\n\t\t\tconst achieved = judgments.filter((entry) => entry.judgment?.verdict === 'achieved').length\n\t\t\tconst unsuccessful = judgments.filter(\n\t\t\t\t(entry) => entry.judgment?.verdict === 'unsuccessful',\n\t\t\t).length\n\t\t\tconst unknown = applicable.length - achieved - unsuccessful\n\t\t\treturn {\n\t\t\t\tarm,\n\t\t\t\ttotal: applicable.length,\n\t\t\t\tachieved,\n\t\t\t\tunsuccessful,\n\t\t\t\tunknown,\n\t\t\t\tcritical: judgments.filter(\n\t\t\t\t\t(entry) => entry.criterion.critical && entry.judgment?.verdict === 'unsuccessful',\n\t\t\t\t).length,\n\t\t\t\tlower: achieved / applicable.length,\n\t\t\t\tupper: (achieved + unknown) / applicable.length,\n\t\t\t\tcoverage: (achieved + unsuccessful) / applicable.length,\n\t\t\t}\n\t\t}),\n\t}))\n\tconst identity = result.manifest.identity\n\treturn {\n\t\tcommand: 'report',\n\t\tresult: result.manifest.id,\n\t\tseal: result.seal.id,\n\t\tidentity: {\n\t\t\tagent: identity.agent,\n\t\t\tsubject: identity.subject,\n\t\t\tinstrument: identity.instrument,\n\t\t\tfixtures: identity.fixtures,\n\t\t\tprofile: identity.profile,\n\t\t\t...(identity.provider === undefined ? {} : { provider: identity.provider }),\n\t\t},\n\t\tpurpose: result.manifest.definition.purpose,\n\t\tpopulation: 'Complete declared trial and criterion horizon',\n\t\tuncertainty:\n\t\t\trepetitions.length === 1\n\t\t\t\t? 'One repetition is descriptive and does not establish replicated capacity or quality.'\n\t\t\t\t: 'Repetitions are retained separately; intervals represent unresolved grading, not statistical confidence.',\n\t\tscores: scores.map((score) => ({ ...score })),\n\t\trepetitions,\n\t\toperations: {\n\t\t\ttrials: {\n\t\t\t\tscheduled: result.manifest.schedule.length,\n\t\t\t\tterminal: result.attempts.length,\n\t\t\t\t...computeStudyPartition(result.attempts),\n\t\t\t\tcompleted: result.attempts.filter(\n\t\t\t\t\t(attempt) =>\n\t\t\t\t\t\tattempt.failure === undefined &&\n\t\t\t\t\t\tattempt.observations.every((observation) => completed.has(observation)),\n\t\t\t\t).length,\n\t\t\t\tfaults: STUDY_CAUSES.map((cause) => ({\n\t\t\t\t\tcause,\n\t\t\t\t\t...computeStudyPartition(\n\t\t\t\t\t\tresult.attempts.filter((attempt) => attempt.failure?.cause === cause),\n\t\t\t\t\t),\n\t\t\t\t})),\n\t\t\t\tattributions: computeStudyAttributions(\n\t\t\t\t\tresult.attempts.flatMap((attempt) =>\n\t\t\t\t\t\tattempt.failure === undefined\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttrial: attempt.trial.id,\n\t\t\t\t\t\t\t\t\t\tgoal: undefined,\n\t\t\t\t\t\t\t\t\t\tfailure: attempt.failure,\n\t\t\t\t\t\t\t\t\t\texecuted: attempt.executed,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t},\n\t\t\tgoals: {\n\t\t\t\tscheduled: observations.length,\n\t\t\t\t...computeStudyPartition(observations),\n\t\t\t\tproducts: observations.filter((observation) => observation.product !== undefined).length,\n\t\t\t\tpartial: observations.filter((observation) => observation.product?.partial === true).length,\n\t\t\t\tcompleted: observations.filter((observation) => completed.has(observation)).length,\n\t\t\t\tfaults: STUDY_CAUSES.map((cause) => ({\n\t\t\t\t\tcause,\n\t\t\t\t\t...computeStudyPartition(\n\t\t\t\t\t\tobservations.filter((observation) => observation.failure?.cause === cause),\n\t\t\t\t\t),\n\t\t\t\t})),\n\t\t\t\tattributions: computeStudyAttributions(\n\t\t\t\t\tresult.attempts.flatMap((attempt) =>\n\t\t\t\t\t\tattempt.observations.flatMap((observation) =>\n\t\t\t\t\t\t\tobservation.failure === undefined\n\t\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\ttrial: attempt.trial.id,\n\t\t\t\t\t\t\t\t\t\t\tgoal: observation.goal,\n\t\t\t\t\t\t\t\t\t\t\tfailure: observation.failure,\n\t\t\t\t\t\t\t\t\t\t\texecuted: observation.executed,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t},\n\t\t},\n\t\tcosts: {\n\t\t\tduration: result.attempts.reduce((total, attempt) => total + attempt.duration, 0),\n\t\t\troles: STUDY_ROLES.map((role) => {\n\t\t\t\tconst charges = usage.filter((entry) => entry.role === role)\n\t\t\t\treturn {\n\t\t\t\t\trole,\n\t\t\t\t\tmeasurements: charges.length,\n\t\t\t\t\tcalls: charges.reduce((total, entry) => total + entry.calls, 0),\n\t\t\t\t\tduration: charges.reduce((total, entry) => total + entry.duration, 0),\n\t\t\t\t\ttokens: {\n\t\t\t\t\t\tknown: charges.reduce((total, entry) => total + (entry.tokens ?? 0), 0),\n\t\t\t\t\t\tunknown: charges.filter((entry) => entry.tokens === undefined).length,\n\t\t\t\t\t},\n\t\t\t\t\tbytes: {\n\t\t\t\t\t\tknown: charges.reduce((total, entry) => total + (entry.bytes ?? 0), 0),\n\t\t\t\t\t\tunknown: charges.filter((entry) => entry.bytes === undefined).length,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}),\n\t\t},\n\t}\n}\n","import type { StudyCommandRequest } from './types.js'\nimport { isAbsolute, resolve } from 'node:path'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyDigest } from '../../core/validators.js'\nimport { isStudyCustodyName } from '../stores/validators.js'\nimport { STUDY_COMMAND_HELP } from './constants.js'\nimport { resolveStudyPath } from './helpers.js'\n\n/** Parses public command tokens with operation-specific grammar diagnostics.\n * @param arguments_ - Exact command tokens, after the CLI help boundary.\n * @returns The independent operation request.\n * @throws StudyError when a token, required flag, or portable path is invalid.\n * @example Parse a study command\n * ```ts\n * import { parseStudyArguments } from '@orkestrel/study/server'\n *\n * parseStudyArguments(['check', 'files', '--profile', 'local'])\n * ```\n */\nexport function parseStudyArguments(arguments_: readonly string[]): StudyCommandRequest {\n\tconst command = arguments_[0]\n\tconst target = arguments_[1]\n\tconst usage =\n\t\tSTUDY_COMMAND_HELP.split('\\n').find((line) => line.startsWith('study ' + command + ' ')) ??\n\t\t'Expected study check, execute, grade, label, or report; use study --help.'\n\tif (!['check', 'execute', 'grade', 'label', 'report'].includes(command ?? ''))\n\t\tthrow new StudyError(\n\t\t\t'CONFIG',\n\t\t\t'Unknown or missing command ' + JSON.stringify(command ?? '<command>') + '. ' + usage,\n\t\t)\n\tif (target === undefined || target === '' || target.startsWith('-'))\n\t\tthrow new StudyError(\n\t\t\t'CONFIG',\n\t\t\t'Missing <' +\n\t\t\t\t(command === 'check' || command === 'execute' ? 'study' : 'result') +\n\t\t\t\t'> before ' +\n\t\t\t\tJSON.stringify(target ?? '<end>') +\n\t\t\t\t'. ' +\n\t\t\t\tusage,\n\t\t)\n\tconst allowed =\n\t\tcommand === 'check'\n\t\t\t? ['--profile']\n\t\t\t: command === 'execute'\n\t\t\t\t? ['--profile', '--out', '--expected']\n\t\t\t\t: command === 'grade'\n\t\t\t\t\t? ['--rubric']\n\t\t\t\t\t: command === 'label'\n\t\t\t\t\t\t? ['--grading', '--labels']\n\t\t\t\t\t\t: ['--grading']\n\tconst tokens: ReadonlyArray<string | undefined> = arguments_.slice(2)\n\t// Positions, not present elements: a sparse token array keeps each hole as an absent flag or value.\n\tconst pairs = [...tokens.entries()].flatMap(([index, flag]) =>\n\t\tindex % 2 === 0 ? [{ flag, value: tokens[index + 1] }] : [],\n\t)\n\t// Reversed so the earliest index of each flag is the one the lookup retains.\n\tconst firsts = new Map(pairs.map(({ flag }, index) => [flag, index] as const).reverse())\n\tfor (const [index, { flag, value }] of pairs.entries()) {\n\t\tif (flag === undefined || !allowed.includes(flag))\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\tJSON.stringify(flag ?? '<end>') +\n\t\t\t\t\t' is not a ' +\n\t\t\t\t\tcommand +\n\t\t\t\t\t' flag; accepts ' +\n\t\t\t\t\tallowed.join(', ') +\n\t\t\t\t\t'. ' +\n\t\t\t\t\tusage,\n\t\t\t)\n\t\tif (firsts.get(flag) !== index) throw new StudyError('CONFIG', flag + ' is duplicate. ' + usage)\n\t\tif (value === undefined || value === '' || value.startsWith('-'))\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\tflag + ' requires a value before ' + JSON.stringify(value ?? '<end>') + '. ' + usage,\n\t\t\t)\n\t}\n\tconst flags = new Map(\n\t\tpairs.flatMap(({ flag, value }) =>\n\t\t\tflag === undefined || value === undefined ? [] : [[flag, value] as const],\n\t\t),\n\t)\n\tif (command === 'check' || command === 'execute') {\n\t\tif (!isStudyCustodyName(target))\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\t'Invalid study token ' + JSON.stringify(target) + '; use a portable study name. ' + usage,\n\t\t\t)\n\t\tconst profile = flags.get('--profile') ?? 'local'\n\t\tconst out = flags.get('--out')\n\t\tconst expected = flags.get('--expected')\n\t\tif (!isStudyCustodyName(profile))\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\t'--profile ' + JSON.stringify(profile) + ' must be a portable name. ' + usage,\n\t\t\t)\n\t\tif (out !== undefined && !isAbsolute(out)) {\n\t\t\ttry {\n\t\t\t\tresolveStudyPath(resolve('.'), out)\n\t\t\t} catch {\n\t\t\t\tthrow new StudyError(\n\t\t\t\t\t'CONFIG',\n\t\t\t\t\t'--out ' +\n\t\t\t\t\t\tJSON.stringify(out) +\n\t\t\t\t\t\t' must be a portable contained path and cannot escape the consumer root. ' +\n\t\t\t\t\t\tusage,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tif (expected !== undefined && !isStudyDigest(expected))\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\t'--expected ' + JSON.stringify(expected) + ' must be a SHA-256 fingerprint. ' + usage,\n\t\t\t)\n\t\treturn { command, target, profile, out, expected }\n\t}\n\tif (command === 'grade') {\n\t\tconst rubric = flags.get('--rubric')\n\t\tif (rubric === undefined) throw new StudyError('CONFIG', 'Missing --rubric. ' + usage)\n\t\treturn { command, target, rubric }\n\t}\n\tconst grading = flags.get('--grading')\n\tif (!isStudyDigest(grading))\n\t\tthrow new StudyError(\n\t\t\t'CONFIG',\n\t\t\t'--grading ' +\n\t\t\t\tJSON.stringify(grading ?? '<missing>') +\n\t\t\t\t' must be an exact SHA-256 grading identity. ' +\n\t\t\t\tusage,\n\t\t)\n\tif (command === 'label') {\n\t\tconst labels = flags.get('--labels')\n\t\tif (labels === undefined) throw new StudyError('CONFIG', 'Missing --labels. ' + usage)\n\t\treturn { command, target, grading, labels }\n\t}\n\treturn { command: 'report', target, grading }\n}\n","import type { JSONValue } from '@orkestrel/contract'\nimport type { StudyGrading, StudyManifest, StudyScenario } from '../../core/types.js'\nimport type { StudySealedResult } from '../stores/types.js'\nimport type {\n\tStudyCommandArtifact,\n\tStudyCommandOptions,\n\tStudyExecutionRequest,\n\tStudyGradeRequest,\n\tStudyGradingContext,\n\tStudyLabelRequest,\n\tStudyPreparation,\n\tStudyReportRequest,\n} from './types.js'\nimport { arrayOf, isArray, isString, parseJSON } from '@orkestrel/contract'\nimport { randomUUID } from 'node:crypto'\nimport { mkdir, mkdtemp, rm } from 'node:fs/promises'\nimport { isAbsolute, join, resolve } from 'node:path'\nimport { StudyError } from '../../core/errors.js'\nimport { buildStudySchedule, validateStudyInputs } from '../../core/helpers.js'\nimport {\n\tparseStudyDefinition,\n\tparseStudyGrading,\n\tparseStudyLabeling,\n\tparseStudyProfile,\n\tparseStudyRubric,\n\tparseStudyScenario,\n} from '../../core/parsers.js'\nimport { StudySeries } from '../../core/engines/StudySeries.js'\nimport { StudyArtifactLoader } from '../processes/StudyArtifactLoader.js'\nimport { StudyProcessDriver } from '../processes/StudyProcessDriver.js'\nimport { computeStudyProfileDigest, valueToWire } from '../processes/helpers.js'\nimport { decodeStudyJSON, encodeStudyJSON, hashStudyBytes } from '../helpers.js'\nimport { STUDY_CUSTODY_BYTES, STUDY_PACKET_DISCLOSURE } from '../stores/constants.js'\nimport {\n\tbuildStudyPacket,\n\tcheckStudyDirectory,\n\tcomputeStudyPacketDigest,\n\treadStudyBytes,\n\treadStudyResult,\n\ttranslateStudyPacketLabeling,\n} from '../stores/helpers.js'\nimport { StudyGradingStore } from '../stores/StudyGradingStore.js'\nimport { StudyResultStore } from '../stores/StudyResultStore.js'\nimport { StudyTask } from '../processes/StudyTask.js'\nimport { isStudyJudgment } from '../../core/validators.js'\nimport { STUDY_COMMAND_DURATION, STUDY_COMMAND_GRADER } from './constants.js'\nimport {\n\tcollectStudyEvidence,\n\tcomputeStudyCommandFingerprint,\n\tcomputeStudyFixtureDigest,\n\tcomputeStudyReport,\n\tresolveStudyPath,\n\tresolveStudyProfile,\n} from './helpers.js'\nimport { parseStudyArguments } from './parsers.js'\n\n/** Executes validated study operations with execution and grading custody kept independent. */\nexport class StudyCommand {\n\treadonly #root: string\n\treadonly #entry: string\n\n\t/**\n\t * Owns the trusted host entry and repository location without reading or writing files.\n\t * @param options - The repository root and built trusted application entry\n\t */\n\tconstructor(options: StudyCommandOptions) {\n\t\tthis.#root = resolve(options.root)\n\t\tthis.#entry = resolve(this.#root, options.entry)\n\t}\n\n\t/**\n\t * Parses command tokens once and executes their independent operation.\n\t * @param arguments_ - The exact command tokens\n\t * @param signal - The caller's execution cancellation\n\t * @returns Truthful operation metadata or a verified whole-horizon report\n\t * @throws StudyError - Thrown when arguments, declarations, identities, or custody fail\n\t */\n\tasync execute(arguments_: readonly string[], signal: AbortSignal): Promise<JSONValue> {\n\t\tconst request = parseStudyArguments(arguments_)\n\t\tsignal.throwIfAborted()\n\t\tif (request.command === 'check') return this.#check(await this.#prepare(request, signal))\n\t\tif (request.command === 'execute') return this.#execution(request, signal)\n\t\tif (request.command === 'grade') return this.#grade(request, signal)\n\t\tif (request.command === 'label') return this.#label(request, signal)\n\t\tif (request.command === 'report') return this.#report(request, signal)\n\t\tthrow new StudyError('CONFIG', 'Unsupported study operation')\n\t}\n\n\tasync #prepare(request: StudyExecutionRequest, signal: AbortSignal): Promise<StudyPreparation> {\n\t\tconst directory = resolveStudyPath(join(this.#root, 'studies'), request.target)\n\t\tconst definitionBytes = await readStudyBytes(\n\t\t\tresolveStudyPath(directory, 'study.json'),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tconst definition = parseStudyDefinition(decodeStudyJSON(definitionBytes))\n\t\tif (definition.name !== request.target)\n\t\t\tthrow new StudyError('CONFIG', 'Study name differs from its selected directory')\n\t\tconst bundle = resolveStudyPath(join(this.#root, 'studies'), definition.driver)\n\t\tconst steps: Array<{\n\t\t\treadonly scenario: StudyScenario\n\t\t\treadonly fixture: StudyCommandArtifact\n\t\t}> = []\n\t\tfor (const id of definition.scenarios) {\n\t\t\tsignal.throwIfAborted()\n\t\t\tconst path = `scenarios/${id}.json`\n\t\t\tconst bytes = await readStudyBytes(resolveStudyPath(bundle, path), STUDY_CUSTODY_BYTES)\n\t\t\tconst scenario = parseStudyScenario(decodeStudyJSON(bytes))\n\t\t\tif (scenario.id !== id) throw new StudyError('CONFIG', 'Scenario identity is incompatible')\n\t\t\tsteps.push({ scenario, fixture: { path, digest: hashStudyBytes(bytes) } })\n\t\t}\n\t\tconst scenarios = steps.map((step) => step.scenario)\n\t\tconst fixtures = steps.map((step) => step.fixture)\n\t\tconst profileBytes = await readStudyBytes(\n\t\t\tresolveStudyPath(bundle, `profiles/${request.profile}.json`),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tconst source = parseStudyProfile(decodeStudyJSON(profileBytes))\n\t\tif (source.name !== request.profile)\n\t\t\tthrow new StudyError('CONFIG', 'Profile name differs from its selected file')\n\t\tif (source.bounds.series.duration > STUDY_COMMAND_DURATION)\n\t\t\tthrow new StudyError('CONFIG', 'Series duration exceeds the 24-hour host ceiling')\n\t\tconst profile = resolveStudyProfile(this.#root, source)\n\t\tconst rubricBytes = await readStudyBytes(\n\t\t\tresolveStudyPath(directory, definition.rubric),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tconst rubric = parseStudyRubric(decodeStudyJSON(rubricBytes))\n\t\tvalidateStudyInputs(definition, scenarios, rubric, profile)\n\t\tif (definition.purpose === 'quality' && profile.qualification === undefined)\n\t\t\tthrow new StudyError('CONFIG', 'Quality studies require a capacity qualification')\n\t\tsignal.throwIfAborted()\n\t\tconst artifacts = new StudyArtifactLoader({\n\t\t\troot: this.#root,\n\t\t\tentry: this.#entry,\n\t\t\tprofile,\n\t\t\tadapter: join(bundle, 'index.ts'),\n\t\t})\n\t\tconst selected = await artifacts.inspect()\n\t\tconst validation = await new StudyTask({\n\t\t\troot: this.#root,\n\t\t\tentry: this.#entry,\n\t\t\tadapter: join(bundle, 'index.ts'),\n\t\t\troots: profile.roots,\n\t\t}).execute({ operation: 'validate', input: { definition, scenarios, rubric, profile } }, signal)\n\t\tif (validation.value !== true || validation.instrument !== selected.instrument)\n\t\t\tthrow new StudyError('FAULT', 'Adapter validation identity differs')\n\t\tartifacts.verify()\n\t\treturn {\n\t\t\tdirectory: bundle,\n\t\t\tdefinition,\n\t\t\tscenarios: Object.freeze(scenarios),\n\t\t\trubric,\n\t\t\tprofile,\n\t\t\tidentity: {\n\t\t\t\t...selected,\n\t\t\t\tfixtures: computeStudyFixtureDigest(definition, fixtures),\n\t\t\t\tprofile: computeStudyProfileDigest(profile),\n\t\t\t},\n\t\t\tartifacts,\n\t\t\tsource: hashStudyBytes(profileBytes),\n\t\t}\n\t}\n\n\t#check(preparation: StudyPreparation): JSONValue {\n\t\tconst fingerprint = computeStudyCommandFingerprint(\n\t\t\tpreparation.identity,\n\t\t\tpreparation.profile.bounds,\n\t\t\tpreparation.definition,\n\t\t)\n\t\treturn valueToWire({\n\t\t\tcommand: 'check',\n\t\t\tstudy: preparation.definition.name,\n\t\t\tpurpose: preparation.definition.purpose,\n\t\t\tdriver: preparation.definition.driver,\n\t\t\tprofile: preparation.profile.name,\n\t\t\tbounds: preparation.profile.bounds,\n\t\t\tidentity: preparation.identity,\n\t\t\tprovenance: { profile: preparation.source },\n\t\t\tfingerprint,\n\t\t\tnext: [\n\t\t\t\t'execute',\n\t\t\t\tpreparation.definition.name,\n\t\t\t\t'--profile',\n\t\t\t\tpreparation.profile.name,\n\t\t\t\t'--expected',\n\t\t\t\tfingerprint,\n\t\t\t],\n\t\t\tschedule: buildStudySchedule(preparation.definition, preparation.scenarios),\n\t\t})\n\t}\n\n\tasync #execution(request: StudyExecutionRequest, signal: AbortSignal): Promise<JSONValue> {\n\t\tconst preparation = await this.#prepare(request, signal)\n\t\tconst fingerprint = computeStudyCommandFingerprint(\n\t\t\tpreparation.identity,\n\t\t\tpreparation.profile.bounds,\n\t\t\tpreparation.definition,\n\t\t)\n\t\tif (request.expected !== undefined && request.expected !== fingerprint)\n\t\t\tthrow new StudyError('CONFIG', 'Validated execution changed after the supervisor check')\n\t\tsignal.throwIfAborted()\n\t\tconst id = randomUUID()\n\t\tconst qualification = await this.#qualification(preparation)\n\t\tsignal.throwIfAborted()\n\t\tconst parent = await this.#temporary()\n\t\tsignal.throwIfAborted()\n\t\tconst directory = request.out === undefined ? join(parent, id) : this.#file(request.out)\n\t\tconst manifest: StudyManifest = {\n\t\t\tid,\n\t\t\tcreated: new Date().toISOString(),\n\t\t\tdefinition: preparation.definition,\n\t\t\tscenarios: preparation.scenarios,\n\t\t\tidentity: preparation.identity,\n\t\t\tschedule: buildStudySchedule(preparation.definition, preparation.scenarios),\n\t\t\tbounds: preparation.profile.bounds,\n\t\t\tqualification,\n\t\t\thost: {\n\t\t\t\tnode: process.version,\n\t\t\t\tplatform: process.platform,\n\t\t\t\tarchitecture: process.arch,\n\t\t\t\tprofile: preparation.source,\n\t\t\t\troots: JSON.stringify(preparation.profile.roots),\n\t\t\t},\n\t\t}\n\t\tconst store = new StudyResultStore({ directory, manifest })\n\t\tawait store.create()\n\t\tconst scratch = await mkdtemp(join(parent, 'scratch-'))\n\t\ttry {\n\t\t\tconst driver = new StudyProcessDriver({\n\t\t\t\troot: this.#root,\n\t\t\t\tentry: this.#entry,\n\t\t\t\tprofile: preparation.profile,\n\t\t\t\tidentity: preparation.identity,\n\t\t\t\tdriver: preparation.definition.driver,\n\t\t\t\tadapter: join(preparation.directory, 'index.ts'),\n\t\t\t\tdirectory: scratch,\n\t\t\t})\n\t\t\tconst attempts = await new StudySeries({ manifest, driver, store, signal }).execute()\n\t\t\tpreparation.artifacts.verify()\n\t\t\tconst seal = await store.seal()\n\t\t\treturn valueToWire({\n\t\t\t\tcommand: 'execute',\n\t\t\t\tstatus: attempts.some((attempt) => attempt.failure !== undefined)\n\t\t\t\t\t? 'operational-failure'\n\t\t\t\t\t: 'completed',\n\t\t\t\tresult: id,\n\t\t\t\tpath: directory,\n\t\t\t\tseal: seal.id,\n\t\t\t\tfingerprint,\n\t\t\t\tnext: [\n\t\t\t\t\t'grade',\n\t\t\t\t\tdirectory,\n\t\t\t\t\t'--rubric',\n\t\t\t\t\tresolveStudyPath(\n\t\t\t\t\t\tresolveStudyPath(join(this.#root, 'studies'), preparation.definition.name),\n\t\t\t\t\t\tpreparation.definition.rubric,\n\t\t\t\t\t),\n\t\t\t\t],\n\t\t\t})\n\t\t} finally {\n\t\t\tawait rm(scratch, { recursive: true, force: true, maxRetries: 3 })\n\t\t}\n\t}\n\n\tasync #grade(request: StudyGradeRequest, signal: AbortSignal): Promise<JSONValue> {\n\t\tconst result = await this.#result(request.target)\n\t\tconst bytes = await readStudyBytes(this.#file(request.rubric), STUDY_CUSTODY_BYTES)\n\t\tconst rubric = parseStudyRubric(decodeStudyJSON(bytes))\n\t\tconst evidence = await collectStudyEvidence(result)\n\t\tsignal.throwIfAborted()\n\t\tconst roots = parseJSON(result.manifest.host.roots ?? '')\n\t\tif (!arrayOf(isString)(roots))\n\t\t\tthrow new StudyError('CONFIG', 'Execution does not retain adapter dependency roots')\n\t\tconst evaluated = await new StudyTask({\n\t\t\troot: this.#root,\n\t\t\tentry: this.#entry,\n\t\t\tadapter: join(\n\t\t\t\tresolveStudyPath(join(this.#root, 'studies'), result.manifest.definition.driver),\n\t\t\t\t'index.ts',\n\t\t\t),\n\t\t\troots,\n\t\t}).execute(\n\t\t\t{\n\t\t\t\toperation: 'grade',\n\t\t\t\tinput: { manifest: result.manifest, rubric, attempts: result.attempts, evidence },\n\t\t\t},\n\t\t\tsignal,\n\t\t)\n\t\tconst judgments: unknown = evaluated.value\n\t\tif (!isArray(judgments) || !judgments.every(isStudyJudgment))\n\t\t\tthrow new StudyError('FAULT', 'Grader returned invalid judgments')\n\t\tconst digest = hashStudyBytes(bytes)\n\t\tconst packet = buildStudyPacket(result, rubric, digest)\n\t\tconst grading: StudyGrading = {\n\t\t\tresult: result.seal.id,\n\t\t\trubric: digest,\n\t\t\tgrader: STUDY_COMMAND_GRADER,\n\t\t\tinstrument: evaluated.instrument,\n\t\t\tattempts: result.manifest.schedule.map((trial) => trial.id),\n\t\t\tlabels: undefined,\n\t\t\tjudgments,\n\t\t\t...(packet === undefined ? {} : { packet: computeStudyPacketDigest(packet) }),\n\t\t}\n\t\tconst store = new StudyGradingStore({\n\t\t\tresult,\n\t\t\trubric: bytes,\n\t\t\t...(packet === undefined ? {} : { packet }),\n\t\t})\n\t\tconst id = await store.write(grading)\n\t\treturn valueToWire({\n\t\t\tcommand: 'grade',\n\t\t\tresult: result.manifest.id,\n\t\t\tgrading: id,\n\t\t\tnext: ['report', result.directory, '--grading', id],\n\t\t\t...(packet === undefined\n\t\t\t\t? {}\n\t\t\t\t: {\n\t\t\t\t\t\tpacket: {\n\t\t\t\t\t\t\tid: hashStudyBytes(packet.content),\n\t\t\t\t\t\t\tpath: join(result.directory, 'grades', id, `${grading.packet}.packet.json`),\n\t\t\t\t\t\t\tdisclosure: STUDY_PACKET_DISCLOSURE,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t})\n\t}\n\n\tasync #label(request: StudyLabelRequest, signal: AbortSignal): Promise<JSONValue> {\n\t\tconst result = await this.#result(request.target)\n\t\tconst previous = await this.#grading(result, request.grading)\n\t\tif (previous.packet === undefined || previous.grading.packet === undefined)\n\t\t\tthrow new StudyError('EVIDENCE', 'Selected grading has no semantic packet')\n\t\tconst bytes = await readStudyBytes(this.#file(request.labels), STUDY_CUSTODY_BYTES)\n\t\tconst labels = parseStudyLabeling(decodeStudyJSON(bytes))\n\t\tconst translated = translateStudyPacketLabeling(\n\t\t\tresult,\n\t\t\tprevious.rubric,\n\t\t\tprevious.grading.rubric,\n\t\t\tlabels,\n\t\t)\n\t\tsignal.throwIfAborted()\n\t\tconst grading: StudyGrading = {\n\t\t\t...previous.grading,\n\t\t\t// Binds the preceding grader so equal labels over distinct gradings stay distinct.\n\t\t\tinstrument: hashStudyBytes(\n\t\t\t\tJSON.stringify([previous.grading.instrument, await this.#instrument()]),\n\t\t\t),\n\t\t\tlabels: hashStudyBytes(bytes),\n\t\t\tjudgments: previous.grading.judgments.map((judgment) => {\n\t\t\t\tconst imported = translated.find(\n\t\t\t\t\t(entry) => entry.trial === judgment.trial && entry.criterion === judgment.criterion,\n\t\t\t\t)\n\t\t\t\tif (imported !== undefined) return imported\n\t\t\t\tif (\n\t\t\t\t\tprevious.rubric.criteria.find((criterion) => criterion.id === judgment.criterion)\n\t\t\t\t\t\t?.method !== 'semantic'\n\t\t\t\t)\n\t\t\t\t\treturn judgment\n\t\t\t\treturn {\n\t\t\t\t\t...judgment,\n\t\t\t\t\tverdict: 'unknown',\n\t\t\t\t\tmethod: 'human',\n\t\t\t\t\treason: 'No label in the selected imported packet',\n\t\t\t\t\treferences: [],\n\t\t\t\t}\n\t\t\t}),\n\t\t}\n\t\tconst store = new StudyGradingStore({\n\t\t\tresult,\n\t\t\trubric: previous.bytes,\n\t\t\tlabels: bytes,\n\t\t\tpacket: previous.packet,\n\t\t})\n\t\tconst id = await store.write(grading)\n\t\treturn valueToWire({\n\t\t\tcommand: 'label',\n\t\t\tresult: result.manifest.id,\n\t\t\tprevious: request.grading,\n\t\t\tgrading: id,\n\t\t\tpacket: labels.packet,\n\t\t\tnext: ['report', result.directory, '--grading', id],\n\t\t})\n\t}\n\n\tasync #report(request: StudyReportRequest, signal: AbortSignal): Promise<JSONValue> {\n\t\tconst result = await this.#result(request.target)\n\t\tconst context = await this.#grading(result, request.grading)\n\t\tsignal.throwIfAborted()\n\t\tconst labels =\n\t\t\tcontext.labels === undefined ? undefined : parseStudyLabeling(decodeStudyJSON(context.labels))\n\t\treturn valueToWire({\n\t\t\tcommand: 'report',\n\t\t\tgrading: request.grading,\n\t\t\treport: computeStudyReport(result, context.rubric, context.grading),\n\t\t\tlabeling:\n\t\t\t\tlabels === undefined\n\t\t\t\t\t? { status: 'absent' }\n\t\t\t\t\t: { labeler: labels.labeler, version: labels.version, usage: labels.usage },\n\t\t})\n\t}\n\n\tasync #result(target: string): Promise<StudySealedResult> {\n\t\tconst path = isAbsolute(target)\n\t\t\t? resolve(target)\n\t\t\t: target.includes('/')\n\t\t\t\t? resolveStudyPath(this.#root, target)\n\t\t\t\t: resolveStudyPath(join(this.#root, 'tmp', 'studies'), target)\n\t\tconst result = await readStudyResult(path)\n\t\tif (result.status !== 'sealed')\n\t\t\tthrow new StudyError('CUSTODY', 'Interrupted execution cannot be graded or reported')\n\t\treturn result\n\t}\n\n\tasync #grading(result: StudySealedResult, id: string): Promise<StudyGradingContext> {\n\t\tconst directory = join(result.directory, 'grades', id)\n\t\tconst raw = await readStudyBytes(join(directory, 'grading.json'), STUDY_CUSTODY_BYTES).catch(\n\t\t\t(error: unknown) => {\n\t\t\t\tif (error instanceof Error && 'code' in error && error.code === 'ENOENT')\n\t\t\t\t\tthrow new StudyError(\n\t\t\t\t\t\t'CUSTODY',\n\t\t\t\t\t\t`Selected grading is missing: ${join(directory, 'grading.json')}`,\n\t\t\t\t\t)\n\t\t\t\tthrow error\n\t\t\t},\n\t\t)\n\t\tif (hashStudyBytes(raw) !== id)\n\t\t\tthrow new StudyError('CUSTODY', 'Selected grading differs from its byte identity')\n\t\tconst declared = parseStudyGrading(decodeStudyJSON(raw))\n\t\tconst bytes = await readStudyBytes(\n\t\t\tjoin(directory, `${declared.rubric}.rubric.json`),\n\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t)\n\t\tconst rubric = parseStudyRubric(decodeStudyJSON(bytes))\n\t\tconst grading = await new StudyGradingStore({ result, rubric: bytes }).read(id)\n\t\tif (grading === undefined)\n\t\t\tthrow new StudyError('CUSTODY', `Selected grading is missing: ${directory}`)\n\t\tconst packet =\n\t\t\tgrading.packet === undefined\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tcontent: await readStudyBytes(\n\t\t\t\t\t\t\tjoin(directory, `${grading.packet}.packet.json`),\n\t\t\t\t\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tmapping: await readStudyBytes(\n\t\t\t\t\t\t\tjoin(directory, `${grading.packet}.mapping.json`),\n\t\t\t\t\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\tconst labels =\n\t\t\tgrading.labels === undefined\n\t\t\t\t? undefined\n\t\t\t\t: await readStudyBytes(\n\t\t\t\t\t\tjoin(directory, `${grading.labels}.labels.json`),\n\t\t\t\t\t\tSTUDY_CUSTODY_BYTES,\n\t\t\t\t\t)\n\t\tif (\n\t\t\thashStudyBytes(bytes) !== grading.rubric ||\n\t\t\t(packet !== undefined && computeStudyPacketDigest(packet) !== grading.packet) ||\n\t\t\t(labels !== undefined && hashStudyBytes(labels) !== grading.labels)\n\t\t)\n\t\t\tthrow new StudyError(\n\t\t\t\t'CUSTODY',\n\t\t\t\t'Grading artifacts changed while reading their verified context',\n\t\t\t)\n\t\treturn { grading, rubric, bytes, packet, labels }\n\t}\n\n\t#file(path: string): string {\n\t\treturn isAbsolute(path) ? resolve(path) : resolveStudyPath(this.#root, path)\n\t}\n\n\t#temporary(): Promise<string> {\n\t\treturn ['tmp', 'studies'].reduce(async (previous, name) => {\n\t\t\tconst directory = join(await previous, name)\n\t\t\ttry {\n\t\t\t\tawait mkdir(directory)\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof Error && 'code' in error && error.code === 'EEXIST')) throw error\n\t\t\t}\n\t\t\treturn checkStudyDirectory(directory)\n\t\t}, checkStudyDirectory(this.#root))\n\t}\n\n\tasync #qualification(preparation: StudyPreparation): Promise<string | undefined> {\n\t\tif (\n\t\t\tpreparation.profile.qualification === undefined ||\n\t\t\tpreparation.definition.purpose === 'capacity'\n\t\t)\n\t\t\treturn undefined\n\t\tconst result = await this.#result(preparation.profile.qualification)\n\t\tif (\n\t\t\tresult.manifest.definition.purpose !== 'capacity' ||\n\t\t\thashStudyBytes(encodeStudyJSON(result.manifest.identity)) !==\n\t\t\t\thashStudyBytes(encodeStudyJSON(preparation.identity)) ||\n\t\t\thashStudyBytes(encodeStudyJSON(result.manifest.bounds)) !==\n\t\t\t\thashStudyBytes(encodeStudyJSON(preparation.profile.bounds)) ||\n\t\t\thashStudyBytes(encodeStudyJSON(result.manifest.schedule)) !==\n\t\t\t\thashStudyBytes(\n\t\t\t\t\tencodeStudyJSON(buildStudySchedule(preparation.definition, preparation.scenarios)),\n\t\t\t\t) ||\n\t\t\thashStudyBytes(encodeStudyJSON(result.manifest.scenarios)) !==\n\t\t\t\thashStudyBytes(encodeStudyJSON(preparation.scenarios)) ||\n\t\t\tresult.attempts.some(\n\t\t\t\t(attempt) =>\n\t\t\t\t\tattempt.failure !== undefined ||\n\t\t\t\t\tattempt.observations.some(\n\t\t\t\t\t\t(observation) => observation.failure !== undefined || observation.product === undefined,\n\t\t\t\t\t),\n\t\t\t)\n\t\t)\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\t'Qualification requires a compatible complete capacity result with no operational failures',\n\t\t\t)\n\t\treturn result.seal.id\n\t}\n\n\tasync #instrument(): Promise<string> {\n\t\treturn hashStudyBytes(await readStudyBytes(this.#entry, STUDY_CUSTODY_BYTES))\n\t}\n}\n","import type { JSONValue } from '@orkestrel/contract'\nimport type { StudyEvidence, StudyAttempt, StudyProfile } from '../../core/types.js'\nimport type { StudyAdapterInterface } from '../adapters/types.js'\nimport { arrayOf, isArray, isRecord, isString } from '@orkestrel/contract'\nimport { dirname } from 'node:path'\nimport { isStudyError, StudyError } from '../../core/errors.js'\nimport {\n\tparseStudyDefinition,\n\tparseStudyProfile,\n\tparseStudyRubric,\n\tparseStudyScenario,\n} from '../../core/parsers.js'\nimport { isStudyJudgment } from '../../core/validators.js'\nimport { ArtifactLoader } from '../artifacts/ArtifactLoader.js'\nimport { readStudyAdapter } from '../adapters/helpers.js'\nimport { hashStudyBytes } from '../helpers.js'\nimport { STUDY_CUSTODY_BYTES } from '../stores/constants.js'\nimport { readStudyBytes } from '../stores/helpers.js'\nimport {\n\tisStudyCustodyAttempt,\n\tisStudyCustodyEvidence,\n\tisStudyCustodyManifest,\n} from '../stores/validators.js'\nimport { STUDY_FRAME_BYTES } from './constants.js'\nimport {\n\tcollectStudyEntries,\n\tcomputeStudyInstrumentDigest,\n\tresolveStudyInstrument,\n\tvalidateStudyRuntime,\n\tvalueToWire,\n} from './helpers.js'\n\n/** Evaluates only admitted instrumentation in a disposable native child. */\nexport class StudyTaskWorker {\n\t/** Processes exactly one inherited request and returns a bounded response. */\n\tasync execute(): Promise<void> {\n\t\tif (process.send === undefined || !process.connected)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter worker requires inherited IPC')\n\t\tprocess.channel?.ref()\n\t\tconst value: unknown = await new Promise((resolve) => process.once('message', resolve))\n\t\tconst outcome = await this.#execute(value).catch((error: unknown): JSONValue => ({\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\tcode: isStudyError(error) ? error.code : 'FAULT',\n\t\t}))\n\t\tconst response: JSONValue =\n\t\t\tBuffer.byteLength(JSON.stringify(outcome)) > STUDY_FRAME_BYTES\n\t\t\t\t? { error: 'Adapter result exceeds the frame allowance', code: 'FAULT' }\n\t\t\t\t: outcome\n\t\tawait new Promise<void>((resolve, reject) =>\n\t\t\tprocess.send?.(response, (error: Error | null) =>\n\t\t\t\terror === null ? resolve() : reject(error),\n\t\t\t),\n\t\t)\n\t}\n\tasync #execute(value: unknown): Promise<JSONValue> {\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\tBuffer.byteLength(JSON.stringify(value)) > STUDY_FRAME_BYTES ||\n\t\t\ttypeof value.adapter !== 'string' ||\n\t\t\ttypeof value.entry !== 'string' ||\n\t\t\t!arrayOf(isString)(value.roots) ||\n\t\t\t!isRecord(value.input)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter request is malformed')\n\t\tconst runtime = resolveStudyInstrument(value.entry)\n\t\tconst roots = [...new Set([...value.roots, runtime])]\n\t\tvalidateStudyRuntime(runtime, roots)\n\t\t// Validation precedes agent, subject and provider evaluation, so their selected entries stay\n\t\t// unreachable from every adapter import edge while shared admitted packages still load.\n\t\tconst profile =\n\t\t\tvalue.operation === 'validate' ? parseStudyProfile(value.input.profile) : undefined\n\t\tconst loader = new ArtifactLoader({\n\t\t\tentries: [],\n\t\t\troots,\n\t\t\tinstrument: runtime,\n\t\t\tsource: { root: dirname(value.adapter), entry: value.adapter },\n\t\t\t...(profile === undefined ? {} : { excluded: collectStudyEntries(profile) }),\n\t\t})\n\t\tconst instrument = computeStudyInstrumentDigest(\n\t\t\thashStudyBytes(await readStudyBytes(value.entry, STUDY_CUSTODY_BYTES)),\n\t\t\tloader.inspect().digest,\n\t\t)\n\t\tconst adapter = readStudyAdapter(await loader.load(value.adapter))\n\t\tif (profile === undefined && value.operation !== 'grade')\n\t\t\tthrow new StudyError('CONFIG', 'Unknown adapter operation')\n\t\tconst output: unknown =\n\t\t\tprofile === undefined\n\t\t\t\t? this.#grade(adapter, value.input)\n\t\t\t\t: this.#validate(adapter, value.input, profile)\n\t\tloader.verify()\n\t\treturn valueToWire({ instrument, value: output })\n\t}\n\n\t#validate(\n\t\tadapter: StudyAdapterInterface,\n\t\tinput: Readonly<Record<string, unknown>>,\n\t\tprofile: StudyProfile,\n\t): true {\n\t\tif (!isArray(input.scenarios)) throw new StudyError('CONFIG', 'Adapter scenarios are invalid')\n\t\tadapter.validate({\n\t\t\tdefinition: parseStudyDefinition(input.definition),\n\t\t\tscenarios: input.scenarios.map(parseStudyScenario),\n\t\t\trubric: parseStudyRubric(input.rubric),\n\t\t\tprofile,\n\t\t})\n\t\treturn true\n\t}\n\n\t#grade(adapter: StudyAdapterInterface, input: Readonly<Record<string, unknown>>): unknown {\n\t\tif (\n\t\t\t!isStudyCustodyManifest(input.manifest) ||\n\t\t\t!isArray(input.attempts) ||\n\t\t\t!isRecord(input.evidence)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter grading input is invalid')\n\t\tconst manifest = input.manifest\n\t\tconst attempts: readonly unknown[] = input.attempts\n\t\tif (\n\t\t\t!attempts.every((retained): retained is StudyAttempt =>\n\t\t\t\tisStudyCustodyAttempt(retained, manifest),\n\t\t\t)\n\t\t)\n\t\t\tthrow new StudyError('CONFIG', 'Adapter attempts are invalid')\n\t\tconst evidence: Record<string, readonly StudyEvidence[]> = Object.fromEntries(\n\t\t\tObject.entries(input.evidence).map(([trial, records]) => {\n\t\t\t\tif (!isArray(records) || !records.every(isStudyCustodyEvidence))\n\t\t\t\t\tthrow new StudyError('CONFIG', 'Adapter evidence is invalid')\n\t\t\t\treturn [trial, records]\n\t\t\t}),\n\t\t)\n\t\tconst output = adapter.grade({\n\t\t\tmanifest,\n\t\t\tattempts,\n\t\t\trubric: parseStudyRubric(input.rubric),\n\t\t\tevidence,\n\t\t})\n\t\tif (!isArray(output) || !output.every(isStudyJudgment))\n\t\t\tthrow new StudyError('FAULT', 'Adapter returned invalid judgments')\n\t\treturn output\n\t}\n}\n","import type { StudyFailure, StudyTicket, StudyUsage } from '../../core/types.js'\nimport type { StudyRemoteTicketOptions } from './types.js'\nimport { StudyError } from '../../core/errors.js'\n\n/** Transmits one settlement without inventing local admission authority. */\nexport class StudyRemoteTicket implements StudyTicket {\n\t#options: StudyRemoteTicketOptions\n\t#settled = false\n\n\t/** Owns the parent's ticket identity and composed cancellation.\n\t * @param options - Transported ticket state and settlement callback, snapshotted at construction.\n\t */\n\tconstructor(options: StudyRemoteTicketOptions) {\n\t\tthis.#options = { ...options }\n\t}\n\tget signal(): AbortSignal {\n\t\treturn this.#options.signal\n\t}\n\tget settled(): boolean {\n\t\treturn this.#settled\n\t}\n\n\t/** Sends actual usage for authoritative parent settlement.\n\t * @param usage - Actual measured request usage.\n\t */\n\tfinish(usage: StudyUsage): void {\n\t\tthis.#settle('finish', usage)\n\t}\n\n\t/** Sends operational failure while preserving unknown actual cost.\n\t * @param failure - The first observed request failure.\n\t */\n\tfail(failure: StudyFailure): void {\n\t\tthis.#settle('fail', failure)\n\t}\n\n\t#settle(operation: 'finish' | 'fail', value: StudyUsage | StudyFailure): void {\n\t\tif (this.#settled) {\n\t\t\tthis.#options.settle('fail', {\n\t\t\t\tcause: 'infrastructure',\n\t\t\t\tmessage: 'Worker ticket settled more than once',\n\t\t\t\trole: undefined,\n\t\t\t\tstop: undefined,\n\t\t\t})\n\t\t\tthrow new StudyError('FAULT', 'Worker ticket settled more than once')\n\t\t}\n\t\tthis.#settled = true\n\t\tthis.#options.settle(operation, value)\n\t}\n}\n","import type { StudyCharge, StudyFailure, StudyTicket, StudyUsage } from '../../core/types.js'\nimport type { StudyRemoteMeterInterface, StudyRemoteMeterOptions } from './types.js'\nimport { isRecord } from '@orkestrel/contract'\nimport { failureToStudyError, readStudyFailure } from '../../core/engines/index.js'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyUsage } from '../../core/validators.js'\nimport { createStudyProcessFailure, valueToWire } from './helpers.js'\nimport { StudyRemoteTicket } from './StudyRemoteTicket.js'\nimport { isStudyProcessFailure } from './validators.js'\n\n/** Waits for authoritative parent admission and drains acknowledged settlements. */\nexport class StudyRemoteMeter implements StudyRemoteMeterInterface {\n\t#options: StudyRemoteMeterOptions\n\t#next = 0\n\t#admissions = 0\n\treadonly #tickets = new Map<number, AbortController>()\n\treadonly #pending = new Set<Promise<void>>()\n\t#usage: StudyUsage[] = []\n\t#closed = false\n\n\t/** Owns one goal's transported tickets without local budget decisions.\n\t * @param options - Parent transport and shared worker failure control, snapshotted at construction.\n\t */\n\tconstructor(options: StudyRemoteMeterOptions) {\n\t\tthis.#options = { ...options }\n\t}\n\tget signal(): AbortSignal {\n\t\treturn this.#options.control.signal\n\t}\n\tget usage(): readonly StudyUsage[] {\n\t\treturn Object.freeze([...this.#usage])\n\t}\n\n\t/** Requests and awaits the parent's dispatch grant.\n\t * @param charge - Upper bounds that the parent reserves before replying.\n\t * @returns A ticket only after authoritative admission succeeds.\n\t */\n\tasync admit(charge: StudyCharge): Promise<StudyTicket> {\n\t\tif (this.#closed || this.#options.control.failure !== undefined)\n\t\t\tthrow failureToStudyError(\n\t\t\t\tthis.#options.control.failure ?? createStudyProcessFailure('Worker meter is closed'),\n\t\t\t)\n\t\tconst id = ++this.#next\n\t\tthis.#admissions++\n\t\ttry {\n\t\t\tconst response = await this.#options.control.wait(\n\t\t\t\tthis.#options.channel.request('admit', valueToWire({ id, charge })),\n\t\t\t)\n\t\t\tif (!isRecord(response) || response.id !== id)\n\t\t\t\tthrow new StudyError('FAULT', 'Worker admission grant is invalid')\n\t\t\tif (this.#closed) throw new StudyError('FAULT', 'Worker goal ended during admission')\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#tickets.set(id, controller)\n\t\t\treturn new StudyRemoteTicket({\n\t\t\t\tid,\n\t\t\t\tsignal: AbortSignal.any([controller.signal, this.signal]),\n\t\t\t\tsettle: (operation, value) => this.#settle(id, operation, value),\n\t\t\t})\n\t\t} catch (error) {\n\t\t\tthis.#options.control.fail(readStudyFailure(error))\n\t\t\tthrow error\n\t\t} finally {\n\t\t\tthis.#admissions--\n\t\t}\n\t}\n\n\t/** Propagates the parent's ticket cancellation without changing its cause.\n\t * @param id - Parent-issued ticket identity.\n\t * @param failure - Authoritative parent attribution.\n\t */\n\tabort(id: number, failure: StudyFailure): void {\n\t\tconst ticket = this.#tickets.get(id)\n\t\tif (ticket === undefined)\n\t\t\tthrow new StudyError('FAULT', 'Cancellation names an unknown worker ticket')\n\t\tticket.abort(failureToStudyError(failure))\n\t\tthis.#options.control.fail(failure)\n\t}\n\n\t/** Closes admission and requires every ticket and acknowledgment to finish. */\n\tasync close(): Promise<void> {\n\t\tthis.#closed = true\n\t\tif (this.#tickets.size !== 0 || this.#admissions !== 0)\n\t\t\tthis.#options.control.fail(\n\t\t\t\tcreateStudyProcessFailure('Worker goal ended with unfinished requests'),\n\t\t\t)\n\t\tawait Promise.all(this.#pending)\n\t\tif (this.#options.control.failure !== undefined)\n\t\t\tthrow failureToStudyError(this.#options.control.failure)\n\t}\n\n\t#settle(id: number, operation: 'finish' | 'fail', value: StudyUsage | StudyFailure): void {\n\t\tif (!this.#tickets.delete(id)) {\n\t\t\tthis.#options.control.fail(\n\t\t\t\tcreateStudyProcessFailure('Worker ticket settlement is repeated or foreign'),\n\t\t\t)\n\t\t\tthrow failureToStudyError(\n\t\t\t\tthis.#options.control.failure ?? createStudyProcessFailure('Worker settlement failed'),\n\t\t\t)\n\t\t}\n\t\tconst accepted = Object.freeze({ ...value })\n\t\tconst work = this.#options.channel\n\t\t\t.request(\n\t\t\t\toperation,\n\t\t\t\tvalueToWire(operation === 'finish' ? { id, usage: accepted } : { id, failure: accepted }),\n\t\t\t)\n\t\t\t.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (operation === 'finish' && isStudyUsage(accepted)) this.#usage.push(accepted)\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.#options.control.fail(readStudyFailure(error))\n\t\t\t\t},\n\t\t\t)\n\t\tthis.#pending.add(work)\n\t\tvoid work.finally(() => this.#pending.delete(work))\n\t\tif (operation === 'fail' && isStudyProcessFailure(accepted))\n\t\t\tthis.#options.control.fail(accepted)\n\t}\n}\n","import type { StudySessionInterface } from '../../core/types.js'\nimport type { StudyOperation } from './types.js'\nimport type { JSONValue } from '@orkestrel/contract'\nimport { isRecord } from '@orkestrel/contract'\nimport {\n\tStudyControl,\n\tStudyDeadline,\n\tfailureToStudyError,\n\treadStudyFailure,\n} from '../../core/engines/index.js'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyGoal, isStudyProduct, isStudyProfile } from '../../core/validators.js'\nimport { STUDY_PROCESS_LABEL } from './constants.js'\nimport { computeStudyProfileDigest, createStudyProcessFailure, valueToWire } from './helpers.js'\nimport { StudyArtifactLoader } from './StudyArtifactLoader.js'\nimport { StudyChannel } from './StudyChannel.js'\nimport { StudyRemoteMeter } from './StudyRemoteMeter.js'\nimport { isStudyIdentity, isStudyProcessFailure, isStudyTrial } from './validators.js'\n\n/** Executes one verified trial behind parent-authorized admission and custody. */\nexport class StudyWorker {\n\t#control = new StudyControl()\n\t#channel: StudyChannel | undefined\n\t#artifacts: StudyArtifactLoader | undefined\n\t#session: StudySessionInterface | undefined\n\treadonly #meters = new Set<StudyRemoteMeter>()\n\t#opening = false\n\t#closing = false\n\t#duration = 1000\n\t#executed = false\n\treadonly #evidence = new Set<Promise<void>>()\n\n\t/** Serves the inherited IPC channel until its parent disconnects.\n\t * @returns Completion after channel and acquired session cleanup.\n\t */\n\tasync execute(): Promise<void> {\n\t\tif (this.#executed || process.send === undefined || !process.connected)\n\t\t\tthrow new StudyError('CONFIG', 'Study worker requires one inherited IPC channel')\n\t\tthis.#executed = true\n\t\tthis.#channel = new StudyChannel({\n\t\t\tendpoint: process,\n\t\t\thandle: (operation, value) => this.#handle(operation, value),\n\t\t\tabort: (value) => this.#abort(value),\n\t\t})\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve) =>\n\t\t\t\tthis.#channel?.signal.addEventListener('abort', () => resolve(), { once: true }),\n\t\t\t)\n\t\t} finally {\n\t\t\tthis.#control.fail(createStudyProcessFailure('Study worker disconnected'))\n\t\t\tif (this.#session !== undefined)\n\t\t\t\tawait new StudyDeadline({ duration: this.#duration, label: STUDY_PROCESS_LABEL })\n\t\t\t\t\t.wait(this.#session.close())\n\t\t\t\t\t.catch(() => undefined)\n\t\t\tthis.#session = undefined\n\t\t\tthis.#channel.close()\n\t\t\tthis.#control.close()\n\t\t}\n\t}\n\n\tasync #handle(operation: StudyOperation, value: JSONValue): Promise<JSONValue> {\n\t\ttry {\n\t\t\tif (operation === 'open') return await this.#open(value)\n\t\t\tif (operation === 'goal') return await this.#goal(value)\n\t\t\tif (operation === 'close') {\n\t\t\t\tif (this.#closing) throw new StudyError('FAULT', 'Worker cleanup repeated')\n\t\t\t\tthis.#closing = true\n\t\t\t\tthis.#control.fail({\n\t\t\t\t\tcause: 'interrupted',\n\t\t\t\t\tmessage: 'Worker cleanup requested',\n\t\t\t\t\trole: undefined,\n\t\t\t\t\tstop: undefined,\n\t\t\t\t})\n\t\t\t\tif (this.#session !== undefined)\n\t\t\t\t\tawait new StudyDeadline({ duration: this.#duration, label: STUDY_PROCESS_LABEL }).wait(\n\t\t\t\t\t\tthis.#session.close(),\n\t\t\t\t\t)\n\t\t\t\tthis.#session = undefined\n\t\t\t\tthis.#artifacts?.verify()\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tthrow new StudyError('FAULT', 'Parent requested a forbidden worker operation')\n\t\t} catch (error) {\n\t\t\tthis.#control.fail(readStudyFailure(error))\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync #open(value: JSONValue): Promise<JSONValue> {\n\t\tif (this.#opening || this.#closing || this.#control.failure !== undefined)\n\t\t\tthrow new StudyError('FAULT', 'Worker trial can open only once')\n\t\tthis.#opening = true\n\t\tif (\n\t\t\t!isRecord(value) ||\n\t\t\ttypeof value.entry !== 'string' ||\n\t\t\ttypeof value.root !== 'string' ||\n\t\t\ttypeof value.directory !== 'string' ||\n\t\t\ttypeof value.driver !== 'string' ||\n\t\t\ttypeof value.adapter !== 'string' ||\n\t\t\t!isStudyProfile(value.profile) ||\n\t\t\t!isStudyIdentity(value.identity) ||\n\t\t\t!isStudyTrial(value.trial)\n\t\t)\n\t\t\tthrow new StudyError(\n\t\t\t\t'CONFIG',\n\t\t\t\t'Worker opening declaration is invalid or driver is unsupported',\n\t\t\t)\n\t\tthis.#duration = value.profile.bounds.request.duration\n\t\tthis.#artifacts = new StudyArtifactLoader({\n\t\t\tentry: value.entry,\n\t\t\troot: value.root,\n\t\t\tprofile: value.profile,\n\t\t\tadapter: value.adapter,\n\t\t})\n\t\tconst identity = await this.#artifacts.inspect()\n\t\tif (\n\t\t\tidentity.agent !== value.identity.agent ||\n\t\t\tidentity.subject !== value.identity.subject ||\n\t\t\tidentity.provider !== value.identity.provider ||\n\t\t\tidentity.instrument !== value.identity.instrument ||\n\t\t\tcomputeStudyProfileDigest(value.profile) !== value.identity.profile\n\t\t)\n\t\t\tthrow new StudyError('FAULT', 'Worker artifact identity differs from parent declaration')\n\t\tconst modules = await this.#artifacts.load()\n\t\tconst adapter = await this.#artifacts.adapter()\n\t\tconst driver = adapter.driver({\n\t\t\t...modules,\n\t\t\tprofile: value.profile,\n\t\t\tdirectory: value.directory,\n\t\t})\n\t\tthis.#session = await driver.open(value.trial, this.#control.signal)\n\t\tif (this.#control.failure !== undefined) throw failureToStudyError(this.#control.failure)\n\t\treturn valueToWire({ ...identity, pid: process.pid })\n\t}\n\n\tasync #goal(value: JSONValue): Promise<JSONValue> {\n\t\tif (\n\t\t\tthis.#session === undefined ||\n\t\t\tthis.#channel === undefined ||\n\t\t\tthis.#meters.size !== 0 ||\n\t\t\tthis.#closing ||\n\t\t\tthis.#control.failure !== undefined ||\n\t\t\t!isStudyGoal(value)\n\t\t)\n\t\t\tthrow new StudyError('FAULT', 'Worker goal is invalid or out of order')\n\t\tconst meter = new StudyRemoteMeter({ channel: this.#channel, control: this.#control })\n\t\tthis.#meters.add(meter)\n\t\ttry {\n\t\t\tconst product = await this.#control.wait(\n\t\t\t\tthis.#session.execute(value, {\n\t\t\t\t\tsignal: this.#control.signal,\n\t\t\t\t\tmeter,\n\t\t\t\t\tevidence: { append: (evidence) => this.#append(valueToWire(evidence)) },\n\t\t\t\t}),\n\t\t\t)\n\t\t\tawait meter.close()\n\t\t\tawait Promise.all(this.#evidence)\n\t\t\tif (this.#control.failure !== undefined) throw failureToStudyError(this.#control.failure)\n\t\t\tif (!isStudyProduct(product))\n\t\t\t\tthrow new StudyError('FAULT', 'Worker driver returned an invalid product')\n\t\t\treturn valueToWire(product)\n\t\t} finally {\n\t\t\tthis.#meters.delete(meter)\n\t\t}\n\t}\n\n\t#append(value: JSONValue): Promise<void> {\n\t\tif (\n\t\t\tthis.#channel === undefined ||\n\t\t\tthis.#meters.size === 0 ||\n\t\t\tthis.#control.failure !== undefined\n\t\t)\n\t\t\treturn Promise.reject(new StudyError('FAULT', 'Worker evidence is outside an active goal'))\n\t\tconst pending = this.#channel\n\t\t\t.request('evidence', value)\n\t\t\t.then((acknowledged) => {\n\t\t\t\tif (acknowledged !== true)\n\t\t\t\t\tthrow new StudyError('FAULT', 'Worker evidence was not acknowledged')\n\t\t\t})\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tthis.#control.fail(readStudyFailure(error))\n\t\t\t\tthrow error\n\t\t\t})\n\t\tthis.#evidence.add(pending)\n\t\tvoid pending.then(\n\t\t\t() => this.#evidence.delete(pending),\n\t\t\t() => this.#evidence.delete(pending),\n\t\t)\n\t\treturn pending\n\t}\n\n\t#abort(value: JSONValue): void {\n\t\tif (!isRecord(value) || !isStudyProcessFailure(value.failure))\n\t\t\tthrow new StudyError('FAULT', 'Worker cancellation is malformed')\n\t\tif (value.id === undefined) this.#control.fail(value.failure)\n\t\telse {\n\t\t\tconst [meter] = this.#meters\n\t\t\tif (typeof value.id !== 'number' || meter === undefined)\n\t\t\t\tthrow new StudyError('FAULT', 'Worker ticket cancellation is foreign')\n\t\t\tmeter.abort(value.id, value.failure)\n\t\t}\n\t}\n}\n","/** Bounds each supervised operation other than execution to 60 seconds. */\nexport const STUDY_LAUNCH_DURATION = 60000\n\n/** Extends supervised execution beyond its declared series duration for cleanup. */\nexport const STUDY_LAUNCH_CLEANUP = 15000\n\n/** Bounds combined supervised command output to 16 MiB before terminating the tree. */\nexport const STUDY_LAUNCH_BYTES = 16 * 1024 * 1024\n","import type { ChildProcess } from 'node:child_process'\nimport type { StudyLaunchResult } from './types.js'\nimport { StudyError } from '../../core/errors.js'\nimport { terminateStudyChild } from '../processes/helpers.js'\nimport { STUDY_LAUNCH_BYTES } from './constants.js'\n\n/** Supervises one launched command child until it closes under its output allowance and deadline. */\nexport class StudyLaunchChild {\n\treadonly #child: ChildProcess\n\treadonly #duration: number\n\treadonly #forward: boolean\n\treadonly #signal: AbortSignal\n\treadonly #chunks: Buffer[] = []\n\t#bytes = 0\n\t#failure: Error | undefined\n\t#expired = false\n\t#executed = false\n\n\t/** Binds one spawned child to its deadline, output route and the launcher's interruption.\n\t * @param child - The spawned child; `execute` subscribes before any of its events can fire.\n\t * @param duration - The deadline in milliseconds.\n\t * @param forward - If `true`, stdout is forwarded to this process; if `false`, it is captured as the result output.\n\t * @param signal - The launcher's interruption; an abort terminates the child and reports 130.\n\t */\n\tconstructor(child: ChildProcess, duration: number, forward: boolean, signal: AbortSignal) {\n\t\tthis.#child = child\n\t\tthis.#duration = duration\n\t\tthis.#forward = forward\n\t\tthis.#signal = signal\n\t}\n\n\t/** Waits for the child to close and reports its exit code and captured output.\n\t * @returns The child's code, 130 after interruption or 124 after the deadline, with captured stdout.\n\t * @throws StudyError - Thrown with code `CONFIG` when this child is already supervised.\n\t */\n\texecute(): Promise<StudyLaunchResult> {\n\t\tif (this.#executed) throw new StudyError('CONFIG', 'Study launch can execute only once')\n\t\tthis.#executed = true\n\t\tconst child = this.#child\n\t\tconst signal = this.#signal\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst listeners = new AbortController()\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.#expired = true\n\t\t\t\tterminateStudyChild(child)\n\t\t\t}, this.#duration)\n\t\t\tsignal.addEventListener('abort', () => terminateStudyChild(child), {\n\t\t\t\tonce: true,\n\t\t\t\tsignal: listeners.signal,\n\t\t\t})\n\t\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\t\tif (!this.#measure(chunk)) return\n\t\t\t\tif (this.#forward) process.stdout.write(chunk)\n\t\t\t\telse this.#chunks.push(chunk)\n\t\t\t})\n\t\t\tchild.stderr?.on('data', (chunk: Buffer) => {\n\t\t\t\tif (this.#measure(chunk)) process.stderr.write(chunk)\n\t\t\t})\n\t\t\tchild.once('error', (error) => {\n\t\t\t\tthis.#failure ??= error\n\t\t\t})\n\t\t\tchild.once('close', (code) => {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\tlisteners.abort()\n\t\t\t\tif (this.#failure !== undefined) {\n\t\t\t\t\treject(this.#failure)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (this.#expired)\n\t\t\t\t\tprocess.stderr.write(\n\t\t\t\t\t\t`study: DEADLINE: Process tree exceeded its ${this.#duration} ms deadline\\n`,\n\t\t\t\t\t)\n\t\t\t\tresolve({\n\t\t\t\t\tcode: signal.aborted ? 130 : this.#expired ? 124 : (code ?? 1),\n\t\t\t\t\toutput: Buffer.concat(this.#chunks).toString('utf8'),\n\t\t\t\t})\n\t\t\t})\n\t\t\tif (signal.aborted) terminateStudyChild(child)\n\t\t})\n\t}\n\n\t// Counts a chunk against the shared stdout and stderr allowance; an overflow retains the failure and terminates the tree.\n\t#measure(chunk: Buffer): boolean {\n\t\tthis.#bytes += chunk.byteLength\n\t\tif (this.#bytes <= STUDY_LAUNCH_BYTES) return true\n\t\tthis.#failure ??= new Error('Study command output exceeds the 16 MiB host allowance')\n\t\tterminateStudyChild(this.#child)\n\t\treturn false\n\t}\n}\n","import type { StudyLaunchOptions, StudyLaunchResult } from './types.js'\nimport { isRecord } from '@orkestrel/contract'\nimport { spawn } from 'node:child_process'\nimport { StudyError } from '../../core/errors.js'\nimport { isStudyBounds, isStudyDigest } from '../../core/validators.js'\nimport { STUDY_COMMAND_DURATION } from '../commands/constants.js'\nimport { parseStudyArguments } from '../commands/parsers.js'\nimport { STUDY_COMMAND_OPERATION } from '../processes/constants.js'\nimport { STUDY_LAUNCH_CLEANUP, STUDY_LAUNCH_DURATION } from './constants.js'\nimport { StudyLaunchChild } from './StudyLaunchChild.js'\n\n/** Supervises finite command trees and binds offline check to execution. */\nexport class StudyLauncher {\n\treadonly #root: string\n\treadonly #entry: string\n\treadonly #interruption = new AbortController()\n\treadonly #signal: () => void\n\n\t/** Owns the trusted runtime entry and caller working directory.\n\t * @param options - Native entry and consumer root.\n\t */\n\tconstructor(options: StudyLaunchOptions) {\n\t\tthis.#root = options.root\n\t\tthis.#entry = options.entry\n\t\tthis.#signal = this.#interruption.abort.bind(this.#interruption)\n\t}\n\n\t/** Checks and supervises the requested command under its finite native allowance.\n\t * @param arguments_ - Public command tokens.\n\t * @returns The exact operational or supervisor exit code.\n\t */\n\tasync execute(arguments_: readonly string[]): Promise<number> {\n\t\tconst entry = this.#entry\n\t\tconst request = parseStudyArguments(arguments_)\n\t\tprocess.on('SIGINT', this.#signal)\n\t\tprocess.on('SIGTERM', this.#signal)\n\t\ttry {\n\t\t\tif (request.command !== 'execute') {\n\t\t\t\tif (this.#interruption.signal.aborted) return 130\n\t\t\t\treturn (await this.#launch(entry, arguments_, STUDY_LAUNCH_DURATION, true)).code\n\t\t\t}\n\t\t\tconst check = ['check', request.target, '--profile', request.profile]\n\t\t\tconst reading = await this.#launch(entry, check, STUDY_LAUNCH_DURATION, false)\n\t\t\tif (reading.code !== 0) {\n\t\t\t\tprocess.stdout.write(reading.output)\n\t\t\t\treturn reading.code\n\t\t\t}\n\t\t\tconst value: unknown = JSON.parse(reading.output)\n\t\t\tif (\n\t\t\t\t!isRecord(value) ||\n\t\t\t\t!isStudyBounds(value.bounds) ||\n\t\t\t\tvalue.bounds.series.duration > STUDY_COMMAND_DURATION\n\t\t\t)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Study execution requires a validated series duration within the 24-hour host ceiling',\n\t\t\t\t)\n\t\t\tif (!isStudyDigest(value.fingerprint))\n\t\t\t\tthrow new Error('Study check did not return an execution fingerprint')\n\t\t\tconst duration = value.bounds.series.duration + STUDY_LAUNCH_CLEANUP\n\t\t\tif (request.expected !== undefined && request.expected !== value.fingerprint)\n\t\t\t\tthrow new StudyError('CONFIG', 'Validated execution differs from the requested fingerprint')\n\t\t\tconst execution = [\n\t\t\t\t'execute',\n\t\t\t\trequest.target,\n\t\t\t\t'--profile',\n\t\t\t\trequest.profile,\n\t\t\t\t...(request.out === undefined ? [] : ['--out', request.out]),\n\t\t\t\t'--expected',\n\t\t\t\tvalue.fingerprint,\n\t\t\t]\n\t\t\tif (this.#interruption.signal.aborted) return 130\n\t\t\treturn (await this.#launch(entry, execution, duration, true)).code\n\t\t} finally {\n\t\t\tprocess.removeListener('SIGINT', this.#signal)\n\t\t\tprocess.removeListener('SIGTERM', this.#signal)\n\t\t}\n\t}\n\n\t// Spawns one command child; its own entity supervises the deadline, output allowance and interruption.\n\t#launch(\n\t\tentry: string,\n\t\targuments_: readonly string[],\n\t\tduration: number,\n\t\tforward: boolean,\n\t): Promise<StudyLaunchResult> {\n\t\tconst child = spawn(\n\t\t\tprocess.execPath,\n\t\t\t[...process.execArgv, entry, STUDY_COMMAND_OPERATION, ...arguments_],\n\t\t\t{\n\t\t\t\tcwd: this.#root,\n\t\t\t\tshell: false,\n\t\t\t\twindowsHide: true,\n\t\t\t\tdetached: process.platform !== 'win32',\n\t\t\t\tstdio: ['ignore', 'pipe', 'pipe', 'ipc'],\n\t\t\t},\n\t\t)\n\t\treturn new StudyLaunchChild(child, duration, forward, this.#interruption.signal).execute()\n\t}\n}\n","import type { StudyLaunchOptions } from './types.js'\nimport { isRecord } from '@orkestrel/contract'\nimport { StudyError } from '../../core/errors.js'\nimport { StudyCommand } from '../commands/StudyCommand.js'\nimport { STUDY_COMMAND_HELP } from '../commands/constants.js'\nimport {\n\tSTUDY_COMMAND_OPERATION,\n\tSTUDY_TASK_OPERATION,\n\tSTUDY_WORKER_OPERATION,\n} from '../processes/constants.js'\nimport { StudyTaskWorker } from '../processes/StudyTaskWorker.js'\nimport { StudyWorker } from '../processes/StudyWorker.js'\nimport { StudyLauncher } from './StudyLauncher.js'\n\n/** Dispatches private child routes before the public native supervisor. */\nexport class StudyCLI {\n\t#options: StudyLaunchOptions\n\t/** Owns the installed executable path and consumer working directory.\n\t * @param options - Exact runtime entry and consumer root, snapshotted at construction.\n\t */\n\tconstructor(options: StudyLaunchOptions) {\n\t\tthis.#options = { ...options }\n\t}\n\t/** Executes one route with truthful public exit semantics.\n\t * @param arguments_ - Native command arguments.\n\t * @returns The command, deadline, interruption, or invalid-input exit code.\n\t */\n\tasync execute(arguments_: readonly string[]): Promise<number> {\n\t\ttry {\n\t\t\tif (\n\t\t\t\t[STUDY_COMMAND_OPERATION, STUDY_WORKER_OPERATION, STUDY_TASK_OPERATION].includes(\n\t\t\t\t\targuments_[0] ?? '',\n\t\t\t\t) &&\n\t\t\t\t(process.send === undefined || !process.connected)\n\t\t\t)\n\t\t\t\tthrow new StudyError(\n\t\t\t\t\t'CONFIG',\n\t\t\t\t\t`Private route ${JSON.stringify(arguments_[0])} requires supervised native IPC; use study check, execute, grade, label, or report. Use study --help for grammar.`,\n\t\t\t\t)\n\t\t\tif (arguments_[0] === STUDY_WORKER_OPERATION) {\n\t\t\t\tawait new StudyWorker().execute()\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (arguments_[0] === STUDY_TASK_OPERATION) {\n\t\t\t\tawait new StudyTaskWorker().execute()\n\t\t\t\treturn 0\n\t\t\t}\n\t\t\tif (arguments_[0] !== STUDY_COMMAND_OPERATION) {\n\t\t\t\tif (arguments_.includes('--help')) {\n\t\t\t\t\tprocess.stdout.write(STUDY_COMMAND_HELP)\n\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t\tif (arguments_.length === 0) {\n\t\t\t\t\tprocess.stderr.write(STUDY_COMMAND_HELP)\n\t\t\t\t\treturn 64\n\t\t\t\t}\n\t\t\t\treturn await new StudyLauncher(this.#options).execute(arguments_)\n\t\t\t}\n\t\t\tconst controller = new AbortController()\n\t\t\tconst listener = controller.abort.bind(controller)\n\t\t\tprocess.once('SIGINT', listener)\n\t\t\tprocess.once('SIGTERM', listener)\n\t\t\ttry {\n\t\t\t\tconst result = await new StudyCommand(this.#options).execute(\n\t\t\t\t\targuments_.slice(1),\n\t\t\t\t\tcontroller.signal,\n\t\t\t\t)\n\t\t\t\tprocess.stdout.write(`${JSON.stringify(result)}\\n`)\n\t\t\t\treturn controller.signal.aborted\n\t\t\t\t\t? 130\n\t\t\t\t\t: isRecord(result) && result.status === 'operational-failure'\n\t\t\t\t\t\t? 1\n\t\t\t\t\t\t: 0\n\t\t\t} finally {\n\t\t\t\tprocess.removeListener('SIGINT', listener)\n\t\t\t\tprocess.removeListener('SIGTERM', listener)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\terror instanceof Error && 'code' in error && typeof error.code === 'string'\n\t\t\t\t\t? error.code\n\t\t\t\t\t: 'FAULT'\n\t\t\tprocess.stderr.write(\n\t\t\t\t`study: ${code}: ${error instanceof Error ? error.message : String(error)}\\n`,\n\t\t\t)\n\t\t\treturn error instanceof StudyError\n\t\t\t\t? error.code === 'CONFIG'\n\t\t\t\t\t? 64\n\t\t\t\t\t: error.failure?.cause === 'deadline'\n\t\t\t\t\t\t? 124\n\t\t\t\t\t\t: error.failure?.cause === 'interrupted'\n\t\t\t\t\t\t\t? 130\n\t\t\t\t\t\t\t: 1\n\t\t\t\t: 1\n\t\t}\n\t}\n}\n","import { fileURLToPath } from 'node:url'\nimport { StudyCLI } from '../server/launchers/StudyCLI.js'\n\nprocess.exitCode = await new StudyCLI({\n\troot: process.cwd(),\n\tentry: fileURLToPath(import.meta.url),\n}).execute(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASA,IAAa,oBAAoB,OAAO,IAAI,wBAAwB;;AASpE,IAAa,aAAa;;AAG1B,IAAa,cAAoC,OAAO,OAAO;CAC9D;CACA;CACA;CACA;C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