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,350 @@
|
|
|
1
|
+
import type { ArchitectureActorKind, ArchitectureSubjectSelectorKind, RecommendationStatus } from "./ledger-records";
|
|
2
|
+
import {
|
|
3
|
+
isValidRefactorKillListSymbolTarget,
|
|
4
|
+
REFACTOR_DECISION_ACTOR_ID_MAX_LENGTH,
|
|
5
|
+
REFACTOR_DECISION_DIRECTORY,
|
|
6
|
+
REFACTOR_DECISION_FILE_PATTERN,
|
|
7
|
+
REFACTOR_DECISION_REASON_MAX_LENGTH,
|
|
8
|
+
REFACTOR_DECISION_SCHEMA_VERSION,
|
|
9
|
+
REFACTOR_DECISION_STABLE_KEY_MAX_LENGTH,
|
|
10
|
+
REFACTOR_DECISION_STATUSES,
|
|
11
|
+
REFACTOR_DETECTOR_EXTRA_KINDS,
|
|
12
|
+
REFACTOR_EVIDENCE_ID_LIST_LIMIT,
|
|
13
|
+
REFACTOR_KILL_LIST_KINDS,
|
|
14
|
+
REFACTOR_OBSERVATION_KINDS,
|
|
15
|
+
REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION,
|
|
16
|
+
REFACTOR_RECOMMENDATION_ID_PATTERN,
|
|
17
|
+
refactorNamespaceIssues,
|
|
18
|
+
type RefactorDecisionStatus
|
|
19
|
+
} from "./refactor-constants";
|
|
20
|
+
import type { RefactorDecisionV1 } from "./refactor-evidence-types";
|
|
21
|
+
import {
|
|
22
|
+
digestIssues,
|
|
23
|
+
GIT_HEAD_SHA_PATTERN,
|
|
24
|
+
outcomeIssues,
|
|
25
|
+
repoPathIssues,
|
|
26
|
+
sortedUniqueIssues
|
|
27
|
+
} from "./refactor-validation-helpers";
|
|
28
|
+
|
|
29
|
+
const REFACTOR_DECISION_ACTOR_KINDS: readonly ArchitectureActorKind[] = ["cli", "daemon", "developer", "hook", "mcp", "migration", "subagent", "system"];
|
|
30
|
+
const REFACTOR_DECISION_SELECTOR_KINDS: readonly ArchitectureSubjectSelectorKind[] = ["node", "repository"];
|
|
31
|
+
const ISO_TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
|
|
32
|
+
const GIT_CONFLICT_MARKER_PATTERN = /^(<{7}|={7}|>{7}|\|{7})( |$)/m;
|
|
33
|
+
|
|
34
|
+
const REFACTOR_DECISION_KEYS = [
|
|
35
|
+
"actor",
|
|
36
|
+
"affectedNodeCount",
|
|
37
|
+
"affectedNodeIds",
|
|
38
|
+
"category",
|
|
39
|
+
"decidedAt",
|
|
40
|
+
"fingerprint",
|
|
41
|
+
"fingerprintSchemaVersion",
|
|
42
|
+
"kind",
|
|
43
|
+
"namespace",
|
|
44
|
+
"observationMetrics",
|
|
45
|
+
"provenance",
|
|
46
|
+
"reason",
|
|
47
|
+
"recommendationId",
|
|
48
|
+
"regressesFrom",
|
|
49
|
+
"schemaVersion",
|
|
50
|
+
"status",
|
|
51
|
+
"subject"
|
|
52
|
+
] as const;
|
|
53
|
+
const REFACTOR_DECISION_OPTIONAL_KEYS = [
|
|
54
|
+
"observationScopeDigest",
|
|
55
|
+
"snapshotDigest",
|
|
56
|
+
"evidenceDigest",
|
|
57
|
+
"resolutionDigest",
|
|
58
|
+
"scope",
|
|
59
|
+
"importNodeLimit",
|
|
60
|
+
"targetOutcomes",
|
|
61
|
+
"killList"
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
export function isRefactorDecisionStatus(status: RecommendationStatus | string): status is RefactorDecisionStatus {
|
|
65
|
+
return (REFACTOR_DECISION_STATUSES as readonly string[]).includes(status);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Who states a refactor recommendation's status (ADR-0046): its Git decision file
|
|
70
|
+
* (`git-decision`), a machine status the ledger holds (`ledger`), or nobody — a human status the
|
|
71
|
+
* ledger recorded whose Git file this checkout does not carry is audit only (`ledger-audit`): it
|
|
72
|
+
* keeps its recorded status as history, is never reported as the current status of the subject,
|
|
73
|
+
* and never appears in an open or status listing.
|
|
74
|
+
*/
|
|
75
|
+
export type RefactorStatusAuthority = "git-decision" | "ledger" | "ledger-audit";
|
|
76
|
+
|
|
77
|
+
/** The one status rule every reader shares. */
|
|
78
|
+
export function refactorRecommendationStatusView(
|
|
79
|
+
ledgerStatus: RecommendationStatus,
|
|
80
|
+
decided: RefactorDecisionStatus | undefined
|
|
81
|
+
): { status: RecommendationStatus; authority: RefactorStatusAuthority } {
|
|
82
|
+
if (decided !== undefined) return { status: decided, authority: "git-decision" };
|
|
83
|
+
return { status: ledgerStatus, authority: isRefactorDecisionStatus(ledgerStatus) ? "ledger-audit" : "ledger" };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The repository path of the decision file for one recommendation id. */
|
|
87
|
+
export function refactorDecisionPath(recommendationId: string): string {
|
|
88
|
+
return `${REFACTOR_DECISION_DIRECTORY}/${recommendationId}.json`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The one serialization the daemon writes: two-space JSON, LF line endings, keys in declaration
|
|
93
|
+
* order at every level (`observationMetrics` keys sorted), final newline. It does not depend on the
|
|
94
|
+
* key order of the value it is given, so a parsed file serializes back to its own bytes only when
|
|
95
|
+
* it is already canonical.
|
|
96
|
+
*/
|
|
97
|
+
export function serializeRefactorDecision(decision: RefactorDecisionV1): string {
|
|
98
|
+
const canonical: RefactorDecisionV1 = {
|
|
99
|
+
schemaVersion: decision.schemaVersion,
|
|
100
|
+
namespace: decision.namespace,
|
|
101
|
+
recommendationId: decision.recommendationId,
|
|
102
|
+
fingerprint: decision.fingerprint,
|
|
103
|
+
fingerprintSchemaVersion: decision.fingerprintSchemaVersion,
|
|
104
|
+
category: decision.category,
|
|
105
|
+
kind: decision.kind,
|
|
106
|
+
subject: {
|
|
107
|
+
selectorKind: decision.subject.selectorKind,
|
|
108
|
+
stableKey: decision.subject.stableKey,
|
|
109
|
+
subjectSelectorId: decision.subject.subjectSelectorId
|
|
110
|
+
},
|
|
111
|
+
affectedNodeIds: decision.affectedNodeIds,
|
|
112
|
+
affectedNodeCount: decision.affectedNodeCount,
|
|
113
|
+
regressesFrom: decision.regressesFrom,
|
|
114
|
+
status: decision.status,
|
|
115
|
+
observationMetrics: decision.observationMetrics === null
|
|
116
|
+
? null
|
|
117
|
+
: Object.fromEntries(Object.entries(decision.observationMetrics).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))),
|
|
118
|
+
...(decision.observationScopeDigest === undefined ? {} : { observationScopeDigest: decision.observationScopeDigest }),
|
|
119
|
+
reason: decision.reason,
|
|
120
|
+
actor: { kind: decision.actor.kind, id: decision.actor.id },
|
|
121
|
+
decidedAt: decision.decidedAt,
|
|
122
|
+
provenance: {
|
|
123
|
+
headSha: decision.provenance.headSha,
|
|
124
|
+
assessmentDigest: decision.provenance.assessmentDigest,
|
|
125
|
+
baselineSnapshotDigest: decision.provenance.baselineSnapshotDigest
|
|
126
|
+
},
|
|
127
|
+
...(decision.snapshotDigest === undefined ? {} : { snapshotDigest: decision.snapshotDigest }),
|
|
128
|
+
...(decision.evidenceDigest === undefined ? {} : { evidenceDigest: decision.evidenceDigest }),
|
|
129
|
+
...(decision.resolutionDigest === undefined ? {} : { resolutionDigest: decision.resolutionDigest }),
|
|
130
|
+
...(decision.scope === undefined ? {} : { scope: decision.scope }),
|
|
131
|
+
...(decision.importNodeLimit === undefined ? {} : { importNodeLimit: decision.importNodeLimit }),
|
|
132
|
+
...(decision.targetOutcomes === undefined ? {} : { targetOutcomes: decision.targetOutcomes }),
|
|
133
|
+
...(decision.killList === undefined ? {} : { killList: decision.killList })
|
|
134
|
+
};
|
|
135
|
+
return `${JSON.stringify(canonical, null, 2)}\n`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Validates a decision value: closed key sets at every level, the frozen vocabularies, bounded
|
|
140
|
+
* one-line strings and sorted bounded id lists. Identity that needs the core hashers (the
|
|
141
|
+
* recommendation id from fingerprint and `regressesFrom`, the namespace-scoped selector) is checked
|
|
142
|
+
* by the reader that has them.
|
|
143
|
+
*/
|
|
144
|
+
export function refactorDecisionInvariantIssues(value: unknown, prefix = "refactorDecision"): string[] {
|
|
145
|
+
if (!isPlainObject(value)) return [`${prefix} must be an object`];
|
|
146
|
+
const issues: string[] = [];
|
|
147
|
+
const allowedKeys: readonly string[] = [...REFACTOR_DECISION_KEYS, ...REFACTOR_DECISION_OPTIONAL_KEYS];
|
|
148
|
+
const unknownKeys = Object.keys(value).filter((key) => !allowedKeys.includes(key)).sort();
|
|
149
|
+
if (unknownKeys.length > 0) issues.push(`${prefix} has unsupported key(s): ${unknownKeys.join(", ")}`);
|
|
150
|
+
const missing = REFACTOR_DECISION_KEYS.filter((key) => !(key in value));
|
|
151
|
+
if (missing.length > 0) issues.push(`${prefix} is missing key(s): ${missing.join(", ")}`);
|
|
152
|
+
if (issues.length > 0) return issues;
|
|
153
|
+
const decision = value as unknown as RefactorDecisionV1;
|
|
154
|
+
if (decision.schemaVersion !== REFACTOR_DECISION_SCHEMA_VERSION) issues.push(`${prefix}.schemaVersion must be ${REFACTOR_DECISION_SCHEMA_VERSION}`);
|
|
155
|
+
issues.push(...refactorNamespaceIssues(decision.namespace, `${prefix}.namespace`));
|
|
156
|
+
if (typeof decision.recommendationId !== "string" || !REFACTOR_RECOMMENDATION_ID_PATTERN.test(decision.recommendationId)) {
|
|
157
|
+
issues.push(`${prefix}.recommendationId must match ${REFACTOR_RECOMMENDATION_ID_PATTERN.source}`);
|
|
158
|
+
}
|
|
159
|
+
if (typeof decision.fingerprint !== "string") issues.push(`${prefix}.fingerprint must be a sha256:<64-hex> digest`);
|
|
160
|
+
else issues.push(...digestIssues(`${prefix}.fingerprint`, decision.fingerprint));
|
|
161
|
+
if (decision.fingerprintSchemaVersion !== REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION) {
|
|
162
|
+
issues.push(`${prefix}.fingerprintSchemaVersion must be ${REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION}`);
|
|
163
|
+
}
|
|
164
|
+
if (decision.category !== "structural_observation" && decision.category !== "refactor_proposal") {
|
|
165
|
+
issues.push(`${prefix}.category must be structural_observation or refactor_proposal`);
|
|
166
|
+
} else if (decision.category === "structural_observation"
|
|
167
|
+
? !(REFACTOR_OBSERVATION_KINDS as readonly unknown[]).includes(decision.kind)
|
|
168
|
+
&& !(REFACTOR_DETECTOR_EXTRA_KINDS as readonly unknown[]).includes(decision.kind)
|
|
169
|
+
: decision.kind !== null) {
|
|
170
|
+
issues.push(`${prefix}.kind must be an observation kind for structural_observation and null for refactor_proposal`);
|
|
171
|
+
}
|
|
172
|
+
issues.push(...decisionSubjectIssues(decision.subject, `${prefix}.subject`));
|
|
173
|
+
if (!Array.isArray(decision.affectedNodeIds) || decision.affectedNodeIds.some((id) => typeof id !== "string" || id.trim() === "")) {
|
|
174
|
+
issues.push(`${prefix}.affectedNodeIds must be an array of node ids`);
|
|
175
|
+
} else {
|
|
176
|
+
issues.push(...sortedUniqueIssues(`${prefix}.affectedNodeIds`, decision.affectedNodeIds));
|
|
177
|
+
if (!Number.isInteger(decision.affectedNodeCount) || decision.affectedNodeCount < 0) {
|
|
178
|
+
issues.push(`${prefix}.affectedNodeCount must be a non-negative integer`);
|
|
179
|
+
} else if (decision.affectedNodeIds.length !== Math.min(decision.affectedNodeCount, REFACTOR_EVIDENCE_ID_LIST_LIMIT)) {
|
|
180
|
+
issues.push(`${prefix}.affectedNodeIds must hold min(affectedNodeCount, ${REFACTOR_EVIDENCE_ID_LIST_LIMIT}) entries`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (decision.regressesFrom !== null
|
|
184
|
+
&& (typeof decision.regressesFrom !== "string" || !REFACTOR_RECOMMENDATION_ID_PATTERN.test(decision.regressesFrom))) {
|
|
185
|
+
issues.push(`${prefix}.regressesFrom must be null or a recommendation id`);
|
|
186
|
+
}
|
|
187
|
+
if (!isRefactorDecisionStatus(String(decision.status))) {
|
|
188
|
+
issues.push(`${prefix}.status must be one of ${REFACTOR_DECISION_STATUSES.join(", ")}`);
|
|
189
|
+
}
|
|
190
|
+
if (decision.observationMetrics !== null) {
|
|
191
|
+
if (!isPlainObject(decision.observationMetrics)
|
|
192
|
+
|| Object.entries(decision.observationMetrics).some(([key, metric]) =>
|
|
193
|
+
key.trim() === "" || !(metric === null || (typeof metric === "number" && Number.isFinite(metric))))) {
|
|
194
|
+
issues.push(`${prefix}.observationMetrics must be null or a map of finite numbers and nulls`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (decision.observationScopeDigest !== undefined) {
|
|
198
|
+
if (typeof decision.observationScopeDigest === "string") issues.push(...digestIssues(`${prefix}.observationScopeDigest`, decision.observationScopeDigest));
|
|
199
|
+
else issues.push(`${prefix}.observationScopeDigest must be a digest`);
|
|
200
|
+
if (decision.category !== "structural_observation" || decision.observationMetrics === null) {
|
|
201
|
+
issues.push(`${prefix}.observationScopeDigest requires measured observation metrics`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
issues.push(...boundedLineIssues(`${prefix}.reason`, decision.reason, REFACTOR_DECISION_REASON_MAX_LENGTH));
|
|
205
|
+
if (!isPlainObject(decision.actor) || Object.keys(decision.actor).sort().join(",") !== "id,kind") {
|
|
206
|
+
issues.push(`${prefix}.actor must carry exactly kind and id`);
|
|
207
|
+
} else {
|
|
208
|
+
if (!REFACTOR_DECISION_ACTOR_KINDS.includes(decision.actor.kind)) issues.push(`${prefix}.actor.kind is unsupported`);
|
|
209
|
+
issues.push(...boundedLineIssues(`${prefix}.actor.id`, decision.actor.id, REFACTOR_DECISION_ACTOR_ID_MAX_LENGTH));
|
|
210
|
+
}
|
|
211
|
+
if (typeof decision.decidedAt !== "string" || !ISO_TIMESTAMP_PATTERN.test(decision.decidedAt)) {
|
|
212
|
+
issues.push(`${prefix}.decidedAt must be an ISO-8601 timestamp`);
|
|
213
|
+
}
|
|
214
|
+
if (!isPlainObject(decision.provenance)
|
|
215
|
+
|| Object.keys(decision.provenance).sort().join(",") !== "assessmentDigest,baselineSnapshotDigest,headSha") {
|
|
216
|
+
issues.push(`${prefix}.provenance must carry exactly headSha, assessmentDigest and baselineSnapshotDigest`);
|
|
217
|
+
} else {
|
|
218
|
+
if (typeof decision.provenance.headSha !== "string" || !GIT_HEAD_SHA_PATTERN.test(decision.provenance.headSha)) {
|
|
219
|
+
issues.push(`${prefix}.provenance.headSha must be a 40-hex Git commit sha`);
|
|
220
|
+
}
|
|
221
|
+
for (const field of ["assessmentDigest", "baselineSnapshotDigest"] as const) {
|
|
222
|
+
const digest = decision.provenance[field];
|
|
223
|
+
issues.push(...(typeof digest === "string" ? digestIssues(`${prefix}.provenance.${field}`, digest) : [`${prefix}.provenance.${field} must be a digest`]));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const field of ["snapshotDigest", "evidenceDigest", "resolutionDigest"] as const) {
|
|
227
|
+
const digest = decision[field];
|
|
228
|
+
if (digest !== undefined) {
|
|
229
|
+
issues.push(...(typeof digest === "string" ? digestIssues(`${prefix}.${field}`, digest) : [`${prefix}.${field} must be a digest`]));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (decision.importNodeLimit !== undefined && !(Number.isInteger(decision.importNodeLimit) && decision.importNodeLimit >= 1)) {
|
|
233
|
+
issues.push(`${prefix}.importNodeLimit must be a positive integer`);
|
|
234
|
+
}
|
|
235
|
+
if (decision.scope !== undefined) {
|
|
236
|
+
issues.push(...decisionScopeIssues(decision.scope, `${prefix}.scope`));
|
|
237
|
+
}
|
|
238
|
+
if (decision.targetOutcomes !== undefined) {
|
|
239
|
+
if (!Array.isArray(decision.targetOutcomes)) issues.push(`${prefix}.targetOutcomes must be an array`);
|
|
240
|
+
else issues.push(...outcomeIssues(`${prefix}.targetOutcomes`, decision.targetOutcomes));
|
|
241
|
+
}
|
|
242
|
+
if (decision.killList !== undefined) {
|
|
243
|
+
if (!Array.isArray(decision.killList)) issues.push(`${prefix}.killList must be an array`);
|
|
244
|
+
else {
|
|
245
|
+
for (const entry of decision.killList) {
|
|
246
|
+
if (!isPlainObject(entry) || !(REFACTOR_KILL_LIST_KINDS as readonly string[]).includes(String(entry.kind)) || typeof entry.target !== "string" || entry.target.trim() === "" || typeof entry.required !== "boolean") {
|
|
247
|
+
issues.push(`${prefix}.killList entry is invalid`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
const entryKeys = Object.keys(entry).sort().join(",");
|
|
251
|
+
if (entryKeys !== "kind,required,target") {
|
|
252
|
+
issues.push(`${prefix}.killList entry must carry exactly kind, target and required`);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (entry.kind === "path") {
|
|
256
|
+
issues.push(...repoPathIssues(`${prefix}.killList.target`, entry.target));
|
|
257
|
+
} else if (entry.kind === "symbol" && !isValidRefactorKillListSymbolTarget(entry.target)) {
|
|
258
|
+
issues.push(`${prefix}.killList.target must be <repo-relative-path>#<symbol>`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return issues;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Parses one decision file exactly as it sits in the checkout. A file with an unresolved merge
|
|
268
|
+
* conflict, a body that is not one JSON object, a value that breaks the contract, a basename that
|
|
269
|
+
* is not its own recommendation id, or bytes that are not the canonical serialization is refused
|
|
270
|
+
* with every reason; nothing is repaired.
|
|
271
|
+
*
|
|
272
|
+
* The one tolerated difference is CRLF line endings: a checkout with `core.autocrlf` (Windows)
|
|
273
|
+
* turns every LF of a committed canonical file into CRLF, so the body is compared after rewriting
|
|
274
|
+
* only `\r\n` pairs to `\n` — the projection digest's rule. A lone CR, or any other byte that
|
|
275
|
+
* differs from the canonical serialization, still fails closed.
|
|
276
|
+
*/
|
|
277
|
+
export function parseRefactorDecisionFile(path: string, body: string): RefactorDecisionV1 {
|
|
278
|
+
const match = REFACTOR_DECISION_FILE_PATTERN.exec(path);
|
|
279
|
+
if (!match) throw new Error(`refactor-decision-path-invalid: ${path} must be ${REFACTOR_DECISION_DIRECTORY}/recommendation.<16-hex>.json`);
|
|
280
|
+
const normalized = body.replaceAll("\r\n", "\n");
|
|
281
|
+
if (GIT_CONFLICT_MARKER_PATTERN.test(normalized)) throw new Error(`refactor-decision-conflicted: ${path} carries Git conflict markers; resolve the merge first`);
|
|
282
|
+
let value: unknown;
|
|
283
|
+
try {
|
|
284
|
+
value = JSON.parse(normalized);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
throw new Error(`refactor-decision-malformed: ${path} is not JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
287
|
+
}
|
|
288
|
+
const issues = refactorDecisionInvariantIssues(value, path);
|
|
289
|
+
if (issues.length > 0) throw new Error(`refactor-decision-invalid: ${issues.join("; ")}`);
|
|
290
|
+
const decision = value as RefactorDecisionV1;
|
|
291
|
+
if (decision.recommendationId !== match[1]) {
|
|
292
|
+
throw new Error(`refactor-decision-invalid: ${path} must be named after its recommendationId ${decision.recommendationId}`);
|
|
293
|
+
}
|
|
294
|
+
if (serializeRefactorDecision(decision) !== normalized) {
|
|
295
|
+
throw new Error(`refactor-decision-noncanonical: ${path} is not the canonical serialization the daemon writes; decision files are written only by archctx recommendations <verb>`);
|
|
296
|
+
}
|
|
297
|
+
return decision;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function decisionSubjectIssues(subject: unknown, label: string): string[] {
|
|
301
|
+
if (!isPlainObject(subject) || Object.keys(subject).sort().join(",") !== "selectorKind,stableKey,subjectSelectorId") {
|
|
302
|
+
return [`${label} must carry exactly selectorKind, stableKey and subjectSelectorId`];
|
|
303
|
+
}
|
|
304
|
+
const issues: string[] = [];
|
|
305
|
+
if (!REFACTOR_DECISION_SELECTOR_KINDS.includes(subject.selectorKind as ArchitectureSubjectSelectorKind)) {
|
|
306
|
+
issues.push(`${label}.selectorKind must be node or repository`);
|
|
307
|
+
}
|
|
308
|
+
issues.push(...boundedLineIssues(`${label}.stableKey`, subject.stableKey, REFACTOR_DECISION_STABLE_KEY_MAX_LENGTH));
|
|
309
|
+
if (typeof subject.subjectSelectorId !== "string" || !/^subject\.(node|repository)\.[a-f0-9]{16}$/.test(subject.subjectSelectorId)) {
|
|
310
|
+
issues.push(`${label}.subjectSelectorId must be a refactor subject selector id`);
|
|
311
|
+
}
|
|
312
|
+
return issues;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function decisionScopeIssues(scope: unknown, label: string): string[] {
|
|
316
|
+
if (!isPlainObject(scope)) return [`${label} must be an object`];
|
|
317
|
+
const keys = Object.keys(scope).sort().join(",");
|
|
318
|
+
if (scope.kind === "repository") {
|
|
319
|
+
return keys === "kind" ? [] : [`${label} must carry only kind for repository scope`];
|
|
320
|
+
}
|
|
321
|
+
if (scope.kind === "node") {
|
|
322
|
+
if (keys !== "kind,nodeId" || typeof scope.nodeId !== "string" || scope.nodeId.trim() === "") {
|
|
323
|
+
return [`${label} must carry kind and a non-empty nodeId for node scope`];
|
|
324
|
+
}
|
|
325
|
+
return [];
|
|
326
|
+
}
|
|
327
|
+
if (scope.kind === "paths") {
|
|
328
|
+
if (keys !== "kind,paths" || !Array.isArray(scope.paths) || scope.paths.length === 0 || scope.paths.some((p) => typeof p !== "string")) {
|
|
329
|
+
return [`${label} must carry kind and a non-empty paths array for paths scope`];
|
|
330
|
+
}
|
|
331
|
+
const issues = sortedUniqueIssues(`${label}.paths`, scope.paths as string[]);
|
|
332
|
+
for (const entry of scope.paths as string[]) {
|
|
333
|
+
issues.push(...repoPathIssues(`${label}.paths`, entry));
|
|
334
|
+
}
|
|
335
|
+
return issues;
|
|
336
|
+
}
|
|
337
|
+
return [`${label}.kind must be repository, node, or paths`];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function boundedLineIssues(label: string, value: unknown, maxLength: number): string[] {
|
|
341
|
+
if (typeof value !== "string" || value.trim() === "" || value !== value.trim()) {
|
|
342
|
+
return [`${label} must be a non-empty string without leading or trailing whitespace`];
|
|
343
|
+
}
|
|
344
|
+
if (value.length > maxLength) return [`${label} must be at most ${maxLength} characters`];
|
|
345
|
+
return /[\u0000-\u001f\u007f]/.test(value) ? [`${label} must be one line without control characters`] : [];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
349
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
350
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ArchitectureActorKind,
|
|
3
|
+
ArchitectureSubjectSelectorKind,
|
|
4
|
+
EvidenceCoverageLevelV2,
|
|
5
|
+
RecommendationCategory
|
|
6
|
+
} from "./ledger-records";
|
|
7
|
+
import type { ArchitectureMajorChangeReasonCode } from "./projection-constants";
|
|
8
|
+
import type {
|
|
9
|
+
REFACTOR_ASSESSMENT_SCHEMA_VERSION,
|
|
10
|
+
REFACTOR_DECISION_SCHEMA_VERSION,
|
|
11
|
+
REFACTOR_DETECTOR_EXTRA_KINDS,
|
|
12
|
+
REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION,
|
|
13
|
+
REFACTOR_RESOLUTION_EVIDENCE_SCHEMA_VERSION,
|
|
14
|
+
RefactorDecisionStatus,
|
|
15
|
+
RefactorExecutionEvidenceKind,
|
|
16
|
+
RefactorKillListKind,
|
|
17
|
+
RefactorObservationKind,
|
|
18
|
+
RefactorResolutionDisposition,
|
|
19
|
+
RefactorScale,
|
|
20
|
+
RefactorScaleReasonCode
|
|
21
|
+
} from "./refactor-constants";
|
|
22
|
+
import type {
|
|
23
|
+
RefactorObservedOutcomeV1,
|
|
24
|
+
RefactorScopeV1,
|
|
25
|
+
RefactorTargetOutcomeV1
|
|
26
|
+
} from "./refactor-types";
|
|
27
|
+
import type { Json, Severity } from "./schema";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One observed file-level import edge, as bounded metadata only: two repo-relative paths, the
|
|
31
|
+
* line the import sits on, the specifier verbatim and the owning nodes. Never a source body.
|
|
32
|
+
* `toPath` carries no line: an import names a module, not a position inside it.
|
|
33
|
+
*/
|
|
34
|
+
export interface RefactorEvidenceImportEdgeV1 {
|
|
35
|
+
fromPath: string;
|
|
36
|
+
/** 1-based line of the import statement in `fromPath`; `null` when the code index reported none. */
|
|
37
|
+
fromLine: number | null;
|
|
38
|
+
toPath: string;
|
|
39
|
+
specifier: string;
|
|
40
|
+
fromNodeId: string;
|
|
41
|
+
toNodeId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface RefactorEvidenceDirectionViolationV1 extends RefactorEvidenceImportEdgeV1 {
|
|
45
|
+
constraintId: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RefactorEvidencePathV1 {
|
|
49
|
+
path: string;
|
|
50
|
+
/**
|
|
51
|
+
* Declared nodes that bear on this path, per kind: for `ownership-ambiguous` every node that
|
|
52
|
+
* claims it; for `unowned-paths` the nodes that own another tracked file in the same directory;
|
|
53
|
+
* for `undeclared-footprint` the nodes that currently own the entrypoint path the node declares.
|
|
54
|
+
*/
|
|
55
|
+
candidateOwnerNodeIds: string[];
|
|
56
|
+
/** How many candidate owners exist; `candidateOwnerNodeIds` is its sorted, bounded prefix. */
|
|
57
|
+
candidateOwnerCount: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface RefactorEvidenceUnresolvedImportV1 {
|
|
61
|
+
fromPath: string;
|
|
62
|
+
fromLine: number | null;
|
|
63
|
+
specifier: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A bounded sample: `totalCount` is the population, `truncated` says the list is a prefix of it. */
|
|
67
|
+
interface RefactorEvidenceSampleV1 {
|
|
68
|
+
totalCount: number;
|
|
69
|
+
truncated: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* One direction of a bidirectional pair: its import-edge population and how many of the sampled
|
|
74
|
+
* `edges` it holds. The thin direction (fewer distinct file edges, ties to the canonical forward
|
|
75
|
+
* direction) is listed first and is sampled first.
|
|
76
|
+
*/
|
|
77
|
+
export interface RefactorEvidencePairDirectionV1 {
|
|
78
|
+
fromNodeId: string;
|
|
79
|
+
toNodeId: string;
|
|
80
|
+
totalCount: number;
|
|
81
|
+
sampledCount: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RefactorEvidenceLowCohesionClusterV1 {
|
|
85
|
+
symbols: string[];
|
|
86
|
+
startLine: number;
|
|
87
|
+
endLine: number;
|
|
88
|
+
intraClusterEdges: number;
|
|
89
|
+
crossClusterEdges: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface RefactorEvidenceLowCohesionFileV1 {
|
|
93
|
+
path: string;
|
|
94
|
+
lineCount: number;
|
|
95
|
+
topLevelSymbolCount: number;
|
|
96
|
+
clusterCount: number;
|
|
97
|
+
clusters: RefactorEvidenceLowCohesionClusterV1[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface RefactorEvidenceUnstableTargetV1 {
|
|
101
|
+
targetNodeId: string;
|
|
102
|
+
targetInstability: number;
|
|
103
|
+
delta: number;
|
|
104
|
+
edgeCount: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface RefactorEvidenceCoChangePairV1 {
|
|
108
|
+
pathA: string;
|
|
109
|
+
pathB: string;
|
|
110
|
+
coChangeCount: number;
|
|
111
|
+
jaccard: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type RefactorObservationEvidenceV1 =
|
|
115
|
+
| ({
|
|
116
|
+
kind: "cycle";
|
|
117
|
+
/** The pair, sorted: `[A, B]`. */
|
|
118
|
+
memberNodeIds: string[];
|
|
119
|
+
/** `[thin, thick]`; `totalCount` is their sum. */
|
|
120
|
+
directions: RefactorEvidencePairDirectionV1[];
|
|
121
|
+
edges: RefactorEvidenceImportEdgeV1[];
|
|
122
|
+
} & RefactorEvidenceSampleV1)
|
|
123
|
+
| ({ kind: "residual-cycle"; memberNodeIds: string[]; edges: RefactorEvidenceImportEdgeV1[] } & RefactorEvidenceSampleV1)
|
|
124
|
+
| ({
|
|
125
|
+
kind: "direction-violation";
|
|
126
|
+
constraintIds: string[];
|
|
127
|
+
/** How many distinct constraints the module violates; `constraintIds` is its bounded prefix. */
|
|
128
|
+
constraintCount: number;
|
|
129
|
+
violations: RefactorEvidenceDirectionViolationV1[];
|
|
130
|
+
} & RefactorEvidenceSampleV1)
|
|
131
|
+
| ({ kind: "ownership-ambiguous" | "undeclared-footprint" | "unowned-paths"; paths: RefactorEvidencePathV1[] } & RefactorEvidenceSampleV1)
|
|
132
|
+
| ({
|
|
133
|
+
kind: "evidence-gap";
|
|
134
|
+
coverage: EvidenceCoverageLevelV2;
|
|
135
|
+
reasonCodes: RefactorScaleReasonCode[];
|
|
136
|
+
unresolvedImports: RefactorEvidenceUnresolvedImportV1[];
|
|
137
|
+
} & RefactorEvidenceSampleV1)
|
|
138
|
+
| ({ kind: "low-cohesion-god-file"; files: RefactorEvidenceLowCohesionFileV1[] } & RefactorEvidenceSampleV1)
|
|
139
|
+
| ({ kind: "entrypoint-bypass"; declaredEntrypointPaths: string[]; edges: RefactorEvidenceImportEdgeV1[] } & RefactorEvidenceSampleV1)
|
|
140
|
+
| ({
|
|
141
|
+
kind: "unstable-dependency";
|
|
142
|
+
sourceFanIn: number;
|
|
143
|
+
sourceInstability: number;
|
|
144
|
+
targets: RefactorEvidenceUnstableTargetV1[];
|
|
145
|
+
} & RefactorEvidenceSampleV1)
|
|
146
|
+
| ({
|
|
147
|
+
kind: "co-change-coupling";
|
|
148
|
+
memberNodeIds: string[];
|
|
149
|
+
coverageStatus: "complete" | "shallow" | "insufficient-history" | "unavailable";
|
|
150
|
+
windowLimit: number;
|
|
151
|
+
observedCommitCount: number;
|
|
152
|
+
pairs: RefactorEvidenceCoChangePairV1[];
|
|
153
|
+
} & RefactorEvidenceSampleV1);
|
|
154
|
+
|
|
155
|
+
export interface RefactorObservationV1 {
|
|
156
|
+
kind: RefactorObservationKind;
|
|
157
|
+
subjectSelectorId: string;
|
|
158
|
+
/**
|
|
159
|
+
* The declared nodes this observation is about, sorted and unique, authored by the producer that
|
|
160
|
+
* measured it: a node subject is `[nodeId]`, a pair its two ends, a residual cycle its members, a
|
|
161
|
+
* repository-wide fact `[]`. Scopes filter on it and the planner copies it; nothing re-derives it.
|
|
162
|
+
*/
|
|
163
|
+
affectedNodeIds: string[];
|
|
164
|
+
signalIds: string[];
|
|
165
|
+
metrics: Record<string, number | null>;
|
|
166
|
+
evidence: RefactorObservationEvidenceV1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface RefactorAssessmentV1 {
|
|
170
|
+
schemaVersion: typeof REFACTOR_ASSESSMENT_SCHEMA_VERSION;
|
|
171
|
+
requestId: string;
|
|
172
|
+
statisticsSnapshotDigest: string;
|
|
173
|
+
modelDigest: string;
|
|
174
|
+
codeFactsDigest: string;
|
|
175
|
+
requestedScope: RefactorScopeV1;
|
|
176
|
+
proposalDigest: string | null;
|
|
177
|
+
observations: RefactorObservationV1[];
|
|
178
|
+
scale: RefactorScale | null;
|
|
179
|
+
scaleReasonCodes: RefactorScaleReasonCode[];
|
|
180
|
+
affectedNodeIds: string[];
|
|
181
|
+
majorChangeReasons: ArchitectureMajorChangeReasonCode[];
|
|
182
|
+
pressure: {
|
|
183
|
+
level: "low" | "medium" | "high";
|
|
184
|
+
score: number;
|
|
185
|
+
signalIds: string[];
|
|
186
|
+
};
|
|
187
|
+
confidence: {
|
|
188
|
+
level: "low" | "medium" | "high";
|
|
189
|
+
callerCoverage: number | null;
|
|
190
|
+
testsObserved: boolean | null;
|
|
191
|
+
rollbackObserved: boolean | null;
|
|
192
|
+
unresolvedEvidence: string[];
|
|
193
|
+
};
|
|
194
|
+
createdAt: string;
|
|
195
|
+
assessmentDigest: string;
|
|
196
|
+
extensions?: Record<string, Json>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface RefactorResidualV1 {
|
|
200
|
+
code: string;
|
|
201
|
+
subject: string;
|
|
202
|
+
severity: Severity;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface RefactorExecutionEvidenceRefV1 {
|
|
206
|
+
kind: RefactorExecutionEvidenceKind;
|
|
207
|
+
locator: string;
|
|
208
|
+
sha256: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface RefactorResolutionEvidenceV1 {
|
|
212
|
+
schemaVersion: typeof REFACTOR_RESOLUTION_EVIDENCE_SCHEMA_VERSION;
|
|
213
|
+
recommendationId: string;
|
|
214
|
+
recommendationDigest: string;
|
|
215
|
+
beforeSnapshotDigest: string;
|
|
216
|
+
afterSnapshotDigest: string;
|
|
217
|
+
verifiedHeadSha: string;
|
|
218
|
+
verifiedWorktreeDigest: string;
|
|
219
|
+
expectedOutcomes: RefactorTargetOutcomeV1[];
|
|
220
|
+
observedOutcomes: RefactorObservedOutcomeV1[];
|
|
221
|
+
residuals: RefactorResidualV1[];
|
|
222
|
+
executionEvidenceRefs: RefactorExecutionEvidenceRefV1[];
|
|
223
|
+
disposition: RefactorResolutionDisposition;
|
|
224
|
+
verifiedAt: string;
|
|
225
|
+
resolutionDigest: string;
|
|
226
|
+
extensions?: Record<string, Json>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface RecommendationV3FingerprintInputV1 {
|
|
230
|
+
category: RecommendationCategory;
|
|
231
|
+
subjectSelectorId: string;
|
|
232
|
+
practiceId: string | null;
|
|
233
|
+
payload: Record<string, Json>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The latest human decision for one refactor recommendation generation, stored in Git at
|
|
238
|
+
* `.archcontext/refactor-decisions/<recommendationId>.json` (ADR-0046). It carries identity and the
|
|
239
|
+
* decided measurement only: no absolute path, storage id, source, diff or evidence body.
|
|
240
|
+
*/
|
|
241
|
+
export interface RefactorDecisionKillTargetV1 {
|
|
242
|
+
kind: RefactorKillListKind;
|
|
243
|
+
target: string;
|
|
244
|
+
required: boolean;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface RefactorDecisionV1 {
|
|
248
|
+
schemaVersion: typeof REFACTOR_DECISION_SCHEMA_VERSION;
|
|
249
|
+
/** The manifest `product.id` the subject selector is scoped by. */
|
|
250
|
+
namespace: string;
|
|
251
|
+
recommendationId: string;
|
|
252
|
+
fingerprint: string;
|
|
253
|
+
fingerprintSchemaVersion: typeof REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION;
|
|
254
|
+
category: "refactor_proposal" | "structural_observation";
|
|
255
|
+
/** The observation or v2 detector kind; `null` for a refactor proposal. */
|
|
256
|
+
kind: RefactorObservationKind | (typeof REFACTOR_DETECTOR_EXTRA_KINDS)[number] | null;
|
|
257
|
+
subject: {
|
|
258
|
+
selectorKind: ArchitectureSubjectSelectorKind;
|
|
259
|
+
stableKey: string;
|
|
260
|
+
subjectSelectorId: string;
|
|
261
|
+
};
|
|
262
|
+
/** Sorted prefix of the affected nodes, bounded by `REFACTOR_EVIDENCE_ID_LIST_LIMIT`. */
|
|
263
|
+
affectedNodeIds: string[];
|
|
264
|
+
affectedNodeCount: number;
|
|
265
|
+
regressesFrom: string | null;
|
|
266
|
+
status: RefactorDecisionStatus;
|
|
267
|
+
/** The measurement the decision was taken against; `null` when the record carries none. */
|
|
268
|
+
observationMetrics: Record<string, number | null> | null;
|
|
269
|
+
/** Scope of the measured observation metrics. Absent for repository baselines. */
|
|
270
|
+
observationScopeDigest?: string;
|
|
271
|
+
reason: string;
|
|
272
|
+
actor: { kind: ArchitectureActorKind; id: string };
|
|
273
|
+
decidedAt: string;
|
|
274
|
+
provenance: {
|
|
275
|
+
headSha: string;
|
|
276
|
+
assessmentDigest: string;
|
|
277
|
+
baselineSnapshotDigest: string;
|
|
278
|
+
};
|
|
279
|
+
snapshotDigest?: string;
|
|
280
|
+
evidenceDigest?: string;
|
|
281
|
+
resolutionDigest?: string;
|
|
282
|
+
scope?: RefactorScopeV1;
|
|
283
|
+
importNodeLimit?: number;
|
|
284
|
+
targetOutcomes?: RefactorTargetOutcomeV1[];
|
|
285
|
+
killList?: RefactorDecisionKillTargetV1[];
|
|
286
|
+
}
|