@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.
Files changed (273) 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 +118 -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 +1083 -0
  37. package/dist/compose.d.ts +9 -0
  38. package/dist/compose.js +72 -0
  39. package/dist/core.d.ts +86 -0
  40. package/dist/core.js +206 -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 +66 -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 +4 -0
  54. package/dist/factory-graph.js +318 -0
  55. package/dist/factory-model.d.ts +97 -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/issue-cache.d.ts +9 -0
  76. package/dist/issue-cache.js +68 -0
  77. package/dist/issue-cli.d.ts +1 -0
  78. package/dist/issue-cli.js +89 -0
  79. package/dist/issue-links.d.ts +15 -0
  80. package/dist/issue-links.js +125 -0
  81. package/dist/linear-issues.d.ts +19 -0
  82. package/dist/linear-issues.js +124 -0
  83. package/dist/local-runtime.d.ts +8 -0
  84. package/dist/local-runtime.js +59 -0
  85. package/dist/map-activity.d.ts +73 -0
  86. package/dist/map-activity.js +234 -0
  87. package/dist/map-model.d.ts +5 -0
  88. package/dist/map-model.js +166 -0
  89. package/dist/map-quality.d.ts +14 -0
  90. package/dist/map-quality.js +56 -0
  91. package/dist/mapping-coverage.d.ts +87 -0
  92. package/dist/mapping-coverage.js +404 -0
  93. package/dist/model.d.ts +182 -0
  94. package/dist/model.js +66 -0
  95. package/dist/operation-benchmark-worker.d.ts +2 -0
  96. package/dist/operation-benchmark-worker.js +60 -0
  97. package/dist/operation-benchmark.d.ts +29 -0
  98. package/dist/operation-benchmark.js +1 -0
  99. package/dist/otel-metrics.d.ts +21 -0
  100. package/dist/otel-metrics.js +146 -0
  101. package/dist/performance-model.d.ts +185 -0
  102. package/dist/performance-model.js +396 -0
  103. package/dist/product-map.d.ts +69 -0
  104. package/dist/product-map.js +168 -0
  105. package/dist/provider-access.cjs +207 -0
  106. package/dist/provider-access.d.cts +14 -0
  107. package/dist/reports-cli.d.ts +1 -0
  108. package/dist/reports-cli.js +111 -0
  109. package/dist/reports-model.d.ts +27 -0
  110. package/dist/reports-model.js +39 -0
  111. package/dist/reports.d.ts +23 -0
  112. package/dist/reports.js +223 -0
  113. package/dist/repository-map.d.ts +22 -0
  114. package/dist/repository-map.js +151 -0
  115. package/dist/resource-cache.d.ts +17 -0
  116. package/dist/resource-cache.js +65 -0
  117. package/dist/review-cli.d.ts +19 -0
  118. package/dist/review-cli.js +224 -0
  119. package/dist/review.d.ts +48 -0
  120. package/dist/review.js +289 -0
  121. package/dist/runtime-metrics.d.ts +26 -0
  122. package/dist/runtime-metrics.js +290 -0
  123. package/dist/scope.d.ts +12 -0
  124. package/dist/scope.js +94 -0
  125. package/dist/sentry-activity.d.ts +39 -0
  126. package/dist/sentry-activity.js +174 -0
  127. package/dist/sentry.d.ts +130 -0
  128. package/dist/sentry.js +369 -0
  129. package/dist/service-release.d.ts +16 -0
  130. package/dist/service-release.js +14 -0
  131. package/dist/setup-cli.d.ts +2 -0
  132. package/dist/setup-cli.js +52 -0
  133. package/dist/setup-kit.cjs +163 -0
  134. package/dist/setup-kit.d.cts +32 -0
  135. package/dist/source-index.d.ts +37 -0
  136. package/dist/source-index.js +166 -0
  137. package/dist/source-review-git.d.ts +7 -0
  138. package/dist/source-review-git.js +103 -0
  139. package/dist/source-review.d.ts +16 -0
  140. package/dist/source-review.js +493 -0
  141. package/dist/telemetry.d.ts +17 -0
  142. package/dist/telemetry.js +51 -0
  143. package/dist/time-window.d.ts +9 -0
  144. package/dist/time-window.js +35 -0
  145. package/dist/trace-evidence.d.ts +23 -0
  146. package/dist/trace-evidence.js +55 -0
  147. package/dist/trace-model.d.ts +26 -0
  148. package/dist/trace-model.js +1 -0
  149. package/dist/tracing.d.ts +44 -0
  150. package/dist/tracing.js +123 -0
  151. package/dist/work-check.d.ts +17 -0
  152. package/dist/work-check.js +110 -0
  153. package/dist/work-cli.d.ts +1 -0
  154. package/dist/work-cli.js +148 -0
  155. package/dist/work-context.d.ts +57 -0
  156. package/dist/work-context.js +568 -0
  157. package/dist/work-intents.d.ts +6 -0
  158. package/dist/work-intents.js +140 -0
  159. package/dist/work-items.d.ts +58 -0
  160. package/dist/work-items.js +86 -0
  161. package/dist/work-model.d.ts +110 -0
  162. package/dist/work-model.js +261 -0
  163. package/dist/work-review-git.d.ts +8 -0
  164. package/dist/work-review-git.js +111 -0
  165. package/dist/work-review.d.ts +26 -0
  166. package/dist/work-review.js +426 -0
  167. package/dist/work-switcher-model.d.ts +43 -0
  168. package/dist/work-switcher-model.js +79 -0
  169. package/dist/work-switcher.d.ts +6 -0
  170. package/dist/work-switcher.js +171 -0
  171. package/dist/working-cli.d.ts +1 -0
  172. package/dist/working-cli.js +33 -0
  173. package/dist/working-code.d.ts +74 -0
  174. package/dist/working-code.js +421 -0
  175. package/dist/workspace-notes.d.ts +71 -0
  176. package/dist/workspace-notes.js +177 -0
  177. package/dist/workspace-tests.d.ts +21 -0
  178. package/dist/workspace-tests.js +573 -0
  179. package/package.json +547 -4
  180. package/src/activity-volume.ts +149 -0
  181. package/src/annotations.ts +481 -0
  182. package/src/benchmark-cli.ts +118 -0
  183. package/src/benchmark-worker.ts +22 -0
  184. package/src/benchmarks.ts +493 -0
  185. package/src/bin.ts +54 -0
  186. package/src/block-cli.ts +106 -0
  187. package/src/block-documents.ts +117 -0
  188. package/src/change-impact.ts +280 -0
  189. package/src/check-source.ts +82 -0
  190. package/src/checks-model.ts +108 -0
  191. package/src/cli.ts +440 -0
  192. package/src/code-model.ts +159 -0
  193. package/src/code-store.ts +98 -0
  194. package/src/compare-artifact.ts +314 -0
  195. package/src/compare.ts +440 -0
  196. package/src/compiler.ts +1326 -0
  197. package/src/compose.ts +94 -0
  198. package/src/core.ts +357 -0
  199. package/src/coverage-cli.ts +52 -0
  200. package/src/declaration-sources.ts +69 -0
  201. package/src/declared-graph.ts +74 -0
  202. package/src/display-name.ts +8 -0
  203. package/src/error-heat.ts +161 -0
  204. package/src/evidence.ts +94 -0
  205. package/src/factory-graph.ts +378 -0
  206. package/src/factory-model.ts +73 -0
  207. package/src/git-code.ts +461 -0
  208. package/src/git-refs.ts +43 -0
  209. package/src/history-activity.ts +146 -0
  210. package/src/history-churn.ts +416 -0
  211. package/src/history-git.ts +163 -0
  212. package/src/history-ledger.ts +636 -0
  213. package/src/history-ownership.ts +116 -0
  214. package/src/history-source.ts +117 -0
  215. package/src/integrations-cli.ts +187 -0
  216. package/src/issue-cache.ts +96 -0
  217. package/src/issue-cli.ts +137 -0
  218. package/src/issue-links.ts +153 -0
  219. package/src/linear-issues.ts +154 -0
  220. package/src/local-runtime.ts +70 -0
  221. package/src/map-activity.ts +309 -0
  222. package/src/map-model.ts +213 -0
  223. package/src/map-quality.ts +61 -0
  224. package/src/mapping-coverage.ts +570 -0
  225. package/src/model.ts +221 -0
  226. package/src/operation-benchmark-worker.ts +60 -0
  227. package/src/operation-benchmark.ts +28 -0
  228. package/src/otel-metrics.ts +176 -0
  229. package/src/performance-model.ts +575 -0
  230. package/src/product-map.ts +236 -0
  231. package/src/provider-access.cjs +207 -0
  232. package/src/provider-access.d.cts +14 -0
  233. package/src/reports-cli.ts +125 -0
  234. package/src/reports-model.ts +73 -0
  235. package/src/reports.ts +276 -0
  236. package/src/repository-map.ts +189 -0
  237. package/src/resource-cache.ts +76 -0
  238. package/src/review-cli.ts +256 -0
  239. package/src/review.ts +376 -0
  240. package/src/runtime-metrics.ts +386 -0
  241. package/src/scope.ts +103 -0
  242. package/src/sentry-activity.ts +234 -0
  243. package/src/sentry.ts +545 -0
  244. package/src/service-release.ts +18 -0
  245. package/src/setup-cli.ts +58 -0
  246. package/src/setup-kit.cjs +163 -0
  247. package/src/setup-kit.d.cts +32 -0
  248. package/src/source-index.ts +205 -0
  249. package/src/source-review-git.ts +129 -0
  250. package/src/source-review.ts +637 -0
  251. package/src/telemetry.ts +68 -0
  252. package/src/time-window.ts +51 -0
  253. package/src/trace-evidence.ts +80 -0
  254. package/src/trace-model.ts +26 -0
  255. package/src/tracing.ts +165 -0
  256. package/src/work-check.ts +143 -0
  257. package/src/work-cli.ts +195 -0
  258. package/src/work-context.ts +713 -0
  259. package/src/work-intents.ts +196 -0
  260. package/src/work-items.ts +151 -0
  261. package/src/work-model.ts +400 -0
  262. package/src/work-review-git.ts +130 -0
  263. package/src/work-review.ts +573 -0
  264. package/src/work-switcher-model.ts +121 -0
  265. package/src/work-switcher.ts +191 -0
  266. package/src/working-cli.ts +38 -0
  267. package/src/working-code.ts +582 -0
  268. package/src/workspace-notes.ts +203 -0
  269. package/src/workspace-tests.ts +654 -0
  270. package/toolkit/GUIDE.md +305 -0
  271. package/toolkit/SKILL.md +131 -0
  272. package/toolkit/bin/fractory +2 -0
  273. package/toolkit/build.json +1 -0
