my-frontend-observer 0.5.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 (123) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +56 -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 +226 -0
  18. package/dist/domain/boundedAgentContext.js +355 -0
  19. package/dist/domain/boundedAgentContext.js.map +1 -0
  20. package/dist/domain/boundedAgentContextCorrelation.d.ts +74 -0
  21. package/dist/domain/boundedAgentContextCorrelation.js +441 -0
  22. package/dist/domain/boundedAgentContextCorrelation.js.map +1 -0
  23. package/dist/domain/boundedAgentContextIdentity.d.ts +26 -0
  24. package/dist/domain/boundedAgentContextIdentity.js +69 -0
  25. package/dist/domain/boundedAgentContextIdentity.js.map +1 -0
  26. package/dist/domain/boundedAgentContextProjection.d.ts +71 -0
  27. package/dist/domain/boundedAgentContextProjection.js +477 -0
  28. package/dist/domain/boundedAgentContextProjection.js.map +1 -0
  29. package/dist/domain/comparison.d.ts +23 -1
  30. package/dist/domain/comparison.js +27 -1
  31. package/dist/domain/comparison.js.map +1 -1
  32. package/dist/domain/comparisonEngine.d.ts +34 -6
  33. package/dist/domain/comparisonEngine.js +48 -8
  34. package/dist/domain/comparisonEngine.js.map +1 -1
  35. package/dist/domain/diagnostics.d.ts +1 -1
  36. package/dist/domain/diagnostics.js +16 -0
  37. package/dist/domain/diagnostics.js.map +1 -1
  38. package/dist/domain/explicitState.d.ts +40 -0
  39. package/dist/domain/explicitState.js +54 -0
  40. package/dist/domain/explicitState.js.map +1 -0
  41. package/dist/domain/externalReference.d.ts +158 -0
  42. package/dist/domain/externalReference.js +167 -0
  43. package/dist/domain/externalReference.js.map +1 -0
  44. package/dist/domain/externalReferenceApplicability.d.ts +43 -0
  45. package/dist/domain/externalReferenceApplicability.js +52 -0
  46. package/dist/domain/externalReferenceApplicability.js.map +1 -0
  47. package/dist/domain/externalReferenceCompatibility.d.ts +40 -0
  48. package/dist/domain/externalReferenceCompatibility.js +48 -0
  49. package/dist/domain/externalReferenceCompatibility.js.map +1 -0
  50. package/dist/domain/externalReferenceFidelity.d.ts +141 -0
  51. package/dist/domain/externalReferenceFidelity.js +413 -0
  52. package/dist/domain/externalReferenceFidelity.js.map +1 -0
  53. package/dist/domain/externalReferenceIdentity.d.ts +38 -0
  54. package/dist/domain/externalReferenceIdentity.js +70 -0
  55. package/dist/domain/externalReferenceIdentity.js.map +1 -0
  56. package/dist/domain/externalReferenceImage.d.ts +35 -0
  57. package/dist/domain/externalReferenceImage.js +160 -0
  58. package/dist/domain/externalReferenceImage.js.map +1 -0
  59. package/dist/domain/externalReferenceRegionRelationships.d.ts +63 -0
  60. package/dist/domain/externalReferenceRegionRelationships.js +98 -0
  61. package/dist/domain/externalReferenceRegionRelationships.js.map +1 -0
  62. package/dist/domain/externalReferenceRegions.d.ts +65 -0
  63. package/dist/domain/externalReferenceRegions.js +105 -0
  64. package/dist/domain/externalReferenceRegions.js.map +1 -0
  65. package/dist/domain/externalReferenceRequirementIdentity.d.ts +12 -0
  66. package/dist/domain/externalReferenceRequirementIdentity.js +35 -0
  67. package/dist/domain/externalReferenceRequirementIdentity.js.map +1 -0
  68. package/dist/domain/externalReferenceRequirements.d.ts +215 -0
  69. package/dist/domain/externalReferenceRequirements.js +401 -0
  70. package/dist/domain/externalReferenceRequirements.js.map +1 -0
  71. package/dist/domain/externalReferenceRuntimeBinding.d.ts +146 -0
  72. package/dist/domain/externalReferenceRuntimeBinding.js +183 -0
  73. package/dist/domain/externalReferenceRuntimeBinding.js.map +1 -0
  74. package/dist/domain/identity.d.ts +11 -8
  75. package/dist/domain/identity.js +12 -8
  76. package/dist/domain/identity.js.map +1 -1
  77. package/dist/domain/referenceCorrectionIdentity.d.ts +40 -0
  78. package/dist/domain/referenceCorrectionIdentity.js +77 -0
  79. package/dist/domain/referenceCorrectionIdentity.js.map +1 -0
  80. package/dist/domain/referenceCorrectionWorkflow.d.ts +160 -0
  81. package/dist/domain/referenceCorrectionWorkflow.js +165 -0
  82. package/dist/domain/referenceCorrectionWorkflow.js.map +1 -0
  83. package/dist/domain/referenceFidelityProjection.d.ts +65 -0
  84. package/dist/domain/referenceFidelityProjection.js +135 -0
  85. package/dist/domain/referenceFidelityProjection.js.map +1 -0
  86. package/dist/domain/relationships.d.ts +43 -1
  87. package/dist/domain/relationships.js +15 -6
  88. package/dist/domain/relationships.js.map +1 -1
  89. package/dist/domain/schema.js +6 -0
  90. package/dist/domain/schema.js.map +1 -1
  91. package/dist/index.d.ts +44 -2
  92. package/dist/index.js +24 -1
  93. package/dist/index.js.map +1 -1
  94. package/dist/request/request.d.ts +12 -0
  95. package/dist/request/request.js +12 -0
  96. package/dist/request/request.js.map +1 -1
  97. package/docs/ARCHITECTURE.md +341 -19
  98. package/docs/CI_CD.md +71 -0
  99. package/docs/COMMANDS.md +187 -0
  100. package/docs/CONTRACTS.md +1416 -13
  101. package/docs/CURRENT_STATE.md +508 -14
  102. package/docs/DEVELOPMENT.md +5 -3
  103. package/docs/DOCUMENTATION_PRESERVATION_POLICY.md +33 -33
  104. package/docs/PROJECT_DESCRIPTION.md +2195 -1770
  105. package/docs/PROJECT_MILESTONES.md +2526 -2073
  106. package/docs/PROJECT_OVERVIEW.md +63 -14
  107. package/docs/QUICKSTART.md +6 -0
  108. package/docs/RELEASE.md +28 -21
  109. package/docs/ROADMAP.md +241 -99
  110. package/docs/SECURITY.md +97 -4
  111. package/docs/WORKFLOWS.md +391 -24
  112. package/docs/reports/v0.7-bounded-fidelity-context-prompt7.md +243 -0
  113. package/docs/reports/v0.7-implementation-completeness-documentation-reconciliation.md +497 -0
  114. package/docs/reports/v0.7-pre-release-readiness.md +337 -0
  115. package/docs/reports/v0.7-reference-binding-prompt5.md +223 -0
  116. package/docs/reports/v0.7-reference-compatibility-prompt4.md +234 -0
  117. package/docs/reports/v0.7-reference-correction-workflow-prompt8.md +222 -0
  118. package/docs/reports/v0.7-reference-fidelity-prompt6.md +216 -0
  119. package/docs/reports/v0.7-reference-foundation-prompt1.md +151 -0
  120. package/docs/reports/v0.7-reference-regions-prompt2.md +195 -0
  121. package/docs/reports/v0.7-reference-requirements-prompt3.md +217 -0
  122. package/docs/reports/v0.7-release-prep.md +423 -0
  123. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,120 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 - 2026-09-06
