@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,426 @@
|
|
|
1
|
+
/** Saved working code versus the work's immutable starting revision. No source execution. */
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { posix } from "node:path";
|
|
4
|
+
import { sourceDigest } from "./source-index.js";
|
|
5
|
+
const printer = ts.createPrinter({ removeComments: true });
|
|
6
|
+
const print = (node, sf) => printer.printNode(ts.EmitHint.Unspecified, node, sf);
|
|
7
|
+
function parse(path, text) {
|
|
8
|
+
const file = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, path.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
9
|
+
const declarations = [], imports = new Map();
|
|
10
|
+
function visit(node) {
|
|
11
|
+
if (ts.isImportDeclaration(node) &&
|
|
12
|
+
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
13
|
+
node.moduleSpecifier.text.startsWith(".")) {
|
|
14
|
+
const bindings = node.importClause?.namedBindings;
|
|
15
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
16
|
+
for (const item of bindings.elements)
|
|
17
|
+
imports.set(item.name.text, {
|
|
18
|
+
file: posix.normalize(posix.join(posix.dirname(path), node.moduleSpecifier.text)),
|
|
19
|
+
name: item.propertyName?.text || item.name.text,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if ((ts.isFunctionDeclaration(node) ||
|
|
23
|
+
ts.isMethodDeclaration(node) ||
|
|
24
|
+
ts.isArrowFunction(node) ||
|
|
25
|
+
ts.isFunctionExpression(node)) &&
|
|
26
|
+
node.body) {
|
|
27
|
+
const owner = ts.isVariableDeclaration(node.parent)
|
|
28
|
+
? node.parent.name.getText(file)
|
|
29
|
+
: "";
|
|
30
|
+
const name = ("name" in node && node.name?.getText(file)) || owner;
|
|
31
|
+
const cls = ts.isMethodDeclaration(node) &&
|
|
32
|
+
(ts.isClassDeclaration(node.parent) ||
|
|
33
|
+
ts.isClassExpression(node.parent))
|
|
34
|
+
? node.parent.name?.text
|
|
35
|
+
: undefined;
|
|
36
|
+
if (name)
|
|
37
|
+
declarations.push({
|
|
38
|
+
key: cls ? `${cls}.${name}` : name,
|
|
39
|
+
node,
|
|
40
|
+
name,
|
|
41
|
+
className: cls,
|
|
42
|
+
start: file.getLineAndCharacterOfPosition(node.getStart(file)).line + 1,
|
|
43
|
+
end: file.getLineAndCharacterOfPosition(node.end).line + 1,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
ts.forEachChild(node, visit);
|
|
47
|
+
}
|
|
48
|
+
visit(file);
|
|
49
|
+
return {
|
|
50
|
+
file,
|
|
51
|
+
declarations,
|
|
52
|
+
imports,
|
|
53
|
+
digest: sourceDigest(text),
|
|
54
|
+
valid: !file
|
|
55
|
+
.parseDiagnostics.length,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function anchor(parsed, ref) {
|
|
59
|
+
if (!parsed?.valid || !ref || ref.scope === "file")
|
|
60
|
+
return;
|
|
61
|
+
const candidates = ref.symbol
|
|
62
|
+
? parsed.declarations.filter((d) => d.key === ref.symbol || d.name === ref.symbol)
|
|
63
|
+
: parsed.digest === ref.digest
|
|
64
|
+
? parsed.declarations
|
|
65
|
+
.filter((d) => d.start <= ref.line && ref.line <= d.end)
|
|
66
|
+
.sort((a, b) => a.end - a.start - (b.end - b.start))
|
|
67
|
+
.slice(0, 1)
|
|
68
|
+
: [];
|
|
69
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
70
|
+
}
|
|
71
|
+
function unique(parsed, key) {
|
|
72
|
+
const ds = parsed?.declarations.filter((d) => d.key === key) || [];
|
|
73
|
+
return ds.length === 1 ? ds[0] : undefined;
|
|
74
|
+
}
|
|
75
|
+
function signature(d, p) {
|
|
76
|
+
const parameters = d.node.parameters.map((n) => print(n, p.file)).join(", ");
|
|
77
|
+
const generics = d.node.typeParameters?.length
|
|
78
|
+
? `<${d.node.typeParameters.map((n) => print(n, p.file)).join(", ")}>`
|
|
79
|
+
: "";
|
|
80
|
+
const modifiers = d.node.modifiers
|
|
81
|
+
?.filter((m) => [
|
|
82
|
+
ts.SyntaxKind.AsyncKeyword,
|
|
83
|
+
ts.SyntaxKind.PublicKeyword,
|
|
84
|
+
ts.SyntaxKind.PrivateKeyword,
|
|
85
|
+
ts.SyntaxKind.ProtectedKeyword,
|
|
86
|
+
ts.SyntaxKind.StaticKeyword,
|
|
87
|
+
].includes(m.kind))
|
|
88
|
+
.map((m) => print(m, p.file))
|
|
89
|
+
.join(" ") || "";
|
|
90
|
+
return `${modifiers ? modifiers + " " : ""}${d.key}${generics}(${parameters}): ${d.node.type ? print(d.node.type, p.file) : "inferred"}`;
|
|
91
|
+
}
|
|
92
|
+
const refFor = (graph, id, file) => {
|
|
93
|
+
const node = graph.elements.find((n) => n.id === id);
|
|
94
|
+
return (node?.sources || (node?.source ? [node.source] : [])).find((r) => r.file === file);
|
|
95
|
+
};
|
|
96
|
+
/** Only explicit, uniquely mapped functions/methods are classified. Dynamic dispatch is not guessed. */
|
|
97
|
+
export function reviewWorkingCode(beforeGraph, graph, files, historicalOwnership) {
|
|
98
|
+
const changes = [], unassigned = [], parsed = new Map();
|
|
99
|
+
for (const f of files)
|
|
100
|
+
if (/\.[cm]?[jt]sx?$/.test(f.path) && !f.unavailable)
|
|
101
|
+
parsed.set(f.path, {
|
|
102
|
+
before: f.before === undefined ? undefined : parse(f.path, f.before),
|
|
103
|
+
after: f.after === undefined ? undefined : parse(f.path, f.after),
|
|
104
|
+
});
|
|
105
|
+
const ownership = new Map();
|
|
106
|
+
for (const [file, p] of parsed) {
|
|
107
|
+
const owners = new Map();
|
|
108
|
+
for (const id of new Set([...beforeGraph.elements, ...graph.elements]
|
|
109
|
+
.filter((n) => (n.sources || (n.source ? [n.source] : [])).some((r) => r.file === file))
|
|
110
|
+
.map((n) => n.id))) {
|
|
111
|
+
let b = anchor(p.before, refFor(beforeGraph, id, file)), a = anchor(p.after, refFor(graph, id, file));
|
|
112
|
+
if (!b && a)
|
|
113
|
+
b = unique(p.before, a.key);
|
|
114
|
+
if (!a && b)
|
|
115
|
+
a = unique(p.after, b.key);
|
|
116
|
+
if (b || a)
|
|
117
|
+
owners.set(id, { before: b, after: a });
|
|
118
|
+
}
|
|
119
|
+
ownership.set(file, owners);
|
|
120
|
+
}
|
|
121
|
+
const nodes = new Map([...beforeGraph.elements, ...graph.elements].map((n) => [n.id, n]));
|
|
122
|
+
function interfaceOf(id) {
|
|
123
|
+
let current = id;
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
while (current && !seen.has(current)) {
|
|
126
|
+
seen.add(current);
|
|
127
|
+
if (nodes.get(current)?.kind === "interface")
|
|
128
|
+
return current;
|
|
129
|
+
current = nodes.get(current)?.parent || "";
|
|
130
|
+
}
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
133
|
+
const unresolvedCalls = new Map();
|
|
134
|
+
function calls(file, d, side) {
|
|
135
|
+
const result = new Set(), p = parsed.get(file)?.[side];
|
|
136
|
+
if (!d || !p)
|
|
137
|
+
return result;
|
|
138
|
+
const declaration = d;
|
|
139
|
+
const unresolved = new Set();
|
|
140
|
+
unresolvedCalls.set(`${file}:${d.key}:${side}`, unresolved);
|
|
141
|
+
const shadowed = new Set();
|
|
142
|
+
function collect(n) {
|
|
143
|
+
if ((ts.isParameter(n) || ts.isVariableDeclaration(n)) &&
|
|
144
|
+
ts.isIdentifier(n.name))
|
|
145
|
+
shadowed.add(n.name.text);
|
|
146
|
+
ts.forEachChild(n, collect);
|
|
147
|
+
}
|
|
148
|
+
collect(declaration.node);
|
|
149
|
+
function visit(n) {
|
|
150
|
+
// A nested callback's dependencies still belong to its enclosing mapped operation.
|
|
151
|
+
if (ts.isCallExpression(n)) {
|
|
152
|
+
let targetFile = file, key = "";
|
|
153
|
+
if (ts.isIdentifier(n.expression)) {
|
|
154
|
+
if (shadowed.has(n.expression.text)) {
|
|
155
|
+
unresolved.add(n.expression.getText(p.file));
|
|
156
|
+
ts.forEachChild(n, visit);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const imp = p.imports.get(n.expression.text);
|
|
160
|
+
key = imp?.name || n.expression.text;
|
|
161
|
+
if (imp) {
|
|
162
|
+
const options = [
|
|
163
|
+
imp.file,
|
|
164
|
+
`${imp.file}.ts`,
|
|
165
|
+
`${imp.file}.tsx`,
|
|
166
|
+
`${imp.file}/index.ts`,
|
|
167
|
+
];
|
|
168
|
+
const matched = [
|
|
169
|
+
...new Set([...ownership.keys(), ...nodes.values()].flatMap((v) => typeof v === "string"
|
|
170
|
+
? [v]
|
|
171
|
+
: (v.sources || (v.source ? [v.source] : [])).map((r) => r.file))),
|
|
172
|
+
].filter((f) => options.includes(f));
|
|
173
|
+
if (matched.length !== 1) {
|
|
174
|
+
unresolved.add(n.expression.getText(p.file));
|
|
175
|
+
ts.forEachChild(n, visit);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
targetFile = matched[0];
|
|
179
|
+
}
|
|
180
|
+
else if (declaration.className) {
|
|
181
|
+
/* Bare calls cannot refer to another instance method. */
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (ts.isPropertyAccessExpression(n.expression) &&
|
|
185
|
+
n.expression.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
186
|
+
declaration.className)
|
|
187
|
+
key = `${declaration.className}.${n.expression.name.text}`;
|
|
188
|
+
if (key) {
|
|
189
|
+
// External unchanged files can only be resolved through an explicit source symbol.
|
|
190
|
+
const mapped = [...(ownership.get(targetFile) || new Map())]
|
|
191
|
+
.filter(([, pair]) => pair[side]?.key === key)
|
|
192
|
+
.map(([id]) => id);
|
|
193
|
+
if (!ownership.has(targetFile))
|
|
194
|
+
for (const node of (side === "before" ? beforeGraph : graph)
|
|
195
|
+
.elements)
|
|
196
|
+
if ((node.sources || (node.source ? [node.source] : [])).some((r) => r.file === targetFile && r.symbol === key))
|
|
197
|
+
mapped.push(node.id);
|
|
198
|
+
if (mapped.length === 1)
|
|
199
|
+
result.add(mapped[0]);
|
|
200
|
+
else
|
|
201
|
+
unresolved.add(n.expression.getText(p.file));
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
unresolved.add(n.expression.getText(p.file));
|
|
205
|
+
}
|
|
206
|
+
ts.forEachChild(n, visit);
|
|
207
|
+
}
|
|
208
|
+
visit(d.node.body);
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
for (const file of files) {
|
|
212
|
+
if (file.before === file.after && !file.unavailable)
|
|
213
|
+
continue;
|
|
214
|
+
const p = parsed.get(file.path), owners = ownership.get(file.path);
|
|
215
|
+
const mapped = [...nodes.values()].filter((n) => (n.sources || (n.source ? [n.source] : [])).some((r) => r.file === file.path));
|
|
216
|
+
if (!mapped.length) {
|
|
217
|
+
const supportOwners = new Set([...nodes.values()]
|
|
218
|
+
.filter((n) => n.attachments?.docs?.some((path) => path.split("#")[0] === file.path) || n.attachments?.tests?.includes(file.path))
|
|
219
|
+
.map((n) => n.id));
|
|
220
|
+
for (const test of [...beforeGraph.tests, ...graph.tests])
|
|
221
|
+
if (test.source.file === file.path)
|
|
222
|
+
for (const id of test.targets)
|
|
223
|
+
supportOwners.add(id);
|
|
224
|
+
if (file.path === "fractory.json")
|
|
225
|
+
supportOwners.add(graph.id);
|
|
226
|
+
if (supportOwners.size) {
|
|
227
|
+
for (const id of supportOwners)
|
|
228
|
+
changes.push({
|
|
229
|
+
kind: "support",
|
|
230
|
+
block: id,
|
|
231
|
+
file: file.path,
|
|
232
|
+
label: file.path === "fractory.json"
|
|
233
|
+
? "Map declarations changed"
|
|
234
|
+
: /\.mdx?$/.test(file.path)
|
|
235
|
+
? "Attached documentation changed"
|
|
236
|
+
: "Associated tests changed",
|
|
237
|
+
});
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
unassigned.push(file.path);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (!p ||
|
|
244
|
+
(!p.before?.valid && file.before !== undefined) ||
|
|
245
|
+
(!p.after?.valid && file.after !== undefined)) {
|
|
246
|
+
for (const n of mapped)
|
|
247
|
+
changes.push({
|
|
248
|
+
kind: "mapping",
|
|
249
|
+
block: n.id,
|
|
250
|
+
file: file.path,
|
|
251
|
+
label: file.unavailable || "No parseable declaration evidence",
|
|
252
|
+
});
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
// A mapped file can also contain changed code outside its mapped declarations.
|
|
256
|
+
const covered = new Set([...(owners?.values() || [])].flatMap((pair) => [pair.before?.key, pair.after?.key].filter(Boolean)));
|
|
257
|
+
const unmatched = new Set([...(p.before?.declarations || []), ...(p.after?.declarations || [])]
|
|
258
|
+
.map((d) => d.key)
|
|
259
|
+
.filter((key) => !covered.has(key)));
|
|
260
|
+
if ([...unmatched].some((key) => {
|
|
261
|
+
const b = unique(p.before, key), a = unique(p.after, key);
|
|
262
|
+
return ((b && p.before ? print(b.node, p.before.file) : undefined) !==
|
|
263
|
+
(a && p.after ? print(a.node, p.after.file) : undefined));
|
|
264
|
+
}))
|
|
265
|
+
unassigned.push(file.path);
|
|
266
|
+
for (const n of mapped) {
|
|
267
|
+
const pair = owners?.get(n.id);
|
|
268
|
+
if (!pair) {
|
|
269
|
+
changes.push({
|
|
270
|
+
kind: "mapping",
|
|
271
|
+
block: n.id,
|
|
272
|
+
file: file.path,
|
|
273
|
+
label: "Refresh this block’s source anchor",
|
|
274
|
+
});
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const { before: b, after: a } = pair;
|
|
278
|
+
if (!historicalOwnership && (b?.key !== a?.key || !b || !a)) {
|
|
279
|
+
changes.push({
|
|
280
|
+
kind: "mapping",
|
|
281
|
+
block: n.id,
|
|
282
|
+
file: file.path,
|
|
283
|
+
label: "Starting revision has no verified block ownership",
|
|
284
|
+
});
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const sb = b && p.before ? signature(b, p.before) : undefined, sa = a && p.after ? signature(a, p.after) : undefined;
|
|
288
|
+
if (sb !== sa)
|
|
289
|
+
changes.push({
|
|
290
|
+
kind: "interface",
|
|
291
|
+
block: interfaceOf(n.id),
|
|
292
|
+
file: file.path,
|
|
293
|
+
label: !b
|
|
294
|
+
? "Added callable"
|
|
295
|
+
: !a
|
|
296
|
+
? "Removed callable"
|
|
297
|
+
: "Declaration changed",
|
|
298
|
+
before: sb?.slice(0, 1800),
|
|
299
|
+
after: sa?.slice(0, 1800),
|
|
300
|
+
});
|
|
301
|
+
const bodyB = b && p.before ? print(b.node.body, p.before.file) : undefined, bodyA = a && p.after ? print(a.node.body, p.after.file) : undefined;
|
|
302
|
+
if (bodyB !== bodyA) {
|
|
303
|
+
changes.push({
|
|
304
|
+
kind: "implementation",
|
|
305
|
+
block: n.id,
|
|
306
|
+
file: file.path,
|
|
307
|
+
label: "Implementation changed",
|
|
308
|
+
});
|
|
309
|
+
if (a && !a.node.type)
|
|
310
|
+
changes.push({
|
|
311
|
+
kind: "mapping",
|
|
312
|
+
block: n.id,
|
|
313
|
+
file: file.path,
|
|
314
|
+
label: "Return type is inferred; contract compatibility needs a type check",
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const cb = calls(file.path, b, "before"), ca = calls(file.path, a, "after");
|
|
318
|
+
const ub = b
|
|
319
|
+
? unresolvedCalls.get(`${file.path}:${b.key}:before`) ||
|
|
320
|
+
new Set()
|
|
321
|
+
: new Set(), ua = a
|
|
322
|
+
? unresolvedCalls.get(`${file.path}:${a.key}:after`) ||
|
|
323
|
+
new Set()
|
|
324
|
+
: new Set();
|
|
325
|
+
if ([...ub].some((key) => !ua.has(key)) ||
|
|
326
|
+
[...ua].some((key) => !ub.has(key)))
|
|
327
|
+
changes.push({
|
|
328
|
+
kind: "mapping",
|
|
329
|
+
block: n.id,
|
|
330
|
+
file: file.path,
|
|
331
|
+
label: "Some changed call targets are dynamic or not mapped",
|
|
332
|
+
});
|
|
333
|
+
for (const [set, other, change] of [
|
|
334
|
+
[ca, cb, "added"],
|
|
335
|
+
[cb, ca, "removed"],
|
|
336
|
+
])
|
|
337
|
+
for (const target of set)
|
|
338
|
+
if (!other.has(target) && target !== n.id) {
|
|
339
|
+
const existing = (change === "removed" ? beforeGraph : graph).connections.find((e) => e.source === n.id &&
|
|
340
|
+
e.target === target &&
|
|
341
|
+
e.relation === "calls");
|
|
342
|
+
const connection = existing || {
|
|
343
|
+
id: `work-call:${n.id}:${target}`,
|
|
344
|
+
source: n.id,
|
|
345
|
+
target,
|
|
346
|
+
relation: "calls",
|
|
347
|
+
label: nodes.get(target)?.label || target,
|
|
348
|
+
provenance: "source",
|
|
349
|
+
};
|
|
350
|
+
changes.push({
|
|
351
|
+
kind: "connection",
|
|
352
|
+
block: n.id,
|
|
353
|
+
file: file.path,
|
|
354
|
+
label: `${change === "added" ? "Calls" : "No longer calls"} ${nodes.get(target)?.label || target}`,
|
|
355
|
+
connection,
|
|
356
|
+
change,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (historicalOwnership) {
|
|
362
|
+
const stable = (value) => Array.isArray(value)
|
|
363
|
+
? value.map(stable)
|
|
364
|
+
: value && typeof value === "object"
|
|
365
|
+
? Object.fromEntries(Object.entries(value)
|
|
366
|
+
.filter(([key]) => ![
|
|
367
|
+
"source",
|
|
368
|
+
"sources",
|
|
369
|
+
"sourceRef",
|
|
370
|
+
"line",
|
|
371
|
+
"digest",
|
|
372
|
+
"provenance",
|
|
373
|
+
].includes(key))
|
|
374
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
375
|
+
.map(([key, value]) => [key, stable(value)]))
|
|
376
|
+
: value;
|
|
377
|
+
const beforeNodes = new Map(beforeGraph.elements.map((n) => [n.id, n]));
|
|
378
|
+
for (const node of graph.elements) {
|
|
379
|
+
const old = beforeNodes.get(node.id);
|
|
380
|
+
if (!old)
|
|
381
|
+
continue;
|
|
382
|
+
const contract = (n) => ({
|
|
383
|
+
contract: n.contract,
|
|
384
|
+
auth: n.attachments?.auth?.symbol,
|
|
385
|
+
});
|
|
386
|
+
if (JSON.stringify(stable(contract(old))) !==
|
|
387
|
+
JSON.stringify(stable(contract(node))))
|
|
388
|
+
changes.push({
|
|
389
|
+
kind: "interface",
|
|
390
|
+
block: interfaceOf(node.id),
|
|
391
|
+
file: node.source?.file || "fractory.json",
|
|
392
|
+
label: "Declared contract or auth changed",
|
|
393
|
+
before: JSON.stringify(stable(contract(old))).slice(0, 1800),
|
|
394
|
+
after: JSON.stringify(stable(contract(node))).slice(0, 1800),
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
const oldEdges = new Map(beforeGraph.connections.map((e) => [e.id, e])), newEdges = new Map(graph.connections.map((e) => [e.id, e]));
|
|
398
|
+
for (const id of new Set([...oldEdges.keys(), ...newEdges.keys()])) {
|
|
399
|
+
const b = oldEdges.get(id), a = newEdges.get(id);
|
|
400
|
+
if (JSON.stringify(stable(b)) === JSON.stringify(stable(a)))
|
|
401
|
+
continue;
|
|
402
|
+
if (changes.some((c) => c.connection?.id === id))
|
|
403
|
+
continue;
|
|
404
|
+
const edge = a || b;
|
|
405
|
+
changes.push({
|
|
406
|
+
kind: "connection",
|
|
407
|
+
block: edge.source,
|
|
408
|
+
file: edge.sourceRef?.file || "fractory.json",
|
|
409
|
+
label: !b
|
|
410
|
+
? "Declared connection added"
|
|
411
|
+
: !a
|
|
412
|
+
? "Declared connection removed"
|
|
413
|
+
: "Declared connection changed",
|
|
414
|
+
connection: edge,
|
|
415
|
+
change: !b ? "added" : !a ? "removed" : "modified",
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// One interface can group several methods with independent signature changes.
|
|
420
|
+
return {
|
|
421
|
+
basis: "saved-code",
|
|
422
|
+
changes,
|
|
423
|
+
unassigned: [...new Set(unassigned)],
|
|
424
|
+
historicalOwnership,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { WorkTarget } from "./work-model.js";
|
|
2
|
+
export interface WorkChoice extends WorkTarget {
|
|
3
|
+
detached: boolean;
|
|
4
|
+
checkout?: string;
|
|
5
|
+
commit?: {
|
|
6
|
+
subject: string;
|
|
7
|
+
at: string;
|
|
8
|
+
author: string;
|
|
9
|
+
};
|
|
10
|
+
blocks: {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}[];
|
|
14
|
+
blockBasis: "plan" | "files";
|
|
15
|
+
status?: {
|
|
16
|
+
changed: number | null;
|
|
17
|
+
conflicts: number | null;
|
|
18
|
+
checkedAt: string | null;
|
|
19
|
+
editedAt?: string;
|
|
20
|
+
unavailable?: string;
|
|
21
|
+
partial: boolean;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface WorkChoices {
|
|
25
|
+
repository: string;
|
|
26
|
+
targets: WorkChoice[];
|
|
27
|
+
checkedAt: string;
|
|
28
|
+
detailed: boolean;
|
|
29
|
+
}
|
|
30
|
+
export type WorkChoiceView = "recent" | "worktrees" | "branches";
|
|
31
|
+
export interface WorkVisit {
|
|
32
|
+
id: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
at: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const friendlyBranch: (name: string) => string;
|
|
37
|
+
export declare function choiceTitle(t: WorkChoice): string;
|
|
38
|
+
export declare function choiceDescription(t: WorkChoice): string;
|
|
39
|
+
export declare function visitTime(t: WorkChoice, visits: WorkVisit[]): number;
|
|
40
|
+
/** Stable ordering within an open switcher is supplied by the caller, not status arrival order. */
|
|
41
|
+
export declare function choiceOrder(t: WorkChoice, visits: WorkVisit[]): number;
|
|
42
|
+
export declare function recentChoices(targets: WorkChoice[], visits: WorkVisit[], active: string, now?: number): WorkChoice[];
|
|
43
|
+
export declare function relativeWorkTime(at: string | undefined, now?: number): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export const friendlyBranch = (name) => {
|
|
2
|
+
const text = name.replace(/^[^/]+\//, "").replace(/[-_]+/g, " ");
|
|
3
|
+
return text ? text[0].toUpperCase() + text.slice(1) : "Local worktree";
|
|
4
|
+
};
|
|
5
|
+
export function choiceTitle(t) {
|
|
6
|
+
if (t.managed)
|
|
7
|
+
return t.title;
|
|
8
|
+
if (!t.detached)
|
|
9
|
+
return friendlyBranch(t.branch);
|
|
10
|
+
return t.blocks.length
|
|
11
|
+
? t.blocks
|
|
12
|
+
.slice(0, 2)
|
|
13
|
+
.map((b) => b.label)
|
|
14
|
+
.join(" · ")
|
|
15
|
+
: "Local worktree";
|
|
16
|
+
}
|
|
17
|
+
export function choiceDescription(t) {
|
|
18
|
+
if (t.detached && !t.managed)
|
|
19
|
+
return [
|
|
20
|
+
t.commit?.subject ? `Last commit: ${t.commit.subject}` : undefined,
|
|
21
|
+
t.checkout,
|
|
22
|
+
]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(" · ");
|
|
25
|
+
return t.blocks.length
|
|
26
|
+
? t.blocks
|
|
27
|
+
.slice(0, 2)
|
|
28
|
+
.map((b) => b.label)
|
|
29
|
+
.join(" · ") + (t.blocks.length > 2 ? ` +${t.blocks.length - 2}` : "")
|
|
30
|
+
: t.commit?.subject
|
|
31
|
+
? `Last commit: ${t.commit.subject}`
|
|
32
|
+
: t.path
|
|
33
|
+
? "Local checkout"
|
|
34
|
+
: "No local checkout";
|
|
35
|
+
}
|
|
36
|
+
export function visitTime(t, visits) {
|
|
37
|
+
return Math.max(0, ...visits
|
|
38
|
+
.filter((v) => v.id === t.id || (!!v.path && v.path === t.path))
|
|
39
|
+
.map((v) => v.at));
|
|
40
|
+
}
|
|
41
|
+
/** Stable ordering within an open switcher is supplied by the caller, not status arrival order. */
|
|
42
|
+
export function choiceOrder(t, visits) {
|
|
43
|
+
return (visitTime(t, visits) ||
|
|
44
|
+
Math.max(0, ...[t.status?.editedAt, t.plannedAt, t.commit?.at].map((at) => Date.parse(at || "") || 0)));
|
|
45
|
+
}
|
|
46
|
+
export function recentChoices(targets, visits, active, now = Date.now()) {
|
|
47
|
+
const recentSince = now - 30 * 86400000;
|
|
48
|
+
return targets
|
|
49
|
+
.filter((t) => visitTime(t, visits) > recentSince ||
|
|
50
|
+
t.id === active ||
|
|
51
|
+
(t.path &&
|
|
52
|
+
(t.managed ||
|
|
53
|
+
(t.status?.changed && choiceOrder(t, []) >= recentSince) ||
|
|
54
|
+
(t.current && !t.detached))))
|
|
55
|
+
.sort((a, b) => visitTime(b, visits) - visitTime(a, visits) ||
|
|
56
|
+
Number(b.id === active) - Number(a.id === active) ||
|
|
57
|
+
Number(b.current) - Number(a.current) ||
|
|
58
|
+
choiceOrder(b, visits) - choiceOrder(a, visits) ||
|
|
59
|
+
Number(b.managed) - Number(a.managed) ||
|
|
60
|
+
a.id.localeCompare(b.id))
|
|
61
|
+
.slice(0, 8);
|
|
62
|
+
}
|
|
63
|
+
export function relativeWorkTime(at, now = Date.now()) {
|
|
64
|
+
if (!at || !Number.isFinite(Date.parse(at)))
|
|
65
|
+
return "";
|
|
66
|
+
const minutes = Math.max(0, Math.floor((now - Date.parse(at)) / 60000));
|
|
67
|
+
if (minutes < 1)
|
|
68
|
+
return "just now";
|
|
69
|
+
if (minutes < 60)
|
|
70
|
+
return `${minutes}m ago`;
|
|
71
|
+
if (minutes < 1440)
|
|
72
|
+
return `${Math.floor(minutes / 60)}h ago`;
|
|
73
|
+
if (minutes < 10080)
|
|
74
|
+
return `${Math.floor(minutes / 1440)}d ago`;
|
|
75
|
+
return new Intl.DateTimeFormat(undefined, {
|
|
76
|
+
month: "short",
|
|
77
|
+
day: "numeric",
|
|
78
|
+
}).format(new Date(at));
|
|
79
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
import type { WorkChoices } from "./work-switcher-model.js";
|
|
3
|
+
export declare function workChoiceCatalog(root: string, graph: DefinitionGraph, fresh?: boolean): WorkChoices;
|
|
4
|
+
/** Reuse the live-work adapter and its read budgets. Each checkout is independent; unknown is never clean. */
|
|
5
|
+
export declare function workChoiceDetails(root: string, graph: DefinitionGraph, fresh?: boolean): Promise<WorkChoices>;
|
|
6
|
+
export declare function invalidateWorkChoices(root: string): void;
|