@@ -0,0 +1,84 @@
1
+ import { existsSync, mkdirSync, writeFileSync, statSync, readFileSync, } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { blockNotes, blockNoteFile, checkedPath, readBlockNote, } from "./workspace-notes.js";
4
+ export function createBlockDocument(root, graph, block, title) {
5
+ if (!graph.elements.some((n) => n.id === block))
6
+ throw Error("Unknown block");
7
+ if (!title.trim() || title.length > 100 || /[\r\n\0]/.test(title))
8
+ throw Error("Use a document title of 1–100 characters.");
9
+ const slug = title
10
+ .toLowerCase()
11
+ .normalize("NFKD")
12
+ .replace(/[\u0300-\u036f]/g, "")
13
+ .replace(/[^a-z0-9]+/g, "-")
14
+ .replace(/^-|-$/g, "")
15
+ .slice(0, 60) || "note";
16
+ const directory = blockNoteFile(block).replace(/\.md$/, "");
17
+ if (blockNotes(graph, block, root).filter((d) => !d.inherited).length > 32)
18
+ throw Error("Keep at most 32 note pages per block.");
19
+ const file = directory + "/" + slug + ".md", path = checkedPath(root, file, true);
20
+ if (existsSync(path))
21
+ throw Error("A note with this title already exists.");
22
+ mkdirSync(dirname(path), { recursive: true });
23
+ checkedPath(root, file, true);
24
+ writeFileSync(path, "# " + title.trim() + "\n\n", {
25
+ flag: "wx",
26
+ mode: 0o600,
27
+ });
28
+ return readBlockNote(root, graph, block, file);
29
+ }
30
+ const indexes = new Map();
31
+ export function searchBlockDocuments(root, graph, query, refresh = false) {
32
+ const term = query.trim().toLowerCase();
33
+ if (term.length < 2 || term.length > 120)
34
+ throw Error("Search with 2–120 characters.");
35
+ const key = root + ":" + graph.revision;
36
+ let entry = indexes.get(key);
37
+ if (!entry || refresh || entry.until < Date.now()) {
38
+ const documents = [], seen = new Set();
39
+ let budget = 8 * 1024 * 1024, partial = false;
40
+ outer: for (const block of graph.elements)
41
+ for (const doc of blockNotes(graph, block.id, root)) {
42
+ if (seen.has(doc.file) || doc.inherited)
43
+ continue;
44
+ seen.add(doc.file);
45
+ try {
46
+ const path = checkedPath(root, doc.file), size = statSync(path).size;
47
+ if (size > 128000)
48
+ continue;
49
+ if (size > budget || documents.length >= 500) {
50
+ partial = true;
51
+ break outer;
52
+ }
53
+ const body = readFileSync(path, "utf8");
54
+ budget -= size;
55
+ documents.push({
56
+ file: doc.file,
57
+ title: /^#\s+(.+)$/m.exec(body)?.[1]?.trim() || doc.label,
58
+ block: block.id,
59
+ label: block.label,
60
+ body,
61
+ });
62
+ }
63
+ catch { }
64
+ }
65
+ entry = { until: Date.now() + 10000, documents, partial };
66
+ indexes.set(key, entry);
67
+ if (indexes.size > 4)
68
+ indexes.delete(indexes.keys().next().value);
69
+ }
70
+ const matches = entry.documents.filter((d) => `${d.title} ${d.label} ${d.body}`.toLowerCase().includes(term));
71
+ return {
72
+ documents: matches.slice(0, 30).map(({ body, ...d }) => {
73
+ const position = body.toLowerCase().indexOf(term);
74
+ return {
75
+ ...d,
76
+ excerpt: body
77
+ .slice(Math.max(0, position - 60), Math.max(0, position - 60) + 200)
78
+ .replace(/\s+/g, " "),
79
+ };
80
+ }),
81
+ more: matches.length > 30,
82
+ partial: entry.partial,
83
+ };
84
+ }
@@ -0,0 +1,55 @@
1
+ import { type Connection, type DefinitionGraph } from "./model.js";
2
+ import type { WorkingOverview } from "./working-code.js";
3
+ /** Evidence about a possible interaction, never evidence that it executed. */
4
+ export declare function connectionEvidence(edge: Connection): "declared" | "code" | "reviewed";
5
+ export type ImpactReason = {
6
+ id: string;
7
+ distance: number;
8
+ /** The dependency that first reached this consumer. */
9
+ via?: string;
10
+ provider?: string;
11
+ };
12
+ export type ImpactInput = {
13
+ kind: "block";
14
+ id: string;
15
+ } | {
16
+ kind: "files";
17
+ paths: string[];
18
+ partial?: boolean;
19
+ };
20
+ export declare function graphIndex(graph: DefinitionGraph): {
21
+ byId: Map<string, import("./model.js").Element>;
22
+ within: (id: string, parent: string) => boolean;
23
+ };
24
+ /** Git status is deliberately a conservative file association, not a line diff. */
25
+ export declare function workingImpactInput(overview: WorkingOverview): ImpactInput;
26
+ export declare function changeImpact(graph: DefinitionGraph, input: ImpactInput, indirect?: boolean): {
27
+ input: ImpactInput;
28
+ seeds: string[];
29
+ files: {
30
+ [k: string]: string[];
31
+ };
32
+ basis: {
33
+ [k: string]: string[];
34
+ };
35
+ consumers: ImpactReason[];
36
+ connectionIds: string[];
37
+ marks: Record<string, {
38
+ kind: "changed" | "consumer";
39
+ distance: number;
40
+ count: number;
41
+ }>;
42
+ interfaces: string[];
43
+ tests: {
44
+ file: string;
45
+ targets: string[];
46
+ reasons: string[];
47
+ }[];
48
+ unmapped: string[];
49
+ unresolved: {
50
+ source: import("./model.js").SourceRef;
51
+ expression: string;
52
+ reason: string;
53
+ }[];
54
+ };
55
+ export type ChangeImpact = ReturnType<typeof changeImpact>;
@@ -0,0 +1,223 @@
1
+ import { relatedTests } from "./model.js";
2
+ /** Evidence about a possible interaction, never evidence that it executed. */
3
+ export function connectionEvidence(edge) {
4
+ if (edge.id.startsWith("call-site:") && edge.sourceRef)
5
+ return "code";
6
+ if (edge.provenance === "declared")
7
+ return "declared";
8
+ return "reviewed";
9
+ }
10
+ export function graphIndex(graph) {
11
+ const byId = new Map(graph.elements.map((node) => [node.id, node]));
12
+ const ancestors = new Map();
13
+ for (const node of graph.elements) {
14
+ const seen = new Set();
15
+ let id = node.id;
16
+ while (byId.has(id) && !seen.has(id)) {
17
+ seen.add(id);
18
+ id = byId.get(id).parent || "";
19
+ }
20
+ ancestors.set(node.id, seen);
21
+ }
22
+ const within = (id, parent) => ancestors.get(id)?.has(parent) || false;
23
+ return { byId, within };
24
+ }
25
+ /** Git status is deliberately a conservative file association, not a line diff. */
26
+ export function workingImpactInput(overview) {
27
+ return {
28
+ kind: "files",
29
+ paths: overview.paths.map((path) => path.path),
30
+ partial: overview.truncated,
31
+ };
32
+ }
33
+ /** Dependencies and consumers have different directions for calls and data transfers. */
34
+ function dependency(edge) {
35
+ return ["flows", "writes", "produces", "resumes"].includes(edge.relation)
36
+ ? { provider: edge.source, consumer: edge.target }
37
+ : { provider: edge.target, consumer: edge.source };
38
+ }
39
+ function contractTypeFiles(input) {
40
+ if (!input || typeof input !== "object")
41
+ return [];
42
+ const value = input;
43
+ const own = Array.isArray(value.typeSources)
44
+ ? value.typeSources.flatMap((source) => source && typeof source.file === "string" ? [source.file] : [])
45
+ : [];
46
+ return [
47
+ ...own,
48
+ ...(Array.isArray(value.members)
49
+ ? value.members.flatMap(contractTypeFiles)
50
+ : []),
51
+ ];
52
+ }
53
+ export function changeImpact(graph, input, indirect = false) {
54
+ const { byId, within } = graphIndex(graph);
55
+ const seeds = new Set(), files = new Map();
56
+ const basis = new Map();
57
+ const unmapped = [];
58
+ if (input.kind === "block") {
59
+ if (byId.has(input.id))
60
+ seeds.add(input.id);
61
+ }
62
+ else {
63
+ const associations = graph.elements.flatMap((node) => [
64
+ ...[...(node.sources || []), ...(node.source ? [node.source] : [])].map((source) => ({
65
+ id: node.id,
66
+ file: source.file,
67
+ basis: source.scope === "file"
68
+ ? "Block implementation file"
69
+ : "Source file",
70
+ })),
71
+ ...contractTypeFiles(node.contract?.input).map((file) => ({
72
+ id: node.id,
73
+ file,
74
+ basis: "Contract type dependency",
75
+ })),
76
+ ]);
77
+ for (const edge of graph.connections)
78
+ for (const source of [
79
+ ...(edge.sources || []),
80
+ ...(edge.sourceRef ? [edge.sourceRef] : []),
81
+ ])
82
+ if (connectionEvidence(edge) === "code")
83
+ associations.push({
84
+ id: edge.source,
85
+ file: source.file,
86
+ basis: "Call evidence",
87
+ });
88
+ for (const path of [...new Set(input.paths)]) {
89
+ const allMatches = associations.filter((source) => path.endsWith("/")
90
+ ? source.file.startsWith(path)
91
+ : source.file === path);
92
+ const preciseFiles = new Set(allMatches
93
+ .filter((source) => source.basis !== "Block implementation file")
94
+ .map((source) => source.file));
95
+ const matches = allMatches.filter((source) => source.basis !== "Block implementation file" ||
96
+ !preciseFiles.has(source.file));
97
+ const ids = new Set(matches.map((source) => source.id));
98
+ const owners = graph.elements.filter((node) => ids.has(node.id));
99
+ if (!owners.length)
100
+ unmapped.push(path);
101
+ // A file can own several unrelated logical parts. Keep them all, but avoid
102
+ // turning a shared file's broad parent anchor into a change to every sibling.
103
+ for (const owner of owners.filter((node) => !owners.some((other) => other.id !== node.id && within(other.id, node.id)))) {
104
+ seeds.add(owner.id);
105
+ files.set(owner.id, [
106
+ ...new Set([...(files.get(owner.id) || []), path]),
107
+ ]);
108
+ basis.set(owner.id, [
109
+ ...new Set([
110
+ ...(basis.get(owner.id) || []),
111
+ ...matches
112
+ .filter((match) => match.id === owner.id)
113
+ .map((match) => match.basis),
114
+ ]),
115
+ ]);
116
+ }
117
+ }
118
+ }
119
+ const reasons = new Map([...seeds].map((id) => [id, { id, distance: 0 }]));
120
+ const links = graph.connections
121
+ .flatMap((edge) => {
122
+ const link = { ...dependency(edge), edge };
123
+ return edge.bidirectional
124
+ ? [link, { provider: link.consumer, consumer: link.provider, edge }]
125
+ : [link];
126
+ })
127
+ .filter((link) => byId.has(link.provider) && byId.has(link.consumer));
128
+ const connectionIds = new Set();
129
+ // Breadth first, bounded by the graph. Containers are conservative dependency
130
+ // boundaries; merely sharing a parent never creates a consumer relationship.
131
+ let frontier = [...reasons.values()];
132
+ while (frontier.length) {
133
+ const next = [];
134
+ for (const link of links) {
135
+ const cause = frontier.find((reason) => within(link.provider, reason.id));
136
+ if (!cause)
137
+ continue;
138
+ if ([...seeds].some((seed) => within(link.consumer, seed)))
139
+ continue;
140
+ const old = reasons.get(link.consumer);
141
+ if (old && old.distance < cause.distance + 1)
142
+ continue;
143
+ connectionIds.add(link.edge.id);
144
+ if (old)
145
+ continue;
146
+ const reason = {
147
+ id: link.consumer,
148
+ distance: cause.distance + 1,
149
+ via: link.edge.id,
150
+ provider: link.provider,
151
+ };
152
+ reasons.set(reason.id, reason);
153
+ next.push(reason);
154
+ }
155
+ if (!indirect)
156
+ break;
157
+ frontier = next;
158
+ }
159
+ const changed = (id) => [...seeds].some((seed) => within(id, seed));
160
+ const consumers = [...reasons.values()].filter((reason) => reason.distance && !changed(reason.id));
161
+ const affected = (id) => changed(id) || consumers.some((reason) => id === reason.id);
162
+ const marks = {};
163
+ for (const node of graph.elements) {
164
+ const insideSeeds = [...seeds].filter((id) => within(id, node.id));
165
+ const insideConsumers = consumers.filter((reason) => within(reason.id, node.id));
166
+ if (changed(node.id) || insideSeeds.length)
167
+ marks[node.id] = {
168
+ kind: "changed",
169
+ distance: 0,
170
+ count: Math.max(1, insideSeeds.length),
171
+ };
172
+ else if (insideConsumers.length)
173
+ marks[node.id] = {
174
+ kind: "consumer",
175
+ distance: Math.min(...insideConsumers.map((reason) => reason.distance)),
176
+ count: insideConsumers.length,
177
+ };
178
+ }
179
+ const tests = new Map();
180
+ for (const reason of reasons.values()) {
181
+ for (const test of relatedTests(graph, reason.id)) {
182
+ const record = tests.get(test.source.file) || {
183
+ file: test.source.file,
184
+ targets: [],
185
+ reasons: [],
186
+ };
187
+ record.targets = [...new Set([...record.targets, reason.id])];
188
+ record.reasons = [
189
+ ...new Set([
190
+ ...record.reasons,
191
+ reason.distance
192
+ ? "Consumer"
193
+ : input.kind === "block"
194
+ ? "Selected block"
195
+ : "Changed file",
196
+ ...(test.association === "attachment" &&
197
+ !test.targets.some((id) => within(id, reason.id))
198
+ ? ["Inherited attachment"]
199
+ : []),
200
+ ]),
201
+ ];
202
+ tests.set(record.file, record);
203
+ }
204
+ }
205
+ const unresolved = graph.gaps.filter((gap) => graph.elements.some((node) => affected(node.id) &&
206
+ (node.sources || (node.source ? [node.source] : [])).some((source) => source.file === gap.source.file)));
207
+ const interfaces = graph.elements.filter((node) => node.kind === "interface" &&
208
+ (affected(node.id) ||
209
+ graph.elements.some((part) => affected(part.id) && within(part.id, node.id))));
210
+ return {
211
+ input,
212
+ seeds: [...seeds],
213
+ files: Object.fromEntries(files),
214
+ basis: Object.fromEntries(basis),
215
+ consumers,
216
+ connectionIds: [...connectionIds],
217
+ marks,
218
+ interfaces: interfaces.map((node) => node.id),
219
+ tests: [...tests.values()],
220
+ unmapped,
221
+ unresolved,
222
+ };
223
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckDefinition } from "./checks-model.js";
2
+ export declare function testDefinitions(body: string, file: string): CheckDefinition[];
@@ -0,0 +1,66 @@
1
+ import ts from "typescript";
2
+ // Discovery only: runner reports remain the authority on which tests executed.
3
+ export function testDefinitions(body, file) {
4
+ const source = ts.createSourceFile(file, body, ts.ScriptTarget.Latest, true);
5
+ const aliases = new Map([
6
+ ["describe", "describe"],
7
+ ["it", "test"],
8
+ ["test", "test"],
9
+ ]);
10
+ for (const statement of source.statements) {
11
+ if (!ts.isImportDeclaration(statement) ||
12
+ !ts.isStringLiteral(statement.moduleSpecifier) ||
13
+ !["vitest", "bun:test"].includes(statement.moduleSpecifier.text))
14
+ continue;
15
+ const imports = statement.importClause?.namedBindings;
16
+ if (imports && ts.isNamedImports(imports))
17
+ for (const item of imports.elements) {
18
+ const original = (item.propertyName || item.name).text;
19
+ if (["describe", "it", "test"].includes(original))
20
+ aliases.set(item.name.text, original === "describe" ? "describe" : "test");
21
+ }
22
+ }
23
+ function head(node) {
24
+ if (ts.isIdentifier(node))
25
+ return { kind: aliases.get(node.text), parameterized: false };
26
+ if (ts.isPropertyAccessExpression(node)) {
27
+ const value = head(node.expression);
28
+ return {
29
+ ...value,
30
+ parameterized: value.parameterized ||
31
+ node.name.text === "each" ||
32
+ node.name.text === "for",
33
+ };
34
+ }
35
+ if (ts.isCallExpression(node) || ts.isTaggedTemplateExpression(node))
36
+ return head(ts.isCallExpression(node) ? node.expression : node.tag);
37
+ return { parameterized: false };
38
+ }
39
+ const result = [];
40
+ function visit(node, groups) {
41
+ if (ts.isCallExpression(node)) {
42
+ const info = head(node.expression), name = node.arguments[0];
43
+ if (info.kind &&
44
+ name &&
45
+ (ts.isStringLiteral(name) || ts.isNoSubstitutionTemplateLiteral(name))) {
46
+ if (info.kind === "test") {
47
+ result.push({
48
+ name: name.text,
49
+ groups,
50
+ parameterized: info.parameterized,
51
+ line: source.getLineAndCharacterOfPosition(node.getStart(source)).line +
52
+ 1,
53
+ endLine: source.getLineAndCharacterOfPosition(node.getEnd()).line + 1,
54
+ });
55
+ return;
56
+ }
57
+ for (const child of node.arguments.slice(1))
58
+ visit(child, [...groups, name.text]);
59
+ return;
60
+ }
61
+ }
62
+ ts.forEachChild(node, (child) => visit(child, groups));
63
+ }
64
+ visit(source, []);
65
+ return result;
66
+ }
@@ -0,0 +1,64 @@
1
+ import { type DefinitionGraph } from "./model.js";
2
+ export type CheckStatus = "queued" | "running" | "passed" | "failed" | "skipped" | "blocked" | "cancelled";
3
+ export interface CheckFile {
4
+ file: string;
5
+ runner: "bun" | "vitest" | null;
6
+ package: string;
7
+ reason?: string;
8
+ associations: string[];
9
+ sourceRevision?: string;
10
+ }
11
+ export interface CheckCase {
12
+ name: string;
13
+ groups: string[];
14
+ status: "passed" | "failed" | "skipped" | "todo";
15
+ duration?: number;
16
+ line?: number;
17
+ failure?: string;
18
+ }
19
+ export interface CheckDefinition {
20
+ name: string;
21
+ groups: string[];
22
+ line: number;
23
+ endLine: number;
24
+ parameterized: boolean;
25
+ }
26
+ export interface CheckSource {
27
+ file: string;
28
+ revision: string;
29
+ body: string;
30
+ definitions: CheckDefinition[];
31
+ }
32
+ export interface CheckResult {
33
+ reason?: string;
34
+ file: string;
35
+ status: CheckStatus;
36
+ passed: number;
37
+ failed: number;
38
+ skipped: number;
39
+ duration?: number;
40
+ cases?: CheckCase[];
41
+ casesTruncated?: boolean;
42
+ sourceRevision?: string;
43
+ }
44
+ export interface CheckRun {
45
+ id: string;
46
+ block: string;
47
+ definition: string;
48
+ startedAt: string;
49
+ finishedAt?: string;
50
+ status: CheckStatus;
51
+ results: CheckResult[];
52
+ output: string;
53
+ stale?: boolean;
54
+ fingerprints: Record<string, string>;
55
+ pid: number;
56
+ }
57
+ export type CheckRunView = Omit<CheckRun, "fingerprints" | "pid">;
58
+ export declare function blockCheckState(graph: DefinitionGraph, block: string, runs: CheckRunView[]): {
59
+ readonly status: "partial" | "failed" | "stale" | "running" | "passed" | "skipped" | "blocked";
60
+ readonly checked: number;
61
+ readonly total: number;
62
+ readonly failed: number;
63
+ readonly passed: number;
64
+ } | undefined;
@@ -0,0 +1,36 @@
1
+ import { relatedTests } from "./model.js";
2
+ export function blockCheckState(graph, block, runs) {
3
+ const files = new Set(relatedTests(graph, block).map((test) => test.source.file));
4
+ const latest = new Map();
5
+ for (const run of runs)
6
+ for (const result of run.results)
7
+ if (files.has(result.file) && !latest.has(result.file))
8
+ latest.set(result.file, { run, result });
9
+ if (!latest.size)
10
+ return;
11
+ const values = [...latest.values()];
12
+ const active = values.some((v) => v.result.status === "running" || v.result.status === "queued");
13
+ const stale = values.some((v) => v.run.stale || v.run.definition !== graph.revision);
14
+ const failed = values.filter((v) => v.result.status === "failed").length;
15
+ const blocked = values.some((v) => v.result.status === "blocked");
16
+ const passed = values.filter((v) => v.result.status === "passed").length;
17
+ return {
18
+ status: active
19
+ ? "running"
20
+ : stale
21
+ ? "stale"
22
+ : failed
23
+ ? "failed"
24
+ : blocked
25
+ ? "blocked"
26
+ : passed === values.length && values.length === files.size
27
+ ? "passed"
28
+ : passed
29
+ ? "partial"
30
+ : "skipped",
31
+ checked: values.length,
32
+ total: files.size,
33
+ failed,
34
+ passed,
35
+ };
36
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function run(args: string[]): string;
2
+ export declare function runSentry(args: string[]): Promise<string>;