@granular-software/fractory 0.0.0-stage → 0.1.25
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/LICENSE +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +122 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1240 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +87 -0
- package/dist/core.js +207 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +67 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +7 -0
- package/dist/factory-graph.js +389 -0
- package/dist/factory-model.d.ts +111 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/interface-map.d.ts +15 -0
- package/dist/interface-map.js +125 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +20 -0
- package/dist/map-quality.js +61 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +71 -0
- package/dist/product-map.js +197 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/public-boundaries.d.ts +13 -0
- package/dist/public-boundaries.js +115 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +153 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +14 -0
- package/dist/scope.js +168 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +170 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +105 -0
- package/dist/source-review.d.ts +18 -0
- package/dist/source-review.js +573 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +18 -0
- package/dist/work-check.js +115 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +176 -0
- package/dist/work-context.d.ts +59 -0
- package/dist/work-context.js +594 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-lock-check.d.ts +12 -0
- package/dist/work-lock-check.js +339 -0
- package/dist/work-locks.d.ts +10 -0
- package/dist/work-locks.js +98 -0
- package/dist/work-model.d.ts +119 -0
- package/dist/work-model.js +310 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +485 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1512 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +361 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +75 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +462 -0
- package/src/factory-model.ts +82 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/interface-map.ts +166 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +66 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +228 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +271 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/public-boundaries.ts +143 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +191 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +192 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +208 -0
- package/src/source-review-git.ts +131 -0
- package/src/source-review.ts +736 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +149 -0
- package/src/work-cli.ts +229 -0
- package/src/work-context.ts +753 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-lock-check.ts +549 -0
- package/src/work-locks.ts +108 -0
- package/src/work-model.ts +466 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +354 -0
- package/toolkit/SKILL.md +142 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
package/src/compare.ts
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import type { CodeSnapshot } from "./code-model";
|
|
2
|
+
import type { Connection, Element, DefinitionGraph } from "./model";
|
|
3
|
+
import { logicalMap } from "./map-model";
|
|
4
|
+
import { graphIndex } from "./change-impact";
|
|
5
|
+
|
|
6
|
+
export type ChangeKind = "added" | "removed" | "modified";
|
|
7
|
+
export type SourceChange = {
|
|
8
|
+
/** Hash of the hunk body; review progress survives unrelated commits without storing raw code. */
|
|
9
|
+
digest?: string;
|
|
10
|
+
attachments?: {
|
|
11
|
+
file: string;
|
|
12
|
+
kind: "notes" | "tests" | "auth";
|
|
13
|
+
elementId: string;
|
|
14
|
+
}[];
|
|
15
|
+
side: "before" | "after";
|
|
16
|
+
file: string;
|
|
17
|
+
start: number;
|
|
18
|
+
count: number;
|
|
19
|
+
matches: { status: string; elementIds: string[] }[];
|
|
20
|
+
};
|
|
21
|
+
export type ElementChange = {
|
|
22
|
+
kind: ChangeKind;
|
|
23
|
+
fields: string[];
|
|
24
|
+
before?: Element;
|
|
25
|
+
after?: Element;
|
|
26
|
+
source: SourceChange[];
|
|
27
|
+
};
|
|
28
|
+
export type ConnectionChange = {
|
|
29
|
+
kind: ChangeKind;
|
|
30
|
+
before?: Connection;
|
|
31
|
+
after?: Connection;
|
|
32
|
+
};
|
|
33
|
+
export interface FactoryComparison {
|
|
34
|
+
schema: "fractal.comparison.v1";
|
|
35
|
+
context?: { title: string; url?: string };
|
|
36
|
+
before: { commit: string; id: string; at: string };
|
|
37
|
+
after: { commit: string; id: string; at: string };
|
|
38
|
+
graph: DefinitionGraph;
|
|
39
|
+
elements: Record<string, ElementChange>;
|
|
40
|
+
connections: Record<string, ConnectionChange>;
|
|
41
|
+
marks: Record<
|
|
42
|
+
string,
|
|
43
|
+
{
|
|
44
|
+
kind: ChangeKind;
|
|
45
|
+
added: number;
|
|
46
|
+
removed: number;
|
|
47
|
+
modified: number;
|
|
48
|
+
own: boolean;
|
|
49
|
+
connections?: number;
|
|
50
|
+
}
|
|
51
|
+
>;
|
|
52
|
+
summary: {
|
|
53
|
+
added: number;
|
|
54
|
+
removed: number;
|
|
55
|
+
modified: number;
|
|
56
|
+
interfaces: number;
|
|
57
|
+
connections: number;
|
|
58
|
+
};
|
|
59
|
+
evidence: {
|
|
60
|
+
source: "git-hunks" | "unavailable";
|
|
61
|
+
ambiguous: number;
|
|
62
|
+
unmapped: number;
|
|
63
|
+
snapshotGaps: number;
|
|
64
|
+
};
|
|
65
|
+
range?: {
|
|
66
|
+
base: string;
|
|
67
|
+
head: string;
|
|
68
|
+
mode: "commits" | "pr";
|
|
69
|
+
mergeBase?: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Locations and whole-file hashes are evidence, not conceptual changes. Arrays
|
|
73
|
+
// represent unordered attachments/members here; argument order stays explicit.
|
|
74
|
+
function semantic(value: unknown): unknown {
|
|
75
|
+
if (Array.isArray(value)) return value.map(semantic);
|
|
76
|
+
if (!value || typeof value !== "object") return value;
|
|
77
|
+
return Object.fromEntries(
|
|
78
|
+
Object.entries(value)
|
|
79
|
+
.filter(
|
|
80
|
+
([key]) =>
|
|
81
|
+
![
|
|
82
|
+
"source",
|
|
83
|
+
"sources",
|
|
84
|
+
"sourceRef",
|
|
85
|
+
"digest",
|
|
86
|
+
"line",
|
|
87
|
+
"definitionRevision",
|
|
88
|
+
"typeSources",
|
|
89
|
+
].includes(key),
|
|
90
|
+
)
|
|
91
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
92
|
+
.map(([key, item]) => [key, semantic(item)]),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const equal = (a: unknown, b: unknown) =>
|
|
96
|
+
JSON.stringify(semantic(a)) === JSON.stringify(semantic(b));
|
|
97
|
+
const set = (values: unknown[]) =>
|
|
98
|
+
[...new Set(values.map((value) => JSON.stringify(semantic(value))))].sort();
|
|
99
|
+
const types = (value: unknown): string[] => {
|
|
100
|
+
if (!value || typeof value !== "object") return [];
|
|
101
|
+
if (Array.isArray(value)) return value.flatMap(types);
|
|
102
|
+
return Object.entries(value).flatMap(([key, item]) =>
|
|
103
|
+
key === "typeSources" && Array.isArray(item)
|
|
104
|
+
? item.map((source) => `${source.file}:${source.digest}`).sort()
|
|
105
|
+
: types(item),
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
const contract = (node: Element) => {
|
|
109
|
+
const input = node.contract?.input;
|
|
110
|
+
if (
|
|
111
|
+
input &&
|
|
112
|
+
typeof input === "object" &&
|
|
113
|
+
"members" in input &&
|
|
114
|
+
Array.isArray(input.members)
|
|
115
|
+
)
|
|
116
|
+
return {
|
|
117
|
+
...node.contract,
|
|
118
|
+
input: {
|
|
119
|
+
...input,
|
|
120
|
+
members: [...input.members].sort((a, b) =>
|
|
121
|
+
String(a.name).localeCompare(String(b.name)),
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
return node.contract;
|
|
126
|
+
};
|
|
127
|
+
const connectionKey = (edge: Connection) =>
|
|
128
|
+
JSON.stringify([
|
|
129
|
+
edge.source,
|
|
130
|
+
edge.target,
|
|
131
|
+
edge.relation,
|
|
132
|
+
["callbacks", "delegates"].includes(edge.relation) ? edge.label : "",
|
|
133
|
+
]);
|
|
134
|
+
function conceptualConnections(graph: DefinitionGraph) {
|
|
135
|
+
const groups = new Map<string, Connection[]>();
|
|
136
|
+
for (const edge of graph.connections) {
|
|
137
|
+
const key = connectionKey(edge);
|
|
138
|
+
groups.set(key, [...(groups.get(key) || []), edge]);
|
|
139
|
+
}
|
|
140
|
+
return new Map(
|
|
141
|
+
[...groups].map(([key, edges]) => [
|
|
142
|
+
key,
|
|
143
|
+
{
|
|
144
|
+
...edges[0],
|
|
145
|
+
id: key,
|
|
146
|
+
members: edges,
|
|
147
|
+
sources: edges.flatMap(
|
|
148
|
+
(edge) => edge.sources || (edge.sourceRef ? [edge.sourceRef] : []),
|
|
149
|
+
),
|
|
150
|
+
exchange: edges.find((edge) => edge.exchange)?.exchange,
|
|
151
|
+
},
|
|
152
|
+
]),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
export function compareFactory(
|
|
156
|
+
before: CodeSnapshot,
|
|
157
|
+
after: CodeSnapshot,
|
|
158
|
+
sourceChanges?: SourceChange[],
|
|
159
|
+
): FactoryComparison {
|
|
160
|
+
if (!before.commit || !after.commit)
|
|
161
|
+
throw Error(
|
|
162
|
+
"Compare two committed revisions; a dirty checkout is not HEAD.",
|
|
163
|
+
);
|
|
164
|
+
const left = logicalMap(before.graph),
|
|
165
|
+
right = logicalMap(after.graph);
|
|
166
|
+
if (left.id !== right.id)
|
|
167
|
+
throw Error("These snapshots describe different factories.");
|
|
168
|
+
const a = new Map(left.elements.map((node) => [node.id, node])),
|
|
169
|
+
b = new Map(right.elements.map((node) => [node.id, node]));
|
|
170
|
+
const elements: FactoryComparison["elements"] = {};
|
|
171
|
+
for (const id of new Set([...a.keys(), ...b.keys()])) {
|
|
172
|
+
const old = a.get(id),
|
|
173
|
+
next = b.get(id);
|
|
174
|
+
const source = (sourceChanges || []).filter((change) =>
|
|
175
|
+
change.matches.some((match) =>
|
|
176
|
+
match.elementIds.some(
|
|
177
|
+
(owner) =>
|
|
178
|
+
(change.side === "before"
|
|
179
|
+
? left.aliases?.[owner]
|
|
180
|
+
: right.aliases?.[owner]) === id || owner === id,
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
const shared = (sourceChanges || []).filter(
|
|
185
|
+
(change) =>
|
|
186
|
+
change.matches.some((match) => match.status === "unmapped") &&
|
|
187
|
+
(change.side === "before" ? left : right).connections.some(
|
|
188
|
+
(edge) =>
|
|
189
|
+
edge.source === id &&
|
|
190
|
+
edge.id.startsWith("call-site:") &&
|
|
191
|
+
(edge.sources || (edge.sourceRef ? [edge.sourceRef] : [])).some(
|
|
192
|
+
(ref) => ref.file === change.file,
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
const attached = (sourceChanges || []).filter((change) =>
|
|
197
|
+
change.attachments?.some((item) => item.elementId === id),
|
|
198
|
+
);
|
|
199
|
+
if (!old || !next) {
|
|
200
|
+
elements[id] = {
|
|
201
|
+
kind: old ? "removed" : "added",
|
|
202
|
+
fields: [],
|
|
203
|
+
before: old,
|
|
204
|
+
after: next,
|
|
205
|
+
source: [...new Set([...source, ...shared, ...attached])],
|
|
206
|
+
};
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const fields: string[] = [];
|
|
210
|
+
for (const [label, one, two] of [
|
|
211
|
+
["Name", old.label, next.label],
|
|
212
|
+
["Placement", old.parent, next.parent],
|
|
213
|
+
["Kind", old.kind, next.kind],
|
|
214
|
+
["Contract", contract(old), contract(next)],
|
|
215
|
+
[
|
|
216
|
+
"Purpose",
|
|
217
|
+
old.description || old.attachments?.description,
|
|
218
|
+
next.description || next.attachments?.description,
|
|
219
|
+
],
|
|
220
|
+
["Auth", old.attachments?.auth?.symbol, next.attachments?.auth?.symbol],
|
|
221
|
+
[
|
|
222
|
+
"Notes",
|
|
223
|
+
set(old.attachments?.docs || []),
|
|
224
|
+
set(next.attachments?.docs || []),
|
|
225
|
+
],
|
|
226
|
+
["Resources", set(old.resources || []), set(next.resources || [])],
|
|
227
|
+
["Benchmarks", set(old.attachments?.benchmarks || []), set(next.attachments?.benchmarks || [])],
|
|
228
|
+
[
|
|
229
|
+
"Tests",
|
|
230
|
+
set(
|
|
231
|
+
left.tests
|
|
232
|
+
.filter((test) => test.targets.includes(id))
|
|
233
|
+
.map((test) => ({
|
|
234
|
+
file: test.source.file,
|
|
235
|
+
association: test.association,
|
|
236
|
+
})),
|
|
237
|
+
),
|
|
238
|
+
set(
|
|
239
|
+
right.tests
|
|
240
|
+
.filter((test) => test.targets.includes(id))
|
|
241
|
+
.map((test) => ({
|
|
242
|
+
file: test.source.file,
|
|
243
|
+
association: test.association,
|
|
244
|
+
})),
|
|
245
|
+
),
|
|
246
|
+
],
|
|
247
|
+
] as const)
|
|
248
|
+
if (!equal(one, two)) fields.push(label);
|
|
249
|
+
if (
|
|
250
|
+
!equal(
|
|
251
|
+
[...new Set(types(old.contract))].sort(),
|
|
252
|
+
[...new Set(types(next.contract))].sort(),
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
fields.push("Contract types");
|
|
256
|
+
if (source.length) fields.push("Code");
|
|
257
|
+
if (shared.length) fields.push("Shared source");
|
|
258
|
+
for (const [kind, label] of [
|
|
259
|
+
["notes", "Notes"],
|
|
260
|
+
["tests", "Tests"],
|
|
261
|
+
["auth", "Auth source"],
|
|
262
|
+
] as const)
|
|
263
|
+
if (
|
|
264
|
+
attached.some((change) =>
|
|
265
|
+
change.attachments?.some(
|
|
266
|
+
(item) => item.elementId === id && item.kind === kind,
|
|
267
|
+
),
|
|
268
|
+
) &&
|
|
269
|
+
!fields.includes(label)
|
|
270
|
+
)
|
|
271
|
+
fields.push(label);
|
|
272
|
+
if (fields.length)
|
|
273
|
+
elements[id] = {
|
|
274
|
+
kind: "modified",
|
|
275
|
+
fields,
|
|
276
|
+
before: old,
|
|
277
|
+
after: next,
|
|
278
|
+
source: [...new Set([...source, ...shared, ...attached])],
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
const oldEdges = conceptualConnections(left),
|
|
282
|
+
newEdges = conceptualConnections(right);
|
|
283
|
+
const connections: FactoryComparison["connections"] = {},
|
|
284
|
+
union: Connection[] = [];
|
|
285
|
+
for (const key of new Set([...oldEdges.keys(), ...newEdges.keys()])) {
|
|
286
|
+
const old = oldEdges.get(key),
|
|
287
|
+
next = newEdges.get(key);
|
|
288
|
+
// Public IDs and source line movements are deliberately excluded.
|
|
289
|
+
const shape = (edge: Connection) => ({
|
|
290
|
+
label: edge.label,
|
|
291
|
+
displayLabel: edge.displayLabel,
|
|
292
|
+
exchange: edge.exchange,
|
|
293
|
+
artifacts: edge.artifacts,
|
|
294
|
+
transport: edge.transport,
|
|
295
|
+
bidirectional: edge.bidirectional,
|
|
296
|
+
condition: edge.condition,
|
|
297
|
+
variants: set(
|
|
298
|
+
(edge.members || [edge]).map((member) => ({
|
|
299
|
+
label: member.label,
|
|
300
|
+
exchange: member.exchange,
|
|
301
|
+
artifacts: member.artifacts,
|
|
302
|
+
transport: member.transport,
|
|
303
|
+
})),
|
|
304
|
+
),
|
|
305
|
+
});
|
|
306
|
+
const id = `comparison:${key}`;
|
|
307
|
+
union.push({ ...(next || old!), id, members: undefined });
|
|
308
|
+
if (!old || !next)
|
|
309
|
+
connections[id] = {
|
|
310
|
+
kind: old ? "removed" : "added",
|
|
311
|
+
before: old,
|
|
312
|
+
after: next,
|
|
313
|
+
};
|
|
314
|
+
else if (!equal(shape(old), shape(next)))
|
|
315
|
+
connections[id] = { kind: "modified", before: old, after: next };
|
|
316
|
+
}
|
|
317
|
+
const graph: DefinitionGraph = {
|
|
318
|
+
...right,
|
|
319
|
+
revision: `compare:${before.id}:${after.id}`,
|
|
320
|
+
elements: [
|
|
321
|
+
...right.elements,
|
|
322
|
+
...left.elements.filter((node) => !b.has(node.id)),
|
|
323
|
+
],
|
|
324
|
+
connections: union,
|
|
325
|
+
tests: [],
|
|
326
|
+
failures: [],
|
|
327
|
+
gaps: [...left.gaps, ...right.gaps],
|
|
328
|
+
};
|
|
329
|
+
const { byId, within } = graphIndex(graph);
|
|
330
|
+
const { within: wasWithin } = graphIndex(left);
|
|
331
|
+
const marks: FactoryComparison["marks"] = {};
|
|
332
|
+
for (const node of graph.elements) {
|
|
333
|
+
const changes = Object.entries(elements).filter(
|
|
334
|
+
([id]) => within(id, node.id) || wasWithin(id, node.id),
|
|
335
|
+
);
|
|
336
|
+
if (!changes.length) continue;
|
|
337
|
+
const added = changes.filter(
|
|
338
|
+
([, change]) => change.kind === "added",
|
|
339
|
+
).length,
|
|
340
|
+
removed = changes.filter(
|
|
341
|
+
([, change]) => change.kind === "removed",
|
|
342
|
+
).length,
|
|
343
|
+
modified = changes.filter(
|
|
344
|
+
([, change]) => change.kind === "modified",
|
|
345
|
+
).length;
|
|
346
|
+
marks[node.id] = {
|
|
347
|
+
kind: elements[node.id]?.kind || "modified",
|
|
348
|
+
added,
|
|
349
|
+
removed,
|
|
350
|
+
modified,
|
|
351
|
+
own: !!elements[node.id],
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
// Count a wire once per containing block, even when both endpoints are inside.
|
|
355
|
+
for (const change of Object.values(connections)) {
|
|
356
|
+
const reached = new Set<string>();
|
|
357
|
+
for (const endpoint of [
|
|
358
|
+
change.after?.source || change.before!.source,
|
|
359
|
+
change.after?.target || change.before!.target,
|
|
360
|
+
]) {
|
|
361
|
+
let node = byId.get(endpoint);
|
|
362
|
+
const seen = new Set<string>();
|
|
363
|
+
while (node && !seen.has(node.id)) {
|
|
364
|
+
seen.add(node.id);
|
|
365
|
+
if (!reached.has(node.id)) {
|
|
366
|
+
reached.add(node.id);
|
|
367
|
+
const mark = (marks[node.id] ||= {
|
|
368
|
+
kind: "modified",
|
|
369
|
+
added: 0,
|
|
370
|
+
removed: 0,
|
|
371
|
+
modified: 0,
|
|
372
|
+
own: false,
|
|
373
|
+
});
|
|
374
|
+
mark.connections = (mark.connections || 0) + 1;
|
|
375
|
+
}
|
|
376
|
+
node = byId.get(node.parent || "");
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const values = Object.values(elements);
|
|
381
|
+
return {
|
|
382
|
+
schema: "fractal.comparison.v1",
|
|
383
|
+
before: { commit: before.commit, id: before.id, at: before.capturedAt },
|
|
384
|
+
after: { commit: after.commit, id: after.id, at: after.capturedAt },
|
|
385
|
+
graph,
|
|
386
|
+
elements,
|
|
387
|
+
connections,
|
|
388
|
+
marks,
|
|
389
|
+
summary: {
|
|
390
|
+
added: values.filter((change) => change.kind === "added").length,
|
|
391
|
+
removed: values.filter((change) => change.kind === "removed").length,
|
|
392
|
+
modified: values.filter((change) => change.kind === "modified").length,
|
|
393
|
+
interfaces: values.filter(
|
|
394
|
+
(change) => (change.after || change.before)?.kind === "interface",
|
|
395
|
+
).length,
|
|
396
|
+
connections: Object.keys(connections).length,
|
|
397
|
+
},
|
|
398
|
+
evidence: {
|
|
399
|
+
source: sourceChanges ? "git-hunks" : "unavailable",
|
|
400
|
+
ambiguous: (sourceChanges || []).filter((change) =>
|
|
401
|
+
change.matches.some((match) => match.status === "ambiguous"),
|
|
402
|
+
).length,
|
|
403
|
+
unmapped: (sourceChanges || []).filter(
|
|
404
|
+
(change) =>
|
|
405
|
+
!change.attachments?.length &&
|
|
406
|
+
change.matches.some((match) => match.status === "unmapped"),
|
|
407
|
+
).length,
|
|
408
|
+
snapshotGaps: before.gaps.length + after.gaps.length,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function comparisonReport(comparison: FactoryComparison) {
|
|
414
|
+
const { summary } = comparison;
|
|
415
|
+
const escape = (value: string) =>
|
|
416
|
+
value.replace(/[\r\n]/g, " ").replace(/[\\`*_[\]<>|]/g, "\\$&");
|
|
417
|
+
const entries = Object.entries(comparison.elements);
|
|
418
|
+
const preferred = entries.filter(
|
|
419
|
+
([, change]) => (change.after || change.before)?.kind !== "method",
|
|
420
|
+
);
|
|
421
|
+
const shown = (preferred.length ? preferred : entries).slice(0, 40);
|
|
422
|
+
return [
|
|
423
|
+
`# Factory comparison`,
|
|
424
|
+
``,
|
|
425
|
+
`${comparison.before.commit} → ${comparison.after.commit}`,
|
|
426
|
+
``,
|
|
427
|
+
`+${summary.added} added · −${summary.removed} removed · ${summary.modified} changed · ${summary.interfaces} interfaces · ${summary.connections} connections`,
|
|
428
|
+
``,
|
|
429
|
+
...shown.map(
|
|
430
|
+
([id, change]) =>
|
|
431
|
+
`- ${change.kind}: ${escape((change.after || change.before)!.label)}${change.fields.length ? ` (${change.fields.join(", ")})` : ""} — \`${escape(id)}\``,
|
|
432
|
+
),
|
|
433
|
+
``,
|
|
434
|
+
...(entries.length > shown.length
|
|
435
|
+
? [`Open the report for all ${entries.length} changed parts.`]
|
|
436
|
+
: []),
|
|
437
|
+
`Code changes use captured source ownership. Contract changes are not automatic proof of compatibility.`,
|
|
438
|
+
``,
|
|
439
|
+
].join("\n");
|
|
440
|
+
}
|