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,4 +1,18 @@
1
- import { isRepoRelativePosixPath } from "./schema";
1
+ import { isRepoRelativePosixPath, type Json } from "./schema";
2
+ import {
3
+ Const,
4
+ CountSchema,
5
+ GitOidSchema,
6
+ Nullable,
7
+ OneOf,
8
+ RawEnum,
9
+ SchemaDocument,
10
+ StrictObject,
11
+ Type,
12
+ TypedUnsafe,
13
+ type Static
14
+ } from "./schema-kit";
15
+ import { validateJsonSchema } from "./validator";
2
16
 
3
17
  export const ARCHITECTURE_HISTORY_SCHEMA_VERSION = "archcontext.architecture-history/v1" as const;
4
18
  export const ARCHITECTURE_HISTORY_MERMAID_SCHEMA_VERSION = "archcontext.architecture-history-mermaid/v1" as const;
@@ -12,55 +26,167 @@ export const ARCHITECTURE_HISTORY_DERIVATION_VERSION = "v3" as const;
12
26
  export const ARCHITECTURE_HISTORY_READ_REASONS = ["target-named", "history-row-missing", "history-file-missing", "history-file-mismatch"] as const;
13
27
  export type ArchitectureHistoryReadReason = (typeof ARCHITECTURE_HISTORY_READ_REASONS)[number];
14
28
 
