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.
Files changed (119) hide show
  1. package/fixtures/invalid/projection-result-applied-incomplete-coverage.json +3 -3
  2. package/fixtures/valid/archctx-capabilities.json +2 -2
  3. package/fixtures/valid/flow-selector-check.json +1 -1
  4. package/fixtures/valid/product-version-manifest.json +5 -11
  5. package/fixtures/valid/projection-manifest.json +1 -1
  6. package/fixtures/valid/projection-result.json +3 -3
  7. package/package.json +4 -1
  8. package/schemas/repo/refactor-decision.schema.json +283 -37
  9. package/schemas/runtime/archctx-capabilities.schema.json +144 -20
  10. package/schemas/runtime/architecture-debt-delta.schema.json +58 -19
  11. package/schemas/runtime/architecture-debt.schema.json +42 -42
  12. package/schemas/runtime/architecture-event.schema.json +1 -1
  13. package/schemas/runtime/architecture-history.schema.json +354 -0
  14. package/schemas/runtime/capability-dependencies.schema.json +266 -59
  15. package/schemas/runtime/cli-check.schema.json +197 -0
  16. package/schemas/runtime/cli-help.schema.json +28 -0
  17. package/schemas/runtime/dependency-constraint-evaluation.schema.json +67 -68
  18. package/schemas/runtime/docs-anchors.schema.json +250 -67
  19. package/schemas/runtime/doctor-code-facts.schema.json +49 -0
  20. package/schemas/runtime/evidence-binding.schema.json +1 -1
  21. package/schemas/runtime/flow-selector-check.schema.json +179 -46
  22. package/schemas/runtime/hook-debt-checkpoint.schema.json +12 -12
  23. package/schemas/runtime/index-seed.schema.json +56 -0
  24. package/schemas/runtime/path-context.schema.json +108 -0
  25. package/schemas/runtime/product-version-manifest.schema.json +142 -54
  26. package/schemas/runtime/projection-apply-readback.schema.json +2 -2
  27. package/schemas/runtime/projection-apply-recovery.schema.json +1 -1
  28. package/schemas/runtime/projection-result.schema.json +1 -1
  29. package/schemas/runtime/projection-slice.schema.json +34 -34
  30. package/schemas/runtime/recommendation-v3.schema.json +372 -1
  31. package/schemas/runtime/ref-impact-batch-request.schema.json +20 -7
  32. package/schemas/runtime/ref-impact-batch.schema.json +83 -13
  33. package/schemas/runtime/ref-impact.schema.json +68 -61
  34. package/schemas/runtime/refactor-scan-v2.schema.json +434 -0
  35. package/schemas/runtime/refactor-simulate.schema.json +505 -0
  36. package/schemas/runtime/refactor-verify-v2.schema.json +172 -0
  37. package/schemas/runtime/resolve-path.schema.json +69 -0
  38. package/schemas/runtime/runtime-recommendation-show.schema.json +531 -2
  39. package/schemas/runtime/runtime-refactor-scan.schema.json +498 -2
  40. package/schemas/runtime/runtime-verify.schema.json +274 -56
  41. package/schemas/runtime/state-machine-check.schema.json +357 -89
  42. package/schemas/runtime/structural-observation-payload.schema.json +372 -1
  43. package/schemas/runtime/sync-check.schema.json +65 -0
  44. package/src/architecture-debt.ts +125 -38
  45. package/src/architecture-history.ts +168 -42
  46. package/src/architecture.ts +100 -0
  47. package/src/cli-read.ts +228 -0
  48. package/src/docs-anchors.ts +105 -50
  49. package/src/explorer-occurrence-ports.ts +175 -0
  50. package/src/explorer-query-ports.ts +270 -0
  51. package/src/failure.ts +3 -0
  52. package/src/index-seed.ts +42 -0
  53. package/src/index.ts +5 -0
  54. package/src/ledger-records.ts +262 -0
  55. package/src/ledger.ts +27 -566
  56. package/src/ownership-dependencies.ts +115 -5
  57. package/src/ports.ts +12 -543
  58. package/src/product-version.ts +75 -56
  59. package/src/projection-apply-types.ts +216 -0
  60. package/src/projection-apply-validators.ts +355 -0
  61. package/src/projection-capabilities.ts +181 -0
  62. package/src/projection-constants.ts +317 -0
  63. package/src/projection-manifest-types.ts +298 -0
  64. package/src/projection-manifest.ts +12 -299
  65. package/src/projection-recovery-validators.ts +229 -0
  66. package/src/projection-request-validators.ts +326 -0
  67. package/src/projection-types.ts +365 -0
  68. package/src/projection-validation-helpers.ts +15 -0
  69. package/src/projection.ts +7 -1689
  70. package/src/ref-impact.ts +225 -33
  71. package/src/refactor-constants.ts +213 -0
  72. package/src/refactor-decision-validators.ts +350 -0
  73. package/src/refactor-evidence-types.ts +286 -0
  74. package/src/refactor-observation-validators.ts +359 -0
  75. package/src/refactor-resolution-validators.ts +229 -0
  76. package/src/refactor-snapshot-validators.ts +368 -0
  77. package/src/refactor-types.ts +270 -0
  78. package/src/refactor-v2.ts +389 -0
  79. package/src/refactor-validation-helpers.ts +195 -0
  80. package/src/refactor.ts +7 -1849
  81. package/src/review-guards.ts +3 -23
  82. package/src/runtime-verify.ts +87 -0
  83. package/src/schema-kit.ts +183 -0
  84. package/src/schema-registry.ts +73 -0
  85. package/src/schema.ts +0 -4
  86. package/src/state-machine-schemas.ts +192 -0
  87. package/src/state-machine-types.ts +188 -0
  88. package/src/state-machine.ts +9 -189
  89. package/fixtures/boundary/agent-job-expired.json +0 -33
  90. package/fixtures/invalid/adapter-fidelity-reverse-sync.json +0 -9
  91. package/fixtures/invalid/agent-job-direct-mutation.json +0 -32
  92. package/fixtures/invalid/cloud-egress-envelope-private-field.json +0 -12
  93. package/fixtures/invalid/investigation-report-direct-mutation.json +0 -38
  94. package/fixtures/invalid/investigation-report-missing-proposed-delta.json +0 -19
  95. package/fixtures/invalid/notification-event-code-field.json +0 -11
  96. package/fixtures/valid/adapter-fidelity.json +0 -9
  97. package/fixtures/valid/agent-job.json +0 -33
  98. package/fixtures/valid/architecture-candidate-delta-policy.json +0 -45
  99. package/fixtures/valid/architecture-candidate-delta.json +0 -188
  100. package/fixtures/valid/chatgpt-ga-tool.json +0 -9
  101. package/fixtures/valid/cloud-egress-envelope.json +0 -11
  102. package/fixtures/valid/entitlement.json +0 -12
  103. package/fixtures/valid/investigation-report.json +0 -38
  104. package/fixtures/valid/likec4-mapping.json +0 -14
  105. package/fixtures/valid/notification-event.json +0 -10
  106. package/fixtures/valid/notification-provider.json +0 -12
  107. package/fixtures/valid/structurizr-mapping.json +0 -15
  108. package/schemas/cloud/cloud-egress-envelope.schema.json +0 -19
  109. package/schemas/cloud/entitlement.schema.json +0 -24
  110. package/schemas/integrations/adapter-fidelity.schema.json +0 -21
  111. package/schemas/integrations/chatgpt-ga-tool.schema.json +0 -25
  112. package/schemas/integrations/likec4-mapping.schema.json +0 -32
  113. package/schemas/integrations/structurizr-mapping.schema.json +0 -33
  114. package/schemas/runtime/agent-job.schema.json +0 -63
  115. package/schemas/runtime/architecture-candidate-delta-policy.schema.json +0 -129
  116. package/schemas/runtime/architecture-candidate-delta.schema.json +0 -386
  117. package/schemas/runtime/investigation-report.schema.json +0 -119
  118. package/schemas/runtime/notification-event.schema.json +0 -18
  119. package/schemas/runtime/notification-provider.schema.json +0 -26
