@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
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model";
|
|
2
|
+
import type { WorkingOverview } from "./working-code";
|
|
3
|
+
import type { WorkView } from "./work-items";
|
|
4
|
+
import { inTimeWindow, type TimeWindow } from "./time-window";
|
|
5
|
+
|
|
6
|
+
export type ActivityKind =
|
|
7
|
+
| "worktrees"
|
|
8
|
+
| "history"
|
|
9
|
+
| "sentry"
|
|
10
|
+
| "linear"
|
|
11
|
+
| "metrics"
|
|
12
|
+
| "benchmarks";
|
|
13
|
+
export interface ActivityCell {
|
|
14
|
+
tone?: "regression" | "improvement" | "neutral";
|
|
15
|
+
displayValue?: string;
|
|
16
|
+
recent?: boolean;
|
|
17
|
+
count: number;
|
|
18
|
+
intensity: number;
|
|
19
|
+
label: string;
|
|
20
|
+
summary: string;
|
|
21
|
+
segments?: { label: string; count: number; tone: string }[];
|
|
22
|
+
series?: number[];
|
|
23
|
+
measurements?: {
|
|
24
|
+
label: string;
|
|
25
|
+
value: string;
|
|
26
|
+
series: number[];
|
|
27
|
+
tone?: "regression" | "improvement" | "neutral";
|
|
28
|
+
}[];
|
|
29
|
+
related?: boolean;
|
|
30
|
+
lineChange?: { added: number; deleted: number; partial: boolean };
|
|
31
|
+
}
|
|
32
|
+
export interface HistorySample {
|
|
33
|
+
source?: import("./history-source").HistorySource;
|
|
34
|
+
latestAt?: string;
|
|
35
|
+
churn?: import("./history-churn").HistoryChurn;
|
|
36
|
+
ledger?: import("./history-ledger").HistoryLedger;
|
|
37
|
+
checkedAt: string;
|
|
38
|
+
windowEnd?: string;
|
|
39
|
+
windowStart?: string;
|
|
40
|
+
days: number;
|
|
41
|
+
partial: boolean;
|
|
42
|
+
commits: {
|
|
43
|
+
commit: string;
|
|
44
|
+
at: string;
|
|
45
|
+
subject: string;
|
|
46
|
+
files: string[];
|
|
47
|
+
changes?: {
|
|
48
|
+
path: string;
|
|
49
|
+
added: number;
|
|
50
|
+
deleted: number;
|
|
51
|
+
binary: boolean;
|
|
52
|
+
}[];
|
|
53
|
+
}[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const indexes = new WeakMap<
|
|
57
|
+
DefinitionGraph,
|
|
58
|
+
{
|
|
59
|
+
revision: string;
|
|
60
|
+
byId: Map<string, DefinitionGraph["elements"][number]>;
|
|
61
|
+
files: Map<string, string[]>;
|
|
62
|
+
}
|
|
63
|
+
>();
|
|
64
|
+
/** File associations, not line-level ownership. Shared files can relate to several blocks. */
|
|
65
|
+
export function fileBlocks(graph: DefinitionGraph, path: string): Set<string> {
|
|
66
|
+
let index = indexes.get(graph);
|
|
67
|
+
if (!index || index.revision !== graph.revision) {
|
|
68
|
+
const files = new Map<string, string[]>();
|
|
69
|
+
for (const node of graph.elements) {
|
|
70
|
+
for (const source of node.sources || (node.source ? [node.source] : []))
|
|
71
|
+
files.set(source.file, [...(files.get(source.file) || []), node.id]);
|
|
72
|
+
for (const file of [
|
|
73
|
+
...(node.attachments?.benchmarks || []),
|
|
74
|
+
...(node.attachments?.docs || []),
|
|
75
|
+
...(node.attachments?.tests || []),
|
|
76
|
+
])
|
|
77
|
+
files.set(file, [...(files.get(file) || []), node.id]);
|
|
78
|
+
}
|
|
79
|
+
for (const test of graph.tests || [])
|
|
80
|
+
files.set(test.source.file, [
|
|
81
|
+
...(files.get(test.source.file) || []),
|
|
82
|
+
...test.targets.map((id) => graph.aliases?.[id] || id),
|
|
83
|
+
]);
|
|
84
|
+
index = {
|
|
85
|
+
revision: graph.revision,
|
|
86
|
+
byId: new Map(graph.elements.map((node) => [node.id, node])),
|
|
87
|
+
files,
|
|
88
|
+
};
|
|
89
|
+
indexes.set(graph, index);
|
|
90
|
+
}
|
|
91
|
+
const { byId, files } = index;
|
|
92
|
+
const owners = new Set<string>();
|
|
93
|
+
const ids = path.endsWith("/")
|
|
94
|
+
? [...files]
|
|
95
|
+
.filter(([file]) => file.startsWith(path))
|
|
96
|
+
.flatMap(([, ids]) => ids)
|
|
97
|
+
: files.get(path) || [];
|
|
98
|
+
for (const id of ids) {
|
|
99
|
+
let current = byId.get(graph.aliases?.[id] || id)!;
|
|
100
|
+
const seen = new Set<string>();
|
|
101
|
+
while (current && !seen.has(current.id)) {
|
|
102
|
+
seen.add(current.id);
|
|
103
|
+
owners.add(current.id);
|
|
104
|
+
current = byId.get(current.parent!)!;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return owners;
|
|
108
|
+
}
|
|
109
|
+
function normalize(
|
|
110
|
+
graph: DefinitionGraph,
|
|
111
|
+
cells: Record<string, ActivityCell>,
|
|
112
|
+
) {
|
|
113
|
+
const max = Math.max(
|
|
114
|
+
1,
|
|
115
|
+
...Object.entries(cells)
|
|
116
|
+
.filter(([id]) => id !== graph.id)
|
|
117
|
+
.map(([, cell]) => cell.count),
|
|
118
|
+
);
|
|
119
|
+
for (const cell of Object.values(cells))
|
|
120
|
+
cell.intensity = Math.min(1, cell.count / max);
|
|
121
|
+
return cells;
|
|
122
|
+
}
|
|
123
|
+
export function workingCells(
|
|
124
|
+
graph: DefinitionGraph,
|
|
125
|
+
overview: WorkingOverview,
|
|
126
|
+
) {
|
|
127
|
+
if (overview.mapping?.revision === graph.revision && overview.mapping)
|
|
128
|
+
return overview.mapping;
|
|
129
|
+
const cells: Record<string, ActivityCell> = {};
|
|
130
|
+
let unmapped = 0;
|
|
131
|
+
for (const path of overview.paths) {
|
|
132
|
+
const owners = fileBlocks(graph, path.path);
|
|
133
|
+
if (!owners.size) unmapped++;
|
|
134
|
+
for (const id of owners) {
|
|
135
|
+
const cell = (cells[id] ||= {
|
|
136
|
+
count: 0,
|
|
137
|
+
intensity: 0,
|
|
138
|
+
label: "changed paths",
|
|
139
|
+
summary: "",
|
|
140
|
+
segments: [
|
|
141
|
+
{ label: "Staged", count: 0, tone: "staged" },
|
|
142
|
+
{ label: "Unstaged", count: 0, tone: "unstaged" },
|
|
143
|
+
{ label: "Untracked", count: 0, tone: "untracked" },
|
|
144
|
+
{ label: "Conflicts", count: 0, tone: "conflict" },
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
cell.count++;
|
|
148
|
+
const age = path.modifiedAt
|
|
149
|
+
? Date.parse(overview.checkedAt) - Date.parse(path.modifiedAt)
|
|
150
|
+
: Infinity;
|
|
151
|
+
// A folder's mtime describes directory entries, not edits to its files.
|
|
152
|
+
if (path.kind !== "directory" && age >= 0 && age < 30_000)
|
|
153
|
+
cell.recent = true;
|
|
154
|
+
if (path.conflict) cell.segments![3].count++;
|
|
155
|
+
else if (path.untracked) cell.segments![2].count++;
|
|
156
|
+
else {
|
|
157
|
+
if (path.index !== ".") cell.segments![0].count++;
|
|
158
|
+
if (path.working !== ".") cell.segments![1].count++;
|
|
159
|
+
}
|
|
160
|
+
cell.summary = cell
|
|
161
|
+
.segments!.filter((s) => s.count)
|
|
162
|
+
.map((s) => `${s.count} ${s.label.toLowerCase()}`)
|
|
163
|
+
.join(" · ");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
167
|
+
}
|
|
168
|
+
export function historyCells(graph: DefinitionGraph, sample: HistorySample) {
|
|
169
|
+
const cells: Record<string, ActivityCell> = {};
|
|
170
|
+
if (sample.ledger) {
|
|
171
|
+
for (const [id, value] of Object.entries(sample.ledger.blocks)) {
|
|
172
|
+
const changed = value.added + value.deleted;
|
|
173
|
+
if (!changed) continue;
|
|
174
|
+
cells[id] = {
|
|
175
|
+
count: changed,
|
|
176
|
+
intensity: 0,
|
|
177
|
+
displayValue: new Intl.NumberFormat("en", {
|
|
178
|
+
notation: "compact",
|
|
179
|
+
maximumFractionDigits: 1,
|
|
180
|
+
}).format(changed),
|
|
181
|
+
label:
|
|
182
|
+
sample.ledger.mode === "activity" ? "line edits" : "line difference",
|
|
183
|
+
lineChange: {
|
|
184
|
+
added: value.added,
|
|
185
|
+
deleted: value.deleted,
|
|
186
|
+
partial: value.associated > 0,
|
|
187
|
+
},
|
|
188
|
+
summary: `${sample.ledger.mode === "activity" ? "Activity across mainline commits; repeated edits count again" : "Difference between range endpoints"} · +${value.added} added · −${value.deleted} removed · ${value.associated} lines use file-level associations rather than exact historical ranges.`,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
cells: normalize(graph, cells),
|
|
193
|
+
unmapped:
|
|
194
|
+
sample.ledger.buckets.unassigned.added +
|
|
195
|
+
sample.ledger.buckets.unassigned.deleted,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (sample.churn && !sample.churn.error) {
|
|
199
|
+
for (const [id, value] of Object.entries(sample.churn.blocks)) {
|
|
200
|
+
const changed = value.added + value.deleted;
|
|
201
|
+
if (!changed) continue;
|
|
202
|
+
const percent =
|
|
203
|
+
value.percent == null ? null : Math.round(value.percent * 10) / 10;
|
|
204
|
+
cells[id] = {
|
|
205
|
+
count: percent || 0,
|
|
206
|
+
intensity: 0,
|
|
207
|
+
displayValue:
|
|
208
|
+
percent == null
|
|
209
|
+
? `${changed}`
|
|
210
|
+
: value.percent! > 0 && percent === 0
|
|
211
|
+
? "<0.1%"
|
|
212
|
+
: `${percent}%`,
|
|
213
|
+
label: percent == null ? "line changes" : "churn",
|
|
214
|
+
lineChange: {
|
|
215
|
+
added: value.added,
|
|
216
|
+
deleted: value.deleted,
|
|
217
|
+
partial: value.partial,
|
|
218
|
+
},
|
|
219
|
+
summary: `+${value.added} added · −${value.deleted} removed · net ${value.added - value.deleted > 0 ? "+" : ""}${value.added - value.deleted} lines. Churn = (added + removed) / ${value.baseline} matched starting lines; an edit counts on both sides.${value.partial ? " Partial source mapping: some historical source could not be assigned." : ""}${percent == null ? " No starting baseline for a percentage." : ""}`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
cells: normalize(graph, cells),
|
|
224
|
+
unmapped: sample.churn.unmappedLines,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const end = Date.parse(sample.windowEnd || sample.checkedAt),
|
|
228
|
+
start = sample.windowStart
|
|
229
|
+
? Date.parse(sample.windowStart)
|
|
230
|
+
: end - sample.days * 86400000,
|
|
231
|
+
span = Math.max(1000, end - start);
|
|
232
|
+
let unmapped = 0;
|
|
233
|
+
for (const commit of sample.commits) {
|
|
234
|
+
const owners = new Set(
|
|
235
|
+
commit.files.flatMap((file) => [...fileBlocks(graph, file)]),
|
|
236
|
+
);
|
|
237
|
+
if (!owners.size) unmapped++;
|
|
238
|
+
const bucket = Math.max(
|
|
239
|
+
0,
|
|
240
|
+
Math.min(13, Math.floor(((Date.parse(commit.at) - start) / span) * 14)),
|
|
241
|
+
);
|
|
242
|
+
for (const id of owners) {
|
|
243
|
+
const cell = (cells[id] ||= {
|
|
244
|
+
count: 0,
|
|
245
|
+
intensity: 0,
|
|
246
|
+
label: "commits",
|
|
247
|
+
summary: `${sample.days ? `Last ${sample.days} days` : "Latest commits"} · file associations`,
|
|
248
|
+
series: Array(14).fill(0),
|
|
249
|
+
});
|
|
250
|
+
cell.count++;
|
|
251
|
+
cell.series![bucket]++;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
255
|
+
}
|
|
256
|
+
export function linearCells(
|
|
257
|
+
graph: DefinitionGraph,
|
|
258
|
+
view: WorkView,
|
|
259
|
+
window?: TimeWindow,
|
|
260
|
+
) {
|
|
261
|
+
const cells: Record<string, ActivityCell> = {};
|
|
262
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
263
|
+
let unmapped = 0;
|
|
264
|
+
for (const item of view.items) {
|
|
265
|
+
if (window && !inTimeWindow(item.metadata?.updatedAt, window)) continue;
|
|
266
|
+
const owners = new Set<string>();
|
|
267
|
+
for (const block of item.blocks) {
|
|
268
|
+
let current = byId.get(graph.aliases?.[block] || block);
|
|
269
|
+
const seen = new Set<string>();
|
|
270
|
+
while (current && !seen.has(current.id)) {
|
|
271
|
+
seen.add(current.id);
|
|
272
|
+
owners.add(current.id);
|
|
273
|
+
current = byId.get(current.parent!);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!owners.size && !["done", "canceled", "archived"].includes(item.state))
|
|
277
|
+
unmapped++;
|
|
278
|
+
if (item.state === "canceled" || item.state === "archived") continue;
|
|
279
|
+
for (const id of owners) {
|
|
280
|
+
const cell = (cells[id] ||= {
|
|
281
|
+
count: 0,
|
|
282
|
+
intensity: 0,
|
|
283
|
+
label: "open issues",
|
|
284
|
+
summary: "",
|
|
285
|
+
segments: [
|
|
286
|
+
{ label: "Planned", count: 0, tone: "todo" },
|
|
287
|
+
{ label: "Active", count: 0, tone: "active" },
|
|
288
|
+
{ label: "Done", count: 0, tone: "done" },
|
|
289
|
+
{ label: "Unknown", count: 0, tone: "unknown" },
|
|
290
|
+
],
|
|
291
|
+
});
|
|
292
|
+
if (item.state === "todo" || item.state === "in_progress") cell.count++;
|
|
293
|
+
const position =
|
|
294
|
+
item.state === "todo"
|
|
295
|
+
? 0
|
|
296
|
+
: item.state === "in_progress"
|
|
297
|
+
? 1
|
|
298
|
+
: item.state === "done"
|
|
299
|
+
? 2
|
|
300
|
+
: 3;
|
|
301
|
+
cell.segments![position].count++;
|
|
302
|
+
cell.summary = cell
|
|
303
|
+
.segments!.filter((s) => s.count)
|
|
304
|
+
.map((s) => `${s.count} ${s.label.toLowerCase()}`)
|
|
305
|
+
.join(" · ");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
309
|
+
}
|
package/src/map-model.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Connection,
|
|
3
|
+
DefinitionGraph,
|
|
4
|
+
Element,
|
|
5
|
+
FlowArtifact,
|
|
6
|
+
LogicalKind,
|
|
7
|
+
ResourceAttachment,
|
|
8
|
+
} from "./model";
|
|
9
|
+
|
|
10
|
+
const kinds: Record<Element["kind"], LogicalKind> = {
|
|
11
|
+
factory: "block",
|
|
12
|
+
system: "block",
|
|
13
|
+
deployment: "block",
|
|
14
|
+
operation: "method",
|
|
15
|
+
block: "block",
|
|
16
|
+
interface: "interface",
|
|
17
|
+
method: "method",
|
|
18
|
+
process: "process",
|
|
19
|
+
resource: "block",
|
|
20
|
+
artifact: "block",
|
|
21
|
+
};
|
|
22
|
+
/** A view projection, not a new source revision. Runtime identities and contracts stay unchanged. */
|
|
23
|
+
export function logicalMap(definition: DefinitionGraph): DefinitionGraph {
|
|
24
|
+
const graph = structuredClone(definition);
|
|
25
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
26
|
+
const detached = new Set(
|
|
27
|
+
graph.elements
|
|
28
|
+
.filter((node) => node.kind === "resource" || node.kind === "artifact")
|
|
29
|
+
.map((node) => node.id),
|
|
30
|
+
);
|
|
31
|
+
const owner = (id: string): string => {
|
|
32
|
+
const seen = new Set<string>();
|
|
33
|
+
let node = byId.get(id);
|
|
34
|
+
while (node && !seen.has(node.id)) {
|
|
35
|
+
seen.add(node.id);
|
|
36
|
+
if (
|
|
37
|
+
!detached.has(node.id) &&
|
|
38
|
+
["block", "process"].includes(kinds[node.kind])
|
|
39
|
+
)
|
|
40
|
+
return node.id;
|
|
41
|
+
node = byId.get(node.parent || "");
|
|
42
|
+
}
|
|
43
|
+
return graph.id;
|
|
44
|
+
};
|
|
45
|
+
const aliases = { ...graph.aliases };
|
|
46
|
+
for (const id of detached)
|
|
47
|
+
aliases[id] = owner(byId.get(id)?.parent || graph.id);
|
|
48
|
+
const target = (id: string) => aliases[id] || id;
|
|
49
|
+
for (const node of graph.elements)
|
|
50
|
+
if (node.kind === "resource") {
|
|
51
|
+
const connections = graph.connections.filter(
|
|
52
|
+
(edge) => edge.source === node.id || edge.target === node.id,
|
|
53
|
+
);
|
|
54
|
+
const attachment: ResourceAttachment = {
|
|
55
|
+
id: node.id,
|
|
56
|
+
label: node.label,
|
|
57
|
+
description: node.description,
|
|
58
|
+
source: node.source,
|
|
59
|
+
sources: node.sources,
|
|
60
|
+
provenance: node.provenance,
|
|
61
|
+
connections,
|
|
62
|
+
};
|
|
63
|
+
const owners = new Set([
|
|
64
|
+
aliases[node.id],
|
|
65
|
+
...connections.map((edge) =>
|
|
66
|
+
owner(edge.source === node.id ? edge.target : edge.source),
|
|
67
|
+
),
|
|
68
|
+
]);
|
|
69
|
+
for (const id of owners) {
|
|
70
|
+
const block = byId.get(id);
|
|
71
|
+
if (block) block.resources = [...(block.resources || []), attachment];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const artifacts = new Map(
|
|
75
|
+
graph.elements
|
|
76
|
+
.filter((node) => node.kind === "artifact")
|
|
77
|
+
.map((node) => [
|
|
78
|
+
node.id,
|
|
79
|
+
{
|
|
80
|
+
id: node.id,
|
|
81
|
+
label: node.label,
|
|
82
|
+
description: node.description,
|
|
83
|
+
source: node.source,
|
|
84
|
+
sources: node.sources,
|
|
85
|
+
provenance: node.provenance,
|
|
86
|
+
} satisfies FlowArtifact,
|
|
87
|
+
]),
|
|
88
|
+
);
|
|
89
|
+
for (const [id, artifact] of artifacts) {
|
|
90
|
+
const block = byId.get(aliases[id]);
|
|
91
|
+
if (block) block.outputs = [...(block.outputs || []), artifact];
|
|
92
|
+
}
|
|
93
|
+
const connections: Connection[] = [];
|
|
94
|
+
const outgoing = new Map<string, Connection[]>();
|
|
95
|
+
for (const edge of graph.connections)
|
|
96
|
+
outgoing.set(edge.source, [...(outgoing.get(edge.source) || []), edge]);
|
|
97
|
+
const evidence = (edge: Connection) =>
|
|
98
|
+
edge.sources || (edge.sourceRef ? [edge.sourceRef] : []);
|
|
99
|
+
const follow = (
|
|
100
|
+
first: Connection,
|
|
101
|
+
edge: Connection,
|
|
102
|
+
path: Connection[],
|
|
103
|
+
materials: FlowArtifact[],
|
|
104
|
+
visited: Set<string>,
|
|
105
|
+
) => {
|
|
106
|
+
if (byId.get(edge.target)?.kind === "resource") return;
|
|
107
|
+
const material = artifacts.get(edge.target);
|
|
108
|
+
if (material) {
|
|
109
|
+
if (visited.has(material.id)) return;
|
|
110
|
+
const seen = new Set([...visited, material.id]);
|
|
111
|
+
const next = outgoing.get(material.id) || [];
|
|
112
|
+
for (const transfer of next)
|
|
113
|
+
follow(
|
|
114
|
+
first,
|
|
115
|
+
transfer,
|
|
116
|
+
[...path, transfer],
|
|
117
|
+
[...materials, material],
|
|
118
|
+
seen,
|
|
119
|
+
);
|
|
120
|
+
if (!next.length) {
|
|
121
|
+
const block = byId.get(owner(first.source));
|
|
122
|
+
if (block) block.outputs = [...(block.outputs || []), material];
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const source = target(first.source),
|
|
127
|
+
destination = target(edge.target);
|
|
128
|
+
if (source === destination) return;
|
|
129
|
+
connections.push({
|
|
130
|
+
...edge,
|
|
131
|
+
source,
|
|
132
|
+
target: destination,
|
|
133
|
+
...(materials.length
|
|
134
|
+
? {
|
|
135
|
+
id: path.map((item) => item.id).join("::"),
|
|
136
|
+
artifacts: [...materials, ...(edge.artifacts || [])],
|
|
137
|
+
sources: path.flatMap(evidence),
|
|
138
|
+
provenance: path.some((item) => item.provenance === "inferred")
|
|
139
|
+
? "inferred"
|
|
140
|
+
: edge.provenance,
|
|
141
|
+
}
|
|
142
|
+
: {}),
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
for (const edge of graph.connections) {
|
|
146
|
+
if (byId.get(edge.source)?.kind === "resource") continue;
|
|
147
|
+
const material = artifacts.get(edge.source);
|
|
148
|
+
if (
|
|
149
|
+
material &&
|
|
150
|
+
graph.connections.some((input) => input.target === edge.source)
|
|
151
|
+
)
|
|
152
|
+
continue;
|
|
153
|
+
follow(
|
|
154
|
+
edge,
|
|
155
|
+
edge,
|
|
156
|
+
[edge],
|
|
157
|
+
material ? [material] : [],
|
|
158
|
+
new Set(material ? [material.id] : []),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
graph.elements = graph.elements
|
|
162
|
+
.filter((node) => !detached.has(node.id))
|
|
163
|
+
.map((node) => ({
|
|
164
|
+
...node,
|
|
165
|
+
kind: kinds[node.kind],
|
|
166
|
+
parent: node.parent ? target(node.parent) : undefined,
|
|
167
|
+
hosting:
|
|
168
|
+
node.hosting || (node.kind === "deployment" ? node.label : undefined),
|
|
169
|
+
resources: node.resources?.filter(
|
|
170
|
+
(resource, i, all) =>
|
|
171
|
+
all.findIndex((item) => item.id === resource.id) === i,
|
|
172
|
+
),
|
|
173
|
+
outputs: node.outputs?.filter(
|
|
174
|
+
(artifact, i, all) =>
|
|
175
|
+
all.findIndex((item) => item.id === artifact.id) === i,
|
|
176
|
+
),
|
|
177
|
+
}));
|
|
178
|
+
graph.connections = connections;
|
|
179
|
+
graph.tests = graph.tests.map((test) => ({
|
|
180
|
+
...test,
|
|
181
|
+
targets: [...new Set(test.targets.map(target))],
|
|
182
|
+
}));
|
|
183
|
+
graph.failures = graph.failures.map((failure) => ({
|
|
184
|
+
...failure,
|
|
185
|
+
operationId: target(failure.operationId),
|
|
186
|
+
}));
|
|
187
|
+
graph.aliases = aliases;
|
|
188
|
+
return graph;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Collapsed black boxes retain the unique dependencies of their contents. */
|
|
192
|
+
export function blockResources(
|
|
193
|
+
graph: DefinitionGraph,
|
|
194
|
+
id: string,
|
|
195
|
+
): ResourceAttachment[] {
|
|
196
|
+
const ids = new Set([id]);
|
|
197
|
+
for (let changed = true; changed; ) {
|
|
198
|
+
changed = false;
|
|
199
|
+
for (const node of graph.elements)
|
|
200
|
+
if (node.parent && ids.has(node.parent) && !ids.has(node.id)) {
|
|
201
|
+
ids.add(node.id);
|
|
202
|
+
changed = true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
...new Map(
|
|
207
|
+
graph.elements
|
|
208
|
+
.filter((node) => ids.has(node.id))
|
|
209
|
+
.flatMap((node) => node.resources || [])
|
|
210
|
+
.map((resource) => [resource.id, resource]),
|
|
211
|
+
).values(),
|
|
212
|
+
];
|
|
213
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { boundaryViolations } from "./public-boundaries";
|
|
2
|
+
import type { DefinitionGraph } from "./model";
|
|
3
|
+
|
|
4
|
+
/** Evidence gaps, not claims that disconnected code is unused. Ownership follows
|
|
5
|
+
* parent identities, never string prefixes or physical file locations. */
|
|
6
|
+
export function mapQuality(graph: DefinitionGraph) {
|
|
7
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
8
|
+
const involved = new Set<string>();
|
|
9
|
+
const problems: string[] = [];
|
|
10
|
+
for (const node of graph.elements) {
|
|
11
|
+
if (node.parent && !byId.has(node.parent))
|
|
12
|
+
problems.push(`Missing parent: ${node.id}`);
|
|
13
|
+
const seen = new Set([node.id]);
|
|
14
|
+
let parent = node.parent;
|
|
15
|
+
while (parent) {
|
|
16
|
+
if (seen.has(parent)) {
|
|
17
|
+
problems.push(`Ownership cycle: ${node.id}`);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
seen.add(parent);
|
|
21
|
+
parent = byId.get(parent)?.parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const edge of graph.connections) {
|
|
25
|
+
for (const endpoint of [edge.source, edge.target]) {
|
|
26
|
+
if (!byId.has(endpoint))
|
|
27
|
+
problems.push(`Missing endpoint: ${edge.id}: ${endpoint}`);
|
|
28
|
+
let node = byId.get(endpoint);
|
|
29
|
+
const seen = new Set<string>();
|
|
30
|
+
while (node && !seen.has(node.id)) {
|
|
31
|
+
seen.add(node.id);
|
|
32
|
+
involved.add(node.id);
|
|
33
|
+
node = byId.get(node.parent || "");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (byId.size !== graph.elements.length)
|
|
38
|
+
problems.push("Duplicate block identities");
|
|
39
|
+
const boundaries = boundaryViolations(graph);
|
|
40
|
+
for (const issue of boundaries)
|
|
41
|
+
problems.push(`${issue.connection}: ${issue.reason}`);
|
|
42
|
+
return {
|
|
43
|
+
problems,
|
|
44
|
+
boundaryViolations: boundaries,
|
|
45
|
+
areas: graph.elements
|
|
46
|
+
.filter((node) => node.parent === graph.id)
|
|
47
|
+
.map((node) => ({
|
|
48
|
+
id: node.id,
|
|
49
|
+
label: node.label,
|
|
50
|
+
parts: graph.elements.filter((child) => child.parent === node.id)
|
|
51
|
+
.length,
|
|
52
|
+
connected: involved.has(node.id),
|
|
53
|
+
})),
|
|
54
|
+
missingPurpose: graph.elements
|
|
55
|
+
.filter(
|
|
56
|
+
(node) =>
|
|
57
|
+
node.id !== graph.id &&
|
|
58
|
+
!node.description &&
|
|
59
|
+
!node.attachments?.description,
|
|
60
|
+
)
|
|
61
|
+
.map((node) => node.id),
|
|
62
|
+
noMappedInteractions: graph.elements
|
|
63
|
+
.filter((node) => node.id !== graph.id && !involved.has(node.id))
|
|
64
|
+
.map((node) => node.id),
|
|
65
|
+
};
|
|
66
|
+
}
|