archctx-contracts 0.13.0 → 0.14.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/src/projection.ts CHANGED
@@ -2,15 +2,15 @@ import type { EvidenceCoverageLevelV2 } from "./ledger";
2
2
  import { digestJson, isRepoRelativePosixPath, type Json } from "./schema";
3
3
 
4
4
  export const PROJECTION_REQUEST_SCHEMA_VERSION = "archcontext.projection-request/v1" as const;
5
- export const PROJECTION_RESULT_SCHEMA_VERSION = "archcontext.projection-result/v2" as const;
5
+ export const PROJECTION_RESULT_SCHEMA_VERSION = "archcontext.projection-result/v3" as const;
6
6
  export const PROJECTION_APPLY_IDENTITY_SCHEMA_VERSION = "archcontext.projection-apply-identity/v1" as const;
7
7
  export const PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION = "archcontext.projection-apply-receipt/v1" as const;
8
- export const PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION = "archcontext.projection-apply-recovery-binding/v1" as const;
8
+ export const PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION = "archcontext.projection-apply-recovery-binding/v2" as const;
9
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/v1" as const;
11
- export const PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION = "archcontext.projection-apply-recovery-result/v1" as const;
12
- export const PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION = "archcontext.projection-apply-readback-result/v1" as const;
13
- export const ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION = "archcontext.architecture-refresh-signal/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
14
  export const ARCHCTX_CAPABILITIES_SCHEMA_VERSION = "archcontext.capabilities/v1" as const;
15
15
  export const ARCHITECTURE_DOCS_RENDERER_VERSION = "archcontext.docs-renderer/v6" as const;
16
16
  /**
@@ -18,11 +18,11 @@ export const ARCHITECTURE_DOCS_RENDERER_VERSION = "archcontext.docs-renderer/v6"
18
18
  * the path lives here because a projection result's `files[]` names the manifest write.
19
19
  */
20
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/v1" as const;
21
+ export const AGENT_CONTEXT_RENDERER_VERSION = "archcontext.agent-context-renderer/v2" as const;
22
22
 
23
23
  export const PROJECTION_MODES = ["check", "plan", "apply", "adopt"] as const;
24
24
  export const PROJECTION_PRIOR_COMMITTED_APPLY_OPERATIONS = ["delete", "write"] as const;
