@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.
Files changed (285) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +28 -2
  3. package/dist/activity-volume.d.ts +18 -0
  4. package/dist/activity-volume.js +94 -0
  5. package/dist/annotations.d.ts +122 -0
  6. package/dist/annotations.js +304 -0
  7. package/dist/benchmark-cli.d.ts +1 -0
  8. package/dist/benchmark-cli.js +95 -0
  9. package/dist/benchmark-worker.d.ts +2 -0
  10. package/dist/benchmark-worker.js +22 -0
  11. package/dist/benchmarks.d.ts +19 -0
  12. package/dist/benchmarks.js +414 -0
  13. package/dist/bin.d.ts +2 -0
  14. package/dist/bin.js +63 -0
  15. package/dist/block-cli.d.ts +1 -0
  16. package/dist/block-cli.js +88 -0
  17. package/dist/block-documents.d.ts +35 -0
  18. package/dist/block-documents.js +84 -0
  19. package/dist/change-impact.d.ts +55 -0
  20. package/dist/change-impact.js +223 -0
  21. package/dist/check-source.d.ts +2 -0
  22. package/dist/check-source.js +66 -0
  23. package/dist/checks-model.d.ts +64 -0
  24. package/dist/checks-model.js +36 -0
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +359 -0
  27. package/dist/code-model.d.ts +38 -0
  28. package/dist/code-model.js +94 -0
  29. package/dist/code-store.d.ts +9 -0
  30. package/dist/code-store.js +79 -0
  31. package/dist/compare-artifact.d.ts +6 -0
  32. package/dist/compare-artifact.js +277 -0
  33. package/dist/compare.d.ts +81 -0
  34. package/dist/compare.js +291 -0
  35. package/dist/compiler.d.ts +10 -0
  36. package/dist/compiler.js +1240 -0
  37. package/dist/compose.d.ts +9 -0
  38. package/dist/compose.js +72 -0
  39. package/dist/core.d.ts +87 -0
  40. package/dist/core.js +207 -0
  41. package/dist/coverage-cli.d.ts +1 -0
  42. package/dist/coverage-cli.js +42 -0
  43. package/dist/declaration-sources.d.ts +3 -0
  44. package/dist/declaration-sources.js +51 -0
  45. package/dist/declared-graph.d.ts +3 -0
  46. package/dist/declared-graph.js +67 -0
  47. package/dist/display-name.d.ts +2 -0
  48. package/dist/display-name.js +8 -0
  49. package/dist/error-heat.d.ts +58 -0
  50. package/dist/error-heat.js +96 -0
  51. package/dist/evidence.d.ts +3 -0
  52. package/dist/evidence.js +68 -0
  53. package/dist/factory-graph.d.ts +7 -0
  54. package/dist/factory-graph.js +389 -0
  55. package/dist/factory-model.d.ts +111 -0
  56. package/dist/factory-model.js +1 -0
  57. package/dist/git-code.d.ts +47 -0
  58. package/dist/git-code.js +352 -0
  59. package/dist/git-refs.d.ts +4 -0
  60. package/dist/git-refs.js +37 -0
  61. package/dist/history-activity.d.ts +4 -0
  62. package/dist/history-activity.js +129 -0
  63. package/dist/history-churn.d.ts +36 -0
  64. package/dist/history-churn.js +302 -0
  65. package/dist/history-git.d.ts +21 -0
  66. package/dist/history-git.js +125 -0
  67. package/dist/history-ledger.d.ts +43 -0
  68. package/dist/history-ledger.js +450 -0
  69. package/dist/history-ownership.d.ts +10 -0
  70. package/dist/history-ownership.js +75 -0
  71. package/dist/history-source.d.ts +13 -0
  72. package/dist/history-source.js +100 -0
  73. package/dist/integrations-cli.d.ts +2 -0
  74. package/dist/integrations-cli.js +159 -0
  75. package/dist/interface-map.d.ts +15 -0
  76. package/dist/interface-map.js +125 -0
  77. package/dist/issue-cache.d.ts +9 -0
  78. package/dist/issue-cache.js +68 -0
  79. package/dist/issue-cli.d.ts +1 -0
  80. package/dist/issue-cli.js +89 -0
  81. package/dist/issue-links.d.ts +15 -0
  82. package/dist/issue-links.js +125 -0
  83. package/dist/linear-issues.d.ts +19 -0
  84. package/dist/linear-issues.js +124 -0
  85. package/dist/local-runtime.d.ts +8 -0
  86. package/dist/local-runtime.js +59 -0
  87. package/dist/map-activity.d.ts +73 -0
  88. package/dist/map-activity.js +234 -0
  89. package/dist/map-model.d.ts +5 -0
  90. package/dist/map-model.js +166 -0
  91. package/dist/map-quality.d.ts +20 -0
  92. package/dist/map-quality.js +61 -0
  93. package/dist/mapping-coverage.d.ts +87 -0
  94. package/dist/mapping-coverage.js +404 -0
  95. package/dist/model.d.ts +186 -0
  96. package/dist/model.js +66 -0
  97. package/dist/operation-benchmark-worker.d.ts +2 -0
  98. package/dist/operation-benchmark-worker.js +60 -0
  99. package/dist/operation-benchmark.d.ts +29 -0
  100. package/dist/operation-benchmark.js +1 -0
  101. package/dist/otel-metrics.d.ts +21 -0
  102. package/dist/otel-metrics.js +146 -0
  103. package/dist/performance-model.d.ts +185 -0
  104. package/dist/performance-model.js +396 -0
  105. package/dist/product-map.d.ts +71 -0
  106. package/dist/product-map.js +197 -0
  107. package/dist/provider-access.cjs +207 -0
  108. package/dist/provider-access.d.cts +14 -0
  109. package/dist/public-boundaries.d.ts +13 -0
  110. package/dist/public-boundaries.js +115 -0
  111. package/dist/reports-cli.d.ts +1 -0
  112. package/dist/reports-cli.js +111 -0
  113. package/dist/reports-model.d.ts +27 -0
  114. package/dist/reports-model.js +39 -0
  115. package/dist/reports.d.ts +23 -0
  116. package/dist/reports.js +223 -0
  117. package/dist/repository-map.d.ts +22 -0
  118. package/dist/repository-map.js +153 -0
  119. package/dist/resource-cache.d.ts +17 -0
  120. package/dist/resource-cache.js +65 -0
  121. package/dist/review-cli.d.ts +19 -0
  122. package/dist/review-cli.js +224 -0
  123. package/dist/review.d.ts +48 -0
  124. package/dist/review.js +289 -0
  125. package/dist/runtime-metrics.d.ts +26 -0
  126. package/dist/runtime-metrics.js +290 -0
  127. package/dist/scope.d.ts +14 -0
  128. package/dist/scope.js +168 -0
  129. package/dist/sentry-activity.d.ts +39 -0
  130. package/dist/sentry-activity.js +174 -0
  131. package/dist/sentry.d.ts +130 -0
  132. package/dist/sentry.js +369 -0
  133. package/dist/service-release.d.ts +16 -0
  134. package/dist/service-release.js +14 -0
  135. package/dist/setup-cli.d.ts +2 -0
  136. package/dist/setup-cli.js +52 -0
  137. package/dist/setup-kit.cjs +163 -0
  138. package/dist/setup-kit.d.cts +32 -0
  139. package/dist/source-index.d.ts +37 -0
  140. package/dist/source-index.js +170 -0
  141. package/dist/source-review-git.d.ts +7 -0
  142. package/dist/source-review-git.js +105 -0
  143. package/dist/source-review.d.ts +18 -0
  144. package/dist/source-review.js +573 -0
  145. package/dist/telemetry.d.ts +17 -0
  146. package/dist/telemetry.js +51 -0
  147. package/dist/time-window.d.ts +9 -0
  148. package/dist/time-window.js +35 -0
  149. package/dist/trace-evidence.d.ts +23 -0
  150. package/dist/trace-evidence.js +55 -0
  151. package/dist/trace-model.d.ts +26 -0
  152. package/dist/trace-model.js +1 -0
  153. package/dist/tracing.d.ts +44 -0
  154. package/dist/tracing.js +123 -0
  155. package/dist/work-check.d.ts +18 -0
  156. package/dist/work-check.js +115 -0
  157. package/dist/work-cli.d.ts +1 -0
  158. package/dist/work-cli.js +176 -0
  159. package/dist/work-context.d.ts +59 -0
  160. package/dist/work-context.js +594 -0
  161. package/dist/work-intents.d.ts +6 -0
  162. package/dist/work-intents.js +140 -0
  163. package/dist/work-items.d.ts +58 -0
  164. package/dist/work-items.js +86 -0
  165. package/dist/work-lock-check.d.ts +12 -0
  166. package/dist/work-lock-check.js +339 -0
  167. package/dist/work-locks.d.ts +10 -0
  168. package/dist/work-locks.js +98 -0
  169. package/dist/work-model.d.ts +119 -0
  170. package/dist/work-model.js +310 -0
  171. package/dist/work-review-git.d.ts +8 -0
  172. package/dist/work-review-git.js +111 -0
  173. package/dist/work-review.d.ts +26 -0
  174. package/dist/work-review.js +426 -0
  175. package/dist/work-switcher-model.d.ts +43 -0
  176. package/dist/work-switcher-model.js +79 -0
  177. package/dist/work-switcher.d.ts +6 -0
  178. package/dist/work-switcher.js +171 -0
  179. package/dist/working-cli.d.ts +1 -0
  180. package/dist/working-cli.js +33 -0
  181. package/dist/working-code.d.ts +74 -0
  182. package/dist/working-code.js +421 -0
  183. package/dist/workspace-notes.d.ts +71 -0
  184. package/dist/workspace-notes.js +177 -0
  185. package/dist/workspace-tests.d.ts +21 -0
  186. package/dist/workspace-tests.js +573 -0
  187. package/package.json +547 -4
  188. package/src/activity-volume.ts +149 -0
  189. package/src/annotations.ts +485 -0
  190. package/src/benchmark-cli.ts +118 -0
  191. package/src/benchmark-worker.ts +22 -0
  192. package/src/benchmarks.ts +493 -0
  193. package/src/bin.ts +54 -0
  194. package/src/block-cli.ts +106 -0
  195. package/src/block-documents.ts +117 -0
  196. package/src/change-impact.ts +280 -0
  197. package/src/check-source.ts +82 -0
  198. package/src/checks-model.ts +108 -0
  199. package/src/cli.ts +440 -0
  200. package/src/code-model.ts +159 -0
  201. package/src/code-store.ts +98 -0
  202. package/src/compare-artifact.ts +314 -0
  203. package/src/compare.ts +440 -0
  204. package/src/compiler.ts +1512 -0
  205. package/src/compose.ts +94 -0
  206. package/src/core.ts +361 -0
  207. package/src/coverage-cli.ts +52 -0
  208. package/src/declaration-sources.ts +69 -0
  209. package/src/declared-graph.ts +75 -0
  210. package/src/display-name.ts +8 -0
  211. package/src/error-heat.ts +161 -0
  212. package/src/evidence.ts +94 -0
  213. package/src/factory-graph.ts +462 -0
  214. package/src/factory-model.ts +82 -0
  215. package/src/git-code.ts +461 -0
  216. package/src/git-refs.ts +43 -0
  217. package/src/history-activity.ts +146 -0
  218. package/src/history-churn.ts +416 -0
  219. package/src/history-git.ts +163 -0
  220. package/src/history-ledger.ts +636 -0
  221. package/src/history-ownership.ts +116 -0
  222. package/src/history-source.ts +117 -0
  223. package/src/integrations-cli.ts +187 -0
  224. package/src/interface-map.ts +166 -0
  225. package/src/issue-cache.ts +96 -0
  226. package/src/issue-cli.ts +137 -0
  227. package/src/issue-links.ts +153 -0
  228. package/src/linear-issues.ts +154 -0
  229. package/src/local-runtime.ts +70 -0
  230. package/src/map-activity.ts +309 -0
  231. package/src/map-model.ts +213 -0
  232. package/src/map-quality.ts +66 -0
  233. package/src/mapping-coverage.ts +570 -0
  234. package/src/model.ts +228 -0
  235. package/src/operation-benchmark-worker.ts +60 -0
  236. package/src/operation-benchmark.ts +28 -0
  237. package/src/otel-metrics.ts +176 -0
  238. package/src/performance-model.ts +575 -0
  239. package/src/product-map.ts +271 -0
  240. package/src/provider-access.cjs +207 -0
  241. package/src/provider-access.d.cts +14 -0
  242. package/src/public-boundaries.ts +143 -0
  243. package/src/reports-cli.ts +125 -0
  244. package/src/reports-model.ts +73 -0
  245. package/src/reports.ts +276 -0
  246. package/src/repository-map.ts +191 -0
  247. package/src/resource-cache.ts +76 -0
  248. package/src/review-cli.ts +256 -0
  249. package/src/review.ts +376 -0
  250. package/src/runtime-metrics.ts +386 -0
  251. package/src/scope.ts +192 -0
  252. package/src/sentry-activity.ts +234 -0
  253. package/src/sentry.ts +545 -0
  254. package/src/service-release.ts +18 -0
  255. package/src/setup-cli.ts +58 -0
  256. package/src/setup-kit.cjs +163 -0
  257. package/src/setup-kit.d.cts +32 -0
  258. package/src/source-index.ts +208 -0
  259. package/src/source-review-git.ts +131 -0
  260. package/src/source-review.ts +736 -0
  261. package/src/telemetry.ts +68 -0
  262. package/src/time-window.ts +51 -0
  263. package/src/trace-evidence.ts +80 -0
  264. package/src/trace-model.ts +26 -0
  265. package/src/tracing.ts +165 -0
  266. package/src/work-check.ts +149 -0
  267. package/src/work-cli.ts +229 -0
  268. package/src/work-context.ts +753 -0
  269. package/src/work-intents.ts +196 -0
  270. package/src/work-items.ts +151 -0
  271. package/src/work-lock-check.ts +549 -0
  272. package/src/work-locks.ts +108 -0
  273. package/src/work-model.ts +466 -0
  274. package/src/work-review-git.ts +130 -0
  275. package/src/work-review.ts +573 -0
  276. package/src/work-switcher-model.ts +121 -0
  277. package/src/work-switcher.ts +191 -0
  278. package/src/working-cli.ts +38 -0
  279. package/src/working-code.ts +582 -0
  280. package/src/workspace-notes.ts +203 -0
  281. package/src/workspace-tests.ts +654 -0
  282. package/toolkit/GUIDE.md +354 -0
  283. package/toolkit/SKILL.md +142 -0
  284. package/toolkit/bin/fractory +2 -0
  285. package/toolkit/build.json +1 -0
