@orkestrel/qualifier 0.0.24 → 0.0.26

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.
@@ -129,41 +129,35 @@ function isEligibilityRecord(value) {
129
129
  return (0, _orkestrel_contract.whereOf)((0, _orkestrel_contract.objectOf)({}), (record) => Object.getOwnPropertyNames(record).every((key) => isEligibility(Reflect.get(record, key))))(value);
130
130
  }
131
131
  /**
132
- * Determines whether a value is an open result-side {@link Premise}.
132
+ * Determines whether a value is an open result-side {@link MessageSlot}.
133
133
  *
134
134
  * @remarks
135
- * The optional `field`, `label`, `description`, `comparison`, and `met` members are checked
136
- * when they are defined. `expected` is unchecked and may be absent or contain any value
137
- * because its published type is `unknown`. `actual` is unchecked and may be absent or contain
138
- * any value for the same reason. Unknown members are admitted, because an open result admits
135
+ * `field` is checked. `actual` must be present and may hold anything, and is never read, because
136
+ * its published type is `unknown`. Unknown members are admitted, because an open result admits
139
137
  * what the published contract does not name.
140
138
  *
141
139
  * @param value - The value to test
142
- * @returns True if every checked premise member follows its published type; false otherwise
140
+ * @returns True if the slot names a field and carries a value; false otherwise
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { isMessageSlot } from '@orkestrel/qualifier'
145
+ *
146
+ * isMessageSlot({ field: ['age'], actual: undefined }) // true
147
+ * isMessageSlot({ field: ['age'] }) // false
148
+ * ```
143
149
  */
