@granular-software/fractory 0.0.0-stage → 0.1.24
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 +118 -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 +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -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 +66 -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 +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -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/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 +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -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 +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -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 +151 -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 +12 -0
- package/dist/scope.js +94 -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 +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -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 +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -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-model.d.ts +110 -0
- package/dist/work-model.js +261 -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 +481 -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 +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -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 +378 -0
- package/src/factory-model.ts +73 -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/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 +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -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 +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -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 +189 -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 +103 -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 +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -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 +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -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 +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { DefinitionGraph, ElementKind, SourceRef } from "./model";
|
|
2
|
+
|
|
3
|
+
export interface CatalogPart {
|
|
4
|
+
/** Stable identity: a local slug, or a qualified ID retained when a part moves. */
|
|
5
|
+
id?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
kind?: string;
|
|
8
|
+
summary: string;
|
|
9
|
+
signature?: string;
|
|
10
|
+
evidence: string[];
|
|
11
|
+
parts?: CatalogPart[];
|
|
12
|
+
resources?: {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
summary?: string;
|
|
16
|
+
evidence: string[];
|
|
17
|
+
}[];
|
|
18
|
+
outputs?: {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
summary?: string;
|
|
22
|
+
evidence: string[];
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ProductMapCatalog {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
date: string;
|
|
30
|
+
basis: string;
|
|
31
|
+
systems: {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
purpose: string;
|
|
35
|
+
hosting: string;
|
|
36
|
+
external: string[];
|
|
37
|
+
parts: CatalogPart[];
|
|
38
|
+
}[];
|
|
39
|
+
connections: {
|
|
40
|
+
id: string;
|
|
41
|
+
source: string;
|
|
42
|
+
target: string;
|
|
43
|
+
label: string;
|
|
44
|
+
transport: string;
|
|
45
|
+
evidence: string[];
|
|
46
|
+
bidirectional: boolean;
|
|
47
|
+
relation?: string;
|
|
48
|
+
condition?: string;
|
|
49
|
+
path?: string;
|
|
50
|
+
backbone?: boolean;
|
|
51
|
+
artifacts?: {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
summary?: string;
|
|
55
|
+
evidence: string[];
|
|
56
|
+
}[];
|
|
57
|
+
}[];
|
|
58
|
+
support: { name: string; paths: string[]; scope: string }[];
|
|
59
|
+
evidence: Record<
|
|
60
|
+
string,
|
|
61
|
+
{ file: string; line: number; anchor: string; digest: string }
|
|
62
|
+
>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Convert a reviewed inventory into the same graph used by the runtime viewer. */
|
|
66
|
+
export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
67
|
+
const sources = (ids: string[]): SourceRef[] =>
|
|
68
|
+
[...new Set(ids)].map((id) => {
|
|
69
|
+
const source = catalog.evidence[id];
|
|
70
|
+
if (!source) throw new Error(`Missing source evidence: ${id}`);
|
|
71
|
+
return {
|
|
72
|
+
file: source.file,
|
|
73
|
+
line: source.line,
|
|
74
|
+
symbol: source.anchor,
|
|
75
|
+
digest: source.digest,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const partKind = (value: string | undefined): ElementKind => {
|
|
79
|
+
const kinds = ["block", "interface", "process", "method"];
|
|
80
|
+
if (value === undefined) return "block";
|
|
81
|
+
if (!kinds.includes(value)) throw new Error(`Unknown part kind: ${value}`);
|
|
82
|
+
return value as ElementKind;
|
|
83
|
+
};
|
|
84
|
+
const idFor = (id: string) => `${catalog.id}/${id}`;
|
|
85
|
+
const elements: DefinitionGraph["elements"] = [
|
|
86
|
+
{
|
|
87
|
+
id: catalog.id,
|
|
88
|
+
label: catalog.name,
|
|
89
|
+
kind: "block",
|
|
90
|
+
provenance: "inferred",
|
|
91
|
+
description: catalog.basis,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
for (const system of catalog.systems) {
|
|
95
|
+
const evidence = sources(system.parts.flatMap((part) => part.evidence));
|
|
96
|
+
elements.push({
|
|
97
|
+
id: idFor(system.id),
|
|
98
|
+
parent: catalog.id,
|
|
99
|
+
label: system.name,
|
|
100
|
+
kind: "block",
|
|
101
|
+
provenance: "inferred",
|
|
102
|
+
description: system.purpose,
|
|
103
|
+
source: evidence[0],
|
|
104
|
+
sources: evidence,
|
|
105
|
+
hosting: system.hosting,
|
|
106
|
+
externalBoundaries: system.external,
|
|
107
|
+
});
|
|
108
|
+
const addParts = (parts: CatalogPart[], parent: string) => {
|
|
109
|
+
for (const part of parts) {
|
|
110
|
+
const evidence = sources(part.evidence);
|
|
111
|
+
const slug =
|
|
112
|
+
part.id ||
|
|
113
|
+
part.name
|
|
114
|
+
.toLowerCase()
|
|
115
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
116
|
+
.replace(/^-|-$/g, "");
|
|
117
|
+
const id = slug.startsWith(`${catalog.id}/`)
|
|
118
|
+
? slug
|
|
119
|
+
: `${parent}/${slug}`;
|
|
120
|
+
elements.push({
|
|
121
|
+
id,
|
|
122
|
+
parent,
|
|
123
|
+
label: part.name,
|
|
124
|
+
kind: partKind(part.kind),
|
|
125
|
+
provenance: "source",
|
|
126
|
+
description: part.summary,
|
|
127
|
+
signature: part.signature,
|
|
128
|
+
source: evidence[0],
|
|
129
|
+
sources: evidence,
|
|
130
|
+
resources: part.resources?.map((resource) => ({
|
|
131
|
+
id: resource.id,
|
|
132
|
+
label: resource.name,
|
|
133
|
+
description: resource.summary,
|
|
134
|
+
sources: sources(resource.evidence),
|
|
135
|
+
source: sources(resource.evidence)[0],
|
|
136
|
+
provenance: "source",
|
|
137
|
+
})),
|
|
138
|
+
outputs: part.outputs?.map((artifact) => ({
|
|
139
|
+
id: artifact.id,
|
|
140
|
+
label: artifact.name,
|
|
141
|
+
description: artifact.summary,
|
|
142
|
+
sources: sources(artifact.evidence),
|
|
143
|
+
source: sources(artifact.evidence)[0],
|
|
144
|
+
provenance: "source",
|
|
145
|
+
})),
|
|
146
|
+
});
|
|
147
|
+
addParts(part.parts || [], id);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
addParts(system.parts, idFor(system.id));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const ids = new Set(elements.map((element) => element.id));
|
|
154
|
+
if (ids.size !== elements.length)
|
|
155
|
+
throw new Error("Duplicate product map identity");
|
|
156
|
+
const connections = catalog.connections.map((edge) => {
|
|
157
|
+
const source = idFor(edge.source),
|
|
158
|
+
target = idFor(edge.target);
|
|
159
|
+
if (!ids.has(source) || !ids.has(target))
|
|
160
|
+
throw new Error(`Unknown system or block in ${edge.id}`);
|
|
161
|
+
const evidence = sources(edge.evidence);
|
|
162
|
+
const relation = edge.relation || "flows";
|
|
163
|
+
if (
|
|
164
|
+
![
|
|
165
|
+
"flows",
|
|
166
|
+
"calls",
|
|
167
|
+
"resumes",
|
|
168
|
+
"requires",
|
|
169
|
+
"reads",
|
|
170
|
+
"writes",
|
|
171
|
+
"produces",
|
|
172
|
+
"loads",
|
|
173
|
+
].includes(relation)
|
|
174
|
+
)
|
|
175
|
+
throw new Error(`Unknown relation: ${relation}`);
|
|
176
|
+
if (edge.path && edge.path !== "failure" && edge.path !== "retry")
|
|
177
|
+
throw new Error(`Unknown path kind: ${edge.path}`);
|
|
178
|
+
return {
|
|
179
|
+
id: `flow:${edge.id}`,
|
|
180
|
+
source,
|
|
181
|
+
target,
|
|
182
|
+
label: edge.label,
|
|
183
|
+
relation: relation as DefinitionGraph["connections"][number]["relation"],
|
|
184
|
+
condition: edge.condition,
|
|
185
|
+
path: edge.path as "failure" | "retry" | undefined,
|
|
186
|
+
overview: edge.backbone,
|
|
187
|
+
provenance: "inferred" as const,
|
|
188
|
+
sourceRef: evidence[0],
|
|
189
|
+
sources: evidence,
|
|
190
|
+
transport: edge.transport,
|
|
191
|
+
bidirectional: edge.bidirectional,
|
|
192
|
+
artifacts:
|
|
193
|
+
edge.artifacts?.map((artifact) => ({
|
|
194
|
+
id: artifact.id,
|
|
195
|
+
label: artifact.name,
|
|
196
|
+
description: artifact.summary,
|
|
197
|
+
sources: sources(artifact.evidence),
|
|
198
|
+
source: sources(artifact.evidence)[0],
|
|
199
|
+
provenance: "inferred" as const,
|
|
200
|
+
})) ||
|
|
201
|
+
(relation === "flows"
|
|
202
|
+
? [
|
|
203
|
+
{
|
|
204
|
+
id: `payload:${edge.id}`,
|
|
205
|
+
label: edge.label,
|
|
206
|
+
sources: evidence,
|
|
207
|
+
source: evidence[0],
|
|
208
|
+
provenance: "inferred" as const,
|
|
209
|
+
},
|
|
210
|
+
]
|
|
211
|
+
: undefined),
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
const content = JSON.stringify({
|
|
215
|
+
elements,
|
|
216
|
+
connections,
|
|
217
|
+
support: catalog.support,
|
|
218
|
+
});
|
|
219
|
+
let hash = 14695981039346656037n;
|
|
220
|
+
for (const byte of new TextEncoder().encode(content))
|
|
221
|
+
hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * 1099511628211n);
|
|
222
|
+
return {
|
|
223
|
+
schema: "fractal.definition.v1",
|
|
224
|
+
id: catalog.id,
|
|
225
|
+
revision: hash.toString(16).padStart(16, "0"),
|
|
226
|
+
generatedAt: catalog.date,
|
|
227
|
+
scope: `${catalog.name} — whole product`,
|
|
228
|
+
basis: "repository-review",
|
|
229
|
+
supportingAreas: catalog.support,
|
|
230
|
+
elements,
|
|
231
|
+
connections,
|
|
232
|
+
tests: [],
|
|
233
|
+
failures: [],
|
|
234
|
+
gaps: [],
|
|
235
|
+
};
|
|
236
|
+
}
|
|
@@ -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,125 @@
|
|
|
1
|
+
import { readRepositoryMap } from "./repository-map";
|
|
2
|
+
import { listWorkContexts, workDeepLink } from "./work-context";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { createReport, listReports, markReport, readReport } from "./reports";
|
|
8
|
+
import { reportsForBlock } from "./reports-model";
|
|
9
|
+
import type { DefinitionGraph } from "./model";
|
|
10
|
+
|
|
11
|
+
export async function runReports(args: string[]) {
|
|
12
|
+
if (args.includes("--help"))
|
|
13
|
+
return "fractory reports [list] [--block ID] [--unread]\nfractory reports create --block ID [--block ID ...] --title TITLE (--file report.md | --stdin) [--author LABEL]\nfractory reports show REPORT_ID\nfractory reports open REPORT_ID\nfractory reports read REPORT_ID\nfractory reports unread REPORT_ID\nUse --root PATH from another directory. Reports are versioned Markdown; read status stays local. Showing a report does not mark it read.";
|
|
14
|
+
const value = (name: string) => {
|
|
15
|
+
const index = args.indexOf(name);
|
|
16
|
+
if (index < 0) return undefined;
|
|
17
|
+
if (!args[index + 1] || args[index + 1].startsWith("--"))
|
|
18
|
+
throw Error(`${name} needs a value.`);
|
|
19
|
+
return args[index + 1];
|
|
20
|
+
};
|
|
21
|
+
let root = resolve(value("--root") || process.cwd());
|
|
22
|
+
if (!value("--root"))
|
|
23
|
+
while (
|
|
24
|
+
!existsSync(join(root, ".git")) &&
|
|
25
|
+
!existsSync(join(root, "fractory.json")) &&
|
|
26
|
+
dirname(root) !== root
|
|
27
|
+
)
|
|
28
|
+
root = dirname(root);
|
|
29
|
+
const action = args[1]?.startsWith("--") ? "list" : args[1] || "list";
|
|
30
|
+
const reportURL = (report: { blocks: string[]; id: string }) => {
|
|
31
|
+
let link = `fractory://open?repo=${encodeURIComponent(root)}`;
|
|
32
|
+
try {
|
|
33
|
+
const context = listWorkContexts(root).find(
|
|
34
|
+
(t) => t.path === realpathSync(root),
|
|
35
|
+
);
|
|
36
|
+
link = workDeepLink(root, context?.id || "main");
|
|
37
|
+
} catch {
|
|
38
|
+
/* Offline report fixtures still produce a repository link. */
|
|
39
|
+
}
|
|
40
|
+
const url = new URL(link);
|
|
41
|
+
url.searchParams.set("block", report.blocks[0]);
|
|
42
|
+
url.searchParams.set("inspect", report.blocks[0]);
|
|
43
|
+
url.searchParams.set("workspace", "reports");
|
|
44
|
+
url.searchParams.set("report", report.id);
|
|
45
|
+
return url.href;
|
|
46
|
+
};
|
|
47
|
+
if (["show", "read", "unread", "open"].includes(action)) {
|
|
48
|
+
const id = args[2];
|
|
49
|
+
if (!id || id.startsWith("--"))
|
|
50
|
+
throw Error("Choose a report ID from fractory reports list.");
|
|
51
|
+
const report = readReport(root, id);
|
|
52
|
+
if (action === "open") {
|
|
53
|
+
const url = reportURL(report);
|
|
54
|
+
execFileSync("open", [url], { stdio: "ignore", timeout: 5000 });
|
|
55
|
+
return url;
|
|
56
|
+
}
|
|
57
|
+
return JSON.stringify(
|
|
58
|
+
action === "show"
|
|
59
|
+
? report
|
|
60
|
+
: markReport(root, id, report.revision, action === "read"),
|
|
61
|
+
null,
|
|
62
|
+
2,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (!["list", "create"].includes(action))
|
|
66
|
+
throw Error(`Unknown reports command: ${action}`);
|
|
67
|
+
const graph = readRepositoryMap(root);
|
|
68
|
+
if (!graph)
|
|
69
|
+
throw Error("No Fractory map in this repository. Run fractory setup.");
|
|
70
|
+
if (action === "list") {
|
|
71
|
+
const view = listReports(root);
|
|
72
|
+
const reports = value("--block")
|
|
73
|
+
? reportsForBlock(graph, view.reports, value("--block")!)
|
|
74
|
+
: view.reports;
|
|
75
|
+
return JSON.stringify(
|
|
76
|
+
{
|
|
77
|
+
...view,
|
|
78
|
+
reports: args.includes("--unread")
|
|
79
|
+
? reports.filter((report) => report.unread)
|
|
80
|
+
: reports,
|
|
81
|
+
},
|
|
82
|
+
null,
|
|
83
|
+
2,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
const blocks = args.flatMap((arg, index) =>
|
|
87
|
+
arg === "--block" ? [args[index + 1]] : [],
|
|
88
|
+
);
|
|
89
|
+
if (blocks.some((block) => !block || block.startsWith("--")))
|
|
90
|
+
throw Error("--block needs a block ID.");
|
|
91
|
+
const file = value("--file"),
|
|
92
|
+
stdin = args.includes("--stdin");
|
|
93
|
+
if ((!file && !stdin) || (file && stdin))
|
|
94
|
+
throw Error("Supply Markdown with either --file PATH or --stdin.");
|
|
95
|
+
if (stdin && process.stdin.isTTY)
|
|
96
|
+
throw Error("Pipe Markdown to --stdin, or use --file PATH.");
|
|
97
|
+
let body: string;
|
|
98
|
+
if (file) {
|
|
99
|
+
const path = resolve(process.cwd(), file),
|
|
100
|
+
stat = statSync(path);
|
|
101
|
+
if (!stat.isFile() || stat.size > 128000)
|
|
102
|
+
throw Error("Supply a Markdown file below 128 KB.");
|
|
103
|
+
body = readFileSync(path, "utf8");
|
|
104
|
+
} else {
|
|
105
|
+
const chunks: Buffer[] = [];
|
|
106
|
+
let size = 0;
|
|
107
|
+
for await (const chunk of process.stdin) {
|
|
108
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
109
|
+
size += buffer.length;
|
|
110
|
+
if (size > 128000) throw Error("Keep this report below 128 KB.");
|
|
111
|
+
chunks.push(buffer);
|
|
112
|
+
}
|
|
113
|
+
body = Buffer.concat(chunks).toString("utf8");
|
|
114
|
+
}
|
|
115
|
+
const report = createReport(root, graph, {
|
|
116
|
+
title: value("--title") || "",
|
|
117
|
+
blocks,
|
|
118
|
+
body,
|
|
119
|
+
author: value("--author"),
|
|
120
|
+
});
|
|
121
|
+
const url = reportURL(report);
|
|
122
|
+
if (args.includes("--open"))
|
|
123
|
+
execFileSync("open", [url], { stdio: "ignore", timeout: 5000 });
|
|
124
|
+
return JSON.stringify({ ...report, url }, null, 2);
|
|
125
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model";
|
|
2
|
+
|
|
3
|
+
export interface ReportMetadata {
|
|
4
|
+
schema: "fractory.report.v1";
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
blocks: string[];
|
|
8
|
+
createdAt: string;
|
|
9
|
+
author?: string;
|
|
10
|
+
codeRevision?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BlockReport extends ReportMetadata {
|
|
13
|
+
file: string;
|
|
14
|
+
revision: string;
|
|
15
|
+
unread: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ReportDocument extends BlockReport {
|
|
18
|
+
body: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ReportsView {
|
|
21
|
+
reports: BlockReport[];
|
|
22
|
+
warnings: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function resolvedReportBlock(graph: DefinitionGraph, id: string) {
|
|
26
|
+
const seen = new Set<string>();
|
|
27
|
+
while (graph.aliases && Object.hasOwn(graph.aliases, id) && typeof graph.aliases[id] === "string" && !seen.has(id)) {
|
|
28
|
+
seen.add(id);
|
|
29
|
+
id = graph.aliases[id];
|
|
30
|
+
}
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A multi-target report contributes once to each ancestor, including the root. */
|
|
35
|
+
export function reportBlocks(
|
|
36
|
+
graph: DefinitionGraph,
|
|
37
|
+
report: Pick<BlockReport, "blocks">,
|
|
38
|
+
) {
|
|
39
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
40
|
+
const owners = new Set<string>();
|
|
41
|
+
// The repository inbox must also retain reports whose target was removed.
|
|
42
|
+
// Their tree placement stays explicitly Unassigned, never a guessed leaf.
|
|
43
|
+
if (byId.has(graph.id)) owners.add(graph.id);
|
|
44
|
+
for (const target of report.blocks) {
|
|
45
|
+
let id: string | undefined = resolvedReportBlock(graph, target);
|
|
46
|
+
const seen = new Set<string>();
|
|
47
|
+
while (id && byId.has(id) && !seen.has(id)) {
|
|
48
|
+
seen.add(id);
|
|
49
|
+
owners.add(id);
|
|
50
|
+
id = byId.get(id)!.parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return owners;
|
|
54
|
+
}
|
|
55
|
+
export function unreadReportCounts(
|
|
56
|
+
graph: DefinitionGraph,
|
|
57
|
+
reports: BlockReport[],
|
|
58
|
+
) {
|
|
59
|
+
const counts: Record<string, number> = Object.create(null);
|
|
60
|
+
for (const report of reports)
|
|
61
|
+
if (report.unread)
|
|
62
|
+
for (const id of reportBlocks(graph, report))
|
|
63
|
+
counts[id] = (counts[id] || 0) + 1;
|
|
64
|
+
return counts;
|
|
65
|
+
}
|
|
66
|
+
export function reportsForBlock(
|
|
67
|
+
graph: DefinitionGraph,
|
|
68
|
+
reports: BlockReport[],
|
|
69
|
+
block: string,
|
|
70
|
+
) {
|
|
71
|
+
const id = resolvedReportBlock(graph, block);
|
|
72
|
+
return reports.filter((report) => reportBlocks(graph, report).has(id));
|
|
73
|
+
}
|