@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,203 @@
|
|
|
1
|
+
import { readGit } from "./git-refs";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
existsSync,
|
|
5
|
+
lstatSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
realpathSync,
|
|
10
|
+
renameSync,
|
|
11
|
+
unlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
15
|
+
import type { DefinitionGraph } from "./model";
|
|
16
|
+
export class WorkspaceConflict extends Error {}
|
|
17
|
+
export const noteRevision = (body: string) =>
|
|
18
|
+
createHash("sha256").update(body).digest("hex");
|
|
19
|
+
export function checkedPath(root: string, file: string, create = false) {
|
|
20
|
+
if (isAbsolute(file) || file.includes("\\") || file.includes("\0"))
|
|
21
|
+
throw Error("Invalid repository path");
|
|
22
|
+
const base = realpathSync(root),
|
|
23
|
+
path = resolve(base, file);
|
|
24
|
+
if (!relative(base, path) || relative(base, path).startsWith(".."))
|
|
25
|
+
throw Error("Path must stay in the repository");
|
|
26
|
+
let current = path;
|
|
27
|
+
while (!existsSync(current)) current = dirname(current);
|
|
28
|
+
const resolved = realpathSync(current);
|
|
29
|
+
if (
|
|
30
|
+
relative(base, resolved).startsWith("..") ||
|
|
31
|
+
isAbsolute(relative(base, resolved))
|
|
32
|
+
)
|
|
33
|
+
throw Error("Linked path leaves the repository");
|
|
34
|
+
if (existsSync(path) && lstatSync(path).isSymbolicLink())
|
|
35
|
+
throw Error("Edit the original file instead of a symlink");
|
|
36
|
+
if (!create && !existsSync(path)) throw Error("File no longer exists");
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
export function blockNoteFile(block: string) {
|
|
40
|
+
const slug = block
|
|
41
|
+
.split("/")
|
|
42
|
+
.at(-1)!
|
|
43
|
+
.replace(/[^a-zA-Z0-9_-]/g, "-")
|
|
44
|
+
.slice(0, 48);
|
|
45
|
+
return `docs/fractory/blocks/${slug}-${noteRevision(block).slice(0, 12)}.md`;
|
|
46
|
+
}
|
|
47
|
+
export function blockNotes(
|
|
48
|
+
graph: DefinitionGraph,
|
|
49
|
+
block: string,
|
|
50
|
+
root?: string,
|
|
51
|
+
) {
|
|
52
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
53
|
+
const owner = byId.get(block);
|
|
54
|
+
if (!owner) throw Error("Unknown block");
|
|
55
|
+
const own = blockNoteFile(block);
|
|
56
|
+
const documents = [
|
|
57
|
+
{ file: own, label: "Block notes", owner: block, inherited: false },
|
|
58
|
+
];
|
|
59
|
+
const seen = new Set([own]);
|
|
60
|
+
if (root) {
|
|
61
|
+
const directory = own.replace(/\.md$/, "");
|
|
62
|
+
try {
|
|
63
|
+
for (const name of readdirSync(checkedPath(root, directory))
|
|
64
|
+
.sort()
|
|
65
|
+
.slice(0, 32)) {
|
|
66
|
+
if (!/^[a-zA-Z0-9_-]+\.md$/.test(name)) continue;
|
|
67
|
+
const file = directory + "/" + name;
|
|
68
|
+
seen.add(file);
|
|
69
|
+
documents.push({
|
|
70
|
+
file,
|
|
71
|
+
label: name.replace(/\.md$/, "").replace(/-/g, " "),
|
|
72
|
+
owner: block,
|
|
73
|
+
inherited: false,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
/* An additional-pages directory is optional. */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let current = owner;
|
|
81
|
+
const visited = new Set<string>();
|
|
82
|
+
while (current && !visited.has(current.id)) {
|
|
83
|
+
visited.add(current.id);
|
|
84
|
+
for (const file of current.attachments?.docs || []) {
|
|
85
|
+
if (!/\.(md|markdown)$/i.test(file) || seen.has(file)) continue;
|
|
86
|
+
seen.add(file);
|
|
87
|
+
documents.push({
|
|
88
|
+
file,
|
|
89
|
+
label: file.split("/").at(-1)!,
|
|
90
|
+
owner: current.id,
|
|
91
|
+
inherited: current.id !== block,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
current = byId.get(current.parent || "")!;
|
|
95
|
+
}
|
|
96
|
+
return documents;
|
|
97
|
+
}
|
|
98
|
+
export function readBlockNote(
|
|
99
|
+
root: string,
|
|
100
|
+
graph: DefinitionGraph,
|
|
101
|
+
block: string,
|
|
102
|
+
file?: string,
|
|
103
|
+
) {
|
|
104
|
+
const documents = blockNotes(graph, block, root).map((document) => {
|
|
105
|
+
// A proposed note filename is not a document yet. Prefer documentation
|
|
106
|
+
// already on disk, while keeping the empty block note available to create.
|
|
107
|
+
let exists = false;
|
|
108
|
+
try {
|
|
109
|
+
const path = checkedPath(root, document.file, true);
|
|
110
|
+
exists = existsSync(path) && lstatSync(path).isFile();
|
|
111
|
+
} catch {
|
|
112
|
+
// Explicit selection still goes through checkedPath below and fails.
|
|
113
|
+
}
|
|
114
|
+
let label = document.label;
|
|
115
|
+
if (exists)
|
|
116
|
+
try {
|
|
117
|
+
const path = checkedPath(root, document.file);
|
|
118
|
+
if (lstatSync(path).size <= 128000)
|
|
119
|
+
label =
|
|
120
|
+
/^#\s+(.+)$/m.exec(readFileSync(path, "utf8"))?.[1]?.trim() ||
|
|
121
|
+
label;
|
|
122
|
+
} catch {}
|
|
123
|
+
return { ...document, label, exists };
|
|
124
|
+
});
|
|
125
|
+
const selected = file
|
|
126
|
+
? documents.find((d) => d.file === file)
|
|
127
|
+
: documents.find((d) => d.exists && !d.inherited) ||
|
|
128
|
+
documents.find((d) => d.exists) ||
|
|
129
|
+
documents[0];
|
|
130
|
+
if (!selected) throw Error("This document is not attached to the block");
|
|
131
|
+
const path = checkedPath(root, selected.file, true);
|
|
132
|
+
if (!existsSync(path))
|
|
133
|
+
return { documents, file: selected.file, body: "", revision: null };
|
|
134
|
+
if (lstatSync(path).size > 128_000)
|
|
135
|
+
throw Error("This note exceeds the 128 KB editor limit");
|
|
136
|
+
const body = readFileSync(path, "utf8");
|
|
137
|
+
return { documents, file: selected.file, body, revision: noteRevision(body) };
|
|
138
|
+
}
|
|
139
|
+
export function saveBlockNote(
|
|
140
|
+
root: string,
|
|
141
|
+
graph: DefinitionGraph,
|
|
142
|
+
block: string,
|
|
143
|
+
file: string,
|
|
144
|
+
body: string,
|
|
145
|
+
revision: string | null,
|
|
146
|
+
) {
|
|
147
|
+
if (Buffer.byteLength(body) > 128_000)
|
|
148
|
+
throw Error("Keep this note below 128 KB");
|
|
149
|
+
const current = readBlockNote(root, graph, block, file);
|
|
150
|
+
if (current.revision !== revision)
|
|
151
|
+
throw new WorkspaceConflict(
|
|
152
|
+
"This note changed on disk. Reload it before saving.",
|
|
153
|
+
);
|
|
154
|
+
const path = checkedPath(root, file, true);
|
|
155
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
156
|
+
checkedPath(root, file, true);
|
|
157
|
+
const temporary = join(dirname(path), `.fractory-${crypto.randomUUID()}.tmp`);
|
|
158
|
+
try {
|
|
159
|
+
writeFileSync(temporary, body, { flag: "wx", mode: 0o600 });
|
|
160
|
+
renameSync(temporary, path);
|
|
161
|
+
} finally {
|
|
162
|
+
if (existsSync(temporary)) unlinkSync(temporary);
|
|
163
|
+
}
|
|
164
|
+
return readBlockNote(root, graph, block, file);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Read a reference without checking it out or borrowing uncommitted Markdown. */
|
|
168
|
+
export function readBlockNoteAt(
|
|
169
|
+
root: string,
|
|
170
|
+
graph: DefinitionGraph,
|
|
171
|
+
block: string,
|
|
172
|
+
ref: string,
|
|
173
|
+
file?: string,
|
|
174
|
+
) {
|
|
175
|
+
const bodies = new Map<string, string>();
|
|
176
|
+
const documents = blockNotes(graph, block).map((d) => {
|
|
177
|
+
let body: string | undefined;
|
|
178
|
+
try {
|
|
179
|
+
body = readGit(root, ["show", `${ref}:${d.file}`]);
|
|
180
|
+
if (Buffer.byteLength(body) > 128000)
|
|
181
|
+
throw Error("Note exceeds read budget");
|
|
182
|
+
bodies.set(d.file, body);
|
|
183
|
+
} catch {}
|
|
184
|
+
return {
|
|
185
|
+
...d,
|
|
186
|
+
exists: body !== undefined,
|
|
187
|
+
label: body ? /^#\s+(.+)$/m.exec(body)?.[1]?.trim() || d.label : d.label,
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
const selected = file
|
|
191
|
+
? documents.find((d) => d.file === file)
|
|
192
|
+
: documents.find((d) => d.exists && !d.inherited) ||
|
|
193
|
+
documents.find((d) => d.exists) ||
|
|
194
|
+
documents[0];
|
|
195
|
+
if (!selected) throw Error("This document is not attached to the block");
|
|
196
|
+
const body = bodies.get(selected.file) || "";
|
|
197
|
+
return {
|
|
198
|
+
documents,
|
|
199
|
+
file: selected.file,
|
|
200
|
+
body,
|
|
201
|
+
revision: bodies.has(selected.file) ? noteRevision(body) : null,
|
|
202
|
+
};
|
|
203
|
+
}
|