@@ -1,3 +1,17 @@
1
+ import {
2
+ Const,
3
+ CountSchema,
4
+ OneOf,
5
+ PositiveIntSchema,
6
+ RawEnum,
7
+ Ref,
8
+ RepoPathSchema,
9
+ SchemaDocument,
10
+ StrictObject,
11
+ Type,
12
+ type Static
13
+ } from "./schema-kit";
14
+
1
15
  /**
2
16
  * `archctx docs anchors` (#298): a read-only signal for stale citations in human-owned text. It
3
17
  * reads the human-owned regions of module documents and node prose (`summary`,
@@ -16,70 +30,111 @@ export type DocsAnchorUncheckedReasonCode = (typeof DOCS_ANCHOR_UNCHECKED_REASON
16
30
  export const DOCS_ANCHOR_CODEGRAPH_UNAVAILABLE_REASON_CODES = ["index-missing", "index-open-failed"] as const;
17
31
  export type DocsAnchorCodeGraphUnavailableReasonCode = (typeof DOCS_ANCHOR_CODEGRAPH_UNAVAILABLE_REASON_CODES)[number];
18
32
 
19
- /** Where the citation is written: a human-owned document line, or a field of the node. */
20
- export type DocsAnchorOriginV1 =
21
- | { kind: "document"; path: string; line: number }
22
- | { kind: "node-summary" }
23
- | { kind: "node-responsibility"; index: number };
33
+ const DocsAnchorOriginBodySchema = OneOf([
34
+ StrictObject({
35
+ kind: Const("document"),
36
+ path: Ref<string>("#/$defs/repoPath"),
37
+ line: Ref<number>("#/$defs/line")
38
+ }),
39
+ StrictObject({ kind: Const("node-summary") }),
40
+ StrictObject({ kind: Const("node-responsibility"), index: Type.Integer({ minimum: 0 }) })
41
+ ]);
42
+ export type DocsAnchorOriginV1 = Static<typeof DocsAnchorOriginBodySchema>;
24
43
 
25
- export interface DocsAnchorCitationV1 {
44
+ const DocsAnchorCitationBodySchema = StrictObject({
26
45
  /** The inline code span as written, without the backticks. */
27
- text: string;
46
+ text: Type.String({ minLength: 1 }),
28
47
  /** The cited path as written. */
29
- path?: string;
48
+ path: Type.Optional(Type.String({ minLength: 1 })),
30
49
  /** The Git-visible file or directory the path resolved to, when it differs from `path`. */
31
- resolvedPath?: string;
32
- line?: number;
33
- endLine?: number;
34
- symbol?: string;
35
- }
50
+ resolvedPath: Type.Optional(Ref<string>("#/$defs/repoPath")),
51
+ line: Type.Optional(Ref<number>("#/$defs/line")),
52
+ endLine: Type.Optional(Ref<number>("#/$defs/line")),
53
+ symbol: Type.Optional(Type.String({ minLength: 1 }))
54
+ });
55
+ export type DocsAnchorCitationV1 = Static<typeof DocsAnchorCitationBodySchema>;
36
56
 