15
- export type HistoryErrorCode = "history-model-layout-unsupported" | "history-model-missing" | "history-model-invalid" | "history-model-too-large";
16
- export interface HistoryNode { id: string; name: string; domain: string | null }
17
- export interface HistoryEdge { source: string; target: string }
18
- export interface HistoryStructureNode { id: string; kind: "capability" | "module" | "component"; name: string; capability: string | null }
19
- export interface HistoryDelta {
20
- baseRev: string | null;
21
- added: Array<Pick<HistoryStructureNode, "id" | "kind" | "capability">>;
22
- removed: Array<Pick<HistoryStructureNode, "id" | "kind" | "capability">>;
23
- renamed: Array<Pick<HistoryStructureNode, "id" | "kind" | "capability"> & { from: string; to: string }>;
24
- edgesChanged: { added: HistoryEdge[]; removed: HistoryEdge[] };
29
+ export const HISTORY_ERROR_CODES = [
30
+ "history-model-layout-unsupported",
31
+ "history-model-missing",
32
+ "history-model-invalid",
33
+ "history-model-too-large"
34
+ ] as const;
35
+
36
+ export const HistoryErrorCodeSchema = RawEnum(HISTORY_ERROR_CODES);
37
+ export type HistoryErrorCode = Static<typeof HistoryErrorCodeSchema>;
38
+
39
+ export const HistoryNodeSchema = StrictObject({
40
+ id: Type.String(),
41
+ name: Type.String(),
42
+ domain: Nullable(Type.String())
43
+ });
44
+ export type HistoryNode = Static<typeof HistoryNodeSchema>;
45
+
46
+ export const HistoryEdgeSchema = StrictObject({
47
+ source: Type.String(),
48
+ target: Type.String()
49
+ });
50
+ export type HistoryEdge = Static<typeof HistoryEdgeSchema>;
51
+
52
+ export const HistoryStructureNodeSchema = StrictObject({
53
+ id: Type.String(),
54
+ kind: RawEnum(["capability", "module", "component"] as const),
55
+ name: Type.String(),
56
+ capability: Nullable(Type.String())
57
+ });
58
+ export type HistoryStructureNode = Static<typeof HistoryStructureNodeSchema>;
59
+
60
+ const HistoryDeltaItemSchema = StrictObject({
61
+ id: Type.String(),
62
+ kind: RawEnum(["capability", "module", "component"] as const),
63
+ capability: Nullable(Type.String())
64
+ });
65
+
66
+ const HistoryRenamedDeltaItemSchema = StrictObject({
67
+ id: Type.String(),
68
+ kind: RawEnum(["capability", "module", "component"] as const),
69
+ capability: Nullable(Type.String()),
70
+ from: Type.String(),
71
+ to: Type.String()
72
+ });
73
+
74
+ export const HistoryDeltaSchema = StrictObject({
75
+ baseRev: Nullable(GitOidSchema),
76
+ added: Type.Array(HistoryDeltaItemSchema),
77
+ removed: Type.Array(HistoryDeltaItemSchema),
78
+ renamed: Type.Array(HistoryRenamedDeltaItemSchema),
79
+ edgesChanged: StrictObject({
80
+ added: Type.Array(HistoryEdgeSchema),
81
+ removed: Type.Array(HistoryEdgeSchema)
82
+ })
83
+ });
84
+ export type HistoryDelta = Static<typeof HistoryDeltaSchema>;
85
+
86
+ const HistoryErrorRecordSchema = StrictObject({
87
+ code: HistoryErrorCodeSchema,
88
+ path: Type.Optional(Type.String({ minLength: 1 }))
89
+ });
90
+
91
+ export const HistoryStateSchema = OneOf([
92
+ StrictObject({
93
+ nodes: Type.Array(HistoryNodeSchema),
94
+ edges: Type.Array(HistoryEdgeSchema),
95
+ structure: Type.Array(HistoryStructureNodeSchema)
96
+ }),
97
+ StrictObject({
98
+ nodes: Type.Null(),
99
+ edges: Type.Null(),
100
+ structure: Type.Null(),
101
+ error: HistoryErrorRecordSchema
102
+ })
103
+ ]);
104
+ export type HistoryState =
105
+ | { nodes: HistoryNode[]; edges: HistoryEdge[]; structure: HistoryStructureNode[]; error?: never }
106
+ | { nodes: null; edges: null; structure: null; error: { code: HistoryErrorCode; path?: string } };
107
+
108
+ export const HistoryMilestoneSchema = OneOf([
109
+ StrictObject({
110
+ rev: GitOidSchema,
111
+ date: Type.String(),
112
+ subject: Type.String(),
113
+ nodes: Type.Array(HistoryNodeSchema),
114
+ edges: Type.Array(HistoryEdgeSchema),
115
+ delta: HistoryDeltaSchema
116
+ }),
117
+ StrictObject({
118
+ rev: GitOidSchema,
119
+ date: Type.String(),
120
+ subject: Type.String(),
121
+ nodes: Type.Null(),
122
+ edges: Type.Null(),
123
+ delta: Type.Null(),
124
+ error: HistoryErrorRecordSchema
125
+ })
126
+ ]);
127
+ export type HistoryMilestone = { rev: string; date: string; subject: string } & (
128
+ | { nodes: HistoryNode[]; edges: HistoryEdge[]; delta: HistoryDelta; error?: never }
129
+ | { nodes: null; edges: null; delta: null; error: { code: HistoryErrorCode; path?: string } }
130
+ );
131
+
132
+ export const ArchitectureHistoryBodySchema = StrictObject({
133
+ schemaVersion: Const(ARCHITECTURE_HISTORY_SCHEMA_VERSION),
134
+ head: GitOidSchema,
135
+ total: CountSchema,
136
+ offset: CountSchema,
137
+ limit: Type.Integer({ minimum: 0, maximum: 1000 }),
138
+ milestones: Type.Array(TypedUnsafe<HistoryMilestone>(HistoryMilestoneSchema))
139
+ });
140
+
141
+ export const ArchitectureHistorySchema = SchemaDocument({
142
+ $id: "https://archcontext.dev/schemas/runtime/architecture-history.schema.json",
143
+ title: "ArchitectureHistory",
144
+ schema: ArchitectureHistoryBodySchema
145
+ });
146
+ export type ArchitectureHistory = Static<typeof ArchitectureHistorySchema>;
147
+
148
+ function isValidDeltaItem(item: { id: string; kind: "capability" | "module" | "component"; capability: string | null }): boolean {
149
+ return item.kind !== "capability" || item.capability === item.id;
25
150
  }
26
- export type HistoryState = { nodes: HistoryNode[]; edges: HistoryEdge[]; structure: HistoryStructureNode[]; error?: never } | { nodes: null; edges: null; structure: null; error: { code: HistoryErrorCode; path?: string } };
27
- export type HistoryMilestone = { rev: string; date: string; subject: string } & ({ nodes: HistoryNode[]; edges: HistoryEdge[]; delta: HistoryDelta; error?: never } | { nodes: null; edges: null; delta: null; error: { code: HistoryErrorCode; path?: string } });
28
- export interface ArchitectureHistory { schemaVersion: typeof ARCHITECTURE_HISTORY_SCHEMA_VERSION; head: string; total: number; offset: number; limit: number; milestones: HistoryMilestone[] }
29
-
30
- const object = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
31
- const string = (v: unknown): v is string => typeof v === "string";
32
- const edge = (v: unknown) => object(v) && string(v.source) && string(v.target);
33
- const kind = (v: unknown) => v === "capability" || v === "module" || v === "component";
34
- const item = (v: unknown) => object(v) && string(v.id) && kind(v.kind) && (v.capability === null || string(v.capability)) && (v.kind !== "capability" || v.capability === v.id);
35
- const structure = (v: unknown) => item(v) && object(v) && string(v.name);
36
- const node = (v: unknown) => object(v) && string(v.id) && string(v.name) && (v.domain === null || string(v.domain));
37
- const errors: readonly string[] = ["history-model-layout-unsupported", "history-model-missing", "history-model-invalid", "history-model-too-large"];
38
- const sha = (v: unknown) => string(v) && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(v);
39
- const count = (v: unknown): v is number => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
40
- const error = (v: unknown) => object(v) && string(v.code) && errors.includes(v.code) && (v.path === undefined || (string(v.path) && isRepoRelativePosixPath(v.path)));
41
- const list = (v: unknown, check: (item: unknown) => unknown) => Array.isArray(v) && v.every(check);
42
151
 
43
152
  /** Cache entries are untrusted and never authority for malformed data. */
44
153
  export function decodeArchitectureHistoryState(value: unknown): HistoryState | undefined {
45
- if (!object(value)) return undefined;
46
- if (value.nodes === null && value.edges === null && value.structure === null && error(value.error)) return value as unknown as HistoryState;
47
- if (value.error === undefined && list(value.nodes, node) && list(value.edges, edge) && list(value.structure, structure)) return value as unknown as HistoryState;
48
- return undefined;
154
+ if (!validateJsonSchema(TypedUnsafe<Json>(HistoryStateSchema), value as Json).valid) return undefined;
155
+ const typed = value as HistoryState;
156
+ if ("error" in typed && typed.error?.path !== undefined && !isRepoRelativePosixPath(typed.error.path)) return undefined;
157
+ if ("structure" in typed && Array.isArray(typed.structure) && !typed.structure.every(isValidDeltaItem)) return undefined;
158
+ return typed;
49
159
  }
50
160
 
51
161
  export function architectureHistoryIssues(value: unknown): string[] {
52
- if (!object(value) || value.schemaVersion !== ARCHITECTURE_HISTORY_SCHEMA_VERSION || !sha(value.head) || !count(value.total) || !count(value.offset) || !count(value.limit) || value.limit > 1000 || !Array.isArray(value.milestones) || value.milestones.length > value.limit || value.milestones.length > Math.max(0, value.total - value.offset)) return ["invalid history envelope"];
162
+ const schemaCheck = validateJsonSchema(TypedUnsafe<Json>(ArchitectureHistorySchema), value as Json);
163
+ if (!schemaCheck.valid) return ["invalid history envelope"];
164
+ const typed = value as ArchitectureHistory;
165
+ if (
166
+ !Number.isSafeInteger(typed.total) ||
167
+ !Number.isSafeInteger(typed.offset) ||
168
+ !Number.isSafeInteger(typed.limit) ||
169
+ typed.milestones.length > typed.limit ||
170
+ typed.milestones.length > Math.max(0, typed.total - typed.offset)
171
+ ) {
172
+ return ["invalid history envelope"];
173
+ }
53
174
  let previousValid: string | null = null;
54
- const valid = value.milestones.every((m: unknown) => {
55
- if (!object(m) || !sha(m.rev) || !string(m.date) || !string(m.subject)) return false;
56
- if (m.nodes === null && m.edges === null && m.delta === null) return error(m.error);
57
- if (m.error !== undefined || !list(m.nodes, node) || !list(m.edges, edge) || !object(m.delta) || (m.delta.baseRev !== null && !sha(m.delta.baseRev)) || (previousValid !== null && m.delta.baseRev !== previousValid) || (previousValid === null && value.offset === 0 && m.delta.baseRev !== null)) return false;
58
- previousValid = m.rev as string;
59
- const renamed = (v: unknown) => item(v) && object(v) && string(v.from) && string(v.to);
60
- return list(m.delta.added, item) && list(m.delta.removed, item) && list(m.delta.renamed, renamed) && object(m.delta.edgesChanged) && list(m.delta.edgesChanged.added, edge) && list(m.delta.edgesChanged.removed, edge);
61
- });
62
- return valid ? [] : ["invalid history milestones"];
175
+ for (const milestone of typed.milestones) {
176
+ if (milestone.delta === null) {
177
+ if (milestone.error.path !== undefined && !isRepoRelativePosixPath(milestone.error.path)) return ["invalid history milestones"];
178
+ continue;
179
+ }
180
+ if (previousValid !== null && milestone.delta.baseRev !== previousValid) return ["invalid history milestones"];
181
+ if (previousValid === null && typed.offset === 0 && milestone.delta.baseRev !== null) return ["invalid history milestones"];
182
+ if (!milestone.delta.added.every(isValidDeltaItem) || !milestone.delta.removed.every(isValidDeltaItem) || !milestone.delta.renamed.every(isValidDeltaItem)) {
183
+ return ["invalid history milestones"];
184
+ }
185
+ previousValid = milestone.rev;
186
+ }
187
+ return [];
63
188
  }
189
+
64
190
  export function decodeArchitectureHistory(value: unknown): ArchitectureHistory | undefined {
65
- return architectureHistoryIssues(value).length === 0 ? value as ArchitectureHistory : undefined;
191
+ return architectureHistoryIssues(value).length === 0 ? (value as ArchitectureHistory) : undefined;
66
192
  }
@@ -1,3 +1,16 @@
1
+ import {
2
+ Const,
3
+ CountSchema,
4
+ NonEmptyStringSchema,
5
+ PositiveIntSchema,
6
+ RawEnum,
7
+ SchemaDocument,
8
+ StrictObject,
9
+ Type,
10
+ UniqueStringArray,
11
+ type Static
12
+ } from "./schema-kit";
13
+
1
14
  export interface ArchitectureSinkSelectorV2 {
2
15
  id: string;
3
16
  path: string;
@@ -174,3 +187,90 @@ export interface ReviewPolicyV1 {
174
187
  /** `default` when the policy file is missing or invalid in any way: every category blocks. */
175
188
  source: "policy-file" | "default";
176
189
  }
190
+
191
+ export const DependencyConstraintEvaluationBodySchema = StrictObject(
192
+ {
193
+ schemaVersion: Const("archcontext.dependency-constraint-evaluation/v1"),
194
+ status: RawEnum(DEPENDENCY_CONSTRAINT_STATUSES),
195
+ coverage: RawEnum(["complete", "partial", "unknown"] as const, {
196
+ description: "`complete` only when an index attested to the evaluated worktree and was not truncated."
197
+ }),
198
+ reasonCodes: UniqueStringArray(RawEnum(DEPENDENCY_CONSTRAINT_REASON_CODES), {
199
+ description: "Why a result is not a complete observation, sorted."
200
+ }),
201
+ constraintIds: Type.Array(NonEmptyStringSchema, {
202
+ description: "The constraints this evaluation covered, in declaration order."
203
+ }),
204
+ importEdgeCount: Type.Integer({
205
+ minimum: 0,
206
+ description: "Import observations the evaluation read; zero when the index did not attest to this tree."
207
+ }),
208
+ unresolvedImports: Type.Array(
209
+ StrictObject({
210
+ from: NonEmptyStringSchema,
211
+ specifier: NonEmptyStringSchema
212
+ }),
213
+ {
214
+ description: "Repository-local specifiers from constrained files that resolved to no file."
215
+ }
216
+ ),
217
+ violations: Type.Array(
218
+ StrictObject({
219
+ constraintId: NonEmptyStringSchema,
220
+ fromPath: NonEmptyStringSchema,
221
+ toPath: NonEmptyStringSchema,
222
+ fromNode: NonEmptyStringSchema,
223
+ toNode: NonEmptyStringSchema,
224
+ fromLayer: Type.Optional(NonEmptyStringSchema),
225
+ toLayer: Type.Optional(NonEmptyStringSchema),
226
+ severity: RawEnum(["error", "warning"] as const)
227
+ }),
228
+ {
229
+ description: "One record per (constraint, from path, to path), sorted by those keys."
230
+ }
231
+ ),
232
+ layerEdges: Type.Optional(
233
+ Type.Array(
234
+ StrictObject({
235
+ constraintId: NonEmptyStringSchema,
236
+ fromLayer: NonEmptyStringSchema,
237
+ toLayer: NonEmptyStringSchema,
238
+ imports: PositiveIntSchema
239
+ }),
240
+ {
241
+ description:
242
+ "Resolved imports between two layers of one `layer-direction` constraint. An import counts only when every owner of each endpoint carries one shared layer listed in the rule. Present only with a `layer-direction` constraint, `status` `pass` or `violated`, and `coverage` `complete`; otherwise absent. When present it may be an empty list, and it is sorted by `(constraintId, fromLayer, toLayer)`."
243
+ }
244
+ )
245
+ ),
246
+ warnings: Type.Array(NonEmptyStringSchema, {
247
+ description:
248
+ "Declaration-reader warnings, such as an unsupported rule. Every unevaluated constraint type produces one, because a validated constraint is not proof that its rule was evaluated."
249
+ })
250
+ },
251
+ {
252
+ allOf: [
253
+ {
254
+ description: "The layer edges are an observation, so they exist only for a settled verdict over complete coverage.",
255
+ if: { required: ["layerEdges"] },
256
+ then: {
257
+ properties: {
258
+ status: { enum: ["pass", "violated"] },
259
+ coverage: { const: "complete" }
260
+ }
261
+ }
262
+ }
263
+ ]
264
+ }
265
+ );
266
+
267
+ export const DependencyConstraintEvaluationSchema = SchemaDocument({
268
+ $id: "https://archcontext.dev/schemas/runtime/dependency-constraint-evaluation.schema.json",
269
+ title: "DependencyConstraintEvaluationV1",
270
+ description:
271
+ "The data of `archctx constraints check`: a read-only evaluation of the model's dependency constraints against observed import edges. `warnings` is added by the constraints-check command from the declaration reader, so it is not part of the evaluator's own type. Without code facts that attest to the measured tree, the evaluation still answers, but `coverage` is not `complete` and the import observations are dropped rather than reported as facts about some other tree.",
272
+ schema: DependencyConstraintEvaluationBodySchema
273
+ });
274
+
275
+ export type DependencyConstraintEvaluationReportV1 = Static<typeof DependencyConstraintEvaluationSchema>;
276
+
@@ -0,0 +1,228 @@
1
+ import type { ArchitectureDebtReportV1 } from "./architecture-debt";
2
+ import type { ProjectionSliceV1 } from "./projection";
3
+ import type { RuntimeVerifyV1 } from "./runtime-verify";
4
+ import type { ArchContextError } from "./schema";
5
+ import {
6
+ ArchContextErrorSchema,
7
+ CodeFactsStateSchema,
8
+ Const,
9
+ GitOidSchema,
10
+ JsonObjectSchema,
11
+ NullableType,
12
+ OneOf,
13
+ Ref,
14
+ RepoPathSchema,
15
+ SchemaDocument,
16
+ Sha256DigestSchema,
17
+ StrictObject,
18
+ StrictSemverSchema,
19
+ StringEnum,
20
+ Type,
21
+ TypedUnsafe,
22
+ UniqueStringArray,
23
+ type Static
24
+ } from "./schema-kit";
25
+
26
+ export const CLI_HELP_SCHEMA_VERSION = "archcontext.cli-help/v1" as const;
27
+ export const CLI_CHECK_SCHEMA_VERSION = "archcontext.cli-check/v1" as const;
28
+ export const PATH_CONTEXT_SCHEMA_VERSION = "archcontext.path-context/v1" as const;
29
+ export const SYNC_CHECK_SCHEMA_VERSION = "archcontext.sync-check/v1" as const;
30
+ export const RESOLVE_PATH_SCHEMA_VERSION = "archcontext.resolve-path/v1" as const;
31
+ export const RESOLVE_PATHS_BATCH_SCHEMA_VERSION = "archcontext.resolve-paths-batch/v1" as const;
32
+
33
+ /**
34
+ * #640: Reported by `archctx doctor --json` and `archctx capabilities --json` so `repo-harness`
35
+ * can verify CodeGraph readiness without parsing unstructured stderr.
36
+ */
37
+ export const DoctorCodeFactsIssueSchema = StrictObject({
38
+ code: Type.String({ minLength: 1 }),
39
+ message: Type.String({ minLength: 1 })
40
+ });
41
+
42
+ export const DoctorCodeFactsBodySchema = StrictObject({
43
+ state: CodeFactsStateSchema,
44
+ codeGraphVersion: Type.String({ minLength: 1 }),
45
+ issues: Type.Array(DoctorCodeFactsIssueSchema)
46
+ });
47
+
48
+ export const DoctorCodeFactsSchema = SchemaDocument({
49
+ $id: "https://archcontext.dev/schemas/runtime/doctor-code-facts.schema.json",
50
+ title: "DoctorCodeFactsV1",
51
+ description: "Machine-readable CodeGraph readiness report returned in `archctx doctor --json` and capability diagnostics.",
52
+ schema: DoctorCodeFactsBodySchema
53
+ });
54
+ export type DoctorCodeFactsV1 = Static<typeof DoctorCodeFactsSchema>;
55
+
56
+ /** #640: `archctx help --json` command surface for downstream command-disposition checks. */
57
+ export const CliHelpOutputBodySchema = StrictObject({
58
+ commands: Type.Array(Type.String({ minLength: 1 }), { uniqueItems: true }),
59
+ examples: Type.Optional(Type.Array(Type.String({ minLength: 1 })))
60
+ });
61
+
62
+ export const CliHelpOutputSchema = SchemaDocument({
63
+ $id: "https://archcontext.dev/schemas/runtime/cli-help.schema.json",
64
+ title: "CliHelpOutputV1",
65
+ description: "Structured `archctx help --json` payload listing supported commands and usage examples.",
66
+ schema: CliHelpOutputBodySchema
67
+ });
68
+ export type CliHelpOutputV1 = Static<typeof CliHelpOutputSchema>;
69
+
70
+ /** #640: `archctx resolve --path` & `archctx resolve --paths-from` per-path ownership result. */
71
+ export const ResolvePathResultSchema = StrictObject({
72
+ path: Type.String({ minLength: 1 }),
73
+ matched: Type.Boolean(),
74
+ ambiguous: Type.Boolean(),
75
+ owningCapabilityId: NullableType("string", { minLength: 1 }),
76
+ stableId: Type.Optional(Type.String({ minLength: 1 })),
77
+ kind: Type.Optional(Type.String({ minLength: 1 })),
78
+ name: Type.Optional(Type.String()),
79
+ source: Type.Optional(JsonObjectSchema),
80
+ extensions: Type.Optional(JsonObjectSchema),
81
+ candidates: Type.Optional(Type.Array(Type.String({ minLength: 1 })))
82
+ });
83
+ export type ResolvePathResultV1 = Static<typeof ResolvePathResultSchema>;
84
+
85
+ export const ResolvePathsBatchResultBodySchema = StrictObject({
86
+ results: Type.Array(ResolvePathResultSchema)
87
+ });
88
+
89
+ export const ResolvePathsBatchResultSchema = SchemaDocument({
90
+ $id: "https://archcontext.dev/schemas/runtime/resolve-path.schema.json",
91
+ title: "ResolvePathsBatchResultV1",
92
+ description: "Batch ownership resolution output for `archctx resolve --paths-from`.",
93
+ schema: ResolvePathsBatchResultBodySchema
94
+ });
95
+ export type ResolvePathsBatchResultV1 = Static<typeof ResolvePathsBatchResultSchema>;
96
+
97
+ /** #642: Non-intrusive host-ownership isolation controls for `archctx init` and `archctx sync`. */
98
+ export const HostOwnershipIsolationOptionsSchema = StrictObject({
99
+ modelOnly: Type.Optional(Type.Boolean()),
100
+ noHooks: Type.Optional(Type.Boolean()),
101
+ noSkills: Type.Optional(Type.Boolean()),
102
+ noInstructions: Type.Optional(Type.Boolean())
103
+ });
104
+ export type HostOwnershipIsolationOptions = Static<typeof HostOwnershipIsolationOptionsSchema>;
105
+
106
+ /** #640 & #642: Unified gate output for `archctx check --changed` and `archctx check --base <ref> [--slice]`. */
107
+ export const CliCheckChangedOutputSchema = StrictObject({
108
+ schemaVersion: Const(CLI_CHECK_SCHEMA_VERSION),
109
+ mode: Const("changed"),
110
+ status: StringEnum(["pass", "findings"]),
111
+ exitCode: TypedUnsafe<0 | 2>({ type: "integer", enum: [0, 2] }),
112
+ changedPaths: Type.Array(RepoPathSchema),
113
+ debt: Ref<ArchitectureDebtReportV1>("https://archctx.repoharness.com/schemas/runtime/architecture-debt.schema.json")
114
+ });
115
+ export type CliCheckChangedOutputV1 = Static<typeof CliCheckChangedOutputSchema>;
116
+
117
+ const CliCheckSliceArmSchema = OneOf([
118
+ StrictObject({
119
+ ok: Const(true),
120
+ data: Ref<ProjectionSliceV1>("https://archcontext.dev/schemas/runtime/projection-slice.schema.json")
121
+ }),
122
+ StrictObject({
123
+ ok: Const(false),
124
+ error: ArchContextErrorSchema as unknown as ReturnType<typeof StrictObject>
125
+ })
126
+ ]);
127
+ export type CliCheckSliceResult = { ok: true; data: ProjectionSliceV1 } | { ok: false; error: ArchContextError };
128
+
129
+ export const CliCheckPrOutputSchema = StrictObject({
130
+ schemaVersion: Const(CLI_CHECK_SCHEMA_VERSION),
131
+ mode: Const("pr"),
132
+ status: StringEnum(["pass", "findings"]),
133
+ exitCode: TypedUnsafe<0 | 2>({ type: "integer", enum: [0, 2] }),
134
+ base: Type.String({ minLength: 1 }),
135
+ baseSha: GitOidSchema,
136
+ headSha: GitOidSchema,
137
+ blockingChecks: Type.Array(Type.String({ minLength: 1 })),
138
+ verify: Ref<RuntimeVerifyV1>("https://archcontext.dev/schemas/runtime/runtime-verify.schema.json"),
139
+ slice: Type.Optional(CliCheckSliceArmSchema as unknown as typeof JsonObjectSchema)
140
+ });
141
+ export type CliCheckPrOutputV1 = Omit<Static<typeof CliCheckPrOutputSchema>, "slice"> & {
142
+ slice?: CliCheckSliceResult;
143
+ };
144
+
145
+ export const CliCheckOutputSchema = SchemaDocument({
146
+ $id: "https://archcontext.dev/schemas/runtime/cli-check.schema.json",
147
+ title: "CliCheckOutputV1",
148
+ description: "Unified read-only gate payload for `archctx check --changed` and `archctx check --base <ref> [--slice]`.",
149
+ schema: OneOf([CliCheckChangedOutputSchema, CliCheckPrOutputSchema])
150
+ });
151
+ export type CliCheckOutputV1 = CliCheckChangedOutputV1 | CliCheckPrOutputV1;
152
+
153
+ /** #642: Composable path-context payload for `archctx context --path <p>... --json`. */
154
+ export const PathContextOutputSchema = SchemaDocument({
155
+ $id: "https://archcontext.dev/schemas/runtime/path-context.schema.json",
156
+ title: "PathContextOutputV1",
157
+ description: "Read-only architecture ownership and relation context resolved for explicit paths.",
158
+ schema: StrictObject({
159
+ schemaVersion: Const(PATH_CONTEXT_SCHEMA_VERSION),
160
+ paths: Type.Array(RepoPathSchema),
161
+ owners: Type.Array(ResolvePathResultSchema),
162
+ nodes: Type.Array(JsonObjectSchema),
163
+ relations: Type.Array(JsonObjectSchema)
164
+ })
165
+ });
166
+ export type PathContextOutputV1 = Static<typeof PathContextOutputSchema>;
167
+
168
+ /** #642 & #640: Read-only projection freshness output for `archctx sync --check --json`. */
169
+ export const SyncCheckOutputSchema = SchemaDocument({
170
+ $id: "https://archcontext.dev/schemas/runtime/sync-check.schema.json",
171
+ title: "SyncCheckOutputV1",
172
+ description: "Read-only projection freshness check returned by `archctx sync --check --json`.",
173
+ schema: StrictObject({
174
+ schemaVersion: Const(SYNC_CHECK_SCHEMA_VERSION),
175
+ check: Const(true),
176
+ fresh: Type.Boolean(),
177
+ profile: StringEnum(["default", "repo-harness/v1"]),
178
+ includeInstructions: Type.Boolean(),
179
+ modelDigest: Sha256DigestSchema,
180
+ pendingGeneratedPaths: Type.Array(RepoPathSchema),
181
+ drift: Type.Optional(JsonObjectSchema)
182
+ })
183
+ });
184
+ export type SyncCheckOutputV1 = Static<typeof SyncCheckOutputSchema>;
185
+
186
+ export const ARCHCTX_CAPABILITIES_V2_SCHEMA_VERSION = "archcontext.capabilities/v1" as const;
187
+
188
+ export function buildCapabilitiesSchemaDocument(input: {
189
+ projectionRequest: string;
190
+ projectionResult: string;
191
+ architectureRefreshSignal: string;
192
+ architectureDocsRenderer: string;
193
+ agentContextRenderer: string;
194
+ featureExamples: readonly string[];
195
+ }) {
196
+ return SchemaDocument({
197
+ $id: "https://archcontext.dev/schemas/runtime/archctx-capabilities.schema.json",
198
+ title: "ArchctxCapabilitiesV1",
199
+ schema: StrictObject({
200
+ schemaVersion: Const(ARCHCTX_CAPABILITIES_V2_SCHEMA_VERSION),
201
+ package: StrictObject({
202
+ name: Const("archctx"),
203
+ version: StrictSemverSchema
204
+ }),
205
+ protocols: StrictObject({
206
+ projectionRequest: Const(input.projectionRequest),
207
+ projectionResult: Const(input.projectionResult),
208
+ architectureRefreshSignal: Const(input.architectureRefreshSignal)
209
+ }),
210
+ renderers: StrictObject({
211
+ architectureDocs: Const(input.architectureDocsRenderer),
212
+ agentContext: Const(input.agentContextRenderer)
213
+ }),
214
+ features: UniqueStringArray(
215
+ Type.String({
216
+ pattern: "^[a-z0-9]+(-[a-z0-9]+)*-v[0-9]+$",
217
+ description:
218
+ "One feature flag: a lowercase kebab-case name that ends in a version suffix (-v1, -v2, ...). The pattern is open, so a validator built from this schema accepts flags that a later archctx adds. A consumer must ignore a flag it does not know. examples lists the flags this schema version knows.",
219
+ examples: [...input.featureExamples]
220
+ }),
221
+ { minItems: 3 }
222
+ ),
223
+ codeFacts: Type.Optional(DoctorCodeFactsBodySchema)
224
+ })
225
+ });
226
+ }
227
+
228
+ export const STRICT_SEMVER_PATTERN_CHECK = StrictSemverSchema;