@@ -0,0 +1,22 @@
1
+ /** Isolated Bun entrypoint; application code is loaded only after an explicit run. */
2
+ export const benchmarkWorker = `
3
+ import { writeFileSync } from 'node:fs';
4
+ import { pathToFileURL } from 'node:url';
5
+ const [file, report] = process.argv.slice(1);
6
+ try {
7
+ const { default: bench } = await import(pathToFileURL(file).href);
8
+ if (!bench || typeof bench.run !== 'function' || typeof bench.warmup !== 'function' || !Array.isArray(bench.tasks)) throw Error('Export a Tinybench Bench instance as default.');
9
+ if (bench.tasks.length < 1 || bench.tasks.length > 12) throw Error('Keep each suite between 1 and 12 cases.');
10
+ bench.time = Math.max(100, Math.min(1000, bench.time || 250));
11
+ bench.iterations = Math.max(20, Math.min(100000, bench.iterations || 20));
12
+ bench.warmupTime = 100; bench.warmupIterations = 20;
13
+ await bench.warmup(); await bench.run();
14
+ const cases = bench.tasks.map(task => {
15
+ const r = task.result; if (r?.error) throw r.error;
16
+ if (!r || !Number.isFinite(r.mean) || r.mean <= 0 || !r.samples.length) throw Error('No valid timing samples for ' + task.name);
17
+ const sorted = [...r.samples].sort((a,b) => a-b);
18
+ return { name: task.name, samples: sorted.length, meanMs: r.mean, marginMs: Number.isFinite(r.moe) ? r.moe : r.mean, p95Ms: sorted[Math.min(sorted.length-1, Math.ceil(sorted.length*.95)-1)], hz: r.hz };
19
+ });
20
+ writeFileSync(report, JSON.stringify({ cases, runtime: Bun.version }));
21
+ } catch (error) { console.error(error); process.exitCode = 1; }
22
+ `;
@@ -0,0 +1,19 @@
1
+ import type { DefinitionGraph } from "./model.js";
2
+ import type { BenchmarkRun, BenchmarkView } from "./performance-model.js";
3
+ export { Bench } from "tinybench";
4
+ export declare function benchmarkPlans(root: string, graph: DefinitionGraph): BenchmarkView["plans"];
5
+ export declare class BenchmarkRunner {
6
+ readonly root: string;
7
+ private graph;
8
+ private active?;
9
+ private completions;
10
+ wait(id: string): Promise<BenchmarkRun>;
11
+ constructor(root: string, graph: DefinitionGraph);
12
+ private directory;
13
+ view(): BenchmarkView;
14
+ private save;
15
+ start(file: string): BenchmarkRun;
16
+ stop(id: string): void;
17
+ baseline(id: string): BenchmarkView;
18
+ private git;
19
+ }
@@ -0,0 +1,414 @@
1
+ import { spawn, execFileSync } from "node:child_process";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync, unlinkSync, statSync, } from "node:fs";
4
+ import { join, dirname } from "node:path";
5
+ import { cpus, platform, arch, hostname, release } from "node:os";
6
+ import ts from "typescript";
7
+ import { checkedPath } from "./workspace-notes.js";
8
+ import { benchmarkWorker } from "./benchmark-worker.js";
9
+ import { operationBenchmarkWorker } from "./operation-benchmark-worker.js";
10
+ export { Bench } from "tinybench";
11
+ const hash = (value) => createHash("sha256").update(value).digest("hex");
12
+ function alive(run) {
13
+ if (!run.runnerPid ||
14
+ !run.heartbeatAt ||
15
+ Date.now() - run.heartbeatAt > 30000)
16
+ return false;
17
+ try {
18
+ process.kill(run.runnerPid, 0);
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ export function benchmarkPlans(root, graph) {
26
+ const plans = new Map();
27
+ for (const node of graph.elements)
28
+ for (const file of node.attachments?.benchmarks || []) {
29
+ if (!/\.bench\.[cm]?[jt]sx?$/.test(file))
30
+ continue;
31
+ try {
32
+ if (statSync(checkedPath(root, file)).size > 128000)
33
+ continue;
34
+ }
35
+ catch {
36
+ continue;
37
+ }
38
+ const plan = plans.get(file) || {
39
+ file,
40
+ blocks: [],
41
+ label: node.label ||
42
+ file
43
+ .split("/")
44
+ .at(-1)
45
+ .replace(/\.bench\.[^.]+$/, "")
46
+ .replace(/-/g, " "),
47
+ };
48
+ // Metadata is read as syntax; listing never imports or runs a suite.
49
+ const syntax = ts.createSourceFile(file, readFileSync(checkedPath(root, file), "utf8"), ts.ScriptTarget.Latest, true);
50
+ let definition;
51
+ for (const statement of syntax.statements)
52
+ if (ts.isExportAssignment(statement)) {
53
+ let value = statement.expression;
54
+ while (ts.isSatisfiesExpression(value) ||
55
+ ts.isAsExpression(value) ||
56
+ ts.isParenthesizedExpression(value))
57
+ value = value.expression;
58
+ if (ts.isObjectLiteralExpression(value))
59
+ definition = value;
60
+ }
61
+ if (definition) {
62
+ const literals = Object.fromEntries(definition.properties.flatMap((property) => ts.isPropertyAssignment(property) &&
63
+ property.name &&
64
+ ts.isIdentifier(property.name) &&
65
+ ts.isStringLiteral(property.initializer)
66
+ ? [[property.name.text, property.initializer.text]]
67
+ : []));
68
+ if (literals.kind === "operation") {
69
+ plan.kind = "operation";
70
+ if (literals.name)
71
+ plan.label = literals.name;
72
+ for (const key of ["description", "startsWhen", "endsWhen"])
73
+ if (literals[key])
74
+ plan[key] = literals[key];
75
+ const attempts = definition.properties.find((p) => ts.isPropertyAssignment(p) &&
76
+ p.name?.getText(syntax) === "attempts");
77
+ if (attempts &&
78
+ ts.isPropertyAssignment(attempts) &&
79
+ ts.isNumericLiteral(attempts.initializer))
80
+ plan.attempts = Number(attempts.initializer.text);
81
+ }
82
+ }
83
+ plan.kind ||= "function";
84
+ plan.blocks.push(node.implementationBlock || node.id);
85
+ plans.set(file, plan);
86
+ }
87
+ return [...plans.values()].map((plan) => ({
88
+ ...plan,
89
+ blocks: [...new Set(plan.blocks)],
90
+ }));
91
+ }
92
+ function fingerprint(root, graph, file) {
93
+ const paths = new Set([file, "bun.lock", "package.json"]);
94
+ const nodes = graph.elements.filter((node) => node.attachments?.benchmarks?.includes(file));
95
+ for (const node of nodes)
96
+ for (const source of node.sources || (node.source ? [node.source] : []))
97
+ paths.add(source.file);
98
+ const visited = new Set(), values = [];
99
+ const visit = (file) => {
100
+ if (visited.has(file))
101
+ return;
102
+ visited.add(file);
103
+ if (visited.size > 512)
104
+ throw Error("Benchmark source fingerprint exceeds 512 files");
105
+ let text;
106
+ try {
107
+ const path = checkedPath(root, file);
108
+ if (statSync(path).size > 4 * 1024 * 1024)
109
+ throw Error("Source too large");
110
+ text = readFileSync(path, "utf8");
111
+ }
112
+ catch {
113
+ values.push(file + ":unavailable");
114
+ return;
115
+ }
116
+ values.push(file + ":" + hash(text));
117
+ if (!/\.[cm]?[jt]sx?$/.test(file))
118
+ return;
119
+ for (const entry of ts.preProcessFile(text).importedFiles) {
120
+ if (!entry.fileName.startsWith("."))
121
+ continue;
122
+ const base = join(dirname(file), entry.fileName).replace(/\.js$/, "");
123
+ const candidate = [
124
+ base,
125
+ base + ".ts",
126
+ base + ".tsx",
127
+ base + ".js",
128
+ join(base, "index.ts"),
129
+ ].find((name) => {
130
+ try {
131
+ return statSync(checkedPath(root, name)).isFile();
132
+ }
133
+ catch {
134
+ return false;
135
+ }
136
+ });
137
+ if (candidate)
138
+ visit(candidate);
139
+ }
140
+ };
141
+ for (const path of paths)
142
+ visit(path);
143
+ return hash(values.sort().join("\n"));
144
+ }
145
+ export class BenchmarkRunner {
146
+ root;
147
+ graph;
148
+ active;
149
+ completions = new Map();
150
+ async wait(id) {
151
+ const completion = this.completions.get(id);
152
+ if (completion)
153
+ return completion;
154
+ const run = this.view().runs.find((run) => run.id === id);
155
+ if (run && (run.status === "passed" || run.status === "failed"))
156
+ return run;
157
+ throw Error("This runner does not own an active benchmark with that ID.");
158
+ }
159
+ constructor(root, graph) {
160
+ this.root = root;
161
+ this.graph = graph;
162
+ }
163
+ directory() {
164
+ return checkedPath(this.root, ".fractal/benchmarks", true);
165
+ }
166
+ view() {
167
+ const runs = [];
168
+ if (existsSync(this.directory()))
169
+ for (const file of readdirSync(this.directory())
170
+ .filter((file) => /^[a-f0-9-]{36}\.json$/.test(file))
171
+ .sort((a, b) => statSync(join(this.directory(), b)).mtimeMs -
172
+ statSync(join(this.directory(), a)).mtimeMs)
173
+ .slice(0, 300)) {
174
+ try {
175
+ const path = checkedPath(this.root, `.fractal/benchmarks/${file}`);
176
+ if (statSync(path).size > 256000)
177
+ continue;
178
+ const run = JSON.parse(readFileSync(path, "utf8"));
179
+ if (run.id && Array.isArray(run.cases))
180
+ runs.push((run.status === "running" || run.status === "queued") &&
181
+ !alive(run)
182
+ ? {
183
+ ...run,
184
+ status: "failed",
185
+ error: "Interrupted when the benchmark host stopped",
186
+ }
187
+ : run);
188
+ }
189
+ catch { }
190
+ }
191
+ if (this.active) {
192
+ const index = runs.findIndex((run) => run.id === this.active.run.id);
193
+ if (index >= 0)
194
+ runs.splice(index, 1);
195
+ runs.push(this.active.run);
196
+ }
197
+ let baselines = {};
198
+ try {
199
+ baselines = JSON.parse(readFileSync(checkedPath(this.root, ".fractal/benchmarks/baselines.json"), "utf8"));
200
+ }
201
+ catch { }
202
+ for (const id of Object.values(baselines))
203
+ if (/^[a-f0-9-]{36}$/.test(id) && !runs.some((run) => run.id === id))
204
+ try {
205
+ const path = checkedPath(this.root, `.fractal/benchmarks/${id}.json`);
206
+ if (statSync(path).size < 256000)
207
+ runs.push(JSON.parse(readFileSync(path, "utf8")));
208
+ }
209
+ catch { }
210
+ const sorted = runs.sort((a, b) => b.at.localeCompare(a.at));
211
+ return {
212
+ plans: benchmarkPlans(this.root, this.graph),
213
+ runs: sorted.filter((run, index) => index < 100 || Object.values(baselines).includes(run.id)),
214
+ baselines,
215
+ };
216
+ }
217
+ save(run) {
218
+ mkdirSync(this.directory(), { recursive: true });
219
+ const path = checkedPath(this.root, `.fractal/benchmarks/${run.id}.json`, true), temporary = path + ".tmp";
220
+ writeFileSync(temporary, JSON.stringify(run), { mode: 0o600 });
221
+ renameSync(temporary, path);
222
+ }
223
+ start(file) {
224
+ if (this.active ||
225
+ this.view().runs.some((run) => run.status === "running" || run.status === "queued"))
226
+ throw Error("A benchmark is already running. Wait or stop it before starting another.");
227
+ const plan = benchmarkPlans(this.root, this.graph).find((plan) => plan.file === file);
228
+ if (!plan)
229
+ throw Error("Choose a benchmark attached to this factory.");
230
+ const source = checkedPath(this.root, file), status = this.git(["status", "--porcelain", "-uno"]), baseCommit = this.git(["rev-parse", "HEAD"]);
231
+ const untracked = this.git([
232
+ "ls-files",
233
+ "--others",
234
+ "--exclude-standard",
235
+ "-z",
236
+ ]);
237
+ const codeDigest = fingerprint(this.root, this.graph, file);
238
+ const machine = [platform(), arch(), cpus()[0]?.model || "unknown"].join(" · ");
239
+ const run = {
240
+ id: randomUUID(),
241
+ file,
242
+ blockIds: plan.blocks,
243
+ at: new Date().toISOString(),
244
+ status: "running",
245
+ baseCommit,
246
+ commit: status || untracked ? null : baseCommit || null,
247
+ codeDigest,
248
+ scenario: hash(readFileSync(source, "utf8")),
249
+ environment: "",
250
+ machine,
251
+ cases: [],
252
+ output: "",
253
+ kind: plan.kind || "function",
254
+ runnerPid: process.pid,
255
+ heartbeatAt: Date.now(),
256
+ };
257
+ this.active = { run };
258
+ this.save(run);
259
+ let resolveCompletion;
260
+ let rejectCompletion;
261
+ const completion = new Promise((resolve, reject) => {
262
+ resolveCompletion = resolve;
263
+ rejectCompletion = reject;
264
+ });
265
+ // The UI observes saved heartbeats; the CLI awaits this exact worker instead of reparsing the map.
266
+ void completion.catch(() => { });
267
+ this.completions.set(run.id, completion);
268
+ if (this.completions.size > 24)
269
+ this.completions.delete(this.completions.keys().next().value);
270
+ const outputFile = checkedPath(this.root, `.fractal/benchmarks/${run.id}.result.tmp`, true);
271
+ const child = spawn("bun", [
272
+ "-e",
273
+ `const version = Bun.version; console.log('__FRACTORY_RUNTIME__' + version);\n${plan.kind === "operation" ? operationBenchmarkWorker : benchmarkWorker}`,
274
+ source,
275
+ outputFile,
276
+ ], {
277
+ cwd: dirname(source),
278
+ stdio: ["ignore", "pipe", "pipe"],
279
+ env: { ...process.env, ELECTRON_RUN_AS_NODE: undefined },
280
+ });
281
+ this.active.child = child;
282
+ const started = Date.now();
283
+ let runtime = "unknown";
284
+ const consume = (data) => {
285
+ const text = data.toString();
286
+ runtime = /__FRACTORY_RUNTIME__([^\s]+)/.exec(text)?.[1] || runtime;
287
+ run.output = (run.output + text.replace(/__FRACTORY_RUNTIME__[^\n]*\n?/, "")).slice(-20000);
288
+ };
289
+ child.stdout?.on("data", consume);
290
+ child.stderr?.on("data", consume);
291
+ const heartbeat = setInterval(() => {
292
+ run.heartbeatAt = Date.now();
293
+ this.save(run);
294
+ }, 2000);
295
+ let timedOut = false, ended = false;
296
+ const timer = setTimeout(() => {
297
+ timedOut = true;
298
+ child.kill("SIGKILL");
299
+ }, plan.kind === "operation" ? 15 * 60_000 : 90000);
300
+ const complete = (code, error) => {
301
+ if (ended)
302
+ return;
303
+ ended = true;
304
+ clearTimeout(timer);
305
+ clearInterval(heartbeat);
306
+ run.durationMs = Date.now() - started;
307
+ run.environment = hash(hostname() +
308
+ "|" +
309
+ release() +
310
+ "|" +
311
+ machine +
312
+ "|bun:" +
313
+ runtime +
314
+ "|tinybench:2.9.0");
315
+ try {
316
+ if (code !== 0 || error)
317
+ throw Error(error ||
318
+ (timedOut
319
+ ? plan.kind === "operation"
320
+ ? "Benchmark exceeded 15 minutes"
321
+ : "Benchmark exceeded 90 seconds"
322
+ : "Benchmark process failed"));
323
+ const report = JSON.parse(readFileSync(outputFile, "utf8"));
324
+ if (typeof report.runtime === "string")
325
+ run.environment = hash(hostname() +
326
+ "|" +
327
+ release() +
328
+ "|" +
329
+ machine +
330
+ "|bun:" +
331
+ report.runtime +
332
+ "|tinybench:2.9.0");
333
+ if (!Array.isArray(report.cases) ||
334
+ report.cases.length > 12 ||
335
+ report.cases.some((item) => !Number.isFinite(item.meanMs) ||
336
+ !Number.isFinite(item.marginMs) ||
337
+ !Number.isFinite(item.p95Ms) ||
338
+ item.samples < (plan.kind === "operation" ? 1 : 20)))
339
+ throw Error("No valid benchmark results");
340
+ if (fingerprint(this.root, this.graph, file) !== codeDigest)
341
+ throw Error("Source changed during this run. Run again on a stable checkout.");
342
+ run.cases = report.cases;
343
+ if (plan.kind === "operation") {
344
+ if (report.kind !== "operation" ||
345
+ !report.target ||
346
+ !report.fixtureDigest)
347
+ throw Error("No product-operation measurement returned.");
348
+ run.target = report.target;
349
+ run.fixture = report.fixture;
350
+ run.fixtureVersion = report.fixtureVersion;
351
+ run.fixtureDescription = report.fixtureDescription;
352
+ run.scenario = hash(run.scenario + ":" + report.fixtureDigest);
353
+ run.machine = report.target.name;
354
+ run.environment = hash(report.target.url +
355
+ ":" +
356
+ report.target.measurement +
357
+ (report.target.measurement === "client" ? ":" + hostname() : ""));
358
+ }
359
+ run.status = "passed";
360
+ }
361
+ catch (cause) {
362
+ run.status = "failed";
363
+ run.error = cause instanceof Error ? cause.message : "Benchmark failed";
364
+ }
365
+ finally {
366
+ if (existsSync(outputFile))
367
+ unlinkSync(outputFile);
368
+ try {
369
+ this.save(run);
370
+ resolveCompletion(structuredClone(run));
371
+ }
372
+ catch (error) {
373
+ rejectCompletion(error);
374
+ }
375
+ if (this.active?.run.id === run.id)
376
+ this.active = undefined;
377
+ }
378
+ };
379
+ child.on("error", (error) => complete(null, error.message));
380
+ child.on("close", (code) => complete(code));
381
+ return run;
382
+ }
383
+ stop(id) {
384
+ if (this.active?.run.id !== id)
385
+ throw Error("This benchmark is not running");
386
+ this.active.child?.kill("SIGTERM");
387
+ }
388
+ baseline(id) {
389
+ const view = this.view(), run = view.runs.find((run) => run.id === id);
390
+ if (!run ||
391
+ run.status !== "passed" ||
392
+ !view.plans.some((plan) => plan.file === run.file))
393
+ throw Error("Choose a successful attached benchmark run.");
394
+ const path = checkedPath(this.root, ".fractal/benchmarks/baselines.json", true), temporary = path + ".tmp";
395
+ writeFileSync(temporary, JSON.stringify({ ...view.baselines, [run.file]: id }), { mode: 0o600 });
396
+ renameSync(temporary, path);
397
+ return this.view();
398
+ }
399
+ git(args) {
400
+ try {
401
+ return execFileSync("git", ["-c", "core.fsmonitor=false", ...args], {
402
+ cwd: this.root,
403
+ encoding: "utf8",
404
+ stdio: ["ignore", "pipe", "ignore"],
405
+ timeout: 5000,
406
+ maxBuffer: 4 * 1024 * 1024,
407
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
408
+ }).trim();
409
+ }
410
+ catch {
411
+ return "";
412
+ }
413
+ }
414
+ }
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ /** Keep native Git activity independent of the legacy inspector's definition/compiler imports. */
3
+ const args = process.argv.slice(2);
4
+ if (!args.length)
5
+ args.push("help");
6
+ try {
7
+ let output;
8
+ if (args[0] === "work") {
9
+ const { runWork } = await import("./work-cli.js");
10
+ output = await runWork(args);
11
+ }
12
+ else if (args[0] === "reports") {
13
+ const { runReports } = await import("./reports-cli.js");
14
+ output = await runReports(args);
15
+ }
16
+ else if (args[0] === "integrations") {
17
+ const { runIntegrations } = await import("./integrations-cli.js");
18
+ output = await runIntegrations(args);
19
+ }
20
+ else if (["setup", "doctor", "guide", "open"].includes(args[0])) {
21
+ const { runSetup } = await import("./setup-cli.js");
22
+ output = runSetup(args);
23
+ }
24
+ else if (args[0] === "benchmark") {
25
+ const { runBenchmark } = await import("./benchmark-cli.js");
26
+ output = await runBenchmark(args);
27
+ }
28
+ else if (args[0] === "coverage") {
29
+ const { runCoverage } = await import("./coverage-cli.js");
30
+ output = await runCoverage(args);
31
+ }
32
+ else if (["block", "tests"].includes(args[0])) {
33
+ const { runBlock } = await import("./block-cli.js");
34
+ output = await runBlock(args);
35
+ }
36
+ else if (args[0] === "review") {
37
+ const { runReview } = await import("./review-cli.js");
38
+ output = runReview(args);
39
+ }
40
+ else if (args[0] === "issues") {
41
+ const { runIssues } = await import("./issue-cli.js");
42
+ output = await runIssues(args);
43
+ }
44
+ else if (args[0] === "working" && !args.includes("--help")) {
45
+ const { runWorking } = await import("./working-cli.js");
46
+ output = await runWorking(args);
47
+ }
48
+ else {
49
+ const { run, runSentry } = await import("./cli.js");
50
+ output =
51
+ args[0] === "sentry" &&
52
+ !args.includes("--event-file") &&
53
+ !args.includes("--help")
54
+ ? await runSentry(args)
55
+ : run(args);
56
+ }
57
+ console.log(output);
58
+ }
59
+ catch (error) {
60
+ console.error(`fractory: ${error instanceof Error ? error.message : String(error)}`);
61
+ process.exitCode = 1;
62
+ }
63
+ export {};
@@ -0,0 +1 @@
1
+ export declare function runBlock(args: string[]): Promise<string>;
@@ -0,0 +1,88 @@
1
+ import { readRepositoryMap } from "./repository-map.js";
2
+ import { resolve } from "node:path";
3
+ import { blockNotes, readBlockNote } from "./workspace-notes.js";
4
+ import { listReports } from "./reports.js";
5
+ import { reportsForBlock } from "./reports-model.js";
6
+ import { checkPlan, WorkspaceTestRunner, readTestSource, } from "./workspace-tests.js";
7
+ export async function runBlock(args) {
8
+ if (args.includes("--help"))
9
+ return "fractal block [BLOCK_ID] [--docs] [--root PATH]\nfractal tests --block BLOCK_ID [--source | --run] [--file PATH] [--root PATH]";
10
+ const value = (name) => {
11
+ const i = args.indexOf(name);
12
+ return i < 0 ? undefined : args[i + 1];
13
+ };
14
+ const root = resolve(value("--root") || process.cwd());
15
+ const graph = readRepositoryMap(root);
16
+ if (!graph)
17
+ throw Error("No Fractory map in this repository. Run fractory setup.");
18
+ const id = value("--block") ||
19
+ (args[1]?.startsWith("-") ? undefined : args[1]) ||
20
+ graph.id, block = graph.elements.find((n) => n.id === id);
21
+ if (!block)
22
+ throw Error("Unknown block. Use its ID from Copy block in Fractory.");
23
+ const tests = checkPlan(root, graph, id);
24
+ if (args[0] === "tests" && args.includes("--run")) {
25
+ const files = value("--file")
26
+ ? [value("--file")]
27
+ : tests.filter((t) => t.runner).map((t) => t.file);
28
+ const runner = new WorkspaceTestRunner(root, graph), run = runner.start(id, files);
29
+ await new Promise((resolve) => {
30
+ const timer = setInterval(() => {
31
+ if (!["queued", "running"].includes(run.status)) {
32
+ clearInterval(timer);
33
+ resolve();
34
+ }
35
+ }, 100);
36
+ });
37
+ if (run.status !== "passed")
38
+ process.exitCode = 1;
39
+ return JSON.stringify(run, null, 2);
40
+ }
41
+ if (args[0] === "tests")
42
+ return JSON.stringify({
43
+ block: id,
44
+ suites: tests,
45
+ ...(args.includes("--source")
46
+ ? {
47
+ source: tests.map((t) => readTestSource(root, graph, id, t.file)),
48
+ }
49
+ : {}),
50
+ }, null, 2);
51
+ const documents = blockNotes(graph, id, root);
52
+ const inside = new Set([id]);
53
+ let grew = true;
54
+ while (grew) {
55
+ grew = false;
56
+ for (const node of graph.elements)
57
+ if (node.parent && inside.has(node.parent) && !inside.has(node.id)) {
58
+ inside.add(node.id);
59
+ grew = true;
60
+ }
61
+ }
62
+ const connections = graph.connections.filter((edge) => inside.has(edge.source) || inside.has(edge.target));
63
+ return JSON.stringify({
64
+ definition: graph.revision,
65
+ block,
66
+ inside: graph.elements
67
+ .filter((n) => n.parent === id)
68
+ .map((n) => ({ id: n.id, label: n.label, kind: n.kind })),
69
+ connections: connections.slice(0, 100),
70
+ connectionsOmitted: Math.max(0, connections.length - 100),
71
+ documents,
72
+ reports: reportsForBlock(graph, listReports(root).reports, id),
73
+ tests,
74
+ ...(args.includes("--docs")
75
+ ? {
76
+ documentation: documents.flatMap((d) => {
77
+ try {
78
+ const note = readBlockNote(root, graph, id, d.file);
79
+ return note.revision === null ? [] : [note];
80
+ }
81
+ catch {
82
+ return [];
83
+ }
84
+ }),
85
+ }
86
+ : {}),
87
+ }, null, 2);
88
+ }
@@ -0,0 +1,35 @@
1
+ import type { DefinitionGraph } from "./model.js";
2
+ export declare function createBlockDocument(root: string, graph: DefinitionGraph, block: string, title: string): {
3
+ documents: {
4
+ label: string;
5
+ exists: boolean;
6
+ file: string;
7
+ owner: string;
8
+ inherited: boolean;
9
+ }[];
10
+ file: string;
11
+ body: string;
12
+ revision: null;
13
+ } | {
14
+ documents: {
15
+ label: string;
16
+ exists: boolean;
17
+ file: string;
18
+ owner: string;
19
+ inherited: boolean;
20
+ }[];
21
+ file: string;
22
+ body: string;
23
+ revision: string;
24
+ };
25
+ export declare function searchBlockDocuments(root: string, graph: DefinitionGraph, query: string, refresh?: boolean): {
26
+ documents: {
27
+ excerpt: string;
28
+ file: string;
29
+ title: string;
30
+ block: string;
31
+ label: string;
32
+ }[];
33
+ more: boolean;
34
+ partial: boolean;
35
+ };