@orkestrel/qualifier 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/dist/src/core/index.cjs +98 -31
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +123 -53
- package/dist/src/core/index.d.ts +123 -53
- package/dist/src/core/index.js +98 -31
- package/dist/src/core/index.js.map +1 -1
- package/package.json +15 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#emitter","#engine","#evaluator","#owned","#validate","#labels","#alive","#qualify","#destroyed"],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/Qualifier.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { Eligibility, QualificationEffect } from './types.js'\n\n/** Holds the default definition validation policy for `createQualifier` / `Qualifier.qualify`. */\nexport const DEFAULT_QUALIFIER_VALIDATE = true\n\n/** Names the reserved internal projection namespace a pass's working projection is written under. */\nexport const QUALIFICATION_KEY = 'qualification'\n\n/** Lists the eligibility severities in order — most to least severe. */\nexport const ELIGIBILITY_PRECEDENCE: readonly Eligibility[] = Object.freeze([\n\t'ineligible',\n\t'referral',\n\t'eligible',\n])\n\n/** Maps each {@link QualificationEffect} to its eligibility impact; `condition` remains eligible. */\nexport const EFFECT_ELIGIBILITIES: Readonly<Record<QualificationEffect, Eligibility>> =\n\tObject.freeze({\n\t\trestriction: 'ineligible',\n\t\treferral: 'referral',\n\t\tcondition: 'eligible',\n\t})\n","import type { QualifierErrorCode, QualifierErrorContext } from './types.js'\n\n/**\n * Represents a coded programmer error thrown by the qualifier layer.\n *\n * @remarks\n * `DEFINITION` — a qualification definition failed semantic validation; when\n * `qualify`'s own validation raises it, `context.definition` names the\n * definition, and when an engine throw maps to it, `context.pass` names the pass\n * and `context.cause` preserves the original throw. `MISMATCH` — a subject is\n * not a record or already carries the reserved `qualification` key.\n * `DESTROYED` — use of a destroyed qualifier; an engine-mapped one carries\n * `context.pass` and `context.cause`. `ENGINE` — the underlying reason engine\n * threw while running a pass; `context.pass` names the pass and `context.cause`\n * preserves the original throw. `context` is absent for a throw that carries no\n * payload.\n */\nexport class QualifierError extends Error {\n\treadonly code: QualifierErrorCode\n\treadonly context: QualifierErrorContext | undefined\n\n\tconstructor(code: QualifierErrorCode, message: string, context?: QualifierErrorContext) {\n\t\tsuper(message)\n\t\tthis.name = 'QualifierError'\n\t\tthis.code = code\n\t\tthis.context = context\n\t}\n}\n\n/**\n * Narrows a caught value to a {@link QualifierError}.\n *\n * @param value - The caught value to test\n * @returns True if `value` is a {@link QualifierError} instance; false otherwise\n */\nexport function isQualifierError(value: unknown): value is QualifierError {\n\treturn value instanceof QualifierError\n}\n","import type {\n\tDerivation,\n\tEligibility,\n\tFinding,\n\tPremise,\n\tQualificationDefinition,\n\tQualificationPass,\n\tQualificationResult,\n\tRuling,\n} from './types.js'\nimport {\n\tarrayOf,\n\tisBoolean,\n\tisNumber,\n\tisRecord,\n\tisString,\n\tliteralOf,\n\tobjectOf,\n\trecordOf,\n\twhereOf,\n} from '@orkestrel/contract'\nimport {\n\tisComparison,\n\tisFieldPath,\n\tisLogicalDefinition,\n\tisQuantitativeDefinition,\n} from '@orkestrel/reason'\n\n/**\n * Determines whether a value is an {@link Eligibility} literal.\n *\n * @param value - The value to test\n * @returns True if `value` is one of the eligibility literals; false otherwise\n */\nexport const isEligibility = literalOf('eligible', 'ineligible', 'referral')\n\n/**\n * Determines whether a value is a {@link QualificationEffect} literal.\n *\n * @param value - The value to test\n * @returns True if `value` is one of the effect literals; false otherwise\n */\nexport const isQualificationEffect = literalOf('restriction', 'referral', 'condition')\n\n/**\n * Determines whether a value is an open string-keyed record of {@link Eligibility} values.\n *\n * @remarks\n * Every own string-named property is checked, including non-enumerable properties. Inherited and\n * symbol-named members are left unchecked because they are outside the record this guard certifies.\n *\n * @param value - The value to test\n * @returns True if `value` is a non-array object whose own string-named values are\n * eligibilities; false otherwise\n */\nexport function isEligibilityRecord(\n\tvalue: unknown,\n): value is Readonly<Record<string, Eligibility>> {\n\treturn whereOf(objectOf({}), (record): record is Readonly<Record<string, Eligibility>> =>\n\t\tObject.getOwnPropertyNames(record).every((key) => isEligibility(Reflect.get(record, key))),\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Premise}.\n *\n * @remarks\n * `expected` is unchecked and may be absent or contain any value because its published type is\n * `unknown`. `actual` is unchecked and may be absent or contain any value for the same reason.\n * Unknown members are admitted.\n *\n * @param value - The value to test\n * @returns True if every checked premise member follows its published type; false otherwise\n */\nexport function isPremise(value: unknown): value is Premise {\n\treturn objectOf(\n\t\t{\n\t\t\tfield: isFieldPath,\n\t\t\tlabel: isString,\n\t\t\tdescription: isString,\n\t\t\tcomparison: isComparison,\n\t\t\tmet: isBoolean,\n\t\t},\n\t\t['field', 'label', 'description', 'comparison', 'met'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Finding}.\n *\n * @remarks\n * Unknown members are admitted. Optional `scope` and `message` members may be absent or\n * `undefined`; a present defined value must be a string.\n *\n * @param value - The value to test\n * @returns True if every published finding member is valid; false otherwise\n */\nexport function isFinding(value: unknown): value is Finding {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tpass: isString,\n\t\t\trule: isString,\n\t\t\teffect: isQualificationEffect,\n\t\t\tscope: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tmessage: isString,\n\t\t\tpremises: arrayOf(isPremise),\n\t\t},\n\t\t['scope', 'message'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Derivation}.\n *\n * @remarks\n * Unknown members are admitted. `value` follows the published `number` type, including `NaN` and\n * infinities.\n *\n * @param value - The value to test\n * @returns True if every published derivation member is valid; false otherwise\n */\nexport function isDerivation(value: unknown): value is Derivation {\n\treturn objectOf({\n\t\tid: isString,\n\t\tvalue: isNumber,\n\t\tsuccess: isBoolean,\n\t\ttrace: arrayOf(isString),\n\t\terrors: arrayOf(isString),\n\t})(value)\n}\n\n/**\n * Determines whether a value is an open {@link QualificationResult} returned by a qualifier.\n *\n * @remarks\n * This guard is result-postured for values returned through a borrowed qualifier interface. It\n * admits unknown members and class instances while checking the complete published result closure.\n *\n * @param value - The value to test\n * @returns True if every published qualification-result member is valid; false otherwise\n */\nexport function isQualificationResult(value: unknown): value is QualificationResult {\n\treturn objectOf({\n\t\tid: isString,\n\t\tname: isString,\n\t\teligibility: isEligibility,\n\t\tscopes: isEligibilityRecord,\n\t\tfindings: arrayOf(isFinding),\n\t\tderivations: arrayOf(isDerivation),\n\t\tsuccess: isBoolean,\n\t\ttrace: arrayOf(isString),\n\t\terrors: arrayOf(isString),\n\t})(value)\n}\n\n/**\n * Determines whether a value is a {@link QualificationPass} (a quantitative or logical definition).\n *\n * @param value - The value to test\n * @returns True if `value` is a complete reason quantitative or logical definition; false otherwise\n */\nexport function isQualificationPass(value: unknown): value is QualificationPass {\n\treturn isQuantitativeDefinition(value) || isLogicalDefinition(value)\n}\n\n/**\n * Determines whether a value is an exact {@link Ruling} record.\n *\n * @param value - The value to test\n * @returns True if `value` carries every ruling member and no unknown key; false otherwise\n */\nexport function isRuling(value: unknown): value is Ruling {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tpass: isString,\n\t\t\trule: isString,\n\t\t\teffect: isQualificationEffect,\n\t\t\tscope: isString,\n\t\t\tmessage: isString,\n\t\t},\n\t\t['scope', 'message'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an exact {@link QualificationDefinition} record.\n *\n * @param value - The value to test\n * @returns True if `value` carries every definition member and no unknown key; false otherwise\n */\nexport function isQualificationDefinition(value: unknown): value is QualificationDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tpasses: arrayOf(isQualificationPass),\n\t\t\trulings: arrayOf(isRuling),\n\t\t\tmetadata: isRecord,\n\t\t},\n\t\t['description', 'rulings', 'metadata'],\n\t)(value)\n}\n","import type {\n\tDerivation,\n\tEligibility,\n\tFinding,\n\tPremise,\n\tQualificationContext,\n\tQualificationDefinition,\n\tQualificationPass,\n\tQualificationProjection,\n\tRuling,\n} from './types.js'\nimport type {\n\tCheck,\n\tCheckResult,\n\tEvaluatorInterface,\n\tLogicalDefinition,\n\tLogicalResult,\n\tQuantitativeResult,\n\tReasonResult,\n\tRule,\n\tSubject,\n} from '@orkestrel/reason'\nimport { EFFECT_ELIGIBILITIES, ELIGIBILITY_PRECEDENCE, QUALIFICATION_KEY } from './constants.js'\nimport { QualifierError } from './errors.js'\nimport { isFiniteNumber, isRecord, resolveField } from '@orkestrel/contract'\nimport {\n\textractAtoms,\n\textractConclusions,\n\tformatField,\n\tisBounds,\n\tisReasonError,\n} from '@orkestrel/reason'\n\n/**\n * Interpolates `{{dotted.path}}` tokens in a message template against a subject.\n *\n * @remarks\n * Each token is split on `.` into a `FieldPath` array and resolved with\n * `resolveField` (a plain string field is ONE key, never dot-split — the split\n * here is the token-to-path bridge). A finite number renders with `en-US`\n * thousand grouping (`5010` → `5,010`); any other resolved value String-coerces.\n * An UNRESOLVED path renders as the empty string.\n *\n * @param template - The message template carrying `{{dotted.path}}` tokens\n * @param subject - The record tokens resolve against\n * @returns The template with every token replaced\n *\n * @example\n * ```ts\n * import { interpolateMessage } from '@orkestrel/qualifier'\n *\n * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'\n * interpolateMessage('Missing {{gone}}', {}) // 'Missing '\n * ```\n */\nexport function interpolateMessage(\n\ttemplate: string,\n\tsubject: Readonly<Record<string, unknown>>,\n): string {\n\treturn template.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, (_match, path: string) => {\n\t\tconst value = resolveField(subject, path.split('.'))\n\t\tif (value === undefined) return ''\n\t\tif (isFiniteNumber(value)) return value.toLocaleString('en-US')\n\t\treturn String(value)\n\t})\n}\n\n/**\n * Renders a {@link Premise} comparison as a display-neutral verb phrase.\n *\n * @param comparison - The comparison to describe\n * @returns A display-neutral phrase\n *\n * @example\n * ```ts\n * import { renderComparison } from '@orkestrel/qualifier'\n *\n * renderComparison('above') // 'is more than'\n * ```\n */\nexport function renderComparison(comparison: NonNullable<Premise['comparison']>): string {\n\tswitch (comparison) {\n\t\tcase 'equals':\n\t\t\treturn 'is'\n\t\tcase 'not':\n\t\t\treturn 'is not'\n\t\tcase 'above':\n\t\t\treturn 'is more than'\n\t\tcase 'below':\n\t\t\treturn 'is less than'\n\t\tcase 'from':\n\t\t\treturn 'is at least'\n\t\tcase 'to':\n\t\t\treturn 'is at most'\n\t\tcase 'any':\n\t\t\treturn 'is any of'\n\t\tcase 'none':\n\t\t\treturn 'is none of'\n\t\tcase 'between':\n\t\t\treturn 'is between'\n\t\tcase 'outside':\n\t\t\treturn 'is outside'\n\t}\n}\n\n/**\n * Renders a structured or scalar expected value display-neutrally.\n *\n * @remarks\n * An array renders as its elements, each `String`-coerced, joined with `', '`.\n * A reason `Bounds`-shaped record (the `between` / `outside` expected value)\n * renders its present sides joined with the word `and`; an absent side is\n * omitted. A finite number and everything else fall back to plain `String()` —\n * a finite number is NOT grouped here (grouping is {@link interpolateMessage}'s\n * message-token-only behavior).\n *\n * @param value - The value to render\n * @returns A display-neutral rendering\n *\n * @example\n * ```ts\n * import { renderValue } from '@orkestrel/qualifier'\n *\n * renderValue([18, 25, 40]) // '18, 25, 40'\n * renderValue({ minimum: 18, maximum: 65 }) // '18 and 65'\n * renderValue(42) // '42'\n * ```\n */\nexport function renderValue(value: unknown): string {\n\tif (Array.isArray(value)) return value.map((entry) => String(entry)).join(', ')\n\tif (isBounds(value)) {\n\t\tconst sides: string[] = []\n\t\tif (value.minimum !== undefined) sides.push(String(value.minimum))\n\t\tif (value.maximum !== undefined) sides.push(String(value.maximum))\n\t\treturn sides.join(' and ')\n\t}\n\treturn String(value)\n}\n\n/**\n * Renders one {@link Premise} into a display-neutral sentence.\n *\n * @remarks\n * The checked form renders only when `field` and `comparison` are BOTH\n * present, and `description` then goes unused; a premise missing either half\n * of the checked pair renders as described instead.\n *\n * @param entry - The premise to render\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A display-neutral sentence\n *\n * @example\n * ```ts\n * import { renderPremise } from '@orkestrel/qualifier'\n *\n * renderPremise({ field: 'age', comparison: 'above', expected: 18, actual: 25, met: true })\n * // 'age is more than 18 → met'\n *\n * renderPremise({ description: 'Applicant is enrolled', met: true })\n * // 'Applicant is enrolled → met'\n * ```\n */\nexport function renderPremise(entry: Premise, labels?: Readonly<Record<string, string>>): string {\n\tconst status = entry.met === undefined ? 'unknown' : entry.met ? 'met' : 'not met'\n\tif (entry.field === undefined || entry.comparison === undefined) {\n\t\treturn `${entry.description ?? 'Premise'} → ${status}`\n\t}\n\tconst field = formatField(entry.field)\n\tconst label = labels?.[field] ?? entry.label ?? field\n\tconst expected = entry.expected === undefined ? '' : ` ${renderValue(entry.expected)}`\n\treturn `${label} ${renderComparison(entry.comparison)}${expected} → ${status}`\n}\n\n/**\n * Builds a {@link Premise} from an authored {@link Check} and its evaluated\n * `CheckResult`.\n *\n * @param check - The authored check\n * @param result - The evaluated check result carrying the resolved `actual` and `met`\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh premise\n *\n * @example\n * ```ts\n * import { checkToPremise } from '@orkestrel/qualifier'\n * import { createCheck } from '@orkestrel/reason'\n *\n * const authored = createCheck('age', 'above', 18)\n * checkToPremise(authored, { field: 'age', actual: 25, met: true })\n * // { field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }\n * ```\n */\nexport function checkToPremise(\n\tcheck: Check,\n\tresult: CheckResult,\n\tlabels?: Readonly<Record<string, string>>,\n): Premise {\n\tconst field = formatField(check.field)\n\treturn {\n\t\tfield: check.field,\n\t\t...(labels?.[field] === undefined ? {} : { label: labels[field] }),\n\t\tcomparison: check.operator,\n\t\texpected: check.value,\n\t\tactual: result.actual,\n\t\tmet: result.met,\n\t}\n}\n\n/**\n * Builds rich premises for one fired {@link Rule} by walking its premise atoms\n * and re-evaluating each against the working subject.\n *\n * @remarks\n * A reason rule result carries only booleans, so this is the qualifier's own\n * premise-audit projection: each authored premise expression is flattened to its\n * atom leaves through `extractAtoms`, and each leaf's `Check` is re-evaluated through\n * the injected `evaluator`. A membership check (`any` / `none`) over an EMPTY\n * array value is content-free and is skipped.\n *\n * @param rule - The authored rule\n * @param working - The working subject to evaluate against\n * @param evaluator - The shared reason check evaluator\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh, ordered list of rich premises\n *\n * @example\n * ```ts\n * import { ruleToPremises } from '@orkestrel/qualifier'\n * import { createAtom, createEvaluator, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const evaluator = createEvaluator()\n * const premises = ruleToPremises(gates.rules[0], { licensed: false }, evaluator)\n *\n * premises[0]?.met // true\n * ```\n */\nexport function ruleToPremises(\n\trule: Rule,\n\tworking: Subject,\n\tevaluator: EvaluatorInterface,\n\tlabels?: Readonly<Record<string, string>>,\n): readonly Premise[] {\n\tconst output: Premise[] = []\n\tfor (const premise of rule.premises) {\n\t\tfor (const atom of extractAtoms(premise)) {\n\t\t\tconst { check } = atom\n\t\t\tif (\n\t\t\t\t(check.operator === 'any' || check.operator === 'none') &&\n\t\t\t\tArray.isArray(check.value) &&\n\t\t\t\tcheck.value.length === 0\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\toutput.push(checkToPremise(check, evaluator.evaluate(check, working), labels))\n\t\t}\n\t}\n\treturn output\n}\n\n/**\n * Locates an authored {@link Rule} by id.\n *\n * @param definition - The logical definition to search\n * @param id - The rule id\n * @returns The matching rule, or `undefined`\n *\n * @example\n * ```ts\n * import { findRule } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n *\n * findRule(gates, 'licensed')?.id // 'licensed'\n * ```\n */\nexport function findRule(definition: LogicalDefinition, id: string): Rule | undefined {\n\treturn definition.rules.find((rule) => rule.id === id)\n}\n\n/**\n * Projects one reason result into the internal qualification namespace.\n *\n * @remarks\n * A quantitative result contributes its numeric `value`. A logical result\n * contributes a record of its `conclusion` plus every applied rule's asserted\n * conclusion fields (`extractConclusions`). A mismatched pairing contributes\n * `false`. The projection is pure — it never mutates the subject or the result.\n *\n * @param definition - The pass definition that produced the result\n * @param result - The evaluated reason result\n * @returns The pass's working projection\n *\n * @example\n * ```ts\n * import { reasonResultToProjection } from '@orkestrel/qualifier'\n * import { createFactorGroup, createQuantitativeDefinition, createStaticFactor } from '@orkestrel/reason'\n *\n * const cap = createQuantitativeDefinition('cap', 'TIV cap', [\n * createFactorGroup('limit', 'sum', [createStaticFactor('base', 500_000)]),\n * ])\n * const result = {\n * reasoning: 'quantitative' as const,\n * value: 500_000,\n * groups: [],\n * count: 1,\n * success: true,\n * trace: [],\n * errors: [],\n * }\n * reasonResultToProjection(cap, result) // 500000\n * ```\n */\nexport function reasonResultToProjection(\n\tdefinition: QualificationPass,\n\tresult: ReasonResult,\n): QualificationProjection {\n\tif (definition.reasoning === 'quantitative' && result.reasoning === 'quantitative') {\n\t\treturn result.value\n\t}\n\tif (definition.reasoning !== 'logical' || result.reasoning !== 'logical') return false\n\tconst projection: Record<string, unknown> = { conclusion: result.conclusion }\n\tfor (const resolved of result.rules) {\n\t\tif (!resolved.applied) continue\n\t\tconst authored = definition.rules.find((rule) => rule.id === resolved.id)\n\t\tif (authored === undefined) continue\n\t\tconst conclusions = extractConclusions(authored.conclusion)\n\t\tfor (const [key, value] of Object.entries(conclusions)) projection[key] = value\n\t}\n\treturn projection\n}\n\n/**\n * Projects a quantitative result into a {@link Derivation} audit record.\n *\n * @param id - The pass id\n * @param result - The evaluated quantitative result\n * @returns A fresh derivation\n *\n * @example\n * ```ts\n * import { quantitativeResultToDerivation } from '@orkestrel/qualifier'\n *\n * const result = { reasoning: 'quantitative' as const, value: 500_000, groups: [], count: 1, success: true, trace: ['cap: 500000'], errors: [] }\n * quantitativeResultToDerivation('cap', result)\n * // { id: 'cap', value: 500000, success: true, trace: ['cap: 500000'], errors: [] }\n * ```\n */\nexport function quantitativeResultToDerivation(id: string, result: QuantitativeResult): Derivation {\n\treturn {\n\t\tid,\n\t\tvalue: result.value,\n\t\tsuccess: result.success,\n\t\ttrace: [...result.trace],\n\t\terrors: [...result.errors],\n\t}\n}\n\n/**\n * Wraps a {@link QualificationContext} under {@link QUALIFICATION_KEY}.\n *\n * @param context - The accumulated projection context\n * @returns A record carrying the context under the reserved key\n *\n * @example\n * ```ts\n * import { qualificationToRecord } from '@orkestrel/qualifier'\n *\n * qualificationToRecord({ cap: 500_000 }) // { qualification: { cap: 500000 } }\n * ```\n */\nexport function qualificationToRecord(\n\tcontext: QualificationContext,\n): Readonly<Record<string, QualificationContext>> {\n\treturn { [QUALIFICATION_KEY]: context }\n}\n\n/**\n * Merges one pass projection into the context, copy-on-write.\n *\n * @param context - The current projection context\n * @param id - The pass id to project under\n * @param projection - The pass's working projection\n * @returns A fresh context with the projection added\n *\n * @example\n * ```ts\n * import { mergeQualificationContext } from '@orkestrel/qualifier'\n *\n * mergeQualificationContext({ cap: 500_000 }, 'excess', 250_000)\n * // { cap: 500000, excess: 250000 }\n * ```\n */\nexport function mergeQualificationContext(\n\tcontext: QualificationContext,\n\tid: string,\n\tprojection: QualificationProjection,\n): QualificationContext {\n\treturn { ...context, [id]: projection }\n}\n\n/**\n * Joins a ruling, its logical rule result, the pass, the pre-projection subject,\n * and an evaluator into a {@link Finding}.\n *\n * @remarks\n * `applied` reflects whether the ruling's rule fired. Premises are re-evaluated\n * against the SAME subject snapshot the pass evaluated, so a conclusion the pass\n * derived can never satisfy its own reported premise. The message interpolates\n * against that snapshot.\n *\n * @param ruling - The authored ruling\n * @param pass - The pass the ruling's rule lives in\n * @param result - The pass's evaluated logical result\n * @param subject - The pre-projection subject snapshot the pass evaluated\n * @param evaluator - The shared reason check evaluator\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh finding\n *\n * @example\n * ```ts\n * import { rulingToFinding } from '@orkestrel/qualifier'\n * import { createAtom, createEvaluator, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const ruling = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const }\n * const result = { reasoning: 'logical' as const, conclusion: true, rules: [{ id: 'licensed', applied: true, premises: [true] }], count: 1, success: true, trace: [], errors: [] }\n * const finding = rulingToFinding(ruling, gates, result, { licensed: false }, createEvaluator())\n *\n * finding.applied // true\n * ```\n */\nexport function rulingToFinding(\n\truling: Ruling,\n\tpass: QualificationPass,\n\tresult: LogicalResult,\n\tsubject: Subject,\n\tevaluator: EvaluatorInterface,\n\tlabels?: Readonly<Record<string, string>>,\n): Finding {\n\tconst entry = result.rules.find((resolved) => resolved.id === ruling.rule)\n\tconst applied = entry?.applied ?? false\n\tconst rule = pass.reasoning === 'logical' ? findRule(pass, ruling.rule) : undefined\n\tconst premises = rule === undefined ? [] : ruleToPremises(rule, subject, evaluator, labels)\n\treturn {\n\t\tid: ruling.id,\n\t\tpass: ruling.pass,\n\t\trule: ruling.rule,\n\t\teffect: ruling.effect,\n\t\t...(ruling.scope === undefined ? {} : { scope: ruling.scope }),\n\t\tapplied,\n\t\t...(ruling.message === undefined\n\t\t\t? {}\n\t\t\t: { message: interpolateMessage(ruling.message, subject) }),\n\t\tpremises,\n\t}\n}\n\n/**\n * Derives global eligibility from applied, unscoped findings.\n *\n * @remarks\n * Only findings that both applied and carry no `scope` shape global eligibility.\n * A failed pass contributes a synthetic `referral` (fail-closed), passed through\n * `failed`.\n *\n * @param findings - The resolved findings\n * @param failed - If `true`, adds a synthetic `referral` impact so an operational failure\n * fails closed; if `false`, derives eligibility from the findings alone. Default: `false`\n * @returns The most severe global eligibility\n *\n * @example\n * ```ts\n * import { deriveFindingEligibility } from '@orkestrel/qualifier'\n *\n * const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const, applied: true, premises: [] }\n * deriveFindingEligibility([finding]) // 'ineligible'\n * ```\n */\nexport function deriveFindingEligibility(\n\tfindings: readonly Finding[],\n\tfailed = false,\n): Eligibility {\n\tconst eligibilities = findings\n\t\t.filter((finding) => finding.applied && finding.scope === undefined)\n\t\t.map((finding) => EFFECT_ELIGIBILITIES[finding.effect])\n\tif (failed) eligibilities.push('referral')\n\treturn combineEligibilities(eligibilities)\n}\n\n/**\n * Returns the most severe {@link Eligibility} in a list.\n *\n * @param eligibilities - The eligibilities to combine\n * @returns The most severe eligibility, or `'eligible'` for an empty list\n *\n * @example\n * ```ts\n * import { combineEligibilities } from '@orkestrel/qualifier'\n *\n * combineEligibilities(['eligible', 'referral']) // 'referral'\n * ```\n */\nexport function combineEligibilities(eligibilities: readonly Eligibility[]): Eligibility {\n\tfor (const eligibility of ELIGIBILITY_PRECEDENCE) {\n\t\tif (eligibilities.includes(eligibility)) return eligibility\n\t}\n\treturn 'eligible'\n}\n\n/**\n * Derives one eligibility per finding scope.\n *\n * @remarks\n * Only applied, scoped findings contribute. Each named scope combines its own\n * findings' impacts by severity. An unmentioned scope is absent (eligible by\n * default at the program layer).\n *\n * @param findings - The resolved findings\n * @returns A fresh record of scope to its combined eligibility\n *\n * @example\n * ```ts\n * import { deriveScopeEligibilities } from '@orkestrel/qualifier'\n *\n * const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind', applied: true, premises: [] }\n * deriveScopeEligibilities([finding]) // { wind: 'ineligible' }\n * ```\n */\nexport function deriveScopeEligibilities(\n\tfindings: readonly Finding[],\n): Readonly<Record<string, Eligibility>> {\n\tconst grouped: Record<string, Eligibility[]> = {}\n\tfor (const finding of findings) {\n\t\tif (!finding.applied || finding.scope === undefined) continue\n\t\tconst current = grouped[finding.scope] ?? []\n\t\tgrouped[finding.scope] = [...current, EFFECT_ELIGIBILITIES[finding.effect]]\n\t}\n\tconst scopes: Record<string, Eligibility> = {}\n\tfor (const [scope, eligibilities] of Object.entries(grouped)) {\n\t\tscopes[scope] = combineEligibilities(eligibilities)\n\t}\n\treturn scopes\n}\n\n/**\n * Describes each ruling whose pass or rule does not exist or whose pass is not\n * logical, and each pass id shadowing the reserved {@link QUALIFICATION_KEY}.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of reference-error messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, createRuling, describeMissingReferences } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [gates], {\n * rulings: [createRuling('license', 'gates', 'absent', 'restriction')],\n * })\n *\n * describeMissingReferences(definition)\n * // [\"Ruling 'license' references missing rule 'absent' in pass 'gates'\"]\n * ```\n */\nexport function describeMissingReferences(definition: QualificationDefinition): readonly string[] {\n\tconst errors: string[] = []\n\tconst passes = new Map(definition.passes.map((pass) => [pass.id, pass]))\n\tfor (const pass of definition.passes) {\n\t\tif (pass.id === QUALIFICATION_KEY) {\n\t\t\terrors.push(`Pass id must not equal reserved key '${QUALIFICATION_KEY}'`)\n\t\t}\n\t}\n\tfor (const ruling of definition.rulings ?? []) {\n\t\tconst pass = passes.get(ruling.pass)\n\t\tif (pass === undefined) {\n\t\t\terrors.push(`Ruling '${ruling.id}' references missing pass '${ruling.pass}'`)\n\t\t\tcontinue\n\t\t}\n\t\tif (pass.reasoning !== 'logical') {\n\t\t\terrors.push(`Ruling '${ruling.id}' references non-logical pass '${ruling.pass}'`)\n\t\t\tcontinue\n\t\t}\n\t\tif (findRule(pass, ruling.rule) === undefined) {\n\t\t\terrors.push(\n\t\t\t\t`Ruling '${ruling.id}' references missing rule '${ruling.rule}' in pass '${ruling.pass}'`,\n\t\t\t)\n\t\t}\n\t}\n\treturn errors\n}\n\n/**\n * Determines whether a subject already owns the reserved {@link QUALIFICATION_KEY}.\n *\n * @param subject - The subject to check\n * @returns True if the subject owns the reserved key; false otherwise\n *\n * @example\n * ```ts\n * import { hasReservedKey } from '@orkestrel/qualifier'\n *\n * hasReservedKey({ id: 's1', qualification: {} }) // true\n * ```\n */\nexport function hasReservedKey(subject: Subject): boolean {\n\treturn Object.hasOwn(subject, QUALIFICATION_KEY)\n}\n\n/**\n * Asserts a value is a valid qualification {@link Subject}, narrowing it in place.\n *\n * @param value - The candidate subject to validate\n * @throws {@link QualifierError} `'MISMATCH'` when the value is not a record, or\n * when it already carries the reserved `qualification` key\n *\n * @example\n * ```ts\n * import { assertSubject } from '@orkestrel/qualifier'\n *\n * assertSubject({ id: 's1' }) // narrows to Subject\n * ```\n */\nexport function assertSubject(value: unknown): asserts value is Subject {\n\tif (!isRecord(value)) {\n\t\tthrow new QualifierError('MISMATCH', 'Qualification subject must be a record')\n\t}\n\tif (hasReservedKey(value)) {\n\t\tthrow new QualifierError(\n\t\t\t'MISMATCH',\n\t\t\t`Qualification subject must not contain reserved key '${QUALIFICATION_KEY}'`,\n\t\t)\n\t}\n}\n\n/**\n * Maps an engine throw caught while running one pass to a typed {@link QualifierError}.\n *\n * @remarks\n * A reason `ReasonError('INVALID')` maps to `DEFINITION` (the engine rejected the\n * pass as an invalid definition); `ReasonError('DESTROYED')` maps to `DESTROYED`;\n * every other `ReasonError` code (for example `MISSING`) and every non-`ReasonError` throw\n * (including a `bail: true` reasoner rethrow) maps to `ENGINE`. The original throw\n * is preserved as `context.cause`.\n *\n * @param error - The value caught from the engine's `reason` call\n * @param pass - The id of the pass that was running\n * @returns A fresh, typed {@link QualifierError}\n *\n * @example\n * ```ts\n * import { mapEngineError } from '@orkestrel/qualifier'\n * import { ReasonError } from '@orkestrel/reason'\n *\n * mapEngineError(new ReasonError('MISSING', 'No reasoner registered'), 'cap').code // 'ENGINE'\n * ```\n */\nexport function mapEngineError(error: unknown, pass: string): QualifierError {\n\tif (isReasonError(error)) {\n\t\tif (error.code === 'INVALID') {\n\t\t\treturn new QualifierError(\n\t\t\t\t'DEFINITION',\n\t\t\t\t`Pass '${pass}' failed engine validation: ${error.message}`,\n\t\t\t\t{ pass, cause: error },\n\t\t\t)\n\t\t}\n\t\tif (error.code === 'DESTROYED') {\n\t\t\treturn new QualifierError(\n\t\t\t\t'DESTROYED',\n\t\t\t\t`Qualifier engine was destroyed during pass '${pass}'`,\n\t\t\t\t{ pass, cause: error },\n\t\t\t)\n\t\t}\n\t\treturn new QualifierError('ENGINE', `Pass '${pass}' engine failure: ${error.message}`, {\n\t\t\tpass,\n\t\t\tcause: error,\n\t\t})\n\t}\n\tconst message = error instanceof Error ? error.message : String(error)\n\treturn new QualifierError('ENGINE', `Pass '${pass}' engine failure: ${message}`, {\n\t\tpass,\n\t\tcause: error,\n\t})\n}\n\n/**\n * Describes each logical pass carrying no rulings.\n *\n * @remarks\n * A logical pass with no matching ruling can never contribute a finding, so its\n * rules only ever influence later passes' reads — this is very likely an authoring\n * oversight.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of warning messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, describeEmptyLogicalPasses } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [gates])\n *\n * describeEmptyLogicalPasses(definition) // [\"Logical pass 'gates' has no rulings\"]\n * ```\n */\nexport function describeEmptyLogicalPasses(definition: QualificationDefinition): readonly string[] {\n\tconst warnings: string[] = []\n\tfor (const pass of definition.passes) {\n\t\tif (pass.reasoning !== 'logical') continue\n\t\tconst hasRuling = (definition.rulings ?? []).some((ruling) => ruling.pass === pass.id)\n\t\tif (!hasRuling) warnings.push(`Logical pass '${pass.id}' has no rulings`)\n\t}\n\treturn warnings\n}\n\n/**\n * Describes each quantitative pass never read by a later pass.\n *\n * @remarks\n * A quantitative pass's projected value lives under `qualification.<id>` — if no\n * later logical premise or quantitative factor field reads that key, the\n * derivation is dead weight. Reads are collected per later pass: a logical pass's\n * premise atoms (conclusion atoms are writes, not reads), and a quantitative\n * pass's field/lookup/range factor sources plus factor checks.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of warning messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, describeUnreadDerivations } from '@orkestrel/qualifier'\n * import { createFactorGroup, createQuantitativeDefinition, createStaticFactor } from '@orkestrel/reason'\n *\n * const cap = createQuantitativeDefinition('cap', 'TIV cap', [\n * createFactorGroup('limit', 'sum', [createStaticFactor('base', 500_000)]),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [cap])\n *\n * describeUnreadDerivations(definition) // [\"Quantitative pass 'cap' is never read by a later pass\"]\n * ```\n */\nexport function describeUnreadDerivations(definition: QualificationDefinition): readonly string[] {\n\tconst warnings: string[] = []\n\tdefinition.passes.forEach((pass, index) => {\n\t\tif (pass.reasoning !== 'quantitative') return\n\t\tconst key = formatField(['qualification', pass.id])\n\t\tconst reads = new Set<string>()\n\t\tfor (const later of definition.passes.slice(index + 1)) {\n\t\t\tif (later.reasoning === 'logical') {\n\t\t\t\tfor (const rule of later.rules) {\n\t\t\t\t\tfor (const premise of rule.premises) {\n\t\t\t\t\t\tfor (const atom of extractAtoms(premise)) reads.add(formatField(atom.check.field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (later.reasoning === 'quantitative') {\n\t\t\t\tfor (const group of later.groups) {\n\t\t\t\t\tfor (const factor of group.factors) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tfactor.source.origin === 'field' ||\n\t\t\t\t\t\t\tfactor.source.origin === 'lookup' ||\n\t\t\t\t\t\t\tfactor.source.origin === 'range'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treads.add(formatField(factor.source.field))\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const check of factor.checks ?? []) reads.add(formatField(check.field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!reads.has(key)) {\n\t\t\twarnings.push(`Quantitative pass '${pass.id}' is never read by a later pass`)\n\t\t}\n\t})\n\treturn warnings\n}\n","import type {\n\tDerivation,\n\tFinding,\n\tQualificationContext,\n\tQualificationDefinition,\n\tQualificationResult,\n\tQualifierEventMap,\n\tQualifierInterface,\n\tQualifierOptions,\n} from './types.js'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tEvaluatorInterface,\n\tReasonInterface,\n\tReasonResult,\n\tReasonValidationResult,\n\tSubject,\n} from '@orkestrel/reason'\nimport { DEFAULT_QUALIFIER_VALIDATE } from './constants.js'\nimport { QualifierError } from './errors.js'\nimport {\n\tassertSubject,\n\tdescribeEmptyLogicalPasses,\n\tdescribeMissingReferences,\n\tdescribeUnreadDerivations,\n\tderiveFindingEligibility,\n\tderiveScopeEligibilities,\n\tmapEngineError,\n\tmergeQualificationContext,\n\tqualificationToRecord,\n\tquantitativeResultToDerivation,\n\treasonResultToProjection,\n\trulingToFinding,\n} from './helpers.js'\nimport { isQualificationPass, isRuling } from './validators.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport {\n\tcreateEvaluator,\n\tcreateLogicalReasoner,\n\tcreateQuantitativeReasoner,\n\tcreateReason,\n\tfindDuplicates,\n} from '@orkestrel/reason'\n\n/**\n * Runs ordered passes over one reason engine and returns eligibility.\n *\n * @remarks\n * The engine is OWNED when self-created (destroyed on `destroy()`) and borrowed\n * when injected (never destroyed). `qualify` builds its working subject through\n * copy-on-write overlays only — the caller's `subject` is never mutated, and the\n * qualifier's internal projection is discarded after each call.\n */\nexport class Qualifier implements QualifierInterface {\n\treadonly #emitter: Emitter<QualifierEventMap>\n\treadonly #engine: ReasonInterface\n\treadonly #evaluator: EvaluatorInterface\n\treadonly #owned: boolean\n\treadonly #validate: boolean\n\treadonly #labels: Readonly<Record<string, string>> | undefined\n\t#destroyed = false\n\n\tconstructor(options?: QualifierOptions) {\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(options?.on === undefined ? {} : { on: options.on }),\n\t\t\t...(options?.error === undefined ? {} : { error: options.error }),\n\t\t})\n\t\tthis.#evaluator = createEvaluator()\n\t\tthis.#owned = options?.engine === undefined\n\t\tthis.#engine =\n\t\t\toptions?.engine ??\n\t\t\tcreateReason({\n\t\t\t\treasoners: [\n\t\t\t\t\tcreateQuantitativeReasoner({ evaluator: this.#evaluator }),\n\t\t\t\t\tcreateLogicalReasoner({ evaluator: this.#evaluator }),\n\t\t\t\t],\n\t\t\t\tbail: false,\n\t\t\t})\n\t\tthis.#validate = options?.validate ?? DEFAULT_QUALIFIER_VALIDATE\n\t\tthis.#labels = options?.labels\n\t}\n\n\t/**\n\t * Holds the typed observation surface carrying `derive`, `finding`, `qualify`, and\n\t * `destroy`.\n\t *\n\t * @returns The emitter this qualifier owns\n\t *\n\t * @example\n\t * ```ts\n\t * import { Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.emitter.on('qualify', (result) => console.log(result.eligibility))\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tget emitter(): EmitterInterface<QualifierEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/**\n\t * Qualifies one subject against one authored definition.\n\t *\n\t * @remarks\n\t * Semantic validation runs first when the `validate` option is on, so an invalid\n\t * definition throws before any pass runs. Passes run in authored order over a\n\t * copy-on-write working subject, and the caller's `subject` is never mutated. An\n\t * unscoped restriction stops the remaining passes because no later finding can be\n\t * more severe.\n\t *\n\t * @param subject - The record to qualify\n\t * @param definition - The authored qualification definition\n\t * @returns A fresh, frozen qualification result\n\t * @throws {@link QualifierError} `'DEFINITION'` when validation is enabled and the\n\t * definition fails semantic validation, or when the engine rejects a pass as an invalid\n\t * definition; `'MISMATCH'` when the subject is not a record or already carries the\n\t * reserved `qualification` key; `'DESTROYED'` after `destroy`, or when the engine\n\t * reports itself destroyed mid-pass; `'ENGINE'` for every other engine throw\n\t *\n\t * @example\n\t * ```ts\n\t * import { createQualificationDefinition, createRuling, Qualifier } from '@orkestrel/qualifier'\n\t * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n\t *\n\t * const gates = createLogicalDefinition('gates', 'Eligibility gates', [\n\t * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n\t * ])\n\t * const definition = createQualificationDefinition('standard', 'Standard eligibility', [gates], {\n\t * rulings: [createRuling('license', 'gates', 'licensed', 'restriction')],\n\t * })\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.qualify({ id: 'risk-1', licensed: false }, definition).eligibility // 'ineligible'\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tqualify(subject: Subject, definition: QualificationDefinition): QualificationResult {\n\t\tthis.#alive()\n\t\tif (this.#validate) {\n\t\t\tconst validation = this.validate(definition)\n\t\t\tif (!validation.valid) {\n\t\t\t\tthrow new QualifierError(\n\t\t\t\t\t'DEFINITION',\n\t\t\t\t\t`Qualification definition is invalid: ${validation.errors.join(', ')}`,\n\t\t\t\t\t{ definition: definition.id },\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn this.#qualify(subject, definition)\n\t}\n\n\t/**\n\t * Validates one authored definition semantically, without running it.\n\t *\n\t * @remarks\n\t * Structural shape is `isQualificationDefinition`'s job. This checks the meaning:\n\t * non-empty id and name, valid and uniquely identified passes and rulings, every\n\t * ruling reference resolving to a logical pass and one of its rules, and no pass id\n\t * shadowing `QUALIFICATION_KEY`. An empty definition, a logical pass carrying no\n\t * ruling, and a derivation no later pass reads are warnings rather than errors.\n\t *\n\t * @param definition - The authored qualification definition\n\t * @returns A fresh validation result carrying `valid`, `errors`, and `warnings`\n\t * @throws {@link QualifierError} `'DESTROYED'` after `destroy`\n\t *\n\t * @example\n\t * ```ts\n\t * import { createQualificationDefinition, Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.validate(createQualificationDefinition('empty', 'Empty', []))\n\t * // { valid: true, errors: [], warnings: ['Definition has no passes'] }\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tvalidate(definition: QualificationDefinition): ReasonValidationResult {\n\t\tthis.#alive()\n\t\tconst errors: string[] = []\n\t\tconst warnings: string[] = []\n\t\tif (definition.id.length === 0) errors.push('Definition id must not be empty')\n\t\tif (definition.name.length === 0) errors.push('Definition name must not be empty')\n\t\tdefinition.passes.forEach((pass, index) => {\n\t\t\tif (!isQualificationPass(pass)) {\n\t\t\t\terrors.push(`Pass at index ${index} is not a valid qualification pass`)\n\t\t\t}\n\t\t})\n\t\t;(definition.rulings ?? []).forEach((ruling, index) => {\n\t\t\tif (!isRuling(ruling)) errors.push(`Ruling at index ${index} is not a valid ruling`)\n\t\t})\n\t\tfor (const id of findDuplicates(definition.passes)) errors.push(`Duplicate pass id '${id}'`)\n\t\tfor (const id of findDuplicates(definition.rulings ?? [])) {\n\t\t\terrors.push(`Duplicate ruling id '${id}'`)\n\t\t}\n\t\tfor (const reference of describeMissingReferences(definition)) errors.push(reference)\n\t\tif (definition.passes.length === 0) warnings.push('Definition has no passes')\n\t\tfor (const warning of describeEmptyLogicalPasses(definition)) warnings.push(warning)\n\t\tfor (const warning of describeUnreadDerivations(definition)) warnings.push(warning)\n\t\treturn { valid: errors.length === 0, errors, warnings }\n\t}\n\n\t/**\n\t * Destroys this qualifier, idempotently.\n\t *\n\t * @remarks\n\t * An engine this qualifier created is destroyed; an injected engine stays\n\t * caller-owned and is left alone. The `destroy` event fires before the emitter\n\t * itself is destroyed, and a later call returns without re-emitting.\n\t *\n\t * @example\n\t * ```ts\n\t * import { Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.destroy()\n\t * qualifier.destroy() // idempotent\n\t * ```\n\t */\n\tdestroy(): void {\n\t\tif (this.#destroyed) return\n\t\tif (this.#owned) this.#engine.destroy()\n\t\tthis.#destroyed = true\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#emitter.destroy()\n\t}\n\n\t#qualify(subject: Subject, definition: QualificationDefinition): QualificationResult {\n\t\tassertSubject(subject)\n\t\tlet context: QualificationContext = {}\n\t\tlet working: Subject = { ...subject }\n\t\tconst findings: Finding[] = []\n\t\tconst derivations: Derivation[] = []\n\t\tconst trace: string[] = []\n\t\tconst errors: string[] = []\n\t\tlet failed = false\n\n\t\tfor (const pass of definition.passes) {\n\t\t\tthis.#alive()\n\t\t\tconst evaluated = working\n\t\t\tlet result: ReasonResult\n\t\t\ttry {\n\t\t\t\tresult = this.#engine.reason(evaluated, pass)\n\t\t\t} catch (error) {\n\t\t\t\tthrow mapEngineError(error, pass.id)\n\t\t\t}\n\n\t\t\ttrace.push(...result.trace.map((entry) => `${pass.id}: ${entry}`))\n\t\t\terrors.push(...result.errors.map((entry) => `${pass.id}: ${entry}`))\n\n\t\t\tif (result.reasoning === 'quantitative') {\n\t\t\t\tconst derivation = quantitativeResultToDerivation(pass.id, result)\n\t\t\t\tderivations.push(derivation)\n\t\t\t\tthis.#emitter.emit('derive', derivation)\n\t\t\t}\n\n\t\t\tif (result.reasoning === 'logical') {\n\t\t\t\tconst rulings = (definition.rulings ?? []).filter((ruling) => ruling.pass === pass.id)\n\t\t\t\tfor (const ruling of rulings) {\n\t\t\t\t\tconst finding = rulingToFinding(\n\t\t\t\t\t\truling,\n\t\t\t\t\t\tpass,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tevaluated,\n\t\t\t\t\t\tthis.#evaluator,\n\t\t\t\t\t\tthis.#labels,\n\t\t\t\t\t)\n\t\t\t\t\tfindings.push(finding)\n\t\t\t\t\tthis.#emitter.emit('finding', finding)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst projection = reasonResultToProjection(pass, result)\n\t\t\tcontext = mergeQualificationContext(context, pass.id, projection)\n\t\t\tworking = { ...subject, ...qualificationToRecord(context) }\n\n\t\t\tif (!result.success) {\n\t\t\t\tfailed = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif (deriveFindingEligibility(findings) === 'ineligible') break\n\t\t}\n\n\t\tconst success = !failed && errors.length === 0\n\t\tconst scopes = deriveScopeEligibilities(findings)\n\t\tconst qualification: QualificationResult = Object.freeze({\n\t\t\tid: definition.id,\n\t\t\tname: definition.name,\n\t\t\teligibility: deriveFindingEligibility(findings, !success),\n\t\t\tscopes: Object.freeze(scopes),\n\t\t\tfindings: Object.freeze(findings),\n\t\t\tderivations: Object.freeze(derivations),\n\t\t\tsuccess,\n\t\t\ttrace: Object.freeze(trace),\n\t\t\terrors: Object.freeze(errors),\n\t\t})\n\t\tthis.#emitter.emit('qualify', qualification)\n\t\treturn qualification\n\t}\n\n\t#alive(): void {\n\t\tif (this.#destroyed) {\n\t\t\tthrow new QualifierError('DESTROYED', 'Qualifier has been destroyed')\n\t\t}\n\t}\n}\n","import type {\n\tQualificationDefinition,\n\tQualificationEffect,\n\tQualificationInput,\n\tQualificationPass,\n\tQualifierInterface,\n\tQualifierOptions,\n\tRuling,\n\tRulingInput,\n} from './types.js'\nimport { Qualifier } from './Qualifier.js'\n\n/**\n * Creates one qualifier over a reason engine.\n *\n * @remarks\n * A standalone qualifier creates and OWNS one shared quantitative-plus-logical\n * reason engine, destroying it on `destroy()`. An injected `options.engine`\n * remains caller-owned and is never destroyed. `validate` runs semantic\n * validation before every qualification. Default: `true`. `labels` overrides the\n * display name of a premise field, keyed by the dot-joined field path\n * `formatField` produces, and takes precedence over a premise's own `label`.\n *\n * @param options - Optional injected engine, validation, labels, and emitter hooks\n * @returns A {@link QualifierInterface}\n *\n * @example\n * ```ts\n * import { createQualifier } from '@orkestrel/qualifier'\n *\n * const qualifier = createQualifier()\n * qualifier.qualify({ id: 'risk-1' }, definition)\n * qualifier.destroy()\n * ```\n */\nexport function createQualifier(options?: QualifierOptions): QualifierInterface {\n\treturn new Qualifier(options)\n}\n\n/**\n * Creates a {@link QualificationDefinition}.\n *\n * @remarks\n * Returns a fresh top-level definition, omitting absent optional keys;\n * `passes` and `rulings` arrays are copied, and record `metadata` is\n * shallow-copied so nested values are not deep-cloned.\n *\n * @param id - The definition id\n * @param name - The display name\n * @param passes - The ordered qualification passes\n * @param input - Optional description, rulings, and metadata\n * @returns A fresh qualification definition\n *\n * @example\n * ```ts\n * import { createQualificationDefinition } from '@orkestrel/qualifier'\n *\n * createQualificationDefinition('standard', 'Standard', [gates], { rulings: [ruling] })\n * ```\n */\nexport function createQualificationDefinition(\n\tid: string,\n\tname: string,\n\tpasses: readonly QualificationPass[],\n\tinput?: QualificationInput,\n): QualificationDefinition {\n\treturn {\n\t\tid,\n\t\tname,\n\t\tpasses: [...passes],\n\t\t...(input?.description === undefined ? {} : { description: input.description }),\n\t\t...(input?.rulings === undefined ? {} : { rulings: [...input.rulings] }),\n\t\t...(input?.metadata === undefined ? {} : { metadata: { ...input.metadata } }),\n\t}\n}\n\n/**\n * Creates a {@link Ruling} — one authored consequence for one rule in one pass.\n *\n * @param id - The ruling id\n * @param pass - The logical pass id the rule lives in\n * @param rule - The rule id whose firing this ruling reacts to\n * @param effect - The eligibility impact when the rule fires\n * @param input - Optional selection scope and message template\n * @returns A fresh ruling\n *\n * @example\n * ```ts\n * import { createRuling } from '@orkestrel/qualifier'\n *\n * createRuling('license', 'gates', 'licensed', 'restriction', { message: 'A license is required' })\n * ```\n */\nexport function createRuling(\n\tid: string,\n\tpass: string,\n\trule: string,\n\teffect: QualificationEffect,\n\tinput?: RulingInput,\n): Ruling {\n\treturn {\n\t\tid,\n\t\tpass,\n\t\trule,\n\t\teffect,\n\t\t...(input?.scope === undefined ? {} : { scope: input.scope }),\n\t\t...(input?.message === undefined ? {} : { message: input.message }),\n\t}\n}\n"],"mappings":";;;;;;AAGA,IAAa,6BAA6B;;AAG1C,IAAa,oBAAoB;;AAGjC,IAAa,yBAAiD,OAAO,OAAO;CAC3E;CACA;CACA;AACD,CAAC;;AAGD,IAAa,uBACZ,OAAO,OAAO;CACb,aAAa;CACb,UAAU;CACV,WAAW;AACZ,CAAC;;;;;;;;;;;;;;;;;;ACJF,IAAa,iBAAb,cAAoC,MAAM;CACzC;CACA;CAEA,YAAY,MAA0B,SAAiB,SAAiC;EACvF,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,UAAU;CAChB;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OAAO,iBAAiB;AACzB;;;;;;;;;ACHA,IAAa,iBAAA,GAAgB,oBAAA,UAAA,CAAU,YAAY,cAAc,UAAU;;;;;;;AAQ3E,IAAa,yBAAA,GAAwB,oBAAA,UAAA,CAAU,eAAe,YAAY,WAAW;;;;;;;;;;;;AAarF,SAAgB,oBACf,OACiD;CACjD,QAAA,GAAO,oBAAA,QAAA,EAAA,GAAQ,oBAAA,SAAA,CAAS,CAAC,CAAC,IAAI,WAC7B,OAAO,oBAAoB,MAAM,CAAC,CAAC,OAAO,QAAQ,cAAc,QAAQ,IAAI,QAAQ,GAAG,CAAC,CAAC,CAC1F,CAAC,CAAC,KAAK;AACR;;;;;;;;;;;;AAaA,SAAgB,UAAU,OAAkC;CAC3D,QAAA,GAAO,oBAAA,SAAA,CACN;EACC,OAAO,kBAAA;EACP,OAAO,oBAAA;EACP,aAAa,oBAAA;EACb,YAAY,kBAAA;EACZ,KAAK,oBAAA;CACN,GACA;EAAC;EAAS;EAAS;EAAe;EAAc;CAAK,CACtD,CAAC,CAAC,KAAK;AACR;;;;;;;;;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Y,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,EAAE;EACtE,GAAI,OAAO,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,SAAS,EAAE;CAC5E;AACD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aACf,IACA,MACA,MACA,QACA,OACS;CACT,OAAO;EACN;EACA;EACA;EACA;EACA,GAAI,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO,MAAM,MAAM;EAC3D,GAAI,OAAO,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM,QAAQ;CAClE;AACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/Qualifier.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { Eligibility, QualificationEffect } from './types.js'\n\n/**\n * Holds the default definition validation policy for `createQualifier` and\n * `Qualifier.qualify`, `true`.\n */\nexport const DEFAULT_QUALIFIER_VALIDATE = true\n\n/**\n * Names `'qualification'`, the reserved internal projection namespace a pass's working\n * projection is written under.\n */\nexport const QUALIFICATION_KEY = 'qualification'\n\n/** Lists the eligibility severities most to least severe: `ineligible`, `referral`, `eligible`. */\nexport const ELIGIBILITY_PRECEDENCE: readonly Eligibility[] = Object.freeze([\n\t'ineligible',\n\t'referral',\n\t'eligible',\n])\n\n/**\n * Maps each {@link QualificationEffect} to its eligibility impact — `restriction` to\n * `ineligible`, `referral` to `referral`, and `condition` to `eligible`.\n */\nexport const EFFECT_ELIGIBILITIES: Readonly<Record<QualificationEffect, Eligibility>> =\n\tObject.freeze({\n\t\trestriction: 'ineligible',\n\t\treferral: 'referral',\n\t\tcondition: 'eligible',\n\t})\n","import type { QualifierErrorCode, QualifierErrorContext } from './types.js'\n\n/**\n * Represents a coded programmer error thrown by the qualifier layer, carrying a\n * `QualifierErrorCode` and an optional context record.\n *\n * @remarks\n * `DEFINITION` — a qualification definition failed semantic validation; when\n * `qualify`'s own validation raises it, `context.definition` names the\n * definition, and when an engine throw maps to it, `context.pass` names the pass\n * and `context.cause` preserves the original throw. `MISMATCH` — a subject is\n * not a record or already carries the reserved `qualification` key.\n * `DESTROYED` — use of a destroyed qualifier; an engine-mapped one carries\n * `context.pass` and `context.cause`. `ENGINE` — the underlying reason engine\n * threw while running a pass; `context.pass` names the pass and `context.cause`\n * preserves the original throw. `context` is absent for a throw that carries no\n * payload.\n */\nexport class QualifierError extends Error {\n\treadonly code: QualifierErrorCode\n\treadonly context: QualifierErrorContext | undefined\n\n\tconstructor(code: QualifierErrorCode, message: string, context?: QualifierErrorContext) {\n\t\tsuper(message)\n\t\tthis.name = 'QualifierError'\n\t\tthis.code = code\n\t\tthis.context = context\n\t}\n}\n\n/**\n * Narrows a caught value to a {@link QualifierError}.\n *\n * @param value - The caught value to test\n * @returns True if `value` is a {@link QualifierError} instance; false otherwise\n */\nexport function isQualifierError(value: unknown): value is QualifierError {\n\treturn value instanceof QualifierError\n}\n","import type {\n\tDerivation,\n\tEligibility,\n\tFinding,\n\tPremise,\n\tQualificationDefinition,\n\tQualificationPass,\n\tQualificationResult,\n\tRuling,\n} from './types.js'\nimport {\n\tarrayOf,\n\tisBoolean,\n\tisNumber,\n\tisRecord,\n\tisString,\n\tliteralOf,\n\tobjectOf,\n\trecordOf,\n\twhereOf,\n} from '@orkestrel/contract'\nimport {\n\tisComparison,\n\tisFieldPath,\n\tisLogicalDefinition,\n\tisQuantitativeDefinition,\n} from '@orkestrel/reason'\n\n/**\n * Determines whether a value is an {@link Eligibility} literal.\n *\n * @remarks\n * The guard is total and leaves nothing unchecked: a scalar union has no open or exact\n * axis.\n *\n * @param value - The value to test\n * @returns True if `value` is one of the eligibility literals; false otherwise\n */\nexport const isEligibility = literalOf('eligible', 'ineligible', 'referral')\n\n/**\n * Determines whether a value is a {@link QualificationEffect} literal.\n *\n * @remarks\n * The guard is total and leaves nothing unchecked: a scalar union has no open or exact\n * axis.\n *\n * @param value - The value to test\n * @returns True if `value` is one of the effect literals; false otherwise\n */\nexport const isQualificationEffect = literalOf('restriction', 'referral', 'condition')\n\n/**\n * Determines whether a value is an open string-keyed record of {@link Eligibility} values.\n *\n * @remarks\n * Every own string-named value is checked through {@link isEligibility}, including\n * non-enumerable values. Inherited and symbol-named members are left unchecked because they\n * are outside the own string-keyed record this guard certifies.\n *\n * @param value - The value to test\n * @returns True if `value` is a non-array object whose own string-named values are\n * eligibilities; false otherwise\n */\nexport function isEligibilityRecord(\n\tvalue: unknown,\n): value is Readonly<Record<string, Eligibility>> {\n\treturn whereOf(objectOf({}), (record): record is Readonly<Record<string, Eligibility>> =>\n\t\tObject.getOwnPropertyNames(record).every((key) => isEligibility(Reflect.get(record, key))),\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Premise}.\n *\n * @remarks\n * The optional `field`, `label`, `description`, `comparison`, and `met` members are checked\n * when they are defined. `expected` is unchecked and may be absent or contain any value\n * because its published type is `unknown`. `actual` is unchecked and may be absent or contain\n * any value for the same reason. Unknown members are admitted, because an open result admits\n * what the published contract does not name.\n *\n * @param value - The value to test\n * @returns True if every checked premise member follows its published type; false otherwise\n */\nexport function isPremise(value: unknown): value is Premise {\n\treturn objectOf(\n\t\t{\n\t\t\tfield: isFieldPath,\n\t\t\tlabel: isString,\n\t\t\tdescription: isString,\n\t\t\tcomparison: isComparison,\n\t\t\tmet: isBoolean,\n\t\t},\n\t\t['field', 'label', 'description', 'comparison', 'met'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Finding}.\n *\n * @remarks\n * Every published member is checked, including each nested {@link Premise}. Optional `scope`\n * and `message` members may be absent or `undefined`; a present defined value must be a\n * string. Unknown members are admitted, because a foreign result implementation may add them\n * without changing the published contract.\n *\n * @param value - The value to test\n * @returns True if every published finding member is valid; false otherwise\n */\nexport function isFinding(value: unknown): value is Finding {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tpass: isString,\n\t\t\trule: isString,\n\t\t\teffect: isQualificationEffect,\n\t\t\tscope: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tmessage: isString,\n\t\t\tpremises: arrayOf(isPremise),\n\t\t},\n\t\t['scope', 'message'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Derivation}.\n *\n * @remarks\n * Every published member is checked: `value` follows the published `number` type, including\n * `NaN` and the infinities, and `trace` and `errors` hold strings. Unknown members are\n * admitted, because a foreign result implementation may add them without changing the\n * published contract.\n *\n * @param value - The value to test\n * @returns True if every published derivation member is valid; false otherwise\n */\nexport function isDerivation(value: unknown): value is Derivation {\n\treturn objectOf({\n\t\tid: isString,\n\t\tvalue: isNumber,\n\t\tsuccess: isBoolean,\n\t\ttrace: arrayOf(isString),\n\t\terrors: arrayOf(isString),\n\t})(value)\n}\n\n/**\n * Determines whether a value is an open {@link QualificationResult} returned by a qualifier.\n *\n * @remarks\n * This guard is result-postured for values returned through a borrowed qualifier interface. It\n * checks the complete published result closure — eligibility, scope values, findings,\n * derivations, success, and the audit trail — and admits unknown members and class instances,\n * because a borrowed `QualifierInterface` implementation may add them beyond the\n * published contract.\n *\n * @param value - The value to test\n * @returns True if every published qualification-result member is valid; false otherwise\n */\nexport function isQualificationResult(value: unknown): value is QualificationResult {\n\treturn objectOf({\n\t\tid: isString,\n\t\tname: isString,\n\t\teligibility: isEligibility,\n\t\tscopes: isEligibilityRecord,\n\t\tfindings: arrayOf(isFinding),\n\t\tderivations: arrayOf(isDerivation),\n\t\tsuccess: isBoolean,\n\t\ttrace: arrayOf(isString),\n\t\terrors: arrayOf(isString),\n\t})(value)\n}\n\n/**\n * Determines whether a value is a {@link QualificationPass} (a quantitative or logical definition).\n *\n * @remarks\n * The guard is exact and requires either complete reason shape, the quantitative definition or\n * the logical one. Nothing is left unchecked, because the reason package owns both authored\n * input shapes.\n *\n * @param value - The value to test\n * @returns True if `value` is a complete reason quantitative or logical definition; false otherwise\n */\nexport function isQualificationPass(value: unknown): value is QualificationPass {\n\treturn isQuantitativeDefinition(value) || isLogicalDefinition(value)\n}\n\n/**\n * Determines whether a value is an exact {@link Ruling} record.\n *\n * @remarks\n * Every authored ruling member and the complete key set are checked. Nothing is left\n * unchecked, because this package owns the authored input record.\n *\n * @param value - The value to test\n * @returns True if `value` carries every ruling member and no unknown key; false otherwise\n */\nexport function isRuling(value: unknown): value is Ruling {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tpass: isString,\n\t\t\trule: isString,\n\t\t\teffect: isQualificationEffect,\n\t\t\tscope: isString,\n\t\t\tmessage: isString,\n\t\t},\n\t\t['scope', 'message'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an exact {@link QualificationDefinition} record.\n *\n * @remarks\n * Every authored definition member, the nested pass and ruling shapes, and the complete key\n * set are checked. Nothing is left unchecked, because this package owns the authored input\n * record.\n *\n * @param value - The value to test\n * @returns True if `value` carries every definition member and no unknown key; false otherwise\n */\nexport function isQualificationDefinition(value: unknown): value is QualificationDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tpasses: arrayOf(isQualificationPass),\n\t\t\trulings: arrayOf(isRuling),\n\t\t\tmetadata: isRecord,\n\t\t},\n\t\t['description', 'rulings', 'metadata'],\n\t)(value)\n}\n","import type {\n\tDerivation,\n\tEligibility,\n\tFinding,\n\tPremise,\n\tQualificationContext,\n\tQualificationDefinition,\n\tQualificationPass,\n\tQualificationProjection,\n\tRuling,\n} from './types.js'\nimport type {\n\tCheck,\n\tCheckResult,\n\tEvaluatorInterface,\n\tLogicalDefinition,\n\tLogicalResult,\n\tQuantitativeResult,\n\tReasonResult,\n\tRule,\n\tSubject,\n} from '@orkestrel/reason'\nimport { EFFECT_ELIGIBILITIES, ELIGIBILITY_PRECEDENCE, QUALIFICATION_KEY } from './constants.js'\nimport { QualifierError } from './errors.js'\nimport { isFiniteNumber, isRecord, resolveField } from '@orkestrel/contract'\nimport {\n\textractAtoms,\n\textractConclusions,\n\tformatField,\n\tisBounds,\n\tisReasonError,\n} from '@orkestrel/reason'\n\n/**\n * Interpolates `{{dotted.path}}` tokens in a message template against a subject.\n *\n * @remarks\n * Each token is split on `.` into a `FieldPath` array and resolved with\n * `resolveField` (a plain string field is one key, never dot-split — the split\n * here is the token-to-path bridge). A finite number renders with `en-US`\n * thousand grouping (`5010` → `5,010`); any other resolved value String-coerces.\n * An unresolved path renders as the empty string.\n *\n * @param template - The message template carrying `{{dotted.path}}` tokens\n * @param subject - The record tokens resolve against\n * @returns The template with every token replaced\n *\n * @example\n * ```ts\n * import { interpolateMessage } from '@orkestrel/qualifier'\n *\n * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'\n * interpolateMessage('Missing {{gone}}', {}) // 'Missing '\n * ```\n */\nexport function interpolateMessage(\n\ttemplate: string,\n\tsubject: Readonly<Record<string, unknown>>,\n): string {\n\treturn template.replace(/\\{\\{\\s*([^}]+?)\\s*\\}\\}/g, (_match, path: string) => {\n\t\tconst value = resolveField(subject, path.split('.'))\n\t\tif (value === undefined) return ''\n\t\tif (isFiniteNumber(value)) return value.toLocaleString('en-US')\n\t\treturn String(value)\n\t})\n}\n\n/**\n * Renders a {@link Premise} comparison as a display-neutral verb phrase.\n *\n * @param comparison - The comparison to describe\n * @returns A display-neutral phrase\n *\n * @example\n * ```ts\n * import { renderComparison } from '@orkestrel/qualifier'\n *\n * renderComparison('above') // 'is more than'\n * ```\n */\nexport function renderComparison(comparison: NonNullable<Premise['comparison']>): string {\n\tswitch (comparison) {\n\t\tcase 'equals':\n\t\t\treturn 'is'\n\t\tcase 'not':\n\t\t\treturn 'is not'\n\t\tcase 'above':\n\t\t\treturn 'is more than'\n\t\tcase 'below':\n\t\t\treturn 'is less than'\n\t\tcase 'from':\n\t\t\treturn 'is at least'\n\t\tcase 'to':\n\t\t\treturn 'is at most'\n\t\tcase 'any':\n\t\t\treturn 'is any of'\n\t\tcase 'none':\n\t\t\treturn 'is none of'\n\t\tcase 'between':\n\t\t\treturn 'is between'\n\t\tcase 'outside':\n\t\t\treturn 'is outside'\n\t}\n}\n\n/**\n * Renders a structured or scalar expected value display-neutrally.\n *\n * @remarks\n * An array renders as its elements, each `String`-coerced, joined with `', '`.\n * A reason `Bounds`-shaped record (the `between` / `outside` expected value)\n * renders its present sides joined with the word `and`; an absent side is\n * omitted. A finite number and everything else fall back to plain `String()` —\n * a finite number is not grouped here (grouping is {@link interpolateMessage}'s\n * message-token-only behavior).\n *\n * @param value - The value to render\n * @returns A display-neutral rendering\n *\n * @example\n * ```ts\n * import { renderValue } from '@orkestrel/qualifier'\n *\n * renderValue([18, 25, 40]) // '18, 25, 40'\n * renderValue({ minimum: 18, maximum: 65 }) // '18 and 65'\n * renderValue(42) // '42'\n * ```\n */\nexport function renderValue(value: unknown): string {\n\tif (Array.isArray(value)) return value.map((entry) => String(entry)).join(', ')\n\tif (isBounds(value)) {\n\t\tconst sides: string[] = []\n\t\tif (value.minimum !== undefined) sides.push(String(value.minimum))\n\t\tif (value.maximum !== undefined) sides.push(String(value.maximum))\n\t\treturn sides.join(' and ')\n\t}\n\treturn String(value)\n}\n\n/**\n * Renders one {@link Premise} into a display-neutral sentence.\n *\n * @remarks\n * The checked form renders only when `field` and `comparison` are both\n * present, and `description` then goes unused; a premise missing either half\n * of the checked pair renders as described instead.\n *\n * @param entry - The premise to render\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A display-neutral sentence\n *\n * @example\n * ```ts\n * import { renderPremise } from '@orkestrel/qualifier'\n *\n * renderPremise({ field: 'age', comparison: 'above', expected: 18, actual: 25, met: true })\n * // 'age is more than 18 → met'\n *\n * renderPremise({ description: 'Applicant is enrolled', met: true })\n * // 'Applicant is enrolled → met'\n * ```\n */\nexport function renderPremise(entry: Premise, labels?: Readonly<Record<string, string>>): string {\n\tconst status = entry.met === undefined ? 'unknown' : entry.met ? 'met' : 'not met'\n\tif (entry.field === undefined || entry.comparison === undefined) {\n\t\treturn `${entry.description ?? 'Premise'} → ${status}`\n\t}\n\tconst field = formatField(entry.field)\n\tconst label = labels?.[field] ?? entry.label ?? field\n\tconst expected = entry.expected === undefined ? '' : ` ${renderValue(entry.expected)}`\n\treturn `${label} ${renderComparison(entry.comparison)}${expected} → ${status}`\n}\n\n/**\n * Builds a {@link Premise} from an authored {@link Check} and its evaluated\n * `CheckResult`.\n *\n * @param check - The authored check\n * @param result - The evaluated check result carrying the resolved `actual` and `met`\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh premise\n *\n * @example\n * ```ts\n * import { checkToPremise } from '@orkestrel/qualifier'\n * import { createCheck } from '@orkestrel/reason'\n *\n * const authored = createCheck('age', 'above', 18)\n * checkToPremise(authored, { field: 'age', actual: 25, met: true })\n * // { field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }\n * ```\n */\nexport function checkToPremise(\n\tcheck: Check,\n\tresult: CheckResult,\n\tlabels?: Readonly<Record<string, string>>,\n): Premise {\n\tconst field = formatField(check.field)\n\treturn {\n\t\tfield: check.field,\n\t\t...(labels?.[field] === undefined ? {} : { label: labels[field] }),\n\t\tcomparison: check.operator,\n\t\texpected: check.value,\n\t\tactual: result.actual,\n\t\tmet: result.met,\n\t}\n}\n\n/**\n * Builds rich premises for one fired {@link Rule} by walking its premise atoms\n * and re-evaluating each against the working subject.\n *\n * @remarks\n * A reason rule result carries only booleans, so this is the qualifier's own\n * premise-audit projection: each authored premise expression is flattened to its\n * atom leaves through `extractAtoms`, and each leaf's `Check` is re-evaluated through\n * the injected `evaluator`. A membership check (`any` / `none`) over an empty\n * array value is content-free and is skipped.\n *\n * @param rule - The authored rule\n * @param working - The working subject to evaluate against\n * @param evaluator - The shared reason check evaluator\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh, ordered list of rich premises\n *\n * @example\n * ```ts\n * import { ruleToPremises } from '@orkestrel/qualifier'\n * import { createAtom, createEvaluator, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const evaluator = createEvaluator()\n * const premises = ruleToPremises(gates.rules[0], { licensed: false }, evaluator)\n *\n * premises[0]?.met // true\n * ```\n */\nexport function ruleToPremises(\n\trule: Rule,\n\tworking: Subject,\n\tevaluator: EvaluatorInterface,\n\tlabels?: Readonly<Record<string, string>>,\n): readonly Premise[] {\n\tconst output: Premise[] = []\n\tfor (const premise of rule.premises) {\n\t\tfor (const atom of extractAtoms(premise)) {\n\t\t\tconst { check } = atom\n\t\t\tif (\n\t\t\t\t(check.operator === 'any' || check.operator === 'none') &&\n\t\t\t\tArray.isArray(check.value) &&\n\t\t\t\tcheck.value.length === 0\n\t\t\t) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\toutput.push(checkToPremise(check, evaluator.evaluate(check, working), labels))\n\t\t}\n\t}\n\treturn output\n}\n\n/**\n * Locates an authored {@link Rule} by id.\n *\n * @param definition - The logical definition to search\n * @param id - The rule id\n * @returns The matching rule, or `undefined`\n *\n * @example\n * ```ts\n * import { findRule } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n *\n * findRule(gates, 'licensed')?.id // 'licensed'\n * ```\n */\nexport function findRule(definition: LogicalDefinition, id: string): Rule | undefined {\n\treturn definition.rules.find((rule) => rule.id === id)\n}\n\n/**\n * Projects one reason result into the internal qualification namespace.\n *\n * @remarks\n * A quantitative result contributes its numeric `value`. A logical result\n * contributes a record of its `conclusion` plus every applied rule's asserted\n * conclusion fields (`extractConclusions`). A mismatched pairing contributes\n * `false`. The projection is pure — it never mutates the subject or the result.\n *\n * @param definition - The pass definition that produced the result\n * @param result - The evaluated reason result\n * @returns The pass's working projection\n *\n * @example\n * ```ts\n * import { reasonResultToProjection } from '@orkestrel/qualifier'\n * import { createFactorGroup, createQuantitativeDefinition, createStaticFactor } from '@orkestrel/reason'\n *\n * const cap = createQuantitativeDefinition('cap', 'TIV cap', [\n * createFactorGroup('limit', 'sum', [createStaticFactor('base', 500_000)]),\n * ])\n * const result = {\n * reasoning: 'quantitative' as const,\n * value: 500_000,\n * groups: [],\n * count: 1,\n * success: true,\n * trace: [],\n * errors: [],\n * }\n * reasonResultToProjection(cap, result) // 500000\n * ```\n */\nexport function reasonResultToProjection(\n\tdefinition: QualificationPass,\n\tresult: ReasonResult,\n): QualificationProjection {\n\tif (definition.reasoning === 'quantitative' && result.reasoning === 'quantitative') {\n\t\treturn result.value\n\t}\n\tif (definition.reasoning !== 'logical' || result.reasoning !== 'logical') return false\n\tconst projection: Record<string, unknown> = { conclusion: result.conclusion }\n\tfor (const resolved of result.rules) {\n\t\tif (!resolved.applied) continue\n\t\tconst authored = definition.rules.find((rule) => rule.id === resolved.id)\n\t\tif (authored === undefined) continue\n\t\tconst conclusions = extractConclusions(authored.conclusion)\n\t\tfor (const [key, value] of Object.entries(conclusions)) projection[key] = value\n\t}\n\treturn projection\n}\n\n/**\n * Projects a quantitative result into a {@link Derivation} audit record.\n *\n * @param id - The pass id\n * @param result - The evaluated quantitative result\n * @returns A fresh derivation\n *\n * @example\n * ```ts\n * import { quantitativeResultToDerivation } from '@orkestrel/qualifier'\n *\n * const result = { reasoning: 'quantitative' as const, value: 500_000, groups: [], count: 1, success: true, trace: ['cap: 500000'], errors: [] }\n * quantitativeResultToDerivation('cap', result)\n * // { id: 'cap', value: 500000, success: true, trace: ['cap: 500000'], errors: [] }\n * ```\n */\nexport function quantitativeResultToDerivation(id: string, result: QuantitativeResult): Derivation {\n\treturn {\n\t\tid,\n\t\tvalue: result.value,\n\t\tsuccess: result.success,\n\t\ttrace: [...result.trace],\n\t\terrors: [...result.errors],\n\t}\n}\n\n/**\n * Wraps a {@link QualificationContext} under {@link QUALIFICATION_KEY}.\n *\n * @param context - The accumulated projection context\n * @returns A record carrying the context under the reserved key\n *\n * @example\n * ```ts\n * import { qualificationToRecord } from '@orkestrel/qualifier'\n *\n * qualificationToRecord({ cap: 500_000 }) // { qualification: { cap: 500000 } }\n * ```\n */\nexport function qualificationToRecord(\n\tcontext: QualificationContext,\n): Readonly<Record<string, QualificationContext>> {\n\treturn { [QUALIFICATION_KEY]: context }\n}\n\n/**\n * Merges one pass projection into the context, copy-on-write.\n *\n * @param context - The current projection context\n * @param id - The pass id to project under\n * @param projection - The pass's working projection\n * @returns A fresh context with the projection added\n *\n * @example\n * ```ts\n * import { mergeQualificationContext } from '@orkestrel/qualifier'\n *\n * mergeQualificationContext({ cap: 500_000 }, 'excess', 250_000)\n * // { cap: 500000, excess: 250000 }\n * ```\n */\nexport function mergeQualificationContext(\n\tcontext: QualificationContext,\n\tid: string,\n\tprojection: QualificationProjection,\n): QualificationContext {\n\treturn { ...context, [id]: projection }\n}\n\n/**\n * Joins a ruling, its logical rule result, the pass, the pre-projection subject,\n * and an evaluator into a {@link Finding}.\n *\n * @remarks\n * `applied` reflects whether the ruling's rule fired. Premises are re-evaluated\n * against the same subject snapshot the pass evaluated, so a conclusion the pass\n * derived can never satisfy its own reported premise. The message interpolates\n * against that snapshot.\n *\n * @param ruling - The authored ruling\n * @param pass - The pass the ruling's rule lives in\n * @param result - The pass's evaluated logical result\n * @param subject - The pre-projection subject snapshot the pass evaluated\n * @param evaluator - The shared reason check evaluator\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh finding\n *\n * @example\n * ```ts\n * import { rulingToFinding } from '@orkestrel/qualifier'\n * import { createAtom, createEvaluator, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const ruling = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const }\n * const result = { reasoning: 'logical' as const, conclusion: true, rules: [{ id: 'licensed', applied: true, premises: [true] }], count: 1, success: true, trace: [], errors: [] }\n * const finding = rulingToFinding(ruling, gates, result, { licensed: false }, createEvaluator())\n *\n * finding.applied // true\n * ```\n */\nexport function rulingToFinding(\n\truling: Ruling,\n\tpass: QualificationPass,\n\tresult: LogicalResult,\n\tsubject: Subject,\n\tevaluator: EvaluatorInterface,\n\tlabels?: Readonly<Record<string, string>>,\n): Finding {\n\tconst entry = result.rules.find((resolved) => resolved.id === ruling.rule)\n\tconst applied = entry?.applied ?? false\n\tconst rule = pass.reasoning === 'logical' ? findRule(pass, ruling.rule) : undefined\n\tconst premises = rule === undefined ? [] : ruleToPremises(rule, subject, evaluator, labels)\n\treturn {\n\t\tid: ruling.id,\n\t\tpass: ruling.pass,\n\t\trule: ruling.rule,\n\t\teffect: ruling.effect,\n\t\t...(ruling.scope === undefined ? {} : { scope: ruling.scope }),\n\t\tapplied,\n\t\t...(ruling.message === undefined\n\t\t\t? {}\n\t\t\t: { message: interpolateMessage(ruling.message, subject) }),\n\t\tpremises,\n\t}\n}\n\n/**\n * Derives global eligibility from applied, unscoped findings.\n *\n * @remarks\n * Only findings that both applied and carry no `scope` shape global eligibility.\n * A failed pass contributes a synthetic `referral` (fail-closed), passed through\n * `failed`.\n *\n * @param findings - The resolved findings\n * @param failed - If `true`, adds a synthetic `referral` impact so an operational failure\n * fails closed; if `false`, derives eligibility from the findings alone. Default: `false`\n * @returns The most severe global eligibility\n *\n * @example\n * ```ts\n * import { deriveFindingEligibility } from '@orkestrel/qualifier'\n *\n * const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const, applied: true, premises: [] }\n * deriveFindingEligibility([finding]) // 'ineligible'\n * ```\n */\nexport function deriveFindingEligibility(\n\tfindings: readonly Finding[],\n\tfailed = false,\n): Eligibility {\n\tconst eligibilities = findings\n\t\t.filter((finding) => finding.applied && finding.scope === undefined)\n\t\t.map((finding) => EFFECT_ELIGIBILITIES[finding.effect])\n\tif (failed) eligibilities.push('referral')\n\treturn combineEligibilities(eligibilities)\n}\n\n/**\n * Returns the most severe {@link Eligibility} in a list.\n *\n * @param eligibilities - The eligibilities to combine\n * @returns The most severe eligibility, or `'eligible'` for an empty list\n *\n * @example\n * ```ts\n * import { combineEligibilities } from '@orkestrel/qualifier'\n *\n * combineEligibilities(['eligible', 'referral']) // 'referral'\n * ```\n */\nexport function combineEligibilities(eligibilities: readonly Eligibility[]): Eligibility {\n\tfor (const eligibility of ELIGIBILITY_PRECEDENCE) {\n\t\tif (eligibilities.includes(eligibility)) return eligibility\n\t}\n\treturn 'eligible'\n}\n\n/**\n * Derives one eligibility per finding scope.\n *\n * @remarks\n * Only applied, scoped findings contribute. Each named scope combines its own\n * findings' impacts by severity. An unmentioned scope is absent (eligible by\n * default at the program layer).\n *\n * @param findings - The resolved findings\n * @returns A fresh record of scope to its combined eligibility\n *\n * @example\n * ```ts\n * import { deriveScopeEligibilities } from '@orkestrel/qualifier'\n *\n * const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind', applied: true, premises: [] }\n * deriveScopeEligibilities([finding]) // { wind: 'ineligible' }\n * ```\n */\nexport function deriveScopeEligibilities(\n\tfindings: readonly Finding[],\n): Readonly<Record<string, Eligibility>> {\n\tconst grouped: Record<string, Eligibility[]> = {}\n\tfor (const finding of findings) {\n\t\tif (!finding.applied || finding.scope === undefined) continue\n\t\tconst current = grouped[finding.scope] ?? []\n\t\tgrouped[finding.scope] = [...current, EFFECT_ELIGIBILITIES[finding.effect]]\n\t}\n\tconst scopes: Record<string, Eligibility> = {}\n\tfor (const [scope, eligibilities] of Object.entries(grouped)) {\n\t\tscopes[scope] = combineEligibilities(eligibilities)\n\t}\n\treturn scopes\n}\n\n/**\n * Describes each ruling whose pass or rule does not exist or whose pass is not\n * logical, and each pass id shadowing the reserved {@link QUALIFICATION_KEY}.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of reference-error messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, createRuling, describeMissingReferences } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [gates], {\n * rulings: [createRuling('license', 'gates', 'absent', 'restriction')],\n * })\n *\n * describeMissingReferences(definition)\n * // [\"Ruling 'license' references missing rule 'absent' in pass 'gates'\"]\n * ```\n */\nexport function describeMissingReferences(definition: QualificationDefinition): readonly string[] {\n\tconst errors: string[] = []\n\tconst passes = new Map(definition.passes.map((pass) => [pass.id, pass]))\n\tfor (const pass of definition.passes) {\n\t\tif (pass.id === QUALIFICATION_KEY) {\n\t\t\terrors.push(`Pass id must not equal reserved key '${QUALIFICATION_KEY}'`)\n\t\t}\n\t}\n\tfor (const ruling of definition.rulings ?? []) {\n\t\tconst pass = passes.get(ruling.pass)\n\t\tif (pass === undefined) {\n\t\t\terrors.push(`Ruling '${ruling.id}' references missing pass '${ruling.pass}'`)\n\t\t\tcontinue\n\t\t}\n\t\tif (pass.reasoning !== 'logical') {\n\t\t\terrors.push(`Ruling '${ruling.id}' references non-logical pass '${ruling.pass}'`)\n\t\t\tcontinue\n\t\t}\n\t\tif (findRule(pass, ruling.rule) === undefined) {\n\t\t\terrors.push(\n\t\t\t\t`Ruling '${ruling.id}' references missing rule '${ruling.rule}' in pass '${ruling.pass}'`,\n\t\t\t)\n\t\t}\n\t}\n\treturn errors\n}\n\n/**\n * Determines whether a subject already owns the reserved {@link QUALIFICATION_KEY}.\n *\n * @param subject - The subject to check\n * @returns True if the subject owns the reserved key; false otherwise\n *\n * @example\n * ```ts\n * import { hasReservedKey } from '@orkestrel/qualifier'\n *\n * hasReservedKey({ id: 's1', qualification: {} }) // true\n * ```\n */\nexport function hasReservedKey(subject: Subject): boolean {\n\treturn Object.hasOwn(subject, QUALIFICATION_KEY)\n}\n\n/**\n * Asserts a value is a valid qualification {@link Subject}, narrowing it in place.\n *\n * @param value - The candidate subject to validate\n * @throws {@link QualifierError} `'MISMATCH'` when the value is not a record, or\n * when it already carries the reserved `qualification` key\n *\n * @example\n * ```ts\n * import { assertSubject } from '@orkestrel/qualifier'\n *\n * assertSubject({ id: 's1' }) // narrows to Subject\n * ```\n */\nexport function assertSubject(value: unknown): asserts value is Subject {\n\tif (!isRecord(value)) {\n\t\tthrow new QualifierError('MISMATCH', 'Qualification subject must be a record')\n\t}\n\tif (hasReservedKey(value)) {\n\t\tthrow new QualifierError(\n\t\t\t'MISMATCH',\n\t\t\t`Qualification subject must not contain reserved key '${QUALIFICATION_KEY}'`,\n\t\t)\n\t}\n}\n\n/**\n * Maps an engine throw caught while running one pass to a typed {@link QualifierError}.\n *\n * @remarks\n * A reason `ReasonError('INVALID')` maps to `DEFINITION` (the engine rejected the\n * pass as an invalid definition); `ReasonError('DESTROYED')` maps to `DESTROYED`;\n * every other `ReasonError` code (for example `MISSING`) and every non-`ReasonError` throw\n * (including a `bail: true` reasoner rethrow) maps to `ENGINE`. The original throw\n * is preserved as `context.cause`.\n *\n * @param error - The value caught from the engine's `reason` call\n * @param pass - The id of the pass that was running\n * @returns A fresh, typed {@link QualifierError}\n *\n * @example\n * ```ts\n * import { mapEngineError } from '@orkestrel/qualifier'\n * import { ReasonError } from '@orkestrel/reason'\n *\n * mapEngineError(new ReasonError('MISSING', 'No reasoner registered'), 'cap').code // 'ENGINE'\n * ```\n */\nexport function mapEngineError(error: unknown, pass: string): QualifierError {\n\tif (isReasonError(error)) {\n\t\tif (error.code === 'INVALID') {\n\t\t\treturn new QualifierError(\n\t\t\t\t'DEFINITION',\n\t\t\t\t`Pass '${pass}' failed engine validation: ${error.message}`,\n\t\t\t\t{ pass, cause: error },\n\t\t\t)\n\t\t}\n\t\tif (error.code === 'DESTROYED') {\n\t\t\treturn new QualifierError(\n\t\t\t\t'DESTROYED',\n\t\t\t\t`Qualifier engine was destroyed during pass '${pass}'`,\n\t\t\t\t{ pass, cause: error },\n\t\t\t)\n\t\t}\n\t\treturn new QualifierError('ENGINE', `Pass '${pass}' engine failure: ${error.message}`, {\n\t\t\tpass,\n\t\t\tcause: error,\n\t\t})\n\t}\n\tconst message = error instanceof Error ? error.message : String(error)\n\treturn new QualifierError('ENGINE', `Pass '${pass}' engine failure: ${message}`, {\n\t\tpass,\n\t\tcause: error,\n\t})\n}\n\n/**\n * Describes each logical pass carrying no rulings.\n *\n * @remarks\n * A logical pass with no matching ruling can never contribute a finding, so its\n * rules only ever influence later passes' reads — this is very likely an authoring\n * oversight.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of warning messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, describeEmptyLogicalPasses } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Gates', [\n * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [gates])\n *\n * describeEmptyLogicalPasses(definition) // [\"Logical pass 'gates' has no rulings\"]\n * ```\n */\nexport function describeEmptyLogicalPasses(definition: QualificationDefinition): readonly string[] {\n\tconst warnings: string[] = []\n\tfor (const pass of definition.passes) {\n\t\tif (pass.reasoning !== 'logical') continue\n\t\tconst hasRuling = (definition.rulings ?? []).some((ruling) => ruling.pass === pass.id)\n\t\tif (!hasRuling) warnings.push(`Logical pass '${pass.id}' has no rulings`)\n\t}\n\treturn warnings\n}\n\n/**\n * Describes each quantitative pass never read by a later pass.\n *\n * @remarks\n * A quantitative pass's projected value lives under `qualification.<id>` — if no\n * later logical premise or quantitative factor field reads that key, the\n * derivation is dead weight. Reads are collected per later pass: a logical pass's\n * premise atoms (conclusion atoms are writes, not reads), and a quantitative\n * pass's field/lookup/range factor sources plus factor checks.\n *\n * @param definition - The qualification definition to check\n * @returns A fresh list of warning messages\n *\n * @example\n * ```ts\n * import { createQualificationDefinition, describeUnreadDerivations } from '@orkestrel/qualifier'\n * import { createFactorGroup, createQuantitativeDefinition, createStaticFactor } from '@orkestrel/reason'\n *\n * const cap = createQuantitativeDefinition('cap', 'TIV cap', [\n * createFactorGroup('limit', 'sum', [createStaticFactor('base', 500_000)]),\n * ])\n * const definition = createQualificationDefinition('standard', 'Standard', [cap])\n *\n * describeUnreadDerivations(definition) // [\"Quantitative pass 'cap' is never read by a later pass\"]\n * ```\n */\nexport function describeUnreadDerivations(definition: QualificationDefinition): readonly string[] {\n\tconst warnings: string[] = []\n\tdefinition.passes.forEach((pass, index) => {\n\t\tif (pass.reasoning !== 'quantitative') return\n\t\tconst key = formatField(['qualification', pass.id])\n\t\tconst reads = new Set<string>()\n\t\tfor (const later of definition.passes.slice(index + 1)) {\n\t\t\tif (later.reasoning === 'logical') {\n\t\t\t\tfor (const rule of later.rules) {\n\t\t\t\t\tfor (const premise of rule.premises) {\n\t\t\t\t\t\tfor (const atom of extractAtoms(premise)) reads.add(formatField(atom.check.field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (later.reasoning === 'quantitative') {\n\t\t\t\tfor (const group of later.groups) {\n\t\t\t\t\tfor (const factor of group.factors) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tfactor.source.origin === 'field' ||\n\t\t\t\t\t\t\tfactor.source.origin === 'lookup' ||\n\t\t\t\t\t\t\tfactor.source.origin === 'range'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treads.add(formatField(factor.source.field))\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const check of factor.checks ?? []) reads.add(formatField(check.field))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!reads.has(key)) {\n\t\t\twarnings.push(`Quantitative pass '${pass.id}' is never read by a later pass`)\n\t\t}\n\t})\n\treturn warnings\n}\n","import type {\n\tDerivation,\n\tFinding,\n\tQualificationContext,\n\tQualificationDefinition,\n\tQualificationResult,\n\tQualifierEventMap,\n\tQualifierInterface,\n\tQualifierOptions,\n} from './types.js'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tEvaluatorInterface,\n\tReasonInterface,\n\tReasonResult,\n\tReasonValidationResult,\n\tSubject,\n} from '@orkestrel/reason'\nimport { DEFAULT_QUALIFIER_VALIDATE } from './constants.js'\nimport { QualifierError } from './errors.js'\nimport {\n\tassertSubject,\n\tdescribeEmptyLogicalPasses,\n\tdescribeMissingReferences,\n\tdescribeUnreadDerivations,\n\tderiveFindingEligibility,\n\tderiveScopeEligibilities,\n\tmapEngineError,\n\tmergeQualificationContext,\n\tqualificationToRecord,\n\tquantitativeResultToDerivation,\n\treasonResultToProjection,\n\trulingToFinding,\n} from './helpers.js'\nimport { isQualificationPass, isRuling } from './validators.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport {\n\tcreateEvaluator,\n\tcreateLogicalReasoner,\n\tcreateQuantitativeReasoner,\n\tcreateReason,\n\tfindDuplicates,\n} from '@orkestrel/reason'\n\n/**\n * Runs ordered passes over one reason engine and returns eligibility.\n *\n * @remarks\n * The engine is owned when self-created (destroyed on `destroy()`) and borrowed\n * when injected (never destroyed). Semantic validation runs before the first pass\n * whenever the `validate` option is on. `qualify` builds its working subject through\n * copy-on-write overlays only — the caller's `subject` is never mutated, and the\n * qualifier's internal projection is discarded after each call.\n */\nexport class Qualifier implements QualifierInterface {\n\treadonly #emitter: Emitter<QualifierEventMap>\n\treadonly #engine: ReasonInterface\n\treadonly #evaluator: EvaluatorInterface\n\treadonly #owned: boolean\n\treadonly #validate: boolean\n\treadonly #labels: Readonly<Record<string, string>> | undefined\n\t#destroyed = false\n\n\tconstructor(options?: QualifierOptions) {\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(options?.on === undefined ? {} : { on: options.on }),\n\t\t\t...(options?.error === undefined ? {} : { error: options.error }),\n\t\t})\n\t\tthis.#evaluator = createEvaluator()\n\t\tthis.#owned = options?.engine === undefined\n\t\tthis.#engine =\n\t\t\toptions?.engine ??\n\t\t\tcreateReason({\n\t\t\t\treasoners: [\n\t\t\t\t\tcreateQuantitativeReasoner({ evaluator: this.#evaluator }),\n\t\t\t\t\tcreateLogicalReasoner({ evaluator: this.#evaluator }),\n\t\t\t\t],\n\t\t\t\tbail: false,\n\t\t\t})\n\t\tthis.#validate = options?.validate ?? DEFAULT_QUALIFIER_VALIDATE\n\t\tthis.#labels = options?.labels\n\t}\n\n\t/**\n\t * Holds the typed observation surface carrying `derive`, `finding`, `qualify`, and\n\t * `destroy`.\n\t *\n\t * @returns The emitter this qualifier owns\n\t *\n\t * @example\n\t * ```ts\n\t * import { Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.emitter.on('qualify', (result) => console.log(result.eligibility))\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tget emitter(): EmitterInterface<QualifierEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/**\n\t * Qualifies one subject against one authored definition.\n\t *\n\t * @remarks\n\t * Semantic validation runs first when the `validate` option is on, so an invalid\n\t * definition throws before any pass runs. Passes run in authored order over a\n\t * copy-on-write working subject, and the caller's `subject` is never mutated. An\n\t * unscoped restriction stops the remaining passes because no later finding can be\n\t * more severe.\n\t *\n\t * @param subject - The record to qualify\n\t * @param definition - The authored qualification definition\n\t * @returns A fresh, frozen qualification result\n\t * @throws {@link QualifierError} `'DEFINITION'` when validation is enabled and the\n\t * definition fails semantic validation, or when the engine rejects a pass as an invalid\n\t * definition; `'MISMATCH'` when the subject is not a record or already carries the\n\t * reserved `qualification` key; `'DESTROYED'` after `destroy`, or when the engine\n\t * reports itself destroyed mid-pass; `'ENGINE'` for every other engine throw\n\t *\n\t * @example\n\t * ```ts\n\t * import { createQualificationDefinition, createRuling, Qualifier } from '@orkestrel/qualifier'\n\t * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n\t *\n\t * const gates = createLogicalDefinition('gates', 'Eligibility gates', [\n\t * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),\n\t * ])\n\t * const definition = createQualificationDefinition('standard', 'Standard eligibility', [gates], {\n\t * rulings: [createRuling('license', 'gates', 'licensed', 'restriction')],\n\t * })\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.qualify({ id: 'risk-1', licensed: false }, definition).eligibility // 'ineligible'\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tqualify(subject: Subject, definition: QualificationDefinition): QualificationResult {\n\t\tthis.#alive()\n\t\tif (this.#validate) {\n\t\t\tconst validation = this.validate(definition)\n\t\t\tif (!validation.valid) {\n\t\t\t\tthrow new QualifierError(\n\t\t\t\t\t'DEFINITION',\n\t\t\t\t\t`Qualification definition is invalid: ${validation.errors.join(', ')}`,\n\t\t\t\t\t{ definition: definition.id },\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn this.#qualify(subject, definition)\n\t}\n\n\t/**\n\t * Validates one authored definition semantically, without running it.\n\t *\n\t * @remarks\n\t * Structural shape is `isQualificationDefinition`'s job. This checks the meaning:\n\t * non-empty id and name, valid and uniquely identified passes and rulings, every\n\t * ruling reference resolving to a logical pass and one of its rules, and no pass id\n\t * shadowing `QUALIFICATION_KEY`. An empty definition, a logical pass carrying no\n\t * ruling, and a derivation no later pass reads are warnings rather than errors.\n\t *\n\t * @param definition - The authored qualification definition\n\t * @returns A fresh validation result carrying `valid`, `errors`, and `warnings`\n\t * @throws {@link QualifierError} `'DESTROYED'` after `destroy`\n\t *\n\t * @example\n\t * ```ts\n\t * import { createQualificationDefinition, Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.validate(createQualificationDefinition('empty', 'Empty', []))\n\t * // { valid: true, errors: [], warnings: ['Definition has no passes'] }\n\t * qualifier.destroy()\n\t * ```\n\t */\n\tvalidate(definition: QualificationDefinition): ReasonValidationResult {\n\t\tthis.#alive()\n\t\tconst errors: string[] = []\n\t\tconst warnings: string[] = []\n\t\tif (definition.id.length === 0) errors.push('Definition id must not be empty')\n\t\tif (definition.name.length === 0) errors.push('Definition name must not be empty')\n\t\tdefinition.passes.forEach((pass, index) => {\n\t\t\tif (!isQualificationPass(pass)) {\n\t\t\t\terrors.push(`Pass at index ${index} is not a valid qualification pass`)\n\t\t\t}\n\t\t})\n\t\t;(definition.rulings ?? []).forEach((ruling, index) => {\n\t\t\tif (!isRuling(ruling)) errors.push(`Ruling at index ${index} is not a valid ruling`)\n\t\t})\n\t\tfor (const id of findDuplicates(definition.passes)) errors.push(`Duplicate pass id '${id}'`)\n\t\tfor (const id of findDuplicates(definition.rulings ?? [])) {\n\t\t\terrors.push(`Duplicate ruling id '${id}'`)\n\t\t}\n\t\tfor (const reference of describeMissingReferences(definition)) errors.push(reference)\n\t\tif (definition.passes.length === 0) warnings.push('Definition has no passes')\n\t\tfor (const warning of describeEmptyLogicalPasses(definition)) warnings.push(warning)\n\t\tfor (const warning of describeUnreadDerivations(definition)) warnings.push(warning)\n\t\treturn { valid: errors.length === 0, errors, warnings }\n\t}\n\n\t/**\n\t * Destroys this qualifier, idempotently.\n\t *\n\t * @remarks\n\t * An engine this qualifier created is destroyed; an injected engine stays\n\t * caller-owned and is left alone. The `destroy` event fires before the emitter\n\t * itself is destroyed, and a later call returns without re-emitting.\n\t *\n\t * @example\n\t * ```ts\n\t * import { Qualifier } from '@orkestrel/qualifier'\n\t *\n\t * const qualifier = new Qualifier()\n\t * qualifier.destroy()\n\t * qualifier.destroy() // idempotent\n\t * ```\n\t */\n\tdestroy(): void {\n\t\tif (this.#destroyed) return\n\t\tif (this.#owned) this.#engine.destroy()\n\t\tthis.#destroyed = true\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#emitter.destroy()\n\t}\n\n\t#qualify(subject: Subject, definition: QualificationDefinition): QualificationResult {\n\t\tassertSubject(subject)\n\t\tlet context: QualificationContext = {}\n\t\tlet working: Subject = { ...subject }\n\t\tconst findings: Finding[] = []\n\t\tconst derivations: Derivation[] = []\n\t\tconst trace: string[] = []\n\t\tconst errors: string[] = []\n\t\tlet failed = false\n\n\t\tfor (const pass of definition.passes) {\n\t\t\tthis.#alive()\n\t\t\tconst evaluated = working\n\t\t\tlet result: ReasonResult\n\t\t\ttry {\n\t\t\t\tresult = this.#engine.reason(evaluated, pass)\n\t\t\t} catch (error) {\n\t\t\t\tthrow mapEngineError(error, pass.id)\n\t\t\t}\n\n\t\t\ttrace.push(...result.trace.map((entry) => `${pass.id}: ${entry}`))\n\t\t\terrors.push(...result.errors.map((entry) => `${pass.id}: ${entry}`))\n\n\t\t\tif (result.reasoning === 'quantitative') {\n\t\t\t\tconst derivation = quantitativeResultToDerivation(pass.id, result)\n\t\t\t\tderivations.push(derivation)\n\t\t\t\tthis.#emitter.emit('derive', derivation)\n\t\t\t}\n\n\t\t\tif (result.reasoning === 'logical') {\n\t\t\t\tconst rulings = (definition.rulings ?? []).filter((ruling) => ruling.pass === pass.id)\n\t\t\t\tfor (const ruling of rulings) {\n\t\t\t\t\tconst finding = rulingToFinding(\n\t\t\t\t\t\truling,\n\t\t\t\t\t\tpass,\n\t\t\t\t\t\tresult,\n\t\t\t\t\t\tevaluated,\n\t\t\t\t\t\tthis.#evaluator,\n\t\t\t\t\t\tthis.#labels,\n\t\t\t\t\t)\n\t\t\t\t\tfindings.push(finding)\n\t\t\t\t\tthis.#emitter.emit('finding', finding)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst projection = reasonResultToProjection(pass, result)\n\t\t\tcontext = mergeQualificationContext(context, pass.id, projection)\n\t\t\tworking = { ...subject, ...qualificationToRecord(context) }\n\n\t\t\tif (!result.success) {\n\t\t\t\tfailed = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif (deriveFindingEligibility(findings) === 'ineligible') break\n\t\t}\n\n\t\tconst success = !failed && errors.length === 0\n\t\tconst scopes = deriveScopeEligibilities(findings)\n\t\tconst qualification: QualificationResult = Object.freeze({\n\t\t\tid: definition.id,\n\t\t\tname: definition.name,\n\t\t\teligibility: deriveFindingEligibility(findings, !success),\n\t\t\tscopes: Object.freeze(scopes),\n\t\t\tfindings: Object.freeze(findings),\n\t\t\tderivations: Object.freeze(derivations),\n\t\t\tsuccess,\n\t\t\ttrace: Object.freeze(trace),\n\t\t\terrors: Object.freeze(errors),\n\t\t})\n\t\tthis.#emitter.emit('qualify', qualification)\n\t\treturn qualification\n\t}\n\n\t#alive(): void {\n\t\tif (this.#destroyed) {\n\t\t\tthrow new QualifierError('DESTROYED', 'Qualifier has been destroyed')\n\t\t}\n\t}\n}\n","import type {\n\tQualificationDefinition,\n\tQualificationEffect,\n\tQualificationInput,\n\tQualificationPass,\n\tQualifierInterface,\n\tQualifierOptions,\n\tRuling,\n\tRulingInput,\n} from './types.js'\nimport { Qualifier } from './Qualifier.js'\n\n/**\n * Creates one {@link QualifierInterface} over a reason engine.\n *\n * @remarks\n * A standalone qualifier creates and owns one shared quantitative-plus-logical\n * reason engine, destroying it on `destroy()`. An injected `options.engine`\n * remains caller-owned and is never destroyed. `validate` runs semantic\n * validation before every qualification. Default: `true`. `labels` overrides the\n * display name of a premise field, keyed by the dot-joined field path\n * `formatField` produces, and takes precedence over a premise's own `label`.\n *\n * @param options - Optional injected engine, validation, labels, and emitter hooks\n * @returns A {@link QualifierInterface}\n *\n * @example Create a qualifier\n * ```ts\n * import { createQualificationDefinition, createQualifier, createRuling } from '@orkestrel/qualifier'\n * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'\n *\n * const gates = createLogicalDefinition('gates', 'Eligibility gates', [\n * \tcreateRule(\n * \t\t'licensed',\n * \t\t[createAtom('licensed', 'equals', false)],\n * \t\tcreateAtom('blocked', 'equals', true),\n * \t),\n * ])\n *\n * const bare = createRuling('license', 'gates', 'licensed', 'restriction')\n * const messaged = createRuling('license', 'gates', 'licensed', 'restriction', {\n * \tmessage: 'A license is required',\n * })\n *\n * 'message' in bare // false — an absent optional key is omitted, never written as undefined\n * messaged.message // 'A license is required'\n *\n * const passes = [gates]\n * const definition = createQualificationDefinition('standard', 'Standard eligibility', passes, {\n * \trulings: [messaged],\n * })\n *\n * 'description' in definition // false\n * definition.passes === passes // false — the factory copies what it is handed\n *\n * const qualifier = createQualifier()\n * qualifier.qualify({ id: 'risk-1', licensed: false }, definition)\n * qualifier.destroy()\n * ```\n */\nexport function createQualifier(options?: QualifierOptions): QualifierInterface {\n\treturn new Qualifier(options)\n}\n\n/**\n * Creates a fresh {@link QualificationDefinition}, omitting every absent optional key.\n *\n * @remarks\n * `passes` and `rulings` arrays are copied, and record `metadata` is\n * shallow-copied so nested values are not deep-cloned.\n *\n * @param id - The definition id\n * @param name - The display name\n * @param passes - The ordered qualification passes\n * @param input - Optional description, rulings, and metadata\n * @returns A fresh qualification definition\n *\n * @example\n * ```ts\n * import { createQualificationDefinition } from '@orkestrel/qualifier'\n *\n * createQualificationDefinition('standard', 'Standard', [gates], { rulings: [ruling] })\n * ```\n */\nexport function createQualificationDefinition(\n\tid: string,\n\tname: string,\n\tpasses: readonly QualificationPass[],\n\tinput?: QualificationInput,\n): QualificationDefinition {\n\treturn {\n\t\tid,\n\t\tname,\n\t\tpasses: [...passes],\n\t\t...(input?.description === undefined ? {} : { description: input.description }),\n\t\t...(input?.rulings === undefined ? {} : { rulings: [...input.rulings] }),\n\t\t...(input?.metadata === undefined ? {} : { metadata: { ...input.metadata } }),\n\t}\n}\n\n/**\n * Creates a fresh {@link Ruling} from the rule it reacts to and the effect it applies.\n *\n * @param id - The ruling id\n * @param pass - The logical pass id the rule lives in\n * @param rule - The rule id whose firing this ruling reacts to\n * @param effect - The eligibility impact when the rule fires\n * @param input - Optional selection scope and message template\n * @returns A fresh ruling\n *\n * @example\n * ```ts\n * import { createRuling } from '@orkestrel/qualifier'\n *\n * createRuling('license', 'gates', 'licensed', 'restriction', { message: 'A license is required' })\n * ```\n */\nexport function createRuling(\n\tid: string,\n\tpass: string,\n\trule: string,\n\teffect: QualificationEffect,\n\tinput?: RulingInput,\n): Ruling {\n\treturn {\n\t\tid,\n\t\tpass,\n\t\trule,\n\t\teffect,\n\t\t...(input?.scope === undefined ? {} : { scope: input.scope }),\n\t\t...(input?.message === undefined ? {} : { message: input.message }),\n\t}\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,6BAA6B;;;;;AAM1C,IAAa,oBAAoB;;AAGjC,IAAa,yBAAiD,OAAO,OAAO;CAC3E;CACA;CACA;AACD,CAAC;;;;;AAMD,IAAa,uBACZ,OAAO,OAAO;CACb,aAAa;CACb,UAAU;CACV,WAAW;AACZ,CAAC;;;;;;;;;;;;;;;;;;;ACZF,IAAa,iBAAb,cAAoC,MAAM;CACzC;CACA;CAEA,YAAY,MAA0B,SAAiB,SAAiC;EACvF,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,UAAU;CAChB;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OAAO,iBAAiB;AACzB;;;;;;;;;;;;;ACAA,IAAa,iBAAA,GAAgB,oBAAA,UAAA,CAAU,YAAY,cAAc,UAAU;;;;;;;;;;;AAY3E,IAAa,yBAAA,GAAwB,oBAAA,UAAA,CAAU,eAAe,YAAY,WAAW;;;;;;;;;;;;;AAcrF,SAAgB,oBACf,OACiD;CACjD,QAAA,GAAO,oBAAA,QAAA,EAAA,GAAQ,oBAAA,SAAA,CAAS,CAAC,CAAC,IAAI,WAC7B,OAAO,oBAAoB,MAAM,CAAC,CAAC,OAAO,QAAQ,cAAc,QAAQ,IAAI,QAAQ,GAAG,CAAC,CAAC,CAC1F,CAAC,CAAC,KAAK;AACR;;;;;;;;;;;;;;AAeA,SAAgB,UAAU,OAAkC;CAC3D,QAAA,GAAO,oBAAA,SAAA,CACN;EACC,OAAO,kBAAA;EACP,OAAO,oBAAA;EACP,aAAa,oBAA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