144
- function isPremise(value) {
145
- return (0, _orkestrel_contract.objectOf)({
146
- field: _orkestrel_reason.isFieldPath,
147
- label: _orkestrel_contract.isString,
148
- description: _orkestrel_contract.isString,
149
- comparison: _orkestrel_reason.isComparison,
150
- state: _orkestrel_reason.isCheckState
151
- }, [
152
- "field",
153
- "label",
154
- "description",
155
- "comparison",
156
- "state"
157
- ])(value);
150
+ function isMessageSlot(value) {
151
+ return (0, _orkestrel_contract.whereOf)((0, _orkestrel_contract.objectOf)({ field: _orkestrel_reason.isFieldPath }), (slot) => Reflect.has(slot, "actual"))(value);
158
152
  }
159
153
  /**
160
154
  * Determines whether a value is an open result-side {@link Finding}.
161
155
  *
162
156
  * @remarks
163
- * Every published member is checked, including each nested {@link Premise}. Optional `scope`
164
- * and `message` members may be absent or `undefined`; a present defined value must be a
165
- * string. Unknown members are admitted, because a foreign result implementation may add them
166
- * without changing the published contract.
157
+ * Every published member is checked, including each nested {@link MessageSlot} and check result.
158
+ * Optional `scope` and `message` members may be absent or `undefined`; a present defined value is
159
+ * checked in full. Unknown members are admitted, because a foreign result implementation may add
160
+ * them without changing the published contract.
167
161
  *
168
162
  * @param value - The value to test
169
163
  * @returns True if every published finding member is valid; false otherwise
@@ -176,8 +170,8 @@ function isFinding(value) {
176
170
  effect: isQualificationEffect,
177
171
  scope: _orkestrel_contract.isString,
178
172
  state: _orkestrel_reason.isCheckState,
179
- message: _orkestrel_contract.isString,
180
- premises: (0, _orkestrel_contract.arrayOf)(isPremise)
173
+ message: (0, _orkestrel_contract.arrayOf)((0, _orkestrel_contract.unionOf)(_orkestrel_contract.isString, isMessageSlot)),
174
+ checks: (0, _orkestrel_contract.arrayOf)(_orkestrel_reason.isCheckResult)
181
175
  }, ["scope", "message"])(value);
182
176
  }
183
177
  /**
@@ -185,9 +179,8 @@ function isFinding(value) {
185
179
  *
186
180
  * @remarks
187
181
  * Every published member is checked: `value` follows the published `number` type, including
188
- * `NaN` and the infinities, and `trace` and `errors` hold strings. Unknown members are
189
- * admitted, because a foreign result implementation may add them without changing the
190
- * published contract.
182
+ * `NaN` and the infinities. Unknown members are admitted, because a foreign result
183
+ * implementation may add them without changing the published contract.
191
184
  *
192
185
  * @param value - The value to test
193
186
  * @returns True if every published derivation member is valid; false otherwise
@@ -198,7 +191,8 @@ function isDerivation(value) {
198
191
  value: _orkestrel_contract.isNumber,
199
192
  success: _orkestrel_contract.isBoolean,
200
193
  trace: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString),
201
- errors: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)
194
+ refusals: (0, _orkestrel_contract.arrayOf)(_orkestrel_reason.isReasonRefusal),
195
+ faults: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isAuditFault)
202
196
  })(value);
203
197
  }
204
198
  /**
@@ -224,7 +218,7 @@ function isQualificationResult(value) {
224
218
  derivations: (0, _orkestrel_contract.arrayOf)(isDerivation),
225
219
  success: _orkestrel_contract.isBoolean,
226
220
  trace: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString),
227
- errors: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString),
221
+ refusals: (0, _orkestrel_contract.arrayOf)(_orkestrel_reason.isReasonRefusal),
228
222
  faults: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isAuditFault),
229
223
  repairs: (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isAuditFault),
230
224
  defaulted: (0, _orkestrel_contract.arrayOf)(_orkestrel_reason.isFieldPath)
@@ -308,212 +302,74 @@ function isQualificationDefinition(value) {
308
302
  }
309
303
  // src/core/helpers.ts
310
304
  /**
311
- * Interpolates `{{dotted.path}}` tokens in a message template against a subject.
305
+ * Splits a message template at its `{{dotted.path}}` tokens, reading each from a subject.
312
306
  *
313
307
  * @remarks
314
- * Each token is split on `.` into a `FieldPath` array and resolved with
315
- * `resolveField` (a plain string field is one key, never dot-split — the split
316
- * here is the token-to-path bridge). A finite number renders with `en-US`
317
- * thousand grouping (`5010` → `5,010`); any other resolved value String-coerces.
318
- * An unresolved path renders as the empty string.
308
+ * The text between tokens stays as authored, and an empty text is left out. Each token becomes a
309
+ * {@link MessageSlot} whose `field` is the token's path as an array of keys and whose `actual` is
310
+ * the raw value there, `undefined` for an absent one. Nothing is formatted. The tokens are those
311
+ * {@link findMessageTokens} finds.
319
312
  *
320
313
  * @param template - The message template carrying `{{dotted.path}}` tokens
321
314
  * @param subject - The record tokens resolve against
322
- * @returns The template with every token replaced
315
+ * @returns The authored texts and the slots, in order
323
316
  *
324
317
  * @example
325
318
  * ```ts
326
- * import { interpolateMessage } from '@orkestrel/qualifier'
319
+ * import { splitMessage } from '@orkestrel/qualifier'
327
320
  *
328
- * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'
329
- * interpolateMessage('Missing {{gone}}', {}) // 'Missing '
321
+ * splitMessage('Limit is {{limit}}', { limit: 5010 })
322
+ * // ['Limit is ', { field: ['limit'], actual: 5010 }]
330
323
  * ```
331
324
  */
332
- function interpolateMessage(template, subject) {
333
- return template.replace(MESSAGE_TOKEN, (_match, path) => {
334
- const value = (0, _orkestrel_contract.resolveField)(subject, path.split("."));
335
- if (value === void 0) return "";
336
- if ((0, _orkestrel_contract.isFiniteNumber)(value)) return value.toLocaleString("en-US");
337
- return String(value);
325
+ function splitMessage(template, subject) {
326
+ return template.split(MESSAGE_TOKEN).flatMap((part, index) => {
327
+ if (index % 2 === 0) return part === "" ? [] : [part];
328
+ const field = part.split(".");
329
+ return [{
330
+ field,
331
+ actual: (0, _orkestrel_contract.resolveField)(subject, field)
332
+ }];
338
333
  });
339
334
  }
340
335
  /**
341
- * Finds the `{{dotted.path}}` tokens a message template reads.
342
- *
343
- * @param template - The message template
344
- * @returns Each token's dotted path, trimmed, in order, repeats included
345
- *
346
- * @example
347
- * ```ts
348
- * import { findMessageTokens } from '@orkestrel/qualifier'
349
- *
350
- * findMessageTokens('Age {{ age }} in {{home.city}}') // ['age', 'home.city']
351
- * ```
352
- */
353
- function findMessageTokens(template) {
354
- return [...template.matchAll(MESSAGE_TOKEN)].map((match) => match[1] ?? "");
355
- }
356
- /**
357
- * Renders a {@link Premise} comparison as a display-neutral verb phrase.
358
- *
359
- * @param comparison - The comparison to describe
360
- * @returns A display-neutral phrase
361
- *
362
- * @example
363
- * ```ts
364
- * import { renderComparison } from '@orkestrel/qualifier'
365
- *
366
- * renderComparison('above') // 'is more than'
367
- * ```
368
- */
369
- function renderComparison(comparison) {
370
- switch (comparison) {
371
- case "equals": return "is";
372
- case "not": return "is not";
373
- case "above": return "is more than";
374
- case "below": return "is less than";
375
- case "from": return "is at least";
376
- case "to": return "is at most";
377
- case "any": return "is any of";
378
- case "none": return "is none of";
379
- case "between": return "is between";
380
- case "outside": return "is outside";
381
- }
382
- }
383
- /**
384
- * Renders a structured or scalar expected value display-neutrally.
385
- *
386
- * @remarks
387
- * An array renders as its elements, each `String`-coerced, joined with `', '`.
388
- * A reason `Bounds`-shaped record (the `between` / `outside` expected value)
389
- * renders its present sides joined with the word `and`; an absent side is
390
- * omitted. A finite number and everything else fall back to plain `String()` —
391
- * a finite number is not grouped here (grouping is {@link interpolateMessage}'s
392
- * message-token-only behavior).
393
- *
394
- * @param value - The value to render
395
- * @returns A display-neutral rendering
396
- *
397
- * @example
398
- * ```ts
399
- * import { renderValue } from '@orkestrel/qualifier'
400
- *
401
- * renderValue([18, 25, 40]) // '18, 25, 40'
402
- * renderValue({ minimum: 18, maximum: 65 }) // '18 and 65'
403
- * renderValue(42) // '42'
404
- * ```
405
- */
406
- function renderValue(value) {
407
- if ((0, _orkestrel_contract.isArray)(value)) return value.map((entry) => String(entry)).join(", ");
408
- if ((0, _orkestrel_reason.isBounds)(value)) {
409
- const sides = [];
410
- if (value.minimum !== void 0) sides.push(String(value.minimum));
411
- if (value.maximum !== void 0) sides.push(String(value.maximum));
412
- return sides.join(" and ");
413
- }
414
- return String(value);
415
- }
416
- /**
417
- * Renders one {@link Premise} into a display-neutral sentence.
336
+ * Projects a slot's `actual` to JSON on its own budget, as `undefined` when it has no JSON form.
418
337
  *
419
- * @remarks
420
- * The checked form renders only when `field` and `comparison` are both
421
- * present, and `description` then goes unused; a premise missing either half
422
- * of the checked pair renders as described instead.
423
- *
424
- * @param entry - The premise to render
425
- * @param labels - Optional field-to-label overrides, keyed by dot-joined field
426
- * @returns A display-neutral sentence
338
+ * @param slot - The slot
339
+ * @returns The slot, its `actual` JSON or `undefined`
427
340
  *
428
341
  * @example
429
342
  * ```ts
430
- * import { renderPremise } from '@orkestrel/qualifier'
431
- *
432
- * renderPremise({ field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' })
433
- * // 'age is more than 18 → met'
343
+ * import { projectMessageSlot } from '@orkestrel/qualifier'
434
344
  *
435
- * renderPremise({ description: 'Applicant is enrolled', state: 'met' })
436
- * // 'Applicant is enrolled → met'
345
+ * projectMessageSlot({ field: ['limit'], actual: Number.NaN }) // { field: ['limit'], actual: null }
437
346
  * ```
438
347
  */
439
- function renderPremise(entry, labels) {
440
- const status = entry.state === "met" ? "met" : entry.state === "unmet" ? "not met" : "unknown";
441
- if (entry.field === void 0 || entry.comparison === void 0) return `${entry.description ?? "Premise"} → ${status}`;
442
- const field = (0, _orkestrel_reason.formatField)(entry.field);
443
- const label = labels?.[field] ?? entry.label ?? field;
444
- const expected = entry.expected === void 0 ? "" : ` ${renderValue(entry.expected)}`;
445
- return `${label} ${renderComparison(entry.comparison)}${expected} → ${status}`;
446
- }
447
- /**
448
- * Builds a {@link Premise} from an authored {@link Check} and its evaluated
449
- * `CheckResult`.
450
- *
451
- * @param check - The authored check
452
- * @param result - The evaluated check result carrying the resolved `actual` and `state`
453
- * @param labels - Optional field-to-label overrides, keyed by dot-joined field
454
- * @returns A fresh premise
455
- *
456
- * @example
457
- * ```ts
458
- * import { checkToPremise } from '@orkestrel/qualifier'
459
- * import { createCheck } from '@orkestrel/reason'
460
- *
461
- * const authored = createCheck('age', 'above', 18)
462
- * checkToPremise(authored, { field: 'age', actual: 25, state: 'met' })
463
- * // { field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }
464
- * ```
465
- */
466
- function checkToPremise(check, result, labels) {
467
- const field = (0, _orkestrel_reason.formatField)(check.field);
348
+ function projectMessageSlot(slot) {
468
349
  return {
469
- field: check.field,
470
- ...labels?.[field] === void 0 ? {} : { label: labels[field] },
471
- comparison: check.operator,
472
- expected: check.value,
473
- actual: result.actual,
474
- state: result.state
350
+ field: slot.field,
351
+ actual: (0, _orkestrel_reason.projectValue)(slot.actual)
475
352
  };
476
353
  }
477
354
  /**
478
- * Builds rich premises for one fired {@link Rule} by walking its premise atoms
479
- * and reading each from what the rule read.
355
+ * Finds the `{{dotted.path}}` tokens a message template reads.
480
356
  *
481
357
  * @remarks
482
- * Each authored premise expression is flattened to its atom leaves through `extractAtoms`,
483
- * which lines up with the `checks` the rule result carries, so a premise cannot disagree with
484
- * the pass. A rule with no result never ran, so its premises carry no `state` or `actual`.
358
+ * White space around a path is trimmed, and the white space inside it stays. A token of white
359
+ * space alone names one key, its last character, and `{{}}` is text.
485
360
  *
486
- * @param rule - The authored rule
487
- * @param resolved - The rule's result, absent when it never ran
488
- * @param labels - Optional field-to-label overrides, keyed by dot-joined field
489
- * @returns A fresh, ordered list of rich premises
361
+ * @param template - The message template
362
+ * @returns Each token's dotted path, in order, repeats included
490
363
  *
491
364
  * @example
492
365
  * ```ts
493
- * import { ruleToPremises } from '@orkestrel/qualifier'
494
- * import { createAtom, createRule } from '@orkestrel/reason'
495
- *
496
- * const rule = createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true))
497
- * const resolved = {
498
- * id: 'licensed',
499
- * state: 'met' as const,
500
- * premises: ['met' as const],
501
- * checks: [{ field: 'licensed', state: 'met' as const, actual: false }],
502
- * }
503
- * ruleToPremises(rule, resolved)[0]?.state // 'met'
366
+ * import { findMessageTokens } from '@orkestrel/qualifier'
367
+ *
368
+ * findMessageTokens('Age {{ age }} in {{home.city}}') // ['age', 'home.city']
504
369
  * ```
505
370
  */
506
- function ruleToPremises(rule, resolved, labels) {
507
- return rule.premises.flatMap((premise) => (0, _orkestrel_reason.extractAtoms)(premise)).map((atom, index) => {
508
- const read = resolved?.checks[index];
509
- if (read !== void 0) return checkToPremise(atom.check, read, labels);
510
- const { state: _state, actual: _actual, ...unrun } = checkToPremise(atom.check, {
511
- field: atom.check.field,
512
- state: "unread",
513
- actual: void 0
514
- }, labels);
515
- return unrun;
516
- });
371
+ function findMessageTokens(template) {
372
+ return [...template.matchAll(MESSAGE_TOKEN)].map((match) => match[1] ?? "");
517
373
  }
518
374
  /**
519
375
  * Locates an authored {@link Rule} by id.
@@ -565,7 +421,10 @@ function findRule(definition, id) {
565
421
  * count: 1,
566
422
  * success: true,
567
423
  * trace: [],
568
- * errors: [],
424
+ * refusals: [],
425
+ * faults: [],
426
+ * repairs: [],
427
+ * defaulted: [],
569
428
  * }
570
429
  * reasonResultToProjection(cap, result) // 500000
571
430
  * ```
@@ -697,32 +556,135 @@ function describeReservedConclusions(definition) {
697
556
  return definition.passes.flatMap((pass) => pass.reasoning !== "logical" ? [] : pass.rules.filter((rule) => Object.hasOwn((0, _orkestrel_reason.extractConclusions)(rule.conclusion), "conclusion")).map((rule) => `Rule '${rule.id}' in pass '${pass.id}' concludes the reserved key 'conclusion'`));
698
557
  }
699
558
  /**
700
- * Determines whether a logical result holds a rule left unread.
559
+ * Finds each rule a logical result does not answer: one it left unread, and an enabled one it
560
+ * omits.
701
561
  *
702
- * @param result - The result of a pass
703
- * @returns True when a logical result holds such a rule; false otherwise
562
+ * @param definition - The logical pass
563
+ * @param result - The result of the pass
564
+ * @returns The rule ids, each once, the unread ones first
704
565
  *
705
566
  * @example
706
567
  * ```ts
707
- * import { hasUnreadRule } from '@orkestrel/qualifier'
568
+ * import { findUnansweredRules } from '@orkestrel/qualifier'
569
+ * import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'
708
570
  *
709
- * const rule = { id: 'r', state: 'unread' as const, premises: [], checks: [] }
710
- * hasUnreadRule({
571
+ * const gates = createLogicalDefinition('gates', 'Gates', [
572
+ * createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),
573
+ * ])
574
+ * findUnansweredRules(gates, {
711
575
  * reasoning: 'logical',
712
- * conclusion: 'unread',
713
- * rules: [rule],
576
+ * conclusion: 'unmet',
577
+ * rules: [],
578
+ * count: 0,
579
+ * success: true,
580
+ * trace: [],
581
+ * refusals: [],
582
+ * faults: [],
583
+ * repairs: [],
584
+ * defaulted: [],
585
+ * }) // ['licensed']
586
+ * ```
587
+ */
588
+ function findUnansweredRules(definition, result) {
589
+ const answered = new Set(result.rules.map((rule) => rule.id));
590
+ return [.../* @__PURE__ */ new Set([...result.rules.filter((rule) => rule.state === "unread").map((rule) => rule.id), ...definition.rules.filter((rule) => rule.enabled !== false && !answered.has(rule.id)).map((rule) => rule.id)])];
591
+ }
592
+ /**
593
+ * Collects why an answer refused: the engine's own refusals, and what the answer leaves out or
594
+ * contradicts by itself.
595
+ *
596
+ * @remarks
597
+ * A failure naming no refusal and no fault is `silent`. A success is `malformed` beside a refusal
598
+ * or a fault, and at a value that is not finite, held in `actual`. Whatever verdict it claims, an
599
+ * answer is `malformed` for each rule it lists more than once, named in `rule`.
600
+ *
601
+ * @param result - The engine's answer
602
+ * @returns The refusals, with no path of this package's
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * import { collectAnswerRefusals } from '@orkestrel/qualifier'
607
+ *
608
+ * collectAnswerRefusals({
609
+ * reasoning: 'quantitative',
610
+ * value: Number.NaN,
611
+ * groups: [],
612
+ * count: 0,
613
+ * success: true,
614
+ * trace: [],
615
+ * refusals: [],
616
+ * faults: [],
617
+ * repairs: [],
618
+ * defaulted: [],
619
+ * }) // [{ cause: 'malformed', actual: NaN }]
620
+ * ```
621
+ */
622
+ function collectAnswerRefusals(result) {
623
+ const { refusals, faults, success } = result;
624
+ const named = refusals.length > 0 || faults.length > 0;
625
+ const repeated = result.reasoning === "logical" ? (0, _orkestrel_reason.findDuplicates)(result.rules).map((rule) => ({
626
+ cause: "malformed",
627
+ rule
628
+ })) : [];
629
+ const silent = named ? [] : [{ cause: "silent" }];
630
+ if (!success) return [
631
+ ...refusals,
632
+ ...silent,
633
+ ...repeated
634
+ ];
635
+ const beside = named ? [{ cause: "malformed" }] : [];
636
+ const valued = result.reasoning === "quantitative" && !(0, _orkestrel_contract.isFiniteNumber)(result.value) ? [{
637
+ cause: "malformed",
638
+ actual: result.value
639
+ }] : [];
640
+ return [
641
+ ...refusals,
642
+ ...beside,
643
+ ...valued,
644
+ ...repeated
645
+ ];
646
+ }
647
+ /**
648
+ * Collects why a pass refused: the engine's own refusals under the pass id, and what its answer
649
+ * leaves out or contradicts.
650
+ *
651
+ * @remarks
652
+ * An injected engine answers through an interface, so its verdict is checked against the rest of
653
+ * its answer, as `collectAnswerRefusals` does, and against its pass. An answer of another
654
+ * reasoning is `malformed`, and so is a success for each rule it does not answer, named in `rule`.
655
+ *
656
+ * @param pass - The pass the engine ran
657
+ * @param result - The engine's answer
658
+ * @returns The refusals, each with the pass id at the head of its `path`
659
+ *
660
+ * @example
661
+ * ```ts
662
+ * import { collectPassRefusals } from '@orkestrel/qualifier'
663
+ * import { createQuantitativeDefinition } from '@orkestrel/reason'
664
+ *
665
+ * collectPassRefusals(createQuantitativeDefinition('cap', 'Cap', []), {
666
+ * reasoning: 'quantitative',
667
+ * value: 0,
668
+ * groups: [],
714
669
  * count: 0,
715
670
  * success: false,
716
671
  * trace: [],
717
- * errors: [],
672
+ * refusals: [],
718
673
  * faults: [],
719
674
  * repairs: [],
720
675
  * defaulted: [],
721
- * }) // true
676
+ * }) // [{ cause: 'silent', path: ['cap'] }]
722
677
  * ```
723
678
  */
724
- function hasUnreadRule(result) {
725
- return result.reasoning === "logical" && result.rules.some((rule) => rule.state === "unread");
679
+ function collectPassRefusals(pass, result) {
680
+ if (result.reasoning !== pass.reasoning) return (0, _orkestrel_reason.nestRefusals)([...result.refusals, { cause: "malformed" }], pass.id);
681
+ const refusals = collectAnswerRefusals(result);
682
+ const refused = new Set(refusals.filter(({ cause }) => cause === "malformed").map(({ rule }) => rule));
683
+ const unanswered = result.success && pass.reasoning === "logical" && result.reasoning === "logical" ? findUnansweredRules(pass, result).filter((rule) => !refused.has(rule)) : [];
684
+ return (0, _orkestrel_reason.nestRefusals)([...refusals, ...unanswered.map((rule) => ({
685
+ cause: "malformed",
686
+ rule
687
+ }))], pass.id);
726
688
  }
727
689
  /**
728
690
  * Describes each message token no field of the definition's shape answers.
@@ -757,8 +719,9 @@ function describeUnknownTokens(definition) {
757
719
  * Projects a result to the JSON its contract reads.
758
720
  *
759
721
  * @remarks
760
- * A premise's `actual` holds whatever the subject held and a derivation's `value` may be `NaN`,
761
- * so a result crosses a boundary as this projection, each `actual` on its own budget.
722
+ * A check's, a slot's, and a refusal's `actual` holds whatever the run read, and a derivation's
723
+ * `value` may be `NaN`, so a result crosses a boundary as this projection, each `actual` on its
724
+ * own budget.
762
725
  *
763
726
  * @param result - The qualification result
764
727
  * @returns Its JSON projection, which `qualificationResultContract` admits
@@ -776,19 +739,28 @@ function describeUnknownTokens(definition) {
776
739
  function projectQualificationResult(result) {
777
740
  const findings = result.findings.map((finding) => ({
778
741
  ...finding,
779
- premises: finding.premises.map((premise) => ({
780
- ...premise,
781
- actual: (0, _orkestrel_reason.projectValue)(premise.actual)
782
- }))
742
+ ...finding.message === void 0 ? {} : { message: finding.message.map((part) => (0, _orkestrel_contract.isString)(part) ? part : projectMessageSlot(part)) },
743
+ checks: finding.checks.map((check) => (0, _orkestrel_reason.projectCheck)(check))
744
+ }));
745
+ const derivations = result.derivations.map((derivation) => ({
746
+ ...derivation,
747
+ refusals: derivation.refusals.map((refusal) => (0, _orkestrel_reason.projectRefusal)(refusal))
783
748
  }));
749
+ const refusals = result.refusals.map((refusal) => (0, _orkestrel_reason.projectRefusal)(refusal));
784
750
  return (0, _orkestrel_reason.projectValue)({
785
751
  ...result,
786
- findings
752
+ findings,
753
+ derivations,
754
+ refusals
787
755
  }, /* @__PURE__ */ new Set(), { left: Number.POSITIVE_INFINITY });
788
756
  }
789
757
  /**
790
758
  * Projects a quantitative result into a {@link Derivation} audit record.
791
759
  *
760
+ * @remarks
761
+ * `refusals` are what `collectAnswerRefusals` collects, and `success` is false exactly when they or
762
+ * the faults hold an entry, whatever verdict the result claims.
763
+ *
792
764
  * @param id - The pass id
793
765
  * @param result - The evaluated quantitative result
794
766
  * @returns A fresh derivation
@@ -797,18 +769,21 @@ function projectQualificationResult(result) {
797
769
  * ```ts
798
770
  * import { quantitativeResultToDerivation } from '@orkestrel/qualifier'
799
771
  *
800
- * const result = { reasoning: 'quantitative' as const, value: 500_000, groups: [], count: 1, success: true, trace: ['cap: 500000'], errors: [] }
772
+ * const result = { reasoning: 'quantitative' as const, value: 500_000, groups: [], count: 1, success: true, trace: ['cap: 500000'], refusals: [], faults: [], repairs: [], defaulted: [] }
801
773
  * quantitativeResultToDerivation('cap', result)
802
- * // { id: 'cap', value: 500000, success: true, trace: ['cap: 500000'], errors: [] }
774
+ * // { id: 'cap', value: 500000, success: true, trace: ['cap: 500000'], refusals: [], faults: [] }
803
775
  * ```
804
776
  */
805
777
  function quantitativeResultToDerivation(id, result) {
778
+ const refusals = [...collectAnswerRefusals(result)];
779
+ const faults = [...result.faults];
806
780
  return {
807
781
  id,
808
782
  value: result.value,
809
- success: result.success,
783
+ success: refusals.length === 0 && faults.length === 0,
810
784
  trace: [...result.trace],
811
- errors: [...result.errors]
785
+ refusals,
786
+ faults
812
787
  };
813
788
  }
814
789
  /**
@@ -856,13 +831,14 @@ function mergeQualificationContext(context, id, projection) {
856
831
  * @remarks
857
832
  * `state` is the state of the ruling's rule. A rule the result omits reads `unmet` when it is
858
833
  * disabled, which is authored, and `unread` otherwise, because a refused pass evaluated no rule.
859
- * Premises come from what the rule read. The message interpolates against the subject.
834
+ * `checks` are the rule result's own, empty for a rule the result omits. A rule the result lists
835
+ * more than once reads `unread` with no checks, because no entry answers for it. The message is
836
+ * split against the subject.
860
837
  *
861
838
  * @param ruling - The authored ruling
862
839
  * @param pass - The pass the ruling's rule lives in
863
840
  * @param result - The pass's evaluated logical result
864
841
  * @param subject - The pre-projection subject snapshot the pass evaluated
865
- * @param labels - Optional field-to-label overrides, keyed by dot-joined field
866
842
  * @returns A fresh finding
867
843
  *
868
844
  * @example
@@ -881,7 +857,7 @@ function mergeQualificationContext(context, id, projection) {
881
857
  * count: 1,
882
858
  * success: true,
883
859
  * trace: [],
884
- * errors: [],
860
+ * refusals: [],
885
861
  * faults: [],
886
862
  * repairs: [],
887
863
  * defaulted: [],
@@ -889,19 +865,20 @@ function mergeQualificationContext(context, id, projection) {
889
865
  * rulingToFinding(ruling, gates, result, { licensed: false }).state // 'met'
890
866
  * ```
891
867
  */
892
- function rulingToFinding(ruling, pass, result, subject, labels) {
893
- const entry = result.rules.find((resolved) => resolved.id === ruling.rule);
868
+ function rulingToFinding(ruling, pass, result, subject) {
869
+ const entries = result.rules.filter((resolved) => resolved.id === ruling.rule);
870
+ const repeated = entries.length > 1;
871
+ const entry = repeated ? void 0 : entries[0];
894
872
  const rule = pass.reasoning === "logical" ? findRule(pass, ruling.rule) : void 0;
895
- const premises = rule === void 0 ? [] : ruleToPremises(rule, entry, labels);
896
873
  return {
897
874
  id: ruling.id,
898
875
  pass: ruling.pass,
899
876
  rule: ruling.rule,
900
877
  effect: ruling.effect,
901
878
  ...ruling.scope === void 0 ? {} : { scope: ruling.scope },
902
- state: entry?.state ?? (rule?.enabled === false ? "unmet" : "unread"),
903
- ...ruling.message === void 0 ? {} : { message: interpolateMessage(ruling.message, subject) },
904
- premises
879
+ state: entry?.state ?? (rule?.enabled === false && !repeated ? "unmet" : "unread"),
880
+ ...ruling.message === void 0 ? {} : { message: splitMessage(ruling.message, subject) },
881
+ checks: [...entry?.checks ?? []]
905
882
  };
906
883
  }
907
884
  /**
@@ -921,7 +898,7 @@ function rulingToFinding(ruling, pass, result, subject, labels) {
921
898
  * ```ts
922
899
  * import { deriveFindingEligibility } from '@orkestrel/qualifier'
923
900
  *
924
- * const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const, state: 'met' as const, premises: [] }
901
+ * const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const, state: 'met' as const, checks: [] }
925
902
  * deriveFindingEligibility([finding]) // 'ineligible'
926
903
  * ```
927
904
  */
@@ -952,8 +929,8 @@ function combineEligibilities(eligibilities) {
952
929
  *
953
930
  * @remarks
954
931
  * Only scoped findings that are `met` contribute. Each named scope combines its own
955
- * findings' impacts by severity. An unmentioned scope is absent (eligible by
956
- * default at the program layer).
932
+ * findings' impacts by severity. A scope no finding is met for is absent, which is eligible only
933
+ * where the run succeeded, because a finding left unread leaves its scope absent too.
957
934
  *
958
935
  * @param findings - The resolved findings
959
936
  * @returns A fresh record of scope to its combined eligibility
@@ -962,7 +939,7 @@ function combineEligibilities(eligibilities) {
962
939
  * ```ts
963
940
  * import { deriveScopeEligibilities } from '@orkestrel/qualifier'
964
941
  *
965
- * const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind', state: 'met' as const, premises: [] }
942
+ * const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind', state: 'met' as const, checks: [] }
966
943
  * deriveScopeEligibilities([finding]) // { wind: 'ineligible' }
967
944
  * ```
968
945
  */
@@ -1167,6 +1144,142 @@ function describeUnreadDerivations(definition) {
1167
1144
  });
1168
1145
  return warnings;
1169
1146
  }
1147
+ // src/core/cloners.ts
1148
+ /**
1149
+ * Copies a list, reading its length and each entry once.
1150
+ *
1151
+ * @param value - The value to copy
1152
+ * @param clone - Copies one entry. Default: carries it as it is
1153
+ * @returns A fresh list, or the value itself when it is no list
1154
+ *
1155
+ * @example
1156
+ * ```ts
1157
+ * import { cloneList } from '@orkestrel/qualifier'
1158
+ *
1159
+ * cloneList(['a', 'b']) // ['a', 'b']
1160
+ * cloneList('a') // 'a'
1161
+ * ```
1162
+ */
1163
+ function cloneList(value, clone) {
1164
+ if (!(0, _orkestrel_contract.isArray)(value)) return value;
1165
+ return Array.from({ length: value.length }, (_, index) => {
1166
+ const entry = value[index];
1167
+ return clone === void 0 ? entry : clone(entry);
1168
+ });
1169
+ }
1170
+ /**
1171
+ * Copies the named members a value has into a plain record, reading each once.
1172
+ *
1173
+ * @remarks
1174
+ * An inherited member and an accessor count, so a class instance keeps what it gives. A member the
1175
+ * names leave out is dropped, and one the value lacks stays absent.
1176
+ *
1177
+ * @param value - The value to copy
1178
+ * @param names - The members to read
1179
+ * @param clones - Copies a member of that name; any other is carried as it is. Default: none
1180
+ * @returns A fresh record, or the value itself when it is a list or no object
1181
+ *
1182
+ * @example
1183
+ * ```ts
1184
+ * import { cloneMembers } from '@orkestrel/qualifier'
1185
+ *
1186
+ * cloneMembers({ a: 1, b: 2 }, ['a']) // { a: 1 }
1187
+ * ```
1188
+ */
1189
+ function cloneMembers(value, names, clones = {}) {
1190
+ if (!(0, _orkestrel_contract.isObject)(value) || (0, _orkestrel_contract.isArray)(value)) return value;
1191
+ return Object.fromEntries(names.filter((name) => Reflect.has(value, name)).map((name) => {
1192
+ const member = Reflect.get(value, name);
1193
+ const clone = (0, _orkestrel_contract.isString)(name) && Object.hasOwn(clones, name) ? clones[name] : void 0;
1194
+ return [name, clone === void 0 ? member : clone(member)];
1195
+ }));
1196
+ }
1197
+ /**
1198
+ * Copies an untrusted engine's answer, reading each member a verdict rests on once, and admits the
1199
+ * copy alone.
1200
+ *
1201
+ * @remarks
1202
+ * Reading the answer again could give another verdict, so everything is derived from the copy. A
1203
+ * check's and a refusal's `actual` and a check's expected value are carried by identity, and so are
1204
+ * the members that hold no verdict, such as a quantitative result's `groups`. A member its contract
1205
+ * does not name is dropped. It never throws.
1206
+ *
1207
+ * @param value - The answer
1208
+ * @returns The copy, or `undefined` when it is no reason result or throws on being read
1209
+ *
1210
+ * @example
1211
+ * ```ts
1212
+ * import { cloneReasonResult } from '@orkestrel/qualifier'
1213
+ * import { createLogicalDefinition, createLogicalReasoner } from '@orkestrel/reason'
1214
+ *
1215
+ * const result = createLogicalReasoner().reason({}, createLogicalDefinition('d', 'd', []))
1216
+ * cloneReasonResult(result)?.success // true
1217
+ * cloneReasonResult({ success: true }) // undefined
1218
+ * ```
1219
+ */
1220
+ function cloneReasonResult(value) {
1221
+ const outcome = (0, _orkestrel_contract.attempt)(() => cloneMembers(value, [
1222
+ "reasoning",
1223
+ "value",
1224
+ "groups",
1225
+ "conclusion",
1226
+ "rules",
1227
+ "count",
1228
+ "solutions",
1229
+ "bindings",
1230
+ "derived",
1231
+ "proof",
1232
+ "success",
1233
+ "trace",
1234
+ "refusals",
1235
+ "faults",
1236
+ "repairs",
1237
+ "defaulted"
1238
+ ], {
1239
+ trace: (trace) => cloneList(trace),
1240
+ refusals: (refusals) => cloneList(refusals, (refusal) => cloneMembers(refusal, [
1241
+ "cause",
1242
+ "path",
1243
+ "rule",
1244
+ "group",
1245
+ "factor",
1246
+ "equation",
1247
+ "deduction",
1248
+ "index",
1249
+ "key",
1250
+ "operator",
1251
+ "field",
1252
+ "actual",
1253
+ "depth",
1254
+ "message"
1255
+ ], {
1256
+ path: (path) => cloneList(path),
1257
+ field: (field) => cloneList(field)
1258
+ })),
1259
+ faults: (faults) => cloneList(faults, (fault) => (0, _orkestrel_contract.isRecord)(fault) ? cloneMembers(fault, Reflect.ownKeys(fault), {
1260
+ path: (path) => cloneList(path),
1261
+ expected: (expected) => cloneList(expected)
1262
+ }) : fault),
1263
+ rules: (rules) => cloneList(rules, (rule) => cloneMembers(rule, [
1264
+ "id",
1265
+ "state",
1266
+ "premises",
1267
+ "checks"
1268
+ ], {
1269
+ premises: (premises) => cloneList(premises),
1270
+ checks: (checks) => cloneList(checks, (read) => cloneMembers(read, [
1271
+ "check",
1272
+ "state",
1273
+ "actual"
1274
+ ], { check: (check) => cloneMembers(check, [
1275
+ "field",
1276
+ "operator",
1277
+ "value"
1278
+ ], { field: (field) => cloneList(field) }) }))
1279
+ }))
1280
+ }));
1281
+ return (0, _orkestrel_contract.isSuccess)(outcome) && (0, _orkestrel_reason.isReasonResult)(outcome.value) ? outcome.value : void 0;
1282
+ }
1170
1283
  // src/core/shapers.ts
1171
1284
  /** Describes a `Ruling`. */
1172
1285
  var rulingShape = (0, _orkestrel_contract.objectShape)({
@@ -1204,15 +1317,10 @@ function createQualificationDefinitionShape() {
1204
1317
  shape: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.shapeShape)())
1205
1318
  });
1206
1319
  }
1207
- /** Describes a `Premise` in its JSON projection. */
1208
- var premiseShape = (0, _orkestrel_contract.objectShape)({
1209
- field: (0, _orkestrel_contract.optionalShape)(_orkestrel_reason.fieldPathShape),
1210
- label: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)()),
1211
- description: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)()),
1212
- comparison: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.literalShape)(_orkestrel_reason.COMPARISONS)),
1213
- expected: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.jsonShape)()),
1214
- actual: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.jsonShape)()),
1215
- state: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.literalShape)(_orkestrel_reason.CHECK_STATES))
1320
+ /** Describes a `MessageSlot` in its JSON projection. */
1321
+ var messageSlotShape = (0, _orkestrel_contract.objectShape)({
1322
+ field: _orkestrel_reason.fieldPathShape,
1323
+ actual: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.jsonShape)())
1216
1324
  });