4
+
5
+ End-to-End Coding-Agent Frontend Change Review.
6
+
7
+ - External-reference artifact and lifecycle: `import-reference`/
8
+ `approve-reference` persist an externally supplied PNG/JPEG/WebP
9
+ design-reference image (header-only format/dimension detection - no
10
+ decode, no OCR, no computer vision) through an explicit two-state
11
+ (`imported`/`approved`) lifecycle. Supersession is represented only as a
12
+ forward pointer to a newer artifact - an existing persisted artifact's own
13
+ manifest is never rewritten.
14
+ - Explicit reference regions and geometry relationships: user/configuration-
15
+ authored rectangles over the reference image, related to each other
16
+ through the same six geometry-only relationship families (horizontal
17
+ order, vertical order, area overlap, relative width, geometric fit,
18
+ vertical sequencing) already used for runtime targets - derived on demand,
19
+ never persisted.
20
+ - Selected design requirements and tolerance semantics: explicit,
21
+ never-inferred requirements over region properties, region-to-region
22
+ relationships, and derived two-region measurements, reusing v0.5's
23
+ requested/expected-dependent/protected/preserved categories directly.
24
+ Three reference-owned tolerance kinds (`exact`/`absolute-reference-px`/
25
+ `percent`) stay distinct from runtime CSS-pixel comparison tolerances.
26
+ - Reference-evidence adequacy: `adequate`/`partial`/`inadequate` reporting on
27
+ whether a reference's own definition actually supports its selected
28
+ requirements, independent of any runtime target or candidate.
29
+ - Explicit applicability and candidate-state compatibility: a shared, closed
30
+ state model (`theme`/`applicationState`/`authenticatedState`, plus an
31
+ applicable CSS-pixel `viewport`) declares which runtime frontend state a
32
+ reference represents. `evaluateReferenceCandidateCompatibility` and
33
+ `observe`'s new `--state-file` reuse v0.4's comparability vocabulary to
34
+ determine whether a reference and a candidate describe the same state -
35
+ an undeclared dimension is never fabricated as a match or a mismatch.
36
+ - Explicit reference-region-to-runtime-target binding: fidelity evaluation
37
+ requires an explicit `{referenceRegion, runtimeTarget}` declaration for
38
+ every region a requirement depends on - never inferred from geometry,
39
+ matching names, or source code.
40
+ - Structured reference-vs-candidate fidelity evaluation: `evaluate-
41
+ reference-fidelity --reference --candidate [--bindings-file] [--enforce]`
42
+ evaluates every selected requirement against live candidate evidence
43
+ through one explicit reference-image-pixel-to-CSS-pixel coordinate scale,
44
+ producing an honest `not-evaluated`/`pass`/`fail` result that never
45
+ fabricates a verdict past a blocked reference-adequacy or
46
+ reference/candidate-compatibility gate.
47
+ - Bounded fidelity integration with v0.6 agent context: `projectBoundedAgentContext`
48
+ gained an optional `fidelity` input so fidelity mismatches compete for the
49
+ same bounded required/permitted-target allocation and adequacy machinery
50
+ v0.5 contract clauses already use - a `not-evaluated` fidelity always
51
+ degrades adequacy rather than being silently reported as "no problems".
52
+ - End-to-end external-reference correction workflow: the programmatic,
53
+ library-only `prepareReferenceCorrection`/`reviewReferenceCorrectionAttempt`
54
+ compose reference fidelity, v0.4 comparison, and v0.5 contract evaluation
55
+ into one overall result - matching the reference is necessary but never
56
+ sufficient, so a candidate that visually satisfies the reference while
57
+ regressing an active protected/preserved contract clause still resolves to
58
+ overall `FAIL`. Neither function edits target source, launches a browser,
59
+ or calls a remote AI provider; an external implementation actor (a human
60
+ or a coding agent) makes the actual change between review attempts.
61
+ - Real-browser regression protection: a dedicated Chromium-driven test
62
+ proves a full success correction, a protected-regression case, a
63
+ two-attempt correction iteration against the same baseline, and an
64
+ incompatible-viewport blocking case, all against a disposable,
65
+ repository-local fixture copy the observer itself never edits.
66
+ - Three new public CLI commands (`import-reference`, `approve-reference`,
67
+ `evaluate-reference-fidelity`) and a complete new programmatic export
68
+ surface (`src/index.ts`) for the reference/region/requirement/
69
+ applicability/compatibility/binding/fidelity/correction-workflow types and
70
+ functions. External-reference schema is `1.0.0`, independent of the
71
+ observation, comparison, frontend-contract, evaluation, and
72
+ bounded-agent-context schema versions, none of which changed.
73
+ - Cross-platform packed-candidate validation: the pre-version-bump
74
+ implementation candidate tarball `my-frontend-observer-0.6.0.tgz`
75
+ (SHA-256 `0347b1f3cfd5d311e13b405c0c2fbc2f507e250cb63223d58b4d2d31df029414`)
76
+ was hash-verified and proven on Windows, Linux, and macOS, including an
77
+ installed-package smoke of every new v0.7 CLI command and programmatic
78
+ export alongside every pre-existing v0.1-v0.6 packed behavior, before this
79
+ release's version bump - see
80
+ `docs/reports/v0.7-pre-release-readiness.md`.
81
+
82
+ ## 0.6.0 - 2026-08-19
83
+
84
+ Bounded Agent Context and Native my-dev-kit Ecosystem Integration.
85
+
86
+ - Bounded runtime projection (`src/domain/boundedAgentContext.ts`,
87
+ `boundedAgentContextProjection.ts#projectBoundedAgentContext`): a
88
+ task-relevant, bounded view of page/viewport identity, stable targets,
89
+ geometry, runtime behavior, relationships, before/after differences,
90
+ contract results, requested/expected-dependent/protected/preserved scope
91
+ (reusing the existing v0.5 `frontendContracts.ts` types directly), and
92
+ screenshot/artifact references - never a raw evidence dump.
93
+ - Explicit adequacy reporting (`adequate`/`partial`/`inadequate` with
94
+ structured reason codes) and omission/truncation records, distinguishing
95
+ required from optional loss.
96
+ - Explicit runtime/static correlation
97
+ (`boundedAgentContextCorrelation.ts#deriveRuntimeStaticCorrelations`/
98
+ `attachRuntimeStaticCorrelations`): `correlated`/`ambiguous`/`unavailable`
99
+ outcomes only - a stable runtime target identity never silently becomes a
100
+ source-ownership claim, and competing candidates remain visible.
101
+ - Deterministic logical identity (`boundedAgentContextIdentity.ts`) distinct
102
+ from fresh per-execution instance identity.
103
+ - Public export/correlation boundary only: `src/index.ts` exports the full
104
+ bounded-agent-context and correlation type/function surface as a
105
+ programmatic library contract (bounded-agent-context schema `1.0.0`) - no
106
+ new CLI command, no disk artifact writer/reader, no `my-dev-kit` runtime
107
+ dependency, no orchestrator/lab code in this repository.
108
+ - Observation schema remains `1.2.0`, comparison schema `1.0.0`, frontend
109
+ contract schema `1.0.0`, evaluation artifact schema `1.0.0` - no existing
110
+ schema was bumped.
111
+ - Cross-platform packed-candidate validation: one hash-verified npm
112
+ candidate tarball (`acd067247c447294a611f37f52eab301b6038ab1c6d493ae65e81c2f1279bfd7`)
113
+ proven on Windows, Linux, and macOS, including an installed-package smoke
114
+ of the new bounded-agent-context projection and runtime/static
115
+ correlation exports alongside every pre-existing v0.1-v0.5 packed
116
+ behavior.
117
+
3
118
  ## 0.5.0 - 2026-08-13
