archctx-contracts 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fixtures/invalid/projection-result-applied-incomplete-coverage.json +3 -3
- package/fixtures/valid/archctx-capabilities.json +2 -2
- package/fixtures/valid/flow-selector-check.json +1 -1
- package/fixtures/valid/product-version-manifest.json +5 -11
- package/fixtures/valid/projection-manifest.json +1 -1
- package/fixtures/valid/projection-result.json +3 -3
- package/package.json +4 -1
- package/schemas/repo/refactor-decision.schema.json +283 -37
- package/schemas/runtime/archctx-capabilities.schema.json +144 -20
- package/schemas/runtime/architecture-debt-delta.schema.json +58 -19
- package/schemas/runtime/architecture-debt.schema.json +42 -42
- package/schemas/runtime/architecture-event.schema.json +1 -1
- package/schemas/runtime/architecture-history.schema.json +354 -0
- package/schemas/runtime/capability-dependencies.schema.json +266 -59
- package/schemas/runtime/cli-check.schema.json +197 -0
- package/schemas/runtime/cli-help.schema.json +28 -0
- package/schemas/runtime/dependency-constraint-evaluation.schema.json +67 -68
- package/schemas/runtime/docs-anchors.schema.json +250 -67
- package/schemas/runtime/doctor-code-facts.schema.json +49 -0
- package/schemas/runtime/evidence-binding.schema.json +1 -1
- package/schemas/runtime/flow-selector-check.schema.json +179 -46
- package/schemas/runtime/hook-debt-checkpoint.schema.json +12 -12
- package/schemas/runtime/index-seed.schema.json +56 -0
- package/schemas/runtime/path-context.schema.json +108 -0
- package/schemas/runtime/product-version-manifest.schema.json +142 -54
- package/schemas/runtime/projection-apply-readback.schema.json +2 -2
- package/schemas/runtime/projection-apply-recovery.schema.json +1 -1
- package/schemas/runtime/projection-result.schema.json +1 -1
- package/schemas/runtime/projection-slice.schema.json +34 -34
- package/schemas/runtime/recommendation-v3.schema.json +372 -1
- package/schemas/runtime/ref-impact-batch-request.schema.json +20 -7
- package/schemas/runtime/ref-impact-batch.schema.json +83 -13
- package/schemas/runtime/ref-impact.schema.json +68 -61
- package/schemas/runtime/refactor-scan-v2.schema.json +434 -0
- package/schemas/runtime/refactor-simulate.schema.json +505 -0
- package/schemas/runtime/refactor-verify-v2.schema.json +172 -0
- package/schemas/runtime/resolve-path.schema.json +69 -0
- package/schemas/runtime/runtime-recommendation-show.schema.json +531 -2
- package/schemas/runtime/runtime-refactor-scan.schema.json +498 -2
- package/schemas/runtime/runtime-verify.schema.json +274 -56
- package/schemas/runtime/state-machine-check.schema.json +357 -89
- package/schemas/runtime/structural-observation-payload.schema.json +372 -1
- package/schemas/runtime/sync-check.schema.json +65 -0
- package/src/architecture-debt.ts +125 -38
- package/src/architecture-history.ts +168 -42
- package/src/architecture.ts +100 -0
- package/src/cli-read.ts +228 -0
- package/src/docs-anchors.ts +105 -50
- package/src/explorer-occurrence-ports.ts +175 -0
- package/src/explorer-query-ports.ts +270 -0
- package/src/failure.ts +3 -0
- package/src/index-seed.ts +42 -0
- package/src/index.ts +5 -0
- package/src/ledger-records.ts +262 -0
- package/src/ledger.ts +27 -566
- package/src/ownership-dependencies.ts +115 -5
- package/src/ports.ts +12 -543
- package/src/product-version.ts +75 -56
- package/src/projection-apply-types.ts +216 -0
- package/src/projection-apply-validators.ts +355 -0
- package/src/projection-capabilities.ts +181 -0
- package/src/projection-constants.ts +317 -0
- package/src/projection-manifest-types.ts +298 -0
- package/src/projection-manifest.ts +12 -299
- package/src/projection-recovery-validators.ts +229 -0
- package/src/projection-request-validators.ts +326 -0
- package/src/projection-types.ts +365 -0
- package/src/projection-validation-helpers.ts +15 -0
- package/src/projection.ts +7 -1689
- package/src/ref-impact.ts +225 -33
- package/src/refactor-constants.ts +213 -0
- package/src/refactor-decision-validators.ts +350 -0
- package/src/refactor-evidence-types.ts +286 -0
- package/src/refactor-observation-validators.ts +359 -0
- package/src/refactor-resolution-validators.ts +229 -0
- package/src/refactor-snapshot-validators.ts +368 -0
- package/src/refactor-types.ts +270 -0
- package/src/refactor-v2.ts +389 -0
- package/src/refactor-validation-helpers.ts +195 -0
- package/src/refactor.ts +7 -1849
- package/src/review-guards.ts +3 -23
- package/src/runtime-verify.ts +87 -0
- package/src/schema-kit.ts +183 -0
- package/src/schema-registry.ts +73 -0
- package/src/schema.ts +0 -4
- package/src/state-machine-schemas.ts +192 -0
- package/src/state-machine-types.ts +188 -0
- package/src/state-machine.ts +9 -189
- package/fixtures/boundary/agent-job-expired.json +0 -33
- package/fixtures/invalid/adapter-fidelity-reverse-sync.json +0 -9
- package/fixtures/invalid/agent-job-direct-mutation.json +0 -32
- package/fixtures/invalid/cloud-egress-envelope-private-field.json +0 -12
- package/fixtures/invalid/investigation-report-direct-mutation.json +0 -38
- package/fixtures/invalid/investigation-report-missing-proposed-delta.json +0 -19
- package/fixtures/invalid/notification-event-code-field.json +0 -11
- package/fixtures/valid/adapter-fidelity.json +0 -9
- package/fixtures/valid/agent-job.json +0 -33
- package/fixtures/valid/architecture-candidate-delta-policy.json +0 -45
- package/fixtures/valid/architecture-candidate-delta.json +0 -188
- package/fixtures/valid/chatgpt-ga-tool.json +0 -9
- package/fixtures/valid/cloud-egress-envelope.json +0 -11
- package/fixtures/valid/entitlement.json +0 -12
- package/fixtures/valid/investigation-report.json +0 -38
- package/fixtures/valid/likec4-mapping.json +0 -14
- package/fixtures/valid/notification-event.json +0 -10
- package/fixtures/valid/notification-provider.json +0 -12
- package/fixtures/valid/structurizr-mapping.json +0 -15
- package/schemas/cloud/cloud-egress-envelope.schema.json +0 -19
- package/schemas/cloud/entitlement.schema.json +0 -24
- package/schemas/integrations/adapter-fidelity.schema.json +0 -21
- package/schemas/integrations/chatgpt-ga-tool.schema.json +0 -25
- package/schemas/integrations/likec4-mapping.schema.json +0 -32
- package/schemas/integrations/structurizr-mapping.schema.json +0 -33
- package/schemas/runtime/agent-job.schema.json +0 -63
- package/schemas/runtime/architecture-candidate-delta-policy.schema.json +0 -129
- package/schemas/runtime/architecture-candidate-delta.schema.json +0 -386
- package/schemas/runtime/investigation-report.schema.json +0 -119
- package/schemas/runtime/notification-event.schema.json +0 -18
- package/schemas/runtime/notification-provider.schema.json +0 -26
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import {
|
|
2
|
+
REFACTOR_NAMESPACE_PATTERN,
|
|
3
|
+
REFACTOR_OBSERVATION_KINDS,
|
|
4
|
+
REFACTOR_DETECTOR_EXTRA_KINDS,
|
|
5
|
+
REFACTOR_KILL_LIST_SYMBOL_TARGET_REGEX,
|
|
6
|
+
formatRefactorKillListSymbolTarget,
|
|
7
|
+
parseRefactorKillListSymbolTarget,
|
|
8
|
+
isValidRefactorKillListSymbolTarget
|
|
9
|
+
} from "./refactor";
|
|
10
|
+
import {
|
|
11
|
+
AnyOf,
|
|
12
|
+
BoundedStringSchema,
|
|
13
|
+
Const,
|
|
14
|
+
CountSchema,
|
|
15
|
+
GitCommitShaSchema,
|
|
16
|
+
NonEmptyStringSchema,
|
|
17
|
+
NullableType,
|
|
18
|
+
OneOf,
|
|
19
|
+
RawEnum,
|
|
20
|
+
RecordOf,
|
|
21
|
+
RepoPathSchema,
|
|
22
|
+
SchemaDocument,
|
|
23
|
+
Sha256DigestSchema,
|
|
24
|
+
StrictObject,
|
|
25
|
+
StringEnum,
|
|
26
|
+
Type,
|
|
27
|
+
UniqueStringArray,
|
|
28
|
+
type Static
|
|
29
|
+
} from "./schema-kit";
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
REFACTOR_KILL_LIST_SYMBOL_TARGET_REGEX,
|
|
33
|
+
formatRefactorKillListSymbolTarget,
|
|
34
|
+
parseRefactorKillListSymbolTarget,
|
|
35
|
+
isValidRefactorKillListSymbolTarget
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const REFACTOR_SCAN_V2_SCHEMA_VERSION = "archcontext.refactor-scan/v2" as const;
|
|
39
|
+
export const REFACTOR_VERIFY_V2_SCHEMA_VERSION = "archcontext.refactor-verify/v2" as const;
|
|
40
|
+
export const REFACTOR_SIMULATION_REQUEST_SCHEMA_VERSION = "archcontext.refactor-simulation-request/v1" as const;
|
|
41
|
+
export const REFACTOR_SIMULATE_V1_SCHEMA_VERSION = "archcontext.runtime-refactor-simulate/v1" as const;
|
|
42
|
+
|
|
43
|
+
export const V2_REFACTOR_DETECTOR_KINDS = [
|
|
44
|
+
"file-cycle",
|
|
45
|
+
"component-cycle",
|
|
46
|
+
"god-file",
|
|
47
|
+
"low-cohesion-god-file",
|
|
48
|
+
"entrypoint-bypass",
|
|
49
|
+
"undeclared-dependency",
|
|
50
|
+
"purity-violation",
|
|
51
|
+
"dead-public-export",
|
|
52
|
+
"unstable-dependency",
|
|
53
|
+
"shotgun-surgery-hotspot",
|
|
54
|
+
"co-change-coupling"
|
|
55
|
+
] as const;
|
|
56
|
+
export type V2RefactorDetectorKind = (typeof V2_REFACTOR_DETECTOR_KINDS)[number];
|
|
57
|
+
|
|
58
|
+
export const ALL_REFACTOR_DECISION_KINDS = [
|
|
59
|
+
...REFACTOR_OBSERVATION_KINDS,
|
|
60
|
+
...REFACTOR_DETECTOR_EXTRA_KINDS
|
|
61
|
+
].sort() as readonly (
|
|
62
|
+
| (typeof REFACTOR_OBSERVATION_KINDS)[number]
|
|
63
|
+
| (typeof REFACTOR_DETECTOR_EXTRA_KINDS)[number]
|
|
64
|
+
)[];
|
|
65
|
+
|
|
66
|
+
const RefactorDecisionScopeSchema = OneOf([
|
|
67
|
+
StrictObject({ kind: Const("repository") }),
|
|
68
|
+
StrictObject({ kind: Const("node"), nodeId: NonEmptyStringSchema }),
|
|
69
|
+
StrictObject({ kind: Const("paths"), paths: UniqueStringArray(RepoPathSchema, { minItems: 1 }) })
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
const RefactorDecisionOutcomeSchema = StrictObject({
|
|
73
|
+
outcomeId: NonEmptyStringSchema,
|
|
74
|
+
metric: NonEmptyStringSchema,
|
|
75
|
+
subjectSelectorId: NonEmptyStringSchema,
|
|
76
|
+
nodeId: NullableType("string"),
|
|
77
|
+
memberNodeIds: Type.Optional(UniqueStringArray(NonEmptyStringSchema, { minItems: 2 })),
|
|
78
|
+
operator: StringEnum(["absent", "equals", "greater_than", "less_than", "present"] as const),
|
|
79
|
+
value: AnyOf([Type.Number(), Type.Null()]),
|
|
80
|
+
required: Type.Boolean()
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const ISO_TIMESTAMP_REGEX = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?(Z|[+-]\\d{2}:\\d{2})$";
|
|
84
|
+
export const GRAPH_LINE_TEXT_REGEX = "^\\S(?:[^\\u0000-\\u001f\\u007f]*\\S)?$";
|
|
85
|
+
|
|
86
|
+
const ObservationMetricValueSchema = AnyOf([
|
|
87
|
+
Type.Null(),
|
|
88
|
+
Type.Number()
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
export const RefactorKillListTargetV2Schema = OneOf([
|
|
92
|
+
StrictObject({
|
|
93
|
+
kind: Const("path"),
|
|
94
|
+
target: RepoPathSchema,
|
|
95
|
+
required: Type.Boolean()
|
|
96
|
+
}),
|
|
97
|
+
StrictObject({
|
|
98
|
+
kind: Const("relation"),
|
|
99
|
+
target: NonEmptyStringSchema,
|
|
100
|
+
required: Type.Boolean()
|
|
101
|
+
}),
|
|
102
|
+
StrictObject({
|
|
103
|
+
kind: Const("symbol"),
|
|
104
|
+
target: Type.String({ pattern: REFACTOR_KILL_LIST_SYMBOL_TARGET_REGEX }),
|
|
105
|
+
required: Type.Boolean()
|
|
106
|
+
})
|
|
107
|
+
]);
|
|
108
|
+
export type RefactorKillListTargetV2 = Static<typeof RefactorKillListTargetV2Schema>;
|
|
109
|
+
|
|
110
|
+
export const RefactorDecisionFileBodySchema = StrictObject({
|
|
111
|
+
schemaVersion: Const("archcontext.refactor-decision/v1"),
|
|
112
|
+
namespace: Type.String({ pattern: REFACTOR_NAMESPACE_PATTERN.source }),
|
|
113
|
+
recommendationId: Type.String({ pattern: "^recommendation\\.[a-f0-9]{16}$" }),
|
|
114
|
+
fingerprint: Sha256DigestSchema,
|
|
115
|
+
fingerprintSchemaVersion: Const("archcontext.recommendation-fingerprint/v3"),
|
|
116
|
+
category: StringEnum(["refactor_proposal", "structural_observation"] as const),
|
|
117
|
+
kind: AnyOf([
|
|
118
|
+
Type.Null(),
|
|
119
|
+
StringEnum(ALL_REFACTOR_DECISION_KINDS as unknown as readonly [string, ...string[]])
|
|
120
|
+
]),
|
|
121
|
+
subject: StrictObject({
|
|
122
|
+
selectorKind: StringEnum(["node", "repository"] as const),
|
|
123
|
+
stableKey: Type.String({ minLength: 1, maxLength: 512, pattern: GRAPH_LINE_TEXT_REGEX }),
|
|
124
|
+
subjectSelectorId: Type.String({ pattern: "^subject\\.(node|repository)\\.[a-f0-9]{16}$" })
|
|
125
|
+
}),
|
|
126
|
+
affectedNodeIds: UniqueStringArray(NonEmptyStringSchema, { maxItems: 32 }),
|
|
127
|
+
affectedNodeCount: CountSchema,
|
|
128
|
+
regressesFrom: AnyOf([
|
|
129
|
+
Type.Null(),
|
|
130
|
+
Type.String({ pattern: "^recommendation\\.[a-f0-9]{16}$" })
|
|
131
|
+
]),
|
|
132
|
+
status: StringEnum([
|
|
133
|
+
"acknowledged",
|
|
134
|
+
"accepted",
|
|
135
|
+
"deferred",
|
|
136
|
+
"rejected",
|
|
137
|
+
"resolved",
|
|
138
|
+
"waived"
|
|
139
|
+
] as const),
|
|
140
|
+
observationScopeDigest: Type.Optional(
|
|
141
|
+
Type.String({
|
|
142
|
+
pattern: "^sha256:[a-f0-9]{64}$",
|
|
143
|
+
description: "Scope of the measured observation metrics. Absent for repository baselines."
|
|
144
|
+
})
|
|
145
|
+
),
|
|
146
|
+
observationMetrics: AnyOf([
|
|
147
|
+
Type.Null(),
|
|
148
|
+
Type.Unsafe<Record<string, number | null>>({
|
|
149
|
+
type: "object",
|
|
150
|
+
additionalProperties: ObservationMetricValueSchema
|
|
151
|
+
})
|
|
152
|
+
]),
|
|
153
|
+
reason: Type.String({ minLength: 1, maxLength: 1024, pattern: GRAPH_LINE_TEXT_REGEX }),
|
|
154
|
+
actor: StrictObject({
|
|
155
|
+
kind: StringEnum([
|
|
156
|
+
"cli",
|
|
157
|
+
"daemon",
|
|
158
|
+
"developer",
|
|
159
|
+
"hook",
|
|
160
|
+
"mcp",
|
|
161
|
+
"migration",
|
|
162
|
+
"subagent",
|
|
163
|
+
"system"
|
|
164
|
+
] as const),
|
|
165
|
+
id: Type.String({ minLength: 1, maxLength: 128, pattern: GRAPH_LINE_TEXT_REGEX })
|
|
166
|
+
}),
|
|
167
|
+
decidedAt: Type.String({ pattern: ISO_TIMESTAMP_REGEX }),
|
|
168
|
+
provenance: StrictObject({
|
|
169
|
+
headSha: GitCommitShaSchema,
|
|
170
|
+
assessmentDigest: Sha256DigestSchema,
|
|
171
|
+
baselineSnapshotDigest: Sha256DigestSchema
|
|
172
|
+
}),
|
|
173
|
+
snapshotDigest: Type.Optional(Sha256DigestSchema),
|
|
174
|
+
evidenceDigest: Type.Optional(Sha256DigestSchema),
|
|
175
|
+
resolutionDigest: Type.Optional(Sha256DigestSchema),
|
|
176
|
+
scope: Type.Optional(RefactorDecisionScopeSchema),
|
|
177
|
+
importNodeLimit: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
178
|
+
targetOutcomes: Type.Optional(Type.Array(RefactorDecisionOutcomeSchema)),
|
|
179
|
+
killList: Type.Optional(Type.Array(RefactorKillListTargetV2Schema))
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const RefactorDecisionFileSchema = SchemaDocument({
|
|
183
|
+
$id: "https://archctx.repoharness.com/schemas/repo/refactor-decision.schema.json",
|
|
184
|
+
title: "RefactorDecision",
|
|
185
|
+
description:
|
|
186
|
+
"The latest human decision for one refactor recommendation generation, stored at .archcontext/refactor-decisions/<recommendationId>.json (ADR-0046). Identity that needs the core hashers (recommendationId from fingerprint and regressesFrom, the namespace-scoped subject selector) is checked by the runtime reader.",
|
|
187
|
+
schema: RefactorDecisionFileBodySchema
|
|
188
|
+
});
|
|
189
|
+
export type RefactorDecisionFileV1 = Static<typeof RefactorDecisionFileSchema>;
|
|
190
|
+
|
|
191
|
+
export const RefactorScanFindingV2Schema = StrictObject({
|
|
192
|
+
recommendationId: Type.String({ pattern: "^recommendation\\.[a-f0-9]{16}$" }),
|
|
193
|
+
fingerprint: Sha256DigestSchema,
|
|
194
|
+
detector: StringEnum(V2_REFACTOR_DETECTOR_KINDS),
|
|
195
|
+
severity: RawEnum(["notice", "warning", "error", "critical"] as const),
|
|
196
|
+
blocking: Type.Boolean(),
|
|
197
|
+
capabilityId: NullableType("string", { minLength: 1 }),
|
|
198
|
+
affectedNodeIds: UniqueStringArray(NonEmptyStringSchema),
|
|
199
|
+
affectedPaths: UniqueStringArray(RepoPathSchema),
|
|
200
|
+
killList: Type.Array(RefactorKillListTargetV2Schema),
|
|
201
|
+
metrics: RecordOf(AnyOf([Type.Number(), Type.Null(), Type.Boolean()])),
|
|
202
|
+
evidence: StrictObject({
|
|
203
|
+
summary: BoundedStringSchema,
|
|
204
|
+
coChangeSupport: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
205
|
+
coChangeCoverageOk: Type.Optional(Type.Boolean()),
|
|
206
|
+
thinDirectionEdgeCount: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
207
|
+
sccSize: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
208
|
+
instabilitySource: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
209
|
+
instabilityTarget: Type.Optional(Type.Number({ minimum: 0, maximum: 1 })),
|
|
210
|
+
testCallerCoverage: Type.Optional(NullableType("number", { minimum: 0, maximum: 1 })),
|
|
211
|
+
lcomScore: Type.Optional(Type.Number({ minimum: 0 })),
|
|
212
|
+
splitClusterCount: Type.Optional(Type.Integer({ minimum: 0 }))
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
export type RefactorScanFindingV2 = Static<typeof RefactorScanFindingV2Schema>;
|
|
216
|
+
|
|
217
|
+
export const RefactorScanV2BodySchema = StrictObject({
|
|
218
|
+
schemaVersion: Const(REFACTOR_SCAN_V2_SCHEMA_VERSION),
|
|
219
|
+
scope: OneOf([
|
|
220
|
+
StrictObject({ kind: Const("repository") }),
|
|
221
|
+
StrictObject({ kind: Const("node"), nodeId: NonEmptyStringSchema }),
|
|
222
|
+
StrictObject({ kind: Const("paths"), paths: UniqueStringArray(RepoPathSchema, { minItems: 1 }) })
|
|
223
|
+
]),
|
|
224
|
+
headSha: GitCommitShaSchema,
|
|
225
|
+
snapshotDigest: Sha256DigestSchema,
|
|
226
|
+
importNodeLimit: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
227
|
+
coverage: StrictObject({
|
|
228
|
+
imports: StringEnum(["complete", "partial", "unavailable"] as const),
|
|
229
|
+
gitHistory: StringEnum(["complete", "shallow", "unavailable"] as const),
|
|
230
|
+
reasonCodes: UniqueStringArray(BoundedStringSchema)
|
|
231
|
+
}),
|
|
232
|
+
findings: Type.Array(RefactorScanFindingV2Schema),
|
|
233
|
+
suppressed: Type.Array(
|
|
234
|
+
StrictObject({
|
|
235
|
+
recommendationId: Type.String({ pattern: "^recommendation\\.[a-f0-9]{16}$" }),
|
|
236
|
+
detector: StringEnum(V2_REFACTOR_DETECTOR_KINDS),
|
|
237
|
+
decisionStatus: StringEnum(["deferred", "rejected", "waived", "resolved"] as const),
|
|
238
|
+
reason: BoundedStringSchema
|
|
239
|
+
})
|
|
240
|
+
)
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
export const RefactorScanV2Schema = SchemaDocument({
|
|
244
|
+
$id: "https://archcontext.dev/schemas/runtime/refactor-scan-v2.schema.json",
|
|
245
|
+
title: "RefactorScanV2",
|
|
246
|
+
description: "v2 Stage 5 deterministic refactor radar output for `archctx scan --json` (#643).",
|
|
247
|
+
schema: RefactorScanV2BodySchema
|
|
248
|
+
});
|
|
249
|
+
export type RefactorScanV2 = Static<typeof RefactorScanV2Schema>;
|
|
250
|
+
|
|
251
|
+
export const RefactorVerifyV2BodySchema = StrictObject({
|
|
252
|
+
schemaVersion: Const(REFACTOR_VERIFY_V2_SCHEMA_VERSION),
|
|
253
|
+
recommendationId: Type.String({ pattern: "^recommendation\\.[a-f0-9]{16}$" }),
|
|
254
|
+
headSha: GitCommitShaSchema,
|
|
255
|
+
snapshotDigest: Sha256DigestSchema,
|
|
256
|
+
disposition: StringEnum([
|
|
257
|
+
"resolved",
|
|
258
|
+
"partially_resolved",
|
|
259
|
+
"unresolved",
|
|
260
|
+
"regressed",
|
|
261
|
+
"stale"
|
|
262
|
+
] as const),
|
|
263
|
+
resolutionDigest: Sha256DigestSchema,
|
|
264
|
+
killListChecks: Type.Array(
|
|
265
|
+
StrictObject({
|
|
266
|
+
kind: StringEnum(["path", "relation", "symbol"] as const),
|
|
267
|
+
target: NonEmptyStringSchema,
|
|
268
|
+
required: Type.Boolean(),
|
|
269
|
+
status: StringEnum(["removed", "still-present", "uncheckable"] as const)
|
|
270
|
+
})
|
|
271
|
+
),
|
|
272
|
+
metricChecks: Type.Array(
|
|
273
|
+
StrictObject({
|
|
274
|
+
metric: NonEmptyStringSchema,
|
|
275
|
+
before: AnyOf([Type.Number(), Type.Null()]),
|
|
276
|
+
after: AnyOf([Type.Number(), Type.Null()]),
|
|
277
|
+
satisfied: Type.Boolean()
|
|
278
|
+
})
|
|
279
|
+
),
|
|
280
|
+
blockingReasons: UniqueStringArray(BoundedStringSchema),
|
|
281
|
+
historicalReceipt: Type.Optional(
|
|
282
|
+
StrictObject({
|
|
283
|
+
status: StringEnum(["acknowledged", "accepted", "deferred", "rejected", "resolved", "waived"] as const),
|
|
284
|
+
headSha: GitCommitShaSchema,
|
|
285
|
+
resolutionDigest: NullableType("string", { pattern: "^sha256:[a-f0-9]{64}$" })
|
|
286
|
+
})
|
|
287
|
+
)
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
export const RefactorVerifyV2Schema = SchemaDocument({
|
|
291
|
+
$id: "https://archcontext.dev/schemas/runtime/refactor-verify-v2.schema.json",
|
|
292
|
+
title: "RefactorVerifyV2",
|
|
293
|
+
description: "v2 Stage 5 attested resolution verification output for `archctx verify <id> --json` (#643).",
|
|
294
|
+
schema: RefactorVerifyV2BodySchema
|
|
295
|
+
});
|
|
296
|
+
export type RefactorVerifyV2 = Static<typeof RefactorVerifyV2Schema>;
|
|
297
|
+
|
|
298
|
+
export const RefactorSimulationMoveSchema = StrictObject({
|
|
299
|
+
path: RepoPathSchema,
|
|
300
|
+
toNodeId: NonEmptyStringSchema,
|
|
301
|
+
symbols: Type.Optional(UniqueStringArray(NonEmptyStringSchema, { minItems: 1 }))
|
|
302
|
+
});
|
|
303
|
+
export type RefactorSimulationMoveV1 = Static<typeof RefactorSimulationMoveSchema>;
|
|
304
|
+
|
|
305
|
+
export interface RefactorSimulationRequestV1 {
|
|
306
|
+
schemaVersion?: typeof REFACTOR_SIMULATION_REQUEST_SCHEMA_VERSION;
|
|
307
|
+
moves?: RefactorSimulationMoveV1[];
|
|
308
|
+
targetSubject?: string;
|
|
309
|
+
expectedHeadSha?: string;
|
|
310
|
+
expectedWorktreeDigest?: string;
|
|
311
|
+
importNodeLimit?: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const RefactorSimulationMetricsSnapshotSchema = StrictObject({
|
|
315
|
+
pairThinDirectionEdgeCount: CountSchema,
|
|
316
|
+
crossModuleEdgeCount: CountSchema,
|
|
317
|
+
crossModuleCycleCount: CountSchema,
|
|
318
|
+
residualCycleCount: CountSchema,
|
|
319
|
+
directionViolationCount: CountSchema
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const RefactorSimulationMetricsDeltaValuesSchema = StrictObject({
|
|
323
|
+
pairThinDirectionEdgeCount: Type.Integer(),
|
|
324
|
+
crossModuleEdgeCount: Type.Integer(),
|
|
325
|
+
crossModuleCycleCount: Type.Integer(),
|
|
326
|
+
residualCycleCount: Type.Integer(),
|
|
327
|
+
directionViolationCount: Type.Integer()
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const RefactorSimulationViolationSchema = StrictObject({
|
|
331
|
+
constraintId: NonEmptyStringSchema,
|
|
332
|
+
fromPath: RepoPathSchema,
|
|
333
|
+
toPath: RepoPathSchema,
|
|
334
|
+
fromNode: NonEmptyStringSchema,
|
|
335
|
+
toNode: NonEmptyStringSchema,
|
|
336
|
+
severity: RawEnum(["notice", "warning", "error", "critical"] as const),
|
|
337
|
+
fromLayer: Type.Optional(NonEmptyStringSchema),
|
|
338
|
+
toLayer: Type.Optional(NonEmptyStringSchema)
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const RefactorSimulationCutCandidateSchema = StrictObject({
|
|
342
|
+
strategy: StringEnum(["move-source-file", "move-target-file", "extract-shared-leaf", "invert-interface"] as const),
|
|
343
|
+
measured: Type.Boolean(),
|
|
344
|
+
measurementStatus: StringEnum(["measured", "unmeasured"] as const),
|
|
345
|
+
summary: BoundedStringSchema,
|
|
346
|
+
moves: Type.Array(RefactorSimulationMoveSchema),
|
|
347
|
+
thinDirectionEdgeDelta: AnyOf([Type.Integer(), Type.Null()]),
|
|
348
|
+
crossModuleCycleDelta: AnyOf([Type.Integer(), Type.Null()]),
|
|
349
|
+
directionViolationDelta: AnyOf([Type.Integer(), Type.Null()]),
|
|
350
|
+
newlyIntroducedViolationCount: AnyOf([CountSchema, Type.Null()]),
|
|
351
|
+
breaksPair: AnyOf([Type.Boolean(), Type.Null()]),
|
|
352
|
+
caveats: UniqueStringArray(BoundedStringSchema)
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
export const RefactorSimulateV1BodySchema = StrictObject({
|
|
356
|
+
schemaVersion: Const(REFACTOR_SIMULATE_V1_SCHEMA_VERSION),
|
|
357
|
+
beforeSnapshotDigest: Sha256DigestSchema,
|
|
358
|
+
modelDigest: Sha256DigestSchema,
|
|
359
|
+
codeFactsCoverage: StringEnum(["complete", "partial", "unknown"] as const),
|
|
360
|
+
moves: Type.Array(RefactorSimulationMoveSchema),
|
|
361
|
+
targetSubject: AnyOf([Type.String({ minLength: 1 }), Type.Null()]),
|
|
362
|
+
measurementStatus: StringEnum(["measured", "unmeasured"] as const),
|
|
363
|
+
unmeasuredReasons: UniqueStringArray(BoundedStringSchema),
|
|
364
|
+
metricsDelta: StrictObject({
|
|
365
|
+
before: RefactorSimulationMetricsSnapshotSchema,
|
|
366
|
+
after: AnyOf([RefactorSimulationMetricsSnapshotSchema, Type.Null()]),
|
|
367
|
+
delta: AnyOf([RefactorSimulationMetricsDeltaValuesSchema, Type.Null()])
|
|
368
|
+
}),
|
|
369
|
+
newlyIntroducedCycles: Type.Array(NonEmptyStringSchema),
|
|
370
|
+
resolvedCycles: Type.Array(NonEmptyStringSchema),
|
|
371
|
+
newlyIntroducedViolations: Type.Array(RefactorSimulationViolationSchema),
|
|
372
|
+
cutCandidates: Type.Array(RefactorSimulationCutCandidateSchema),
|
|
373
|
+
simulationDigest: Sha256DigestSchema,
|
|
374
|
+
privacy: StrictObject({
|
|
375
|
+
writes: Const("none"),
|
|
376
|
+
rawSourcePersisted: Const(false),
|
|
377
|
+
rawDiffPersisted: Const(false),
|
|
378
|
+
promptPersisted: Const(false)
|
|
379
|
+
})
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
export const RefactorSimulateV1Schema = SchemaDocument({
|
|
383
|
+
$id: "https://archcontext.dev/schemas/runtime/refactor-simulate.schema.json",
|
|
384
|
+
title: "RefactorSimulateV1",
|
|
385
|
+
description: "Read-only move/cut impact simulation preview (#638, #643 Phase 2).",
|
|
386
|
+
schema: RefactorSimulateV1BodySchema
|
|
387
|
+
});
|
|
388
|
+
export type RefactorSimulateV1 = Static<typeof RefactorSimulateV1Schema>;
|
|
389
|
+
export type RefactorSimulationResultV1 = RefactorSimulateV1;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { RecommendationAuthorV1, RecommendationCategory } from "./ledger-records";
|
|
2
|
+
import type {
|
|
3
|
+
PracticeRecommendationPayloadV1,
|
|
4
|
+
RecommendationPayloadV1,
|
|
5
|
+
RefactorProposalPayloadV1,
|
|
6
|
+
StructuralObservationPayloadV1
|
|
7
|
+
} from "./ledger";
|
|
8
|
+
import {
|
|
9
|
+
REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH,
|
|
10
|
+
REFACTOR_PROPOSAL_AUTHOR_KINDS,
|
|
11
|
+
REFACTOR_PROPOSAL_AUTHOR_PAIRS,
|
|
12
|
+
REFACTOR_PROPOSAL_AUTHOR_SOURCES,
|
|
13
|
+
type RefactorProposalAuthorKind,
|
|
14
|
+
type RefactorProposalAuthorSource
|
|
15
|
+
} from "./refactor-constants";
|
|
16
|
+
import type { ArchitectureTargetDeltaV1, RefactorTargetOutcomeV1 } from "./refactor-types";
|
|
17
|
+
import { isRepoRelativePosixPath, type Json } from "./schema";
|
|
18
|
+
|
|
19
|
+
export const DIGEST_PREFIX_LENGTH = "sha256:".length;
|
|
20
|
+
export const SHA256_DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
21
|
+
export const BARE_SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
22
|
+
export const GIT_HEAD_SHA_PATTERN = /^[a-f0-9]{40}$/;
|
|
23
|
+
|
|
24
|
+
export function authoredTargetDelta(delta: ArchitectureTargetDeltaV1): Omit<ArchitectureTargetDeltaV1, "interventionId" | "unresolvedTargets" | "extensions"> {
|
|
25
|
+
const {
|
|
26
|
+
interventionId: _interventionId,
|
|
27
|
+
unresolvedTargets: _unresolvedTargets,
|
|
28
|
+
extensions: _extensions,
|
|
29
|
+
...authored
|
|
30
|
+
} = delta;
|
|
31
|
+
return authored;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isRefactorProposalAuthorSource(source: string): source is RefactorProposalAuthorSource {
|
|
35
|
+
return (REFACTOR_PROPOSAL_AUTHOR_SOURCES as readonly string[]).includes(source);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isRefactorProposalAuthorKind(kind: string): kind is RefactorProposalAuthorKind {
|
|
39
|
+
return (REFACTOR_PROPOSAL_AUTHOR_KINDS as readonly string[]).includes(kind);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function refactorProposalAuthorIssues(author: RecommendationAuthorV1, prefix: string): string[] {
|
|
43
|
+
const issues: string[] = [];
|
|
44
|
+
if (author.id.trim() === "") issues.push(`${prefix}.authoredBy.id must not be empty`);
|
|
45
|
+
if (!isRefactorProposalAuthorSource(author.source)) {
|
|
46
|
+
issues.push(`${prefix}.authoredBy.source must not be ${author.source}; refactor proposals are agent or human authored`);
|
|
47
|
+
}
|
|
48
|
+
if (!isRefactorProposalAuthorKind(author.kind)) {
|
|
49
|
+
issues.push(`${prefix}.authoredBy.kind must not be ${author.kind}; refactor proposals are agent or human authored`);
|
|
50
|
+
return issues;
|
|
51
|
+
}
|
|
52
|
+
if (isRefactorProposalAuthorSource(author.source) && !REFACTOR_PROPOSAL_AUTHOR_PAIRS[author.kind].includes(author.source)) {
|
|
53
|
+
issues.push(`${prefix}.authoredBy.kind ${author.kind} is not compatible with source ${author.source}`);
|
|
54
|
+
}
|
|
55
|
+
return issues;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function outcomeSatisfied(expected: RefactorTargetOutcomeV1, observedValue: number | null): boolean {
|
|
59
|
+
switch (expected.operator) {
|
|
60
|
+
case "absent":
|
|
61
|
+
return observedValue === null || observedValue === 0;
|
|
62
|
+
case "present":
|
|
63
|
+
return observedValue !== null && observedValue !== 0;
|
|
64
|
+
case "equals":
|
|
65
|
+
return observedValue !== null && expected.value !== null && observedValue === expected.value;
|
|
66
|
+
case "greater_than":
|
|
67
|
+
return observedValue !== null && expected.value !== null && observedValue > expected.value;
|
|
68
|
+
case "less_than":
|
|
69
|
+
return observedValue !== null && expected.value !== null && observedValue < expected.value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function recommendationPayloadShapeIssues(
|
|
74
|
+
category: RecommendationCategory,
|
|
75
|
+
payload: RecommendationPayloadV1,
|
|
76
|
+
prefix: string
|
|
77
|
+
): string[] {
|
|
78
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
79
|
+
return [`${prefix}.payload must be an object for category ${category}`];
|
|
80
|
+
}
|
|
81
|
+
const record = payload as unknown as Record<string, unknown>;
|
|
82
|
+
const required = REQUIRED_PAYLOAD_FIELDS[category];
|
|
83
|
+
const missing = required.filter((field) => !(field in record));
|
|
84
|
+
return missing.length === 0 ? [] : [`${prefix}.payload does not match category ${category}; missing ${missing.sort().join(", ")}`];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function nonNegativeIntegerIssues(label: string, value: number | null): string[] {
|
|
88
|
+
if (value === null) return [];
|
|
89
|
+
return Number.isInteger(value) && value >= 0 ? [] : [`${label} must be a non-negative integer`];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function ratioIssues(label: string, value: number | null): string[] {
|
|
93
|
+
if (value === null) return [];
|
|
94
|
+
return Number.isFinite(value) && value >= 0 && value <= 1 ? [] : [`${label} must be a ratio between 0 and 1`];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const REQUIRED_PAYLOAD_FIELDS: Readonly<Record<RecommendationCategory, readonly string[]>> = {
|
|
98
|
+
practice: ["baselineDigest", "practiceId"],
|
|
99
|
+
refactor_proposal: [
|
|
100
|
+
"affectedNodeIds",
|
|
101
|
+
"assessmentDigest",
|
|
102
|
+
"baselineSnapshotDigest",
|
|
103
|
+
"killList",
|
|
104
|
+
"majorChangeReasons",
|
|
105
|
+
"proposalDigest",
|
|
106
|
+
"scale",
|
|
107
|
+
"targetOutcomes"
|
|
108
|
+
],
|
|
109
|
+
structural_observation: [
|
|
110
|
+
"affectedNodeIds",
|
|
111
|
+
"assessmentDigest",
|
|
112
|
+
"baselineSnapshotDigest",
|
|
113
|
+
"derivedOutcomes",
|
|
114
|
+
"evidence",
|
|
115
|
+
"kind",
|
|
116
|
+
"metrics",
|
|
117
|
+
"signalIds"
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export function fingerprintPayloadSubset(category: RecommendationCategory, payload: RecommendationPayloadV1): Record<string, Json> {
|
|
122
|
+
if (category === "practice") {
|
|
123
|
+
return { baselineDigest: (payload as PracticeRecommendationPayloadV1).baselineDigest };
|
|
124
|
+
}
|
|
125
|
+
if (category === "structural_observation") {
|
|
126
|
+
const observation = payload as StructuralObservationPayloadV1;
|
|
127
|
+
return { kind: observation.kind, affectedNodeIds: [...observation.affectedNodeIds].sort() };
|
|
128
|
+
}
|
|
129
|
+
const proposal = payload as RefactorProposalPayloadV1;
|
|
130
|
+
return {
|
|
131
|
+
proposalDigest: proposal.proposalDigest,
|
|
132
|
+
scale: proposal.scale,
|
|
133
|
+
affectedNodeIds: [...proposal.affectedNodeIds].sort(),
|
|
134
|
+
majorChangeReasons: [...proposal.majorChangeReasons].sort()
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function outcomeIssues(label: string, outcomes: readonly RefactorTargetOutcomeV1[]): string[] {
|
|
139
|
+
const issues = sortedUniqueIssues(`${label}.outcomeId`, outcomes.map((outcome) => outcome.outcomeId));
|
|
140
|
+
for (const outcome of outcomes) {
|
|
141
|
+
if (outcome.memberNodeIds !== undefined) {
|
|
142
|
+
if (!Array.isArray(outcome.memberNodeIds) || outcome.memberNodeIds.length < 2) {
|
|
143
|
+
issues.push(`${label} memberNodeIds must list at least two modules`);
|
|
144
|
+
} else {
|
|
145
|
+
issues.push(...sortedUniqueIssues(`${label}.memberNodeIds`, outcome.memberNodeIds));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const valueless = outcome.operator === "absent" || outcome.operator === "present";
|
|
149
|
+
if (valueless && outcome.value !== null) issues.push(`${label} operator ${outcome.operator} must not carry a value`);
|
|
150
|
+
if (!valueless && outcome.value === null) issues.push(`${label} operator ${outcome.operator} requires a value`);
|
|
151
|
+
if (outcome.metric.trim() === "") issues.push(`${label} metric must not be empty`);
|
|
152
|
+
}
|
|
153
|
+
return issues;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function compareText(left: string, right: string): number {
|
|
157
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** An unknown line sorts before every known one, so the order is total. */
|
|
161
|
+
export function compareLine(left: number | null, right: number | null): number {
|
|
162
|
+
return (left ?? 0) - (right ?? 0);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function repoPathIssues(label: string, path: string): string[] {
|
|
166
|
+
return typeof path === "string" && isRepoRelativePosixPath(path) ? [] : [`${label} must be a repo-relative POSIX path`];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function lineIssues(label: string, line: number | null): string[] {
|
|
170
|
+
return line === null || (Number.isInteger(line) && line >= 1) ? [] : [`${label} must be null or a positive integer`];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function specifierIssues(label: string, specifier: string): string[] {
|
|
174
|
+
return typeof specifier === "string"
|
|
175
|
+
&& specifier.length > 0
|
|
176
|
+
&& specifier.length <= REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH
|
|
177
|
+
&& !/[\u0000-\u001f\u007f]/.test(specifier)
|
|
178
|
+
? []
|
|
179
|
+
: [`${label} must be a single-line specifier of 1-${REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH} characters`];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function digestIssues(label: string, value: string): string[] {
|
|
183
|
+
return SHA256_DIGEST_PATTERN.test(value) ? [] : [`${label} must be a sha256:<64-hex> digest`];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function isPresent<T>(value: T | undefined): value is T {
|
|
187
|
+
return value !== undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function sortedUniqueIssues(label: string, values: readonly string[]): string[] {
|
|
191
|
+
const expected = [...new Set(values)].sort();
|
|
192
|
+
return expected.length === values.length && expected.every((value, index) => value === values[index])
|
|
193
|
+
? []
|
|
194
|
+
: [`${label} must be sorted and unique`];
|
|
195
|
+
}
|