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
package/src/ref-impact.ts
CHANGED
|
@@ -1,22 +1,235 @@
|
|
|
1
|
-
import type { NativeContextSnapshot } from "./native-context";
|
|
2
1
|
import { isRepoRelativePosixPath } from "./schema";
|
|
2
|
+
import {
|
|
3
|
+
ArchContextErrorSchema,
|
|
4
|
+
Const,
|
|
5
|
+
GitOidSchema,
|
|
6
|
+
NullableType,
|
|
7
|
+
OneOf,
|
|
8
|
+
RawEnum,
|
|
9
|
+
Ref,
|
|
10
|
+
SchemaDocument,
|
|
11
|
+
StrictObject,
|
|
12
|
+
Type,
|
|
13
|
+
TypedUnsafe,
|
|
14
|
+
type Static
|
|
15
|
+
} from "./schema-kit";
|
|
3
16
|
|
|
4
17
|
export const REF_IMPACT_BATCH_REQUEST_SCHEMA_VERSION = "archcontext.ref-impact-batch-request/v1" as const;
|
|
5
18
|
export const REF_IMPACT_BATCH_SCHEMA_VERSION = "archcontext.ref-impact-batch/v1" as const;
|
|
19
|
+
export const REF_IMPACT_SCHEMA_VERSION = "archcontext.ref-impact/v1" as const;
|
|
6
20
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
export const REF_IMPACT_LIMITS = Object.freeze({
|
|
22
|
+
changedPaths: 1000,
|
|
23
|
+
nodes: 1000,
|
|
24
|
+
relations: 5000,
|
|
25
|
+
flowSteps: 2000,
|
|
26
|
+
dependents: 5000,
|
|
27
|
+
modelChanges: 5000,
|
|
28
|
+
depth: 10,
|
|
29
|
+
diffLines: 100_000,
|
|
30
|
+
diffWork: 2_000_000,
|
|
31
|
+
diffBytes: 8 * 1024 * 1024,
|
|
32
|
+
responseBytes: 8 * 1024 * 1024,
|
|
33
|
+
codeFactFiles: 10_000,
|
|
34
|
+
codeFactBytes: 8 * 1024 * 1024
|
|
35
|
+
});
|
|
11
36
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
export const NativeContextSnapshotSchema = OneOf([
|
|
38
|
+
StrictObject({
|
|
39
|
+
source: Const("ref"),
|
|
40
|
+
commitSha: GitOidSchema,
|
|
41
|
+
treeOid: GitOidSchema,
|
|
42
|
+
validation: Const("immutable-tree")
|
|
43
|
+
}),
|
|
44
|
+
StrictObject({
|
|
45
|
+
source: Const("worktree"),
|
|
46
|
+
headSha: GitOidSchema,
|
|
47
|
+
headTreeOid: GitOidSchema,
|
|
48
|
+
validation: Const("stable-read")
|
|
49
|
+
})
|
|
50
|
+
]);
|
|
15
51
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
52
|
+
const RefImpactFlowStepSchema = StrictObject({
|
|
53
|
+
flowId: Type.String(),
|
|
54
|
+
stepId: Type.String(),
|
|
55
|
+
outcomeId: NullableType("string"),
|
|
56
|
+
reasonCodes: Type.Array(Type.String())
|
|
57
|
+
});
|
|
58
|
+
/** Items also identify uncertain steps via selector-evidence-unavailable; inspect reasons before claiming a touch. */
|
|
59
|
+
export type RefImpactFlowStep = Static<typeof RefImpactFlowStepSchema>;
|
|
60
|
+
|
|
61
|
+
const RefImpactModelChangeSchema = StrictObject({
|
|
62
|
+
kind: RawEnum(["nodes", "relations", "flows"] as const),
|
|
63
|
+
id: Type.String(),
|
|
64
|
+
change: RawEnum(["added", "removed", "changed"] as const),
|
|
65
|
+
fields: Type.Array(Type.String())
|
|
66
|
+
});
|
|
67
|
+
export type RefImpactModelChange = { kind: string; id: string; change: "added" | "removed" | "changed"; fields: string[] };
|
|
68
|
+
|
|
69
|
+
const touchedFlowStepsSchema = OneOf([
|
|
70
|
+
StrictObject({
|
|
71
|
+
status: Const("known"),
|
|
72
|
+
reasonCodes: Type.Array(Type.String(), { maxItems: 0 }),
|
|
73
|
+
items: Type.Array(RefImpactFlowStepSchema, { maxItems: REF_IMPACT_LIMITS.flowSteps })
|
|
74
|
+
}),
|
|
75
|
+
StrictObject({
|
|
76
|
+
status: Const("unknown"),
|
|
77
|
+
reasonCodes: Type.Array(Type.String(), { minItems: 1 }),
|
|
78
|
+
items: OneOf([
|
|
79
|
+
Type.Null(),
|
|
80
|
+
Type.Array(RefImpactFlowStepSchema, { maxItems: REF_IMPACT_LIMITS.flowSteps })
|
|
81
|
+
])
|
|
82
|
+
})
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
const modelDeltaSchema = OneOf([
|
|
86
|
+
StrictObject({
|
|
87
|
+
status: Const("known"),
|
|
88
|
+
changes: Type.Array(RefImpactModelChangeSchema, { maxItems: REF_IMPACT_LIMITS.modelChanges }),
|
|
89
|
+
truncated: Type.Boolean()
|
|
90
|
+
}),
|
|
91
|
+
StrictObject({
|
|
92
|
+
status: Const("unknown"),
|
|
93
|
+
reasonCode: Const("paths-only"),
|
|
94
|
+
changes: Type.Null(),
|
|
95
|
+
truncated: Const(false)
|
|
96
|
+
})
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const RefImpactBodySchema = StrictObject({
|
|
100
|
+
schemaVersion: Const(REF_IMPACT_SCHEMA_VERSION),
|
|
101
|
+
base: OneOf([Type.Null(), NativeContextSnapshotSchema]),
|
|
102
|
+
head: NativeContextSnapshotSchema,
|
|
103
|
+
depth: Type.Integer({ minimum: 0, maximum: REF_IMPACT_LIMITS.depth }),
|
|
104
|
+
changedPaths: Type.Array(
|
|
105
|
+
StrictObject({
|
|
106
|
+
path: Type.String(),
|
|
107
|
+
added: NullableType("integer", { minimum: 0 }),
|
|
108
|
+
deleted: NullableType("integer", { minimum: 0 }),
|
|
109
|
+
baseOwners: Type.Array(Type.String()),
|
|
110
|
+
headOwners: Type.Array(Type.String()),
|
|
111
|
+
owners: Type.Array(Type.String()),
|
|
112
|
+
reasonCodes: Type.Array(Type.String())
|
|
113
|
+
}),
|
|
114
|
+
{ maxItems: REF_IMPACT_LIMITS.changedPaths }
|
|
115
|
+
),
|
|
116
|
+
unownedPaths: Type.Array(Type.String()),
|
|
117
|
+
touchedNodes: Type.Array(
|
|
118
|
+
StrictObject({
|
|
119
|
+
nodeId: Type.String(),
|
|
120
|
+
pathCount: Type.Integer({ minimum: 0 })
|
|
121
|
+
}),
|
|
122
|
+
{ maxItems: REF_IMPACT_LIMITS.nodes }
|
|
123
|
+
),
|
|
124
|
+
touchedFlowSteps: TypedUnsafe<{ status: "known" | "unknown"; reasonCodes: string[]; items: RefImpactFlowStep[] | null }>(touchedFlowStepsSchema),
|
|
125
|
+
dependents: Type.Array(
|
|
126
|
+
StrictObject({
|
|
127
|
+
nodeId: Type.String(),
|
|
128
|
+
touchedNodeId: Type.String(),
|
|
129
|
+
relationIds: Type.Array(Type.String())
|
|
130
|
+
}),
|
|
131
|
+
{ maxItems: REF_IMPACT_LIMITS.dependents }
|
|
132
|
+
),
|
|
133
|
+
dependencyCoverage: StrictObject({
|
|
134
|
+
status: RawEnum(["complete", "partial"] as const),
|
|
135
|
+
graph: Const("head"),
|
|
136
|
+
pathSelection: Const("one-shortest-path-per-node-pair")
|
|
137
|
+
}),
|
|
138
|
+
modelDelta: TypedUnsafe<
|
|
139
|
+
| { status: "known"; changes: RefImpactModelChange[]; truncated: boolean }
|
|
140
|
+
| { status: "unknown"; reasonCode: "paths-only"; changes: null; truncated: false }
|
|
141
|
+
>(modelDeltaSchema),
|
|
142
|
+
limits: StrictObject({
|
|
143
|
+
codeFactFiles: Const(REF_IMPACT_LIMITS.codeFactFiles),
|
|
144
|
+
codeFactBytes: Const(REF_IMPACT_LIMITS.codeFactBytes),
|
|
145
|
+
changedPaths: Const(REF_IMPACT_LIMITS.changedPaths),
|
|
146
|
+
nodes: Const(REF_IMPACT_LIMITS.nodes),
|
|
147
|
+
relations: Const(REF_IMPACT_LIMITS.relations),
|
|
148
|
+
flowSteps: Const(REF_IMPACT_LIMITS.flowSteps),
|
|
149
|
+
dependents: Const(REF_IMPACT_LIMITS.dependents),
|
|
150
|
+
modelChanges: Const(REF_IMPACT_LIMITS.modelChanges),
|
|
151
|
+
depth: Const(REF_IMPACT_LIMITS.depth),
|
|
152
|
+
diffBytes: Const(REF_IMPACT_LIMITS.diffBytes),
|
|
153
|
+
responseBytes: Const(REF_IMPACT_LIMITS.responseBytes),
|
|
154
|
+
diffLines: Const(REF_IMPACT_LIMITS.diffLines),
|
|
155
|
+
diffWork: Const(REF_IMPACT_LIMITS.diffWork)
|
|
156
|
+
}),
|
|
157
|
+
truncated: StrictObject({
|
|
158
|
+
changedPaths: Type.Boolean(),
|
|
159
|
+
touchedNodes: Type.Boolean(),
|
|
160
|
+
relations: Type.Boolean(),
|
|
161
|
+
flowSteps: Type.Boolean(),
|
|
162
|
+
dependents: Type.Boolean(),
|
|
163
|
+
modelDelta: Type.Boolean()
|
|
164
|
+
})
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export const RefImpactSchema = SchemaDocument({
|
|
168
|
+
$id: "https://archctx.repoharness.com/schemas/runtime/ref-impact.schema.json",
|
|
169
|
+
title: "RefImpactV1",
|
|
170
|
+
schema: RefImpactBodySchema
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/** No timestamps, workspace paths, source bodies or live session state. */
|
|
174
|
+
export type RefImpactV1 = Static<typeof RefImpactSchema>;
|
|
175
|
+
|
|
176
|
+
const BATCH_REPO_PATH_PATTERN = "^(?!/)(?![\\s\\S]*(?:^|/)\\.\\.(?:/|(?![\\s\\S])))[^\\\\\u0000]+$";
|
|
177
|
+
|
|
178
|
+
export const RefImpactBatchRequestBodySchema = StrictObject({
|
|
179
|
+
schemaVersion: Const(REF_IMPACT_BATCH_REQUEST_SCHEMA_VERSION),
|
|
180
|
+
items: Type.Array(
|
|
181
|
+
StrictObject({
|
|
182
|
+
id: Type.String(),
|
|
183
|
+
paths: Type.Array(Type.String({ pattern: BATCH_REPO_PATH_PATTERN }))
|
|
184
|
+
})
|
|
185
|
+
)
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export const RefImpactBatchRequestSchema = SchemaDocument({
|
|
189
|
+
$id: "https://archcontext.dev/schemas/runtime/ref-impact-batch-request.schema.json",
|
|
190
|
+
title: "RefImpactBatchRequestV1",
|
|
191
|
+
schema: RefImpactBatchRequestBodySchema
|
|
192
|
+
});
|
|
193
|
+
export type RefImpactBatchRequestV1 = Static<typeof RefImpactBatchRequestSchema>;
|
|
194
|
+
|
|
195
|
+
export const REF_IMPACT_BATCH_UNAVAILABLE_REASONS = [
|
|
196
|
+
"batch-response-bytes",
|
|
197
|
+
"head-ref-unavailable",
|
|
198
|
+
"base-ref-unavailable",
|
|
199
|
+
"diff-limit-exceeded",
|
|
200
|
+
"model-invalid",
|
|
201
|
+
"path-invalid",
|
|
202
|
+
"worktree-error"
|
|
203
|
+
] as const;
|
|
204
|
+
export type RefImpactBatchUnavailableReason = (typeof REF_IMPACT_BATCH_UNAVAILABLE_REASONS)[number];
|
|
205
|
+
|
|
206
|
+
export const RefImpactBatchItemSchema = OneOf([
|
|
207
|
+
StrictObject({
|
|
208
|
+
id: Type.String(),
|
|
209
|
+
impact: Ref<RefImpactV1>("https://archctx.repoharness.com/schemas/runtime/ref-impact.schema.json")
|
|
210
|
+
}),
|
|
211
|
+
StrictObject({
|
|
212
|
+
id: Type.String(),
|
|
213
|
+
status: Const("unavailable"),
|
|
214
|
+
reasonCode: RawEnum(REF_IMPACT_BATCH_UNAVAILABLE_REASONS),
|
|
215
|
+
error: Type.Optional(ArchContextErrorSchema)
|
|
216
|
+
})
|
|
217
|
+
]);
|
|
218
|
+
export type RefImpactBatchItemV1 = Static<typeof RefImpactBatchItemSchema>;
|
|
219
|
+
|
|
220
|
+
export const RefImpactBatchBodySchema = StrictObject({
|
|
221
|
+
schemaVersion: Const(REF_IMPACT_BATCH_SCHEMA_VERSION),
|
|
222
|
+
items: Type.Array(RefImpactBatchItemSchema, {
|
|
223
|
+
description: "One impact or typed refusal/response-limit status per request item, in request order."
|
|
224
|
+
})
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export const RefImpactBatchSchema = SchemaDocument({
|
|
228
|
+
$id: "https://archcontext.dev/schemas/runtime/ref-impact-batch.schema.json",
|
|
229
|
+
title: "RefImpactBatchV1",
|
|
230
|
+
schema: RefImpactBatchBodySchema
|
|
231
|
+
});
|
|
232
|
+
export type RefImpactBatchV1 = Static<typeof RefImpactBatchSchema>;
|
|
20
233
|
|
|
21
234
|
export function isRefImpactBatchRequest(value: unknown): value is RefImpactBatchRequestV1 {
|
|
22
235
|
if (!isRecord(value) || Object.keys(value).length !== 2 || value.schemaVersion !== REF_IMPACT_BATCH_REQUEST_SCHEMA_VERSION || !Array.isArray(value.items)) return false;
|
|
@@ -32,24 +245,3 @@ export function isRefImpactBatchRequest(value: unknown): value is RefImpactBatch
|
|
|
32
245
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
33
246
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
34
247
|
}
|
|
35
|
-
export const REF_IMPACT_SCHEMA_VERSION = "archcontext.ref-impact/v1" as const;
|
|
36
|
-
export const REF_IMPACT_LIMITS = Object.freeze({ changedPaths: 1000, nodes: 1000, relations: 5000, flowSteps: 2000, dependents: 5000, modelChanges: 5000, depth: 10, diffLines: 100_000, diffWork: 2_000_000, diffBytes: 8 * 1024 * 1024, responseBytes: 8 * 1024 * 1024, codeFactFiles: 10_000, codeFactBytes: 8 * 1024 * 1024 });
|
|
37
|
-
export interface RefImpactModelChange { kind: string; id: string; change: "added" | "removed" | "changed"; fields: string[] }
|
|
38
|
-
/** Items also identify uncertain steps via selector-evidence-unavailable; inspect reasons before claiming a touch. */
|
|
39
|
-
export interface RefImpactFlowStep { flowId: string; stepId: string; outcomeId: string | null; reasonCodes: string[] }
|
|
40
|
-
/** No timestamps, workspace paths, source bodies or live session state. */
|
|
41
|
-
export interface RefImpactV1 {
|
|
42
|
-
schemaVersion: typeof REF_IMPACT_SCHEMA_VERSION;
|
|
43
|
-
base: NativeContextSnapshot | null;
|
|
44
|
-
head: NativeContextSnapshot;
|
|
45
|
-
depth: number;
|
|
46
|
-
changedPaths: Array<{ path: string; added: number | null; deleted: number | null; baseOwners: string[]; headOwners: string[]; owners: string[]; reasonCodes: string[] }>;
|
|
47
|
-
unownedPaths: string[];
|
|
48
|
-
touchedNodes: Array<{ nodeId: string; pathCount: number }>;
|
|
49
|
-
touchedFlowSteps: { status: "known" | "unknown"; reasonCodes: string[]; items: RefImpactFlowStep[] | null };
|
|
50
|
-
dependents: Array<{ nodeId: string; touchedNodeId: string; relationIds: string[] }>;
|
|
51
|
-
dependencyCoverage: { status: "complete" | "partial"; graph: "head"; pathSelection: "one-shortest-path-per-node-pair" };
|
|
52
|
-
modelDelta: { status: "known"; changes: RefImpactModelChange[]; truncated: boolean } | { status: "unknown"; reasonCode: "paths-only"; changes: null; truncated: false };
|
|
53
|
-
limits: typeof REF_IMPACT_LIMITS;
|
|
54
|
-
truncated: { changedPaths: boolean; touchedNodes: boolean; relations: boolean; flowSteps: boolean; dependents: boolean; modelDelta: boolean };
|
|
55
|
-
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ArchitectureActorKind,
|
|
3
|
+
ArchitectureSubjectSelectorKind,
|
|
4
|
+
RecommendationStatus
|
|
5
|
+
} from "./ledger-records";
|
|
6
|
+
import { isRepoRelativePosixPath } from "./schema";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The bounded grammar an execution evidence `locator` must fit: 1..256 characters drawn from the
|
|
10
|
+
* unreserved plus sub-delims/gen-delims set that repo-relative paths and URLs already live in.
|
|
11
|
+
*
|
|
12
|
+
* A locator is a *reference*, not a body. Left unbounded it is a string field on a record whose
|
|
13
|
+
* envelope promises `privacy.rawDiffPersisted: false`, so a caller could park a whole diff, a
|
|
14
|
+
* credential, or a multi-line prompt in it and the digest check would still pass. Whitespace,
|
|
15
|
+
* newlines and control characters are the shapes that only a body has, and the length ceiling is
|
|
16
|
+
* what stops a single-line body from riding through anyway.
|
|
17
|
+
*/
|
|
18
|
+
export const REFACTOR_EXECUTION_EVIDENCE_LOCATOR_PATTERN = /^[A-Za-z0-9._~:\/?#@!$&'()*+,;=%-]{1,256}$/;
|
|
19
|
+
|
|
20
|
+
/** The single sentence every ingress uses to name the locator rule, so they cannot drift apart. */
|
|
21
|
+
export const REFACTOR_EXECUTION_EVIDENCE_LOCATOR_RULE =
|
|
22
|
+
"must be a bounded reference: 1-256 characters from [A-Za-z0-9._~:/?#@!$&'()*+,;=%-], no whitespace or control characters";
|
|
23
|
+
|
|
24
|
+
/** The only top-level keys a verification request may carry; anything else is a caller typo. */
|
|
25
|
+
export const REFACTOR_VERIFICATION_REQUEST_KEYS = [
|
|
26
|
+
"executionEvidenceRefs",
|
|
27
|
+
"expectedHeadSha",
|
|
28
|
+
"expectedWorktreeDigest",
|
|
29
|
+
"importNodeLimit",
|
|
30
|
+
"recommendationId",
|
|
31
|
+
"schemaVersion"
|
|
32
|
+
] as const;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The grammar of the refactor identity namespace: the manifest `product.id`, which scopes every
|
|
36
|
+
* refactor subject selector so one subject has one recommendation id in every worktree, branch and
|
|
37
|
+
* clone (ADR-0046). It is the declared-id grammar node ids use, without the cross-repo prefix.
|
|
38
|
+
*/
|
|
39
|
+
export const REFACTOR_NAMESPACE_PATTERN = /^[a-z][a-z0-9]*(\.[a-z0-9][a-z0-9-]*)+$/;
|
|
40
|
+
|
|
41
|
+
/** Issues with a refactor namespace value; empty when it is a well-formed `product.id`. */
|
|
42
|
+
export function refactorNamespaceIssues(value: unknown, label = "product.id"): string[] {
|
|
43
|
+
if (typeof value !== "string") return [`${label} must be a string`];
|
|
44
|
+
if (value.trim() === "") return [`${label} must not be blank`];
|
|
45
|
+
return REFACTOR_NAMESPACE_PATTERN.test(value)
|
|
46
|
+
? []
|
|
47
|
+
: [`${label} must match ${REFACTOR_NAMESPACE_PATTERN.source}`];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const REFACTOR_REQUEST_SCHEMA_VERSION = "archcontext.refactor-request/v1" as const;
|
|
51
|
+
export const REFACTOR_PROPOSAL_SCHEMA_VERSION = "archcontext.refactor-proposal/v1" as const;
|
|
52
|
+
export const MODULE_STATISTICS_SCHEMA_VERSION = "archcontext.module-statistics/v1" as const;
|
|
53
|
+
export const REFACTOR_ASSESSMENT_SCHEMA_VERSION = "archcontext.refactor-assessment/v1" as const;
|
|
54
|
+
export const REFACTOR_RESOLUTION_EVIDENCE_SCHEMA_VERSION = "archcontext.refactor-resolution-evidence/v1" as const;
|
|
55
|
+
export const REFACTOR_VERIFICATION_REQUEST_SCHEMA_VERSION = "archcontext.refactor-verification-request/v1" as const;
|
|
56
|
+
|
|
57
|
+
export const REFACTOR_SCALES = [
|
|
58
|
+
"architecture",
|
|
59
|
+
"cross_module",
|
|
60
|
+
"insufficient_evidence",
|
|
61
|
+
"model_adoption_required",
|
|
62
|
+
"module"
|
|
63
|
+
] as const;
|
|
64
|
+
export const REFACTOR_SCALE_REASON_CODES = [
|
|
65
|
+
"caller-coverage-unknown",
|
|
66
|
+
"code-facts-import-limit",
|
|
67
|
+
"code-facts-missing",
|
|
68
|
+
"code-facts-truncated",
|
|
69
|
+
"major-change-detected",
|
|
70
|
+
"multi-node-scope",
|
|
71
|
+
"node-footprint-undeclared",
|
|
72
|
+
"ownership-ambiguous",
|
|
73
|
+
"single-node-scope",
|
|
74
|
+
"target-unresolved",
|
|
75
|
+
"unowned-paths"
|
|
76
|
+
] as const;
|
|
77
|
+
/**
|
|
78
|
+
* `cycle` is one bidirectional module pair; `residual-cycle` is a strongly connected component that
|
|
79
|
+
* survives cutting the thin direction of every pair (ADR-0046).
|
|
80
|
+
*/
|
|
81
|
+
export const REFACTOR_OBSERVATION_KINDS = [
|
|
82
|
+
"co-change-coupling",
|
|
83
|
+
"cycle",
|
|
84
|
+
"direction-violation",
|
|
85
|
+
"entrypoint-bypass",
|
|
86
|
+
"evidence-gap",
|
|
87
|
+
"low-cohesion-god-file",
|
|
88
|
+
"ownership-ambiguous",
|
|
89
|
+
"residual-cycle",
|
|
90
|
+
"undeclared-footprint",
|
|
91
|
+
"unowned-paths",
|
|
92
|
+
"unstable-dependency"
|
|
93
|
+
] as const;
|
|
94
|
+
export const REFACTOR_DETECTOR_EXTRA_KINDS = [
|
|
95
|
+
"component-cycle",
|
|
96
|
+
"dead-public-export",
|
|
97
|
+
"file-cycle",
|
|
98
|
+
"god-file",
|
|
99
|
+
"purity-violation",
|
|
100
|
+
"shotgun-surgery-hotspot",
|
|
101
|
+
"undeclared-dependency"
|
|
102
|
+
] as const;
|
|
103
|
+
export const REFACTOR_RESOLUTION_DISPOSITIONS = [
|
|
104
|
+
"not_improved",
|
|
105
|
+
"partially_resolved",
|
|
106
|
+
"regressed",
|
|
107
|
+
"resolved",
|
|
108
|
+
"stale"
|
|
109
|
+
] as const;
|
|
110
|
+
export const REFACTOR_OUTCOME_OPERATORS = ["absent", "equals", "greater_than", "less_than", "present"] as const;
|
|
111
|
+
export const REFACTOR_OUTCOME_DIRECTIONS = ["improved", "regressed", "unchanged", "unknown"] as const;
|
|
112
|
+
export const REFACTOR_KILL_LIST_KINDS = ["path", "relation", "symbol"] as const;
|
|
113
|
+
export const REFACTOR_EXECUTION_EVIDENCE_KINDS = [
|
|
114
|
+
"acceptance_receipt",
|
|
115
|
+
"cutover_closure",
|
|
116
|
+
"merge_receipt",
|
|
117
|
+
"task_contract"
|
|
118
|
+
] as const;
|
|
119
|
+
export const REFACTOR_PROPOSAL_AUTHOR_SOURCES = ["cli", "manual", "mcp", "subagent"] as const;
|
|
120
|
+
export const REFACTOR_PROPOSAL_AUTHOR_KINDS = ["cli", "developer", "mcp", "subagent"] as const;
|
|
121
|
+
/**
|
|
122
|
+
* A refactor proposal is authored by an agent surface acting for itself, or by
|
|
123
|
+
* a human acting manually. `daemon`, `system`, `hook`, and `migration` kinds
|
|
124
|
+
* are ArchContext acting on its own behalf and can never author a proposal.
|
|
125
|
+
*/
|
|
126
|
+
export const REFACTOR_PROPOSAL_AUTHOR_PAIRS: Readonly<Record<RefactorProposalAuthorKind, readonly RefactorProposalAuthorSource[]>> = {
|
|
127
|
+
cli: ["cli"],
|
|
128
|
+
developer: ["manual"],
|
|
129
|
+
mcp: ["mcp"],
|
|
130
|
+
subagent: ["subagent"]
|
|
131
|
+
};
|
|
132
|
+
export const MODULE_DYNAMIC_INVOCATION_LEVELS = ["known", "none_observed", "possible", "unknown"] as const;
|
|
133
|
+
export const MODULE_TESTS_COVERAGE_STATUSES = ["measured", "partial", "unknown"] as const;
|
|
134
|
+
|
|
135
|
+
export type RefactorScale = (typeof REFACTOR_SCALES)[number];
|
|
136
|
+
export type RefactorScaleReasonCode = (typeof REFACTOR_SCALE_REASON_CODES)[number];
|
|
137
|
+
export type RefactorObservationKind = (typeof REFACTOR_OBSERVATION_KINDS)[number];
|
|
138
|
+
export type RefactorResolutionDisposition = (typeof REFACTOR_RESOLUTION_DISPOSITIONS)[number];
|
|
139
|
+
export type RefactorOutcomeOperator = (typeof REFACTOR_OUTCOME_OPERATORS)[number];
|
|
140
|
+
export type RefactorOutcomeDirection = (typeof REFACTOR_OUTCOME_DIRECTIONS)[number];
|
|
141
|
+
export type RefactorKillListKind = (typeof REFACTOR_KILL_LIST_KINDS)[number];
|
|
142
|
+
export type RefactorExecutionEvidenceKind = (typeof REFACTOR_EXECUTION_EVIDENCE_KINDS)[number];
|
|
143
|
+
export type RefactorProposalAuthorSource = (typeof REFACTOR_PROPOSAL_AUTHOR_SOURCES)[number];
|
|
144
|
+
export type RefactorProposalAuthorKind = (typeof REFACTOR_PROPOSAL_AUTHOR_KINDS)[number];
|
|
145
|
+
export type ModuleDynamicInvocationLevel = (typeof MODULE_DYNAMIC_INVOCATION_LEVELS)[number];
|
|
146
|
+
export type ModuleTestsCoverageStatus = (typeof MODULE_TESTS_COVERAGE_STATUSES)[number];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The fixed per-observation bound on sampled evidence entries (edges, violations, paths,
|
|
150
|
+
* unresolved imports). It bounds entry *count* only: a path or a specifier has no fixed byte
|
|
151
|
+
* size, so this bound alone does not keep a recording event under the ledger's persisted-JSON
|
|
152
|
+
* ceiling. The recording planner enforces that separately, by measuring the event it would
|
|
153
|
+
* persist and shrinking every sample to one shared smaller limit until the event fits.
|
|
154
|
+
*/
|
|
155
|
+
export const REFACTOR_OBSERVATION_EVIDENCE_LIMIT = 20;
|
|
156
|
+
/**
|
|
157
|
+
* The fixed bound on every id list inside evidence (`memberNodeIds`, `constraintIds`,
|
|
158
|
+
* `candidateOwnerNodeIds`). Each list is the sorted prefix of its population and carries the true
|
|
159
|
+
* size beside it (`metrics.memberCount`, `constraintCount`, `candidateOwnerCount`). It is no
|
|
160
|
+
* smaller than `REFACTOR_OBSERVATION_EVIDENCE_LIMIT`, so the constraints named by a violation
|
|
161
|
+
* sample — the smallest ids, since violations sort by constraint first — are always listed.
|
|
162
|
+
*/
|
|
163
|
+
export const REFACTOR_EVIDENCE_ID_LIST_LIMIT = 32;
|
|
164
|
+
/** An import specifier is a module reference, not code: one line, bounded like a locator. */
|
|
165
|
+
export const REFACTOR_EVIDENCE_SPECIFIER_MAX_LENGTH = 512;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The fingerprint schema every refactor recommendation id is derived under. v3 is the first whose
|
|
169
|
+
* subject selector is scoped by the product namespace instead of the worktree path (ADR-0046).
|
|
170
|
+
* Owned here so the planner and the Git decision contract can never name two different versions.
|
|
171
|
+
*/
|
|
172
|
+
export const REFACTOR_RECOMMENDATION_FINGERPRINT_SCHEMA_VERSION = "archcontext.recommendation-fingerprint/v3" as const;
|
|
173
|
+
|
|
174
|
+
export const REFACTOR_DECISION_SCHEMA_VERSION = "archcontext.refactor-decision/v1" as const;
|
|
175
|
+
/** Git-visible home of human refactor decisions; outside `listModelFiles`, so never in `modelDigest`. */
|
|
176
|
+
export const REFACTOR_DECISION_DIRECTORY = ".archcontext/refactor-decisions" as const;
|
|
177
|
+
export const REFACTOR_DECISION_FILE_PATTERN = /^\.archcontext\/refactor-decisions\/(recommendation\.[a-f0-9]{16})\.json$/;
|
|
178
|
+
export const REFACTOR_RECOMMENDATION_ID_PATTERN = /^recommendation\.[a-f0-9]{16}$/;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* #636 / #643: Symbolic kill-list targets use `path#symbol`, where `path` is a safe repo-relative
|
|
182
|
+
* POSIX path and `symbol` is a non-empty identifier without whitespace or control characters.
|
|
183
|
+
*/
|
|
184
|
+
export const REFACTOR_KILL_LIST_SYMBOL_TARGET_REGEX = "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[^#\\s\\\\\\u0000-\\u001f\\u007f]+#[^\\s\\u0000-\\u001f\\u007f]+$";
|
|
185
|
+
|
|
186
|
+
export function formatRefactorKillListSymbolTarget(path: string, symbol: string): string {
|
|
187
|
+
return `${path}#${symbol}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function parseRefactorKillListSymbolTarget(target: string): { path: string; symbol: string } | undefined {
|
|
191
|
+
const hashIndex = target.indexOf("#");
|
|
192
|
+
if (hashIndex <= 0 || hashIndex === target.length - 1) return undefined;
|
|
193
|
+
if (target.indexOf("#", hashIndex + 1) !== -1) return undefined;
|
|
194
|
+
const path = target.slice(0, hashIndex);
|
|
195
|
+
const symbol = target.slice(hashIndex + 1);
|
|
196
|
+
if (!isRepoRelativePosixPath(path) || /[\s\u0000-\u001f\u007f]/.test(path)) return undefined;
|
|
197
|
+
if (/[\s\u0000-\u001f\u007f]/.test(symbol) || symbol.length === 0) return undefined;
|
|
198
|
+
return { path, symbol };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function isValidRefactorKillListSymbolTarget(target: string): boolean {
|
|
202
|
+
return parseRefactorKillListSymbolTarget(target) !== undefined;
|
|
203
|
+
}
|
|
204
|
+
/** The six human statuses. `open` is a machine status and is never a decision. */
|
|
205
|
+
export const REFACTOR_DECISION_STATUSES = ["acknowledged", "accepted", "deferred", "rejected", "resolved", "waived"] as const;
|
|
206
|
+
export const REFACTOR_DECISION_REASON_MAX_LENGTH = 1024;
|
|
207
|
+
export const REFACTOR_DECISION_ACTOR_ID_MAX_LENGTH = 128;
|
|
208
|
+
export const REFACTOR_DECISION_STABLE_KEY_MAX_LENGTH = 512;
|
|
209
|
+
|
|
210
|
+
export type RefactorDecisionStatus = (typeof REFACTOR_DECISION_STATUSES)[number];
|
|
211
|
+
export type RefactorDecisionActorKind = ArchitectureActorKind;
|
|
212
|
+
export type RefactorDecisionSelectorKind = ArchitectureSubjectSelectorKind;
|
|
213
|
+
export type RefactorDecisionRecommendationStatus = RecommendationStatus;
|