1217
1325
  /** Describes a `Finding` in its JSON projection. */
1218
1326
  var findingShape = (0, _orkestrel_contract.objectShape)({
@@ -1222,8 +1330,8 @@ var findingShape = (0, _orkestrel_contract.objectShape)({
1222
1330
  effect: (0, _orkestrel_contract.literalShape)(QUALIFICATION_EFFECTS),
1223
1331
  scope: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)()),
1224
1332
  state: (0, _orkestrel_contract.literalShape)(_orkestrel_reason.CHECK_STATES),
1225
- message: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)()),
1226
- premises: (0, _orkestrel_contract.arrayShape)(premiseShape)
1333
+ message: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.unionShape)((0, _orkestrel_contract.stringShape)(), messageSlotShape))),
1334
+ checks: (0, _orkestrel_contract.arrayShape)(_orkestrel_reason.checkResultShape)
1227
1335
  });
1228
1336
  /** Describes a `Derivation` in its JSON projection, where a non-finite number is `null`. */
1229
1337
  var derivationShape = (0, _orkestrel_contract.objectShape)({
@@ -1231,7 +1339,8 @@ var derivationShape = (0, _orkestrel_contract.objectShape)({
1231
1339
  value: (0, _orkestrel_contract.nullableShape)((0, _orkestrel_contract.numberShape)()),
1232
1340
  success: (0, _orkestrel_contract.booleanShape)(),
1233
1341
  trace: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.stringShape)()),
1234
- errors: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.stringShape)())
1342
+ refusals: (0, _orkestrel_contract.arrayShape)(_orkestrel_reason.reasonRefusalShape),
1343
+ faults: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.auditFaultShape)())
1235
1344
  });
