@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,124 @@
|
|
|
1
|
+
import { issueReference } from "./work-items.js";
|
|
2
|
+
export function normalizeLinearIssue(raw, checkedAt = new Date().toISOString()) {
|
|
3
|
+
const id = raw.uuid || raw.id, identifier = raw.identifier || raw.id;
|
|
4
|
+
if (!/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(id || "") ||
|
|
5
|
+
!/^[A-Z][A-Z0-9]{0,15}-[1-9][0-9]{0,9}$/.test(identifier || "") ||
|
|
6
|
+
typeof raw.title !== "string" ||
|
|
7
|
+
raw.title.length > 1000)
|
|
8
|
+
throw Error("Invalid Linear issue metadata");
|
|
9
|
+
const url = issueReference(raw.url);
|
|
10
|
+
if (url.key !== identifier)
|
|
11
|
+
throw Error("Linear issue URL does not match its identifier");
|
|
12
|
+
const state = raw.state || { name: raw.status, type: raw.statusType };
|
|
13
|
+
if (typeof state?.name !== "string" ||
|
|
14
|
+
typeof state?.type !== "string" ||
|
|
15
|
+
!Number.isFinite(Date.parse(raw.updatedAt)) ||
|
|
16
|
+
!Number.isFinite(Date.parse(checkedAt)))
|
|
17
|
+
throw Error("Issue status or timestamps unavailable");
|
|
18
|
+
return {
|
|
19
|
+
id,
|
|
20
|
+
identifier,
|
|
21
|
+
title: raw.title,
|
|
22
|
+
url: url.url,
|
|
23
|
+
state: { name: state.name.slice(0, 100), type: state.type.slice(0, 40) },
|
|
24
|
+
updatedAt: raw.updatedAt,
|
|
25
|
+
checkedAt,
|
|
26
|
+
...(raw.archivedAt ? { archivedAt: raw.archivedAt } : {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export class LinearIssuesReader {
|
|
30
|
+
token;
|
|
31
|
+
workspaceId;
|
|
32
|
+
fetcher;
|
|
33
|
+
constructor(token, workspaceId, fetcher = fetch) {
|
|
34
|
+
this.token = token;
|
|
35
|
+
this.workspaceId = workspaceId;
|
|
36
|
+
this.fetcher = fetcher;
|
|
37
|
+
}
|
|
38
|
+
/** Explicit, bounded title search. Never used to assign ownership automatically. */
|
|
39
|
+
async search(query) {
|
|
40
|
+
const term = query.trim();
|
|
41
|
+
if (term.length < 3 || term.length > 120)
|
|
42
|
+
throw Error("Search with 3–120 characters");
|
|
43
|
+
const response = await this.fetcher("https://api.linear.app/graphql", {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"content-type": "application/json",
|
|
47
|
+
Authorization: this.token,
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
query: `query FractalIssueSearch($term: String!) {
|
|
51
|
+
organization { id }
|
|
52
|
+
issues(first: 20, filter: { title: { containsIgnoreCase: $term } }) {
|
|
53
|
+
nodes { id identifier title url updatedAt archivedAt state { name type } }
|
|
54
|
+
pageInfo { hasNextPage }
|
|
55
|
+
}
|
|
56
|
+
}`,
|
|
57
|
+
variables: { term },
|
|
58
|
+
}),
|
|
59
|
+
signal: AbortSignal.timeout(10000),
|
|
60
|
+
});
|
|
61
|
+
if (response.status === 429)
|
|
62
|
+
throw Error("Linear rate limit reached; retry later");
|
|
63
|
+
if (!response.ok)
|
|
64
|
+
throw Error("Linear search failed (" + response.status + ")");
|
|
65
|
+
const body = await response.json();
|
|
66
|
+
if (body.errors?.length ||
|
|
67
|
+
!Array.isArray(body.data?.issues?.nodes) ||
|
|
68
|
+
!body.data?.organization?.id)
|
|
69
|
+
throw Error("Linear returned incomplete search results");
|
|
70
|
+
if (this.workspaceId && body.data.organization.id !== this.workspaceId)
|
|
71
|
+
throw Error("Linear credential belongs to a different workspace");
|
|
72
|
+
const checkedAt = new Date().toISOString();
|
|
73
|
+
return {
|
|
74
|
+
issues: body.data.issues.nodes.map((issue) => normalizeLinearIssue(issue, checkedAt)),
|
|
75
|
+
more: !!body.data.issues.pageInfo?.hasNextPage,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async issues(references) {
|
|
79
|
+
return (await this.issueResults(references)).issues;
|
|
80
|
+
}
|
|
81
|
+
/** Refresh every permitted registry link; unavailable issues are explicit, not old successes. */
|
|
82
|
+
async issueResults(references) {
|
|
83
|
+
const keys = [...new Set(references.map((ref) => issueReference(ref).key))];
|
|
84
|
+
if (keys.length > 500)
|
|
85
|
+
throw Error("Refresh up to 500 linked issues at a time");
|
|
86
|
+
const result = [];
|
|
87
|
+
const unavailable = [];
|
|
88
|
+
for (let start = 0; start < keys.length; start += 25) {
|
|
89
|
+
const refs = keys.slice(start, start + 25), definitions = refs.map((_, i) => `$id${i}: String!`).join(","), queries = refs
|
|
90
|
+
.map((_, i) => `i${i}: issue(id:$id${i}) { id identifier title url updatedAt archivedAt state { name type } }`)
|
|
91
|
+
.join("\n");
|
|
92
|
+
const checkedAt = new Date().toISOString();
|
|
93
|
+
const response = await this.fetcher("https://api.linear.app/graphql", {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: {
|
|
96
|
+
"content-type": "application/json",
|
|
97
|
+
Authorization: this.token,
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
query: `query FractalIssues(${definitions}) { organization { id } ${queries} }`,
|
|
101
|
+
variables: Object.fromEntries(refs.map((ref, i) => ["id" + i, ref])),
|
|
102
|
+
}),
|
|
103
|
+
signal: AbortSignal.timeout(10000),
|
|
104
|
+
});
|
|
105
|
+
if (response.status === 429)
|
|
106
|
+
throw Error("Linear rate limit reached; recorded status remains available");
|
|
107
|
+
if (!response.ok)
|
|
108
|
+
throw Error("Linear status refresh failed (" + response.status + ")");
|
|
109
|
+
const body = await response.json();
|
|
110
|
+
if (!body.data?.organization?.id ||
|
|
111
|
+
body.errors?.some((error) => !/^i\d+$/.test(String(error.path?.[0] || ""))))
|
|
112
|
+
throw Error("Linear returned incomplete issue data; recorded status remains available");
|
|
113
|
+
if (this.workspaceId && body.data.organization.id !== this.workspaceId)
|
|
114
|
+
throw Error("Linear credential belongs to a different workspace");
|
|
115
|
+
for (let i = 0; i < refs.length; i++)
|
|
116
|
+
if (body.data["i" + i] &&
|
|
117
|
+
!body.errors?.some((error) => error.path?.[0] === "i" + i))
|
|
118
|
+
result.push(normalizeLinearIssue(body.data["i" + i], checkedAt));
|
|
119
|
+
else
|
|
120
|
+
unavailable.push(refs[i]);
|
|
121
|
+
}
|
|
122
|
+
return { issues: result, unavailable };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A desktop backend is a local workspace even when its UI is production-built.
|
|
2
|
+
* This is a capability flag, not authentication: every desktop request must also
|
|
3
|
+
* present the per-launch session and exact loopback host. */
|
|
4
|
+
export declare function desktopRuntime(env?: Record<string, string | undefined>): boolean;
|
|
5
|
+
export declare function localRepositoryRuntime(env?: Record<string, string | undefined>): boolean;
|
|
6
|
+
export declare function desktopRequestAllowed(headers: Pick<Headers, "get">, env?: Record<string, string | undefined>): boolean;
|
|
7
|
+
/** Explicit loopback-only web development; packaged builds always require their session. */
|
|
8
|
+
export declare function developmentRequestAllowed(headers: Pick<Headers, "get">, env?: Record<string, string | undefined>): boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** A desktop backend is a local workspace even when its UI is production-built.
|
|
2
|
+
* This is a capability flag, not authentication: every desktop request must also
|
|
3
|
+
* present the per-launch session and exact loopback host. */
|
|
4
|
+
export function desktopRuntime(env = process.env) {
|
|
5
|
+
if (env.FRACTORY_DESKTOP !== "1" ||
|
|
6
|
+
!/^[a-f0-9]{64}$/.test(env.FRACTORY_DESKTOP_TOKEN || ""))
|
|
7
|
+
return false;
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(env.FRACTORY_DESKTOP_ORIGIN || "");
|
|
10
|
+
return (url.protocol === "http:" &&
|
|
11
|
+
url.hostname === "127.0.0.1" &&
|
|
12
|
+
!!url.port &&
|
|
13
|
+
url.origin === env.FRACTORY_DESKTOP_ORIGIN);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function localRepositoryRuntime(env = process.env) {
|
|
20
|
+
return env.NODE_ENV !== "production" || desktopRuntime(env);
|
|
21
|
+
}
|
|
22
|
+
export function desktopRequestAllowed(headers, env = process.env) {
|
|
23
|
+
if (!desktopRuntime(env))
|
|
24
|
+
return false;
|
|
25
|
+
const expected = new URL(env.FRACTORY_DESKTOP_ORIGIN);
|
|
26
|
+
if (headers.get("host") !== expected.host)
|
|
27
|
+
return false;
|
|
28
|
+
const origin = headers.get("origin");
|
|
29
|
+
if (origin && origin !== expected.origin)
|
|
30
|
+
return false;
|
|
31
|
+
const cookie = (headers.get("cookie") || "")
|
|
32
|
+
.split(";")
|
|
33
|
+
.map((part) => part.trim())
|
|
34
|
+
.find((part) => part.startsWith("fractory-session="))
|
|
35
|
+
?.slice("fractory-session=".length);
|
|
36
|
+
const token = env.FRACTORY_DESKTOP_TOKEN;
|
|
37
|
+
if (!cookie || cookie.length !== token.length)
|
|
38
|
+
return false;
|
|
39
|
+
let difference = 0;
|
|
40
|
+
for (let index = 0; index < token.length; index++)
|
|
41
|
+
difference |= token.charCodeAt(index) ^ cookie.charCodeAt(index);
|
|
42
|
+
return difference === 0;
|
|
43
|
+
}
|
|
44
|
+
/** Explicit loopback-only web development; packaged builds always require their session. */
|
|
45
|
+
export function developmentRequestAllowed(headers, env = process.env) {
|
|
46
|
+
if (env.NODE_ENV !== "development" || env.FRACTORY_WEB_DEV !== "1")
|
|
47
|
+
return false;
|
|
48
|
+
try {
|
|
49
|
+
const expected = new URL(env.FRACTORY_DEV_ORIGIN || "");
|
|
50
|
+
return (expected.protocol === "http:" &&
|
|
51
|
+
expected.hostname === "127.0.0.1" &&
|
|
52
|
+
!!expected.port &&
|
|
53
|
+
headers.get("host") === expected.host &&
|
|
54
|
+
(!headers.get("origin") || headers.get("origin") === expected.origin));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
import type { WorkingOverview } from "./working-code.js";
|
|
3
|
+
import type { WorkView } from "./work-items.js";
|
|
4
|
+
import { type TimeWindow } from "./time-window.js";
|
|
5
|
+
export type ActivityKind = "worktrees" | "history" | "sentry" | "linear" | "metrics" | "benchmarks";
|
|
6
|
+
export interface ActivityCell {
|
|
7
|
+
tone?: "regression" | "improvement" | "neutral";
|
|
8
|
+
displayValue?: string;
|
|
9
|
+
recent?: boolean;
|
|
10
|
+
count: number;
|
|
11
|
+
intensity: number;
|
|
12
|
+
label: string;
|
|
13
|
+
summary: string;
|
|
14
|
+
segments?: {
|
|
15
|
+
label: string;
|
|
16
|
+
count: number;
|
|
17
|
+
tone: string;
|
|
18
|
+
}[];
|
|
19
|
+
series?: number[];
|
|
20
|
+
measurements?: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: string;
|
|
23
|
+
series: number[];
|
|
24
|
+
tone?: "regression" | "improvement" | "neutral";
|
|
25
|
+
}[];
|
|
26
|
+
related?: boolean;
|
|
27
|
+
lineChange?: {
|
|
28
|
+
added: number;
|
|
29
|
+
deleted: number;
|
|
30
|
+
partial: boolean;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface HistorySample {
|
|
34
|
+
source?: import("./history-source.js").HistorySource;
|
|
35
|
+
latestAt?: string;
|
|
36
|
+
churn?: import("./history-churn.js").HistoryChurn;
|
|
37
|
+
ledger?: import("./history-ledger.js").HistoryLedger;
|
|
38
|
+
checkedAt: string;
|
|
39
|
+
windowEnd?: string;
|
|
40
|
+
windowStart?: string;
|
|
41
|
+
days: number;
|
|
42
|
+
partial: boolean;
|
|
43
|
+
commits: {
|
|
44
|
+
commit: string;
|
|
45
|
+
at: string;
|
|
46
|
+
subject: string;
|
|
47
|
+
files: string[];
|
|
48
|
+
changes?: {
|
|
49
|
+
path: string;
|
|
50
|
+
added: number;
|
|
51
|
+
deleted: number;
|
|
52
|
+
binary: boolean;
|
|
53
|
+
}[];
|
|
54
|
+
}[];
|
|
55
|
+
}
|
|
56
|
+
/** File associations, not line-level ownership. Shared files can relate to several blocks. */
|
|
57
|
+
export declare function fileBlocks(graph: DefinitionGraph, path: string): Set<string>;
|
|
58
|
+
export declare function workingCells(graph: DefinitionGraph, overview: WorkingOverview): {
|
|
59
|
+
revision: string;
|
|
60
|
+
cells: Record<string, import("./map-activity.js").ActivityCell>;
|
|
61
|
+
unmapped: number;
|
|
62
|
+
} | {
|
|
63
|
+
cells: Record<string, ActivityCell>;
|
|
64
|
+
unmapped: number;
|
|
65
|
+
};
|
|
66
|
+
export declare function historyCells(graph: DefinitionGraph, sample: HistorySample): {
|
|
67
|
+
cells: Record<string, ActivityCell>;
|
|
68
|
+
unmapped: number;
|
|
69
|
+
};
|
|
70
|
+
export declare function linearCells(graph: DefinitionGraph, view: WorkView, window?: TimeWindow): {
|
|
71
|
+
cells: Record<string, ActivityCell>;
|
|
72
|
+
unmapped: number;
|
|
73
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { inTimeWindow } from "./time-window.js";
|
|
2
|
+
const indexes = new WeakMap();
|
|
3
|
+
/** File associations, not line-level ownership. Shared files can relate to several blocks. */
|
|
4
|
+
export function fileBlocks(graph, path) {
|
|
5
|
+
let index = indexes.get(graph);
|
|
6
|
+
if (!index || index.revision !== graph.revision) {
|
|
7
|
+
const files = new Map();
|
|
8
|
+
for (const node of graph.elements) {
|
|
9
|
+
for (const source of node.sources || (node.source ? [node.source] : []))
|
|
10
|
+
files.set(source.file, [...(files.get(source.file) || []), node.id]);
|
|
11
|
+
for (const file of [
|
|
12
|
+
...(node.attachments?.benchmarks || []),
|
|
13
|
+
...(node.attachments?.docs || []),
|
|
14
|
+
...(node.attachments?.tests || []),
|
|
15
|
+
])
|
|
16
|
+
files.set(file, [...(files.get(file) || []), node.id]);
|
|
17
|
+
}
|
|
18
|
+
for (const test of graph.tests || [])
|
|
19
|
+
files.set(test.source.file, [
|
|
20
|
+
...(files.get(test.source.file) || []),
|
|
21
|
+
...test.targets.map((id) => graph.aliases?.[id] || id),
|
|
22
|
+
]);
|
|
23
|
+
index = {
|
|
24
|
+
revision: graph.revision,
|
|
25
|
+
byId: new Map(graph.elements.map((node) => [node.id, node])),
|
|
26
|
+
files,
|
|
27
|
+
};
|
|
28
|
+
indexes.set(graph, index);
|
|
29
|
+
}
|
|
30
|
+
const { byId, files } = index;
|
|
31
|
+
const owners = new Set();
|
|
32
|
+
const ids = path.endsWith("/")
|
|
33
|
+
? [...files]
|
|
34
|
+
.filter(([file]) => file.startsWith(path))
|
|
35
|
+
.flatMap(([, ids]) => ids)
|
|
36
|
+
: files.get(path) || [];
|
|
37
|
+
for (const id of ids) {
|
|
38
|
+
let current = byId.get(graph.aliases?.[id] || id);
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
while (current && !seen.has(current.id)) {
|
|
41
|
+
seen.add(current.id);
|
|
42
|
+
owners.add(current.id);
|
|
43
|
+
current = byId.get(current.parent);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return owners;
|
|
47
|
+
}
|
|
48
|
+
function normalize(graph, cells) {
|
|
49
|
+
const max = Math.max(1, ...Object.entries(cells)
|
|
50
|
+
.filter(([id]) => id !== graph.id)
|
|
51
|
+
.map(([, cell]) => cell.count));
|
|
52
|
+
for (const cell of Object.values(cells))
|
|
53
|
+
cell.intensity = Math.min(1, cell.count / max);
|
|
54
|
+
return cells;
|
|
55
|
+
}
|
|
56
|
+
export function workingCells(graph, overview) {
|
|
57
|
+
if (overview.mapping?.revision === graph.revision && overview.mapping)
|
|
58
|
+
return overview.mapping;
|
|
59
|
+
const cells = {};
|
|
60
|
+
let unmapped = 0;
|
|
61
|
+
for (const path of overview.paths) {
|
|
62
|
+
const owners = fileBlocks(graph, path.path);
|
|
63
|
+
if (!owners.size)
|
|
64
|
+
unmapped++;
|
|
65
|
+
for (const id of owners) {
|
|
66
|
+
const cell = (cells[id] ||= {
|
|
67
|
+
count: 0,
|
|
68
|
+
intensity: 0,
|
|
69
|
+
label: "changed paths",
|
|
70
|
+
summary: "",
|
|
71
|
+
segments: [
|
|
72
|
+
{ label: "Staged", count: 0, tone: "staged" },
|
|
73
|
+
{ label: "Unstaged", count: 0, tone: "unstaged" },
|
|
74
|
+
{ label: "Untracked", count: 0, tone: "untracked" },
|
|
75
|
+
{ label: "Conflicts", count: 0, tone: "conflict" },
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
cell.count++;
|
|
79
|
+
const age = path.modifiedAt
|
|
80
|
+
? Date.parse(overview.checkedAt) - Date.parse(path.modifiedAt)
|
|
81
|
+
: Infinity;
|
|
82
|
+
// A folder's mtime describes directory entries, not edits to its files.
|
|
83
|
+
if (path.kind !== "directory" && age >= 0 && age < 30_000)
|
|
84
|
+
cell.recent = true;
|
|
85
|
+
if (path.conflict)
|
|
86
|
+
cell.segments[3].count++;
|
|
87
|
+
else if (path.untracked)
|
|
88
|
+
cell.segments[2].count++;
|
|
89
|
+
else {
|
|
90
|
+
if (path.index !== ".")
|
|
91
|
+
cell.segments[0].count++;
|
|
92
|
+
if (path.working !== ".")
|
|
93
|
+
cell.segments[1].count++;
|
|
94
|
+
}
|
|
95
|
+
cell.summary = cell
|
|
96
|
+
.segments.filter((s) => s.count)
|
|
97
|
+
.map((s) => `${s.count} ${s.label.toLowerCase()}`)
|
|
98
|
+
.join(" · ");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
102
|
+
}
|
|
103
|
+
export function historyCells(graph, sample) {
|
|
104
|
+
const cells = {};
|
|
105
|
+
if (sample.ledger) {
|
|
106
|
+
for (const [id, value] of Object.entries(sample.ledger.blocks)) {
|
|
107
|
+
const changed = value.added + value.deleted;
|
|
108
|
+
if (!changed)
|
|
109
|
+
continue;
|
|
110
|
+
cells[id] = {
|
|
111
|
+
count: changed,
|
|
112
|
+
intensity: 0,
|
|
113
|
+
displayValue: new Intl.NumberFormat("en", {
|
|
114
|
+
notation: "compact",
|
|
115
|
+
maximumFractionDigits: 1,
|
|
116
|
+
}).format(changed),
|
|
117
|
+
label: sample.ledger.mode === "activity" ? "line edits" : "line difference",
|
|
118
|
+
lineChange: {
|
|
119
|
+
added: value.added,
|
|
120
|
+
deleted: value.deleted,
|
|
121
|
+
partial: value.associated > 0,
|
|
122
|
+
},
|
|
123
|
+
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.`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
cells: normalize(graph, cells),
|
|
128
|
+
unmapped: sample.ledger.buckets.unassigned.added +
|
|
129
|
+
sample.ledger.buckets.unassigned.deleted,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (sample.churn && !sample.churn.error) {
|
|
133
|
+
for (const [id, value] of Object.entries(sample.churn.blocks)) {
|
|
134
|
+
const changed = value.added + value.deleted;
|
|
135
|
+
if (!changed)
|
|
136
|
+
continue;
|
|
137
|
+
const percent = value.percent == null ? null : Math.round(value.percent * 10) / 10;
|
|
138
|
+
cells[id] = {
|
|
139
|
+
count: percent || 0,
|
|
140
|
+
intensity: 0,
|
|
141
|
+
displayValue: percent == null
|
|
142
|
+
? `${changed}`
|
|
143
|
+
: value.percent > 0 && percent === 0
|
|
144
|
+
? "<0.1%"
|
|
145
|
+
: `${percent}%`,
|
|
146
|
+
label: percent == null ? "line changes" : "churn",
|
|
147
|
+
lineChange: {
|
|
148
|
+
added: value.added,
|
|
149
|
+
deleted: value.deleted,
|
|
150
|
+
partial: value.partial,
|
|
151
|
+
},
|
|
152
|
+
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." : ""}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
cells: normalize(graph, cells),
|
|
157
|
+
unmapped: sample.churn.unmappedLines,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const end = Date.parse(sample.windowEnd || sample.checkedAt), start = sample.windowStart
|
|
161
|
+
? Date.parse(sample.windowStart)
|
|
162
|
+
: end - sample.days * 86400000, span = Math.max(1000, end - start);
|
|
163
|
+
let unmapped = 0;
|
|
164
|
+
for (const commit of sample.commits) {
|
|
165
|
+
const owners = new Set(commit.files.flatMap((file) => [...fileBlocks(graph, file)]));
|
|
166
|
+
if (!owners.size)
|
|
167
|
+
unmapped++;
|
|
168
|
+
const bucket = Math.max(0, Math.min(13, Math.floor(((Date.parse(commit.at) - start) / span) * 14)));
|
|
169
|
+
for (const id of owners) {
|
|
170
|
+
const cell = (cells[id] ||= {
|
|
171
|
+
count: 0,
|
|
172
|
+
intensity: 0,
|
|
173
|
+
label: "commits",
|
|
174
|
+
summary: `${sample.days ? `Last ${sample.days} days` : "Latest commits"} · file associations`,
|
|
175
|
+
series: Array(14).fill(0),
|
|
176
|
+
});
|
|
177
|
+
cell.count++;
|
|
178
|
+
cell.series[bucket]++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
182
|
+
}
|
|
183
|
+
export function linearCells(graph, view, window) {
|
|
184
|
+
const cells = {};
|
|
185
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
186
|
+
let unmapped = 0;
|
|
187
|
+
for (const item of view.items) {
|
|
188
|
+
if (window && !inTimeWindow(item.metadata?.updatedAt, window))
|
|
189
|
+
continue;
|
|
190
|
+
const owners = new Set();
|
|
191
|
+
for (const block of item.blocks) {
|
|
192
|
+
let current = byId.get(graph.aliases?.[block] || block);
|
|
193
|
+
const seen = new Set();
|
|
194
|
+
while (current && !seen.has(current.id)) {
|
|
195
|
+
seen.add(current.id);
|
|
196
|
+
owners.add(current.id);
|
|
197
|
+
current = byId.get(current.parent);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (!owners.size && !["done", "canceled", "archived"].includes(item.state))
|
|
201
|
+
unmapped++;
|
|
202
|
+
if (item.state === "canceled" || item.state === "archived")
|
|
203
|
+
continue;
|
|
204
|
+
for (const id of owners) {
|
|
205
|
+
const cell = (cells[id] ||= {
|
|
206
|
+
count: 0,
|
|
207
|
+
intensity: 0,
|
|
208
|
+
label: "open issues",
|
|
209
|
+
summary: "",
|
|
210
|
+
segments: [
|
|
211
|
+
{ label: "Planned", count: 0, tone: "todo" },
|
|
212
|
+
{ label: "Active", count: 0, tone: "active" },
|
|
213
|
+
{ label: "Done", count: 0, tone: "done" },
|
|
214
|
+
{ label: "Unknown", count: 0, tone: "unknown" },
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
if (item.state === "todo" || item.state === "in_progress")
|
|
218
|
+
cell.count++;
|
|
219
|
+
const position = item.state === "todo"
|
|
220
|
+
? 0
|
|
221
|
+
: item.state === "in_progress"
|
|
222
|
+
? 1
|
|
223
|
+
: item.state === "done"
|
|
224
|
+
? 2
|
|
225
|
+
: 3;
|
|
226
|
+
cell.segments[position].count++;
|
|
227
|
+
cell.summary = cell
|
|
228
|
+
.segments.filter((s) => s.count)
|
|
229
|
+
.map((s) => `${s.count} ${s.label.toLowerCase()}`)
|
|
230
|
+
.join(" · ");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { cells: normalize(graph, cells), unmapped };
|
|
234
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DefinitionGraph, ResourceAttachment } from "./model.js";
|
|
2
|
+
/** A view projection, not a new source revision. Runtime identities and contracts stay unchanged. */
|
|
3
|
+
export declare function logicalMap(definition: DefinitionGraph): DefinitionGraph;
|
|
4
|
+
/** Collapsed black boxes retain the unique dependencies of their contents. */
|
|
5
|
+
export declare function blockResources(graph: DefinitionGraph, id: string): ResourceAttachment[];
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
const kinds = {
|
|
2
|
+
factory: "block",
|
|
3
|
+
system: "block",
|
|
4
|
+
deployment: "block",
|
|
5
|
+
operation: "method",
|
|
6
|
+
block: "block",
|
|
7
|
+
interface: "interface",
|
|
8
|
+
method: "method",
|
|
9
|
+
process: "process",
|
|
10
|
+
resource: "block",
|
|
11
|
+
artifact: "block",
|
|
12
|
+
};
|
|
13
|
+
/** A view projection, not a new source revision. Runtime identities and contracts stay unchanged. */
|
|
14
|
+
export function logicalMap(definition) {
|
|
15
|
+
const graph = structuredClone(definition);
|
|
16
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
17
|
+
const detached = new Set(graph.elements
|
|
18
|
+
.filter((node) => node.kind === "resource" || node.kind === "artifact")
|
|
19
|
+
.map((node) => node.id));
|
|
20
|
+
const owner = (id) => {
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
let node = byId.get(id);
|
|
23
|
+
while (node && !seen.has(node.id)) {
|
|
24
|
+
seen.add(node.id);
|
|
25
|
+
if (!detached.has(node.id) &&
|
|
26
|
+
["block", "process"].includes(kinds[node.kind]))
|
|
27
|
+
return node.id;
|
|
28
|
+
node = byId.get(node.parent || "");
|
|
29
|
+
}
|
|
30
|
+
return graph.id;
|
|
31
|
+
};
|
|
32
|
+
const aliases = { ...graph.aliases };
|
|
33
|
+
for (const id of detached)
|
|
34
|
+
aliases[id] = owner(byId.get(id)?.parent || graph.id);
|
|
35
|
+
const target = (id) => aliases[id] || id;
|
|
36
|
+
for (const node of graph.elements)
|
|
37
|
+
if (node.kind === "resource") {
|
|
38
|
+
const connections = graph.connections.filter((edge) => edge.source === node.id || edge.target === node.id);
|
|
39
|
+
const attachment = {
|
|
40
|
+
id: node.id,
|
|
41
|
+
label: node.label,
|
|
42
|
+
description: node.description,
|
|
43
|
+
source: node.source,
|
|
44
|
+
sources: node.sources,
|
|
45
|
+
provenance: node.provenance,
|
|
46
|
+
connections,
|
|
47
|
+
};
|
|
48
|
+
const owners = new Set([
|
|
49
|
+
aliases[node.id],
|
|
50
|
+
...connections.map((edge) => owner(edge.source === node.id ? edge.target : edge.source)),
|
|
51
|
+
]);
|
|
52
|
+
for (const id of owners) {
|
|
53
|
+
const block = byId.get(id);
|
|
54
|
+
if (block)
|
|
55
|
+
block.resources = [...(block.resources || []), attachment];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const artifacts = new Map(graph.elements
|
|
59
|
+
.filter((node) => node.kind === "artifact")
|
|
60
|
+
.map((node) => [
|
|
61
|
+
node.id,
|
|
62
|
+
{
|
|
63
|
+
id: node.id,
|
|
64
|
+
label: node.label,
|
|
65
|
+
description: node.description,
|
|
66
|
+
source: node.source,
|
|
67
|
+
sources: node.sources,
|
|
68
|
+
provenance: node.provenance,
|
|
69
|
+
},
|
|
70
|
+
]));
|
|
71
|
+
for (const [id, artifact] of artifacts) {
|
|
72
|
+
const block = byId.get(aliases[id]);
|
|
73
|
+
if (block)
|
|
74
|
+
block.outputs = [...(block.outputs || []), artifact];
|
|
75
|
+
}
|
|
76
|
+
const connections = [];
|
|
77
|
+
const outgoing = new Map();
|
|
78
|
+
for (const edge of graph.connections)
|
|
79
|
+
outgoing.set(edge.source, [...(outgoing.get(edge.source) || []), edge]);
|
|
80
|
+
const evidence = (edge) => edge.sources || (edge.sourceRef ? [edge.sourceRef] : []);
|
|
81
|
+
const follow = (first, edge, path, materials, visited) => {
|
|
82
|
+
if (byId.get(edge.target)?.kind === "resource")
|
|
83
|
+
return;
|
|
84
|
+
const material = artifacts.get(edge.target);
|
|
85
|
+
if (material) {
|
|
86
|
+
if (visited.has(material.id))
|
|
87
|
+
return;
|
|
88
|
+
const seen = new Set([...visited, material.id]);
|
|
89
|
+
const next = outgoing.get(material.id) || [];
|
|
90
|
+
for (const transfer of next)
|
|
91
|
+
follow(first, transfer, [...path, transfer], [...materials, material], seen);
|
|
92
|
+
if (!next.length) {
|
|
93
|
+
const block = byId.get(owner(first.source));
|
|
94
|
+
if (block)
|
|
95
|
+
block.outputs = [...(block.outputs || []), material];
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const source = target(first.source), destination = target(edge.target);
|
|
100
|
+
if (source === destination)
|
|
101
|
+
return;
|
|
102
|
+
connections.push({
|
|
103
|
+
...edge,
|
|
104
|
+
source,
|
|
105
|
+
target: destination,
|
|
106
|
+
...(materials.length
|
|
107
|
+
? {
|
|
108
|
+
id: path.map((item) => item.id).join("::"),
|
|
109
|
+
artifacts: [...materials, ...(edge.artifacts || [])],
|
|
110
|
+
sources: path.flatMap(evidence),
|
|
111
|
+
provenance: path.some((item) => item.provenance === "inferred")
|
|
112
|
+
? "inferred"
|
|
113
|
+
: edge.provenance,
|
|
114
|
+
}
|
|
115
|
+
: {}),
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
for (const edge of graph.connections) {
|
|
119
|
+
if (byId.get(edge.source)?.kind === "resource")
|
|
120
|
+
continue;
|
|
121
|
+
const material = artifacts.get(edge.source);
|
|
122
|
+
if (material &&
|
|
123
|
+
graph.connections.some((input) => input.target === edge.source))
|
|
124
|
+
continue;
|
|
125
|
+
follow(edge, edge, [edge], material ? [material] : [], new Set(material ? [material.id] : []));
|
|
126
|
+
}
|
|
127
|
+
graph.elements = graph.elements
|
|
128
|
+
.filter((node) => !detached.has(node.id))
|
|
129
|
+
.map((node) => ({
|
|
130
|
+
...node,
|
|
131
|
+
kind: kinds[node.kind],
|
|
132
|
+
parent: node.parent ? target(node.parent) : undefined,
|
|
133
|
+
hosting: node.hosting || (node.kind === "deployment" ? node.label : undefined),
|
|
134
|
+
resources: node.resources?.filter((resource, i, all) => all.findIndex((item) => item.id === resource.id) === i),
|
|
135
|
+
outputs: node.outputs?.filter((artifact, i, all) => all.findIndex((item) => item.id === artifact.id) === i),
|
|
136
|
+
}));
|
|
137
|
+
graph.connections = connections;
|
|
138
|
+
graph.tests = graph.tests.map((test) => ({
|
|
139
|
+
...test,
|
|
140
|
+
targets: [...new Set(test.targets.map(target))],
|
|
141
|
+
}));
|
|
142
|
+
graph.failures = graph.failures.map((failure) => ({
|
|
143
|
+
...failure,
|
|
144
|
+
operationId: target(failure.operationId),
|
|
145
|
+
}));
|
|
146
|
+
graph.aliases = aliases;
|
|
147
|
+
return graph;
|
|
148
|
+
}
|
|
149
|
+
/** Collapsed black boxes retain the unique dependencies of their contents. */
|
|
150
|
+
export function blockResources(graph, id) {
|
|
151
|
+
const ids = new Set([id]);
|
|
152
|
+
for (let changed = true; changed;) {
|
|
153
|
+
changed = false;
|
|
154
|
+
for (const node of graph.elements)
|
|
155
|
+
if (node.parent && ids.has(node.parent) && !ids.has(node.id)) {
|
|
156
|
+
ids.add(node.id);
|
|
157
|
+
changed = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return [
|
|
161
|
+
...new Map(graph.elements
|
|
162
|
+
.filter((node) => ids.has(node.id))
|
|
163
|
+
.flatMap((node) => node.resources || [])
|
|
164
|
+
.map((resource) => [resource.id, resource])).values(),
|
|
165
|
+
];
|
|
166
|
+
}
|