@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,224 @@
|
|
|
1
|
+
import { repositoryMapPaths } from "./repository-map.js";
|
|
2
|
+
/** Resolve a review link using Git identities, without compiling or checking out code. */
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { comparisonMergeBase, resolveComparisonRef } from "./git-refs.js";
|
|
7
|
+
const native = (command, args, cwd, input) => execFileSync(command, args, {
|
|
8
|
+
cwd,
|
|
9
|
+
input,
|
|
10
|
+
encoding: "utf8",
|
|
11
|
+
timeout: 15000,
|
|
12
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
13
|
+
stdio: [input === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
14
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
|
|
15
|
+
});
|
|
16
|
+
export function reviewTarget(root, options = {}) {
|
|
17
|
+
const git = (args, input) => native("git", ["--no-pager", ...args], root, input).trim();
|
|
18
|
+
let branch = null;
|
|
19
|
+
try {
|
|
20
|
+
branch = git(["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* detached HEAD remains a valid explicit review */
|
|
24
|
+
}
|
|
25
|
+
let base = options.base;
|
|
26
|
+
if (!base) {
|
|
27
|
+
try {
|
|
28
|
+
base = git([
|
|
29
|
+
"symbolic-ref",
|
|
30
|
+
"--quiet",
|
|
31
|
+
"--short",
|
|
32
|
+
"refs/remotes/origin/HEAD",
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* repositories may not record a default remote branch */
|
|
37
|
+
}
|
|
38
|
+
if (!base)
|
|
39
|
+
for (const ref of ["origin/main", "origin/master", "main", "master"]) {
|
|
40
|
+
try {
|
|
41
|
+
resolveComparisonRef(root, ref);
|
|
42
|
+
base = ref;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* next local candidate */
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!base)
|
|
51
|
+
throw Error("Choose --base REF; no default branch is available locally.");
|
|
52
|
+
let baseCommit, head;
|
|
53
|
+
try {
|
|
54
|
+
baseCommit = resolveComparisonRef(root, base);
|
|
55
|
+
head = resolveComparisonRef(root, options.head || "HEAD");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw Error("These review refs are not available locally. Fetch the selected PR base/head, then retry; no checkout is needed.");
|
|
59
|
+
}
|
|
60
|
+
const from = comparisonMergeBase(root, baseCommit, head);
|
|
61
|
+
const definitions = options.definition
|
|
62
|
+
? [options.definition]
|
|
63
|
+
: repositoryMapPaths(root);
|
|
64
|
+
if (definitions.some((file) => !file || /[\r\n\0]/.test(file)))
|
|
65
|
+
throw Error("Choose a repository-relative definition path.");
|
|
66
|
+
const captured = (commit) => {
|
|
67
|
+
const ref = join(root, ".fractal/commits", commit);
|
|
68
|
+
if (!existsSync(ref))
|
|
69
|
+
return false;
|
|
70
|
+
const id = readFileSync(ref, "utf8").trim();
|
|
71
|
+
return (/^[a-f0-9]{64}$/.test(id) &&
|
|
72
|
+
existsSync(join(root, ".fractal/objects", id + ".json")));
|
|
73
|
+
};
|
|
74
|
+
const available = (commit) => {
|
|
75
|
+
if (captured(commit))
|
|
76
|
+
return true;
|
|
77
|
+
const present = git(["cat-file", "--batch-check"], definitions.map((file) => `${commit}:${file}`).join("\n") + "\n")
|
|
78
|
+
.split("\n")
|
|
79
|
+
.map((line) => /^[a-f0-9]{40,64} blob \d+$/.test(line));
|
|
80
|
+
return options.definition
|
|
81
|
+
? present.every(Boolean)
|
|
82
|
+
: present[0] || (present.length > 1 && present.slice(1).every(Boolean));
|
|
83
|
+
};
|
|
84
|
+
const historicalMaps = available(from) && available(head);
|
|
85
|
+
const status = git([
|
|
86
|
+
"status",
|
|
87
|
+
"--porcelain=v1",
|
|
88
|
+
"-z",
|
|
89
|
+
"--untracked-files=normal",
|
|
90
|
+
]).split("\0");
|
|
91
|
+
let dirtyEntries = 0;
|
|
92
|
+
for (let i = 0; i < status.length; i++) {
|
|
93
|
+
if (!status[i])
|
|
94
|
+
continue;
|
|
95
|
+
dirtyEntries++;
|
|
96
|
+
if (/[RC]/.test(status[i].slice(0, 2)))
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
const viewer = new URL(options.viewer ||
|
|
100
|
+
process.env.FRACTORY_VIEWER_URL ||
|
|
101
|
+
"http://127.0.0.1:4318/fractal");
|
|
102
|
+
if (!["http:", "https:", "fractory:"].includes(viewer.protocol) ||
|
|
103
|
+
(viewer.protocol === "fractory:" && viewer.hostname !== "open") ||
|
|
104
|
+
viewer.username ||
|
|
105
|
+
viewer.password)
|
|
106
|
+
throw Error("Use an HTTP(S) factory viewer URL or fractory://open without credentials.");
|
|
107
|
+
if (viewer.pathname === "/")
|
|
108
|
+
viewer.pathname = "/fractal";
|
|
109
|
+
viewer.search = new URLSearchParams({
|
|
110
|
+
...(viewer.protocol === "fractory:" ? { repo: root } : {}),
|
|
111
|
+
base: baseCommit,
|
|
112
|
+
head,
|
|
113
|
+
compare: "pr",
|
|
114
|
+
...(!historicalMaps ? { footprint: "1" } : {}),
|
|
115
|
+
...(options.title ? { reviewTitle: options.title.slice(0, 500) } : {}),
|
|
116
|
+
...(options.url?.startsWith("https://") ? { reviewUrl: options.url } : {}),
|
|
117
|
+
}).toString();
|
|
118
|
+
return {
|
|
119
|
+
url: viewer.href,
|
|
120
|
+
branch,
|
|
121
|
+
base: baseCommit,
|
|
122
|
+
mergeBase: from,
|
|
123
|
+
head,
|
|
124
|
+
basis: historicalMaps ? "snapshots" : "current-map",
|
|
125
|
+
dirtyEntries,
|
|
126
|
+
warnings: [
|
|
127
|
+
...(!historicalMaps
|
|
128
|
+
? [
|
|
129
|
+
"Historical factory maps are missing. This opens source associations on a reviewed map; historical contracts and connection changes remain unknown.",
|
|
130
|
+
]
|
|
131
|
+
: []),
|
|
132
|
+
...(dirtyEntries
|
|
133
|
+
? [
|
|
134
|
+
`${dirtyEntries} working-tree entries are uncommitted and are not included in this committed comparison. Use the map's working-change Impact view to inspect them.`,
|
|
135
|
+
]
|
|
136
|
+
: []),
|
|
137
|
+
...(from === head && baseCommit !== head
|
|
138
|
+
? [
|
|
139
|
+
"The selected head is behind the base; it has no committed branch-only changes.",
|
|
140
|
+
]
|
|
141
|
+
: []),
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export function runReview(args, cwd = process.cwd(), open = (url) => {
|
|
146
|
+
const command = process.platform === "darwin"
|
|
147
|
+
? "open"
|
|
148
|
+
: process.platform === "win32"
|
|
149
|
+
? "explorer.exe"
|
|
150
|
+
: "xdg-open";
|
|
151
|
+
native(command, [url], cwd);
|
|
152
|
+
}) {
|
|
153
|
+
if (args.includes("--help"))
|
|
154
|
+
return "Fractory review\n\n bun run fractal review [--base main] [--head HEAD] [--open]\n bun run fractal review --pr [466] [--open]\n bun run fractal review --base BASE_SHA --head HEAD_SHA --title 'PR #466' --url https://github.com/owner/repo/pull/466\n\nPrints a map URL for merge-base → head. A missing historical map opens an explicitly labeled file footprint. --pr uses the installed GitHub CLI for one metadata read; agents can instead use their GitHub connector and pass the resolved refs. --viewer URL selects the repository viewer. Uncommitted changes are reported separately.\n";
|
|
155
|
+
const allowed = new Set([
|
|
156
|
+
"--base",
|
|
157
|
+
"--head",
|
|
158
|
+
"--viewer",
|
|
159
|
+
"--definition",
|
|
160
|
+
"--title",
|
|
161
|
+
"--url",
|
|
162
|
+
"--root",
|
|
163
|
+
"--pr",
|
|
164
|
+
"--open",
|
|
165
|
+
"--help",
|
|
166
|
+
]);
|
|
167
|
+
for (const argument of args)
|
|
168
|
+
if (argument.startsWith("--") && !allowed.has(argument))
|
|
169
|
+
throw Error(`Unknown review option: ${argument}`);
|
|
170
|
+
const value = (flag) => {
|
|
171
|
+
const index = args.indexOf(flag);
|
|
172
|
+
if (index < 0)
|
|
173
|
+
return;
|
|
174
|
+
const next = args[index + 1];
|
|
175
|
+
if (!next || next.startsWith("--"))
|
|
176
|
+
throw Error(`${flag} needs a value`);
|
|
177
|
+
return next;
|
|
178
|
+
};
|
|
179
|
+
const root = resolve(value("--root") ||
|
|
180
|
+
native("git", ["rev-parse", "--show-toplevel"], cwd).trim());
|
|
181
|
+
let options = {
|
|
182
|
+
base: value("--base"),
|
|
183
|
+
head: value("--head"),
|
|
184
|
+
viewer: value("--viewer"),
|
|
185
|
+
definition: value("--definition"),
|
|
186
|
+
title: value("--title"),
|
|
187
|
+
url: value("--url"),
|
|
188
|
+
};
|
|
189
|
+
const prIndex = args.indexOf("--pr");
|
|
190
|
+
const pr = prIndex >= 0 && args[prIndex + 1] && !args[prIndex + 1].startsWith("--")
|
|
191
|
+
? args[prIndex + 1]
|
|
192
|
+
: undefined;
|
|
193
|
+
if (prIndex >= 0) {
|
|
194
|
+
if (pr &&
|
|
195
|
+
!/^(?:\d+|https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/pull\/\d+)$/.test(pr))
|
|
196
|
+
throw Error("Use a PR number or HTTPS pull-request URL.");
|
|
197
|
+
try {
|
|
198
|
+
const info = JSON.parse(native("gh", [
|
|
199
|
+
"pr",
|
|
200
|
+
"view",
|
|
201
|
+
...(pr ? [pr] : []),
|
|
202
|
+
"--json",
|
|
203
|
+
"number,title,url,baseRefOid,headRefOid",
|
|
204
|
+
], root));
|
|
205
|
+
if (!/^[a-f0-9]{40}$/.test(info.baseRefOid) ||
|
|
206
|
+
!/^[a-f0-9]{40}$/.test(info.headRefOid))
|
|
207
|
+
throw Error("Missing PR identities");
|
|
208
|
+
options = {
|
|
209
|
+
...options,
|
|
210
|
+
base: info.baseRefOid,
|
|
211
|
+
head: info.headRefOid,
|
|
212
|
+
title: `PR #${info.number} · ${info.title}`,
|
|
213
|
+
url: info.url,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
throw Error("Could not read this PR through gh. Use the GitHub connector, then pass --base SHA --head SHA --title TITLE --url URL.");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const target = reviewTarget(root, options);
|
|
221
|
+
if (args.includes("--open"))
|
|
222
|
+
open(target.url);
|
|
223
|
+
return JSON.stringify(target, null, 2);
|
|
224
|
+
}
|
package/dist/review.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FactoryComparison } from "./compare.js";
|
|
2
|
+
import type { DefinitionGraph } from "./model.js";
|
|
3
|
+
import { connectionEvidence } from "./change-impact.js";
|
|
4
|
+
/** A footprint is explicitly today's map associated with changed paths, not two historical factories. */
|
|
5
|
+
export interface FactoryFootprint {
|
|
6
|
+
schema: "fractal.footprint.v1";
|
|
7
|
+
/** Added capability memberships and interactions were read from this commit. Not a historical contract diff. */
|
|
8
|
+
mappingRevision?: string;
|
|
9
|
+
concepts?: import("./work-review.js").WorkReview;
|
|
10
|
+
graph: DefinitionGraph;
|
|
11
|
+
base: string;
|
|
12
|
+
head: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
url?: string;
|
|
15
|
+
files: {
|
|
16
|
+
path: string;
|
|
17
|
+
status: "added" | "removed" | "modified";
|
|
18
|
+
digest?: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
export type ReviewFacet = "internal" | "interfaces" | "structure" | "metadata" | "source";
|
|
22
|
+
export declare const reviewFacets: ReviewFacet[];
|
|
23
|
+
export type ReviewMark = Record<ReviewFacet, number> & {
|
|
24
|
+
consumers: number;
|
|
25
|
+
};
|
|
26
|
+
export type ConsumerReason = {
|
|
27
|
+
id: string;
|
|
28
|
+
provider: string;
|
|
29
|
+
via: string;
|
|
30
|
+
distance: number;
|
|
31
|
+
evidence: ReturnType<typeof connectionEvidence>;
|
|
32
|
+
};
|
|
33
|
+
export interface FactoryReview {
|
|
34
|
+
graph: DefinitionGraph;
|
|
35
|
+
key: string;
|
|
36
|
+
basis: "snapshots" | "current-map" | "head-source" | "working-code";
|
|
37
|
+
direct: Record<string, ReviewFacet[]>;
|
|
38
|
+
marks: Record<string, ReviewMark>;
|
|
39
|
+
consumers: ConsumerReason[];
|
|
40
|
+
connectionIds: string[];
|
|
41
|
+
fingerprints: Record<string, string>;
|
|
42
|
+
files: Record<string, string[]>;
|
|
43
|
+
unmapped: string[];
|
|
44
|
+
}
|
|
45
|
+
export declare function factoryReview(input: FactoryComparison | FactoryFootprint, indirect?: boolean): FactoryReview;
|
|
46
|
+
/** A parent review is valid only while all of its scoped evidence is unchanged. */
|
|
47
|
+
export declare function reviewedScope(review: FactoryReview, saved: Record<string, string>, id: string): boolean;
|
|
48
|
+
export declare function reviewUnits(review: FactoryReview): string[];
|
package/dist/review.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { logicalMap } from "./map-model.js";
|
|
2
|
+
import { graphIndex, connectionEvidence } from "./change-impact.js";
|
|
3
|
+
export const reviewFacets = [
|
|
4
|
+
"internal",
|
|
5
|
+
"interfaces",
|
|
6
|
+
"structure",
|
|
7
|
+
"metadata",
|
|
8
|
+
"source",
|
|
9
|
+
];
|
|
10
|
+
const empty = () => ({
|
|
11
|
+
internal: 0,
|
|
12
|
+
interfaces: 0,
|
|
13
|
+
structure: 0,
|
|
14
|
+
metadata: 0,
|
|
15
|
+
source: 0,
|
|
16
|
+
consumers: 0,
|
|
17
|
+
});
|
|
18
|
+
/** A review checksum, not a security or source integrity hash. */
|
|
19
|
+
function fingerprint(value) {
|
|
20
|
+
const text = JSON.stringify(value);
|
|
21
|
+
let a = 2166136261, b = 5381;
|
|
22
|
+
for (let i = 0; i < text.length; i++) {
|
|
23
|
+
a = Math.imul(a ^ text.charCodeAt(i), 16777619);
|
|
24
|
+
b = Math.imul(b, 33) ^ text.charCodeAt(i);
|
|
25
|
+
}
|
|
26
|
+
return `${(a >>> 0).toString(16)}${(b >>> 0).toString(16)}:${text.length}`;
|
|
27
|
+
}
|
|
28
|
+
function normalized(value) {
|
|
29
|
+
if (Array.isArray(value))
|
|
30
|
+
return value.map(normalized);
|
|
31
|
+
if (!value || typeof value !== "object")
|
|
32
|
+
return value;
|
|
33
|
+
return Object.fromEntries(Object.entries(value)
|
|
34
|
+
.filter(([key]) => ![
|
|
35
|
+
"source",
|
|
36
|
+
"sources",
|
|
37
|
+
"sourceRef",
|
|
38
|
+
"digest",
|
|
39
|
+
"line",
|
|
40
|
+
"definitionRevision",
|
|
41
|
+
"generatedAt",
|
|
42
|
+
].includes(key))
|
|
43
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
44
|
+
.map(([key, item]) => [key, normalized(item)]));
|
|
45
|
+
}
|
|
46
|
+
export function factoryReview(input, indirect = false) {
|
|
47
|
+
const exact = input.schema === "fractal.comparison.v1" ? input : undefined;
|
|
48
|
+
const footprint = input.schema === "fractal.footprint.v1" ? input : undefined;
|
|
49
|
+
const graph = logicalMap(input.graph), { byId, within } = graphIndex(graph);
|
|
50
|
+
const ancestors = (id) => {
|
|
51
|
+
const result = [], seen = new Set();
|
|
52
|
+
while (byId.has(id) && !seen.has(id)) {
|
|
53
|
+
result.push(id);
|
|
54
|
+
seen.add(id);
|
|
55
|
+
id = byId.get(id)?.parent || "";
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
const direct = {}, files = {}, evidence = new Map();
|
|
60
|
+
const add = (id, facet, item) => {
|
|
61
|
+
if (!byId.has(id))
|
|
62
|
+
return;
|
|
63
|
+
direct[id] = [...new Set([...(direct[id] || []), facet])];
|
|
64
|
+
if (item !== undefined)
|
|
65
|
+
evidence.set(id, [...(evidence.get(id) || []), item]);
|
|
66
|
+
};
|
|
67
|
+
const interfaceOf = (id) => ancestors(id).find((parent) => byId.get(parent)?.kind === "interface");
|
|
68
|
+
if (exact) {
|
|
69
|
+
for (const [id, change] of Object.entries(exact.elements)) {
|
|
70
|
+
const node = change.after || change.before;
|
|
71
|
+
const source = change.source.map((part) => ({
|
|
72
|
+
side: part.side,
|
|
73
|
+
file: part.file,
|
|
74
|
+
digest: part.digest || exact.after.commit,
|
|
75
|
+
}));
|
|
76
|
+
const item = [
|
|
77
|
+
normalized(change.before),
|
|
78
|
+
normalized(change.after),
|
|
79
|
+
change.fields,
|
|
80
|
+
source,
|
|
81
|
+
];
|
|
82
|
+
if (change.kind !== "modified")
|
|
83
|
+
add(id, "structure", item);
|
|
84
|
+
if (change.fields.some((field) => ["Placement", "Kind"].includes(field)))
|
|
85
|
+
add(id, "structure", item);
|
|
86
|
+
if (change.fields.some((field) => ["Code", "Shared source"].includes(field)))
|
|
87
|
+
add(id, "internal", item);
|
|
88
|
+
if (change.fields.some((field) => ["Contract", "Contract types", "Auth", "Auth source"].includes(field)) ||
|
|
89
|
+
(node.kind === "interface" && change.kind !== "modified")) {
|
|
90
|
+
const boundary = interfaceOf(id);
|
|
91
|
+
if (boundary)
|
|
92
|
+
add(boundary, "interfaces", item);
|
|
93
|
+
else
|
|
94
|
+
add(id, "internal", item);
|
|
95
|
+
}
|
|
96
|
+
if (change.fields.some((field) => ![
|
|
97
|
+
"Code",
|
|
98
|
+
"Shared source",
|
|
99
|
+
"Contract",
|
|
100
|
+
"Contract types",
|
|
101
|
+
"Auth",
|
|
102
|
+
"Auth source",
|
|
103
|
+
"Placement",
|
|
104
|
+
"Kind",
|
|
105
|
+
].includes(field)))
|
|
106
|
+
add(id, "metadata", item);
|
|
107
|
+
}
|
|
108
|
+
for (const [id, change] of Object.entries(exact.connections)) {
|
|
109
|
+
const edge = change.after || change.before;
|
|
110
|
+
// The wire itself owns one change; both endpoint containers can summarize it.
|
|
111
|
+
for (const endpoint of new Set([edge.source, edge.target]))
|
|
112
|
+
add(endpoint, "structure", [id, normalized(change)]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const unmapped = [];
|
|
116
|
+
if (footprint?.concepts) {
|
|
117
|
+
for (const change of footprint.concepts.changes) {
|
|
118
|
+
add(change.block, {
|
|
119
|
+
implementation: "internal",
|
|
120
|
+
interface: "interfaces",
|
|
121
|
+
connection: "structure",
|
|
122
|
+
mapping: "source",
|
|
123
|
+
support: "metadata",
|
|
124
|
+
}[change.kind], change);
|
|
125
|
+
files[change.block] = [
|
|
126
|
+
...new Set([...(files[change.block] || []), change.file]),
|
|
127
|
+
];
|
|
128
|
+
if (change.connection)
|
|
129
|
+
add(change.connection.target, "structure", change);
|
|
130
|
+
}
|
|
131
|
+
unmapped.push(...footprint.concepts.unassigned);
|
|
132
|
+
}
|
|
133
|
+
else if (footprint) {
|
|
134
|
+
const associations = new Map();
|
|
135
|
+
const associate = (file, id) => {
|
|
136
|
+
const ids = associations.get(file) || new Set();
|
|
137
|
+
ids.add(id);
|
|
138
|
+
associations.set(file, ids);
|
|
139
|
+
};
|
|
140
|
+
for (const node of graph.elements) {
|
|
141
|
+
for (const ref of node.sources || (node.source ? [node.source] : []))
|
|
142
|
+
associate(ref.file, node.id);
|
|
143
|
+
for (const file of node.attachments?.docs || [])
|
|
144
|
+
associate(file.split("#")[0], node.id);
|
|
145
|
+
if (node.attachments?.auth?.source)
|
|
146
|
+
associate(node.attachments.auth.source.file, node.id);
|
|
147
|
+
}
|
|
148
|
+
for (const test of graph.tests)
|
|
149
|
+
for (const target of test.targets)
|
|
150
|
+
associate(test.source.file, target);
|
|
151
|
+
for (const edge of graph.connections)
|
|
152
|
+
for (const ref of edge.sources ||
|
|
153
|
+
(edge.sourceRef ? [edge.sourceRef] : []))
|
|
154
|
+
associate(ref.file, edge.source);
|
|
155
|
+
for (const file of footprint.files) {
|
|
156
|
+
const matches = [...(associations.get(file.path) || [])];
|
|
157
|
+
if (!matches.length) {
|
|
158
|
+
unmapped.push(file.path);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// File association is conservative and may include several logical siblings.
|
|
162
|
+
const leaves = matches.filter((id) => !matches.some((other) => other !== id && within(other, id)));
|
|
163
|
+
for (const id of leaves) {
|
|
164
|
+
add(id, "source", [file, file.digest ? undefined : footprint.head]);
|
|
165
|
+
files[id] = [...(files[id] || []), file.path];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const seeds = Object.keys(direct).filter((id) => direct[id].includes("interfaces") ||
|
|
170
|
+
(footprint && !footprint.concepts && direct[id].includes("source")));
|
|
171
|
+
const links = graph.connections.flatMap((edge) => {
|
|
172
|
+
const [provider, consumer] = [
|
|
173
|
+
"flows",
|
|
174
|
+
"writes",
|
|
175
|
+
"produces",
|
|
176
|
+
"resumes",
|
|
177
|
+
].includes(edge.relation)
|
|
178
|
+
? [edge.source, edge.target]
|
|
179
|
+
: [edge.target, edge.source];
|
|
180
|
+
return [
|
|
181
|
+
{ provider, consumer, edge },
|
|
182
|
+
...(edge.bidirectional
|
|
183
|
+
? [{ provider: consumer, consumer: provider, edge }]
|
|
184
|
+
: []),
|
|
185
|
+
];
|
|
186
|
+
});
|
|
187
|
+
const consumers = [], connections = new Set();
|
|
188
|
+
const reached = new Set(seeds);
|
|
189
|
+
let frontier = seeds;
|
|
190
|
+
for (let distance = 1; frontier.length && distance <= graph.elements.length; distance++) {
|
|
191
|
+
const next = [];
|
|
192
|
+
for (const link of links) {
|
|
193
|
+
const provider = frontier.find((id) => within(link.provider, id));
|
|
194
|
+
if (!provider ||
|
|
195
|
+
within(link.consumer, provider) ||
|
|
196
|
+
reached.has(link.consumer))
|
|
197
|
+
continue;
|
|
198
|
+
connections.add(link.edge.id);
|
|
199
|
+
consumers.push({
|
|
200
|
+
id: link.consumer,
|
|
201
|
+
provider,
|
|
202
|
+
via: link.edge.id,
|
|
203
|
+
distance,
|
|
204
|
+
evidence: connectionEvidence(link.edge),
|
|
205
|
+
});
|
|
206
|
+
reached.add(link.consumer);
|
|
207
|
+
next.push(link.consumer);
|
|
208
|
+
}
|
|
209
|
+
if (!indirect)
|
|
210
|
+
break;
|
|
211
|
+
frontier = next;
|
|
212
|
+
}
|
|
213
|
+
const marks = {}, items = new Map();
|
|
214
|
+
const sourceFiles = new Map();
|
|
215
|
+
for (const [id, facets] of Object.entries(direct)) {
|
|
216
|
+
const parents = new Set(ancestors(id));
|
|
217
|
+
// Moves also light the old container; a review must not hide what left it.
|
|
218
|
+
let oldParent = exact?.elements[id]?.before?.parent;
|
|
219
|
+
const seen = new Set();
|
|
220
|
+
while (oldParent && byId.has(oldParent) && !seen.has(oldParent)) {
|
|
221
|
+
seen.add(oldParent);
|
|
222
|
+
parents.add(oldParent);
|
|
223
|
+
oldParent =
|
|
224
|
+
exact?.elements[oldParent]?.before?.parent ||
|
|
225
|
+
byId.get(oldParent)?.parent;
|
|
226
|
+
}
|
|
227
|
+
for (const parent of parents) {
|
|
228
|
+
const mark = (marks[parent] ||= empty());
|
|
229
|
+
for (const facet of facets)
|
|
230
|
+
mark[facet]++;
|
|
231
|
+
if (facets.includes("source")) {
|
|
232
|
+
const paths = sourceFiles.get(parent) || new Set();
|
|
233
|
+
for (const file of files[id] || [])
|
|
234
|
+
paths.add(file);
|
|
235
|
+
sourceFiles.set(parent, paths);
|
|
236
|
+
mark.source = paths.size;
|
|
237
|
+
}
|
|
238
|
+
items.set(parent, [
|
|
239
|
+
...(items.get(parent) || []),
|
|
240
|
+
[id, facets, evidence.get(id)],
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
for (const reason of consumers)
|
|
245
|
+
for (const parent of ancestors(reason.id)) {
|
|
246
|
+
(marks[parent] ||= empty()).consumers++;
|
|
247
|
+
items.set(parent, [...(items.get(parent) || []), reason]);
|
|
248
|
+
}
|
|
249
|
+
const fingerprints = Object.fromEntries([...items].map(([id, values]) => [id, fingerprint(values)]));
|
|
250
|
+
return {
|
|
251
|
+
graph,
|
|
252
|
+
key: `${graph.id}:${exact?.before.commit || footprint.base}`,
|
|
253
|
+
basis: exact
|
|
254
|
+
? "snapshots"
|
|
255
|
+
: footprint?.concepts
|
|
256
|
+
? "working-code"
|
|
257
|
+
: footprint?.mappingRevision
|
|
258
|
+
? "head-source"
|
|
259
|
+
: "current-map",
|
|
260
|
+
direct,
|
|
261
|
+
marks,
|
|
262
|
+
consumers,
|
|
263
|
+
connectionIds: [...connections],
|
|
264
|
+
fingerprints,
|
|
265
|
+
files,
|
|
266
|
+
unmapped,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/** A parent review is valid only while all of its scoped evidence is unchanged. */
|
|
270
|
+
export function reviewedScope(review, saved, id) {
|
|
271
|
+
const { within } = graphIndex(review.graph);
|
|
272
|
+
return Object.keys(saved).some((parent) => within(id, parent) && saved[parent] === review.fingerprints[parent]);
|
|
273
|
+
}
|
|
274
|
+
export function reviewUnits(review) {
|
|
275
|
+
const { byId } = graphIndex(review.graph);
|
|
276
|
+
const units = new Set();
|
|
277
|
+
for (const id of new Set([
|
|
278
|
+
...Object.keys(review.direct),
|
|
279
|
+
...review.consumers.map((reason) => reason.id),
|
|
280
|
+
])) {
|
|
281
|
+
let node = byId.get(id);
|
|
282
|
+
while (node && !["block", "process"].includes(node.kind))
|
|
283
|
+
node = byId.get(node.parent || "");
|
|
284
|
+
if (node)
|
|
285
|
+
units.add(node.id);
|
|
286
|
+
}
|
|
287
|
+
// Ancestor-owned edits are not covered by reviewing only a descendant.
|
|
288
|
+
return [...units];
|
|
289
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
import type { TimeWindow } from "./time-window.js";
|
|
3
|
+
import type { RuntimeMetrics } from "./performance-model.js";
|
|
4
|
+
export interface MetricsConnection {
|
|
5
|
+
url?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
username?: string;
|
|
8
|
+
environment?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function metricsConnection(env?: NodeJS.ProcessEnv): MetricsConnection;
|
|
11
|
+
type PromSeries = {
|
|
12
|
+
metric: Record<string, string>;
|
|
13
|
+
value?: [number, string];
|
|
14
|
+
values?: [number, string][];
|
|
15
|
+
};
|
|
16
|
+
export declare class PrometheusReader {
|
|
17
|
+
private configuration;
|
|
18
|
+
private transport;
|
|
19
|
+
constructor(configuration: MetricsConnection, transport?: typeof fetch);
|
|
20
|
+
query(query: string, at: string, range?: {
|
|
21
|
+
from: string;
|
|
22
|
+
step: number;
|
|
23
|
+
}): Promise<PromSeries[]>;
|
|
24
|
+
}
|
|
25
|
+
export declare function readRuntimeMetrics(root: string, graph: DefinitionGraph, window: TimeWindow, connection?: MetricsConnection, transport?: typeof fetch): Promise<RuntimeMetrics>;
|
|
26
|
+
export {};
|