37
- export interface DocsAnchorFindingV1 {
38
- kind: DocsAnchorFindingKind;
39
- origin: DocsAnchorOriginV1;
40
- citation: DocsAnchorCitationV1;
57
+ const DocsAnchorFindingBodySchema = StrictObject({
58
+ kind: RawEnum(DOCS_ANCHOR_FINDING_KINDS),
59
+ origin: Ref<DocsAnchorOriginV1>("#/$defs/origin"),
60
+ citation: Ref<DocsAnchorCitationV1>("#/$defs/citation"),
41
61
  /** `line-out-of-range` only: the current line count of the cited file. */
42
- lineCount?: number;
62
+ lineCount: Type.Optional(Ref<number>("#/$defs/count")),
43
63
  /** `line-moved` only: the current start lines of the cited symbol, sorted. */
44
- currentLines?: number[];
45
- }
64
+ currentLines: Type.Optional(
65
+ Type.Array(Ref<number>("#/$defs/line"), { minItems: 1, uniqueItems: true })
66
+ )
67
+ });
68
+ export type DocsAnchorFindingV1 = Static<typeof DocsAnchorFindingBodySchema>;
46
69
 
47
- export interface DocsAnchorUncheckedV1 {
48
- reasonCode: DocsAnchorUncheckedReasonCode;
49
- origin: DocsAnchorOriginV1;
50
- citation: DocsAnchorCitationV1;
51
- }
70
+ const DocsAnchorUncheckedBodySchema = StrictObject({
71
+ reasonCode: RawEnum(DOCS_ANCHOR_UNCHECKED_REASON_CODES),
72
+ origin: Ref<DocsAnchorOriginV1>("#/$defs/origin"),
73
+ citation: Ref<DocsAnchorCitationV1>("#/$defs/citation")
74
+ });
75
+ export type DocsAnchorUncheckedV1 = Static<typeof DocsAnchorUncheckedBodySchema>;
52
76
 
53
- export interface DocsAnchorsNodeV1 {
54
- nodeId: string;
55
- /** The node's module document, when the active layout has one and it exists. */
56
- documentPath?: string;
57
- citationCount: number;
58
- findings: DocsAnchorFindingV1[];
59
- unchecked: DocsAnchorUncheckedV1[];
60
- }
77
+ export const DocsAnchorsCodeGraphSchema = OneOf([
78
+ StrictObject({ availability: Const("ready") }),
79
+ StrictObject({
80
+ availability: Const("unavailable"),
81
+ reasonCode: RawEnum(DOCS_ANCHOR_CODEGRAPH_UNAVAILABLE_REASON_CODES)
82
+ })
83
+ ]);
61
84
 
62
- export type DocsAnchorsCodeGraphV1 =
63
- | { availability: "ready" }
64
- | { availability: "unavailable"; reasonCode: DocsAnchorCodeGraphUnavailableReasonCode };
85
+ export const DocsAnchorsNodeSchema = StrictObject({
86
+ nodeId: Type.String({ minLength: 1 }),
87
+ /** The node's module document, when the active layout has one and it exists. */
88
+ documentPath: Type.Optional(Ref<string>("#/$defs/repoPath")),
89
+ citationCount: Type.Integer({ minimum: 1 }),
90
+ findings: Type.Array(Ref<DocsAnchorFindingV1>("#/$defs/finding")),
91
+ unchecked: Type.Array(Ref<DocsAnchorUncheckedV1>("#/$defs/unchecked"))
92
+ });
65
93
 