1236
1345
  /** Describes a `QualificationResult` in its JSON projection. */
1237
1346
  var qualificationResultShape = (0, _orkestrel_contract.objectShape)({
@@ -1243,7 +1352,7 @@ var qualificationResultShape = (0, _orkestrel_contract.objectShape)({
1243
1352
  derivations: (0, _orkestrel_contract.arrayShape)(derivationShape),
1244
1353
  success: (0, _orkestrel_contract.booleanShape)(),
1245
1354
  trace: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.stringShape)()),
1246
- errors: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.stringShape)()),
1355
+ refusals: (0, _orkestrel_contract.arrayShape)(_orkestrel_reason.reasonRefusalShape),
1247
1356
  faults: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.auditFaultShape)()),
1248
1357
  repairs: (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.auditFaultShape)()),
1249
1358
  defaulted: (0, _orkestrel_contract.arrayShape)(_orkestrel_reason.fieldPathShape)
@@ -1267,7 +1376,6 @@ var Qualifier = class {
1267
1376
  #engine;
1268
1377
  #owned;
1269
1378
  #validate;
1270
- #labels;
1271
1379
  #door = (0, _orkestrel_reason.createSubjectDoor)();
1272
1380
  #valid = /* @__PURE__ */ new WeakSet();
1273
1381
  #shaped = /* @__PURE__ */ new WeakSet();
@@ -1283,7 +1391,6 @@ var Qualifier = class {
1283
1391
  bail: false
1284
1392
  });
