my-frontend-observer 0.6.0 → 0.7.0

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.
Files changed (118) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +43 -4
  3. package/dist/application/externalReferencePersistenceService.d.ts +75 -0
  4. package/dist/application/externalReferencePersistenceService.js +182 -0
  5. package/dist/application/externalReferencePersistenceService.js.map +1 -0
  6. package/dist/application/referenceFidelityEvaluationService.d.ts +28 -0
  7. package/dist/application/referenceFidelityEvaluationService.js +45 -0
  8. package/dist/application/referenceFidelityEvaluationService.js.map +1 -0
  9. package/dist/artifacts/externalReferenceArtifactReader.d.ts +18 -0
  10. package/dist/artifacts/externalReferenceArtifactReader.js +35 -0
  11. package/dist/artifacts/externalReferenceArtifactReader.js.map +1 -0
  12. package/dist/artifacts/externalReferenceArtifactWriter.d.ts +44 -0
  13. package/dist/artifacts/externalReferenceArtifactWriter.js +77 -0
  14. package/dist/artifacts/externalReferenceArtifactWriter.js.map +1 -0
  15. package/dist/cli.js +844 -0
  16. package/dist/cli.js.map +1 -1
  17. package/dist/domain/boundedAgentContext.d.ts +52 -0
  18. package/dist/domain/boundedAgentContext.js +44 -1
  19. package/dist/domain/boundedAgentContext.js.map +1 -1
  20. package/dist/domain/boundedAgentContextIdentity.d.ts +16 -6
  21. package/dist/domain/boundedAgentContextIdentity.js +22 -6
  22. package/dist/domain/boundedAgentContextIdentity.js.map +1 -1
  23. package/dist/domain/boundedAgentContextProjection.d.ts +11 -0
  24. package/dist/domain/boundedAgentContextProjection.js +32 -4
  25. package/dist/domain/boundedAgentContextProjection.js.map +1 -1
  26. package/dist/domain/comparison.d.ts +23 -1
  27. package/dist/domain/comparison.js +27 -1
  28. package/dist/domain/comparison.js.map +1 -1
  29. package/dist/domain/comparisonEngine.d.ts +34 -6
  30. package/dist/domain/comparisonEngine.js +48 -8
  31. package/dist/domain/comparisonEngine.js.map +1 -1
  32. package/dist/domain/diagnostics.d.ts +1 -1
  33. package/dist/domain/diagnostics.js +16 -0
  34. package/dist/domain/diagnostics.js.map +1 -1
  35. package/dist/domain/explicitState.d.ts +40 -0
  36. package/dist/domain/explicitState.js +54 -0
  37. package/dist/domain/explicitState.js.map +1 -0
  38. package/dist/domain/externalReference.d.ts +158 -0
  39. package/dist/domain/externalReference.js +167 -0
  40. package/dist/domain/externalReference.js.map +1 -0
  41. package/dist/domain/externalReferenceApplicability.d.ts +43 -0
  42. package/dist/domain/externalReferenceApplicability.js +52 -0
  43. package/dist/domain/externalReferenceApplicability.js.map +1 -0
  44. package/dist/domain/externalReferenceCompatibility.d.ts +40 -0
  45. package/dist/domain/externalReferenceCompatibility.js +48 -0
  46. package/dist/domain/externalReferenceCompatibility.js.map +1 -0
  47. package/dist/domain/externalReferenceFidelity.d.ts +141 -0
  48. package/dist/domain/externalReferenceFidelity.js +413 -0
  49. package/dist/domain/externalReferenceFidelity.js.map +1 -0
  50. package/dist/domain/externalReferenceIdentity.d.ts +38 -0
  51. package/dist/domain/externalReferenceIdentity.js +70 -0
  52. package/dist/domain/externalReferenceIdentity.js.map +1 -0
  53. package/dist/domain/externalReferenceImage.d.ts +35 -0
  54. package/dist/domain/externalReferenceImage.js +160 -0
  55. package/dist/domain/externalReferenceImage.js.map +1 -0
  56. package/dist/domain/externalReferenceRegionRelationships.d.ts +63 -0
  57. package/dist/domain/externalReferenceRegionRelationships.js +98 -0
  58. package/dist/domain/externalReferenceRegionRelationships.js.map +1 -0
  59. package/dist/domain/externalReferenceRegions.d.ts +65 -0
  60. package/dist/domain/externalReferenceRegions.js +105 -0
  61. package/dist/domain/externalReferenceRegions.js.map +1 -0
  62. package/dist/domain/externalReferenceRequirementIdentity.d.ts +12 -0
  63. package/dist/domain/externalReferenceRequirementIdentity.js +35 -0
  64. package/dist/domain/externalReferenceRequirementIdentity.js.map +1 -0
  65. package/dist/domain/externalReferenceRequirements.d.ts +215 -0
  66. package/dist/domain/externalReferenceRequirements.js +401 -0
  67. package/dist/domain/externalReferenceRequirements.js.map +1 -0
  68. package/dist/domain/externalReferenceRuntimeBinding.d.ts +146 -0
  69. package/dist/domain/externalReferenceRuntimeBinding.js +183 -0
  70. package/dist/domain/externalReferenceRuntimeBinding.js.map +1 -0
  71. package/dist/domain/identity.d.ts +11 -8
  72. package/dist/domain/identity.js +12 -8
  73. package/dist/domain/identity.js.map +1 -1
  74. package/dist/domain/referenceCorrectionIdentity.d.ts +40 -0
  75. package/dist/domain/referenceCorrectionIdentity.js +77 -0
  76. package/dist/domain/referenceCorrectionIdentity.js.map +1 -0
  77. package/dist/domain/referenceCorrectionWorkflow.d.ts +160 -0
  78. package/dist/domain/referenceCorrectionWorkflow.js +165 -0
  79. package/dist/domain/referenceCorrectionWorkflow.js.map +1 -0
  80. package/dist/domain/referenceFidelityProjection.d.ts +65 -0
  81. package/dist/domain/referenceFidelityProjection.js +135 -0
  82. package/dist/domain/referenceFidelityProjection.js.map +1 -0
  83. package/dist/domain/relationships.d.ts +43 -1
  84. package/dist/domain/relationships.js +15 -6
  85. package/dist/domain/relationships.js.map +1 -1
  86. package/dist/domain/schema.js +6 -0
  87. package/dist/domain/schema.js.map +1 -1
  88. package/dist/index.d.ts +39 -4
  89. package/dist/index.js +21 -2
  90. package/dist/index.js.map +1 -1
  91. package/dist/request/request.d.ts +12 -0
  92. package/dist/request/request.js +12 -0
  93. package/dist/request/request.js.map +1 -1
  94. package/docs/ARCHITECTURE.md +271 -11
  95. package/docs/CI_CD.md +50 -0
  96. package/docs/COMMANDS.md +187 -0
  97. package/docs/CONTRACTS.md +1347 -12
  98. package/docs/CURRENT_STATE.md +451 -13
  99. package/docs/PROJECT_DESCRIPTION.md +513 -88
  100. package/docs/PROJECT_MILESTONES.md +550 -97
  101. package/docs/PROJECT_OVERVIEW.md +56 -14
  102. package/docs/QUICKSTART.md +6 -0
  103. package/docs/RELEASE.md +28 -21
  104. package/docs/ROADMAP.md +238 -99
  105. package/docs/SECURITY.md +80 -4
  106. package/docs/WORKFLOWS.md +358 -23
  107. package/docs/reports/v0.7-bounded-fidelity-context-prompt7.md +243 -0
  108. package/docs/reports/v0.7-implementation-completeness-documentation-reconciliation.md +497 -0
  109. package/docs/reports/v0.7-pre-release-readiness.md +337 -0
  110. package/docs/reports/v0.7-reference-binding-prompt5.md +223 -0
  111. package/docs/reports/v0.7-reference-compatibility-prompt4.md +234 -0
  112. package/docs/reports/v0.7-reference-correction-workflow-prompt8.md +222 -0
  113. package/docs/reports/v0.7-reference-fidelity-prompt6.md +216 -0
  114. package/docs/reports/v0.7-reference-foundation-prompt1.md +151 -0
  115. package/docs/reports/v0.7-reference-regions-prompt2.md +195 -0
  116. package/docs/reports/v0.7-reference-requirements-prompt3.md +217 -0
  117. package/docs/reports/v0.7-release-prep.md +423 -0
  118. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalReferenceCompatibility.js","sourceRoot":"","sources":["../../src/domain/externalReferenceCompatibility.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,oCAAoC,EAAE,MAAM,uBAAuB,CAAC;AAU7E,SAAS,aAAa,CAAC,QAA2C;IAChE,OAAO,GAAG,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uCAAuC,CAAC,SAAoC,EAAE,SAA8B;IAC1H,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;IAC9C,MAAM,OAAO,GAA0B,EAAE,CAAC;IAE1C,MAAM,sBAAsB,GAAG,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,MAAM,sBAAsB,GAAG,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/E,MAAM,cAAc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C,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAEhH,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAiC,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,YAAY,CAAC;IAElI,OAAO;QACL,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;QAChD,sBAAsB,EAAE,SAAS,CAAC,aAAa;QAC/C,kBAAkB,EAAE,SAAS,CAAC,SAAS;QACvC,aAAa,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;KAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * v0.7 Prompt 6 structured reference-vs-candidate fidelity evaluation.
