@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,271 @@
|
|
|
1
|
+
import type { DefinitionGraph, ElementKind, SourceRef } from "./model";
|
|
2
|
+
import { interfaceMap, type PublicEntry } from "./interface-map";
|
|
3
|
+
|
|
4
|
+
export interface CatalogPart {
|
|
5
|
+
/** Explicit reviewed public surface for this existing implementation ID. */
|
|
6
|
+
entryFor?: string;
|
|
7
|
+
/** Stable identity: a local slug, or a qualified ID retained when a part moves. */
|
|
8
|
+
id?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
kind?: string;
|
|
11
|
+
summary: string;
|
|
12
|
+
signature?: string;
|
|
13
|
+
evidence: string[];
|
|
14
|
+
parts?: CatalogPart[];
|
|
15
|
+
resources?: {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
summary?: string;
|
|
19
|
+
evidence: string[];
|
|
20
|
+
}[];
|
|
21
|
+
outputs?: {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
summary?: string;
|
|
25
|
+
evidence: string[];
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ProductMapCatalog {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
date: string;
|
|
33
|
+
basis: string;
|
|
34
|
+
systems: {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
purpose: string;
|
|
38
|
+
hosting: string;
|
|
39
|
+
external: string[];
|
|
40
|
+
parts: CatalogPart[];
|
|
41
|
+
}[];
|
|
42
|
+
connections: {
|
|
43
|
+
id: string;
|
|
44
|
+
source: string;
|
|
45
|
+
target: string;
|
|
46
|
+
label: string;
|
|
47
|
+
transport: string;
|
|
48
|
+
evidence: string[];
|
|
49
|
+
bidirectional: boolean;
|
|
50
|
+
relation?: string;
|
|
51
|
+
condition?: string;
|
|
52
|
+
path?: string;
|
|
53
|
+
backbone?: boolean;
|
|
54
|
+
artifacts?: {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
summary?: string;
|
|
58
|
+
evidence: string[];
|
|
59
|
+
}[];
|
|
60
|
+
}[];
|
|
61
|
+
support: { name: string; paths: string[]; scope: string }[];
|
|
62
|
+
evidence: Record<
|
|
63
|
+
string,
|
|
64
|
+
{ file: string; line: number; anchor: string; digest: string }
|
|
65
|
+
>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Convert a reviewed inventory into the same graph used by the runtime viewer. */
|
|
69
|
+
export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
70
|
+
const sources = (ids: string[]): SourceRef[] =>
|
|
71
|
+
[...new Set(ids)].map((id) => {
|
|
72
|
+
const source = catalog.evidence[id];
|
|
73
|
+
if (!source) throw new Error(`Missing source evidence: ${id}`);
|
|
74
|
+
return {
|
|
75
|
+
file: source.file,
|
|
76
|
+
line: source.line,
|
|
77
|
+
symbol: source.anchor,
|
|
78
|
+
digest: source.digest,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const partKind = (value: string | undefined): ElementKind => {
|
|
82
|
+
const kinds = ["block", "interface", "process", "method"];
|
|
83
|
+
if (value === undefined) return "block";
|
|
84
|
+
if (!kinds.includes(value)) throw new Error(`Unknown part kind: ${value}`);
|
|
85
|
+
return value as ElementKind;
|
|
86
|
+
};
|
|
87
|
+
const idFor = (id: string) => `${catalog.id}/${id}`;
|
|
88
|
+
const elements: DefinitionGraph["elements"] = [
|
|
89
|
+
{
|
|
90
|
+
id: catalog.id,
|
|
91
|
+
label: catalog.name,
|
|
92
|
+
kind: "block",
|
|
93
|
+
provenance: "inferred",
|
|
94
|
+
description: catalog.basis,
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
const entries: PublicEntry[] = [];
|
|
98
|
+
for (const system of catalog.systems) {
|
|
99
|
+
const evidence = sources(system.parts.flatMap((part) => part.evidence));
|
|
100
|
+
elements.push({
|
|
101
|
+
id: idFor(system.id),
|
|
102
|
+
parent: catalog.id,
|
|
103
|
+
label: system.name,
|
|
104
|
+
kind: "block",
|
|
105
|
+
provenance: "inferred",
|
|
106
|
+
description: system.purpose,
|
|
107
|
+
source: evidence[0],
|
|
108
|
+
sources: evidence,
|
|
109
|
+
hosting: system.hosting,
|
|
110
|
+
externalBoundaries: system.external,
|
|
111
|
+
});
|
|
112
|
+
const addParts = (parts: CatalogPart[], parent: string) => {
|
|
113
|
+
for (const part of parts) {
|
|
114
|
+
const evidence = sources(part.evidence);
|
|
115
|
+
const slug =
|
|
116
|
+
part.id ||
|
|
117
|
+
part.name
|
|
118
|
+
.toLowerCase()
|
|
119
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
120
|
+
.replace(/^-|-$/g, "");
|
|
121
|
+
const id = slug.startsWith(`${catalog.id}/`)
|
|
122
|
+
? slug
|
|
123
|
+
: `${parent}/${slug}`;
|
|
124
|
+
elements.push({
|
|
125
|
+
id,
|
|
126
|
+
parent,
|
|
127
|
+
label: part.name,
|
|
128
|
+
kind: partKind(part.kind),
|
|
129
|
+
provenance: "source",
|
|
130
|
+
description: part.summary,
|
|
131
|
+
signature: part.signature,
|
|
132
|
+
...(part.entryFor
|
|
133
|
+
? {
|
|
134
|
+
contract: {
|
|
135
|
+
id,
|
|
136
|
+
input: {
|
|
137
|
+
language: "reviewed-source",
|
|
138
|
+
signature: part.signature,
|
|
139
|
+
declarations: evidence.map((source) => ({
|
|
140
|
+
source,
|
|
141
|
+
declaration: source.symbol,
|
|
142
|
+
})),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: {}),
|
|
147
|
+
source: part.entryFor
|
|
148
|
+
? { ...evidence[0], scope: "contract" }
|
|
149
|
+
: evidence[0],
|
|
150
|
+
sources: part.entryFor
|
|
151
|
+
? evidence.map((source) => ({
|
|
152
|
+
...source,
|
|
153
|
+
scope: "contract" as const,
|
|
154
|
+
}))
|
|
155
|
+
: evidence,
|
|
156
|
+
resources: part.resources?.map((resource) => ({
|
|
157
|
+
id: resource.id,
|
|
158
|
+
label: resource.name,
|
|
159
|
+
description: resource.summary,
|
|
160
|
+
sources: sources(resource.evidence),
|
|
161
|
+
source: sources(resource.evidence)[0],
|
|
162
|
+
provenance: "source",
|
|
163
|
+
})),
|
|
164
|
+
outputs: part.outputs?.map((artifact) => ({
|
|
165
|
+
id: artifact.id,
|
|
166
|
+
label: artifact.name,
|
|
167
|
+
description: artifact.summary,
|
|
168
|
+
sources: sources(artifact.evidence),
|
|
169
|
+
source: sources(artifact.evidence)[0],
|
|
170
|
+
provenance: "source",
|
|
171
|
+
})),
|
|
172
|
+
});
|
|
173
|
+
if (part.entryFor)
|
|
174
|
+
entries.push({
|
|
175
|
+
implementation: part.entryFor,
|
|
176
|
+
interface: elements[elements.length - 1],
|
|
177
|
+
});
|
|
178
|
+
addParts(part.parts || [], id);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
addParts(system.parts, idFor(system.id));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const ids = new Set(elements.map((element) => element.id));
|
|
185
|
+
if (ids.size !== elements.length)
|
|
186
|
+
throw new Error("Duplicate product map identity");
|
|
187
|
+
const connections = catalog.connections.map((edge) => {
|
|
188
|
+
const source = idFor(edge.source),
|
|
189
|
+
target = idFor(edge.target);
|
|
190
|
+
if (!ids.has(source) || !ids.has(target))
|
|
191
|
+
throw new Error(`Unknown system or block in ${edge.id}`);
|
|
192
|
+
const evidence = sources(edge.evidence);
|
|
193
|
+
const relation = edge.relation || "flows";
|
|
194
|
+
if (
|
|
195
|
+
![
|
|
196
|
+
"flows",
|
|
197
|
+
"calls",
|
|
198
|
+
"resumes",
|
|
199
|
+
"requires",
|
|
200
|
+
"reads",
|
|
201
|
+
"writes",
|
|
202
|
+
"produces",
|
|
203
|
+
"loads",
|
|
204
|
+
].includes(relation)
|
|
205
|
+
)
|
|
206
|
+
throw new Error(`Unknown relation: ${relation}`);
|
|
207
|
+
if (edge.path && edge.path !== "failure" && edge.path !== "retry")
|
|
208
|
+
throw new Error(`Unknown path kind: ${edge.path}`);
|
|
209
|
+
return {
|
|
210
|
+
id: `flow:${edge.id}`,
|
|
211
|
+
source,
|
|
212
|
+
target,
|
|
213
|
+
label: edge.label,
|
|
214
|
+
relation: relation as DefinitionGraph["connections"][number]["relation"],
|
|
215
|
+
condition: edge.condition,
|
|
216
|
+
path: edge.path as "failure" | "retry" | undefined,
|
|
217
|
+
overview: edge.backbone,
|
|
218
|
+
provenance: "inferred" as const,
|
|
219
|
+
sourceRef: evidence[0],
|
|
220
|
+
sources: evidence,
|
|
221
|
+
transport: edge.transport,
|
|
222
|
+
bidirectional: edge.bidirectional,
|
|
223
|
+
artifacts:
|
|
224
|
+
edge.artifacts?.map((artifact) => ({
|
|
225
|
+
id: artifact.id,
|
|
226
|
+
label: artifact.name,
|
|
227
|
+
description: artifact.summary,
|
|
228
|
+
sources: sources(artifact.evidence),
|
|
229
|
+
source: sources(artifact.evidence)[0],
|
|
230
|
+
provenance: "inferred" as const,
|
|
231
|
+
})) ||
|
|
232
|
+
(relation === "flows"
|
|
233
|
+
? [
|
|
234
|
+
{
|
|
235
|
+
id: `payload:${edge.id}`,
|
|
236
|
+
label: edge.label,
|
|
237
|
+
sources: evidence,
|
|
238
|
+
source: evidence[0],
|
|
239
|
+
provenance: "inferred" as const,
|
|
240
|
+
},
|
|
241
|
+
]
|
|
242
|
+
: undefined),
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
const content = JSON.stringify({
|
|
246
|
+
elements,
|
|
247
|
+
connections,
|
|
248
|
+
support: catalog.support,
|
|
249
|
+
});
|
|
250
|
+
let hash = 14695981039346656037n;
|
|
251
|
+
for (const byte of new TextEncoder().encode(content))
|
|
252
|
+
hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * 1099511628211n);
|
|
253
|
+
return interfaceMap(
|
|
254
|
+
{
|
|
255
|
+
schema: "fractal.definition.v1",
|
|
256
|
+
id: catalog.id,
|
|
257
|
+
revision: hash.toString(16).padStart(16, "0"),
|
|
258
|
+
generatedAt: catalog.date,
|
|
259
|
+
scope: `${catalog.name} — whole product`,
|
|
260
|
+
basis: "repository-review",
|
|
261
|
+
supportingAreas: catalog.support,
|
|
262
|
+
elements,
|
|
263
|
+
connections,
|
|
264
|
+
tests: [],
|
|
265
|
+
failures: [],
|
|
266
|
+
gaps: [],
|
|
267
|
+
},
|
|
268
|
+
entries,
|
|
269
|
+
{ exposeAncestors: true },
|
|
270
|
+
);
|
|
271
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/** Fixed read-only provider checks. Never return credential material or provider error bodies. */
|
|
2
|
+
const { execFileSync } = require("node:child_process");
|
|
3
|
+
const { readFileSync } = require("node:fs");
|
|
4
|
+
const { join } = require("node:path");
|
|
5
|
+
const { homedir } = require("node:os");
|
|
6
|
+
const { parseEnv } = require("node:util");
|
|
7
|
+
function command(binary, args) {
|
|
8
|
+
return execFileSync(binary, args, {
|
|
9
|
+
encoding: "utf8",
|
|
10
|
+
timeout: 15000,
|
|
11
|
+
maxBuffer: 1024 * 1024,
|
|
12
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
13
|
+
}).trim();
|
|
14
|
+
}
|
|
15
|
+
function discovery(root, env = process.env) {
|
|
16
|
+
const values = { ...env };
|
|
17
|
+
for (const file of [
|
|
18
|
+
".env",
|
|
19
|
+
".env.local",
|
|
20
|
+
])
|
|
21
|
+
try {
|
|
22
|
+
for (const [key, value] of Object.entries(
|
|
23
|
+
parseEnv(readFileSync(join(root, file), "utf8")),
|
|
24
|
+
))
|
|
25
|
+
if (
|
|
26
|
+
/^(FRACTAL_(GITHUB_(TOKEN|REPOSITORY)|SENTRY_(TOKEN|ORG|PROJECTS)|LINEAR_(API_KEY|WORKSPACE_ID|WORKSPACE_URL))|SENTRY_(AUTH_TOKEN|ORG|PROJECT)|LINEAR_API_KEY|GH_TOKEN|GITHUB_TOKEN)$/.test(
|
|
27
|
+
key,
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
values[key] = value;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e.code !== "ENOENT")
|
|
33
|
+
throw Error("Could not read repository integration settings.");
|
|
34
|
+
}
|
|
35
|
+
let repository = values.FRACTAL_GITHUB_REPOSITORY;
|
|
36
|
+
if (!repository)
|
|
37
|
+
try {
|
|
38
|
+
const remote = command("git", [
|
|
39
|
+
"-C",
|
|
40
|
+
root,
|
|
41
|
+
"remote",
|
|
42
|
+
"get-url",
|
|
43
|
+
"origin",
|
|
44
|
+
]);
|
|
45
|
+
repository = remote.match(
|
|
46
|
+
/(?:github\.com[:/])([\w.-]+\/[\w.-]+?)(?:\.git)?$/,
|
|
47
|
+
)?.[1];
|
|
48
|
+
} catch {}
|
|
49
|
+
let sentry = values.FRACTAL_SENTRY_TOKEN || values.SENTRY_AUTH_TOKEN;
|
|
50
|
+
if (!sentry)
|
|
51
|
+
try {
|
|
52
|
+
sentry = readFileSync(join(homedir(), ".sentryclirc"), "utf8").match(
|
|
53
|
+
/\[auth\][\s\S]*?^token\s*=\s*(\S+)/m,
|
|
54
|
+
)?.[1];
|
|
55
|
+
} catch {}
|
|
56
|
+
return {
|
|
57
|
+
github: {
|
|
58
|
+
token:
|
|
59
|
+
values.FRACTAL_GITHUB_TOKEN || values.GH_TOKEN || values.GITHUB_TOKEN,
|
|
60
|
+
repository,
|
|
61
|
+
},
|
|
62
|
+
sentry: {
|
|
63
|
+
token: sentry,
|
|
64
|
+
org: values.FRACTAL_SENTRY_ORG || values.SENTRY_ORG,
|
|
65
|
+
projects: values.FRACTAL_SENTRY_PROJECTS || values.SENTRY_PROJECT,
|
|
66
|
+
},
|
|
67
|
+
linear: {
|
|
68
|
+
token: values.FRACTAL_LINEAR_API_KEY || values.LINEAR_API_KEY,
|
|
69
|
+
workspaceId: values.FRACTAL_LINEAR_WORKSPACE_ID,
|
|
70
|
+
workspaceUrl: values.FRACTAL_LINEAR_WORKSPACE_URL,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function checkProvider(provider, input, fetcher = fetch) {
|
|
75
|
+
const config = { ...input };
|
|
76
|
+
if (provider === "github" && config.mode === "cli") {
|
|
77
|
+
try {
|
|
78
|
+
config.token = command("gh", [
|
|
79
|
+
"auth",
|
|
80
|
+
"token",
|
|
81
|
+
"--hostname",
|
|
82
|
+
"github.com",
|
|
83
|
+
]);
|
|
84
|
+
} catch {
|
|
85
|
+
throw Error(
|
|
86
|
+
"GitHub authorization required. Run fractory integrations connect github --login.",
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (provider === "sentry" && config.mode === "cli") {
|
|
91
|
+
try {
|
|
92
|
+
config.token = command("sentry", ["auth", "token"]);
|
|
93
|
+
} catch {
|
|
94
|
+
throw Error(
|
|
95
|
+
"Sentry authorization required. Run fractory integrations connect sentry --login.",
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!config.token)
|
|
100
|
+
throw Error(
|
|
101
|
+
"No credential found. The agent must complete provider authorization.",
|
|
102
|
+
);
|
|
103
|
+
const request = async (url, body) => {
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await fetcher(url, {
|
|
107
|
+
method: body ? "POST" : "GET",
|
|
108
|
+
headers: {
|
|
109
|
+
Authorization:
|
|
110
|
+
provider === "linear" ? config.token : `Bearer ${config.token}`,
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
Accept: "application/json",
|
|
113
|
+
},
|
|
114
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
115
|
+
redirect: "error",
|
|
116
|
+
signal: AbortSignal.timeout(15000),
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
throw Error(
|
|
120
|
+
`${provider} could not be reached. Check the network and retry.`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (!response.ok)
|
|
124
|
+
throw Error(
|
|
125
|
+
`${provider} access check failed (HTTP ${response.status}). Credentials were not saved.`,
|
|
126
|
+
);
|
|
127
|
+
const json = await response.json();
|
|
128
|
+
if (json.errors)
|
|
129
|
+
throw Error(
|
|
130
|
+
`${provider} rejected the read request. Check the account and read permissions.`,
|
|
131
|
+
);
|
|
132
|
+
return json;
|
|
133
|
+
};
|
|
134
|
+
let account;
|
|
135
|
+
if (provider === "github") {
|
|
136
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(config.repository || ""))
|
|
137
|
+
throw Error("Choose the GitHub repository with --repository owner/repo.");
|
|
138
|
+
const repo = await request(
|
|
139
|
+
"https://api.github.com/repos/" + config.repository,
|
|
140
|
+
);
|
|
141
|
+
if (repo.full_name?.toLowerCase() !== config.repository.toLowerCase())
|
|
142
|
+
throw Error("GitHub returned a different repository.");
|
|
143
|
+
await request(
|
|
144
|
+
"https://api.github.com/repos/" +
|
|
145
|
+
config.repository +
|
|
146
|
+
"/pulls?state=open&per_page=1",
|
|
147
|
+
);
|
|
148
|
+
account = repo.full_name;
|
|
149
|
+
} else if (provider === "sentry") {
|
|
150
|
+
if (config.org && !/^[\w.-]+$/.test(config.org))
|
|
151
|
+
throw Error("Invalid Sentry organization.");
|
|
152
|
+
if (!config.org) {
|
|
153
|
+
const orgs = await request("https://sentry.io/api/0/organizations/");
|
|
154
|
+
if (orgs.length !== 1)
|
|
155
|
+
throw Error("Choose a Sentry organization with --org.");
|
|
156
|
+
config.org = orgs[0].slug;
|
|
157
|
+
}
|
|
158
|
+
const projects = await request(
|
|
159
|
+
"https://sentry.io/api/0/organizations/" + config.org + "/projects/",
|
|
160
|
+
);
|
|
161
|
+
const chosen = (config.projects || "")
|
|
162
|
+
.split(",")
|
|
163
|
+
.map((s) => s.trim())
|
|
164
|
+
.filter(Boolean);
|
|
165
|
+
if (chosen.some((p) => !projects.some((x) => x.slug === p || x.id === p)))
|
|
166
|
+
throw Error(
|
|
167
|
+
"A selected Sentry project is not accessible to this account.",
|
|
168
|
+
);
|
|
169
|
+
if (!chosen.length)
|
|
170
|
+
throw Error(
|
|
171
|
+
"Choose this repository’s Sentry projects with --projects slug,slug.",
|
|
172
|
+
);
|
|
173
|
+
await request(
|
|
174
|
+
"https://sentry.io/api/0/projects/" +
|
|
175
|
+
config.org +
|
|
176
|
+
"/" +
|
|
177
|
+
projects.find((p) => p.slug === chosen[0] || p.id === chosen[0]).slug +
|
|
178
|
+
"/issues/?limit=1&statsPeriod=24h",
|
|
179
|
+
);
|
|
180
|
+
config.projects = chosen.join(",");
|
|
181
|
+
account = config.org;
|
|
182
|
+
} else if (provider === "linear") {
|
|
183
|
+
const data = (
|
|
184
|
+
await request("https://api.linear.app/graphql", {
|
|
185
|
+
query:
|
|
186
|
+
"query FractoryAccess { viewer { id name } organization { id name urlKey } issues(first: 1) { nodes { id } } }",
|
|
187
|
+
})
|
|
188
|
+
).data;
|
|
189
|
+
if (!data?.organization?.id)
|
|
190
|
+
throw Error("Linear did not return a workspace.");
|
|
191
|
+
if (config.workspaceId && config.workspaceId !== data.organization.id)
|
|
192
|
+
throw Error("This credential belongs to a different Linear workspace.");
|
|
193
|
+
config.workspaceId = data.organization.id;
|
|
194
|
+
config.workspaceUrl = "https://linear.app/" + data.organization.urlKey;
|
|
195
|
+
account = data.organization.name;
|
|
196
|
+
} else throw Error("Unsupported integration.");
|
|
197
|
+
if (config.mode === "cli") delete config.token;
|
|
198
|
+
else config.mode = "token";
|
|
199
|
+
return {
|
|
200
|
+
value: Object.fromEntries(
|
|
201
|
+
Object.entries(config).filter(([, v]) => typeof v === "string"),
|
|
202
|
+
),
|
|
203
|
+
account,
|
|
204
|
+
checkedAt: new Date().toISOString(),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
module.exports = { discovery, checkProvider };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Provider = "github" | "sentry" | "linear";
|
|
2
|
+
export function discovery(
|
|
3
|
+
root: string,
|
|
4
|
+
env?: NodeJS.ProcessEnv,
|
|
5
|
+
): Record<Provider, Record<string, string | undefined>>;
|
|
6
|
+
export function checkProvider(
|
|
7
|
+
provider: Provider,
|
|
8
|
+
input: Record<string, string>,
|
|
9
|
+
fetcher?: typeof fetch,
|
|
10
|
+
): Promise<{
|
|
11
|
+
value: Record<string, string>;
|
|
12
|
+
account: string;
|
|
13
|
+
checkedAt: string;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { DefinitionGraph, Connection } from "./model";
|
|
2
|
+
|
|
3
|
+
const transfers = new Set([
|
|
4
|
+
"calls",
|
|
5
|
+
"renders",
|
|
6
|
+
"callbacks",
|
|
7
|
+
"delegates",
|
|
8
|
+
"resumes",
|
|
9
|
+
"requires",
|
|
10
|
+
"flows",
|
|
11
|
+
"reads",
|
|
12
|
+
"writes",
|
|
13
|
+
"loads",
|
|
14
|
+
"produces",
|
|
15
|
+
"exposes",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/** Outside is relative to each enclosing black box. Never fabricate an interface
|
|
19
|
+
* to make a direct implementation call look encapsulated. Pure source diagnosis. */
|
|
20
|
+
export function boundaryViolations(graph: DefinitionGraph) {
|
|
21
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
22
|
+
const path = (id: string) => {
|
|
23
|
+
const result: string[] = [],
|
|
24
|
+
seen = new Set<string>();
|
|
25
|
+
while (byId.has(id) && !seen.has(id)) {
|
|
26
|
+
seen.add(id);
|
|
27
|
+
result.push(id);
|
|
28
|
+
id = byId.get(id)?.parent || "";
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
const paths = new Map(graph.elements.map((n) => [n.id, path(n.id)]));
|
|
33
|
+
const exposures = new Map<string, Set<string>>();
|
|
34
|
+
for (const e of graph.connections)
|
|
35
|
+
if (e.relation === "exposes" && byId.get(e.target)?.kind === "interface") {
|
|
36
|
+
if (!exposures.has(e.source)) exposures.set(e.source, new Set());
|
|
37
|
+
exposures.get(e.source)!.add(e.target);
|
|
38
|
+
}
|
|
39
|
+
return graph.connections.flatMap((edge) => {
|
|
40
|
+
if (!transfers.has(edge.relation)) return [];
|
|
41
|
+
const sourcePath = new Set(paths.get(edge.source) || []),
|
|
42
|
+
targetPath = paths.get(edge.target) || [];
|
|
43
|
+
// A receiver itself can be an interface; methods inside it also belong to its contract.
|
|
44
|
+
const issues: {
|
|
45
|
+
connection: string;
|
|
46
|
+
block: string;
|
|
47
|
+
target: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
}[] = [];
|
|
50
|
+
const receiver = byId.get(edge.target);
|
|
51
|
+
if (edge.relation === "exposes") {
|
|
52
|
+
return receiver?.kind === "interface"
|
|
53
|
+
? []
|
|
54
|
+
: [
|
|
55
|
+
{
|
|
56
|
+
connection: edge.id,
|
|
57
|
+
block: edge.source,
|
|
58
|
+
target: edge.target,
|
|
59
|
+
reason: "Only an interface can be publicly exposed.",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
const owner = targetPath.find((id) => {
|
|
64
|
+
const node = byId.get(id)!;
|
|
65
|
+
return ![
|
|
66
|
+
"interface",
|
|
67
|
+
"method",
|
|
68
|
+
"operation",
|
|
69
|
+
"resource",
|
|
70
|
+
"artifact",
|
|
71
|
+
].includes(node.kind);
|
|
72
|
+
});
|
|
73
|
+
if (
|
|
74
|
+
receiver &&
|
|
75
|
+
owner &&
|
|
76
|
+
!sourcePath.has(owner) &&
|
|
77
|
+
!["interface", "resource", "artifact"].includes(receiver.kind)
|
|
78
|
+
)
|
|
79
|
+
issues.push({
|
|
80
|
+
connection: edge.id,
|
|
81
|
+
block: owner,
|
|
82
|
+
target: edge.target,
|
|
83
|
+
reason: `Connect to a public interface of ${byId.get(owner)!.label}, not its internal ${receiver.label}.`,
|
|
84
|
+
});
|
|
85
|
+
for (let i = 0; i < targetPath.length; i++) {
|
|
86
|
+
const id = targetPath[i],
|
|
87
|
+
node = byId.get(id)!;
|
|
88
|
+
if (sourcePath.has(id)) break;
|
|
89
|
+
if (
|
|
90
|
+
["interface", "method", "operation", "resource", "artifact"].includes(
|
|
91
|
+
node.kind,
|
|
92
|
+
) ||
|
|
93
|
+
id === graph.id
|
|
94
|
+
)
|
|
95
|
+
continue;
|
|
96
|
+
const entry = i > 0 ? byId.get(targetPath[i - 1]) : undefined;
|
|
97
|
+
// An interface is public to its immediate owner. An inner interface is
|
|
98
|
+
// not implicitly exposed on every ancestor.
|
|
99
|
+
const exposed =
|
|
100
|
+
entry?.kind === "interface" ||
|
|
101
|
+
targetPath.slice(0, i).some((target) => exposures.get(id)?.has(target));
|
|
102
|
+
if (!exposed && !issues.some((issue) => issue.block === id))
|
|
103
|
+
issues.push({
|
|
104
|
+
connection: edge.id,
|
|
105
|
+
block: id,
|
|
106
|
+
target: edge.target,
|
|
107
|
+
reason: `Call bypasses the public interface of ${node.label}.`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return issues;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** New definitions and plan edits are rejected at the model boundary. Readers
|
|
115
|
+
* can still inspect older snapshots and report their original violations. */
|
|
116
|
+
export function assertPublicConnections(graph: DefinitionGraph) {
|
|
117
|
+
const issues = boundaryViolations(graph);
|
|
118
|
+
if (issues.length)
|
|
119
|
+
throw Error(
|
|
120
|
+
issues.map((issue) => `${issue.connection}: ${issue.reason}`).join("\n"),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function publicConnectionError(
|
|
125
|
+
graph: DefinitionGraph,
|
|
126
|
+
edge: Connection,
|
|
127
|
+
) {
|
|
128
|
+
if (
|
|
129
|
+
![edge.source, edge.target].every((id) =>
|
|
130
|
+
graph.elements.some((node) => node.id === id),
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
return "Choose an existing block and a public interface.";
|
|
134
|
+
return boundaryViolations({
|
|
135
|
+
...graph,
|
|
136
|
+
connections: [
|
|
137
|
+
...graph.connections.filter(
|
|
138
|
+
(item) => item.relation === "exposes" && item.id !== edge.id,
|
|
139
|
+
),
|
|
140
|
+
edge,
|
|
141
|
+
],
|
|
142
|
+
}).find((issue) => issue.connection === edge.id)?.reason;
|
|
143
|
+
}
|