archctx-contracts 0.17.1 → 0.18.1
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/valid/archctx-capabilities.json +2 -2
- package/fixtures/valid/product-version-manifest.json +4 -10
- package/package.json +4 -1
- package/schemas/repo/refactor-decision.schema.json +307 -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 +209 -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 +262 -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 +120 -0
- package/schemas/runtime/product-version-manifest.schema.json +142 -54
- 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 +1392 -0
- package/schemas/runtime/refactor-simulate.schema.json +553 -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 +77 -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 +4 -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 +6 -541
- package/src/product-version.ts +74 -55
- 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 +351 -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 +554 -0
- package/src/refactor-validation-helpers.ts +199 -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 +187 -0
- package/src/schema-registry.ts +73 -0
- package/src/schema.ts +15 -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,199 @@
|
|
|
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 { isCanonicalRepoRelativePosixPath, 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 canonicalRepoPathIssues(label: string, path: string): string[] {
|
|
170
|
+
return typeof path === "string" && isCanonicalRepoRelativePosixPath(path) ? [] : [`${label} must be a canonical repo-relative POSIX path`];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function lineIssues(label: string, line: number | null): string[] {
|
|
174
|
+
return line === null || (Number.isInteger(line) && line >= 1) ? [] : [`${label} must be null or a positive integer`];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function specifierIssues(label: string, specifier: string): string[] {
|
|
178
|
+
return typeof specifier === "string"
|
|
179
|
+
&& specifier.length > 0
|
|
180
|
+
&& specifier.length <= REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH
|
|
181
|
+
&& !/[\u0000-\u001f\u007f]/.test(specifier)
|
|
182
|
+
? []
|
|
183
|
+
: [`${label} must be a single-line specifier of 1-${REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH} characters`];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function digestIssues(label: string, value: string): string[] {
|
|
187
|
+
return SHA256_DIGEST_PATTERN.test(value) ? [] : [`${label} must be a sha256:<64-hex> digest`];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function isPresent<T>(value: T | undefined): value is T {
|
|
191
|
+
return value !== undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function sortedUniqueIssues(label: string, values: readonly string[]): string[] {
|
|
195
|
+
const expected = [...new Set(values)].sort();
|
|
196
|
+
return expected.length === values.length && expected.every((value, index) => value === values[index])
|
|
197
|
+
? []
|
|
198
|
+
: [`${label} must be sorted and unique`];
|
|
199
|
+
}
|