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,12 +1,8 @@
1
1
  /**
2
- * Guards that keep a caller from forging a review conclusion, and the envelope shape the remaining
3
- * Cloud surfaces still record.
2
+ * Guards that keep a caller from forging a review conclusion.
4
3
  *
5
- * These live here, not with the rest of the retired governance surface, because they survive ADR-0053:
6
- * the runtime daemon's `completeTask` and the mcp-local `complete-task` tool use the attestation-field
7
- * guards for local review, and `schemas/cloud/cloud-egress-envelope.schema.json` plus the ADR-0035
8
- * privacy rule keep `CloudEgressEnvelope`. Keeping them in `github-governance.ts` would have made that
9
- * file undeletable without breaking local review.
4
+ * These survive ADR-0053 so local review and attestation checks reject caller-supplied conclusion
5
+ * or attestation fields. Keeping them outside governance files allows independent cleanup.
10
6
  */
11
7
 
12
8
  export const CALLER_PROVIDED_ATTESTATION_FIELDS = [
@@ -72,19 +68,3 @@ export function assertNoLlmAdvisoryConclusionFields(value: unknown): void {
72
68
  const fields = findLlmAdvisoryForbiddenFields(value);
73
69
  if (fields.length > 0) throw new Error(`llm-advisory-conclusion-field-forbidden: ${fields.join(",")}`);
74
70
  }
75
-
76
- /**
77
- * What a remaining Cloud surface records when it calls the GitHub API. ADR-0035's privacy rule and
78
- * `schemas/cloud/cloud-egress-envelope.schema.json` both depend on this shape.
79
- */
80
- export interface CloudEgressEnvelope {
81
- schemaVersion: "archcontext.cloud-egress/v1";
82
- requestId: string;
83
- category: "github.metadata" | "github.pull-head" | "github.check-list-for-ref" | "github.check-create" | "github.check-update";
84
- method: "GET" | "POST" | "PATCH";
85
- host: "api.github.com";
86
- pathTemplate: string;
87
- statusCode: number;
88
- latencyMs: number;
89
- recordedAt: string;
90
- }
@@ -6,6 +6,19 @@ import type { ArchitectureFlowSelectorCheckV1 } from "./projection";
6
6
  import type { ProjectionPrVerificationV1 } from "./projection-writer";
7
7
  import type { ArchContextError } from "./schema";
8
8
  import type { StateMachineCheckReportV1 } from "./state-machine";
9
+ import {
10
+ ArchContextErrorSchema,
11
+ Const,
12
+ GitOidSchema,
13
+ JsonValueSchema,
14
+ OneOf,
15
+ RawEnum,
16
+ Ref,
17
+ SchemaDocument,
18
+ Sha256DigestSchema,
19
+ StrictObject,
20
+ Type
21
+ } from "./schema-kit";
9
22
 
10
23
  export const RUNTIME_VERIFY_SCHEMA_VERSION = "archcontext.runtime-verify/v1" as const;
11
24
 
@@ -26,3 +39,77 @@ export interface RuntimeVerifyV1 {
26
39
  debt: RuntimeVerifyCheck<ArchitectureDebtReportV1>;
27
40
  };
28
41
  }