66
- export interface DocsAnchorsReportV1 {
67
- schemaVersion: typeof DOCS_ANCHORS_REPORT_SCHEMA_VERSION;
68
- profile: "default" | "repo-harness/v1";
69
- codeGraph: DocsAnchorsCodeGraphV1;
70
- summary: {
94
+ export const DocsAnchorsReportBodySchema = StrictObject({
95
+ schemaVersion: Const(DOCS_ANCHORS_REPORT_SCHEMA_VERSION),
96
+ profile: RawEnum(["default", "repo-harness/v1"] as const),
97
+ codeGraph: DocsAnchorsCodeGraphSchema,
98
+ summary: StrictObject({
71
99
  /** Model nodes whose prose and module document were read. */
72
- nodes: number;
100
+ nodes: Ref<number>("#/$defs/count"),
73
101
  /** Module documents read. */
74
- documents: number;
75
- citations: number;
76
- findings: number;
77
- unchecked: number;
78
- byKind: Record<DocsAnchorFindingKind, number>;
79
- };
102
+ documents: Ref<number>("#/$defs/count"),
103
+ citations: Ref<number>("#/$defs/count"),
104
+ findings: Ref<number>("#/$defs/count"),
105
+ unchecked: Ref<number>("#/$defs/count"),
106
+ byKind: StrictObject({
107
+ "line-moved": Ref<number>("#/$defs/count"),
108
+ "line-out-of-range": Ref<number>("#/$defs/count"),
109
+ "missing-path": Ref<number>("#/$defs/count"),
110
+ "missing-symbol": Ref<number>("#/$defs/count"),
111
+ "unknown-selector": Ref<number>("#/$defs/count")
112
+ })
113
+ }),
80
114
  /** Nodes with at least one citation, sorted by `nodeId`. */
81
- nodes: DocsAnchorsNodeV1[];
82
- }
115
+ nodes: Type.Array(DocsAnchorsNodeSchema)
116
+ });
117
+
118
+ export const DocsAnchorsReportSchema = SchemaDocument({
119
+ $id: "https://archcontext.dev/schemas/runtime/docs-anchors.schema.json",
120
+ title: "DocsAnchorsReportV1",
121
+ description: "Read-only result of `archctx docs anchors`: stale citations in human-owned module document regions and node prose. A signal, not a gate.",
122
+ schema: DocsAnchorsReportBodySchema,
123
+ $defs: {
124
+ count: CountSchema,
125
+ line: PositiveIntSchema,
126
+ repoPath: RepoPathSchema,
127
+ origin: DocsAnchorOriginBodySchema,
128
+ citation: DocsAnchorCitationBodySchema,
129
+ finding: DocsAnchorFindingBodySchema,
130
+ unchecked: DocsAnchorUncheckedBodySchema
131
+ }
132
+ });
133
+
134
+ /** Where the citation is written: a human-owned document line, or a field of the node. */
135
+ export type DocsAnchorsNodeV1 = Static<typeof DocsAnchorsNodeSchema>;
136
+ export type DocsAnchorsCodeGraphV1 = Static<typeof DocsAnchorsCodeGraphSchema>;
137
+ export type DocsAnchorsReportV1 = Static<typeof DocsAnchorsReportSchema>;
83
138
 