25
- export const PROJECTION_TARGETS = ["agent-context", "architecture-docs"] as const;
25
+ export const PROJECTION_TARGETS = ["agent-context", "architecture-docs", "architecture-history"] as const;
26
26
  export const PROJECTION_RESULT_STATUSES = [
27
27
  "adoption-required",
28
28
  "applied",
@@ -99,10 +99,10 @@ export const ARCHCTX_FEATURES = [
99
99
  "projection-apply-replay-v1",
100
100
  "projection-architecture-debt-v1",
101
101
  "projection-capability-isolation-v1",
102
- "projection-change-classification-v1",
103
- "projection-check-freshness-v1",
104
- "projection-freshness-v1",
105
- "projection-manifest-contract-v3",
102
+ "projection-change-classification-v2",
103
+ "projection-check-freshness-v2",
104
+ "projection-freshness-v2",
105
+ "projection-manifest-contract-v4",
106
106
  "projection-observed-major-change-acceptance-v1",
107
107
  "projection-orphan-review-v1",
108
108
  "projection-preview-v1",
@@ -210,15 +210,17 @@ export const PROJECTION_FILE_PREVIEW_MAX_BYTES = 65_536;
210
210
  export const PROJECTION_PREVIEW_TOTAL_MAX_BYTES = 1_048_576;
211
211
 
212
212
  /**
213
- * Why a projection is not fresh. Shared by the core freshness evaluator and the `check` result's
214
- * `freshness` field so the two can never disagree.
213
+ * Why a projection is not fresh (ADR-0056 §1). Shared by the engine's freshness evaluator and the
214
+ * `check` result's `freshness` field so the two can never disagree. `projection-output-changed`:
215
+ * a target renders an output other than its committed row's (`staleTargets`).
216
+ * `projection-manifest-changed`: every output equals its row, but the manifest the render would
217
+ * write differs from the committed bytes (the semantic baseline or a header line).
215
218
  */
216
219
  export const PROJECTION_FRESHNESS_REASON_CODES = [
220
+ "projection-manifest-changed",
217
221
  "projection-manifest-missing",
218
222
  "projection-manifest-unreadable",
219
- "projection-source-changed-since-stamp",
220
- "projection-source-stamp-missing",
221
- "projection-source-tree-digest-mismatch"
223
+ "projection-output-changed"
222
224
  ] as const;
223
225
 
224
226
  /** The architecture debt a `check` or `plan` result reports. Debt is a finding, never a blocker. */
@@ -240,8 +242,8 @@ export const PROJECTION_ARCHITECTURE_DEBT_COVERAGE_REASON_CODES = [
240
242
  * down: `blocked` (a human must act before the target can be written: Phase 1 isolation, an orphan
241
243
  * that needs review, an adoption or ownership rejection), `proof-change` (a known proof change,
242
244
  * which a missing baseline never hides), `baseline-missing` (a comparison is unknown: no committed
243
- * v3 manifest, or no committed row for the target), `semantic-change`, `output-change`,
244
- * `stamp-only` (only the source stamps moved) and `unchanged`.
245
+ * current-format manifest, or no committed row for the target), `semantic-change`, `output-change`
246
+ * and `unchanged`.
245
247
  * `projectionTargetChangeClassification` is the one precedence rule.
246
248
  */
247
249
  export const PROJECTION_TARGET_CHANGE_CLASSIFICATIONS = [
@@ -250,7 +252,6 @@ export const PROJECTION_TARGET_CHANGE_CLASSIFICATIONS = [
250
252
  "output-change",
251
253
  "proof-change",
252
254
  "semantic-change",
253
- "stamp-only",
254
255
  "unchanged"
255
256
  ] as const;
256
257
  /** What the projection write does to the target's file: the result's own `files[]` decision for that path. */
@@ -264,8 +265,7 @@ export const PROJECTION_TARGET_CHANGE_BLOCKING_REASON_CODES = [
264
265
  "verified-flow-proof-changed"
265
266
  ] as const;
266
267
  /**
267
- * Why a target is classified as it is. Each comparison flag has its codes: `stampChanged` is
268
- * `source-stamp-changed`; `semanticChanged` is `semantic-fingerprint-changed` or, for a target that
268
+ * Why a target is classified as it is. Each comparison flag has its codes: `semanticChanged` is `semantic-fingerprint-changed` or, for a target that
269
269
  * describes the whole model, `model-digest-changed` (the committed `semanticBaseline.modelDigest`
270
270
  * differs from the current model's); `proofChanged` is
271
271
  * `flow-proof-changed` or `selector-evidence-changed`; `outputChanged` is `rendered-output-changed`
@@ -285,7 +285,6 @@ export const PROJECTION_TARGET_CHANGE_REASON_CODES = [
285
285
  "rendered-output-changed",
286
286
  "selector-evidence-changed",
287
287
  "semantic-fingerprint-changed",
288
- "source-stamp-changed",
289
288
  "target-added",
290
289
  "target-removed",
291
290
  "target-row-missing",
@@ -433,9 +432,12 @@ export interface ProjectionApplyIdentityV1 {
433
432
  refreshSignalsDigest: Sha256Digest;
434
433
  }
435
434
 
436
- export interface ArchitectureDigestSetV1 {
435
+ /**
436
+ * The global digests of a projection. The base digests come from the committed manifest, which
437
+ * records no source state, so the set carries no source tree digest (ADR-0056 §4).
438
+ */
439
+ export interface ArchitectureDigestSetV2 {
437
440
  modelDigest: Sha256Digest;
438
- sourceTreeDigest: Sha256Digest;
439
441
  flowProofDigest: Sha256Digest;
440
442
  projectionDigest: Sha256Digest;
441
443
  }
@@ -447,7 +449,7 @@ export interface AcceptedArchitectureChangeReferenceV1 {
447
449
  affectedNodeIds: string[];
448
450
  }
449
451
 
450
- export interface ArchitectureRefreshSignalV1 {
452
+ export interface ArchitectureRefreshSignalV2 {
451
453
  schemaVersion: typeof ARCHITECTURE_REFRESH_SIGNAL_SCHEMA_VERSION;
452
454
  signalId: Sha256Digest;
453
455
  idempotencyKey: Sha256Digest;
@@ -466,8 +468,8 @@ export interface ArchitectureRefreshSignalV1 {
466
468
  */
467
469
  capabilities?: ArchitectureCapabilityChangeV1[];
468
470
  refreshTargets: ArchitectureRefreshTarget[];
469
- baseDigests: ArchitectureDigestSetV1;
470
- resultingDigests: ArchitectureDigestSetV1;
471
+ baseDigests: ArchitectureDigestSetV2;
472
+ resultingDigests: ArchitectureDigestSetV2;
471
473
  projectionReceiptDigest: Sha256Digest;
472
474
  }
473
475
 
@@ -498,19 +500,27 @@ export interface ProjectionPriorCommittedApplyV1 {
498
500
  files: ProjectionPriorCommittedApplyFileV1[];
499
501
  }
500
502
 
501
- export interface ProjectionFreshnessStaleNodeV1 {
502
- nodeId: string;
503
- /** Source-footprint digest the node's projected document is stamped with. */
504
- stampedDigest: Sha256Digest;
505
- /** Source-footprint digest measured by this run. */
506
- currentDigest: Sha256Digest;
503
+ /** One target whose rendered output differs from its committed manifest row. */
504
+ export interface ProjectionFreshnessStaleTargetV2 {
505
+ targetId: string;
506
+ path: string;
507
+ /** The committed row's `outputDigest`; `null` for a target the committed manifest does not record. */
508
+ committedOutputDigest: Sha256Digest | null;
509
+ /** The current render's `outputDigest`; `null` for a committed row the current layout no longer renders. */
510
+ renderedOutputDigest: Sha256Digest | null;
507
511
  }
508
512
 
509
- /** Read-only per-node freshness of the committed projection, as `check` measured it. */
510
- export interface ProjectionFreshnessV1 {
513
+ /**
514
+ * Render-equivalent freshness of the committed projection (ADR-0056 §1): a target is fresh when the
515
+ * output the current render produces equals its committed row's `outputDigest`, and the projection
516
+ * is fresh when every target is, the two target sets are equal, and the manifest the render would
517
+ * write equals the committed bytes.
518
+ */
519
+ export interface ProjectionFreshnessV2 {
511
520
  ok: boolean;
512
521
  reasonCodes: ProjectionFreshnessReasonCode[];
513
- staleNodes: ProjectionFreshnessStaleNodeV1[];
522
+ /** Sorted and unique by targetId. Non-empty exactly when `projection-output-changed` is reported. */
523
+ staleTargets: ProjectionFreshnessStaleTargetV2[];
514
524
  }
515
525
 
516
526
  /**
@@ -582,11 +592,10 @@ export interface ProjectionCoverageV1 {
582
592
  * One target of a `check` or `plan` result (#327 finding 2): how it changes since the committed
583
593
  * projection, and what this run's write does to its file. The entries cover the union of the
584
594
  * current layout's targets and the committed manifest's rows (plus orphans the manifest does not
585
- * record), one per path. The projection manifest is not a target; its write is the `files[]` entry
586
- * no change names.
595
+ * record), one per target. Only agent-context targets share a path (ADR-0056 §9). The projection
596
+ * manifest is not a target; its write is the `files[]` entry no change names.
587
597
  *
588
- * Each comparison is against the committed v3 manifest: `stampChanged` the target row's
589
- * `sourceStamps`; `outputChanged` the row's `outputDigest`, or any byte the write changes;
598
+ * Each comparison is against the committed v4 manifest: `outputChanged` the row's `outputDigest`, or any byte the write changes;
590
599
  * `semanticChanged` the `semanticFingerprint` of a capability the target documents (every
591
600
  * capability for a target that is not an entity summary, which also compares the manifest's
592
601
  * `semanticBaseline.modelDigest`, because it renders the whole model); `proofChanged` the `flowProofFingerprint`
@@ -600,12 +609,11 @@ export interface ProjectionCoverageV1 {
600
609
  * path rejected for adoption or ownership repair is `blocked` and `none`, because only an
601
610
  * approved adoption writes it. `classification` never changes `status`, the write set or a gate.
602
611
  */
603
- export interface ProjectionTargetChangeV1 {
612
+ export interface ProjectionTargetChangeV2 {
604
613
  targetId: string;
605
614
  path: string;
606
615
  /** Sorted and unique: the documented capabilities whose change affects this target. Empty when unchanged. */
607
616
  affectedCapabilityIds: string[];
608
- stampChanged: boolean | null;
609
617
  outputChanged: boolean;
610
618
  semanticChanged: boolean | null;
611
619
  proofChanged: boolean | null;
@@ -615,7 +623,7 @@ export interface ProjectionTargetChangeV1 {
615
623
  reasonCodes: ProjectionTargetChangeReasonCode[];
616
624
  }
617
625
 
618
- export interface ProjectionResultV2 {
626
+ export interface ProjectionResultV3 {
619
627
  schemaVersion: typeof PROJECTION_RESULT_SCHEMA_VERSION;
620
628
  requestId: string;
621
629
  status: ProjectionResultStatus;
@@ -624,7 +632,7 @@ export interface ProjectionResultV2 {
624
632
  affectedNodeIds: string[];
625
633
  files: ProjectionFileResultV1[];
626
634
  humanActions: ProjectionHumanActionV1[];
627
- refreshSignals: ArchitectureRefreshSignalV1[];
635
+ refreshSignals: ArchitectureRefreshSignalV2[];
628
636
  applyReceipt?: ProjectionApplyIdentityV1;
629
637
  /**
630
638
  * Omitted, never `[]`, when no earlier attempt of this requestId committed. Never present on
@@ -633,10 +641,10 @@ export interface ProjectionResultV2 {
633
641
  */
634
642
  priorCommittedApplies?: ProjectionPriorCommittedApplyV1[];
635
643
  /**
636
- * Present on `check` results only: which nodes changed since their documents were verified.
637
- * Consumers gate on the `projection-check-freshness-v1` capability, not on field presence.
644
+ * Present on `check` results only: which targets render differently from the committed
645
+ * manifest. Consumers gate on the `projection-check-freshness-v2` capability, not on field presence.
638
646
  */
639
- freshness?: ProjectionFreshnessV1;
647
+ freshness?: ProjectionFreshnessV2;
640
648
  /**
641
649
  * Present on every `check` and `plan` result, and on no other: the architecture debt this run
642
650
  * found. It never changes `status`. Consumers gate on the `projection-architecture-debt-v1`
@@ -645,9 +653,9 @@ export interface ProjectionResultV2 {
645
653
  architectureDebt?: ProjectionArchitectureDebtV1;
646
654
  /**
647
655
  * Present on every `check` and `plan` result, and on no other: per-target change classification,
648
- * sorted by path (#327). It never changes `status` or `files`.
656
+ * sorted by path, then targetId (#327). It never changes `status` or `files`.
649
657
  */
650
- changes?: ProjectionTargetChangeV1[];
658
+ changes?: ProjectionTargetChangeV2[];
651
659
  /**
652
660
  * Present, as `true`, only when this response returns an apply this requestId already committed
653
661
  * for the same request digest, without applying again (#265). It is excluded from
@@ -681,22 +689,22 @@ export interface ProjectionResultV2 {
681
689
  export interface ProjectionApplyReceiptV1 {
682
690
  schemaVersion: typeof PROJECTION_APPLY_RECEIPT_SCHEMA_VERSION;
683
691
  identity: ProjectionApplyIdentityV1;
684
- result: ProjectionResultV2;
692
+ result: ProjectionResultV3;
685
693
  /**
686
694
  * Present only on receipts written after recovery protocol v1 shipped. Receipts created by
687
695
  * v0.4.7 remain inspectable, but cannot be recovered because they never recorded this exact
688
696
  * approval binding.
689
697
  */
690
- recovery?: ProjectionApplyRecoveryBindingV1;
698
+ recovery?: ProjectionApplyRecoveryBindingV2;
691
699
  }
692
700
 
693
701
  /** Immutable approval metadata recorded with a new committed apply receipt, never inferred later. */
694
- export interface ProjectionApplyRecoveryBindingV1 {
702
+ export interface ProjectionApplyRecoveryBindingV2 {
695
703
  schemaVersion: typeof PROJECTION_APPLY_RECOVERY_BINDING_SCHEMA_VERSION;
696
704
  targets: ProjectionTarget[];
697
705
  changedPaths: string[];
698
706
  originalExpectedSnapshot: ProjectionExpectedSnapshotV1;
699
- expectedResultingDigests: ArchitectureDigestSetV1;
707
+ expectedResultingDigests: ArchitectureDigestSetV2;
700
708
  rendererVersion: typeof ARCHITECTURE_DOCS_RENDERER_VERSION;
701
709
  layoutVersion: "archcontext.docs-layout/v1";
702
710
  generatedFrom: ProjectionSnapshotV1["generatedFrom"];
@@ -731,7 +739,7 @@ export type ProjectionApplyRecoveryDeliveryStatus = "delivered" | "already-deliv
731
739
  * `proofDigest` intentionally excludes deliveryStatus so an idempotent repeat can change only
732
740
  * that explicitly declared field.
733
741
  */
734
- export interface ProjectionApplyRecoveryProofV1 {
742
+ export interface ProjectionApplyRecoveryProofV2 {
735
743
  schemaVersion: typeof PROJECTION_APPLY_RECOVERY_PROOF_SCHEMA_VERSION;
736
744
  requestId: string;
737
745
  requestDigest: Sha256Digest;
@@ -743,28 +751,28 @@ export interface ProjectionApplyRecoveryProofV1 {
743
751
  receiptDigest: Sha256Digest;
744
752
  };
745
753
  acceptedChange: AcceptedArchitectureChangeReferenceV1;
746
- expectedResultingDigests: ArchitectureDigestSetV1;
754
+ expectedResultingDigests: ArchitectureDigestSetV2;
747
755
  current: {
748
756
  snapshot: ProjectionSnapshotV1;
749
- resultingDigests: ArchitectureDigestSetV1;
757
+ resultingDigests: ArchitectureDigestSetV2;
750
758
  ownedOutputDigest: Sha256Digest;
751
759
  fixedPointDigest: Sha256Digest;
752
760
  };
753
761
  }
754
762
 
755
- export interface ProjectionApplyRecoveryResultV1 {
763
+ export interface ProjectionApplyRecoveryResultV2 {
756
764
  schemaVersion: typeof PROJECTION_APPLY_RECOVERY_RESULT_SCHEMA_VERSION;
757
- proof: ProjectionApplyRecoveryProofV1;
758
- refreshSignals: ArchitectureRefreshSignalV1[];
765
+ proof: ProjectionApplyRecoveryProofV2;
766
+ refreshSignals: ArchitectureRefreshSignalV2[];
759
767
  }
760
768
 
761
769
  /** Non-consuming receipt retrieval; current state is rebuilt for every response. */
762
- export interface ProjectionApplyReadbackResultV1 {
770
+ export interface ProjectionApplyReadbackResultV2 {
763
771
  schemaVersion: typeof PROJECTION_APPLY_READBACK_RESULT_SCHEMA_VERSION;
764
772
  requestId: string;
765
773
  requestDigest: Sha256Digest;
766
774
  receipt: ProjectionApplyReceiptV1;
767
- current: ProjectionApplyRecoveryProofV1["current"];
775
+ current: ProjectionApplyRecoveryProofV2["current"];
768
776
  readbackDigest: Sha256Digest;
769
777
  }
770
778
 
@@ -778,7 +786,7 @@ export interface ProjectionApplyAbsenceV1 {
778
786
  absenceDigest: Sha256Digest;
779
787
  }
780
788
 
781
- export type ProjectionApplyReadbackV1 = ProjectionApplyReadbackResultV1 | ProjectionApplyAbsenceV1;
789
+ export type ProjectionApplyReadbackV1 = ProjectionApplyReadbackResultV2 | ProjectionApplyAbsenceV1;
782
790
 
783
791
  export interface ArchctxCapabilitiesV1 {
784
792
  schemaVersion: typeof ARCHCTX_CAPABILITIES_SCHEMA_VERSION;
@@ -856,7 +864,7 @@ export function projectionRequestInvariantIssues(input: ProjectionRequestV1): st
856
864
  * not carry: only a `plan` result previews what it would write (#264); `check`, `apply` and
857
865
  * `adopt` results never carry `files[].preview`, whatever their status.
858
866
  */
859
- export function projectionResultRequestModeIssues(input: ProjectionResultV2, mode: ProjectionMode): string[] {
867
+ export function projectionResultRequestModeIssues(input: ProjectionResultV3, mode: ProjectionMode): string[] {
860
868
  const issues: string[] = [];
861
869
  if (mode !== "plan" && input.files.some((file) => file.preview !== undefined)) {
862
870
  issues.push(`files[].preview is only allowed on a plan result, never when mode=${mode}`);
@@ -880,7 +888,7 @@ export function projectionResultRequestModeIssues(input: ProjectionResultV2, mod
880
888
  return issues;
881
889
  }
882
890
 
883
- export function projectionResultInvariantIssues(input: ProjectionResultV2): string[] {
891
+ export function projectionResultInvariantIssues(input: ProjectionResultV3): string[] {
884
892
  const issues = [
885
893
  ...sortedUniqueIssues("affectedNodeIds", input.affectedNodeIds),
886
894
  ...sortedUniqueIssues("files.path", input.files.map((file) => file.path)),
@@ -961,7 +969,7 @@ export function projectionResultInvariantIssues(input: ProjectionResultV2): stri
961
969
  if (committedApply) issues.push("changes is only allowed on a check or plan result, never on a committed apply");
962
970
  // A carried-forward target is blocked, by the same reasons its coverage entry names.
963
971
  for (const target of input.coverage?.blockedTargets ?? []) {
964
- const entry = input.changes.find((candidate) => candidate.path === target.path);
972
+ const entry = input.changes.find((candidate) => candidate.targetId === target.targetId);
965
973
  if (!entry || entry.classification !== "blocked" || target.reasonCodes.some((code) => !entry.reasonCodes.includes(code))) {
966
974
  issues.push(`changes must classify the carried-forward target ${target.path} as blocked with its coverage reason codes`);
967
975
  }
@@ -1076,21 +1084,18 @@ const TARGET_CHANGE_SEMANTIC_REASONS = ["model-digest-changed", "semantic-finger
1076
1084
 
1077
1085
  /**
1078
1086
  * The one precedence rule of a target change: blocked > proof-change (`proofChanged === true`) >
1079
- * baseline-missing > semantic-change > output-change > stamp-only > unchanged. A known proof change
1080
- * is never hidden by an unknown comparison (a target without a committed row can still carry a
1081
- * moved flow proof); an unknown comparison outranks everything below the proof change and is never
1082
- * `unchanged`. `stamp-only` therefore means the stamps moved while the output bytes, and the
1083
- * semantic and proof comparisons, are known and unchanged on a target nothing blocks.
1087
+ * baseline-missing > semantic-change > output-change > unchanged. A known proof change is never
1088
+ * hidden by an unknown comparison (a target without a committed row can still carry a moved flow
1089
+ * proof); an unknown comparison outranks everything below the proof change and is never `unchanged`.
1084
1090
  */
1085
1091
  export function projectionTargetChangeClassification(
1086
- input: Pick<ProjectionTargetChangeV1, "reasonCodes" | "stampChanged" | "outputChanged" | "semanticChanged" | "proofChanged">
1092
+ input: Pick<ProjectionTargetChangeV2, "reasonCodes" | "outputChanged" | "semanticChanged" | "proofChanged">
1087
1093
  ): ProjectionTargetChangeClassification {
1088
1094
  if (input.reasonCodes.some((code) => TARGET_CHANGE_BLOCKING_REASONS.has(code))) return "blocked";
1089
1095
  if (input.proofChanged === true) return "proof-change";
1090
- if (input.stampChanged === null || input.semanticChanged === null || input.proofChanged === null) return "baseline-missing";
1096
+ if (input.semanticChanged === null || input.proofChanged === null) return "baseline-missing";
1091
1097
  if (input.semanticChanged) return "semantic-change";
1092
1098
  if (input.outputChanged) return "output-change";
1093
- if (input.stampChanged) return "stamp-only";
1094
1099
  return "unchanged";
1095
1100
  }
1096
1101
 
@@ -1101,9 +1106,20 @@ export function projectionTargetChangeClassification(
1101
1106
  * repair, so that change is blocked by that rejection, and still reports the bytes that entry
1102
1107
  * changes (`outputChanged`). Every `files[]` entry that changes a file has a change of its path,
1103
1108
  * except the projection manifest, which is never a target.
1109
+ *
1110
+ * One entry per target: `targetId` is unique, and entries are ordered by path, then targetId. Only
1111
+ * agent-context targets share a path, because several nodes' regions live in one contract file
1112
+ * (ADR-0056 §9).
1104
1113
  */
1105
- export function projectionTargetChangesIssues(input: readonly ProjectionTargetChangeV1[], files: readonly ProjectionFileResultV1[] = []): string[] {
1106
- const issues = sortedUniqueIssues("changes.path", input.map((entry) => entry.path));
1114
+ export function projectionTargetChangesIssues(input: readonly ProjectionTargetChangeV2[], files: readonly ProjectionFileResultV1[] = []): string[] {
1115
+ const issues: string[] = new Set(input.map((entry) => entry.targetId)).size === input.length ? [] : ["changes.targetId must be unique"];
1116
+ const order = (entry: ProjectionTargetChangeV2) => `${entry.path}\u0000${entry.targetId}`;
1117
+ if (input.some((entry, index) => index > 0 && order(input[index - 1]!) >= order(entry))) issues.push("changes must be ordered by path, then targetId");
1118
+ const targetIdsByPath = new Map<string, string[]>();
1119
+ for (const entry of input) targetIdsByPath.set(entry.path, [...(targetIdsByPath.get(entry.path) ?? []), entry.targetId]);
1120
+ for (const [path, targetIds] of targetIdsByPath) {
1121
+ 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`);
1122
+ }
1107
1123
  const fileByPath = new Map(files.map((file) => [file.path, file]));
1108
1124
  const reasons = new Set<string>(PROJECTION_TARGET_CHANGE_REASON_CODES);
1109
1125
  for (const [index, entry] of input.entries()) {
@@ -1115,16 +1131,15 @@ export function projectionTargetChangesIssues(input: readonly ProjectionTargetCh
1115
1131
  if (entry.affectedCapabilityIds.some((id) => typeof id !== "string" || id.trim() === "")) issues.push(`${prefix}.affectedCapabilityIds must not contain empty ids`);
1116
1132
  const unsupported = entry.reasonCodes.find((code) => !reasons.has(code));
1117
1133
  if (unsupported !== undefined) issues.push(`${prefix}.reasonCodes contains an unsupported code: ${unsupported}`);
1118
- for (const field of ["stampChanged", "semanticChanged", "proofChanged"] as const) {
1134
+ for (const field of ["semanticChanged", "proofChanged"] as const) {
1119
1135
  if (entry[field] !== null && typeof entry[field] !== "boolean") issues.push(`${prefix}.${field} must be a boolean or null`);
1120
1136
  }
1121
1137
  if (typeof entry.outputChanged !== "boolean") issues.push(`${prefix}.outputChanged must be a boolean`);
1122
1138
  if (!(PROJECTION_TARGET_CHANGE_PLANNED_ACTIONS as readonly string[]).includes(entry.plannedAction)) issues.push(`${prefix}.plannedAction is unsupported`);
1123
- if ((entry.stampChanged === true) !== has(["source-stamp-changed"])) issues.push(`${prefix}.stampChanged must be true exactly when source-stamp-changed is reported`);
1124
1139
  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`);
1125
1140
  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`);
1126
1141
  if (entry.outputChanged !== has(TARGET_CHANGE_OUTPUT_REASONS)) issues.push(`${prefix}.outputChanged must be true exactly when an output reason code is reported`);
1127
- if ((entry.stampChanged === null || entry.semanticChanged === null || entry.proofChanged === null) !== has(TARGET_CHANGE_UNKNOWN_REASONS)) {
1142
+ if ((entry.semanticChanged === null || entry.proofChanged === null) !== has(TARGET_CHANGE_UNKNOWN_REASONS)) {
1128
1143
  issues.push(`${prefix} must report baseline-missing or target-row-missing exactly when a comparison is unknown`);
1129
1144
  }
1130
1145
  const derived = projectionTargetChangeClassification(entry);
@@ -1151,22 +1166,30 @@ export function projectionTargetChangesIssues(input: readonly ProjectionTargetCh
1151
1166
  return issues;
1152
1167
  }
1153
1168
 
1154
- export function projectionFreshnessIssues(input: ProjectionFreshnessV1): string[] {
1169
+ /** The targetId shape of an agent-context target: `projection_target.agent-context.<agents|claude>.<node>`. */
1170
+ function isAgentContextTargetId(targetId: unknown): boolean {
1171
+ return typeof targetId === "string" && /^projection_target\.agent-context\.(agents|claude)\.[^.]+$/.test(targetId);
1172
+ }
1173
+
1174
+ export function projectionFreshnessIssues(input: ProjectionFreshnessV2): string[] {
1155
1175
  const issues = [
1156
1176
  ...sortedUniqueIssues("freshness.reasonCodes", input.reasonCodes),
1157
- ...sortedUniqueIssues("freshness.staleNodes.nodeId", input.staleNodes.map((node) => node.nodeId))
1177
+ ...sortedUniqueIssues("freshness.staleTargets.targetId", input.staleTargets.map((target) => target.targetId))
1158
1178
  ];
1159
1179
  const unsupported = input.reasonCodes.find((code) => !(PROJECTION_FRESHNESS_REASON_CODES as readonly string[]).includes(code));
1160
1180
  if (unsupported) issues.push(`freshness.reasonCodes contains an unsupported code: ${unsupported}`);
1161
1181
  if (input.ok !== (input.reasonCodes.length === 0)) issues.push("freshness.ok must be true exactly when reasonCodes is empty");
1162
- if ((input.staleNodes.length > 0) !== input.reasonCodes.includes("projection-source-changed-since-stamp")) {
1163
- issues.push("freshness.staleNodes must be non-empty exactly when projection-source-changed-since-stamp is reported");
1182
+ if ((input.staleTargets.length > 0) !== input.reasonCodes.includes("projection-output-changed")) {
1183
+ issues.push("freshness.staleTargets must be non-empty exactly when projection-output-changed is reported");
1164
1184
  }
1165
- for (const [index, node] of input.staleNodes.entries()) {
1166
- const prefix = `freshness.staleNodes[${index}]`;
1167
- if (node.nodeId.trim() === "") issues.push(`${prefix}.nodeId must not be empty`);
1168
- if (!SHA256_DIGEST.test(node.stampedDigest) || !SHA256_DIGEST.test(node.currentDigest)) issues.push(`${prefix} digests must be SHA-256 digests`);
1169
- else if (node.stampedDigest === node.currentDigest) issues.push(`${prefix} must name two different digests`);
1185
+ for (const [index, target] of input.staleTargets.entries()) {
1186
+ const prefix = `freshness.staleTargets[${index}]`;
1187
+ if (target.targetId.trim() === "") issues.push(`${prefix}.targetId must not be empty`);
1188
+ if (!isRepoRelativePosixPath(target.path)) issues.push(`${prefix}.path must be a repository-relative POSIX path`);
1189
+ const digests = [target.committedOutputDigest, target.renderedOutputDigest];
1190
+ if (digests.every((digest) => digest === null)) issues.push(`${prefix} must name at least one digest`);
1191
+ else if (digests.some((digest) => digest !== null && !SHA256_DIGEST.test(digest))) issues.push(`${prefix} digests must be SHA-256 digests or null`);
1192
+ else if (target.committedOutputDigest === target.renderedOutputDigest) issues.push(`${prefix} must name two different digests`);
1170
1193
  }
1171
1194
  return issues;
1172
1195
  }
@@ -1235,7 +1258,7 @@ export function projectionPriorCommittedAppliesIssues(
1235
1258
  * receipt payload to avoid a circular hash; every signal must then bind that receipt via
1236
1259
  * projectionReceiptDigest, which projectionResultInvariantIssues verifies.
1237
1260
  */
1238
- export function projectionResultReceiptDigest(input: Omit<ProjectionResultV2, "receiptDigest">): Sha256Digest {
1261
+ export function projectionResultReceiptDigest(input: Omit<ProjectionResultV3, "receiptDigest">): Sha256Digest {
1239
1262
  const { replayed: _replayed, written: _written, ...payload } = input;
1240
1263
  const refreshSignals = payload.refreshSignals.map(({ projectionReceiptDigest: _projectionReceiptDigest, ...signal }) => signal);
1241
1264
  return digestJson({ ...payload, refreshSignals } as unknown as Json) as Sha256Digest;
@@ -1261,7 +1284,7 @@ export function createProjectionApplyIdentity(input: {
1261
1284
  changeSetId: string;
1262
1285
  idempotencyKey: string;
1263
1286
  files: ProjectionFileResultV1[];
1264
- refreshSignals: ArchitectureRefreshSignalV1[];
1287
+ refreshSignals: ArchitectureRefreshSignalV2[];
1265
1288
  }): ProjectionApplyIdentityV1 {
1266
1289
  const lookupKey = projectionApplyLookupKey(input);
1267
1290
  const ownedFilesDigest = digestJson(input.files as unknown as Json) as Sha256Digest;
@@ -1308,7 +1331,7 @@ export function projectionApplyReceiptInvariantIssues(input: ProjectionApplyRece
1308
1331
  }
1309
1332
 
1310
1333
  export function projectionApplyRecoveryBindingInvariantIssues(
1311
- binding: ProjectionApplyRecoveryBindingV1,
1334
+ binding: ProjectionApplyRecoveryBindingV2,
1312
1335
  receipt?: ProjectionApplyReceiptV1
1313
1336
  ): string[] {
1314
1337
  const issues = [
@@ -1406,12 +1429,12 @@ export function projectionApplyAbsenceInvariantIssues(input: ProjectionApplyAbse
1406
1429
  return issues;
1407
1430
  }
1408
1431
 
1409
- export function projectionApplyReadbackResultDigest(input: Omit<ProjectionApplyReadbackResultV1, "readbackDigest">): Sha256Digest {
1432
+ export function projectionApplyReadbackResultDigest(input: Omit<ProjectionApplyReadbackResultV2, "readbackDigest">): Sha256Digest {
1410
1433
  return digestJson(input as unknown as Json) as Sha256Digest;
1411
1434
  }
1412
1435
 
1413
1436
  export function projectionApplyReadbackResultInvariantIssues(
1414
- input: ProjectionApplyReadbackResultV1,
1437
+ input: ProjectionApplyReadbackResultV2,
1415
1438
  request?: ProjectionRequestV1
1416
1439
  ): string[] {
1417
1440
  const issues = projectionApplyReceiptInvariantIssues(input.receipt);
@@ -1464,11 +1487,11 @@ export function projectionApplyRecoveryIntentInvariantIssues(input: ProjectionAp
1464
1487
  return issues;
1465
1488
  }
1466
1489
 
1467
- export function projectionApplyRecoveryProofDigest(input: Omit<ProjectionApplyRecoveryProofV1, "proofDigest" | "deliveryStatus">): Sha256Digest {
1490
+ export function projectionApplyRecoveryProofDigest(input: Omit<ProjectionApplyRecoveryProofV2, "proofDigest" | "deliveryStatus">): Sha256Digest {
1468
1491
  return digestJson(input as unknown as Json) as Sha256Digest;
1469
1492
  }
1470
1493
 
1471
- export function projectionApplyRecoveryProofInvariantIssues(input: ProjectionApplyRecoveryProofV1): string[] {
1494
+ export function projectionApplyRecoveryProofInvariantIssues(input: ProjectionApplyRecoveryProofV2): string[] {
1472
1495
  const issues = [
1473
1496
  ...sortedUniqueIssues("acceptedChange.reasonCodes", input.acceptedChange.reasonCodes),
1474
1497
  ...sortedUniqueIssues("acceptedChange.affectedNodeIds", input.acceptedChange.affectedNodeIds)
@@ -1483,7 +1506,7 @@ export function projectionApplyRecoveryProofInvariantIssues(input: ProjectionApp
1483
1506
  return issues;
1484
1507
  }
1485
1508
 
1486
- export function projectionApplyRecoveryResultInvariantIssues(input: ProjectionApplyRecoveryResultV1): string[] {
1509
+ export function projectionApplyRecoveryResultInvariantIssues(input: ProjectionApplyRecoveryResultV2): string[] {
1487
1510
  const issues = [
1488
1511
  ...projectionApplyRecoveryProofInvariantIssues(input.proof),
1489
1512
  ...input.refreshSignals.flatMap((signal, index) => architectureRefreshSignalInvariantIssues(signal, `refreshSignals[${index}]`)),
@@ -1512,7 +1535,7 @@ export function projectionApplyRecoveryResultInvariantIssues(input: ProjectionAp
1512
1535
 
1513
1536
  /** The durable store uses this before delivery; it can validate immutable bindings but not re-render the current projection. */
1514
1537
  export function projectionApplyRecoveryProofReceiptInvariantIssues(
1515
- proof: ProjectionApplyRecoveryProofV1,
1538
+ proof: ProjectionApplyRecoveryProofV2,
1516
1539
  receipt: ProjectionApplyReceiptV1
1517
1540
  ): string[] {
1518
1541
  const issues = [
@@ -1540,7 +1563,7 @@ export function projectionApplyRecoveryProofReceiptInvariantIssues(
1540
1563
  return issues;
1541
1564
  }
1542
1565
 
1543
- function projectionApplyReceiptResultingDigests(receipt: ProjectionApplyReceiptV1): ArchitectureDigestSetV1 | undefined {
1566
+ function projectionApplyReceiptResultingDigests(receipt: ProjectionApplyReceiptV1): ArchitectureDigestSetV2 | undefined {
1544
1567
  const signals = receipt.result.refreshSignals;
1545
1568
  if (signals.length === 0) return undefined;
1546
1569
  const [first] = signals;
@@ -1549,7 +1572,7 @@ function projectionApplyReceiptResultingDigests(receipt: ProjectionApplyReceiptV
1549
1572
  : undefined;
1550
1573
  }
1551
1574
 
1552
- export function architectureRefreshSignalInvariantIssues(input: ArchitectureRefreshSignalV1, prefix = "signal"): string[] {
1575
+ export function architectureRefreshSignalInvariantIssues(input: ArchitectureRefreshSignalV2, prefix = "signal"): string[] {
1553
1576
  const issues = [
1554
1577
  ...sortedUniqueIssues(`${prefix}.reasonCodes`, input.reasonCodes),
1555
1578
  ...sortedUniqueIssues(`${prefix}.affectedNodeIds`, input.affectedNodeIds),
@@ -134,6 +134,7 @@ export type StateMachineBreak =
134
134
  | { kind: "dead-step"; event: string; step: number }
135
135
  | { kind: "deadlock"; state: StateMachineGlobalState; path: StateMachinePathStep[]; count: number };
136
136
 
137
+ /** The built-in check of one machine by the model alone: rules and breaks, no code read. */
137
138
  export interface StateMachineMachineReport {
138
139
  id: string;
139
140
  capabilityId: string;
@@ -143,13 +144,6 @@ export interface StateMachineMachineReport {
143
144
  breaks: StateMachineBreak[];
144
145
  }
145
146
 
146
- /** The model-only result of `checkStateMachines`: rules and breaks, no code read. */
147
- export interface StateMachineRuleCheckV1 {
148
- schemaVersion: typeof STATE_MACHINE_CHECK_SCHEMA_VERSION;
149
- /** Sorted by machine id. */
150
- machines: StateMachineMachineReport[];
151
- }
152
-
153
147
  export type StateMachineAnchorStatus =
154
148
  | "anchor-missing-path"
155
149
  | "anchor-language-unsupported"
@@ -169,8 +163,18 @@ export interface StateMachineAnchor {
169
163
  status: StateMachineAnchorStatus;
170
164
  /** Present for `anchor-unconfirmed`, `anchor-changed` and `confirmed`. */
171
165
  digest?: string;
172
- /** Present for `unchecked`: the reason code of the unavailable symbol reader. */
173
- reason?: "index-missing" | "index-open-failed";
166
+ /** Present for a symbol anchor with a digest: the direct callees that the digest covers, in digest order. */
167
+ callees?: StateMachineAnchorCallee[];
168
+ /**
169
+ * Present for `unchecked`: the symbol reader is unavailable, or the index does not hold the
170
+ * current content of the anchor's file or of a callee's file.
171
+ */
172
+ reason?: "index-missing" | "index-open-failed" | "index-stale";
173
+ }
174
+
175
+ export interface StateMachineAnchorCallee {
176
+ path: string;
177
+ qualifiedName: string;
174
178
  }
175
179
 
176
180
  export interface StateMachineCheckMachineV1 extends StateMachineMachineReport {
@@ -189,8 +193,9 @@ type NodeRecord = Readonly<Record<string, Json | undefined>>;
189
193
 
190
194
  /**
191
195
  * Cross-entity rules of the state machine model that the per-file schema cannot state. The
192
- * loader and the YAML model store both call this one function on schema-valid machines, so
193
- * `archctx validate` and `archctx state-machines check` cannot disagree.
196
+ * loader and the YAML model store both run it on schema-valid machines through
197
+ * `stateMachinesFromModelFiles`, so `archctx validate` and `archctx state-machines check` cannot
198
+ * disagree.
194
199
  *
195
200
  * The result is aligned with `stateMachines`: entry `i` holds the issues of machine `i`, so a
196
201
  * caller can name the file of each issue even when two machines share an id. A repeated machine