@sdxc/kit 2026.10.21 → 2026.10.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 (113) hide show
  1. package/README.md +84 -4
  2. package/changelog.jsonl +168 -0
  3. package/config.schema.json +154 -0
  4. package/dist/architecture/complexity.d.ts +73 -0
  5. package/dist/architecture/complexity.js +185 -0
  6. package/dist/architecture/crap.d.ts +62 -0
  7. package/dist/architecture/crap.js +121 -0
  8. package/dist/architecture/graph.d.ts +55 -0
  9. package/dist/architecture/graph.js +194 -0
  10. package/dist/architecture/layers.d.ts +29 -0
  11. package/dist/architecture/layers.js +81 -0
  12. package/dist/architecture/mermaid.d.ts +20 -0
  13. package/dist/architecture/mermaid.js +51 -0
  14. package/dist/cli.js +9 -0
  15. package/dist/commands/create.js +4 -3
  16. package/dist/commands/deploy.js +10 -9
  17. package/dist/commands/destroy.d.ts +1 -1
  18. package/dist/commands/diagram.d.ts +17 -0
  19. package/dist/commands/diagram.js +45 -0
  20. package/dist/commands/fix.d.ts +69 -0
  21. package/dist/commands/fix.js +102 -0
  22. package/dist/commands/make.d.ts +71 -2
  23. package/dist/commands/make.js +46 -0
  24. package/dist/commands/run.d.ts +15 -11
  25. package/dist/commands/run.js +21 -16
  26. package/dist/commands/scaffold.d.ts +1 -1
  27. package/dist/commands/setup.d.ts +26 -0
  28. package/dist/commands/setup.js +33 -0
  29. package/dist/config.d.ts +52 -0
  30. package/dist/config.js +88 -1
  31. package/dist/contract.d.ts +52 -3
  32. package/dist/contract.js +124 -2
  33. package/dist/dependencies.js +7 -1
  34. package/dist/deploy/plan.d.ts +5 -0
  35. package/dist/deploy/plan.js +10 -0
  36. package/dist/destroy.js +13 -6
  37. package/dist/diagram.d.ts +32 -0
  38. package/dist/diagram.js +47 -0
  39. package/dist/doctor/checks.d.ts +2 -1
  40. package/dist/doctor/checks.js +24 -1
  41. package/dist/doctor/complexity.d.ts +13 -0
  42. package/dist/doctor/complexity.js +52 -0
  43. package/dist/doctor/crap.d.ts +14 -0
  44. package/dist/doctor/crap.js +67 -0
  45. package/dist/doctor/dependencies.d.ts +13 -0
  46. package/dist/doctor/dependencies.js +42 -0
  47. package/dist/doctor/duplication.d.ts +19 -0
  48. package/dist/doctor/duplication.js +106 -0
  49. package/dist/doctor/fan-out.d.ts +12 -0
  50. package/dist/doctor/fan-out.js +42 -0
  51. package/dist/doctor/feature-scatter.d.ts +15 -0
  52. package/dist/doctor/feature-scatter.js +84 -0
  53. package/dist/doctor/module-size.d.ts +13 -0
  54. package/dist/doctor/module-size.js +50 -0
  55. package/dist/doctor/mutation.d.ts +20 -0
  56. package/dist/doctor/mutation.js +97 -0
  57. package/dist/doctor/orphans.d.ts +13 -0
  58. package/dist/doctor/orphans.js +50 -0
  59. package/dist/doctor/project.js +8 -5
  60. package/dist/doctor/result-throws.d.ts +17 -0
  61. package/dist/doctor/result-throws.js +72 -0
  62. package/dist/doctor/test-ratio.d.ts +12 -0
  63. package/dist/doctor/test-ratio.js +31 -0
  64. package/dist/fix/commands.d.ts +37 -0
  65. package/dist/fix/commands.js +63 -0
  66. package/dist/fix/emails.d.ts +21 -0
  67. package/dist/fix/emails.js +159 -0
  68. package/dist/fix/env.d.ts +29 -0
  69. package/dist/fix/env.js +58 -0
  70. package/dist/fix/index.d.ts +11 -0
  71. package/dist/fix/index.js +11 -0
  72. package/dist/fix/models.d.ts +20 -0
  73. package/dist/fix/models.js +95 -0
  74. package/dist/lock.js +12 -2
  75. package/dist/make/binding.d.ts +42 -0
  76. package/dist/make/binding.js +237 -0
  77. package/dist/make/imports.js +7 -5
  78. package/dist/make/schema-diff.js +8 -1
  79. package/dist/models.js +7 -7
  80. package/dist/routes/modules.js +8 -5
  81. package/dist/routes/parse.js +8 -7
  82. package/dist/routes/routers.js +9 -5
  83. package/dist/setup/auth.d.ts +12 -0
  84. package/dist/setup/auth.js +209 -0
  85. package/dist/setup/billing.d.ts +11 -0
  86. package/dist/setup/billing.js +116 -0
  87. package/dist/setup/catalog.d.ts +25 -0
  88. package/dist/setup/catalog.js +34 -0
  89. package/dist/setup/credit.d.ts +13 -0
  90. package/dist/setup/credit.js +21 -0
  91. package/dist/setup/flags.d.ts +11 -0
  92. package/dist/setup/flags.js +62 -0
  93. package/dist/setup/index.d.ts +25 -0
  94. package/dist/setup/index.js +53 -0
  95. package/dist/setup/plan.d.ts +38 -0
  96. package/dist/setup/plan.js +62 -0
  97. package/dist/testing.js +3 -3
  98. package/dist/ui/layout.js +1 -1
  99. package/dist/ui/registry.d.ts +2 -2
  100. package/dist/upgrade/project.d.ts +2 -2
  101. package/dist/upgrade/prompt.js +7 -5
  102. package/package.json +11 -8
  103. package/registry/ui/attachment.json +2 -2
  104. package/registry/ui/breadcrumbs.json +6 -3
  105. package/registry/ui/group.json +6 -3
  106. package/registry/ui/link-button.json +3 -3
  107. package/registry/ui/link.json +6 -3
  108. package/registry/ui/nav-link.json +6 -3
  109. package/registry/ui/navigation-menu.json +6 -3
  110. package/registry/ui/pagination.json +3 -3
  111. package/registry/ui/sidebar.json +3 -3
  112. package/templates/app/AGENTS.md +14 -1
  113. package/templates/app/package.json +1 -1
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The `crap` check: CRAP scores from cyclomatic complexity and Istanbul coverage stay at or
3
+ * under the configured maximum (default 12). Without a coverage report the check skips, since a
4
+ * score without coverage would only restate complexity.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFile } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { measureComplexity } from "../architecture/complexity.js";
13
+ import { coverageExists, loadCoverage, scoreFunctions } from "../architecture/crap.js";
14
+ import { PROJECT_FOLDERS } from "../stats.js";
15
+ import { passed, skipped } from "./check.js";
16
+ import { isAppSource, listFiles } from "./files.js";
17
+ /**
18
+ * Warns on each function whose CRAP score exceeds `doctor.crap.max` when coverage data is
19
+ * present at `doctor.crap.coverage`.
20
+ */
21
+ export const crapCheck = {
22
+ name: "crap",
23
+ async run(context) {
24
+ let { max, coverage: coverageFile } = context.config.doctor.crap;
25
+ if (!(await coverageExists(context.root, coverageFile))) {
26
+ return skipped(`No coverage at ${coverageFile}; run tests with coverage then re-run doctor`);
27
+ }
28
+ let coverage = await loadCoverage(context.root, coverageFile);
29
+ let findings = [];
30
+ let scored = 0;
31
+ for (let folder of PROJECT_FOLDERS) {
32
+ for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
33
+ let source = await wrap(() => readFile(join(context.root, file), "utf8"));
34
+ if (isFailure(source))
35
+ continue;
36
+ let functions = measureComplexity(file, source.data);
37
+ for (let entry of scoreFunctions(file, functions, coverage)) {
38
+ if (entry.crap === null)
39
+ continue;
40
+ scored += 1;
41
+ if (entry.crap <= max)
42
+ continue;
43
+ let pct = entry.coverage === null ? "?" : `${Math.round(entry.coverage * 100)}%`;
44
+ findings.push(`${entry.file}:${entry.line}: ${entry.name} CRAP ${formatCrap(entry.crap)} (cc ${entry.complexity}, cov ${pct}, max ${max})`);
45
+ }
46
+ }
47
+ }
48
+ if (scored === 0) {
49
+ return skipped(`Coverage at ${coverageFile} matches no app functions; generate coverage for app source`);
50
+ }
51
+ if (findings.length === 0) {
52
+ return passed(`Every scored function stays at CRAP ${max} or below`);
53
+ }
54
+ return {
55
+ status: "warn",
56
+ message: findings.length === 1
57
+ ? "Found 1 function above the CRAP limit"
58
+ : `Found ${findings.length} functions above the CRAP limit`,
59
+ findings,
60
+ fix: `Lower complexity, raise coverage, or raise doctor.crap.max in .config/sdxc.jsonc`,
61
+ };
62
+ },
63
+ };
64
+ /** One decimal place when the score is not an integer. */
65
+ function formatCrap(value) {
66
+ return Number.isInteger(value) ? String(value) : value.toFixed(1);
67
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The `dependencies` check: import cycles and Clean Architecture breaches against the app-layout
3
+ * layers — models stay inward of services and http, resources stay outward of delivery code.
4
+ * Oxlint has no project-wide dependency-rule or cycle check for this layout.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns on each import cycle and each edge that points from an inner layer to an outer one.
12
+ */
13
+ export declare const dependenciesCheck: Check;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The `dependencies` check: import cycles and Clean Architecture breaches against the app-layout
3
+ * layers — models stay inward of services and http, resources stay outward of delivery code.
4
+ * Oxlint has no project-wide dependency-rule or cycle check for this layout.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { projectGraph } from "../architecture/graph.js";
10
+ import { layerOf } from "../architecture/layers.js";
11
+ import { passed, skipped } from "./check.js";
12
+ /**
13
+ * Warns on each import cycle and each edge that points from an inner layer to an outer one.
14
+ */
15
+ export const dependenciesCheck = {
16
+ name: "dependencies",
17
+ async run(context) {
18
+ let graph = await projectGraph(context.root);
19
+ if (graph.modules.length === 0)
20
+ return skipped("No app source to check dependencies");
21
+ let findings = [];
22
+ for (let cycle of graph.cycles) {
23
+ findings.push(`cycle: ${cycle.join(" -> ")} -> ${cycle[0]}`);
24
+ }
25
+ for (let edge of graph.violations) {
26
+ let from = layerOf(edge.from) ?? "?";
27
+ let to = layerOf(edge.to) ?? "?";
28
+ findings.push(`${edge.from} (${from}) imports ${edge.to} (${to}); dependencies must point inward`);
29
+ }
30
+ if (findings.length === 0) {
31
+ return passed("No import cycles; every layer edge points inward");
32
+ }
33
+ return {
34
+ status: "warn",
35
+ message: findings.length === 1
36
+ ? "Found 1 dependency structure problem"
37
+ : `Found ${findings.length} dependency structure problems`,
38
+ findings,
39
+ fix: "Break each cycle with an interface or extract shared code inward; move imports so outer layers depend on inner ones (models innermost). sdxc diagram shows the graph",
40
+ };
41
+ },
42
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The `duplication` check: identical blocks of at least `doctor.duplication.minLines` code
3
+ * lines (blank and comments stripped) appear in more than one module, so agents extract shared
4
+ * helpers instead of pasting.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns when the same normalised code block of `minLines` or more appears in two places.
12
+ */
13
+ export declare const duplicationCheck: Check;
14
+ /** Sliding windows of `minLines` consecutive code lines, keyed by their joined text. */
15
+ export declare function codeBlocks(file: string, source: string, minLines: number): Array<{
16
+ key: string;
17
+ file: string;
18
+ line: number;
19
+ }>;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The `duplication` check: identical blocks of at least `doctor.duplication.minLines` code
3
+ * lines (blank and comments stripped) appear in more than one module, so agents extract shared
4
+ * helpers instead of pasting.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFile } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { PROJECT_FOLDERS } from "../stats.js";
13
+ import { passed, skipped } from "./check.js";
14
+ import { isAppSource, listFiles } from "./files.js";
15
+ /**
16
+ * Warns when the same normalised code block of `minLines` or more appears in two places.
17
+ */
18
+ export const duplicationCheck = {
19
+ name: "duplication",
20
+ async run(context) {
21
+ let minLines = context.config.doctor.duplication.minLines;
22
+ let blocks = new Map();
23
+ let files = 0;
24
+ for (let folder of PROJECT_FOLDERS) {
25
+ for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
26
+ files += 1;
27
+ let source = await wrap(() => readFile(join(context.root, file), "utf8"));
28
+ if (isFailure(source))
29
+ continue;
30
+ for (let block of codeBlocks(file, source.data, minLines)) {
31
+ let hits = blocks.get(block.key) ?? [];
32
+ hits.push({ file: block.file, line: block.line });
33
+ blocks.set(block.key, hits);
34
+ }
35
+ }
36
+ }
37
+ if (files === 0)
38
+ return skipped("No app source to scan for duplication");
39
+ let findings = [...blocks.values()]
40
+ .filter((hits) => uniqueFiles(hits).length > 1)
41
+ .flatMap((hits) => {
42
+ let places = uniqueFiles(hits)
43
+ .map((hit) => `${hit.file}:${hit.line}`)
44
+ .sort();
45
+ return [`duplicate block at ${places.join(" and ")}`];
46
+ })
47
+ .sort();
48
+ if (findings.length === 0) {
49
+ return passed(`No duplicated blocks of ${minLines}+ code lines`);
50
+ }
51
+ return {
52
+ status: "warn",
53
+ message: findings.length === 1
54
+ ? "Found 1 duplicated code block"
55
+ : `Found ${findings.length} duplicated code blocks`,
56
+ findings,
57
+ fix: `Extract a shared helper, or raise doctor.duplication.minLines in .config/sdxc.jsonc`,
58
+ };
59
+ },
60
+ };
61
+ /** Sliding windows of `minLines` consecutive code lines, keyed by their joined text. */
62
+ export function codeBlocks(file, source, minLines) {
63
+ let code = [];
64
+ let inBlock = false;
65
+ let lines = source.split("\n");
66
+ for (let index = 0; index < lines.length; index++) {
67
+ let raw = lines[index];
68
+ let trimmed = raw.trim();
69
+ if (inBlock) {
70
+ if (trimmed.includes("*/"))
71
+ inBlock = false;
72
+ continue;
73
+ }
74
+ if (trimmed === "" || trimmed.startsWith("//"))
75
+ continue;
76
+ if (trimmed.startsWith("/*") || trimmed.startsWith("{/*")) {
77
+ if (!trimmed.includes("*/"))
78
+ inBlock = true;
79
+ continue;
80
+ }
81
+ code.push({ line: index + 1, text: normalize(trimmed) });
82
+ }
83
+ let blocks = [];
84
+ for (let start = 0; start + minLines <= code.length; start++) {
85
+ let slice = code.slice(start, start + minLines);
86
+ let key = slice.map((line) => line.text).join("\n");
87
+ blocks.push({ key, file, line: slice[0].line });
88
+ }
89
+ return blocks;
90
+ }
91
+ /** Collapses whitespace so indent-only differences do not hide a paste. */
92
+ function normalize(line) {
93
+ return line.replace(/\s+/g, " ");
94
+ }
95
+ /** One hit per file (first line wins). */
96
+ function uniqueFiles(hits) {
97
+ let seen = new Set();
98
+ let unique = [];
99
+ for (let hit of hits) {
100
+ if (seen.has(hit.file))
101
+ continue;
102
+ seen.add(hit.file);
103
+ unique.push(hit);
104
+ }
105
+ return unique;
106
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The `fan-out` check: no module imports more distinct project modules than
3
+ * `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import type { Check } from "./check.js";
9
+ /**
10
+ * Warns on each module whose distinct import targets exceed the configured maximum.
11
+ */
12
+ export declare const fanOutCheck: Check;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The `fan-out` check: no module imports more distinct project modules than
3
+ * `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { projectGraph } from "../architecture/graph.js";
9
+ import { passed, skipped } from "./check.js";
10
+ /**
11
+ * Warns on each module whose distinct import targets exceed the configured maximum.
12
+ */
13
+ export const fanOutCheck = {
14
+ name: "fan-out",
15
+ async run(context) {
16
+ let max = context.config.doctor.fanOut.max;
17
+ let graph = await projectGraph(context.root);
18
+ if (graph.modules.length === 0)
19
+ return skipped("No app source to measure fan-out");
20
+ let counts = new Map();
21
+ for (let edge of graph.edges) {
22
+ let set = counts.get(edge.from) ?? new Set();
23
+ set.add(edge.to);
24
+ counts.set(edge.from, set);
25
+ }
26
+ let findings = [...counts.entries()]
27
+ .filter(([, targets]) => targets.size > max)
28
+ .sort((a, b) => b[1].size - a[1].size || a[0].localeCompare(b[0]))
29
+ .map(([file, targets]) => `${file}: imports ${targets.size} modules (max ${max})`);
30
+ if (findings.length === 0) {
31
+ return passed(`Every module imports at most ${max} others`);
32
+ }
33
+ return {
34
+ status: "warn",
35
+ message: findings.length === 1
36
+ ? "Found 1 module above the fan-out limit"
37
+ : `Found ${findings.length} modules above the fan-out limit`,
38
+ findings,
39
+ fix: `Split the module or extract a narrower facade, or raise doctor.fanOut.max in .config/sdxc.jsonc`,
40
+ };
41
+ },
42
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `feature-scatter` check: a feature folder name that appears under one app layer should
3
+ * also appear under the others that already use feature folders, so a glob on that name finds
4
+ * the whole feature.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns when a feature name already spans two or more layers but is missing from another
12
+ * layer that also hosts multi-layer features. A folder that exists in only one layer is left
13
+ * alone — not every feature crosses every kind.
14
+ */
15
+ export declare const featureScatterCheck: Check;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The `feature-scatter` check: a feature folder name that appears under one app layer should
3
+ * also appear under the others that already use feature folders, so a glob on that name finds
4
+ * the whole feature.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readdir } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { passed, skipped } from "./check.js";
13
+ /** Layers that group by feature with the same folder name. */
14
+ const FEATURE_LAYERS = [
15
+ "app/http/controllers",
16
+ "app/http/middleware",
17
+ "app/http/validators",
18
+ "app/jobs",
19
+ "app/services",
20
+ "app/policies",
21
+ "app/emails",
22
+ "app/commands",
23
+ "app/mcp/tools",
24
+ "app/mcp/resources",
25
+ ];
26
+ /**
27
+ * Warns when a feature name already spans two or more layers but is missing from another
28
+ * layer that also hosts multi-layer features. A folder that exists in only one layer is left
29
+ * alone — not every feature crosses every kind.
30
+ */
31
+ export const featureScatterCheck = {
32
+ name: "feature-scatter",
33
+ async run(context) {
34
+ let byLayer = new Map();
35
+ for (let layer of FEATURE_LAYERS) {
36
+ let names = await featureFolders(context.root, layer);
37
+ if (names.size > 0)
38
+ byLayer.set(layer, names);
39
+ }
40
+ if (byLayer.size < 2) {
41
+ return skipped("Fewer than two layers use feature folders");
42
+ }
43
+ let layersFor = new Map();
44
+ for (let [layer, names] of byLayer) {
45
+ for (let name of names) {
46
+ let list = layersFor.get(name) ?? [];
47
+ list.push(layer);
48
+ layersFor.set(name, list);
49
+ }
50
+ }
51
+ let multi = [...layersFor.entries()].filter(([, layers]) => layers.length >= 2);
52
+ if (multi.length === 0) {
53
+ return skipped("No feature folder name appears in more than one layer");
54
+ }
55
+ let peerLayers = new Set(multi.flatMap(([, layers]) => layers));
56
+ let findings = [];
57
+ for (let [feature, present] of multi.sort((a, b) => a[0].localeCompare(b[0]))) {
58
+ let missing = [...peerLayers].filter((layer) => !present.includes(layer)).sort();
59
+ if (missing.length === 0)
60
+ continue;
61
+ findings.push(`${feature}: in ${present.sort().join(", ")} but missing from ${missing.join(", ")}`);
62
+ }
63
+ if (findings.length === 0) {
64
+ return passed("Multi-layer feature folders line up across their peer layers");
65
+ }
66
+ return {
67
+ status: "warn",
68
+ message: findings.length === 1
69
+ ? "Found 1 feature scattered across layers"
70
+ : `Found ${findings.length} features scattered across layers`,
71
+ findings,
72
+ fix: "Add the missing feature folder (or move the files) so the shared name groups the feature in every peer layer",
73
+ };
74
+ },
75
+ };
76
+ /** Immediate subdirectories of `layer` that look like feature groups (not files). */
77
+ async function featureFolders(root, layer) {
78
+ let entries = await wrap(() => readdir(join(root, layer), { withFileTypes: true }));
79
+ if (isFailure(entries))
80
+ return new Set();
81
+ return new Set(entries.data
82
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
83
+ .map((entry) => entry.name));
84
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The `module-size` check: every app-source module stays within the configured code-line budget
3
+ * (default 200), counting like `sdxc stats` so blank lines and comments do not inflate the size.
4
+ * File-level size is outside oxlint's per-function rules.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns on each module whose code lines exceed `doctor.moduleSize.maxLines`.
12
+ */
13
+ export declare const moduleSizeCheck: Check;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The `module-size` check: every app-source module stays within the configured code-line budget
3
+ * (default 200), counting like `sdxc stats` so blank lines and comments do not inflate the size.
4
+ * File-level size is outside oxlint's per-function rules.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFile } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { codeLines, PROJECT_FOLDERS } from "../stats.js";
13
+ import { passed, skipped } from "./check.js";
14
+ import { isAppSource, listFiles } from "./files.js";
15
+ /**
16
+ * Warns on each module whose code lines exceed `doctor.moduleSize.maxLines`.
17
+ */
18
+ export const moduleSizeCheck = {
19
+ name: "module-size",
20
+ async run(context) {
21
+ let max = context.config.doctor.moduleSize.maxLines;
22
+ let findings = [];
23
+ let files = 0;
24
+ for (let folder of PROJECT_FOLDERS) {
25
+ for (let file of (await listFiles(context.root, folder)).filter(isAppSource)) {
26
+ files += 1;
27
+ let source = await wrap(() => readFile(join(context.root, file), "utf8"));
28
+ if (isFailure(source))
29
+ continue;
30
+ let lines = codeLines(source.data, false);
31
+ if (lines <= max)
32
+ continue;
33
+ findings.push(`${file}: ${lines} code lines (max ${max})`);
34
+ }
35
+ }
36
+ if (files === 0)
37
+ return skipped("No app source to measure module size");
38
+ if (findings.length === 0) {
39
+ return passed(`Every module stays within ${max} code lines`);
40
+ }
41
+ return {
42
+ status: "warn",
43
+ message: findings.length === 1
44
+ ? "Found 1 module above the size limit"
45
+ : `Found ${findings.length} modules above the size limit`,
46
+ findings,
47
+ fix: `Extract helpers or split the module, or raise doctor.moduleSize.maxLines in .config/sdxc.jsonc`,
48
+ };
49
+ },
50
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The `mutation` check: surviving mutants in a mutation-testing report stay at or under
3
+ * `doctor.mutation.maxSurvived`. Without the report file the check skips — the same honesty
4
+ * rule as `crap` and coverage.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns when the configured mutation report lists more survivors than allowed. Understands a
12
+ * Stryker-like `{ files: { …: { mutants: [{ status }] } } }` shape and a flat
13
+ * `{ survivors: [...] }` / `{ survived: number }` summary.
14
+ */
15
+ export declare const mutationCheck: Check;
16
+ /** Counts and names survivors from common mutation report shapes. */
17
+ export declare function survivingMutants(report: unknown): {
18
+ count: number;
19
+ findings: string[];
20
+ };
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The `mutation` check: surviving mutants in a mutation-testing report stay at or under
3
+ * `doctor.mutation.maxSurvived`. Without the report file the check skips — the same honesty
4
+ * rule as `crap` and coverage.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFile } from "node:fs/promises";
10
+ import { join } from "node:path";
11
+ import { isFailure, wrap } from "@sdxc/result";
12
+ import { passed, skipped } from "./check.js";
13
+ /**
14
+ * Warns when the configured mutation report lists more survivors than allowed. Understands a
15
+ * Stryker-like `{ files: { …: { mutants: [{ status }] } } }` shape and a flat
16
+ * `{ survivors: [...] }` / `{ survived: number }` summary.
17
+ */
18
+ export const mutationCheck = {
19
+ name: "mutation",
20
+ async run(context) {
21
+ let { report: relative, maxSurvived } = context.config.doctor.mutation;
22
+ let absolute = join(context.root, relative);
23
+ let text = await wrap(() => readFile(absolute, "utf8"));
24
+ if (isFailure(text)) {
25
+ return skipped(`No mutation report at ${relative}; run mutation tests then re-run doctor`);
26
+ }
27
+ let parsed = await wrap(() => Promise.resolve(JSON.parse(text.data)));
28
+ if (isFailure(parsed)) {
29
+ return {
30
+ status: "warn",
31
+ message: `Mutation report at ${relative} is not valid JSON`,
32
+ findings: [parsed.error.message],
33
+ fix: `Regenerate ${relative} from the mutation runner`,
34
+ };
35
+ }
36
+ let survivors = survivingMutants(parsed.data);
37
+ if (survivors.count <= maxSurvived) {
38
+ return passed(survivors.count === 0
39
+ ? "No surviving mutants in the mutation report"
40
+ : `${survivors.count} surviving mutant(s), within max ${maxSurvived}`);
41
+ }
42
+ return {
43
+ status: "warn",
44
+ message: `${survivors.count} surviving mutant(s), above max ${maxSurvived}`,
45
+ findings: survivors.findings.slice(0, 20),
46
+ fix: `Kill the survivors with stronger tests, or raise doctor.mutation.maxSurvived in .config/sdxc.jsonc`,
47
+ };
48
+ },
49
+ };
50
+ /** Counts and names survivors from common mutation report shapes. */
51
+ export function survivingMutants(report) {
52
+ if (report === null || typeof report !== "object") {
53
+ return { count: 0, findings: [] };
54
+ }
55
+ let record = report;
56
+ if (typeof record.survived === "number") {
57
+ return { count: record.survived, findings: [`survived: ${record.survived}`] };
58
+ }
59
+ if (Array.isArray(record.survivors)) {
60
+ let findings = record.survivors.map((item, index) => formatSurvivor(item, index));
61
+ return { count: findings.length, findings };
62
+ }
63
+ if (record.files && typeof record.files === "object") {
64
+ let findings = [];
65
+ for (let [file, entry] of Object.entries(record.files)) {
66
+ if (!entry || typeof entry !== "object")
67
+ continue;
68
+ let mutants = entry.mutants;
69
+ if (!Array.isArray(mutants))
70
+ continue;
71
+ for (let mutant of mutants) {
72
+ if (!mutant || typeof mutant !== "object")
73
+ continue;
74
+ let fields = mutant;
75
+ let status = typeof fields.status === "string" ? fields.status : "";
76
+ if (status.toLowerCase() !== "survived")
77
+ continue;
78
+ let mutator = typeof fields.mutatorName === "string" ? fields.mutatorName : "mutant";
79
+ let id = typeof fields.id === "string" || typeof fields.id === "number" ? String(fields.id) : null;
80
+ findings.push(`${file}: ${mutator}${id !== null ? ` #${id}` : ""}`);
81
+ }
82
+ }
83
+ return { count: findings.length, findings };
84
+ }
85
+ return { count: 0, findings: [] };
86
+ }
87
+ function formatSurvivor(item, index) {
88
+ if (typeof item === "string")
89
+ return item;
90
+ if (item && typeof item === "object") {
91
+ let record = item;
92
+ let file = typeof record.file === "string" ? record.file : `survivor[${index}]`;
93
+ let mutator = typeof record.mutatorName === "string" ? record.mutatorName : "mutant";
94
+ return `${file}: ${mutator}`;
95
+ }
96
+ return `survivor[${index}]`;
97
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The `orphans` check: every app-source module is imported by another, or is an entry the layout
3
+ * loads from outside the graph (bootstrap, routes, initializers, migrations, factories). Dead
4
+ * agent leftovers show up as unreferenced files.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Check } from "./check.js";
10
+ /**
11
+ * Warns on each non-entry module that nothing in the project imports.
12
+ */
13
+ export declare const orphansCheck: Check;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The `orphans` check: every app-source module is imported by another, or is an entry the layout
3
+ * loads from outside the graph (bootstrap, routes, initializers, migrations, factories). Dead
4
+ * agent leftovers show up as unreferenced files.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { projectGraph } from "../architecture/graph.js";
10
+ import { passed, skipped } from "./check.js";
11
+ /** Prefixes that may have no importers inside the project graph. */
12
+ const ENTRY_PREFIXES = [
13
+ "bootstrap/",
14
+ "routes/",
15
+ "app/initializers/",
16
+ "database/migrations/",
17
+ "database/factories/",
18
+ "config/",
19
+ ];
20
+ /**
21
+ * Warns on each non-entry module that nothing in the project imports.
22
+ */
23
+ export const orphansCheck = {
24
+ name: "orphans",
25
+ async run(context) {
26
+ let graph = await projectGraph(context.root);
27
+ if (graph.modules.length === 0)
28
+ return skipped("No app source to find orphans");
29
+ let imported = new Set(graph.edges.map((edge) => edge.to));
30
+ let findings = graph.modules
31
+ .filter((module) => !imported.has(module) && !isEntry(module))
32
+ .sort()
33
+ .map((module) => `${module}: nothing in the project imports it`);
34
+ if (findings.length === 0) {
35
+ return passed("Every non-entry module is imported somewhere");
36
+ }
37
+ return {
38
+ status: "warn",
39
+ message: findings.length === 1
40
+ ? "Found 1 orphaned module"
41
+ : `Found ${findings.length} orphaned modules`,
42
+ findings,
43
+ fix: "Delete the file, or wire it from an initializer, router, job map or another module that needs it",
44
+ };
45
+ },
46
+ };
47
+ /** Whether `path` is an entry the layout loads without a same-project importer. */
48
+ function isEntry(path) {
49
+ return ENTRY_PREFIXES.some((prefix) => path.startsWith(prefix));
50
+ }