archctx-contracts 0.17.0 → 0.18.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.
- package/fixtures/invalid/projection-result-applied-incomplete-coverage.json +3 -3
- package/fixtures/valid/archctx-capabilities.json +2 -2
- package/fixtures/valid/flow-selector-check.json +1 -1
- package/fixtures/valid/product-version-manifest.json +5 -11
- package/fixtures/valid/projection-manifest.json +1 -1
- package/fixtures/valid/projection-result.json +3 -3
- package/package.json +4 -1
- package/schemas/repo/refactor-decision.schema.json +283 -37
- package/schemas/runtime/archctx-capabilities.schema.json +144 -20
- package/schemas/runtime/architecture-debt-delta.schema.json +58 -19
- package/schemas/runtime/architecture-debt.schema.json +42 -42
- package/schemas/runtime/architecture-event.schema.json +1 -1
- package/schemas/runtime/architecture-history.schema.json +354 -0
- package/schemas/runtime/capability-dependencies.schema.json +266 -59
- package/schemas/runtime/cli-check.schema.json +197 -0
- package/schemas/runtime/cli-help.schema.json +28 -0
- package/schemas/runtime/dependency-constraint-evaluation.schema.json +67 -68
- package/schemas/runtime/docs-anchors.schema.json +250 -67
- package/schemas/runtime/doctor-code-facts.schema.json +49 -0
- package/schemas/runtime/evidence-binding.schema.json +1 -1
- package/schemas/runtime/flow-selector-check.schema.json +179 -46
- package/schemas/runtime/hook-debt-checkpoint.schema.json +12 -12
- package/schemas/runtime/index-seed.schema.json +56 -0
- package/schemas/runtime/path-context.schema.json +108 -0
- package/schemas/runtime/product-version-manifest.schema.json +142 -54
- package/schemas/runtime/projection-apply-readback.schema.json +2 -2
- package/schemas/runtime/projection-apply-recovery.schema.json +1 -1
- package/schemas/runtime/projection-result.schema.json +1 -1
- package/schemas/runtime/projection-slice.schema.json +34 -34
- package/schemas/runtime/recommendation-v3.schema.json +372 -1
- package/schemas/runtime/ref-impact-batch-request.schema.json +20 -7
- package/schemas/runtime/ref-impact-batch.schema.json +83 -13
- package/schemas/runtime/ref-impact.schema.json +68 -61
- package/schemas/runtime/refactor-scan-v2.schema.json +434 -0
- package/schemas/runtime/refactor-simulate.schema.json +505 -0
- package/schemas/runtime/refactor-verify-v2.schema.json +172 -0
- package/schemas/runtime/resolve-path.schema.json +69 -0
- package/schemas/runtime/runtime-recommendation-show.schema.json +531 -2
- package/schemas/runtime/runtime-refactor-scan.schema.json +498 -2
- package/schemas/runtime/runtime-verify.schema.json +274 -56
- package/schemas/runtime/state-machine-check.schema.json +357 -89
- package/schemas/runtime/structural-observation-payload.schema.json +372 -1
- package/schemas/runtime/sync-check.schema.json +65 -0
- package/src/architecture-debt.ts +125 -38
- package/src/architecture-history.ts +168 -42
- package/src/architecture.ts +100 -0
- package/src/cli-read.ts +228 -0
- package/src/docs-anchors.ts +105 -50
- package/src/explorer-occurrence-ports.ts +175 -0
- package/src/explorer-query-ports.ts +270 -0
- package/src/failure.ts +3 -0
- package/src/index-seed.ts +42 -0
- package/src/index.ts +5 -0
- package/src/ledger-records.ts +262 -0
- package/src/ledger.ts +27 -566
- package/src/ownership-dependencies.ts +115 -5
- package/src/ports.ts +12 -543
- package/src/product-version.ts +75 -56
- package/src/projection-apply-types.ts +216 -0
- package/src/projection-apply-validators.ts +355 -0
- package/src/projection-capabilities.ts +181 -0
- package/src/projection-constants.ts +317 -0
- package/src/projection-manifest-types.ts +298 -0
- package/src/projection-manifest.ts +12 -299
- package/src/projection-recovery-validators.ts +229 -0
- package/src/projection-request-validators.ts +326 -0
- package/src/projection-types.ts +365 -0
- package/src/projection-validation-helpers.ts +15 -0
- package/src/projection.ts +7 -1689
- package/src/ref-impact.ts +225 -33
- package/src/refactor-constants.ts +213 -0
- package/src/refactor-decision-validators.ts +350 -0
- package/src/refactor-evidence-types.ts +286 -0
- package/src/refactor-observation-validators.ts +359 -0
- package/src/refactor-resolution-validators.ts +229 -0
- package/src/refactor-snapshot-validators.ts +368 -0
- package/src/refactor-types.ts +270 -0
- package/src/refactor-v2.ts +389 -0
- package/src/refactor-validation-helpers.ts +195 -0
- package/src/refactor.ts +7 -1849
- package/src/review-guards.ts +3 -23
- package/src/runtime-verify.ts +87 -0
- package/src/schema-kit.ts +183 -0
- package/src/schema-registry.ts +73 -0
- package/src/schema.ts +0 -4
- package/src/state-machine-schemas.ts +192 -0
- package/src/state-machine-types.ts +188 -0
- package/src/state-machine.ts +9 -189
- package/fixtures/boundary/agent-job-expired.json +0 -33
- package/fixtures/invalid/adapter-fidelity-reverse-sync.json +0 -9
- package/fixtures/invalid/agent-job-direct-mutation.json +0 -32
- package/fixtures/invalid/cloud-egress-envelope-private-field.json +0 -12
- package/fixtures/invalid/investigation-report-direct-mutation.json +0 -38
- package/fixtures/invalid/investigation-report-missing-proposed-delta.json +0 -19
- package/fixtures/invalid/notification-event-code-field.json +0 -11
- package/fixtures/valid/adapter-fidelity.json +0 -9
- package/fixtures/valid/agent-job.json +0 -33
- package/fixtures/valid/architecture-candidate-delta-policy.json +0 -45
- package/fixtures/valid/architecture-candidate-delta.json +0 -188
- package/fixtures/valid/chatgpt-ga-tool.json +0 -9
- package/fixtures/valid/cloud-egress-envelope.json +0 -11
- package/fixtures/valid/entitlement.json +0 -12
- package/fixtures/valid/investigation-report.json +0 -38
- package/fixtures/valid/likec4-mapping.json +0 -14
- package/fixtures/valid/notification-event.json +0 -10
- package/fixtures/valid/notification-provider.json +0 -12
- package/fixtures/valid/structurizr-mapping.json +0 -15
- package/schemas/cloud/cloud-egress-envelope.schema.json +0 -19
- package/schemas/cloud/entitlement.schema.json +0 -24
- package/schemas/integrations/adapter-fidelity.schema.json +0 -21
- package/schemas/integrations/chatgpt-ga-tool.schema.json +0 -25
- package/schemas/integrations/likec4-mapping.schema.json +0 -32
- package/schemas/integrations/structurizr-mapping.schema.json +0 -33
- package/schemas/runtime/agent-job.schema.json +0 -63
- package/schemas/runtime/architecture-candidate-delta-policy.schema.json +0 -129
- package/schemas/runtime/architecture-candidate-delta.schema.json +0 -386
- package/schemas/runtime/investigation-report.schema.json +0 -119
- package/schemas/runtime/notification-event.schema.json +0 -18
- package/schemas/runtime/notification-provider.schema.json +0 -26
package/src/projection.ts
CHANGED
|
@@ -1,1689 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export const PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION = "archcontext.projection-apply-recovery-binding/v2" as const;
|
|
9
|
-
export const PROJECTION_APPLY_RECOVERY_INTENT_SCHEMA_VERSION = "archcontext.projection-apply-recovery-intent/v1" as const;
|
|
10
|
-
export const PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION = "archcontext.projection-apply-recovery-proof/v2" as const;
|
|
11
|
-
export const PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION = "archcontext.projection-apply-recovery-result/v2" as const;
|
|
12
|
-
export const PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION = "archcontext.projection-apply-readback-result/v2" as const;
|
|
13
|
-
export const ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION = "archcontext.architecture-refresh-signal/v2" as const;
|
|
14
|
-
export const ARCHCTX_CAPABILITIES_SCHEMA_VERSION = "archcontext.capabilities/v1" as const;
|
|
15
|
-
export const ARCHITECTURE_DOCS_RENDERER_VERSION = "archcontext.docs-renderer/v6" as const;
|
|
16
|
-
/**
|
|
17
|
-
* The committed projection manifest's path. `projection-manifest.ts` owns its shape and byte layout;
|
|
18
|
-
* the path lives here because a projection result's `files[]` names the manifest write.
|
|
19
|
-
*/
|
|
20
|
-
export const ARCHITECTURE_DOCS_PROJECTION_MANIFEST_PATH = "docs/architecture/.projection-manifest.json" as const;
|
|
21
|
-
export const AGENT_CONTEXT_RENDERER_VERSION = "archcontext.agent-context-renderer/v2" as const;
|
|
22
|
-
|
|
23
|
-
export const PROJECTION_MODES = ["check", "plan", "apply", "adopt"] as const;
|
|
24
|
-
export const PROJECTION_PRIOR_COMMITTED_APPLY_OPERATIONS = ["delete", "write"] as const;
|
|
25
|
-
export const PROJECTION_TARGETS = ["agent-context", "architecture-docs", "architecture-history"] as const;
|
|
26
|
-
export const PROJECTION_RESULT_STATUSES = [
|
|
27
|
-
"adoption-required",
|
|
28
|
-
"applied",
|
|
29
|
-
"applied-partial",
|
|
30
|
-
"applied-reconcile-required",
|
|
31
|
-
"blocked",
|
|
32
|
-
"human-action-required",
|
|
33
|
-
"noop",
|
|
34
|
-
"permanent-failure",
|
|
35
|
-
"planned",
|
|
36
|
-
"planned-partial",
|
|
37
|
-
"retryable-failure"
|
|
38
|
-
] as const;
|
|
39
|
-
/**
|
|
40
|
-
* The two statuses of a projection that covers only part of its targets (#327, Phase 1 capability
|
|
41
|
-
* isolation): `planned-partial` from `check` and `plan`, `applied-partial` from `apply`. Exactly
|
|
42
|
-
* these results carry `coverage`, always with `complete: false`; a complete result omits it.
|
|
43
|
-
*/
|
|
44
|
-
export const PROJECTION_PARTIAL_RESULT_STATUSES = ["applied-partial", "planned-partial"] as const;
|
|
45
|
-
/**
|
|
46
|
-
* Why a target is carried forward instead of applied: a capability it depends on has an
|
|
47
|
-
* unprovable P1 or P2 proof (`unprovable-required-flow`), or its flow proof moved since the
|
|
48
|
-
* committed baseline while its semantic fingerprint held (`verified-flow-proof-changed`).
|
|
49
|
-
*/
|
|
50
|
-
export const PROJECTION_COVERAGE_REASON_CODES = ["unprovable-required-flow", "verified-flow-proof-changed"] as const;
|
|
51
|
-
export const PROJECTION_HUMAN_ACTION_REASON_CODES = [
|
|
52
|
-
"adoption-required",
|
|
53
|
-
"manual-region-conflict",
|
|
54
|
-
"orphaned-document-review",
|
|
55
|
-
"target-collision",
|
|
56
|
-
"unprovable-required-flow",
|
|
57
|
-
"unresolved-major-change"
|
|
58
|
-
] as const;
|
|
59
|
-
export const ARCHITECTURE_MAJOR_CHANGE_REASON_CODES = [
|
|
60
|
-
"constraint-changed",
|
|
61
|
-
"entrypoint-changed",
|
|
62
|
-
"interface-changed",
|
|
63
|
-
"lifecycle-changed",
|
|
64
|
-
"node-added",
|
|
65
|
-
"node-moved",
|
|
66
|
-
"node-removed",
|
|
67
|
-
"node-renamed",
|
|
68
|
-
"ownership-changed",
|
|
69
|
-
"relation-changed",
|
|
70
|
-
"responsibility-changed",
|
|
71
|
-
"risk-boundary-changed",
|
|
72
|
-
"verified-flow-proof-changed"
|
|
73
|
-
] as const;
|
|
74
|
-
export const ARCHITECTURE_REFRESH_TARGETS = [
|
|
75
|
-
"architecture-contract-context",
|
|
76
|
-
"architecture-readiness",
|
|
77
|
-
"architecture-request-index",
|
|
78
|
-
"capability-context",
|
|
79
|
-
"capability-index"
|
|
80
|
-
] as const;
|
|
81
|
-
export const ARCHCTX_FEATURES = [
|
|
82
|
-
"architecture-change-capabilities-v1",
|
|
83
|
-
"architecture-debt-v1",
|
|
84
|
-
"architecture-docs-renderer-v2",
|
|
85
|
-
"architecture-refresh-signal-v1",
|
|
86
|
-
"capability-dependencies-declared-v1",
|
|
87
|
-
"capability-dependencies-v1",
|
|
88
|
-
"changeset-entity-operations-v1",
|
|
89
|
-
"changeset-ownership-delta-v1",
|
|
90
|
-
"code-facts-unavailable-error-v1",
|
|
91
|
-
"docs-anchors-v1",
|
|
92
|
-
"flow-selector-check-v1",
|
|
93
|
-
"module-statistics-v1",
|
|
94
|
-
"native-context-export-v1",
|
|
95
|
-
"projection-apply-readback-v1",
|
|
96
|
-
"projection-apply-receipt-v1",
|
|
97
|
-
"projection-apply-recovery-v1",
|
|
98
|
-
"projection-apply-replay-restore-v1",
|
|
99
|
-
"projection-apply-replay-v1",
|
|
100
|
-
"projection-architecture-debt-v1",
|
|
101
|
-
"projection-capability-isolation-v1",
|
|
102
|
-
"projection-change-classification-v2",
|
|
103
|
-
"projection-check-freshness-v2",
|
|
104
|
-
"projection-freshness-v2",
|
|
105
|
-
"projection-manifest-contract-v4",
|
|
106
|
-
"projection-observed-major-change-acceptance-v1",
|
|
107
|
-
"projection-orphan-review-v1",
|
|
108
|
-
"projection-preview-v1",
|
|
109
|
-
"projection-prior-committed-applies-v1",
|
|
110
|
-
"projection-protocol-v2",
|
|
111
|
-
"projection-publish-v1",
|
|
112
|
-
"projection-slice-v1",
|
|
113
|
-
"projection-snapshot-v1",
|
|
114
|
-
"projection-verify-pr-v1",
|
|
115
|
-
"recommendation-scan-decision-v1",
|
|
116
|
-
"recommendation-v3",
|
|
117
|
-
"refactor-assessment-v1",
|
|
118
|
-
"refactor-observation-evidence-v1",
|
|
119
|
-
"refactor-resolution-v1",
|
|
120
|
-
"refactor-scan-limits-v1",
|
|
121
|
-
"refactor-scan-untracked-count-v1"
|
|
122
|
-
] as const;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* The closed set of semantic facets a capability's semantic state digests. Each facet maps to the
|
|
126
|
-
* major-change reason code it raises when its digest moves.
|
|
127
|
-
*/
|
|
128
|
-
export const ARCHITECTURE_SEMANTIC_FACETS = [
|
|
129
|
-
"constraints",
|
|
130
|
-
"entrypoints",
|
|
131
|
-
"interfaces",
|
|
132
|
-
"lifecycle",
|
|
133
|
-
"names",
|
|
134
|
-
"ownership",
|
|
135
|
-
"placement",
|
|
136
|
-
"relations",
|
|
137
|
-
"responsibilities",
|
|
138
|
-
"riskBoundaries"
|
|
139
|
-
] as const;
|
|
140
|
-
export const ARCHITECTURE_PROOF_P1_STATUSES = ["proven", "unprovable"] as const;
|
|
141
|
-
export const ARCHITECTURE_PROOF_P2_STATUSES = ["not-applicable", "proven", "unprovable"] as const;
|
|
142
|
-
|
|
143
|
-
export const ARCHITECTURE_FLOW_SELECTOR_CHECK_SCHEMA_VERSION = "archcontext.flow-selector-check/v1" as const;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The proof status of one declared entrypoint→sink selector, as the P2 flow proof reads its
|
|
147
|
-
* evidence. Only `proven` can bind a flow step. `no-direct-call`: no `calls` edge from the source
|
|
148
|
-
* to the sink. `only-references`: no proving call, but the source references the sink by value.
|
|
149
|
-
* `false-builtin-call`: the only calls carry a runtime built-in name and the source file does not
|
|
150
|
-
* import the sink file. `ambiguous-symbol`: the source or the sink matches more than one indexed
|
|
151
|
-
* symbol. `evidence-missing`: no evidence was measured (for example, no CodeGraph index).
|
|
152
|
-
* `evidence-truncated`: the evidence producer could not enumerate every edge.
|
|
153
|
-
*/
|
|
154
|
-
export const ARCHITECTURE_FLOW_SELECTOR_PROOF_STATUSES = [
|
|
155
|
-
"ambiguous-symbol",
|
|
156
|
-
"evidence-missing",
|
|
157
|
-
"evidence-truncated",
|
|
158
|
-
"false-builtin-call",
|
|
159
|
-
"no-direct-call",
|
|
160
|
-
"only-references",
|
|
161
|
-
"proven"
|
|
162
|
-
] as const;
|
|
163
|
-
export type ArchitectureFlowSelectorProofStatus = typeof ARCHITECTURE_FLOW_SELECTOR_PROOF_STATUSES[number];
|
|
164
|
-
|
|
165
|
-
export interface ArchitectureFlowSelectorSiteV1 {
|
|
166
|
-
path: string;
|
|
167
|
-
line?: number;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface ArchitectureFlowSelectorCheckEntryV1 {
|
|
171
|
-
nodeId: string;
|
|
172
|
-
entrypointId: string;
|
|
173
|
-
sourcePath: string;
|
|
174
|
-
sourceSymbol: string;
|
|
175
|
-
sinkId: string;
|
|
176
|
-
sinkPath: string;
|
|
177
|
-
sinkSymbol: string;
|
|
178
|
-
status: ArchitectureFlowSelectorProofStatus;
|
|
179
|
-
callSites: ArchitectureFlowSelectorSiteV1[];
|
|
180
|
-
referenceSites: ArchitectureFlowSelectorSiteV1[];
|
|
181
|
-
rejectedBuiltinCallSites: ArchitectureFlowSelectorSiteV1[];
|
|
182
|
-
/** The required-flow steps that name this selector as evidence. Empty for an unused selector. */
|
|
183
|
-
flowSteps: Array<{ flowId: string; stepId: string }>;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export interface ArchitectureFlowSelectorCheckCapabilityV1 {
|
|
187
|
-
capabilityId: string;
|
|
188
|
-
/** The same P2 status a projection records for this capability. */
|
|
189
|
-
p2Status: typeof ARCHITECTURE_PROOF_P2_STATUSES[number];
|
|
190
|
-
diagnostics: Array<{ code: string; flowId?: string; stepId?: string; detail: string }>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* `archctx flows check`: the P2 flow proof without rendering. Read-only. `ok` is true when no
|
|
195
|
-
* capability that declares a flow has an unprovable P2 proof.
|
|
196
|
-
*/
|
|
197
|
-
export interface ArchitectureFlowSelectorCheckV1 {
|
|
198
|
-
schemaVersion: typeof ARCHITECTURE_FLOW_SELECTOR_CHECK_SCHEMA_VERSION;
|
|
199
|
-
ok: boolean;
|
|
200
|
-
codeGraph: { availability: "ready" | "unavailable"; version: string };
|
|
201
|
-
summary: { selectors: number; proven: number; unproven: number; usedUnproven: number };
|
|
202
|
-
selectors: ArchitectureFlowSelectorCheckEntryV1[];
|
|
203
|
-
capabilities: ArchitectureFlowSelectorCheckCapabilityV1[];
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** `files[].preview.format`: a `create` carries the rendered body, an `update` or `delete` a unified diff. */
|
|
207
|
-
export const PROJECTION_SLICE_SCHEMA_VERSION = "archcontext.projection-slice/v1" as const;
|
|
208
|
-
export const PROJECTION_FILE_PREVIEW_FORMATS = ["body", "unified-diff"] as const;
|
|
209
|
-
/** Upper bound, in UTF-8 bytes, on one `files[].preview.content`. */
|
|
210
|
-
export const PROJECTION_FILE_PREVIEW_MAX_BYTES = 65_536;
|
|
211
|
-
/** Upper bound, in UTF-8 bytes, on the sum of every `files[].preview.content` of one result. */
|
|
212
|
-
export const PROJECTION_PREVIEW_TOTAL_MAX_BYTES = 1_048_576;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Why a projection is not fresh (ADR-0056 §1). Shared by the engine's freshness evaluator and the
|
|
216
|
-
* `check` result's `freshness` field so the two can never disagree. `projection-output-changed`:
|
|
217
|
-
* a target renders an output other than its committed row's (`staleTargets`).
|
|
218
|
-
* `projection-manifest-changed`: every output equals its row, but the manifest the render would
|
|
219
|
-
* write differs from the committed bytes (the semantic baseline or a header line).
|
|
220
|
-
*/
|
|
221
|
-
export const PROJECTION_FRESHNESS_REASON_CODES = [
|
|
222
|
-
"projection-manifest-changed",
|
|
223
|
-
"projection-manifest-missing",
|
|
224
|
-
"projection-manifest-unreadable",
|
|
225
|
-
"projection-output-changed"
|
|
226
|
-
] as const;
|
|
227
|
-
|
|
228
|
-
/** The architecture debt a `check` or `plan` result reports. Debt is a finding, never a blocker. */
|
|
229
|
-
export const PROJECTION_ARCHITECTURE_DEBT_REASON_CODES = ["undeclared-dependency"] as const;
|
|
230
|
-
/**
|
|
231
|
-
* Why the debt read is not a complete observation. The `code-facts-*` codes mean what they mean on
|
|
232
|
-
* `archctx deps`; `workspace-resolution-failed` means the workspace package map was unreadable, so
|
|
233
|
-
* no bare workspace import specifier could be resolved.
|
|
234
|
-
*/
|
|
235
|
-
export const PROJECTION_ARCHITECTURE_DEBT_COVERAGE_REASON_CODES = [
|
|
236
|
-
"code-facts-import-limit",
|
|
237
|
-
"code-facts-truncated",
|
|
238
|
-
"code-facts-unavailable",
|
|
239
|
-
"workspace-resolution-failed"
|
|
240
|
-
] as const;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* How one target of a `check` or `plan` result changes (#327 finding 2), from the strongest reason
|
|
244
|
-
* down: `blocked` (a human must act before the target can be written: Phase 1 isolation, an orphan
|
|
245
|
-
* that needs review, an adoption or ownership rejection), `proof-change` (a known proof change,
|
|
246
|
-
* which a missing baseline never hides), `baseline-missing` (a comparison is unknown: no committed
|
|
247
|
-
* current-format manifest, or no committed row for the target), `semantic-change`, `output-change`
|
|
248
|
-
* and `unchanged`.
|
|
249
|
-
* `projectionTargetChangeClassification` is the one precedence rule.
|
|
250
|
-
*/
|
|
251
|
-
export const PROJECTION_TARGET_CHANGE_CLASSIFICATIONS = [
|
|
252
|
-
"baseline-missing",
|
|
253
|
-
"blocked",
|
|
254
|
-
"output-change",
|
|
255
|
-
"proof-change",
|
|
256
|
-
"semantic-change",
|
|
257
|
-
"unchanged"
|
|
258
|
-
] as const;
|
|
259
|
-
/** What the projection write does to the target's file: the result's own `files[]` decision for that path. */
|
|
260
|
-
export const PROJECTION_TARGET_CHANGE_PLANNED_ACTIONS = ["create", "delete", "none", "update"] as const;
|
|
261
|
-
/** The reason codes that block a target: no apply writes it until a human acts. */
|
|
262
|
-
export const PROJECTION_TARGET_CHANGE_BLOCKING_REASON_CODES = [
|
|
263
|
-
"adoption-required",
|
|
264
|
-
"ambiguous-ownership",
|
|
265
|
-
"orphan-review-required",
|
|
266
|
-
"unprovable-required-flow",
|
|
267
|
-
"verified-flow-proof-changed"
|
|
268
|
-
] as const;
|
|
269
|
-
/**
|
|
270
|
-
* Why a target is classified as it is. Each comparison flag has its codes: `semanticChanged` is `semantic-fingerprint-changed` or, for a target that
|
|
271
|
-
* describes the whole model, `model-digest-changed` (the committed `semanticBaseline.modelDigest`
|
|
272
|
-
* differs from the current model's); `proofChanged` is
|
|
273
|
-
* `flow-proof-changed` or `selector-evidence-changed`; `outputChanged` is `rendered-output-changed`
|
|
274
|
-
* (the rendered output differs from the committed row's `outputDigest`), `target-added`,
|
|
275
|
-
* `target-removed` or `file-bytes-changed` (the write changes the file although its rendered output
|
|
276
|
-
* is the committed one: a marker, a missing file, an edited region); an unknown comparison is
|
|
277
|
-
* `baseline-missing` or `target-row-missing`.
|
|
278
|
-
*/
|
|
279
|
-
export const PROJECTION_TARGET_CHANGE_REASON_CODES = [
|
|
280
|
-
"adoption-required",
|
|
281
|
-
"ambiguous-ownership",
|
|
282
|
-
"baseline-missing",
|
|
283
|
-
"file-bytes-changed",
|
|
284
|
-
"flow-proof-changed",
|
|
285
|
-
"model-digest-changed",
|
|
286
|
-
"orphan-review-required",
|
|
287
|
-
"rendered-output-changed",
|
|
288
|
-
"selector-evidence-changed",
|
|
289
|
-
"semantic-fingerprint-changed",
|
|
290
|
-
"target-added",
|
|
291
|
-
"target-removed",
|
|
292
|
-
"target-row-missing",
|
|
293
|
-
"unprovable-required-flow",
|
|
294
|
-
"verified-flow-proof-changed"
|
|
295
|
-
] as const;
|
|
296
|
-
|
|
297
|
-
export type ProjectionMode = (typeof PROJECTION_MODES)[number];
|
|
298
|
-
export type ProjectionTargetChangeClassification = (typeof PROJECTION_TARGET_CHANGE_CLASSIFICATIONS)[number];
|
|
299
|
-
export type ProjectionTargetChangePlannedAction = (typeof PROJECTION_TARGET_CHANGE_PLANNED_ACTIONS)[number];
|
|
300
|
-
export type ProjectionTargetChangeReasonCode = (typeof PROJECTION_TARGET_CHANGE_REASON_CODES)[number];
|
|
301
|
-
export type ProjectionFreshnessReasonCode = (typeof PROJECTION_FRESHNESS_REASON_CODES)[number];
|
|
302
|
-
export type ProjectionTarget = (typeof PROJECTION_TARGETS)[number];
|
|
303
|
-
export type ProjectionResultStatus = (typeof PROJECTION_RESULT_STATUSES)[number];
|
|
304
|
-
export type ProjectionPartialResultStatus = (typeof PROJECTION_PARTIAL_RESULT_STATUSES)[number];
|
|
305
|
-
export type ProjectionCoverageReasonCode = (typeof PROJECTION_COVERAGE_REASON_CODES)[number];
|
|
306
|
-
export type ProjectionHumanActionReasonCode = (typeof PROJECTION_HUMAN_ACTION_REASON_CODES)[number];
|
|
307
|
-
export type ProjectionPriorCommittedApplyOperation = (typeof PROJECTION_PRIOR_COMMITTED_APPLY_OPERATIONS)[number];
|
|
308
|
-
export type ArchitectureMajorChangeReasonCode = (typeof ARCHITECTURE_MAJOR_CHANGE_REASON_CODES)[number];
|
|
309
|
-
export type ArchitectureRefreshTarget = (typeof ARCHITECTURE_REFRESH_TARGETS)[number];
|
|
310
|
-
export type ArchctxFeature = (typeof ARCHCTX_FEATURES)[number];
|
|
311
|
-
export type ProjectionArchitectureDebtReasonCode = (typeof PROJECTION_ARCHITECTURE_DEBT_REASON_CODES)[number];
|
|
312
|
-
export type ProjectionArchitectureDebtCoverageReasonCode = (typeof PROJECTION_ARCHITECTURE_DEBT_COVERAGE_REASON_CODES)[number];
|
|
313
|
-
export type ArchitectureSemanticFacet = (typeof ARCHITECTURE_SEMANTIC_FACETS)[number];
|
|
314
|
-
export type ProjectionFilePreviewFormat = (typeof PROJECTION_FILE_PREVIEW_FORMATS)[number];
|
|
315
|
-
export type Sha256Digest = `sha256:${string}`;
|
|
316
|
-
|
|
317
|
-
/** One capability's P1/P2 proof status, as its semantic state records it. */
|
|
318
|
-
export interface ArchitectureCapabilityProofStatusV1 {
|
|
319
|
-
p1: (typeof ARCHITECTURE_PROOF_P1_STATUSES)[number];
|
|
320
|
-
p2: (typeof ARCHITECTURE_PROOF_P2_STATUSES)[number];
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Why one capability is part of a major change: the reason codes and semantic facets that moved for
|
|
325
|
-
* it between the committed semantic baseline and this run. `proofStatusBefore` is null when the
|
|
326
|
-
* baseline has no such capability (or no baseline exists); `proofStatusAfter` is null when the
|
|
327
|
-
* capability was removed. A capability present on one side only lists no changed facets. A
|
|
328
|
-
* capability listed only because its current proof is unprovable, while another capability carries
|
|
329
|
-
* the observed change, lists no reason codes.
|
|
330
|
-
*/
|
|
331
|
-
export interface ArchitectureCapabilityChangeV1 {
|
|
332
|
-
capabilityId: string;
|
|
333
|
-
reasonCodes: ArchitectureMajorChangeReasonCode[];
|
|
334
|
-
changedFacets: ArchitectureSemanticFacet[];
|
|
335
|
-
proofStatusBefore: ArchitectureCapabilityProofStatusV1 | null;
|
|
336
|
-
proofStatusAfter: ArchitectureCapabilityProofStatusV1 | null;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* What a `plan` would write to one file, returned in the response only and never persisted: the
|
|
341
|
-
* rendered body of a `create`, or a unified diff (current bytes to rendered bytes) of an `update` or
|
|
342
|
-
* `delete`. `content` is cut at a line boundary to at most PROJECTION_FILE_PREVIEW_MAX_BYTES UTF-8
|
|
343
|
-
* bytes, and to whatever remains of PROJECTION_PREVIEW_TOTAL_MAX_BYTES across the result, in path
|
|
344
|
-
* order; `byteLength` is the UTF-8 length of the complete content and `truncated` says whether
|
|
345
|
-
* `content` is shorter.
|
|
346
|
-
*/
|
|
347
|
-
export interface ProjectionSliceEntrypointV1 {
|
|
348
|
-
nodeId: string;
|
|
349
|
-
entrypointId: string;
|
|
350
|
-
path: string;
|
|
351
|
-
symbol: string;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
export interface ProjectionSliceCapabilityV1 {
|
|
355
|
-
capabilityId: string;
|
|
356
|
-
modulePath: string;
|
|
357
|
-
/** Unfenced Mermaid. Null when the capability was removed or P1 cannot be rendered. */
|
|
358
|
-
diagramMermaid: string | null;
|
|
359
|
-
entrypoints: ProjectionSliceEntrypointV1[];
|
|
360
|
-
markdown: string;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export interface ProjectionSliceV1 {
|
|
364
|
-
schemaVersion: typeof PROJECTION_SLICE_SCHEMA_VERSION;
|
|
365
|
-
base: string;
|
|
366
|
-
baseSha: string;
|
|
367
|
-
mergeBase: string;
|
|
368
|
-
headSha: string;
|
|
369
|
-
changedPaths: string[];
|
|
370
|
-
changed: boolean;
|
|
371
|
-
affectedCapabilities: ProjectionSliceCapabilityV1[];
|
|
372
|
-
markdown: string;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
export interface ProjectionFilePreviewV1 {
|
|
376
|
-
format: ProjectionFilePreviewFormat;
|
|
377
|
-
content: string;
|
|
378
|
-
byteLength: number;
|
|
379
|
-
truncated: boolean;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export interface ProjectionExpectedSnapshotV1 {
|
|
383
|
-
repositoryId: string;
|
|
384
|
-
workspaceId: string;
|
|
385
|
-
headSha: string;
|
|
386
|
-
worktreeDigest: Sha256Digest;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
export interface ProjectionRequestV1 {
|
|
390
|
-
schemaVersion: typeof PROJECTION_REQUEST_SCHEMA_VERSION;
|
|
391
|
-
requestId: string;
|
|
392
|
-
profile: "repo-harness/v1";
|
|
393
|
-
mode: ProjectionMode;
|
|
394
|
-
targets: ProjectionTarget[];
|
|
395
|
-
changedPaths: string[];
|
|
396
|
-
expected: ProjectionExpectedSnapshotV1;
|
|
397
|
-
adoptionPlanId?: string;
|
|
398
|
-
acceptedChange?: AcceptedArchitectureChangeReferenceV1;
|
|
399
|
-
/**
|
|
400
|
-
* `apply` and `adopt` only, never together with `acceptedChange`: accept the major change this
|
|
401
|
-
* run observes at `expected`. The provider classifies, derives the accepted change and applies
|
|
402
|
-
* it against the same expected snapshot, which the daemon re-checks under its writer lock before
|
|
403
|
-
* writing. The apply receipt records the observed change with provider-generated `changeSetId`
|
|
404
|
-
* and `eventId`. Absent, a major change still stops at `human-action-required` (#261).
|
|
405
|
-
*/
|
|
406
|
-
acceptObservedMajorChange?: true;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export interface ProjectionSnapshotV1 extends ProjectionExpectedSnapshotV1 {
|
|
410
|
-
baseHeadSha: string;
|
|
411
|
-
sourceTreeDigest: Sha256Digest;
|
|
412
|
-
modelDigest: Sha256Digest;
|
|
413
|
-
codeGraphDigest: Sha256Digest;
|
|
414
|
-
indexedWorktreeDigest: Sha256Digest | null;
|
|
415
|
-
projectionInputDigest: Sha256Digest;
|
|
416
|
-
rendererVersion: typeof ARCHITECTURE_DOCS_RENDERER_VERSION;
|
|
417
|
-
layoutVersion: "archcontext.docs-layout/v1";
|
|
418
|
-
generatedFrom: {
|
|
419
|
-
codeGraphPackage: "@colbymchenry/codegraph";
|
|
420
|
-
codeGraphVersion: "1.6.2";
|
|
421
|
-
codeGraphStatus: "ready" | "unavailable";
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export interface ProjectionFileResultV1 {
|
|
426
|
-
path: string;
|
|
427
|
-
action: "create" | "delete" | "unchanged" | "update";
|
|
428
|
-
preimageDigest: Sha256Digest | null;
|
|
429
|
-
outputDigest: Sha256Digest | null;
|
|
430
|
-
/**
|
|
431
|
-
* `plan` results only (#264): what this entry would write. Absent on every other mode, on a
|
|
432
|
-
* committed receipt, and on an entry whose path the projection rejected for adoption or ownership
|
|
433
|
-
* repair, because no apply writes that rendered body. Consumers gate on `projection-preview-v1`.
|
|
434
|
-
*/
|
|
435
|
-
preview?: ProjectionFilePreviewV1;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
export interface ProjectionHumanActionV1 {
|
|
439
|
-
reasonCode: ProjectionHumanActionReasonCode;
|
|
440
|
-
affectedNodeIds: string[];
|
|
441
|
-
/**
|
|
442
|
-
* Present exactly on `orphaned-document-review`: the managed document whose target the model no
|
|
443
|
-
* longer renders and which may hold human text. `apply` never deletes it; a human must review,
|
|
444
|
-
* move or remove it. A generated-only orphan is a `files[]` delete instead.
|
|
445
|
-
*/
|
|
446
|
-
path?: string;
|
|
447
|
-
requestPayloadDigest: Sha256Digest;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export interface ProjectionApplyIdentityV1 {
|
|
451
|
-
schemaVersion: typeof PROJECTION_APPLY_IDENTITY_SCHEMA_VERSION;
|
|
452
|
-
applyId: Sha256Digest;
|
|
453
|
-
lookupKey: Sha256Digest;
|
|
454
|
-
repositoryId: string;
|
|
455
|
-
workspaceId: string;
|
|
456
|
-
acceptedChange: AcceptedArchitectureChangeReferenceV1;
|
|
457
|
-
semanticCommit: {
|
|
458
|
-
changeSetId: string;
|
|
459
|
-
idempotencyKey: string;
|
|
460
|
-
};
|
|
461
|
-
ownedFilesDigest: Sha256Digest;
|
|
462
|
-
refreshSignalsDigest: Sha256Digest;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* The global digests of a projection. The base digests come from the committed manifest, which
|
|
467
|
-
* records no source state, so the set carries no source tree digest (ADR-0056 §4).
|
|
468
|
-
*/
|
|
469
|
-
export interface ArchitectureDigestSetV2 {
|
|
470
|
-
modelDigest: Sha256Digest;
|
|
471
|
-
flowProofDigest: Sha256Digest;
|
|
472
|
-
projectionDigest: Sha256Digest;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
export interface AcceptedArchitectureChangeReferenceV1 {
|
|
476
|
-
changeSetId: string;
|
|
477
|
-
eventId: string;
|
|
478
|
-
reasonCodes: ArchitectureMajorChangeReasonCode[];
|
|
479
|
-
affectedNodeIds: string[];
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
export interface ArchitectureRefreshSignalV2 {
|
|
483
|
-
schemaVersion: typeof ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION;
|
|
484
|
-
signalId: Sha256Digest;
|
|
485
|
-
idempotencyKey: Sha256Digest;
|
|
486
|
-
mode: "human-action-required" | "refresh-required";
|
|
487
|
-
repository: { repositoryId: string };
|
|
488
|
-
worktree: { workspaceId: string; headSha: string; worktreeDigest: Sha256Digest };
|
|
489
|
-
cause: "accepted-semantic-delta" | "unresolved-major-candidate" | "verified-flow-proof-delta";
|
|
490
|
-
acceptedChange?: AcceptedArchitectureChangeReferenceV1;
|
|
491
|
-
reasonCodes: ArchitectureMajorChangeReasonCode[];
|
|
492
|
-
affectedNodeIds: string[];
|
|
493
|
-
/**
|
|
494
|
-
* The observed per-capability breakdown of the semantic delta this signal classifies, sorted by
|
|
495
|
-
* capabilityId (#264). Every signal this provider produces carries it; it is part of the signal
|
|
496
|
-
* identity; signals committed before it existed lack it. Consumers gate on
|
|
497
|
-
* `architecture-change-capabilities-v1`, not on field presence.
|
|
498
|
-
*/
|
|
499
|
-
capabilities?: ArchitectureCapabilityChangeV1[];
|
|
500
|
-
refreshTargets: ArchitectureRefreshTarget[];
|
|
501
|
-
baseDigests: ArchitectureDigestSetV2;
|
|
502
|
-
resultingDigests: ArchitectureDigestSetV2;
|
|
503
|
-
projectionReceiptDigest: Sha256Digest;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
export interface ProjectionPriorCommittedApplyFileV1 {
|
|
507
|
-
path: string;
|
|
508
|
-
operation: ProjectionPriorCommittedApplyOperation;
|
|
509
|
-
/** `digestJson({ body })` of the body this ChangeSet wrote, or `"missing"` for a delete. */
|
|
510
|
-
hash: string;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* A ChangeSet already committed under this request's requestId by an earlier attempt of the same
|
|
515
|
-
* request. The CLI is a short-lived RPC client while the daemon owns the write, so a caller whose
|
|
516
|
-
* process was killed after the commit sees only `status: noop` on retry; this array is the only
|
|
517
|
-
* surface that names what that lost attempt actually wrote.
|
|
518
|
-
*/
|
|
519
|
-
export interface ProjectionPriorCommittedApplyV1 {
|
|
520
|
-
/**
|
|
521
|
-
* Present together with `lookupKey` only when the committed ChangeSet also carried a projection
|
|
522
|
-
* apply receipt, which happens only for an accepted-semantic-change apply. A plain drift-repair
|
|
523
|
-
* apply commits without one, and both fields are then absent rather than invented.
|
|
524
|
-
*/
|
|
525
|
-
applyId?: Sha256Digest;
|
|
526
|
-
lookupKey?: Sha256Digest;
|
|
527
|
-
requestId: string;
|
|
528
|
-
changeSetId: string;
|
|
529
|
-
committedAt: string;
|
|
530
|
-
files: ProjectionPriorCommittedApplyFileV1[];
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/** One target whose rendered output differs from its committed manifest row. */
|
|
534
|
-
export interface ProjectionFreshnessStaleTargetV2 {
|
|
535
|
-
targetId: string;
|
|
536
|
-
path: string;
|
|
537
|
-
/** The committed row's `outputDigest`; `null` for a target the committed manifest does not record. */
|
|
538
|
-
committedOutputDigest: Sha256Digest | null;
|
|
539
|
-
/** The current render's `outputDigest`; `null` for a committed row the current layout no longer renders. */
|
|
540
|
-
renderedOutputDigest: Sha256Digest | null;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Render-equivalent freshness of the committed projection (ADR-0056 §1): a target is fresh when the
|
|
545
|
-
* output the current render produces equals its committed row's `outputDigest`, and the projection
|
|
546
|
-
* is fresh when every target is, the two target sets are equal, and the manifest the render would
|
|
547
|
-
* write equals the committed bytes.
|
|
548
|
-
*/
|
|
549
|
-
export interface ProjectionFreshnessV2 {
|
|
550
|
-
ok: boolean;
|
|
551
|
-
reasonCodes: ProjectionFreshnessReasonCode[];
|
|
552
|
-
/** Sorted and unique by targetId. Non-empty exactly when `projection-output-changed` is reported. */
|
|
553
|
-
staleTargets: ProjectionFreshnessStaleTargetV2[];
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* One capability pair whose imports no model relation declares, under the rule of
|
|
558
|
-
* CAPABILITY_DEPENDENCY_DECLARING_RELATION_KINDS. It is the same pair, with the same edge count,
|
|
559
|
-
* that `archctx deps` reports as a cross-capability cell with `declared: false`, measured over
|
|
560
|
-
* the files this run measured instead of the `HEAD` tree.
|
|
561
|
-
*/
|
|
562
|
-
export interface ProjectionUndeclaredDependencyV1 {
|
|
563
|
-
reasonCode: "undeclared-dependency";
|
|
564
|
-
fromCapabilityId: string;
|
|
565
|
-
toCapabilityId: string;
|
|
566
|
-
/** Distinct file-to-file import edges from `fromCapabilityId` into `toCapabilityId`; at least 1. */
|
|
567
|
-
importEdgeCount: number;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Architecture debt that this `check` or `plan` run found. It reuses the import facts the run
|
|
572
|
-
* already read, never blocks a mode and changes no rendered output. It covers every capability
|
|
573
|
-
* pair in the repository, not only pairs that touch the request's `changedPaths`.
|
|
574
|
-
*/
|
|
575
|
-
export interface ProjectionArchitectureDebtV1 {
|
|
576
|
-
/**
|
|
577
|
-
* `unknown` when the run had no code facts (`code-facts-unavailable`): `items` is then empty and
|
|
578
|
-
* says nothing about the repository. `partial` when the import read is a prefix of the index or
|
|
579
|
-
* a workspace specifier could not be resolved: `items` then holds what was observed.
|
|
580
|
-
*/
|
|
581
|
-
coverage: EvidenceCoverageLevelV2;
|
|
582
|
-
/** Sorted and unique; empty exactly when `coverage` is `complete`. */
|
|
583
|
-
coverageReasonCodes: ProjectionArchitectureDebtCoverageReasonCode[];
|
|
584
|
-
/** Sorted by `fromCapabilityId`, then `toCapabilityId`. */
|
|
585
|
-
items: ProjectionUndeclaredDependencyV1[];
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/** One target a partial result carries forward instead of applying. */
|
|
589
|
-
export interface ProjectionCoverageBlockedTargetV1 {
|
|
590
|
-
targetId: string;
|
|
591
|
-
path: string;
|
|
592
|
-
/** The blocked capabilities this target depends on, sorted. Never empty. */
|
|
593
|
-
capabilityIds: string[];
|
|
594
|
-
/** Why those capabilities block it, sorted. Never empty. */
|
|
595
|
-
reasonCodes: ProjectionCoverageReasonCode[];
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
* Which part of the projection a `planned-partial` or `applied-partial` result covers (#327,
|
|
600
|
-
* Phase 1 capability isolation). The blocked capabilities are those whose proof is unprovable or
|
|
601
|
-
* whose flow proof moved without an accepted change, while their semantic fingerprint held. Every
|
|
602
|
-
* target that depends on one of them is carried forward unchanged: its document, its manifest row
|
|
603
|
-
* and the capability's baseline entry keep their committed bytes. `appliedTargetIds` are all the
|
|
604
|
-
* other targets, which the result renders from the current model and sources.
|
|
605
|
-
*
|
|
606
|
-
* `complete` is always `false`: a result that covers every target omits `coverage` instead. A
|
|
607
|
-
* partial result is never an acceptance. It carries no apply receipt and no refresh signal, and a
|
|
608
|
-
* complete check or the `complete` gate still reports the blocked capabilities until they are
|
|
609
|
-
* fixed or accepted.
|
|
610
|
-
*/
|
|
611
|
-
export interface ProjectionCoverageV1 {
|
|
612
|
-
complete: false;
|
|
613
|
-
/** Sorted and unique. Never empty. */
|
|
614
|
-
blockedCapabilityIds: string[];
|
|
615
|
-
/** Sorted and unique by targetId. Never empty. */
|
|
616
|
-
blockedTargets: ProjectionCoverageBlockedTargetV1[];
|
|
617
|
-
/** Sorted and unique; disjoint from the blocked targets. */
|
|
618
|
-
appliedTargetIds: string[];
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* One target of a `check` or `plan` result (#327 finding 2): how it changes since the committed
|
|
623
|
-
* projection, and what this run's write does to its file. The entries cover the union of the
|
|
624
|
-
* current layout's targets and the committed manifest's rows (plus orphans the manifest does not
|
|
625
|
-
* record), one per target. Only agent-context targets share a path (ADR-0056 §9). The projection
|
|
626
|
-
* manifest is not a target; its write is the `files[]` entry no change names.
|
|
627
|
-
*
|
|
628
|
-
* Each comparison is against the committed v4 manifest: `outputChanged` the row's `outputDigest`, or any byte the write changes;
|
|
629
|
-
* `semanticChanged` the `semanticFingerprint` of a capability the target documents (every
|
|
630
|
-
* capability for a target that is not an entity summary, which also compares the manifest's
|
|
631
|
-
* `semanticBaseline.modelDigest`, because it renders the whole model); `proofChanged` the `flowProofFingerprint`
|
|
632
|
-
* or `selectorEvidenceDigest` of a capability an entity summary documents. `null` is an unknown
|
|
633
|
-
* comparison, never `false`.
|
|
634
|
-
*
|
|
635
|
-
* `plannedAction` is the result's own write decision (`files[]`) for that path. When `status` is
|
|
636
|
-
* `planned` or `planned-partial`, the targets whose action is not `none` are exactly the documents
|
|
637
|
-
* an apply of this run writes or deletes; under `adoption-required` or `human-action-required`
|
|
638
|
-
* apply writes nothing, and `plannedAction` reports only what the render would write. A
|
|
639
|
-
* path rejected for adoption or ownership repair is `blocked` and `none`, because only an
|
|
640
|
-
* approved adoption writes it. `classification` never changes `status`, the write set or a gate.
|
|
641
|
-
*/
|
|
642
|
-
export interface ProjectionTargetChangeV2 {
|
|
643
|
-
targetId: string;
|
|
644
|
-
path: string;
|
|
645
|
-
/** Sorted and unique: the documented capabilities whose change affects this target. Empty when unchanged. */
|
|
646
|
-
affectedCapabilityIds: string[];
|
|
647
|
-
outputChanged: boolean;
|
|
648
|
-
semanticChanged: boolean | null;
|
|
649
|
-
proofChanged: boolean | null;
|
|
650
|
-
plannedAction: ProjectionTargetChangePlannedAction;
|
|
651
|
-
classification: ProjectionTargetChangeClassification;
|
|
652
|
-
/** Sorted and unique. Empty exactly when `classification` is `unchanged`. */
|
|
653
|
-
reasonCodes: ProjectionTargetChangeReasonCode[];
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
export interface ProjectionResultV3 {
|
|
657
|
-
schemaVersion: typeof PROJECTION_RESULT_SCHEMA_VERSION;
|
|
658
|
-
requestId: string;
|
|
659
|
-
status: ProjectionResultStatus;
|
|
660
|
-
inputSnapshot: ProjectionSnapshotV1;
|
|
661
|
-
outputSnapshot: ProjectionSnapshotV1;
|
|
662
|
-
affectedNodeIds: string[];
|
|
663
|
-
files: ProjectionFileResultV1[];
|
|
664
|
-
humanActions: ProjectionHumanActionV1[];
|
|
665
|
-
refreshSignals: ArchitectureRefreshSignalV2[];
|
|
666
|
-
applyReceipt?: ProjectionApplyIdentityV1;
|
|
667
|
-
/**
|
|
668
|
-
* Omitted, never `[]`, when no earlier attempt of this requestId committed. Never present on
|
|
669
|
-
* `check` results: a check runs in-process without the daemon journal, so read committed applies
|
|
670
|
-
* through `apply` or `readback`.
|
|
671
|
-
*/
|
|
672
|
-
priorCommittedApplies?: ProjectionPriorCommittedApplyV1[];
|
|
673
|
-
/**
|
|
674
|
-
* Present on `check` results only: which targets render differently from the committed
|
|
675
|
-
* manifest. Consumers gate on the `projection-check-freshness-v2` capability, not on field presence.
|
|
676
|
-
*/
|
|
677
|
-
freshness?: ProjectionFreshnessV2;
|
|
678
|
-
/**
|
|
679
|
-
* Present on every `check` and `plan` result, and on no other: the architecture debt this run
|
|
680
|
-
* found. It never changes `status`. Consumers gate on the `projection-architecture-debt-v1`
|
|
681
|
-
* capability, not on field presence.
|
|
682
|
-
*/
|
|
683
|
-
architectureDebt?: ProjectionArchitectureDebtV1;
|
|
684
|
-
/**
|
|
685
|
-
* Present on every `check` and `plan` result, and on no other: per-target change classification,
|
|
686
|
-
* sorted by path, then targetId (#327). It never changes `status` or `files`.
|
|
687
|
-
*/
|
|
688
|
-
changes?: ProjectionTargetChangeV2[];
|
|
689
|
-
/**
|
|
690
|
-
* Present, as `true`, only when this response returns an apply this requestId already committed
|
|
691
|
-
* for the same request digest, without applying again (#265). It is excluded from
|
|
692
|
-
* `receiptDigest`, so a replay carries the committed receipt digest unchanged.
|
|
693
|
-
*/
|
|
694
|
-
replayed?: true;
|
|
695
|
-
/**
|
|
696
|
-
* Present exactly when `replayed` is: whether this response wrote projection-owned files (#325).
|
|
697
|
-
* `false` means it wrote nothing; the committed result is returned as recorded. `true` means
|
|
698
|
-
* the projection-owned outputs differed from the approved result at the approved snapshot, so
|
|
699
|
-
* the provider wrote the committed fixed point again under the original receipt. Excluded from
|
|
700
|
-
* `receiptDigest`.
|
|
701
|
-
*/
|
|
702
|
-
written?: boolean;
|
|
703
|
-
/**
|
|
704
|
-
* Present only on a `human-action-required` result whose request sent `acceptObservedMajorChange`
|
|
705
|
-
* and the provider declined it: `declined-unprovable-proof` means a capability's P1 or P2 proof is
|
|
706
|
-
* unprovable, so no observed change can be accepted. The result then carries an
|
|
707
|
-
* `unprovable-required-flow` action naming those capabilities, never `unresolved-major-change`,
|
|
708
|
-
* so a caller can tell a declined flag from an absent one (#275).
|
|
709
|
-
*/
|
|
710
|
-
majorChangeAcceptance?: "declined-unprovable-proof";
|
|
711
|
-
/**
|
|
712
|
-
* Present exactly on `planned-partial` and `applied-partial` results, with `complete: false`; a
|
|
713
|
-
* result that covers every target omits it. Consumers gate on `projection-capability-isolation-v1`.
|
|
714
|
-
*/
|
|
715
|
-
coverage?: ProjectionCoverageV1;
|
|
716
|
-
receiptDigest: Sha256Digest;
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
export interface ProjectionApplyReceiptV1 {
|
|
720
|
-
schemaVersion: typeof PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION;
|
|
721
|
-
identity: ProjectionApplyIdentityV1;
|
|
722
|
-
result: ProjectionResultV3;
|
|
723
|
-
/**
|
|
724
|
-
* Present only on receipts written after recovery protocol v1 shipped. Receipts created by
|
|
725
|
-
* v0.4.7 remain inspectable, but cannot be recovered because they never recorded this exact
|
|
726
|
-
* approval binding.
|
|
727
|
-
*/
|
|
728
|
-
recovery?: ProjectionApplyRecoveryBindingV2;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/** Immutable approval metadata recorded with a new committed apply receipt, never inferred later. */
|
|
732
|
-
export interface ProjectionApplyRecoveryBindingV2 {
|
|
733
|
-
schemaVersion: typeof PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION;
|
|
734
|
-
targets: ProjectionTarget[];
|
|
735
|
-
changedPaths: string[];
|
|
736
|
-
originalExpectedSnapshot: ProjectionExpectedSnapshotV1;
|
|
737
|
-
expectedResultingDigests: ArchitectureDigestSetV2;
|
|
738
|
-
rendererVersion: typeof ARCHITECTURE_DOCS_RENDERER_VERSION;
|
|
739
|
-
layoutVersion: "archcontext.docs-layout/v1";
|
|
740
|
-
generatedFrom: ProjectionSnapshotV1["generatedFrom"];
|
|
741
|
-
ownedOutputDigest: Sha256Digest;
|
|
742
|
-
receiptDigest: Sha256Digest;
|
|
743
|
-
/**
|
|
744
|
-
* `digestJson` of the caller's ProjectionRequestV1 exactly as received. With the result's
|
|
745
|
-
* requestId it is the replay key of #265; it never includes provider-generated ids. Receipts
|
|
746
|
-
* committed before it existed lack it and are never replayed.
|
|
747
|
-
*/
|
|
748
|
-
requestDigest?: Sha256Digest;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* The only client-supplied recovery input. The daemon resolves every semantic field from the
|
|
753
|
-
* committed receipt and repository authority while it holds the writer boundary.
|
|
754
|
-
*/
|
|
755
|
-
export interface ProjectionApplyRecoveryIntentV1 {
|
|
756
|
-
schemaVersion: typeof PROJECTION_APPLY_RECOVERY_INTENT_SCHEMA_VERSION;
|
|
757
|
-
requestId: string;
|
|
758
|
-
profile: "repo-harness/v1";
|
|
759
|
-
receipt: {
|
|
760
|
-
lookupKey: Sha256Digest;
|
|
761
|
-
applyId: Sha256Digest;
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
export type ProjectionApplyRecoveryDeliveryStatus = "delivered" | "already-delivered";
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* A semantic proof created only after the CLI has rebuilt the current projection fixed point.
|
|
769
|
-
* `proofDigest` intentionally excludes deliveryStatus so an idempotent repeat can change only
|
|
770
|
-
* that explicitly declared field.
|
|
771
|
-
*/
|
|
772
|
-
export interface ProjectionApplyRecoveryProofV2 {
|
|
773
|
-
schemaVersion: typeof PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION;
|
|
774
|
-
requestId: string;
|
|
775
|
-
requestDigest: Sha256Digest;
|
|
776
|
-
proofDigest: Sha256Digest;
|
|
777
|
-
deliveryStatus: ProjectionApplyRecoveryDeliveryStatus;
|
|
778
|
-
receipt: {
|
|
779
|
-
lookupKey: Sha256Digest;
|
|
780
|
-
applyId: Sha256Digest;
|
|
781
|
-
receiptDigest: Sha256Digest;
|
|
782
|
-
};
|
|
783
|
-
acceptedChange: AcceptedArchitectureChangeReferenceV1;
|
|
784
|
-
expectedResultingDigests: ArchitectureDigestSetV2;
|
|
785
|
-
current: {
|
|
786
|
-
snapshot: ProjectionSnapshotV1;
|
|
787
|
-
resultingDigests: ArchitectureDigestSetV2;
|
|
788
|
-
ownedOutputDigest: Sha256Digest;
|
|
789
|
-
fixedPointDigest: Sha256Digest;
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
export interface ProjectionApplyRecoveryResultV2 {
|
|
794
|
-
schemaVersion: typeof PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION;
|
|
795
|
-
proof: ProjectionApplyRecoveryProofV2;
|
|
796
|
-
refreshSignals: ArchitectureRefreshSignalV2[];
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
/** Non-consuming receipt retrieval; current state is rebuilt for every response. */
|
|
800
|
-
export interface ProjectionApplyReadbackResultV2 {
|
|
801
|
-
schemaVersion: typeof PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION;
|
|
802
|
-
requestId: string;
|
|
803
|
-
requestDigest: Sha256Digest;
|
|
804
|
-
receipt: ProjectionApplyReceiptV1;
|
|
805
|
-
current: ProjectionApplyRecoveryProofV2["current"];
|
|
806
|
-
readbackDigest: Sha256Digest;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/** Exact-request absence observed under the same writer boundary used by apply. */
|
|
810
|
-
export interface ProjectionApplyAbsenceV1 {
|
|
811
|
-
schemaVersion: "archcontext.projection-apply-absence/v1";
|
|
812
|
-
requestId: string;
|
|
813
|
-
requestDigest: Sha256Digest;
|
|
814
|
-
lookupKey: Sha256Digest;
|
|
815
|
-
current: ProjectionExpectedSnapshotV1;
|
|
816
|
-
absenceDigest: Sha256Digest;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
export type ProjectionApplyReadbackV1 = ProjectionApplyReadbackResultV2 | ProjectionApplyAbsenceV1;
|
|
820
|
-
|
|
821
|
-
export interface ArchctxCapabilitiesV1 {
|
|
822
|
-
schemaVersion: typeof ARCHCTX_CAPABILITIES_SCHEMA_VERSION;
|
|
823
|
-
package: {
|
|
824
|
-
name: "archctx";
|
|
825
|
-
version: string;
|
|
826
|
-
};
|
|
827
|
-
protocols: {
|
|
828
|
-
projectionRequest: typeof PROJECTION_REQUEST_SCHEMA_VERSION;
|
|
829
|
-
projectionResult: typeof PROJECTION_RESULT_SCHEMA_VERSION;
|
|
830
|
-
architectureRefreshSignal: typeof ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION;
|
|
831
|
-
};
|
|
832
|
-
renderers: {
|
|
833
|
-
architectureDocs: typeof ARCHITECTURE_DOCS_RENDERER_VERSION;
|
|
834
|
-
agentContext: typeof AGENT_CONTEXT_RENDERER_VERSION;
|
|
835
|
-
};
|
|
836
|
-
features: ArchctxFeature[];
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
export function archctxCapabilities(packageVersion: string): ArchctxCapabilitiesV1 {
|
|
840
|
-
return {
|
|
841
|
-
schemaVersion: ARCHCTX_CAPABILITIES_SCHEMA_VERSION,
|
|
842
|
-
package: { name: "archctx", version: packageVersion },
|
|
843
|
-
protocols: {
|
|
844
|
-
projectionRequest: PROJECTION_REQUEST_SCHEMA_VERSION,
|
|
845
|
-
projectionResult: PROJECTION_RESULT_SCHEMA_VERSION,
|
|
846
|
-
architectureRefreshSignal: ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION
|
|
847
|
-
},
|
|
848
|
-
renderers: {
|
|
849
|
-
architectureDocs: ARCHITECTURE_DOCS_RENDERER_VERSION,
|
|
850
|
-
agentContext: AGENT_CONTEXT_RENDERER_VERSION
|
|
851
|
-
},
|
|
852
|
-
features: [...ARCHCTX_FEATURES]
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
export function projectionRequestInvariantIssues(input: ProjectionRequestV1): string[] {
|
|
857
|
-
const issues = [
|
|
858
|
-
...sortedUniqueIssues("targets", input.targets),
|
|
859
|
-
...sortedUniqueIssues("changedPaths", input.changedPaths),
|
|
860
|
-
...(input.acceptedChange
|
|
861
|
-
? [
|
|
862
|
-
...sortedUniqueIssues("acceptedChange.reasonCodes", input.acceptedChange.reasonCodes),
|
|
863
|
-
...sortedUniqueIssues("acceptedChange.affectedNodeIds", input.acceptedChange.affectedNodeIds)
|
|
864
|
-
]
|
|
865
|
-
: [])
|
|
866
|
-
];
|
|
867
|
-
if (input.targets.length === 0) issues.push("targets must contain at least one projection target");
|
|
868
|
-
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("requestId must use the stable identifier character set");
|
|
869
|
-
if (input.mode === "adopt" && !input.adoptionPlanId) issues.push("adoptionPlanId is required when mode=adopt");
|
|
870
|
-
if (input.mode !== "adopt" && input.adoptionPlanId !== undefined) issues.push("adoptionPlanId is only allowed when mode=adopt");
|
|
871
|
-
if (input.acceptObservedMajorChange !== undefined) {
|
|
872
|
-
if (input.acceptObservedMajorChange !== true) issues.push("acceptObservedMajorChange must be true when present");
|
|
873
|
-
if (input.mode !== "apply" && input.mode !== "adopt") issues.push("acceptObservedMajorChange is only allowed when mode=apply or mode=adopt");
|
|
874
|
-
if (input.acceptedChange !== undefined) issues.push("acceptObservedMajorChange and acceptedChange are mutually exclusive");
|
|
875
|
-
}
|
|
876
|
-
if (input.acceptedChange) {
|
|
877
|
-
if (input.acceptedChange.changeSetId.trim() === "") issues.push("acceptedChange.changeSetId must not be empty");
|
|
878
|
-
if (input.acceptedChange.eventId.trim() === "") issues.push("acceptedChange.eventId must not be empty");
|
|
879
|
-
if (input.acceptedChange.reasonCodes.length === 0) issues.push("acceptedChange.reasonCodes must contain at least one reason");
|
|
880
|
-
if (input.acceptedChange.affectedNodeIds.length === 0) issues.push("acceptedChange.affectedNodeIds must contain at least one node");
|
|
881
|
-
const allowedReasons = new Set<string>(ARCHITECTURE_MAJOR_CHANGE_REASON_CODES);
|
|
882
|
-
for (const reason of input.acceptedChange.reasonCodes) {
|
|
883
|
-
if (!allowedReasons.has(reason)) issues.push(`acceptedChange.reasonCodes contains unsupported reason: ${reason}`);
|
|
884
|
-
}
|
|
885
|
-
for (const nodeId of input.acceptedChange.affectedNodeIds) {
|
|
886
|
-
if (nodeId.trim() === "") issues.push("acceptedChange.affectedNodeIds must not contain empty node ids");
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return issues;
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Invariants that bind a result to the request mode that produced it, which the result itself does
|
|
894
|
-
* not carry: only a `plan` result previews what it would write (#264); `check`, `apply` and
|
|
895
|
-
* `adopt` results never carry `files[].preview`, whatever their status.
|
|
896
|
-
*/
|
|
897
|
-
export function projectionResultRequestModeIssues(input: ProjectionResultV3, mode: ProjectionMode): string[] {
|
|
898
|
-
const issues: string[] = [];
|
|
899
|
-
if (mode !== "plan" && input.files.some((file) => file.preview !== undefined)) {
|
|
900
|
-
issues.push(`files[].preview is only allowed on a plan result, never when mode=${mode}`);
|
|
901
|
-
}
|
|
902
|
-
if (mode !== "check" && mode !== "plan" && input.architectureDebt !== undefined) {
|
|
903
|
-
issues.push(`architectureDebt is only allowed on a check or plan result, never when mode=${mode}`);
|
|
904
|
-
}
|
|
905
|
-
if (mode !== "check" && mode !== "plan" && input.changes !== undefined) {
|
|
906
|
-
issues.push(`changes is only allowed on a check or plan result, never when mode=${mode}`);
|
|
907
|
-
}
|
|
908
|
-
// The schema cannot condition on the request mode, so the presence promise is checked here.
|
|
909
|
-
if ((mode === "check" || mode === "plan") && input.changes === undefined) {
|
|
910
|
-
issues.push(`changes is required on every check or plan result, also when mode=${mode}`);
|
|
911
|
-
}
|
|
912
|
-
if (input.status === "planned-partial" && mode !== "check" && mode !== "plan") {
|
|
913
|
-
issues.push(`planned-partial is only allowed on a check or plan result, never when mode=${mode}`);
|
|
914
|
-
}
|
|
915
|
-
if (input.status === "applied-partial" && mode !== "apply") {
|
|
916
|
-
issues.push(`applied-partial is only allowed on an apply result, never when mode=${mode}`);
|
|
917
|
-
}
|
|
918
|
-
return issues;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
export function projectionResultInvariantIssues(input: ProjectionResultV3): string[] {
|
|
922
|
-
const issues = [
|
|
923
|
-
...sortedUniqueIssues("affectedNodeIds", input.affectedNodeIds),
|
|
924
|
-
...sortedUniqueIssues("files.path", input.files.map((file) => file.path)),
|
|
925
|
-
...sortedUniqueIssues("refreshSignals.signalId", input.refreshSignals.map((signal) => signal.signalId)),
|
|
926
|
-
...input.humanActions.flatMap((action, index) => sortedUniqueIssues(`humanActions[${index}].affectedNodeIds`, action.affectedNodeIds)),
|
|
927
|
-
...input.refreshSignals.flatMap((signal, index) => architectureRefreshSignalInvariantIssues(signal, `refreshSignals[${index}]`))
|
|
928
|
-
];
|
|
929
|
-
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("requestId must use the stable identifier character set");
|
|
930
|
-
if (input.inputSnapshot.repositoryId !== input.outputSnapshot.repositoryId) issues.push("outputSnapshot.repositoryId must match inputSnapshot.repositoryId");
|
|
931
|
-
if (input.inputSnapshot.workspaceId !== input.outputSnapshot.workspaceId) issues.push("outputSnapshot.workspaceId must match inputSnapshot.workspaceId");
|
|
932
|
-
if (input.inputSnapshot.baseHeadSha !== input.outputSnapshot.baseHeadSha) issues.push("outputSnapshot.baseHeadSha must match inputSnapshot.baseHeadSha");
|
|
933
|
-
const statusRequiresHumanAction = input.status === "adoption-required" || input.status === "human-action-required";
|
|
934
|
-
if (statusRequiresHumanAction && input.humanActions.length === 0) issues.push(`${input.status} status requires at least one human action`);
|
|
935
|
-
if (!statusRequiresHumanAction && input.humanActions.length > 0) issues.push(`human actions are not allowed when status=${input.status}`);
|
|
936
|
-
if (input.status === "applied-reconcile-required") {
|
|
937
|
-
if (!input.applyReceipt) issues.push("applied-reconcile-required status requires applyReceipt");
|
|
938
|
-
if (input.refreshSignals.length > 0) issues.push("applied-reconcile-required status cannot deliver refreshSignals");
|
|
939
|
-
}
|
|
940
|
-
const partial = (PROJECTION_PARTIAL_RESULT_STATUSES as readonly string[]).includes(input.status);
|
|
941
|
-
if (partial !== (input.coverage !== undefined)) issues.push("coverage must be present exactly when status is planned-partial or applied-partial");
|
|
942
|
-
if (input.coverage !== undefined) issues.push(...projectionCoverageIssues(input.coverage, input.files));
|
|
943
|
-
if (partial) {
|
|
944
|
-
// An incomplete projection is never an acceptance: it records no apply and signals no refresh.
|
|
945
|
-
if (input.applyReceipt !== undefined) issues.push(`${input.status} status never carries applyReceipt`);
|
|
946
|
-
if (input.refreshSignals.length > 0) issues.push(`${input.status} status carries no refreshSignals`);
|
|
947
|
-
}
|
|
948
|
-
const committedApply = input.applyReceipt !== undefined || input.status === "applied" || input.status === "applied-partial" || input.status === "applied-reconcile-required";
|
|
949
|
-
for (const [index, action] of input.humanActions.entries()) {
|
|
950
|
-
const prefix = `humanActions[${index}]`;
|
|
951
|
-
if (!(PROJECTION_HUMAN_ACTION_REASON_CODES as readonly string[]).includes(action.reasonCode)) issues.push(`${prefix}.reasonCode is unsupported`);
|
|
952
|
-
if ((action.reasonCode === "orphaned-document-review") !== (action.path !== undefined)) {
|
|
953
|
-
issues.push(`${prefix}.path must be present exactly when reasonCode=orphaned-document-review`);
|
|
954
|
-
}
|
|
955
|
-
if (action.path !== undefined && !isRepoRelativePosixPath(action.path)) issues.push(`${prefix}.path must be a repository-relative POSIX path`);
|
|
956
|
-
}
|
|
957
|
-
const orphanReviewPaths = input.humanActions.flatMap((action) => action.reasonCode === "orphaned-document-review" && action.path !== undefined ? [action.path] : []);
|
|
958
|
-
issues.push(...sortedUniqueIssues("humanActions[orphaned-document-review].path", orphanReviewPaths));
|
|
959
|
-
if (orphanReviewPaths.some((path) => input.files.some((file) => file.path === path))) {
|
|
960
|
-
issues.push("an orphaned-document-review path must not also be a files[] entry");
|
|
961
|
-
}
|
|
962
|
-
for (const [index, file] of input.files.entries()) {
|
|
963
|
-
const prefix = `files[${index}]`;
|
|
964
|
-
if (file.action === "create" && (file.preimageDigest !== null || file.outputDigest === null)) {
|
|
965
|
-
issues.push(`${prefix} create requires null preimageDigest and non-null outputDigest`);
|
|
966
|
-
}
|
|
967
|
-
if (file.action === "delete" && (file.preimageDigest === null || file.outputDigest !== null)) {
|
|
968
|
-
issues.push(`${prefix} delete requires non-null preimageDigest and null outputDigest`);
|
|
969
|
-
}
|
|
970
|
-
if (file.action === "update" && (file.preimageDigest === null || file.outputDigest === null || file.preimageDigest === file.outputDigest)) {
|
|
971
|
-
issues.push(`${prefix} update requires two different non-null digests`);
|
|
972
|
-
}
|
|
973
|
-
if (file.action === "unchanged" && (file.preimageDigest === null || file.outputDigest === null || file.preimageDigest !== file.outputDigest)) {
|
|
974
|
-
issues.push(`${prefix} unchanged requires equal non-null digests`);
|
|
975
|
-
}
|
|
976
|
-
if (file.preview !== undefined) issues.push(...projectionFilePreviewIssues(file, prefix));
|
|
977
|
-
}
|
|
978
|
-
const previewBytes = input.files.reduce((total, file) => total + (file.preview ? utf8ByteLength(file.preview.content) : 0), 0);
|
|
979
|
-
if (previewBytes > PROJECTION_PREVIEW_TOTAL_MAX_BYTES) {
|
|
980
|
-
issues.push(`files[].preview.content must not exceed ${PROJECTION_PREVIEW_TOTAL_MAX_BYTES} UTF-8 bytes in total`);
|
|
981
|
-
}
|
|
982
|
-
// The result does not carry its request mode; projectionResultRequestModeIssues binds a preview
|
|
983
|
-
// to mode=plan. On the result alone, a committed apply (and so a persisted receipt) never carries one.
|
|
984
|
-
if (input.files.some((file) => file.preview !== undefined) && committedApply) {
|
|
985
|
-
issues.push("files[].preview is only allowed on a plan result, never on a committed apply");
|
|
986
|
-
}
|
|
987
|
-
if (input.priorCommittedApplies) {
|
|
988
|
-
issues.push(...projectionPriorCommittedAppliesIssues(input.priorCommittedApplies, input.requestId));
|
|
989
|
-
}
|
|
990
|
-
if (input.freshness) issues.push(...projectionFreshnessIssues(input.freshness));
|
|
991
|
-
if (input.architectureDebt) {
|
|
992
|
-
issues.push(...projectionArchitectureDebtIssues(input.architectureDebt));
|
|
993
|
-
if (committedApply) {
|
|
994
|
-
issues.push("architectureDebt is only allowed on a check or plan result, never on a committed apply");
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
if (input.changes) {
|
|
998
|
-
issues.push(...projectionTargetChangesIssues(input.changes, input.files));
|
|
999
|
-
if (committedApply) issues.push("changes is only allowed on a check or plan result, never on a committed apply");
|
|
1000
|
-
// A carried-forward target is blocked, by the same reasons its coverage entry names.
|
|
1001
|
-
for (const target of input.coverage?.blockedTargets ?? []) {
|
|
1002
|
-
const entry = input.changes.find((candidate) => candidate.targetId === target.targetId);
|
|
1003
|
-
if (!entry || entry.classification !== "blocked" || target.reasonCodes.some((code) => !entry.reasonCodes.includes(code))) {
|
|
1004
|
-
issues.push(`changes must classify the carried-forward target ${target.path} as blocked with its coverage reason codes`);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
if (input.majorChangeAcceptance !== undefined) {
|
|
1009
|
-
if (input.majorChangeAcceptance !== "declined-unprovable-proof") issues.push("majorChangeAcceptance is unsupported");
|
|
1010
|
-
if (input.status !== "human-action-required"
|
|
1011
|
-
|| !input.humanActions.some((action) => action.reasonCode === "unprovable-required-flow")
|
|
1012
|
-
|| input.humanActions.some((action) => action.reasonCode === "unresolved-major-change")) {
|
|
1013
|
-
issues.push("majorChangeAcceptance requires human-action-required with unprovable-required-flow in place of unresolved-major-change");
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
if (input.replayed !== undefined) {
|
|
1017
|
-
if (input.replayed !== true) issues.push("replayed must be true when present");
|
|
1018
|
-
if (!input.applyReceipt || (input.status !== "applied" && input.status !== "applied-reconcile-required")) {
|
|
1019
|
-
issues.push("replayed is only allowed on a committed apply result with applyReceipt");
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
if ((input.replayed !== undefined) !== (input.written !== undefined)) issues.push("written must be present exactly when replayed is present");
|
|
1023
|
-
if (input.written !== undefined && typeof input.written !== "boolean") issues.push("written must be a boolean when present");
|
|
1024
|
-
const { receiptDigest, ...receiptPayload } = input;
|
|
1025
|
-
if (projectionResultReceiptDigest(receiptPayload) !== receiptDigest) issues.push("receiptDigest must match the canonical projection result payload");
|
|
1026
|
-
for (const [index, signal] of input.refreshSignals.entries()) {
|
|
1027
|
-
const prefix = `refreshSignals[${index}]`;
|
|
1028
|
-
if (signal.projectionReceiptDigest !== receiptDigest) issues.push(`${prefix}.projectionReceiptDigest must match receiptDigest`);
|
|
1029
|
-
if (signal.repository.repositoryId !== input.outputSnapshot.repositoryId) issues.push(`${prefix}.repositoryId must match outputSnapshot.repositoryId`);
|
|
1030
|
-
if (signal.worktree.workspaceId !== input.outputSnapshot.workspaceId) issues.push(`${prefix}.workspaceId must match outputSnapshot.workspaceId`);
|
|
1031
|
-
if (signal.worktree.headSha !== input.outputSnapshot.headSha) issues.push(`${prefix}.headSha must match outputSnapshot.headSha`);
|
|
1032
|
-
if (signal.worktree.worktreeDigest !== input.outputSnapshot.worktreeDigest) issues.push(`${prefix}.worktreeDigest must match outputSnapshot.worktreeDigest`);
|
|
1033
|
-
}
|
|
1034
|
-
return issues;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
function projectionFilePreviewIssues(file: ProjectionFileResultV1, prefix: string): string[] {
|
|
1038
|
-
const preview = file.preview!;
|
|
1039
|
-
const issues: string[] = [];
|
|
1040
|
-
const expectedFormat: ProjectionFilePreviewFormat | undefined = file.action === "create"
|
|
1041
|
-
? "body"
|
|
1042
|
-
: file.action === "update" || file.action === "delete" ? "unified-diff" : undefined;
|
|
1043
|
-
if (expectedFormat === undefined) issues.push(`${prefix}.preview is not allowed when action=${file.action}`);
|
|
1044
|
-
else if (preview.format !== expectedFormat) issues.push(`${prefix}.preview.format must be ${expectedFormat} when action=${file.action}`);
|
|
1045
|
-
if (typeof preview.content !== "string" || typeof preview.truncated !== "boolean"
|
|
1046
|
-
|| !Number.isSafeInteger(preview.byteLength) || preview.byteLength < 0) {
|
|
1047
|
-
issues.push(`${prefix}.preview must carry string content, a boolean truncated flag and a non-negative integer byteLength`);
|
|
1048
|
-
return issues;
|
|
1049
|
-
}
|
|
1050
|
-
const contentBytes = utf8ByteLength(preview.content);
|
|
1051
|
-
if (contentBytes > PROJECTION_FILE_PREVIEW_MAX_BYTES) issues.push(`${prefix}.preview.content must not exceed ${PROJECTION_FILE_PREVIEW_MAX_BYTES} UTF-8 bytes`);
|
|
1052
|
-
if (preview.truncated ? contentBytes >= preview.byteLength : contentBytes !== preview.byteLength) {
|
|
1053
|
-
issues.push(`${prefix}.preview.truncated must be true exactly when content is shorter than byteLength`);
|
|
1054
|
-
}
|
|
1055
|
-
return issues;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
const UTF8 = new TextEncoder();
|
|
1059
|
-
|
|
1060
|
-
function utf8ByteLength(value: string): number {
|
|
1061
|
-
return UTF8.encode(value).length;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
/**
|
|
1065
|
-
* Shape and canonical order of a partial result's `coverage`, and its binding to the result's
|
|
1066
|
-
* files: a carried-forward target is never also a written file.
|
|
1067
|
-
*/
|
|
1068
|
-
export function projectionCoverageIssues(input: ProjectionCoverageV1, files: readonly ProjectionFileResultV1[] = []): string[] {
|
|
1069
|
-
const issues = [
|
|
1070
|
-
...sortedUniqueIssues("coverage.blockedCapabilityIds", input.blockedCapabilityIds),
|
|
1071
|
-
...sortedUniqueIssues("coverage.blockedTargets.targetId", input.blockedTargets.map((target) => target.targetId)),
|
|
1072
|
-
...sortedUniqueIssues("coverage.appliedTargetIds", input.appliedTargetIds)
|
|
1073
|
-
];
|
|
1074
|
-
if (input.complete !== false) issues.push("coverage.complete must be false; a result that covers every target omits coverage");
|
|
1075
|
-
if (input.blockedCapabilityIds.length === 0) issues.push("coverage.blockedCapabilityIds must name at least one capability");
|
|
1076
|
-
if (input.blockedTargets.length === 0) issues.push("coverage.blockedTargets must name at least one target");
|
|
1077
|
-
if (input.blockedCapabilityIds.some((id) => typeof id !== "string" || id.trim() === "")) issues.push("coverage.blockedCapabilityIds must not contain empty ids");
|
|
1078
|
-
if (input.appliedTargetIds.some((id) => typeof id !== "string" || id.trim() === "")) issues.push("coverage.appliedTargetIds must not contain empty ids");
|
|
1079
|
-
const blockedCapabilities = new Set(input.blockedCapabilityIds);
|
|
1080
|
-
const blockingCapabilities = new Set<string>();
|
|
1081
|
-
const blockedPaths = new Set<string>();
|
|
1082
|
-
const reasons = new Set<string>(PROJECTION_COVERAGE_REASON_CODES);
|
|
1083
|
-
for (const [index, target] of input.blockedTargets.entries()) {
|
|
1084
|
-
const prefix = `coverage.blockedTargets[${index}]`;
|
|
1085
|
-
if (typeof target.targetId !== "string" || target.targetId.trim() === "") issues.push(`${prefix}.targetId must not be empty`);
|
|
1086
|
-
if (!isRepoRelativePosixPath(target.path)) issues.push(`${prefix}.path must be a repository-relative POSIX path`);
|
|
1087
|
-
else if (blockedPaths.has(target.path)) issues.push(`${prefix}.path is named by another blocked target`);
|
|
1088
|
-
blockedPaths.add(target.path);
|
|
1089
|
-
issues.push(...sortedUniqueIssues(`${prefix}.capabilityIds`, target.capabilityIds), ...sortedUniqueIssues(`${prefix}.reasonCodes`, target.reasonCodes));
|
|
1090
|
-
if (target.capabilityIds.length === 0) issues.push(`${prefix}.capabilityIds must name at least one capability`);
|
|
1091
|
-
if (target.reasonCodes.length === 0) issues.push(`${prefix}.reasonCodes must name at least one reason`);
|
|
1092
|
-
for (const capabilityId of target.capabilityIds) {
|
|
1093
|
-
if (!blockedCapabilities.has(capabilityId)) issues.push(`${prefix}.capabilityIds names ${capabilityId}, which is not a blocked capability`);
|
|
1094
|
-
blockingCapabilities.add(capabilityId);
|
|
1095
|
-
}
|
|
1096
|
-
const reason = target.reasonCodes.find((code) => !reasons.has(code));
|
|
1097
|
-
if (reason !== undefined) issues.push(`${prefix}.reasonCodes contains unsupported reason: ${reason}`);
|
|
1098
|
-
if (input.appliedTargetIds.includes(target.targetId)) issues.push(`${prefix}.targetId must not also be an applied target`);
|
|
1099
|
-
}
|
|
1100
|
-
for (const capabilityId of input.blockedCapabilityIds) {
|
|
1101
|
-
if (!blockingCapabilities.has(capabilityId)) issues.push(`coverage.blockedCapabilityIds names ${capabilityId}, which blocks no target`);
|
|
1102
|
-
}
|
|
1103
|
-
for (const file of files) {
|
|
1104
|
-
if (blockedPaths.has(file.path)) issues.push(`files[] must not write the carried-forward target path ${file.path}`);
|
|
1105
|
-
}
|
|
1106
|
-
return issues;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
const TARGET_CHANGE_BLOCKING_REASONS = new Set<string>(PROJECTION_TARGET_CHANGE_BLOCKING_REASON_CODES);
|
|
1110
|
-
const TARGET_CHANGE_UNKNOWN_REASONS = ["baseline-missing", "target-row-missing"] as const;
|
|
1111
|
-
const TARGET_CHANGE_OUTPUT_REASONS = ["file-bytes-changed", "rendered-output-changed", "target-added", "target-removed"] as const;
|
|
1112
|
-
const TARGET_CHANGE_PROOF_REASONS = ["flow-proof-changed", "selector-evidence-changed"] as const;
|
|
1113
|
-
const TARGET_CHANGE_SEMANTIC_REASONS = ["model-digest-changed", "semantic-fingerprint-changed"] as const;
|
|
1114
|
-
|
|
1115
|
-
/**
|
|
1116
|
-
* The one precedence rule of a target change: blocked > proof-change (`proofChanged === true`) >
|
|
1117
|
-
* baseline-missing > semantic-change > output-change > unchanged. A known proof change is never
|
|
1118
|
-
* hidden by an unknown comparison (a target without a committed row can still carry a moved flow
|
|
1119
|
-
* proof); an unknown comparison outranks everything below the proof change and is never `unchanged`.
|
|
1120
|
-
*/
|
|
1121
|
-
export function projectionTargetChangeClassification(
|
|
1122
|
-
input: Pick<ProjectionTargetChangeV2, "reasonCodes" | "outputChanged" | "semanticChanged" | "proofChanged">
|
|
1123
|
-
): ProjectionTargetChangeClassification {
|
|
1124
|
-
if (input.reasonCodes.some((code) => TARGET_CHANGE_BLOCKING_REASONS.has(code))) return "blocked";
|
|
1125
|
-
if (input.proofChanged === true) return "proof-change";
|
|
1126
|
-
if (input.semanticChanged === null || input.proofChanged === null) return "baseline-missing";
|
|
1127
|
-
if (input.semanticChanged) return "semantic-change";
|
|
1128
|
-
if (input.outputChanged) return "output-change";
|
|
1129
|
-
return "unchanged";
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* Shape, canonical order and internal consistency of a result's `changes`, and their binding to its
|
|
1134
|
-
* `files`: a change with a planned action names the `files[]` entry of its path with that action; a
|
|
1135
|
-
* `files[]` entry a change names but does not plan is a path rejected for adoption or ownership
|
|
1136
|
-
* repair, so that change is blocked by that rejection, and still reports the bytes that entry
|
|
1137
|
-
* changes (`outputChanged`). Every `files[]` entry that changes a file has a change of its path,
|
|
1138
|
-
* except the projection manifest, which is never a target.
|
|
1139
|
-
*
|
|
1140
|
-
* One entry per target: `targetId` is unique, and entries are ordered by path, then targetId. Only
|
|
1141
|
-
* agent-context targets share a path, because several nodes' regions live in one contract file
|
|
1142
|
-
* (ADR-0056 §9).
|
|
1143
|
-
*/
|
|
1144
|
-
export function projectionTargetChangesIssues(input: readonly ProjectionTargetChangeV2[], files: readonly ProjectionFileResultV1[] = []): string[] {
|
|
1145
|
-
const issues: string[] = new Set(input.map((entry) => entry.targetId)).size === input.length ? [] : ["changes.targetId must be unique"];
|
|
1146
|
-
const order = (entry: ProjectionTargetChangeV2) => `${entry.path}\u0000${entry.targetId}`;
|
|
1147
|
-
if (input.some((entry, index) => index > 0 && order(input[index - 1]!) >= order(entry))) issues.push("changes must be ordered by path, then targetId");
|
|
1148
|
-
const targetIdsByPath = new Map<string, string[]>();
|
|
1149
|
-
for (const entry of input) targetIdsByPath.set(entry.path, [...(targetIdsByPath.get(entry.path) ?? []), entry.targetId]);
|
|
1150
|
-
for (const [path, targetIds] of targetIdsByPath) {
|
|
1151
|
-
if (targetIds.length > 1 && targetIds.some((targetId) => !isAgentContextTargetId(targetId))) issues.push(`changes.path ${path} is shared by targets that are not all agent-context targets`);
|
|
1152
|
-
}
|
|
1153
|
-
const fileByPath = new Map(files.map((file) => [file.path, file]));
|
|
1154
|
-
const reasons = new Set<string>(PROJECTION_TARGET_CHANGE_REASON_CODES);
|
|
1155
|
-
for (const [index, entry] of input.entries()) {
|
|
1156
|
-
const prefix = `changes[${index}]`;
|
|
1157
|
-
const has = (codes: readonly string[]) => codes.some((code) => entry.reasonCodes.includes(code as ProjectionTargetChangeReasonCode));
|
|
1158
|
-
if (typeof entry.targetId !== "string" || entry.targetId.trim() === "") issues.push(`${prefix}.targetId must not be empty`);
|
|
1159
|
-
if (!isRepoRelativePosixPath(entry.path)) issues.push(`${prefix}.path must be a repository-relative POSIX path`);
|
|
1160
|
-
issues.push(...sortedUniqueIssues(`${prefix}.affectedCapabilityIds`, entry.affectedCapabilityIds), ...sortedUniqueIssues(`${prefix}.reasonCodes`, entry.reasonCodes));
|
|
1161
|
-
if (entry.affectedCapabilityIds.some((id) => typeof id !== "string" || id.trim() === "")) issues.push(`${prefix}.affectedCapabilityIds must not contain empty ids`);
|
|
1162
|
-
const unsupported = entry.reasonCodes.find((code) => !reasons.has(code));
|
|
1163
|
-
if (unsupported !== undefined) issues.push(`${prefix}.reasonCodes contains an unsupported code: ${unsupported}`);
|
|
1164
|
-
for (const field of ["semanticChanged", "proofChanged"] as const) {
|
|
1165
|
-
if (entry[field] !== null && typeof entry[field] !== "boolean") issues.push(`${prefix}.${field} must be a boolean or null`);
|
|
1166
|
-
}
|
|
1167
|
-
if (typeof entry.outputChanged !== "boolean") issues.push(`${prefix}.outputChanged must be a boolean`);
|
|
1168
|
-
if (!(PROJECTION_TARGET_CHANGE_PLANNED_ACTIONS as readonly string[]).includes(entry.plannedAction)) issues.push(`${prefix}.plannedAction is unsupported`);
|
|
1169
|
-
if ((entry.semanticChanged === true) !== has(TARGET_CHANGE_SEMANTIC_REASONS)) issues.push(`${prefix}.semanticChanged must be true exactly when semantic-fingerprint-changed or model-digest-changed is reported`);
|
|
1170
|
-
if ((entry.proofChanged === true) !== has(TARGET_CHANGE_PROOF_REASONS)) issues.push(`${prefix}.proofChanged must be true exactly when flow-proof-changed or selector-evidence-changed is reported`);
|
|
1171
|
-
if (entry.outputChanged !== has(TARGET_CHANGE_OUTPUT_REASONS)) issues.push(`${prefix}.outputChanged must be true exactly when an output reason code is reported`);
|
|
1172
|
-
if ((entry.semanticChanged === null || entry.proofChanged === null) !== has(TARGET_CHANGE_UNKNOWN_REASONS)) {
|
|
1173
|
-
issues.push(`${prefix} must report baseline-missing or target-row-missing exactly when a comparison is unknown`);
|
|
1174
|
-
}
|
|
1175
|
-
const derived = projectionTargetChangeClassification(entry);
|
|
1176
|
-
if (entry.classification !== derived) issues.push(`${prefix}.classification must be ${derived} for its comparisons and reason codes`);
|
|
1177
|
-
if ((entry.classification === "unchanged") !== (entry.reasonCodes.length === 0)) issues.push(`${prefix}.reasonCodes must be empty exactly when classification is unchanged`);
|
|
1178
|
-
if (entry.classification === "unchanged" && entry.affectedCapabilityIds.length > 0) issues.push(`${prefix} is unchanged, so affectedCapabilityIds must be empty`);
|
|
1179
|
-
if (entry.classification === "blocked" && entry.plannedAction !== "none") issues.push(`${prefix} is blocked, so plannedAction must be none`);
|
|
1180
|
-
if (entry.plannedAction !== "none" && entry.outputChanged !== true) issues.push(`${prefix} writes its file, so outputChanged must be true`);
|
|
1181
|
-
if (entry.path === ARCHITECTURE_DOCS_PROJECTION_MANIFEST_PATH) issues.push(`${prefix} names the projection manifest, which is not a target`);
|
|
1182
|
-
const file = fileByPath.get(entry.path);
|
|
1183
|
-
const fileAction = file === undefined || file.action === "unchanged" ? "none" : file.action;
|
|
1184
|
-
const rejected = has(["adoption-required", "ambiguous-ownership"]);
|
|
1185
|
-
if (entry.plannedAction !== fileAction && !(rejected && entry.plannedAction === "none" && fileAction === "update")) {
|
|
1186
|
-
issues.push(`${prefix}.plannedAction must be ${fileAction}, the files[] action for ${entry.path}`);
|
|
1187
|
-
}
|
|
1188
|
-
// The file result proves the bytes change, whether or not this run may write them.
|
|
1189
|
-
if (fileAction !== "none" && entry.outputChanged !== true) issues.push(`${prefix}.outputChanged must be true, the files[] entry for ${entry.path} changes its bytes`);
|
|
1190
|
-
}
|
|
1191
|
-
const changedPaths = new Set(input.map((entry) => entry.path));
|
|
1192
|
-
for (const file of files) {
|
|
1193
|
-
if (file.action === "unchanged" || file.path === ARCHITECTURE_DOCS_PROJECTION_MANIFEST_PATH || changedPaths.has(file.path)) continue;
|
|
1194
|
-
issues.push(`changes must name the files[] ${file.action} of ${file.path}; only the projection manifest has none`);
|
|
1195
|
-
}
|
|
1196
|
-
return issues;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
/** The targetId shape of an agent-context target: `projection_target.agent-context.<agents|claude>.<node>`. */
|
|
1200
|
-
function isAgentContextTargetId(targetId: unknown): boolean {
|
|
1201
|
-
return typeof targetId === "string" && /^projection_target\.agent-context\.(agents|claude)\.[^.]+$/.test(targetId);
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
export function projectionFreshnessIssues(input: ProjectionFreshnessV2): string[] {
|
|
1205
|
-
const issues = [
|
|
1206
|
-
...sortedUniqueIssues("freshness.reasonCodes", input.reasonCodes),
|
|
1207
|
-
...sortedUniqueIssues("freshness.staleTargets.targetId", input.staleTargets.map((target) => target.targetId))
|
|
1208
|
-
];
|
|
1209
|
-
const unsupported = input.reasonCodes.find((code) => !(PROJECTION_FRESHNESS_REASON_CODES as readonly string[]).includes(code));
|
|
1210
|
-
if (unsupported) issues.push(`freshness.reasonCodes contains an unsupported code: ${unsupported}`);
|
|
1211
|
-
if (input.ok !== (input.reasonCodes.length === 0)) issues.push("freshness.ok must be true exactly when reasonCodes is empty");
|
|
1212
|
-
if ((input.staleTargets.length > 0) !== input.reasonCodes.includes("projection-output-changed")) {
|
|
1213
|
-
issues.push("freshness.staleTargets must be non-empty exactly when projection-output-changed is reported");
|
|
1214
|
-
}
|
|
1215
|
-
for (const [index, target] of input.staleTargets.entries()) {
|
|
1216
|
-
const prefix = `freshness.staleTargets[${index}]`;
|
|
1217
|
-
if (target.targetId.trim() === "") issues.push(`${prefix}.targetId must not be empty`);
|
|
1218
|
-
if (!isRepoRelativePosixPath(target.path)) issues.push(`${prefix}.path must be a repository-relative POSIX path`);
|
|
1219
|
-
const digests = [target.committedOutputDigest, target.renderedOutputDigest];
|
|
1220
|
-
if (digests.every((digest) => digest === null)) issues.push(`${prefix} must name at least one digest`);
|
|
1221
|
-
else if (digests.some((digest) => digest !== null && !SHA256_DIGEST.test(digest))) issues.push(`${prefix} digests must be SHA-256 digests or null`);
|
|
1222
|
-
else if (target.committedOutputDigest === target.renderedOutputDigest) issues.push(`${prefix} must name two different digests`);
|
|
1223
|
-
}
|
|
1224
|
-
return issues;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
export function projectionArchitectureDebtIssues(input: ProjectionArchitectureDebtV1): string[] {
|
|
1228
|
-
const issues = [
|
|
1229
|
-
...sortedUniqueIssues("architectureDebt.coverageReasonCodes", input.coverageReasonCodes),
|
|
1230
|
-
...sortedUniqueIssues("architectureDebt.items", input.items.map((item) => JSON.stringify([item.fromCapabilityId, item.toCapabilityId])))
|
|
1231
|
-
];
|
|
1232
|
-
if (!(["complete", "partial", "unknown"] as const).includes(input.coverage)) issues.push("architectureDebt.coverage is unsupported");
|
|
1233
|
-
const unsupported = input.coverageReasonCodes.find((code) => !(PROJECTION_ARCHITECTURE_DEBT_COVERAGE_REASON_CODES as readonly string[]).includes(code));
|
|
1234
|
-
if (unsupported) issues.push(`architectureDebt.coverageReasonCodes contains an unsupported code: ${unsupported}`);
|
|
1235
|
-
if ((input.coverage === "complete") !== (input.coverageReasonCodes.length === 0)) {
|
|
1236
|
-
issues.push("architectureDebt.coverageReasonCodes must be empty exactly when coverage is complete");
|
|
1237
|
-
}
|
|
1238
|
-
if ((input.coverage === "unknown") !== input.coverageReasonCodes.includes("code-facts-unavailable")) {
|
|
1239
|
-
issues.push("architectureDebt.coverage must be unknown exactly when code-facts-unavailable is reported");
|
|
1240
|
-
}
|
|
1241
|
-
if (input.coverage === "unknown" && input.items.length > 0) issues.push("architectureDebt.items must be empty when coverage is unknown");
|
|
1242
|
-
for (const [index, item] of input.items.entries()) {
|
|
1243
|
-
const prefix = `architectureDebt.items[${index}]`;
|
|
1244
|
-
if (!(PROJECTION_ARCHITECTURE_DEBT_REASON_CODES as readonly string[]).includes(item.reasonCode)) issues.push(`${prefix}.reasonCode is unsupported`);
|
|
1245
|
-
if (item.fromCapabilityId.trim() === "" || item.toCapabilityId.trim() === "") issues.push(`${prefix} must name two capabilities`);
|
|
1246
|
-
else if (item.fromCapabilityId === item.toCapabilityId) issues.push(`${prefix} must name two different capabilities`);
|
|
1247
|
-
if (!Number.isSafeInteger(item.importEdgeCount) || item.importEdgeCount < 1) issues.push(`${prefix}.importEdgeCount must be a positive integer`);
|
|
1248
|
-
}
|
|
1249
|
-
return issues;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
export function projectionPriorCommittedAppliesIssues(
|
|
1253
|
-
input: readonly ProjectionPriorCommittedApplyV1[],
|
|
1254
|
-
requestId: string
|
|
1255
|
-
): string[] {
|
|
1256
|
-
const issues = sortedUniqueIssues("priorCommittedApplies.changeSetId", input.map((entry) => entry.changeSetId));
|
|
1257
|
-
if (input.length === 0) issues.push("priorCommittedApplies must be omitted instead of empty");
|
|
1258
|
-
for (const [index, entry] of input.entries()) {
|
|
1259
|
-
const prefix = `priorCommittedApplies[${index}]`;
|
|
1260
|
-
issues.push(...sortedUniqueIssues(`${prefix}.files.path`, entry.files.map((file) => file.path)));
|
|
1261
|
-
if (entry.requestId !== requestId) issues.push(`${prefix}.requestId must match the projection result requestId`);
|
|
1262
|
-
if (entry.changeSetId.trim() === "") issues.push(`${prefix}.changeSetId must not be empty`);
|
|
1263
|
-
if (!ISO_INSTANT.test(entry.committedAt)) issues.push(`${prefix}.committedAt must be an ISO-8601 UTC instant`);
|
|
1264
|
-
if (entry.files.length === 0) issues.push(`${prefix}.files must name at least one committed file`);
|
|
1265
|
-
if ((entry.applyId === undefined) !== (entry.lookupKey === undefined)) {
|
|
1266
|
-
issues.push(`${prefix}.applyId and lookupKey must be present together or both absent`);
|
|
1267
|
-
}
|
|
1268
|
-
for (const field of ["applyId", "lookupKey"] as const) {
|
|
1269
|
-
const value = entry[field];
|
|
1270
|
-
if (value !== undefined && !SHA256_DIGEST.test(value)) issues.push(`${prefix}.${field} must be a SHA-256 digest`);
|
|
1271
|
-
}
|
|
1272
|
-
for (const [fileIndex, file] of entry.files.entries()) {
|
|
1273
|
-
const filePrefix = `${prefix}.files[${fileIndex}]`;
|
|
1274
|
-
if (!isRepoRelativePosixPath(file.path)) issues.push(`${filePrefix}.path must be a repository-relative POSIX path`);
|
|
1275
|
-
if (!(PROJECTION_PRIOR_COMMITTED_APPLY_OPERATIONS as readonly string[]).includes(file.operation)) {
|
|
1276
|
-
issues.push(`${filePrefix}.operation must be a supported committed operation`);
|
|
1277
|
-
}
|
|
1278
|
-
const expectsMissing = file.operation === "delete";
|
|
1279
|
-
if (expectsMissing && file.hash !== "missing") issues.push(`${filePrefix}.hash must be "missing" for a delete`);
|
|
1280
|
-
if (!expectsMissing && !SHA256_DIGEST.test(file.hash)) issues.push(`${filePrefix}.hash must be a SHA-256 body digest`);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
return issues;
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
/**
|
|
1287
|
-
* Computes the accepted projection receipt. Signal back-references are omitted from the
|
|
1288
|
-
* receipt payload to avoid a circular hash; every signal must then bind that receipt via
|
|
1289
|
-
* projectionReceiptDigest, which projectionResultInvariantIssues verifies.
|
|
1290
|
-
*/
|
|
1291
|
-
export function projectionResultReceiptDigest(input: Omit<ProjectionResultV3, "receiptDigest">): Sha256Digest {
|
|
1292
|
-
const { replayed: _replayed, written: _written, ...payload } = input;
|
|
1293
|
-
const refreshSignals = payload.refreshSignals.map(({ projectionReceiptDigest: _projectionReceiptDigest, ...signal }) => signal);
|
|
1294
|
-
return digestJson({ ...payload, refreshSignals } as unknown as Json) as Sha256Digest;
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
export function projectionApplyLookupKey(input: {
|
|
1298
|
-
repositoryId: string;
|
|
1299
|
-
workspaceId: string;
|
|
1300
|
-
acceptedChange: AcceptedArchitectureChangeReferenceV1;
|
|
1301
|
-
}): Sha256Digest {
|
|
1302
|
-
return digestJson({
|
|
1303
|
-
schemaVersion: "archcontext.projection-apply-lookup/v1",
|
|
1304
|
-
repositoryId: input.repositoryId,
|
|
1305
|
-
workspaceId: input.workspaceId,
|
|
1306
|
-
acceptedChange: input.acceptedChange
|
|
1307
|
-
} as unknown as Json) as Sha256Digest;
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
export function createProjectionApplyIdentity(input: {
|
|
1311
|
-
repositoryId: string;
|
|
1312
|
-
workspaceId: string;
|
|
1313
|
-
acceptedChange: AcceptedArchitectureChangeReferenceV1;
|
|
1314
|
-
changeSetId: string;
|
|
1315
|
-
idempotencyKey: string;
|
|
1316
|
-
files: ProjectionFileResultV1[];
|
|
1317
|
-
refreshSignals: ArchitectureRefreshSignalV2[];
|
|
1318
|
-
}): ProjectionApplyIdentityV1 {
|
|
1319
|
-
const lookupKey = projectionApplyLookupKey(input);
|
|
1320
|
-
const ownedFilesDigest = digestJson(input.files as unknown as Json) as Sha256Digest;
|
|
1321
|
-
const refreshSignals = input.refreshSignals.map(({ projectionReceiptDigest: _receipt, ...signal }) => signal);
|
|
1322
|
-
const refreshSignalsDigest = digestJson(refreshSignals as unknown as Json) as Sha256Digest;
|
|
1323
|
-
const withoutApplyId = {
|
|
1324
|
-
schemaVersion: PROJECTION_APPLY_IDENTITY_SCHEMA_VERSION,
|
|
1325
|
-
lookupKey,
|
|
1326
|
-
repositoryId: input.repositoryId,
|
|
1327
|
-
workspaceId: input.workspaceId,
|
|
1328
|
-
acceptedChange: input.acceptedChange,
|
|
1329
|
-
semanticCommit: { changeSetId: input.changeSetId, idempotencyKey: input.idempotencyKey },
|
|
1330
|
-
ownedFilesDigest,
|
|
1331
|
-
refreshSignalsDigest
|
|
1332
|
-
};
|
|
1333
|
-
return {
|
|
1334
|
-
...withoutApplyId,
|
|
1335
|
-
applyId: digestJson(withoutApplyId as unknown as Json) as Sha256Digest
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
export function projectionApplyReceiptInvariantIssues(input: ProjectionApplyReceiptV1): string[] {
|
|
1340
|
-
const identity = createProjectionApplyIdentity({
|
|
1341
|
-
repositoryId: input.identity.repositoryId,
|
|
1342
|
-
workspaceId: input.identity.workspaceId,
|
|
1343
|
-
acceptedChange: input.identity.acceptedChange,
|
|
1344
|
-
changeSetId: input.identity.semanticCommit.changeSetId,
|
|
1345
|
-
idempotencyKey: input.identity.semanticCommit.idempotencyKey,
|
|
1346
|
-
files: input.result.files,
|
|
1347
|
-
refreshSignals: input.result.refreshSignals
|
|
1348
|
-
});
|
|
1349
|
-
const issues = projectionResultInvariantIssues(input.result);
|
|
1350
|
-
if (digestJson(identity as unknown as Json) !== digestJson(input.identity as unknown as Json)) {
|
|
1351
|
-
issues.push("projection apply identity must bind the committed files and original refresh signals");
|
|
1352
|
-
}
|
|
1353
|
-
if (input.result.status !== "applied") issues.push("projection apply receipt result status must be applied");
|
|
1354
|
-
// A partial projection is never accepted, so no receipt ever records one.
|
|
1355
|
-
if (input.result.coverage !== undefined) issues.push("projection apply receipt result must cover every target");
|
|
1356
|
-
if (digestJson(input.result.applyReceipt as unknown as Json) !== digestJson(input.identity as unknown as Json)) {
|
|
1357
|
-
issues.push("projection apply receipt result must carry the same apply identity");
|
|
1358
|
-
}
|
|
1359
|
-
if (input.recovery) issues.push(...projectionApplyRecoveryBindingInvariantIssues(input.recovery, input));
|
|
1360
|
-
return issues;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
export function projectionApplyRecoveryBindingInvariantIssues(
|
|
1364
|
-
binding: ProjectionApplyRecoveryBindingV2,
|
|
1365
|
-
receipt?: ProjectionApplyReceiptV1
|
|
1366
|
-
): string[] {
|
|
1367
|
-
const issues = [
|
|
1368
|
-
...sortedUniqueIssues("recovery.targets", binding.targets),
|
|
1369
|
-
...sortedUniqueIssues("recovery.changedPaths", binding.changedPaths)
|
|
1370
|
-
];
|
|
1371
|
-
if (binding.schemaVersion !== PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION) {
|
|
1372
|
-
issues.push("recovery schemaVersion is invalid");
|
|
1373
|
-
}
|
|
1374
|
-
if (binding.targets.length === 0) issues.push("recovery targets must contain at least one projection target");
|
|
1375
|
-
if (binding.requestDigest !== undefined && !SHA256_DIGEST.test(binding.requestDigest)) issues.push("recovery requestDigest must be a SHA-256 digest");
|
|
1376
|
-
if (receipt) {
|
|
1377
|
-
if (binding.receiptDigest !== receipt.result.receiptDigest) {
|
|
1378
|
-
issues.push("recovery receiptDigest must match the committed result receiptDigest");
|
|
1379
|
-
}
|
|
1380
|
-
if (binding.originalExpectedSnapshot.repositoryId !== receipt.result.inputSnapshot.repositoryId
|
|
1381
|
-
|| binding.originalExpectedSnapshot.workspaceId !== receipt.result.inputSnapshot.workspaceId
|
|
1382
|
-
|| binding.originalExpectedSnapshot.headSha !== receipt.result.inputSnapshot.headSha
|
|
1383
|
-
|| binding.originalExpectedSnapshot.worktreeDigest !== receipt.result.inputSnapshot.worktreeDigest) {
|
|
1384
|
-
issues.push("recovery originalExpectedSnapshot must match the committed input snapshot");
|
|
1385
|
-
}
|
|
1386
|
-
if (binding.rendererVersion !== receipt.result.outputSnapshot.rendererVersion
|
|
1387
|
-
|| binding.layoutVersion !== receipt.result.outputSnapshot.layoutVersion
|
|
1388
|
-
|| digestJson(binding.generatedFrom as unknown as Json) !== digestJson(receipt.result.outputSnapshot.generatedFrom as unknown as Json)) {
|
|
1389
|
-
issues.push("recovery renderer, layout, and CodeGraph provenance must match the committed output snapshot");
|
|
1390
|
-
}
|
|
1391
|
-
const expectedDigests = projectionApplyReceiptResultingDigests(receipt);
|
|
1392
|
-
if (!expectedDigests || digestJson(binding.expectedResultingDigests as unknown as Json) !== digestJson(expectedDigests as unknown as Json)) {
|
|
1393
|
-
issues.push("recovery expectedResultingDigests must match committed refresh signals");
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
return issues;
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
/** Readback carries the original accepted apply request, never caller-authored receipt data. */
|
|
1400
|
-
export function projectionApplyReadbackRequestInvariantIssues(request: ProjectionRequestV1): string[] {
|
|
1401
|
-
const issues = projectionRequestInvariantIssues(request);
|
|
1402
|
-
const allowed = new Set(["schemaVersion", "requestId", "profile", "mode", "targets", "changedPaths", "expected", "acceptedChange"]);
|
|
1403
|
-
if (Object.keys(request).some((key) => !allowed.has(key))) issues.push("readback request contains unsupported fields");
|
|
1404
|
-
if (request.mode !== "apply" || !request.acceptedChange) issues.push("readback requires an accepted apply request");
|
|
1405
|
-
if (request.schemaVersion !== PROJECTION_REQUEST_SCHEMA_VERSION || request.profile !== "repo-harness/v1") issues.push("readback request protocol is invalid");
|
|
1406
|
-
if (typeof request.requestId !== "string"
|
|
1407
|
-
|| request.targets.some((target) => !(PROJECTION_TARGETS as readonly string[]).includes(target))
|
|
1408
|
-
|| request.changedPaths.some((path) => typeof path !== "string" || !isRepoRelativePosixPath(path))) issues.push("readback request fields are invalid");
|
|
1409
|
-
const expectedKeys = ["repositoryId", "workspaceId", "headSha", "worktreeDigest"];
|
|
1410
|
-
if (Object.keys(request.expected).some((key) => !expectedKeys.includes(key))
|
|
1411
|
-
|| expectedKeys.some((key) => typeof request.expected[key as keyof ProjectionExpectedSnapshotV1] !== "string")
|
|
1412
|
-
|| !request.expected.repositoryId || !request.expected.workspaceId
|
|
1413
|
-
|| !/^[a-f0-9]{40}$/.test(request.expected.headSha)
|
|
1414
|
-
|| !SHA256_DIGEST.test(request.expected.worktreeDigest)) issues.push("readback expected snapshot is invalid");
|
|
1415
|
-
if (request.acceptedChange && Object.keys(request.acceptedChange).some((key) => !["changeSetId", "eventId", "reasonCodes", "affectedNodeIds"].includes(key))) {
|
|
1416
|
-
issues.push("readback accepted change contains unsupported fields");
|
|
1417
|
-
}
|
|
1418
|
-
return issues;
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
/**
|
|
1422
|
-
* The readback request for a committed apply receipt, built only from what the receipt recorded:
|
|
1423
|
-
* its requestId, the recovery binding's targets, changedPaths and original expected snapshot, and
|
|
1424
|
-
* the identity's accepted change. Readback always takes `mode: "apply"`, also for an adopt receipt,
|
|
1425
|
-
* because the binding never records the mode. A caller that held only `acceptObservedMajorChange`
|
|
1426
|
-
* never had the accepted change, so `AC_PROJECTION_APPLY_COMMITTED` hands it this request (#278).
|
|
1427
|
-
* Undefined for a receipt without a recovery binding, which readback cannot prove.
|
|
1428
|
-
*/
|
|
1429
|
-
export function projectionApplyReadbackRequestFromReceipt(receipt: ProjectionApplyReceiptV1): ProjectionRequestV1 | undefined {
|
|
1430
|
-
const binding = receipt.recovery;
|
|
1431
|
-
if (!binding) return undefined;
|
|
1432
|
-
return {
|
|
1433
|
-
schemaVersion: PROJECTION_REQUEST_SCHEMA_VERSION,
|
|
1434
|
-
requestId: receipt.result.requestId,
|
|
1435
|
-
profile: "repo-harness/v1",
|
|
1436
|
-
mode: "apply",
|
|
1437
|
-
targets: [...binding.targets],
|
|
1438
|
-
changedPaths: [...binding.changedPaths],
|
|
1439
|
-
expected: { ...binding.originalExpectedSnapshot },
|
|
1440
|
-
acceptedChange: {
|
|
1441
|
-
...receipt.identity.acceptedChange,
|
|
1442
|
-
reasonCodes: [...receipt.identity.acceptedChange.reasonCodes],
|
|
1443
|
-
affectedNodeIds: [...receipt.identity.acceptedChange.affectedNodeIds]
|
|
1444
|
-
}
|
|
1445
|
-
};
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
export function projectionApplyAbsenceInvariantIssues(input: ProjectionApplyAbsenceV1, request: ProjectionRequestV1): string[] {
|
|
1449
|
-
const issues = projectionApplyReadbackRequestInvariantIssues(request);
|
|
1450
|
-
if (input.schemaVersion !== "archcontext.projection-apply-absence/v1") issues.push("absence schemaVersion is invalid");
|
|
1451
|
-
if (Object.keys(input).some((key) => !["schemaVersion", "requestId", "requestDigest", "lookupKey", "current", "absenceDigest"].includes(key))) issues.push("absence contains unsupported fields");
|
|
1452
|
-
const { absenceDigest, ...body } = input;
|
|
1453
|
-
if (absenceDigest !== digestJson(body as unknown as Json)) issues.push("absenceDigest must bind the complete absence result");
|
|
1454
|
-
if (input.requestId !== request.requestId || input.requestDigest !== digestJson(request as unknown as Json)) issues.push("absence request identity mismatch");
|
|
1455
|
-
if (digestJson(input.current as unknown as Json) !== digestJson(request.expected as unknown as Json)) issues.push("absence current snapshot differs from request");
|
|
1456
|
-
if (!request.acceptedChange || input.lookupKey !== projectionApplyLookupKey({
|
|
1457
|
-
repositoryId: request.expected.repositoryId, workspaceId: request.expected.workspaceId, acceptedChange: request.acceptedChange
|
|
1458
|
-
})) issues.push("absence lookup identity mismatch");
|
|
1459
|
-
return issues;
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
export function projectionApplyReadbackResultDigest(input: Omit<ProjectionApplyReadbackResultV2, "readbackDigest">): Sha256Digest {
|
|
1463
|
-
return digestJson(input as unknown as Json) as Sha256Digest;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
export function projectionApplyReadbackResultInvariantIssues(
|
|
1467
|
-
input: ProjectionApplyReadbackResultV2,
|
|
1468
|
-
request?: ProjectionRequestV1
|
|
1469
|
-
): string[] {
|
|
1470
|
-
const issues = projectionApplyReceiptInvariantIssues(input.receipt);
|
|
1471
|
-
const { readbackDigest, ...body } = input;
|
|
1472
|
-
if (input.schemaVersion !== PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION) issues.push("readback schemaVersion is invalid");
|
|
1473
|
-
if (projectionApplyReadbackResultDigest(body) !== readbackDigest) issues.push("readbackDigest must bind the complete readback result");
|
|
1474
|
-
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("readback requestId is invalid");
|
|
1475
|
-
for (const value of [input.requestDigest, input.current.ownedOutputDigest, input.current.fixedPointDigest]) {
|
|
1476
|
-
if (!/^sha256:[a-f0-9]{64}$/.test(value)) issues.push("readback digest is invalid");
|
|
1477
|
-
}
|
|
1478
|
-
const receipt = input.receipt;
|
|
1479
|
-
if (receipt.schemaVersion !== PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION) issues.push("readback receipt schemaVersion is invalid");
|
|
1480
|
-
const binding = receipt.recovery;
|
|
1481
|
-
if (!binding) return [...issues, "committed receipt lacks its original recovery binding"];
|
|
1482
|
-
for (const field of ["repositoryId", "workspaceId", "headSha", "worktreeDigest"] as const) {
|
|
1483
|
-
if (input.current.snapshot[field] !== binding.originalExpectedSnapshot[field]) issues.push(`readback current ${field} differs from approval`);
|
|
1484
|
-
}
|
|
1485
|
-
if (input.current.snapshot.generatedFrom.codeGraphStatus !== "ready"
|
|
1486
|
-
|| input.current.snapshot.rendererVersion !== binding.rendererVersion
|
|
1487
|
-
|| input.current.snapshot.layoutVersion !== binding.layoutVersion
|
|
1488
|
-
|| input.current.snapshot.projectionInputDigest !== receipt.result.outputSnapshot.projectionInputDigest
|
|
1489
|
-
|| input.current.snapshot.codeGraphDigest !== receipt.result.outputSnapshot.codeGraphDigest
|
|
1490
|
-
|| digestJson(input.current.snapshot.generatedFrom as unknown as Json) !== digestJson(binding.generatedFrom as unknown as Json)
|
|
1491
|
-
|| digestJson(input.current.resultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)
|
|
1492
|
-
|| input.current.ownedOutputDigest !== binding.ownedOutputDigest) {
|
|
1493
|
-
issues.push("readback current state differs from committed recovery binding");
|
|
1494
|
-
}
|
|
1495
|
-
if (input.requestId !== receipt.result.requestId) issues.push("readback requestId differs from committed request");
|
|
1496
|
-
if (request) {
|
|
1497
|
-
issues.push(...projectionApplyReadbackRequestInvariantIssues(request));
|
|
1498
|
-
if (input.requestDigest !== digestJson(request as unknown as Json) || input.requestId !== request.requestId) issues.push("readback request identity mismatch");
|
|
1499
|
-
if (digestJson(request.expected as unknown as Json) !== digestJson(binding.originalExpectedSnapshot as unknown as Json)
|
|
1500
|
-
|| digestJson(request.acceptedChange as unknown as Json) !== digestJson(receipt.identity.acceptedChange as unknown as Json)
|
|
1501
|
-
|| digestJson(request.targets as unknown as Json) !== digestJson(binding.targets as unknown as Json)
|
|
1502
|
-
|| digestJson(request.changedPaths as unknown as Json) !== digestJson(binding.changedPaths as unknown as Json)) {
|
|
1503
|
-
issues.push("readback request differs from committed approval binding");
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
return issues;
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
export function projectionApplyRecoveryIntentInvariantIssues(input: ProjectionApplyRecoveryIntentV1): string[] {
|
|
1510
|
-
const issues: string[] = [];
|
|
1511
|
-
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_INTENT_SCHEMA_VERSION) issues.push("recovery intent schemaVersion is invalid");
|
|
1512
|
-
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("recovery intent requestId must use the stable identifier character set");
|
|
1513
|
-
if (input.profile !== "repo-harness/v1") issues.push("recovery intent profile is invalid");
|
|
1514
|
-
for (const field of ["lookupKey", "applyId"] as const) {
|
|
1515
|
-
if (!/^sha256:[a-f0-9]{64}$/.test(input.receipt[field])) issues.push(`recovery intent receipt.${field} must be a SHA-256 digest`);
|
|
1516
|
-
}
|
|
1517
|
-
return issues;
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
export function projectionApplyRecoveryProofDigest(input: Omit<ProjectionApplyRecoveryProofV2, "proofDigest" | "deliveryStatus">): Sha256Digest {
|
|
1521
|
-
return digestJson(input as unknown as Json) as Sha256Digest;
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
export function projectionApplyRecoveryProofInvariantIssues(input: ProjectionApplyRecoveryProofV2): string[] {
|
|
1525
|
-
const issues = [
|
|
1526
|
-
...sortedUniqueIssues("acceptedChange.reasonCodes", input.acceptedChange.reasonCodes),
|
|
1527
|
-
...sortedUniqueIssues("acceptedChange.affectedNodeIds", input.acceptedChange.affectedNodeIds)
|
|
1528
|
-
];
|
|
1529
|
-
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION) issues.push("recovery proof schemaVersion is invalid");
|
|
1530
|
-
if (!/^[a-zA-Z0-9_.:-]+$/.test(input.requestId)) issues.push("recovery proof requestId must use the stable identifier character set");
|
|
1531
|
-
if (input.current.snapshot.generatedFrom.codeGraphStatus !== "ready") issues.push("recovery proof requires a ready current CodeGraph snapshot");
|
|
1532
|
-
const { proofDigest: _proofDigest, deliveryStatus: _deliveryStatus, ...payload } = input;
|
|
1533
|
-
if (projectionApplyRecoveryProofDigest(payload) !== input.proofDigest) {
|
|
1534
|
-
issues.push("recovery proofDigest must bind the semantic proof payload");
|
|
1535
|
-
}
|
|
1536
|
-
return issues;
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
export function projectionApplyRecoveryResultInvariantIssues(input: ProjectionApplyRecoveryResultV2): string[] {
|
|
1540
|
-
const issues = [
|
|
1541
|
-
...projectionApplyRecoveryProofInvariantIssues(input.proof),
|
|
1542
|
-
...input.refreshSignals.flatMap((signal, index) => architectureRefreshSignalInvariantIssues(signal, `refreshSignals[${index}]`)),
|
|
1543
|
-
...sortedUniqueIssues("refreshSignals.signalId", input.refreshSignals.map((signal) => signal.signalId))
|
|
1544
|
-
];
|
|
1545
|
-
if (input.schemaVersion !== PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION) {
|
|
1546
|
-
issues.push("recovery result schemaVersion is invalid");
|
|
1547
|
-
}
|
|
1548
|
-
if (input.proof.deliveryStatus === "already-delivered" && input.refreshSignals.length > 0) {
|
|
1549
|
-
issues.push("already-delivered recovery result cannot repeat refreshSignals");
|
|
1550
|
-
}
|
|
1551
|
-
for (const [index, signal] of input.refreshSignals.entries()) {
|
|
1552
|
-
const prefix = `refreshSignals[${index}]`;
|
|
1553
|
-
if (signal.projectionReceiptDigest !== input.proof.receipt.receiptDigest) {
|
|
1554
|
-
issues.push(`${prefix}.projectionReceiptDigest must match recovery proof receiptDigest`);
|
|
1555
|
-
}
|
|
1556
|
-
if (digestJson(signal.acceptedChange as unknown as Json) !== digestJson(input.proof.acceptedChange as unknown as Json)) {
|
|
1557
|
-
issues.push(`${prefix}.acceptedChange must match recovery proof approval`);
|
|
1558
|
-
}
|
|
1559
|
-
if (digestJson(signal.resultingDigests as unknown as Json) !== digestJson(input.proof.expectedResultingDigests as unknown as Json)) {
|
|
1560
|
-
issues.push(`${prefix}.resultingDigests must match recovery proof`);
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
return issues;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
/** The durable store uses this before delivery; it can validate immutable bindings but not re-render the current projection. */
|
|
1567
|
-
export function projectionApplyRecoveryProofReceiptInvariantIssues(
|
|
1568
|
-
proof: ProjectionApplyRecoveryProofV2,
|
|
1569
|
-
receipt: ProjectionApplyReceiptV1
|
|
1570
|
-
): string[] {
|
|
1571
|
-
const issues = [
|
|
1572
|
-
...projectionApplyRecoveryProofInvariantIssues(proof),
|
|
1573
|
-
...projectionApplyReceiptInvariantIssues(receipt)
|
|
1574
|
-
];
|
|
1575
|
-
const binding = receipt.recovery;
|
|
1576
|
-
if (!binding) return [...issues, "committed projection receipt does not support semantic recovery"];
|
|
1577
|
-
if (proof.receipt.lookupKey !== receipt.identity.lookupKey
|
|
1578
|
-
|| proof.receipt.applyId !== receipt.identity.applyId
|
|
1579
|
-
|| proof.receipt.receiptDigest !== receipt.result.receiptDigest) {
|
|
1580
|
-
issues.push("recovery proof receipt identity must match the committed receipt");
|
|
1581
|
-
}
|
|
1582
|
-
if (digestJson(proof.acceptedChange as unknown as Json) !== digestJson(receipt.identity.acceptedChange as unknown as Json)
|
|
1583
|
-
|| digestJson(proof.expectedResultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)) {
|
|
1584
|
-
issues.push("recovery proof approval binding must match the committed receipt");
|
|
1585
|
-
}
|
|
1586
|
-
if (digestJson(proof.current.resultingDigests as unknown as Json) !== digestJson(binding.expectedResultingDigests as unknown as Json)
|
|
1587
|
-
|| proof.current.ownedOutputDigest !== binding.ownedOutputDigest
|
|
1588
|
-
|| proof.current.snapshot.rendererVersion !== binding.rendererVersion
|
|
1589
|
-
|| proof.current.snapshot.layoutVersion !== binding.layoutVersion
|
|
1590
|
-
|| digestJson(proof.current.snapshot.generatedFrom as unknown as Json) !== digestJson(binding.generatedFrom as unknown as Json)) {
|
|
1591
|
-
issues.push("recovery proof current state must match the committed recovery binding");
|
|
1592
|
-
}
|
|
1593
|
-
return issues;
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
function projectionApplyReceiptResultingDigests(receipt: ProjectionApplyReceiptV1): ArchitectureDigestSetV2 | undefined {
|
|
1597
|
-
const signals = receipt.result.refreshSignals;
|
|
1598
|
-
if (signals.length === 0) return undefined;
|
|
1599
|
-
const [first] = signals;
|
|
1600
|
-
return signals.every((signal) => digestJson(signal.resultingDigests as unknown as Json) === digestJson(first.resultingDigests as unknown as Json))
|
|
1601
|
-
? first.resultingDigests
|
|
1602
|
-
: undefined;
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
export function architectureRefreshSignalInvariantIssues(input: ArchitectureRefreshSignalV2, prefix = "signal"): string[] {
|
|
1606
|
-
const issues = [
|
|
1607
|
-
...sortedUniqueIssues(`${prefix}.reasonCodes`, input.reasonCodes),
|
|
1608
|
-
...sortedUniqueIssues(`${prefix}.affectedNodeIds`, input.affectedNodeIds),
|
|
1609
|
-
...sortedUniqueIssues(`${prefix}.refreshTargets`, input.refreshTargets)
|
|
1610
|
-
];
|
|
1611
|
-
if (input.acceptedChange) {
|
|
1612
|
-
issues.push(
|
|
1613
|
-
...sortedUniqueIssues(`${prefix}.acceptedChange.reasonCodes`, input.acceptedChange.reasonCodes),
|
|
1614
|
-
...sortedUniqueIssues(`${prefix}.acceptedChange.affectedNodeIds`, input.acceptedChange.affectedNodeIds)
|
|
1615
|
-
);
|
|
1616
|
-
if (input.acceptedChange.changeSetId.trim() === "") issues.push(`${prefix}.acceptedChange.changeSetId must not be empty`);
|
|
1617
|
-
if (input.acceptedChange.eventId.trim() === "") issues.push(`${prefix}.acceptedChange.eventId must not be empty`);
|
|
1618
|
-
if (input.acceptedChange.reasonCodes.join("\u0000") !== input.reasonCodes.join("\u0000")) {
|
|
1619
|
-
issues.push(`${prefix}.acceptedChange.reasonCodes must match signal reasonCodes`);
|
|
1620
|
-
}
|
|
1621
|
-
if (input.acceptedChange.affectedNodeIds.join("\u0000") !== input.affectedNodeIds.join("\u0000")) {
|
|
1622
|
-
issues.push(`${prefix}.acceptedChange.affectedNodeIds must match signal affectedNodeIds`);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
if (input.capabilities !== undefined) issues.push(...architectureCapabilityChangesIssues(input.capabilities, `${prefix}.capabilities`));
|
|
1626
|
-
if (input.reasonCodes.length === 0) issues.push(`${prefix}.reasonCodes must contain at least one reason`);
|
|
1627
|
-
if (input.affectedNodeIds.length === 0) issues.push(`${prefix}.affectedNodeIds must contain at least one node`);
|
|
1628
|
-
if (input.refreshTargets.length === 0) issues.push(`${prefix}.refreshTargets must contain at least one target`);
|
|
1629
|
-
if (input.cause === "unresolved-major-candidate" && input.mode !== "human-action-required") {
|
|
1630
|
-
issues.push(`${prefix}.unresolved-major-candidate requires human-action-required mode`);
|
|
1631
|
-
}
|
|
1632
|
-
if (input.cause !== "unresolved-major-candidate" && input.mode !== "refresh-required") {
|
|
1633
|
-
issues.push(`${prefix}.${input.cause} requires refresh-required mode`);
|
|
1634
|
-
}
|
|
1635
|
-
if (input.mode === "refresh-required" && !input.acceptedChange) {
|
|
1636
|
-
issues.push(`${prefix}.refresh-required requires acceptedChange`);
|
|
1637
|
-
}
|
|
1638
|
-
if (input.mode === "human-action-required" && input.acceptedChange) {
|
|
1639
|
-
issues.push(`${prefix}.human-action-required forbids acceptedChange`);
|
|
1640
|
-
}
|
|
1641
|
-
return issues;
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
/** Shape and canonical order of a per-capability major-change breakdown (#264). */
|
|
1645
|
-
export function architectureCapabilityChangesIssues(input: readonly ArchitectureCapabilityChangeV1[], prefix = "capabilities"): string[] {
|
|
1646
|
-
const issues = sortedUniqueIssues(`${prefix}.capabilityId`, input.map((entry) => entry.capabilityId));
|
|
1647
|
-
if (input.length === 0) issues.push(`${prefix} must name at least one capability`);
|
|
1648
|
-
const reasons = new Set<string>(ARCHITECTURE_MAJOR_CHANGE_REASON_CODES);
|
|
1649
|
-
const facets = new Set<string>(ARCHITECTURE_SEMANTIC_FACETS);
|
|
1650
|
-
for (const [index, entry] of input.entries()) {
|
|
1651
|
-
const entryPrefix = `${prefix}[${index}]`;
|
|
1652
|
-
if (typeof entry.capabilityId !== "string" || entry.capabilityId.trim() === "") issues.push(`${entryPrefix}.capabilityId must not be empty`);
|
|
1653
|
-
issues.push(
|
|
1654
|
-
...sortedUniqueIssues(`${entryPrefix}.reasonCodes`, entry.reasonCodes),
|
|
1655
|
-
...sortedUniqueIssues(`${entryPrefix}.changedFacets`, entry.changedFacets)
|
|
1656
|
-
);
|
|
1657
|
-
const reason = entry.reasonCodes.find((code) => !reasons.has(code));
|
|
1658
|
-
if (reason !== undefined) issues.push(`${entryPrefix}.reasonCodes contains unsupported reason: ${reason}`);
|
|
1659
|
-
const facet = entry.changedFacets.find((name) => !facets.has(name));
|
|
1660
|
-
if (facet !== undefined) issues.push(`${entryPrefix}.changedFacets contains unsupported facet: ${facet}`);
|
|
1661
|
-
for (const field of ["proofStatusBefore", "proofStatusAfter"] as const) {
|
|
1662
|
-
const status = entry[field];
|
|
1663
|
-
if (status !== null && !isArchitectureCapabilityProofStatus(status)) issues.push(`${entryPrefix}.${field} must be null or a P1/P2 proof status`);
|
|
1664
|
-
}
|
|
1665
|
-
if (entry.proofStatusBefore === null && entry.proofStatusAfter === null) issues.push(`${entryPrefix} must exist before or after the change`);
|
|
1666
|
-
if ((entry.proofStatusBefore === null || entry.proofStatusAfter === null) && entry.changedFacets.length > 0) {
|
|
1667
|
-
issues.push(`${entryPrefix}.changedFacets must be empty for a capability present on one side only`);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
return issues;
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
export function isArchitectureCapabilityProofStatus(value: unknown): value is ArchitectureCapabilityProofStatusV1 {
|
|
1674
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1675
|
-
const record = value as Record<string, unknown>;
|
|
1676
|
-
return Object.keys(record).length === 2
|
|
1677
|
-
&& (ARCHITECTURE_PROOF_P1_STATUSES as readonly unknown[]).includes(record.p1)
|
|
1678
|
-
&& (ARCHITECTURE_PROOF_P2_STATUSES as readonly unknown[]).includes(record.p2);
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
const SHA256_DIGEST = /^sha256:[a-f0-9]{64}$/;
|
|
1682
|
-
const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
|
|
1683
|
-
|
|
1684
|
-
function sortedUniqueIssues(label: string, values: readonly string[]): string[] {
|
|
1685
|
-
const expected = [...new Set(values)].sort();
|
|
1686
|
-
return expected.length === values.length && expected.every((value, index) => value === values[index])
|
|
1687
|
-
? []
|
|
1688
|
-
: [`${label} must be sorted and unique`];
|
|
1689
|
-
}
|
|
1
|
+
export * from "./projection-constants";
|
|
2
|
+
export * from "./projection-types";
|
|
3
|
+
export * from "./projection-apply-types";
|
|
4
|
+
export * from "./projection-capabilities";
|
|
5
|
+
export * from "./projection-request-validators";
|
|
6
|
+
export * from "./projection-apply-validators";
|
|
7
|
+
export * from "./projection-recovery-validators";
|