1285
1393
  this.#validate = options?.validate ?? true;
1286
- this.#labels = options?.labels;
1287
1394
  }
1288
1395
  /**
1289
1396
  * Holds the typed observation surface carrying `derive`, `finding`, `qualify`, and
@@ -1313,7 +1420,8 @@ var Qualifier = class {
1313
1420
  * `shape` on the definition admits the subject through a door first. An unscoped
1314
1421
  * restriction stops the remaining passes because no later finding can be more severe.
1315
1422
  * A pass left unread projects nothing and reads `referral`, and the run goes on, so a later
1316
- * restriction can still outrank it. An error no fault can say stops the run.
1423
+ * restriction can still outrank it. A refusal stops the run, and so does an answer that
1424
+ * contradicts itself or its pass, which is refused as `malformed`.
1317
1425
  *
1318
1426
  * @param subject - The record to qualify
1319
1427
  * @param definition - The authored qualification definition
@@ -1467,16 +1575,15 @@ var Qualifier = class {
1467
1575
  const admission = this.#door.admit(subject, definition.shape);
1468
1576
  const admitted = admission.subject;
1469
1577
  if (admitted !== void 0) assertSubject(admitted);
1470
- if (admitted === void 0) return this.#finish(definition, [], [], [], [...admission.errors], admission.faults, admission);
1578
+ if (admitted === void 0) return this.#finish(definition, [], [], [], [...admission.refusals], [...admission.faults], admission);
1471
1579
  const steps = [{
1472
1580
  context: {},
1473
- subject: { ...admitted },
1474
- success: true
1581
+ subject: { ...admitted }
1475
1582
  }];
1476
1583
  const findings = [];
1477
1584
  const derivations = [];
1478
1585
  const trace = [];
1479
- const errors = [];
1586
+ const refusals = [];
1480
1587
  const faults = [];
1481
1588
  const unread = /* @__PURE__ */ new Map();