84
139
  export function docsAnchorsReportIssues(report: DocsAnchorsReportV1): string[] {
85
140
  const issues: string[] = [];
@@ -0,0 +1,175 @@
1
+ import type {
2
+ AuthorityCursorV1,
3
+ ExplorerPressureLevel,
4
+ ExplorerProjectionCursorV2,
5
+ ExplorerSemanticLevelV2,
6
+ ExplorerSubjectRefKindV2,
7
+ ExplorerVerificationStatus,
8
+ ExplorerViewIdV2,
9
+ ProjectionInputManifestV1,
10
+ SourceSelector
11
+ } from "./explorer-query-ports";
12
+
13
+ export interface ExplorerSubjectRefV2 {
14
+ kind: ExplorerSubjectRefKindV2;
15
+ id: string;
16
+ }
17
+
18
+ export interface ExplorerOccurrenceProvenanceV2 {
19
+ declaredEntityIds: string[];
20
+ observedSymbolIds: string[];
21
+ evidenceBindingIds: string[];
22
+ }
23
+
24
+ export type ExplorerAuthorityStateV2 = "BOUND" | "UNBOUND_OBSERVED" | "DECLARED_UNOBSERVED" | "DERIVED";
25
+
26
+ export interface ExplorerPressureEvaluationV2 {
27
+ evaluated: boolean;
28
+ level?: ExplorerPressureLevel;
29
+ score?: number;
30
+ signals: string[];
31
+ inputDigest?: string;
32
+ }
33
+
34
+ export interface ExplorerInspectorV2 {
35
+ summary?: string;
36
+ responsibility?: string;
37
+ constraints: Array<{ id: string; kind: string; severity?: string; summary?: string }>;
38
+ decisions: Array<{ eventId: string; title?: string; rationale?: string }>;
39
+ historyEvents: Array<{ eventId: string; title?: string; rationale?: string }>;
40
+ sourceSelectors: SourceSelector[];
41
+ evidenceBindingIds: string[];
42
+ }
43
+
44
+ export interface ExplorerBacklinksV2 {
45
+ appearsInViews: ExplorerViewIdV2[];
46
+ affectedByTaskSessionIds: string[];
47
+ constrainedByIds: string[];
48
+ evidencedByBindingIds: string[];
49
+ changedByEventIds: string[];
50
+ decidedByEventIds: string[];
51
+ incomingRelationIds: string[];
52
+ outgoingRelationIds: string[];
53
+ }
54
+
55
+ export interface ExplorerSubjectOccurrenceV2 {
56
+ occurrenceId: string;
57
+ role: "subject";
58
+ parentOccurrenceId?: string;
59
+ subjectRefs: ExplorerSubjectRefV2[];
60
+ name: string;
61
+ kind: string;
62
+ childrenCount: number;
63
+ expandable: boolean;
64
+ verificationStatus: ExplorerVerificationStatus;
65
+ authorityState: ExplorerAuthorityStateV2;
66
+ pressure: ExplorerPressureEvaluationV2;
67
+ sourceSelectors: SourceSelector[];
68
+ provenance: ExplorerOccurrenceProvenanceV2;
69
+ inspector: ExplorerInspectorV2;
70
+ backlinks: ExplorerBacklinksV2;
71
+ }
72
+
73
+ export interface ExplorerDerivedGroupOccurrenceV2 {
74
+ occurrenceId: string;
75
+ role: "derived-group";
76
+ parentOccurrenceId?: string;
77
+ subjectRefs: [];
78
+ name: string;
79
+ kind: string;
80
+ childrenCount: number;
81
+ expandable: boolean;
82
+ verificationStatus: "UNKNOWN";
83
+ authorityState: "DERIVED";
84
+ pressure: ExplorerPressureEvaluationV2;
85
+ sourceSelectors: [];
86
+ provenance: ExplorerOccurrenceProvenanceV2;
87
+ derivation: {
88
+ ruleId: string;
89
+ inputDigest: string;
90
+ compilerVersion: "archcontext.explorer-view-compiler/v1";
91
+ };
92
+ }
93
+
94
+ export type ExplorerOccurrenceV2 = ExplorerSubjectOccurrenceV2 | ExplorerDerivedGroupOccurrenceV2;
95
+
96
+ export interface ExplorerRelationOccurrenceV2 {
97
+ occurrenceId: string;
98
+ sourceOccurrenceId: string;
99
+ targetOccurrenceId: string;
100
+ kind: string;
101
+ verificationStatus: ExplorerVerificationStatus;
102
+ provenance: {
103
+ declaredRelationIds: string[];
104
+ observedEdgeIds: string[];
105
+ evidenceBindingIds: string[];
106
+ };
107
+ }
108
+
109
+ export interface ExplorerProjectionV2 {
110
+ schemaVersion: "archcontext.explorer-projection/v2";
111
+ view: {
112
+ id: ExplorerViewIdV2;
113
+ title: string;
114
+ question: string;
115
+ };
116
+ availableViews: Array<{ id: ExplorerViewIdV2; enabled: boolean; reason?: string }>;
117
+ semanticLevel: ExplorerSemanticLevelV2;
118
+ breadcrumbs: Array<{ occurrenceId: string; label: string }>;
119
+ cursor: ExplorerProjectionCursorV2;
120
+ inputManifest: ProjectionInputManifestV1;
121
+ occurrences: ExplorerOccurrenceV2[];
122
+ relations: ExplorerRelationOccurrenceV2[];
123
+ page: {
124
+ budget: { maxNodes: number; maxRelations: number };
125
+ totalNodes: number;
126
+ totalRelations: number;
127
+ returnedNodes: number;
128
+ returnedRelations: number;
129
+ truncated: boolean;
130
+ omittedNodeCount: number;
131
+ omittedRelationCount: number;
132
+ };
133
+ projectionDigest: string;
134
+ capabilities: {
135
+ readOnly: true;
136
+ mutationMode: "forbidden";
137
+ egress: "none";
138
+ tokenRequired: boolean;
139
+ };
140
+ }
141
+
142
+ export type ExplorerDeltaClassV2 = "architecture-fact" | "evidence" | "projection";
143
+
144
+ export type ExplorerDeltaFailureReasonV2 =
145
+ | "invalid-delta-query"
146
+ | "projection-cache-miss"
147
+ | "authority-event-missing"
148
+ | "authority-cursor-reversed"
149
+ | "projection-authority-mismatch"
150
+ | "projection-manifest-incompatible";
151
+
152
+ export interface ExplorerDeltaQueryV2 {
153
+ schemaVersion: "archcontext.explorer-delta-query/v2";
154
+ base: { eventId: string; projectionDigest: string };
155
+ head: { eventId: string; projectionDigest: string };
156
+ }
157
+
158
+ export interface ExplorerDeltaChangeV2 {
159
+ deltaClass: ExplorerDeltaClassV2;
160
+ subjectId: string;
161
+ change: "added" | "removed" | "changed";
162
+ fields: string[];
163
+ verificationTransition?: { from: ExplorerVerificationStatus; to: ExplorerVerificationStatus };
164
+ }
165
+
166
+ export interface ExplorerProjectionDeltaV2 {
167
+ schemaVersion: "archcontext.explorer-projection-delta/v2";
168
+ base: AuthorityCursorV1 & { projectionDigest: string; inputManifestDigest: string };
169
+ head: AuthorityCursorV1 & { projectionDigest: string; inputManifestDigest: string };
170
+ factChanges: ExplorerDeltaChangeV2[];
171
+ evidenceChanges: ExplorerDeltaChangeV2[];
172
+ projectionChanges: ExplorerDeltaChangeV2[];
173
+ counts: Record<ExplorerDeltaClassV2, number>;
174
+ deltaDigest: string;
175
+ }
@@ -0,0 +1,270 @@
1
+ import { digestJson, type Json } from "./schema";
2
+ import type {
3
+ ArchitectureRepositoryIdentityV1,
4
+ ArchitectureWorktreeIdentityV1
5
+ } from "./ledger-records";
6
+
7
+ export type ExplorerVerificationStatus = "MATCHED" | "DRIFT" | "UNKNOWN" | "VERIFIED";
8
+ export type ExplorerPressureLevel = "low" | "medium" | "high";
9
+
10
+ export interface SourceSelector {
11
+ path: string;
12
+ symbolId?: string;
13
+ startLine?: number;
14
+ endLine?: number;
15
+ }
16
+
17
+ export interface ExplorerServiceContract {
18
+ schemaVersion: "archcontext.explorer-service/v1";
19
+ bindHost: "127.0.0.1";
20
+ protocol: "http-loopback";
21
+ optIn: true;
22
+ defaultEnabled: false;
23
+ tokenTtlSeconds: number;
24
+ readOnly: true;
25
+ allowedMethods: ["GET"];
26
+ egress: "none";
27
+ }
28
+
29
+ export const EXPLORER_VIEW_IDS = ["system-map", "task-impact", "drift-pressure", "data-flow", "external-integrations"] as const;
30
+ export type ExplorerViewIdV2 = typeof EXPLORER_VIEW_IDS[number];
31
+ export type ExplorerSemanticLevelV2 = "overview" | "context" | "detail";
32
+ export type ExplorerOccurrenceRoleV2 = "subject" | "derived-group";
33
+ export type ExplorerSubjectRefKindV2 =
34
+ | "architecture-entity"
35
+ | "architecture-relation"
36
+ | "architecture-constraint"
37
+ | "code-symbol";
38
+
39
+ export interface AuthorityCursorV1 {
40
+ schemaVersion: "archcontext.authority-cursor/v1";
41
+ repository: ArchitectureRepositoryIdentityV1;
42
+ worktree: ArchitectureWorktreeIdentityV1;
43
+ eventSequence: number;
44
+ eventId: string;
45
+ eventHash: string;
46
+ graphDigest: string;
47
+ evidenceStateDigest: string;
48
+ }
49
+
50
+ export interface ExplorerExpectedCursorV2 {
51
+ headSha: string;
52
+ worktreeDigest: string;
53
+ graphDigest: string;
54
+ observedFactsDigest?: string;
55
+ }
56
+
57
+ export interface ExplorerProjectionQueryV2 {
58
+ schemaVersion: "archcontext.explorer-projection-query/v2";
59
+ viewId: ExplorerViewIdV2;
60
+ semanticLevel?: ExplorerSemanticLevelV2;
61
+ taskSessionId?: string;
62
+ expectedCursor?: ExplorerExpectedCursorV2;
63
+ focus?: { subjectId: string };
64
+ expandedOccurrenceIds?: string[];
65
+ depth: 0 | 1 | 2;
66
+ budget: {
67
+ maxNodes: number;
68
+ maxRelations: number;
69
+ };
70
+ }
71
+
72
+ export interface ExplorerProjectionCursorV2 {
73
+ repository: ArchitectureRepositoryIdentityV1;
74
+ worktree: ArchitectureWorktreeIdentityV1;
75
+ authoritySource: "git" | "ledger";
76
+ authorityCursor: AuthorityCursorV1 | null;
77
+ evidenceAuthorityCursor: AuthorityCursorV1 | null;
78
+ inputManifestDigest: string;
79
+ compatibilityDigest: string;
80
+ graphDigest: string;
81
+ evidenceStateDigest: string;
82
+ observedFactsDigest: string;
83
+ viewDefinitionDigest: string;
84
+ compilerVersion: "archcontext.explorer-view-compiler/v1";
85
+ taskSessionDigest?: string;
86
+ observedAvailability: { status: "ready" | "unavailable"; reasonCode?: string };
87
+ }
88
+
89
+ export interface ProjectionInputManifestV1 {
90
+ schemaVersion: "archcontext.projection-input-manifest/v1";
91
+ repository: ArchitectureRepositoryIdentityV1;
92
+ worktree: ArchitectureWorktreeIdentityV1;
93
+ authoritySource: "git" | "ledger";
94
+ authorityCursor: AuthorityCursorV1 | null;
95
+ evidenceAuthorityCursor: AuthorityCursorV1 | null;
96
+ queryDigest: string;
97
+ graphDigest: string;
98
+ evidenceStateDigest: string;
99
+ observedFactsDigest: string;
100
+ observedAvailability: { status: "ready" | "unavailable"; reasonCode?: string };
101
+ bindingsDigest: string;
102
+ eventBacklinksDigest: string;
103
+ driftDigest: string | null;
104
+ pressureDigest: string | null;
105
+ taskSessionDigest: string | null;
106
+ readPlan: ProjectionReadPlanV1;
107
+ readSet: ProjectionReadSetV1;
108
+ inputDomains: Record<ProjectionInputDomainV1, ProjectionInputDomainStateV1>;
109
+ viewDefinitionDigest: string;
110
+ compilerVersion: "archcontext.explorer-view-compiler/v1";
111
+ tokenRequired: boolean;
112
+ compatibilityDigest: string;
113
+ manifestDigest: string;
114
+ }
115
+
116
+ export type ProjectionInputDomainV1 =
117
+ | "authority"
118
+ | "graph"
119
+ | "evidence"
120
+ | "observed"
121
+ | "bindings"
122
+ | "event-backlinks"
123
+ | "drift"
124
+ | "pressure"
125
+ | "task-session";
126
+
127
+ export type ProjectionInputDomainStateV1 =
128
+ | { requirement: "required"; status: "ready"; digest: string }
129
+ | { requirement: "optional"; status: "ready"; digest: string }
130
+ | { requirement: "optional"; status: "unavailable"; digest: null; reasonCode: string }
131
+ | { requirement: "not-used"; status: "not-used"; digest: null };
132
+
133
+ export const EXPLORER_VIEW_INPUT_REQUIREMENTS = {
134
+ "system-map": {
135
+ authority: "required", graph: "required", evidence: "required", observed: "required", bindings: "required",
136
+ "event-backlinks": "optional", drift: "optional", pressure: "optional", "task-session": "optional"
137
+ },
138
+ "task-impact": {
139
+ authority: "required", graph: "required", evidence: "required", observed: "required", bindings: "required",
140
+ "event-backlinks": "optional", drift: "optional", pressure: "optional", "task-session": "required"
141
+ },
142
+ "drift-pressure": {
143
+ authority: "required", graph: "required", evidence: "required", observed: "required", bindings: "required",
144
+ "event-backlinks": "optional", drift: "required", pressure: "required", "task-session": "optional"
145
+ },
146
+ "data-flow": {
147
+ authority: "required", graph: "required", evidence: "required", observed: "required", bindings: "required",
148
+ "event-backlinks": "optional", drift: "optional", pressure: "optional", "task-session": "optional"
149
+ },
150
+ "external-integrations": {
151
+ authority: "required", graph: "required", evidence: "required", observed: "required", bindings: "required",
152
+ "event-backlinks": "optional", drift: "optional", pressure: "optional", "task-session": "optional"
153
+ }
154
+ } as const satisfies Record<ExplorerViewIdV2, Record<ProjectionInputDomainV1, ProjectionInputDomainStateV1["requirement"]>>;
155
+
156
+ export const PROJECTION_READ_PLANNER_VERSION = "archcontext.projection-read-planner/v1" as const;
157
+ export const EXPLORER_PROJECTION_CACHE_POLICY_SCHEMA_VERSION = "archcontext.explorer-cache-policy/v1" as const;
158
+
159
+ export interface ExplorerProjectionCachePolicyV1 {
160
+ schemaVersion: typeof EXPLORER_PROJECTION_CACHE_POLICY_SCHEMA_VERSION;
161
+ maxEntriesPerScope: number;
162
+ maxBytesPerScope: number;
163
+ maxAgeMs: number;
164
+ maxPinnedEntriesPerScope: number;
165
+ maxPinTtlMs: number;
166
+ }
167
+
168
+ export interface ProjectionReadPlanV1 {
169
+ schemaVersion: "archcontext.projection-read-plan/v1";
170
+ plannerVersion: typeof PROJECTION_READ_PLANNER_VERSION;
171
+ kind: "overview-aggregate" | "bounded-context" | "focused-neighborhood";
172
+ source: "git-authority" | "verified-ledger-current";
173
+ queryDigest: string;
174
+ semanticLevel: ExplorerSemanticLevelV2;
175
+ focusSubjectId: string | null;
176
+ expandedKinds: string[];
177
+ depth: 0 | 1 | 2;
178
+ limits: {
179
+ maxEntities: number;
180
+ maxRelations: number;
181
+ maxConstraints: number;
182
+ maxBindings: number;
183
+ maxBacklinks: number;
184
+ maxGraphRows: number;
185
+ };
186
+ requiredDomains: ProjectionInputDomainV1[];
187
+ ordering: "canonical-id-asc";
188
+ truncation: "hard-limit-with-authoritative-totals";
189
+ planDigest: string;
190
+ }
191
+
192
+ export interface ProjectionReadSetV1 {
193
+ schemaVersion: "archcontext.projection-read-set/v1";
194
+ planDigest: string;
195
+ selectedGraphDigest: string;
196
+ authoritativeTotals: { entities: number; relations: number; constraints: number };
197
+ entityKindTotals: Array<{ kind: string; count: number }>;
198
+ rowsRead: { entities: number; relations: number; constraints: number; bindings: number; backlinks: number };
199
+ truncated: boolean;
200
+ readSetDigest: string;
201
+ }
202
+
203
+ export function explorerProjectionQueryDigestV2(query: ExplorerProjectionQueryV2): string {
204
+ return digestJson({
205
+ schemaVersion: query.schemaVersion,
206
+ viewId: query.viewId,
207
+ semanticLevel: query.semanticLevel ?? "context",
208
+ taskSessionId: query.taskSessionId ?? null,
209
+ focus: query.focus ?? null,
210
+ expandedOccurrenceIds: [...new Set(query.expandedOccurrenceIds ?? [])].sort(),
211
+ depth: query.depth,
212
+ budget: query.budget
213
+ } as unknown as Json);
214
+ }
215
+
216
+ export function canonicalProjectionReadPlanV1(
217
+ query: ExplorerProjectionQueryV2,
218
+ source: ProjectionReadPlanV1["source"]
219
+ ): ProjectionReadPlanV1 {
220
+ if (
221
+ query.schemaVersion !== "archcontext.explorer-projection-query/v2"
222
+ || !(EXPLORER_VIEW_IDS as readonly string[]).includes(query.viewId)
223
+ || !Number.isInteger(query.depth) || query.depth < 0 || query.depth > 2
224
+ || !Number.isInteger(query.budget.maxNodes) || query.budget.maxNodes < 1 || query.budget.maxNodes > 1_000
225
+ || !Number.isInteger(query.budget.maxRelations) || query.budget.maxRelations < 0 || query.budget.maxRelations > 5_000
226
+ ) {
227
+ throw new Error("explorer-projection-query-invalid");
228
+ }
229
+ const semanticLevel = query.semanticLevel ?? "context";
230
+ const kind: ProjectionReadPlanV1["kind"] = semanticLevel === "overview"
231
+ ? "overview-aggregate"
232
+ : query.focus
233
+ ? "focused-neighborhood"
234
+ : "bounded-context";
235
+ const maxEntities = query.budget.maxNodes;
236
+ const maxRelations = query.budget.maxRelations;
237
+ const maxConstraints = Math.max(1, Math.min(2_000, maxEntities * 2));
238
+ const maxBindings = Math.max(1, Math.min(4_000, maxEntities * 4));
239
+ const maxBacklinks = Math.max(1, Math.min(8_000, maxEntities * 8));
240
+ const requirements = EXPLORER_VIEW_INPUT_REQUIREMENTS[query.viewId];
241
+ const withoutDigest = {
242
+ schemaVersion: "archcontext.projection-read-plan/v1" as const,
243
+ plannerVersion: PROJECTION_READ_PLANNER_VERSION,
244
+ kind,
245
+ source,
246
+ queryDigest: explorerProjectionQueryDigestV2(query),
247
+ semanticLevel,
248
+ focusSubjectId: query.focus?.subjectId ?? null,
249
+ expandedKinds: [...new Set((query.expandedOccurrenceIds ?? []).flatMap((id) => {
250
+ const prefix = `occurrence.${query.viewId}.group.kind.`;
251
+ return id.startsWith(prefix) ? [id.slice(prefix.length)] : [];
252
+ }))].sort(),
253
+ depth: query.depth,
254
+ limits: {
255
+ maxEntities,
256
+ maxRelations,
257
+ maxConstraints,
258
+ maxBindings,
259
+ maxBacklinks,
260
+ maxGraphRows: maxEntities + maxRelations + maxConstraints
261
+ },
262
+ requiredDomains: (Object.entries(requirements) as Array<[ProjectionInputDomainV1, ProjectionInputDomainStateV1["requirement"]]>)
263
+ .filter(([, requirement]) => requirement === "required")
264
+ .map(([domain]) => domain)
265
+ .sort(),
266
+ ordering: "canonical-id-asc" as const,
267
+ truncation: "hard-limit-with-authoritative-totals" as const
268
+ };
269
+ return { ...withoutDigest, planDigest: digestJson(withoutDigest as unknown as Json) };
270
+ }
package/src/failure.ts CHANGED
@@ -293,6 +293,9 @@ Object.assign(policies, {
293
293
  "refactor-request-head-changed": {code: "AC_REFACTOR_STALE", message: "The requested HEAD differs from the measured HEAD.", facts: {expectedHeadSha: "head", actualHeadSha: "head"}},
294
294
  "refactor-request-worktree-changed": {code: "AC_REFACTOR_STALE", message: "The requested worktree differs from the measured worktree.", facts: {expectedWorktreeDigest: "sha256", actualWorktreeDigest: "sha256"}},
295
295
  "refactor-measurement-changed": {"code": "AC_REFACTOR_STALE","facts": {"changedFields": "changedFields"},"message": "Refactor measurement changed."},
296
+ "refactor-decision-sparse-write-refused": {"code": "AC_PRECONDITION_FAILED","facts": {"path": "repoPath"},"message": "Refactor decision path is hidden by sparse checkout."},
297
+ "refactor-baseline-metadata-missing": {"code": "AC_REFACTOR_STALE","facts": {"recommendationId": "id"},"message": "Refactor decision lacks baseline outcome or kill-list metadata for clean verification."},
298
+ "refactor-simulate-input-invalid": {"code": "AC_SCHEMA_INVALID","facts": {},"message": "Refactor simulation request is invalid."},
296
299
  "audit-issue-list-inconclusive": {"code": "AC_PRECONDITION_FAILED","facts": {"runId": "id"},"message": "Audit issue list inconclusive."},
297
300
  "audit-issue-create-inconclusive": {"code": "AC_PRECONDITION_FAILED","facts": {"runId": "id","draftId": "id"},"message": "Audit issue create inconclusive."}
298
301
  } as Record<string, Policy>);
@@ -0,0 +1,42 @@
1
+ import {
2
+ Const,
3
+ CountSchema,
4
+ SchemaDocument,
5
+ Sha256DigestSchema,
6
+ StrictObject,
7
+ StringEnum,
8
+ Type,
9
+ type Static
10
+ } from "./schema-kit";
11
+
12
+ /**
13
+ * Multi-worktree CodeGraph shared-base seeding contract (#641), decoupled from `archctx sync`
14
+ * (architecture documentation projection).
15
+ */
16
+ export const INDEX_SEED_SCHEMA_VERSION = "archcontext.index-seed/v1" as const;
17
+
18
+ export const INDEX_SEED_MODES = ["primary-refresh", "worktree-seed", "already-present"] as const;
19
+ export type IndexSeedMode = (typeof INDEX_SEED_MODES)[number];
20
+
21
+ export const INDEX_SEED_WORKTREE_ROLES = ["primary", "linked"] as const;
22
+ export type IndexSeedWorktreeRole = (typeof INDEX_SEED_WORKTREE_ROLES)[number];
23
+
24
+ export const IndexSeedResultBodySchema = StrictObject({
25
+ schemaVersion: Const(INDEX_SEED_SCHEMA_VERSION),
26
+ mode: StringEnum(INDEX_SEED_MODES),
27
+ worktreeRole: StringEnum(INDEX_SEED_WORKTREE_ROLES),
28
+ seededFromBase: Type.Boolean(),
29
+ hardlinkedFiles: CountSchema,
30
+ copiedFiles: CountSchema,
31
+ elapsedMs: Type.Number({ minimum: 0 }),
32
+ indexDigest: Type.Optional(Sha256DigestSchema)
33
+ });
34
+
35
+ export const IndexSeedResultSchema = SchemaDocument({
36
+ $id: "https://archcontext.dev/schemas/runtime/index-seed.schema.json",
37
+ title: "IndexSeedResultV1",
38
+ description: "Result of `archctx index seed` (#641): refreshes or hardlink-seeds private `.codegraph` storage separately from documentation projection.",
39
+ schema: IndexSeedResultBodySchema
40
+ });
41
+
42
+ export type IndexSeedResultV1 = Static<typeof IndexSeedResultSchema>;