3
+ * Answers "for a compatible candidate with explicit valid bindings, does the
4
+ * candidate actually match the selected reference design requirements?" -
5
+ * the first point in this whole v0.7 stack where a reference's authored
6
+ * expectation is actually compared against live candidate evidence.
7
+ *
8
+ * Reuses, never duplicates:
9
+ * - `deriveReferenceRequirementAdequacy`/`deriveReferenceRequirementExpectation`
10
+ * (v0.7 Prompt 3) for reference-side expected values/relationships and the
11
+ * reference-adequacy gate.
12
+ * - `evaluateReferenceCandidateCompatibility` (v0.7 Prompt 4) as a hard gate
13
+ * - viewport/theme/application-state/authenticated-state comparison is
14
+ * never re-implemented here.
15
+ * - `evaluateReferenceRuntimeBindings` (v0.7 Prompt 5) as the sole source of
16
+ * which runtime target (if any) represents each reference region for this
17
+ * candidate - no automatic binding, no name/geometry matching.
18
+ * - `deriveLayoutRelationships` (v0.4) as the sole source of runtime
19
+ * relationship evidence, scoped to the exact requested relationship
20
+ * family (the same Prompt 3 bug-fix precedent - matching the first
21
+ * record for a pair, regardless of family, was a real bug there and would
22
+ * be here too).
23
+ *
24
+ * Coordinate systems are never conflated: Prompt 2 regions and Prompt 3
25
+ * tolerances are authored in reference-image pixels; `ObservationArtifact`
26
+ * target geometry is CSS pixels. This module establishes one explicit,
27
+ * deterministic, full-frame scale from `reference.applicability.viewport`
28
+ * (CSS pixels) to the reference image's own pixel dimensions, and converts
29
+ * candidate CSS measurements into reference-image-pixel space before
30
+ * comparing them against a Prompt 3 tolerance - it never assumes 1
31
+ * reference-image pixel equals 1 CSS pixel, never re-expresses a tolerance
32
+ * in a different unit, and never performs cropping/offset/rotation/
33
+ * perspective registration.
34
+ *
35
+ * No new persisted artifact family: `evaluateReferenceCandidateFidelity` is
36
+ * a pure, synchronous, on-demand function over already-persisted/in-memory
37
+ * evidence (an `ExternalReferenceArtifact`, an `ObservationArtifact`, and a
38
+ * binding-declaration collection). It mutates none of its inputs.
39
+ */
40
+ import type { ExternalReferenceArtifact } from './externalReference.js';
41
+ import type { ReferenceRequirementSubject, ReferenceRequirementTolerance, ReferenceRequirementAdequacy, AuthoredChangeScopeCategory, ExpectedDependentMode } from './externalReferenceRequirements.js';
42
+ import type { ObservationArtifact } from './schema.js';
43
+ import type { ComparabilityResult } from './comparison.js';
44
+ import type { ReferenceRuntimeBindingDeclaration, ReferenceRuntimeBindingEvaluation } from './externalReferenceRuntimeBinding.js';
45
+ import type { PairwiseRelationshipKind } from './relationships.js';
46
+ /**
47
+ * Deliberately its own small vocabulary, not an import of v0.5's
48
+ * `CLAUSE_RESULT_STATUSES`: that vocabulary includes `'conflict'`, which has
49
+ * no equivalent here (each requirement is evaluated independently against
50
+ * its own single reference/candidate pair - there is no cross-requirement
51
+ * authoring conflict concept in Prompt 6). `pass`/`fail`/`unavailable` are
52
+ * reused as the same honest three-state shape v0.5 already established.
53
+ */
54
+ export declare const REFERENCE_REQUIREMENT_FIDELITY_STATUSES: readonly ["pass", "fail", "unavailable"];
55
+ export type ReferenceRequirementFidelityStatus = (typeof REFERENCE_REQUIREMENT_FIDELITY_STATUSES)[number];
56
+ export declare const REFERENCE_REQUIREMENT_FIDELITY_REASON_CODES: readonly ["reference-evidence-unavailable", "reference-relationship-not-exhibited", "binding-unavailable", "candidate-evidence-unavailable", "coordinate-mapping-unavailable"];
57
+ export type ReferenceRequirementFidelityReasonCode = (typeof REFERENCE_REQUIREMENT_FIDELITY_REASON_CODES)[number];
58
+ /**
59
+ * One requirement's structured result. Numeric fields (`referenceValue`
60
+ * through `tolerance`) apply only to `region-property`/`region-measurement`
61
+ * subjects; relationship fields (`expectedRelationship`/`actualRelationship`)
62
+ * apply only to `region-relationship` subjects - never both populated on
63
+ * the same result, mirroring the subject's own discriminated shape.
64
+ * `reasonCode`/`detail` are present only when `status === 'unavailable'` - a
65
+ * `fail` is already fully explained by its numeric/relationship fields.
66
+ */
67
+ export interface ReferenceRequirementFidelityResult {
68
+ requirementId: string;
69
+ category: AuthoredChangeScopeCategory;
70
+ expectedDependentMode?: ExpectedDependentMode;
71
+ subject: ReferenceRequirementSubject;
72
+ boundRuntimeTargets: string[];
73
+ status: ReferenceRequirementFidelityStatus;
74
+ reasonCode?: ReferenceRequirementFidelityReasonCode;
75
+ detail?: string;
76
+ referenceValue?: number;
77
+ candidateRawValue?: number;
78
+ candidateValue?: number;
79
+ delta?: number;
80
+ tolerance?: ReferenceRequirementTolerance;
81
+ expectedRelationship?: PairwiseRelationshipKind;
82
+ actualRelationship?: PairwiseRelationshipKind;
83
+ }
84
+ /**
85
+ * v0.7 Prompt 7 addition (additive; no prior structural validator existed
86
+ * for this Prompt 6 shape - fidelity evaluations previously only ever
87
+ * flowed in-memory from `evaluateReferenceCandidateFidelity`'s own return
88
+ * type, with no external/persisted input path to defend against). Reused by
89
+ * `boundedAgentContext.ts` as defense-in-depth when a caller-supplied
90
+ * `ReferenceRequirementFidelityResult` becomes part of a bounded fidelity
91
+ * projection. No change to `evaluateReferenceCandidateFidelity`'s own logic.
92
+ */
93
+ export declare function isValidReferenceRequirementFidelityResult(value: unknown): value is ReferenceRequirementFidelityResult;
94
+ export declare const REFERENCE_FIDELITY_STATES: readonly ["not-evaluated", "pass", "fail"];
95
+ export type ReferenceFidelityState = (typeof REFERENCE_FIDELITY_STATES)[number];
96
+ export declare const REFERENCE_FIDELITY_BLOCK_REASONS: readonly ["reference-inadequate", "incompatible"];
97
+ export type ReferenceFidelityBlockReason = (typeof REFERENCE_FIDELITY_BLOCK_REASONS)[number];
98
+ /**
99
+ * `state === 'not-evaluated'` exactly when an earlier gate (reference
100
+ * adequacy or reference/candidate compatibility) blocked ordinary
101
+ * evaluation - `requirementResults`/`bindings` are empty in that case, never
102
+ * a fabricated PASS/FAIL set. This is REFERENCE FIDELITY only - a
103
+ * downstream, separate concern from v0.5 baseline/per-change contract
104
+ * evaluation (see docs/CONTRACTS.md "v0.7 Prompt 6"): a `pass` here says
105
+ * nothing about, and never overrides, any v0.5 contract result.
106
+ */
107
+ export interface ReferenceCandidateFidelityEvaluation {
108
+ referenceId: string;
109
+ referenceRequestId: string;
110
+ candidateObservationId: string;
111
+ candidateRequestId: string;
112
+ adequacy: ReferenceRequirementAdequacy;
113
+ compatibility?: ComparabilityResult;
114
+ bindings?: ReferenceRuntimeBindingEvaluation;
115
+ state: ReferenceFidelityState;
116
+ blockedBy?: ReferenceFidelityBlockReason;
117
+ requirementResults: ReferenceRequirementFidelityResult[];
118
+ }
119
+ export type EvaluateReferenceCandidateFidelityResult = {
120
+ ok: true;
121
+ evaluation: ReferenceCandidateFidelityEvaluation;
122
+ } | {
123
+ ok: false;
124
+ reason: string;
125
+ };
126
+ export interface EvaluateReferenceCandidateFidelityOptions {
127
+ geometryTolerancePx?: number;
128
+ }
129
+ /**
130
+ * Pure and synchronous. Evaluation order (frozen by this prompt's own
131
+ * design, never reordered): reference structural validation -> candidate
132
+ * structural validation -> binding-declaration structural validation ->
133
+ * Prompt 3 reference adequacy -> Prompt 4 compatibility -> Prompt 5 binding
134
+ * evaluation -> per-requirement candidate-evidence/coordinate-mapping
135
+ * checks -> per-requirement tolerance/relationship comparison -> overall
136
+ * result. An earlier blocking gate (adequacy `inadequate`, compatibility
137
+ * `incomparable`) always short-circuits to `state: 'not-evaluated'` with an
138
+ * empty `requirementResults` - no ordinary PASS/FAIL set is ever fabricated
139
+ * past a blocked gate.
140
+ */
141
+ export declare function evaluateReferenceCandidateFidelity(reference: ExternalReferenceArtifact, candidate: ObservationArtifact, bindingDeclarations: readonly ReferenceRuntimeBindingDeclaration[], options?: EvaluateReferenceCandidateFidelityOptions): EvaluateReferenceCandidateFidelityResult;
@@ -0,0 +1,413 @@
1
+ import { isValidExternalReferenceArtifact, isImportedExternalReferenceArtifact } from './externalReference.js';
2
+ import { deriveReferenceRequirementAdequacy, deriveReferenceRequirementExpectation, deriveReferenceRequirementMeasurement, isAuthoredChangeScopeCategory, isValidExpectedDependentMode, isValidReferenceRequirementSubjectShape, isValidReferenceRequirementTolerance, } from './externalReferenceRequirements.js';
3
+ import { isValidObservationArtifact } from './schema.js';
4
+ import { evidenceValue } from './evidence.js';
5
+ import { evaluateReferenceCandidateCompatibility } from './externalReferenceCompatibility.js';
6
+ import { evaluateReferenceRuntimeBindings } from './externalReferenceRuntimeBinding.js';
7
+ import { deriveLayoutRelationships, HORIZONTAL_ORDER_RELATIONSHIPS, VERTICAL_ORDER_RELATIONSHIPS, AREA_OVERLAP_RELATIONSHIPS, RELATIVE_WIDTH_RELATIONSHIPS, GEOMETRIC_FIT_RELATIONSHIPS, VERTICAL_SEQUENCE_RELATIONSHIPS, PAIRWISE_RELATIONSHIP_KINDS, } from './relationships.js';
8
+ function isPlainObject(value) {
9
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
10
+ }
11
+ function isNonEmptyString(value) {
12
+ return typeof value === 'string' && value.length > 0;
13
+ }
14
+ // ---------------------------------------------------------------------------
15
+ // Result vocabulary
16
+ // ---------------------------------------------------------------------------
17
+ /**
18
+ * Deliberately its own small vocabulary, not an import of v0.5's
19
+ * `CLAUSE_RESULT_STATUSES`: that vocabulary includes `'conflict'`, which has
20
+ * no equivalent here (each requirement is evaluated independently against
21
+ * its own single reference/candidate pair - there is no cross-requirement
22
+ * authoring conflict concept in Prompt 6). `pass`/`fail`/`unavailable` are
23
+ * reused as the same honest three-state shape v0.5 already established.
24
+ */
25
+ export const REFERENCE_REQUIREMENT_FIDELITY_STATUSES = ['pass', 'fail', 'unavailable'];
26
+ export const REFERENCE_REQUIREMENT_FIDELITY_REASON_CODES = [
27
+ 'reference-evidence-unavailable',
28
+ 'reference-relationship-not-exhibited',
29
+ 'binding-unavailable',
30
+ 'candidate-evidence-unavailable',
31
+ 'coordinate-mapping-unavailable',
32
+ ];
33
+ /**
34
+ * v0.7 Prompt 7 addition (additive; no prior structural validator existed
35
+ * for this Prompt 6 shape - fidelity evaluations previously only ever
36
+ * flowed in-memory from `evaluateReferenceCandidateFidelity`'s own return
37
+ * type, with no external/persisted input path to defend against). Reused by
38
+ * `boundedAgentContext.ts` as defense-in-depth when a caller-supplied
39
+ * `ReferenceRequirementFidelityResult` becomes part of a bounded fidelity
40
+ * projection. No change to `evaluateReferenceCandidateFidelity`'s own logic.
41
+ */
42
+ export function isValidReferenceRequirementFidelityResult(value) {
43
+ if (!isPlainObject(value))
44
+ return false;
45
+ if (!isNonEmptyString(value.requirementId))
46
+ return false;
47
+ if (!isAuthoredChangeScopeCategory(value.category))
48
+ return false;
49
+ if (value.expectedDependentMode !== undefined && !isValidExpectedDependentMode(value.expectedDependentMode))
50
+ return false;
51
+ if (!isValidReferenceRequirementSubjectShape(value.subject))
52
+ return false;
53
+ if (!Array.isArray(value.boundRuntimeTargets) || !value.boundRuntimeTargets.every(isNonEmptyString))
54
+ return false;
55
+ if (typeof value.status !== 'string' || !REFERENCE_REQUIREMENT_FIDELITY_STATUSES.includes(value.status))
56
+ return false;
57
+ if (value.status === 'unavailable') {
58
+ if (typeof value.reasonCode !== 'string' || !REFERENCE_REQUIREMENT_FIDELITY_REASON_CODES.includes(value.reasonCode))
59
+ return false;
60
+ if (!isNonEmptyString(value.detail))
61
+ return false;
62
+ }
63
+ else if ('reasonCode' in value && value.reasonCode !== undefined) {
64
+ return false;
65
+ }
66
+ for (const key of ['referenceValue', 'candidateRawValue', 'candidateValue', 'delta']) {
67
+ if (value[key] !== undefined && typeof value[key] !== 'number')
68
+ return false;
69
+ }
70
+ if (value.tolerance !== undefined && !isValidReferenceRequirementTolerance(value.tolerance))
71
+ return false;
72
+ for (const key of ['expectedRelationship', 'actualRelationship']) {
73
+ if (value[key] !== undefined && (typeof value[key] !== 'string' || !PAIRWISE_RELATIONSHIP_KINDS.includes(value[key])))
74
+ return false;
75
+ }
76
+ return true;
77
+ }
78
+ export const REFERENCE_FIDELITY_STATES = ['not-evaluated', 'pass', 'fail'];
79
+ export const REFERENCE_FIDELITY_BLOCK_REASONS = ['reference-inadequate', 'incompatible'];
80
+ // ---------------------------------------------------------------------------
81
+ // Coordinate mapping (reference-image pixels <-> CSS pixels)
82
+ // ---------------------------------------------------------------------------
83
+ /**
84
+ * A coordinate-mapping-validity check only - never a design tolerance.
85
+ * Independently owned, deliberately tiny: this exists solely to detect
86
+ * "the applicable viewport and the reference image cannot represent the
87
+ * same full-frame content" (e.g. a viewport declared with a materially
88
+ * different aspect ratio than the image), never to forgive an actual
89
+ * design mismatch.
90
+ */
91
+ const ASPECT_RATIO_MAPPING_TOLERANCE = 0.01;
92
+ function referenceImageDimensions(reference) {
93
+ if (isImportedExternalReferenceArtifact(reference))
94
+ return { width: reference.image.width, height: reference.image.height };
95
+ return { width: reference.sourceReference.image.width, height: reference.sourceReference.image.height };
96
+ }
97
+ /**
98
+ * Establishes the one explicit reference-image-pixel <-> CSS-pixel scale
99
+ * this module ever uses, from `reference.applicability.viewport` (the CSS-
100
+ * pixel runtime viewport the design represents) and the reference image's
101
+ * own pixel dimensions (never conflated - see externalReferenceApplicability.ts).
102
+ * No applicable viewport at all means no scale can be established (this
103
+ * module never infers one from image dimensions alone). A deliberately
104
+ * bounded full-frame mapping only: `scaleX`/`scaleY` must agree within
105
+ * `ASPECT_RATIO_MAPPING_TOLERANCE`, or the mapping is rejected outright -
106
+ * this module performs no cropping, offset, rotation, perspective, or other
107
+ * arbitrary affine registration.
108
+ */
109
+ function deriveCoordinateScale(reference) {
110
+ const viewport = reference.applicability?.viewport;
111
+ if (!viewport) {
112
+ return { ok: false, reason: 'reference declares no applicable viewport; reference-image-pixel <-> CSS-pixel coordinate mapping cannot be established' };
113
+ }
114
+ const { width: imageWidth, height: imageHeight } = referenceImageDimensions(reference);
115
+ const scaleX = imageWidth / viewport.width;
116
+ const scaleY = imageHeight / viewport.height;
117
+ const largerScale = Math.max(scaleX, scaleY);
118
+ const relativeScaleDelta = largerScale === 0 ? 0 : Math.abs(scaleX - scaleY) / largerScale;
119
+ if (relativeScaleDelta > ASPECT_RATIO_MAPPING_TOLERANCE) {
120
+ return {
121
+ ok: false,
122
+ reason: `reference image (${imageWidth}x${imageHeight}) and applicable viewport (${viewport.width}x${viewport.height}) do not share a coherent full-frame aspect ratio (scaleX=${scaleX}, scaleY=${scaleY})`,
123
+ };
124
+ }
125
+ return { ok: true, scale: { scaleX, scaleY } };
126
+ }
127
+ /** Raw CSS-pixel geometry, reshaped into `ReferenceRegionGeometry`'s exact field set (adding centerX/centerY, computed identically to `deriveReferenceRegionGeometry`) so the same downstream property/measurement logic applies to both reference and candidate geometry uniformly. */
128
+ function candidateRawGeometry(geometry) {
129
+ return {
130
+ x: geometry.x,
131
+ y: geometry.y,
132
+ width: geometry.width,
133
+ height: geometry.height,
134
+ right: geometry.right,
135
+ bottom: geometry.bottom,
136
+ centerX: geometry.x + geometry.width / 2,
137
+ centerY: geometry.y + geometry.height / 2,
138
+ };
139
+ }
140
+ /** Applies the coordinate scale per axis - horizontal fields (x/width/right/centerX) scale by `scaleX`, vertical fields (y/height/bottom/centerY) scale by `scaleY`. Never rounds; subpixel precision is preserved through to the final tolerance comparison. */
141
+ function scaleGeometryToReferenceSpace(geometry, scale) {
142
+ return {
143
+ x: geometry.x * scale.scaleX,
144
+ y: geometry.y * scale.scaleY,
145
+ width: geometry.width * scale.scaleX,
146
+ height: geometry.height * scale.scaleY,
147
+ right: geometry.right * scale.scaleX,
148
+ bottom: geometry.bottom * scale.scaleY,
149
+ centerX: geometry.centerX * scale.scaleX,
150
+ centerY: geometry.centerY * scale.scaleY,
151
+ };
152
+ }
153
+ // ---------------------------------------------------------------------------
154
+ // Tolerance (reused exactly, never redefined)
155
+ // ---------------------------------------------------------------------------
156
+ /**
157
+ * `exact` is the zero-tolerance case of the same rule, so a single
158
+ * `abs(delta) <= allowed` comparison covers every Prompt 3 tolerance kind
159
+ * without a separate equality branch. Percent's denominator mirrors
160
+ * v0.5's own `toleranceToPx` convention exactly (`frontendContractEvaluation.ts`:
161
+ * "the absolute before-value, the standard 'may vary by up to N%' reading") -
162
+ * independently reimplemented here in reference-image-pixel units, never
163
+ * imported, since v0.5's CSS-pixel `ContractTolerance` is a different unit
164
+ * (see externalReferenceRequirements.ts's own tolerance doc comment).
165
+ */
166
+ function referenceToleranceAmountPx(tolerance, referenceValue) {
167
+ switch (tolerance.kind) {
168
+ case 'exact':
169
+ return 0;
170
+ case 'absolute-reference-px':
171
+ return tolerance.amount;
172
+ case 'percent':
173
+ return (tolerance.amount / 100) * Math.abs(referenceValue);
174
+ }
175
+ }
176
+ // ---------------------------------------------------------------------------
177
+ // Runtime-target lookup (mirrors externalReferenceRuntimeBinding.ts's own
178
+ // case-insensitive resolution convention - duplicated per the established
179
+ // per-module small-helper-ownership pattern, not cross-imported as a
180
+ // private helper)
181
+ // ---------------------------------------------------------------------------
182
+ function resolveConfiguredTargetName(candidate, runtimeTarget) {
183
+ const lower = runtimeTarget.toLowerCase();
184
+ return candidate.requestConfig.targets.find((t) => t.name.toLowerCase() === lower)?.name;
185
+ }
186
+ /** Mirrors frontendContractEvaluation.ts's/externalReferenceRequirements.ts's own independently-owned `RELATIONSHIP_FAMILY_GROUPS` shape - the third such duplicate in this repository, per the same established "never share this constant cross-module" convention. */
187
+ const RELATIONSHIP_FAMILY_GROUPS = [
188
+ HORIZONTAL_ORDER_RELATIONSHIPS,
189
+ VERTICAL_ORDER_RELATIONSHIPS,
190
+ AREA_OVERLAP_RELATIONSHIPS,
191
+ RELATIVE_WIDTH_RELATIONSHIPS,
192
+ GEOMETRIC_FIT_RELATIONSHIPS,
193
+ VERTICAL_SEQUENCE_RELATIONSHIPS,
194
+ ];
195
+ // ---------------------------------------------------------------------------
196
+ // Per-requirement evaluation
197
+ // ---------------------------------------------------------------------------
198
+ function baseFields(requirement) {
199
+ return {
200
+ requirementId: requirement.requirementId,
201
+ category: requirement.category,
202
+ subject: requirement.subject,
203
+ ...(requirement.expectedDependentMode !== undefined ? { expectedDependentMode: requirement.expectedDependentMode } : {}),
204
+ };
205
+ }
206
+ function unavailable(requirement, boundRuntimeTargets, reasonCode, detail) {
207
+ return { ...baseFields(requirement), boundRuntimeTargets, status: 'unavailable', reasonCode, detail };
208
+ }
209
+ function bindingFor(bindingsByRegion, regionId) {
210
+ return bindingsByRegion.get(regionId.toLowerCase());
211
+ }
212
+ function evaluateRegionPropertyRequirement(requirement, subject, reference, candidate, bindingsByRegion, scaleResult, options) {
213
+ const expectation = deriveReferenceRequirementExpectation(subject, reference.regions ?? [], options);
214
+ if (!expectation.available)
215
+ return unavailable(requirement, [], 'reference-evidence-unavailable', expectation.reason);
216
+ if (expectation.kind !== 'numeric')
217
+ return unavailable(requirement, [], 'reference-evidence-unavailable', 'a region-property subject unexpectedly produced non-numeric reference evidence');
218
+ const binding = bindingFor(bindingsByRegion, subject.region);
219
+ if (!binding || binding.status !== 'bound') {
220
+ return unavailable(requirement, [], 'binding-unavailable', binding ? binding.detail : `no runtime binding declared for reference region "${subject.region}"`);
221
+ }
222
+ const boundRuntimeTargets = [binding.runtimeTarget];
223
+ const configuredName = resolveConfiguredTargetName(candidate, binding.runtimeTarget);
224
+ const record = configuredName ? candidate.targetEvidence[configuredName] : undefined;
225
+ const visibility = record ? evidenceValue(record.visibility) : undefined;
226
+ if (!visibility || !visibility.visible) {
227
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'bound runtime target is not visible; geometry evidence is not usable for fidelity evaluation');
228
+ }
229
+ const geometry = record ? evidenceValue(record.geometry) : undefined;
230
+ if (!geometry) {
231
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'bound runtime target has no geometry evidence');
232
+ }
233
+ if (!scaleResult.ok) {
234
+ return unavailable(requirement, boundRuntimeTargets, 'coordinate-mapping-unavailable', scaleResult.reason);
235
+ }
236
+ const rawGeometry = candidateRawGeometry(geometry);
237
+ const scaledGeometry = scaleGeometryToReferenceSpace(rawGeometry, scaleResult.scale);
238
+ const candidateRawValue = rawGeometry[subject.property];
239
+ const candidateValue = scaledGeometry[subject.property];
240
+ const referenceValue = expectation.value;
241
+ const delta = candidateValue - referenceValue;
242
+ const tolerance = requirement.tolerance;
243
+ const allowed = referenceToleranceAmountPx(tolerance, referenceValue);
244
+ const status = Math.abs(delta) <= allowed ? 'pass' : 'fail';
245
+ return { ...baseFields(requirement), boundRuntimeTargets, status, referenceValue, candidateRawValue, candidateValue, delta, tolerance };
246
+ }
247
+ function evaluateRegionMeasurementRequirement(requirement, subject, reference, candidate, bindingsByRegion, scaleResult, options) {
248
+ const expectation = deriveReferenceRequirementExpectation(subject, reference.regions ?? [], options);
249
+ if (!expectation.available)
250
+ return unavailable(requirement, [], 'reference-evidence-unavailable', expectation.reason);
251
+ if (expectation.kind !== 'numeric')
252
+ return unavailable(requirement, [], 'reference-evidence-unavailable', 'a region-measurement subject unexpectedly produced non-numeric reference evidence');
253
+ const subjectBinding = bindingFor(bindingsByRegion, subject.subjectRegion);
254
+ const relatedBinding = bindingFor(bindingsByRegion, subject.relatedRegion);
255
+ if (!subjectBinding || subjectBinding.status !== 'bound') {
256
+ return unavailable(requirement, [], 'binding-unavailable', subjectBinding ? subjectBinding.detail : `no runtime binding declared for reference region "${subject.subjectRegion}"`);
257
+ }
258
+ if (!relatedBinding || relatedBinding.status !== 'bound') {
259
+ return unavailable(requirement, [subjectBinding.runtimeTarget], 'binding-unavailable', relatedBinding ? relatedBinding.detail : `no runtime binding declared for reference region "${subject.relatedRegion}"`);
260
+ }
261
+ const boundRuntimeTargets = [subjectBinding.runtimeTarget, relatedBinding.runtimeTarget];
262
+ const subjectConfiguredName = resolveConfiguredTargetName(candidate, subjectBinding.runtimeTarget);
263
+ const relatedConfiguredName = resolveConfiguredTargetName(candidate, relatedBinding.runtimeTarget);
264
+ const subjectRecord = subjectConfiguredName ? candidate.targetEvidence[subjectConfiguredName] : undefined;
265
+ const relatedRecord = relatedConfiguredName ? candidate.targetEvidence[relatedConfiguredName] : undefined;
266
+ const subjectVisibility = subjectRecord ? evidenceValue(subjectRecord.visibility) : undefined;
267
+ const relatedVisibility = relatedRecord ? evidenceValue(relatedRecord.visibility) : undefined;
268
+ if (!subjectVisibility?.visible || !relatedVisibility?.visible) {
269
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'one or both bound runtime targets are not visible; geometry evidence is not usable for fidelity evaluation');
270
+ }
271
+ const subjectGeometry = subjectRecord ? evidenceValue(subjectRecord.geometry) : undefined;
272
+ const relatedGeometry = relatedRecord ? evidenceValue(relatedRecord.geometry) : undefined;
273
+ if (!subjectGeometry || !relatedGeometry) {
274
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'one or both bound runtime targets have no geometry evidence');
275
+ }
276
+ if (!scaleResult.ok) {
277
+ return unavailable(requirement, boundRuntimeTargets, 'coordinate-mapping-unavailable', scaleResult.reason);
278
+ }
279
+ const subjectRaw = candidateRawGeometry(subjectGeometry);
280
+ const relatedRaw = candidateRawGeometry(relatedGeometry);
281
+ const subjectScaled = scaleGeometryToReferenceSpace(subjectRaw, scaleResult.scale);
282
+ const relatedScaled = scaleGeometryToReferenceSpace(relatedRaw, scaleResult.scale);
283
+ const candidateRawValue = deriveReferenceRequirementMeasurement(subject.measurement, subjectRaw, relatedRaw);
284
+ const candidateValue = deriveReferenceRequirementMeasurement(subject.measurement, subjectScaled, relatedScaled);
285
+ if (candidateValue === undefined) {
286
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', `"${subject.measurement}" is geometrically undefined for these two bound runtime targets (they overlap on the relevant axis)`);
287
+ }
288
+ const referenceValue = expectation.value;
289
+ const delta = candidateValue - referenceValue;
290
+ const tolerance = requirement.tolerance;
291
+ const allowed = referenceToleranceAmountPx(tolerance, referenceValue);
292
+ const status = Math.abs(delta) <= allowed ? 'pass' : 'fail';
293
+ return {
294
+ ...baseFields(requirement),
295
+ boundRuntimeTargets,
296
+ status,
297
+ referenceValue,
298
+ ...(candidateRawValue !== undefined ? { candidateRawValue } : {}),
299
+ candidateValue,
300
+ delta,
301
+ tolerance,
302
+ };
303
+ }
304
+ function evaluateRegionRelationshipRequirement(requirement, subject, reference, candidate, bindingsByRegion, options) {
305
+ const expectation = deriveReferenceRequirementExpectation(subject, reference.regions ?? [], options);
306
+ if (!expectation.available)
307
+ return unavailable(requirement, [], 'reference-evidence-unavailable', expectation.reason);
308
+ if (expectation.kind === 'relationship' && !expectation.matches) {
309
+ return unavailable(requirement, [], 'reference-relationship-not-exhibited', `the reference does not exhibit the required "${subject.relationship}" relationship between "${subject.subjectRegion}" and "${subject.relatedRegion}"`);
310
+ }
311
+ const subjectBinding = bindingFor(bindingsByRegion, subject.subjectRegion);
312
+ const relatedBinding = bindingFor(bindingsByRegion, subject.relatedRegion);
313
+ if (!subjectBinding || subjectBinding.status !== 'bound') {
314
+ return unavailable(requirement, [], 'binding-unavailable', subjectBinding ? subjectBinding.detail : `no runtime binding declared for reference region "${subject.subjectRegion}"`);
315
+ }
316
+ if (!relatedBinding || relatedBinding.status !== 'bound') {
317
+ return unavailable(requirement, [subjectBinding.runtimeTarget], 'binding-unavailable', relatedBinding ? relatedBinding.detail : `no runtime binding declared for reference region "${subject.relatedRegion}"`);
318
+ }
319
+ const boundRuntimeTargets = [subjectBinding.runtimeTarget, relatedBinding.runtimeTarget];
320
+ const relationshipsResult = deriveLayoutRelationships(candidate, options.geometryTolerancePx !== undefined ? { geometryTolerancePx: options.geometryTolerancePx } : {});
321
+ if (!relationshipsResult.ok) {
322
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', relationshipsResult.reason);
323
+ }
324
+ const subjectTargetName = resolveConfiguredTargetName(candidate, subjectBinding.runtimeTarget);
325
+ const relatedTargetName = resolveConfiguredTargetName(candidate, relatedBinding.runtimeTarget);
326
+ if (!subjectTargetName || !relatedTargetName) {
327
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'bound runtime target is not part of the candidate\'s configured target set');
328
+ }
329
+ const unresolved = new Set(relationshipsResult.graph.unresolvedTargets.map((u) => u.target));
330
+ if (unresolved.has(subjectTargetName) || unresolved.has(relatedTargetName)) {
331
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', 'one or both bound runtime targets have no usable geometry for relationship derivation');
332
+ }
333
+ const family = RELATIONSHIP_FAMILY_GROUPS.find((group) => group.includes(subject.relationship));
334
+ const direct = relationshipsResult.graph.pairwiseRelationships.find((r) => family.includes(r.kind) && r.subjectTarget === subjectTargetName && r.relatedTarget === relatedTargetName);
335
+ if (direct) {
336
+ const status = direct.kind === subject.relationship ? 'pass' : 'fail';
337
+ return { ...baseFields(requirement), boundRuntimeTargets, status, expectedRelationship: subject.relationship, actualRelationship: direct.kind };
338
+ }
339
+ const reversed = relationshipsResult.graph.pairwiseRelationships.find((r) => family.includes(r.kind) && r.subjectTarget === relatedTargetName && r.relatedTarget === subjectTargetName);
340
+ if (reversed) {
341
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', `runtime relationship evidence for the bound targets was only derivable in the opposite order (found "${reversed.kind}") - this requirement's subjectRegion/relatedRegion order does not match the candidate's configured target order`);
342
+ }
343
+ return unavailable(requirement, boundRuntimeTargets, 'candidate-evidence-unavailable', `no "${subject.relationship}" runtime relationship evidence was derivable between the bound targets`);
344
+ }
345
+ function evaluateOneRequirement(requirement, reference, candidate, bindingsByRegion, scaleResult, options) {
346
+ const subject = requirement.subject;
347
+ if (subject.kind === 'region-property')
348
+ return evaluateRegionPropertyRequirement(requirement, subject, reference, candidate, bindingsByRegion, scaleResult, options);
349
+ if (subject.kind === 'region-measurement')
350
+ return evaluateRegionMeasurementRequirement(requirement, subject, reference, candidate, bindingsByRegion, scaleResult, options);
351
+ return evaluateRegionRelationshipRequirement(requirement, subject, reference, candidate, bindingsByRegion, options);
352
+ }
353
+ // ---------------------------------------------------------------------------
354
+ // Top-level evaluation
355
+ // ---------------------------------------------------------------------------
356
+ /**
357
+ * Pure and synchronous. Evaluation order (frozen by this prompt's own
358
+ * design, never reordered): reference structural validation -> candidate
359
+ * structural validation -> binding-declaration structural validation ->
360
+ * Prompt 3 reference adequacy -> Prompt 4 compatibility -> Prompt 5 binding
361
+ * evaluation -> per-requirement candidate-evidence/coordinate-mapping
362
+ * checks -> per-requirement tolerance/relationship comparison -> overall
363
+ * result. An earlier blocking gate (adequacy `inadequate`, compatibility
364
+ * `incomparable`) always short-circuits to `state: 'not-evaluated'` with an
365
+ * empty `requirementResults` - no ordinary PASS/FAIL set is ever fabricated
366
+ * past a blocked gate.
367
+ */
368
+ export function evaluateReferenceCandidateFidelity(reference, candidate, bindingDeclarations, options = {}) {
369
+ const referenceValidation = isValidExternalReferenceArtifact(reference);
370
+ if (!referenceValidation.valid)
371
+ return { ok: false, reason: `reference is invalid: ${referenceValidation.reason}` };
372
+ const candidateValidation = isValidObservationArtifact(candidate);
373
+ if (!candidateValidation.valid)
374
+ return { ok: false, reason: `candidate is invalid: ${candidateValidation.reason}` };
375
+ const geometryOptions = options.geometryTolerancePx !== undefined ? { geometryTolerancePx: options.geometryTolerancePx } : {};
376
+ const adequacy = deriveReferenceRequirementAdequacy(reference.regions ?? [], reference.requirements ?? [], geometryOptions);
377
+ const provenance = {
378
+ referenceId: reference.referenceId,
379
+ referenceRequestId: reference.referenceRequestId,
380
+ candidateObservationId: candidate.observationId,
381
+ candidateRequestId: candidate.requestId,
382
+ };
383
+ if (adequacy.status === 'inadequate') {
384
+ return { ok: true, evaluation: { ...provenance, adequacy, state: 'not-evaluated', blockedBy: 'reference-inadequate', requirementResults: [] } };
385
+ }
386
+ const compatibilityResult = evaluateReferenceCandidateCompatibility(reference, candidate);
387
+ if (compatibilityResult.compatibility.state === 'incomparable') {
388
+ return {
389
+ ok: true,
390
+ evaluation: { ...provenance, adequacy, compatibility: compatibilityResult.compatibility, state: 'not-evaluated', blockedBy: 'incompatible', requirementResults: [] },
391
+ };
392
+ }
393
+ const bindingEvaluationResult = evaluateReferenceRuntimeBindings(reference, candidate, bindingDeclarations);
394
+ if (!bindingEvaluationResult.ok)
395
+ return { ok: false, reason: bindingEvaluationResult.reason };
396
+ const bindingEvaluation = bindingEvaluationResult.evaluation;
397
+ const bindingsByRegion = new Map(bindingEvaluation.bindings.map((b) => [b.referenceRegion.toLowerCase(), b]));
398
+ const scaleResult = deriveCoordinateScale(reference);
399
+ const requirementResults = (reference.requirements ?? []).map((requirement) => evaluateOneRequirement(requirement, reference, candidate, bindingsByRegion, scaleResult, geometryOptions));
400
+ const state = requirementResults.every((r) => r.status === 'pass') ? 'pass' : 'fail';
401
+ return {
402
+ ok: true,
403
+ evaluation: {
404
+ ...provenance,
405
+ adequacy,
406
+ compatibility: compatibilityResult.compatibility,
407
+ bindings: bindingEvaluation,
408
+ state,
409
+ requirementResults,
410
+ },
411
+ };
412
+ }
413
+ //# sourceMappingURL=externalReferenceFidelity.js.map
@@ -0,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uB,GAAG,gCAAgC,CAAC,SAAS,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAC5G,IAAI,CAAC,uBAAuB,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,CAAC,MAAM,EAAE,CAAC;IAC9F,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,UAAU,CAAC;IAE7D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC,CAAU,CAAC,CAAC,CAAC;IACvH,MAAM,WAAW,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAErD,MAAM,kBAAkB,GAAG,CAAC,SAAS,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAC5E,sBAAsB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAC1G,CAAC;IAEF,MAAM,KAAK,GAA2B,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAE7G,OAAO;QACL,EAAE,EAAE,IAAI;QACR,UAAU,EAAE;YACV,GAAG,UAAU;YACb,QAAQ;YACR,aAAa,EAAE,mBAAmB,CAAC,aAAa;YAChD,QAAQ,EAAE,iBAAiB;YAC3B,KAAK;YACL,kBAAkB;SACnB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ExternalReferenceImageFormat } from './externalReferenceImage.js';
2
+ import type { ReferenceRegion } from './externalReferenceRegions.js';
3
+ import type { ExternalReferenceRequirement } from './externalReferenceRequirements.js';
4
+ import type { ExternalReferenceApplicability } from './externalReferenceApplicability.js';
5
+ /**
6
+ * Pure function of {imageSha256, format, width, height, supersedesReferenceId,
7
+ * regions?} - the semantic content of the reference image, which prior
8
+ * reference (if any) it explicitly supersedes, and (v0.7 Prompt 2 addition)
9
+ * its explicitly authored reference regions when present. Never includes a
10
+ * filesystem path, output location, a captured timestamp, or a
11
+ * caller-supplied label: two imports of byte-identical image content and
12
+ * region content from different operational locations, with different
13
+ * labels, produce the same logical identity; changing the image content, its
14
+ * detected format/dimensions, the supersession target, or the region set
15
+ * (added/removed/renamed/moved/resized) changes it.
16
+ *
17
+ * `regions`/`requirements`/`applicability` are each omitted from the hashed
18
+ * view entirely when not supplied (rather than included as `null`, unlike
19
+ * `supersedes`) so that every pre-Prompt-2/3/4 call site - and every later
20
+ * call that legitimately omits one of them - keeps producing byte-identical
21
+ * identity to the earlier prompt, never a new hash purely because a
22
+ * parameter now exists. Region/requirement order is part of the semantic
23
+ * view (authored order is semantic, mirroring domain/identity.ts's `targets`
24
+ * treatment) - canonicalize sorts object keys but deliberately never
25
+ * reorders arrays. `requirements` entries already carry their own
26
+ * content-derived `requirementId` (see externalReferenceRequirementIdentity.ts),
27
+ * so changing a selected property, tolerance, or category changes both that
28
+ * requirement's own id and this artifact-level identity.
29
+ */
30
+ export declare function buildExternalReferenceRequestIdentity(imageSha256: string, format: ExternalReferenceImageFormat, width: number, height: number, supersedesReferenceId?: string, regions?: readonly ReferenceRegion[], requirements?: readonly ExternalReferenceRequirement[], applicability?: ExternalReferenceApplicability): string;
31
+ /**
32
+ * Fresh, opaque per-persisted-instance identity - never derived from a
33
+ * timestamp alone, never collides even when called twice with the same
34
+ * requestIdentity within the same millisecond. Used both for a fresh import
35
+ * and for a fresh approval of an already-imported reference (same
36
+ * referenceRequestId, a new referenceId each time something is persisted).
37
+ */
38
+ export declare function buildExternalReferenceInstanceIdentity(requestIdentity: string): string;