42
+
43
+ const StringsRefSchema = Type.Array(Type.String());
44
+ const PassedEnvelopeSchema = StrictObject({
45
+ ok: Const(true),
46
+ data: JsonValueSchema
47
+ });
48
+ const FailedEnvelopeSchema = StrictObject({
49
+ ok: Const(false),
50
+ error: ArchContextErrorSchema
51
+ });
52
+ const VerifyValidationBodySchema = StrictObject({
53
+ valid: Type.Boolean(),
54
+ errors: Ref<string[]>("#/$defs/strings"),
55
+ modelDigest: Sha256DigestSchema,
56
+ referenceErrors: Type.Optional(Ref<string[]>("#/$defs/strings")),
57
+ layerOrderErrors: Type.Optional(Ref<string[]>("#/$defs/strings")),
58
+ allowedTargetErrors: Type.Optional(Ref<string[]>("#/$defs/strings")),
59
+ warnings: Type.Optional(Ref<string[]>("#/$defs/strings")),
60
+ diagnostics: Type.Optional(
61
+ Type.Array(
62
+ StrictObject({
63
+ path: Type.String(),
64
+ code: RawEnum(["missing-file", "schema-version-missing", "node-schema-invalid"] as const),
65
+ error: Type.String()
66
+ })
67
+ )
68
+ ),
69
+ nodeSchemaErrors: Type.Optional(
70
+ Type.Array(
71
+ StrictObject({
72
+ path: Type.String(),
73
+ error: Type.String()
74
+ })
75
+ )
76
+ )
77
+ });
78
+
79
+ function verifyCheckArm(dataSchema: Record<string, unknown>) {
80
+ return OneOf([
81
+ Ref("#/$defs/failed"),
82
+ Type.Unsafe({
83
+ allOf: [{ $ref: "#/$defs/passed" }, { properties: { data: dataSchema } }]
84
+ })
85
+ ]);
86
+ }
87
+
88
+ export const RuntimeVerifyBodySchema = StrictObject({
89
+ schemaVersion: Const(RUNTIME_VERIFY_SCHEMA_VERSION),
90
+ base: Type.String({ minLength: 1 }),
91
+ baseSha: Ref<string>("#/$defs/oid"),
92
+ headSha: Ref<string>("#/$defs/oid"),
93
+ checks: StrictObject({
94
+ validate: verifyCheckArm({ $ref: "#/$defs/validation" }),
95
+ flows: verifyCheckArm({ $ref: "flow-selector-check.schema.json" }),
96
+ "state-machines": verifyCheckArm({ $ref: "state-machine-check.schema.json" }),
97
+ constraints: verifyCheckArm({ $ref: "dependency-constraint-evaluation.schema.json" }),
98
+ docs: verifyCheckArm({ $ref: "docs-anchors.schema.json" }),
99
+ projection: verifyCheckArm({ $ref: "projection-pr-verification.schema.json" }),
100
+ debt: verifyCheckArm({ $ref: "https://archctx.repoharness.com/schemas/runtime/architecture-debt.schema.json" })
101
+ })
102
+ });
103
+
104
+ export const RuntimeVerifySchema = SchemaDocument({
105
+ $id: "https://archcontext.dev/schemas/runtime/runtime-verify.schema.json",
106
+ title: "RuntimeVerifyV1",
107
+ schema: RuntimeVerifyBodySchema,
108
+ $defs: {
109
+ oid: GitOidSchema,
110
+ strings: StringsRefSchema,
111
+ passed: PassedEnvelopeSchema,
112
+ failed: FailedEnvelopeSchema,
113
+ validation: VerifyValidationBodySchema
114
+ }
115
+ });
@@ -0,0 +1,183 @@
1
+ import {
2
+ Type,
3
+ type ArrayOptions,
4
+ type IntegerOptions,
5
+ type NumberOptions,
6
+ type ObjectOptions,
7
+ type SchemaOptions,
8
+ type Static,
9
+ type StringOptions,
10
+ type TProperties,
11
+ type TSchema,
12
+ type TUnsafe
13
+ } from "@sinclair/typebox";
14
+ import type { Json } from "./schema";
15
+
16
+ export { Type, type Static, type TSchema };
17
+
18
+ export const JSON_SCHEMA_DRAFT_2020_12 = "https://json-schema.org/draft/2020-12/schema" as const;
19
+
20
+ export const SHA256_DIGEST_REGEX = "^sha256:[a-f0-9]{64}$";
21
+ export const GIT_OID_REGEX = "^(?:[a-f0-9]{40}|[a-f0-9]{64})$";
22
+ export const GIT_COMMIT_SHA_REGEX = "^[a-f0-9]{40}$";
23
+ export const SEMVER_REGEX = "^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$";
24
+ export const STRICT_SEMVER_REGEX =
25
+ "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$";
26
+
27
+ export function StrictObject<T extends TProperties>(properties: T, options: ObjectOptions = {}) {
28
+ return Type.Object(properties, { additionalProperties: false, ...options });
29
+ }
30
+
31
+ export function LooseObject<T extends TProperties>(properties: T, options: ObjectOptions = {}) {
32
+ return Type.Object(properties, options);
33
+ }
34
+
35
+ export function StringEnum<const T extends readonly [string, ...string[]]>(
36
+ values: T,
37
+ options: SchemaOptions = {}
38
+ ): TUnsafe<T[number]> {
39
+ return Type.Unsafe<T[number]>({ ...options, type: "string", enum: [...values] });
40
+ }
41
+
42
+ export function RawEnum<const T extends readonly [string, ...string[]]>(
43
+ values: T,
44
+ options: SchemaOptions = {}
45
+ ): TUnsafe<T[number]> {
46
+ return Type.Unsafe<T[number]>({ ...options, enum: [...values] });
47
+ }
48
+
49
+ export function Const<const T extends string | number | boolean>(
50
+ value: T,
51
+ options: SchemaOptions = {}
52
+ ): TUnsafe<T> {
53
+ return Type.Unsafe<T>({ ...options, const: value });
54
+ }
55
+
56
+ export function OneOf<const T extends TSchema[]>(
57
+ schemas: [...T],
58
+ options: SchemaOptions = {}
59
+ ): TUnsafe<{ [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never }[number]> {
60
+ return Type.Unsafe({ ...options, oneOf: schemas });
61
+ }
62
+
63
+ export function AnyOf<const T extends TSchema[]>(
64
+ schemas: [...T],
65
+ options: SchemaOptions = {}
66
+ ): TUnsafe<{ [K in keyof T]: T[K] extends TSchema ? Static<T[K]> : never }[number]> {
67
+ return Type.Unsafe({ ...options, anyOf: schemas });
68
+ }
69
+
70
+ export function Nullable<T extends TSchema>(schema: T, options: SchemaOptions = {}): TUnsafe<Static<T> | null> {
71
+ return OneOf([schema, Type.Null()], options) as TUnsafe<Static<T> | null>;
72
+ }
73
+
74
+ export function NullableType<const P extends "string" | "integer" | "number" | "boolean">(
75
+ primitive: P,
76
+ options: SchemaOptions & StringOptions & NumberOptions & IntegerOptions = {}
77
+ ): TUnsafe<
78
+ (P extends "string" ? string : P extends "boolean" ? boolean : number) | null
79
+ > {
80
+ return Type.Unsafe({ ...options, type: [primitive, "null"] });
81
+ }
82
+
83
+ export function RecordOf<T extends TSchema>(
84
+ valueSchema: T,
85
+ options: SchemaOptions = {}
86
+ ): TUnsafe<Record<string, Static<T>>> {
87
+ return Type.Unsafe<Record<string, Static<T>>>({
88
+ ...options,
89
+ type: "object",
90
+ additionalProperties: valueSchema
91
+ });
92
+ }
93
+
94
+ export function Ref<Out = unknown>(ref: string, options: SchemaOptions = {}): TUnsafe<Out> {
95
+ return Type.Unsafe<Out>({ ...options, $ref: ref });
96
+ }
97
+
98
+ export function TypedUnsafe<Out>(rawSchema: Record<string, unknown>): TUnsafe<Out> {
99
+ return Type.Unsafe<Out>(rawSchema);
100
+ }
101
+
102
+ export function UniqueStringArray<T extends TSchema = typeof BoundedStringSchema>(
103
+ itemSchema: T = BoundedStringSchema as unknown as T,
104
+ options: ArrayOptions = {}
105
+ ) {
106
+ return Type.Array(itemSchema, { uniqueItems: true, ...options });
107
+ }
108
+
109
+ export function SchemaDocument<T extends TSchema>(input: {
110
+ $id: string;
111
+ title: string;
112
+ schema: T;
113
+ description?: string;
114
+ $defs?: Record<string, TSchema>;
115
+ }): T {
116
+ const { $id, title, schema, description, $defs } = input;
117
+ const { $schema: _s, $id: _i, title: _t, description: _d, ...body } = schema as unknown as Record<string, unknown>;
118
+ const ordered: Record<string, unknown> = {
119
+ $schema: JSON_SCHEMA_DRAFT_2020_12,
120
+ $id,
121
+ title
122
+ };
123
+ if (description !== undefined) ordered.description = description;
124
+ else if (typeof schema.description === "string") ordered.description = schema.description;
125
+ for (const [key, value] of Object.entries(body)) {
126
+ ordered[key] = value;
127
+ }
128
+ if ($defs && Object.keys($defs).length > 0) {
129
+ ordered.$defs = $defs;
130
+ }
131
+ return ordered as unknown as T;
132
+ }
133
+
134
+ export function serializeSchemaDocument(schema: TSchema): string {
135
+ const plain = JSON.parse(JSON.stringify(schema)) as unknown;
136
+ return `${JSON.stringify(plain, null, 2)}\n`;
137
+ }
138
+
139
+ export const NonEmptyStringSchema = Type.String({ minLength: 1 });
140
+ export const BoundedStringSchema = Type.String({ minLength: 1, maxLength: 1024 });
141
+ export const CountSchema = Type.Integer({ minimum: 0 });
142
+ export const PositiveIntSchema = Type.Integer({ minimum: 1 });
143
+ export const Sha256DigestSchema = Type.String({ pattern: SHA256_DIGEST_REGEX });
144
+ export const GitOidSchema = Type.String({ pattern: GIT_OID_REGEX });
145
+ export const GitCommitShaSchema = Type.String({ pattern: GIT_COMMIT_SHA_REGEX });
146
+ export const SemverSchema = Type.String({ pattern: SEMVER_REGEX });
147
+ export const StrictSemverSchema = Type.String({ pattern: STRICT_SEMVER_REGEX });
148
+
149
+ export const RepoPathSchema: TUnsafe<string> = TypedUnsafe<string>({
150
+ type: "string",
151
+ minLength: 1,
152
+ not: {
153
+ anyOf: [
154
+ { pattern: "^/" },
155
+ { pattern: "\\\\" },
156
+ { pattern: "(^|/)\\.\\.(/|$)" }
157
+ ]
158
+ }
159
+ });
160
+
161
+ export const JsonValueSchema: TUnsafe<Json> = Type.Unsafe<Json>({});
162
+ export const JsonObjectSchema: TUnsafe<{ [key: string]: Json }> = Type.Unsafe<{ [key: string]: Json }>({
163
+ type: "object"
164
+ });
165
+
166
+ export const SeveritySchema = RawEnum(["notice", "warning", "error", "critical"] as const);
167
+
168
+ export const CodeFactsStateSchema = StringEnum([
169
+ "ready",
170
+ "not-ready",
171
+ "index-missing",
172
+ "unavailable"
173
+ ] as const);
174
+
175
+ export const ArchContextErrorSchema = StrictObject({
176
+ code: Type.String({ pattern: "^AC_[A-Z_]+$" }),
177
+ message: Type.String(),
178
+ severity: SeveritySchema,
179
+ retryable: Type.Boolean(),
180
+ action: Type.String(),
181
+ reasonCode: Type.Optional(Type.String()),
182
+ details: Type.Optional(JsonObjectSchema)
183
+ });
@@ -0,0 +1,73 @@
1
+ import { DependencyConstraintEvaluationSchema } from "./architecture";
2
+ import {
3
+ ArchitectureDebtDeltaReportSchema,
4
+ ArchitectureDebtHookCheckpointSchema,
5
+ ArchitectureDebtReportSchema
6
+ } from "./architecture-debt";
7
+ import { ArchitectureHistorySchema } from "./architecture-history";
8
+ import {
9
+ CliCheckOutputSchema,
10
+ CliHelpOutputSchema,
11
+ DoctorCodeFactsSchema,
12
+ PathContextOutputSchema,
13
+ ResolvePathsBatchResultSchema,
14
+ SyncCheckOutputSchema
15
+ } from "./cli-read";
16
+ import { DocsAnchorsReportSchema } from "./docs-anchors";
17
+ import { IndexSeedResultSchema } from "./index-seed";
18
+ import { CapabilityDependenciesSchema } from "./ownership-dependencies";
19
+ import { ProductVersionManifestSchema } from "./product-version";
20
+ import {
21
+ ArchctxCapabilitiesSchema,
22
+ ArchitectureFlowSelectorCheckSchema,
23
+ ProjectionSliceSchema
24
+ } from "./projection";
25
+ import {
26
+ RefImpactBatchRequestSchema,
27
+ RefImpactBatchSchema,
28
+ RefImpactSchema
29
+ } from "./ref-impact";
30
+ import {
31
+ RefactorDecisionFileSchema,
32
+ RefactorScanV2Schema,
33
+ RefactorSimulateV1Schema,
34
+ RefactorVerifyV2Schema
35
+ } from "./refactor-v2";
36
+ import { RuntimeVerifySchema } from "./runtime-verify";
37
+ import type { TSchema } from "./schema-kit";
38
+ import { StateMachineCheckReportSchema } from "./state-machine";
39
+
40
+ /**
41
+ * Single-source TypeBox -> JSON Schema registry.
42
+ * Every path listed here is generated directly from TypeScript TypeBox schemas and verified
43
+ * against `schemas/` in CI so `.schema.json` files never drift from runtime contracts.
44
+ */
45
+ export const CONTRACT_SCHEMA_REGISTRY: Readonly<Record<string, TSchema>> = {
46
+ "schemas/repo/refactor-decision.schema.json": RefactorDecisionFileSchema,
47
+ "schemas/runtime/archctx-capabilities.schema.json": ArchctxCapabilitiesSchema,
48
+ "schemas/runtime/architecture-debt-delta.schema.json": ArchitectureDebtDeltaReportSchema,
49
+ "schemas/runtime/architecture-debt.schema.json": ArchitectureDebtReportSchema,
50
+ "schemas/runtime/architecture-history.schema.json": ArchitectureHistorySchema,
51
+ "schemas/runtime/capability-dependencies.schema.json": CapabilityDependenciesSchema,
52
+ "schemas/runtime/cli-check.schema.json": CliCheckOutputSchema,
53
+ "schemas/runtime/cli-help.schema.json": CliHelpOutputSchema,
54
+ "schemas/runtime/dependency-constraint-evaluation.schema.json": DependencyConstraintEvaluationSchema,
55
+ "schemas/runtime/docs-anchors.schema.json": DocsAnchorsReportSchema,
56
+ "schemas/runtime/doctor-code-facts.schema.json": DoctorCodeFactsSchema,
57
+ "schemas/runtime/flow-selector-check.schema.json": ArchitectureFlowSelectorCheckSchema,
58
+ "schemas/runtime/hook-debt-checkpoint.schema.json": ArchitectureDebtHookCheckpointSchema,
59
+ "schemas/runtime/index-seed.schema.json": IndexSeedResultSchema,
60
+ "schemas/runtime/path-context.schema.json": PathContextOutputSchema,
61
+ "schemas/runtime/product-version-manifest.schema.json": ProductVersionManifestSchema,
62
+ "schemas/runtime/projection-slice.schema.json": ProjectionSliceSchema,
63
+ "schemas/runtime/ref-impact-batch-request.schema.json": RefImpactBatchRequestSchema,
64
+ "schemas/runtime/ref-impact-batch.schema.json": RefImpactBatchSchema,
65
+ "schemas/runtime/ref-impact.schema.json": RefImpactSchema,
66
+ "schemas/runtime/refactor-scan-v2.schema.json": RefactorScanV2Schema,
67
+ "schemas/runtime/refactor-simulate.schema.json": RefactorSimulateV1Schema,
68
+ "schemas/runtime/refactor-verify-v2.schema.json": RefactorVerifyV2Schema,
69
+ "schemas/runtime/resolve-path.schema.json": ResolvePathsBatchResultSchema,
70
+ "schemas/runtime/runtime-verify.schema.json": RuntimeVerifySchema,
71
+ "schemas/runtime/state-machine-check.schema.json": StateMachineCheckReportSchema,
72
+ "schemas/runtime/sync-check.schema.json": SyncCheckOutputSchema
73
+ };
package/src/schema.ts CHANGED
@@ -31,8 +31,6 @@ export type ArchContextErrorCode =
31
31
  | "AC_PROOF_REQUIRED"
32
32
  | "AC_COMPAT_CONTRACT_REQUIRED"
33
33
  | "AC_USER_CONFIRMATION_REQUIRED"
34
- | "AC_ENTITLEMENT_REQUIRED"
35
- | "AC_TUNNEL_SCOPE_DENIED"
36
34
  | "AC_MODEL_ADOPTION_REQUIRED"
37
35
  | "AC_REFACTOR_STALE"
38
36
  | "AC_REFACTOR_EVIDENCE_REQUIRED"
@@ -81,8 +79,6 @@ export const ERROR_CATALOG: Record<ArchContextErrorCode, Omit<ArchContextError,
81
79
  AC_PROOF_REQUIRED: { code: "AC_PROOF_REQUIRED", severity: "warning", retryable: false, action: "execute-proof-point" },
82
80
  AC_COMPAT_CONTRACT_REQUIRED: { code: "AC_COMPAT_CONTRACT_REQUIRED", severity: "error", retryable: false, action: "delete-or-contract" },
83
81
  AC_USER_CONFIRMATION_REQUIRED: { code: "AC_USER_CONFIRMATION_REQUIRED", severity: "warning", retryable: true, action: "show-human-decision" },
84
- AC_ENTITLEMENT_REQUIRED: { code: "AC_ENTITLEMENT_REQUIRED", severity: "error", retryable: false, action: "login-or-subscribe" },
85
- AC_TUNNEL_SCOPE_DENIED: { code: "AC_TUNNEL_SCOPE_DENIED", severity: "error", retryable: false, action: "reduce-scope" },
86
82
  AC_MODEL_ADOPTION_REQUIRED: { code: "AC_MODEL_ADOPTION_REQUIRED", severity: "error", retryable: false, action: "adopt-architecture-model" },
87
83
  AC_REFACTOR_STALE: { code: "AC_REFACTOR_STALE", severity: "warning", retryable: true, action: "rerun-refactor-scan" },
88
84
  AC_REFACTOR_EVIDENCE_REQUIRED: { code: "AC_REFACTOR_EVIDENCE_REQUIRED", severity: "error", retryable: false, action: "run-refactor-verify" },
@@ -0,0 +1,192 @@
1
+ import {
2
+ Const,
3
+ NonEmptyStringSchema,
4
+ OneOf,
5
+ PositiveIntSchema,
6
+ RawEnum,
7
+ Ref,
8
+ SchemaDocument,
9
+ StrictObject,
10
+ Type,
11
+ TypedUnsafe
12
+ } from "./schema-kit";
13
+ import {
14
+ STATE_MACHINE_CHECK_SCHEMA_VERSION,
15
+ type StateMachineGlobalState,
16
+ type StateMachinePathStep
17
+ } from "./state-machine-types";
18
+
19
+ const StateMachineLocalIdSchema = Type.String({ pattern: "^[a-z][a-z0-9]*(-[a-z0-9]+)*$" });
20
+ const StateMachineStepIndexSchema = Type.Integer({
21
+ minimum: 1,
22
+ description: "The 1-based index of the step in its event."
23
+ });
24
+ const StateMachineGlobalStateDefSchema = TypedUnsafe<StateMachineGlobalState>({
25
+ description: "One state per region, keyed by region id in declaration order.",
26
+ type: "object",
27
+ minProperties: 1,
28
+ propertyNames: { $ref: "#/$defs/localId" },
29
+ additionalProperties: { $ref: "#/$defs/localId" }
30
+ });
31
+ const StateMachinePathDefSchema = Type.Array(
32
+ StrictObject({
33
+ event: Ref<string>("#/$defs/localId"),
34
+ step: Ref<number>("#/$defs/stepIndex")
35
+ }),
36
+ { description: "The shortest sequence of fired steps from the initial global state." }
37
+ );
38
+
39
+ const StateMachineRuleResultSchema = StrictObject(
40
+ {
41
+ id: Ref<string>("#/$defs/localId"),
42
+ kind: RawEnum(["never", "final"] as const),
43
+ status: RawEnum(["holds", "broken", "finding-open", "finding-resolved"] as const),
44
+ tracking: Type.Optional(
45
+ Type.String({
46
+ pattern:
47
+ "^https://[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*(?::[0-9]{1,5})?(?:[/?#][^\\s]*)?$"
48
+ })
49
+ ),
50
+ state: Type.Optional(Ref<StateMachineGlobalState>("#/$defs/globalState")),
51
+ path: Type.Optional(Ref<StateMachinePathStep[]>("#/$defs/path")),
52
+ protectedBy: Type.Optional(
53
+ Type.Array(
54
+ StrictObject({
55
+ event: Ref<string>("#/$defs/localId"),
56
+ step: Ref<number>("#/$defs/stepIndex"),
57
+ region: Ref<string>("#/$defs/localId")
58
+ }),
59
+ { description: "The guards whose removal breaks this holding rule, in declaration order of the guards." }
60
+ )
61
+ )
62
+ },
63
+ {
64
+ allOf: [
65
+ {
66
+ if: { properties: { status: { enum: ["broken", "finding-open"] } } },
67
+ then: { required: ["state", "path"], not: { required: ["protectedBy"] } },
68
+ else: { not: { anyOf: [{ required: ["state"] }, { required: ["path"] }] } }
69
+ },
70
+ {
71
+ if: { properties: { status: { enum: ["finding-open", "finding-resolved"] } } },
72
+ then: { required: ["tracking"] },
73
+ else: { not: { required: ["tracking"] } }
74
+ }
75
+ ]
76
+ }
77
+ );
78
+
79
+ const StateMachineBreakDefSchema = OneOf([
80
+ StrictObject({
81
+ kind: Const("unreachable-state"),
82
+ region: Ref<string>("#/$defs/localId"),
83
+ state: Ref<string>("#/$defs/localId")
84
+ }),
85
+ StrictObject({
86
+ kind: Const("dead-step"),
87
+ event: Ref<string>("#/$defs/localId"),
88
+ step: Ref<number>("#/$defs/stepIndex")
89
+ }),
90
+ StrictObject({
91
+ kind: Const("deadlock"),
92
+ state: Ref<StateMachineGlobalState>("#/$defs/globalState"),
93
+ path: Ref<StateMachinePathStep[]>("#/$defs/path"),
94
+ count: Type.Integer({ minimum: 1, description: "The number of deadlocked reachable global states." })
95
+ })
96
+ ]);
97
+
98
+ const StateMachineAnchorDefSchema = StrictObject(
99
+ {
100
+ owner: RawEnum(["region", "event"] as const),
101
+ ownerId: Ref<string>("#/$defs/localId"),
102
+ path: NonEmptyStringSchema,
103
+ symbol: Type.Optional(NonEmptyStringSchema),
104
+ status: RawEnum([
105
+ "anchor-missing-path",
106
+ "anchor-language-unsupported",
107
+ "anchor-missing-symbol",
108
+ "anchor-ambiguous-symbol",
109
+ "unchecked",
110
+ "anchor-unconfirmed",
111
+ "anchor-changed",
112
+ "confirmed"
113
+ ] as const),
114
+ digest: Type.Optional(
115
+ Type.String({
116
+ pattern: "^sha256:[0-9a-f]{64}$",
117
+ description: "The file content, or a JSON array of the lines of the one matching declaration and of each direct callee, with CRLF read as LF."
118
+ })
119
+ ),
120
+ callees: Type.Optional(
121
+ Type.Array(
122
+ StrictObject({
123
+ path: NonEmptyStringSchema,
124
+ qualifiedName: NonEmptyStringSchema
125
+ }),
126
+ { description: "The direct callees that the digest of a symbol anchor covers, in digest order." }
127
+ )
128
+ ),
129
+ reason: Type.Optional(
130
+ RawEnum(["index-missing", "index-open-failed", "index-stale"] as const, {
131
+ description:
132
+ "Why the symbol reader is unavailable, or that the index does not hold the current content of the anchor's file or of a callee's file."
133
+ })
134
+ )
135
+ },
136
+ {
137
+ allOf: [
138
+ {
139
+ if: { required: ["symbol", "digest"] },
140
+ then: { required: ["callees"] },
141
+ else: { not: { required: ["callees"] } }
142
+ },
143
+ {
144
+ if: { properties: { status: { enum: ["anchor-unconfirmed", "anchor-changed", "confirmed"] } } },
145
+ then: { required: ["digest"] },
146
+ else: { not: { required: ["digest"] } }
147
+ },
148
+ {
149
+ if: { properties: { status: { const: "unchecked" } } },
150
+ then: { required: ["reason", "symbol"] },
151
+ else: { not: { required: ["reason"] } }
152
+ }
153
+ ]
154
+ }
155
+ );
156
+
157
+ export const StateMachineCheckReportBodySchema = StrictObject({
158
+ schemaVersion: Const(STATE_MACHINE_CHECK_SCHEMA_VERSION),
159
+ machines: Type.Array(
160
+ StrictObject({
161
+ id: Type.String({ pattern: "^state-machine\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" }),
162
+ capabilityId: Type.String({ pattern: "^capability\\.[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)*$" }),
163
+ reachableStates: PositiveIntSchema,
164
+ transitions: Type.Integer({
165
+ minimum: 0,
166
+ description: "Pairs of a reachable global state and an enabled step that changes it."
167
+ }),
168
+ rules: Type.Array(StateMachineRuleResultSchema, { description: "In declaration order." }),
169
+ breaks: Type.Array(StateMachineBreakDefSchema, {
170
+ description: "Every unreachable state, then every dead step, each in declaration order, then at most one deadlock."
171
+ }),
172
+ anchors: Type.Array(StateMachineAnchorDefSchema, {
173
+ description: "Every code source of a region or an event, regions first, then events, each in declaration order, with its status against the current file."
174
+ })
175
+ }),
176
+ { description: "Sorted by machine id." }
177
+ )
178
+ });
179
+
180
+ export const StateMachineCheckReportSchema = SchemaDocument({
181
+ $id: "https://archcontext.dev/schemas/runtime/state-machine-check.schema.json",
182
+ title: "StateMachineCheckV1",
183
+ description:
184
+ "The data of `archctx state-machines check`: for every declared state machine, the size of its reachable global state space, the result of each declared rule, the built-in breaks and the status of each code anchor. The same model gives the same bytes.",
185
+ schema: StateMachineCheckReportBodySchema,
186
+ $defs: {
187
+ localId: StateMachineLocalIdSchema,
188
+ stepIndex: StateMachineStepIndexSchema,
189
+ globalState: StateMachineGlobalStateDefSchema,
190
+ path: StateMachinePathDefSchema
191
+ }
192
+ });