4
119
 
5
120
  Executable Frontend Contracts and Explicit Change Scope.
package/README.md CHANGED
@@ -6,8 +6,10 @@ in [docs/PROJECT_DESCRIPTION.md](docs/PROJECT_DESCRIPTION.md).
6
6
 
7
7
  ## Current status
8
8
 
9
- `v0.5.0`, Executable Frontend Contracts and Explicit Change Scope, is the
10
- current published release: `my-frontend-observer observe` launches a real,
9
+ `v0.7.0`, End-to-End Coding-Agent Frontend Change Review, is the current
10
+ published release. It builds on `v0.6.0`, Bounded Agent Context and Native
11
+ my-dev-kit Ecosystem Integration, and `v0.5.0`, Executable Frontend
12
+ Contracts and Explicit Change Scope: `my-frontend-observer observe` launches a real,
11
13
  sandboxed Chromium browser, enforces a loopback-only safety policy, captures
12
14
  a viewport screenshot plus bounded page/target evidence, and persists it as
13
15
  one portable `manifest.json` + `screenshot.png` artifact (observation schema
@@ -119,6 +121,55 @@ verdict; the verdict itself, and its persisted evidence, are unaffected. See
119
121
  [docs/COMMANDS.md](docs/COMMANDS.md) for the full flag reference and
120
122
  [docs/WORKFLOWS.md](docs/WORKFLOWS.md) for the end-to-end flow.
121
123
 
124
+ ### Bounded agent context (v0.6.0)
125
+
126
+ `src/domain/boundedAgentContext.ts`, `boundedAgentContextProjection.ts`,
127
+ `boundedAgentContextCorrelation.ts`, and `boundedAgentContextIdentity.ts`
128
+ ship a programmatic (library-only, no CLI command) bounded runtime
129
+ projection and an explicit runtime/static correlation boundary
130
+ (`correlated`/`ambiguous`/`unavailable`, never inferred source ownership),
131
+ exported from `src/index.ts` (bounded-agent-context schema `1.0.0`). See
132
+ [docs/CONTRACTS.md](docs/CONTRACTS.md) for the exact contract and
133
+ [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for how it fits the existing
134
+ pipeline.
135
+
136
+ ### External-reference correction workflow (v0.7.0)
137
+
138
+ `import-reference` and
139
+ `approve-reference` persist an externally supplied design-reference image
140
+ (with optional regions, selected requirements/tolerances, and applicability
141
+ state); `evaluate-reference-fidelity --reference --candidate
142
+ [--bindings-file] [--enforce]` compares an already-persisted candidate
143
+ observation against it, gated by reference adequacy, reference/candidate
144
+ compatibility, and explicit region-to-target bindings:
145
+
146
+ ```powershell
147
+ my-frontend-observer import-reference design.png --output references --regions-file regions.json --requirements-file requirements.json --applicability-file applicability.json
148
+ my-frontend-observer approve-reference --reference references/<id> --output references
149
+ my-frontend-observer evaluate-reference-fidelity --reference references/<approved-id> --candidate observations/<id> --bindings-file bindings.json
150
+ ```
151
+
152
+ (From a source checkout, use `node dist/cli.js import-reference ...` etc.
153
+ instead.)
154
+
155
+ `import-reference`/`approve-reference`/`evaluate-reference-fidelity` never
156
+ launch a browser or edit any file outside their own declared output
157
+ location; `evaluate-reference-fidelity` persists nothing. A programmatic,
158
+ library-only correction-workflow coordinator
159
+ (`prepareReferenceCorrection`/`reviewReferenceCorrectionAttempt`, exported
160
+ from `src/index.ts`, no CLI command) composes the full cycle - reference
161
+ fidelity (reused unchanged) plus canonical v0.4 comparison and v0.5 contract
162
+ evaluation - into one overall result: matching the reference is necessary
163
+ but never sufficient, so a candidate that visually satisfies the reference
164
+ while regressing an active protected/preserved contract clause still
165
+ resolves to overall `FAIL`. my-frontend-observer never edits target source
166
+ itself; an external implementation actor (a human or a coding agent, never
167
+ this package) makes the actual source change between review attempts. See
168
+ [docs/CONTRACTS.md](docs/CONTRACTS.md) and
169
+ [docs/WORKFLOWS.md](docs/WORKFLOWS.md) for the exact contract and workflow,
170
+ and [docs/CURRENT_STATE.md](docs/CURRENT_STATE.md) for the full
171
+ implementation record.
172
+
122
173
  Validation:
123
174
 
124
175
  ```powershell
@@ -126,6 +177,7 @@ npm run typecheck
126
177
  npm run lint
127
178
  npm test
128
179
  npm run test:browser
180
+ npm run test:security
129
181
  npm run build
130
182
  npm run check:docs
131
183
  ```
@@ -136,8 +188,8 @@ Planning authorities:
136
188
  intent and responsibility boundaries.
137
189
  - [Project Milestones](docs/PROJECT_MILESTONES.md): complete ordered capability
138
190
  design and cross-milestone rules.
139
- - [ROADMAP](docs/ROADMAP.md): version-level requirements; v0.1-v0.5 are
140
- released, v0.6 is next.
191
+ - [ROADMAP](docs/ROADMAP.md): version-level requirements; v0.1-v0.7 are
192
+ released; v0.8+ remain future.
141
193
  - [Current State](docs/CURRENT_STATE.md): retained scaffold and release state.
142
194
 
143
195
  No sibling ecosystem repository is a runtime dependency of the retained
@@ -0,0 +1,75 @@
1
+ import type { Diagnostic } from '../domain/diagnostics.js';
2
+ import type { ReferenceRegion } from '../domain/externalReferenceRegions.js';
3
+ import type { RawReferenceRequirement, ReferenceRequirementAdequacy } from '../domain/externalReferenceRequirements.js';
4
+ import type { ExternalReferenceApplicability } from '../domain/externalReferenceApplicability.js';
5
+ import type { WriteExternalReferenceArtifactOptions } from '../artifacts/externalReferenceArtifactWriter.js';
6
+ export interface ImportExternalReferenceOptions {
7
+ outputLocation: string;
8
+ cwd?: WriteExternalReferenceArtifactOptions['cwd'];
9
+ label?: string;
10
+ /** Root directory of a prior external-reference artifact this import explicitly supersedes. */
11
+ supersedesReferenceRoot?: string;
12
+ /** v0.7 Prompt 2: explicit, user/configuration-authored reference-image regions. Identity-bearing when present - see externalReferenceIdentity.ts. */
13
+ regions?: ReferenceRegion[];
14
+ /** v0.7 Prompt 3: explicit, user/configuration-selected design requirements over `regions` above. Raw (not yet identified) authored input - see domain/externalReferenceRequirements.ts#RawReferenceRequirement. Identity-bearing when present. */
15
+ requirements?: RawReferenceRequirement[];
16
+ /** v0.7 Prompt 4: the runtime frontend state (applicable viewport/theme/application-state/authenticated-state) this reference is intended to represent. Identity-bearing when present. */
17
+ applicability?: ExternalReferenceApplicability;
18
+ }
19
+ export interface ApproveExternalReferenceOptions {
20
+ outputLocation: string;
21
+ cwd?: WriteExternalReferenceArtifactOptions['cwd'];
22
+ /** Root directory of a prior external-reference artifact this approval explicitly supersedes. */
23
+ supersedesReferenceRoot?: string;
24
+ }
25
+ export type ApplicationImportExternalReferenceResult = {
26
+ ok: true;
27
+ referenceId: string;
28
+ referenceRequestId: string;
29
+ artifactRoot: string;
30
+ manifestPath: string;
31
+ imagePath: string;
32
+ regionCount: number;
33
+ requirementCount: number;
34
+ adequacy: ReferenceRequirementAdequacy;
35
+ hasApplicability: boolean;
36
+ } | {
37
+ ok: false;
38
+ diagnostics: Diagnostic[];
39
+ };
40
+ export type ApplicationApproveExternalReferenceResult = {
41
+ ok: true;
42
+ referenceId: string;
43
+ referenceRequestId: string;
44
+ artifactRoot: string;
45
+ manifestPath: string;
46
+ regionCount: number;
47
+ requirementCount: number;
48
+ adequacy: ReferenceRequirementAdequacy;
49
+ hasApplicability: boolean;
50
+ } | {
51
+ ok: false;
52
+ diagnostics: Diagnostic[];
53
+ };
54
+ /**
55
+ * The one canonical application-level "import" use case: validates the raw
56
+ * image bytes through the existing pure image-format/dimension boundary
57
+ * (`domain/externalReferenceImage.ts`), resolves an optional explicit
58
+ * supersession target through the existing reader, computes identity through
59
+ * the existing identity module, and persists exactly once through the
60
+ * existing writer. Never approves the result - the persisted artifact's
61
+ * `lifecycle.state` is always `'imported'`, regardless of a supplied label or
62
+ * supersession target (see behavior-model.txt INV-007).
63
+ */
64
+ export declare function importExternalReference(imageBytes: Uint8Array, options: ImportExternalReferenceOptions): Promise<ApplicationImportExternalReferenceResult>;
65
+ /**
66
+ * The one canonical application-level "approval" use case, mirroring
67
+ * `application/frontendContractPersistenceService.ts#approveAndPersistBaseline`'s
68
+ * shape: reads the target through the existing reader, refuses to approve
69
+ * anything not currently in the `'imported'` lifecycle state, resolves an
70
+ * optional explicit supersession target through the same reader, and
71
+ * persists a brand-new artifact instance - never mutating the imported
72
+ * artifact's own manifest - carrying a `sourceReference` back to it instead
73
+ * of a second copy of the image bytes.
74
+ */
75
+ export declare function approveExternalReference(importedArtifactRoot: string, options: ApproveExternalReferenceOptions): Promise<ApplicationApproveExternalReferenceResult>;
@@ -0,0 +1,182 @@
1
+ import { createHash } from 'node:crypto';
2
+ import path from 'node:path';
3
+ import { DIAGNOSTIC_SEVERITY } from '../domain/diagnostics.js';
4
+ import { deriveCompletion } from '../domain/completion.js';
5
+ import { getProducerInfo } from '../domain/schema.js';
6
+ import { detectExternalReferenceImageFormat, readExternalReferenceImageDimensions, isValidExternalReferenceImageDimensions, fileExtensionForFormat, EXTERNAL_REFERENCE_MAX_IMAGE_BYTES, } from '../domain/externalReferenceImage.js';
7
+ import { EXTERNAL_REFERENCE_ARTIFACT_KIND, EXTERNAL_REFERENCE_SCHEMA_VERSION, isImportedExternalReferenceArtifact } from '../domain/externalReference.js';
8
+ import { buildExternalReferenceRequestIdentity, buildExternalReferenceInstanceIdentity } from '../domain/externalReferenceIdentity.js';
9
+ import { isValidReferenceRegions } from '../domain/externalReferenceRegions.js';
10
+ import { isValidRawReferenceRequirement, buildReferenceRequirement, isValidReferenceRequirements, deriveReferenceRequirementAdequacy } from '../domain/externalReferenceRequirements.js';
11
+ import { isValidExternalReferenceApplicability } from '../domain/externalReferenceApplicability.js';
12
+ import { normalizeOutputLocation } from '../request/paths.js';
13
+ import { writeExternalReferenceArtifact } from '../artifacts/externalReferenceArtifactWriter.js';
14
+ import { EXTERNAL_REFERENCE_MANIFEST_FILENAME } from '../artifacts/externalReferenceArtifactWriter.js';
15
+ import { readExternalReferenceArtifact } from '../artifacts/externalReferenceArtifactReader.js';
16
+ function failure(code, message) {
17
+ return { ok: false, diagnostics: [{ code, severity: DIAGNOSTIC_SEVERITY[code], message }] };
18
+ }
19
+ async function resolveSupersedesReferenceId(supersedesReferenceRoot) {
20
+ if (supersedesReferenceRoot === undefined)
21
+ return { ok: true };
22
+ const read = await readExternalReferenceArtifact(path.join(supersedesReferenceRoot, EXTERNAL_REFERENCE_MANIFEST_FILENAME));
23
+ if (!read.ok)
24
+ return failure('reference-not-found', `supersedesReferenceRoot: ${read.reason}`);
25
+ return { ok: true, referenceId: read.artifact.referenceId };
26
+ }
27
+ /**
28
+ * The one canonical application-level "import" use case: validates the raw
29
+ * image bytes through the existing pure image-format/dimension boundary
30
+ * (`domain/externalReferenceImage.ts`), resolves an optional explicit
31
+ * supersession target through the existing reader, computes identity through
32
+ * the existing identity module, and persists exactly once through the
33
+ * existing writer. Never approves the result - the persisted artifact's
34
+ * `lifecycle.state` is always `'imported'`, regardless of a supplied label or
35
+ * supersession target (see behavior-model.txt INV-007).
36
+ */
37
+ export async function importExternalReference(imageBytes, options) {
38
+ const format = detectExternalReferenceImageFormat(imageBytes);
39
+ if (format === undefined)
40
+ return failure('unsupported-image-format', 'the supplied bytes do not match any supported reference image format (png, jpeg, webp)');
41
+ if (imageBytes.length > EXTERNAL_REFERENCE_MAX_IMAGE_BYTES) {
42
+ return failure('image-too-large', `reference image is ${imageBytes.length} bytes, exceeding the maximum of ${EXTERNAL_REFERENCE_MAX_IMAGE_BYTES} bytes`);
43
+ }
44
+ const dimensions = readExternalReferenceImageDimensions(imageBytes, format);
45
+ if (dimensions === undefined || !isValidExternalReferenceImageDimensions(dimensions)) {
46
+ return failure('invalid-image-dimensions', 'the supplied reference image header does not contain valid, bounded dimensions');
47
+ }
48
+ if (options.regions !== undefined) {
49
+ const regionsValidation = isValidReferenceRegions(options.regions, dimensions.width, dimensions.height);
50
+ if (!regionsValidation.valid)
51
+ return failure('invalid-reference-region', regionsValidation.reason);
52
+ }
53
+ let requirements;
54
+ if (options.requirements !== undefined) {
55
+ const built = [];
56
+ for (const raw of options.requirements) {
57
+ const rawValidation = isValidRawReferenceRequirement(raw);
58
+ if (!rawValidation.valid)
59
+ return failure('invalid-reference-requirement', rawValidation.reason);
60
+ built.push(buildReferenceRequirement(raw));
61
+ }
62
+ const collectionValidation = isValidReferenceRequirements(built, options.regions ?? []);
63
+ if (!collectionValidation.valid)
64
+ return failure('invalid-reference-requirement', collectionValidation.reason);
65
+ requirements = built;
66
+ }
67
+ if (options.applicability !== undefined) {
68
+ const applicabilityValidation = isValidExternalReferenceApplicability(options.applicability);
69
+ if (!applicabilityValidation.valid)
70
+ return failure('invalid-reference-applicability', applicabilityValidation.reason);
71
+ }
72
+ const supersedes = await resolveSupersedesReferenceId(options.supersedesReferenceRoot);
73
+ if (!supersedes.ok)
74
+ return supersedes;
75
+ const normalizedOutput = normalizeOutputLocation(options.outputLocation);
76
+ if (!normalizedOutput.ok)
77
+ return { ok: false, diagnostics: [normalizedOutput.diagnostic] };
78
+ const imageSha256 = createHash('sha256').update(imageBytes).digest('hex');
79
+ const referenceRequestId = buildExternalReferenceRequestIdentity(imageSha256, format, dimensions.width, dimensions.height, supersedes.referenceId, options.regions, requirements, options.applicability);
80
+ const referenceId = buildExternalReferenceInstanceIdentity(referenceRequestId);
81
+ const artifact = {
82
+ artifactKind: EXTERNAL_REFERENCE_ARTIFACT_KIND,
83
+ schemaVersion: EXTERNAL_REFERENCE_SCHEMA_VERSION,
84
+ referenceRequestId,
85
+ referenceId,
86
+ producer: getProducerInfo(),
87
+ provenance: { importedAt: new Date().toISOString(), ...(options.label === undefined ? {} : { label: options.label }) },
88
+ image: {
89
+ path: `reference.${fileExtensionForFormat(format)}`,
90
+ format,
91
+ width: dimensions.width,
92
+ height: dimensions.height,
93
+ byteLength: imageBytes.length,
94
+ sha256: imageSha256,
95
+ },
96
+ lifecycle: { state: 'imported' },
97
+ ...(supersedes.referenceId === undefined ? {} : { supersedesReferenceId: supersedes.referenceId }),
98
+ ...(options.regions === undefined ? {} : { regions: options.regions }),
99
+ ...(requirements === undefined ? {} : { requirements }),
100
+ ...(options.applicability === undefined ? {} : { applicability: options.applicability }),
101
+ diagnostics: [],
102
+ completion: deriveCompletion([], 'post-capture'),
103
+ };
104
+ const persisted = await writeExternalReferenceArtifact(artifact, imageBytes, normalizedOutput.value, options.cwd === undefined ? {} : { cwd: options.cwd });
105
+ if (!persisted.ok)
106
+ return { ok: false, diagnostics: persisted.diagnostics };
107
+ return {
108
+ ok: true,
109
+ referenceId: artifact.referenceId,
110
+ referenceRequestId: artifact.referenceRequestId,
111
+ artifactRoot: persisted.artifactRoot,
112
+ manifestPath: persisted.manifestPath,
113
+ imagePath: persisted.imagePath,
114
+ regionCount: artifact.regions?.length ?? 0,
115
+ requirementCount: artifact.requirements?.length ?? 0,
116
+ adequacy: deriveReferenceRequirementAdequacy(artifact.regions ?? [], artifact.requirements ?? []),
117
+ hasApplicability: artifact.applicability !== undefined,
118
+ };
119
+ }
120
+ /**
121
+ * The one canonical application-level "approval" use case, mirroring
122
+ * `application/frontendContractPersistenceService.ts#approveAndPersistBaseline`'s
123
+ * shape: reads the target through the existing reader, refuses to approve
124
+ * anything not currently in the `'imported'` lifecycle state, resolves an
125
+ * optional explicit supersession target through the same reader, and
126
+ * persists a brand-new artifact instance - never mutating the imported
127
+ * artifact's own manifest - carrying a `sourceReference` back to it instead
128
+ * of a second copy of the image bytes.
129
+ */
130
+ export async function approveExternalReference(importedArtifactRoot, options) {
131
+ const read = await readExternalReferenceArtifact(path.join(importedArtifactRoot, EXTERNAL_REFERENCE_MANIFEST_FILENAME));
132
+ if (!read.ok)
133
+ return failure('reference-not-found', read.reason);
134
+ if (!isImportedExternalReferenceArtifact(read.artifact)) {
135
+ return failure('invalid-request', `external-reference artifact "${read.artifact.referenceId}" is not in the "imported" lifecycle state; only a freshly imported reference can be approved`);
136
+ }
137
+ const imported = read.artifact;
138
+ const supersedes = await resolveSupersedesReferenceId(options.supersedesReferenceRoot);
139
+ if (!supersedes.ok)
140
+ return supersedes;
141
+ const normalizedOutput = normalizeOutputLocation(options.outputLocation);
142
+ if (!normalizedOutput.ok)
143
+ return { ok: false, diagnostics: [normalizedOutput.diagnostic] };
144
+ const referenceId = buildExternalReferenceInstanceIdentity(imported.referenceRequestId);
145
+ const artifact = {
146
+ artifactKind: EXTERNAL_REFERENCE_ARTIFACT_KIND,
147
+ schemaVersion: EXTERNAL_REFERENCE_SCHEMA_VERSION,
148
+ referenceRequestId: imported.referenceRequestId,
149
+ referenceId,
150
+ producer: getProducerInfo(),
151
+ provenance: { importedAt: imported.provenance.importedAt, ...(imported.provenance.label === undefined ? {} : { label: imported.provenance.label }) },
152
+ sourceReference: {
153
+ referenceId: imported.referenceId,
154
+ referenceRequestId: imported.referenceRequestId,
155
+ producer: imported.producer,
156
+ schemaVersion: imported.schemaVersion,
157
+ image: imported.image,
158
+ },
159
+ lifecycle: { state: 'approved', approvedAt: new Date().toISOString() },
160
+ ...(supersedes.referenceId === undefined ? {} : { supersedesReferenceId: supersedes.referenceId }),
161
+ ...(imported.regions === undefined ? {} : { regions: imported.regions }),
162
+ ...(imported.requirements === undefined ? {} : { requirements: imported.requirements }),
163
+ ...(imported.applicability === undefined ? {} : { applicability: imported.applicability }),
164
+ diagnostics: [],
165
+ completion: deriveCompletion([], 'post-capture'),
166
+ };
167
+ const persisted = await writeExternalReferenceArtifact(artifact, undefined, normalizedOutput.value, options.cwd === undefined ? {} : { cwd: options.cwd });
168
+ if (!persisted.ok)
169
+ return { ok: false, diagnostics: persisted.diagnostics };
170
+ return {
171
+ ok: true,
172
+ referenceId: artifact.referenceId,
173
+ referenceRequestId: artifact.referenceRequestId,
174
+ artifactRoot: persisted.artifactRoot,
175
+ manifestPath: persisted.manifestPath,
176
+ regionCount: artifact.regions?.length ?? 0,
177
+ requirementCount: artifact.requirements?.length ?? 0,
178
+ adequacy: deriveReferenceRequirementAdequacy(artifact.regions ?? [], artifact.requirements ?? []),
179
+ hasApplicability: artifact.applicability !== undefined,
180
+ };
181
+ }
182
+ //# sourceMappingURL=externalReferencePersistenceService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalReferencePersistenceService.js","sourceRoot":"","sources":["../../src/application/externalReferencePersistenceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,kCAAkC,EAClC,oCAAoC,EACpC,uCAAuC,EACvC,sBAAsB,EACtB,kCAAkC,GACnC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,gCAAgC,EAAE,iCAAiC,EAAE,mCAAmC,EAAE,MAAM,gCAAgC,CAAC;AAC1J,OAAO,EAAE,qCAAqC,EAAE,sCAAsC,EAAE,MAAM,wCAAwC,CAAC;AAEvI,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AAEzL,OAAO,EAAE,qCAAqC,EAAE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OAAO,IAAI,EAAE,EAAE,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC;QACjG,gBAAgB,EAAE,QAAQ,CAAC,aAAa,KAAK,SAAS;KACvD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { EvaluateReferenceCandidateFidelityOptions, ReferenceCandidateFidelityEvaluation } from '../domain/externalReferenceFidelity.js';
2
+ import type { ReferenceRuntimeBindingDeclaration } from '../domain/externalReferenceRuntimeBinding.js';
3
+ import type { Diagnostic } from '../domain/diagnostics.js';
4
+ export type EvaluateReferenceFidelityOptions = EvaluateReferenceCandidateFidelityOptions;
5
+ export type ApplicationReferenceFidelityResult = {
6
+ ok: true;
7
+ evaluation: ReferenceCandidateFidelityEvaluation;
8
+ } | {
9
+ ok: false;
10
+ diagnostics: Diagnostic[];
11
+ };
12
+ /**
13
+ * The canonical CLI-facing orchestration for Prompt 6, mirroring
14
+ * `comparisonService.ts#compareAndPersistFromArtifactRoots`'s exact shape:
15
+ * reads one already-persisted `ExternalReferenceArtifact` and one already-
16
+ * persisted `ObservationArtifact` by their root directories through the
17
+ * existing readers, then delegates to the pure
18
+ * `evaluateReferenceCandidateFidelity` exactly once. A thin wrapper only -
19
+ * artifact reading stays owned by `artifacts/`, evaluation semantics stay
20
+ * owned by `domain/externalReferenceFidelity.ts`. Kept in `application/`
21
+ * (not `artifacts/`) so `src/cli.ts` can depend on it without importing the
22
+ * artifacts layer directly, matching every other command's import-boundary
23
+ * convention. Never launches a browser, never re-resolves targets, and -
24
+ * deliberately, per this prompt's persistence decision - never persists
25
+ * anything: the caller receives the structured in-memory evaluation result
26
+ * directly.
27
+ */
28
+ export declare function evaluateReferenceCandidateFidelityFromArtifactRoots(referenceRoot: string, candidateRoot: string, bindingDeclarations: readonly ReferenceRuntimeBindingDeclaration[], options?: EvaluateReferenceFidelityOptions): Promise<ApplicationReferenceFidelityResult>;
@@ -0,0 +1,45 @@
1
+ import path from 'node:path';
2
+ import { readExternalReferenceArtifact } from '../artifacts/externalReferenceArtifactReader.js';
3
+ import { EXTERNAL_REFERENCE_MANIFEST_FILENAME } from '../artifacts/externalReferenceArtifactWriter.js';
4
+ import { readObservationArtifact } from '../artifacts/artifactReader.js';
5
+ import { MANIFEST_FILENAME as OBSERVATION_MANIFEST_FILENAME } from '../artifacts/artifactWriter.js';
6
+ import { evaluateReferenceCandidateFidelity } from '../domain/externalReferenceFidelity.js';
7
+ import { DIAGNOSTIC_SEVERITY } from '../domain/diagnostics.js';
8
+ /**
9
+ * The canonical CLI-facing orchestration for Prompt 6, mirroring
10
+ * `comparisonService.ts#compareAndPersistFromArtifactRoots`'s exact shape:
11
+ * reads one already-persisted `ExternalReferenceArtifact` and one already-
12
+ * persisted `ObservationArtifact` by their root directories through the
13
+ * existing readers, then delegates to the pure
14
+ * `evaluateReferenceCandidateFidelity` exactly once. A thin wrapper only -
15
+ * artifact reading stays owned by `artifacts/`, evaluation semantics stay
16
+ * owned by `domain/externalReferenceFidelity.ts`. Kept in `application/`
17
+ * (not `artifacts/`) so `src/cli.ts` can depend on it without importing the
18
+ * artifacts layer directly, matching every other command's import-boundary
19
+ * convention. Never launches a browser, never re-resolves targets, and -
20
+ * deliberately, per this prompt's persistence decision - never persists
21
+ * anything: the caller receives the structured in-memory evaluation result
22
+ * directly.
23
+ */
24
+ export async function evaluateReferenceCandidateFidelityFromArtifactRoots(referenceRoot, candidateRoot, bindingDeclarations, options = {}) {
25
+ const referenceRead = await readExternalReferenceArtifact(path.join(referenceRoot, EXTERNAL_REFERENCE_MANIFEST_FILENAME));
26
+ if (!referenceRead.ok) {
27
+ return {
28
+ ok: false,
29
+ diagnostics: [{ code: 'invalid-request', severity: DIAGNOSTIC_SEVERITY['invalid-request'], message: `--reference external-reference artifact: ${referenceRead.reason}` }],
30
+ };
31
+ }
32
+ const candidateRead = await readObservationArtifact(path.join(candidateRoot, OBSERVATION_MANIFEST_FILENAME));
33
+ if (!candidateRead.ok) {
34
+ return {
35
+ ok: false,
36
+ diagnostics: [{ code: 'invalid-request', severity: DIAGNOSTIC_SEVERITY['invalid-request'], message: `--candidate observation artifact: ${candidateRead.reason}` }],
37
+ };
38
+ }
39
+ const result = evaluateReferenceCandidateFidelity(referenceRead.artifact, candidateRead.artifact, bindingDeclarations, options);
40
+ if (!result.ok) {
41
+ return { ok: false, diagnostics: [{ code: 'invalid-request', severity: DIAGNOSTIC_SEVERITY['invalid-request'], message: result.reason }] };
42
+ }
43
+ return { ok: true, evaluation: result.evaluation };
44
+ }
45
+ //# sourceMappingURL=referenceFidelityEvaluationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referenceFidelityEvaluationService.js","sourceRoot":"","sources":["../../src/application/referenceFidelityEvaluationService.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,oCAAoC,EAAE,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,iBAAiB,IAAI,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AAI5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAM/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,mDAAmD,CACvE,aAAqB,EACrB,aAAqB,EACrB,mBAAkE,EAClE,UAA4C,EAAE;IAE9C,MAAM,aAAa,GAAG,MAAM,6BAA6B,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,oCAAoC,CAAC,CAAC,CAAC;IAC1H,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QACtB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,4CAA4C,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;SAC1K,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,6BAA6B,CAAC,CAAC,CAAC;IAC7G,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QACtB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,qCAAqC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;SACnK,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,kCAAkC,CAAC,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC,QAAQ,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAC;IAChI,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;IAC7I,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ExternalReferenceArtifact } from '../domain/externalReference.js';
2
+ export type ReadExternalReferenceArtifactResult = {
3
+ ok: true;
4
+ artifact: ExternalReferenceArtifact;
5
+ } | {
6
+ ok: false;
7
+ reason: string;
8
+ };
9
+ /**
10
+ * Narrow canonical reader counterpart to
11
+ * `externalReferenceArtifactWriter.ts#writeExternalReferenceArtifact`: reads
12
+ * one `manifest.json`, parses it, and validates it through the same
13
+ * `isValidExternalReferenceArtifact` structural gate the writer itself uses -
14
+ * never a second validator. Read-only: never mutates the file, never resolves
15
+ * the sibling image file's bytes (an 'imported' manifest's `image.path` field
16
+ * is returned as-is for the caller to resolve if it needs the bytes).
17
+ */
18
+ export declare function readExternalReferenceArtifact(manifestPath: string): Promise<ReadExternalReferenceArtifactResult>;
@@ -0,0 +1,35 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { isValidExternalReferenceArtifact } from '../domain/externalReference.js';
3
+ /**
4
+ * Narrow canonical reader counterpart to
5
+ * `externalReferenceArtifactWriter.ts#writeExternalReferenceArtifact`: reads
6
+ * one `manifest.json`, parses it, and validates it through the same
7
+ * `isValidExternalReferenceArtifact` structural gate the writer itself uses -
8
+ * never a second validator. Read-only: never mutates the file, never resolves
9
+ * the sibling image file's bytes (an 'imported' manifest's `image.path` field
10
+ * is returned as-is for the caller to resolve if it needs the bytes).
11
+ */
12
+ export async function readExternalReferenceArtifact(manifestPath) {
13
+ let raw;
14
+ try {
15
+ raw = await readFile(manifestPath, 'utf8');
16
+ }
17
+ catch (err) {
18
+ const message = err instanceof Error ? err.message : String(err);
19
+ return { ok: false, reason: `failed to read external-reference artifact manifest at "${manifestPath}": ${message}` };
20
+ }
21
+ let parsed;
22
+ try {
23
+ parsed = JSON.parse(raw);
24
+ }
25
+ catch (err) {
26
+ const message = err instanceof Error ? err.message : String(err);
27
+ return { ok: false, reason: `external-reference artifact manifest at "${manifestPath}" is not valid JSON: ${message}` };
28
+ }
29
+ const validation = isValidExternalReferenceArtifact(parsed);
30
+ if (!validation.valid) {
31
+ return { ok: false, reason: `external-reference artifact manifest at "${manifestPath}" failed structural validation: ${validation.reason}` };
32
+ }
33
+ return { ok: true, artifact: parsed };
34
+ }
35
+ //# sourceMappingURL=externalReferenceArtifactReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externalReferenceArtifactReader.js","sourceRoot":"","sources":["../../src/artifacts/externalReferenceArtifactReader.ts"],"names":[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