1482
1589
  for (const pass of definition.passes) {
@@ -1484,56 +1591,48 @@ var Qualifier = class {
1484
1591
  const previous = steps.at(-1);
1485
1592
  if (previous === void 0) throw new Error("Qualification has no initial step");
1486
1593
  const evaluated = previous.subject;
1487
- const result = this.#reason(evaluated, pass);
1488
- if (!(0, _orkestrel_reason.isReasonResult)(result)) {
1489
- errors.push(`${pass.id}: The engine returned a malformed result`);
1490
- steps.push({
1491
- ...previous,
1492
- success: false
1594
+ const result = cloneReasonResult(this.#reason(evaluated, pass));
1595
+ if (result === void 0) {
1596
+ refusals.push({
1597
+ cause: "malformed",
1598
+ path: [pass.id]
1493
1599
  });
1494
1600
  break;
1495
1601
  }
1496
1602
  trace.push(...result.trace.map((entry) => `${pass.id}: ${entry}`));
1497
- const said = new Set(result.faults.map((fault) => (0, _orkestrel_contract.describeFaults)([fault])));
1498
- const fatal = [
1499
- ...result.errors.filter((entry) => !said.has(entry)),
1500
- ...!result.success && result.errors.length === 0 ? ["The pass failed and said nothing"] : [],
1501
- ...result.success && hasUnreadRule(result) ? ["The pass succeeded beside an unread rule"] : []
1502
- ];
1503
- errors.push(...fatal.map((entry) => `${pass.id}: ${entry}`));
1603
+ const refused = collectPassRefusals(pass, result);
1604
+ refusals.push(...refused);
1504
1605
  const leaves = expandPassFaults(result.faults, unread);
1505
1606
  faults.push(...leaves);
1506
1607
  if (leaves.length > 0) unread.set(pass.id, leaves);
1507
- if (result.reasoning === "quantitative") {
1608
+ if (pass.reasoning === "quantitative" && result.reasoning === "quantitative") {
1508
1609
  const derivation = quantitativeResultToDerivation(pass.id, result);
1509
1610
  derivations.push(derivation);
1510
1611
  this.#emitter.emit("derive", derivation);
1511
1612
  }
1512
- if (result.reasoning === "logical") {
1613
+ if (pass.reasoning === "logical" && result.reasoning === "logical") {
1513
1614
  const rulings = (definition.rulings ?? []).filter((ruling) => ruling.pass === pass.id);
1514
1615
  for (const ruling of rulings) {
1515
- const finding = rulingToFinding(ruling, pass, result, evaluated, this.#labels);
1616
+ const finding = rulingToFinding(ruling, pass, result, evaluated);
1516
1617
  findings.push(finding);
1517
1618
  this.#emitter.emit("finding", finding);
1518
1619
  }
1519
1620
  }
1520
- const context = result.success && fatal.length === 0 ? mergeQualificationContext(previous.context, pass.id, reasonResultToProjection(pass, result)) : previous.context;
1621
+ if (refused.length > 0) break;
1622
+ if (deriveFindingEligibility(findings) === "ineligible") break;
1623
+ const context = result.success ? mergeQualificationContext(previous.context, pass.id, reasonResultToProjection(pass, result)) : previous.context;
1521
1624
  steps.push({
1522
1625
  context,
1523
1626
  subject: {
1524
1627
  ...admitted,
1525
1628
  ...qualificationToRecord(context)
1526
- },
1527
- success: result.success && fatal.length === 0
1629
+ }
1528
1630
  });
1529
- if (fatal.length > 0) break;
1530
- if (deriveFindingEligibility(findings) === "ineligible") break;
1531
1631
  }
1532
- const leaves = (0, _orkestrel_reason.filterUniqueFaults)(faults);
1533
- return this.#finish(definition, findings, derivations, trace, [...errors, ...leaves.map((fault) => (0, _orkestrel_contract.describeFaults)([fault]))], leaves, admission);
1632
+ return this.#finish(definition, findings, derivations, trace, refusals, (0, _orkestrel_reason.filterUniqueFaults)(faults), admission);
1534
1633
  }
1535
- #finish(definition, findings, derivations, trace, errors, faults, admission) {
1536
- const success = errors.length === 0;
1634
+ #finish(definition, findings, derivations, trace, refusals, faults, admission) {
1635
+ const success = refusals.length === 0 && faults.length === 0;
1537
1636
  const qualification = Object.freeze({
1538
1637
  id: definition.id,
1539
1638
  name: definition.name,
@@ -1543,7 +1642,7 @@ var Qualifier = class {
1543
1642
  derivations: Object.freeze(derivations),
1544
1643
  success,
1545
1644
  trace: Object.freeze(trace),
1546
- errors: Object.freeze(errors),
1645
+ refusals: Object.freeze(refusals),
1547
1646
  faults: Object.freeze(faults),
1548
1647
  repairs: Object.freeze([...admission.repairs]),
1549
1648
  defaulted: Object.freeze([...admission.defaulted])
@@ -1597,11 +1696,9 @@ function createQualificationDefinitionContract() {
1597
1696
  * A standalone qualifier creates and owns one shared quantitative-plus-logical
1598
1697
  * reason engine, destroying it on `destroy()`. An injected `options.engine`
1599
1698
  * remains caller-owned and is never destroyed. `validate` runs semantic
1600
- * validation before every qualification. Default: `true`. `labels` overrides the
1601
- * display name of a premise field, keyed by the dot-joined field path
1602
- * `formatField` produces, and takes precedence over a premise's own `label`.
1699
+ * validation before every qualification. Default: `true`.
1603
1700
  *
1604
- * @param options - Optional injected engine, validation, labels, and emitter hooks
1701
+ * @param options - Optional injected engine, validation, and emitter hooks
1605
1702
  * @returns A {@link QualifierInterface}
1606
1703
  *
1607
1704
  * @example Create a qualifier
@@ -1709,7 +1806,11 @@ exports.QUALIFICATION_KEY = QUALIFICATION_KEY;
1709
1806
  exports.Qualifier = Qualifier;
1710
1807
  exports.QualifierError = QualifierError;
1711
1808
  exports.assertSubject = assertSubject;
1712
- exports.checkToPremise = checkToPremise;
1809
+ exports.cloneList = cloneList;
1810
+ exports.cloneMembers = cloneMembers;
1811
+ exports.cloneReasonResult = cloneReasonResult;
1812
+ exports.collectAnswerRefusals = collectAnswerRefusals;
1813
+ exports.collectPassRefusals = collectPassRefusals;
1713
1814
  exports.combineEligibilities = combineEligibilities;
1714
1815
  exports.createQualificationDefinition = createQualificationDefinition;
1715
1816
  exports.createQualificationDefinitionContract = createQualificationDefinitionContract;
@@ -1727,16 +1828,15 @@ exports.describeUnreadDerivations = describeUnreadDerivations;
1727
1828
  exports.expandPassFaults = expandPassFaults;
1728
1829
  exports.findMessageTokens = findMessageTokens;
1729
1830
  exports.findRule = findRule;
1831
+ exports.findUnansweredRules = findUnansweredRules;
1730
1832
  exports.findingShape = findingShape;
1731
1833
  exports.hasReservedKey = hasReservedKey;
1732
- exports.hasUnreadRule = hasUnreadRule;
1733
- exports.interpolateMessage = interpolateMessage;
1734
1834
  exports.isDefinitionMetadata = isDefinitionMetadata;
1735
1835
  exports.isDerivation = isDerivation;
1736
1836
  exports.isEligibility = isEligibility;
1737
1837
  exports.isEligibilityRecord = isEligibilityRecord;
1738
1838
  exports.isFinding = isFinding;
1739
- exports.isPremise = isPremise;
1839
+ exports.isMessageSlot = isMessageSlot;
1740
1840
  exports.isQualificationDefinition = isQualificationDefinition;
1741
1841
  exports.isQualificationEffect = isQualificationEffect;
1742
1842
  exports.isQualificationPass = isQualificationPass;
@@ -1745,7 +1845,8 @@ exports.isQualifierError = isQualifierError;
1745
1845
  exports.isRuling = isRuling;
1746
1846
  exports.mapEngineError = mapEngineError;
1747
1847
  exports.mergeQualificationContext = mergeQualificationContext;
1748
- exports.premiseShape = premiseShape;
1848
+ exports.messageSlotShape = messageSlotShape;
1849
+ exports.projectMessageSlot = projectMessageSlot;
1749
1850
  exports.projectQualificationResult = projectQualificationResult;
1750
1851
  exports.qualificationResultContract = qualificationResultContract;
1751
1852
  exports.qualificationResultShape = qualificationResultShape;
@@ -1753,12 +1854,9 @@ exports.qualificationToRecord = qualificationToRecord;
1753
1854
  exports.quantitativeResultToDerivation = quantitativeResultToDerivation;
1754
1855
  exports.readsProjection = readsProjection;
1755
1856
  exports.reasonResultToProjection = reasonResultToProjection;
1756
- exports.renderComparison = renderComparison;
1757
- exports.renderPremise = renderPremise;
1758
- exports.renderValue = renderValue;
1759
- exports.ruleToPremises = ruleToPremises;
1760
1857
  exports.rulingShape = rulingShape;
1761
1858
  exports.rulingToFinding = rulingToFinding;
1762
1859
  exports.scanDefinitionShape = scanDefinitionShape;
1860
+ exports.splitMessage = splitMessage;
1763
1861
 
1764
1862
  //# sourceMappingURL=index.cjs.map